--- a/PLCGenerator.py Mon Aug 13 18:04:19 2007 +0200
+++ b/PLCGenerator.py Mon Aug 13 18:06:50 2007 +0200
@@ -62,6 +62,7 @@
self.Interface = []
self.InitialSteps = []
self.BlockComputed = {}
+ self.ComputedBlocks = ""
self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}}
self.ActionNumber = 0
self.Program = ""
@@ -130,11 +131,11 @@
self.GenerateSFCTransition(instance, pou)
elif isinstance(instance, plcopen.jumpStep):
self.GenerateSFCJump(instance, pou)
- if len(self.InitialSteps) > 0:
+ if len(self.InitialSteps) > 0 and self.ComputedBlocks != "":
action_name = "COMPUTE_FUNCTION_BLOCKS"
action_infos = {"qualifier" : "S", "content" : action_name}
self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos)
- self.SFCNetworks["Actions"][action_name] = ReIndentText(self.Program, 4)
+ self.SFCNetworks["Actions"][action_name] = ReIndentText(self.ComputedBlocks, 4)
self.Program = ""
else:
raise Exception
@@ -205,7 +206,7 @@
if isinstance(next, plcopen.leftPowerRail) or isinstance(next, plcopen.contact):
return "LD"
elif isinstance(next, plcopen.block):
- for variable in instance.inputVariables.getVariable():
+ for variable in next.inputVariables.getVariable():
result = self.GetNetworkType(variable.connectionPointIn.getConnections(), body)
if result != "FBD":
return result
@@ -326,16 +327,18 @@
connections = instance.connectionPointIn.getConnections()
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(actionBody, connections[0])
- self.SFCNetworks["Actions"][action_name] = self.Program + " %s := %s;\n"%(var, expression)
+ action_content = self.Program + " %s := %s;\n"%(var, expression)
self.Program = ""
+ self.SFCNetworks["Actions"][action_name] = ReIndentText(action_content, 4)
elif actionType == "LD":
for instance in actionbody.getContentInstances():
if isinstance(instance, plcopen.coil):
paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), actionBody)
variable = self.ExtractModifier(instance, instance.getVariable())
expression = self.ComputeLDExpression(paths, True)
- self.SFCNetworks["Actions"][action_name] = self.Program + " %s := %s;\n"%(variable, expression)
+ action_content = self.Program + " %s := %s;\n"%(variable, expression)
self.Program = ""
+ self.SFCNetworks["Actions"][action_name] = ReIndentText(action_content, 4)
def GenerateSFCTransition(self, transition, pou):
if transition not in self.SFCNetworks["Transitions"].keys():
@@ -374,12 +377,16 @@
if connections and len(connections) == 1:
expression = self.ComputeFBDExpression(transitionBody, connections[0])
transition_infos["content"] = "\n := %s;\n"%expression
+ self.ComputedBlocks += self.Program
+ self.Program = ""
elif transitionType == "LD":
for instance in transitionBody.getContentInstances():
if isinstance(instance, plcopen.coil):
paths = self.GenerateLDPaths(instance.connectionPointIn.getConnections(), transitionBody)
expression = self.ComputeLDExpression(paths, True)
transition_infos["content"] = "\n := %s;\n"%expression
+ self.ComputedBlocks += self.Program
+ self.Program = ""
elif transitionValues["type"] == "connection":
body = pou.getBody()
connections = transition.getConnections()
@@ -390,9 +397,13 @@
paths = self.GenerateLDPaths(connections, body)
expression = self.ComputeLDExpression(paths, True)
transition_infos["content"] = "\n := %s;\n"%expression
+ self.ComputedBlocks += self.Program
+ self.Program = ""
else:
expression = self.ComputeFBDExpression(body, connections[0])
transition_infos["content"] = "\n := %s;\n"%expression
+ self.ComputedBlocks += self.Program
+ self.Program = ""
for step in steps:
self.GenerateSFCStep(step, pou)
step_name = step.getName()
--- a/PLCOpenEditor.py Mon Aug 13 18:04:19 2007 +0200
+++ b/PLCOpenEditor.py Mon Aug 13 18:06:50 2007 +0200
@@ -414,8 +414,8 @@
self.CurrentToolBar = []
self.CurrentLanguage = ""
- self.DrawingMode = FREEDRAWING_MODE
- #self.DrawingMode = DRIVENDRAWING_MODE
+ #self.DrawingMode = FREEDRAWING_MODE
+ self.DrawingMode = DRIVENDRAWING_MODE
self.RefreshFileMenu()
self.RefreshEditMenu()
@@ -829,10 +829,10 @@
if itemtype == ITEM_PROJECT:
self.Controler.SetProjectProperties(name = new_name)
elif itemtype == ITEM_POU:
- if new_name.upper() in self.Controler.GetProjectPouNames():
+ if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
message = "\"%s\" pou already exists!"%new_name
abort = True
- elif new_name.upper() in self.Controler.GetProjectPouVariables():
+ elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]:
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION)
if messageDialog.ShowModal() == wx.ID_NO:
abort = True
@@ -845,9 +845,9 @@
category = self.ProjectTree.GetItemParent(item)
pou = self.ProjectTree.GetItemParent(category)
pou_name = self.ProjectTree.GetItemText(pou)
- if new_name.upper() in self.Controler.GetProjectPouNames():
+ if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
message = "A pou with \"%s\" as name exists!"%new_name
- elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name):
+ elif new_name.upper() in [name.upper() for name 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)
@@ -857,28 +857,14 @@
category = self.ProjectTree.GetItemParent(item)
pou = self.ProjectTree.GetItemParent(category)
pou_name = self.ProjectTree.GetItemText(pou)
- if new_name.upper() in self.Controler.GetProjectPouNames():
+ if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]:
message = "A pou with \"%s\" as name exists!"%new_name
- elif new_name.upper() in self.Controler.GetProjectPouVariables(pou_name):
+ elif new_name.upper() in [name.upper() for name 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 = wx.MessageDialog(self, message, "Error", wx.OK|wx.ICON_ERROR)
@@ -1122,6 +1108,7 @@
def OnAddPouMenu(self, event):
dialog = PouDialog(self)
dialog.SetPouNames(self.Controler.GetProjectPouNames())
+ dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
@@ -1174,6 +1161,8 @@
pouname = self.ProjectTree.GetItemText(selected)
if self.Controler.GetPouBodyType(pouname) == "SFC":
dialog = PouTransitionDialog(self)
+ dialog.SetPouNames(self.Controler.GetProjectPouNames())
+ dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname))
if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"])
@@ -1201,6 +1190,8 @@
pouname = self.ProjectTree.GetItemText(selected)
if self.Controler.GetPouBodyType(pouname) == "SFC":
dialog = PouActionDialog(self)
+ dialog.SetPouNames(self.Controler.GetProjectPouNames())
+ dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname))
if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"])
@@ -1531,6 +1522,7 @@
self.RefreshLanguage()
self.PouNames = []
+ self.PouElementNames = []
def OnOK(self, event):
error = []
@@ -1565,6 +1557,12 @@
message = wx.MessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
+ elif pou_name.upper() in self.PouElementNames:
+ message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%pou_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION)
+ result = message.ShowModal()
+ message.Destroy()
+ if result == wx.ID_YES:
+ self.EndModal(wx.ID_OK)
else:
self.EndModal(wx.ID_OK)
@@ -1584,6 +1582,9 @@
def SetPouNames(self, pou_names):
self.PouNames = [pou_name.upper() for pou_name in pou_names]
+ def SetPouElementNames(self, element_names):
+ self.PouElementNames = [element_name.upper() for element_name in element_names]
+
def SetValues(self, values):
for item, value in values.items():
if item == "pouName":
@@ -1672,9 +1673,13 @@
for option in ["IL","ST","LD","FBD"]:
self.Language.Append(option)
+
+ self.PouNames = []
+ self.PouElementNames = []
def OnOK(self, event):
error = []
+ transition_name = self.TransitionName.GetValue()
if self.TransitionName.GetValue() == "":
error.append("Transition Name")
if self.Language.GetStringSelection() == "":
@@ -1691,9 +1696,31 @@
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
+ elif not TestIdentifier(transition_name):
+ message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%transition_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif transition_name.upper() in IEC_KEYWORDS:
+ message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%transition_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif transition_name.upper() in self.PouNames:
+ message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif transition_name.upper() in self.PouElementNames:
+ message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
else:
self.EndModal(wx.ID_OK)
-
+
+ def SetPouNames(self, pou_names):
+ self.PouNames = [pou_name.upper() for pou_name in pou_names]
+
+ def SetPouElementNames(self, pou_names):
+ self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
+
def SetValues(self, values):
for item, value in values.items():
if item == "transitionName":
@@ -1779,9 +1806,13 @@
for option in ["IL","ST","LD","FBD"]:
self.Language.Append(option)
+ self.PouNames = []
+ self.PouElementNames = []
+
def OnOK(self, event):
error = []
- if self.ActionName.GetValue() == "":
+ action_name = self.ActionName.GetValue()
+ if action_name == "":
error.append("Action Name")
if self.Language.GetStringSelection() == "":
error.append("Language")
@@ -1797,9 +1828,31 @@
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
+ elif not TestIdentifier(action_name):
+ message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%action_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif action_name.upper() in IEC_KEYWORDS:
+ message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%action_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif action_name.upper() in self.PouNames:
+ message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ elif action_name.upper() in self.PouElementNames:
+ message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
else:
self.EndModal(wx.ID_OK)
-
+
+ def SetPouNames(self, pou_names):
+ self.PouNames = [pou_name.upper() for pou_name in pou_names]
+
+ def SetPouElementNames(self, element_names):
+ self.PouElementNames = [element_name.upper() for element_name in element_names]
+
def SetValues(self, values):
for item, value in values.items():
if item == "actionName":
@@ -2204,18 +2257,18 @@
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : "True"}
if pou_type in ["config", "resource"] or pou_type == "program":
- self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant", "Edit"])
+ self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"])
if pou_type not in ["config", "resource"]:
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"]
else:
self.FilterChoices = ["All","Global","Access"]
- self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70, 50]
- self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER, wx.ALIGN_LEFT]
- else:
- self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Initial Value", "Retain", "Constant", "Edit"])
+ self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70]
+ self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
+ else:
+ self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Initial Value", "Retain", "Constant"])
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"]
- self.ColSizes = [40, 120, 70, 80, 120, 60, 70, 50]
- self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER, wx.ALIGN_LEFT]
+ self.ColSizes = [40, 120, 70, 80, 120, 60, 70]
+ self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER]
for choice in self.FilterChoices:
self.ClassFilter.Append(choice)
reverse_transfer = {}