Adding error messages on LD editor
authorlbessard
Tue, 10 Apr 2007 18:02:40 +0200
changeset 7 f1691e685c49
parent 6 c8cf918ee7ea
child 8 7ceec5c40d77
Adding error messages on LD editor
Adding Drag and Drop on ST and IL Editors
LDViewer.py
PLCOpenEditor.py
graphics/LD_Objects.py
--- a/LDViewer.py	Fri Apr 06 18:06:00 2007 +0200
+++ b/LDViewer.py	Tue Apr 10 18:02:40 2007 +0200
@@ -550,6 +550,10 @@
                 new_bbox = rung.GetBoundingBox()
                 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
                 self.Refresh()
+        else:
+            message = wxMessageDialog(self, "You must select the wire where a contact should be added!", "Error", wxOK|wxICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
 
     def AddBranch(self):
         blocks = []
@@ -645,7 +649,7 @@
                 right_elements = [element for element in infos["rights"]]
                 for right_element in right_elements:
                     if isinstance(right_element.GetParentBlock(), LD_PowerRail):
-                        infos["rights"].remove(tight_element)
+                        infos["rights"].remove(right_element)
                         if "LD_PowerRail" not in infos["rights"]:
                             infos["rights"].append("LD_PowerRail")
                 infos["lefts"].sort()
@@ -688,7 +692,60 @@
                             rung.SelectElement(new_wire)
                         right_elements.reverse()
                     elif right_powerrail:
-                        pass
+                        dialog = LDElementDialog(self.Parent, "coil")
+                        varlist = []
+                        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
+                        if vars:
+                            for var in vars:
+                                if var["Class"] != "Input" and var["Type"] == "BOOL":
+                                    varlist.append(var["Name"])
+                        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
+                        if returntype == "BOOL":
+                            varlist.append(self.Controler.GetCurrentElementEditingName())
+                        dialog.SetVariables(varlist)
+                        dialog.SetValues({"name":"","type":COIL_NORMAL})
+                        if dialog.ShowModal() == wxID_OK:
+                            values = dialog.GetValues()
+                            powerrail = right_elements[0].GetParentBlock()
+                            index = 0
+                            for right_element in right_elements: 
+                                index = max(index, powerrail.GetConnectorIndex(right_element))
+                            if powerrail.IsNullConnector(index + 1):
+                                powerrail.DeleteConnector(index + 1)
+                            powerrail.InsertConnector(index + 1)
+                            powerrail.RefreshModel()
+                            connectors = powerrail.GetConnectors()
+                            # Create Coil
+                            id = self.GetNewId()
+                            coil = LD_Coil(self, values["type"], values["name"], id)
+                            pos = blocks[0].GetPosition()
+                            coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE)
+                            self.Elements.append(coil)
+                            self.Blocks.append(coil)
+                            rung.SelectElement(coil)
+                            self.Controler.AddCurrentElementEditingCoil(id)
+                            coil_connectors = coil.GetConnectors()
+                            # Create Wire between LeftPowerRail and Coil
+                            wire = Wire(self)
+                            connectors[index + 1].Connect((wire, 0), False)
+                            coil_connectors["output"].Connect((wire, -1), False)
+                            wire.ConnectStartPoint(None, connectors[index + 1])
+                            wire.ConnectEndPoint(None, coil_connectors["output"])
+                            self.Wires.append(wire)
+                            self.Elements.append(wire)
+                            rung.SelectElement(wire)                                
+                            for i, left_element in enumerate(left_elements):
+                                # Create Wire between LeftPowerRail and Coil
+                                new_wire = Wire(self)
+                                coil_connectors["input"].Connect((new_wire, 0), False)
+                                left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False)
+                                new_wire.ConnectStartPoint(None, coil_connectors["input"])
+                                new_wire.ConnectEndPoint(None, left_element)
+                                self.Wires.append(new_wire)
+                                self.Elements.append(new_wire)
+                                rung.SelectElement(new_wire)
+                            left_elements.reverse()
+                            self.RefreshPosition(coil)
                     else:
                         left_elements.reverse()
                         right_elements.reverse()
@@ -720,6 +777,20 @@
                 new_bbox = rung.GetBoundingBox()
                 self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
                 self.Refresh()
+            else:
+                message = wxMessageDialog(self, "The group of block must be coherent!", "Error", wxOK|wxICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+        else:
+            message = wxMessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wxOK|wxICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+
+
+    def AddBlock(self):
+        message = wxMessageDialog(self, "This option isn't available yet!", "Warning", wxOK|wxICON_EXCLAMATION)
+        message.ShowModal()
+        message.Destroy()
 
 #-------------------------------------------------------------------------------
 #                          Delete element functions
--- a/PLCOpenEditor.py	Fri Apr 06 18:06:00 2007 +0200
+++ b/PLCOpenEditor.py	Tue Apr 10 18:02:40 2007 +0200
@@ -345,6 +345,38 @@
         self._init_utils()
         self.SetClientSize(wx.Size(1000, 600))
         self.SetMenuBar(self.menuBar1)
+        
+        self.splitterWindow1 = wx.SplitterWindow(id=wxID_PLCOPENEDITORSPLITTERWINDOW1,
+              name='splitterWindow1', parent=self, point=wx.Point(0, 0),
+              size=wx.Size(-1, -1), style=wx.SP_3D)
+        self.splitterWindow1.SetNeedUpdating(True)
+        self.splitterWindow1.SetMinimumPaneSize(1)
+
+        self.EditorPanel = wx.Panel(id=wxID_PLCOPENEDITOREDITORPANEL, 
+              name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0),
+              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
+        
+        self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED,
+              name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0,
+              0), size=wx.Size(-1, -1), style=0)
+        self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
+              self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED)
+
+        self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar',
+              parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40),
+              style=wxTB_HORIZONTAL | wxNO_BORDER)
+        self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARITEMS0, 
+              wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object")
+        self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
+              id=wxID_PLCOPENEDITORTOOLBARITEMS0)
+        
+        self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE,
+              name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0),
+              size=wx.Size(-1, -1),
+              style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
+        self.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
+        self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
+              id=wxID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
               id=wxID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit,
@@ -353,36 +385,6 @@
               id=wxID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected,
               id=wxID_PLCOPENEDITORPROJECTTREE)
-        
-        self.splitterWindow1 = wx.SplitterWindow(id=wxID_PLCOPENEDITORSPLITTERWINDOW1,
-              name='splitterWindow1', parent=self, point=wx.Point(0, 0),
-              size=wx.Size(-1, -1), style=wx.SP_3D)
-        self.splitterWindow1.SetNeedUpdating(True)
-        self.splitterWindow1.SetMinimumPaneSize(1)
-
-        self.EditorPanel = wx.Panel(id=wxID_PLCOPENEDITOREDITORPANEL, 
-              name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0),
-              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
-        
-        self.TabsOpened = wx.Notebook(id=wxID_PLCOPENEDITORTABSOPENED,
-              name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0,
-              0), size=wx.Size(-1, -1), style=0)
-        self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
-              self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED)
-
-        self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar',
-              parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40),
-              style=wxTB_HORIZONTAL | wxNO_BORDER)
-        self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARITEMS0, 
-              wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object")
-        self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
-              id=wxID_PLCOPENEDITORTOOLBARITEMS0)
-        
-        self.ProjectTree = wx.TreeCtrl(id=wxID_PLCOPENEDITORPROJECTTREE,
-              name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0),
-              size=wx.Size(-1, -1),
-              style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
-        self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
         self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel,
               200)
               
@@ -662,7 +664,7 @@
     def OnLDBlockTool(self, event):
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
-            pass
+            self.TabsOpened.GetPage(selected).AddBlock()
         event.Skip()
     
     def OnLDBranchTool(self, event): 
@@ -688,6 +690,15 @@
             self.RefreshToolBar()
         event.Skip()
 
+    def OnProjectTreeBeginDrag(self, event):
+        item = event.GetItem()
+        if self.ProjectTree.GetPyData(item) == ITEM_VARIABLE:
+            data = wxTextDataObject(self.ProjectTree.GetItemText(item))
+            dragSource = wxDropSource(self.ProjectTree)
+            dragSource.SetData(data)
+            dragSource.DoDragDrop()
+        event.Skip()
+
     def OnProjectTreeItemEndEdit(self, event):
         message = None
         abort = False
--- a/graphics/LD_Objects.py	Fri Apr 06 18:06:00 2007 +0200
+++ b/graphics/LD_Objects.py	Tue Apr 10 18:02:40 2007 +0200
@@ -133,7 +133,7 @@
             position += LD_LINE_SIZE
         self.RefreshConnected()
     
-    # Refresh the position of wires connefcted to power rail
+    # Refresh the position of wires connected to power rail
     def RefreshConnected(self, exclude = []):
         for connector in self.Connectors:
             connector.MoveConnected(exclude)