author | laurent |
Tue, 27 Mar 2012 23:50:19 +0200 | |
changeset 658 | 89d20745b061 |
parent 633 | 3536f4469cde |
child 687 | 629680fb0582 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
2 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
2 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
2 | 25 |
from xmlclass import * |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
26 |
from structures import * |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
27 |
from types import * |
166 | 28 |
import os, re |
0 | 29 |
|
30 |
""" |
|
31 |
Dictionary that makes the relation between var names in plcopen and displayed values |
|
32 |
""" |
|
33 |
VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars", |
|
34 |
"Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars", |
|
35 |
"Global" : "globalVars", "Access" : "accessVars"} |
|
36 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
37 |
searchResultVarTypes = { |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
38 |
"inputVars": "var_input", |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
39 |
"outputVars": "var_output", |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
40 |
"inOutVars": "var_inout" |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
41 |
} |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
42 |
|
0 | 43 |
""" |
44 |
Define in which order var types must be displayed |
|
45 |
""" |
|
46 |
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"] |
|
47 |
||
48 |
""" |
|
49 |
Define which action qualifier must be associated with a duration |
|
50 |
""" |
|
51 |
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, |
|
52 |
"P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True} |
|
53 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
54 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
55 |
FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)" |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
56 |
|
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
57 |
def update_address(address, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
58 |
result = address_model.match(address) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
59 |
if result is None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
60 |
return address |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
61 |
groups = result.groups() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
62 |
return groups[0] + new_leading + groups[2] |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
63 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
64 |
def _init_and_compare(function, v1, v2): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
65 |
if v1 is None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
66 |
return v2 |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
67 |
if v2 is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
68 |
return function(v1, v2) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
69 |
return v1 |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
70 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
71 |
""" |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
72 |
Helper class for bounding_box calculation |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
73 |
""" |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
74 |
class rect: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
75 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
76 |
def __init__(self, x=None, y=None, width=None, height=None): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
77 |
self.x_min = x |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
78 |
self.x_max = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
79 |
self.y_min = y |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
80 |
self.y_max = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
81 |
if width is not None and x is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
82 |
self.x_max = x + width |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
83 |
if height is not None and y is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
84 |
self.y_max = y + height |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
85 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
86 |
def update(self, x, y): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
87 |
self.x_min = _init_and_compare(min, self.x_min, x) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
88 |
self.x_max = _init_and_compare(max, self.x_max, x) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
89 |
self.y_min = _init_and_compare(min, self.y_min, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
90 |
self.y_max = _init_and_compare(max, self.y_max, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
91 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
92 |
def union(self, rect): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
93 |
self.x_min = _init_and_compare(min, self.x_min, rect.x_min) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
94 |
self.x_max = _init_and_compare(max, self.x_max, rect.x_max) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
95 |
self.y_min = _init_and_compare(min, self.y_min, rect.y_min) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
96 |
self.y_max = _init_and_compare(max, self.y_max, rect.y_max) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
97 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
98 |
def bounding_box(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
99 |
width = height = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
100 |
if self.x_min is not None and self.x_max is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
101 |
width = self.x_max - self.x_min |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
102 |
if self.y_min is not None and self.y_max is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
103 |
height = self.y_max - self.y_min |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
104 |
return self.x_min, self.y_min, width, height |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
105 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
106 |
def TextLenInRowColumn(text): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
107 |
if text == "": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
108 |
return (0, 0) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
109 |
lines = text.split("\n") |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
110 |
return len(lines) - 1, len(lines[-1]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
111 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
112 |
def TestTextElement(text, criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
113 |
lines = text.splitlines() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
114 |
if not criteria["case_sensitive"]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
115 |
text = text.upper() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
116 |
test_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
117 |
result = criteria["pattern"].search(text) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
118 |
while result is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
119 |
start = TextLenInRowColumn(text[:result.start()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
120 |
end = TextLenInRowColumn(text[:result.end() - 1]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
121 |
test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1]))) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
122 |
result = criteria["pattern"].search(text, result.end()) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
123 |
return test_result |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
124 |
|
389 | 125 |
PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
2 | 126 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
127 |
ElementNameToClass = {} |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
128 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
129 |
cls = PLCOpenClasses.get("formattedText", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
130 |
if cls: |
58 | 131 |
def updateElementName(self, old_name, new_name): |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
132 |
text = self.text.decode("utf-8") |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
133 |
index = text.find(old_name) |
58 | 134 |
while index != -1: |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
135 |
if index > 0 and (text[index - 1].isalnum() or text[index - 1] == "_"): |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
136 |
index = text.find(old_name, index + len(old_name)) |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
137 |
elif index < len(text) - len(old_name) and (text[index + len(old_name)].isalnum() or text[index + len(old_name)] == "_"): |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
138 |
index = text.find(old_name, index + len(old_name)) |
58 | 139 |
else: |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
140 |
text = text[:index] + new_name + text[index + len(old_name):] |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
141 |
index = text.find(old_name, index + len(new_name)) |
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
142 |
self.text = text.encode("utf-8") |
58 | 143 |
setattr(cls, "updateElementName", updateElementName) |
144 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
145 |
def updateElementAddress(self, address_model, new_leading): |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
146 |
text = self.text.decode("utf-8") |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
147 |
startpos = 0 |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
148 |
result = address_model.search(text, startpos) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
149 |
while result is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
150 |
groups = result.groups() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
151 |
new_address = groups[0] + new_leading + groups[2] |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
152 |
text = text[:result.start()] + new_address + text[result.end():] |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
153 |
startpos = result.start() + len(new_address) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
154 |
result = address_model.search(self.text, startpos) |
594
41e62b3174dc
Fixing bug when updating name of project elements in utf-8 formatted text
laurent
parents:
590
diff
changeset
|
155 |
self.text = text.encode("utf-8") |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
156 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
157 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
158 |
def Search(self, criteria, parent_infos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
159 |
return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
160 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
161 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
162 |
cls = PLCOpenClasses.get("project", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
163 |
if cls: |
2 | 164 |
cls.singleLineAttributes = False |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
165 |
cls.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
166 |
cls.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
167 |
cls.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
168 |
cls.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
169 |
cls.CustomBlockTypes = [] |
2 | 170 |
|
151 | 171 |
def setname(self, name): |
172 |
self.contentHeader.setname(name) |
|
173 |
setattr(cls, "setname", setname) |
|
145 | 174 |
|
151 | 175 |
def getname(self): |
176 |
return self.contentHeader.getname() |
|
177 |
setattr(cls, "getname", getname) |
|
178 |
||
179 |
def getfileHeader(self): |
|
2 | 180 |
fileheader = {} |
151 | 181 |
fileheader["companyName"] = self.fileHeader.getcompanyName() |
182 |
if self.fileHeader.getcompanyURL(): |
|
183 |
fileheader["companyURL"] = self.fileHeader.getcompanyURL() |
|
184 |
fileheader["productName"] = self.fileHeader.getproductName() |
|
185 |
fileheader["productVersion"] = self.fileHeader.getproductVersion() |
|
186 |
if self.fileHeader.getproductRelease(): |
|
187 |
fileheader["productRelease"] = self.fileHeader.getproductRelease() |
|
188 |
fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime() |
|
189 |
if self.fileHeader.getcontentDescription(): |
|
190 |
fileheader["contentDescription"] = self.fileHeader.getcontentDescription() |
|
2 | 191 |
return fileheader |
151 | 192 |
setattr(cls, "getfileHeader", getfileHeader) |
193 |
||
194 |
def setfileHeader(self, fileheader): |
|
195 |
self.fileHeader.setcompanyName(fileheader["companyName"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
196 |
if fileheader.has_key("companyURL"): |
151 | 197 |
self.fileHeader.setcompanyURL(fileheader["companyURL"]) |
198 |
self.fileHeader.setproductName(fileheader["productName"]) |
|
199 |
self.fileHeader.setproductVersion(fileheader["productVersion"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
200 |
if fileheader.has_key("productRelease"): |
151 | 201 |
self.fileHeader.setproductRelease(fileheader["productRelease"]) |
202 |
self.fileHeader.setcreationDateTime(fileheader["creationDateTime"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
203 |
if fileheader.has_key("contentDescription"): |
151 | 204 |
self.fileHeader.setcontentDescription(fileheader["contentDescription"]) |
205 |
setattr(cls, "setfileHeader", setfileHeader) |
|
206 |
||
207 |
def getcontentHeader(self): |
|
145 | 208 |
contentheader = {} |
151 | 209 |
contentheader["projectName"] = self.contentHeader.getname() |
210 |
if self.contentHeader.getversion(): |
|
211 |
contentheader["projectVersion"] = self.contentHeader.getversion() |
|
212 |
if self.contentHeader.getmodificationDateTime(): |
|
213 |
contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime() |
|
214 |
if self.contentHeader.getorganization(): |
|
215 |
contentheader["organization"] = self.contentHeader.getorganization() |
|
216 |
if self.contentHeader.getauthor(): |
|
217 |
contentheader["authorName"] = self.contentHeader.getauthor() |
|
218 |
if self.contentHeader.getlanguage(): |
|
219 |
contentheader["language"] = self.contentHeader.getlanguage() |
|
220 |
contentheader["pageSize"] = self.contentHeader.getpageSize() |
|
221 |
contentheader["scaling"] = self.contentHeader.getscaling() |
|
145 | 222 |
return contentheader |
151 | 223 |
setattr(cls, "getcontentHeader", getcontentHeader) |
224 |
||
225 |
def setcontentHeader(self, contentheader): |
|
226 |
self.contentHeader.setname(contentheader["projectName"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
227 |
if contentheader.has_key("projectVersion"): |
151 | 228 |
self.contentHeader.setversion(contentheader["projectVersion"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
229 |
if contentheader.has_key("modificationDateTime"): |
151 | 230 |
self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
231 |
if contentheader.has_key("organization"): |
151 | 232 |
self.contentHeader.setorganization(contentheader["organization"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
233 |
if contentheader.has_key("authorName"): |
151 | 234 |
self.contentHeader.setauthor(contentheader["authorName"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
235 |
if contentheader.has_key("language"): |
151 | 236 |
self.contentHeader.setlanguage(contentheader["language"]) |
237 |
self.contentHeader.setpageSize(*contentheader["pageSize"]) |
|
238 |
self.contentHeader.setscaling(contentheader["scaling"]) |
|
239 |
setattr(cls, "setcontentHeader", setcontentHeader) |
|
240 |
||
241 |
def getdataTypes(self): |
|
242 |
return self.types.getdataTypeElements() |
|
243 |
setattr(cls, "getdataTypes", getdataTypes) |
|
244 |
||
245 |
def getdataType(self, name): |
|
246 |
return self.types.getdataTypeElement(name) |
|
247 |
setattr(cls, "getdataType", getdataType) |
|
248 |
||
249 |
def appenddataType(self, name): |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
250 |
if self.CustomTypeHierarchy.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
251 |
raise ValueError, "\"%s\" Data Type already exists !!!"%name |
151 | 252 |
self.types.appenddataTypeElement(name) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
253 |
self.AddCustomDataType(self.getdataType(name)) |
151 | 254 |
setattr(cls, "appenddataType", appenddataType) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
255 |
|
151 | 256 |
def insertdataType(self, index, datatype): |
257 |
self.types.insertdataTypeElement(index, datatype) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
258 |
self.AddCustomDataType(datatype) |
151 | 259 |
setattr(cls, "insertdataType", insertdataType) |
260 |
||
261 |
def removedataType(self, name): |
|
262 |
self.types.removedataTypeElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
263 |
self.RefreshDataTypeHierarchy() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
264 |
self.RefreshElementUsingTree() |
151 | 265 |
setattr(cls, "removedataType", removedataType) |
266 |
||
267 |
def getpous(self): |
|
268 |
return self.types.getpouElements() |
|
269 |
setattr(cls, "getpous", getpous) |
|
270 |
||
271 |
def getpou(self, name): |
|
272 |
return self.types.getpouElement(name) |
|
273 |
setattr(cls, "getpou", getpou) |
|
274 |
||
275 |
def appendpou(self, name, pou_type, body_type): |
|
276 |
self.types.appendpouElement(name, pou_type, body_type) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
277 |
self.AddCustomBlockType(self.getpou(name)) |
151 | 278 |
setattr(cls, "appendpou", appendpou) |
0 | 279 |
|
151 | 280 |
def insertpou(self, index, pou): |
281 |
self.types.insertpouElement(index, pou) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
282 |
self.AddCustomBlockType(pou) |
151 | 283 |
setattr(cls, "insertpou", insertpou) |
284 |
||
285 |
def removepou(self, name): |
|
286 |
self.types.removepouElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
287 |
self.RefreshCustomBlockTypes() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
288 |
self.RefreshElementUsingTree() |
151 | 289 |
setattr(cls, "removepou", removepou) |
290 |
||
291 |
def getconfigurations(self): |
|
292 |
configurations = self.instances.configurations.getconfiguration() |
|
2 | 293 |
if configurations: |
294 |
return configurations |
|
295 |
return [] |
|
151 | 296 |
setattr(cls, "getconfigurations", getconfigurations) |
297 |
||
298 |
def getconfiguration(self, name): |
|
299 |
for configuration in self.instances.configurations.getconfiguration(): |
|
300 |
if configuration.getname() == name: |
|
2 | 301 |
return configuration |
302 |
return None |
|
151 | 303 |
setattr(cls, "getconfiguration", getconfiguration) |
304 |
||
305 |
def addconfiguration(self, name): |
|
306 |
for configuration in self.instances.configurations.getconfiguration(): |
|
307 |
if configuration.getname() == name: |
|
391 | 308 |
raise ValueError, _("\"%s\" configuration already exists !!!")%name |
2 | 309 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
151 | 310 |
new_configuration.setname(name) |
311 |
self.instances.configurations.appendconfiguration(new_configuration) |
|
312 |
setattr(cls, "addconfiguration", addconfiguration) |
|
313 |
||
314 |
def removeconfiguration(self, name): |
|
2 | 315 |
found = False |
151 | 316 |
for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
317 |
if configuration.getname() == name: |
|
318 |
self.instances.configurations.removeconfiguration(idx) |
|
2 | 319 |
found = True |
320 |
break |
|
321 |
if not found: |
|
391 | 322 |
raise ValueError, ("\"%s\" configuration doesn't exist !!!")%name |
151 | 323 |
setattr(cls, "removeconfiguration", removeconfiguration) |
324 |
||
325 |
def getconfigurationResource(self, config_name, name): |
|
326 |
configuration = self.getconfiguration(config_name) |
|
2 | 327 |
if configuration: |
151 | 328 |
for resource in configuration.getresource(): |
329 |
if resource.getname() == name: |
|
2 | 330 |
return resource |
331 |
return None |
|
151 | 332 |
setattr(cls, "getconfigurationResource", getconfigurationResource) |
333 |
||
334 |
def addconfigurationResource(self, config_name, name): |
|
335 |
configuration = self.getconfiguration(config_name) |
|
2 | 336 |
if configuration: |
151 | 337 |
for resource in configuration.getresource(): |
338 |
if resource.getname() == name: |
|
391 | 339 |
raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!")%(name, config_name) |
2 | 340 |
new_resource = PLCOpenClasses["configuration_resource"]() |
151 | 341 |
new_resource.setname(name) |
342 |
configuration.appendresource(new_resource) |
|
343 |
setattr(cls, "addconfigurationResource", addconfigurationResource) |
|
344 |
||
345 |
def removeconfigurationResource(self, config_name, name): |
|
346 |
configuration = self.getconfiguration(config_name) |
|
2 | 347 |
if configuration: |
0 | 348 |
found = False |
151 | 349 |
for idx, resource in enumerate(configuration.getresource()): |
350 |
if resource.getname() == name: |
|
351 |
configuration.removeresource(idx) |
|
0 | 352 |
found = True |
353 |
break |
|
354 |
if not found: |
|
391 | 355 |
raise ValueError, _("\"%s\" resource doesn't exist in \"%s\" configuration !!!")%(name, config_name) |
151 | 356 |
setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
357 |
||
358 |
def updateElementName(self, old_name, new_name): |
|
348
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
359 |
for datatype in self.types.getdataTypeElements(): |
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
360 |
datatype.updateElementName(old_name, new_name) |
151 | 361 |
for pou in self.types.getpouElements(): |
58 | 362 |
pou.updateElementName(old_name, new_name) |
151 | 363 |
for configuration in self.instances.configurations.getconfiguration(): |
58 | 364 |
configuration.updateElementName(old_name, new_name) |
365 |
setattr(cls, "updateElementName", updateElementName) |
|
366 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
367 |
def updateElementAddress(self, old_leading, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
368 |
address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
369 |
for pou in self.types.getpouElements(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
370 |
pou.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
371 |
for configuration in self.instances.configurations.getconfiguration(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
372 |
configuration.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
373 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
374 |
|
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
375 |
def removeVariableByAddress(self, address): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
376 |
for pou in self.types.getpouElements(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
377 |
pou.removeVariableByAddress(address) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
378 |
for configuration in self.instances.configurations.getconfiguration(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
379 |
configuration.removeVariableByAddress(address) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
380 |
setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
381 |
|
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
382 |
def removeVariableByFilter(self, leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
383 |
address_model = re.compile(FILTER_ADDRESS_MODEL % leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
384 |
for pou in self.types.getpouElements(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
385 |
pou.removeVariableByFilter(address_model) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
386 |
for configuration in self.instances.configurations.getconfiguration(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
387 |
configuration.removeVariableByFilter(address_model) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
388 |
setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
389 |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
390 |
def RefreshDataTypeHierarchy(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
391 |
self.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
392 |
self.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
393 |
self.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
394 |
for datatype in self.getdataTypes(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
395 |
self.AddCustomDataType(datatype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
396 |
setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
397 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
398 |
def AddCustomDataType(self, datatype): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
399 |
name = datatype.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
400 |
basetype_content = datatype.getbaseType().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
401 |
if basetype_content["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
402 |
self.CustomTypeHierarchy[name] = basetype_content["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
403 |
elif basetype_content["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
404 |
self.CustomTypeHierarchy[name] = basetype_content["name"].upper() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
405 |
elif basetype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
406 |
self.CustomTypeHierarchy[name] = basetype_content["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
407 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
408 |
range = (basetype_content["value"].range.getlower(), |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
409 |
basetype_content["value"].range.getupper()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
410 |
self.CustomDataTypeRange[name] = range |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
411 |
base_type = basetype_content["value"].baseType.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
412 |
if base_type["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
413 |
self.CustomTypeHierarchy[name] = base_type["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
414 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
415 |
self.CustomTypeHierarchy[name] = base_type["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
416 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
417 |
if basetype_content["name"] == "enum": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
418 |
values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
419 |
for value in basetype_content["value"].values.getvalue(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
420 |
values.append(value.getname()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
421 |
self.EnumeratedDataTypeValues[name] = values |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
422 |
self.CustomTypeHierarchy[name] = "ANY_DERIVED" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
423 |
setattr(cls, "AddCustomDataType", AddCustomDataType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
424 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
425 |
# Update Block types with user-defined pou added |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
426 |
def RefreshCustomBlockTypes(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
427 |
# Reset the tree of user-defined pou cross-use |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
428 |
self.CustomBlockTypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
429 |
for pou in self.getpous(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
430 |
self.AddCustomBlockType(pou) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
431 |
setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
432 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
433 |
def AddCustomBlockType(self, pou): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
434 |
pou_name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
435 |
pou_type = pou.getpouType() |
286 | 436 |
block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
633
3536f4469cde
Fixing ToolTip behavior and bug with INOUT interface variables in Function Blocks and adding support for display connection point between wire and connector when mouse passing over.
laurent
parents:
630
diff
changeset
|
437 |
"inputs" : [], "outputs" : [], "comment" : pou.getdescription(), |
286 | 438 |
"generate" : generate_block, "initialise" : initialise_block} |
439 |
if pou.getinterface(): |
|
440 |
return_type = pou.interface.getreturnType() |
|
441 |
if return_type: |
|
442 |
var_type = return_type.getcontent() |
|
443 |
if var_type["name"] == "derived": |
|
444 |
block_infos["outputs"].append(("", var_type["value"].getname(), "none")) |
|
445 |
elif var_type["name"] in ["string", "wstring"]: |
|
446 |
block_infos["outputs"].append(("", var_type["name"].upper(), "none")) |
|
447 |
else: |
|
448 |
block_infos["outputs"].append(("", var_type["name"], "none")) |
|
449 |
for type, varlist in pou.getvars(): |
|
450 |
if type == "InOut": |
|
451 |
for var in varlist.getvariable(): |
|
452 |
var_type = var.type.getcontent() |
|
453 |
if var_type["name"] == "derived": |
|
454 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
455 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
456 |
elif var_type["name"] in ["string", "wstring"]: |
|
457 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
458 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
459 |
else: |
|
460 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
461 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
462 |
elif type == "Input": |
|
463 |
for var in varlist.getvariable(): |
|
464 |
var_type = var.type.getcontent() |
|
465 |
if var_type["name"] == "derived": |
|
466 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
467 |
elif var_type["name"] in ["string", "wstring"]: |
|
468 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
469 |
else: |
|
470 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
471 |
elif type == "Output": |
|
472 |
for var in varlist.getvariable(): |
|
473 |
var_type = var.type.getcontent() |
|
474 |
if var_type["name"] == "derived": |
|
475 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
476 |
elif var_type["name"] in ["string", "wstring"]: |
|
477 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
478 |
else: |
|
479 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
625
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
480 |
block_infos["usage"] = "\n (%s) => (%s)" % (", ".join(["%s:%s" % (input[1], input[0]) for input in block_infos["inputs"]]), |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
481 |
", ".join(["%s:%s" % (output[1], output[0]) for output in block_infos["outputs"]])) |
286 | 482 |
self.CustomBlockTypes.append(block_infos) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
483 |
setattr(cls, "AddCustomBlockType", AddCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
484 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
485 |
def RefreshElementUsingTree(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
486 |
# Reset the tree of user-defined element cross-use |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
487 |
self.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
488 |
pous = self.getpous() |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
489 |
datatypes = self.getdataTypes() |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
490 |
# Reference all the user-defined elementu names and initialize the tree of |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
491 |
# user-defined elemnt cross-use |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
492 |
elementnames = [datatype.getname() for datatype in datatypes] + \ |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
493 |
[pou.getname() for pou in pous] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
494 |
for name in elementnames: |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
495 |
self.ElementUsingTree[name] = [] |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
496 |
# Analyze each datatype |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
497 |
for datatype in datatypes: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
498 |
name = datatype.getname() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
499 |
basetype_content = datatype.baseType.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
500 |
if basetype_content["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
501 |
typename = basetype_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
502 |
if name in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
503 |
self.ElementUsingTree[typename].append(name) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
504 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
505 |
base_type = basetype_content["value"].baseType.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
506 |
if base_type["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
507 |
typename = base_type["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
508 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
509 |
self.ElementUsingTree[typename].append(name) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
510 |
elif basetype_content["name"] == "struct": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
511 |
for element in basetype_content["value"].getvariable(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
512 |
type_content = element.type.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
513 |
if type_content["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
514 |
typename = type_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
515 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
516 |
self.ElementUsingTree[typename].append(name) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
517 |
# Analyze each pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
518 |
for pou in pous: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
519 |
name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
520 |
if pou.interface: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
521 |
# Extract variables from every varLists |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
522 |
for type, varlist in pou.getvars(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
523 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
524 |
vartype_content = var.gettype().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
525 |
if vartype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
526 |
typename = vartype_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
527 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
528 |
self.ElementUsingTree[typename].append(name) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
529 |
setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
530 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
531 |
def GetParentType(self, type): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
532 |
if self.CustomTypeHierarchy.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
533 |
return self.CustomTypeHierarchy[type] |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
534 |
elif TypeHierarchy.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
535 |
return TypeHierarchy[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
536 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
537 |
setattr(cls, "GetParentType", GetParentType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
538 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
539 |
def GetBaseType(self, type): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
540 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
541 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
542 |
if parent_type.startswith("ANY"): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
543 |
return type |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
544 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
545 |
return self.GetBaseType(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
546 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
547 |
setattr(cls, "GetBaseType", GetBaseType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
548 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
549 |
def GetSubrangeBaseTypes(self, exclude): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
550 |
derived = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
551 |
for type in self.CustomTypeHierarchy.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
552 |
for base_type in DataTypeRange.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
553 |
if self.IsOfType(type, base_type) and not self.IsOfType(type, exclude): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
554 |
derived.append(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
555 |
break |
630
9d7e38e271cb
Adding support for loading datatypes defined in plugins to allow to use them in PLC program
laurent
parents:
625
diff
changeset
|
556 |
return derived |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
557 |
setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
558 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
559 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
560 |
returns true if the given data type is the same that "reference" meta-type or one of its types. |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
561 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
562 |
def IsOfType(self, type, reference): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
563 |
if reference is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
564 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
565 |
elif type == reference: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
566 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
567 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
568 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
569 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
570 |
return self.IsOfType(parent_type, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
571 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
572 |
setattr(cls, "IsOfType", IsOfType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
573 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
574 |
# Return if pou given by name is used by another pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
575 |
def ElementIsUsed(self, name): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
576 |
if self.ElementUsingTree.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
577 |
return len(self.ElementUsingTree[name]) > 0 |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
578 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
579 |
setattr(cls, "ElementIsUsed", ElementIsUsed) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
580 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
581 |
def DataTypeIsDerived(self, name): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
582 |
return name in self.CustomTypeHierarchy.values() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
583 |
setattr(cls, "DataTypeIsDerived", DataTypeIsDerived) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
584 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
585 |
# Return if pou given by name is directly or undirectly used by the reference pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
586 |
def ElementIsUsedBy(self, name, reference): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
587 |
if self.ElementUsingTree.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
588 |
list = self.ElementUsingTree[name] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
589 |
# Test if pou is directly used by reference |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
590 |
if reference in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
591 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
592 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
593 |
# Test if pou is undirectly used by reference, by testing if pous |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
594 |
# that directly use pou is directly or undirectly used by reference |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
595 |
used = False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
596 |
for element in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
597 |
used |= self.ElementIsUsedBy(element, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
598 |
return used |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
599 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
600 |
setattr(cls, "ElementIsUsedBy", ElementIsUsedBy) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
601 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
602 |
def GetDataTypeRange(self, type): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
603 |
if self.CustomDataTypeRange.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
604 |
return self.CustomDataTypeRange[type] |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
605 |
elif DataTypeRange.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
606 |
return DataTypeRange[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
607 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
608 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
609 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
610 |
return self.GetDataTypeRange(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
611 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
612 |
setattr(cls, "GetDataTypeRange", GetDataTypeRange) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
613 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
614 |
def GetEnumeratedDataTypeValues(self, type = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
615 |
if type is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
616 |
all_values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
617 |
for values in self.EnumeratedDataTypeValues.values(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
618 |
all_values.extend(values) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
619 |
return all_values |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
620 |
elif self.EnumeratedDataTypeValues.has_key(type): |
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
621 |
return self.EnumeratedDataTypeValues[type] |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
622 |
return [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
623 |
setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
624 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
625 |
# Function that returns the block definition associated to the block type given |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
626 |
def GetCustomBlockType(self, type, inputs = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
627 |
for customblocktype in self.CustomBlockTypes: |
539
8dbb1de154c1
Fix bug when compiling pou including user-defined blocks with unconnected input
laurent
parents:
491
diff
changeset
|
628 |
if inputs is not None and inputs != "undefined": |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
629 |
customblock_inputs = tuple([var_type for name, var_type, modifier in customblocktype["inputs"]]) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
630 |
same_inputs = inputs == customblock_inputs |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
631 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
632 |
same_inputs = True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
633 |
if customblocktype["name"] == type and same_inputs: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
634 |
return customblocktype |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
635 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
636 |
setattr(cls, "GetCustomBlockType", GetCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
637 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
638 |
# Return Block types checking for recursion |
251
cc5377a296ea
Fix bug in popup menu and function block types in Variable Panel
lbessard
parents:
246
diff
changeset
|
639 |
def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False): |
238
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
640 |
type = None |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
641 |
if exclude != "": |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
642 |
pou = self.getpou(exclude) |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
643 |
if pou is not None: |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
644 |
type = pou.getpouType() |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
645 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
646 |
for customblocktype in self.CustomBlockTypes: |
286 | 647 |
if customblocktype["type"] != "program" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
648 |
customblocktypes.append(customblocktype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
649 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
650 |
setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
651 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
652 |
# Return Function Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
653 |
def GetCustomFunctionBlockTypes(self, exclude = ""): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
654 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
655 |
for customblocktype in self.CustomBlockTypes: |
286 | 656 |
if customblocktype["type"] == "functionBlock" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]): |
246
9cf9694e8d66
Bug with GetCustomFunctionBlockTypes without exclusion POU fixed
lbessard
parents:
238
diff
changeset
|
657 |
customblocktypes.append(customblocktype["name"]) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
658 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
659 |
setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
660 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
661 |
# Return Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
662 |
def GetCustomBlockResource(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
663 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
664 |
for customblocktype in self.CustomBlockTypes: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
665 |
if customblocktype["type"] == "program": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
666 |
customblocktypes.append(customblocktype["name"]) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
667 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
668 |
setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
669 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
670 |
# Return Data Types checking for recursion |
552
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
671 |
def GetCustomDataTypes(self, exclude = "", only_locatable = False): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
672 |
customdatatypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
673 |
for customdatatype in self.getdataTypes(): |
552
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
674 |
if not only_locatable or self.IsLocatableType(customdatatype): |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
675 |
customdatatype_name = customdatatype.getname() |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
676 |
if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name): |
630
9d7e38e271cb
Adding support for loading datatypes defined in plugins to allow to use them in PLC program
laurent
parents:
625
diff
changeset
|
677 |
customdatatypes.append({"name": customdatatype_name, "infos": customdatatype}) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
678 |
return customdatatypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
679 |
setattr(cls, "GetCustomDataTypes", GetCustomDataTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
680 |
|
552
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
681 |
# Return if Data Type can be used for located variables |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
682 |
def IsLocatableType(self, datatype): |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
683 |
basetype_content = datatype.baseType.getcontent() |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
684 |
if basetype_content["name"] in ["enum", "struct"]: |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
685 |
return False |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
686 |
elif basetype_content["name"] == "derived": |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
687 |
base_type = self.getdataType(basetype_content["value"].getname()) |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
688 |
if base_type is not None: |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
689 |
return self.IsLocatableType(base_type) |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
690 |
elif basetype_content["name"] == "array": |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
691 |
array_base_type = basetype_content["value"].baseType.getcontent() |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
692 |
if array_base_type["value"] is not None and array_base_type["name"] not in ["string", "wstring"]: |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
693 |
base_type = self.getdataType(array_base_type["value"].getname()) |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
694 |
if base_type is not None: |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
695 |
return self.IsLocatableType(base_type) |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
696 |
return True |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
697 |
setattr(cls, "IsLocatableType", IsLocatableType) |
a387f258814a
Disabling location definition for enumerated and structure variables
laurent
parents:
550
diff
changeset
|
698 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
699 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
700 |
result = self.types.Search(criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
701 |
for configuration in self.instances.configurations.getconfiguration(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
702 |
result.extend(configuration.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
703 |
return result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
704 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
705 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
706 |
cls = PLCOpenClasses.get("project_fileHeader", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
707 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
708 |
cls.singleLineAttributes = False |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
709 |
|
145 | 710 |
cls = PLCOpenClasses.get("project_contentHeader", None) |
711 |
if cls: |
|
712 |
cls.singleLineAttributes = False |
|
713 |
||
151 | 714 |
def setpageSize(self, width, height): |
715 |
self.coordinateInfo.setpageSize(width, height) |
|
716 |
setattr(cls, "setpageSize", setpageSize) |
|
717 |
||
718 |
def getpageSize(self): |
|
719 |
return self.coordinateInfo.getpageSize() |
|
720 |
setattr(cls, "getpageSize", getpageSize) |
|
721 |
||
722 |
def setscaling(self, scaling): |
|
145 | 723 |
for language, (x, y) in scaling.items(): |
151 | 724 |
self.coordinateInfo.setscaling(language, x, y) |
725 |
setattr(cls, "setscaling", setscaling) |
|
726 |
||
727 |
def getscaling(self): |
|
145 | 728 |
scaling = {} |
151 | 729 |
scaling["FBD"] = self.coordinateInfo.getscaling("FBD") |
730 |
scaling["LD"] = self.coordinateInfo.getscaling("LD") |
|
731 |
scaling["SFC"] = self.coordinateInfo.getscaling("SFC") |
|
145 | 732 |
return scaling |
151 | 733 |
setattr(cls, "getscaling", getscaling) |
145 | 734 |
|
735 |
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None) |
|
736 |
if cls: |
|
151 | 737 |
def setpageSize(self, width, height): |
145 | 738 |
if width == 0 and height == 0: |
151 | 739 |
self.deletepageSize() |
145 | 740 |
else: |
741 |
if self.pageSize is None: |
|
151 | 742 |
self.addpageSize() |
743 |
self.pageSize.setx(width) |
|
744 |
self.pageSize.sety(height) |
|
745 |
setattr(cls, "setpageSize", setpageSize) |
|
746 |
||
747 |
def getpageSize(self): |
|
145 | 748 |
if self.pageSize is not None: |
151 | 749 |
return self.pageSize.getx(), self.pageSize.gety() |
145 | 750 |
return 0, 0 |
151 | 751 |
setattr(cls, "getpageSize", getpageSize) |
752 |
||
753 |
def setscaling(self, language, x, y): |
|
145 | 754 |
if language == "FBD": |
151 | 755 |
self.fbd.scaling.setx(x) |
756 |
self.fbd.scaling.sety(y) |
|
145 | 757 |
elif language == "LD": |
151 | 758 |
self.ld.scaling.setx(x) |
759 |
self.ld.scaling.sety(y) |
|
145 | 760 |
elif language == "SFC": |
151 | 761 |
self.sfc.scaling.setx(x) |
762 |
self.sfc.scaling.sety(y) |
|
763 |
setattr(cls, "setscaling", setscaling) |
|
764 |
||
765 |
def getscaling(self, language): |
|
145 | 766 |
if language == "FBD": |
151 | 767 |
return self.fbd.scaling.getx(), self.fbd.scaling.gety() |
145 | 768 |
elif language == "LD": |
151 | 769 |
return self.ld.scaling.getx(), self.ld.scaling.gety() |
145 | 770 |
elif language == "SFC": |
151 | 771 |
return self.sfc.scaling.getx(), self.sfc.scaling.gety() |
145 | 772 |
return 0, 0 |
151 | 773 |
setattr(cls, "getscaling", getscaling) |
145 | 774 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
775 |
def _Search(attributes, criteria, parent_infos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
776 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
777 |
for attr, value in attributes: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
778 |
if value is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
779 |
search_result.extend([(tuple(parent_infos + [attr]),) + result for result in TestTextElement(value, criteria)]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
780 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
781 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
782 |
def _updateConfigurationResourceElementName(self, old_name, new_name): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
783 |
for varlist in self.getglobalVars(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
784 |
for var in varlist.getvariable(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
785 |
var_address = var.getaddress() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
786 |
if var_address is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
787 |
if var_address == old_name: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
788 |
var.setaddress(new_name) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
789 |
if var.getname() == old_name: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
790 |
var.setname(new_name) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
791 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
792 |
def _updateConfigurationResourceElementAddress(self, address_model, new_leading): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
793 |
for varlist in self.getglobalVars(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
794 |
for var in varlist.getvariable(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
795 |
var_address = var.getaddress() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
796 |
if var_address is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
797 |
var.setaddress(update_address(var_address, address_model, new_leading)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
798 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
799 |
def _removeConfigurationResourceVariableByAddress(self, address): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
800 |
for varlist in self.getglobalVars(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
801 |
variables = varlist.getvariable() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
802 |
for i in xrange(len(variables)-1, -1, -1): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
803 |
if variables[i].getaddress() == address: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
804 |
variables.pop(i) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
805 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
806 |
def _removeConfigurationResourceVariableByFilter(self, address_model): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
807 |
for varlist in self.getglobalVars(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
808 |
variables = varlist.getvariable() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
809 |
for i in xrange(len(variables)-1, -1, -1): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
810 |
var_address = variables[i].getaddress() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
811 |
if var_address is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
812 |
result = address_model.match(var_address) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
813 |
if result is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
814 |
variables.pop(i) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
815 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
816 |
def _SearchInConfigurationResource(self, criteria, parent_infos=[]): |
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
817 |
search_result = _Search([("name", self.getname())], criteria, parent_infos) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
818 |
var_number = 0 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
819 |
for varlist in self.getglobalVars(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
820 |
variable_type = searchResultVarTypes.get("globalVars", "var_local") |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
821 |
variables = varlist.getvariable() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
822 |
for modifier, has_modifier in [("constant", varlist.getconstant()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
823 |
("retain", varlist.getretain()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
824 |
("non_retain", varlist.getnonretain())]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
825 |
if has_modifier: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
826 |
for result in TestTextElement(modifier, criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
827 |
search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
828 |
break |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
829 |
for variable in variables: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
830 |
search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
831 |
var_number += 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
832 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
833 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
834 |
cls = PLCOpenClasses.get("configurations_configuration", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
835 |
if cls: |
58 | 836 |
def updateElementName(self, old_name, new_name): |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
837 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
151 | 838 |
for resource in self.getresource(): |
58 | 839 |
resource.updateElementName(old_name, new_name) |
840 |
setattr(cls, "updateElementName", updateElementName) |
|
841 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
842 |
def updateElementAddress(self, address_model, new_leading): |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
843 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
844 |
for resource in self.getresource(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
845 |
resource.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
846 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
847 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
848 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
849 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
850 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
851 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
852 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
853 |
parent_infos = parent_infos + ["C::%s" % self.getname()] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
854 |
filter = criteria["filter"] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
855 |
if filter == "all" or "configuration" in filter: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
856 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
857 |
for resource in self.getresource(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
858 |
search_result.extend(resource.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
859 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
860 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
861 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
862 |
cls = PLCOpenClasses.get("configuration_resource", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
863 |
if cls: |
58 | 864 |
def updateElementName(self, old_name, new_name): |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
865 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
187 | 866 |
for instance in self.getpouInstance(): |
58 | 867 |
instance.updateElementName(old_name, new_name) |
187 | 868 |
for task in self.gettask(): |
58 | 869 |
task.updateElementName(old_name, new_name) |
870 |
setattr(cls, "updateElementName", updateElementName) |
|
871 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
872 |
def updateElementAddress(self, address_model, new_leading): |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
873 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
874 |
for task in self.gettask(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
875 |
task.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
876 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
877 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
878 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
879 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
880 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
881 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
882 |
parent_infos = parent_infos[:-1] + ["R::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
883 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
884 |
task_number = 0 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
885 |
instance_number = 0 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
886 |
for task in self.gettask(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
887 |
results = TestTextElement(task.getname(), criteria) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
888 |
for result in results: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
889 |
search_result.append((tuple(parent_infos + ["task", task_number, "name"]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
890 |
search_result.extend(task.Search(criteria, parent_infos + ["task", task_number])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
891 |
task_number += 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
892 |
for instance in task.getpouInstance(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
893 |
search_result.extend(task.Search(criteria, parent_infos + ["instance", instance_number])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
894 |
for result in results: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
895 |
search_result.append((tuple(parent_infos + ["instance", instance_number, "task"]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
896 |
instance_number += 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
897 |
for instance in self.getpouInstance(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
898 |
search_result.extend(instance.Search(criteria, parent_infos + ["instance", instance_number])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
899 |
instance_number += 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
900 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
901 |
setattr(cls, "Search", Search) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
902 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
903 |
cls = PLCOpenClasses.get("resource_task", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
904 |
if cls: |
389 | 905 |
def compatibility(self, tree): |
906 |
if tree.hasAttribute("interval"): |
|
907 |
interval = GetAttributeValue(tree._attrs["interval"]) |
|
908 |
result = time_model.match(interval) |
|
909 |
if result is not None: |
|
910 |
values = result.groups() |
|
911 |
time_values = [int(v) for v in values[:2]] |
|
912 |
seconds = float(values[2]) |
|
913 |
time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
914 |
text = "t#" |
|
915 |
if time_values[0] != 0: |
|
916 |
text += "%dh"%time_values[0] |
|
917 |
if time_values[1] != 0: |
|
918 |
text += "%dm"%time_values[1] |
|
919 |
if time_values[2] != 0: |
|
920 |
text += "%ds"%time_values[2] |
|
921 |
if time_values[3] != 0: |
|
922 |
if time_values[3] % 1000 != 0: |
|
923 |
text += "%.3fms"%(float(time_values[3]) / 1000) |
|
924 |
else: |
|
925 |
text += "%dms"%(time_values[3] / 1000) |
|
926 |
NodeSetAttr(tree, "interval", text) |
|
927 |
setattr(cls, "compatibility", compatibility) |
|
928 |
||
58 | 929 |
def updateElementName(self, old_name, new_name): |
930 |
if self.single == old_name: |
|
931 |
self.single = new_name |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
932 |
if self.interval == old_name: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
933 |
self.interval = new_name |
187 | 934 |
for instance in self.getpouInstance(): |
58 | 935 |
instance.updateElementName(old_name, new_name) |
936 |
setattr(cls, "updateElementName", updateElementName) |
|
937 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
938 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
939 |
if self.single is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
940 |
self.single = update_address(self.single, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
941 |
if self.interval is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
942 |
self.interval = update_address(self.interval, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
943 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
944 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
945 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
946 |
return _Search([("single", self.getsingle()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
947 |
("interval", self.getinterval()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
948 |
("priority", str(self.getpriority()))], |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
949 |
criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
950 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
951 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
952 |
cls = PLCOpenClasses.get("pouInstance", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
953 |
if cls: |
389 | 954 |
def compatibility(self, tree): |
955 |
if tree.hasAttribute("type"): |
|
956 |
NodeRenameAttr(tree, "type", "typeName") |
|
957 |
setattr(cls, "compatibility", compatibility) |
|
958 |
||
58 | 959 |
def updateElementName(self, old_name, new_name): |
417
218142afdb53
fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents:
394
diff
changeset
|
960 |
if self.typeName == old_name: |
218142afdb53
fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents:
394
diff
changeset
|
961 |
self.typeName = new_name |
58 | 962 |
setattr(cls, "updateElementName", updateElementName) |
963 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
964 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
965 |
return _Search([("name", self.getname()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
966 |
("type", self.gettypeName())], |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
967 |
criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
968 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
969 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
970 |
cls = PLCOpenClasses.get("varListPlain_variable", None) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
971 |
if cls: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
972 |
def gettypeAsText(self): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
973 |
vartype_content = self.gettype().getcontent() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
974 |
# Variable type is a user data type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
975 |
if vartype_content["name"] == "derived": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
976 |
return vartype_content["value"].getname() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
977 |
# Variable type is a string type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
978 |
elif vartype_content["name"] in ["string", "wstring"]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
979 |
return vartype_content["name"].upper() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
980 |
# Variable type is an array |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
981 |
elif vartype_content["name"] == "array": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
982 |
base_type = vartype_content["value"].baseType.getcontent() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
983 |
# Array derived directly from a user defined type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
984 |
if base_type["name"] == "derived": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
985 |
basetype_name = base_type["value"].getname() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
986 |
# Array derived directly from a string type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
987 |
elif base_type["name"] in ["string", "wstring"]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
988 |
basetype_name = base_type["name"].upper() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
989 |
# Array derived directly from an elementary type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
990 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
991 |
basetype_name = base_type["name"] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
992 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "%s..%s" % (x.getlower(), x.getupper()), vartype_content["value"].getdimension())), basetype_name) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
993 |
# Variable type is an elementary type |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
994 |
return vartype_content["name"] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
995 |
setattr(cls, "gettypeAsText", gettypeAsText) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
996 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
997 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
998 |
search_result = _Search([("name", self.getname()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
999 |
("type", self.gettypeAsText()), |
617 | 1000 |
("location", self.getaddress())], |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1001 |
criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1002 |
initial = self.getinitialValue() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1003 |
if initial is not None: |
617 | 1004 |
search_result.extend(_Search([("initial value", initial.getvalue())], criteria, parent_infos)) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1005 |
doc = self.getdocumentation() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1006 |
if doc is not None: |
608
b67536e93c11
Fixing bug while searching into documentation element
laurent
parents:
594
diff
changeset
|
1007 |
search_result.extend(doc.Search(criteria, parent_infos + ["documentation"])) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1008 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1009 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1010 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1011 |
cls = PLCOpenClasses.get("project_types", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1012 |
if cls: |
151 | 1013 |
def getdataTypeElements(self): |
1014 |
return self.dataTypes.getdataType() |
|
1015 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
1016 |
||
1017 |
def getdataTypeElement(self, name): |
|
1018 |
elements = self.dataTypes.getdataType() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1019 |
for element in elements: |
151 | 1020 |
if element.getname() == name: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1021 |
return element |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1022 |
return None |
151 | 1023 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
1024 |
||
1025 |
def appenddataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1026 |
new_datatype = PLCOpenClasses["dataTypes_dataType"]() |
151 | 1027 |
new_datatype.setname(name) |
1028 |
new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None}) |
|
1029 |
self.dataTypes.appenddataType(new_datatype) |
|
1030 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
1031 |
|
151 | 1032 |
def insertdataTypeElement(self, index, dataType): |
1033 |
self.dataTypes.insertdataType(index, dataType) |
|
1034 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
1035 |
||
1036 |
def removedataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1037 |
found = False |
151 | 1038 |
for idx, element in enumerate(self.dataTypes.getdataType()): |
1039 |
if element.getname() == name: |
|
1040 |
self.dataTypes.removedataType(idx) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1041 |
found = True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1042 |
break |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1043 |
if not found: |
391 | 1044 |
raise ValueError, _("\"%s\" Data Type doesn't exist !!!")%name |
151 | 1045 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
1046 |
||
1047 |
def getpouElements(self): |
|
1048 |
return self.pous.getpou() |
|
1049 |
setattr(cls, "getpouElements", getpouElements) |
|
1050 |
||
1051 |
def getpouElement(self, name): |
|
1052 |
elements = self.pous.getpou() |
|
2 | 1053 |
for element in elements: |
151 | 1054 |
if element.getname() == name: |
2 | 1055 |
return element |
1056 |
return None |
|
151 | 1057 |
setattr(cls, "getpouElement", getpouElement) |
1058 |
||
1059 |
def appendpouElement(self, name, pou_type, body_type): |
|
1060 |
for element in self.pous.getpou(): |
|
1061 |
if element.getname() == name: |
|
391 | 1062 |
raise ValueError, _("\"%s\" POU already exists !!!")%name |
2 | 1063 |
new_pou = PLCOpenClasses["pous_pou"]() |
151 | 1064 |
new_pou.setname(name) |
1065 |
new_pou.setpouType(pou_type) |
|
389 | 1066 |
new_pou.appendbody(PLCOpenClasses["body"]()) |
151 | 1067 |
new_pou.setbodyType(body_type) |
1068 |
self.pous.appendpou(new_pou) |
|
1069 |
setattr(cls, "appendpouElement", appendpouElement) |
|
2 | 1070 |
|
151 | 1071 |
def insertpouElement(self, index, pou): |
1072 |
self.pous.insertpou(index, pou) |
|
1073 |
setattr(cls, "insertpouElement", insertpouElement) |
|
1074 |
||
1075 |
def removepouElement(self, name): |
|
2 | 1076 |
found = False |
151 | 1077 |
for idx, element in enumerate(self.pous.getpou()): |
1078 |
if element.getname() == name: |
|
1079 |
self.pous.removepou(idx) |
|
2 | 1080 |
found = True |
1081 |
break |
|
1082 |
if not found: |
|
391 | 1083 |
raise ValueError, _("\"%s\" POU doesn't exist !!!")%name |
151 | 1084 |
setattr(cls, "removepouElement", removepouElement) |
1085 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1086 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1087 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1088 |
filter = criteria["filter"] |
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1089 |
for datatype in self.dataTypes.getdataType(): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1090 |
search_result.extend(datatype.Search(criteria, parent_infos)) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1091 |
for pou in self.pous.getpou(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1092 |
search_result.extend(pou.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1093 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1094 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1095 |
|
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1096 |
def _updateBaseTypeElementName(self, old_name, new_name): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1097 |
self.baseType.updateElementName(old_name, new_name) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1098 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1099 |
cls = PLCOpenClasses.get("dataTypes_dataType", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1100 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1101 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1102 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1103 |
def Search(self, criteria, parent_infos=[]): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1104 |
search_result = [] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1105 |
filter = criteria["filter"] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1106 |
if filter == "all" or "datatype" in filter: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1107 |
parent_infos = parent_infos + ["D::%s" % self.getname()] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1108 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1109 |
search_result.extend(self.baseType.Search(criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1110 |
if self.initialValue is not None: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1111 |
search_result.extend(_Search([("initial", self.initialValue.getvalue())], criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1112 |
return search_result |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1113 |
setattr(cls, "Search", Search) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1114 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1115 |
cls = PLCOpenClasses.get("dataType", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1116 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1117 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1118 |
def updateElementName(self, old_name, new_name): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1119 |
if self.content["name"] in ["derived", "array", "subrangeSigned", "subrangeUnsigned"]: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1120 |
self.content["value"].updateElementName(old_name, new_name) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1121 |
elif self.content["name"] == "struct": |
590
b2442bb10c0b
Fixing bug when modifying the name of a derived data type
laurent
parents:
576
diff
changeset
|
1122 |
for element in self.content["value"].getvariable(): |
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1123 |
element_type = element.type.updateElementName(old_name, new_name) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1124 |
setattr(cls, "updateElementName", updateElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1125 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1126 |
def Search(self, criteria, parent_infos=[]): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1127 |
search_result = [] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1128 |
if self.content["name"] in ["derived", "array", "enum", "subrangeSigned", "subrangeUnsigned"]: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1129 |
search_result.extend(self.content["value"].Search(criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1130 |
elif self.content["name"] == "struct": |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1131 |
for i, element in enumerate(self.content["value"].getvariable()): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1132 |
search_result.extend(element.Search(criteria, parent_infos + ["struct", i])) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1133 |
else: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1134 |
basetype = self.content["name"] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1135 |
if basetype in ["string", "wstring"]: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1136 |
basetype = basetype.upper() |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1137 |
search_result.extend(_Search([("base", basetype)], criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1138 |
return search_result |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1139 |
setattr(cls, "Search", Search) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1140 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1141 |
cls = PLCOpenClasses.get("derivedTypes_array", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1142 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1143 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1144 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1145 |
def Search(self, criteria, parent_infos=[]): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1146 |
search_result = self.baseType.Search(criteria, parent_infos) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1147 |
for i, dimension in enumerate(self.getdimension()): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1148 |
search_result.extend(_Search([("lower", dimension.getlower()), |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1149 |
("upper", dimension.getupper())], |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1150 |
criteria, parent_infos + ["range", i])) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1151 |
return search_result |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1152 |
setattr(cls, "Search", Search) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1153 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1154 |
def _SearchInSubrange(self, criteria, parent_infos=[]): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1155 |
search_result = self.baseType.Search(criteria, parent_infos) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1156 |
search_result.extend(_Search([("lower", self.range.getlower()), |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1157 |
("upper", self.range.getupper())], |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1158 |
criteria, parent_infos)) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1159 |
return search_result |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1160 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1161 |
cls = PLCOpenClasses.get("derivedTypes_subrangeSigned", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1162 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1163 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1164 |
setattr(cls, "Search", _SearchInSubrange) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1165 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1166 |
cls = PLCOpenClasses.get("derivedTypes_subrangeUnsigned", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1167 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1168 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1169 |
setattr(cls, "Search", _SearchInSubrange) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1170 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1171 |
cls = PLCOpenClasses.get("derivedTypes_enum", None) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1172 |
if cls: |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1173 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1174 |
def updateElementName(self, old_name, new_name): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1175 |
pass |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1176 |
setattr(cls, "updateElementName", updateElementName) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1177 |
|
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1178 |
def Search(self, criteria, parent_infos=[]): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1179 |
search_result = [] |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1180 |
for i, value in enumerate(self.values.getvalue()): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1181 |
for result in TestTextElement(value.getname(), criteria): |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1182 |
search_result.append((tuple(parent_infos + ["value", i]),) + result) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1183 |
return search_result |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1184 |
setattr(cls, "Search", Search) |
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1185 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1186 |
cls = PLCOpenClasses.get("pous_pou", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1187 |
if cls: |
389 | 1188 |
|
625
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1189 |
def setdescription(self, description): |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1190 |
doc = self.getdocumentation() |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1191 |
if doc is None: |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1192 |
doc = PLCOpenClasses["formattedText"]() |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1193 |
self.setdocumentation(doc) |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1194 |
doc.settext(description) |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1195 |
setattr(cls, "setdescription", setdescription) |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1196 |
|
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1197 |
def getdescription(self): |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1198 |
doc = self.getdocumentation() |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1199 |
if doc is not None: |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1200 |
return doc.gettext() |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1201 |
return "" |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1202 |
setattr(cls, "getdescription", getdescription) |
b7062a7018ec
Adding support for defining a description for a user POU type, and displaying this information in library tree.
laurent
parents:
617
diff
changeset
|
1203 |
|
389 | 1204 |
def setbodyType(self, type): |
1205 |
if len(self.body) > 0: |
|
1206 |
if type == "IL": |
|
1207 |
self.body[0].setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
1208 |
elif type == "ST": |
|
1209 |
self.body[0].setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1210 |
elif type == "LD": |
|
1211 |
self.body[0].setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
1212 |
elif type == "FBD": |
|
1213 |
self.body[0].setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
1214 |
elif type == "SFC": |
|
1215 |
self.body[0].setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
1216 |
else: |
|
1217 |
raise ValueError, "%s isn't a valid body type!"%type |
|
151 | 1218 |
setattr(cls, "setbodyType", setbodyType) |
389 | 1219 |
|
1220 |
def getbodyType(self): |
|
1221 |
if len(self.body) > 0: |
|
1222 |
return self.body[0].getcontent()["name"] |
|
151 | 1223 |
setattr(cls, "getbodyType", getbodyType) |
389 | 1224 |
|
1225 |
def resetexecutionOrder(self): |
|
1226 |
if len(self.body) > 0: |
|
1227 |
self.body[0].resetexecutionOrder() |
|
151 | 1228 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
389 | 1229 |
|
1230 |
def compileexecutionOrder(self): |
|
1231 |
if len(self.body) > 0: |
|
1232 |
self.body[0].compileexecutionOrder() |
|
151 | 1233 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
389 | 1234 |
|
1235 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1236 |
if len(self.body) > 0: |
|
1237 |
self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
|
151 | 1238 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
389 | 1239 |
|
1240 |
def addinstance(self, name, instance): |
|
1241 |
if len(self.body) > 0: |
|
1242 |
self.body[0].appendcontentInstance(name, instance) |
|
151 | 1243 |
setattr(cls, "addinstance", addinstance) |
389 | 1244 |
|
1245 |
def getinstances(self): |
|
1246 |
if len(self.body) > 0: |
|
1247 |
return self.body[0].getcontentInstances() |
|
1248 |
return [] |
|
151 | 1249 |
setattr(cls, "getinstances", getinstances) |
389 | 1250 |
|
1251 |
def getinstance(self, id): |
|
1252 |
if len(self.body) > 0: |
|
1253 |
return self.body[0].getcontentInstance(id) |
|
1254 |
return None |
|
151 | 1255 |
setattr(cls, "getinstance", getinstance) |
389 | 1256 |
|
1257 |
def getrandomInstance(self, exclude): |
|
1258 |
if len(self.body) > 0: |
|
1259 |
return self.body[0].getcontentRandomInstance(exclude) |
|
1260 |
return None |
|
151 | 1261 |
setattr(cls, "getrandomInstance", getrandomInstance) |
389 | 1262 |
|
1263 |
def getinstanceByName(self, name): |
|
1264 |
if len(self.body) > 0: |
|
1265 |
return self.body[0].getcontentInstanceByName(name) |
|
1266 |
return None |
|
151 | 1267 |
setattr(cls, "getinstanceByName", getinstanceByName) |
389 | 1268 |
|
1269 |
def removeinstance(self, id): |
|
1270 |
if len(self.body) > 0: |
|
1271 |
self.body[0].removecontentInstance(id) |
|
151 | 1272 |
setattr(cls, "removeinstance", removeinstance) |
389 | 1273 |
|
1274 |
def settext(self, text): |
|
1275 |
if len(self.body) > 0: |
|
1276 |
self.body[0].settext(text) |
|
151 | 1277 |
setattr(cls, "settext", settext) |
389 | 1278 |
|
1279 |
def gettext(self): |
|
1280 |
if len(self.body) > 0: |
|
1281 |
return self.body[0].gettext() |
|
1282 |
return "" |
|
151 | 1283 |
setattr(cls, "gettext", gettext) |
1284 |
||
1285 |
def getvars(self): |
|
2 | 1286 |
vars = [] |
282 | 1287 |
if self.interface is not None: |
1288 |
reverse_types = {} |
|
1289 |
for name, value in VarTypes.items(): |
|
1290 |
reverse_types[value] = name |
|
1291 |
for varlist in self.interface.getcontent(): |
|
1292 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
|
2 | 1293 |
return vars |
151 | 1294 |
setattr(cls, "getvars", getvars) |
1295 |
||
1296 |
def setvars(self, vars): |
|
282 | 1297 |
if self.interface is None: |
1298 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
151 | 1299 |
self.interface.setcontent([]) |
2 | 1300 |
for vartype, varlist in vars: |
151 | 1301 |
self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
1302 |
setattr(cls, "setvars", setvars) |
|
1303 |
||
616
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1304 |
def addpouLocalVar(self, type, name, location="", description=""): |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1305 |
self.addpouVar(type, name, location=location, description=description) |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1306 |
setattr(cls, "addpouLocalVar", addpouLocalVar) |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1307 |
|
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1308 |
def addpouExternalVar(self, type, name): |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1309 |
self.addpouVar(type, name, "externalVars") |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1310 |
setattr(cls, "addpouExternalVar", addpouExternalVar) |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1311 |
|
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1312 |
def addpouVar(self, type, name, var_class="localVars", location="", description=""): |
282 | 1313 |
if self.interface is None: |
1314 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
151 | 1315 |
content = self.interface.getcontent() |
616
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1316 |
if len(content) == 0 or content[-1]["name"] != var_class: |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1317 |
content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1318 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1319 |
varlist = content[-1]["value"] |
151 | 1320 |
variables = varlist.getvariable() |
1321 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
616
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
608
diff
changeset
|
1322 |
content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1323 |
var = PLCOpenClasses["varListPlain_variable"]() |
151 | 1324 |
var.setname(name) |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1325 |
var_type = PLCOpenClasses["dataType"]() |
435
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1326 |
if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1327 |
if type == "STRING": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1328 |
var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1329 |
elif type == "WSTRING": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1330 |
var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1331 |
else: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1332 |
var_type.setcontent({"name" : type, "value" : None}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1333 |
else: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1334 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1335 |
derived_type.setname(type) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1336 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
151 | 1337 |
var.settype(var_type) |
435
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1338 |
if location != "": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1339 |
var.setaddress(location) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1340 |
if description != "": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1341 |
ft = PLCOpenClasses["formattedText"]() |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1342 |
ft.settext(description) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1343 |
var.setdocumentation(ft) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
1344 |
|
151 | 1345 |
content[-1]["value"].appendvariable(var) |
1346 |
setattr(cls, "addpouVar", addpouVar) |
|
1347 |
||
1348 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
|
282 | 1349 |
if self.interface is not None: |
1350 |
content = self.interface.getcontent() |
|
1351 |
for varlist in content: |
|
1352 |
variables = varlist["value"].getvariable() |
|
1353 |
for var in variables: |
|
1354 |
if var.getname() == old_name: |
|
1355 |
vartype_content = var.gettype().getcontent() |
|
1356 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
|
1357 |
var.setname(new_name) |
|
1358 |
vartype_content["value"].setname(new_type) |
|
1359 |
return |
|
151 | 1360 |
setattr(cls, "changepouVar", changepouVar) |
1361 |
||
1362 |
def removepouVar(self, type, name): |
|
282 | 1363 |
if self.interface is not None: |
1364 |
content = self.interface.getcontent() |
|
1365 |
for varlist in content: |
|
1366 |
variables = varlist["value"].getvariable() |
|
1367 |
for var in variables: |
|
1368 |
if var.getname() == name: |
|
1369 |
vartype_content = var.gettype().getcontent() |
|
1370 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
|
1371 |
variables.remove(var) |
|
1372 |
break |
|
1373 |
if len(varlist["value"].getvariable()) == 0: |
|
1374 |
content.remove(varlist) |
|
1375 |
break |
|
151 | 1376 |
setattr(cls, "removepouVar", removepouVar) |
1377 |
||
1378 |
def hasblock(self, name): |
|
1379 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1380 |
for instance in self.getinstances(): |
|
1381 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1382 |
return True |
89 | 1383 |
if self.transitions: |
151 | 1384 |
for transition in self.transitions.gettransition(): |
1385 |
result = transition.hasblock(name) |
|
89 | 1386 |
if result: |
1387 |
return result |
|
1388 |
if self.actions: |
|
151 | 1389 |
for action in self.actions.getaction(): |
1390 |
result = action.hasblock(name) |
|
89 | 1391 |
if result: |
1392 |
return result |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1393 |
return False |
151 | 1394 |
setattr(cls, "hasblock", hasblock) |
1395 |
||
1396 |
def addtransition(self, name, type): |
|
2 | 1397 |
if not self.transitions: |
151 | 1398 |
self.addtransitions() |
1399 |
self.transitions.settransition([]) |
|
2 | 1400 |
transition = PLCOpenClasses["transitions_transition"]() |
151 | 1401 |
transition.setname(name) |
1402 |
transition.setbodyType(type) |
|
200 | 1403 |
if type == "ST": |
1404 |
transition.settext(":= ;") |
|
1405 |
elif type == "IL": |
|
1406 |
transition.settext("\tST\t%s"%name) |
|
151 | 1407 |
self.transitions.appendtransition(transition) |
1408 |
setattr(cls, "addtransition", addtransition) |
|
1409 |
||
1410 |
def gettransition(self, name): |
|
2 | 1411 |
if self.transitions: |
151 | 1412 |
for transition in self.transitions.gettransition(): |
1413 |
if transition.getname() == name: |
|
2 | 1414 |
return transition |
1415 |
return None |
|
151 | 1416 |
setattr(cls, "gettransition", gettransition) |
2 | 1417 |
|
151 | 1418 |
def gettransitionList(self): |
2 | 1419 |
if self.transitions: |
151 | 1420 |
return self.transitions.gettransition() |
2 | 1421 |
return [] |
151 | 1422 |
setattr(cls, "gettransitionList", gettransitionList) |
1423 |
||
1424 |
def removetransition(self, name): |
|
2 | 1425 |
if self.transitions: |
151 | 1426 |
transitions = self.transitions.gettransition() |
2 | 1427 |
i = 0 |
1428 |
removed = False |
|
1429 |
while i < len(transitions) and not removed: |
|
151 | 1430 |
if transitions[i].getname() == name: |
46 | 1431 |
transitions.pop(i) |
2 | 1432 |
removed = True |
1433 |
i += 1 |
|
1434 |
if not removed: |
|
427 | 1435 |
raise ValueError, _("Transition with name %s doesn't exist!")%name |
151 | 1436 |
setattr(cls, "removetransition", removetransition) |
1437 |
||
1438 |
def addaction(self, name, type): |
|
2 | 1439 |
if not self.actions: |
151 | 1440 |
self.addactions() |
1441 |
self.actions.setaction([]) |
|
2 | 1442 |
action = PLCOpenClasses["actions_action"]() |
151 | 1443 |
action.setname(name) |
1444 |
action.setbodyType(type) |
|
1445 |
self.actions.appendaction(action) |
|
1446 |
setattr(cls, "addaction", addaction) |
|
1447 |
||
1448 |
def getaction(self, name): |
|
2 | 1449 |
if self.actions: |
151 | 1450 |
for action in self.actions.getaction(): |
1451 |
if action.getname() == name: |
|
2 | 1452 |
return action |
1453 |
return None |
|
151 | 1454 |
setattr(cls, "getaction", getaction) |
1455 |
||
1456 |
def getactionList(self): |
|
2 | 1457 |
if self.actions: |
151 | 1458 |
return self.actions.getaction() |
2 | 1459 |
return [] |
151 | 1460 |
setattr(cls, "getactionList", getactionList) |
2 | 1461 |
|
151 | 1462 |
def removeaction(self, name): |
2 | 1463 |
if self.actions: |
151 | 1464 |
actions = self.actions.getaction() |
2 | 1465 |
i = 0 |
1466 |
removed = False |
|
1467 |
while i < len(actions) and not removed: |
|
151 | 1468 |
if actions[i].getname() == name: |
46 | 1469 |
actions.pop(i) |
2 | 1470 |
removed = True |
1471 |
i += 1 |
|
1472 |
if not removed: |
|
427 | 1473 |
raise ValueError, _("Action with name %s doesn't exist!")%name |
151 | 1474 |
setattr(cls, "removeaction", removeaction) |
2 | 1475 |
|
58 | 1476 |
def updateElementName(self, old_name, new_name): |
348
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1477 |
if self.interface: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1478 |
for content in self.interface.getcontent(): |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1479 |
for var in content["value"].getvariable(): |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1480 |
var_address = var.getaddress() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1481 |
if var_address is not None: |
470 | 1482 |
if var_address == old_name: |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1483 |
var.setaddress(new_name) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1484 |
if var.getname() == old_name: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1485 |
var.setname(new_name) |
348
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1486 |
var_type_content = var.gettype().getcontent() |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1487 |
if var_type_content["name"] == "derived": |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1488 |
if var_type_content["value"].getname() == old_name: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1489 |
var_type_content["value"].setname(new_name) |
394 | 1490 |
self.body[0].updateElementName(old_name, new_name) |
151 | 1491 |
for action in self.getactionList(): |
58 | 1492 |
action.updateElementName(old_name, new_name) |
151 | 1493 |
for transition in self.gettransitionList(): |
58 | 1494 |
transition.updateElementName(old_name, new_name) |
1495 |
setattr(cls, "updateElementName", updateElementName) |
|
1496 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1497 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1498 |
if self.interface: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1499 |
for content in self.interface.getcontent(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1500 |
for var in content["value"].getvariable(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1501 |
var_address = var.getaddress() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1502 |
if var_address is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1503 |
var.setaddress(update_address(var_address, address_model, new_leading)) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1504 |
self.body[0].updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1505 |
for action in self.getactionList(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1506 |
action.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1507 |
for transition in self.gettransitionList(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1508 |
transition.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1509 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1510 |
|
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1511 |
def removeVariableByAddress(self, address): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1512 |
if self.interface: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1513 |
for content in self.interface.getcontent(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1514 |
variables = content["value"].getvariable() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1515 |
for i in xrange(len(variables)-1, -1, -1): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1516 |
if variables[i].getaddress() == address: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1517 |
variables.pop(i) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1518 |
setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1519 |
|
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1520 |
def removeVariableByFilter(self, address_model): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1521 |
if self.interface: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1522 |
for content in self.interface.getcontent(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1523 |
variables = content["value"].getvariable() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1524 |
for i in xrange(len(variables)-1, -1, -1): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1525 |
var_address = variables[i].getaddress() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1526 |
if var_address is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1527 |
result = address_model.match(var_address) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1528 |
if result is not None: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1529 |
variables.pop(i) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1530 |
setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1531 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1532 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1533 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1534 |
filter = criteria["filter"] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1535 |
if filter == "all" or self.getpouType() in filter: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1536 |
parent_infos = parent_infos + ["P::%s" % self.getname()] |
576
3f2024f30553
Adding support for searching pattern in datatype elements
laurent
parents:
566
diff
changeset
|
1537 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1538 |
if self.interface is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1539 |
var_number = 0 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1540 |
for content in self.interface.getcontent(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1541 |
variable_type = searchResultVarTypes.get(content["value"], "var_local") |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1542 |
variables = content["value"].getvariable() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1543 |
for modifier, has_modifier in [("constant", content["value"].getconstant()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1544 |
("retain", content["value"].getretain()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1545 |
("non_retain", content["value"].getnonretain())]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1546 |
if has_modifier: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1547 |
for result in TestTextElement(modifier, criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1548 |
search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1549 |
break |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1550 |
for variable in variables: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1551 |
search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1552 |
var_number += 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1553 |
if len(self.body) > 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1554 |
search_result.extend(self.body[0].Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1555 |
for action in self.getactionList(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1556 |
search_result.extend(action.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1557 |
for transition in self.gettransitionList(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1558 |
search_result.extend(transition.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1559 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1560 |
setattr(cls, "Search", Search) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1561 |
|
389 | 1562 |
def setbodyType(self, type): |
1563 |
if type == "IL": |
|
1564 |
self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
1565 |
elif type == "ST": |
|
1566 |
self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1567 |
elif type == "LD": |
|
1568 |
self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
1569 |
elif type == "FBD": |
|
1570 |
self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
1571 |
elif type == "SFC": |
|
1572 |
self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
1573 |
else: |
|
1574 |
raise ValueError, "%s isn't a valid body type!"%type |
|
1575 |
||
1576 |
def getbodyType(self): |
|
1577 |
return self.body.getcontent()["name"] |
|
1578 |
||
1579 |
def resetexecutionOrder(self): |
|
1580 |
self.body.resetexecutionOrder() |
|
1581 |
||
1582 |
def compileexecutionOrder(self): |
|
1583 |
self.body.compileexecutionOrder() |
|
1584 |
||
1585 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1586 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
1587 |
||
1588 |
def addinstance(self, name, instance): |
|
1589 |
self.body.appendcontentInstance(name, instance) |
|
1590 |
||
1591 |
def getinstances(self): |
|
1592 |
return self.body.getcontentInstances() |
|
1593 |
||
1594 |
def getinstance(self, id): |
|
1595 |
return self.body.getcontentInstance(id) |
|
1596 |
||
1597 |
def getrandomInstance(self, exclude): |
|
1598 |
return self.body.getcontentRandomInstance(exclude) |
|
1599 |
||
1600 |
def getinstanceByName(self, name): |
|
1601 |
return self.body.getcontentInstanceByName(name) |
|
1602 |
||
1603 |
def removeinstance(self, id): |
|
1604 |
self.body.removecontentInstance(id) |
|
1605 |
||
1606 |
def settext(self, text): |
|
1607 |
self.body.settext(text) |
|
1608 |
||
1609 |
def gettext(self): |
|
1610 |
return self.body.gettext() |
|
1611 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1612 |
cls = PLCOpenClasses.get("transitions_transition", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1613 |
if cls: |
151 | 1614 |
setattr(cls, "setbodyType", setbodyType) |
1615 |
setattr(cls, "getbodyType", getbodyType) |
|
1616 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1617 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1618 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1619 |
setattr(cls, "addinstance", addinstance) |
|
1620 |
setattr(cls, "getinstances", getinstances) |
|
1621 |
setattr(cls, "getinstance", getinstance) |
|
1622 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1623 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1624 |
setattr(cls, "removeinstance", removeinstance) |
|
1625 |
setattr(cls, "settext", settext) |
|
1626 |
setattr(cls, "gettext", gettext) |
|
2 | 1627 |
|
58 | 1628 |
def updateElementName(self, old_name, new_name): |
1629 |
self.body.updateElementName(old_name, new_name) |
|
1630 |
setattr(cls, "updateElementName", updateElementName) |
|
1631 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1632 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1633 |
self.body.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1634 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1635 |
|
151 | 1636 |
def hasblock(self, name): |
1637 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1638 |
for instance in self.getinstances(): |
|
1639 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1640 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1641 |
return False |
151 | 1642 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1643 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1644 |
def Search(self, criteria, parent_infos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1645 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1646 |
parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1647 |
for result in TestTextElement(self.getname(), criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1648 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1649 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1650 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1651 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1652 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1653 |
cls = PLCOpenClasses.get("actions_action", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1654 |
if cls: |
151 | 1655 |
setattr(cls, "setbodyType", setbodyType) |
1656 |
setattr(cls, "getbodyType", getbodyType) |
|
1657 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1658 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1659 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1660 |
setattr(cls, "addinstance", addinstance) |
|
1661 |
setattr(cls, "getinstances", getinstances) |
|
1662 |
setattr(cls, "getinstance", getinstance) |
|
1663 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1664 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1665 |
setattr(cls, "removeinstance", removeinstance) |
|
1666 |
setattr(cls, "settext", settext) |
|
1667 |
setattr(cls, "gettext", gettext) |
|
2 | 1668 |
|
58 | 1669 |
def updateElementName(self, old_name, new_name): |
1670 |
self.body.updateElementName(old_name, new_name) |
|
1671 |
setattr(cls, "updateElementName", updateElementName) |
|
1672 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1673 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1674 |
self.body.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1675 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1676 |
|
151 | 1677 |
def hasblock(self, name): |
1678 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1679 |
for instance in self.getinstances(): |
|
1680 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1681 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1682 |
return False |
151 | 1683 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1684 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1685 |
def Search(self, criteria, parent_infos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1686 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1687 |
parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1688 |
for result in TestTextElement(self.getname(), criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1689 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1690 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1691 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1692 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1693 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1694 |
cls = PLCOpenClasses.get("body", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1695 |
if cls: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1696 |
cls.currentExecutionOrderId = 0 |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1697 |
|
151 | 1698 |
def resetcurrentExecutionOrderId(self): |
200 | 1699 |
object.__setattr__(self, "currentExecutionOrderId", 0) |
151 | 1700 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
1701 |
||
1702 |
def getnewExecutionOrderId(self): |
|
200 | 1703 |
object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1704 |
return self.currentExecutionOrderId |
151 | 1705 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1706 |
||
1707 |
def resetexecutionOrder(self): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1708 |
if self.content["name"] == "FBD": |
151 | 1709 |
for element in self.content["value"].getcontent(): |
1710 |
if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
|
1711 |
PLCOpenClasses.get("commonObjects_connector", None), |
|
1712 |
PLCOpenClasses.get("commonObjects_continuation", None))): |
|
1713 |
element["value"].setexecutionOrderId(0) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1714 |
else: |
391 | 1715 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1716 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1717 |
||
1718 |
def compileexecutionOrder(self): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1719 |
if self.content["name"] == "FBD": |
151 | 1720 |
self.resetexecutionOrder() |
1721 |
self.resetcurrentExecutionOrderId() |
|
1722 |
for element in self.content["value"].getcontent(): |
|
200 | 1723 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
151 | 1724 |
connections = element["value"].connectionPointIn.getconnections() |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1725 |
if connections and len(connections) == 1: |
151 | 1726 |
self.compileelementExecutionOrder(connections[0]) |
1727 |
element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1728 |
else: |
391 | 1729 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1730 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1731 |
||
1732 |
def compileelementExecutionOrder(self, link): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1733 |
if self.content["name"] == "FBD": |
151 | 1734 |
localid = link.getrefLocalId() |
1735 |
instance = self.getcontentInstance(localid) |
|
1736 |
if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
|
1737 |
for variable in instance.inputVariables.getvariable(): |
|
1738 |
connections = variable.connectionPointIn.getconnections() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1739 |
if connections and len(connections) == 1: |
151 | 1740 |
self.compileelementExecutionOrder(connections[0]) |
1741 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
|
1742 |
elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
|
1743 |
name = instance.getname() |
|
1744 |
for tmp_instance in self.getcontentInstances(): |
|
1745 |
if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
|
1746 |
connections = tmp_instance.connectionPointIn.getconnections() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1747 |
if connections and len(connections) == 1: |
151 | 1748 |
self.compileelementExecutionOrder(connections[0]) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1749 |
else: |
391 | 1750 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1751 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1752 |
||
1753 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1754 |
if self.content["name"] == "FBD": |
151 | 1755 |
old_executionOrder = instance.getexecutionOrderId() |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1756 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
151 | 1757 |
for element in self.content["value"].getcontent(): |
1758 |
if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
|
1759 |
element_executionOrder = element["value"].getexecutionOrderId() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1760 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
151 | 1761 |
element["value"].setexecutionOrderId(element_executionOrder - 1) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1762 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
151 | 1763 |
element["value"].setexecutionOrderId(element_executionOrder + 1) |
1764 |
instance.setexecutionOrderId(new_executionOrder) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1765 |
else: |
391 | 1766 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1767 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1768 |
||
1769 |
def appendcontentInstance(self, name, instance): |
|
2 | 1770 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1771 |
self.content["value"].appendcontent({"name" : name, "value" : instance}) |
2 | 1772 |
else: |
391 | 1773 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1774 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
1775 |
||
1776 |
def getcontentInstances(self): |
|
2 | 1777 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1778 |
instances = [] |
|
151 | 1779 |
for element in self.content["value"].getcontent(): |
2 | 1780 |
instances.append(element["value"]) |
1781 |
return instances |
|
1782 |
else: |
|
391 | 1783 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1784 |
setattr(cls, "getcontentInstances", getcontentInstances) |
1785 |
||
1786 |
def getcontentInstance(self, id): |
|
2 | 1787 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1788 |
for element in self.content["value"].getcontent(): |
1789 |
if element["value"].getlocalId() == id: |
|
2 | 1790 |
return element["value"] |
0 | 1791 |
return None |
2 | 1792 |
else: |
391 | 1793 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1794 |
setattr(cls, "getcontentInstance", getcontentInstance) |
1795 |
||
1796 |
def getcontentRandomInstance(self, exclude): |
|
2 | 1797 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1798 |
for element in self.content["value"].getcontent(): |
1799 |
if element["value"].getlocalId() not in exclude: |
|
2 | 1800 |
return element["value"] |
1801 |
return None |
|
1802 |
else: |
|
391 | 1803 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1804 |
setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1805 |
||
1806 |
def getcontentInstanceByName(self, name): |
|
2 | 1807 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1808 |
for element in self.content["value"].getcontent(): |
193 | 1809 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
2 | 1810 |
return element["value"] |
1811 |
else: |
|
391 | 1812 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1813 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1814 |
||
1815 |
def removecontentInstance(self, id): |
|
2 | 1816 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1817 |
i = 0 |
|
1818 |
removed = False |
|
151 | 1819 |
elements = self.content["value"].getcontent() |
2 | 1820 |
while i < len(elements) and not removed: |
151 | 1821 |
if elements[i]["value"].getlocalId() == id: |
1822 |
self.content["value"].removecontent(i) |
|
2 | 1823 |
removed = True |
1824 |
i += 1 |
|
1825 |
if not removed: |
|
427 | 1826 |
raise ValueError, _("Instance with id %d doesn't exist!")%id |
2 | 1827 |
else: |
1828 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1829 |
setattr(cls, "removecontentInstance", removecontentInstance) |
1830 |
||
1831 |
def settext(self, text): |
|
2 | 1832 |
if self.content["name"] in ["IL","ST"]: |
151 | 1833 |
self.content["value"].settext(text) |
2 | 1834 |
else: |
391 | 1835 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
151 | 1836 |
setattr(cls, "settext", settext) |
1837 |
||
1838 |
def gettext(self): |
|
2 | 1839 |
if self.content["name"] in ["IL","ST"]: |
151 | 1840 |
return self.content["value"].gettext() |
2 | 1841 |
else: |
391 | 1842 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
151 | 1843 |
setattr(cls, "gettext", gettext) |
58 | 1844 |
|
1845 |
def updateElementName(self, old_name, new_name): |
|
1846 |
if self.content["name"] in ["IL", "ST"]: |
|
1847 |
self.content["value"].updateElementName(old_name, new_name) |
|
1848 |
else: |
|
151 | 1849 |
for element in self.content["value"].getcontent(): |
58 | 1850 |
element["value"].updateElementName(old_name, new_name) |
1851 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1852 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1853 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1854 |
if self.content["name"] in ["IL", "ST"]: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1855 |
self.content["value"].updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1856 |
else: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1857 |
for element in self.content["value"].getcontent(): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1858 |
element["value"].updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1859 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1860 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1861 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1862 |
if self.content["name"] in ["IL", "ST"]: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1863 |
search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1864 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1865 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1866 |
for element in self.content["value"].getcontent(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1867 |
search_result.extend(element["value"].Search(criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1868 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1869 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1870 |
|
151 | 1871 |
def getx(self): |
1872 |
return self.position.getx() |
|
1873 |
||
1874 |
def gety(self): |
|
1875 |
return self.position.gety() |
|
1876 |
||
1877 |
def setx(self, x): |
|
1878 |
self.position.setx(x) |
|
1879 |
||
1880 |
def sety(self, y): |
|
1881 |
self.position.sety(y) |
|
1882 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1883 |
def _getBoundingBox(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1884 |
return rect(self.getx(), self.gety(), self.getwidth(), self.getheight()) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1885 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1886 |
def _getConnectionsBoundingBox(connectionPointIn): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1887 |
bbox = rect() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1888 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1889 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1890 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1891 |
for x, y in connection.getpoints(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1892 |
bbox.update(x, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1893 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1894 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1895 |
def _getBoundingBoxSingle(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1896 |
bbox = _getBoundingBox(self) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1897 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1898 |
bbox.union(_getConnectionsBoundingBox(self.connectionPointIn)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1899 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1900 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1901 |
def _getBoundingBoxMultiple(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1902 |
bbox = _getBoundingBox(self) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1903 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1904 |
bbox.union(_getConnectionsBoundingBox(connectionPointIn)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1905 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1906 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1907 |
def _filterConnections(connectionPointIn, localId, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1908 |
in_connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1909 |
if in_connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1910 |
to_delete = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1911 |
for i, connection in enumerate(in_connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1912 |
connected = connection.getrefLocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1913 |
if not connections.has_key((localId, connected)) and \ |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1914 |
not connections.has_key((connected, localId)): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1915 |
to_delete.append(i) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1916 |
to_delete.reverse() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1917 |
for i in to_delete: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1918 |
connectionPointIn.removeconnection(i) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1919 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1920 |
def _filterConnectionsSingle(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1921 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1922 |
_filterConnections(self.connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1923 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1924 |
def _filterConnectionsMultiple(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1925 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1926 |
_filterConnections(connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1927 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1928 |
def _getconnectionsdefinition(instance, connections_end): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1929 |
id = instance.getlocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1930 |
return dict([((id, end), True) for end in connections_end]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1931 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1932 |
def _updateConnectionsId(connectionPointIn, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1933 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1934 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1935 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1936 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1937 |
refLocalId = connection.getrefLocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1938 |
new_reflocalId = translation.get(refLocalId, refLocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1939 |
connection.setrefLocalId(new_reflocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1940 |
connections_end.append(new_reflocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1941 |
return connections_end |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1942 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1943 |
def _updateConnectionsIdSingle(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1944 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1945 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1946 |
connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1947 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1948 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1949 |
def _updateConnectionsIdMultiple(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1950 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1951 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1952 |
connections_end.extend(_updateConnectionsId(connectionPointIn, translation)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1953 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1954 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1955 |
def _translate(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1956 |
self.setx(self.getx() + dx) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1957 |
self.sety(self.gety() + dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1958 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1959 |
def _translateConnections(connectionPointIn, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1960 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1961 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1962 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1963 |
for position in connection.getposition(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1964 |
position.setx(position.getx() + dx) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1965 |
position.sety(position.gety() + dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1966 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1967 |
def _translateSingle(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1968 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1969 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1970 |
_translateConnections(self.connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1971 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1972 |
def _translateMultiple(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1973 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1974 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1975 |
_translateConnections(connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1976 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1977 |
def _updateElementName(self, old_name, new_name): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1978 |
pass |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1979 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1980 |
def _updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1981 |
pass |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
1982 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1983 |
def _SearchInElement(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1984 |
return [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1985 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1986 |
_connectionsFunctions = { |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1987 |
"bbox": {"none": _getBoundingBox, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1988 |
"single": _getBoundingBoxSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1989 |
"multiple": _getBoundingBoxMultiple}, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1990 |
"translate": {"none": _translate, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1991 |
"single": _translateSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1992 |
"multiple": _translateMultiple}, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1993 |
"filter": {"none": lambda self, connections: None, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1994 |
"single": _filterConnectionsSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1995 |
"multiple": _filterConnectionsMultiple}, |
387 | 1996 |
"update": {"none": lambda self, translation: {}, |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1997 |
"single": _updateConnectionsIdSingle, |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
1998 |
"multiple": _updateConnectionsIdMultiple}, |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1999 |
} |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2000 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2001 |
def _initElementClass(name, classname, connectionPointInType="none"): |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2002 |
ElementNameToClass[name] = classname |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2003 |
cls = PLCOpenClasses.get(classname, None) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2004 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2005 |
setattr(cls, "getx", getx) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2006 |
setattr(cls, "gety", gety) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2007 |
setattr(cls, "setx", setx) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2008 |
setattr(cls, "sety", sety) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2009 |
setattr(cls, "updateElementName", _updateElementName) |
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2010 |
setattr(cls, "updateElementAddress", _updateElementAddress) |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2011 |
setattr(cls, "getBoundingBox", _connectionsFunctions["bbox"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2012 |
setattr(cls, "translate", _connectionsFunctions["translate"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2013 |
setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2014 |
setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2015 |
setattr(cls, "Search", _SearchInElement) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2016 |
return cls |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2017 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2018 |
def _getexecutionOrder(instance, specific_values): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2019 |
executionOrder = instance.getexecutionOrderId() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2020 |
if executionOrder is None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2021 |
executionOrder = 0 |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2022 |
specific_values["executionOrder"] = executionOrder |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2023 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2024 |
def _getdefaultmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2025 |
infos["negated"] = instance.getnegated() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2026 |
infos["edge"] = instance.getedge() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2027 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2028 |
def _getinputmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2029 |
infos["negated"] = instance.getnegatedIn() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2030 |
infos["edge"] = instance.getedgeIn() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2031 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2032 |
def _getoutputmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2033 |
infos["negated"] = instance.getnegatedOut() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2034 |
infos["edge"] = instance.getedgeOut() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2035 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2036 |
MODIFIERS_FUNCTIONS = {"default": _getdefaultmodifiers, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2037 |
"input": _getinputmodifiers, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2038 |
"output": _getoutputmodifiers} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2039 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2040 |
def _getconnectioninfos(instance, connection, links=False, modifiers=None, parameter=False): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2041 |
infos = {"position": connection.getrelPositionXY()} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2042 |
if parameter: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2043 |
infos["name"] = instance.getformalParameter() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2044 |
MODIFIERS_FUNCTIONS.get(modifiers, lambda x, y: None)(instance, infos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2045 |
if links: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2046 |
infos["links"] = [] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2047 |
connections = connection.getconnections() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2048 |
if connections is not None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2049 |
for link in connections: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2050 |
dic = {"refLocalId": link.getrefLocalId(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2051 |
"points": link.getpoints(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2052 |
"formalParameter": link.getformalParameter()} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2053 |
infos["links"].append(dic) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2054 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2055 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2056 |
def _getelementinfos(instance): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2057 |
return {"id": instance.getlocalId(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2058 |
"x": instance.getx(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2059 |
"y": instance.gety(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2060 |
"height": instance.getheight(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2061 |
"width": instance.getwidth(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2062 |
"specific_values": {}, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2063 |
"inputs": [], |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2064 |
"outputs": []} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2065 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2066 |
def _getvariableinfosFunction(type, input, output): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2067 |
def getvariableinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2068 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2069 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2070 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2071 |
specific_values["name"] = self.getexpression() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2072 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2073 |
if input and output: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2074 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2075 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2076 |
elif input: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2077 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "default")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2078 |
elif output: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2079 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2080 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2081 |
return getvariableinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2082 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2083 |
def _getconnectorinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2084 |
def getvariableinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2085 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2086 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2087 |
infos["specific_values"]["name"] = self.getname() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2088 |
if type == "connector": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2089 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2090 |
elif type == "continuation": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2091 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2092 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2093 |
return getvariableinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2094 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2095 |
def _getpowerrailinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2096 |
def getpowerrailinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2097 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2098 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2099 |
if type == "rightPowerRail": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2100 |
for connectionPointIn in self.getconnectionPointIn(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2101 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
550 | 2102 |
infos["specific_values"]["connectors"] = len(infos["inputs"]) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2103 |
elif type == "leftPowerRail": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2104 |
for connectionPointOut in self.getconnectionPointOut(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2105 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
550 | 2106 |
infos["specific_values"]["connectors"] = len(infos["outputs"]) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2107 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2108 |
return getpowerrailinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2109 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2110 |
def _getldelementinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2111 |
def getldelementinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2112 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2113 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2114 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2115 |
specific_values["name"] = self.getvariable() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2116 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2117 |
specific_values["negated"] = self.getnegated() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2118 |
specific_values["edge"] = self.getedge() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2119 |
if type == "coil": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2120 |
specific_values["storage"] = self.getstorage() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2121 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2122 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2123 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2124 |
return getldelementinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2125 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2126 |
DIVERGENCE_TYPES = {(True, True): "simultaneousDivergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2127 |
(True, False): "selectionDivergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2128 |
(False, True): "simultaneousConvergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2129 |
(False, False): "selectionConvergence"} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2130 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2131 |
def _getdivergenceinfosFunction(divergence, simultaneous): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2132 |
def getdivergenceinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2133 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2134 |
infos["type"] = DIVERGENCE_TYPES[(divergence, simultaneous)] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2135 |
if divergence: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2136 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2137 |
for connectionPointOut in self.getconnectionPointOut(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2138 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2139 |
infos["specific_values"]["connectors"] = len(infos["outputs"]) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2140 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2141 |
for connectionPointIn in self.getconnectionPointIn(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2142 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2143 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2144 |
infos["specific_values"]["connectors"] = len(infos["inputs"]) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2145 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2146 |
return getdivergenceinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2147 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2148 |
cls = _initElementClass("comment", "commonObjects_comment") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2149 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2150 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2151 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2152 |
infos["type"] = "comment" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2153 |
infos["specific_values"]["content"] = self.getcontentText() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2154 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2155 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2156 |
|
151 | 2157 |
def setcontentText(self, text): |
2158 |
self.content.settext(text) |
|
2159 |
setattr(cls, "setcontentText", setcontentText) |
|
0 | 2160 |
|
151 | 2161 |
def getcontentText(self): |
2162 |
return self.content.gettext() |
|
2163 |
setattr(cls, "getcontentText", getcontentText) |
|
58 | 2164 |
|
2165 |
def updateElementName(self, old_name, new_name): |
|
2166 |
self.content.updateElementName(old_name, new_name) |
|
2167 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 2168 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2169 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2170 |
self.content.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2171 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2172 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2173 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2174 |
return self.content.Search(criteria, parent_infos + ["comment", self.getlocalId(), "content"]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2175 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2176 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2177 |
cls = _initElementClass("block", "fbdObjects_block") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2178 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2179 |
def getBoundingBox(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2180 |
bbox = _getBoundingBox(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2181 |
for input in self.inputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2182 |
bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2183 |
return bbox |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2184 |
setattr(cls, "getBoundingBox", getBoundingBox) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2185 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2186 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2187 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2188 |
infos["type"] = self.gettypeName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2189 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2190 |
specific_values["name"] = self.getinstanceName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2191 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2192 |
for variable in self.inputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2193 |
infos["inputs"].append(_getconnectioninfos(variable, variable.connectionPointIn, True, "default", True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2194 |
for variable in self.outputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2195 |
infos["outputs"].append(_getconnectioninfos(variable, variable.connectionPointOut, False, "default", True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2196 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2197 |
setattr(cls, "getinfos", getinfos) |
2 | 2198 |
|
58 | 2199 |
def updateElementName(self, old_name, new_name): |
2200 |
if self.typeName == old_name: |
|
2201 |
self.typeName = new_name |
|
2202 |
setattr(cls, "updateElementName", updateElementName) |
|
2203 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2204 |
def filterConnections(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2205 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2206 |
_filterConnections(input.connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2207 |
setattr(cls, "filterConnections", filterConnections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2208 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2209 |
def updateConnectionsId(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2210 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2211 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2212 |
connections_end.extend(_updateConnectionsId(input.connectionPointIn, translation)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2213 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2214 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2215 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2216 |
def translate(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2217 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2218 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2219 |
_translateConnections(input.connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2220 |
setattr(cls, "translate", translate) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
2221 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2222 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2223 |
parent_infos = parent_infos + ["block", self.getlocalId()] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2224 |
search_result = _Search([("name", self.getinstanceName()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2225 |
("type", self.gettypeName())], |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2226 |
criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2227 |
for i, variable in enumerate(self.inputVariables.getvariable()): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2228 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2229 |
search_result.append((tuple(parent_infos + ["input", i]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2230 |
for i, variable in enumerate(self.outputVariables.getvariable()): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2231 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2232 |
search_result.append((tuple(parent_infos + ["output", i]),) + result) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2233 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2234 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2235 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2236 |
cls = _initElementClass("leftPowerRail", "ldObjects_leftPowerRail") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2237 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2238 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("leftPowerRail")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2239 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2240 |
cls = _initElementClass("rightPowerRail", "ldObjects_rightPowerRail", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2241 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2242 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2243 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2244 |
cls = _initElementClass("contact", "ldObjects_contact", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2245 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2246 |
setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2247 |
|
58 | 2248 |
def updateElementName(self, old_name, new_name): |
2249 |
if self.variable == old_name: |
|
2250 |
self.variable = new_name |
|
2251 |
setattr(cls, "updateElementName", updateElementName) |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2252 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2253 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2254 |
self.variable = update_address(self.variable, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2255 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2256 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2257 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2258 |
return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2259 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2260 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2261 |
cls = _initElementClass("coil", "ldObjects_coil", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2262 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2263 |
setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2264 |
|
58 | 2265 |
def updateElementName(self, old_name, new_name): |
2266 |
if self.variable == old_name: |
|
2267 |
self.variable = new_name |
|
2268 |
setattr(cls, "updateElementName", updateElementName) |
|
2269 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2270 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2271 |
self.variable = update_address(self.variable, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2272 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2273 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2274 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2275 |
return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2276 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2277 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2278 |
cls = _initElementClass("step", "sfcObjects_step", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2279 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2280 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2281 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2282 |
infos["type"] = "step" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2283 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2284 |
specific_values["name"] = self.getname() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2285 |
specific_values["initial"] = self.getinitialStep() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2286 |
if self.connectionPointIn: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2287 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2288 |
if self.connectionPointOut: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2289 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2290 |
if self.connectionPointOutAction: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2291 |
specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2292 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2293 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2294 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2295 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2296 |
return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2297 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2298 |
|
389 | 2299 |
cls = PLCOpenClasses.get("transition_condition", None) |
2300 |
if cls: |
|
2301 |
def compatibility(self, tree): |
|
2302 |
connections = [] |
|
2303 |
for child in tree.childNodes: |
|
2304 |
if child.nodeName == "connection": |
|
2305 |
connections.append(child) |
|
2306 |
if len(connections) > 0: |
|
2307 |
node = CreateNode("connectionPointIn") |
|
2308 |
relPosition = CreateNode("relPosition") |
|
2309 |
NodeSetAttr(relPosition, "x", "0") |
|
2310 |
NodeSetAttr(relPosition, "y", "0") |
|
2311 |
node.childNodes.append(relPosition) |
|
2312 |
node.childNodes.extend(connections) |
|
2313 |
tree.childNodes = [node] |
|
2314 |
setattr(cls, "compatibility", compatibility) |
|
2315 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2316 |
cls = _initElementClass("transition", "sfcObjects_transition", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2317 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2318 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2319 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2320 |
infos["type"] = "transition" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2321 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2322 |
priority = self.getpriority() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2323 |
if priority is None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2324 |
priority = 0 |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2325 |
specific_values["priority"] = priority |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2326 |
condition = self.getconditionContent() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2327 |
specific_values["condition_type"] = condition["type"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2328 |
if specific_values["condition_type"] == "connection": |
389 | 2329 |
specific_values["connection"] = _getconnectioninfos(self, condition["value"], True) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2330 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2331 |
specific_values["condition"] = condition["value"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2332 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2333 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2334 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2335 |
setattr(cls, "getinfos", getinfos) |
151 | 2336 |
|
2337 |
def setconditionContent(self, type, value): |
|
2 | 2338 |
if not self.condition: |
151 | 2339 |
self.addcondition() |
2 | 2340 |
if type == "reference": |
2341 |
condition = PLCOpenClasses["condition_reference"]() |
|
151 | 2342 |
condition.setname(value) |
2 | 2343 |
elif type == "inline": |
2344 |
condition = PLCOpenClasses["condition_inline"]() |
|
151 | 2345 |
condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
2346 |
condition.settext(value) |
|
69 | 2347 |
elif type == "connection": |
389 | 2348 |
type = "connectionPointIn" |
2349 |
condition = PLCOpenClasses["connectionPointIn"]() |
|
151 | 2350 |
self.condition.setcontent({"name" : type, "value" : condition}) |
2351 |
setattr(cls, "setconditionContent", setconditionContent) |
|
0 | 2352 |
|
151 | 2353 |
def getconditionContent(self): |
2 | 2354 |
if self.condition: |
151 | 2355 |
content = self.condition.getcontent() |
2 | 2356 |
values = {"type" : content["name"]} |
2357 |
if values["type"] == "reference": |
|
151 | 2358 |
values["value"] = content["value"].getname() |
2 | 2359 |
elif values["type"] == "inline": |
151 | 2360 |
values["value"] = content["value"].gettext() |
389 | 2361 |
elif values["type"] == "connectionPointIn": |
2362 |
values["type"] = "connection" |
|
2363 |
values["value"] = content["value"] |
|
2 | 2364 |
return values |
2365 |
return "" |
|
151 | 2366 |
setattr(cls, "getconditionContent", getconditionContent) |
2 | 2367 |
|
58 | 2368 |
def updateElementName(self, old_name, new_name): |
2369 |
if self.condition: |
|
151 | 2370 |
content = self.condition.getcontent() |
58 | 2371 |
if content["name"] == "reference": |
151 | 2372 |
if content["value"].getname() == old_name: |
2373 |
content["value"].setname(new_name) |
|
58 | 2374 |
elif content["name"] == "inline": |
2375 |
content["value"].updateElementName(old_name, new_name) |
|
2376 |
setattr(cls, "updateElementName", updateElementName) |
|
2377 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2378 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2379 |
if self.condition: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2380 |
content = self.condition.getcontent() |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2381 |
if content["name"] == "reference": |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2382 |
content["value"].setname(update_address(content["value"].getname(), address_model, new_leading)) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2383 |
elif content["name"] == "inline": |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2384 |
content["value"].updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2385 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2386 |
|
151 | 2387 |
def getconnections(self): |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
2388 |
if self.condition: |
151 | 2389 |
content = self.condition.getcontent() |
389 | 2390 |
if content["name"] == "connectionPointIn": |
2391 |
return content["value"].getconnections() |
|
151 | 2392 |
setattr(cls, "getconnections", getconnections) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2393 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2394 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2395 |
parent_infos = parent_infos + ["transition", self.getlocalId()] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2396 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2397 |
content = self.condition.getcontent() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2398 |
if content["name"] == "reference": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2399 |
search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2400 |
elif content["name"] == "inline": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2401 |
search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2402 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2403 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2404 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2405 |
cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2406 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2407 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2408 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2409 |
cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2410 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2411 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2412 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2413 |
cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2414 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2415 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2416 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2417 |
cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2418 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2419 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2420 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2421 |
cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2422 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2423 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2424 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2425 |
infos["type"] = "jump" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2426 |
infos["specific_values"]["target"] = self.gettargetName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2427 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2428 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2429 |
setattr(cls, "getinfos", getinfos) |
58 | 2430 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2431 |
def Search(self, criteria, parent_infos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2432 |
return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2433 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2434 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2435 |
cls = PLCOpenClasses.get("actionBlock_action", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2436 |
if cls: |
389 | 2437 |
def compatibility(self, tree): |
2438 |
relPosition = reduce(lambda x, y: x | (y.nodeName == "relPosition"), tree.childNodes, False) |
|
2439 |
if not tree.hasAttribute("localId"): |
|
2440 |
NodeSetAttr(tree, "localId", "0") |
|
2441 |
if not relPosition: |
|
2442 |
node = CreateNode("relPosition") |
|
2443 |
NodeSetAttr(node, "x", "0") |
|
2444 |
NodeSetAttr(node, "y", "0") |
|
2445 |
tree.childNodes.insert(0, node) |
|
2446 |
setattr(cls, "compatibility", compatibility) |
|
2447 |
||
151 | 2448 |
def setreferenceName(self, name): |
2449 |
if self.reference: |
|
2450 |
self.reference.setname(name) |
|
2451 |
setattr(cls, "setreferenceName", setreferenceName) |
|
2452 |
||
2453 |
def getreferenceName(self): |
|
2454 |
if self.reference: |
|
2455 |
return self.reference.getname() |
|
2 | 2456 |
return None |
151 | 2457 |
setattr(cls, "getreferenceName", getreferenceName) |
2458 |
||
2459 |
def setinlineContent(self, content): |
|
2460 |
if self.inline: |
|
2461 |
self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2462 |
self.inline.settext(content) |
|
2463 |
setattr(cls, "setinlineContent", setinlineContent) |
|
2464 |
||
2465 |
def getinlineContent(self): |
|
2466 |
if self.inline: |
|
2467 |
return self.inline.gettext() |
|
2 | 2468 |
return None |
151 | 2469 |
setattr(cls, "getinlineContent", getinlineContent) |
2470 |
||
2471 |
def updateElementName(self, old_name, new_name): |
|
2472 |
if self.reference and self.reference.getname() == old_name: |
|
2473 |
self.reference.setname(new_name) |
|
58 | 2474 |
if self.inline: |
2475 |
self.inline.updateElementName(old_name, new_name) |
|
2476 |
setattr(cls, "updateElementName", updateElementName) |
|
2477 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2478 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2479 |
if self.reference: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2480 |
self.reference.setname(update_address(self.reference.getname(), address_model, new_leading)) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2481 |
if self.inline: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2482 |
self.inline.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2483 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2484 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2485 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2486 |
qualifier = self.getqualifier() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2487 |
if qualifier is None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2488 |
qualifier = "N" |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2489 |
return _Search([("inline", self.getinlineContent()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2490 |
("reference", self.getreferenceName()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2491 |
("qualifier", qualifier), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2492 |
("duration", self.getduration()), |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2493 |
("indicator", self.getindicator())], |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2494 |
criteria, parent_infos) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2495 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2496 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2497 |
cls = _initElementClass("actionBlock", "commonObjects_actionBlock", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2498 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2499 |
def compatibility(self, tree): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2500 |
for child in tree.childNodes[:]: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2501 |
if child.nodeName == "connectionPointOut": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2502 |
tree.childNodes.remove(child) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2503 |
setattr(cls, "compatibility", compatibility) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2504 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2505 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2506 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2507 |
infos["type"] = "actionBlock" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2508 |
infos["specific_values"]["actions"] = self.getactions() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2509 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2510 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2511 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2512 |
|
151 | 2513 |
def setactions(self, actions): |
2 | 2514 |
self.action = [] |
2515 |
for params in actions: |
|
2516 |
action = PLCOpenClasses["actionBlock_action"]() |
|
151 | 2517 |
action.setqualifier(params["qualifier"]) |
2 | 2518 |
if params["type"] == "reference": |
151 | 2519 |
action.addreference() |
2520 |
action.setreferenceName(params["value"]) |
|
0 | 2521 |
else: |
151 | 2522 |
action.addinline() |
2523 |
action.setinlineContent(params["value"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
2524 |
if params.has_key("duration"): |
151 | 2525 |
action.setduration(params["duration"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
2526 |
if params.has_key("indicator"): |
151 | 2527 |
action.setindicator(params["indicator"]) |
2 | 2528 |
self.action.append(action) |
151 | 2529 |
setattr(cls, "setactions", setactions) |
2530 |
||
2531 |
def getactions(self): |
|
2 | 2532 |
actions = [] |
2533 |
for action in self.action: |
|
2534 |
params = {} |
|
151 | 2535 |
params["qualifier"] = action.getqualifier() |
108 | 2536 |
if params["qualifier"] is None: |
2537 |
params["qualifier"] = "N" |
|
151 | 2538 |
if action.getreference(): |
2 | 2539 |
params["type"] = "reference" |
151 | 2540 |
params["value"] = action.getreferenceName() |
2541 |
elif action.getinline(): |
|
2 | 2542 |
params["type"] = "inline" |
151 | 2543 |
params["value"] = action.getinlineContent() |
2544 |
duration = action.getduration() |
|
2 | 2545 |
if duration: |
2546 |
params["duration"] = duration |
|
151 | 2547 |
indicator = action.getindicator() |
2 | 2548 |
if indicator: |
2549 |
params["indicator"] = indicator |
|
2550 |
actions.append(params) |
|
2551 |
return actions |
|
151 | 2552 |
setattr(cls, "getactions", getactions) |
2 | 2553 |
|
58 | 2554 |
def updateElementName(self, old_name, new_name): |
2555 |
for action in self.action: |
|
2556 |
action.updateElementName(old_name, new_name) |
|
2557 |
setattr(cls, "updateElementName", updateElementName) |
|
2558 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2559 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2560 |
for action in self.action: |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2561 |
action.updateElementAddress(address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2562 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2563 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2564 |
def Search(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2565 |
parent_infos = parent_infos + ["action_block", self.getlocalId()] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2566 |
search_result = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2567 |
for idx, action in enumerate(self.action): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2568 |
search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2569 |
return search_result |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2570 |
setattr(cls, "Search", Search) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2571 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2572 |
def _SearchInIOVariable(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2573 |
return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2574 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2575 |
cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2576 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2577 |
setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
58 | 2578 |
|
2579 |
def updateElementName(self, old_name, new_name): |
|
2580 |
if self.expression == old_name: |
|
2581 |
self.expression = new_name |
|
2582 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 2583 |
|
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2584 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2585 |
self.expression = update_address(self.expression, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2586 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2587 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2588 |
setattr(cls, "Search", _SearchInIOVariable) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2589 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2590 |
cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2591 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2592 |
setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2593 |
|
58 | 2594 |
def updateElementName(self, old_name, new_name): |
2595 |
if self.expression == old_name: |
|
2596 |
self.expression = new_name |
|
2597 |
setattr(cls, "updateElementName", updateElementName) |
|
2598 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2599 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2600 |
self.expression = update_address(self.expression, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2601 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2602 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2603 |
setattr(cls, "Search", _SearchInIOVariable) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2604 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2605 |
cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2606 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2607 |
setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2608 |
|
58 | 2609 |
def updateElementName(self, old_name, new_name): |
2610 |
if self.expression == old_name: |
|
2611 |
self.expression = new_name |
|
2612 |
setattr(cls, "updateElementName", updateElementName) |
|
2613 |
||
461
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2614 |
def updateElementAddress(self, address_model, new_leading): |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2615 |
self.expression = update_address(self.expression, address_model, new_leading) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2616 |
setattr(cls, "updateElementAddress", updateElementAddress) |
649a8465148d
Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents:
435
diff
changeset
|
2617 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2618 |
setattr(cls, "Search", _SearchInIOVariable) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2619 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2620 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2621 |
def _SearchInConnector(self, criteria, parent_infos=[]): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2622 |
return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2623 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2624 |
cls = _initElementClass("continuation", "commonObjects_continuation") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2625 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2626 |
setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2627 |
setattr(cls, "Search", _SearchInConnector) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2628 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2629 |
cls = _initElementClass("connector", "commonObjects_connector", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2630 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
2631 |
setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
557
diff
changeset
|
2632 |
setattr(cls, "Search", _SearchInConnector) |
2 | 2633 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2634 |
cls = PLCOpenClasses.get("connection", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2635 |
if cls: |
151 | 2636 |
def setpoints(self, points): |
2 | 2637 |
self.position = [] |
2638 |
for point in points: |
|
2639 |
position = PLCOpenClasses["position"]() |
|
151 | 2640 |
position.setx(point.x) |
2641 |
position.sety(point.y) |
|
2 | 2642 |
self.position.append(position) |
151 | 2643 |
setattr(cls, "setpoints", setpoints) |
2644 |
||
2645 |
def getpoints(self): |
|
2 | 2646 |
points = [] |
2647 |
for position in self.position: |
|
151 | 2648 |
points.append((position.getx(),position.gety())) |
2 | 2649 |
return points |
151 | 2650 |
setattr(cls, "getpoints", getpoints) |
2 | 2651 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2652 |
cls = PLCOpenClasses.get("connectionPointIn", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2653 |
if cls: |
151 | 2654 |
def setrelPositionXY(self, x, y): |
2 | 2655 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 2656 |
self.relPosition.setx(x) |
2657 |
self.relPosition.sety(y) |
|
2658 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2659 |
||
2660 |
def getrelPositionXY(self): |
|
2 | 2661 |
if self.relPosition: |
151 | 2662 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 2663 |
else: |
0 | 2664 |
return self.relPosition |
151 | 2665 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2666 |
||
2667 |
def addconnection(self): |
|
2 | 2668 |
if not self.content: |
151 | 2669 |
self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
2 | 2670 |
else: |
2671 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
151 | 2672 |
setattr(cls, "addconnection", addconnection) |
2673 |
||
2674 |
def removeconnection(self, idx): |
|
2 | 2675 |
if self.content: |
2676 |
self.content["value"].pop(idx) |
|
2677 |
if len(self.content["value"]) == 0: |
|
2678 |
self.content = None |
|
151 | 2679 |
setattr(cls, "removeconnection", removeconnection) |
2680 |
||
2681 |
def removeconnections(self): |
|
2 | 2682 |
if self.content: |
2683 |
self.content = None |
|
151 | 2684 |
setattr(cls, "removeconnections", removeconnections) |
2685 |
||
2686 |
def getconnections(self): |
|
2 | 2687 |
if self.content: |
2688 |
return self.content["value"] |
|
151 | 2689 |
setattr(cls, "getconnections", getconnections) |
2690 |
||
2691 |
def setconnectionId(self, idx, id): |
|
2 | 2692 |
if self.content: |
151 | 2693 |
self.content["value"][idx].setrefLocalId(id) |
2694 |
setattr(cls, "setconnectionId", setconnectionId) |
|
2695 |
||
2696 |
def getconnectionId(self, idx): |
|
2 | 2697 |
if self.content: |
151 | 2698 |
return self.content["value"][idx].getrefLocalId() |
2 | 2699 |
return None |
151 | 2700 |
setattr(cls, "getconnectionId", getconnectionId) |
2701 |
||
2702 |
def setconnectionPoints(self, idx, points): |
|
2 | 2703 |
if self.content: |
151 | 2704 |
self.content["value"][idx].setpoints(points) |
2705 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
2706 |
||
2707 |
def getconnectionPoints(self, idx): |
|
2 | 2708 |
if self.content: |
151 | 2709 |
return self.content["value"][idx].getpoints() |
2 | 2710 |
return None |
151 | 2711 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
2712 |
||
2713 |
def setconnectionParameter(self, idx, parameter): |
|
27 | 2714 |
if self.content: |
151 | 2715 |
self.content["value"][idx].setformalParameter(parameter) |
2716 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
2717 |
||
2718 |
def getconnectionParameter(self, idx): |
|
27 | 2719 |
if self.content: |
151 | 2720 |
return self.content["value"][idx].getformalParameter() |
27 | 2721 |
return None |
151 | 2722 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
27 | 2723 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2724 |
cls = PLCOpenClasses.get("connectionPointOut", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2725 |
if cls: |
151 | 2726 |
def setrelPositionXY(self, x, y): |
2 | 2727 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 2728 |
self.relPosition.setx(x) |
2729 |
self.relPosition.sety(y) |
|
2730 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2731 |
||
2732 |
def getrelPositionXY(self): |
|
2 | 2733 |
if self.relPosition: |
151 | 2734 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 2735 |
return self.relPosition |
151 | 2736 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2 | 2737 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2738 |
cls = PLCOpenClasses.get("value", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2739 |
if cls: |
151 | 2740 |
def setvalue(self, value): |
557
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2741 |
value = value.strip() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2742 |
if value.startswith("[") and value.endswith("]"): |
2 | 2743 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
151 | 2744 |
self.content = {"name" : "arrayValue", "value" : arrayValue} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2745 |
elif value.startswith("(") and value.endswith(")"): |
2 | 2746 |
structValue = PLCOpenClasses["value_structValue"]() |
151 | 2747 |
self.content = {"name" : "structValue", "value" : structValue} |
2 | 2748 |
else: |
2749 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
151 | 2750 |
self.content = {"name" : "simpleValue", "value": simpleValue} |
2751 |
self.content["value"].setvalue(value) |
|
2752 |
setattr(cls, "setvalue", setvalue) |
|
2753 |
||
2754 |
def getvalue(self): |
|
2755 |
return self.content["value"].getvalue() |
|
2756 |
setattr(cls, "getvalue", getvalue) |
|
2 | 2757 |
|
147 | 2758 |
def extractValues(values): |
145 | 2759 |
items = values.split(",") |
2760 |
i = 1 |
|
2761 |
while i < len(items): |
|
2762 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
2763 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
2764 |
if opened > closed: |
|
2765 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
2766 |
elif opened == closed: |
|
2767 |
i += 1 |
|
2768 |
else: |
|
391 | 2769 |
raise ValueError, _("\"%s\" is an invalid value!")%value |
145 | 2770 |
return items |
2771 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2772 |
cls = PLCOpenClasses.get("value_arrayValue", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2773 |
if cls: |
145 | 2774 |
arrayValue_model = re.compile("([0-9]*)\((.*)\)$") |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2775 |
|
151 | 2776 |
def setvalue(self, value): |
2 | 2777 |
self.value = [] |
145 | 2778 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2779 |
item = item.strip() |
2 | 2780 |
element = PLCOpenClasses["arrayValue_value"]() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2781 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2782 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2783 |
groups = result.groups() |
389 | 2784 |
element.setrepetitionValue(groups[0]) |
151 | 2785 |
element.setvalue(groups[1].strip()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2786 |
else: |
151 | 2787 |
element.setvalue(item) |
2 | 2788 |
self.value.append(element) |
151 | 2789 |
setattr(cls, "setvalue", setvalue) |
2790 |
||
2791 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2792 |
values = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2793 |
for element in self.value: |
151 | 2794 |
repetition = element.getrepetitionValue() |
557
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2795 |
if repetition is not None and int(repetition) > 1: |
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2796 |
value = element.getvalue() |
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2797 |
if value is None: |
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2798 |
value = "" |
0f591ac019f3
Fix bug in extraction and computation of array initial value
laurent
parents:
552
diff
changeset
|
2799 |
values.append("%s(%s)"%(repetition, value)) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2800 |
else: |
151 | 2801 |
values.append(element.getvalue()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2802 |
return "[%s]"%", ".join(values) |
151 | 2803 |
setattr(cls, "getvalue", getvalue) |
2 | 2804 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2805 |
cls = PLCOpenClasses.get("value_structValue", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2806 |
if cls: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2807 |
structValue_model = re.compile("(.*):=(.*)") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2808 |
|
151 | 2809 |
def setvalue(self, value): |
2 | 2810 |
self.value = [] |
145 | 2811 |
for item in extractValues(value[1:-1]): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
2812 |
result = structValue_model.match(item) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2813 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2814 |
groups = result.groups() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2815 |
element = PLCOpenClasses["structValue_value"]() |
151 | 2816 |
element.setmember(groups[0].strip()) |
2817 |
element.setvalue(groups[1].strip()) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
2818 |
self.value.append(element) |
151 | 2819 |
setattr(cls, "setvalue", setvalue) |
2820 |
||
2821 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2822 |
values = [] |
2 | 2823 |
for element in self.value: |
151 | 2824 |
values.append("%s := %s"%(element.getmember(), element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2825 |
return "(%s)"%", ".join(values) |
151 | 2826 |
setattr(cls, "getvalue", getvalue) |