--- a/PLCOpenEditor.py Wed Mar 21 16:38:28 2007 +0100
+++ b/PLCOpenEditor.py Fri Apr 06 18:06:00 2007 +0200
@@ -66,6 +66,7 @@
sys.exit()
elif len(args) == 1:
fileOpen = args[0]
+CWD = sys.path[0]
# Test if identifier is valid
@@ -81,29 +82,30 @@
return True
[wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE,
- wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITORTABSOPENED,
- wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR,
+ wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL,
+ wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR,
+ wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR,
wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR,
-] = [wx.NewId() for _init_ctrls in range(8)]
-
-[wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0,
+] = [wx.NewId() for _init_ctrls in range(10)]
+
+[wxID_PLCOPENEDITORTOOLBARITEMS0,
] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(1)]
-[wxID_PLCOPENEDITORSFCTOOLBARITEMS0, wxID_PLCOPENEDITORSFCTOOLBARITEMS1,
+SFC_ITEMS = [wxID_PLCOPENEDITORSFCTOOLBARITEMS1,
wxID_PLCOPENEDITORSFCTOOLBARITEMS2, wxID_PLCOPENEDITORSFCTOOLBARITEMS3,
wxID_PLCOPENEDITORSFCTOOLBARITEMS4, wxID_PLCOPENEDITORSFCTOOLBARITEMS5,
wxID_PLCOPENEDITORSFCTOOLBARITEMS6,
-] = [wx.NewId() for _init_coll_SFCToolBar_Items in range(7)]
-
-[wxID_PLCOPENEDITORFBDTOOLBARITEMS0, wxID_PLCOPENEDITORFBDTOOLBARITEMS1,
+] = [wx.NewId() for _init_coll_SFCToolBar_Items in range(6)]
+
+FBD_ITEMS = [wxID_PLCOPENEDITORFBDTOOLBARITEMS1,
wxID_PLCOPENEDITORFBDTOOLBARITEMS2, wxID_PLCOPENEDITORFBDTOOLBARITEMS3,
wxID_PLCOPENEDITORFBDTOOLBARITEMS4, wxID_PLCOPENEDITORFBDTOOLBARITEMS5,
-] = [wx.NewId() for _init_coll_FBDToolBar_Items in range(6)]
-
-[wxID_PLCOPENEDITORLDTOOLBARITEMS0, wxID_PLCOPENEDITORLDTOOLBARITEMS1,
+] = [wx.NewId() for _init_coll_FBDToolBar_Items in range(5)]
+
+LD_ITEMS = [wxID_PLCOPENEDITORLDTOOLBARITEMS1,
wxID_PLCOPENEDITORLDTOOLBARITEMS2, wxID_PLCOPENEDITORLDTOOLBARITEMS3,
wxID_PLCOPENEDITORLDTOOLBARITEMS4,
-] = [wx.NewId() for _init_coll_LDToolBar_Items in range(5)]
+] = [wx.NewId() for _init_coll_LDToolBar_Items in range(4)]
[wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1,
wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3,
@@ -303,20 +305,37 @@
parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW)
+ def _init_coll_EditorGridSizer_Items(self, parent):
+ # generated method, don't edit
+
+ parent.AddWindow(self.ToolBar, 0, border=0, flag=wxGROW)
+ parent.AddWindow(self.TabsOpened, 0, border=0, flag=wxGROW)
+
def _init_coll_MainGridSizer_Growables(self, parent):
# generated method, don't edit
parent.AddGrowableCol(0)
parent.AddGrowableRow(0)
+ def _init_coll_EditorGridSizer_Growables(self, parent):
+ # generated method, don't edit
+
+ parent.AddGrowableCol(0)
+ parent.AddGrowableRow(1)
+
def _init_sizers(self):
# generated method, don't edit
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
+ self.EditorGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
+
self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
self._init_coll_MainGridSizer_Items(self.MainGridSizer)
-
+ self._init_coll_EditorGridSizer_Growables(self.EditorGridSizer)
+ self._init_coll_EditorGridSizer_Items(self.EditorGridSizer)
+
self.SetSizer(self.MainGridSizer)
+ self.EditorPanel.SetSizer(self.EditorGridSizer)
def _init_ctrls(self, prnt):
# generated method, don't edit
@@ -341,131 +360,36 @@
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.splitterWindow1, pos=wx.Point(0,
+ 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.TabsOpened,
+ self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel,
200)
self._init_sizers()
- def init_coll_DefaultToolBar_Items(self, parent):
- parent.AddRadioTool(wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0,
- wxBitmap('Images/select.png'), wxNullBitmap, "Select an object")
- self.Bind(wx.EVT_TOOL, self.OnSelectionTool,
- id=wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0)
-
- def init_coll_SFCToolBar_Items(self, parent):
- parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS0,
- wxBitmap('Images/select.png'), wxNullBitmap, "Select an object")
- parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS1,
- wxBitmap('Images/comment.png'), wxNullBitmap, "Create a new comment")
- parent.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS2,
- wxBitmap('Images/initial_step.png'), wxNullBitmap, "Create a new initial step")
- parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS3,
- wxBitmap('Images/step.png'), "Create a new step")
- parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS4,
- wxBitmap('Images/action.png'), "Add action block to step")
- parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS5,
- wxBitmap('Images/divergence.png'), "Create a new divergence")
- parent.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS6,
- wxBitmap('Images/jump.png'), "Create a new jump")
- self.Bind(wx.EVT_TOOL, self.OnSelectionTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS0)
- self.Bind(wx.EVT_TOOL, self.OnCommentTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS1)
- self.Bind(wx.EVT_TOOL, self.OnSFCInitialStepTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS2)
- self.Bind(wx.EVT_TOOL, self.OnSFCStepTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS3)
- self.Bind(wx.EVT_TOOL, self.OnSFCActionBlockTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS4)
- self.Bind(wx.EVT_TOOL, self.OnSFCDivergenceTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS5)
- self.Bind(wx.EVT_TOOL, self.OnSFCJumpTool,
- id=wxID_PLCOPENEDITORSFCTOOLBARITEMS6)
-
- def init_coll_FBDToolBar_Items(self, parent):
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS0,
- wxBitmap('Images/select.png'), wxNullBitmap, "Select an object")
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS1,
- wxBitmap('Images/comment.png'), wxNullBitmap, "Create a new comment")
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS2,
- wxBitmap('Images/variable.png'), wxNullBitmap, "Create a new variable")
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS3,
- wxBitmap('Images/block.png'), wxNullBitmap, "Create a new block")
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS4,
- wxBitmap('Images/connection.png'), wxNullBitmap, "Create a new connection")
- parent.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS5,
- wxBitmap('Images/wire.png'), wxNullBitmap, "Create a new wire")
- self.Bind(wx.EVT_TOOL, self.OnSelectionTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS0)
- self.Bind(wx.EVT_TOOL, self.OnCommentTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS1)
- self.Bind(wx.EVT_TOOL, self.OnFBDVariableTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS2)
- self.Bind(wx.EVT_TOOL, self.OnFBDBlockTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS3)
- self.Bind(wx.EVT_TOOL, self.OnFBDConnectionTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS4)
- self.Bind(wx.EVT_TOOL, self.OnWireTool,
- id=wxID_PLCOPENEDITORFBDTOOLBARITEMS5)
-
- def init_coll_LDToolBar_Items(self, parent):
- parent.AddRadioTool(wxID_PLCOPENEDITORLDTOOLBARITEMS0,
- wxBitmap('Images/select.png'), wxNullBitmap, "Select an object")
- parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS1,
- wxBitmap('Images/coil.png'), "Create a new rung")
- parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS2,
- wxBitmap('Images/contact.png'), "Create a new contact")
- parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS3,
- wxBitmap('Images/block.png'), "Create a new block")
- parent.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS4,
- wxBitmap('Images/branch.png'), "Create a new branch")
- self.Bind(wx.EVT_TOOL, self.OnSelectionTool,
- id=wxID_PLCOPENEDITORLDTOOLBARITEMS0)
- self.Bind(wx.EVT_TOOL, self.OnLDCoilTool,
- id=wxID_PLCOPENEDITORLDTOOLBARITEMS1)
- self.Bind(wx.EVT_TOOL, self.OnLDContactTool,
- id=wxID_PLCOPENEDITORLDTOOLBARITEMS2)
- self.Bind(wx.EVT_TOOL, self.OnLDBlockTool,
- id=wxID_PLCOPENEDITORLDTOOLBARITEMS3)
- self.Bind(wx.EVT_TOOL, self.OnLDBranchTool,
- id=wxID_PLCOPENEDITORLDTOOLBARITEMS4)
-
- def init_toolbars(self):
- self.DefaultToolBar = wxToolBar(id=wxID_PLCOPENEDITORDEFAULTTOOLBAR, name='DefaultToolBar',
- parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0),
- style=wxTB_HORIZONTAL | wxNO_BORDER)
-
- self.SFCToolBar = wxToolBar(id=wxID_PLCOPENEDITORSFCTOOLBAR, name='SFCToolBar',
- parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0),
- style=wxTB_HORIZONTAL | wxNO_BORDER)
-
- self.FBDToolBar = wxToolBar(id=wxID_PLCOPENEDITORFBDTOOLBAR, name='FBDToolBar',
- parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0),
- style=wxTB_HORIZONTAL | wxNO_BORDER)
-
- self.LDToolBar = wxToolBar(id=wxID_PLCOPENEDITORLDTOOLBAR, name='LDToolBar',
- parent=self, pos=wx.Point(0, 27), size=wx.Size(0, 0),
- style=wxTB_HORIZONTAL | wxNO_BORDER)
-
- self.init_coll_DefaultToolBar_Items(self.DefaultToolBar)
- self.init_coll_SFCToolBar_Items(self.SFCToolBar)
- self.init_coll_FBDToolBar_Items(self.FBDToolBar)
- self.init_coll_LDToolBar_Items(self.LDToolBar)
-
def __init__(self, parent):
self._init_ctrls(parent)
- self.init_toolbars()
self.Controler = PLCControler()
@@ -473,6 +397,8 @@
self.Controler.OpenXMLFile(fileOpen)
self.RefreshProjectTree()
+ self.CurrentToolBar = []
+
self.RefreshFileMenu()
self.RefreshEditMenu()
self.RefreshToolBar()
@@ -625,22 +551,22 @@
dialog.Destroy()
def OnQuitMenu(self, event):
+ self.ToolBar.Reparent(self)
+ self.Controler.Reset()
self.Close()
event.Skip()
def ResetCurrentMode(self):
selected = self.TabsOpened.GetSelection()
if selected != -1:
- self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION)
- language = self.Controler.GetCurrentElementEditingBodyType()
- if language == "SFC":
- self.SFCToolBar.ToggleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS0, True)
- elif language == "FBD":
- self.FBDToolBar.ToggleTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS0, True)
- elif language == "LD":
- self.LDToolBar.ToggleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS0, True)
- else:
- self.DefaultToolBar.ToggleTool(wxID_PLCOPENEDITORDEFAULTTOOLBARITEMS0, True)
+ window = self.TabsOpened.GetPage(selected)
+ if not isinstance(window, TextViewer):
+ window.SetMode(MODE_SELECTION)
+ self.ToolBar.ToggleTool(wxID_PLCOPENEDITORTOOLBARITEMS0, True)
+
+ def ResetToolToggle(self, id):
+ tool = self.ToolBar.FindById(id)
+ tool.SetToggle(False)
def OnSelectionTool(self, event):
selected = self.TabsOpened.GetSelection()
@@ -648,19 +574,15 @@
self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION)
event.Skip()
- def OnCommentTool(self, event):
+ def OnSFCCommentTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS1)
selected = self.TabsOpened.GetSelection()
if selected != -1:
self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
event.Skip()
-
- def OnWireTool(self, event):
- selected = self.TabsOpened.GetSelection()
- if selected != -1:
- self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE)
- event.Skip()
def OnSFCInitialStepTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORSFCTOOLBARITEMS2)
selected = self.TabsOpened.GetSelection()
if selected != -1:
self.TabsOpened.GetPage(selected).SetMode(MODE_INITIAL_STEP)
@@ -690,24 +612,41 @@
self.TabsOpened.GetPage(selected).AddJump()
event.Skip()
+ def OnFBDCommentTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS1)
+ selected = self.TabsOpened.GetSelection()
+ if selected != -1:
+ self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
+ event.Skip()
+
def OnFBDVariableTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS2)
selected = self.TabsOpened.GetSelection()
if selected != -1:
self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)
event.Skip()
def OnFBDBlockTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS3)
selected = self.TabsOpened.GetSelection()
if selected != -1:
self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK)
event.Skip()
def OnFBDConnectionTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS4)
selected = self.TabsOpened.GetSelection()
if selected != -1:
self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION)
event.Skip()
+ def OnFBDWireTool(self, event):
+ self.ResetToolToggle(wxID_PLCOPENEDITORFBDTOOLBARITEMS5)
+ selected = self.TabsOpened.GetSelection()
+ if selected != -1:
+ self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE)
+ event.Skip()
+
def OnLDCoilTool(self, event):
selected = self.TabsOpened.GetSelection()
if selected != -1:
@@ -750,40 +689,81 @@
event.Skip()
def OnProjectTreeItemEndEdit(self, event):
+ message = None
+ abort = False
new_name = event.GetLabel()
if new_name != "":
- if TestIdentifier(new_name):
+ if not TestIdentifier(new_name):
+ message = "\"%s\" is not a valid identifier!"%new_name
+ elif new_name.upper() in IEC_KEYWORDS:
+ message = "\"%s\" is a keyword. It can't be used!"%new_name
+ else:
item = event.GetItem()
itemtype = self.ProjectTree.GetPyData(item)
if itemtype == ITEM_PROJECT:
self.Controler.SetProjectName(new_name)
elif itemtype == ITEM_POU:
- old_name = self.ProjectTree.GetItemText(item)
- self.Controler.ChangePouName(old_name, new_name)
- self.RefreshTabsOpenedTitles()
+ if new_name.upper() in self.Controler.GetProjectPouNames():
+ message = "\"%s\" pou already exists!"%new_name
+ abort = True
+ elif new_name.upper() in self.Controler.GetProjectPouVariables():
+ messageDialog = wxMessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wxYES_NO|wxICON_QUESTION)
+ if messageDialog.ShowModal() == wxID_NO:
+ abort = True
+ messageDialog.Destroy()
+ if not abort:
+ old_name = self.ProjectTree.GetItemText(item)
+ self.Controler.ChangePouName(old_name, new_name)
+ self.RefreshTabsOpenedTitles()
elif itemtype == ITEM_TRANSITION:
- old_name = self.ProjectTree.GetItemText(item)
- parent = self.ProjectTree.GetItemParent(item)
- grandparent = self.ProjectTree.GetItemParent(parent)
- grandparent_name = self.ProjectTree.GetItemText(grandparent)
- self.Controler.ChangePouTransitionName(grandparent_name, old_name, new_name)
- self.RefreshTabsOpenedTitles()
+ category = self.ProjectTree.GetItemParent(item)
+ pou = self.ProjectTree.GetItemParent(category)
+ pou_name = self.ProjectTree.GetItemText(pou)
+ if new_name.upper() in self.Controler.GetProjectPouNames():
+ message = "A pou with \"%s\" as name exists!"%new_name
+ elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name):
+ message = "A variable with \"%s\" as name already exists in this pou!"%new_name
+ else:
+ old_name = self.ProjectTree.GetItemText(item)
+ self.Controler.ChangePouTransitionName(pou_name, old_name, new_name)
+ self.RefreshTabsOpenedTitles()
elif itemtype == ITEM_ACTION:
- old_name = self.ProjectTree.GetItemText(item)
- parent = self.ProjectTree.GetItemParent(item)
- grandparent = self.ProjectTree.GetItemParent(parent)
- grandparent_name = self.ProjectTree.GetItemText(grandparent)
- self.Controler.ChangePouActionName(grandparent_name, old_name, new_name)
- self.RefreshTabsOpenedTitles()
- wxCallAfter(self.RefreshProjectTree)
- event.Skip()
- else:
- message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%new_name, "Error", wxOK|wxICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ category = self.ProjectTree.GetItemParent(item)
+ pou = self.ProjectTree.GetItemParent(category)
+ pou_name = self.ProjectTree.GetItemText(pou)
+ if new_name.upper() in self.Controler.GetProjectPouNames():
+ message = "A pou with \"%s\" as name exists!"%new_name
+ elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name):
+ message = "A variable with \"%s\" as name already exists in this pou!"%new_name
+ else:
+ old_name = self.ProjectTree.GetItemText(item)
+ self.Controler.ChangePouActionName(pou_name, old_name, new_name)
+ self.RefreshTabsOpenedTitles()
+ elif itemtype == ITEM_VARIABLE:
+ category = self.ProjectTree.GetItemParent(item)
+ if self.ProjectTree.GetItemText(category) != 'Global':
+ category = self.ProjectTree.GetItemParent(category)
+ pou = self.ProjectTree.GetItemParent(category)
+ pou_name = self.ProjectTree.GetItemText(pou)
+ if new_name.upper() in self.Controler.GetProjectPouNames():
+ message = "A pou with \"%s\" as name exists!"%new_name
+ elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name):
+ message = "A variable with \"%s\" as name already exists in this pou!"%new_name
+ else:
+ old_name = self.ProjectTree.GetItemText(item)
+ self.Controler.ChangePouVariableName(pou_name, old_name, new_name)
+ self.RefreshTabsOpenedTitles()
+ if message or abort:
+ if message:
+ messageDialog = wxMessageDialog(self, message, "Error", wxOK|wxICON_ERROR)
+ messageDialog.ShowModal()
+ messageDialog.Destroy()
item = event.GetItem()
wxCallAfter(self.ProjectTree.EditLabel, item)
event.Veto()
+ else:
+ wxCallAfter(self.RefreshProjectTree)
+ event.Skip()
def OnProjectTreeItemBeginEdit(self, event):
selected = event.GetItem()
@@ -821,6 +801,7 @@
item_type = self.ProjectTree.GetPyData(item)
pou_name = self.ProjectTree.GetItemText(item)
dialog = EditVariableDialog(self, pou_name, self.Controler.GetPouType(pou_name), name)
+ dialog.SetPouNames(self.Controler.GetProjectPouNames())
values = {}
values["returnType"] = self.Controler.GetPouInterfaceReturnTypeByName(pou_name)
values["data"] = self.Controler.GetPouInterfaceVarsByName(pou_name)
@@ -846,10 +827,12 @@
message.ShowModal()
message.Destroy()
dialog.Destroy()
+ self.RefreshProjectTree()
elif name == "Global Vars":
parent = self.ProjectTree.GetItemParent(selected)
parent_name = self.ProjectTree.GetItemText(parent)
dialog = EditVariableDialog(self, parent_name, None)
+ dialog.SetPouNames(self.Controler.GetProjectPouNames())
if self.ProjectTree.GetPyData(parent) == ITEM_CONFIGURATION:
values = {"data" : self.Controler.GetConfigurationGlobalVars(parent_name)}
dialog.SetValues(values)
@@ -864,6 +847,7 @@
if dialog.ShowModal() == wxID_OK:
new_values = dialog.GetValues()
self.Controler.SetConfigurationResourceGlobalVars(config_name, parent_name, new_values["data"])
+ self.RefreshProjectTree()
elif data in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]:
if data == ITEM_POU:
idx = self.Controler.OpenElementEditing(name)
@@ -1023,32 +1007,88 @@
for item in to_delete:
self.ProjectTree.Delete(item)
+ def ResetToolBar(self):
+ for item in self.CurrentToolBar:
+ self.ToolBar.DeleteTool(item)
+
def RefreshToolBar(self):
language = self.Controler.GetCurrentElementEditingBodyType()
if language == "SFC":
- self.SFCToolBar.Show()
- self.SetToolBar(self.SFCToolBar)
- self.DefaultToolBar.Hide()
- self.FBDToolBar.Hide()
- self.LDToolBar.Hide()
+ if self.CurrentToolBar != SFC_ITEMS:
+ self.ResetToolBar()
+ self.CurrentToolBar = SFC_ITEMS
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS1,
+ wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment")
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS2,
+ wxBitmap(os.path.join(CWD, 'Images/initial_step.png')), wxNullBitmap, "Create a new initial step")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS3,
+ wxBitmap(os.path.join(CWD, 'Images/step.png')), "Create a new step")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS4,
+ wxBitmap(os.path.join(CWD, 'Images/action.png')), "Add action block to step")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS5,
+ wxBitmap(os.path.join(CWD, 'Images/divergence.png')), "Create a new divergence")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORSFCTOOLBARITEMS6,
+ wxBitmap(os.path.join(CWD, 'Images/jump.png')), "Create a new jump")
+ self.Bind(wx.EVT_TOOL, self.OnSFCCommentTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS1)
+ self.Bind(wx.EVT_TOOL, self.OnSFCInitialStepTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS2)
+ self.Bind(wx.EVT_TOOL, self.OnSFCStepTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS3)
+ self.Bind(wx.EVT_TOOL, self.OnSFCActionBlockTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS4)
+ self.Bind(wx.EVT_TOOL, self.OnSFCDivergenceTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS5)
+ self.Bind(wx.EVT_TOOL, self.OnSFCJumpTool,
+ id=wxID_PLCOPENEDITORSFCTOOLBARITEMS6)
elif language == "FBD":
- self.FBDToolBar.Show()
- self.SetToolBar(self.FBDToolBar)
- self.DefaultToolBar.Hide()
- self.SFCToolBar.Hide()
- self.LDToolBar.Hide()
+ if self.CurrentToolBar != FBD_ITEMS:
+ self.ResetToolBar()
+ self.CurrentToolBar = FBD_ITEMS
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS1,
+ wxBitmap(os.path.join(CWD, 'Images/comment.png')), wxNullBitmap, "Create a new comment")
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS2,
+ wxBitmap(os.path.join(CWD, 'Images/variable.png')), wxNullBitmap, "Create a new variable")
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS3,
+ wxBitmap(os.path.join(CWD, 'Images/block.png')), wxNullBitmap, "Create a new block")
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS4,
+ wxBitmap(os.path.join(CWD, 'Images/connection.png')), wxNullBitmap, "Create a new connection")
+ self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORFBDTOOLBARITEMS5,
+ wxBitmap(os.path.join(CWD, 'Images/wire.png')), wxNullBitmap, "Create a new wire")
+ self.Bind(wx.EVT_TOOL, self.OnFBDCommentTool,
+ id=wxID_PLCOPENEDITORFBDTOOLBARITEMS1)
+ self.Bind(wx.EVT_TOOL, self.OnFBDVariableTool,
+ id=wxID_PLCOPENEDITORFBDTOOLBARITEMS2)
+ self.Bind(wx.EVT_TOOL, self.OnFBDBlockTool,
+ id=wxID_PLCOPENEDITORFBDTOOLBARITEMS3)
+ self.Bind(wx.EVT_TOOL, self.OnFBDConnectionTool,
+ id=wxID_PLCOPENEDITORFBDTOOLBARITEMS4)
+ self.Bind(wx.EVT_TOOL, self.OnFBDWireTool,
+ id=wxID_PLCOPENEDITORFBDTOOLBARITEMS5)
elif language == "LD":
- self.LDToolBar.Show()
- self.SetToolBar(self.LDToolBar)
- self.DefaultToolBar.Hide()
- self.SFCToolBar.Hide()
- self.FBDToolBar.Hide()
+ if self.CurrentToolBar != LD_ITEMS:
+ self.ResetToolBar()
+ self.CurrentToolBar = LD_ITEMS
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS1,
+ wxBitmap(os.path.join(CWD, 'Images/coil.png')), "Create a new rung")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS2,
+ wxBitmap(os.path.join(CWD, 'Images/contact.png')), "Create a new contact")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS3,
+ wxBitmap(os.path.join(CWD, 'Images/block.png')), "Create a new block")
+ self.ToolBar.AddSimpleTool(wxID_PLCOPENEDITORLDTOOLBARITEMS4,
+ wxBitmap(os.path.join(CWD, 'Images/branch.png')), "Create a new branch")
+ self.Bind(wx.EVT_TOOL, self.OnLDCoilTool,
+ id=wxID_PLCOPENEDITORLDTOOLBARITEMS1)
+ self.Bind(wx.EVT_TOOL, self.OnLDContactTool,
+ id=wxID_PLCOPENEDITORLDTOOLBARITEMS2)
+ self.Bind(wx.EVT_TOOL, self.OnLDBlockTool,
+ id=wxID_PLCOPENEDITORLDTOOLBARITEMS3)
+ self.Bind(wx.EVT_TOOL, self.OnLDBranchTool,
+ id=wxID_PLCOPENEDITORLDTOOLBARITEMS4)
else:
- self.DefaultToolBar.Show()
- self.SetToolBar(self.DefaultToolBar)
- self.SFCToolBar.Hide()
- self.FBDToolBar.Hide()
- self.LDToolBar.Hide()
+ if len(self.CurrentToolBar) > 0:
+ self.ResetToolBar()
+ self.CurrentToolBar = []
self.ResetCurrentMode()
def RefreshTabsOpenedTitles(self):
@@ -1429,6 +1469,8 @@
self.PouType.Append(option)
self.RefreshLanguage()
+ self.PouNames = []
+
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
def OnOK(self, event):
@@ -1948,6 +1990,7 @@
False, 'Sans'))
self.VariablesGrid.DisableDragGridSize()
self.VariablesGrid.EnableScrolling(False, True)
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
self.AddButton = wx.Button(id=wxID_EDITVARIABLEDIALOGADDBUTTON, label='Add',
name='AddButton', parent=self.MainPanel, pos=wx.Point(345, 340),
@@ -2027,6 +2070,8 @@
self.Table.ResetView(self.VariablesGrid)
+ self.PouNames = []
+
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
def OnOK(self, event):
@@ -2100,6 +2145,39 @@
self.Table.ResetView(self.VariablesGrid)
event.Skip()
+ def OnVariablesGridCellChange(self, event):
+ row, col = event.GetRow(), event.GetCol()
+ colname = self.Table.GetColLabelValue(col)
+ value = self.Table.GetValue(row, col)
+ if colname == "Name":
+ if not TestIdentifier(value):
+ message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wxOK|wxICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ event.Veto()
+ elif value.upper() in IEC_KEYWORDS:
+ message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wxOK|wxICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ event.Veto()
+ elif value.upper() in self.PouNames:
+ message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wxOK|wxICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ event.Veto()
+ elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]:
+ message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ event.Veto()
+ else:
+ event.Skip()
+ else:
+ event.Skip()
+
+ def SetPouNames(self, pou_names):
+ self.PouNames = [pou_name.upper() for pou_name in pou_names]
+
def SetValues(self, values):
for item, value in values.items():
if item == "returnType" and value and self.ReturnType.IsEnabled():