955 else: |
955 else: |
956 tempvar["Constant"] = "No" |
956 tempvar["Constant"] = "No" |
957 vars.append(tempvar) |
957 vars.append(tempvar) |
958 return vars |
958 return vars |
959 |
959 |
960 # Return the interface of the pou given by its name |
|
961 def GetPouInterfaceVarsByName(self, name, debug = False): |
|
962 project = self.GetProject(debug) |
|
963 if project is not None: |
|
964 # Found the pou correponding to name and return the interface vars |
|
965 pou = project.getpou(name) |
|
966 if pou is not None: |
|
967 return self.GetPouInterfaceVars(pou, debug) |
|
968 return None |
|
969 |
|
970 # Recursively generate element name tree for a structured variable |
960 # Recursively generate element name tree for a structured variable |
971 def GenerateVarTree(self, typename, debug = False): |
961 def GenerateVarTree(self, typename, debug = False): |
972 project = self.GetProject(debug) |
962 project = self.GetProject(debug) |
973 if project is not None: |
963 if project is not None: |
974 blocktype = self.GetBlockType(typename, debug = debug) |
964 blocktype = self.GetBlockType(typename, debug = debug) |
975 if blocktype is not None: |
965 if blocktype is not None: |
976 tree = {} |
966 tree = [] |
977 for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
967 for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
978 tree[var_name] = self.GenerateVarTree(var_type, debug) |
968 tree.append((var_name, var_type, self.GenerateVarTree(var_type, debug))) |
979 return tree |
969 return tree |
980 datatype = project.getdataType(typename) |
970 datatype = project.getdataType(typename) |
981 if datatype is not None: |
971 if datatype is not None: |
982 tree = {} |
972 tree = [] |
983 basetype_content = datatype.baseType.getcontent() |
973 basetype_content = datatype.baseType.getcontent() |
984 if basetype_content["name"] == "derived": |
974 if basetype_content["name"] == "derived": |
985 tree = self.GenerateVarTree(basetype_content["value"].getname()) |
975 tree = self.GenerateVarTree(basetype_content["value"].getname()) |
986 elif basetype_content["name"] == "array": |
976 elif basetype_content["name"] == "array": |
987 base_type = basetype_content["value"].baseType.getcontent() |
977 base_type = basetype_content["value"].baseType.getcontent() |
988 if base_type["name"] == "derived": |
978 if base_type["name"] == "derived": |
989 tree = self.GenerateVarTree(base_type["value"].getname()) |
979 tree = [self.GenerateVarTree(base_type["value"].getname())] |
990 elif basetype_content["name"] == "struct": |
980 elif basetype_content["name"] == "struct": |
991 for element in basetype_content["value"].getvariable(): |
981 for element in basetype_content["value"].getvariable(): |
992 element_type = element.type.getcontent() |
982 element_type = element.type.getcontent() |
993 if element_type["name"] == "derived": |
983 if element_type["name"] == "derived": |
994 tree[element.getname()] = self.GenerateVarTree(element_type["value"].getname()) |
984 tree.append((element.getname(), element_type["value"].getname(), self.GenerateVarTree(element_type["value"].getname()))) |
995 else: |
985 else: |
996 tree[element.getname()] = {} |
986 tree.append((element.getname(), element_type["name"], [])) |
997 return tree |
987 return tree |
998 return {} |
988 return {} |
999 |
989 |
1000 # Return the interface for the given pou |
990 # Return the interface for the given pou |
1001 def GetPouInterfaceVars(self, pou, debug = False): |
991 def GetPouInterfaceVars(self, pou, debug = False): |
1003 # Verify that the pou has an interface |
993 # Verify that the pou has an interface |
1004 if pou.interface is not None: |
994 if pou.interface is not None: |
1005 # Extract variables from every varLists |
995 # Extract variables from every varLists |
1006 for type, varlist in pou.getvars(): |
996 for type, varlist in pou.getvars(): |
1007 for var in varlist.getvariable(): |
997 for var in varlist.getvariable(): |
1008 tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : {}} |
998 tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : []} |
1009 vartype_content = var.gettype().getcontent() |
999 vartype_content = var.gettype().getcontent() |
1010 if vartype_content["name"] == "derived": |
1000 if vartype_content["name"] == "derived": |
1011 tempvar["Type"] = vartype_content["value"].getname() |
1001 tempvar["Type"] = vartype_content["value"].getname() |
1012 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
1002 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
1013 tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) |
1003 tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) |