author | Edouard Tisserant |
Wed, 02 Dec 2020 14:32:56 +0100 | |
branch | svghmi |
changeset 3083 | 45f044cf845b |
parent 3049 | 4ac68ec9786f |
child 2739 | 7278186a2083 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1629
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
814 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
814 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
20 |
# GNU General Public License for more details. |
814 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
26 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
27 |
from __future__ import absolute_import |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
28 |
from __future__ import division |
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import re |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
30 |
from collections import OrderedDict |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
31 |
|
2432
dbc065a2f7a5
python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
32 |
from six.moves import xrange |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
33 |
from lxml import etree |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
34 |
|
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
35 |
from xmlclass import * |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1629
diff
changeset
|
36 |
import util.paths as paths |
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
37 |
|
1837
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
38 |
|
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
39 |
#: Dictionary that makes the relation between var names |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
40 |
#: in plcopen and displayed values |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
41 |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
42 |
VarTypes = { |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
43 |
"Local": "localVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
44 |
"Temp": "tempVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
45 |
"Input": "inputVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
46 |
"Output": "outputVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
47 |
"InOut": "inOutVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
48 |
"External": "externalVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
49 |
"Global": "globalVars", |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
50 |
"Access": "accessVars" |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
51 |
} |
814 | 52 |
|
53 |
searchResultVarTypes = { |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
54 |
"inputVars": "var_input", |
814 | 55 |
"outputVars": "var_output", |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
56 |
"inOutVars": "var_inout" |
814 | 57 |
} |
58 |
||
1837
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
59 |
|
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
60 |
#: Define in which order var types must be displayed |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
61 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
62 |
VarOrder = ["Local", "Temp", "Input", "Output", "InOut", "External", "Global", "Access"] |
814 | 63 |
|
1837
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
64 |
|
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
65 |
#: Define which action qualifier must be associated with a duration |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
66 |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
67 |
QualifierList = OrderedDict([ |
1837
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
68 |
("N", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
69 |
("R", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
70 |
("S", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
71 |
("L", True), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
72 |
("D", True), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
73 |
("P", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
74 |
("P0", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
75 |
("P1", False), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
76 |
("SD", True), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
77 |
("DS", True), |
c507c363625e
fix pylint warning '(pointless-string-statement) String statement has no effect'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
78 |
("SL", True)]) |
814 | 79 |
|
80 |
||
2439
f0a040f1de1b
Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
81 |
FILTER_ADDRESS_MODEL = r"(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)" |
814 | 82 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
83 |
|
814 | 84 |
def update_address(address, address_model, new_leading): |
85 |
result = address_model.match(address) |
|
86 |
if result is None: |
|
87 |
return address |
|
88 |
groups = result.groups() |
|
89 |
return groups[0] + new_leading + groups[2] |
|
90 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
91 |
|
814 | 92 |
def _init_and_compare(function, v1, v2): |
93 |
if v1 is None: |
|
94 |
return v2 |
|
95 |
if v2 is not None: |
|
96 |
return function(v1, v2) |
|
97 |
return v1 |
|
98 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
99 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
100 |
class rect(object): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
101 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
102 |
Helper class for bounding_box calculation |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
103 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
104 |
|
814 | 105 |
def __init__(self, x=None, y=None, width=None, height=None): |
106 |
self.x_min = x |
|
107 |
self.x_max = None |
|
108 |
self.y_min = y |
|
109 |
self.y_max = None |
|
110 |
if width is not None and x is not None: |
|
111 |
self.x_max = x + width |
|
112 |
if height is not None and y is not None: |
|
113 |
self.y_max = y + height |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
114 |
|
814 | 115 |
def update(self, x, y): |
116 |
self.x_min = _init_and_compare(min, self.x_min, x) |
|
117 |
self.x_max = _init_and_compare(max, self.x_max, x) |
|
118 |
self.y_min = _init_and_compare(min, self.y_min, y) |
|
119 |
self.y_max = _init_and_compare(max, self.y_max, y) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
120 |
|
814 | 121 |
def union(self, rect): |
122 |
self.x_min = _init_and_compare(min, self.x_min, rect.x_min) |
|
123 |
self.x_max = _init_and_compare(max, self.x_max, rect.x_max) |
|
124 |
self.y_min = _init_and_compare(min, self.y_min, rect.y_min) |
|
125 |
self.y_max = _init_and_compare(max, self.y_max, rect.y_max) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
126 |
|
814 | 127 |
def bounding_box(self): |
128 |
width = height = None |
|
129 |
if self.x_min is not None and self.x_max is not None: |
|
130 |
width = self.x_max - self.x_min |
|
131 |
if self.y_min is not None and self.y_max is not None: |
|
132 |
height = self.y_max - self.y_min |
|
133 |
return self.x_min, self.y_min, width, height |
|
134 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
135 |
|
814 | 136 |
def TextLenInRowColumn(text): |
137 |
if text == "": |
|
138 |
return (0, 0) |
|
139 |
lines = text.split("\n") |
|
140 |
return len(lines) - 1, len(lines[-1]) |
|
141 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
142 |
|
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
143 |
def CompilePattern(criteria): |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
144 |
flag = 0 if criteria["case_sensitive"] else re.IGNORECASE |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
145 |
find_pattern = criteria["find_pattern"] |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
146 |
if not criteria["regular_expression"]: |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
147 |
find_pattern = re.escape(find_pattern) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
148 |
criteria["pattern"] = re.compile(find_pattern, flag) |
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1534
diff
changeset
|
149 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
150 |
|
814 | 151 |
def TestTextElement(text, criteria): |
152 |
lines = text.splitlines() |
|
153 |
test_result = [] |
|
154 |
result = criteria["pattern"].search(text) |
|
155 |
while result is not None: |
|
1967
92796bb8d4fe
fix search in TextViewer objects, search returns only first entry
Surkov Sergey <surkovsv93@gmail.com>
parents:
1881
diff
changeset
|
156 |
prev_pos = result.span()[1] |
814 | 157 |
start = TextLenInRowColumn(text[:result.start()]) |
158 |
end = TextLenInRowColumn(text[:result.end() - 1]) |
|
159 |
test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
|
160 |
result = criteria["pattern"].search(text, result.end()) |
|
1967
92796bb8d4fe
fix search in TextViewer objects, search returns only first entry
Surkov Sergey <surkovsv93@gmail.com>
parents:
1881
diff
changeset
|
161 |
if result is not None and prev_pos == result.end(): |
1695
a63bb4025852
avoid infinite loop in search
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1693
diff
changeset
|
162 |
break |
814 | 163 |
return test_result |
164 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
165 |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
166 |
def TextMatched(str1, str2): |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
167 |
return str1 and str2 and (str1.upper() == str2.upper()) |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
168 |
|
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
|
169 |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1629
diff
changeset
|
170 |
PLCOpenParser = GenerateParserFromXSD(paths.AbsNeighbourFile(__file__, "tc6_xml_v201.xsd")) |
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1759
diff
changeset
|
171 |
|
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1759
diff
changeset
|
172 |
|
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1759
diff
changeset
|
173 |
def PLCOpen_XPath(xpath): |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1759
diff
changeset
|
174 |
return etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP) |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1759
diff
changeset
|
175 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
176 |
|
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
177 |
LOAD_POU_PROJECT_TEMPLATE = """ |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
178 |
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
179 |
xmlns:xhtml="http://www.w3.org/1999/xhtml" |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
180 |
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
181 |
xmlns="http://www.plcopen.org/xml/tc6_0201"> |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
182 |
<fileHeader companyName="" productName="" productVersion="" |
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
183 |
creationDateTime="1970-01-01T00:00:00"/> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
184 |
<contentHeader name="paste_project"> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
185 |
<coordinateInfo> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
186 |
<fbd><scaling x="0" y="0"/></fbd> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
187 |
<ld><scaling x="0" y="0"/></ld> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
188 |
<sfc><scaling x="0" y="0"/></sfc> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
189 |
</coordinateInfo> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
190 |
</contentHeader> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
191 |
<types> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
192 |
<dataTypes/> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
193 |
<pous>%s</pous> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
194 |
</types> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
195 |
<instances> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
196 |
<configurations/> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
197 |
</instances> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
198 |
</project> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
199 |
""" |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
200 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
201 |
|
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
202 |
def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
203 |
return LOAD_POU_PROJECT_TEMPLATE % """ |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
204 |
<pou name="paste_pou" pouType="program"> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
205 |
<body> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
206 |
<%(body_type)s>%%s</%(body_type)s> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
207 |
</body> |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
208 |
</pou>""" % locals() |
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
209 |
|
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
|
210 |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1629
diff
changeset
|
211 |
PLCOpen_v1_file = open(paths.AbsNeighbourFile(__file__, "TC6_XML_V10_B.xsd")) |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
212 |
PLCOpen_v1_xml = PLCOpen_v1_file.read() |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
213 |
PLCOpen_v1_file.close() |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
214 |
PLCOpen_v1_xml = PLCOpen_v1_xml.replace( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1872
diff
changeset
|
215 |
"http://www.plcopen.org/xml/tc6.xsd", |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1872
diff
changeset
|
216 |
"http://www.plcopen.org/xml/tc6_0201") |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
217 |
PLCOpen_v1_xsd = etree.XMLSchema(etree.fromstring(PLCOpen_v1_xml)) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
218 |
|
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
219 |
# XPath for file compatibility process |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
220 |
ProjectResourcesXPath = PLCOpen_XPath("ppx:instances/ppx:configurations/ppx:configuration/ppx:resource") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
221 |
ResourceInstancesXpath = PLCOpen_XPath("ppx:pouInstance | ppx:task/ppx:pouInstance") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
222 |
TransitionsConditionXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:transition/ppx:condition") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
223 |
ConditionConnectionsXPath = PLCOpen_XPath("ppx:connection") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
224 |
ActionBlocksXPath = PLCOpen_XPath("ppx:types/ppx:pous/ppx:pou/ppx:body/*/ppx:actionBlock") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
225 |
ActionBlocksConnectionPointOutXPath = PLCOpen_XPath("ppx:connectionPointOut") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
226 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
227 |
|
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
228 |
def LoadProjectXML(project_xml): |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
229 |
project_xml = project_xml.replace( |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
230 |
"http://www.plcopen.org/xml/tc6.xsd", |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
231 |
"http://www.plcopen.org/xml/tc6_0201") |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
232 |
for cre, repl in [ |
2439
f0a040f1de1b
Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
233 |
(re.compile(r"(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), |
f0a040f1de1b
Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
234 |
(re.compile(r"(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
235 |
project_xml = cre.sub(repl, project_xml) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
236 |
|
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
237 |
try: |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
238 |
tree, error = PLCOpenParser.LoadXMLString(project_xml) |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
239 |
if error is None: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
240 |
return tree, None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
241 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
242 |
if PLCOpen_v1_xsd.validate(tree): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
243 |
# Make file compatible with PLCOpen v2 |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
244 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
245 |
# Update resource interval value |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
246 |
for resource in ProjectResourcesXPath(tree): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
247 |
for task in resource.gettask(): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
248 |
interval = task.get("interval") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
249 |
if interval is not None: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
250 |
result = time_model.match(interval) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
251 |
if result is not None: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
252 |
values = result.groups() |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
253 |
time_values = [int(v) for v in values[:2]] |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
254 |
seconds = float(values[2]) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
255 |
time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
256 |
text = "T#" |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
257 |
if time_values[0] != 0: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
258 |
text += "%dh" % time_values[0] |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
259 |
if time_values[1] != 0: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
260 |
text += "%dm" % time_values[1] |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
261 |
if time_values[2] != 0: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
262 |
text += "%ds" % time_values[2] |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
263 |
if time_values[3] != 0: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
264 |
if time_values[3] % 1000 != 0: |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
265 |
text += "%.3fms" % (time_values[3] / 1000) |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
266 |
else: |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
267 |
text += "%dms" % (time_values[3] // 1000) |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
268 |
task.set("interval", text) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
269 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
270 |
# Update resources pou instance attributes |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
271 |
for pouInstance in ResourceInstancesXpath(resource): |
1339 | 272 |
type_name = pouInstance.attrib.pop("type") |
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
273 |
if type_name is not None: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
274 |
pouInstance.set("typeName", type_name) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
275 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
276 |
# Update transitions condition |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
277 |
for transition_condition in TransitionsConditionXPath(tree): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
278 |
connections = ConditionConnectionsXPath(transition_condition) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
279 |
if len(connections) > 0: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
280 |
connectionPointIn = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
281 |
transition_condition.setcontent(connectionPointIn) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
282 |
connectionPointIn.setrelPositionXY(0, 0) |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
283 |
for connection in connections: |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
284 |
connectionPointIn.append(connection) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
285 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
286 |
# Update actionBlocks |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
287 |
for actionBlock in ActionBlocksXPath(tree): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
288 |
for connectionPointOut in ActionBlocksConnectionPointOutXPath(actionBlock): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
289 |
actionBlock.remove(connectionPointOut) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
290 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
291 |
for action in actionBlock.getaction(): |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
292 |
action.set("localId", "0") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
293 |
relPosition = PLCOpenParser.CreateElement("relPosition", "action") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
294 |
relPosition.set("x", "0") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
295 |
relPosition.set("y", "0") |
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
296 |
action.setrelPosition(relPosition) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
297 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
298 |
return tree, None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
299 |
|
1334
b0c2c4e1c1f1
Added support for loading PLCOpen v1 files and modify their content to be compatible with PLCOpen v2
Laurent Bessard
parents:
1331
diff
changeset
|
300 |
return tree, error |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
301 |
|
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1972
diff
changeset
|
302 |
except Exception as e: |
2447
1c04a50dc7ff
python3 support: pylint, W1645 # (exception-message-attribute) Exception.message removed in Python 3
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2439
diff
changeset
|
303 |
return None, str(e) |
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
304 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
305 |
|
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
306 |
def LoadProject(filepath): |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
307 |
project_file = open(filepath) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
308 |
project_xml = project_file.read() |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
309 |
project_file.close() |
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
310 |
return LoadProjectXML(project_xml) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
311 |
|
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
|
312 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
313 |
project_pou_xpath = PLCOpen_XPath("/ppx:project/ppx:types/ppx:pous/ppx:pou") |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
314 |
|
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
315 |
|
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
316 |
def LoadPou(xml_string): |
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
317 |
root, error = LoadProjectXML(LOAD_POU_PROJECT_TEMPLATE % xml_string) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
318 |
return project_pou_xpath(root)[0], error |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
319 |
|
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
|
320 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
321 |
project_pou_instances_xpath = { |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
322 |
body_type: PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
323 |
"/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type) |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
324 |
for body_type in ["FBD", "LD", "SFC"]} |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
325 |
|
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
326 |
|
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
327 |
def LoadPouInstances(xml_string, body_type): |
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
328 |
root, error = LoadProjectXML( |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
329 |
LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1322
diff
changeset
|
330 |
return project_pou_instances_xpath[body_type](root), error |
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
331 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
332 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
333 |
def SaveProject(project, filepath): |
3049
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
334 |
content = etree.tostring( |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
335 |
project, |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
336 |
pretty_print=True, |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
337 |
xml_declaration=True, |
3049
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
338 |
encoding='utf-8') |
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
339 |
|
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
340 |
assert len(content) != 0 |
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
341 |
|
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
342 |
project_file = open(filepath, 'w') |
4ac68ec9786f
Attempt to workaround problem reported about empty plc.xml after unrelated crash. Now, if etree model is corrupted in a way tostring() would generate an empty string, exception prevents saving.
Edouard Tisserant
parents:
2524
diff
changeset
|
343 |
project_file.write(content) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
344 |
project_file.close() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
345 |
|
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
|
346 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
347 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
348 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
349 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
350 |
def _updateFormattedTextClass(cls): |
814 | 351 |
def updateElementName(self, old_name, new_name): |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
352 |
text = self.getanyText() |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
353 |
pattern = re.compile('\\b' + old_name + '\\b', re.IGNORECASE) |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
354 |
text = pattern.sub(new_name, text) |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
355 |
self.setanyText(text) |
814 | 356 |
setattr(cls, "updateElementName", updateElementName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
357 |
|
814 | 358 |
def updateElementAddress(self, address_model, new_leading): |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
359 |
text = self.getanyText() |
814 | 360 |
startpos = 0 |
361 |
result = address_model.search(text, startpos) |
|
362 |
while result is not None: |
|
363 |
groups = result.groups() |
|
364 |
new_address = groups[0] + new_leading + groups[2] |
|
365 |
text = text[:result.start()] + new_address + text[result.end():] |
|
366 |
startpos = result.start() + len(new_address) |
|
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
367 |
result = address_model.search(text, startpos) |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
368 |
self.setanyText(text) |
814 | 369 |
setattr(cls, "updateElementAddress", updateElementAddress) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
370 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
371 |
def hasblock(self, block_type): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
372 |
text = self.getanyText() |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
373 |
pattern = re.compile('\\b' + block_type + '\\b', re.IGNORECASE) |
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
374 |
return pattern.search(text) is not None |
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
375 |
setattr(cls, "hasblock", hasblock) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
376 |
|
814 | 377 |
def Search(self, criteria, parent_infos): |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
378 |
return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)] |
814 | 379 |
setattr(cls, "Search", Search) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
380 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
381 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
382 |
cls = PLCOpenParser.GetElementClass("formattedText") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
383 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
384 |
_updateFormattedTextClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
385 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
386 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
387 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
388 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
389 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
390 |
def _updateProjectClass(cls): |
814 | 391 |
def setname(self, name): |
392 |
self.contentHeader.setname(name) |
|
393 |
setattr(cls, "setname", setname) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
394 |
|
814 | 395 |
def getname(self): |
396 |
return self.contentHeader.getname() |
|
397 |
setattr(cls, "getname", getname) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
398 |
|
814 | 399 |
def getfileHeader(self): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
400 |
fileheader_obj = self.fileHeader |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
401 |
return { |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
402 |
attr: value if value is not None else "" |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
403 |
for attr, value in [ |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
404 |
("companyName", fileheader_obj.getcompanyName()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
405 |
("companyURL", fileheader_obj.getcompanyURL()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
406 |
("productName", fileheader_obj.getproductName()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
407 |
("productVersion", fileheader_obj.getproductVersion()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
408 |
("productRelease", fileheader_obj.getproductRelease()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
409 |
("creationDateTime", fileheader_obj.getcreationDateTime()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
410 |
("contentDescription", fileheader_obj.getcontentDescription())] |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
411 |
} |
814 | 412 |
setattr(cls, "getfileHeader", getfileHeader) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
413 |
|
814 | 414 |
def setfileHeader(self, fileheader): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
415 |
fileheader_obj = self.fileHeader |
1309
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
416 |
for attr in ["companyName", "companyURL", "productName", |
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
417 |
"productVersion", "productRelease", "creationDateTime", |
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
418 |
"contentDescription"]: |
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
419 |
value = fileheader.get(attr) |
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
420 |
if value is not None: |
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
421 |
setattr(fileheader_obj, attr, value) |
814 | 422 |
setattr(cls, "setfileHeader", setfileHeader) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
423 |
|
814 | 424 |
def getcontentHeader(self): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
425 |
contentheader_obj = self.contentHeader |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
426 |
contentheader = { |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
427 |
attr: value if value is not None else "" |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
428 |
for attr, value in [ |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
429 |
("projectName", contentheader_obj.getname()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
430 |
("projectVersion", contentheader_obj.getversion()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
431 |
("modificationDateTime", contentheader_obj.getmodificationDateTime()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
432 |
("organization", contentheader_obj.getorganization()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
433 |
("authorName", contentheader_obj.getauthor()), |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
434 |
("language", contentheader_obj.getlanguage())] |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
435 |
} |
814 | 436 |
contentheader["pageSize"] = self.contentHeader.getpageSize() |
437 |
contentheader["scaling"] = self.contentHeader.getscaling() |
|
438 |
return contentheader |
|
439 |
setattr(cls, "getcontentHeader", getcontentHeader) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
440 |
|
814 | 441 |
def setcontentHeader(self, contentheader): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
442 |
contentheader_obj = self.contentHeader |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
443 |
for attr, value in contentheader.iteritems(): |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
444 |
func = {"projectName": contentheader_obj.setname, |
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
445 |
"projectVersion": contentheader_obj.setversion, |
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
446 |
"authorName": contentheader_obj.setauthor, |
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
447 |
"pageSize": lambda v: contentheader_obj.setpageSize(*v), |
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
448 |
"scaling": contentheader_obj.setscaling}.get(attr) |
1972
38e912c8bd31
fix bug with indelible values in some 'optional' fields in project properties panel
Surkov Sergey <surkovsv93@gmail.com>
parents:
1967
diff
changeset
|
449 |
if func is not None and value is not None: |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
450 |
func(value) |
1309
85ce56758900
Fixed bug when modifying project properties
Laurent Bessard
parents:
1307
diff
changeset
|
451 |
elif attr in ["modificationDateTime", "organization", "language"]: |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
452 |
setattr(contentheader_obj, attr, value) |
814 | 453 |
setattr(cls, "setcontentHeader", setcontentHeader) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
454 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
455 |
def gettypeElementFunc(element_type): |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
456 |
elements_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
457 |
"ppx:types/ppx:%(element_type)ss/ppx:%(element_type)s[@name=$name]" % locals()) |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
458 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
459 |
def gettypeElement(self, name): |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
460 |
elements = elements_xpath(self, name=name) |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
461 |
if len(elements) == 1: |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
462 |
return elements[0] |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
463 |
return None |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
464 |
return gettypeElement |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
465 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
466 |
datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType") |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
467 |
filtered_datatypes_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
468 |
"ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
469 |
|
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
470 |
def getdataTypes(self, exclude=None): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
471 |
if exclude is not None: |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
472 |
return filtered_datatypes_xpath(self, exclude=exclude) |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
473 |
return datatypes_xpath(self) |
814 | 474 |
setattr(cls, "getdataTypes", getdataTypes) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
475 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
476 |
setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
477 |
|
814 | 478 |
def appenddataType(self, name): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
479 |
if self.getdataType(name) is not None: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
480 |
raise ValueError("\"%s\" Data Type already exists !!!" % name) |
814 | 481 |
self.types.appenddataTypeElement(name) |
482 |
setattr(cls, "appenddataType", appenddataType) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
483 |
|
814 | 484 |
def insertdataType(self, index, datatype): |
485 |
self.types.insertdataTypeElement(index, datatype) |
|
486 |
setattr(cls, "insertdataType", insertdataType) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
487 |
|
814 | 488 |
def removedataType(self, name): |
489 |
self.types.removedataTypeElement(name) |
|
490 |
setattr(cls, "removedataType", removedataType) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
491 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
492 |
def getpous(self, exclude=None, filter=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
493 |
filter = [] if filter is None else filter |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
494 |
return self.xpath( |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
495 |
"ppx:types/ppx:pous/ppx:pou%s%s" % |
1777
c46ec818bdd7
clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
496 |
(("[@name!='%s']" % exclude) if exclude is not None else '', |
c46ec818bdd7
clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
497 |
("[%s]" % " or ".join( |
c46ec818bdd7
clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
498 |
map(lambda x: "@pouType='%s'" % x, filter))) |
c46ec818bdd7
clean-up: fix PEP8 E131 continuation line unaligned for hanging indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
499 |
if len(filter) > 0 else ""), |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
500 |
namespaces=PLCOpenParser.NSMAP) |
814 | 501 |
setattr(cls, "getpous", getpous) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
502 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
503 |
setattr(cls, "getpou", gettypeElementFunc("pou")) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
504 |
|
814 | 505 |
def appendpou(self, name, pou_type, body_type): |
506 |
self.types.appendpouElement(name, pou_type, body_type) |
|
507 |
setattr(cls, "appendpou", appendpou) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
508 |
|
814 | 509 |
def insertpou(self, index, pou): |
510 |
self.types.insertpouElement(index, pou) |
|
511 |
setattr(cls, "insertpou", insertpou) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
512 |
|
814 | 513 |
def removepou(self, name): |
514 |
self.types.removepouElement(name) |
|
515 |
setattr(cls, "removepou", removepou) |
|
516 |
||
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
517 |
configurations_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
518 |
"ppx:instances/ppx:configurations/ppx:configuration") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
519 |
|
814 | 520 |
def getconfigurations(self): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
521 |
return configurations_xpath(self) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
522 |
setattr(cls, "getconfigurations", getconfigurations) |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
523 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
524 |
configuration_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
525 |
"ppx:instances/ppx:configurations/ppx:configuration[@name=$name]") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
526 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
527 |
def getconfiguration(self, name): |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
528 |
configurations = configuration_xpath(self, name=name) |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
529 |
if len(configurations) == 1: |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
530 |
return configurations[0] |
814 | 531 |
return None |
532 |
setattr(cls, "getconfiguration", getconfiguration) |
|
533 |
||
534 |
def addconfiguration(self, name): |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
535 |
if self.getconfiguration(name) is not None: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
536 |
raise ValueError(_("\"%s\" configuration already exists !!!") % name) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
537 |
new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
814 | 538 |
new_configuration.setname(name) |
539 |
self.instances.configurations.appendconfiguration(new_configuration) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
540 |
setattr(cls, "addconfiguration", addconfiguration) |
814 | 541 |
|
542 |
def removeconfiguration(self, name): |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
543 |
configuration = self.getconfiguration(name) |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
544 |
if configuration is None: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
545 |
raise ValueError(_("\"%s\" configuration doesn't exist !!!") % name) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
546 |
self.instances.configurations.remove(configuration) |
814 | 547 |
setattr(cls, "removeconfiguration", removeconfiguration) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
548 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
549 |
resources_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
550 |
"ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
551 |
|
814 | 552 |
def getconfigurationResource(self, config_name, name): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
553 |
resources = resources_xpath(self, configname=config_name, name=name) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
554 |
if len(resources) == 1: |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
555 |
return resources[0] |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
556 |
return None |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
557 |
setattr(cls, "getconfigurationResource", getconfigurationResource) |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
558 |
|
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
559 |
def addconfigurationResource(self, config_name, name): |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
560 |
if self.getconfigurationResource(config_name, name) is not None: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
561 |
raise ValueError( |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
562 |
_("\"{a1}\" resource already exists in \"{a2}\" configuration !!!"). |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
563 |
format(a1=name, a2=config_name)) |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
564 |
|
814 | 565 |
configuration = self.getconfiguration(config_name) |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
566 |
if configuration is not None: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
567 |
new_resource = PLCOpenParser.CreateElement("resource", "configuration") |
814 | 568 |
new_resource.setname(name) |
569 |
configuration.appendresource(new_resource) |
|
570 |
setattr(cls, "addconfigurationResource", addconfigurationResource) |
|
571 |
||
572 |
def removeconfigurationResource(self, config_name, name): |
|
573 |
configuration = self.getconfiguration(config_name) |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
574 |
found = False |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
575 |
if configuration is not None: |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
576 |
resource = self.getconfigurationResource(config_name, name) |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
577 |
if resource is not None: |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
578 |
configuration.remove(resource) |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
579 |
found = True |
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
580 |
if not found: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
581 |
raise ValueError( |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
582 |
_("\"{a1}\" resource doesn't exist in \"{a2}\" configuration !!!"). |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
583 |
format(a1=name, a2=config_name)) |
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
584 |
|
814 | 585 |
setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
586 |
||
587 |
def updateElementName(self, old_name, new_name): |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
588 |
for datatype in self.getdataTypes(): |
814 | 589 |
datatype.updateElementName(old_name, new_name) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
590 |
for pou in self.getpous(): |
814 | 591 |
pou.updateElementName(old_name, new_name) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
592 |
for configuration in self.getconfigurations(): |
814 | 593 |
configuration.updateElementName(old_name, new_name) |
594 |
setattr(cls, "updateElementName", updateElementName) |
|
595 |
||
596 |
def updateElementAddress(self, old_leading, new_leading): |
|
597 |
address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
598 |
for pou in self.getpous(): |
814 | 599 |
pou.updateElementAddress(address_model, new_leading) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
600 |
for configuration in self.getconfigurations(): |
814 | 601 |
configuration.updateElementAddress(address_model, new_leading) |
602 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
603 |
||
604 |
def removeVariableByAddress(self, address): |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
605 |
for pou in self.getpous(): |
814 | 606 |
pou.removeVariableByAddress(address) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
607 |
for configuration in self.getconfigurations(): |
814 | 608 |
configuration.removeVariableByAddress(address) |
609 |
setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
|
610 |
||
611 |
def removeVariableByFilter(self, leading): |
|
612 |
address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
613 |
for pou in self.getpous(): |
814 | 614 |
pou.removeVariableByFilter(address_model) |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
615 |
for configuration in self.getconfigurations(): |
814 | 616 |
configuration.removeVariableByFilter(address_model) |
617 |
setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
|
618 |
||
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
619 |
enumerated_values_xpath = PLCOpen_XPath( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
620 |
"ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
621 |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
622 |
def GetEnumeratedDataTypeValues(self): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
623 |
return [value.getname() for value in enumerated_values_xpath(self)] |
814 | 624 |
setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
625 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
626 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
627 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 628 |
result = self.types.Search(criteria, parent_infos) |
629 |
for configuration in self.instances.configurations.getconfiguration(): |
|
630 |
result.extend(configuration.Search(criteria, parent_infos)) |
|
631 |
return result |
|
632 |
setattr(cls, "Search", Search) |
|
633 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
634 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
635 |
cls = PLCOpenParser.GetElementClass("project") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
636 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
637 |
_updateProjectClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
638 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
639 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
640 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
641 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
642 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
643 |
def _updateContentHeaderProjectClass(cls): |
814 | 644 |
def setpageSize(self, width, height): |
645 |
self.coordinateInfo.setpageSize(width, height) |
|
646 |
setattr(cls, "setpageSize", setpageSize) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
647 |
|
814 | 648 |
def getpageSize(self): |
649 |
return self.coordinateInfo.getpageSize() |
|
650 |
setattr(cls, "getpageSize", getpageSize) |
|
651 |
||
652 |
def setscaling(self, scaling): |
|
653 |
for language, (x, y) in scaling.items(): |
|
654 |
self.coordinateInfo.setscaling(language, x, y) |
|
655 |
setattr(cls, "setscaling", setscaling) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
656 |
|
814 | 657 |
def getscaling(self): |
658 |
scaling = {} |
|
659 |
scaling["FBD"] = self.coordinateInfo.getscaling("FBD") |
|
660 |
scaling["LD"] = self.coordinateInfo.getscaling("LD") |
|
661 |
scaling["SFC"] = self.coordinateInfo.getscaling("SFC") |
|
662 |
return scaling |
|
663 |
setattr(cls, "getscaling", getscaling) |
|
664 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
665 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
666 |
cls = PLCOpenParser.GetElementClass("contentHeader", "project") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
667 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
668 |
_updateContentHeaderProjectClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
669 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
670 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
671 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
672 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
673 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
674 |
def _updateCoordinateInfoContentHeaderClass(cls): |
814 | 675 |
def setpageSize(self, width, height): |
676 |
if width == 0 and height == 0: |
|
677 |
self.deletepageSize() |
|
678 |
else: |
|
679 |
if self.pageSize is None: |
|
680 |
self.addpageSize() |
|
681 |
self.pageSize.setx(width) |
|
682 |
self.pageSize.sety(height) |
|
683 |
setattr(cls, "setpageSize", setpageSize) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
684 |
|
814 | 685 |
def getpageSize(self): |
686 |
if self.pageSize is not None: |
|
687 |
return self.pageSize.getx(), self.pageSize.gety() |
|
688 |
return 0, 0 |
|
689 |
setattr(cls, "getpageSize", getpageSize) |
|
690 |
||
691 |
def setscaling(self, language, x, y): |
|
692 |
if language == "FBD": |
|
693 |
self.fbd.scaling.setx(x) |
|
694 |
self.fbd.scaling.sety(y) |
|
695 |
elif language == "LD": |
|
696 |
self.ld.scaling.setx(x) |
|
697 |
self.ld.scaling.sety(y) |
|
698 |
elif language == "SFC": |
|
699 |
self.sfc.scaling.setx(x) |
|
700 |
self.sfc.scaling.sety(y) |
|
701 |
setattr(cls, "setscaling", setscaling) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
702 |
|
814 | 703 |
def getscaling(self, language): |
704 |
if language == "FBD": |
|
705 |
return self.fbd.scaling.getx(), self.fbd.scaling.gety() |
|
706 |
elif language == "LD": |
|
707 |
return self.ld.scaling.getx(), self.ld.scaling.gety() |
|
708 |
elif language == "SFC": |
|
709 |
return self.sfc.scaling.getx(), self.sfc.scaling.gety() |
|
710 |
return 0, 0 |
|
711 |
setattr(cls, "getscaling", getscaling) |
|
712 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
713 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
714 |
cls = PLCOpenParser.GetElementClass("coordinateInfo", "contentHeader") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
715 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
716 |
_updateCoordinateInfoContentHeaderClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
717 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
718 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
719 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
720 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
721 |
|
814 | 722 |
def _Search(attributes, criteria, parent_infos): |
723 |
search_result = [] |
|
724 |
for attr, value in attributes: |
|
725 |
if value is not None: |
|
726 |
search_result.extend([(tuple(parent_infos + [attr]),) + result for result in TestTextElement(value, criteria)]) |
|
727 |
return search_result |
|
728 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
729 |
|
814 | 730 |
def _updateConfigurationResourceElementName(self, old_name, new_name): |
731 |
for varlist in self.getglobalVars(): |
|
732 |
for var in varlist.getvariable(): |
|
733 |
var_address = var.getaddress() |
|
734 |
if var_address is not None: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
735 |
if TextMatched(var_address, old_name): |
814 | 736 |
var.setaddress(new_name) |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
737 |
if TextMatched(var.getname(), old_name): |
814 | 738 |
var.setname(new_name) |
739 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
740 |
|
814 | 741 |
def _updateConfigurationResourceElementAddress(self, address_model, new_leading): |
742 |
for varlist in self.getglobalVars(): |
|
743 |
for var in varlist.getvariable(): |
|
744 |
var_address = var.getaddress() |
|
745 |
if var_address is not None: |
|
746 |
var.setaddress(update_address(var_address, address_model, new_leading)) |
|
747 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
748 |
|
814 | 749 |
def _removeConfigurationResourceVariableByAddress(self, address): |
750 |
for varlist in self.getglobalVars(): |
|
751 |
variables = varlist.getvariable() |
|
752 |
for i in xrange(len(variables)-1, -1, -1): |
|
753 |
if variables[i].getaddress() == address: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
754 |
variables.remove(variables[i]) |
814 | 755 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
756 |
|
814 | 757 |
def _removeConfigurationResourceVariableByFilter(self, address_model): |
758 |
for varlist in self.getglobalVars(): |
|
759 |
variables = varlist.getvariable() |
|
760 |
for i in xrange(len(variables)-1, -1, -1): |
|
761 |
var_address = variables[i].getaddress() |
|
762 |
if var_address is not None: |
|
763 |
result = address_model.match(var_address) |
|
764 |
if result is not None: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
765 |
variables.remove(variables[i]) |
814 | 766 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
767 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
768 |
def _SearchInConfigurationResource(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
769 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 770 |
search_result = _Search([("name", self.getname())], criteria, parent_infos) |
771 |
var_number = 0 |
|
772 |
for varlist in self.getglobalVars(): |
|
773 |
variable_type = searchResultVarTypes.get("globalVars", "var_local") |
|
774 |
variables = varlist.getvariable() |
|
775 |
for modifier, has_modifier in [("constant", varlist.getconstant()), |
|
776 |
("retain", varlist.getretain()), |
|
777 |
("non_retain", varlist.getnonretain())]: |
|
778 |
if has_modifier: |
|
779 |
for result in TestTextElement(modifier, criteria): |
|
780 |
search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result) |
|
781 |
break |
|
782 |
for variable in variables: |
|
783 |
search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number])) |
|
784 |
var_number += 1 |
|
785 |
return search_result |
|
786 |
||
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
|
787 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
788 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
789 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
790 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
791 |
def _updateConfigurationConfigurationsClass(cls): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
792 |
def addglobalVar(self, var_type, name, location="", description=""): |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
793 |
globalvars = self.getglobalVars() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
794 |
if len(globalvars) == 0: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
795 |
globalvars.append(PLCOpenParser.CreateElement("varList")) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
796 |
var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
797 |
var.setname(name) |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
798 |
var.settype(var_type) |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
799 |
if location != "": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
800 |
var.setaddress(location) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
801 |
if description != "": |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
802 |
ft = PLCOpenParser.CreateElement("documentation", "variable") |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
803 |
ft.setanyText(description) |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
804 |
var.setdocumentation(ft) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
805 |
globalvars[-1].appendvariable(var) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
806 |
setattr(cls, "addglobalVar", addglobalVar) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
807 |
|
814 | 808 |
def updateElementName(self, old_name, new_name): |
809 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
|
810 |
for resource in self.getresource(): |
|
811 |
resource.updateElementName(old_name, new_name) |
|
812 |
setattr(cls, "updateElementName", updateElementName) |
|
813 |
||
814 |
def updateElementAddress(self, address_model, new_leading): |
|
815 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
|
816 |
for resource in self.getresource(): |
|
817 |
resource.updateElementAddress(address_model, new_leading) |
|
818 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
819 |
||
820 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
|
821 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
|
822 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
823 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
824 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 825 |
search_result = [] |
826 |
parent_infos = parent_infos + ["C::%s" % self.getname()] |
|
827 |
filter = criteria["filter"] |
|
828 |
if filter == "all" or "configuration" in filter: |
|
829 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
|
830 |
for resource in self.getresource(): |
|
831 |
search_result.extend(resource.Search(criteria, parent_infos)) |
|
832 |
return search_result |
|
833 |
setattr(cls, "Search", Search) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
834 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
835 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
836 |
cls = PLCOpenParser.GetElementClass("configuration", "configurations") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
837 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
838 |
_updateConfigurationConfigurationsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
839 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
840 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
841 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
842 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
843 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
844 |
def _updateResourceConfigurationClass(cls): |
814 | 845 |
def updateElementName(self, old_name, new_name): |
846 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
|
847 |
for instance in self.getpouInstance(): |
|
848 |
instance.updateElementName(old_name, new_name) |
|
849 |
for task in self.gettask(): |
|
850 |
task.updateElementName(old_name, new_name) |
|
851 |
setattr(cls, "updateElementName", updateElementName) |
|
852 |
||
853 |
def updateElementAddress(self, address_model, new_leading): |
|
854 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
|
855 |
for task in self.gettask(): |
|
856 |
task.updateElementAddress(address_model, new_leading) |
|
857 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
858 |
||
859 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
|
860 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
|
861 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
862 |
def Search(self, criteria, parent_infos=None): |
2524
c80b0d864475
WIP adding searching capabilities in python files. was done :
Edouard Tisserant
parents:
2450
diff
changeset
|
863 |
# FIXME : two next lines are incompatible [][-1] raises exception ! |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
864 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 865 |
parent_infos = parent_infos[:-1] + ["R::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
866 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
|
867 |
task_number = 0 |
|
868 |
instance_number = 0 |
|
869 |
for task in self.gettask(): |
|
870 |
results = TestTextElement(task.getname(), criteria) |
|
871 |
for result in results: |
|
872 |
search_result.append((tuple(parent_infos + ["task", task_number, "name"]),) + result) |
|
873 |
search_result.extend(task.Search(criteria, parent_infos + ["task", task_number])) |
|
874 |
task_number += 1 |
|
875 |
for instance in task.getpouInstance(): |
|
876 |
search_result.extend(task.Search(criteria, parent_infos + ["instance", instance_number])) |
|
877 |
for result in results: |
|
878 |
search_result.append((tuple(parent_infos + ["instance", instance_number, "task"]),) + result) |
|
879 |
instance_number += 1 |
|
880 |
for instance in self.getpouInstance(): |
|
881 |
search_result.extend(instance.Search(criteria, parent_infos + ["instance", instance_number])) |
|
882 |
instance_number += 1 |
|
883 |
return search_result |
|
884 |
setattr(cls, "Search", Search) |
|
885 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
886 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
887 |
cls = PLCOpenParser.GetElementClass("resource", "configuration") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
888 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
889 |
_updateResourceConfigurationClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
890 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
891 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
892 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
893 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
894 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
895 |
def _updateTaskResourceClass(cls): |
814 | 896 |
def updateElementName(self, old_name, new_name): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
897 |
if TextMatched(self.single, old_name): |
814 | 898 |
self.single = new_name |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
899 |
if TextMatched(self.interval, old_name): |
814 | 900 |
self.interval = new_name |
901 |
for instance in self.getpouInstance(): |
|
902 |
instance.updateElementName(old_name, new_name) |
|
903 |
setattr(cls, "updateElementName", updateElementName) |
|
904 |
||
905 |
def updateElementAddress(self, address_model, new_leading): |
|
906 |
if self.single is not None: |
|
907 |
self.single = update_address(self.single, address_model, new_leading) |
|
908 |
if self.interval is not None: |
|
909 |
self.interval = update_address(self.interval, address_model, new_leading) |
|
910 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
911 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
912 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
913 |
parent_infos = [] if parent_infos is None else parent_infos |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
914 |
return _Search([("single", self.getsingle()), |
814 | 915 |
("interval", self.getinterval()), |
916 |
("priority", str(self.getpriority()))], |
|
917 |
criteria, parent_infos) |
|
918 |
setattr(cls, "Search", Search) |
|
919 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
920 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
921 |
cls = PLCOpenParser.GetElementClass("task", "resource") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
922 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
923 |
_updateTaskResourceClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
924 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
925 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
926 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
927 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
928 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
929 |
def _updatePouInstanceClass(cls): |
814 | 930 |
def updateElementName(self, old_name, new_name): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
931 |
if TextMatched(self.typeName, old_name): |
814 | 932 |
self.typeName = new_name |
933 |
setattr(cls, "updateElementName", updateElementName) |
|
934 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
935 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
936 |
parent_infos = [] if parent_infos is None else parent_infos |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
937 |
return _Search([("name", self.getname()), |
814 | 938 |
("type", self.gettypeName())], |
939 |
criteria, parent_infos) |
|
940 |
setattr(cls, "Search", Search) |
|
941 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
942 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
943 |
cls = PLCOpenParser.GetElementClass("pouInstance") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
944 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
945 |
_updatePouInstanceClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
946 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
947 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
948 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
949 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
950 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
951 |
def _updateVariableVarListPlain(cls): |
814 | 952 |
def gettypeAsText(self): |
953 |
vartype_content = self.gettype().getcontent() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
954 |
vartype_content_name = vartype_content.getLocalTag() |
814 | 955 |
# Variable type is a user data type |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
956 |
if vartype_content_name == "derived": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
957 |
return vartype_content.getname() |
814 | 958 |
# Variable type is a string type |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
959 |
elif vartype_content_name in ["string", "wstring"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
960 |
return vartype_content_name.upper() |
814 | 961 |
# Variable type is an array |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
962 |
elif vartype_content_name == "array": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
963 |
base_type = vartype_content.baseType.getcontent() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
964 |
base_type_name = base_type.getLocalTag() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
965 |
# Array derived directly from a user defined type |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
966 |
if base_type_name == "derived": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
967 |
basetype_name = base_type.getname() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
968 |
# Array derived directly from a string type |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
969 |
elif base_type_name in ["string", "wstring"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
970 |
basetype_name = base_type_name.upper() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
971 |
# Array derived directly from an elementary type |
814 | 972 |
else: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
973 |
basetype_name = base_type_name |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
974 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x: "%s..%s" % (x.getlower(), x.getupper()), vartype_content.getdimension())), basetype_name) |
814 | 975 |
# Variable type is an elementary type |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
976 |
return vartype_content_name |
814 | 977 |
setattr(cls, "gettypeAsText", gettypeAsText) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
978 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
979 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
980 |
parent_infos = [] if parent_infos is None else parent_infos |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
981 |
search_result = _Search([("name", self.getname()), |
814 | 982 |
("type", self.gettypeAsText()), |
983 |
("location", self.getaddress())], |
|
984 |
criteria, parent_infos) |
|
985 |
initial = self.getinitialValue() |
|
986 |
if initial is not None: |
|
987 |
search_result.extend(_Search([("initial value", initial.getvalue())], criteria, parent_infos)) |
|
988 |
doc = self.getdocumentation() |
|
989 |
if doc is not None: |
|
990 |
search_result.extend(doc.Search(criteria, parent_infos + ["documentation"])) |
|
991 |
return search_result |
|
992 |
setattr(cls, "Search", Search) |
|
993 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
994 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
995 |
cls = PLCOpenParser.GetElementClass("variable", "varListPlain") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
996 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
997 |
_updateVariableVarListPlain(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
998 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
999 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1000 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1001 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1002 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1003 |
def _updateTypesProjectClass(cls): |
814 | 1004 |
def getdataTypeElements(self): |
1005 |
return self.dataTypes.getdataType() |
|
1006 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1007 |
|
814 | 1008 |
def getdataTypeElement(self, name): |
1009 |
elements = self.dataTypes.getdataType() |
|
1010 |
for element in elements: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1011 |
if TextMatched(element.getname(), name): |
814 | 1012 |
return element |
1013 |
return None |
|
1014 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
|
1015 |
||
1016 |
def appenddataTypeElement(self, name): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1017 |
new_datatype = PLCOpenParser.CreateElement("dataType", "dataTypes") |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1018 |
self.dataTypes.appenddataType(new_datatype) |
814 | 1019 |
new_datatype.setname(name) |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1020 |
new_datatype.baseType.setcontent(PLCOpenParser.CreateElement("BOOL", "dataType")) |
814 | 1021 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1022 |
|
814 | 1023 |
def insertdataTypeElement(self, index, dataType): |
1024 |
self.dataTypes.insertdataType(index, dataType) |
|
1025 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1026 |
|
814 | 1027 |
def removedataTypeElement(self, name): |
1028 |
found = False |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1029 |
for element in self.dataTypes.getdataType(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1030 |
if TextMatched(element.getname(), name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1031 |
self.dataTypes.remove(element) |
814 | 1032 |
found = True |
1033 |
break |
|
1034 |
if not found: |
|
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1035 |
raise ValueError(_("\"%s\" Data Type doesn't exist !!!") % name) |
814 | 1036 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1037 |
|
814 | 1038 |
def getpouElements(self): |
1039 |
return self.pous.getpou() |
|
1040 |
setattr(cls, "getpouElements", getpouElements) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1041 |
|
814 | 1042 |
def getpouElement(self, name): |
1043 |
elements = self.pous.getpou() |
|
1044 |
for element in elements: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1045 |
if TextMatched(element.getname(), name): |
814 | 1046 |
return element |
1047 |
return None |
|
1048 |
setattr(cls, "getpouElement", getpouElement) |
|
1049 |
||
1050 |
def appendpouElement(self, name, pou_type, body_type): |
|
1051 |
for element in self.pous.getpou(): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1052 |
if TextMatched(element.getname(), name): |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1053 |
raise ValueError(_("\"%s\" POU already exists !!!") % name) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1054 |
new_pou = PLCOpenParser.CreateElement("pou", "pous") |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1055 |
self.pous.appendpou(new_pou) |
814 | 1056 |
new_pou.setname(name) |
1057 |
new_pou.setpouType(pou_type) |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1058 |
new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
814 | 1059 |
new_pou.setbodyType(body_type) |
1060 |
setattr(cls, "appendpouElement", appendpouElement) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1061 |
|
814 | 1062 |
def insertpouElement(self, index, pou): |
1063 |
self.pous.insertpou(index, pou) |
|
1064 |
setattr(cls, "insertpouElement", insertpouElement) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1065 |
|
814 | 1066 |
def removepouElement(self, name): |
1067 |
found = False |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1068 |
for element in self.pous.getpou(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1069 |
if TextMatched(element.getname(), name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1070 |
self.pous.remove(element) |
814 | 1071 |
found = True |
1072 |
break |
|
1073 |
if not found: |
|
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1074 |
raise ValueError(_("\"%s\" POU doesn't exist !!!") % name) |
814 | 1075 |
setattr(cls, "removepouElement", removepouElement) |
1076 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1077 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1078 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1079 |
search_result = [] |
1080 |
for datatype in self.dataTypes.getdataType(): |
|
1081 |
search_result.extend(datatype.Search(criteria, parent_infos)) |
|
1082 |
for pou in self.pous.getpou(): |
|
1083 |
search_result.extend(pou.Search(criteria, parent_infos)) |
|
1084 |
return search_result |
|
1085 |
setattr(cls, "Search", Search) |
|
1086 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1087 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1088 |
cls = PLCOpenParser.GetElementClass("types", "project") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1089 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1090 |
_updateTypesProjectClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1091 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1092 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1093 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1094 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1095 |
|
814 | 1096 |
def _updateBaseTypeElementName(self, old_name, new_name): |
1097 |
self.baseType.updateElementName(old_name, new_name) |
|
1098 |
||
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
|
1099 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1100 |
def _updateDataTypeDataTypesClass(cls): |
814 | 1101 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1102 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1103 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1104 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1105 |
search_result = [] |
1106 |
filter = criteria["filter"] |
|
1107 |
if filter == "all" or "datatype" in filter: |
|
1108 |
parent_infos = parent_infos + ["D::%s" % self.getname()] |
|
1109 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
|
1110 |
search_result.extend(self.baseType.Search(criteria, parent_infos)) |
|
1111 |
if self.initialValue is not None: |
|
1112 |
search_result.extend(_Search([("initial", self.initialValue.getvalue())], criteria, parent_infos)) |
|
1113 |
return search_result |
|
1114 |
setattr(cls, "Search", Search) |
|
1115 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1116 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1117 |
cls = PLCOpenParser.GetElementClass("dataType", "dataTypes") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1118 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1119 |
_updateDataTypeDataTypesClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1120 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1121 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1122 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1123 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1124 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1125 |
def _updateDataTypeClass(cls): |
814 | 1126 |
def updateElementName(self, old_name, new_name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1127 |
content_name = self.content.getLocalTag() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1128 |
if content_name in ["derived", "array", "subrangeSigned", "subrangeUnsigned"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1129 |
self.content.updateElementName(old_name, new_name) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1130 |
elif content_name == "struct": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1131 |
for element in self.content.getvariable(): |
1846
14b40afccd69
remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1840
diff
changeset
|
1132 |
element.type.updateElementName(old_name, new_name) |
814 | 1133 |
setattr(cls, "updateElementName", updateElementName) |
1134 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1135 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1136 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1137 |
search_result = [] |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1138 |
content_name = self.content.getLocalTag() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1139 |
if content_name in ["derived", "array", "enum", "subrangeSigned", "subrangeUnsigned"]: |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1140 |
search_result.extend(self.content.Search(criteria, parent_infos + ["base"])) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1141 |
elif content_name == "struct": |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1142 |
for i, element in enumerate(self.content.getvariable()): |
814 | 1143 |
search_result.extend(element.Search(criteria, parent_infos + ["struct", i])) |
1144 |
else: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1145 |
if content_name in ["string", "wstring"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1146 |
content_name = content_name.upper() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1147 |
search_result.extend(_Search([("base", content_name)], criteria, parent_infos)) |
814 | 1148 |
return search_result |
1149 |
setattr(cls, "Search", Search) |
|
1150 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1151 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1152 |
cls = PLCOpenParser.GetElementClass("dataType") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1153 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1154 |
_updateDataTypeClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1155 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1156 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1157 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1158 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1159 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1160 |
def _updateDerivedDataTypeClass(cls): |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1161 |
def updateElementName(self, old_name, new_name): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1162 |
if TextMatched(self.name, old_name): |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1163 |
self.name = new_name |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1164 |
setattr(cls, "updateElementName", updateElementName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1165 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1166 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1167 |
parent_infos = [] if parent_infos is None else parent_infos |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1168 |
return [(tuple(parent_infos),) + result for result in TestTextElement(self.name, criteria)] |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1169 |
setattr(cls, "Search", Search) |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1170 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1171 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1172 |
cls = PLCOpenParser.GetElementClass("derived", "dataType") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1173 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1174 |
_updateDerivedDataTypeClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1175 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1176 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1177 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1178 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1179 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1180 |
def _updateArrayDataTypeClass(cls): |
814 | 1181 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1182 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1183 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1184 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1185 |
search_result = self.baseType.Search(criteria, parent_infos) |
1186 |
for i, dimension in enumerate(self.getdimension()): |
|
1187 |
search_result.extend(_Search([("lower", dimension.getlower()), |
|
1188 |
("upper", dimension.getupper())], |
|
1189 |
criteria, parent_infos + ["range", i])) |
|
1190 |
return search_result |
|
1191 |
setattr(cls, "Search", Search) |
|
1192 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1193 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1194 |
cls = PLCOpenParser.GetElementClass("array", "dataType") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1195 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1196 |
_updateArrayDataTypeClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1197 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1198 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1199 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1200 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1201 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1202 |
def _SearchInSubrange(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1203 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1204 |
search_result = self.baseType.Search(criteria, parent_infos) |
1205 |
search_result.extend(_Search([("lower", self.range.getlower()), |
|
1206 |
("upper", self.range.getupper())], |
|
1207 |
criteria, parent_infos)) |
|
1208 |
return search_result |
|
1209 |
||
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
|
1210 |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1211 |
cls = PLCOpenParser.GetElementClass("subrangeSigned", "dataType") |
814 | 1212 |
if cls: |
1213 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1214 |
setattr(cls, "Search", _SearchInSubrange) |
|
1215 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1216 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1217 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1218 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1219 |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1220 |
cls = PLCOpenParser.GetElementClass("subrangeUnsigned", "dataType") |
814 | 1221 |
if cls: |
1222 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1223 |
setattr(cls, "Search", _SearchInSubrange) |
|
1224 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1225 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1226 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1227 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1228 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1229 |
def _updateEnumDataTypeClass(cls): |
814 | 1230 |
def updateElementName(self, old_name, new_name): |
1231 |
pass |
|
1232 |
setattr(cls, "updateElementName", updateElementName) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1233 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1234 |
enumerated_datatype_values_xpath = PLCOpen_XPath("ppx:values/ppx:value") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
1235 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1236 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1237 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1238 |
search_result = [] |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1239 |
for i, value in enumerate(enumerated_datatype_values_xpath(self)): |
814 | 1240 |
for result in TestTextElement(value.getname(), criteria): |
1241 |
search_result.append((tuple(parent_infos + ["value", i]),) + result) |
|
1242 |
return search_result |
|
1243 |
setattr(cls, "Search", Search) |
|
1244 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1245 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1246 |
cls = PLCOpenParser.GetElementClass("enum", "dataType") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1247 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1248 |
_updateEnumDataTypeClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1249 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1250 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1251 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1252 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1253 |
|
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1254 |
def _getvariableTypeinfos(variable_type): |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1255 |
type_content = variable_type.getcontent() |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1256 |
type_content_type = type_content.getLocalTag() |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1257 |
if type_content_type == "derived": |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1258 |
return type_content.getname() |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1259 |
return type_content_type.upper() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1260 |
|
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
|
1261 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1262 |
def _updatePouPousClass(cls): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1263 |
def getblockInfos(self): |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1264 |
block_infos = { |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1265 |
"name": self.getname(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1266 |
"type": self.getpouType(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1267 |
"extensible": False, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1268 |
"inputs": [], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1269 |
"outputs": [], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
1270 |
"comment": self.getdescription()} |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1271 |
if self.interface is not None: |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1272 |
return_type = self.interface.getreturnType() |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1273 |
if return_type is not None: |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1274 |
block_infos["outputs"].append( |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1275 |
("OUT", _getvariableTypeinfos(return_type), "none")) |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1276 |
block_infos["inputs"].extend( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1277 |
[(var.getname(), _getvariableTypeinfos(var.type), "none") |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1278 |
for var in block_inputs_xpath(self)]) |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1279 |
block_infos["outputs"].extend( |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1280 |
[(var.getname(), _getvariableTypeinfos(var.type), "none") |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1281 |
for var in block_outputs_xpath(self)]) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1282 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1283 |
block_infos["usage"] = ("\n (%s) => (%s)" % |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
1284 |
(", ".join(["%s:%s" % (input[1], input[0]) |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
1285 |
for input in block_infos["inputs"]]), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
1286 |
", ".join(["%s:%s" % (output[1], output[0]) |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
1287 |
for output in block_infos["outputs"]]))) |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1288 |
return block_infos |
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
1289 |
setattr(cls, "getblockInfos", getblockInfos) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1290 |
|
814 | 1291 |
def setdescription(self, description): |
1292 |
doc = self.getdocumentation() |
|
1293 |
if doc is None: |
|
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1294 |
doc = PLCOpenParser.CreateElement("documentation", "pou") |
814 | 1295 |
self.setdocumentation(doc) |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1296 |
doc.setanyText(description) |
814 | 1297 |
setattr(cls, "setdescription", setdescription) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1298 |
|
814 | 1299 |
def getdescription(self): |
1300 |
doc = self.getdocumentation() |
|
1301 |
if doc is not None: |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1302 |
return doc.getanyText() |
814 | 1303 |
return "" |
1304 |
setattr(cls, "getdescription", getdescription) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1305 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1306 |
def setbodyType(self, body_type): |
814 | 1307 |
if len(self.body) > 0: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1308 |
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1309 |
self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
814 | 1310 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1311 |
raise ValueError("%s isn't a valid body type!" % type) |
814 | 1312 |
setattr(cls, "setbodyType", setbodyType) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1313 |
|
814 | 1314 |
def getbodyType(self): |
1315 |
if len(self.body) > 0: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1316 |
return self.body[0].getcontent().getLocalTag() |
814 | 1317 |
setattr(cls, "getbodyType", getbodyType) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1318 |
|
814 | 1319 |
def resetexecutionOrder(self): |
1320 |
if len(self.body) > 0: |
|
1321 |
self.body[0].resetexecutionOrder() |
|
1322 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1323 |
|
814 | 1324 |
def compileexecutionOrder(self): |
1325 |
if len(self.body) > 0: |
|
1326 |
self.body[0].compileexecutionOrder() |
|
1327 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1328 |
|
814 | 1329 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
1330 |
if len(self.body) > 0: |
|
1331 |
self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
|
1332 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1333 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1334 |
def addinstance(self, instance): |
814 | 1335 |
if len(self.body) > 0: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1336 |
self.body[0].appendcontentInstance(instance) |
814 | 1337 |
setattr(cls, "addinstance", addinstance) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1338 |
|
814 | 1339 |
def getinstances(self): |
1340 |
if len(self.body) > 0: |
|
1341 |
return self.body[0].getcontentInstances() |
|
1342 |
return [] |
|
1343 |
setattr(cls, "getinstances", getinstances) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1344 |
|
814 | 1345 |
def getinstance(self, id): |
1346 |
if len(self.body) > 0: |
|
1347 |
return self.body[0].getcontentInstance(id) |
|
1348 |
return None |
|
1349 |
setattr(cls, "getinstance", getinstance) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1350 |
|
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1351 |
def getinstancesIds(self): |
814 | 1352 |
if len(self.body) > 0: |
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1353 |
return self.body[0].getcontentInstancesIds() |
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1354 |
return [] |
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1355 |
setattr(cls, "getinstancesIds", getinstancesIds) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1356 |
|
814 | 1357 |
def getinstanceByName(self, name): |
1358 |
if len(self.body) > 0: |
|
1359 |
return self.body[0].getcontentInstanceByName(name) |
|
1360 |
return None |
|
1361 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1362 |
|
814 | 1363 |
def removeinstance(self, id): |
1364 |
if len(self.body) > 0: |
|
1365 |
self.body[0].removecontentInstance(id) |
|
1366 |
setattr(cls, "removeinstance", removeinstance) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1367 |
|
814 | 1368 |
def settext(self, text): |
1369 |
if len(self.body) > 0: |
|
1370 |
self.body[0].settext(text) |
|
1371 |
setattr(cls, "settext", settext) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1372 |
|
814 | 1373 |
def gettext(self): |
1374 |
if len(self.body) > 0: |
|
1375 |
return self.body[0].gettext() |
|
1376 |
return "" |
|
1377 |
setattr(cls, "gettext", gettext) |
|
1378 |
||
1379 |
def getvars(self): |
|
1380 |
vars = [] |
|
1381 |
if self.interface is not None: |
|
1382 |
reverse_types = {} |
|
1383 |
for name, value in VarTypes.items(): |
|
1384 |
reverse_types[value] = name |
|
1385 |
for varlist in self.interface.getcontent(): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1386 |
vars.append((reverse_types[varlist.getLocalTag()], varlist)) |
814 | 1387 |
return vars |
1388 |
setattr(cls, "getvars", getvars) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1389 |
|
814 | 1390 |
def setvars(self, vars): |
1391 |
if self.interface is None: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1392 |
self.interface = PLCOpenParser.CreateElement("interface", "pou") |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1393 |
self.interface.setcontent(vars) |
814 | 1394 |
setattr(cls, "setvars", setvars) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1395 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1396 |
def addpouExternalVar(self, var_type, name): |
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1397 |
self.addpouVar(var_type, name, "externalVars") |
814 | 1398 |
setattr(cls, "addpouExternalVar", addpouExternalVar) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1399 |
|
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1400 |
def addpouVar(self, var_type, name, var_class="localVars", location="", description="", initval=""): |
814 | 1401 |
if self.interface is None: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1402 |
self.interface = PLCOpenParser.CreateElement("interface", "pou") |
814 | 1403 |
content = self.interface.getcontent() |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1404 |
if len(content) == 0: |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1405 |
varlist = PLCOpenParser.CreateElement(var_class, "interface") |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1406 |
self.interface.setcontent([varlist]) |
1371
3c55c99b10ab
Fixed bug when adding and removing function block in graphic viewer. In some cases, the associated variable could stay in the variable panel.
Laurent Bessard
parents:
1355
diff
changeset
|
1407 |
elif content[-1].getLocalTag() != var_class: |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1408 |
varlist = PLCOpenParser.CreateElement(var_class, "interface") |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1409 |
content[-1].addnext(varlist) |
814 | 1410 |
else: |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1411 |
varlist = content[-1] |
814 | 1412 |
variables = varlist.getvariable() |
1413 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1414 |
varlist = PLCOpenParser.CreateElement(var_class, "interface") |
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1415 |
content[-1].addnext(varlist) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1416 |
var = PLCOpenParser.CreateElement("variable", "varListPlain") |
814 | 1417 |
var.setname(name) |
1313
85c167bfff93
Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents:
1310
diff
changeset
|
1418 |
var.settype(var_type) |
814 | 1419 |
if location != "": |
1420 |
var.setaddress(location) |
|
1421 |
if description != "": |
|
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1422 |
ft = PLCOpenParser.CreateElement("documentation", "variable") |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1423 |
ft.setanyText(description) |
814 | 1424 |
var.setdocumentation(ft) |
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1425 |
if initval != "": |
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1426 |
el = PLCOpenParser.CreateElement("initialValue", "variable") |
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1427 |
el.setvalue(initval) |
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1428 |
var.setinitialValue(el) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1429 |
|
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1430 |
varlist.appendvariable(var) |
814 | 1431 |
setattr(cls, "addpouVar", addpouVar) |
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1400
diff
changeset
|
1432 |
setattr(cls, "addpouLocalVar", addpouVar) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1433 |
|
814 | 1434 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
1435 |
if self.interface is not None: |
|
1436 |
content = self.interface.getcontent() |
|
1437 |
for varlist in content: |
|
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1438 |
variables = varlist.getvariable() |
814 | 1439 |
for var in variables: |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1440 |
if TextMatched(var.getname(), old_name): |
814 | 1441 |
vartype_content = var.gettype().getcontent() |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1442 |
if vartype_content.getLocalTag() == "derived" and TextMatched(vartype_content.getname(), old_type): |
814 | 1443 |
var.setname(new_name) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1444 |
vartype_content.setname(new_type) |
814 | 1445 |
return |
1446 |
setattr(cls, "changepouVar", changepouVar) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1447 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1448 |
def removepouVar(self, var_type, name): |
814 | 1449 |
if self.interface is not None: |
1450 |
content = self.interface.getcontent() |
|
1451 |
for varlist in content: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1452 |
for var in varlist.getvariable(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1453 |
if TextMatched(var.getname(), name): |
814 | 1454 |
vartype_content = var.gettype().getcontent() |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1455 |
if vartype_content.getLocalTag() == "derived" and TextMatched(vartype_content.getname(), var_type): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1456 |
varlist.remove(var) |
1371
3c55c99b10ab
Fixed bug when adding and removing function block in graphic viewer. In some cases, the associated variable could stay in the variable panel.
Laurent Bessard
parents:
1355
diff
changeset
|
1457 |
if len(varlist.getvariable()) == 0: |
3c55c99b10ab
Fixed bug when adding and removing function block in graphic viewer. In some cases, the associated variable could stay in the variable panel.
Laurent Bessard
parents:
1355
diff
changeset
|
1458 |
self.interface.remove(varlist) |
814 | 1459 |
break |
1460 |
setattr(cls, "removepouVar", removepouVar) |
|
1626
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1461 |
|
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1462 |
def hasstep(self, name=None): |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1463 |
if self.getbodyType() in ["SFC"]: |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1464 |
for instance in self.getinstances(): |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1465 |
if isinstance(instance, PLCOpenParser.GetElementClass("step", "sfcObjects")) and TextMatched(instance.getname(), name): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1466 |
return True |
1626
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1467 |
return False |
0779c1b18c01
check before program generation whether SFC step, that is referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1619
diff
changeset
|
1468 |
setattr(cls, "hasstep", hasstep) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1469 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1470 |
def hasblock(self, name=None, block_type=None): |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1471 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
814 | 1472 |
for instance in self.getinstances(): |
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1473 |
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1474 |
and (TextMatched(instance.getinstanceName(), name) or |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1475 |
TextMatched(instance.gettypeName(), block_type)): |
814 | 1476 |
return True |
1477 |
if self.transitions: |
|
1478 |
for transition in self.transitions.gettransition(): |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1479 |
result = transition.hasblock(name, block_type) |
814 | 1480 |
if result: |
1481 |
return result |
|
1482 |
if self.actions: |
|
1483 |
for action in self.actions.getaction(): |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1484 |
result = action.hasblock(name, block_type) |
814 | 1485 |
if result: |
1486 |
return result |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1487 |
elif block_type is not None and len(self.body) > 0: |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1488 |
return self.body[0].hasblock(block_type) |
814 | 1489 |
return False |
1490 |
setattr(cls, "hasblock", hasblock) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1491 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1492 |
def addtransition(self, name, body_type): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1493 |
if self.transitions is None: |
814 | 1494 |
self.addtransitions() |
1495 |
self.transitions.settransition([]) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1496 |
transition = PLCOpenParser.CreateElement("transition", "transitions") |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1497 |
self.transitions.appendtransition(transition) |
814 | 1498 |
transition.setname(name) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1499 |
transition.setbodyType(body_type) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1500 |
if body_type == "ST": |
1616
3638463d6e02
fix issue with creating SFC transitions using ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1611
diff
changeset
|
1501 |
transition.settext(":= ;") |
814 | 1502 |
setattr(cls, "addtransition", addtransition) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1503 |
|
814 | 1504 |
def gettransition(self, name): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1505 |
if self.transitions is not None: |
814 | 1506 |
for transition in self.transitions.gettransition(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1507 |
if TextMatched(transition.getname(), name): |
814 | 1508 |
return transition |
1509 |
return None |
|
1510 |
setattr(cls, "gettransition", gettransition) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1511 |
|
814 | 1512 |
def gettransitionList(self): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1513 |
if self.transitions is not None: |
814 | 1514 |
return self.transitions.gettransition() |
1515 |
return [] |
|
1516 |
setattr(cls, "gettransitionList", gettransitionList) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1517 |
|
814 | 1518 |
def removetransition(self, name): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1519 |
if self.transitions is not None: |
814 | 1520 |
removed = False |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1521 |
for transition in self.transitions.gettransition(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1522 |
if TextMatched(transition.getname(), name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1523 |
if transition.getbodyType() in ["FBD", "LD", "SFC"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1524 |
for instance in transition.getinstances(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1525 |
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1526 |
self.removepouVar(instance.gettypeName(), |
824
be669f4c51c4
Fix bug in SFC function block declarations from transition and action not removed when transition or action is deleted
laurent
parents:
814
diff
changeset
|
1527 |
instance.getinstanceName()) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1528 |
self.transitions.remove(transition) |
814 | 1529 |
removed = True |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1530 |
break |
814 | 1531 |
if not removed: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1532 |
raise ValueError(_("Transition with name %s doesn't exist!") % name) |
814 | 1533 |
setattr(cls, "removetransition", removetransition) |
1534 |
||
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1535 |
def addaction(self, name, body_type): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1536 |
if self.actions is None: |
814 | 1537 |
self.addactions() |
1538 |
self.actions.setaction([]) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1539 |
action = PLCOpenParser.CreateElement("action", "actions") |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1540 |
self.actions.appendaction(action) |
814 | 1541 |
action.setname(name) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1542 |
action.setbodyType(body_type) |
814 | 1543 |
setattr(cls, "addaction", addaction) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1544 |
|
814 | 1545 |
def getaction(self, name): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1546 |
if self.actions is not None: |
814 | 1547 |
for action in self.actions.getaction(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1548 |
if TextMatched(action.getname(), name): |
814 | 1549 |
return action |
1550 |
return None |
|
1551 |
setattr(cls, "getaction", getaction) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1552 |
|
814 | 1553 |
def getactionList(self): |
1382
675a6229fc60
Fixed bugs in SFC when loading transition condition and referenced transition or action body
Laurent Bessard
parents:
1371
diff
changeset
|
1554 |
if self.actions is not None: |
814 | 1555 |
return self.actions.getaction() |
1556 |
return [] |
|
1557 |
setattr(cls, "getactionList", getactionList) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1558 |
|
814 | 1559 |
def removeaction(self, name): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1560 |
if self.actions is not None: |
814 | 1561 |
removed = False |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1562 |
for action in self.actions.getaction(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1563 |
if TextMatched(action.getname(), name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1564 |
if action.getbodyType() in ["FBD", "LD", "SFC"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1565 |
for instance in action.getinstances(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1566 |
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1567 |
self.removepouVar(instance.gettypeName(), |
824
be669f4c51c4
Fix bug in SFC function block declarations from transition and action not removed when transition or action is deleted
laurent
parents:
814
diff
changeset
|
1568 |
instance.getinstanceName()) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1569 |
self.actions.remove(action) |
814 | 1570 |
removed = True |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1571 |
break |
814 | 1572 |
if not removed: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1573 |
raise ValueError(_("Action with name %s doesn't exist!") % name) |
814 | 1574 |
setattr(cls, "removeaction", removeaction) |
1575 |
||
1576 |
def updateElementName(self, old_name, new_name): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1577 |
if self.interface is not None: |
814 | 1578 |
for content in self.interface.getcontent(): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1579 |
for var in content.getvariable(): |
814 | 1580 |
var_address = var.getaddress() |
1581 |
if var_address is not None: |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1582 |
if TextMatched(var_address, old_name): |
814 | 1583 |
var.setaddress(new_name) |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1584 |
if TextMatched(var.getname(), old_name): |
814 | 1585 |
var.setname(new_name) |
1586 |
var_type_content = var.gettype().getcontent() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1587 |
if var_type_content.getLocalTag() == "derived": |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1588 |
if TextMatched(var_type_content.getname(), old_name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1589 |
var_type_content.setname(new_name) |
814 | 1590 |
self.body[0].updateElementName(old_name, new_name) |
1591 |
for action in self.getactionList(): |
|
1592 |
action.updateElementName(old_name, new_name) |
|
1593 |
for transition in self.gettransitionList(): |
|
1594 |
transition.updateElementName(old_name, new_name) |
|
1595 |
setattr(cls, "updateElementName", updateElementName) |
|
1596 |
||
1597 |
def updateElementAddress(self, address_model, new_leading): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1598 |
if self.interface is not None: |
814 | 1599 |
for content in self.interface.getcontent(): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1600 |
for var in content.getvariable(): |
814 | 1601 |
var_address = var.getaddress() |
1602 |
if var_address is not None: |
|
1603 |
var.setaddress(update_address(var_address, address_model, new_leading)) |
|
1604 |
self.body[0].updateElementAddress(address_model, new_leading) |
|
1605 |
for action in self.getactionList(): |
|
1606 |
action.updateElementAddress(address_model, new_leading) |
|
1607 |
for transition in self.gettransitionList(): |
|
1608 |
transition.updateElementAddress(address_model, new_leading) |
|
1609 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
1610 |
||
1611 |
def removeVariableByAddress(self, address): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1612 |
if self.interface is not None: |
814 | 1613 |
for content in self.interface.getcontent(): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1614 |
for variable in content.getvariable(): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
1615 |
if TextMatched(variable.getaddress(), address): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1616 |
content.remove(variable) |
814 | 1617 |
setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
1618 |
||
1619 |
def removeVariableByFilter(self, address_model): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1620 |
if self.interface is not None: |
814 | 1621 |
for content in self.interface.getcontent(): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1622 |
for variable in content.getvariable(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1623 |
var_address = variable.getaddress() |
814 | 1624 |
if var_address is not None: |
1625 |
result = address_model.match(var_address) |
|
1626 |
if result is not None: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1627 |
content.remove(variable) |
814 | 1628 |
setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1629 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1630 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1631 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 1632 |
search_result = [] |
1633 |
filter = criteria["filter"] |
|
1634 |
if filter == "all" or self.getpouType() in filter: |
|
1619
163d3a883575
fix local search in actions and transitions
Surkov Sergey <surkovsv93@gmail.com>
parents:
1616
diff
changeset
|
1635 |
if parent_infos == []: |
163d3a883575
fix local search in actions and transitions
Surkov Sergey <surkovsv93@gmail.com>
parents:
1616
diff
changeset
|
1636 |
parent_infos = parent_infos + ["P::%s" % self.getname()] |
814 | 1637 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
1638 |
if self.interface is not None: |
|
1639 |
var_number = 0 |
|
1640 |
for content in self.interface.getcontent(): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1641 |
variable_type = searchResultVarTypes.get(content, "var_local") |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1642 |
variables = content.getvariable() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1643 |
for modifier, has_modifier in [("constant", content.getconstant()), |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1644 |
("retain", content.getretain()), |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1645 |
("non_retain", content.getnonretain())]: |
814 | 1646 |
if has_modifier: |
1647 |
for result in TestTextElement(modifier, criteria): |
|
1648 |
search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result) |
|
1649 |
break |
|
1650 |
for variable in variables: |
|
1651 |
search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number])) |
|
1652 |
var_number += 1 |
|
1653 |
if len(self.body) > 0: |
|
1654 |
search_result.extend(self.body[0].Search(criteria, parent_infos)) |
|
1655 |
for action in self.getactionList(): |
|
1656 |
search_result.extend(action.Search(criteria, parent_infos)) |
|
1657 |
for transition in self.gettransitionList(): |
|
1658 |
search_result.extend(transition.Search(criteria, parent_infos)) |
|
1659 |
return search_result |
|
1660 |
setattr(cls, "Search", Search) |
|
1661 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1662 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1663 |
cls = PLCOpenParser.GetElementClass("pou", "pous") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1664 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1665 |
block_inputs_xpath = PLCOpen_XPath( |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1666 |
"ppx:interface/*[self::ppx:inputVars or self::ppx:inOutVars]/ppx:variable") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1667 |
block_outputs_xpath = PLCOpen_XPath( |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1668 |
"ppx:interface/*[self::ppx:outputVars or self::ppx:inOutVars]/ppx:variable") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1669 |
_updatePouPousClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1670 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1671 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1672 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1673 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1674 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1675 |
def setbodyType(self, body_type): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1676 |
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1677 |
self.body.setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
814 | 1678 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1679 |
raise ValueError("%s isn't a valid body type!" % type) |
814 | 1680 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1681 |
|
814 | 1682 |
def getbodyType(self): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1683 |
return self.body.getcontent().getLocalTag() |
814 | 1684 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1685 |
|
814 | 1686 |
def resetexecutionOrder(self): |
1687 |
self.body.resetexecutionOrder() |
|
1688 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1689 |
|
814 | 1690 |
def compileexecutionOrder(self): |
1691 |
self.body.compileexecutionOrder() |
|
1692 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1693 |
|
814 | 1694 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
1695 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
1696 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1697 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1698 |
def addinstance(self, instance): |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1699 |
self.body.appendcontentInstance(instance) |
814 | 1700 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1701 |
|
814 | 1702 |
def getinstances(self): |
1703 |
return self.body.getcontentInstances() |
|
1704 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1705 |
|
814 | 1706 |
def getinstance(self, id): |
1707 |
return self.body.getcontentInstance(id) |
|
1708 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1709 |
|
814 | 1710 |
def getrandomInstance(self, exclude): |
1711 |
return self.body.getcontentRandomInstance(exclude) |
|
1712 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1713 |
|
814 | 1714 |
def getinstanceByName(self, name): |
1715 |
return self.body.getcontentInstanceByName(name) |
|
1716 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1717 |
|
814 | 1718 |
def removeinstance(self, id): |
1719 |
self.body.removecontentInstance(id) |
|
1720 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1721 |
|
814 | 1722 |
def settext(self, text): |
1723 |
self.body.settext(text) |
|
1724 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1725 |
|
814 | 1726 |
def gettext(self): |
1727 |
return self.body.gettext() |
|
1728 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1729 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1730 |
def hasblock(self, name=None, block_type=None): |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1731 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1732 |
for instance in self.getinstances(): |
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1733 |
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1734 |
(TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type)): |
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1735 |
return True |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1736 |
elif block_type is not None: |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1737 |
return self.body.hasblock(block_type) |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1738 |
return False |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1739 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1740 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1741 |
def updateElementName(self, old_name, new_name): |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1742 |
self.body.updateElementName(old_name, new_name) |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1743 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
1744 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1745 |
def updateElementAddress(self, address_model, new_leading): |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1746 |
self.body.updateElementAddress(address_model, new_leading) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1747 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1748 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1749 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1750 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1751 |
def _updateTransitionTransitionsClass(cls): |
814 | 1752 |
setattr(cls, "setbodyType", setbodyType) |
1753 |
setattr(cls, "getbodyType", getbodyType) |
|
1754 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1755 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1756 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1757 |
setattr(cls, "addinstance", addinstance) |
|
1758 |
setattr(cls, "getinstances", getinstances) |
|
1759 |
setattr(cls, "getinstance", getinstance) |
|
1760 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1761 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1762 |
setattr(cls, "removeinstance", removeinstance) |
|
1763 |
setattr(cls, "settext", settext) |
|
1764 |
setattr(cls, "gettext", gettext) |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1765 |
setattr(cls, "hasblock", hasblock) |
814 | 1766 |
setattr(cls, "updateElementName", updateElementName) |
1767 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1768 |
|
814 | 1769 |
def Search(self, criteria, parent_infos): |
1770 |
search_result = [] |
|
1771 |
parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
|
1772 |
for result in TestTextElement(self.getname(), criteria): |
|
1773 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
|
1774 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
|
1775 |
return search_result |
|
1776 |
setattr(cls, "Search", Search) |
|
1777 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1778 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1779 |
cls = PLCOpenParser.GetElementClass("transition", "transitions") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1780 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1781 |
_updateTransitionTransitionsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1782 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1783 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1784 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1785 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1786 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1787 |
def _updateActionActionsClass(cls): |
814 | 1788 |
setattr(cls, "setbodyType", setbodyType) |
1789 |
setattr(cls, "getbodyType", getbodyType) |
|
1790 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1791 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1792 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1793 |
setattr(cls, "addinstance", addinstance) |
|
1794 |
setattr(cls, "getinstances", getinstances) |
|
1795 |
setattr(cls, "getinstance", getinstance) |
|
1796 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1797 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1798 |
setattr(cls, "removeinstance", removeinstance) |
|
1799 |
setattr(cls, "settext", settext) |
|
1800 |
setattr(cls, "gettext", gettext) |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1801 |
setattr(cls, "hasblock", hasblock) |
814 | 1802 |
setattr(cls, "updateElementName", updateElementName) |
1803 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1804 |
|
814 | 1805 |
def Search(self, criteria, parent_infos): |
1806 |
search_result = [] |
|
1807 |
parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
|
1808 |
for result in TestTextElement(self.getname(), criteria): |
|
1809 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
|
1810 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
|
1811 |
return search_result |
|
1812 |
setattr(cls, "Search", Search) |
|
1813 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1814 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1815 |
cls = PLCOpenParser.GetElementClass("action", "actions") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1816 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1817 |
_updateActionActionsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1818 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1819 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1820 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1821 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1822 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
1823 |
def _updateBodyClass(cls): |
814 | 1824 |
cls.currentExecutionOrderId = 0 |
1629
80eee3c5a057
attach checkedBlockDict variable to the body object
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1626
diff
changeset
|
1825 |
cls.checkedBlocksDict = {} |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
1826 |
|
814 | 1827 |
def resetcurrentExecutionOrderId(self): |
1828 |
object.__setattr__(self, "currentExecutionOrderId", 0) |
|
1829 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1830 |
|
814 | 1831 |
def getnewExecutionOrderId(self): |
1832 |
object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
|
1833 |
return self.currentExecutionOrderId |
|
1834 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1835 |
|
814 | 1836 |
def resetexecutionOrder(self): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1837 |
if self.content.getLocalTag() == "FBD": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1838 |
for element in self.content.getcontent(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1839 |
if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1840 |
PLCOpenParser.GetElementClass("connector", "commonObjects"), |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1841 |
PLCOpenParser.GetElementClass("continuation", "commonObjects"))): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1842 |
element.setexecutionOrderId(0) |
1629
80eee3c5a057
attach checkedBlockDict variable to the body object
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1626
diff
changeset
|
1843 |
self.checkedBlocksDict.clear() |
814 | 1844 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1845 |
raise TypeError(_("Can only generate execution order on FBD networks!")) |
814 | 1846 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1847 |
|
814 | 1848 |
def compileexecutionOrder(self): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1849 |
if self.content.getLocalTag() == "FBD": |
814 | 1850 |
self.resetexecutionOrder() |
1851 |
self.resetcurrentExecutionOrderId() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1852 |
for element in self.content.getcontent(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1853 |
if isinstance(element, PLCOpenParser.GetElementClass("outVariable", "fbdObjects")) and element.getexecutionOrderId() == 0: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1854 |
connections = element.connectionPointIn.getconnections() |
814 | 1855 |
if connections and len(connections) == 1: |
1856 |
self.compileelementExecutionOrder(connections[0]) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1857 |
element.setexecutionOrderId(self.getnewExecutionOrderId()) |
814 | 1858 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1859 |
raise TypeError(_("Can only generate execution order on FBD networks!")) |
814 | 1860 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1861 |
|
814 | 1862 |
def compileelementExecutionOrder(self, link): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1863 |
if self.content.getLocalTag() == "FBD": |
814 | 1864 |
localid = link.getrefLocalId() |
1865 |
instance = self.getcontentInstance(localid) |
|
1629
80eee3c5a057
attach checkedBlockDict variable to the body object
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1626
diff
changeset
|
1866 |
self.checkedBlocksDict[localid] = True |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1867 |
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and instance.getexecutionOrderId() == 0: |
814 | 1868 |
for variable in instance.inputVariables.getvariable(): |
1869 |
connections = variable.connectionPointIn.getconnections() |
|
1870 |
if connections and len(connections) == 1: |
|
1763
bcc07ff2362c
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
1871 |
if not connections[0].getrefLocalId() in self.checkedBlocksDict: |
1534
d2abe4109467
fix infinite recursion in 'Reset Execution Order' functionality if FBD body contains feedback connections
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1406
diff
changeset
|
1872 |
self.compileelementExecutionOrder(connections[0]) |
d2abe4109467
fix infinite recursion in 'Reset Execution Order' functionality if FBD body contains feedback connections
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1406
diff
changeset
|
1873 |
if instance.getexecutionOrderId() == 0: |
d2abe4109467
fix infinite recursion in 'Reset Execution Order' functionality if FBD body contains feedback connections
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1406
diff
changeset
|
1874 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1875 |
elif isinstance(instance, PLCOpenParser.GetElementClass("continuation", "commonObjects")) and instance.getexecutionOrderId() == 0: |
814 | 1876 |
for tmp_instance in self.getcontentInstances(): |
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1877 |
if isinstance(tmp_instance, PLCOpenParser.GetElementClass("connector", "commonObjects")) and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1878 |
TextMatched(tmp_instance.getname(), instance.getname()) and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
1879 |
tmp_instance.getexecutionOrderId() == 0: |
814 | 1880 |
connections = tmp_instance.connectionPointIn.getconnections() |
1881 |
if connections and len(connections) == 1: |
|
1882 |
self.compileelementExecutionOrder(connections[0]) |
|
1883 |
else: |
|
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1884 |
raise TypeError(_("Can only generate execution order on FBD networks!")) |
814 | 1885 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1886 |
|
814 | 1887 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
1294
f02ba5b83811
Fixed datatype and configuration editing in xmlclass refactoring
Laurent Bessard
parents:
1293
diff
changeset
|
1888 |
if self.content.getLocalTag() == "FBD": |
814 | 1889 |
old_executionOrder = instance.getexecutionOrderId() |
1890 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1891 |
for element in self.content.getcontent(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1892 |
if element != instance and not isinstance(element, PLCOpenParser.GetElementClass("comment", "commonObjects")): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1893 |
element_executionOrder = element.getexecutionOrderId() |
814 | 1894 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1895 |
element.setexecutionOrderId(element_executionOrder - 1) |
814 | 1896 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1897 |
element.setexecutionOrderId(element_executionOrder + 1) |
814 | 1898 |
instance.setexecutionOrderId(new_executionOrder) |
1899 |
else: |
|
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1900 |
raise TypeError(_("Can only generate execution order on FBD networks!")) |
814 | 1901 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1902 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
1903 |
def appendcontentInstance(self, instance): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1904 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1905 |
self.content.appendcontent(instance) |
814 | 1906 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1907 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
814 | 1908 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1909 |
|
814 | 1910 |
def getcontentInstances(self): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1911 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1912 |
return self.content.getcontent() |
814 | 1913 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1914 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
814 | 1915 |
setattr(cls, "getcontentInstances", getcontentInstances) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1916 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1917 |
instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1918 |
instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
1919 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1920 |
def getcontentInstance(self, local_id): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1921 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1922 |
instance = instance_by_id_xpath(self.content, localId=local_id) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1923 |
if len(instance) > 0: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1924 |
return instance[0] |
814 | 1925 |
return None |
1926 |
else: |
|
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1927 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
814 | 1928 |
setattr(cls, "getcontentInstance", getcontentInstance) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1929 |
|
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1930 |
def getcontentInstancesIds(self): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1931 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1932 |
return OrderedDict([(instance.getlocalId(), True) |
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1933 |
for instance in self.content]) |
814 | 1934 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1935 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1331
38c5de794e62
Added support for speed-up loading of graphic POU tabs
Laurent Bessard
parents:
1330
diff
changeset
|
1936 |
setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1937 |
|
814 | 1938 |
def getcontentInstanceByName(self, name): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1939 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
1940 |
instance = instance_by_name_xpath(self.content) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1941 |
if len(instance) > 0: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1942 |
return instance[0] |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1943 |
return None |
814 | 1944 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1945 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
814 | 1946 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1947 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1948 |
def removecontentInstance(self, local_id): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1949 |
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1318 | 1950 |
instance = instance_by_id_xpath(self.content, localId=local_id) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1951 |
if len(instance) > 0: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1952 |
self.content.remove(instance[0]) |
1232
b6894285d4cc
Added support for speed up loading graphic viewers
Laurent Bessard
parents:
1171
diff
changeset
|
1953 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1954 |
raise ValueError(_("Instance with id %d doesn't exist!") % id) |
814 | 1955 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1956 |
raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
814 | 1957 |
setattr(cls, "removecontentInstance", removecontentInstance) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1958 |
|
814 | 1959 |
def settext(self, text): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1960 |
if self.content.getLocalTag() in ["IL", "ST"]: |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1961 |
self.content.setanyText(text) |
814 | 1962 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1963 |
raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
814 | 1964 |
setattr(cls, "settext", settext) |
1965 |
||
1966 |
def gettext(self): |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1967 |
if self.content.getLocalTag() in ["IL", "ST"]: |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
1968 |
return self.content.getanyText() |
814 | 1969 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1970 |
raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
814 | 1971 |
setattr(cls, "gettext", gettext) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1972 |
|
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1973 |
def hasblock(self, block_type): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
1974 |
if self.content.getLocalTag() in ["IL", "ST"]: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1975 |
return self.content.hasblock(block_type) |
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1976 |
else: |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
1977 |
raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1978 |
setattr(cls, "hasblock", hasblock) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
1979 |
|
814 | 1980 |
def updateElementName(self, old_name, new_name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1981 |
if self.content.getLocalTag() in ["IL", "ST"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1982 |
self.content.updateElementName(old_name, new_name) |
814 | 1983 |
else: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1984 |
for element in self.content.getcontent(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1985 |
element.updateElementName(old_name, new_name) |
814 | 1986 |
setattr(cls, "updateElementName", updateElementName) |
1987 |
||
1988 |
def updateElementAddress(self, address_model, new_leading): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1989 |
if self.content.getLocalTag() in ["IL", "ST"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1990 |
self.content.updateElementAddress(address_model, new_leading) |
814 | 1991 |
else: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1992 |
for element in self.content.getcontent(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1993 |
element.updateElementAddress(address_model, new_leading) |
814 | 1994 |
setattr(cls, "updateElementAddress", updateElementAddress) |
1995 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1996 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
1997 |
parent_infos = [] if parent_infos is None else parent_infos |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1998 |
if self.content.getLocalTag() in ["IL", "ST"]: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
1999 |
search_result = self.content.Search(criteria, parent_infos + ["body", 0]) |
814 | 2000 |
else: |
2001 |
search_result = [] |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2002 |
for element in self.content.getcontent(): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2003 |
search_result.extend(element.Search(criteria, parent_infos)) |
814 | 2004 |
return search_result |
2005 |
setattr(cls, "Search", Search) |
|
2006 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2007 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2008 |
cls = PLCOpenParser.GetElementClass("body") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2009 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2010 |
_updateBodyClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2011 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2012 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2013 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2014 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2015 |
|
814 | 2016 |
def getx(self): |
2017 |
return self.position.getx() |
|
2018 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2019 |
|
814 | 2020 |
def gety(self): |
2021 |
return self.position.gety() |
|
2022 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2023 |
|
814 | 2024 |
def setx(self, x): |
2025 |
self.position.setx(x) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2026 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2027 |
|
814 | 2028 |
def sety(self, y): |
2029 |
self.position.sety(y) |
|
2030 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2031 |
|
814 | 2032 |
def _getBoundingBox(self): |
2033 |
return rect(self.getx(), self.gety(), self.getwidth(), self.getheight()) |
|
2034 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2035 |
|
814 | 2036 |
def _getConnectionsBoundingBox(connectionPointIn): |
2037 |
bbox = rect() |
|
2038 |
connections = connectionPointIn.getconnections() |
|
2039 |
if connections is not None: |
|
2040 |
for connection in connections: |
|
2041 |
for x, y in connection.getpoints(): |
|
2042 |
bbox.update(x, y) |
|
2043 |
return bbox |
|
2044 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2045 |
|
814 | 2046 |
def _getBoundingBoxSingle(self): |
2047 |
bbox = _getBoundingBox(self) |
|
2048 |
if self.connectionPointIn is not None: |
|
2049 |
bbox.union(_getConnectionsBoundingBox(self.connectionPointIn)) |
|
2050 |
return bbox |
|
2051 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2052 |
|
814 | 2053 |
def _getBoundingBoxMultiple(self): |
2054 |
bbox = _getBoundingBox(self) |
|
2055 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2056 |
bbox.union(_getConnectionsBoundingBox(connectionPointIn)) |
|
2057 |
return bbox |
|
2058 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2059 |
|
814 | 2060 |
def _filterConnections(connectionPointIn, localId, connections): |
2061 |
in_connections = connectionPointIn.getconnections() |
|
2062 |
if in_connections is not None: |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2063 |
for connection in in_connections: |
814 | 2064 |
connected = connection.getrefLocalId() |
1763
bcc07ff2362c
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
2065 |
if not (localId, connected) in connections and \ |
bcc07ff2362c
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
2066 |
not (connected, localId) in connections: |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2067 |
connectionPointIn.remove(connection) |
814 | 2068 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2069 |
|
814 | 2070 |
def _filterConnectionsSingle(self, connections): |
2071 |
if self.connectionPointIn is not None: |
|
2072 |
_filterConnections(self.connectionPointIn, self.localId, connections) |
|
2073 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2074 |
|
814 | 2075 |
def _filterConnectionsMultiple(self, connections): |
2076 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2077 |
_filterConnections(connectionPointIn, self.localId, connections) |
|
2078 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2079 |
|
814 | 2080 |
def _getconnectionsdefinition(instance, connections_end): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2081 |
local_id = instance.getlocalId() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2082 |
return dict([((local_id, end), True) for end in connections_end]) |
814 | 2083 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2084 |
|
814 | 2085 |
def _updateConnectionsId(connectionPointIn, translation): |
2086 |
connections_end = [] |
|
2087 |
connections = connectionPointIn.getconnections() |
|
2088 |
if connections is not None: |
|
2089 |
for connection in connections: |
|
2090 |
refLocalId = connection.getrefLocalId() |
|
2091 |
new_reflocalId = translation.get(refLocalId, refLocalId) |
|
2092 |
connection.setrefLocalId(new_reflocalId) |
|
2093 |
connections_end.append(new_reflocalId) |
|
2094 |
return connections_end |
|
2095 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2096 |
|
814 | 2097 |
def _updateConnectionsIdSingle(self, translation): |
2098 |
connections_end = [] |
|
2099 |
if self.connectionPointIn is not None: |
|
2100 |
connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
|
2101 |
return _getconnectionsdefinition(self, connections_end) |
|
2102 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2103 |
|
814 | 2104 |
def _updateConnectionsIdMultiple(self, translation): |
2105 |
connections_end = [] |
|
2106 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2107 |
connections_end.extend(_updateConnectionsId(connectionPointIn, translation)) |
|
2108 |
return _getconnectionsdefinition(self, connections_end) |
|
2109 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2110 |
|
814 | 2111 |
def _translate(self, dx, dy): |
2112 |
self.setx(self.getx() + dx) |
|
2113 |
self.sety(self.gety() + dy) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2114 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2115 |
|
814 | 2116 |
def _translateConnections(connectionPointIn, dx, dy): |
2117 |
connections = connectionPointIn.getconnections() |
|
2118 |
if connections is not None: |
|
2119 |
for connection in connections: |
|
2120 |
for position in connection.getposition(): |
|
2121 |
position.setx(position.getx() + dx) |
|
2122 |
position.sety(position.gety() + dy) |
|
2123 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2124 |
|
814 | 2125 |
def _translateSingle(self, dx, dy): |
2126 |
_translate(self, dx, dy) |
|
2127 |
if self.connectionPointIn is not None: |
|
2128 |
_translateConnections(self.connectionPointIn, dx, dy) |
|
2129 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2130 |
|
814 | 2131 |
def _translateMultiple(self, dx, dy): |
2132 |
_translate(self, dx, dy) |
|
2133 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2134 |
_translateConnections(connectionPointIn, dx, dy) |
|
2135 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2136 |
|
814 | 2137 |
def _updateElementName(self, old_name, new_name): |
2138 |
pass |
|
2139 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2140 |
|
814 | 2141 |
def _updateElementAddress(self, address_model, new_leading): |
2142 |
pass |
|
2143 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2144 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2145 |
def _SearchInElement(self, criteria, parent_infos=None): |
814 | 2146 |
return [] |
2147 |
||
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
|
2148 |
|
814 | 2149 |
_connectionsFunctions = { |
2150 |
"bbox": {"none": _getBoundingBox, |
|
2151 |
"single": _getBoundingBoxSingle, |
|
2152 |
"multiple": _getBoundingBoxMultiple}, |
|
2153 |
"translate": {"none": _translate, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
2154 |
"single": _translateSingle, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
2155 |
"multiple": _translateMultiple}, |
814 | 2156 |
"filter": {"none": lambda self, connections: None, |
2157 |
"single": _filterConnectionsSingle, |
|
2158 |
"multiple": _filterConnectionsMultiple}, |
|
2159 |
"update": {"none": lambda self, translation: {}, |
|
2160 |
"single": _updateConnectionsIdSingle, |
|
2161 |
"multiple": _updateConnectionsIdMultiple}, |
|
2162 |
} |
|
2163 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2164 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2165 |
def _initElementClass(name, parent, connectionPointInType="none"): |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2166 |
cls = PLCOpenParser.GetElementClass(name, parent) |
814 | 2167 |
if cls: |
2168 |
setattr(cls, "getx", getx) |
|
2169 |
setattr(cls, "gety", gety) |
|
2170 |
setattr(cls, "setx", setx) |
|
2171 |
setattr(cls, "sety", sety) |
|
2172 |
setattr(cls, "updateElementName", _updateElementName) |
|
2173 |
setattr(cls, "updateElementAddress", _updateElementAddress) |
|
2174 |
setattr(cls, "getBoundingBox", _connectionsFunctions["bbox"][connectionPointInType]) |
|
2175 |
setattr(cls, "translate", _connectionsFunctions["translate"][connectionPointInType]) |
|
2176 |
setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
|
2177 |
setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
|
2178 |
setattr(cls, "Search", _SearchInElement) |
|
2179 |
return cls |
|
2180 |
||
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
|
2181 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2182 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2183 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2184 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2185 |
def _updateCommentCommonObjectsClass(cls): |
814 | 2186 |
def setcontentText(self, text): |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2187 |
self.content.setanyText(text) |
814 | 2188 |
setattr(cls, "setcontentText", setcontentText) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2189 |
|
814 | 2190 |
def getcontentText(self): |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2191 |
return self.content.getanyText() |
814 | 2192 |
setattr(cls, "getcontentText", getcontentText) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2193 |
|
814 | 2194 |
def updateElementName(self, old_name, new_name): |
2195 |
self.content.updateElementName(old_name, new_name) |
|
2196 |
setattr(cls, "updateElementName", updateElementName) |
|
2197 |
||
2198 |
def updateElementAddress(self, address_model, new_leading): |
|
2199 |
self.content.updateElementAddress(address_model, new_leading) |
|
2200 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2201 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2202 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2203 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2204 |
return self.content.Search(criteria, parent_infos + ["comment", self.getlocalId(), "content"]) |
2205 |
setattr(cls, "Search", Search) |
|
2206 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2207 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2208 |
cls = _initElementClass("comment", "commonObjects") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2209 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2210 |
_updateCommentCommonObjectsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2211 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2212 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2213 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2214 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2215 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2216 |
def _updateBlockFbdObjectsClass(cls): |
814 | 2217 |
def getBoundingBox(self): |
2218 |
bbox = _getBoundingBox(self) |
|
2219 |
for input in self.inputVariables.getvariable(): |
|
2220 |
bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
|
2221 |
return bbox |
|
2222 |
setattr(cls, "getBoundingBox", getBoundingBox) |
|
2223 |
||
2224 |
def updateElementName(self, old_name, new_name): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2225 |
if TextMatched(self.typeName, old_name): |
814 | 2226 |
self.typeName = new_name |
2227 |
setattr(cls, "updateElementName", updateElementName) |
|
2228 |
||
2229 |
def filterConnections(self, connections): |
|
2230 |
for input in self.inputVariables.getvariable(): |
|
2231 |
_filterConnections(input.connectionPointIn, self.localId, connections) |
|
2232 |
setattr(cls, "filterConnections", filterConnections) |
|
2233 |
||
2234 |
def updateConnectionsId(self, translation): |
|
2235 |
connections_end = [] |
|
2236 |
for input in self.inputVariables.getvariable(): |
|
2237 |
connections_end.extend(_updateConnectionsId(input.connectionPointIn, translation)) |
|
2238 |
return _getconnectionsdefinition(self, connections_end) |
|
2239 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
|
2240 |
||
2241 |
def translate(self, dx, dy): |
|
2242 |
_translate(self, dx, dy) |
|
2243 |
for input in self.inputVariables.getvariable(): |
|
2244 |
_translateConnections(input.connectionPointIn, dx, dy) |
|
2245 |
setattr(cls, "translate", translate) |
|
2246 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2247 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2248 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2249 |
parent_infos = parent_infos + ["block", self.getlocalId()] |
2250 |
search_result = _Search([("name", self.getinstanceName()), |
|
2251 |
("type", self.gettypeName())], |
|
2252 |
criteria, parent_infos) |
|
2253 |
for i, variable in enumerate(self.inputVariables.getvariable()): |
|
2254 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
|
2255 |
search_result.append((tuple(parent_infos + ["input", i]),) + result) |
|
2256 |
for i, variable in enumerate(self.outputVariables.getvariable()): |
|
2257 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
|
2258 |
search_result.append((tuple(parent_infos + ["output", i]),) + result) |
|
2259 |
return search_result |
|
2260 |
setattr(cls, "Search", Search) |
|
2261 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2262 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2263 |
cls = _initElementClass("block", "fbdObjects") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2264 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2265 |
_updateBlockFbdObjectsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2266 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2267 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2268 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2269 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2270 |
|
1355
9183fb765f16
Fixed bug when modifying power rail in LD Viewer
Laurent Bessard
parents:
1346
diff
changeset
|
2271 |
_initElementClass("leftPowerRail", "ldObjects") |
9183fb765f16
Fixed bug when modifying power rail in LD Viewer
Laurent Bessard
parents:
1346
diff
changeset
|
2272 |
_initElementClass("rightPowerRail", "ldObjects", "multiple") |
9183fb765f16
Fixed bug when modifying power rail in LD Viewer
Laurent Bessard
parents:
1346
diff
changeset
|
2273 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2274 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2275 |
def _UpdateLDElementName(self, old_name, new_name): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2276 |
if TextMatched(self.variable, old_name): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2277 |
self.variable = new_name |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2278 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2279 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2280 |
def _UpdateLDElementAddress(self, address_model, new_leading): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2281 |
self.variable = update_address(self.variable, address_model, new_leading) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2282 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2283 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2284 |
def _getSearchInLDElement(ld_element_type): |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2285 |
def SearchInLDElement(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2286 |
parent_infos = [] if parent_infos is None else parent_infos |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2287 |
return _Search([("reference", self.variable)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2288 |
return SearchInLDElement |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2289 |
|
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
|
2290 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2291 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2292 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2293 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2294 |
cls = _initElementClass("contact", "ldObjects", "single") |
814 | 2295 |
if cls: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2296 |
setattr(cls, "updateElementName", _UpdateLDElementName) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2297 |
setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2298 |
setattr(cls, "Search", _getSearchInLDElement("contact")) |
814 | 2299 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2300 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2301 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2302 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2303 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2304 |
cls = _initElementClass("coil", "ldObjects", "single") |
814 | 2305 |
if cls: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2306 |
setattr(cls, "updateElementName", _UpdateLDElementName) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2307 |
setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2308 |
setattr(cls, "Search", _getSearchInLDElement("coil")) |
814 | 2309 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2310 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2311 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2312 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2313 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2314 |
def _updateStepSfcObjectSingleClass(cls): |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2315 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2316 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2317 |
return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
2318 |
setattr(cls, "Search", Search) |
|
2319 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2320 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2321 |
cls = _initElementClass("step", "sfcObjects", "single") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2322 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2323 |
_updateStepSfcObjectSingleClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2324 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2325 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2326 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2327 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2328 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2329 |
def _updateTransitionSfcObjectsClass(cls): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2330 |
def setconditionContent(self, condition_type, value): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2331 |
if self.condition is None: |
814 | 2332 |
self.addcondition() |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2333 |
if condition_type == "connection": |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2334 |
condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2335 |
else: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2336 |
condition = PLCOpenParser.CreateElement(condition_type, "condition") |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2337 |
self.condition.setcontent(condition) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2338 |
if condition_type == "reference": |
814 | 2339 |
condition.setname(value) |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2340 |
elif condition_type == "inline": |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2341 |
condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2342 |
condition.settext(value) |
814 | 2343 |
setattr(cls, "setconditionContent", setconditionContent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2344 |
|
814 | 2345 |
def getconditionContent(self): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2346 |
if self.condition is not None: |
814 | 2347 |
content = self.condition.getcontent() |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
2348 |
values = {"type": content.getLocalTag()} |
814 | 2349 |
if values["type"] == "reference": |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2350 |
values["value"] = content.getname() |
814 | 2351 |
elif values["type"] == "inline": |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2352 |
values["value"] = content.gettext() |
814 | 2353 |
elif values["type"] == "connectionPointIn": |
2354 |
values["type"] = "connection" |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2355 |
values["value"] = content |
814 | 2356 |
return values |
2357 |
return "" |
|
2358 |
setattr(cls, "getconditionContent", getconditionContent) |
|
2359 |
||
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2360 |
def getconditionConnection(self): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2361 |
if self.condition is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2362 |
content = self.condition.getcontent() |
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
2363 |
if content.getLocalTag() == "connectionPointIn": |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2364 |
return content |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2365 |
return None |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2366 |
setattr(cls, "getconditionConnection", getconditionConnection) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2367 |
|
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2368 |
def getBoundingBox(self): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2369 |
bbox = _getBoundingBoxSingle(self) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2370 |
condition_connection = self.getconditionConnection() |
1302
7856cd7767d6
Removed dictionaries storing datatypes and pous defined in project and pou and datatype using tree from model
Laurent Bessard
parents:
1301
diff
changeset
|
2371 |
if condition_connection is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2372 |
bbox.union(_getConnectionsBoundingBox(condition_connection)) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2373 |
return bbox |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2374 |
setattr(cls, "getBoundingBox", getBoundingBox) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2375 |
|
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2376 |
def translate(self, dx, dy): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2377 |
_translateSingle(self, dx, dy) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2378 |
condition_connection = self.getconditionConnection() |
1299
9ffc49bfdf9d
Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents:
1298
diff
changeset
|
2379 |
if condition_connection is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2380 |
_translateConnections(condition_connection, dx, dy) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2381 |
setattr(cls, "translate", translate) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2382 |
|
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2383 |
def filterConnections(self, connections): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2384 |
_filterConnectionsSingle(self, connections) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2385 |
condition_connection = self.getconditionConnection() |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
2386 |
if condition_connection is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2387 |
_filterConnections(condition_connection, self.localId, connections) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2388 |
setattr(cls, "filterConnections", filterConnections) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2389 |
|
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2390 |
def updateConnectionsId(self, translation): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2391 |
connections_end = [] |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2392 |
if self.connectionPointIn is not None: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2393 |
connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2394 |
condition_connection = self.getconditionConnection() |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
2395 |
if condition_connection is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2396 |
connections_end.extend(_updateConnectionsId(condition_connection, translation)) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2397 |
return _getconnectionsdefinition(self, connections_end) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2398 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2399 |
|
814 | 2400 |
def updateElementName(self, old_name, new_name): |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
2401 |
if self.condition is not None: |
814 | 2402 |
content = self.condition.getcontent() |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2403 |
content_name = content.getLocalTag() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2404 |
if content_name == "reference": |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2405 |
if TextMatched(content.getname(), old_name): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2406 |
content.setname(new_name) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2407 |
elif content_name == "inline": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2408 |
content.updateElementName(old_name, new_name) |
814 | 2409 |
setattr(cls, "updateElementName", updateElementName) |
2410 |
||
2411 |
def updateElementAddress(self, address_model, new_leading): |
|
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
2412 |
if self.condition is not None: |
814 | 2413 |
content = self.condition.getcontent() |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2414 |
content_name = content.getLocalTag() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2415 |
if content_name == "reference": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2416 |
content.setname(update_address(content.getname(), address_model, new_leading)) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2417 |
elif content_name == "inline": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2418 |
content.updateElementAddress(address_model, new_leading) |
814 | 2419 |
setattr(cls, "updateElementAddress", updateElementAddress) |
2420 |
||
2421 |
def getconnections(self): |
|
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2422 |
condition_connection = self.getconditionConnection() |
1301
fcca121a000f
Removed dictionaries storing enumerated datatypes values, subrange datatypes range and project datatype hierarchy from model
Laurent Bessard
parents:
1299
diff
changeset
|
2423 |
if condition_connection is not None: |
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2424 |
return condition_connection.getconnections() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2425 |
return None |
814 | 2426 |
setattr(cls, "getconnections", getconnections) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2427 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2428 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2429 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2430 |
parent_infos = parent_infos + ["transition", self.getlocalId()] |
2431 |
search_result = [] |
|
2432 |
content = self.condition.getcontent() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2433 |
content_name = content.getLocalTag() |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2434 |
if content_name == "reference": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2435 |
search_result.extend(_Search([("reference", content.getname())], criteria, parent_infos)) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2436 |
elif content_name == "inline": |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2437 |
search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
814 | 2438 |
return search_result |
2439 |
setattr(cls, "Search", Search) |
|
1346 | 2440 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2441 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2442 |
cls = _initElementClass("transition", "sfcObjects") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2443 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2444 |
_updateTransitionSfcObjectsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2445 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2446 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2447 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2448 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2449 |
|
1346 | 2450 |
_initElementClass("selectionDivergence", "sfcObjects", "single") |
2451 |
_initElementClass("selectionConvergence", "sfcObjects", "multiple") |
|
2452 |
_initElementClass("simultaneousDivergence", "sfcObjects", "single") |
|
2453 |
_initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2454 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2455 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2456 |
def _updateJumpStepSfcObjectSingleClass(cls): |
814 | 2457 |
def Search(self, criteria, parent_infos): |
2458 |
return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
|
2459 |
setattr(cls, "Search", Search) |
|
2460 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2461 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2462 |
cls = _initElementClass("jumpStep", "sfcObjects", "single") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2463 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2464 |
_updateJumpStepSfcObjectSingleClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2465 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2466 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2467 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2468 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2469 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2470 |
def _updateActionActionBlockClass(cls): |
814 | 2471 |
def setreferenceName(self, name): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2472 |
if self.reference is not None: |
814 | 2473 |
self.reference.setname(name) |
2474 |
setattr(cls, "setreferenceName", setreferenceName) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2475 |
|
814 | 2476 |
def getreferenceName(self): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2477 |
if self.reference is not None: |
814 | 2478 |
return self.reference.getname() |
2479 |
return None |
|
2480 |
setattr(cls, "getreferenceName", getreferenceName) |
|
2481 |
||
2482 |
def setinlineContent(self, content): |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2483 |
if self.inline is not None: |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2484 |
self.inline.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2485 |
self.inline.settext(content) |
814 | 2486 |
setattr(cls, "setinlineContent", setinlineContent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2487 |
|
814 | 2488 |
def getinlineContent(self): |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2489 |
if self.inline is not None: |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2490 |
return self.inline.gettext() |
814 | 2491 |
return None |
2492 |
setattr(cls, "getinlineContent", getinlineContent) |
|
2493 |
||
2494 |
def updateElementName(self, old_name, new_name): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2495 |
if self.reference is not None and TextMatched(self.reference.getname(), old_name): |
814 | 2496 |
self.reference.setname(new_name) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2497 |
if self.inline is not None: |
814 | 2498 |
self.inline.updateElementName(old_name, new_name) |
2499 |
setattr(cls, "updateElementName", updateElementName) |
|
2500 |
||
2501 |
def updateElementAddress(self, address_model, new_leading): |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2502 |
if self.reference is not None: |
814 | 2503 |
self.reference.setname(update_address(self.reference.getname(), address_model, new_leading)) |
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2504 |
if self.inline is not None: |
814 | 2505 |
self.inline.updateElementAddress(address_model, new_leading) |
2506 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2507 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2508 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2509 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2510 |
qualifier = self.getqualifier() |
2511 |
if qualifier is None: |
|
2512 |
qualifier = "N" |
|
2513 |
return _Search([("inline", self.getinlineContent()), |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2514 |
("reference", self.getreferenceName()), |
814 | 2515 |
("qualifier", qualifier), |
2516 |
("duration", self.getduration()), |
|
2517 |
("indicator", self.getindicator())], |
|
2518 |
criteria, parent_infos) |
|
2519 |
setattr(cls, "Search", Search) |
|
2520 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2521 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2522 |
cls = PLCOpenParser.GetElementClass("action", "actionBlock") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2523 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2524 |
_updateActionActionBlockClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2525 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2526 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2527 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2528 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2529 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2530 |
def _updateActionBlockCommonObjectsSingleClass(cls): |
814 | 2531 |
def setactions(self, actions): |
2532 |
self.action = [] |
|
2533 |
for params in actions: |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2534 |
action = PLCOpenParser.CreateElement("action", "actionBlock") |
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2535 |
self.appendaction(action) |
1339 | 2536 |
action.setqualifier(params.qualifier) |
2537 |
if params.type == "reference": |
|
814 | 2538 |
action.addreference() |
1339 | 2539 |
action.setreferenceName(params.value) |
814 | 2540 |
else: |
2541 |
action.addinline() |
|
1339 | 2542 |
action.setinlineContent(params.value) |
2543 |
if params.duration != "": |
|
2544 |
action.setduration(params.duration) |
|
2545 |
if params.indicator != "": |
|
2546 |
action.setindicator(params.indicator) |
|
814 | 2547 |
setattr(cls, "setactions", setactions) |
2548 |
||
2549 |
def getactions(self): |
|
2550 |
actions = [] |
|
2551 |
for action in self.action: |
|
2552 |
params = {} |
|
2553 |
params["qualifier"] = action.getqualifier() |
|
2554 |
if params["qualifier"] is None: |
|
2555 |
params["qualifier"] = "N" |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2556 |
if action.getreference() is not None: |
814 | 2557 |
params["type"] = "reference" |
2558 |
params["value"] = action.getreferenceName() |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2559 |
elif action.getinline() is not None: |
814 | 2560 |
params["type"] = "inline" |
2561 |
params["value"] = action.getinlineContent() |
|
2562 |
duration = action.getduration() |
|
2563 |
if duration: |
|
2564 |
params["duration"] = duration |
|
2565 |
indicator = action.getindicator() |
|
1298
f034fb2b1aab
Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents:
1294
diff
changeset
|
2566 |
if indicator is not None: |
814 | 2567 |
params["indicator"] = indicator |
2568 |
actions.append(params) |
|
2569 |
return actions |
|
2570 |
setattr(cls, "getactions", getactions) |
|
2571 |
||
2572 |
def updateElementName(self, old_name, new_name): |
|
2573 |
for action in self.action: |
|
2574 |
action.updateElementName(old_name, new_name) |
|
2575 |
setattr(cls, "updateElementName", updateElementName) |
|
2576 |
||
2577 |
def updateElementAddress(self, address_model, new_leading): |
|
2578 |
for action in self.action: |
|
2579 |
action.updateElementAddress(address_model, new_leading) |
|
2580 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2581 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2582 |
def Search(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2583 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2584 |
parent_infos = parent_infos + ["action_block", self.getlocalId()] |
2585 |
search_result = [] |
|
2586 |
for idx, action in enumerate(self.action): |
|
2587 |
search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
|
2588 |
return search_result |
|
2589 |
setattr(cls, "Search", Search) |
|
2590 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2591 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2592 |
cls = _initElementClass("actionBlock", "commonObjects", "single") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2593 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2594 |
_updateActionBlockCommonObjectsSingleClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2595 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2596 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2597 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2598 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2599 |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2600 |
def _SearchInIOVariable(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2601 |
parent_infos = [] if parent_infos is None else parent_infos |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2602 |
return _Search([("expression", self.expression)], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2603 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2604 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2605 |
def _UpdateIOElementName(self, old_name, new_name): |
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2606 |
if TextMatched(self.expression, old_name): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2607 |
self.expression = new_name |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2608 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2609 |
|
1400 | 2610 |
def _UpdateIOElementAddress(self, address_model, new_leading): |
1322
0a9227f743b3
Fixed xmlclass for working with included files, adding support for SimpleType elements and solving ambiguity in extension class when different elements share the same name and parent name
Laurent Bessard
parents:
1318
diff
changeset
|
2611 |
self.expression = update_address(self.expression, address_model, new_leading) |
814 | 2612 |
|
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
|
2613 |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2614 |
cls = _initElementClass("inVariable", "fbdObjects") |
814 | 2615 |
if cls: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2616 |
setattr(cls, "updateElementName", _UpdateIOElementName) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2617 |
setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
814 | 2618 |
setattr(cls, "Search", _SearchInIOVariable) |
2619 |
||
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2620 |
cls = _initElementClass("outVariable", "fbdObjects", "single") |
814 | 2621 |
if cls: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2622 |
setattr(cls, "updateElementName", _UpdateIOElementName) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2623 |
setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
814 | 2624 |
setattr(cls, "Search", _SearchInIOVariable) |
2625 |
||
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2626 |
cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
814 | 2627 |
if cls: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2628 |
setattr(cls, "updateElementName", _UpdateIOElementName) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2629 |
setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
814 | 2630 |
setattr(cls, "Search", _SearchInIOVariable) |
2631 |
||
2632 |
||
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2633 |
def _SearchInConnector(self, criteria, parent_infos=None): |
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
2634 |
parent_infos = [] if parent_infos is None else parent_infos |
814 | 2635 |
return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2636 |
||
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
|
2637 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2638 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2639 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2640 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2641 |
def _updateContinuationCommonObjectsClass(cls): |
814 | 2642 |
setattr(cls, "Search", _SearchInConnector) |
2643 |
||
2644 |
def updateElementName(self, old_name, new_name): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2645 |
if TextMatched(self.name, old_name): |
814 | 2646 |
self.name = new_name |
2647 |
setattr(cls, "updateElementName", updateElementName) |
|
2648 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2649 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2650 |
cls = _initElementClass("continuation", "commonObjects") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2651 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2652 |
_updateContinuationCommonObjectsClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2653 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2654 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2655 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2656 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2657 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2658 |
def _updateConnectorCommonObjectsSingleClass(cls): |
814 | 2659 |
setattr(cls, "Search", _SearchInConnector) |
2660 |
||
2661 |
def updateElementName(self, old_name, new_name): |
|
1611
5e64d552b25a
make renames caseinsensitive
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
2662 |
if TextMatched(self.name, old_name): |
814 | 2663 |
self.name = new_name |
2664 |
setattr(cls, "updateElementName", updateElementName) |
|
2665 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2666 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2667 |
cls = _initElementClass("connector", "commonObjects", "single") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2668 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2669 |
_updateConnectorCommonObjectsSingleClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2670 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2671 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2672 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2673 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2674 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2675 |
def _updateConnectionClass(cls): |
814 | 2676 |
def setpoints(self, points): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2677 |
positions = [] |
814 | 2678 |
for point in points: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2679 |
position = PLCOpenParser.CreateElement("position", "connection") |
814 | 2680 |
position.setx(point.x) |
2681 |
position.sety(point.y) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2682 |
positions.append(position) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2683 |
self.position = positions |
814 | 2684 |
setattr(cls, "setpoints", setpoints) |
2685 |
||
2686 |
def getpoints(self): |
|
2687 |
points = [] |
|
2688 |
for position in self.position: |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
2689 |
points.append((position.getx(), position.gety())) |
814 | 2690 |
return points |
2691 |
setattr(cls, "getpoints", getpoints) |
|
2692 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2693 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2694 |
cls = PLCOpenParser.GetElementClass("connection") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2695 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2696 |
_updateConnectionClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2697 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2698 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2699 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2700 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2701 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2702 |
def _updateConnectionPointInClass(cls): |
814 | 2703 |
def setrelPositionXY(self, x, y): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2704 |
self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointIn") |
814 | 2705 |
self.relPosition.setx(x) |
2706 |
self.relPosition.sety(y) |
|
2707 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2708 |
||
2709 |
def getrelPositionXY(self): |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2710 |
if self.relPosition is not None: |
814 | 2711 |
return self.relPosition.getx(), self.relPosition.gety() |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2712 |
return self.relPosition |
814 | 2713 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2714 |
||
2715 |
def addconnection(self): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2716 |
self.append(PLCOpenParser.CreateElement("connection", "connectionPointIn")) |
814 | 2717 |
setattr(cls, "addconnection", addconnection) |
2718 |
||
2719 |
def removeconnection(self, idx): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2720 |
if len(self.content) > idx: |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2721 |
self.remove(self.content[idx]) |
814 | 2722 |
setattr(cls, "removeconnection", removeconnection) |
2723 |
||
2724 |
def removeconnections(self): |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2725 |
self.content = None |
814 | 2726 |
setattr(cls, "removeconnections", removeconnections) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2727 |
|
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
2728 |
connection_xpath = PLCOpen_XPath("ppx:connection") |
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
2729 |
connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]") |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
2730 |
|
814 | 2731 |
def getconnections(self): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
2732 |
return connection_xpath(self) |
814 | 2733 |
setattr(cls, "getconnections", getconnections) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2734 |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2735 |
def getconnection(self, idx): |
1305
714f1381a09a
Fixed xmlclass and plcopen using precompile xpath where possible
Laurent Bessard
parents:
1302
diff
changeset
|
2736 |
connection = connection_by_position_xpath(self, pos=idx+1) |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2737 |
if len(connection) > 0: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2738 |
return connection[0] |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2739 |
return None |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2740 |
setattr(cls, "getconnection", getconnection) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2741 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2742 |
def setconnectionId(self, idx, local_id): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2743 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2744 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2745 |
connection.setrefLocalId(local_id) |
814 | 2746 |
setattr(cls, "setconnectionId", setconnectionId) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2747 |
|
814 | 2748 |
def getconnectionId(self, idx): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2749 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2750 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2751 |
return connection.getrefLocalId() |
814 | 2752 |
return None |
2753 |
setattr(cls, "getconnectionId", getconnectionId) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2754 |
|
814 | 2755 |
def setconnectionPoints(self, idx, points): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2756 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2757 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2758 |
connection.setpoints(points) |
814 | 2759 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
2760 |
||
2761 |
def getconnectionPoints(self, idx): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2762 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2763 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2764 |
return connection.getpoints() |
1285
fa77f3b8f182
Fixed bug when no connection defined for connectionPointIn
Laurent Bessard
parents:
1283
diff
changeset
|
2765 |
return [] |
814 | 2766 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
2767 |
||
2768 |
def setconnectionParameter(self, idx, parameter): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2769 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2770 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2771 |
connection.setformalParameter(parameter) |
814 | 2772 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2773 |
|
814 | 2774 |
def getconnectionParameter(self, idx): |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2775 |
connection = self.getconnection(idx) |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2776 |
if connection is not None: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2777 |
return connection.getformalParameter() |
814 | 2778 |
return None |
2779 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
|
2780 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2781 |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2782 |
cls = PLCOpenParser.GetElementClass("connectionPointOut") |
814 | 2783 |
if cls: |
2784 |
def setrelPositionXY(self, x, y): |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2785 |
self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") |
814 | 2786 |
self.relPosition.setx(x) |
2787 |
self.relPosition.sety(y) |
|
2788 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2789 |
||
2790 |
def getrelPositionXY(self): |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2791 |
if self.relPosition is not None: |
814 | 2792 |
return self.relPosition.getx(), self.relPosition.gety() |
2793 |
return self.relPosition |
|
2794 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
|
2795 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2796 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2797 |
cls = PLCOpenParser.GetElementClass("connectionPointIn") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2798 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2799 |
_updateConnectionPointInClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2800 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2801 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2802 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2803 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2804 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2805 |
def _updateValueClass(cls): |
814 | 2806 |
def setvalue(self, value): |
2807 |
value = value.strip() |
|
2808 |
if value.startswith("[") and value.endswith("]"): |
|
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2809 |
content = PLCOpenParser.CreateElement("arrayValue", "value") |
814 | 2810 |
elif value.startswith("(") and value.endswith(")"): |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2811 |
content = PLCOpenParser.CreateElement("structValue", "value") |
814 | 2812 |
else: |
1291
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2813 |
content = PLCOpenParser.CreateElement("simpleValue", "value") |
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2814 |
content.setvalue(value) |
42ea51d083ce
Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents:
1290
diff
changeset
|
2815 |
self.setcontent(content) |
814 | 2816 |
setattr(cls, "setvalue", setvalue) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2817 |
|
814 | 2818 |
def getvalue(self): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2819 |
return self.content.getvalue() |
814 | 2820 |
setattr(cls, "getvalue", getvalue) |
2821 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
2822 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2823 |
cls = PLCOpenParser.GetElementClass("value") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2824 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2825 |
_updateValueClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2826 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2827 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2828 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2829 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2830 |
|
814 | 2831 |
def extractValues(values): |
2832 |
items = values.split(",") |
|
2833 |
i = 1 |
|
2834 |
while i < len(items): |
|
2835 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
2836 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
2837 |
if opened > closed: |
|
2838 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
2839 |
elif opened == closed: |
|
2840 |
i += 1 |
|
2841 |
else: |
|
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1852
diff
changeset
|
2842 |
raise ValueError(_("\"%s\" is an invalid value!") % values) |
814 | 2843 |
return items |
2844 |
||
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
|
2845 |
|
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2846 |
def _updateArrayValueValueClass(cls): |
814 | 2847 |
def setvalue(self, value): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2848 |
elements = [] |
814 | 2849 |
for item in extractValues(value[1:-1]): |
2850 |
item = item.strip() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2851 |
element = PLCOpenParser.CreateElement("value", "arrayValue") |
814 | 2852 |
result = arrayValue_model.match(item) |
2853 |
if result is not None: |
|
2854 |
groups = result.groups() |
|
2855 |
element.setrepetitionValue(groups[0]) |
|
2856 |
element.setvalue(groups[1].strip()) |
|
2857 |
else: |
|
2858 |
element.setvalue(item) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2859 |
elements.append(element) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2860 |
self.value = elements |
814 | 2861 |
setattr(cls, "setvalue", setvalue) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2862 |
|
814 | 2863 |
def getvalue(self): |
2864 |
values = [] |
|
2865 |
for element in self.value: |
|
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2866 |
try: |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2867 |
repetition = int(element.getrepetitionValue()) |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1777
diff
changeset
|
2868 |
except Exception: |
1293
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2869 |
repetition = 1 |
40117d02601b
Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents:
1291
diff
changeset
|
2870 |
if repetition > 1: |
814 | 2871 |
value = element.getvalue() |
2872 |
if value is None: |
|
2873 |
value = "" |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
2874 |
values.append("%s(%s)" % (repetition, value)) |
814 | 2875 |
else: |
2876 |
values.append(element.getvalue()) |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
2877 |
return "[%s]" % ", ".join(values) |
814 | 2878 |
setattr(cls, "getvalue", getvalue) |
2879 |
||
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2880 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2881 |
cls = PLCOpenParser.GetElementClass("arrayValue", "value") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2882 |
if cls: |
2439
f0a040f1de1b
Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2437
diff
changeset
|
2883 |
arrayValue_model = re.compile(r"([0-9]+)\((.*)\)$") |
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2884 |
_updateArrayValueValueClass(cls) |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2885 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2886 |
# ---------------------------------------------------------------------- |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2887 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2888 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2889 |
def _updateStructValueValueClass(cls): |
814 | 2890 |
def setvalue(self, value): |
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2891 |
elements = [] |
814 | 2892 |
for item in extractValues(value[1:-1]): |
2893 |
result = structValue_model.match(item) |
|
2894 |
if result is not None: |
|
2895 |
groups = result.groups() |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2896 |
element = PLCOpenParser.CreateElement("value", "structValue") |
814 | 2897 |
element.setmember(groups[0].strip()) |
2898 |
element.setvalue(groups[1].strip()) |
|
1290
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2899 |
elements.append(element) |
13ee5f4ab612
First stage of xmlclass refactoring using lxml
Laurent Bessard
parents:
1285
diff
changeset
|
2900 |
self.value = elements |
814 | 2901 |
setattr(cls, "setvalue", setvalue) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1695
diff
changeset
|
2902 |
|
814 | 2903 |
def getvalue(self): |
2904 |
values = [] |
|
2905 |
for element in self.value: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
2906 |
values.append("%s := %s" % (element.getmember(), element.getvalue())) |
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
2907 |
return "(%s)" % ", ".join(values) |
814 | 2908 |
setattr(cls, "getvalue", getvalue) |
1840
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2909 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2910 |
|
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2911 |
cls = PLCOpenParser.GetElementClass("structValue", "value") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2912 |
if cls: |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2913 |
structValue_model = re.compile("(.*):=(.*)") |
cf5ef4c0deff
fix pylint error '(function-redefined) method already defined'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1837
diff
changeset
|
2914 |
_updateStructValueValueClass(cls) |