graphics/SFC_Objects.py
changeset 243 c5da8b706cde
parent 231 fc2d6cbb8b39
child 249 d8425712acef
equal deleted inserted replaced
242:5b3e1c4569e6 243:c5da8b706cde
   232     # Returns input and output step connectors 
   232     # Returns input and output step connectors 
   233     def GetConnectors(self):
   233     def GetConnectors(self):
   234         return {"input":self.Input,"output":self.Output,"action":self.Action}
   234         return {"input":self.Input,"output":self.Output,"action":self.Action}
   235     
   235     
   236     # Test if point given is on step input or output connector
   236     # Test if point given is on step input or output connector
   237     def TestConnector(self, pt, exclude=True):
   237     def TestConnector(self, pt, direction = None, exclude=True):
   238         # Test input connector if it exists
   238         # Test input connector if it exists
   239         if self.Input and self.Input.TestPoint(pt, exclude):
   239         if self.Input and self.Input.TestPoint(pt, direction, exclude):
   240             return self.Input
   240             return self.Input
   241         # Test output connector
   241         # Test output connector
   242         if self.Output and self.Output.TestPoint(pt, exclude):
   242         if self.Output and self.Output.TestPoint(pt, direction, exclude):
   243             return self.Output
   243             return self.Output
   244         # Test action connector
   244         # Test action connector
   245         if self.Action and self.Action.TestPoint(pt, exclude):
   245         if self.Action and self.Action.TestPoint(pt, direction, exclude):
   246             return self.Action
   246             return self.Action
   247         return None
   247         return None
   248 
   248 
   249     # Changes the step name
   249     # Changes the step name
   250     def SetName(self, name):
   250     def SetName(self, name):
   674         if self.Type == "connection":
   674         if self.Type == "connection":
   675             connectors["connection"] = self.Condition
   675             connectors["connection"] = self.Condition
   676         return connectors
   676         return connectors
   677     
   677     
   678     # Test if point given is on transition input or output connector
   678     # Test if point given is on transition input or output connector
   679     def TestConnector(self, pt, exclude=True):
   679     def TestConnector(self, pt, direction = None, exclude=True):
   680         # Test input connector
   680         # Test input connector
   681         if self.Input.TestPoint(pt, exclude):
   681         if self.Input.TestPoint(pt, direction, exclude):
   682             return self.Input
   682             return self.Input
   683         # Test output connector
   683         # Test output connector
   684         if self.Output.TestPoint(pt, exclude):
   684         if self.Output.TestPoint(pt, direction, exclude):
   685             return self.Output
   685             return self.Output
   686         # Test condition connector
   686         # Test condition connector
   687         if self.Type == "connection" and self.Condition.TestPoint(pt, exclude):
   687         if self.Type == "connection" and self.Condition.TestPoint(pt, direction, exclude):
   688             return self.Condition
   688             return self.Condition
   689         return None
   689         return None
   690 
   690 
   691     # Changes the transition type
   691     # Changes the transition type
   692     def SetType(self, type, condition = None):
   692     def SetType(self, type, condition = None):
  1013             return len(self.Inputs)
  1013             return len(self.Inputs)
  1014     
  1014     
  1015     # Returns if the point given is in the bounding box
  1015     # Returns if the point given is in the bounding box
  1016     def HitTest(self, pt):
  1016     def HitTest(self, pt):
  1017         rect = self.BoundingBox
  1017         rect = self.BoundingBox
  1018         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None
  1018         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, exclude=False) != None
  1019     
  1019     
  1020     # Refresh the divergence bounding box
  1020     # Refresh the divergence bounding box
  1021     def RefreshBoundingBox(self):
  1021     def RefreshBoundingBox(self):
  1022         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1022         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1023             self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, 
  1023             self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, 
  1087     # Returns input and output divergence connectors 
  1087     # Returns input and output divergence connectors 
  1088     def GetConnectors(self):
  1088     def GetConnectors(self):
  1089         return {"inputs":self.Inputs,"outputs":self.Outputs}
  1089         return {"inputs":self.Inputs,"outputs":self.Outputs}
  1090     
  1090     
  1091     # Test if point given is on divergence input or output connector
  1091     # Test if point given is on divergence input or output connector
  1092     def TestConnector(self, pt, exclude=True):
  1092     def TestConnector(self, pt, direction = None, exclude=True):
  1093         # Test input connector
  1093         # Test input connector
  1094         for input in self.Inputs:
  1094         for input in self.Inputs:
  1095             if input.TestPoint(pt, exclude):
  1095             if input.TestPoint(pt, direction, exclude):
  1096                 return input
  1096                 return input
  1097         # Test output connector
  1097         # Test output connector
  1098         for output in self.Outputs:
  1098         for output in self.Outputs:
  1099             if output.TestPoint(pt, exclude):
  1099             if output.TestPoint(pt, direction, exclude):
  1100                 return output
  1100                 return output
  1101         return None
  1101         return None
  1102     
  1102     
  1103     # Changes the divergence size
  1103     # Changes the divergence size
  1104     def SetSize(self, width, height):
  1104     def SetSize(self, width, height):
  1207     
  1207     
  1208     # Method called when a RightDown event have been generated
  1208     # Method called when a RightDown event have been generated
  1209     def OnRightDown(self, event, dc, scaling):
  1209     def OnRightDown(self, event, dc, scaling):
  1210         pos = GetScaledEventPosition(event, dc, scaling)
  1210         pos = GetScaledEventPosition(event, dc, scaling)
  1211         # Test if a connector have been handled
  1211         # Test if a connector have been handled
  1212         connector = self.TestConnector(pos, False)
  1212         connector = self.TestConnector(pos, exclude=False)
  1213         if connector:
  1213         if connector:
  1214             self.Handle = (HANDLE_CONNECTOR, connector)
  1214             self.Handle = (HANDLE_CONNECTOR, connector)
  1215             self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
  1215             self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
  1216             self.Selected = False
  1216             self.Selected = False
  1217             # Initializes the last position
  1217             # Initializes the last position
  1235                     block.RefreshOutputModel()
  1235                     block.RefreshOutputModel()
  1236             Graphic_Element.OnRightUp(self, event, dc, scaling)
  1236             Graphic_Element.OnRightUp(self, event, dc, scaling)
  1237         else:
  1237         else:
  1238             pos = GetScaledEventPosition(event, dc, scaling)
  1238             pos = GetScaledEventPosition(event, dc, scaling)
  1239             # Popup the menu with special items for a block and a connector if one is handled
  1239             # Popup the menu with special items for a block and a connector if one is handled
  1240             connector = self.TestConnector(pos, False)
  1240             connector = self.TestConnector(pos, exclude=False)
  1241             if connector:
  1241             if connector:
  1242                 self.Handle = (HANDLE_CONNECTOR, connector)
  1242                 self.Handle = (HANDLE_CONNECTOR, connector)
  1243                 self.Parent.PopupDivergenceMenu(True)
  1243                 self.Parent.PopupDivergenceMenu(True)
  1244             else:
  1244             else:
  1245                 # Popup the divergence menu without delete branch
  1245                 # Popup the divergence menu without delete branch
  1414     # Returns input jump connector 
  1414     # Returns input jump connector 
  1415     def GetConnector(self, position = None, name = None):
  1415     def GetConnector(self, position = None, name = None):
  1416         return self.Input
  1416         return self.Input
  1417     
  1417     
  1418     # Test if point given is on jump input connector
  1418     # Test if point given is on jump input connector
  1419     def TestConnector(self, pt, exclude = True):
  1419     def TestConnector(self, pt, direction = None, exclude = True):
  1420         # Test input connector
  1420         # Test input connector
  1421         if self.Input and self.Input.TestPoint(pt, exclude):
  1421         if self.Input and self.Input.TestPoint(pt, direction, exclude):
  1422             return self.Input
  1422             return self.Input
  1423         return None
  1423         return None
  1424     
  1424     
  1425     # Changes the jump target
  1425     # Changes the jump target
  1426     def SetTarget(self, target):
  1426     def SetTarget(self, target):
  1624     # Returns input action block connector 
  1624     # Returns input action block connector 
  1625     def GetConnector(self, position = None, name = None):
  1625     def GetConnector(self, position = None, name = None):
  1626         return self.Input
  1626         return self.Input
  1627     
  1627     
  1628     # Test if point given is on action block input connector
  1628     # Test if point given is on action block input connector
  1629     def TestConnector(self, pt, exclude = True):
  1629     def TestConnector(self, pt, direction = None, exclude = True):
  1630         # Test input connector
  1630         # Test input connector
  1631         if self.Input.TestPoint(pt, exclude):
  1631         if self.Input.TestPoint(pt, direction, exclude):
  1632             return self.Input
  1632             return self.Input
  1633         return None
  1633         return None
  1634     
  1634     
  1635     # Refresh the element connectors position
  1635     # Refresh the element connectors position
  1636     def RefreshConnectors(self):
  1636     def RefreshConnectors(self):