PLCOpenEditor.py
changeset 45 42637f721b5b
parent 42 4a8400732001
child 46 4379e98a30aa
--- 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