Bugs fixed
authorlbessard
Thu, 19 Jul 2007 11:53:14 +0200
changeset 45 42637f721b5b
parent 44 c6e153273ea1
child 46 4379e98a30aa
Bugs fixed
Dialogs.py
LDViewer.py
PLCControler.py
PLCOpenEditor.py
SFCViewer.py
Viewer.py
graphics/__init__.py
--- a/Dialogs.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/Dialogs.py	Thu Jul 19 11:53:14 2007 +0200
@@ -26,9 +26,7 @@
 from wxPython.grid import *
 import wx
 
-from graphics.FBD_Objects import *
-from graphics.LD_Objects import *
-from graphics.SFC_Objects import *
+from graphics import *
 
 #-------------------------------------------------------------------------------
 #                          Create New Block Dialog
--- a/LDViewer.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/LDViewer.py	Thu Jul 19 11:53:14 2007 +0200
@@ -26,11 +26,7 @@
 import wx
 from types import *
 
-from plcopen.structures import *
-from graphics.GraphicCommons import *
-from graphics.FBD_Objects import *
 from Viewer import *
-from Dialogs import *
 
 def ExtractNextBlocks(block, block_list):
     current_list = [block]
--- a/PLCControler.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/PLCControler.py	Thu Jul 19 11:53:14 2007 +0200
@@ -1073,7 +1073,7 @@
                     infos["connectors"]["outputs"].append(connector)
             elif isinstance(instance, plcopen.inVariable):
                 infos["name"] = instance.getExpression()
-                infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"])
+                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
                 infos["type"] = "input"
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
@@ -1081,7 +1081,7 @@
                 infos["connector"]["edge"] = instance.getConnectorEdge()
             elif isinstance(instance, plcopen.outVariable):
                 infos["name"] = instance.getExpression()
-                infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"])
+                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
                 infos["type"] = "output"
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
@@ -1095,7 +1095,7 @@
                         infos["connector"]["links"].append(dic)
             elif isinstance(instance, plcopen.inOutVariable):
                 infos["name"] = instance.getExpression()
-                infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"])
+                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
                 infos["type"] = "inout"
                 infos["connectors"] = {"input":{},"output":{}}
                 infos["connectors"]["output"]["position"] = instance.connectionPointOut.getRelPosition()
@@ -1112,13 +1112,13 @@
                         infos["connectors"]["input"]["links"].append(dic)
             elif isinstance(instance, plcopen.continuation):
                 infos["name"] = instance.getName()
-                infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"])
+                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
                 infos["type"] = "continuation"
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointOut.getRelPosition()
             elif isinstance(instance, plcopen.connector):
                 infos["name"] = instance.getName()
-                infos["value_type"] = self.GetPouVarValueType(self.GetCurrentElementEditing(), infos["name"])
+                infos["value_type"] = self.GetCurrentPouVarValueType(infos["name"])
                 infos["type"] = "connection"
                 infos["connector"] = {}
                 infos["connector"]["position"] = instance.connectionPointIn.getRelPosition()
@@ -1273,7 +1273,13 @@
         return False
     
     # Return the variable type of the given pou
-    def GetPouVarValueType(self, pou, varname):
+    def GetCurrentPouVarValueType(self, varname):
+        current_name = self.ElementsOpened[self.CurrentElementEditing]
+        words = current_name.split("::")
+        if len(words) == 1:
+            pou = self.Project.getPou(current_name)
+        else:
+            pou = self.Project.getPou(words[1])
         for type, varlist in pou.getVars():
             for var in varlist.getVariable():
                 if var.getName() == varname:
--- a/PLCOpenEditor.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/PLCOpenEditor.py	Thu Jul 19 11:53:14 2007 +0200
@@ -35,7 +35,6 @@
 from RessourceEditor import *
 from PLCControler import *
 from plcopen import OpenPDFDoc
-from plcopen.structures import *
 
 import os, re, platform, sys, time, traceback, getopt
 
@@ -908,7 +907,7 @@
                 dialog.Destroy()
                 self.RefreshProjectTree()
             elif item_type == ITEM_CONFIGURATION:
-                dialog = EditVariableDialog(self, item_name, None, name)
+                dialog = EditVariableDialog(self, item_name, None, False, name)
                 dialog.SetPouNames(self.Controler.GetProjectPouNames())
                 values = {"data" : self.Controler.GetConfigurationGlobalVars(item_name)}
                 dialog.SetValues(values)
@@ -925,7 +924,7 @@
                     config_type = self.ProjectTree.GetPyData(config)
                 if config.IsOk():
                     config_name = self.ProjectTree.GetItemText(config)
-                    dialog = EditVariableDialog(self, item_name, None, name)
+                    dialog = EditVariableDialog(self, item_name, None, False, name)
                     values = {"data" : self.Controler.GetConfigurationResourceGlobalVars(config_name, item_name)}
                     dialog.SetValues(values)
                     if dialog.ShowModal() == wxID_OK:
@@ -1192,26 +1191,32 @@
         event.Skip()
 
     def OnAddPouTransitionMenu(self, event):
-        dialog = PouTransitionDialog(self)
-        dialog.SetPous(self.Controler.GetSFCPous())
-        if dialog.ShowModal() == wxID_OK: 
-            values = dialog.GetValues()
-            self.Controler.ProjectAddPouTransition(values["pouName"], values["transitionName"], values["language"])
-            self.RefreshProjectTree()
-        dialog.Destroy()
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
+            pouname = self.ProjectTree.GetItemText(selected)
+            if self.Controler.GetPouBodyType(pouname) == "SFC":
+                dialog = PouTransitionDialog(self)
+                if dialog.ShowModal() == wxID_OK: 
+                    values = dialog.GetValues()
+                    self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"])
+                    self.RefreshProjectTree()
+                dialog.Destroy()
         event.Skip()
 
     def OnRemovePouTransitionMenu(self, event):
         event.Skip()
 
     def OnAddPouActionMenu(self, event):
-        dialog = PouActionDialog(self)
-        dialog.SetPous(self.Controler.GetSFCPous())
-        if dialog.ShowModal() == wxID_OK:
-            values = dialog.GetValues()
-            self.Controler.ProjectAddPouAction(values["pouName"], values["actionName"], values["language"])
-            self.RefreshProjectTree()
-        dialog.Destroy()
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
+            pouname = self.ProjectTree.GetItemText(selected)
+            if self.Controler.GetPouBodyType(pouname) == "SFC":
+                dialog = PouActionDialog(self)
+                if dialog.ShowModal() == wxID_OK:
+                    values = dialog.GetValues()
+                    self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"])
+                    self.RefreshProjectTree()
+                dialog.Destroy()
         event.Skip()
 
     def OnRemovePouActionMenu(self, event):
@@ -1572,10 +1577,9 @@
 #-------------------------------------------------------------------------------
 
 [wxID_POUTRANSITIONDIALOG, wxID_POUTRANSITIONDIALOGMAINPANEL, 
- wxID_POUTRANSITIONDIALOGPOUNAME, wxID_POUTRANSITIONDIALOGTRANSITIONNAME, 
- wxID_POUTRANSITIONDIALOGLANGUAGE, wxID_POUTRANSITIONDIALOGSTATICTEXT1,
- wxID_POUTRANSITIONDIALOGSTATICTEXT2, wxID_POUTRANSITIONDIALOGSTATICTEXT3, 
-] = [wx.NewId() for _init_ctrls in range(8)]
+ wxID_POUTRANSITIONDIALOGTRANSITIONNAME, wxID_POUTRANSITIONDIALOGLANGUAGE, 
+ wxID_POUTRANSITIONDIALOGSTATICTEXT1, wxID_POUTRANSITIONDIALOGSTATICTEXT2,
+] = [wx.NewId() for _init_ctrls in range(6)]
 
 class PouTransitionDialog(wx.Dialog):
     def _init_coll_flexGridSizer1_Items(self, parent):
@@ -1594,10 +1598,10 @@
     def _init_ctrls(self, prnt):
         # generated method, don't edit
         wx.Dialog.__init__(self, id=wxID_POUTRANSITIONDIALOG,
-              name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223),
+              name='PouTransitionDialog', parent=prnt, pos=wx.Point(376, 223),
               size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE,
-              title='Create a new project')
-        self.SetClientSize(wx.Size(350, 200))
+              title='Create a new transition')
+        self.SetClientSize(wx.Size(350, 160))
 
         self.MainPanel = wx.Panel(id=wxID_POUTRANSITIONDIALOGMAINPANEL,
               name='MainPanel', parent=self, pos=wx.Point(0, 0),
@@ -1605,27 +1609,19 @@
         self.MainPanel.SetAutoLayout(True)
 
         self.staticText1 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT1,
-              label='POU Name:', name='staticText1', parent=self.MainPanel,
+              label='Transition Name:', name='staticText1', parent=self.MainPanel,
               pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0)
 
-        self.PouName = wx.Choice(id=wxID_POUTRANSITIONDIALOGPOUNAME,
-              name='POUName', parent=self.MainPanel, pos=wx.Point(154, 24), 
+        self.TransitionName = wx.TextCtrl(id=wxID_POUTRANSITIONDIALOGTRANSITIONNAME,
+              name='TransitionName', parent=self.MainPanel, pos=wx.Point(154, 24),
               size=wx.Size(150, 24), style=0)
 
         self.staticText2 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT2,
-              label='Transition Name:', name='staticText2', parent=self.MainPanel,
+              label='Language:', name='staticText2', parent=self.MainPanel,
               pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0)
 
-        self.TransitionName = wx.TextCtrl(id=wxID_POUTRANSITIONDIALOGTRANSITIONNAME,
-              name='TransitionName', parent=self.MainPanel, pos=wx.Point(154, 64),
-              size=wx.Size(150, 24), style=0)
-
-        self.staticText3 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT3,
-              label='Language:', name='staticText3', parent=self.MainPanel,
-              pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0)
-
         self.Language = wx.Choice(id=wxID_POUTRANSITIONDIALOGLANGUAGE,
-              name='Language', parent=self.MainPanel, pos=wx.Point(154, 104),
+              name='Language', parent=self.MainPanel, pos=wx.Point(154, 64),
               size=wx.Size(150, 24), style=0)
 
         self._init_sizers()
@@ -1634,7 +1630,7 @@
         self._init_ctrls(parent)
         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
-
+        
         for option in ["IL","ST","LD","FBD"]:
             self.Language.Append(option)
         
@@ -1642,8 +1638,6 @@
     
     def OnOK(self, event):
         error = []
-        if self.PouName.GetStringSelection() == "":
-            error.append("POU Name")
         if self.TransitionName.GetValue() == "":
             error.append("Transition Name")
         if self.Language.GetStringSelection() == "":
@@ -1663,22 +1657,15 @@
         else:
             self.EndModal(wxID_OK)
 
-    def SetPous(self, pous):
-        for pou in pous:
-            self.PouName.Append(pou)
-
     def SetValues(self, values):
         for item, value in values.items():
-            if item == "pouName":
-                self.PouName.SetStringSelection(value)
-            elif item == "transitionName":
+            if item == "transitionName":
                 self.TransitionName.SetValue(value)
             elif item == "language":
                 self.Language.SetStringSelection(value)
                 
     def GetValues(self):
         values = {}
-        values["pouName"] = self.PouName.GetStringSelection()
         values["transitionName"] = self.TransitionName.GetValue()
         values["language"] = self.Language.GetStringSelection()
         return values
@@ -1688,10 +1675,9 @@
 #-------------------------------------------------------------------------------
 
 [wxID_POUACTIONDIALOG, wxID_POUACTIONDIALOGMAINPANEL, 
- wxID_POUACTIONDIALOGPOUNAME, wxID_POUACTIONDIALOGACTIONNAME, 
- wxID_POUACTIONDIALOGLANGUAGE, wxID_POUACTIONDIALOGSTATICTEXT1,
- wxID_POUACTIONDIALOGSTATICTEXT2, wxID_POUACTIONDIALOGSTATICTEXT3, 
-] = [wx.NewId() for _init_ctrls in range(8)]
+ wxID_POUACTIONDIALOGACTIONNAME, wxID_POUACTIONDIALOGLANGUAGE, 
+ wxID_POUACTIONDIALOGSTATICTEXT1, wxID_POUACTIONDIALOGSTATICTEXT2, 
+] = [wx.NewId() for _init_ctrls in range(6)]
 
 class PouActionDialog(wx.Dialog):
     def _init_coll_flexGridSizer1_Items(self, parent):
@@ -1710,10 +1696,10 @@
     def _init_ctrls(self, prnt):
         # generated method, don't edit
         wx.Dialog.__init__(self, id=wxID_POUACTIONDIALOG,
-              name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223),
+              name='PouActionDialog', parent=prnt, pos=wx.Point(376, 223),
               size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE,
-              title='Create a new project')
-        self.SetClientSize(wx.Size(320, 200))
+              title='Create a new action')
+        self.SetClientSize(wx.Size(320, 160))
 
         self.MainPanel = wx.Panel(id=wxID_POUACTIONDIALOGMAINPANEL,
               name='MainPanel', parent=self, pos=wx.Point(0, 0),
@@ -1721,27 +1707,19 @@
         self.MainPanel.SetAutoLayout(True)
 
         self.staticText1 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT1,
-              label='POU Name:', name='staticText1', parent=self.MainPanel,
+              label='Action Name:', name='staticText1', parent=self.MainPanel,
               pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0)
 
-        self.PouName = wx.Choice(id=wxID_POUACTIONDIALOGPOUNAME,
-              name='POUName', parent=self.MainPanel, pos=wx.Point(124, 24), 
+        self.ActionName = wx.TextCtrl(id=wxID_POUACTIONDIALOGACTIONNAME,
+              name='ActionName', parent=self.MainPanel, pos=wx.Point(124, 24),
               size=wx.Size(150, 24), style=0)
 
-        self.staticText2 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT2,
-              label='Action Name:', name='staticText2', parent=self.MainPanel,
+        self.staticText3 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT2,
+              label='Language:', name='staticText2', parent=self.MainPanel,
               pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0)
 
-        self.ActionName = wx.TextCtrl(id=wxID_POUACTIONDIALOGACTIONNAME,
-              name='ActionName', parent=self.MainPanel, pos=wx.Point(124, 64),
-              size=wx.Size(150, 24), style=0)
-
-        self.staticText3 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT3,
-              label='Language:', name='staticText3', parent=self.MainPanel,
-              pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0)
-
         self.Language = wx.Choice(id=wxID_POUACTIONDIALOGLANGUAGE,
-              name='Language', parent=self.MainPanel, pos=wx.Point(124, 104),
+              name='Language', parent=self.MainPanel, pos=wx.Point(124, 64),
               size=wx.Size(150, 24), style=0)
 
         self._init_sizers()
@@ -1750,7 +1728,7 @@
         self._init_ctrls(parent)
         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
-
+        
         for option in ["IL","ST","LD","FBD"]:
             self.Language.Append(option)
         
@@ -1758,8 +1736,6 @@
     
     def OnOK(self, event):
         error = []
-        if self.PouName.GetStringSelection() == "":
-            error.append("POU Name")
         if self.ActionName.GetValue() == "":
             error.append("Action Name")
         if self.Language.GetStringSelection() == "":
@@ -1779,22 +1755,15 @@
         else:
             self.EndModal(wxID_OK)
 
-    def SetPous(self, pous):
-        for pou in pous:
-            self.PouName.Append(pou)
-
     def SetValues(self, values):
         for item, value in values.items():
-            if item == "pouName":
-                self.PouName.SetStringSelection(value)
-            elif item == "actionName":
+            if item == "actionName":
                 self.ActionName.SetValue(value)
             elif item == "language":
                 self.Language.SetStringSelection(value)
                 
     def GetValues(self):
         values = {}
-        values["pouName"] = self.PouName.GetStringSelection()
         values["actionName"] = self.ActionName.GetValue()
         values["language"] = self.Language.GetStringSelection()
         return values
--- a/SFCViewer.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/SFCViewer.py	Thu Jul 19 11:53:14 2007 +0200
@@ -26,11 +26,7 @@
 import wx
 from types import *
 
-from plcopen.structures import *
-from graphics.GraphicCommons import *
-from graphics.SFC_Objects import *
 from Viewer import *
-from Dialogs import *
 
 class SFC_Viewer(Viewer):
     
@@ -922,7 +918,7 @@
                 if next:
                     wire = self.ConnectConnectors(next, previous)
                     previous_block = previous.GetParentBlock()
-                    pos = previous.GetPosition(False)
+                    previous_pos = previous.GetPosition(False)
                     next_pos = next.GetPosition(False)
                     wire_size = GetWireSize(previous_block)
                     previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
--- a/Viewer.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/Viewer.py	Thu Jul 19 11:53:14 2007 +0200
@@ -26,10 +26,6 @@
 import wx
 
 from plcopen.structures import *
-from graphics.GraphicCommons import *
-from graphics.FBD_Objects import *
-from graphics.LD_Objects import *
-from graphics.SFC_Objects import *
 
 from Dialogs import *
 
@@ -803,7 +799,7 @@
         elif self.Mode == MODE_WIRE and self.SelectedElement:
             if self.SelectedElement.EndConnected != None:
                 self.SelectedElement.ResetPoints()
-                self.SelectedElement.OnMotion(event, dc, self.Scaling)
+                self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
                 self.SelectedElement.GeneratePoints()
                 self.SelectedElement.RefreshModel()
                 self.SelectedElement.SetSelected(True)
--- a/graphics/__init__.py	Wed Jul 18 16:22:39 2007 +0200
+++ b/graphics/__init__.py	Thu Jul 19 11:53:14 2007 +0200
@@ -26,4 +26,5 @@
 
 from GraphicCommons import *
 from FBD_Objects import *
-from LD_Objects import *
\ No newline at end of file
+from LD_Objects import *
+from SFC_Objects import *
\ No newline at end of file