graphics/SFC_Objects.py
changeset 165 e464a4e4e06d
parent 162 e746ff4aa8be
child 172 198f7949f737
equal deleted inserted replaced
164:0fb64076d3f5 165:e464a4e4e06d
   148             self.Action = None
   148             self.Action = None
   149             self.RefreshBoundingBox()
   149             self.RefreshBoundingBox()
   150     
   150     
   151     # Refresh the step bounding box
   151     # Refresh the step bounding box
   152     def RefreshBoundingBox(self):
   152     def RefreshBoundingBox(self):
   153         dc = wx.ClientDC(self.Parent)
       
   154         # Calculate the bounding box size
   153         # Calculate the bounding box size
   155         if self.Action:
   154         if self.Action:
   156             bbx_width = self.Size[0] + CONNECTOR_SIZE
   155             bbx_width = self.Size[0] + CONNECTOR_SIZE
   157         else:
   156         else:
   158             bbx_width = self.Size[0]
   157             bbx_width = self.Size[0]
   288             return max(0, action_block.GetLineNumber() - 1)
   287             return max(0, action_block.GetLineNumber() - 1)
   289         return 0
   288         return 0
   290     
   289     
   291     # Returns the step minimum size
   290     # Returns the step minimum size
   292     def GetMinSize(self):
   291     def GetMinSize(self):
   293         dc = wx.ClientDC(self.Parent)
   292         text_width, text_height = self.Parent.GetTextExtent(self.Name)
   294         text_width, text_height = dc.GetTextExtent(self.Name)
       
   295         if self.Initial:
   293         if self.Initial:
   296             return text_width + 14, text_height + 14
   294             return text_width + 14, text_height + 14
   297         else:
   295         else:
   298             return text_width + 10, text_height + 10
   296             return text_width + 10, text_height + 10
   299     
   297     
   391     def OnRightUp(self, event, dc, scaling):
   389     def OnRightUp(self, event, dc, scaling):
   392         # Popup the menu with special items for a step
   390         # Popup the menu with special items for a step
   393         self.Parent.PopupDefaultMenu()
   391         self.Parent.PopupDefaultMenu()
   394     
   392     
   395     # Refreshes the step state according to move defined and handle selected
   393     # Refreshes the step state according to move defined and handle selected
   396     def ProcessDragging(self, movex, movey, scaling):
   394     def ProcessDragging(self, movex, movey, centered, scaling):
   397         handle_type, handle = self.Handle
   395         handle_type, handle = self.Handle
   398         if handle_type == HANDLE_MOVE:
   396         if handle_type == HANDLE_MOVE:
   399             movex = max(-self.BoundingBox.x, movex)
   397             movex = max(-self.BoundingBox.x, movex)
   400             movey = max(-self.BoundingBox.y, movey)
   398             movey = max(-self.BoundingBox.y, movey)
   401             if scaling is not None:
   399             if scaling is not None:
   416                 self.Move(movex, 0)
   414                 self.Move(movex, 0)
   417                 self.RefreshInputPosition()
   415                 self.RefreshInputPosition()
   418                 self.RefreshOutputPosition()
   416                 self.RefreshOutputPosition()
   419                 return movex, 0
   417                 return movex, 0
   420         else:
   418         else:
   421             return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
   419             return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
   422     
   420     
   423     # Refresh input element model
   421     # Refresh input element model
   424     def RefreshInputModel(self):
   422     def RefreshInputModel(self):
   425         if self.Input:
   423         if self.Input:
   426             input = self.GetPreviousConnector()
   424             input = self.GetPreviousConnector()
   541             Graphic_Element.Resize(self, x, y, width, height)
   539             Graphic_Element.Resize(self, x, y, width, height)
   542     
   540     
   543     # Refresh the size of text for name
   541     # Refresh the size of text for name
   544     def RefreshConditionSize(self):
   542     def RefreshConditionSize(self):
   545         if self.Type != "connection":
   543         if self.Type != "connection":
   546             dc = wx.ClientDC(self.Parent)
       
   547             if self.Condition != "":
   544             if self.Condition != "":
   548                 self.ConditionSize = dc.GetTextExtent(self.Condition)
   545                 self.ConditionSize = self.Parent.GetTextExtent(self.Condition)
   549             else:
   546             else:
   550                 self.ConditionSize = dc.GetTextExtent("Transition")
   547                 self.ConditionSize = self.Parent.GetTextExtent("Transition")
   551     
   548     
   552     # Refresh the size of text for name
   549     # Refresh the size of text for name
   553     def RefreshPrioritySize(self):
   550     def RefreshPrioritySize(self):
   554         if self.Priority != "":
   551         if self.Priority != "":
   555             dc = wx.ClientDC(self.Parent)
   552             self.PrioritySize = self.Parent.GetTextExtent(str(self.Priority))
   556             self.PrioritySize = dc.GetTextExtent(str(self.Priority))
       
   557         else:
   553         else:
   558             self.PrioritySize = None
   554             self.PrioritySize = None
   559 
   555 
   560     # Delete this transition by calling the appropriate method
   556     # Delete this transition by calling the appropriate method
   561     def Delete(self):
   557     def Delete(self):
   568         if self.Type == "connection":
   564         if self.Type == "connection":
   569             self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   565             self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   570     
   566     
   571     # Refresh the transition bounding box
   567     # Refresh the transition bounding box
   572     def RefreshBoundingBox(self):
   568     def RefreshBoundingBox(self):
   573         dc = wx.ClientDC(self.Parent)
       
   574         bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
   569         bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
   575         if self.Priority != 0:
   570         if self.Priority != 0:
   576             bbx_y = self.Pos.y - self.PrioritySize[1] - 2
   571             bbx_y = self.Pos.y - self.PrioritySize[1] - 2
   577             bbx_width = max(self.Size[0], self.PrioritySize[0])
   572             bbx_width = max(self.Size[0], self.PrioritySize[0])
   578             bbx_height = self.Size[1] + self.PrioritySize[1] + 2
   573             bbx_height = self.Size[1] + self.PrioritySize[1] + 2
   767     def OnRightUp(self, event, dc, scaling):
   762     def OnRightUp(self, event, dc, scaling):
   768         # Popup the menu with special items for a step
   763         # Popup the menu with special items for a step
   769         self.Parent.PopupDefaultMenu()
   764         self.Parent.PopupDefaultMenu()
   770     
   765     
   771     # Refreshes the transition state according to move defined and handle selected
   766     # Refreshes the transition state according to move defined and handle selected
   772     def ProcessDragging(self, movex, movey, scaling):
   767     def ProcessDragging(self, movex, movey, centered, scaling):
   773         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   768         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   774             movex = max(-self.BoundingBox.x, movex)
   769             movex = max(-self.BoundingBox.x, movex)
   775             if scaling is not None:
   770             if scaling is not None:
   776                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
   771                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
   777             self.Move(movex, 0)
   772             self.Move(movex, 0)
   778             self.RefreshInputPosition()
   773             self.RefreshInputPosition()
   779             self.RefreshOutputPosition()
   774             self.RefreshOutputPosition()
   780             return movex, 0
   775             return movex, 0
   781         else:
   776         else:
   782             return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
   777             return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
   783     
   778     
   784     # Refresh input element model
   779     # Refresh input element model
   785     def RefreshInputModel(self):
   780     def RefreshInputModel(self):
   786         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   781         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   787             input = self.GetPreviousConnector()
   782             input = self.GetPreviousConnector()
  1194             else:
  1189             else:
  1195                 # Popup the divergence menu without delete branch
  1190                 # Popup the divergence menu without delete branch
  1196                 self.Parent.PopupDivergenceMenu(False)
  1191                 self.Parent.PopupDivergenceMenu(False)
  1197     
  1192     
  1198     # Refreshes the divergence state according to move defined and handle selected
  1193     # Refreshes the divergence state according to move defined and handle selected
  1199     def ProcessDragging(self, movex, movey, scaling):
  1194     def ProcessDragging(self, movex, movey, centered, scaling):
  1200         handle_type, handle = self.Handle
  1195         handle_type, handle = self.Handle
  1201         # A connector has been handled
  1196         # A connector has been handled
  1202         if handle_type == HANDLE_CONNECTOR:
  1197         if handle_type == HANDLE_CONNECTOR:
  1203             movex = max(-self.BoundingBox.x, movex)
  1198             movex = max(-self.BoundingBox.x, movex)
  1204             if scaling is not None:
  1199             if scaling is not None:
  1206             self.MoveConnector(handle, movex)
  1201             self.MoveConnector(handle, movex)
  1207             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1202             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1208                 self.RefreshConnectedPosition(handle)
  1203                 self.RefreshConnectedPosition(handle)
  1209             return movex, 0
  1204             return movex, 0
  1210         elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1205         elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1211             return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
  1206             return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
  1212         return 0, 0
  1207         return 0, 0
  1213     
  1208     
  1214     # Refresh output element model
  1209     # Refresh output element model
  1215     def RefreshOutputModel(self, move=False):
  1210     def RefreshOutputModel(self, move=False):
  1216         if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1211         if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1327     def Clean(self):
  1322     def Clean(self):
  1328         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1323         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1329     
  1324     
  1330     # Refresh the jump bounding box
  1325     # Refresh the jump bounding box
  1331     def RefreshBoundingBox(self):
  1326     def RefreshBoundingBox(self):
  1332         dc = wx.ClientDC(self.Parent)
  1327         text_width, text_height = self.Parent.GetTextExtent(self.Target)
  1333         text_width, text_height = dc.GetTextExtent(self.Target)
       
  1334         # Calculate the bounding box size
  1328         # Calculate the bounding box size
  1335         bbx_width = self.Size[0] + 2 + text_width
  1329         bbx_width = self.Size[0] + 2 + text_width
  1336         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1330         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1337                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1331                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1338     
  1332     
  1411     def OnRightUp(self, event, dc, scaling):
  1405     def OnRightUp(self, event, dc, scaling):
  1412         # Popup the default menu
  1406         # Popup the default menu
  1413         self.Parent.PopupDefaultMenu()
  1407         self.Parent.PopupDefaultMenu()
  1414     
  1408     
  1415     # Refreshes the jump state according to move defined and handle selected
  1409     # Refreshes the jump state according to move defined and handle selected
  1416     def ProcessDragging(self, movex, movey, scaling):
  1410     def ProcessDragging(self, movex, movey, centered, scaling):
  1417         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1411         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1418             movex = max(-self.BoundingBox.x, movex)
  1412             movex = max(-self.BoundingBox.x, movex)
  1419             if scaling is not None:
  1413             if scaling is not None:
  1420                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
  1414                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
  1421             self.Move(movex, 0)
  1415             self.Move(movex, 0)
  1422             self.RefreshInputPosition()
  1416             self.RefreshInputPosition()
  1423             return movex, 0
  1417             return movex, 0
  1424         else:
  1418         else:
  1425             return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
  1419             return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
  1426     
  1420     
  1427     # Refresh input element model
  1421     # Refresh input element model
  1428     def RefreshInputModel(self):
  1422     def RefreshInputModel(self):
  1429         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1423         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1430             input = self.GetPreviousConnector()
  1424             input = self.GetPreviousConnector()
  1573         self.Input.SetPosition(wx.Point(0, vertical_pos))
  1567         self.Input.SetPosition(wx.Point(0, vertical_pos))
  1574         self.RefreshConnected()
  1568         self.RefreshConnected()
  1575     
  1569     
  1576     # Changes the action block actions
  1570     # Changes the action block actions
  1577     def SetActions(self, actions):
  1571     def SetActions(self, actions):
  1578         dc = wx.ClientDC(self.Parent)
       
  1579         self.Actions = actions
  1572         self.Actions = actions
  1580         self.ColSize = [0, 0, 0]
  1573         self.ColSize = [0, 0, 0]
  1581         min_height = 0
  1574         min_height = 0
  1582         for action in self.Actions:
  1575         for action in self.Actions:
  1583             width, height = dc.GetTextExtent(action["qualifier"])
  1576             width, height = self.Parent.GetTextExtent(action["qualifier"])
  1584             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1577             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1585             row_height = height
  1578             row_height = height
  1586             if "duration" in action:
  1579             if "duration" in action:
  1587                 width, height = dc.GetTextExtent(action["duration"])
  1580                 width, height = self.Parent.GetTextExtent(action["duration"])
  1588                 row_height = max(row_height, height)
  1581                 row_height = max(row_height, height)
  1589                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1582                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1590             width, height = dc.GetTextExtent(action["value"])
  1583             width, height = self.Parent.GetTextExtent(action["value"])
  1591             row_height = max(row_height, height)
  1584             row_height = max(row_height, height)
  1592             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1585             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1593             if "indicator" in action and action["indicator"] != "":
  1586             if "indicator" in action and action["indicator"] != "":
  1594                 width, height = dc.GetTextExtent(action["indicator"])
  1587                 width, height = self.Parent.GetTextExtent(action["indicator"])
  1595                 row_height = max(row_height, height)
  1588                 row_height = max(row_height, height)
  1596                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1589                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1597             min_height += row_height + 5
  1590             min_height += row_height + 5
  1598         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1591         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1599             self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1]))
  1592             self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1]))
  1630     def OnRightUp(self, event, dc, scaling):
  1623     def OnRightUp(self, event, dc, scaling):
  1631         # Popup the default menu
  1624         # Popup the default menu
  1632         self.Parent.PopupDefaultMenu()
  1625         self.Parent.PopupDefaultMenu()
  1633     
  1626     
  1634     # Refreshes the action block state according to move defined and handle selected
  1627     # Refreshes the action block state according to move defined and handle selected
  1635     def ProcessDragging(self, movex, movey, scaling):
  1628     def ProcessDragging(self, movex, movey, centered, scaling):
  1636         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1629         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1637             handle_type, handle = self.Handle
  1630             handle_type, handle = self.Handle
  1638             if handle_type == HANDLE_MOVE:
  1631             if handle_type == HANDLE_MOVE:
  1639                 movex = max(-self.BoundingBox.x, movex)
  1632                 movex = max(-self.BoundingBox.x, movex)
  1640                 if scaling is not None:
  1633                 if scaling is not None:
  1645                     if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
  1638                     if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
  1646                         self.Move(movex, 0)
  1639                         self.Move(movex, 0)
  1647                         return movex, 0
  1640                         return movex, 0
  1648                 return 0, 0
  1641                 return 0, 0
  1649             else:
  1642             else:
  1650                 return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
  1643                 return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
  1651         else:
  1644         else:
  1652             return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
  1645             return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling)
  1653 
  1646 
  1654     
  1647     
  1655    # Refreshes the action block model
  1648    # Refreshes the action block model
  1656     def RefreshModel(self, move=True):
  1649     def RefreshModel(self, move=True):
  1657         self.Parent.RefreshActionBlockModel(self)
  1650         self.Parent.RefreshActionBlockModel(self)