40 from plcopen import * |
40 from plcopen import * |
41 from plcopen.types_enums import * |
41 from plcopen.types_enums import * |
42 from plcopen.XSLTModelQuery import _StringValue, _BoolValue, _translate_args |
42 from plcopen.XSLTModelQuery import _StringValue, _BoolValue, _translate_args |
43 from plcopen.InstancesPathCollector import InstancesPathCollector |
43 from plcopen.InstancesPathCollector import InstancesPathCollector |
44 from plcopen.POUVariablesCollector import POUVariablesCollector |
44 from plcopen.POUVariablesCollector import POUVariablesCollector |
|
45 from plcopen.InstanceTagnameCollector import InstanceTagnameCollector |
45 from graphics.GraphicCommons import * |
46 from graphics.GraphicCommons import * |
46 from PLCGenerator import * |
47 from PLCGenerator import * |
47 |
48 |
48 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
49 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
49 |
50 |
122 |
123 |
123 def AddVariable(self, context, *args): |
124 def AddVariable(self, context, *args): |
124 self.Variables.append(_VariableInfos(*( |
125 self.Variables.append(_VariableInfos(*( |
125 _translate_args([_StringValue] * 5 + [_BoolValue] + [_StringValue], args) + |
126 _translate_args([_StringValue] * 5 + [_BoolValue] + [_StringValue], args) + |
126 [self.GetType(), self.GetTree()]))) |
127 [self.GetType(), self.GetTree()]))) |
127 |
|
128 class InstanceTagName(object): |
|
129 """Helpers object for generating instance tagname""" |
|
130 |
|
131 def __init__(self, controller): |
|
132 self.Controller = controller |
|
133 self.TagName = None |
|
134 |
|
135 def GetTagName(self): |
|
136 return self.TagName |
|
137 |
|
138 def ConfigTagName(self, context, *args): |
|
139 self.TagName = ComputeConfigurationName(args[0][0]) |
|
140 |
|
141 def ResourceTagName(self, context, *args): |
|
142 self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0]) |
|
143 |
|
144 def PouTagName(self, context, *args): |
|
145 self.TagName = ComputePouName(args[0][0]) |
|
146 |
|
147 def ActionTagName(self, context, *args): |
|
148 self.TagName = ComputePouActionName(args[0][0], args[0][1]) |
|
149 |
|
150 def TransitionTagName(self, context, *args): |
|
151 self.TagName = ComputePouTransitionName(args[0][0], args[0][1]) |
|
152 |
128 |
153 |
129 |
154 # ------------------------------------------------------------------------------- |
130 # ------------------------------------------------------------------------------- |
155 # Helpers object for generating pou block instances list |
131 # Helpers object for generating pou block instances list |
156 # ------------------------------------------------------------------------------- |
132 # ------------------------------------------------------------------------------- |
406 def __init__(self): |
382 def __init__(self): |
407 self.LastNewIndex = 0 |
383 self.LastNewIndex = 0 |
408 self.Reset() |
384 self.Reset() |
409 self.InstancesPathCollector = InstancesPathCollector(self) |
385 self.InstancesPathCollector = InstancesPathCollector(self) |
410 self.POUVariablesCollector = POUVariablesCollector(self) |
386 self.POUVariablesCollector = POUVariablesCollector(self) |
|
387 self.InstanceTagnameCollector = InstanceTagnameCollector(self) |
411 |
388 |
412 # Reset PLCControler internal variables |
389 # Reset PLCControler internal variables |
413 def Reset(self): |
390 def Reset(self): |
414 self.Project = None |
391 self.Project = None |
415 self.ProjectBufferEnabled = True |
392 self.ProjectBufferEnabled = True |
660 ComputePouName(words[1]), debug)] |
637 ComputePouName(words[1]), debug)] |
661 return [] |
638 return [] |
662 |
639 |
663 def GetPouInstanceTagName(self, instance_path, debug=False): |
640 def GetPouInstanceTagName(self, instance_path, debug=False): |
664 project = self.GetProject(debug) |
641 project = self.GetProject(debug) |
665 factory = InstanceTagName(self) |
642 if project is not None : |
666 |
643 return self.InstanceTagnameCollector.Collect(project, |
667 parser = etree.XMLParser() |
644 debug, |
668 parser.resolvers.add(LibraryResolver(self, debug)) |
645 instance_path) |
669 |
|
670 instance_tagname_xslt_tree = etree.XSLT( |
|
671 etree.parse( |
|
672 os.path.join(ScriptDirectory, "plcopen", "instance_tagname.xslt"), |
|
673 parser), |
|
674 extensions={("instance_tagname_ns", name): getattr(factory, name) |
|
675 for name in ["ConfigTagName", |
|
676 "ResourceTagName", |
|
677 "PouTagName", |
|
678 "ActionTagName", |
|
679 "TransitionTagName"]}) |
|
680 |
|
681 instance_tagname_xslt_tree( |
|
682 project, instance_path=etree.XSLT.strparam(instance_path)) |
|
683 |
|
684 return factory.GetTagName() |
|
685 |
646 |
686 def GetInstanceInfos(self, instance_path, debug=False): |
647 def GetInstanceInfos(self, instance_path, debug=False): |
687 tagname = self.GetPouInstanceTagName(instance_path) |
648 tagname = self.GetPouInstanceTagName(instance_path) |
688 if tagname is not None: |
649 if tagname is not None: |
689 infos = self.GetPouVariables(tagname, debug) |
650 infos = self.GetPouVariables(tagname, debug) |