# HG changeset patch # User lbessard # Date 1176391567 -7200 # Node ID b29105e290814290ae61e7a4e37ce37e1ae1cae7 # Parent 7ceec5c40d77158dc212227a3955d4878cd4d706 Adding test on step names in SFC Editor Adding language icons into project tree diff -r 7ceec5c40d77 -r b29105e29081 FBDViewer.py --- a/FBDViewer.py Wed Apr 11 17:26:07 2007 +0200 +++ b/FBDViewer.py Thu Apr 12 17:26:07 2007 +0200 @@ -471,7 +471,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.Name.SetValue("") self.Name.Enable(False) @@ -670,7 +670,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.Variable = None self.VarList = [] @@ -845,7 +845,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.Connection = None self.MinConnectionSize = None @@ -892,3 +892,4 @@ def OnPaint(self, event): self.RefreshPreview() + diff -r 7ceec5c40d77 -r b29105e29081 Images/FBD.png Binary file Images/FBD.png has changed diff -r 7ceec5c40d77 -r b29105e29081 Images/IL.png Binary file Images/IL.png has changed diff -r 7ceec5c40d77 -r b29105e29081 Images/LD.png Binary file Images/LD.png has changed diff -r 7ceec5c40d77 -r b29105e29081 Images/SFC.png Binary file Images/SFC.png has changed diff -r 7ceec5c40d77 -r b29105e29081 Images/ST.png Binary file Images/ST.png has changed diff -r 7ceec5c40d77 -r b29105e29081 Images/icons.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Images/icons.svg Thu Apr 12 17:26:07 2007 +0200 @@ -0,0 +1,142 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff -r 7ceec5c40d77 -r b29105e29081 LDViewer.py --- a/LDViewer.py Wed Apr 11 17:26:07 2007 +0200 +++ b/LDViewer.py Thu Apr 12 17:26:07 2007 +0200 @@ -1241,7 +1241,7 @@ self.Element = LD_Coil(self.Preview, COIL_NORMAL, "") self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) EVT_PAINT(self, self.OnPaint) diff -r 7ceec5c40d77 -r b29105e29081 PLCOpenEditor.py --- a/PLCOpenEditor.py Wed Apr 11 17:26:07 2007 +0200 +++ b/PLCOpenEditor.py Thu Apr 12 17:26:07 2007 +0200 @@ -68,19 +68,6 @@ fileOpen = args[0] CWD = sys.path[0] - -# Test if identifier is valid -def TestIdentifier(identifier): - if identifier[0].isdigit(): - return False - words = identifier.split('_') - for i, word in enumerate(words): - if len(word) == 0 and i != 0: - return False - if len(word) != 0 and not word.isalnum(): - return False - return True - [wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL, wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR, @@ -393,6 +380,11 @@ def __init__(self, parent): self._init_ctrls(parent) + self.TreeImageList = wxImageList(16, 16) + for language in LANGUAGES: + self.TreeImageList.Add(wxBitmap(os.path.join(CWD, 'Images/%s.png'%language))) + self.ProjectTree.SetImageList(self.TreeImageList) + self.Controler = PLCControler() if fileOpen: @@ -406,46 +398,48 @@ self.RefreshToolBar() def RefreshFileMenu(self): - if self.Controler.HasOpenedProject(): - if self.TabsOpened.GetPageCount() > 0: - self.FileMenu.FindItemByPosition(2).Enable(True) + if self.FileMenu: + if self.Controler.HasOpenedProject(): + if self.TabsOpened.GetPageCount() > 0: + self.FileMenu.FindItemByPosition(2).Enable(True) + else: + self.FileMenu.FindItemByPosition(2).Enable(False) + self.FileMenu.FindItemByPosition(3).Enable(True) + self.FileMenu.FindItemByPosition(5).Enable(True) + self.FileMenu.FindItemByPosition(6).Enable(True) + self.FileMenu.FindItemByPosition(7).Enable(True) + self.FileMenu.FindItemByPosition(9).Enable(True) else: self.FileMenu.FindItemByPosition(2).Enable(False) - self.FileMenu.FindItemByPosition(3).Enable(True) - self.FileMenu.FindItemByPosition(5).Enable(True) - self.FileMenu.FindItemByPosition(6).Enable(True) - self.FileMenu.FindItemByPosition(7).Enable(True) - self.FileMenu.FindItemByPosition(9).Enable(True) - else: - self.FileMenu.FindItemByPosition(2).Enable(False) - self.FileMenu.FindItemByPosition(3).Enable(False) - self.FileMenu.FindItemByPosition(5).Enable(False) - self.FileMenu.FindItemByPosition(6).Enable(False) - self.FileMenu.FindItemByPosition(7).Enable(False) - self.FileMenu.FindItemByPosition(9).Enable(False) + self.FileMenu.FindItemByPosition(3).Enable(False) + self.FileMenu.FindItemByPosition(5).Enable(False) + self.FileMenu.FindItemByPosition(6).Enable(False) + self.FileMenu.FindItemByPosition(7).Enable(False) + self.FileMenu.FindItemByPosition(9).Enable(False) def RefreshEditMenu(self): - self.EditMenu.FindItemByPosition(1).Enable(False) - self.EditMenu.FindItemByPosition(2).Enable(False) - if self.Controler.HasOpenedProject(): - if self.TabsOpened.GetPageCount() > 0: - self.EditMenu.FindItemByPosition(0).Enable(True) + if self.EditMenu: + self.EditMenu.FindItemByPosition(1).Enable(False) + self.EditMenu.FindItemByPosition(2).Enable(False) + if self.Controler.HasOpenedProject(): + if self.TabsOpened.GetPageCount() > 0: + self.EditMenu.FindItemByPosition(0).Enable(True) + else: + self.EditMenu.FindItemByPosition(0).Enable(False) + self.EditMenu.FindItemByPosition(8).Enable(True) + self.EditMenu.FindItemByPosition(9).Enable(True) else: self.EditMenu.FindItemByPosition(0).Enable(False) - self.EditMenu.FindItemByPosition(8).Enable(True) - self.EditMenu.FindItemByPosition(9).Enable(True) - else: - self.EditMenu.FindItemByPosition(0).Enable(False) - self.EditMenu.FindItemByPosition(8).Enable(False) - self.EditMenu.FindItemByPosition(9).Enable(False) - bodytype = self.Controler.GetCurrentElementEditingBodyType() - if bodytype in ["IL","ST"]: - self.EditMenu.FindItemByPosition(4).Enable(True) - self.EditMenu.FindItemByPosition(5).Enable(True) - self.EditMenu.FindItemByPosition(6).Enable(True) - else: - self.EditMenu.FindItemByPosition(4).Enable(False) - self.EditMenu.FindItemByPosition(5).Enable(False) + self.EditMenu.FindItemByPosition(8).Enable(False) + self.EditMenu.FindItemByPosition(9).Enable(False) + bodytype = self.Controler.GetCurrentElementEditingBodyType() + if bodytype in ["IL","ST"]: + self.EditMenu.FindItemByPosition(4).Enable(True) + self.EditMenu.FindItemByPosition(5).Enable(True) + self.EditMenu.FindItemByPosition(6).Enable(True) + else: + self.EditMenu.FindItemByPosition(4).Enable(False) + self.EditMenu.FindItemByPosition(5).Enable(False) self.EditMenu.FindItemByPosition(6).Enable(False) def OnNewProjectMenu(self, event): @@ -1005,6 +999,8 @@ else: root = self.ProjectTree.AddRoot(infos["name"]) self.ProjectTree.SetPyData(root, infos["type"]) + if infos["type"] == ITEM_POU: + self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) item, root_cookie = self.ProjectTree.GetFirstChild(root) if len(infos["values"]) > 0: for values in infos["values"]: @@ -1348,7 +1344,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) @@ -1474,7 +1470,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) for option in ["function","functionBlock","program"]: @@ -1619,7 +1615,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) for option in ["IL","ST","LD","FBD"]: @@ -1735,7 +1731,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) for option in ["IL","ST","LD","FBD"]: @@ -2028,7 +2024,7 @@ def __init__(self, parent, name, pou_type, filter = "All"): self._init_ctrls(parent, name) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.Filter = filter self.FilterChoices = [] diff -r 7ceec5c40d77 -r b29105e29081 SFCViewer.py --- a/SFCViewer.py Wed Apr 11 17:26:07 2007 +0200 +++ b/SFCViewer.py Thu Apr 12 17:26:07 2007 +0200 @@ -329,7 +329,10 @@ #------------------------------------------------------------------------------- def AddInitialStep(self, pos): - dialog = wxTextEntryDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wxOK|wxCANCEL) + dialog = StepNameDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wxOK|wxCANCEL) + dialog.SetPouNames(self.Controler.GetProjectPouNames()) + dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) + dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) if dialog.ShowModal() == wxID_OK: id = self.GetNewId() name = dialog.GetValue() @@ -348,7 +351,10 @@ def AddStep(self): if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): - dialog = wxTextEntryDialog(self.Parent, "Add a new step", "Please enter step name", "", wxOK|wxCANCEL) + dialog = StepNameDialog(self.Parent, "Add a new step", "Please enter step name", "", wxOK|wxCANCEL) + dialog.SetPouNames(self.Controler.GetProjectPouNames()) + dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) + dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) if dialog.ShowModal() == wxID_OK: name = dialog.GetValue() if self.SelectedElement in self.Wires: @@ -688,7 +694,10 @@ dialog.Destroy() def EditStepContent(self, step): - dialog = wxTextEntryDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wxOK|wxCANCEL) + dialog = StepNameDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wxOK|wxCANCEL) + dialog.SetPouNames(self.Controler.GetProjectPouNames()) + dialog.SetVariables(self.Controler.GetCurrentElementEditingInterfaceVars()) + dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) if dialog.ShowModal() == wxID_OK: value = dialog.GetValue() step.SetName(value) @@ -1069,7 +1078,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) @@ -1221,7 +1230,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.Divergence = None @@ -1508,7 +1517,7 @@ def __init__(self, parent): self._init_ctrls(parent) - self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) + self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} @@ -1609,3 +1618,58 @@ action["indicator"] = data["Indicator"] values.append(action) return values + + +#------------------------------------------------------------------------------- +# Edit Step Name Dialog +#------------------------------------------------------------------------------- + +class StepNameDialog(wxTextEntryDialog): + + def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", + style = wxOK|wxCANCEL|wxCENTRE, pos = wxDefaultPosition): + wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) + + self.PouNames = [] + self.Variables = [] + self.StepNames = [] + + EVT_BUTTON(self, self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId(), self.OnOK) + + def OnOK(self, event): + step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() + if step_name == "": + message = wxMessageDialog(self, "You must type a name!", "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + elif not TestIdentifier(step_name): + message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + elif step_name.upper() in IEC_KEYWORDS: + message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + elif step_name.upper() in self.PouNames: + message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + elif step_name.upper() in self.Variables: + message = wxMessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + elif step_name.upper() in self.StepNames: + message = wxMessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wxOK|wxICON_ERROR) + message.ShowModal() + message.Destroy() + else: + self.EndModal(wxID_OK) + + def SetPouNames(self, pou_names): + self.PouNames = [pou_name.upper() for pou_name in pou_names] + + def SetVariables(self, variables): + self.Variables = [var["Name"].upper() for var in variables] + + def SetStepNames(self, step_names): + self.StepNames = [step_name.upper() for step_name in step_names] diff -r 7ceec5c40d77 -r b29105e29081 plcopen/structures.py --- a/plcopen/structures.py Wed Apr 11 17:26:07 2007 +0200 +++ b/plcopen/structures.py Thu Apr 12 17:26:07 2007 +0200 @@ -23,6 +23,8 @@ #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +LANGUAGES = ["IL","ST","FBD","LD","SFC"] + #------------------------------------------------------------------------------- # Function Block Types definitions #------------------------------------------------------------------------------- @@ -377,6 +379,24 @@ #------------------------------------------------------------------------------- +# Test identifier +#------------------------------------------------------------------------------- + + + +# Test if identifier is valid +def TestIdentifier(identifier): + if identifier[0].isdigit(): + return False + words = identifier.split('_') + for i, word in enumerate(words): + if len(word) == 0 and i != 0: + return False + if len(word) != 0 and not word.isalnum(): + return False + return True + +#------------------------------------------------------------------------------- # Languages Keywords #-------------------------------------------------------------------------------