graphics/SFC_Objects.py
changeset 652 676307069508
parent 641 e9295622ce9b
child 759 264637370f8f
equal deleted inserted replaced
651:34c1fa1a89a9 652:676307069508
  1177         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1177         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1178             return len(self.Inputs)
  1178             return len(self.Inputs)
  1179     
  1179     
  1180     # Returns if the point given is in the bounding box
  1180     # Returns if the point given is in the bounding box
  1181     def HitTest(self, pt, connectors=True):
  1181     def HitTest(self, pt, connectors=True):
  1182         if connectors:
  1182         return self.BoundingBox.InsideXY(pt.x, pt.y) or self.TestConnector(pt, exclude=False) != None
  1183             rect = self.BoundingBox
       
  1184         else:
       
  1185             rect = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
       
  1186         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, exclude=False) != None
       
  1187     
  1183     
  1188     # Refresh the divergence bounding box
  1184     # Refresh the divergence bounding box
  1189     def RefreshBoundingBox(self):
  1185     def RefreshBoundingBox(self):
  1190         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1186         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1191             self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, 
  1187             self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, 
  1347                     output_block.Move(move[0], move[1], self.Parent.Wires)
  1343                     output_block.Move(move[0], move[1], self.Parent.Wires)
  1348                     output_block.RefreshOutputPosition(move)
  1344                     output_block.RefreshOutputPosition(move)
  1349     
  1345     
  1350     # Method called when a LeftDown event have been generated
  1346     # Method called when a LeftDown event have been generated
  1351     def OnLeftDown(self, event, dc, scaling):
  1347     def OnLeftDown(self, event, dc, scaling):
  1352         self.RealConnectors = {"Inputs":[],"Outputs":[]}
  1348         connector = None
  1353         for input in self.Inputs:
  1349         if event.ControlDown():
  1354             position = input.GetRelPosition()
  1350             pos = GetScaledEventPosition(event, dc, scaling)
  1355             self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
  1351             # Test if a connector have been handled
  1356         for output in self.Outputs:
  1352             connector = self.TestConnector(pos, exclude=False)
  1357             position = output.GetRelPosition()
       
  1358             self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
       
  1359         Graphic_Element.OnLeftDown(self, event, dc, scaling)
       
  1360     
       
  1361     # Method called when a LeftUp event have been generated
       
  1362     def OnLeftUp(self, event, dc, scaling):
       
  1363         Graphic_Element.OnLeftUp(self, event, dc, scaling)
       
  1364         self.RealConnectors = None
       
  1365     
       
  1366     # Method called when a RightDown event have been generated
       
  1367     def OnRightDown(self, event, dc, scaling):
       
  1368         pos = GetScaledEventPosition(event, dc, scaling)
       
  1369         # Test if a connector have been handled
       
  1370         connector = self.TestConnector(pos, exclude=False)
       
  1371         if connector:
  1353         if connector:
  1372             self.Handle = (HANDLE_CONNECTOR, connector)
  1354             self.Handle = (HANDLE_CONNECTOR, connector)
  1373             wx.CallAfter(self.Parent.SetCurrentCursor, 1)
  1355             wx.CallAfter(self.Parent.SetCurrentCursor, 1)
  1374             self.Selected = False
  1356             self.Selected = False
  1375             # Initializes the last position
  1357             # Initializes the last position
  1376             self.oldPos = GetScaledEventPosition(event, dc, scaling)
  1358             self.oldPos = GetScaledEventPosition(event, dc, scaling)
  1377         else:
  1359         else:
  1378             Graphic_Element.OnRightDown(self, event, dc, scaling)
  1360             self.RealConnectors = {"Inputs":[],"Outputs":[]}
  1379     
  1361             for input in self.Inputs:
  1380     # Method called when a RightUp event have been generated
  1362                 position = input.GetRelPosition()
  1381     def OnRightUp(self, event, dc, scaling):
  1363                 self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
       
  1364             for output in self.Outputs:
       
  1365                 position = output.GetRelPosition()
       
  1366                 self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
       
  1367             Graphic_Element.OnLeftDown(self, event, dc, scaling)
       
  1368     
       
  1369     # Method called when a LeftUp event have been generated
       
  1370     def OnLeftUp(self, event, dc, scaling):
  1382         handle_type, handle = self.Handle
  1371         handle_type, handle = self.Handle
  1383         if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos:
  1372         if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos:
  1384             wires = handle.GetWires()
  1373             wires = handle.GetWires()
  1385             if len(wires) == 1:
  1374             if len(wires) == 1:
  1386                 block = wires[0][0].GetOtherConnected(handle).GetParentBlock()
  1375                 block = wires[0][0].GetOtherConnected(handle).GetParentBlock()
  1388                 if not isinstance(block, SFC_Divergence):
  1377                 if not isinstance(block, SFC_Divergence):
  1389                     if handle in self.Inputs:
  1378                     if handle in self.Inputs:
  1390                         block.RefreshInputModel()
  1379                         block.RefreshInputModel()
  1391                     else:
  1380                     else:
  1392                         block.RefreshOutputModel()
  1381                         block.RefreshOutputModel()
  1393             Graphic_Element.OnRightUp(self, event, dc, scaling)
  1382         Graphic_Element.OnLeftUp(self, event, dc, scaling)
  1394         else:
  1383         self.RealConnectors = None
  1395             pos = GetScaledEventPosition(event, dc, scaling)
  1384     
  1396             # Popup the menu with special items for a block and a connector if one is handled
  1385     # Method called when a RightUp event have been generated
  1397             connector = self.TestConnector(pos, exclude=False)
  1386     def OnRightUp(self, event, dc, scaling):
  1398             if connector:
  1387         pos = GetScaledEventPosition(event, dc, scaling)
  1399                 self.Handle = (HANDLE_CONNECTOR, connector)
  1388         # Popup the menu with special items for a block and a connector if one is handled
  1400                 self.Parent.PopupDivergenceMenu(True)
  1389         connector = self.TestConnector(pos, exclude=False)
  1401             else:
  1390         if connector:
  1402                 # Popup the divergence menu without delete branch
  1391             self.Handle = (HANDLE_CONNECTOR, connector)
  1403                 self.Parent.PopupDivergenceMenu(False)
  1392             self.Parent.PopupDivergenceMenu(True)
       
  1393         else:
       
  1394             # Popup the divergence menu without delete branch
       
  1395             self.Parent.PopupDivergenceMenu(False)
  1404     
  1396     
  1405     # Refreshes the divergence state according to move defined and handle selected
  1397     # Refreshes the divergence state according to move defined and handle selected
  1406     def ProcessDragging(self, movex, movey, event, scaling):
  1398     def ProcessDragging(self, movex, movey, event, scaling):
  1407         handle_type, handle = self.Handle
  1399         handle_type, handle = self.Handle
  1408         # A connector has been handled
  1400         # A connector has been handled