graphics/SFC_Objects.py
changeset 108 9aa1fdfb7cb2
parent 80 c798a68c5560
child 110 29b6b70e1721
equal deleted inserted replaced
107:255eada20688 108:9aa1fdfb7cb2
    50         self.Initial = initial
    50         self.Initial = initial
    51         self.Id = id
    51         self.Id = id
    52         self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
    52         self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
    53         # Create an input and output connector
    53         # Create an input and output connector
    54         if not self.Initial:
    54         if not self.Initial:
    55             self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
    55             self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
    56         else:
    56         else:
    57             self.Input = None
    57             self.Input = None
    58         self.Output = None
    58         self.Output = None
    59         self.Action = None
    59         self.Action = None
    60     
    60     
    78             self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    78             self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    79     
    79     
    80     # Add output connector to step
    80     # Add output connector to step
    81     def AddInput(self):
    81     def AddInput(self):
    82         if not self.Input:
    82         if not self.Input:
    83             self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
    83             self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
    84             self.RefreshBoundingBox()
    84             self.RefreshBoundingBox()
    85     
    85     
    86     # Remove output connector from step
    86     # Remove output connector from step
    87     def RemoveInput(self):
    87     def RemoveInput(self):
    88         if self.Input:
    88         if self.Input:
    91             self.RefreshBoundingBox()
    91             self.RefreshBoundingBox()
    92     
    92     
    93     # Add output connector to step
    93     # Add output connector to step
    94     def AddOutput(self):
    94     def AddOutput(self):
    95         if not self.Output:
    95         if not self.Output:
    96             self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
    96             self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
    97             self.RefreshBoundingBox()
    97             self.RefreshBoundingBox()
    98     
    98     
    99     # Remove output connector from step
    99     # Remove output connector from step
   100     def RemoveOutput(self):
   100     def RemoveOutput(self):
   101         if self.Output:
   101         if self.Output:
   104             self.RefreshBoundingBox()
   104             self.RefreshBoundingBox()
   105     
   105     
   106     # Add action connector to step
   106     # Add action connector to step
   107     def AddAction(self):
   107     def AddAction(self):
   108         if not self.Action:
   108         if not self.Action:
   109             self.Action = Connector(self, "", "ANY", wx.Point(self.Size[0], self.Size[1] / 2), EAST)
   109             self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST)
   110             self.RefreshBoundingBox()
   110             self.RefreshBoundingBox()
   111     
   111     
   112     # Remove action connector from step
   112     # Remove action connector from step
   113     def RemoveAction(self):
   113     def RemoveAction(self):
   114         if self.Action:
   114         if self.Action:
   197         if self.Input and self.Input.TestPoint(pt, exclude):
   197         if self.Input and self.Input.TestPoint(pt, exclude):
   198             return self.Input
   198             return self.Input
   199         # Test output connector
   199         # Test output connector
   200         if self.Output and self.Output.TestPoint(pt, exclude):
   200         if self.Output and self.Output.TestPoint(pt, exclude):
   201             return self.Output
   201             return self.Output
       
   202         # Test action connector
       
   203         if self.Action and self.Action.TestPoint(pt, exclude):
       
   204             return self.Action
   202         return None
   205         return None
   203 
   206 
   204     # Changes the step name
   207     # Changes the step name
   205     def SetName(self, name):
   208     def SetName(self, name):
   206         self.Name = name
   209         self.Name = name
   260     def UpdateSize(self, width, height):
   263     def UpdateSize(self, width, height):
   261         diffx = self.Size.GetWidth() / 2 - width / 2
   264         diffx = self.Size.GetWidth() / 2 - width / 2
   262         diffy = height - self.Size.GetHeight()
   265         diffy = height - self.Size.GetHeight()
   263         self.Move(diffx, 0)
   266         self.Move(diffx, 0)
   264         Graphic_Element.SetSize(self, width, height)
   267         Graphic_Element.SetSize(self, width, height)
   265         self.RefreshOutputPosition((0, diffy))
   268         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   269             self.RefreshConnected()
       
   270         else:
       
   271             self.RefreshOutputPosition((0, diffy))
   266     
   272     
   267     # Align input element with this step
   273     # Align input element with this step
   268     def RefreshInputPosition(self):
   274     def RefreshInputPosition(self):
   269         if self.Input:
   275         if self.Input:
   270             current_pos = self.Input.GetPosition(False)
   276             current_pos = self.Input.GetPosition(False)
   441         self.Type = None
   447         self.Type = None
   442         self.Id = id
   448         self.Id = id
   443         self.Priority = 0
   449         self.Priority = 0
   444         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   450         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   445         # Create an input and output connector
   451         # Create an input and output connector
   446         self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
   452         self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
   447         self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
   453         self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
   448         self.SetType(type, condition)
   454         self.SetType(type, condition)
   449         self.SetPriority(priority)
   455         self.SetPriority(priority)
   450     
   456     
   451     # Destructor
   457     # Destructor
   452     def __del__(self):
   458     def __del__(self):
   774             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1)
   780             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1)
   775         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   781         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   776             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3)
   782             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3)
   777         # Create an input and output connector
   783         # Create an input and output connector
   778         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   784         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   779             self.Inputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)]
   785             self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)]
   780             self.Outputs = []
   786             self.Outputs = []
   781             for i in xrange(number):
   787             for i in xrange(number):
   782                 self.Outputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
   788                 self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
   783         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   789         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   784             self.Inputs = []
   790             self.Inputs = []
   785             for i in xrange(number):
   791             for i in xrange(number):
   786                 self.Inputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
   792                 self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
   787             self.Outputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)]
   793             self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)]
   788     
   794     
   789     # Destructor
   795     # Destructor
   790     def __del__(self):
   796     def __del__(self):
   791         self.Inputs = []
   797         self.Inputs = []
   792         self.Outputs = []
   798         self.Outputs = []
   816         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   822         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   817             maxx = 0
   823             maxx = 0
   818             for output in self.Outputs:
   824             for output in self.Outputs:
   819                 pos = output.GetRelPosition()
   825                 pos = output.GetRelPosition()
   820                 maxx = max(maxx, pos.x)
   826                 maxx = max(maxx, pos.x)
   821             connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
   827             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
   822             self.Outputs.append(connector)
   828             self.Outputs.append(connector)
   823             self.MoveConnector(connector, 0)
   829             self.MoveConnector(connector, 0)
   824         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   830         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   825             maxx = 0
   831             maxx = 0
   826             for input in self.Inputs:
   832             for input in self.Inputs:
   827                 pos = input.GetRelPosition()
   833                 pos = input.GetRelPosition()
   828                 maxx = max(maxx, pos.x)
   834                 maxx = max(maxx, pos.x)
   829             connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
   835             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
   830             self.Inputs.append(connector)
   836             self.Inputs.append(connector)
   831             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
   837             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
   832     
   838     
   833     # Remove a branch from the divergence
   839     # Remove a branch from the divergence
   834     def RemoveBranch(self, connector):
   840     def RemoveBranch(self, connector):
  1147         Graphic_Element.__init__(self, parent)
  1153         Graphic_Element.__init__(self, parent)
  1148         self.Target = target
  1154         self.Target = target
  1149         self.Id = id
  1155         self.Id = id
  1150         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1156         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1151         # Create an input and output connector
  1157         # Create an input and output connector
  1152         self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
  1158         self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
  1153         
  1159         
  1154     # Destructor
  1160     # Destructor
  1155     def __del__(self):
  1161     def __del__(self):
  1156         self.Input = None
  1162         self.Input = None
  1157     
  1163     
  1316     # Create a new action block
  1322     # Create a new action block
  1317     def __init__(self, parent, actions = [], id = None):
  1323     def __init__(self, parent, actions = [], id = None):
  1318         Graphic_Element.__init__(self, parent)
  1324         Graphic_Element.__init__(self, parent)
  1319         self.Id = id
  1325         self.Id = id
  1320         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1326         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
       
  1327         self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1321         # Create an input and output connector
  1328         # Create an input and output connector
  1322         self.Input = Connector(self, "", "ANY", wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
  1329         self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
  1323         self.SetActions(actions)
  1330         self.SetActions(actions)
  1324     
  1331     
  1325     # Destructor
  1332     # Destructor
  1326     def __del__(self):
  1333     def __del__(self):
  1327         self.Input = None
  1334         self.Input = None
  1329     # Returns the number of action lines
  1336     # Returns the number of action lines
  1330     def GetLineNumber(self):
  1337     def GetLineNumber(self):
  1331         return len(self.Actions)
  1338         return len(self.Actions)
  1332     
  1339     
  1333     def GetLineSize(self):
  1340     def GetLineSize(self):
  1334         if len(self.Actions) > 1:
  1341         if len(self.Actions) > 0:
  1335             return self.Size[1] / len(self.Actions)
  1342             return self.Size[1] / len(self.Actions)
  1336         else:
  1343         else:
  1337             return SFC_ACTION_MIN_SIZE[1]
  1344             return SFC_ACTION_MIN_SIZE[1]
  1338     
  1345     
  1339     # Forbids to resize the action block
  1346     # Forbids to resize the action block
  1374     # Changes the action block actions
  1381     # Changes the action block actions
  1375     def SetActions(self, actions):
  1382     def SetActions(self, actions):
  1376         dc = wx.ClientDC(self.Parent)
  1383         dc = wx.ClientDC(self.Parent)
  1377         self.Actions = actions
  1384         self.Actions = actions
  1378         self.ColSize = [0, 0, 0]
  1385         self.ColSize = [0, 0, 0]
       
  1386         min_height = 0
  1379         for action in self.Actions:
  1387         for action in self.Actions:
  1380             width, height = dc.GetTextExtent(action["qualifier"])
  1388             width, height = dc.GetTextExtent(action["qualifier"])
  1381             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1389             self.ColSize[0] = max(self.ColSize[0], width + 10)
       
  1390             row_height = height
  1382             if "duration" in action:
  1391             if "duration" in action:
  1383                 width, height = dc.GetTextExtent(action["duration"])
  1392                 width, height = dc.GetTextExtent(action["duration"])
       
  1393                 row_height = max(row_height, height)
  1384                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1394                 self.ColSize[0] = max(self.ColSize[0], width + 10)
  1385             width, height = dc.GetTextExtent(action["value"])
  1395             width, height = dc.GetTextExtent(action["value"])
       
  1396             row_height = max(row_height, height)
  1386             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1397             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1387             if "indicator" in action and action["indicator"] != "":
  1398             if "indicator" in action and action["indicator"] != "":
  1388                 width, height = dc.GetTextExtent(action["indicator"])
  1399                 width, height = dc.GetTextExtent(action["indicator"])
       
  1400                 row_height = max(row_height, height)
  1389                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1401                 self.ColSize[2] = max(self.ColSize[2], width + 10)
       
  1402             min_height += row_height + 5
  1390         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1403         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1391             line_size = self.GetLineSize()
  1404             self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1]))
  1392             self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size)
  1405             self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
       
  1406                 SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height)
       
  1407             self.RefreshBoundingBox()
  1393         else:
  1408         else:
  1394             self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1409             self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1395                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1410                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1396         self.RefreshBoundingBox()
  1411             self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1397         if self.Input:
  1412                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
  1398             wires = self.Input.GetWires()
  1413             self.RefreshBoundingBox()
  1399             if len(wires) == 1:
  1414             if self.Input:
  1400                 input_block = wires[0][0].EndConnected.GetParentBlock()
  1415                 wires = self.Input.GetWires()
  1401                 input_block.RefreshOutputPosition()
  1416                 if len(wires) == 1:
  1402                 input_block.RefreshOutputModel(True)
  1417                     input_block = wires[0][0].EndConnected.GetParentBlock()
       
  1418                     input_block.RefreshOutputPosition()
       
  1419                     input_block.RefreshOutputModel(True)
  1403     
  1420     
  1404     # Returns the action block actions
  1421     # Returns the action block actions
  1405     def GetActions(self):
  1422     def GetActions(self):
  1406         return self.Actions
  1423         return self.Actions
  1407     
  1424     
  1408     # Returns the action block minimum size
  1425     # Returns the action block minimum size
  1409     def GetMinSize(self):
  1426     def GetMinSize(self):
  1410         return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1427         return self.MinSize
  1411             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
       
  1412     
  1428     
  1413     # Method called when a LeftDClick event have been generated
  1429     # Method called when a LeftDClick event have been generated
  1414     def OnLeftDClick(self, event, dc, scaling):
  1430     def OnLeftDClick(self, event, dc, scaling):
  1415         # Edit the action block properties
  1431         # Edit the action block properties
  1416         self.Parent.EditActionBlockContent(self)
  1432         self.Parent.EditActionBlockContent(self)