plcopen/POUVariablesCollector.py
changeset 1953 5736d25bb393
parent 1952 0c20fc810d61
child 1973 cc7a46953471
equal deleted inserted replaced
1952:0c20fc810d61 1953:5736d25bb393
     4 # See COPYING file for copyrights details.
     4 # See COPYING file for copyrights details.
     5 
     5 
     6 from __future__ import absolute_import
     6 from __future__ import absolute_import
     7 from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args
     7 from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args
     8 from plcopen.types_enums import CLASS_TYPES, POU_TYPES, VAR_CLASS_INFOS
     8 from plcopen.types_enums import CLASS_TYPES, POU_TYPES, VAR_CLASS_INFOS
       
     9 
     9 
    10 
    10 def class_extraction(value):
    11 def class_extraction(value):
    11     class_type = CLASS_TYPES.get(value)
    12     class_type = CLASS_TYPES.get(value)
    12     if class_type is not None:
    13     if class_type is not None:
    13         return class_type
    14         return class_type
    54                 *(_translate_args(
    55                 *(_translate_args(
    55                     [_StringValue, class_extraction, _StringValue] +
    56                     [_StringValue, class_extraction, _StringValue] +
    56                     [_BoolValue] * 2, args) + [[]])))
    57                     [_BoolValue] * 2, args) + [[]])))
    57 
    58 
    58 
    59 
    59 
       
    60 class POUVariablesCollector(XSLTModelQuery):
    60 class POUVariablesCollector(XSLTModelQuery):
    61     def __init__(self, controller):
    61     def __init__(self, controller):
    62         XSLTModelQuery.__init__(self,
    62         XSLTModelQuery.__init__(self,
    63                                 controller,
    63                                 controller,
    64                                 "pou_variables.xslt",
    64                                 "pou_variables.xslt",
    65                                 [(name, self.FactoryCaller(name)) 
    65                                 [(name, self.FactoryCaller(name))
    66                                     for name in ["SetRoot", "AddVariable"]])
    66                                  for name in ["SetRoot", "AddVariable"]])
    67 
    67 
    68     def FactoryCaller(self, funcname):
    68     def FactoryCaller(self, funcname):
    69         def CallFactory(*args):
    69         def CallFactory(*args):
    70             return getattr(self.factory, funcname)(*args)
    70             return getattr(self.factory, funcname)(*args)
    71         return CallFactory
    71         return CallFactory
    74         self.factory = VariablesTreeInfosFactory()
    74         self.factory = VariablesTreeInfosFactory()
    75         self._process_xslt(root, debug)
    75         self._process_xslt(root, debug)
    76         res = self.factory.GetRoot()
    76         res = self.factory.GetRoot()
    77         self.factory = None
    77         self.factory = None
    78         return res
    78         return res
    79