Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
authorlaurent
Thu, 10 Dec 2009 16:37:11 +0100
changeset 483 779a519f78f2
parent 482 4edbbab206a3
child 484 acef952101a5
Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
PLCControler.py
PLCGenerator.py
VariablePanel.py
plcopen/structures.py
--- a/PLCControler.py	Thu Dec 10 12:26:06 2009 +0100
+++ b/PLCControler.py	Thu Dec 10 16:37:11 2009 +0100
@@ -875,13 +875,12 @@
         current_type = None
         for var in vars:
             next_type = (var["Class"], 
-                                var["Retain"], 
-                                var["Constant"], 
-                                var["Location"] in ["", None] or 
-                                    # When declaring globals, located 
-                                    # and not located variables are 
-                                    # in the same declaration block
-                                    var["Class"] == "Global")
+                         var["Option"], 
+                         var["Location"] in ["", None] or 
+                         # When declaring globals, located 
+                         # and not located variables are 
+                         # in the same declaration block
+                         var["Class"] == "Global")
             if current_type != next_type:
                 current_type = next_type
                 infos = VAR_CLASS_INFOS.get(var["Class"], None)
@@ -890,10 +889,12 @@
                 else:
                     current_varlist = plcopen.varList()
                 varlist_list.append((var["Class"], current_varlist))
-                if var["Retain"] == "Yes":
+                if var["Option"] == "Constant":
+                    current_varlist.setconstant(True)
+                elif var["Option"] == "Retain":
                     current_varlist.setretain(True)
-                if var["Constant"] == "Yes":
-                    current_varlist.setconstant(True)
+                elif var["Option"] == "Non-Retain":
+                    current_varlist.setnonretain(True)
             # Create variable and change its properties
             tempvar = plcopen.varListPlain_variable()
             tempvar.setname(var["Name"])
@@ -935,7 +936,7 @@
         returned by Get*Vars)
         '''
 
-        tempvar = {"Name" : var.getname()}
+        tempvar = {"Name": var.getname()}
 
         vartype_content = var.gettype().getcontent()
         if vartype_content["name"] == "derived":
@@ -959,15 +960,14 @@
         else:
             tempvar["Location"] = ""
 
-        if varlist.getretain():
-            tempvar["Retain"] = "Yes"
+        if varlist.getconstant():
+            tempvar["Option"] = "Constant"
+        elif varlist.getretain():
+            tempvar["Option"] = "Retain"
+        elif varlist.getnonretain():
+            tempvar["Option"] = "Non-Retain"
         else:
-            tempvar["Retain"] = "No"
-
-        if varlist.getconstant():
-            tempvar["Constant"] = "Yes"
-        else:
-            tempvar["Constant"] = "No"
+            tempvar["Option"] = ""
 
         doc = var.getdocumentation()
         if doc:
--- a/PLCGenerator.py	Thu Dec 10 12:26:06 2009 +0100
+++ b/PLCGenerator.py	Thu Dec 10 16:37:11 2009 +0100
@@ -249,10 +249,12 @@
         for varlist in configuration.getglobalVars():
             # Generate variable block with modifier
             config += [("  VAR_GLOBAL", ())]
-            if varlist.getretain():
-                config += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))]
             if varlist.getconstant():
                 config += [(" CONSTANT", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "constant"))]
+            elif varlist.getretain():
+                config += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))]
+            elif varlist.getretain():
+                config += [(" NON_RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "non_retain"))]
             config += [("\n", ())]
             # Generate any variable of this block
             for var in varlist.getvariable():
@@ -302,10 +304,12 @@
         for varlist in resource.getglobalVars():
             # Generate variable block with modifier
             resrce += [("    VAR_GLOBAL", ())]
-            if varlist.getretain():
-                resrce += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))]
             if varlist.getconstant():
                 resrce += [(" CONSTANT", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "constant"))]
+            elif varlist.getretain():
+                resrce += [(" RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "retain"))]
+            elif varlist.getnonretain():
+                resrce += [(" NON_RETAIN", (tagname, "variable", (var_number, var_number + len(varlist.getvariable())), "non_retain"))]
             resrce += [("\n", ())]
             # Generate any variable of this block
             for var in varlist.getvariable():
@@ -471,7 +475,7 @@
     
     # Test if a variable has already been defined
     def IsAlreadyDefined(self, name):
-        for list_type, retain, constant, located, vars in self.Interface:
+        for list_type, option, located, vars in self.Interface:
             for var_type, var_name, var_address, var_initial in vars:
                 if name == var_name:
                     return True
@@ -479,7 +483,7 @@
     
     # Return the type of a variable defined in interface
     def GetVariableType(self, name):
-        for list_type, retain, constant, located, vars in self.Interface:
+        for list_type, option, located, vars in self.Interface:
             for var_type, var_name, var_address, var_initial in vars:
                 if name == var_name:
                     return var_type
@@ -592,12 +596,18 @@
                             located.append((vartype_content["name"], var.getname(), address, initial_value))
                         else:
                             variables.append((vartype_content["name"], var.getname(), None, initial_value))
+                if varlist["value"].getconstant():
+                    option = "CONSTANT"
+                elif varlist["value"].getretain():
+                    option = "RETAIN"
+                elif varlist["value"].getnonretain():
+                    option = "NON_RETAIN"
+                else:
+                    option = None
                 if len(variables) > 0:
-                    self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
-                                varlist["value"].getconstant(), False, variables))
+                    self.Interface.append((varTypeNames[varlist["name"]], option, False, variables))
                 if len(located) > 0:
-                    self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getretain(), 
-                                varlist["value"].getconstant(), True, located))
+                    self.Interface.append((varTypeNames[varlist["name"]], option, True, located))
         
     def ComputeConnectionTypes(self, pou):
         body = pou.getbody()
@@ -951,14 +961,14 @@
         return expression
     
     def AddTrigger(self, edge, expression, var_info):
-        if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]:
-            self.Interface.append(("VAR", False, False, False, []))
+        if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] is not None or self.Interface[-1][2]:
+            self.Interface.append(("VAR", None, False, []))
         i = 1
         name = "%s%d"%(edge, i)
         while self.IsAlreadyDefined(name):
             i += 1
             name = "%s%d"%(edge, i)
-        self.Interface[-1][4].append((edge, name, None, None))
+        self.Interface[-1][3].append((edge, name, None, None))
         self.Program += [(self.CurrentIndent, ()), (name, var_info), ("(CLK := ", ())] 
         self.Program += expression
         self.Program += [(");\n", ())]
@@ -1256,12 +1266,10 @@
         if len(self.Program) == 0 :
             raise PLCGenException, _("No body defined in \"%s\" POU")%self.Name
         var_number = 0
-        for list_type, retain, constant, located, variables in self.Interface:
+        for list_type, option, located, variables in self.Interface:
             program += [("  %s"%list_type, ())]
-            if retain:
-                program += [(" RETAIN", (self.TagName, "variable", (var_number, var_number + len(variables)), "retain"))]
-            if constant:
-                program += [(" CONSTANT", (self.TagName, "variable", (var_number, var_number + len(variables)), "constant"))]
+            if option is not None:
+                program += [(" %s"%option, (self.TagName, "variable", (var_number, var_number + len(variables)), option.lower()))]
             program += [("\n", ())]
             for var_type, var_name, var_address, var_initial in variables:
                 program += [("    ", ())]
--- a/VariablePanel.py	Thu Dec 10 12:26:06 2009 +0100
+++ b/VariablePanel.py	Thu Dec 10 16:37:11 2009 +0100
@@ -49,13 +49,13 @@
 def GetVariableTableColnames(location):
     _ = lambda x : x
     if location:
-    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
-    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
-
-def GetAlternativeOptions():
+    	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
+    return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
+
+def GetOptions():
     _ = lambda x : x
-    return [_("Yes"), _("No")]
-ALTERNATIVE_OPTIONS_DICT = dict([(_(option), option) for option in GetAlternativeOptions()])
+    return ["", _("Constant"), _("Retain"), _("Non-Retain")]
+OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
 
 def GetFilterChoiceTransfer():
     _ = lambda x : x
@@ -105,7 +105,7 @@
                 return self.data[row]["Number"]
             colname = self.GetColLabelValue(col, False)
             value = str(self.data[row].get(colname, ""))
-            if colname in ["Class", "Retain", "Constant"]:
+            if colname in ["Class", "Option"]:
                 return _(value)
             return value
     
@@ -116,8 +116,8 @@
                 self.old_value = self.data[row][colname]
             elif colname == "Class":
                 value = VARIABLE_CLASSES_DICT[value]
-            elif colname in ["Retain", "Constant"]:
-                value = ALTERNATIVE_OPTIONS_DICT[value]
+            elif colname == "Option":
+                value = OPTIONS_DICT[value]
             self.data[row][colname] = value
     
     def GetValueByName(self, row, colname):
@@ -177,7 +177,10 @@
                 editor = None
                 renderer = None
                 colname = self.GetColLabelValue(col, False)
-                if col != 0 and self.GetValueByName(row, "Edit"):
+                if colname == "Option":
+                    editor = wx.grid.GridCellChoiceEditor()
+                    editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
+                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"]:
@@ -205,12 +208,7 @@
                             if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
                                 excluded.extend(["Local","Temp"])
                             editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
-                    elif colname in ["Retain", "Constant"]:
-                        editor = wx.grid.GridCellChoiceEditor()
-                        editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
-                    elif colname == "Type":
-                        editor = wx.grid.GridCellTextEditor()
-                else:
+                elif colname != "Documentation":
                     grid.SetReadOnly(row, col, True)
                 
                 grid.SetCellEditor(row, col, editor)
@@ -486,7 +484,7 @@
         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
         
         self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
-                                "Initial Value" : "", "Retain" : "No", "Constant" : "No",
+                                "Initial Value" : "", "Option" : "",
                                 "Documentation" : "", "Edit" : True
                             }
 
@@ -511,9 +509,9 @@
             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]
+            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
+            self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
+            self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]
 
         else:
             # this is an element that cannot have located variables
@@ -532,9 +530,9 @@
             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]
+            #                      Num  Name    Class   Type    Init    Option   Doc
+            self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
+            self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
 
         for choice in self.FilterChoices:
             self.ClassFilter.Append(_(choice))
@@ -545,7 +543,7 @@
         self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
         self.RefreshTypeList()
 
-        self.OptionList = GetAlternativeOptions()
+        self.OptionList = GetOptions()
         
         if element_type == "function":
             for base_type in self.Controler.GetBaseTypes():
@@ -707,12 +705,13 @@
                     self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
                 self.Controler.BufferProject()
                 self.ParentWindow.RefreshEditor(variablepanel = False)
-                self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
+                self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
                 event.Skip()
         else:
             self.SaveValues()
             if colname == "Class":
                 self.Table.ResetView(self.VariablesGrid)
+            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU)
             event.Skip()
     
     def OnVariablesGridEditorShown(self, event):
--- a/plcopen/structures.py	Thu Dec 10 12:26:06 2009 +0100
+++ b/plcopen/structures.py	Thu Dec 10 16:37:11 2009 +0100
@@ -74,12 +74,12 @@
                         variable_name = "%s%d"%(type, block.getlocalId())
                     else:
                         variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter)
-                    if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]:
-                        generator.Interface.append(("VAR", False, False, False, []))
+                    if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] is not None or generator.Interface[-1][2]:
+                        generator.Interface.append(("VAR", None, False, []))
                     if variable.connectionPointOut in generator.ConnectionTypes:
-                        generator.Interface[-1][4].append((generator.ConnectionTypes[variable.connectionPointOut], variable_name, None, None))
+                        generator.Interface[-1][3].append((generator.ConnectionTypes[variable.connectionPointOut], variable_name, None, None))
                     else:
-                        generator.Interface[-1][4].append(("ANY", variable_name, None, None))
+                        generator.Interface[-1][3].append(("ANY", variable_name, None, None))
                     if len(output_variables) > 1 and parameter not in ["", "OUT"]:
                         vars.append([(parameter, (generator.TagName, "block", block.getlocalId(), "output", i)), 
                                      (" => %s"%variable_name, ())])