diff -r a4382ae1ba82 -r 9dc0e38552b2 PLCControler.py --- a/PLCControler.py Sat Feb 17 16:42:56 2018 +0100 +++ b/PLCControler.py Sat Feb 17 23:58:47 2018 +0100 @@ -39,6 +39,7 @@ from util.TranslationCatalogs import NoTranslate from plcopen import * from plcopen.InstancesPathCollector import InstancesPathCollector +from plcopen.POUVariablesCollector import POUVariablesCollector from graphics.GraphicCommons import * from PLCGenerator import * @@ -209,65 +210,6 @@ _translate_args([_StringValue] * 5 + [_BoolValue] + [_StringValue], args) + [self.GetType(), self.GetTree()]))) -# ------------------------------------------------------------------------------- -# Helpers object for generating pou variable instance list -# ------------------------------------------------------------------------------- - - -def class_extraction(value): - class_type = { - "configuration": ITEM_CONFIGURATION, - "resource": ITEM_RESOURCE, - "action": ITEM_ACTION, - "transition": ITEM_TRANSITION, - "program": ITEM_PROGRAM}.get(value) - if class_type is not None: - return class_type - - pou_type = POU_TYPES.get(value) - if pou_type is not None: - return pou_type - - var_type = VAR_CLASS_INFOS.get(value) - if var_type is not None: - return var_type[1] - - return None - - -class _VariablesTreeItemInfos(object): - __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"] - - def __init__(self, *args): - for attr, value in zip(self.__slots__, args): - setattr(self, attr, value if value is not None else "") - - def copy(self): - return _VariablesTreeItemInfos(*[getattr(self, attr) for attr in self.__slots__]) - - -class VariablesTreeInfosFactory(object): - - def __init__(self): - self.Root = None - - def GetRoot(self): - return self.Root - - def SetRoot(self, context, *args): - self.Root = _VariablesTreeItemInfos( - *([''] + _translate_args( - [class_extraction, _StringValue] + [_BoolValue] * 2, - args) + [[]])) - - def AddVariable(self, context, *args): - if self.Root is not None: - self.Root.variables.append(_VariablesTreeItemInfos( - *(_translate_args( - [_StringValue, class_extraction, _StringValue] + - [_BoolValue] * 2, args) + [[]]))) - - class InstanceTagName(object): """Helpers object for generating instance tagname""" @@ -550,6 +492,7 @@ self.LastNewIndex = 0 self.Reset() self.InstancesPathCollector = InstancesPathCollector(self) + self.POUVariablesCollector = POUVariablesCollector(self) # Reset PLCControler internal variables def Reset(self): @@ -772,18 +715,6 @@ def GetPouVariables(self, tagname, debug=False): project = self.GetProject(debug) if project is not None: - factory = VariablesTreeInfosFactory() - - parser = etree.XMLParser() - parser.resolvers.add(LibraryResolver(self, debug)) - - pou_variable_xslt_tree = etree.XSLT( - etree.parse( - os.path.join(ScriptDirectory, "plcopen", "pou_variables.xslt"), - parser), - extensions={("pou_vars_ns", name): getattr(factory, name) - for name in ["SetRoot", "AddVariable"]}) - obj = None words = tagname.split("::") if words[0] == "P": @@ -791,8 +722,7 @@ elif words[0] != "D": obj = self.GetEditedElement(tagname, debug) if obj is not None: - pou_variable_xslt_tree(obj) - return factory.GetRoot() + return self.POUVariablesCollector.Collect(obj, debug) return None