Viewer.py
changeset 108 9aa1fdfb7cb2
parent 106 3fc63036de16
child 111 0ec40799ba11
--- a/Viewer.py	Fri Oct 05 18:11:51 2007 +0200
+++ b/Viewer.py	Wed Oct 17 17:50:27 2007 +0200
@@ -53,6 +53,7 @@
         self.ParentWindow = parent
     
     def OnDropText(self, x, y, data):
+        x, y = self.ParentWindow.CalcUnscrolledPosition(x, y)
         values = eval(data)
         if values[1] == "program":
             message = wx.MessageDialog(self.ParentWindow, "Programs can't be used by other POUs!", "Error", wx.OK|wx.ICON_ERROR)
@@ -1286,6 +1287,46 @@
             self.Refresh(False)
         dialog.Destroy()
 
+    def AddNewJump(self, bbox):
+        choices = []
+        for block in self.Blocks:
+            if isinstance(block, SFC_Step):
+                choices.append(block.GetName())
+        dialog = wx.SingleChoiceDialog(self.ParentWindow, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL)
+        if dialog.ShowModal() == wx.ID_OK:
+            id = self.GetNewId()
+            value = dialog.GetStringSelection()
+            jump = SFC_Jump(self, value, id)
+            jump.SetPosition(bbox.x, bbox.y)
+            min_width, min_height = jump.GetMinSize()
+            jump.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
+            self.AddBlock(jump)
+            self.Controler.AddCurrentElementEditingJump(id)
+            self.RefreshJumpModel(jump)
+            self.RefreshBuffer()
+            self.RefreshScrollBars()
+            self.Refresh()
+        dialog.Destroy()
+
+    def AddNewActionBlock(self, bbox):
+        dialog = ActionBlockDialog(self.ParentWindow)
+        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
+        dialog.SetActionList(self.Controler.GetCurrentElementEditingActions())
+        dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars())
+        if dialog.ShowModal() == wx.ID_OK:
+            actions = dialog.GetValues()
+            id = self.GetNewId()
+            actionblock = SFC_ActionBlock(self, actions, id)
+            actionblock.SetPosition(bbox.x, bbox.y)
+            min_width, min_height = actionblock.GetMinSize()
+            actionblock.SetSize(max(bbox.width, min_width), max(bbox.height, min_height))
+            self.AddBlock(actionblock)
+            self.Controler.AddCurrentElementEditingActionBlock(id)
+            self.RefreshActionBlockModel(actionblock)
+            self.RefreshBuffer()
+            self.RefreshScrollBars()
+            self.Refresh()
+        dialog.Destroy()
 
 #-------------------------------------------------------------------------------
 #                          Edit element content functions
@@ -1716,9 +1757,9 @@
                 for element in connector.GetConnectedBlocks():
                     if element not in elements:
                         elements.append(element)
-        powerrrail.Clean()
-        self.RemoveBlock(powerrrail)
-        self.Controler.RemoveCurrentElementEditingInstance(powerrrail.GetId())
+        powerrail.Clean()
+        self.RemoveBlock(powerrail)
+        self.Controler.RemoveCurrentElementEditingInstance(powerrail.GetId())
         for element in elements:
             element.RefreshModel()