author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 28 Sep 2018 13:07:46 +0300 | |
changeset 2350 | 9f7028ab8294 |
parent 1973 | cc7a46953471 |
child 3750 | f62625418bff |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
3 |
# This file is part of Beremiz. |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1508
diff
changeset
|
4 |
# See COPYING file for copyrights details. |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
5 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1879
diff
changeset
|
6 |
from __future__ import absolute_import |
1959
ce1bfd04b3f6
pep8 and pylint hate me
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1957
diff
changeset
|
7 |
from collections import OrderedDict, namedtuple |
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
8 |
from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
9 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
10 |
# ------------------------------------------------------------------------------- |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
11 |
# Helpers object for generating pou block instances list |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
12 |
# ------------------------------------------------------------------------------- |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
13 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
14 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
15 |
_Point = namedtuple("Point", ["x", "y"]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
16 |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
17 |
_BlockInstanceInfos = namedtuple( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
18 |
"BlockInstanceInfos", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
19 |
["type", "id", "x", "y", "width", "height", "specific_values", "inputs", "outputs"]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
20 |
|
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
21 |
_BlockSpecificValues = ( |
1411 | 22 |
namedtuple("BlockSpecificValues", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
23 |
["name", "execution_order"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
24 |
[_StringValue, int]) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
25 |
_VariableSpecificValues = ( |
1411 | 26 |
namedtuple("VariableSpecificValues", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
27 |
["name", "value_type", "execution_order"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
28 |
[_StringValue, _StringValue, int]) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
29 |
_ConnectionSpecificValues = ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
30 |
namedtuple("ConnectionSpecificValues", ["name"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
31 |
[_StringValue]) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
32 |
|
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
33 |
_PowerRailSpecificValues = ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
34 |
namedtuple("PowerRailSpecificValues", ["connectors"]), |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
35 |
[int]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
36 |
|
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
37 |
_LDElementSpecificValues = ( |
1411 | 38 |
namedtuple("LDElementSpecificValues", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
39 |
["name", "negated", "edge", "storage", "execution_order"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
40 |
[_StringValue, _BoolValue, _StringValue, _StringValue, int]) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
41 |
|
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
42 |
_DivergenceSpecificValues = ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
43 |
namedtuple("DivergenceSpecificValues", ["connectors"]), |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
44 |
[int]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
45 |
|
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
46 |
_SpecificValuesTuples = { |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
47 |
"comment": ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
48 |
namedtuple("CommentSpecificValues", ["content"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
49 |
[_StringValue]), |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
50 |
"input": _VariableSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
51 |
"output": _VariableSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
52 |
"inout": _VariableSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
53 |
"connector": _ConnectionSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
54 |
"continuation": _ConnectionSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
55 |
"leftPowerRail": _PowerRailSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
56 |
"rightPowerRail": _PowerRailSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
57 |
"contact": _LDElementSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
58 |
"coil": _LDElementSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
59 |
"step": ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
60 |
namedtuple("StepSpecificValues", ["name", "initial", "action"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
61 |
[_StringValue, _BoolValue, lambda x: x]), |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
62 |
"transition": ( |
1411 | 63 |
namedtuple("TransitionSpecificValues", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
64 |
["priority", "condition_type", "condition", "connection"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
65 |
[int, _StringValue, _StringValue, lambda x: x]), |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
66 |
"selectionDivergence": _DivergenceSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
67 |
"selectionConvergence": _DivergenceSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
68 |
"simultaneousDivergence": _DivergenceSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
69 |
"simultaneousConvergence": _DivergenceSpecificValues, |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
70 |
"jump": ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
71 |
namedtuple("JumpSpecificValues", ["target"]), |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
72 |
[_StringValue]), |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
73 |
"actionBlock": ( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
74 |
namedtuple("ActionBlockSpecificValues", ["actions"]), |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
75 |
[lambda x: x]), |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
76 |
} |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
77 |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
78 |
_InstanceConnectionInfos = namedtuple( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
79 |
"InstanceConnectionInfos", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
80 |
["name", "negated", "edge", "position", "links"]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
81 |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
82 |
_ConnectionLinkInfos = namedtuple( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
83 |
"ConnectionLinkInfos", |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
84 |
["refLocalId", "formalParameter", "points"]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
85 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
86 |
|
1341 | 87 |
class _ActionInfos(object): |
1339 | 88 |
__slots__ = ["qualifier", "type", "value", "duration", "indicator"] |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
89 |
|
1339 | 90 |
def __init__(self, *args): |
91 |
for attr, value in zip(self.__slots__, args): |
|
92 |
setattr(self, attr, value if value is not None else "") |
|
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
93 |
|
1339 | 94 |
def copy(self): |
95 |
return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__]) |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
96 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
97 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1785
diff
changeset
|
98 |
class BlockInstanceFactory(object): |
1411 | 99 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
100 |
def __init__(self, block_instances): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
101 |
self.BlockInstances = block_instances |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
102 |
self.CurrentInstance = None |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
103 |
self.SpecificValues = None |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
104 |
self.CurrentConnection = None |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
105 |
self.CurrentLink = None |
1411 | 106 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
107 |
def SetSpecificValues(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
108 |
self.SpecificValues = list(args) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
109 |
self.CurrentInstance = None |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
110 |
self.CurrentConnection = None |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
111 |
self.CurrentLink = None |
1411 | 112 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
113 |
def AddBlockInstance(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
114 |
specific_values_tuple, specific_values_translation = \ |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
115 |
_SpecificValuesTuples.get(args[0][0], _BlockSpecificValues) |
1411 | 116 |
|
1774
ac0fe8aabb5e
clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
117 |
if args[0][0] == "step" and len(self.SpecificValues) < 3 or \ |
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
118 |
args[0][0] == "transition" and len(self.SpecificValues) < 4: |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
119 |
self.SpecificValues.append([None]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
120 |
elif args[0][0] == "actionBlock" and len(self.SpecificValues) < 1: |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
121 |
self.SpecificValues.append([[]]) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
122 |
specific_values = specific_values_tuple(*_translate_args( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
123 |
specific_values_translation, self.SpecificValues)) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
124 |
self.SpecificValues = None |
1411 | 125 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
126 |
self.CurrentInstance = _BlockInstanceInfos( |
1411 | 127 |
*(_translate_args([_StringValue, int] + [float] * 4, args) + |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
128 |
[specific_values, [], []])) |
1411 | 129 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
130 |
self.BlockInstances[self.CurrentInstance.id] = self.CurrentInstance |
1411 | 131 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
132 |
def AddInstanceConnection(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
133 |
connection_args = _translate_args( |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
134 |
[_StringValue] * 2 + [_BoolValue, _StringValue] + [float] * 2, args) |
1411 | 135 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
136 |
self.CurrentConnection = _InstanceConnectionInfos( |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
137 |
*(connection_args[1:4] + [ |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
138 |
_Point(*connection_args[4:6]), []])) |
1411 | 139 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
140 |
if self.CurrentInstance is not None: |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
141 |
if connection_args[0] == "input": |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
142 |
self.CurrentInstance.inputs.append(self.CurrentConnection) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
143 |
else: |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
144 |
self.CurrentInstance.outputs.append(self.CurrentConnection) |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
145 |
else: |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
146 |
self.SpecificValues.append([self.CurrentConnection]) |
1411 | 147 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
148 |
def AddConnectionLink(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
149 |
self.CurrentLink = _ConnectionLinkInfos( |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
150 |
*(_translate_args([int, _StringValue], args) + [[]])) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
151 |
self.CurrentConnection.links.append(self.CurrentLink) |
1411 | 152 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
153 |
def AddLinkPoint(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
154 |
self.CurrentLink.points.append(_Point( |
1373
4278d5c1e414
Fixed bug when graphic element position and size and connection points are decimal
Laurent Bessard
parents:
1372
diff
changeset
|
155 |
*_translate_args([float] * 2, args))) |
1411 | 156 |
|
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
157 |
def AddAction(self, context, *args): |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
158 |
if len(self.SpecificValues) == 0: |
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
159 |
self.SpecificValues.append([[]]) |
1378
cbc0f64a25eb
Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents:
1373
diff
changeset
|
160 |
translated_args = _translate_args([_StringValue] * 5, args) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
161 |
self.SpecificValues[0][0].append(_ActionInfos(*translated_args)) |
1411 | 162 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
163 |
|
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
164 |
class BlockInstanceCollector(XSLTModelQuery): |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
165 |
""" object for collecting instances path list""" |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
166 |
def __init__(self, controller): |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
167 |
XSLTModelQuery.__init__(self, |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
168 |
controller, |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
169 |
"pou_block_instances.xslt", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
170 |
[(name, self.FactoryCaller(name)) |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
171 |
for name in ["AddBlockInstance", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
172 |
"SetSpecificValues", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
173 |
"AddInstanceConnection", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
174 |
"AddConnectionLink", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
175 |
"AddLinkPoint", |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
176 |
"AddAction"]]) |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
177 |
|
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
178 |
def FactoryCaller(self, funcname): |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
179 |
def CallFactory(*args): |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
180 |
return getattr(self.factory, funcname)(*args) |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
181 |
return CallFactory |
814 | 182 |
|
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
183 |
def Collect(self, root, debug): |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
184 |
element_instances = OrderedDict() |
1957
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
185 |
self.factory = BlockInstanceFactory(element_instances) |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
186 |
self._process_xslt(root, debug) |
2d1cc4f5e4ef
GetEditedElementInstancesInfos now optimized as well. Forgotten because not using [R.I.P]LibraryResolver, but still XSLT compiling was hapenning on each call.
Edouard Tisserant
parents:
1954
diff
changeset
|
187 |
self.factory = None |
1338
c1e6c712cc35
Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents:
1337
diff
changeset
|
188 |
return element_instances |