# HG changeset patch # User b.taylor@willowglen.ca # Date 1253045219 21600 # Node ID d19c4a6460ab9263d75cfd5b1cdd0785ee1604b3 # Parent 53aa0c334f2f12a7a79be03923c1a124b86a7bad add a Documentation column to the VariablePanel diff -r 53aa0c334f2f -r d19c4a6460ab PLCControler.py --- a/PLCControler.py Mon Sep 14 10:57:12 2009 -0600 +++ b/PLCControler.py Tue Sep 15 14:06:59 2009 -0600 @@ -847,6 +847,7 @@ # Create variable and change its properties tempvar = plcopen.varListPlain_variable() tempvar.setname(var["Name"]) + var_type = plcopen.dataType() if var["Type"] in self.GetBaseTypes(): if var["Type"] == "STRING": @@ -860,6 +861,7 @@ derived_type.setname(var["Type"]) var_type.setcontent({"name" : "derived", "value" : derived_type}) tempvar.settype(var_type) + if var["Initial Value"] != "": value = plcopen.value() value.setvalue(var["Initial Value"]) @@ -868,9 +870,62 @@ tempvar.setaddress(var["Location"]) else: tempvar.setaddress(None) + if var['Documentation'] != "": + ft = plcopen.formattedText() + ft.settext(var['Documentation']) + tempvar.setdocumentation(ft) + # Add variable to varList current_varlist.appendvariable(tempvar) return varlist_list + + def GetVariableDictionary(self, varlist, var): + ''' + convert a PLC variable to the dictionary representation + returned by Get*Vars) + ''' + + tempvar = {"Name" : var.getname()} + + vartype_content = var.gettype().getcontent() + if vartype_content["name"] == "derived": + tempvar["Type"] = vartype_content["value"].getname() + elif vartype_content["name"] in ["string", "wstring"]: + tempvar["Type"] = vartype_content["name"].upper() + else: + tempvar["Type"] = vartype_content["name"] + + tempvar["Edit"] = True + + initial = var.getinitialValue() + if initial: + tempvar["Initial Value"] = initial.getvalue() + else: + tempvar["Initial Value"] = "" + + address = var.getaddress() + if address: + tempvar["Location"] = address + else: + tempvar["Location"] = "" + + if varlist.getretain(): + tempvar["Retain"] = "Yes" + else: + tempvar["Retain"] = "No" + + if varlist.getconstant(): + tempvar["Constant"] = "Yes" + else: + tempvar["Constant"] = "No" + + doc = var.getdocumentation() + if doc: + tempvar["Documentation"] = doc.gettext() + else: + tempvar["Documentation"] = "" + + return tempvar # Replace the configuration globalvars by those given def SetConfigurationGlobalVars(self, name, vars): @@ -894,33 +949,8 @@ # Extract variables from every varLists for varlist in configuration.getglobalVars(): for var in varlist.getvariable(): - tempvar = {"Name" : var.getname(), "Class" : "Global"} - vartype_content = var.gettype().getcontent() - if vartype_content["name"] == "derived": - tempvar["Type"] = vartype_content["value"].getname() - elif vartype_content["name"] in ["string", "wstring"]: - tempvar["Type"] = vartype_content["name"].upper() - else: - tempvar["Type"] = vartype_content["name"] - tempvar["Edit"] = True - initial = var.getinitialValue() - if initial: - tempvar["Initial Value"] = initial.getvalue() - else: - tempvar["Initial Value"] = "" - address = var.getaddress() - if address: - tempvar["Location"] = address - else: - tempvar["Location"] = "" - if varlist.getretain(): - tempvar["Retain"] = "Yes" - else: - tempvar["Retain"] = "No" - if varlist.getconstant(): - tempvar["Constant"] = "Yes" - else: - tempvar["Constant"] = "No" + tempvar = self.GetVariableDictionary(varlist, var) + tempvar["Class"] = "Global" vars.append(tempvar) return vars @@ -946,33 +976,8 @@ # Extract variables from every varLists for varlist in resource.getglobalVars(): for var in varlist.getvariable(): - tempvar = {"Name" : var.getname(), "Class" : "Global"} - vartype_content = var.gettype().getcontent() - if vartype_content["name"] == "derived": - tempvar["Type"] = vartype_content["value"].getname() - elif vartype_content["name"] in ["string", "wstring"]: - tempvar["Type"] = vartype_content["name"].upper() - else: - tempvar["Type"] = vartype_content["name"] - tempvar["Edit"] = True - initial = var.getinitialValue() - if initial: - tempvar["Initial Value"] = initial.getvalue() - else: - tempvar["Initial Value"] = "" - address = var.getaddress() - if address: - tempvar["Location"] = address - else: - tempvar["Location"] = "" - if varlist.getretain(): - tempvar["Retain"] = "Yes" - else: - tempvar["Retain"] = "No" - if varlist.getconstant(): - tempvar["Constant"] = "Yes" - else: - tempvar["Constant"] = "No" + tempvar = self.GetVariableDictionary(varlist, var) + tempvar["Class"] = "Global" vars.append(tempvar) return vars @@ -1011,7 +1016,7 @@ tree.append((element.getname(), element_type["name"], ([], []))) return tree, [] return [], [] - + # Return the interface for the given pou def GetPouInterfaceVars(self, pou, debug = False): vars = [] @@ -1020,36 +1025,16 @@ # Extract variables from every varLists for type, varlist in pou.getvars(): for var in varlist.getvariable(): - tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : ([], [])} + tempvar = self.GetVariableDictionary(varlist, var) + + tempvar["Class"] = type + tempvar["Tree"] = ([], []) + vartype_content = var.gettype().getcontent() if vartype_content["name"] == "derived": - tempvar["Type"] = vartype_content["value"].getname() tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) - else: - if vartype_content["name"] in ["string", "wstring"]: - tempvar["Type"] = vartype_content["name"].upper() - else: - tempvar["Type"] = vartype_content["name"] - tempvar["Edit"] = True - initial = var.getinitialValue() - if initial: - tempvar["Initial Value"] = initial.getvalue() - else: - tempvar["Initial Value"] = "" - address = var.getaddress() - if address: - tempvar["Location"] = address - else: - tempvar["Location"] = "" - if varlist.getretain(): - tempvar["Retain"] = "Yes" - else: - tempvar["Retain"] = "No" - if varlist.getconstant(): - tempvar["Constant"] = "Yes" - else: - tempvar["Constant"] = "No" + vars.append(tempvar) return vars diff -r 53aa0c334f2f -r d19c4a6460ab VariablePanel.py --- a/VariablePanel.py Mon Sep 14 10:57:12 2009 -0600 +++ b/VariablePanel.py Tue Sep 15 14:06:59 2009 -0600 @@ -35,8 +35,8 @@ def GetVariableTableColnames(location): _ = lambda x : x if location: - return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant")] - return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant")] + return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")] + return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")] def GetAlternativeOptions(): _ = lambda x : x @@ -472,30 +472,60 @@ self.FilterChoices = [] self.FilterChoiceTransfer = GetFilterChoiceTransfer() + self.DefaultValue = { "Name" : "", "Class" : "", "Type" : "INT", "Location" : "", + "Initial Value" : "", "Retain" : "No", "Constant" : "No", + "Documentation" : "", "Edit" : True + } + if element_type in ["config", "resource"]: self.DefaultTypes = {"All" : "Global"} - self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} else: self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} - self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} - if element_type in ["config", "resource"] or element_type in ["program", "transition", "action"]: + + if element_type in ["config", "resource"] \ + or element_type in ["program", "transition", "action"]: + # this is an element that can have located variables self.Table = VariableTable(self, [], GetVariableTableColnames(True)) - if element_type not in ["config", "resource"]: - self.FilterChoices = ["All", "Interface", " Input", " Output", " InOut", " External", "Variables", " Local", " Temp"]#,"Access"] + + if element_type in ["config", "resource"]: + self.FilterChoices = ["All", "Global"]#,"Access"] else: - self.FilterChoices = ["All", "Global"]#,"Access"] - 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.FilterChoices = ["All", + "Interface", " Input", " Output", " InOut", " External", + "Variables", " Local", " Temp"]#,"Access"] + + # these condense the ColAlignements list + l = wx.ALIGN_LEFT + c = wx.ALIGN_CENTER + + # Num Name Class Type Loc Init Retain Const Doc + self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70, 80] + self.ColAlignements = [c, l, l, l, l, l, c, c, l] + + else: + # this is an element that cannot have located variables self.Table = VariableTable(self, [], GetVariableTableColnames(False)) + if element_type == "function": - self.FilterChoices = ["All", "Interface", " Input", " Output", " InOut", "Variables", " Local", " Temp"] + self.FilterChoices = ["All", + "Interface", " Input", " Output", " InOut", + "Variables", " Local", " Temp"] else: - self.FilterChoices = ["All", "Interface", " Input", " Output", " InOut", " External", "Variables", " Local", " Temp"] - 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] + self.FilterChoices = ["All", + "Interface", " Input", " Output", " InOut", " External", + "Variables", " Local", " Temp"] + + # these condense the ColAlignements list + l = wx.ALIGN_LEFT + c = wx.ALIGN_CENTER + + # Num Name Class Type Init Retain Const Doc + self.ColSizes = [40, 80, 70, 80, 80, 60, 70, 160] + self.ColAlignements = [c, l, l, l, l, c, c, l] + for choice in self.FilterChoices: self.ClassFilter.Append(_(choice)) + reverse_transfer = {} for filter, choice in self.FilterChoiceTransfer.items(): reverse_transfer[choice] = filter