Adding support for generating real array dimension in variable blocks
authorlbessard
Mon, 12 Jan 2009 09:41:47 +0100
changeset 299 15669fe26e56
parent 298 1b1a3ee785da
child 300 34d1402c0e24
Adding support for generating real array dimension in variable blocks
PLCControler.py
TextViewer.py
Viewer.py
--- a/PLCControler.py	Fri Jan 09 17:11:09 2009 +0100
+++ b/PLCControler.py	Mon Jan 12 09:41:47 2009 +0100
@@ -966,26 +966,32 @@
                 tree = []
                 for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]:
                     tree.append((var_name, var_type, self.GenerateVarTree(var_type, debug)))
-                return tree
+                return tree, []
             datatype = project.getdataType(typename)
             if datatype is not None:
                 tree = []
                 basetype_content = datatype.baseType.getcontent()
                 if basetype_content["name"] == "derived":
-                    tree = self.GenerateVarTree(basetype_content["value"].getname())
+                    return self.GenerateVarTree(basetype_content["value"].getname())
                 elif basetype_content["name"] == "array":
+                    dimensions = []
                     base_type = basetype_content["value"].baseType.getcontent()
                     if base_type["name"] == "derived":
-                        tree = [self.GenerateVarTree(base_type["value"].getname())]
+                        tree = self.GenerateVarTree(base_type["value"].getname())
+                        if len(tree[1]) == 0:
+                            tree = tree[0]
+                        for dimension in basetype_content["value"].getdimension():
+                            dimensions.append((dimension.getlower(), dimension.getupper()))
+                    return tree, dimensions
                 elif basetype_content["name"] == "struct":
                     for element in basetype_content["value"].getvariable():
                         element_type = element.type.getcontent()
                         if element_type["name"] == "derived":
                             tree.append((element.getname(), element_type["value"].getname(), self.GenerateVarTree(element_type["value"].getname())))
                         else:
-                            tree.append((element.getname(), element_type["name"], []))
-                return tree
-        return {}
+                            tree.append((element.getname(), element_type["name"], ([], [])))
+                    return tree, []
+        return [], []
     
     # Return the interface for the given pou
     def GetPouInterfaceVars(self, pou, debug = False):
@@ -995,7 +1001,7 @@
             # Extract variables from every varLists
             for type, varlist in pou.getvars():
                 for var in varlist.getvariable():
-                    tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : []}
+                    tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : ([], [])}
                     vartype_content = var.gettype().getcontent()
                     if vartype_content["name"] == "derived":
                         tempvar["Type"] = vartype_content["value"].getname()
--- a/TextViewer.py	Fri Jan 09 17:11:09 2009 +0100
+++ b/TextViewer.py	Mon Jan 12 09:41:47 2009 +0100
@@ -294,7 +294,7 @@
         tree = {}
         if len(list) == 1 and isinstance(list, ListType):
             list = list[0]
-        for var_name, var_type, var_tree in list:
+        for var_name, var_type, (var_tree, var_dimension) in list:
             tree[var_name] = self.GenerateVariableTree(var_tree)
         return tree
     
--- a/Viewer.py	Fri Jan 09 17:11:09 2009 +0100
+++ b/Viewer.py	Mon Jan 12 09:41:47 2009 +0100
@@ -176,15 +176,14 @@
             wx.CallAfter(self.ShowMessage, message)
 
     def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
-        for child_name, child_type, child_tree in tree:
+        for child_name, child_type, (child_tree, child_dimensions) in tree:
             if base_path:
                 child_path = "%s.%s" % (base_path, child_name)
             else:
                 child_path = child_name
-            if len(child_tree) == 1 and isinstance(child_tree[0], ListType):
-                child_path += "[0]"
+            if len(child_dimensions) > 0:
+                child_path += "[%s]" % ",".join([str(dimension[0]) for dimension in child_dimensions])
                 child_name += "[]"
-                child_tree = child_tree[0]
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name)
             self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id)