SFCViewer.py
changeset 64 dd6f693e46a1
parent 58 39cd981ff242
child 67 3a1b0afdaf84
equal deleted inserted replaced
63:04a02b4b2a57 64:dd6f693e46a1
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 from wxPython.wx import *
       
    26 import wx
    25 import wx
    27 from types import *
    26 from types import *
    28 
    27 
    29 from Viewer import *
    28 from Viewer import *
    30 
    29 
    54         wire = self.ConnectConnectors(transition_connectors["input"], connector)
    53         wire = self.ConnectConnectors(transition_connectors["input"], connector)
    55         if isinstance(previous, SFC_Divergence):
    54         if isinstance(previous, SFC_Divergence):
    56             previous.RefreshConnectedPosition(connector)
    55             previous.RefreshConnectedPosition(connector)
    57         else:
    56         else:
    58             previous.RefreshOutputPosition()
    57             previous.RefreshOutputPosition()
    59         wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)])
    58         wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
    60         self.AddBlock(transition)
    59         self.AddBlock(transition)
    61         self.Controler.AddCurrentElementEditingTransition(id)
    60         self.Controler.AddCurrentElementEditingTransition(id)
    62         self.RefreshTransitionModel(transition)
    61         self.RefreshTransitionModel(transition)
    63         if next:
    62         if next:
    64             wire = self.ConnectConnectors(next, transition_connectors["output"])
    63             wire = self.ConnectConnectors(next, transition_connectors["output"])
    65             pos = transition_connectors["output"].GetPosition(False)
    64             pos = transition_connectors["output"].GetPosition(False)
    66             next_block = next.GetParentBlock()
    65             next_block = next.GetParentBlock()
    67             next_pos = next.GetPosition(False)
    66             next_pos = next.GetPosition(False)
    68             transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
    67             transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
    69             wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
    68             wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
    70             if isinstance(next_block, SFC_Divergence):
    69             if isinstance(next_block, SFC_Divergence):
    71                 next_block.RefreshPosition()
    70                 next_block.RefreshPosition()
    72             transition.RefreshOutputModel(True)
    71             transition.RefreshOutputModel(True)
    73         return transition
    72         return transition
    74     
    73     
   108         wire = self.ConnectConnectors(step_connectors["input"], connector)
   107         wire = self.ConnectConnectors(step_connectors["input"], connector)
   109         if isinstance(previous, SFC_Divergence):
   108         if isinstance(previous, SFC_Divergence):
   110             previous.RefreshConnectedPosition(connector)
   109             previous.RefreshConnectedPosition(connector)
   111         else:
   110         else:
   112             previous.RefreshOutputPosition()
   111             previous.RefreshOutputPosition()
   113         wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)])
   112         wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
   114         self.AddBlock(step)
   113         self.AddBlock(step)
   115         self.Controler.AddCurrentElementEditingStep(id)
   114         self.Controler.AddCurrentElementEditingStep(id)
   116         self.RefreshStepModel(step)
   115         self.RefreshStepModel(step)
   117         if next:
   116         if next:
   118             wire = self.ConnectConnectors(next, step_connectors["output"])
   117             wire = self.ConnectConnectors(next, step_connectors["output"])
   119             pos = step_connectors["output"].GetPosition(False)
   118             pos = step_connectors["output"].GetPosition(False)
   120             next_block = next.GetParentBlock()
   119             next_block = next.GetParentBlock()
   121             next_pos = next.GetPosition(False)
   120             next_pos = next.GetPosition(False)
   122             step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   121             step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   123             wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
   122             wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
   124             if isinstance(next_block, SFC_Divergence):
   123             if isinstance(next_block, SFC_Divergence):
   125                 next_block.RefreshPosition()
   124                 next_block.RefreshPosition()
   126             step.RefreshOutputModel(True)
   125             step.RefreshOutputModel(True)
   127         return step
   126         return step
   128 
   127 
   205         elif self.Mode == MODE_COMMENT:
   204         elif self.Mode == MODE_COMMENT:
   206             self.rubberBand.Reset()
   205             self.rubberBand.Reset()
   207             self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
   206             self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
   208         elif self.Mode == MODE_WIRE:
   207         elif self.Mode == MODE_WIRE:
   209             pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
   208             pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
   210             wire = Wire(self, [wxPoint(pos.x, pos.y), SOUTH], [wxPoint(pos.x, pos.y), NORTH])
   209             wire = Wire(self, [wx.Point(pos.x, pos.y), SOUTH], [wx.Point(pos.x, pos.y), NORTH])
   211             wire.oldPos = pos
   210             wire.oldPos = pos
   212             wire.Handle = (HANDLE_POINT, 0)
   211             wire.Handle = (HANDLE_POINT, 0)
   213             wire.ProcessDragging(0, 0)
   212             wire.ProcessDragging(0, 0)
   214             wire.Handle = (HANDLE_POINT, 1)
   213             wire.Handle = (HANDLE_POINT, 1)
   215             self.AddWire(wire)
   214             self.AddWire(wire)
   232                     self.SelectedElement.SetSelected(True)
   231                     self.SelectedElement.SetSelected(True)
   233                     self.Refresh()
   232                     self.Refresh()
   234             elif self.Mode == MODE_COMMENT:
   233             elif self.Mode == MODE_COMMENT:
   235                 bbox = self.rubberBand.GetCurrentExtent()
   234                 bbox = self.rubberBand.GetCurrentExtent()
   236                 self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
   235                 self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
   237                 wxCallAfter(self.AddComment, bbox)
   236                 wx.CallAfter(self.AddComment, bbox)
   238         elif self.Mode == MODE_INITIALSTEP:
   237         elif self.Mode == MODE_INITIALSTEP:
   239             wxCallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
   238             wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
   240         elif self.Mode == MODE_SELECTION and self.SelectedElement:
   239         elif self.Mode == MODE_SELECTION and self.SelectedElement:
   241             if self.IsWire(self.SelectedElement):
   240             if self.IsWire(self.SelectedElement):
   242                 self.SelectedElement.SetSelectedSegment(0)
   241                 self.SelectedElement.SetSelectedSegment(0)
   243             else:
   242             else:
   244                 self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
   243                 self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
   245             wxCallAfter(self.SetCursor, wxNullCursor)
   244             wx.CallAfter(self.SetCursor, wx.NullCursor)
   246             self.ReleaseMouse()
   245             self.ReleaseMouse()
   247             self.Refresh()
   246             self.Refresh()
   248         elif self.Mode == MODE_WIRE and self.SelectedElement:
   247         elif self.Mode == MODE_WIRE and self.SelectedElement:
   249             self.SelectedElement.ResetPoints()
   248             self.SelectedElement.ResetPoints()
   250             self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
   249             self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
   268                 if self.IsWire(self.SelectedElement):
   267                 if self.IsWire(self.SelectedElement):
   269                     self.SelectedElement.SetSelectedSegment(0)
   268                     self.SelectedElement.SetSelectedSegment(0)
   270                 else:
   269                 else:
   271                     self.SelectedElement.SetSelected(True)
   270                     self.SelectedElement.SetSelected(True)
   272                     self.SelectedElement.OnRightUp(event, dc, self.Scaling)
   271                     self.SelectedElement.OnRightUp(event, dc, self.Scaling)
   273                 wxCallAfter(self.SetCursor, wxNullCursor)
   272                 wx.CallAfter(self.SetCursor, wx.NullCursor)
   274                 self.ReleaseMouse()
   273                 self.ReleaseMouse()
   275                 self.Refresh()
   274                 self.Refresh()
   276         event.Skip()
   275         event.Skip()
   277     
   276     
   278     def OnViewerLeftDClick(self, event):
   277     def OnViewerLeftDClick(self, event):
   303 #-------------------------------------------------------------------------------
   302 #-------------------------------------------------------------------------------
   304 #                          Keyboard event functions
   303 #                          Keyboard event functions
   305 #-------------------------------------------------------------------------------
   304 #-------------------------------------------------------------------------------
   306 
   305 
   307     def OnChar(self, event):
   306     def OnChar(self, event):
       
   307         xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
       
   308         xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
       
   309         ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
   308         keycode = event.GetKeyCode()
   310         keycode = event.GetKeyCode()
   309         if self.Scaling:
   311         if self.Scaling:
   310             scaling = self.Scaling
   312             scaling = self.Scaling
   311         else:
   313         else:
   312             scaling = (8, 8)
   314             scaling = (8, 8)
   313         if keycode == WXK_DELETE and self.SelectedElement:
   315         if keycode == wx.WXK_DELETE and self.SelectedElement:
   314             self.SelectedElement.Delete()
   316             self.SelectedElement.Delete()
   315             self.SelectedElement = None
   317             self.SelectedElement = None
   316             self.RefreshBuffer()
   318             self.RefreshBuffer()
   317             self.RefreshScrollBars()
   319             self.RefreshScrollBars()
   318             self.Refresh()
   320             self.Refresh()
   319         elif keycode == WXK_LEFT:
   321         elif keycode == wx.WXK_LEFT:
   320             if event.ControlDown() and event.ShiftDown():
   322             if event.ControlDown() and event.ShiftDown():
   321                 self.Scroll(0, ypos)
   323                 self.Scroll(0, ypos)
   322             elif event.ControlDown():
   324             elif event.ControlDown():
   323                 self.Scroll(max(0, xpos - 1), ypos)
   325                 self.Scroll(max(0, xpos - 1), ypos)
   324             elif self.SelectedElement:
   326             elif self.SelectedElement:
   325                 self.SelectedElement.Move(-scaling[0], 0)
   327                 self.SelectedElement.Move(-scaling[0], 0)
   326                 self.RefreshBuffer()
   328                 self.RefreshBuffer()
   327                 self.RefreshScrollBars()
   329                 self.RefreshScrollBars()
   328                 self.Refresh()
   330                 self.Refresh()
   329         elif keycode == WXK_RIGHT:
   331         elif keycode == wx.WXK_RIGHT:
   330             if event.ControlDown() and event.ShiftDown():
   332             if event.ControlDown() and event.ShiftDown():
   331                 self.Scroll(xmax, ypos)
   333                 self.Scroll(xmax, ypos)
   332             elif event.ControlDown():
   334             elif event.ControlDown():
   333                 self.Scroll(min(xpos + 1, xmax), ypos)
   335                 self.Scroll(min(xpos + 1, xmax), ypos)
   334             elif self.SelectedElement:
   336             elif self.SelectedElement:
   335                 self.SelectedElement.Move(scaling[0], 0)
   337                 self.SelectedElement.Move(scaling[0], 0)
   336                 self.RefreshBuffer()
   338                 self.RefreshBuffer()
   337                 self.RefreshScrollBars()
   339                 self.RefreshScrollBars()
   338                 self.Refresh()
   340                 self.Refresh()
   339         elif keycode == WXK_UP:
   341         elif keycode == wx.WXK_UP:
   340             if event.ControlDown() and event.ShiftDown():
   342             if event.ControlDown() and event.ShiftDown():
   341                 self.Scroll(xpos, 0)
   343                 self.Scroll(xpos, 0)
   342             elif event.ControlDown():
   344             elif event.ControlDown():
   343                 self.Scroll(xpos, max(0, ypos - 1))
   345                 self.Scroll(xpos, max(0, ypos - 1))
   344             elif self.SelectedElement:
   346             elif self.SelectedElement:
   345                 self.SelectedElement.Move(0, -scaling[1])
   347                 self.SelectedElement.Move(0, -scaling[1])
   346                 self.RefreshBuffer()
   348                 self.RefreshBuffer()
   347                 self.RefreshScrollBars()
   349                 self.RefreshScrollBars()
   348                 self.Refresh()
   350                 self.Refresh()
   349         elif keycode == WXK_DOWN:
   351         elif keycode == wx.WXK_DOWN:
   350             if event.ControlDown() and event.ShiftDown():
   352             if event.ControlDown() and event.ShiftDown():
   351                 self.Scroll(xpos, ymax)
   353                 self.Scroll(xpos, ymax)
   352             elif event.ControlDown():
   354             elif event.ControlDown():
   353                 self.Scroll(xpos, min(ypos + 1, ymax))
   355                 self.Scroll(xpos, min(ypos + 1, ymax))
   354             elif self.SelectedElement:
   356             elif self.SelectedElement:
   360 #-------------------------------------------------------------------------------
   362 #-------------------------------------------------------------------------------
   361 #                          Adding element functions
   363 #                          Adding element functions
   362 #-------------------------------------------------------------------------------
   364 #-------------------------------------------------------------------------------
   363 
   365 
   364     def AddInitialStep(self, pos):
   366     def AddInitialStep(self, pos):
   365         dialog = StepNameDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wxOK|wxCANCEL)
   367         dialog = StepNameDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wx.OK|wx.CANCEL)
   366         dialog.SetPouNames(self.Controler.GetProjectPouNames())
   368         dialog.SetPouNames(self.Controler.GetProjectPouNames())
   367         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   369         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   368         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
   370         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
   369         if dialog.ShowModal() == wxID_OK:
   371         if dialog.ShowModal() == wx.ID_OK:
   370             id = self.GetNewId()
   372             id = self.GetNewId()
   371             name = dialog.GetValue()
   373             name = dialog.GetValue()
   372             step = SFC_Step(self, name, True, id)
   374             step = SFC_Step(self, name, True, id)
   373             min_width, min_height = step.GetMinSize()
   375             min_width, min_height = step.GetMinSize()
   374             step.SetPosition(pos.x, pos.y)
   376             step.SetPosition(pos.x, pos.y)
   383             self.Refresh()
   385             self.Refresh()
   384         dialog.Destroy()
   386         dialog.Destroy()
   385 
   387 
   386     def AddStep(self):
   388     def AddStep(self):
   387         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step):
   389         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step):
   388             dialog = StepNameDialog(self.Parent, "Add a new step", "Please enter step name", "", wxOK|wxCANCEL)
   390             dialog = StepNameDialog(self.Parent, "Add a new step", "Please enter step name", "", wx.OK|wx.CANCEL)
   389             dialog.SetPouNames(self.Controler.GetProjectPouNames())
   391             dialog.SetPouNames(self.Controler.GetProjectPouNames())
   390             dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   392             dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   391             dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
   393             dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
   392             if dialog.ShowModal() == wxID_OK:
   394             if dialog.ShowModal() == wx.ID_OK:
   393                 name = dialog.GetValue()
   395                 name = dialog.GetValue()
   394                 if self.IsWire(self.SelectedElement):
   396                 if self.IsWire(self.SelectedElement):
   395                     self.SelectedElement.SetSelectedSegment(None)
   397                     self.SelectedElement.SetSelectedSegment(None)
   396                     previous = self.SelectedElement.EndConnected
   398                     previous = self.SelectedElement.EndConnected
   397                     next = self.SelectedElement.StartConnected
   399                     next = self.SelectedElement.StartConnected
   444             if not connectors["action"]:
   446             if not connectors["action"]:
   445                 dialog = ActionBlockDialog(self.Parent)
   447                 dialog = ActionBlockDialog(self.Parent)
   446                 dialog.SetQualifierList(self.Controler.GetQualifierTypes())
   448                 dialog.SetQualifierList(self.Controler.GetQualifierTypes())
   447                 dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
   449                 dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
   448                 dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
   450                 dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
   449                 if dialog.ShowModal() == wxID_OK:
   451                 if dialog.ShowModal() == wx.ID_OK:
   450                     actions = dialog.GetValues()
   452                     actions = dialog.GetValues()
   451                     self.SelectedElement.AddAction()
   453                     self.SelectedElement.AddAction()
   452                     self.RefreshStepModel(self.SelectedElement)
   454                     self.RefreshStepModel(self.SelectedElement)
   453                     connectors = self.SelectedElement.GetConnectors()
   455                     connectors = self.SelectedElement.GetConnectors()
   454                     pos = connectors["action"].GetPosition(False)
   456                     pos = connectors["action"].GetPosition(False)
   455                     id = self.GetNewId()
   457                     id = self.GetNewId()
   456                     actionblock = SFC_ActionBlock(self, [], id)
   458                     actionblock = SFC_ActionBlock(self, [], id)
   457                     actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2)
   459                     actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2)
   458                     actionblock_connector = actionblock.GetConnector()
   460                     actionblock_connector = actionblock.GetConnector()
   459                     wire = self.ConnectConnectors(actionblock_connector, connectors["action"])
   461                     wire = self.ConnectConnectors(actionblock_connector, connectors["action"])
   460                     wire.SetPoints([wxPoint(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wxPoint(pos.x, pos.y)])
   462                     wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)])
   461                     actionblock.SetActions(actions)
   463                     actionblock.SetActions(actions)
   462                     self.AddBlock(actionblock)
   464                     self.AddBlock(actionblock)
   463                     self.Controler.AddCurrentElementEditingActionBlock(id)
   465                     self.Controler.AddCurrentElementEditingActionBlock(id)
   464                     self.RefreshActionBlockModel(actionblock)
   466                     self.RefreshActionBlockModel(actionblock)
   465                     self.RefreshBuffer()
   467                     self.RefreshBuffer()
   468                 dialog.Destroy()
   470                 dialog.Destroy()
   469     
   471     
   470     def AddDivergence(self):
   472     def AddDivergence(self):
   471         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step):        
   473         if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step):        
   472             dialog = DivergenceCreateDialog(self.Parent)
   474             dialog = DivergenceCreateDialog(self.Parent)
   473             if dialog.ShowModal() == wxID_OK:
   475             if dialog.ShowModal() == wx.ID_OK:
   474                 value = dialog.GetValues()
   476                 value = dialog.GetValues()
   475                 if value["type"] == SELECTION_DIVERGENCE:
   477                 if value["type"] == SELECTION_DIVERGENCE:
   476                     if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step):
   478                     if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step):
   477                         self.SelectedElement.SetSelectedSegment(None)
   479                         self.SelectedElement.SetSelectedSegment(None)
   478                         previous = self.SelectedElement.EndConnected
   480                         previous = self.SelectedElement.EndConnected
   506                     wire_size = GetWireSize(previous_block)
   508                     wire_size = GetWireSize(previous_block)
   507                     divergence.SetPosition(pos.x, pos.y + wire_size)
   509                     divergence.SetPosition(pos.x, pos.y + wire_size)
   508                     divergence_connectors = divergence.GetConnectors()
   510                     divergence_connectors = divergence.GetConnectors()
   509                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
   511                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
   510                     previous_block.RefreshOutputPosition()
   512                     previous_block.RefreshOutputPosition()
   511                     wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
   513                     wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
   512                     self.AddBlock(divergence)
   514                     self.AddBlock(divergence)
   513                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
   515                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
   514                     self.RefreshDivergenceModel(divergence)
   516                     self.RefreshDivergenceModel(divergence)
   515                     for index, connector in enumerate(divergence_connectors["outputs"]):
   517                     for index, connector in enumerate(divergence_connectors["outputs"]):
   516                         if next:
   518                         if next:
   518                             pos = connector.GetPosition(False)
   520                             pos = connector.GetPosition(False)
   519                             next_pos = next.GetPosition(False)
   521                             next_pos = next.GetPosition(False)
   520                             next_block = next.GetParentBlock()
   522                             next_block = next.GetParentBlock()
   521                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   523                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   522                             divergence.RefreshConnectedPosition(connector)
   524                             divergence.RefreshConnectedPosition(connector)
   523                             wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
   525                             wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
   524                             next_block.RefreshModel()
   526                             next_block.RefreshModel()
   525                             next = None
   527                             next = None
   526                         else:
   528                         else:
   527                             transition = self.CreateTransition(connector)
   529                             transition = self.CreateTransition(connector)
   528                             transition_connectors = transition.GetConnectors()
   530                             transition_connectors = transition.GetConnectors()
   564                     wire_size = GetWireSize(previous_block)
   566                     wire_size = GetWireSize(previous_block)
   565                     divergence.SetPosition(pos.x, pos.y + wire_size)
   567                     divergence.SetPosition(pos.x, pos.y + wire_size)
   566                     divergence_connectors = divergence.GetConnectors()
   568                     divergence_connectors = divergence.GetConnectors()
   567                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
   569                     wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
   568                     previous_block.RefreshOutputPosition()
   570                     previous_block.RefreshOutputPosition()
   569                     wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
   571                     wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
   570                     self.AddBlock(divergence)
   572                     self.AddBlock(divergence)
   571                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
   573                     self.Controler.AddCurrentElementEditingDivergence(id, value["type"])
   572                     self.RefreshDivergenceModel(divergence)
   574                     self.RefreshDivergenceModel(divergence)
   573                     for index, connector in enumerate(divergence_connectors["outputs"]):
   575                     for index, connector in enumerate(divergence_connectors["outputs"]):
   574                         if next:
   576                         if next:
   576                             pos = connector.GetPosition(False)
   578                             pos = connector.GetPosition(False)
   577                             next_pos = next.GetPosition(False)
   579                             next_pos = next.GetPosition(False)
   578                             next_block = next.GetParentBlock()
   580                             next_block = next.GetParentBlock()
   579                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   581                             divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   580                             divergence.RefreshConnectedPosition(connector)
   582                             divergence.RefreshConnectedPosition(connector)
   581                             wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
   583                             wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
   582                             next_block.RefreshModel()
   584                             next_block.RefreshModel()
   583                             next = None
   585                             next = None
   584                         else:
   586                         else:
   585                             step = self.CreateStep("Step", connector)
   587                             step = self.CreateStep("Step", connector)
   586                 elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1:
   588                 elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1:
   630                     divergence_connectors = divergence.GetConnectors()
   632                     divergence_connectors = divergence.GetConnectors()
   631                     for i, input in enumerate(inputs):
   633                     for i, input in enumerate(inputs):
   632                         pos = input.GetPosition(False)
   634                         pos = input.GetPosition(False)
   633                         wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input)
   635                         wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input)
   634                         wire_size = GetWireSize(input)
   636                         wire_size = GetWireSize(input)
   635                         wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
   637                         wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
   636                         input_block = input.GetParentBlock()
   638                         input_block = input.GetParentBlock()
   637                         input_block.RefreshOutputPosition()
   639                         input_block.RefreshOutputPosition()
   638                     divergence.RefreshPosition()
   640                     divergence.RefreshPosition()
   639                     pos = divergence_connectors["outputs"][0].GetRelPosition()
   641                     pos = divergence_connectors["outputs"][0].GetRelPosition()
   640                     divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x)
   642                     divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x)
   646                         pos = divergence_connectors["outputs"][0].GetPosition(False)
   648                         pos = divergence_connectors["outputs"][0].GetPosition(False)
   647                         next_pos = next.GetPosition(False)
   649                         next_pos = next.GetPosition(False)
   648                         next_block = next.GetParentBlock()
   650                         next_block = next.GetParentBlock()
   649                         divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   651                         divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
   650                         divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0])
   652                         divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0])
   651                         wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
   653                         wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
   652                         next_block.RefreshModel()
   654                         next_block.RefreshModel()
   653                     else:
   655                     else:
   654                         if value["type"] == SELECTION_CONVERGENCE:
   656                         if value["type"] == SELECTION_CONVERGENCE:
   655                             previous = divergence_connectors["outputs"][0]
   657                             previous = divergence_connectors["outputs"][0]
   656                         else:
   658                         else:
   684         if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output:
   686         if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output:
   685             choices = []
   687             choices = []
   686             for block in self.Blocks:
   688             for block in self.Blocks:
   687                 if isinstance(block, SFC_Step):
   689                 if isinstance(block, SFC_Step):
   688                     choices.append(block.GetName())
   690                     choices.append(block.GetName())
   689             dialog = wxSingleChoiceDialog(self.Parent, "Add a new jump", "Please choose a target", choices, wxOK|wxCANCEL)
   691             dialog = wx.SingleChoiceDialog(self.Parent, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL)
   690             if dialog.ShowModal() == wxID_OK:
   692             if dialog.ShowModal() == wx.ID_OK:
   691                 value = dialog.GetStringSelection()
   693                 value = dialog.GetStringSelection()
   692                 self.SelectedElement.AddOutput()
   694                 self.SelectedElement.AddOutput()
   693                 self.RefreshStepModel(self.SelectedElement)
   695                 self.RefreshStepModel(self.SelectedElement)
   694                 step_connectors = self.SelectedElement.GetConnectors()
   696                 step_connectors = self.SelectedElement.GetConnectors()
   695                 transition = self.CreateTransition(step_connectors["output"])
   697                 transition = self.CreateTransition(step_connectors["output"])
   701                 self.AddBlock(jump)
   703                 self.AddBlock(jump)
   702                 self.Controler.AddCurrentElementEditingJump(id)
   704                 self.Controler.AddCurrentElementEditingJump(id)
   703                 jump_connector = jump.GetConnector()
   705                 jump_connector = jump.GetConnector()
   704                 wire = self.ConnectConnectors(jump_connector, transition_connectors["output"])
   706                 wire = self.ConnectConnectors(jump_connector, transition_connectors["output"])
   705                 transition.RefreshOutputPosition()
   707                 transition.RefreshOutputPosition()
   706                 wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)])
   708                 wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
   707                 self.RefreshJumpModel(jump)
   709                 self.RefreshJumpModel(jump)
   708                 self.RefreshBuffer()
   710                 self.RefreshBuffer()
   709                 self.RefreshScrollBars()
   711                 self.RefreshScrollBars()
   710                 self.Refresh()
   712                 self.Refresh()
   711             dialog.Destroy()
   713             dialog.Destroy()
   712 
   714 
   713     def EditStepContent(self, step):
   715     def EditStepContent(self, step):
   714         dialog = StepNameDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wxOK|wxCANCEL)
   716         dialog = StepNameDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wx.OK|wx.CANCEL)
   715         dialog.SetPouNames(self.Controler.GetProjectPouNames())
   717         dialog.SetPouNames(self.Controler.GetProjectPouNames())
   716         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   718         dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars())
   717         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
   719         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
   718         if dialog.ShowModal() == wxID_OK:
   720         if dialog.ShowModal() == wx.ID_OK:
   719             value = dialog.GetValue()
   721             value = dialog.GetValue()
   720             step.SetName(value)
   722             step.SetName(value)
   721             min_size = step.GetMinSize()
   723             min_size = step.GetMinSize()
   722             size = step.GetSize()
   724             size = step.GetSize()
   723             step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1]))
   725             step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1]))
   724             step.RefreshModel()
   726             step.RefreshModel()
   725             self.RefreshBuffer()
   727             self.RefreshBuffer()
   726             self.RefreshScrollBars()
   728             self.RefreshScrollBars()
   727             self.Refresh()
   729             self.Refresh()
   728         dialog.Destroy()
   730         dialog.Destroy()
   729 
       
   730     def EditTransitionContent(self, transition):
       
   731         dialog = TransitionContentDialog(self.Parent)
       
   732         dialog.SetTransitions(self.Controler.GetCurrentElementEditingTransitions())
       
   733         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition()})
       
   734         if dialog.ShowModal() == wxID_OK:
       
   735             values = dialog.GetValues()
       
   736             transition.SetType(values["type"])
       
   737             transition.SetCondition(values["value"])
       
   738             transition.RefreshModel()
       
   739             self.RefreshBuffer()
       
   740             self.RefreshScrollBars()
       
   741             self.Refresh()
       
   742         dialog.Destroy()
       
   743 
       
   744     def EditJumpContent(self, jump):
       
   745         choices = []
       
   746         for block in self.Blocks:
       
   747             if isinstance(block, SFC_Step):
       
   748                 choices.append(block.GetName())
       
   749         dialog = wxSingleChoiceDialog(self.Parent, "Edit jump target", "Please choose a target", choices, wxOK|wxCANCEL)
       
   750         dialog.SetSelection(choices.index(jump.GetTarget()))
       
   751         if dialog.ShowModal() == wxID_OK:
       
   752             value = dialog.GetStringSelection()
       
   753             jump.SetTarget(value)
       
   754             jump.RefreshModel()
       
   755             self.RefreshBuffer()
       
   756             self.RefreshScrollBars()
       
   757             self.Refresh()
       
   758         dialog.Destroy()
       
   759 
       
   760     def EditActionBlockContent(self, actionblock):
       
   761         dialog = ActionBlockDialog(self.Parent)
       
   762         dialog.SetQualifierList(self.Controler.GetQualifierTypes())
       
   763         dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
       
   764         dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
       
   765         dialog.SetValues(actionblock.GetActions())
       
   766         if dialog.ShowModal() == wxID_OK:
       
   767             actions = dialog.GetValues()
       
   768             actionblock.SetActions(actions)
       
   769             actionblock.RefreshModel()
       
   770             self.RefreshBuffer()
       
   771             self.RefreshScrollBars()
       
   772             self.Refresh()
       
   773         dialog.Destroy()
       
   774         
       
   775 
   731 
   776 #-------------------------------------------------------------------------------
   732 #-------------------------------------------------------------------------------
   777 #                          Delete element functions
   733 #                          Delete element functions
   778 #-------------------------------------------------------------------------------
   734 #-------------------------------------------------------------------------------
   779 
   735 
   826                     else:
   782                     else:
   827                         pos = previous.GetPosition(False)
   783                         pos = previous.GetPosition(False)
   828                         next_pos = next.GetPosition(False)
   784                         next_pos = next.GetPosition(False)
   829                         wire_size = GetWireSize(previous_block)
   785                         wire_size = GetWireSize(previous_block)
   830                         previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y))
   786                         previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y))
   831                         wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)])
   787                         wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
   832                         if isinstance(next_block, SFC_Divergence):
   788                         if isinstance(next_block, SFC_Divergence):
   833                             next_block.RefreshPosition()
   789                             next_block.RefreshPosition()
   834                         previous_block.RefreshOutputModel(True)
   790                         previous_block.RefreshOutputModel(True)
   835                 else:
   791                 else:
   836                     if isinstance(previous_block, SFC_Step):
   792                     if isinstance(previous_block, SFC_Step):
   939                     previous_block = previous.GetParentBlock()
   895                     previous_block = previous.GetParentBlock()
   940                     previous_pos = previous.GetPosition(False)
   896                     previous_pos = previous.GetPosition(False)
   941                     next_pos = next.GetPosition(False)
   897                     next_pos = next.GetPosition(False)
   942                     wire_size = GetWireSize(previous_block)
   898                     wire_size = GetWireSize(previous_block)
   943                     previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
   899                     previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
   944                     wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), 
   900                     wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
   945                         wxPoint(previous_pos.x, previous_pos.y)])
   901                         wx.Point(previous_pos.x, previous_pos.y)])
   946                     if isinstance(next_block, SFC_Divergence):
   902                     if isinstance(next_block, SFC_Divergence):
   947                         next_block.RefreshPosition()
   903                         next_block.RefreshPosition()
   948                     previous_block.RefreshOutputModel(True)
   904                     previous_block.RefreshOutputModel(True)
   949             elif divergence.GetBranchNumber() == 1:
   905             elif divergence.GetBranchNumber() == 1:
   950                 wires = connectors["inputs"][0].GetWires()
   906                 wires = connectors["inputs"][0].GetWires()
   969                 wire = self.ConnectConnectors(next, previous)
   925                 wire = self.ConnectConnectors(next, previous)
   970                 previous_pos = previous.GetPosition(False)
   926                 previous_pos = previous.GetPosition(False)
   971                 next_pos = next.GetPosition(False)
   927                 next_pos = next.GetPosition(False)
   972                 wire_size = GetWireSize(previous_block)
   928                 wire_size = GetWireSize(previous_block)
   973                 previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y))
   929                 previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y))
   974                 wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), 
   930                 wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
   975                     wxPoint(previous_pos.x, previous_pos.y)])
   931                     wx.Point(previous_pos.x, previous_pos.y)])
   976                 if isinstance(next_block, SFC_Divergence):
   932                 if isinstance(next_block, SFC_Divergence):
   977                     next_block.RefreshPosition()
   933                     next_block.RefreshPosition()
   978                 previous_block.RefreshOutputModel(True)
   934                 previous_block.RefreshOutputModel(True)
   979             self.Parent.RefreshProjectTree()
   935             self.Parent.RefreshProjectTree()
   980 
   936