graphics/SFC_Objects.py
changeset 27 dae55dd9ee14
parent 5 f8652b073e84
child 42 4a8400732001
equal deleted inserted replaced
26:36d378bd852e 27:dae55dd9ee14
   146             self.Output.MoveConnected(exclude)
   146             self.Output.MoveConnected(exclude)
   147         if self.Action:
   147         if self.Action:
   148             self.Action.MoveConnected(exclude)
   148             self.Action.MoveConnected(exclude)
   149     
   149     
   150     # Returns the step connector that starts with the point given if it exists 
   150     # Returns the step connector that starts with the point given if it exists 
   151     def GetConnector(self, position):
   151     def GetConnector(self, position, name = None):
       
   152         # if a name is given
       
   153         if name:
       
   154             # Test input, output and action connector if they exists
       
   155             if self.Input and name == self.Input.GetName():
       
   156                 return self.Input
       
   157             if self.Output and name == self.Output.GetName():
       
   158                 return self.Output
       
   159             if self.Action and name == self.Action.GetName():
       
   160                 return self.Action
   152         # Test input connector if it exists
   161         # Test input connector if it exists
   153         if self.Input:
   162         if self.Input:
   154             input_pos = self.Input.GetRelPosition()
   163             input_pos = self.Input.GetRelPosition()
   155             if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   164             if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   156                 return self.Input
   165                 return self.Input
   310             action_block.Move(move[0], move[1], self.Parent.Wires)
   319             action_block.Move(move[0], move[1], self.Parent.Wires)
   311             wires[0][0].Move(move[0], move[1], True)
   320             wires[0][0].Move(move[0], move[1], True)
   312     
   321     
   313     # Resize the divergence from position and size given
   322     # Resize the divergence from position and size given
   314     def Resize(self, x, y, width, height):
   323     def Resize(self, x, y, width, height):
   315         self.UpdateSize(width, height)
   324         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
       
   325             self.UpdateSize(width, height)
       
   326         else:
       
   327             Graphic_Element.Resize(self, x, y, width, height)
   316     
   328     
   317     # Method called when a LeftDClick event have been generated
   329     # Method called when a LeftDClick event have been generated
   318     def OnLeftDClick(self, event, scaling):
   330     def OnLeftDClick(self, event, scaling):
   319         # Edit the step properties
   331         # Edit the step properties
   320         self.Parent.EditStepContent(self)
   332         self.Parent.EditStepContent(self)
   321     
   333     
   322     # Method called when a RightUp event have been generated
   334     # Method called when a RightUp event have been generated
   323     def OnRightUp(self, event, scaling):
   335     def OnRightUp(self, event, dc, scaling):
   324         # Popup the menu with special items for a step
   336         # Popup the menu with special items for a step
   325         self.Parent.PopupDefaultMenu()
   337         self.Parent.PopupDefaultMenu()
   326     
   338     
   327     # Refreshes the step state according to move defined and handle selected
   339     # Refreshes the step state according to move defined and handle selected
   328     def ProcessDragging(self, movex, movey):
   340     def ProcessDragging(self, movex, movey):
   329         handle_type, handle = self.Handle
   341         handle_type, handle = self.Handle
   330         if handle_type == HANDLE_MOVE:
   342         if handle_type == HANDLE_MOVE:
   331             action_block = None
   343             action_block = None
   332             if self.Initial:
   344             if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   345                 self.Move(movex, movey)
       
   346                 self.RefreshConnected()
       
   347             elif self.Initial:
   333                 self.MoveActionBlock((movex, movey))
   348                 self.MoveActionBlock((movex, movey))
   334                 self.Move(movex, movey, self.Parent.Wires)
   349                 self.Move(movex, movey, self.Parent.Wires)
   335                 self.RefreshOutputPosition((movex, movey))
   350                 self.RefreshOutputPosition((movex, movey))
   336             else:
   351             else:
   337                 self.MoveActionBlock((movex, 0))
   352                 self.MoveActionBlock((movex, 0))
   369             if action:
   384             if action:
   370                 action_block = action.GetParentBlock()
   385                 action_block = action.GetParentBlock()
   371                 action_block.RefreshModel(False)
   386                 action_block.RefreshModel(False)
   372         # If step has moved, refresh the model of wires connected to output
   387         # If step has moved, refresh the model of wires connected to output
   373         if move:
   388         if move:
   374             self.RefreshInputModel()
   389             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   375             self.RefreshOutputModel(self.Initial)
   390                 self.RefreshInputModel()
       
   391                 self.RefreshOutputModel(self.Initial)
       
   392             elif self.Output:
       
   393                 self.Output.RefreshWires()
   376     
   394     
   377     # Draws step
   395     # Draws step
   378     def Draw(self, dc):
   396     def Draw(self, dc):
   379         dc.SetPen(wxBLACK_PEN)
   397         dc.SetPen(wxBLACK_PEN)
   380         dc.SetBrush(wxWHITE_BRUSH)
   398         dc.SetBrush(wxWHITE_BRUSH)
   421         self.Input = None
   439         self.Input = None
   422         self.Output = None
   440         self.Output = None
   423     
   441     
   424     # Forbids to change the transition size
   442     # Forbids to change the transition size
   425     def SetSize(self, width, height):
   443     def SetSize(self, width, height):
   426         pass
   444         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   445             Graphic_Element.SetSize(self, width, height)
   427     
   446     
   428     # Forbids to resize the transition
   447     # Forbids to resize the transition
   429     def Resize(self, x, y, width, height):
   448     def Resize(self, x, y, width, height):
   430         pass
   449         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   450             Graphic_Element.Resize(self, x, y, width, height)
   431     
   451     
   432     # Delete this transition by calling the appropriate method
   452     # Delete this transition by calling the appropriate method
   433     def Delete(self):
   453     def Delete(self):
   434         self.Parent.DeleteTransition(self)
   454         self.Parent.DeleteTransition(self)
   435     
   455     
   477     def RefreshConnected(self, exclude = []):
   497     def RefreshConnected(self, exclude = []):
   478         self.Input.MoveConnected(exclude)
   498         self.Input.MoveConnected(exclude)
   479         self.Output.MoveConnected(exclude)
   499         self.Output.MoveConnected(exclude)
   480     
   500     
   481     # Returns the transition connector that starts with the point given if it exists 
   501     # Returns the transition connector that starts with the point given if it exists 
   482     def GetConnector(self, position):
   502     def GetConnector(self, position, name = None):
       
   503         # if a name is given
       
   504         if name:
       
   505             # Test input and output connector
       
   506             if name == self.Input.GetName():
       
   507                 return self.Input
       
   508             if name == self.Output.GetName():
       
   509                 return self.Output
   483         # Test input connector
   510         # Test input connector
   484         input_pos = self.Input.GetRelPosition()
   511         input_pos = self.Input.GetRelPosition()
   485         if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   512         if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   486             return self.Input
   513             return self.Input
   487         # Test output connector
   514         # Test output connector
   566         else:
   593         else:
   567             if isinstance(output_block, SFC_Step):
   594             if isinstance(output_block, SFC_Step):
   568                 output_block.MoveActionBlock((diffx, 0))
   595                 output_block.MoveActionBlock((diffx, 0))
   569             output_block.Move(diffx, 0)
   596             output_block.Move(diffx, 0)
   570             output_block.RefreshOutputPosition()
   597             output_block.RefreshOutputPosition()
   571     
   598 
   572     # Method called when a LeftDClick event have been generated
   599     # Method called when a LeftDClick event have been generated
   573     def OnLeftDClick(self, event, scaling):
   600     def OnLeftDClick(self, event, dc, scaling):
   574         # Edit the transition properties
   601         # Edit the transition properties
   575         self.Parent.EditTransitionContent(self)
   602         self.Parent.EditTransitionContent(self)
   576     
   603     
   577     # Method called when a RightUp event have been generated
   604     # Method called when a RightUp event have been generated
   578     def OnRightUp(self, event, scaling):
   605     def OnRightUp(self, event, dc, scaling):
   579         # Popup the menu with special items for a step
   606         # Popup the menu with special items for a step
   580         self.Parent.PopupDefaultMenu()
   607         self.Parent.PopupDefaultMenu()
   581     
   608     
   582     # Refreshes the transition state according to move defined and handle selected
   609     # Refreshes the transition state according to move defined and handle selected
   583     def ProcessDragging(self, movex, movey):
   610     def ProcessDragging(self, movex, movey):
   584         self.Move(movex, 0)
   611         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   585         self.RefreshInputPosition()
   612             self.Move(movex, 0)
   586         self.RefreshOutputPosition()
   613             self.RefreshInputPosition()
       
   614             self.RefreshOutputPosition()
       
   615         else:
       
   616             Graphic_Element.ProcessDragging(self, movex, movey)
   587     
   617     
   588     # Refresh input element model
   618     # Refresh input element model
   589     def RefreshInputModel(self):
   619     def RefreshInputModel(self):
   590         input = self.GetPreviousConnector()
   620         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   591         if input:
   621             input = self.GetPreviousConnector()
   592             input_block = input.GetParentBlock()
   622             if input:
   593             input_block.RefreshModel(False)
   623                 input_block = input.GetParentBlock()
   594             if not isinstance(input_block, SFC_Divergence):
   624                 input_block.RefreshModel(False)
   595                 input_block.RefreshInputModel()
   625                 if not isinstance(input_block, SFC_Divergence):
       
   626                     input_block.RefreshInputModel()
   596     
   627     
   597     # Refresh output element model
   628     # Refresh output element model
   598     def RefreshOutputModel(self, move=False):
   629     def RefreshOutputModel(self, move=False):
   599         output = self.GetNextConnector()
   630         output = self.GetNextConnector()
   600         if output:
   631         if output:
   606     # Refreshes the transition model
   637     # Refreshes the transition model
   607     def RefreshModel(self, move=True):
   638     def RefreshModel(self, move=True):
   608         self.Parent.RefreshTransitionModel(self)
   639         self.Parent.RefreshTransitionModel(self)
   609         # If transition has moved, refresh the model of wires connected to output
   640         # If transition has moved, refresh the model of wires connected to output
   610         if move:
   641         if move:
   611             self.RefreshInputModel()
   642             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   612             self.RefreshOutputModel()
   643                 self.RefreshInputModel()
       
   644                 self.RefreshOutputModel()
       
   645             else:
       
   646                 self.Output.RefreshWires()
   613     
   647     
   614     # Draws transition
   648     # Draws transition
   615     def Draw(self, dc):
   649     def Draw(self, dc):
   616         dc.SetPen(wxBLACK_PEN)
   650         dc.SetPen(wxBLACK_PEN)
   617         dc.SetBrush(wxBLACK_BRUSH)
   651         dc.SetBrush(wxBLACK_BRUSH)
   670         self.Inputs = []
   704         self.Inputs = []
   671         self.Outputs = []
   705         self.Outputs = []
   672     
   706     
   673     # Forbids to resize the divergence
   707     # Forbids to resize the divergence
   674     def Resize(self, x, y, width, height):
   708     def Resize(self, x, y, width, height):
   675         pass
   709         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   710             Graphic_Element.Resize(self, x, y, width, height)
   676     
   711     
   677     # Delete this divergence by calling the appropriate method
   712     # Delete this divergence by calling the appropriate method
   678     def Delete(self):
   713     def Delete(self):
   679         self.Parent.DeleteDivergence(self)
   714         self.Parent.DeleteDivergence(self)
   680     
   715     
   772         self.Size[0] = maxx - minx
   807         self.Size[0] = maxx - minx
   773         connector.MoveConnected()
   808         connector.MoveConnected()
   774         self.RefreshBoundingBox()
   809         self.RefreshBoundingBox()
   775     
   810     
   776     # Returns the divergence connector that starts with the point given if it exists 
   811     # Returns the divergence connector that starts with the point given if it exists 
   777     def GetConnector(self, position):
   812     def GetConnector(self, position, name = None):
       
   813         # if a name is given
       
   814         if name:
       
   815             # Test each input and output connector
       
   816             for input in self.Inputs:
       
   817                 if name == input.GetName():
       
   818                     return input
       
   819             for output in self.Outputs:
       
   820                 if name == output.GetName():
       
   821                     return output
   778         # Test input connector
   822         # Test input connector
   779         for input in self.Inputs:
   823         for input in self.Inputs:
   780             input_pos = input.GetPosition(False)
   824             input_pos = input.GetPosition(False)
   781             if position.x == input_pos.x and position.y == input_pos.y:
   825             if position.x == input_pos.x and position.y == input_pos.y:
   782                 return input
   826                 return input
   806     # Changes the divergence size
   850     # Changes the divergence size
   807     def SetSize(self, width, height):
   851     def SetSize(self, width, height):
   808         for i, input in enumerate(self.Inputs):
   852         for i, input in enumerate(self.Inputs):
   809             position = input.GetRelPosition()
   853             position = input.GetRelPosition()
   810             if self.RealConnectors:
   854             if self.RealConnectors:
   811                 input.SetPosition(wxPoint(int(round(self.RealConnectors["Inputs"][i] * width)), position.y))
   855                 input.SetPosition(wxPoint(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
   812             else:
   856             else:
   813                 input.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), position.y))
   857                 input.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0))
   814             input.MoveConnected()
   858             input.MoveConnected()
   815         for i, output in enumerate(self.Outputs):
   859         for i, output in enumerate(self.Outputs):
   816             position = output.GetRelPosition()
   860             position = output.GetRelPosition()
   817             if self.RealConnectors:
   861             if self.RealConnectors:
   818                 output.SetPosition(wxPoint(int(round(self.RealConnectors["Outputs"][i] * width)), position.y))
   862                 output.SetPosition(wxPoint(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1]))
   819             else:
   863             else:
   820                 output.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), position.y))
   864                 output.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1]))
   821             output.MoveConnected()
   865             output.MoveConnected()
   822         self.Size = wxSize(width, self.Size[1])
   866         self.Size = wxSize(width, height)
   823         self.RefreshBoundingBox()
   867         self.RefreshBoundingBox()
   824     
   868     
   825     # Returns the divergence minimum size
   869     # Returns the divergence minimum size
   826     def GetMinSize(self):
   870     def GetMinSize(self):
   827         return 0, self.Size[1]
   871         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
       
   872             return 0, 1
       
   873         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
       
   874             return 0, 3
       
   875         return 0, 0
   828     
   876     
   829     # Refresh the position of the block connected to connector
   877     # Refresh the position of the block connected to connector
   830     def RefreshConnectedPosition(self, connector):
   878     def RefreshConnectedPosition(self, connector):
   831         wires = connector.GetWires()
   879         wires = connector.GetWires()
   832         if len(wires) != 1:
   880         if len(wires) != 1:
   845             next_block.Move(diffx, 0)
   893             next_block.Move(diffx, 0)
   846             if connector in self.Inputs:
   894             if connector in self.Inputs:
   847                 next_block.RefreshInputPosition()
   895                 next_block.RefreshInputPosition()
   848             else:
   896             else:
   849                 next_block.RefreshOutputPosition()
   897                 next_block.RefreshOutputPosition()
   850     
   898 
   851     # Refresh the position of this divergence
   899     # Refresh the position of this divergence
   852     def RefreshPosition(self):
   900     def RefreshPosition(self):
   853         y = 0
   901         y = 0
   854         for input in self.Inputs:
   902         for input in self.Inputs:
   855             wires = input.GetWires()
   903             wires = input.GetWires()
   883                 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0:
   931                 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0:
   884                     output_block.Move(move[0], move[1], self.Parent.Wires)
   932                     output_block.Move(move[0], move[1], self.Parent.Wires)
   885                     output_block.RefreshOutputPosition(move)
   933                     output_block.RefreshOutputPosition(move)
   886     
   934     
   887     # Method called when a LeftDown event have been generated
   935     # Method called when a LeftDown event have been generated
   888     def OnLeftDown(self, event, scaling):
   936     def OnLeftDown(self, event, dc, scaling):
   889         pos = GetScaledEventPosition(event, scaling)
   937         pos = GetScaledEventPosition(event, dc, scaling)
   890         # Test if a connector have been handled
   938         # Test if a connector have been handled
   891         connector = self.TestConnector(pos, False)
   939         connector = self.TestConnector(pos, False)
   892         if connector:
   940         if connector:
   893             self.Handle = (HANDLE_CONNECTOR, connector)
   941             self.Handle = (HANDLE_CONNECTOR, connector)
   894             self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND))
   942             self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND))
   895             self.Selected = False
   943             self.Selected = False
   896             # Initializes the last position
   944             # Initializes the last position
   897             self.oldPos = GetScaledEventPosition(event, scaling)
   945             self.oldPos = GetScaledEventPosition(event, dc, scaling)
   898         else:
   946         else:
   899             self.RealConnectors = {"Inputs":[],"Outputs":[]}
   947             self.RealConnectors = {"Inputs":[],"Outputs":[]}
   900             for input in self.Inputs:
   948             for input in self.Inputs:
   901                 position = input.GetRelPosition()
   949                 position = input.GetRelPosition()
   902                 self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
   950                 self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
   903             for output in self.Outputs:
   951             for output in self.Outputs:
   904                 position = output.GetRelPosition()
   952                 position = output.GetRelPosition()
   905                 self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
   953                 self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
   906             Graphic_Element.OnLeftDown(self, event, scaling)
   954             Graphic_Element.OnLeftDown(self, event, dc, scaling)
   907     
   955     
   908     # Method called when a LeftUp event have been generated
   956     # Method called when a LeftUp event have been generated
   909     def OnLeftUp(self, event, scaling):
   957     def OnLeftUp(self, event, dc, scaling):
   910         self.RealConnectors = None
   958         self.RealConnectors = None
   911         handle_type, handle = self.Handle
   959         handle_type, handle = self.Handle
   912         if handle_type == HANDLE_CONNECTOR:
   960         if handle_type == HANDLE_CONNECTOR:
   913             wires = handle.GetWires()
   961             wires = handle.GetWires()
   914             if len(wires) != 1:
   962             if len(wires) != 1:
   921             if not isinstance(block, SFC_Divergence):
   969             if not isinstance(block, SFC_Divergence):
   922                 if handle in self.Inputs:
   970                 if handle in self.Inputs:
   923                     block.RefreshInputModel()
   971                     block.RefreshInputModel()
   924                 else:
   972                 else:
   925                     block.RefreshOutputModel()
   973                     block.RefreshOutputModel()
   926         Graphic_Element.OnLeftUp(self, event, scaling)
   974         Graphic_Element.OnLeftUp(self, event, dc, scaling)
   927     
   975     
   928     # Method called when a RightUp event have been generated
   976     # Method called when a RightUp event have been generated
   929     def OnRightUp(self, event, scaling):
   977     def OnRightUp(self, event, dc, scaling):
   930         pos = GetScaledEventPosition(event, scaling)
   978         pos = GetScaledEventPosition(event, dc, scaling)
   931         # Popup the menu with special items for a block and a connector if one is handled
   979         # Popup the menu with special items for a block and a connector if one is handled
   932         connector = self.TestConnector(pos, False)
   980         connector = self.TestConnector(pos, False)
   933         if connector:
   981         if connector:
   934             self.Handle = (HANDLE_CONNECTOR, connector)
   982             self.Handle = (HANDLE_CONNECTOR, connector)
   935             self.Parent.PopupDivergenceMenu(True)
   983             self.Parent.PopupDivergenceMenu(True)
   941     def ProcessDragging(self, movex, movey):
   989     def ProcessDragging(self, movex, movey):
   942         handle_type, handle = self.Handle
   990         handle_type, handle = self.Handle
   943         # A connector has been handled
   991         # A connector has been handled
   944         if handle_type == HANDLE_CONNECTOR:
   992         if handle_type == HANDLE_CONNECTOR:
   945             self.MoveConnector(handle, movex)
   993             self.MoveConnector(handle, movex)
   946             self.RefreshConnectedPosition(handle)
   994             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
       
   995                 self.RefreshConnectedPosition(handle)
       
   996         elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
   997             Graphic_Element.ProcessDragging(self, movex, movey)
   947     
   998     
   948     # Refresh output element model
   999     # Refresh output element model
   949     def RefreshOutputModel(self, move=False):
  1000     def RefreshOutputModel(self, move=False):
   950         if move:
  1001         if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   951             for output in self.Outputs:
  1002             for output in self.Outputs:
   952                 wires = output.GetWires()
  1003                 wires = output.GetWires()
   953                 if len(wires) != 1:
  1004                 if len(wires) != 1:
   954                     return
  1005                     return
   955                 output_block = wires[0][0].StartConnected.GetParentBlock()
  1006                 output_block = wires[0][0].StartConnected.GetParentBlock()
   960     # Refreshes the divergence model
  1011     # Refreshes the divergence model
   961     def RefreshModel(self, move=True):
  1012     def RefreshModel(self, move=True):
   962         self.Parent.RefreshDivergenceModel(self)
  1013         self.Parent.RefreshDivergenceModel(self)
   963         # If divergence has moved, refresh the model of wires connected to outputs
  1014         # If divergence has moved, refresh the model of wires connected to outputs
   964         if move:
  1015         if move:
   965             self.RefreshOutputModel()
  1016             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
       
  1017                 self.RefreshOutputModel()
       
  1018             else:
       
  1019                 for output in self.Outputs:
       
  1020                     output.RefreshWires()
   966     
  1021     
   967     # Draws divergence
  1022     # Draws divergence
   968     def Draw(self, dc):
  1023     def Draw(self, dc):
   969         dc.SetPen(wxBLACK_PEN)
  1024         dc.SetPen(wxBLACK_PEN)
   970         dc.SetBrush(wxBLACK_BRUSH)
  1025         dc.SetBrush(wxBLACK_BRUSH)
   972         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1027         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   973             dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1028             dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   974         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1029         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   975             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, 
  1030             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, 
   976                         self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y)
  1031                         self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y)
   977             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + 3, 
  1032             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1], 
   978                         self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + 3)
  1033                         self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[1])
   979         # Draw inputs and outputs connectors
  1034         # Draw inputs and outputs connectors
   980         for input in self.Inputs:
  1035         for input in self.Inputs:
   981             input.Draw(dc)
  1036             input.Draw(dc)
   982         for output in self.Outputs:
  1037         for output in self.Outputs:
   983             output.Draw(dc)
  1038             output.Draw(dc)
  1002         # Create an input and output connector
  1057         # Create an input and output connector
  1003         self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)
  1058         self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)
  1004         
  1059         
  1005     # Destructor
  1060     # Destructor
  1006     def __del__(self):
  1061     def __del__(self):
  1007         self.Inputs = None
  1062         self.Input = None
  1008     
  1063     
  1009     # Forbids to change the jump size
  1064     # Forbids to change the jump size
  1010     def SetSize(self, width, height):
  1065     def SetSize(self, width, height):
  1011         pass
  1066         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
  1067             Graphic_Element.SetSize(self, width, height)
  1012     
  1068     
  1013     # Forbids to resize jump
  1069     # Forbids to resize jump
  1014     def Resize(self, x, y, width, height):
  1070     def Resize(self, x, y, width, height):
  1015         pass
  1071         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
       
  1072             Graphic_Element.Resize(self, x, y, width, height)
  1016     
  1073     
  1017     # Delete this jump by calling the appropriate method
  1074     # Delete this jump by calling the appropriate method
  1018     def Delete(self):
  1075     def Delete(self):
  1019         self.Parent.DeleteJump(self)
  1076         self.Parent.DeleteJump(self)
  1020     
  1077     
  1021     # Unconnect input
  1078     # Unconnect input
  1022     def Clean(self):
  1079     def Clean(self):
  1023         if self.Input:
  1080         self.Input.UnConnect()
  1024             self.Input.UnConnect()
       
  1025     
  1081     
  1026     # Refresh the jump bounding box
  1082     # Refresh the jump bounding box
  1027     def RefreshBoundingBox(self):
  1083     def RefreshBoundingBox(self):
  1028         dc = wxClientDC(self.Parent)
  1084         dc = wxClientDC(self.Parent)
  1029         text_width, text_height = dc.GetTextExtent(self.Target)
  1085         text_width, text_height = dc.GetTextExtent(self.Target)
  1032         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1088         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1033                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1089                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1034     
  1090     
  1035     # Returns the connector connected to input
  1091     # Returns the connector connected to input
  1036     def GetPreviousConnector(self):
  1092     def GetPreviousConnector(self):
  1037         if self.Input:
  1093         wires = self.Input.GetWires()
  1038             wires = self.Input.GetWires()
  1094         if len(wires) == 1:
  1039             if len(wires) == 1:
  1095             return wires[0][0].EndConnected
  1040                 return wires[0][0].EndConnected
       
  1041         return None
  1096         return None
       
  1097     
       
  1098     # Refresh the element connectors position
       
  1099     def RefreshConnectors(self):
       
  1100         self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0))
       
  1101         self.RefreshConnected()
  1042     
  1102     
  1043     # Refresh the position of wires connected to jump
  1103     # Refresh the position of wires connected to jump
  1044     def RefreshConnected(self, exclude = []):
  1104     def RefreshConnected(self, exclude = []):
  1045         if self.Input:
  1105         if self.Input:
  1046             self.Input.MoveConnected(exclude)
  1106             self.Input.MoveConnected(exclude)
  1047     
  1107     
  1048     # Returns input jump connector 
  1108     # Returns input jump connector 
  1049     def GetConnector(self, position = None):
  1109     def GetConnector(self, position = None, name = None):
  1050         return self.Input
  1110         return self.Input
  1051     
  1111     
  1052     # Test if point given is on jump input connector
  1112     # Test if point given is on jump input connector
  1053     def TestConnector(self, pt, exclude = True):
  1113     def TestConnector(self, pt, exclude = True):
  1054         # Test input connector
  1114         # Test input connector
  1089     # Can't align output element, because there is no output
  1149     # Can't align output element, because there is no output
  1090     def RefreshOutputPosition(self, move = None):
  1150     def RefreshOutputPosition(self, move = None):
  1091         pass
  1151         pass
  1092     
  1152     
  1093     # Method called when a LeftDClick event have been generated
  1153     # Method called when a LeftDClick event have been generated
  1094     def OnLeftDClick(self, event, scaling):
  1154     def OnLeftDClick(self, event, dc, scaling):
  1095         # Edit the jump properties
  1155         # Edit the jump properties
  1096         self.Parent.EditJumpContent(self)
  1156         self.Parent.EditJumpContent(self)
  1097     
  1157     
  1098     # Method called when a RightUp event have been generated
  1158     # Method called when a RightUp event have been generated
  1099     def OnRightUp(self, event, scaling):
  1159     def OnRightUp(self, event, dc, scaling):
  1100         # Popup the default menu
  1160         # Popup the default menu
  1101         self.Parent.PopupDefaultMenu()
  1161         self.Parent.PopupDefaultMenu()
  1102     
  1162     
  1103     # Refreshes the jump state according to move defined and handle selected
  1163     # Refreshes the jump state according to move defined and handle selected
  1104     def ProcessDragging(self, movex, movey):
  1164     def ProcessDragging(self, movex, movey):
  1105         self.Move(movex, 0)
  1165         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1106         self.RefreshInputPosition()
  1166             self.Move(movex, 0)
       
  1167             self.RefreshInputPosition()
       
  1168         else:
       
  1169             Graphic_Element.ProcessDragging(self, movex, movey)
  1107     
  1170     
  1108     # Refresh input element model
  1171     # Refresh input element model
  1109     def RefreshInputModel(self):
  1172     def RefreshInputModel(self):
  1110         input = self.GetPreviousConnector()
  1173         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1111         if input:
  1174             input = self.GetPreviousConnector()
  1112             input_block = input.GetParentBlock()
  1175             if input:
  1113             input_block.RefreshModel(False)
  1176                 input_block = input.GetParentBlock()
  1114             if not isinstance(input_block, SFC_Divergence):
  1177                 input_block.RefreshModel(False)
  1115                 input_block.RefreshInputModel()
  1178                 if not isinstance(input_block, SFC_Divergence):
       
  1179                     input_block.RefreshInputModel()
  1116     
  1180     
  1117     # Refresh output element model
  1181     # Refresh output element model
  1118     def RefreshOutputModel(self, move=False):
  1182     def RefreshOutputModel(self, move=False):
  1119         pass
  1183         pass
  1120     
  1184     
  1121     # Refreshes the jump model
  1185     # Refreshes the jump model
  1122     def RefreshModel(self, move=True):
  1186     def RefreshModel(self, move=True):
  1123         self.Parent.RefreshJumpModel(self)
  1187         self.Parent.RefreshJumpModel(self)
  1124         if move:
  1188         if move:
  1125             self.RefreshInputModel()
  1189             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
       
  1190                 self.RefreshInputModel()
  1126     
  1191     
  1127     # Draws divergence
  1192     # Draws divergence
  1128     def Draw(self, dc):
  1193     def Draw(self, dc):
  1129         dc.SetPen(wxBLACK_PEN)
  1194         dc.SetPen(wxBLACK_PEN)
  1130         dc.SetBrush(wxBLACK_BRUSH)
  1195         dc.SetBrush(wxBLACK_BRUSH)
  1169     
  1234     
  1170     # Returns the number of action lines
  1235     # Returns the number of action lines
  1171     def GetLineNumber(self):
  1236     def GetLineNumber(self):
  1172         return len(self.Actions)
  1237         return len(self.Actions)
  1173     
  1238     
       
  1239     def GetLineSize(self):
       
  1240         if len(self.Actions) > 1:
       
  1241             return self.Size[1] / len(self.Actions)
       
  1242         else:
       
  1243             return SFC_ACTION_MIN_SIZE[1]
       
  1244     
  1174     # Forbids to resize the action block
  1245     # Forbids to resize the action block
  1175     def Resize(self, x, y, width, height):
  1246     def Resize(self, x, y, width, height):
  1176         if x == 0:
  1247         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1177             self.SetSize(width, self.Size[1])
  1248             if x == 0:
       
  1249                 self.SetSize(width, self.Size[1])
       
  1250         else:
       
  1251             Graphic_Element.Resize(self, x, y, width, height)
  1178     
  1252     
  1179     # Delete this action block by calling the appropriate method
  1253     # Delete this action block by calling the appropriate method
  1180     def Delete(self):
  1254     def Delete(self):
  1181         self.Parent.DeleteActionBlock(self)
  1255         self.Parent.DeleteActionBlock(self)
  1182     
  1256     
  1191     # Refresh the position of wires connected to action block
  1265     # Refresh the position of wires connected to action block
  1192     def RefreshConnected(self, exclude = []):
  1266     def RefreshConnected(self, exclude = []):
  1193         self.Input.MoveConnected(exclude)
  1267         self.Input.MoveConnected(exclude)
  1194     
  1268     
  1195     # Returns input action block connector 
  1269     # Returns input action block connector 
  1196     def GetConnector(self, position = None):
  1270     def GetConnector(self, position = None, name = None):
  1197         return self.Input
  1271         return self.Input
  1198     
  1272     
  1199     # Test if point given is on action block input connector
  1273     # Test if point given is on action block input connector
  1200     def TestConnector(self, pt, exclude = True):
  1274     def TestConnector(self, pt, exclude = True):
  1201         # Test input connector
  1275         # Test input connector
  1217             width, height = dc.GetTextExtent(action["value"])
  1291             width, height = dc.GetTextExtent(action["value"])
  1218             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1292             self.ColSize[1] = max(self.ColSize[1], width + 10)
  1219             if "indicator" in action and action["indicator"] != "":
  1293             if "indicator" in action and action["indicator"] != "":
  1220                 width, height = dc.GetTextExtent(action["indicator"])
  1294                 width, height = dc.GetTextExtent(action["indicator"])
  1221                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1295                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1222         self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1296         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1223             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1297             line_size = self.GetLineSize()
       
  1298             self.Size = wxSize(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size)
       
  1299         else:
       
  1300             self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
       
  1301                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1224         self.RefreshBoundingBox()
  1302         self.RefreshBoundingBox()
  1225         if self.Input:
  1303         if self.Input:
  1226             wires = self.Input.GetWires()
  1304             wires = self.Input.GetWires()
  1227             if len(wires) == 1:
  1305             if len(wires) == 1:
  1228                 input_block = wires[0][0].EndConnected.GetParentBlock()
  1306                 input_block = wires[0][0].EndConnected.GetParentBlock()
  1237     def GetMinSize(self):
  1315     def GetMinSize(self):
  1238         return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1316         return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1239             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
  1317             SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
  1240     
  1318     
  1241     # Method called when a LeftDClick event have been generated
  1319     # Method called when a LeftDClick event have been generated
  1242     def OnLeftDClick(self, event, scaling):
  1320     def OnLeftDClick(self, event, dc, scaling):
  1243         # Edit the action block properties
  1321         # Edit the action block properties
  1244         self.Parent.EditActionBlockContent(self)
  1322         self.Parent.EditActionBlockContent(self)
  1245     
  1323     
  1246     # Refreshes the action block state according to move defined and handle selected
  1324     # Refreshes the action block state according to move defined and handle selected
  1247     def ProcessDragging(self, movex, movey):
  1325     def ProcessDragging(self, movex, movey):
  1248         handle_type, handle = self.Handle
  1326         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1249         if handle_type == HANDLE_MOVE:
  1327             handle_type, handle = self.Handle
  1250             wires = self.Input.GetWires()
  1328             if handle_type == HANDLE_MOVE:
  1251             if len(wires) == 1:
  1329                 wires = self.Input.GetWires()
  1252                 input_pos = wires[0][0].EndConnected.GetPosition(False)
  1330                 if len(wires) == 1:
  1253                 if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
  1331                     input_pos = wires[0][0].EndConnected.GetPosition(False)
  1254                     self.Move(movex, 0)
  1332                     if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
       
  1333                         self.Move(movex, 0)
       
  1334             else:
       
  1335                 Graphic_Element.ProcessDragging(self, movex, movey)
  1255         else:
  1336         else:
  1256             Graphic_Element.ProcessDragging(self, movex, movey)
  1337             Graphic_Element.ProcessDragging(self, movex, movey)
       
  1338 
  1257     
  1339     
  1258    # Refreshes the action block model
  1340    # Refreshes the action block model
  1259     def RefreshModel(self, move=True):
  1341     def RefreshModel(self, move=True):
  1260         self.Parent.RefreshActionBlockModel(self)
  1342         self.Parent.RefreshActionBlockModel(self)
  1261     
  1343     
  1268         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1350         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1269         dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, 
  1351         dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, 
  1270                 self.Pos.x + colsize[0], self.Pos.y + self.Size[1])
  1352                 self.Pos.x + colsize[0], self.Pos.y + self.Size[1])
  1271         dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, 
  1353         dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, 
  1272                 self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1])
  1354                 self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1])
       
  1355         line_size = self.GetLineSize()
  1273         for i, action in enumerate(self.Actions):
  1356         for i, action in enumerate(self.Actions):
  1274             if i != 0:
  1357             if i != 0:
  1275                 dc.DrawLine(self.Pos.x, self.Pos.y + i * SFC_ACTION_MIN_SIZE[1], 
  1358                 dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, 
  1276                     self.Pos.x + self.Size[0], self.Pos.y + i * SFC_ACTION_MIN_SIZE[1])
  1359                     self.Pos.x + self.Size[0], self.Pos.y + i * line_size)
  1277             text_width, text_height = dc.GetTextExtent(action["qualifier"])
  1360             text_width, text_height = dc.GetTextExtent(action["qualifier"])
  1278             if "duration" in action:
  1361             if "duration" in action:
  1279                 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
  1362                 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
  1280                     self.Pos.y + i * SFC_ACTION_MIN_SIZE[1] + SFC_ACTION_MIN_SIZE[1] / 2 - text_height)
  1363                     self.Pos.y + i * line_size + line_size / 2 - text_height)
  1281                 text_width, text_height = dc.GetTextExtent(action["duration"])
  1364                 text_width, text_height = dc.GetTextExtent(action["duration"])
  1282                 dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2,
  1365                 dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2,
  1283                     self.Pos.y + i * SFC_ACTION_MIN_SIZE[1] + SFC_ACTION_MIN_SIZE[1] / 2)
  1366                     self.Pos.y + i * line_size + line_size / 2)
  1284             else:
  1367             else:
  1285                 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
  1368                 dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2,
  1286                         self.Pos.y + i * SFC_ACTION_MIN_SIZE[1] + (SFC_ACTION_MIN_SIZE[1] - text_height) / 2)
  1369                         self.Pos.y + i * line_size + (line_size - text_height) / 2)
  1287             text_width, text_height = dc.GetTextExtent(action["value"])
  1370             text_width, text_height = dc.GetTextExtent(action["value"])
  1288             dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2,
  1371             dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2,
  1289                     self.Pos.y + i * SFC_ACTION_MIN_SIZE[1] + (SFC_ACTION_MIN_SIZE[1] - text_height) / 2)
  1372                     self.Pos.y + i * line_size + (line_size - text_height) / 2)
  1290             if "indicator" in action:
  1373             if "indicator" in action:
  1291                 text_width, text_height = dc.GetTextExtent(action["indicator"])
  1374                 text_width, text_height = dc.GetTextExtent(action["indicator"])
  1292                 dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2,
  1375                 dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2,
  1293                         self.Pos.y + i * SFC_ACTION_MIN_SIZE[1] + (SFC_ACTION_MIN_SIZE[1] - text_height) / 2)
  1376                         self.Pos.y + i * line_size + (line_size - text_height) / 2)
  1294         # Draw input connector
  1377         # Draw input connector
  1295         self.Input.Draw(dc)
  1378         self.Input.Draw(dc)
  1296         Graphic_Element.Draw(self, dc)
  1379         Graphic_Element.Draw(self, dc)
       
  1380