# HG changeset patch # User lbessard # Date 1170870212 -3600 # Node ID 93bc4c2cf376523a5826e1ed402c439d3e29996d # Parent e9d01d824086dfdf3a2c81edcf1248cfd6e68151 PLCGenerator finished Code for generated classes from xsd and specific code for plcopen separated Bug in SFC corrected diff -r e9d01d824086 -r 93bc4c2cf376 FBDViewer.py --- a/FBDViewer.py Thu Feb 01 18:09:34 2007 +0100 +++ b/FBDViewer.py Wed Feb 07 18:43:32 2007 +0100 @@ -293,8 +293,8 @@ connector = variable.GetConnector() wires.extend([wire[0] for wire in connector.GetWires()]) variable.Clean() - self.Blocks.remove(self.SelectedElement) - self.Elements.remove(self.SelectedElement) + self.Blocks.remove(variable) + self.Elements.remove(variable) self.Controler.RemoveCurrentElementEditingInstance(variable.GetId()) for wire in wires: wire.RefreshModel() @@ -306,26 +306,47 @@ connector = connection.GetConnector() wires.extend([wire[0] for wire in connector.GetWires()]) connection.Clean() - self.Blocks.remove(self.SelectedElement) - self.Elements.remove(self.SelectedElement) + self.Blocks.remove(connection) + self.Elements.remove(connection) self.Controler.RemoveCurrentElementEditingInstance(connection.GetId()) for wire in wires: wire.RefreshModel() self.Parent.RefreshProjectTree() def DeleteComment(self, comment): - self.Elements.remove(self.SelectedElement) + self.Elements.remove(comment) self.Controler.RemoveCurrentElementEditingInstance(comment.GetId()) def DeleteWire(self, wire): connected = wire.GetConnected() self.SelectedElement.Clean() - self.Wires.remove(self.SelectedElement) - self.Elements.remove(self.SelectedElement) + self.Wires.remove(wire) + self.Elements.remove(wire) for connector in connected: connector.RefreshParentBlock() #------------------------------------------------------------------------------- +# Edit element content functions +#------------------------------------------------------------------------------- + + def EditBlockContent(self, block): + dialog = BlockPropertiesDialog(self.Parent) + dialog.SetBlockList(self.Controler.GetBlockTypes()) + dialog.SetMinBlockSize(block.GetSize()) + values = {"name" : block.GetName(), "type" : block.GetType()} + values["extension"] = block.GetExtension() + dialog.SetValues(values) + if dialog.ShowModal() == wxID_OK: + values = dialog.GetValues() + if "name" in values: + block.SetName(values["name"]) + block.SetExtension(values["extension"]) + block.SetSize(values["width"], values["height"]) + block.SetType(values["type"]) + self.Refresh() + dialog.Destroy() + +#------------------------------------------------------------------------------- # Create New Block Dialog #------------------------------------------------------------------------------- @@ -419,6 +440,19 @@ EVT_PAINT(self, self.OnPaint) EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) + def FindTreeItem(self, root, name): + if root.IsOk(): + if self.TypeTree.GetItemText(root) == name: + return root + else: + item, root_cookie = self.TypeTree.GetFirstChild(root) + while item.IsOk(): + result = self.FindTreeItem(item, name) + if result: + return result + item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie) + return None + def OnOK(self, event): error = [] selected = self.TypeTree.GetSelection() @@ -443,6 +477,18 @@ def SetMinBlockSize(self, size): self.MinBlockSize = size + def SetValues(self, values): + for name, value in values.items(): + if name == "type": + item = self.FindTreeItem(self.TypeTree.GetRootItem(), value) + if item: + self.TypeTree.SelectItem(item) + elif name == "name": + self.Name.SetValue(value) + elif name == "extension": + self.Inputs.SetValue(value) + self.RefreshPreview() + def GetValues(self): values = {} values["type"] = self.TypeTree.GetItemText(self.TypeTree.GetSelection()) @@ -561,7 +607,7 @@ self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, label='Preview:', name='staticText3', parent=self.MainPanel, - pos=wx.Point(24, 72), size=wx.Size(100, 17), style=0) + pos=wx.Point(24, 78), size=wx.Size(100, 17), style=0) self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS, name='Class', parent=self.MainPanel, pos=wx.Point(24, 48), diff -r e9d01d824086 -r 93bc4c2cf376 LDViewer.py --- a/LDViewer.py Thu Feb 01 18:09:34 2007 +0100 +++ b/LDViewer.py Wed Feb 07 18:43:32 2007 +0100 @@ -977,7 +977,7 @@ vars = self.Controler.GetCurrentElementEditingInterfaceVars() if vars: for var in vars: - if var["Type"] != "Output" and var["Value"] == "BOOL": + if var["Class"] != "Output" and var["Type"] == "BOOL": varlist.append(var["Name"]) dialog.SetVariables(varlist) dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()}) @@ -995,7 +995,7 @@ vars = self.Controler.GetCurrentElementEditingInterfaceVars() if vars: for var in vars: - if var["Type"] != "Input" and var["Value"] == "BOOL": + if var["Class"] != "Input" and var["Type"] == "BOOL": varlist.append(var["Name"]) returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType() if returntype == "BOOL": @@ -1097,10 +1097,10 @@ def __init__(self, parent, type): self.Type = type if type == "contact": - self._init_ctrls(parent, "Edit Contact Values", ['Normal','Reverse','Rising Edge','Falling Edge']) + self._init_ctrls(parent, "Edit Contact Values", ['Normal','Negate','Rising Edge','Falling Edge']) self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "") elif type == "coil": - self._init_ctrls(parent, "Edit Coil Values", ['Normal','Reverse','Set','Reset']) + self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset']) self.Element = LD_Coil(self.Preview, COIL_NORMAL, "") self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2) diff -r e9d01d824086 -r 93bc4c2cf376 PLCControler.py --- a/PLCControler.py Thu Feb 01 18:09:34 2007 +0100 +++ b/PLCControler.py Wed Feb 07 18:43:32 2007 +0100 @@ -34,6 +34,28 @@ [ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE, ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE] = range(9) +""" +pyxsval is not complete and the parts that are not supported print some error +reports. This class is used for not displaying them +""" +class HolePseudoFile: + """ Base class for file like objects to facilitate StdOut for the Shell.""" + def __init__(self, output = None): + if output is None: output = [] + self.output = output + + def writelines(self, l): + map(self.write, l) + + def write(self, s): + pass + + def flush(self): + pass + + def isatty(self): + return false + #------------------------------------------------------------------------------- # Undo Buffer for PLCOpenEditor #------------------------------------------------------------------------------- @@ -1755,7 +1777,7 @@ def OpenXMLFile(self, filepath): if sys: - sys.stdout = plcopen.HolePseudoFile() + sys.stdout = HolePseudoFile() tree = pyxsval.parseAndValidate(filepath, "plcopen/TC6_XML_V10_B.xsd") if sys: sys.stdout = sys.__stdout__ @@ -1781,7 +1803,7 @@ text += self.Project.generateXMLText("project", 0, extras) if sys: - sys.stdout = plcopen.HolePseudoFile() + sys.stdout = HolePseudoFile() pyxsval.parseAndValidateString(text, open("plcopen/TC6_XML_V10_B.xsd","r").read()) if sys: sys.stdout = sys.__stdout__ diff -r e9d01d824086 -r 93bc4c2cf376 PLCGenerator.py --- a/PLCGenerator.py Thu Feb 01 18:09:34 2007 +0100 +++ b/PLCGenerator.py Wed Feb 07 18:43:32 2007 +0100 @@ -41,7 +41,10 @@ for i in xrange(spaces, nb_spaces): indent += " " for line in lines: - compute += "%s%s\n"%(indent, line) + if line != "": + compute += "%s%s\n"%(indent, line) + else: + compute += "\n" return compute """ @@ -175,6 +178,24 @@ else: return variable + def ExtractDivergenceInput(self, divergence, pou): + connectionPointIn = divergence.getConnectionPointIn() + if connectionPointIn: + connections = connectionPointIn.getConnections() + if len(connections) == 1: + instanceLocalId = connections[0].getRefLocalId() + return pou.body.getContentInstance(instanceLocalId) + return None + + def ExtractConvergenceInputs(self, convergence, pou): + instances = [] + for connectionPointIn in convergence.getConnectionPointIn(): + connections = connectionPointIn.getConnections() + if len(connections) == 1: + instanceLocalId = connections[0].getRefLocalId() + instances.append(pou.body.getContentInstance(instanceLocalId)) + return instances + def GenerateSFCStep(self, step, pou): step_name = step.getName() if step_name not in self.SFCNetworks["Steps"].keys(): @@ -188,26 +209,18 @@ instanceLocalId = connections[0].getRefLocalId() instance = pou.body.getContentInstance(instanceLocalId) if isinstance(instance, plcopen.transition): - self.GenerateSFCTransition(instance, pou) instances.append(instance) elif isinstance(instance, plcopen.selectionConvergence): - for connectionPointIn in instance.getConnectionPointIn(): - divergence_connections = connectionPointIn.getConnections() - if len(divergence_connections) == 1: - transitionLocalId = connections[0].getRefLocalId() - transition = pou.body.getContentInstance(transitionLocalId) - self.GenerateSFCTransition(transition, pou) + instances.extend(self.ExtractConvergenceInputs(instance, pou)) + elif isinstance(instance, plcopen.simultaneousDivergence): + transition = self.ExtractDivergenceInput(instance, pou) + if transition: + if isinstance(transition, plcopen.transition): instances.append(transition) - elif isinstance(instance, plcopen.simultaneousDivergence): - connectionPointIn = instance.getConnectionPointIn() - if connectionPointIn: - divergence_connections = connectionPointIn.getConnections() - if len(divergence_connections) == 1: - transitionLocalId = connections[0].getRefLocalId() - transition = pou.body.getContentInstance(transitionLocalId) - self.GenerateSFCTransition(transition, pou) - instances.append(transition) + elif isinstance(transition, plcopen.selectionConvergence): + instances.extend(self.ExtractConvergenceInputs(transition, pou)) for instance in instances: + self.GenerateSFCTransition(instance, pou) if instance in self.SFCNetworks["Transitions"].keys(): self.SFCNetworks["Transitions"][instance]["to"].append(step_name) self.SFCNetworks["Steps"][step_name] = step_infos @@ -221,26 +234,18 @@ instanceLocalId = connections[0].getRefLocalId() instance = pou.body.getContentInstance(instanceLocalId) if isinstance(instance, plcopen.transition): - self.GenerateSFCTransition(instance, pou) instances.append(instance) elif isinstance(instance, plcopen.selectionConvergence): - for connectionPointIn in instance.getConnectionPointIn(): - divergence_connections = connectionPointIn.getConnections() - if len(divergence_connections) == 1: - transitionLocalId = divergence_connections[0].getRefLocalId() - transition = pou.body.getContentInstance(transitionLocalId) - self.GenerateSFCTransition(transition, pou) + instances.extend(self.ExtractConvergenceInputs(instance, pou)) + elif isinstance(instance, plcopen.simultaneousDivergence): + transition = self.ExtractDivergenceInput(instance, pou) + if transition: + if isinstance(transition, plcopen.transition): instances.append(transition) - elif isinstance(instance, plcopen.simultaneousDivergence): - connectionPointIn = instance.getConnectionPointIn() - if connectionPointIn: - divergence_connections = connectionPointIn.getConnections() - if len(divergence_connections) == 1: - transitionLocalId = connections[0].getRefLocalId() - transition = pou.body.getContentInstance(transitionLocalId) - self.GenerateSFCTransition(transition, pou) - instances.append(transition) + elif isinstance(transition, plcopen.selectionConvergence): + instances.extend(self.ExtractConvergenceInputs(transition, pou)) for instance in instances: + self.GenerateSFCTransition(instance, pou) if instance in self.SFCNetworks["Transitions"].keys(): self.SFCNetworks["Transitions"][instance]["to"].append(jump_target) @@ -297,16 +302,16 @@ instanceLocalId = connections[0].getRefLocalId() instance = pou.body.getContentInstance(instanceLocalId) if isinstance(instance, plcopen.step): - self.GenerateSFCStep(instance, pou) - steps.append(instance.getName()) + steps.append(instance) elif isinstance(instance, plcopen.selectionDivergence): - divergence_connections = instance.connectionPointIn.getConnections() - if len(divergence_connections) == 1: - stepLocalId = divergence_connections[0].getRefLocalId() - divergence_instance = pou.body.getContentInstance(stepLocalId) - if isinstance(divergence_instance, plcopen.step): - self.GenerateSFCStep(divergence_instance, pou) - steps.append(divergence_instance.getName()) + step = self.ExtractDivergenceInput(instance, pou) + if step: + if isinstance(step, plcopen.step): + steps.append(step) + elif isinstance(step, plcopen.simultaneousConvergence): + steps.extend(self.ExtractConvergenceInputs(step, pou)) + elif isinstance(instance, plcopen.simultaneousConvergence): + steps.extend(self.ExtractConvergenceInputs(instance, pou)) transition_infos = {"from": [], "to" : []} transitionValues = transition.getConditionContent() if transitionValues["type"] == "inline": @@ -316,9 +321,9 @@ transitionType = transitionContent.getBodyType() transitionBody = transitionContent.getBody() if transitionType == "IL": - transition_infos["content"] = ":\n%s\n"%ReIndentText(transitionBody.getText(), 4) + transition_infos["content"] = ":\n%s"%ReIndentText(transitionBody.getText(), 4) elif transitionType == "ST": - transition_infos["content"] = "\n%s\n"%ReIndentText(transitionBody.getText(), 4) + transition_infos["content"] = "\n%s"%ReIndentText(transitionBody.getText(), 4) elif conditionType == "FBD": for instance in transitionBody.getContentInstances(): if isinstance(instance, plcopen.outVariable): @@ -332,7 +337,9 @@ paths = self.GenerateLDPaths(instance, conditionBody) expression = self.ComputeLDExpression(paths, True) transition_infos["content"] = "\n := %s;\n"%expression - for step_name in steps: + for step in steps: + self.GenerateSFCStep(step, pou) + step_name = step.getName() if step_name in self.SFCNetworks["Steps"].keys(): transition_infos["from"].append(step_name) self.SFCNetworks["Steps"][step_name]["transitions"].append(transition) diff -r e9d01d824086 -r 93bc4c2cf376 PLCOpenEditor.py --- a/PLCOpenEditor.py Thu Feb 01 18:09:34 2007 +0100 +++ b/PLCOpenEditor.py Wed Feb 07 18:43:32 2007 +0100 @@ -445,6 +445,8 @@ self.DefaultToolBar = wxToolBar(id=wxID_PLCOPENEDITORDEFAULTTOOLBAR, name='DefaultToolBar', parent=parent, pos=wx.Point(0, 27), size=wx.Size(0, 0), style=wxTB_HORIZONTAL | wxNO_BORDER) + self.Bind(wx.EVT_LEFT_DCLICK, self.OnDefaultToolDCLick, + id=wxID_PLCOPENEDITORDEFAULTTOOLBAR) self.SFCToolBar = wxToolBar(id=wxID_PLCOPENEDITORSFCTOOLBAR, name='SFCToolBar', parent=parent, pos=wx.Point(0, 27), size=wx.Size(0, 0), @@ -477,6 +479,10 @@ self.RefreshEditMenu() self.RefreshToolBar() + def OnDefaultToolDCLick(self, event): + print "Default ToolBar DClick" + event.Skip() + def RefreshFileMenu(self): if self.Controler.HasOpenedProject(): if self.TabsOpened.GetPageCount() > 0: diff -r e9d01d824086 -r 93bc4c2cf376 SFCViewer.py --- a/SFCViewer.py Thu Feb 01 18:09:34 2007 +0100 +++ b/SFCViewer.py Wed Feb 07 18:43:32 2007 +0100 @@ -75,7 +75,7 @@ wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() - next_block.RefreshModel() + transition.RefreshOutputModel(True) return transition def RemoveTransition(self, transition): @@ -133,7 +133,7 @@ wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() - next_block.RefreshModel() + step.RefreshOutputModel(True) return step def RemoveStep(self, step): @@ -795,7 +795,7 @@ wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() - next_block.RefreshModel() + previous_block.RefreshOutputModel(True) else: if isinstance(previous_block, SFC_Step): previous_block.RemoveOutput() @@ -910,7 +910,7 @@ wxPoint(previous_pos.x, previous_pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() - next_block.RefreshModel() + previous_block.RefreshOutputModel(True) elif divergence.GetBranchNumber() == 1: wires = connectors["inputs"][0].GetWires() if len(wires) != 1: @@ -943,7 +943,7 @@ wxPoint(previous_pos.x, previous_pos.y)]) if isinstance(next_block, SFC_Divergence): next_block.RefreshPosition() - next_block.RefreshModel() + previous_block.RefreshOutputModel(True) self.Parent.RefreshProjectTree() def DeleteJump(self, jump): diff -r e9d01d824086 -r 93bc4c2cf376 Viewer.py --- a/Viewer.py Thu Feb 01 18:09:34 2007 +0100 +++ b/Viewer.py Wed Feb 07 18:43:32 2007 +0100 @@ -873,6 +873,7 @@ # Indentation size self.SetTabWidth(2) + self.SetUseTabs(0) self.Keywords = [] self.Variables = [] diff -r e9d01d824086 -r 93bc4c2cf376 examples/example.xml --- a/examples/example.xml Thu Feb 01 18:09:34 2007 +0100 +++ b/examples/example.xml Wed Feb 07 18:43:32 2007 +0100 @@ -451,9 +451,9 @@