plcopen/InstanceTagnameCollector.py
changeset 1950 752ec68da94d
child 1952 0c20fc810d61
equal deleted inserted replaced
1949:c266fbaae0f6 1950:752ec68da94d
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 # This file is part of Beremiz.
       
     4 # See COPYING file for copyrights details.
       
     5 
       
     6 from __future__ import absolute_import
       
     7 from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args
       
     8 from plcopen.types_enums import *
       
     9 
       
    10 class InstanceTagName(object):
       
    11     """Helpers object for generating instance tagname"""
       
    12 
       
    13     def __init__(self):
       
    14         self.TagName = None
       
    15 
       
    16     def GetTagName(self):
       
    17         return self.TagName
       
    18 
       
    19     def ConfigTagName(self, context, *args):
       
    20         self.TagName = ComputeConfigurationName(args[0][0])
       
    21 
       
    22     def ResourceTagName(self, context, *args):
       
    23         self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0])
       
    24 
       
    25     def PouTagName(self, context, *args):
       
    26         self.TagName = ComputePouName(args[0][0])
       
    27 
       
    28     def ActionTagName(self, context, *args):
       
    29         self.TagName = ComputePouActionName(args[0][0], args[0][1])
       
    30 
       
    31     def TransitionTagName(self, context, *args):
       
    32         self.TagName = ComputePouTransitionName(args[0][0], args[0][1])
       
    33 
       
    34 
       
    35 class InstanceTagnameCollector(XSLTModelQuery):
       
    36     """ object for collecting instances path list"""
       
    37     def __init__(self, controller):
       
    38         XSLTModelQuery.__init__(self,
       
    39                                 controller,
       
    40                                 "instance_tagname.xslt",
       
    41                                 [(name, self.FactoryCaller(name)) 
       
    42                                     for name in ["ConfigTagName",
       
    43                                                  "ResourceTagName",
       
    44                                                  "PouTagName",
       
    45                                                  "ActionTagName",
       
    46                                                  "TransitionTagName"]])
       
    47 
       
    48     def FactoryCaller(self, funcname):
       
    49         def CallFactory(*args):
       
    50             return getattr(self.factory, funcname)(*args)
       
    51         return CallFactory
       
    52 
       
    53     def Collect(self, root, debug, instance_path):
       
    54         self.factory = InstanceTagName()
       
    55         self._process_xslt(root, debug, instance_path=instance_path)
       
    56         res = self.factory.GetTagName()
       
    57         self.factory = None
       
    58         return res