graphics/FBD_Objects.py
changeset 145 4fb225afddf4
parent 144 b67a5de5a24a
child 162 e746ff4aa8be
equal deleted inserted replaced
144:b67a5de5a24a 145:4fb225afddf4
   121             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   121             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   122         self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
   122         self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
   123     
   123     
   124     # Refresh the positions of the block connectors
   124     # Refresh the positions of the block connectors
   125     def RefreshConnectors(self):
   125     def RefreshConnectors(self):
       
   126         scaling = self.Parent.GetScaling()
   126         # Calculate the size for the connector lines
   127         # Calculate the size for the connector lines
   127         lines = max(len(self.Inputs), len(self.Outputs))
   128         lines = max(len(self.Inputs), len(self.Outputs))
   128         if lines > 0:
   129         if lines > 0:
   129             linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
   130             linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
   130             # Update inputs positions
   131             # Update inputs and outputs positions
   131             position = BLOCK_LINE_SIZE + linesize / 2
   132             position = BLOCK_LINE_SIZE + linesize / 2
   132             for input in self.Inputs:
   133             for i in xrange(lines):
   133                 input.SetPosition(wx.Point(0, position))
   134                 if scaling is not None:
   134                 position += linesize
   135                     ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y
   135             # Update outputs positions
   136                 else:
   136             position = BLOCK_LINE_SIZE + linesize / 2
   137                     ypos = position
   137             for output in self.Outputs:
   138                 if i < len(self.Inputs):
   138                 output.SetPosition(wx.Point(self.Size[0], position))
   139                     self.Inputs[i].SetPosition(wx.Point(0, ypos))
       
   140                 if i < len(self.Outputs):
       
   141                     self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
   139                 position += linesize
   142                 position += linesize
   140         self.RefreshConnected()
   143         self.RefreshConnected()
   141     
   144     
   142     # Refresh the positions of wires connected to inputs and outputs
   145     # Refresh the positions of wires connected to inputs and outputs
   143     def RefreshConnected(self, exclude = []):
   146     def RefreshConnected(self, exclude = []):
   190                 outputtype = output.GetConnectedType()
   193                 outputtype = output.GetConnectedType()
   191                 if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype):
   194                 if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype):
   192                     resulttype = outputtype
   195                     resulttype = outputtype
   193         return resulttype
   196         return resulttype
   194     
   197     
   195     # Returns all the block connectors 
   198     # Returns all the block connectors
   196     def GetConnectors(self):
   199     def GetConnectors(self):
   197         return {"inputs" : self.Inputs, "outputs" : self.Outputs}
   200         return {"inputs" : self.Inputs, "outputs" : self.Outputs}
   198     
   201     
   199     # Test if point given is on one of the block connectors
   202     # Test if point given is on one of the block connectors
   200     def TestConnector(self, pt, exclude = True):
   203     def TestConnector(self, pt, exclude = True):
   462             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   465             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   463         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
   466         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
   464     
   467     
   465     # Refresh the position of the variable connector
   468     # Refresh the position of the variable connector
   466     def RefreshConnectors(self):
   469     def RefreshConnectors(self):
       
   470         scaling = self.Parent.GetScaling()
       
   471         if scaling is not None:
       
   472             position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
       
   473         else:
       
   474             position = self.Size[1] / 2
   467         if self.Input:
   475         if self.Input:
   468             self.Input.SetPosition(wx.Point(0, self.Size[1] / 2))
   476             self.Input.SetPosition(wx.Point(0, position))
   469         if self.Output:
   477         if self.Output:
   470             self.Output.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
   478             self.Output.SetPosition(wx.Point(self.Size[0], position))
   471         self.RefreshConnected()
   479         self.RefreshConnected()
   472     
   480     
   473     # Refresh the position of wires connected to connector
   481     # Refresh the position of wires connected to connector
   474     def RefreshConnected(self, exclude = []):
   482     def RefreshConnected(self, exclude = []):
   475         if self.Input:
   483         if self.Input:
   672         bbx_width = self.Size[0] + CONNECTOR_SIZE
   680         bbx_width = self.Size[0] + CONNECTOR_SIZE
   673         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
   681         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
   674     
   682     
   675     # Refresh the position of the connection connector
   683     # Refresh the position of the connection connector
   676     def RefreshConnectors(self):
   684     def RefreshConnectors(self):
       
   685         scaling = self.Parent.GetScaling()
       
   686         if scaling is not None:
       
   687             position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y
       
   688         else:
       
   689             position = self.Size[1] / 2
   677         if self.Type == CONNECTOR:
   690         if self.Type == CONNECTOR:
   678             self.Connector.SetPosition(wx.Point(0, self.Size[1] / 2))
   691             self.Connector.SetPosition(wx.Point(0, position))
   679         else:
   692         else:
   680             self.Connector.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
   693             self.Connector.SetPosition(wx.Point(self.Size[0], position))
   681         self.RefreshConnected()
   694         self.RefreshConnected()
   682     
   695     
   683     # Refresh the position of wires connected to connector
   696     # Refresh the position of wires connected to connector
   684     def RefreshConnected(self, exclude = []):
   697     def RefreshConnected(self, exclude = []):
   685         if self.Connector:
   698         if self.Connector:
   708             self.RefreshConnectors()
   721             self.RefreshConnectors()
   709     
   722     
   710     # Returns the connection type
   723     # Returns the connection type
   711     def GetType(self):
   724     def GetType(self):
   712         return self.Type
   725         return self.Type
       
   726     
       
   727     def GetConnectionResultType(self, connector, connectortype):
       
   728         return connectortype
   713     
   729     
   714     # Changes the connection name
   730     # Changes the connection name
   715     def SetName(self, name):
   731     def SetName(self, name):
   716         self.Name = name
   732         self.Name = name
   717         self.RefreshNameSize()
   733         self.RefreshNameSize()