# HG changeset patch # User laurent # Date 1260646655 -3600 # Node ID acef952101a5ec32a0442f25e9fa6a49d9df6bd8 # Parent 779a519f78f2dc494b49ef2cf50c75a477eeb317 Adding support for excluding option when not available according to IEC 61131 standard Disabling use of complex types (array and structure) for POU interface until matiec can generate code diff -r 779a519f78f2 -r acef952101a5 PLCControler.py --- a/PLCControler.py Thu Dec 10 16:37:11 2009 +0100 +++ b/PLCControler.py Sat Dec 12 20:37:35 2009 +0100 @@ -1245,7 +1245,7 @@ return blocktypes # Return Data Types checking for recursion - def GetDataTypes(self, tagname = "", basetypes = True, debug = False): + def GetDataTypes(self, tagname = "", basetypes = True, complextypes = True, debug = False): if basetypes: datatypes = self.GetBaseTypes() else: @@ -1256,7 +1256,7 @@ words = tagname.split("::") if words[0] in ["D"]: name = words[1] - datatypes.extend(project.GetCustomDataTypes(name)) + datatypes.extend(project.GetCustomDataTypes(name, complextypes=complextypes)) return datatypes # Return Base Type of given possible derived type diff -r 779a519f78f2 -r acef952101a5 VariablePanel.py --- a/VariablePanel.py Thu Dec 10 16:37:11 2009 +0100 +++ b/VariablePanel.py Sat Dec 12 20:37:35 2009 +0100 @@ -52,9 +52,16 @@ return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")] return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")] -def GetOptions(): +def GetOptions(constant=True, retain=True, non_retain=True): _ = lambda x : x - return ["", _("Constant"), _("Retain"), _("Non-Retain")] + options = [""] + if constant: + options.append(_("Constant")) + if retain: + options.append(_("Retain")) + if non_retain: + options.append(_("Non-Retain")) + return options OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()]) def GetFilterChoiceTransfer(): @@ -65,6 +72,15 @@ _(" Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")} VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()]) +CheckOptionForClass = {"Local": lambda x: x, + "Temp": lambda x: "", + "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), + "InOut": lambda x: "", + "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), + "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), + "External": lambda x: {"Constant": "Constant"}.get(x, "") + } + class VariableTable(wx.grid.PyGridTableBase): """ @@ -116,6 +132,9 @@ self.old_value = self.data[row][colname] elif colname == "Class": value = VARIABLE_CLASSES_DICT[value] + self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option"))) + if value == "External": + self.SetValueByName(row, "Initial Value", "") elif colname == "Option": value = OPTIONS_DICT[value] self.data[row][colname] = value @@ -173,32 +192,42 @@ Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): + var_class = self.GetValueByName(row, "Class") for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) if colname == "Option": - editor = wx.grid.GridCellChoiceEditor() - editor.SetParameters(",".join(map(_, self.Parent.OptionList))) + options = GetOptions(constant = var_class in ["Local", "External", "Global"], + retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], + non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) + if len(options) > 1: + editor = wx.grid.GridCellChoiceEditor() + editor.SetParameters(",".join(map(_, options))) + else: + grid.SetReadOnly(row, col, True) elif col != 0 and self.GetValueByName(row, "Edit"): grid.SetReadOnly(row, col, False) if colname == "Name": - if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: + if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: grid.SetReadOnly(row, col, True) else: editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Initial Value": - editor = wx.grid.GridCellTextEditor() - renderer = wx.grid.GridCellStringRenderer() + if var_class != "External": + editor = wx.grid.GridCellTextEditor() + renderer = wx.grid.GridCellStringRenderer() + else: + grid.SetReadOnly(row, col, True) elif colname == "Location": - if self.GetValueByName(row, "Class") in ["Local", "Global"]: + if var_class in ["Local", "Global"]: editor = LocationCellEditor(self, self.Parent.Controler) renderer = wx.grid.GridCellStringRenderer() else: grid.SetReadOnly(row, col, True) elif colname == "Class": - if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: + if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]: grid.SetReadOnly(row, col, True) else: editor = wx.grid.GridCellChoiceEditor() @@ -520,7 +549,7 @@ if element_type == "function": self.FilterChoices = ["All", "Interface", " Input", " Output", " InOut", - "Variables", " Local", " Temp"] + "Variables", " Local"] else: self.FilterChoices = ["All", "Interface", " Input", " Output", " InOut", " External", @@ -543,8 +572,6 @@ self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter])) self.RefreshTypeList() - self.OptionList = GetOptions() - if element_type == "function": for base_type in self.Controler.GetBaseTypes(): self.ReturnType.Append(base_type) @@ -732,7 +759,10 @@ # build a submenu containing user-defined types datatype_menu = wx.Menu(title='') - datatypes = self.Controler.GetDataTypes(basetypes = False) + + # TODO : remove complextypes argument when matiec can manage complex types in pou interface + datatypes = self.Controler.GetDataTypes(basetypes = False, + complextypes = self.Table.GetValueByName(row, "Class") not in ["Input", "Ouput", "InOut"]) for datatype in datatypes: new_id = wx.NewId() AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) diff -r 779a519f78f2 -r acef952101a5 plcopen/plcopen.py --- a/plcopen/plcopen.py Thu Dec 10 16:37:11 2009 +0100 +++ b/plcopen/plcopen.py Sat Dec 12 20:37:35 2009 +0100 @@ -649,10 +649,12 @@ setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) # Return Data Types checking for recursion - def GetCustomDataTypes(self, exclude = ""): + def GetCustomDataTypes(self, exclude = "", complextypes = True): customdatatypes = [] for customdatatype in self.getdataTypes(): customdatatype_name = customdatatype.getname() + if not complextypes and customdatatype.baseType.getcontent()["name"] in ["array", "struct"]: + continue if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name): customdatatypes.append(customdatatype_name) return customdatatypes