# This file is part of Beremiz.
# See COPYING file for copyrights details.
from __future__ import absolute_import
from plcopen.XSLTModelQuery import XSLTModelQuery
def class_extraction(value):
"configuration": ITEM_CONFIGURATION,
"resource": ITEM_RESOURCE,
"transition": ITEM_TRANSITION,
"program": ITEM_PROGRAM}.get(value)
if class_type is not None:
pou_type = POU_TYPES.get(value)
var_type = VAR_CLASS_INFOS.get(value)
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 "")
return _VariablesTreeItemInfos(*[getattr(self, attr) for attr in self.__slots__])
class VariablesTreeInfosFactory(object):
def SetRoot(self, context, *args):
self.Root = _VariablesTreeItemInfos(
*([''] + _translate_args(
[class_extraction, _StringValue] + [_BoolValue] * 2,
def AddVariable(self, context, *args):
if self.Root is not None:
self.Root.variables.append(_VariablesTreeItemInfos(
[_StringValue, class_extraction, _StringValue] +
[_BoolValue] * 2, args) + [[]])))
class POUVariablesCollector(XSLTModelQuery):
""" object for collecting instances path list"""
def __init__(self, controller):
XSLTModelQuery.__init__(self,
[(name, lambda *x : getattr(self.factory, name)(*x))
for name in ["SetRoot", "AddVariable"]])
def Collect(self, root, debug):
self.factory = VariablesTreeInfosFactory()
self._process_xslt(root, debug)
res = self.factory.GetRoot()