graphics/FBD_Objects.py
changeset 717 86a2d1786684
parent 687 629680fb0582
child 721 f3dffc1a5ffe
equal deleted inserted replaced
716:2681a6da58d6 717:86a2d1786684
   159             linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
   159             linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
   160             # Update inputs and outputs positions
   160             # Update inputs and outputs positions
   161             position = BLOCK_LINE_SIZE + linesize / 2
   161             position = BLOCK_LINE_SIZE + linesize / 2
   162             for i in xrange(lines):
   162             for i in xrange(lines):
   163                 if scaling is not None:
   163                 if scaling is not None:
   164                     ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
   164                     ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y
   165                 else:
   165                 else:
   166                     ypos = position
   166                     ypos = position
   167                 if i < len(self.Inputs):
   167                 if i < len(self.Inputs):
   168                     self.Inputs[i].SetPosition(wx.Point(0, ypos))
   168                     self.Inputs[i].SetPosition(wx.Point(0, ypos))
   169                 if i < len(self.Outputs):
   169                 if i < len(self.Outputs):
   588     
   588     
   589     # Refresh the position of the variable connector
   589     # Refresh the position of the variable connector
   590     def RefreshConnectors(self):
   590     def RefreshConnectors(self):
   591         scaling = self.Parent.GetScaling()
   591         scaling = self.Parent.GetScaling()
   592         if scaling is not None:
   592         if scaling is not None:
   593             position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
   593             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   594         else:
   594         else:
   595             position = self.Size[1] / 2
   595             position = self.Size[1] / 2
   596         if self.Input:
   596         if self.Input:
   597             self.Input.SetPosition(wx.Point(0, position))
   597             self.Input.SetPosition(wx.Point(0, position))
   598         if self.Output:
   598         if self.Output:
   687         self.RefreshExecutionOrderSize()
   687         self.RefreshExecutionOrderSize()
   688     
   688     
   689     # Returs the execution order
   689     # Returs the execution order
   690     def GetExecutionOrder(self):
   690     def GetExecutionOrder(self):
   691         return self.ExecutionOrder
   691         return self.ExecutionOrder
       
   692     
       
   693     # Changes the element size
       
   694     def SetSize(self, width, height):
       
   695         scaling = self.Parent.GetScaling()
       
   696         min_width, min_height = self.GetMinSize()
       
   697         if width < min_width:
       
   698             if self.Type == INPUT:
       
   699                 posx = max(0, self.Pos.x + width - min_width)
       
   700                 if scaling is not None:
       
   701                     posx = round_scaling(posx, scaling[0])
       
   702                 self.Pos.x = posx
       
   703             elif self.Type == OUTPUT:
       
   704                 posy = max(0, self.Pos.x + (width - min_width) / 2)
       
   705                 if scaling is not None:
       
   706                     posx = round_scaling(posx, scaling[0])
       
   707                 self.Pos.x = posx
       
   708             width = min_width
       
   709             if scaling is not None:
       
   710                 width = round_scaling(width, scaling[0], 1)
       
   711         if height < min_height:
       
   712             posy = max(0, self.Pos.y + (height - min_height) / 2)
       
   713             if scaling is not None:
       
   714                 posy = round_scaling(posy, scaling[1])
       
   715             self.Pos.y = posy
       
   716             height = min_height
       
   717             if scaling is not None:
       
   718                 height = round_scaling(height, scaling[1], 1)
       
   719         Graphic_Element.SetSize(self, width, height)
   692     
   720     
   693     # Returns the variable minimum size
   721     # Returns the variable minimum size
   694     def GetMinSize(self):
   722     def GetMinSize(self):
   695         return self.NameSize[0] + 10, self.NameSize[1] + 10
   723         return self.NameSize[0] + 10, self.NameSize[1] + 10
   696     
   724     
   835     
   863     
   836     # Refresh the position of the connection connector
   864     # Refresh the position of the connection connector
   837     def RefreshConnectors(self):
   865     def RefreshConnectors(self):
   838         scaling = self.Parent.GetScaling()
   866         scaling = self.Parent.GetScaling()
   839         if scaling is not None:
   867         if scaling is not None:
   840             position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
   868             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   841         else:
   869         else:
   842             position = self.Size[1] / 2
   870             position = self.Size[1] / 2
   843         if self.Type == CONNECTOR:
   871         if self.Type == CONNECTOR:
   844             self.Connector.SetPosition(wx.Point(0, position))
   872             self.Connector.SetPosition(wx.Point(0, position))
   845         else:
   873         else:
   899         self.RefreshNameSize()
   927         self.RefreshNameSize()
   900         
   928         
   901     # Returns the connection name
   929     # Returns the connection name
   902     def GetName(self):
   930     def GetName(self):
   903         return self.Name
   931         return self.Name
       
   932     
       
   933     # Changes the element size
       
   934     def SetSize(self, width, height):
       
   935         scaling = self.Parent.GetScaling()
       
   936         min_width, min_height = self.GetMinSize()
       
   937         if width < min_width:
       
   938             if self.Type == CONTINUATION:
       
   939                 posx = max(0, self.Pos.x + width - min_width)
       
   940                 if scaling is not None:
       
   941                     posx = round_scaling(posx, scaling[0])
       
   942                 self.Pos.x = posx
       
   943             width = min_width
       
   944             if scaling is not None:
       
   945                 width = round_scaling(width, scaling[0], 1)
       
   946         if height < min_height:
       
   947             posy = max(0, self.Pos.y + (height - min_height) / 2)
       
   948             if scaling is not None:
       
   949                 posy = round_scaling(posy, scaling[1])
       
   950             self.Pos.y = posy
       
   951             height = min_height
       
   952             if scaling is not None:
       
   953                 height = round_scaling(height, scaling[1], 1)
       
   954         Graphic_Element.SetSize(self, width, height)
   904     
   955     
   905     # Returns the connection minimum size
   956     # Returns the connection minimum size
   906     def GetMinSize(self):
   957     def GetMinSize(self):
   907         text_width, text_height = self.NameSize
   958         text_width, text_height = self.NameSize
   908         if text_height % 2 == 1:
   959         if text_height % 2 == 1: