graphics/FBD_Objects.py
changeset 1852 70c1cc354a8f
parent 1847 6198190bc121
child 1872 866fb3ab8778
equal deleted inserted replaced
1851:1b8b5324506c 1852:70c1cc354a8f
    41     """
    41     """
    42     Class that implements the graphic representation of a function block
    42     Class that implements the graphic representation of a function block
    43     """
    43     """
    44 
    44 
    45     # Create a new block
    45     # Create a new block
    46     def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors={}, executionControl=False, executionOrder=0):
    46     def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors=None, executionControl=False, executionOrder=0):
    47         Graphic_Element.__init__(self, parent)
    47         Graphic_Element.__init__(self, parent)
    48         self.Type = None
    48         self.Type = None
    49         self.Description = None
    49         self.Description = None
    50         self.Extension = None
    50         self.Extension = None
    51         self.ExecutionControl = False
    51         self.ExecutionControl = False
   172                     self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
   172                     self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
   173                 position += linesize
   173                 position += linesize
   174         self.RefreshConnected()
   174         self.RefreshConnected()
   175 
   175 
   176     # Refresh the positions of wires connected to inputs and outputs
   176     # Refresh the positions of wires connected to inputs and outputs
   177     def RefreshConnected(self, exclude=[]):
   177     def RefreshConnected(self, exclude=None):
   178         for input in self.Inputs:
   178         for input in self.Inputs:
   179             input.MoveConnected(exclude)
   179             input.MoveConnected(exclude)
   180         for output in self.Outputs:
   180         for output in self.Outputs:
   181             output.MoveConnected(exclude)
   181             output.MoveConnected(exclude)
   182 
   182 
   234             if output.TestPoint(pt, direction, exclude):
   234             if output.TestPoint(pt, direction, exclude):
   235                 return output
   235                 return output
   236         return None
   236         return None
   237 
   237 
   238     # Changes the block type
   238     # Changes the block type
   239     def SetType(self, type, extension, inputs=None, connectors={}, executionControl=False):
   239     def SetType(self, type, extension, inputs=None, connectors=None, executionControl=False):
   240         if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl:
   240         if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl:
   241             if type != self.Type:
   241             if type != self.Type:
   242                 self.Type = type
   242                 self.Type = type
   243                 self.TypeSize = self.Parent.GetTextExtent(self.Type)
   243                 self.TypeSize = self.Parent.GetTextExtent(self.Type)
   244             self.Extension = extension
   244             self.Extension = extension
   257                         inputs.append(("IN%d" % start, inputs[-1][1], inputs[-1][2]))
   257                         inputs.append(("IN%d" % start, inputs[-1][1], inputs[-1][2]))
   258                 comment = blocktype["comment"]
   258                 comment = blocktype["comment"]
   259                 self.Description = _(comment) + blocktype.get("usage", "")
   259                 self.Description = _(comment) + blocktype.get("usage", "")
   260             else:
   260             else:
   261                 self.Colour = wx.RED
   261                 self.Colour = wx.RED
       
   262                 connectors = {} if connectors is None else connectors
   262                 inputs = connectors.get("inputs", [])
   263                 inputs = connectors.get("inputs", [])
   263                 outputs = connectors.get("outputs", [])
   264                 outputs = connectors.get("outputs", [])
   264                 self.Description = None
   265                 self.Description = None
   265             if self.ExecutionControl:
   266             if self.ExecutionControl:
   266                 inputs.insert(0,  ("EN",   "BOOL", "none"))
   267                 inputs.insert(0,  ("EN",   "BOOL", "none"))
   609         if self.Output:
   610         if self.Output:
   610             self.Output.SetPosition(wx.Point(self.Size[0], position))
   611             self.Output.SetPosition(wx.Point(self.Size[0], position))
   611         self.RefreshConnected()
   612         self.RefreshConnected()
   612 
   613 
   613     # Refresh the position of wires connected to connector
   614     # Refresh the position of wires connected to connector
   614     def RefreshConnected(self, exclude=[]):
   615     def RefreshConnected(self, exclude=None):
   615         if self.Input:
   616         if self.Input:
   616             self.Input.MoveConnected(exclude)
   617             self.Input.MoveConnected(exclude)
   617         if self.Output:
   618         if self.Output:
   618             self.Output.MoveConnected(exclude)
   619             self.Output.MoveConnected(exclude)
   619 
   620 
   881         else:
   882         else:
   882             self.Connector.SetPosition(wx.Point(self.Size[0], position))
   883             self.Connector.SetPosition(wx.Point(self.Size[0], position))
   883         self.RefreshConnected()
   884         self.RefreshConnected()
   884 
   885 
   885     # Refresh the position of wires connected to connector
   886     # Refresh the position of wires connected to connector
   886     def RefreshConnected(self, exclude=[]):
   887     def RefreshConnected(self, exclude=None):
   887         if self.Connector:
   888         if self.Connector:
   888             self.Connector.MoveConnected(exclude)
   889             self.Connector.MoveConnected(exclude)
   889 
   890 
   890     # Test if point given is on the connection connector
   891     # Test if point given is on the connection connector
   891     def TestConnector(self, pt, direction=None, exclude=True):
   892     def TestConnector(self, pt, direction=None, exclude=True):