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