author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 30 Aug 2024 11:50:23 +0200 | |
changeset 4008 | f30573e98600 |
parent 3751 | a80a66ba52d6 |
permissions | -rw-r--r-- |
1951
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
3 |
# This file is part of Beremiz. |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
4 |
# See COPYING file for copyrights details. |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
5 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
1953
diff
changeset
|
6 |
|
3751 | 7 |
from . XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args |
1951
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
8 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
9 |
# ------------------------------------------------------------------------------- |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
10 |
# Helpers object for generating pou var list |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
11 |
# ------------------------------------------------------------------------------- |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
12 |
|
1953
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
13 |
|
1951
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
14 |
class _VariableInfos(object): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
15 |
__slots__ = ["Name", "Class", "Option", "Location", "InitialValue", |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
16 |
"Edit", "Documentation", "Type", "Tree", "Number"] |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
17 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
18 |
def __init__(self, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
19 |
for attr, value in zip(self.__slots__, args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
20 |
setattr(self, attr, value if value is not None else "") |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
21 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
22 |
def copy(self): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
23 |
return _VariableInfos(*[getattr(self, attr) for attr in self.__slots__]) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
24 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
25 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
26 |
class VariablesInfosFactory(object): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
27 |
""" Helpers object for generating pou var list """ |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
28 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
29 |
def __init__(self, variables): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
30 |
self.Variables = variables |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
31 |
self.TreeStack = [] |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
32 |
self.Type = None |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
33 |
self.Dimensions = None |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
34 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
35 |
def SetType(self, context, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
36 |
self.Type = args[0][0] |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
37 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
38 |
def GetType(self): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
39 |
if len(self.Dimensions) > 0: |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
40 |
return ("array", self.Type, self.Dimensions) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
41 |
return self.Type |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
42 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
43 |
def GetTree(self): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
44 |
return (self.TreeStack.pop(-1), self.Dimensions) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
45 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
46 |
def AddDimension(self, context, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
47 |
self.Dimensions.append(tuple( |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
48 |
_translate_args([_StringValue] * 2, args))) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
49 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
50 |
def AddTree(self, context, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
51 |
self.TreeStack.append([]) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
52 |
self.Dimensions = [] |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
53 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
54 |
def AddVarToTree(self, context, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
55 |
var = (args[0][0], self.Type, self.GetTree()) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
56 |
self.TreeStack[-1].append(var) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
57 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
58 |
def AddVariable(self, context, *args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
59 |
self.Variables.append(_VariableInfos(*( |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
60 |
_translate_args([_StringValue] * 5 + [_BoolValue] + [_StringValue], args) + |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
61 |
[self.GetType(), self.GetTree()]))) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
62 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
63 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
64 |
class VariableInfoCollector(XSLTModelQuery): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
65 |
def __init__(self, controller): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
66 |
XSLTModelQuery.__init__(self, |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
67 |
controller, |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
68 |
"variables_infos.xslt", |
1953
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
69 |
[(name, self.FactoryCaller(name)) |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
70 |
for name in [ |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
71 |
"SetType", |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
72 |
"AddDimension", |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
73 |
"AddTree", |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
74 |
"AddVarToTree", |
5736d25bb393
PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents:
1951
diff
changeset
|
75 |
"AddVariable"]]) |
1951
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
76 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
77 |
def FactoryCaller(self, funcname): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
78 |
def CallFactory(*args): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
79 |
return getattr(self.factory, funcname)(*args) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
80 |
return CallFactory |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
81 |
|
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
82 |
def Collect(self, root, debug, variables, tree): |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
83 |
self.factory = VariablesInfosFactory(variables) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
84 |
self._process_xslt(root, debug, tree=str(tree)) |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
85 |
res = self.factory |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
86 |
self.factory = None |
bbd1e1744c91
GetVariableDictionary and GetPouInterfaceReturnType optimized with new VariableInfoCollector based on XSLTModelQuery. Moved corresponding definitions out of PLCControler.py.
Edouard Tisserant
parents:
diff
changeset
|
87 |
return res |