# HG changeset patch # User Laurent Bessard # Date 1380727424 -7200 # Node ID 6adf05c4508d3578293da2f05127bb383be67394 # Parent c1e6c712cc350e70f5dc806e581e163454980658 Fixed bug in actionBlock actions editing diff -r c1e6c712cc35 -r 6adf05c4508d PLCControler.py --- a/PLCControler.py Wed Oct 02 01:21:35 2013 +0200 +++ b/PLCControler.py Wed Oct 02 17:23:44 2013 +0200 @@ -419,8 +419,13 @@ _ConnectionLinkInfos = namedtuple("ConnectionLinkInfos", ["refLocalId", "formalParameter", "points"]) -_ActionInfos = namedtuple("ActionInfos", - ["qualifier", "type", "value", "duration", "indicator"]) +class _ActionInfos: + __slots__ = ["qualifier", "type", "value", "duration", "indicator"] + def __init__(self, *args): + for attr, value in zip(self.__slots__, args): + setattr(self, attr, value if value is not None else "") + def copy(self): + return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__]) def _translate_args(translations, args): return [translate(arg[0]) if len(arg) > 0 else None @@ -490,8 +495,6 @@ if len(self.SpecificValues) == 0: self.SpecificValues.append([[]]) translated_args = _translate_args([str] * 5, args) - if translated_args[0] is None: - translated_args[0] = "" self.SpecificValues[0][0].append(_ActionInfos(*translated_args)) pou_block_instances_xslt = etree.parse( diff -r c1e6c712cc35 -r 6adf05c4508d dialogs/ActionBlockDialog.py --- a/dialogs/ActionBlockDialog.py Wed Oct 02 01:21:35 2013 +0200 +++ b/dialogs/ActionBlockDialog.py Wed Oct 02 17:23:44 2013 +0200 @@ -27,6 +27,7 @@ from controls import CustomGrid, CustomTable from util.BitmapLibrary import GetBitmap +from PLCControler import _ActionInfos #------------------------------------------------------------------------------- # Helpers @@ -49,17 +50,19 @@ def GetValue(self, row, col): if row < self.GetNumberRows(): colname = self.GetColLabelValue(col, False) - name = str(self.data[row].get(colname, "")) + value = getattr(self.data[row], colname.lower()) if colname == "Type": - return _(name) - return name + return _(value) + return value def SetValue(self, row, col, value): if col < len(self.colnames): colname = self.GetColLabelValue(col, False) if colname == "Type": value = self.Parent.TranslateType[value] - self.data[row][colname] = value + elif colname == "Qualifier" and not self.Parent.DurationList[value]: + self.data[row].duration = "" + setattr(self.data[row], colname.lower(), value) def _updateColAttrs(self, grid): """ @@ -81,23 +84,19 @@ if colname == "Duration": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() - if self.Parent.DurationList[self.data[row]["Qualifier"]]: - readonly = False - else: - readonly = True - self.data[row]["Duration"] = "" + readonly = not self.Parent.DurationList[self.data[row].qualifier] elif colname == "Type": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.TypeList) elif colname == "Value": - type = self.data[row]["Type"] - if type == "Action": + value_type = self.data[row].type + if value_type == "Action": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.ActionList) - elif type == "Variable": + elif value_type == "Variable": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.VariableList) - elif type == "Inline": + elif value_type == "Inline": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Indicator": @@ -168,11 +167,7 @@ self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] self.ActionsGrid.SetTable(self.Table) - self.ActionsGrid.SetDefaultValue({"Qualifier" : "N", - "Duration" : "", - "Type" : "Action", - "Value" : "", - "Indicator" : ""}) + self.ActionsGrid.SetDefaultValue(_ActionInfos("N", "Action", "", "", "")) self.ActionsGrid.SetButtons({"Add": self.AddButton, "Delete": self.DeleteButton, "Up": self.UpButton, @@ -199,7 +194,7 @@ event.Skip() def SetQualifierList(self, list): - self.QualifierList = "," + ",".join(list) + self.QualifierList = ",".join(list) self.DurationList = list def SetVariableList(self, list): @@ -210,41 +205,23 @@ def SetValues(self, actions): for action in actions: - row = {"Qualifier" : action["qualifier"], "Value" : action["value"]} - if action["type"] == "reference": - if action["value"] in self.ActionList: - row["Type"] = "Action" - elif action["value"] in self.VariableList: - row["Type"] = "Variable" - else: - row["Type"] = "Inline" + if action.type == "reference" and action.value in self.ActionList: + action.type = "Action" + elif action.type == "reference" and action.value in self.VariableList: + action.type = "Variable" else: - row["Type"] = "Inline" - if "duration" in action: - row["Duration"] = action["duration"] - else: - row["Duration"] = "" - if "indicator" in action: - row["Indicator"] = action["indicator"] - else: - row["Indicator"] = "" - self.Table.AppendRow(row) + action.type = "Inline" + self.Table.SetData(actions) self.Table.ResetView(self.ActionsGrid) if len(actions) > 0: self.ActionsGrid.SetGridCursor(0, 0) self.ActionsGrid.RefreshButtons() def GetValues(self): - values = [] - for data in self.Table.GetData(): - action = {"qualifier" : data["Qualifier"], "value" : data["Value"]} - if data["Type"] in ["Action", "Variable"]: - action["type"] = "reference" + actions = self.Table.GetData() + for action in actions: + if action.type in ["Action", "Variable"]: + action.type = "reference" else: - action["type"] = "inline" - if data["Duration"] != "": - action["duration"] = data["Duration"] - if data["Indicator"] != "": - action["indicator"] = data["Indicator"] - values.append(action) - return values + action.type = "inline" + return actions diff -r c1e6c712cc35 -r 6adf05c4508d graphics/SFC_Objects.py --- a/graphics/SFC_Objects.py Wed Oct 02 01:21:35 2013 +0200 +++ b/graphics/SFC_Objects.py Wed Oct 02 17:23:44 2013 +0200 @@ -1894,17 +1894,18 @@ self.ColSize = [0, 0, 0] min_height = 0 for action in self.Actions: - width, height = self.Parent.GetTextExtent(action.qualifier) + width, height = self.Parent.GetTextExtent( + action.qualifier if action.qualifier != "" else "N") self.ColSize[0] = max(self.ColSize[0], width + 10) row_height = height - if action.duration is not None: + if action.duration != "": width, height = self.Parent.GetTextExtent(action.duration) row_height = max(row_height, height) self.ColSize[0] = max(self.ColSize[0], width + 10) width, height = self.Parent.GetTextExtent(action.value) row_height = max(row_height, height) self.ColSize[1] = max(self.ColSize[1], width + 10) - if action.indicator is not None: + if action.indicator != "": width, height = self.Parent.GetTextExtent(action.indicator) row_height = max(row_height, height) self.ColSize[2] = max(self.ColSize[2], width + 10) @@ -1920,7 +1921,7 @@ self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] self.RefreshBoundingBox() - if self.Input: + if self.Input is not None: wires = self.Input.GetWires() if len(wires) == 1: input_block = wires[0][0].GetOtherConnected(self.Input).GetParentBlock() @@ -2023,7 +2024,7 @@ dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, self.Pos.x + self.Size[0], self.Pos.y + i * line_size) qualifier_size = dc.GetTextExtent(action.qualifier) - if action.duration is not None: + if action.duration != "": qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1]) duration_size = dc.GetTextExtent(action.duration) @@ -2038,7 +2039,7 @@ content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2, self.Pos.y + i * line_size + (line_size - content_size[1]) / 2) dc.DrawText(action.value, content_pos[0], content_pos[1]) - if action.indicator is not None: + if action.indicator != "": indicator_size = dc.GetTextExtent(action.indicator) indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) diff -r c1e6c712cc35 -r 6adf05c4508d plcopen/plcopen.py --- a/plcopen/plcopen.py Wed Oct 02 01:21:35 2013 +0200 +++ b/plcopen/plcopen.py Wed Oct 02 17:23:44 2013 +0200 @@ -49,8 +49,9 @@ """ Define which action qualifier must be associated with a duration """ -QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, - "P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True} +QualifierList = OrderedDict([("N", False), ("R", False), ("S", False), + ("L", True), ("D", True), ("P", False), ("P0", False), + ("P1", False), ("SD", True), ("DS", True), ("SL", True)]) FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)" @@ -218,7 +219,7 @@ # Update resources pou instance attributes for pouInstance in ResourceInstancesXpath(resource): - type_name = pouInstance.get("type") + type_name = pouInstance.attrib.pop("type") if type_name is not None: pouInstance.set("typeName", type_name) @@ -2148,17 +2149,17 @@ for params in actions: action = PLCOpenParser.CreateElement("action", "actionBlock") self.appendaction(action) - action.setqualifier(params["qualifier"]) - if params["type"] == "reference": + action.setqualifier(params.qualifier) + if params.type == "reference": action.addreference() - action.setreferenceName(params["value"]) + action.setreferenceName(params.value) else: action.addinline() - action.setinlineContent(params["value"]) - if params.has_key("duration"): - action.setduration(params["duration"]) - if params.has_key("indicator"): - action.setindicator(params["indicator"]) + action.setinlineContent(params.value) + if params.duration != "": + action.setduration(params.duration) + if params.indicator != "": + action.setindicator(params.indicator) setattr(cls, "setactions", setactions) def getactions(self): diff -r c1e6c712cc35 -r 6adf05c4508d plcopen/pou_block_instances.xslt --- a/plcopen/pou_block_instances.xslt Wed Oct 02 01:21:35 2013 +0200 +++ b/plcopen/pou_block_instances.xslt Wed Oct 02 17:23:44 2013 +0200 @@ -1,1 +1,1 @@ -0inputoutputoutputSTRINGWSTRINGBOOLinputoutput0connectionreferenceinlinejumpreferenceinline \ No newline at end of file +0inputoutputoutputSTRINGWSTRINGBOOLinputoutput0connectionreferenceinlinejumpreferenceinlineN \ No newline at end of file diff -r c1e6c712cc35 -r 6adf05c4508d plcopen/pou_block_instances.ysl2 --- a/plcopen/pou_block_instances.ysl2 Wed Oct 02 01:21:35 2013 +0200 +++ b/plcopen/pou_block_instances.ysl2 Wed Oct 02 17:23:44 2013 +0200 @@ -339,8 +339,14 @@ otherwise > } } + variable "qualifier" { + choose { + when "@qualifier" > «@qualifier» + otherwise > N + } + } variable "actionBlock_action" { - > «ns:AddAction(@qualifier, $type, $value, @duration, @indicator)» + > «ns:AddAction($qualifier, $type, $value, @duration, @indicator)» } }