--- a/PLCControler.py Sat May 19 12:40:53 2012 +0200
+++ b/PLCControler.py Mon May 21 09:59:44 2012 +0200
@@ -577,7 +577,7 @@
return ["%s.%s" % (words[1], words[2])]
return []
- def RecursiveGetPouInstanceTagname(self, project, pou_type, parts):
+ def RecursiveGetPouInstanceTagName(self, project, pou_type, parts):
pou = project.getpou(pou_type)
if pou is not None:
if len(parts) == 0:
@@ -587,13 +587,13 @@
for variable in varlist.getvariable():
vartype_content = variable.gettype().getcontent()
if vartype_content["name"] == "derived":
- return self.RecursiveGetPouInstanceTagname(
+ return self.RecursiveGetPouInstanceTagName(
project,
vartype_content["value"].getname(),
parts[1:])
return None
- def GetPouInstanceTagname(self, instance_path, debug = False):
+ def GetPouInstanceTagName(self, instance_path, debug = False):
parts = instance_path.split(".")
if len(parts) == 1:
return self.ComputeConfigurationName(parts[0])
@@ -614,149 +614,26 @@
return self.ComputePouName(
pou_instance.gettypeName())
else:
- return self.RecursiveGetPouInstanceTagname(
+ return self.RecursiveGetPouInstanceTagName(
project,
pou_instance.gettypeName(),
parts[3:])
return None
- def GetInstanceInfos(self, instance_path):
+ def GetInstanceInfos(self, instance_path, debug = False):
tagname = self.GetPouInstanceTagName(instance_path)
if tagname is not None:
- return self.Controler.GetPouVariables(tagname, self.Debug)
+ return self.GetPouVariables(tagname, debug)
else:
- pou_path, var_name = tagname.rsplit(".", 1)
- tagname = self.Controler.GetPouInstanceTagName(pou_path)
+ pou_path, var_name = instance_path.rsplit(".", 1)
+ tagname = self.GetPouInstanceTagName(pou_path)
if tagname is not None:
- pou_infos = self.Controler.GetPouVariables(tagname, self.Debug)
+ pou_infos = self.GetPouVariables(tagname, debug)
for var_infos in pou_infos["variables"]:
if var_infos["name"] == var_name:
return var_infos
return None
-
- # Return project topology informations
- def GetProjectTopology(self, debug = False):
- project = self.GetProject(debug)
- if project is not None:
- infos = {"name": project.getname(), "type": ITEM_PROJECT, "values" : []}
- for config in project.getconfigurations():
- config_infos = {"name" : config.getname(), "type": ITEM_CONFIGURATION, "values" : []}
- for resource in config.getresource():
- resource_infos = {"name" : resource.getname(), "type": ITEM_RESOURCE, "values": []}
- for task in resource.gettask():
- for pou in task.getpouInstance():
- instance_infos = self.GetPouTopology(pou.getname(), pou.gettypeName(), debug=debug)
- if instance_infos is not None:
- resource_infos["values"].append(instance_infos)
- for pou in resource.getpouInstance():
- instance_infos = self.GetPouTopology(pou.getname(), pou.gettypeName(), debug=debug)
- if instance_infos is not None:
- resource_infos["values"].append(instance_infos)
- for varlist in resource.getglobalVars():
- for variable in varlist.getvariable():
- vartype_content = variable.gettype().getcontent()
- if vartype_content["name"] == "derived":
- var_infos = self.GetPouTopology(variable.getname(), vartype_content["value"].getname(), True, debug)
- if var_infos is not None:
- resource_infos["values"].append(var_infos)
- elif vartype_content["name"] in ["string", "wstring"]:
- resource_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"].upper(),
- "type" : ITEM_VAR_GLOBAL, "values" : []})
- else:
- resource_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"],
- "type" : ITEM_VAR_GLOBAL, "values" : []})
- config_infos["values"].append(resource_infos)
- for varlist in config.getglobalVars():
- for variable in varlist.getvariable():
- vartype_content = variable.gettype().getcontent()
- if vartype_content["name"] == "derived":
- var_infos = self.GetPouTopology(variable.getname(), vartype_content["value"].getname(), True, debug)
- if var_infos is not None:
- config_infos["values"].append(var_infos)
- elif vartype_content["name"] in ["string", "wstring"]:
- config_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"].upper(),
- "type" : ITEM_VAR_GLOBAL, "values" : []})
- else:
- config_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"],
- "type" : ITEM_VAR_GLOBAL, "values" : []})
- infos["values"].append(config_infos)
- return infos
- return None
-
- # Return pou topology informations
- def GetPouTopology(self, name, type, global_var = False, debug = False):
- project = self.GetProject(debug)
- if project is not None:
- pou = project.getpou(type)
- if pou is not None:
- pou_type = pou.getpouType()
- if pou_type == "function":
- return None
- elif pou_type == "program":
- pou_infos = {"name" : name, "elmt_type" : type, "type" : ITEM_PROGRAM,
- "tagname" : self.ComputePouName(pou.getname()), "values" : []}
- else:
- pou_infos = {"name" : name, "elmt_type" : type, "type" : ITEM_FUNCTIONBLOCK,
- "tagname" : self.ComputePouName(pou.getname()), "values" : []}
- if pou.getbodyType() == "SFC":
- for transition in pou.gettransitionList():
- pou_infos["values"].append({"name" : transition.getname(),
- "elmt_type" : "TRANSITION", "type" : ITEM_TRANSITION,
- "tagname" : self.ComputePouActionName(pou.getname(), transition.getname()),
- "values" : []})
- for action in pou.getactionList():
- pou_infos["values"].append({"name": action.getname(),
- "elmt_type" : "ACTION", "type": ITEM_ACTION,
- "tagname" : self.ComputePouActionName(pou.getname(), action.getname()),
- "values" : []})
- if pou.interface:
- # Extract variables from every varLists
- for type, varlist in pou.getvars():
- infos = VAR_CLASS_INFOS.get(type, None)
- if infos is not None:
- current_var_class = infos[1]
- else:
- current_var_class = ITEM_VAR_LOCAL
- for variable in varlist.getvariable():
- vartype_content = variable.gettype().getcontent()
- if vartype_content["name"] == "derived":
- var_infos = self.GetPouTopology(variable.getname(), vartype_content["value"].getname())
- if var_infos is not None:
- pou_infos["values"].append(var_infos)
- elif vartype_content["name"] in ["string", "wstring"]:
- pou_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"].upper(),
- "type" : current_var_class, "values" : []})
- else:
- pou_infos["values"].append({"name" : variable.getname(),
- "elmt_type" : vartype_content["name"],
- "type" : current_var_class, "values" : []})
- return pou_infos
- block_infos = self.GetBlockType(type, debug = debug)
- if block_infos is not None:
- if block_infos["type"] == "function":
- return None
- elif block_infos["type"] == "program":
- pou_infos = {"name" : name, "elmt_type" : type, "type" : ITEM_PROGRAM, "values" : []}
- else:
- pou_infos = {"name" : name, "elmt_type" : type, "type" : ITEM_FUNCTIONBLOCK, "values" : []}
- for varname, vartype, varmodifier in block_infos["inputs"]:
- pou_infos["values"].append({"name" : varname, "elmt_type" : vartype, "type" : ITEM_VAR_INPUT, "values" : []})
- for varname, vartype, varmodifier in block_infos["outputs"]:
- pou_infos["values"].append({"name" : varname, "elmt_type" : vartype, "type" : ITEM_VAR_OUTPUT, "values" : []})
- return pou_infos
-
- if type in self.GetDataTypes(debug = debug):
- if global_var:
- return {"name" : name, "elmt_type" : type, "type" : ITEM_VAR_GLOBAL, "values" : []}
- else:
- return {"name" : name, "elmt_type" : type, "type" : ITEM_VAR_LOCAL, "values" : []}
- return None
-
+
# Return if data type given by name is used by another data type or pou
def DataTypeIsUsed(self, name, debug = False):
project = self.GetProject(debug)
@@ -919,6 +796,15 @@
self.Project.removepou(pou_name)
self.BufferProject()
+ # Return the name of the configuration if only one exist
+ def GetProjectMainConfigurationName(self):
+ if self.Project is not None:
+ # Found the configuration corresponding to old name and change its name to new name
+ configurations = self.Project.getconfigurations()
+ if len(configurations) == 1:
+ return configurations[0].getname()
+ return None
+
# Add a configuration to Project
def ProjectAddConfiguration(self, config_name):
if self.Project is not None: