245 variables = [] |
245 variables = [] |
246 project = self.GetProject(debug) |
246 project = self.GetProject(debug) |
247 if project is not None: |
247 if project is not None: |
248 for pou in project.getpous(): |
248 for pou in project.getpous(): |
249 if pou_name is None or pou_name == pou.getname(): |
249 if pou_name is None or pou_name == pou.getname(): |
250 variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou)]) |
250 variables.extend([var["Name"] for var in self.GetPouInterfaceVars(pou, debug)]) |
251 for transition in pou.gettransitionList(): |
251 for transition in pou.gettransitionList(): |
252 variables.append(transition.getname()) |
252 variables.append(transition.getname()) |
253 for action in pou.getactionList(): |
253 for action in pou.getactionList(): |
254 variables.append(action.getname()) |
254 variables.append(action.getname()) |
255 return variables |
255 return variables |
962 project = self.GetProject(debug) |
962 project = self.GetProject(debug) |
963 if project is not None: |
963 if project is not None: |
964 # Found the pou correponding to name and return the interface vars |
964 # Found the pou correponding to name and return the interface vars |
965 pou = project.getpou(name) |
965 pou = project.getpou(name) |
966 if pou is not None: |
966 if pou is not None: |
967 return self.GetPouInterfaceVars(pou) |
967 return self.GetPouInterfaceVars(pou, debug) |
968 return None |
968 return None |
969 |
969 |
|
970 # Recursively generate element name tree for a structured variable |
|
971 def GenerateVarTree(self, typename, debug = False): |
|
972 project = self.GetProject(debug) |
|
973 if project is not None: |
|
974 blocktype = self.GetBlockType(typename, debug = debug) |
|
975 if blocktype is not None: |
|
976 tree = {} |
|
977 for var_name, var_type, var_modifier in blocktype["inputs"] + blocktype["outputs"]: |
|
978 tree[var_name] = self.GenerateVarTree(var_type, debug) |
|
979 return tree |
|
980 datatype = project.getdataType(typename) |
|
981 if datatype is not None: |
|
982 tree = {} |
|
983 basetype_content = datatype.baseType.getcontent() |
|
984 if basetype_content["name"] == "derived": |
|
985 tree = self.GenerateVarTree(basetype_content["value"].getname()) |
|
986 elif basetype_content["name"] == "array": |
|
987 base_type = basetype_content["value"].baseType.getcontent() |
|
988 if base_type["name"] == "derived": |
|
989 tree = self.GenerateVarTree(base_type["value"].getname()) |
|
990 elif basetype_content["name"] == "struct": |
|
991 for element in basetype_content["value"].getvariable(): |
|
992 element_type = element.type.getcontent() |
|
993 if element_type["name"] == "derived": |
|
994 tree[element.getname()] = self.GenerateVarTree(element_type["value"].getname()) |
|
995 else: |
|
996 tree[element.getname()] = {} |
|
997 return tree |
|
998 return {} |
|
999 |
970 # Return the interface for the given pou |
1000 # Return the interface for the given pou |
971 def GetPouInterfaceVars(self, pou): |
1001 def GetPouInterfaceVars(self, pou, debug = False): |
972 vars = [] |
1002 vars = [] |
973 # Verify that the pou has an interface |
1003 # Verify that the pou has an interface |
974 if pou.interface is not None: |
1004 if pou.interface is not None: |
975 # Extract variables from every varLists |
1005 # Extract variables from every varLists |
976 for type, varlist in pou.getvars(): |
1006 for type, varlist in pou.getvars(): |
977 for var in varlist.getvariable(): |
1007 for var in varlist.getvariable(): |
978 tempvar = {"Name" : var.getname(), "Class" : type} |
1008 tempvar = {"Name" : var.getname(), "Class" : type, "Tree" : {}} |
979 vartype_content = var.gettype().getcontent() |
1009 vartype_content = var.gettype().getcontent() |
980 if vartype_content["name"] == "derived": |
1010 if vartype_content["name"] == "derived": |
981 tempvar["Type"] = vartype_content["value"].getname() |
1011 tempvar["Type"] = vartype_content["value"].getname() |
982 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
1012 tempvar["Edit"] = not pou.hasblock(tempvar["Name"]) |
|
1013 tempvar["Tree"] = self.GenerateVarTree(tempvar["Type"], debug) |
983 else: |
1014 else: |
984 if vartype_content["name"] in ["string", "wstring"]: |
1015 if vartype_content["name"] in ["string", "wstring"]: |
985 tempvar["Type"] = vartype_content["name"].upper() |
1016 tempvar["Type"] = vartype_content["name"].upper() |
986 else: |
1017 else: |
987 tempvar["Type"] = vartype_content["name"] |
1018 tempvar["Type"] = vartype_content["name"] |
1301 base_type = basetype_content["value"].baseType.getcontent() |
1332 base_type = basetype_content["value"].baseType.getcontent() |
1302 if base_type["value"] is None: |
1333 if base_type["value"] is None: |
1303 infos["base_type"] = base_type["name"] |
1334 infos["base_type"] = base_type["name"] |
1304 else: |
1335 else: |
1305 infos["base_type"] = base_type["value"].getname() |
1336 infos["base_type"] = base_type["value"].getname() |
|
1337 elif basetype_content["name"] == "struct": |
|
1338 infos["type"] = "Structure" |
|
1339 infos["elements"] = [] |
|
1340 for element in basetype_content["value"].getvariable(): |
|
1341 element_infos = {} |
|
1342 element_infos["Name"] = element.getname() |
|
1343 element_type = element.type.getcontent() |
|
1344 if element_type["value"] is None: |
|
1345 element_infos["Type"] = element_type["name"] |
|
1346 else: |
|
1347 element_infos["Type"] = element_type["value"].getname() |
|
1348 if element.initialValue is not None: |
|
1349 element_infos["Initial Value"] = str(element.initialValue.getvalue()) |
|
1350 else: |
|
1351 element_infos["Initial Value"] = "" |
|
1352 infos["elements"].append(element_infos) |
1306 if datatype.initialValue is not None: |
1353 if datatype.initialValue is not None: |
1307 infos["initial"] = str(datatype.initialValue.getvalue()) |
1354 infos["initial"] = str(datatype.initialValue.getvalue()) |
1308 else: |
1355 else: |
1309 infos["initial"] = "" |
1356 infos["initial"] = "" |
1310 return infos |
1357 return infos |
1372 else: |
1419 else: |
1373 derived_datatype = plcopen.derivedTypes_derived() |
1420 derived_datatype = plcopen.derivedTypes_derived() |
1374 derived_datatype.setname(infos["base_type"]) |
1421 derived_datatype.setname(infos["base_type"]) |
1375 array.baseType.setcontent({"name" : "derived", "value" : derived_datatype}) |
1422 array.baseType.setcontent({"name" : "derived", "value" : derived_datatype}) |
1376 datatype.baseType.setcontent({"name" : "array", "value" : array}) |
1423 datatype.baseType.setcontent({"name" : "array", "value" : array}) |
|
1424 elif infos["type"] == "Structure": |
|
1425 struct = plcopen.varListPlain() |
|
1426 for i, element_infos in enumerate(infos["elements"]): |
|
1427 element = plcopen.varListPlain_variable() |
|
1428 element.setname(element_infos["Name"]) |
|
1429 if element_infos["Type"] in self.GetBaseTypes(): |
|
1430 if element_infos["Type"] == "STRING": |
|
1431 element.type.setcontent({"name" : "string", "value" : plcopen.elementaryTypes_string()}) |
|
1432 elif element_infos["Type"] == "WSTRING": |
|
1433 element.type.setcontent({"name" : "wstring", "value" : plcopen.wstring()}) |
|
1434 else: |
|
1435 element.type.setcontent({"name" : element_infos["Type"], "value" : None}) |
|
1436 else: |
|
1437 derived_datatype = plcopen.derivedTypes_derived() |
|
1438 derived_datatype.setname(element_infos["Type"]) |
|
1439 element.type.setcontent({"name" : "derived", "value" : derived_datatype}) |
|
1440 if element_infos["Initial Value"] != "": |
|
1441 value = plcopen.value() |
|
1442 value.setvalue(element_infos["Initial Value"]) |
|
1443 element.setinitialValue(value) |
|
1444 if i == 0: |
|
1445 struct.setvariable([element]) |
|
1446 else: |
|
1447 struct.appendvariable(element) |
|
1448 datatype.baseType.setcontent({"name" : "struct", "value" : struct}) |
1377 if infos["initial"] != "": |
1449 if infos["initial"] != "": |
1378 if datatype.initialValue is None: |
1450 if datatype.initialValue is None: |
1379 datatype.initialValue = plcopen.value() |
1451 datatype.initialValue = plcopen.value() |
1380 datatype.initialValue.setvalue(infos["initial"]) |
1452 datatype.initialValue.setvalue(infos["initial"]) |
1381 else: |
1453 else: |
1382 datatype.initialValue = None |
1454 datatype.initialValue = None |
1383 self.Project.RefreshDataTypeHierarchy() |
1455 self.Project.RefreshDataTypeHierarchy() |
|
1456 self.Project.RefreshElementUsingTree() |
1384 self.BufferProject() |
1457 self.BufferProject() |
1385 |
1458 |
1386 #------------------------------------------------------------------------------- |
1459 #------------------------------------------------------------------------------- |
1387 # Project opened Pous management functions |
1460 # Project opened Pous management functions |
1388 #------------------------------------------------------------------------------- |
1461 #------------------------------------------------------------------------------- |
1442 if words[0] in ["P","T","A"]: |
1515 if words[0] in ["P","T","A"]: |
1443 project = self.GetProject(debug) |
1516 project = self.GetProject(debug) |
1444 if project is not None: |
1517 if project is not None: |
1445 pou = project.getpou(words[1]) |
1518 pou = project.getpou(words[1]) |
1446 if pou is not None: |
1519 if pou is not None: |
1447 return self.GetPouInterfaceVars(pou) |
1520 return self.GetPouInterfaceVars(pou, debug) |
1448 return [] |
1521 return [] |
1449 |
1522 |
1450 # Return the edited element return type |
1523 # Return the edited element return type |
1451 def GetEditedElementInterfaceReturnType(self, tagname, debug = False): |
1524 def GetEditedElementInterfaceReturnType(self, tagname, debug = False): |
1452 words = tagname.split("::") |
1525 words = tagname.split("::") |