author | Laurent Bessard |
Thu, 30 May 2013 09:46:22 +0200 | |
changeset 1195 | 8f8d9859e9fc |
parent 1171 | a506e4de8f84 |
child 1232 | b6894285d4cc |
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: |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
858 |
|
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
859 |
def addglobalVar(self, type, name, location="", description=""): |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
860 |
globalvars = self.getglobalVars() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
861 |
if len(globalvars) == 0: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
862 |
globalvars.append(PLCOpenClasses["varList"]()) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
863 |
var = PLCOpenClasses["varListPlain_variable"]() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
864 |
var.setname(name) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
865 |
var_type = PLCOpenClasses["dataType"]() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
866 |
if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
867 |
if type == "STRING": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
868 |
var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
869 |
elif type == "WSTRING": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
870 |
var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
871 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
872 |
var_type.setcontent({"name" : type, "value" : None}) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
873 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
874 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
875 |
derived_type.setname(type) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
876 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
877 |
var.settype(var_type) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
878 |
if location != "": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
879 |
var.setaddress(location) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
880 |
if description != "": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
881 |
ft = PLCOpenClasses["formattedText"]() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
882 |
ft.settext(description) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
883 |
var.setdocumentation(ft) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
884 |
globalvars[-1].appendvariable(var) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
885 |
setattr(cls, "addglobalVar", addglobalVar) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1142
diff
changeset
|
886 |
|
814 | 887 |
def updateElementName(self, old_name, new_name): |
888 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
|
889 |
for resource in self.getresource(): |
|
890 |
resource.updateElementName(old_name, new_name) |
|
891 |
setattr(cls, "updateElementName", updateElementName) |
|
892 |
||
893 |
def updateElementAddress(self, address_model, new_leading): |
|
894 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
|
895 |
for resource in self.getresource(): |
|
896 |
resource.updateElementAddress(address_model, new_leading) |
|
897 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
898 |
||
899 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
|
900 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
|
901 |
||
902 |
def Search(self, criteria, parent_infos=[]): |
|
903 |
search_result = [] |
|
904 |
parent_infos = parent_infos + ["C::%s" % self.getname()] |
|
905 |
filter = criteria["filter"] |
|
906 |
if filter == "all" or "configuration" in filter: |
|
907 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
|
908 |
for resource in self.getresource(): |
|
909 |
search_result.extend(resource.Search(criteria, parent_infos)) |
|
910 |
return search_result |
|
911 |
setattr(cls, "Search", Search) |
|
912 |
||
913 |
cls = PLCOpenClasses.get("configuration_resource", None) |
|
914 |
if cls: |
|
915 |
def updateElementName(self, old_name, new_name): |
|
916 |
_updateConfigurationResourceElementName(self, old_name, new_name) |
|
917 |
for instance in self.getpouInstance(): |
|
918 |
instance.updateElementName(old_name, new_name) |
|
919 |
for task in self.gettask(): |
|
920 |
task.updateElementName(old_name, new_name) |
|
921 |
setattr(cls, "updateElementName", updateElementName) |
|
922 |
||
923 |
def updateElementAddress(self, address_model, new_leading): |
|
924 |
_updateConfigurationResourceElementAddress(self, address_model, new_leading) |
|
925 |
for task in self.gettask(): |
|
926 |
task.updateElementAddress(address_model, new_leading) |
|
927 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
928 |
||
929 |
setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress) |
|
930 |
setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter) |
|
931 |
||
932 |
def Search(self, criteria, parent_infos=[]): |
|
933 |
parent_infos = parent_infos[:-1] + ["R::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
|
934 |
search_result = _SearchInConfigurationResource(self, criteria, parent_infos) |
|
935 |
task_number = 0 |
|
936 |
instance_number = 0 |
|
937 |
for task in self.gettask(): |
|
938 |
results = TestTextElement(task.getname(), criteria) |
|
939 |
for result in results: |
|
940 |
search_result.append((tuple(parent_infos + ["task", task_number, "name"]),) + result) |
|
941 |
search_result.extend(task.Search(criteria, parent_infos + ["task", task_number])) |
|
942 |
task_number += 1 |
|
943 |
for instance in task.getpouInstance(): |
|
944 |
search_result.extend(task.Search(criteria, parent_infos + ["instance", instance_number])) |
|
945 |
for result in results: |
|
946 |
search_result.append((tuple(parent_infos + ["instance", instance_number, "task"]),) + result) |
|
947 |
instance_number += 1 |
|
948 |
for instance in self.getpouInstance(): |
|
949 |
search_result.extend(instance.Search(criteria, parent_infos + ["instance", instance_number])) |
|
950 |
instance_number += 1 |
|
951 |
return search_result |
|
952 |
setattr(cls, "Search", Search) |
|
953 |
||
954 |
cls = PLCOpenClasses.get("resource_task", None) |
|
955 |
if cls: |
|
956 |
def compatibility(self, tree): |
|
957 |
if tree.hasAttribute("interval"): |
|
958 |
interval = GetAttributeValue(tree._attrs["interval"]) |
|
959 |
result = time_model.match(interval) |
|
960 |
if result is not None: |
|
961 |
values = result.groups() |
|
962 |
time_values = [int(v) for v in values[:2]] |
|
963 |
seconds = float(values[2]) |
|
964 |
time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
965 |
text = "t#" |
|
966 |
if time_values[0] != 0: |
|
967 |
text += "%dh"%time_values[0] |
|
968 |
if time_values[1] != 0: |
|
969 |
text += "%dm"%time_values[1] |
|
970 |
if time_values[2] != 0: |
|
971 |
text += "%ds"%time_values[2] |
|
972 |
if time_values[3] != 0: |
|
973 |
if time_values[3] % 1000 != 0: |
|
974 |
text += "%.3fms"%(float(time_values[3]) / 1000) |
|
975 |
else: |
|
976 |
text += "%dms"%(time_values[3] / 1000) |
|
977 |
NodeSetAttr(tree, "interval", text) |
|
978 |
setattr(cls, "compatibility", compatibility) |
|
979 |
||
980 |
def updateElementName(self, old_name, new_name): |
|
981 |
if self.single == old_name: |
|
982 |
self.single = new_name |
|
983 |
if self.interval == old_name: |
|
984 |
self.interval = new_name |
|
985 |
for instance in self.getpouInstance(): |
|
986 |
instance.updateElementName(old_name, new_name) |
|
987 |
setattr(cls, "updateElementName", updateElementName) |
|
988 |
||
989 |
def updateElementAddress(self, address_model, new_leading): |
|
990 |
if self.single is not None: |
|
991 |
self.single = update_address(self.single, address_model, new_leading) |
|
992 |
if self.interval is not None: |
|
993 |
self.interval = update_address(self.interval, address_model, new_leading) |
|
994 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
995 |
||
996 |
def Search(self, criteria, parent_infos=[]): |
|
997 |
return _Search([("single", self.getsingle()), |
|
998 |
("interval", self.getinterval()), |
|
999 |
("priority", str(self.getpriority()))], |
|
1000 |
criteria, parent_infos) |
|
1001 |
setattr(cls, "Search", Search) |
|
1002 |
||
1003 |
cls = PLCOpenClasses.get("pouInstance", None) |
|
1004 |
if cls: |
|
1005 |
def compatibility(self, tree): |
|
1006 |
if tree.hasAttribute("type"): |
|
1007 |
NodeRenameAttr(tree, "type", "typeName") |
|
1008 |
setattr(cls, "compatibility", compatibility) |
|
1009 |
||
1010 |
def updateElementName(self, old_name, new_name): |
|
1011 |
if self.typeName == old_name: |
|
1012 |
self.typeName = new_name |
|
1013 |
setattr(cls, "updateElementName", updateElementName) |
|
1014 |
||
1015 |
def Search(self, criteria, parent_infos=[]): |
|
1016 |
return _Search([("name", self.getname()), |
|
1017 |
("type", self.gettypeName())], |
|
1018 |
criteria, parent_infos) |
|
1019 |
setattr(cls, "Search", Search) |
|
1020 |
||
1021 |
cls = PLCOpenClasses.get("varListPlain_variable", None) |
|
1022 |
if cls: |
|
1023 |
def gettypeAsText(self): |
|
1024 |
vartype_content = self.gettype().getcontent() |
|
1025 |
# Variable type is a user data type |
|
1026 |
if vartype_content["name"] == "derived": |
|
1027 |
return vartype_content["value"].getname() |
|
1028 |
# Variable type is a string type |
|
1029 |
elif vartype_content["name"] in ["string", "wstring"]: |
|
1030 |
return vartype_content["name"].upper() |
|
1031 |
# Variable type is an array |
|
1032 |
elif vartype_content["name"] == "array": |
|
1033 |
base_type = vartype_content["value"].baseType.getcontent() |
|
1034 |
# Array derived directly from a user defined type |
|
1035 |
if base_type["name"] == "derived": |
|
1036 |
basetype_name = base_type["value"].getname() |
|
1037 |
# Array derived directly from a string type |
|
1038 |
elif base_type["name"] in ["string", "wstring"]: |
|
1039 |
basetype_name = base_type["name"].upper() |
|
1040 |
# Array derived directly from an elementary type |
|
1041 |
else: |
|
1042 |
basetype_name = base_type["name"] |
|
1043 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "%s..%s" % (x.getlower(), x.getupper()), vartype_content["value"].getdimension())), basetype_name) |
|
1044 |
# Variable type is an elementary type |
|
1045 |
return vartype_content["name"] |
|
1046 |
setattr(cls, "gettypeAsText", gettypeAsText) |
|
1047 |
||
1048 |
def Search(self, criteria, parent_infos=[]): |
|
1049 |
search_result = _Search([("name", self.getname()), |
|
1050 |
("type", self.gettypeAsText()), |
|
1051 |
("location", self.getaddress())], |
|
1052 |
criteria, parent_infos) |
|
1053 |
initial = self.getinitialValue() |
|
1054 |
if initial is not None: |
|
1055 |
search_result.extend(_Search([("initial value", initial.getvalue())], criteria, parent_infos)) |
|
1056 |
doc = self.getdocumentation() |
|
1057 |
if doc is not None: |
|
1058 |
search_result.extend(doc.Search(criteria, parent_infos + ["documentation"])) |
|
1059 |
return search_result |
|
1060 |
setattr(cls, "Search", Search) |
|
1061 |
||
1062 |
cls = PLCOpenClasses.get("project_types", None) |
|
1063 |
if cls: |
|
1064 |
def getdataTypeElements(self): |
|
1065 |
return self.dataTypes.getdataType() |
|
1066 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
1067 |
||
1068 |
def getdataTypeElement(self, name): |
|
1069 |
elements = self.dataTypes.getdataType() |
|
1070 |
for element in elements: |
|
1071 |
if element.getname() == name: |
|
1072 |
return element |
|
1073 |
return None |
|
1074 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
|
1075 |
||
1076 |
def appenddataTypeElement(self, name): |
|
1077 |
new_datatype = PLCOpenClasses["dataTypes_dataType"]() |
|
1078 |
new_datatype.setname(name) |
|
1079 |
new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None}) |
|
1080 |
self.dataTypes.appenddataType(new_datatype) |
|
1081 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
|
1082 |
||
1083 |
def insertdataTypeElement(self, index, dataType): |
|
1084 |
self.dataTypes.insertdataType(index, dataType) |
|
1085 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
1086 |
||
1087 |
def removedataTypeElement(self, name): |
|
1088 |
found = False |
|
1089 |
for idx, element in enumerate(self.dataTypes.getdataType()): |
|
1090 |
if element.getname() == name: |
|
1091 |
self.dataTypes.removedataType(idx) |
|
1092 |
found = True |
|
1093 |
break |
|
1094 |
if not found: |
|
1095 |
raise ValueError, _("\"%s\" Data Type doesn't exist !!!")%name |
|
1096 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
|
1097 |
||
1098 |
def getpouElements(self): |
|
1099 |
return self.pous.getpou() |
|
1100 |
setattr(cls, "getpouElements", getpouElements) |
|
1101 |
||
1102 |
def getpouElement(self, name): |
|
1103 |
elements = self.pous.getpou() |
|
1104 |
for element in elements: |
|
1105 |
if element.getname() == name: |
|
1106 |
return element |
|
1107 |
return None |
|
1108 |
setattr(cls, "getpouElement", getpouElement) |
|
1109 |
||
1110 |
def appendpouElement(self, name, pou_type, body_type): |
|
1111 |
for element in self.pous.getpou(): |
|
1112 |
if element.getname() == name: |
|
1113 |
raise ValueError, _("\"%s\" POU already exists !!!")%name |
|
1114 |
new_pou = PLCOpenClasses["pous_pou"]() |
|
1115 |
new_pou.setname(name) |
|
1116 |
new_pou.setpouType(pou_type) |
|
1117 |
new_pou.appendbody(PLCOpenClasses["body"]()) |
|
1118 |
new_pou.setbodyType(body_type) |
|
1119 |
self.pous.appendpou(new_pou) |
|
1120 |
setattr(cls, "appendpouElement", appendpouElement) |
|
1121 |
||
1122 |
def insertpouElement(self, index, pou): |
|
1123 |
self.pous.insertpou(index, pou) |
|
1124 |
setattr(cls, "insertpouElement", insertpouElement) |
|
1125 |
||
1126 |
def removepouElement(self, name): |
|
1127 |
found = False |
|
1128 |
for idx, element in enumerate(self.pous.getpou()): |
|
1129 |
if element.getname() == name: |
|
1130 |
self.pous.removepou(idx) |
|
1131 |
found = True |
|
1132 |
break |
|
1133 |
if not found: |
|
1134 |
raise ValueError, _("\"%s\" POU doesn't exist !!!")%name |
|
1135 |
setattr(cls, "removepouElement", removepouElement) |
|
1136 |
||
1137 |
def Search(self, criteria, parent_infos=[]): |
|
1138 |
search_result = [] |
|
1139 |
filter = criteria["filter"] |
|
1140 |
for datatype in self.dataTypes.getdataType(): |
|
1141 |
search_result.extend(datatype.Search(criteria, parent_infos)) |
|
1142 |
for pou in self.pous.getpou(): |
|
1143 |
search_result.extend(pou.Search(criteria, parent_infos)) |
|
1144 |
return search_result |
|
1145 |
setattr(cls, "Search", Search) |
|
1146 |
||
1147 |
def _updateBaseTypeElementName(self, old_name, new_name): |
|
1148 |
self.baseType.updateElementName(old_name, new_name) |
|
1149 |
||
1150 |
cls = PLCOpenClasses.get("dataTypes_dataType", None) |
|
1151 |
if cls: |
|
1152 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1153 |
||
1154 |
def Search(self, criteria, parent_infos=[]): |
|
1155 |
search_result = [] |
|
1156 |
filter = criteria["filter"] |
|
1157 |
if filter == "all" or "datatype" in filter: |
|
1158 |
parent_infos = parent_infos + ["D::%s" % self.getname()] |
|
1159 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
|
1160 |
search_result.extend(self.baseType.Search(criteria, parent_infos)) |
|
1161 |
if self.initialValue is not None: |
|
1162 |
search_result.extend(_Search([("initial", self.initialValue.getvalue())], criteria, parent_infos)) |
|
1163 |
return search_result |
|
1164 |
setattr(cls, "Search", Search) |
|
1165 |
||
1166 |
cls = PLCOpenClasses.get("dataType", None) |
|
1167 |
if cls: |
|
1168 |
||
1169 |
def updateElementName(self, old_name, new_name): |
|
1170 |
if self.content["name"] in ["derived", "array", "subrangeSigned", "subrangeUnsigned"]: |
|
1171 |
self.content["value"].updateElementName(old_name, new_name) |
|
1172 |
elif self.content["name"] == "struct": |
|
1173 |
for element in self.content["value"].getvariable(): |
|
1174 |
element_type = element.type.updateElementName(old_name, new_name) |
|
1175 |
setattr(cls, "updateElementName", updateElementName) |
|
1176 |
||
1177 |
def Search(self, criteria, parent_infos=[]): |
|
1178 |
search_result = [] |
|
1179 |
if self.content["name"] in ["derived", "array", "enum", "subrangeSigned", "subrangeUnsigned"]: |
|
1180 |
search_result.extend(self.content["value"].Search(criteria, parent_infos)) |
|
1181 |
elif self.content["name"] == "struct": |
|
1182 |
for i, element in enumerate(self.content["value"].getvariable()): |
|
1183 |
search_result.extend(element.Search(criteria, parent_infos + ["struct", i])) |
|
1184 |
else: |
|
1185 |
basetype = self.content["name"] |
|
1186 |
if basetype in ["string", "wstring"]: |
|
1187 |
basetype = basetype.upper() |
|
1188 |
search_result.extend(_Search([("base", basetype)], criteria, parent_infos)) |
|
1189 |
return search_result |
|
1190 |
setattr(cls, "Search", Search) |
|
1191 |
||
1192 |
cls = PLCOpenClasses.get("derivedTypes_array", None) |
|
1193 |
if cls: |
|
1194 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1195 |
||
1196 |
def Search(self, criteria, parent_infos=[]): |
|
1197 |
search_result = self.baseType.Search(criteria, parent_infos) |
|
1198 |
for i, dimension in enumerate(self.getdimension()): |
|
1199 |
search_result.extend(_Search([("lower", dimension.getlower()), |
|
1200 |
("upper", dimension.getupper())], |
|
1201 |
criteria, parent_infos + ["range", i])) |
|
1202 |
return search_result |
|
1203 |
setattr(cls, "Search", Search) |
|
1204 |
||
1205 |
def _SearchInSubrange(self, criteria, parent_infos=[]): |
|
1206 |
search_result = self.baseType.Search(criteria, parent_infos) |
|
1207 |
search_result.extend(_Search([("lower", self.range.getlower()), |
|
1208 |
("upper", self.range.getupper())], |
|
1209 |
criteria, parent_infos)) |
|
1210 |
return search_result |
|
1211 |
||
1212 |
cls = PLCOpenClasses.get("derivedTypes_subrangeSigned", None) |
|
1213 |
if cls: |
|
1214 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1215 |
setattr(cls, "Search", _SearchInSubrange) |
|
1216 |
||
1217 |
cls = PLCOpenClasses.get("derivedTypes_subrangeUnsigned", None) |
|
1218 |
if cls: |
|
1219 |
setattr(cls, "updateElementName", _updateBaseTypeElementName) |
|
1220 |
setattr(cls, "Search", _SearchInSubrange) |
|
1221 |
||
1222 |
cls = PLCOpenClasses.get("derivedTypes_enum", None) |
|
1223 |
if cls: |
|
1224 |
||
1225 |
def updateElementName(self, old_name, new_name): |
|
1226 |
pass |
|
1227 |
setattr(cls, "updateElementName", updateElementName) |
|
1228 |
||
1229 |
def Search(self, criteria, parent_infos=[]): |
|
1230 |
search_result = [] |
|
1231 |
for i, value in enumerate(self.values.getvalue()): |
|
1232 |
for result in TestTextElement(value.getname(), criteria): |
|
1233 |
search_result.append((tuple(parent_infos + ["value", i]),) + result) |
|
1234 |
return search_result |
|
1235 |
setattr(cls, "Search", Search) |
|
1236 |
||
1237 |
cls = PLCOpenClasses.get("pous_pou", None) |
|
1238 |
if cls: |
|
1239 |
||
1240 |
def setdescription(self, description): |
|
1241 |
doc = self.getdocumentation() |
|
1242 |
if doc is None: |
|
1243 |
doc = PLCOpenClasses["formattedText"]() |
|
1244 |
self.setdocumentation(doc) |
|
1245 |
doc.settext(description) |
|
1246 |
setattr(cls, "setdescription", setdescription) |
|
1247 |
||
1248 |
def getdescription(self): |
|
1249 |
doc = self.getdocumentation() |
|
1250 |
if doc is not None: |
|
1251 |
return doc.gettext() |
|
1252 |
return "" |
|
1253 |
setattr(cls, "getdescription", getdescription) |
|
1254 |
||
1255 |
def setbodyType(self, type): |
|
1256 |
if len(self.body) > 0: |
|
1257 |
if type == "IL": |
|
1258 |
self.body[0].setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
1259 |
elif type == "ST": |
|
1260 |
self.body[0].setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1261 |
elif type == "LD": |
|
1262 |
self.body[0].setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
1263 |
elif type == "FBD": |
|
1264 |
self.body[0].setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
1265 |
elif type == "SFC": |
|
1266 |
self.body[0].setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
1267 |
else: |
|
1268 |
raise ValueError, "%s isn't a valid body type!"%type |
|
1269 |
setattr(cls, "setbodyType", setbodyType) |
|
1270 |
||
1271 |
def getbodyType(self): |
|
1272 |
if len(self.body) > 0: |
|
1273 |
return self.body[0].getcontent()["name"] |
|
1274 |
setattr(cls, "getbodyType", getbodyType) |
|
1275 |
||
1276 |
def resetexecutionOrder(self): |
|
1277 |
if len(self.body) > 0: |
|
1278 |
self.body[0].resetexecutionOrder() |
|
1279 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1280 |
||
1281 |
def compileexecutionOrder(self): |
|
1282 |
if len(self.body) > 0: |
|
1283 |
self.body[0].compileexecutionOrder() |
|
1284 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1285 |
||
1286 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1287 |
if len(self.body) > 0: |
|
1288 |
self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
|
1289 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1290 |
||
1291 |
def addinstance(self, name, instance): |
|
1292 |
if len(self.body) > 0: |
|
1293 |
self.body[0].appendcontentInstance(name, instance) |
|
1294 |
setattr(cls, "addinstance", addinstance) |
|
1295 |
||
1296 |
def getinstances(self): |
|
1297 |
if len(self.body) > 0: |
|
1298 |
return self.body[0].getcontentInstances() |
|
1299 |
return [] |
|
1300 |
setattr(cls, "getinstances", getinstances) |
|
1301 |
||
1302 |
def getinstance(self, id): |
|
1303 |
if len(self.body) > 0: |
|
1304 |
return self.body[0].getcontentInstance(id) |
|
1305 |
return None |
|
1306 |
setattr(cls, "getinstance", getinstance) |
|
1307 |
||
1308 |
def getrandomInstance(self, exclude): |
|
1309 |
if len(self.body) > 0: |
|
1310 |
return self.body[0].getcontentRandomInstance(exclude) |
|
1311 |
return None |
|
1312 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1313 |
||
1314 |
def getinstanceByName(self, name): |
|
1315 |
if len(self.body) > 0: |
|
1316 |
return self.body[0].getcontentInstanceByName(name) |
|
1317 |
return None |
|
1318 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1319 |
||
1320 |
def removeinstance(self, id): |
|
1321 |
if len(self.body) > 0: |
|
1322 |
self.body[0].removecontentInstance(id) |
|
1323 |
setattr(cls, "removeinstance", removeinstance) |
|
1324 |
||
1325 |
def settext(self, text): |
|
1326 |
if len(self.body) > 0: |
|
1327 |
self.body[0].settext(text) |
|
1328 |
setattr(cls, "settext", settext) |
|
1329 |
||
1330 |
def gettext(self): |
|
1331 |
if len(self.body) > 0: |
|
1332 |
return self.body[0].gettext() |
|
1333 |
return "" |
|
1334 |
setattr(cls, "gettext", gettext) |
|
1335 |
||
1336 |
def getvars(self): |
|
1337 |
vars = [] |
|
1338 |
if self.interface is not None: |
|
1339 |
reverse_types = {} |
|
1340 |
for name, value in VarTypes.items(): |
|
1341 |
reverse_types[value] = name |
|
1342 |
for varlist in self.interface.getcontent(): |
|
1343 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
|
1344 |
return vars |
|
1345 |
setattr(cls, "getvars", getvars) |
|
1346 |
||
1347 |
def setvars(self, vars): |
|
1348 |
if self.interface is None: |
|
1349 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
1350 |
self.interface.setcontent([]) |
|
1351 |
for vartype, varlist in vars: |
|
1352 |
self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
|
1353 |
setattr(cls, "setvars", setvars) |
|
1354 |
||
1355 |
def addpouLocalVar(self, type, name, location="", description=""): |
|
1356 |
self.addpouVar(type, name, location=location, description=description) |
|
1357 |
setattr(cls, "addpouLocalVar", addpouLocalVar) |
|
1358 |
||
1359 |
def addpouExternalVar(self, type, name): |
|
1360 |
self.addpouVar(type, name, "externalVars") |
|
1361 |
setattr(cls, "addpouExternalVar", addpouExternalVar) |
|
1362 |
||
1363 |
def addpouVar(self, type, name, var_class="localVars", location="", description=""): |
|
1364 |
if self.interface is None: |
|
1365 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
1366 |
content = self.interface.getcontent() |
|
1367 |
if len(content) == 0 or content[-1]["name"] != var_class: |
|
1368 |
content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
|
1369 |
else: |
|
1370 |
varlist = content[-1]["value"] |
|
1371 |
variables = varlist.getvariable() |
|
1372 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
1373 |
content.append({"name" : var_class, "value" : PLCOpenClasses["interface_%s" % var_class]()}) |
|
1374 |
var = PLCOpenClasses["varListPlain_variable"]() |
|
1375 |
var.setname(name) |
|
1376 |
var_type = PLCOpenClasses["dataType"]() |
|
1377 |
if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
|
1378 |
if type == "STRING": |
|
1379 |
var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
|
1380 |
elif type == "WSTRING": |
|
1381 |
var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
|
1382 |
else: |
|
1383 |
var_type.setcontent({"name" : type, "value" : None}) |
|
1384 |
else: |
|
1385 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
|
1386 |
derived_type.setname(type) |
|
1387 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
|
1388 |
var.settype(var_type) |
|
1389 |
if location != "": |
|
1390 |
var.setaddress(location) |
|
1391 |
if description != "": |
|
1392 |
ft = PLCOpenClasses["formattedText"]() |
|
1393 |
ft.settext(description) |
|
1394 |
var.setdocumentation(ft) |
|
1395 |
||
1396 |
content[-1]["value"].appendvariable(var) |
|
1397 |
setattr(cls, "addpouVar", addpouVar) |
|
1398 |
||
1399 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
|
1400 |
if self.interface is not None: |
|
1401 |
content = self.interface.getcontent() |
|
1402 |
for varlist in content: |
|
1403 |
variables = varlist["value"].getvariable() |
|
1404 |
for var in variables: |
|
1405 |
if var.getname() == old_name: |
|
1406 |
vartype_content = var.gettype().getcontent() |
|
1407 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
|
1408 |
var.setname(new_name) |
|
1409 |
vartype_content["value"].setname(new_type) |
|
1410 |
return |
|
1411 |
setattr(cls, "changepouVar", changepouVar) |
|
1412 |
||
1413 |
def removepouVar(self, type, name): |
|
1414 |
if self.interface is not None: |
|
1415 |
content = self.interface.getcontent() |
|
1416 |
for varlist in content: |
|
1417 |
variables = varlist["value"].getvariable() |
|
1418 |
for var in variables: |
|
1419 |
if var.getname() == name: |
|
1420 |
vartype_content = var.gettype().getcontent() |
|
1421 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
|
1422 |
variables.remove(var) |
|
1423 |
break |
|
1424 |
if len(varlist["value"].getvariable()) == 0: |
|
1425 |
content.remove(varlist) |
|
1426 |
break |
|
1427 |
setattr(cls, "removepouVar", removepouVar) |
|
1428 |
||
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1429 |
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
|
1430 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
814 | 1431 |
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
|
1432 |
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
|
1433 |
(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
|
1434 |
block_type and instance.gettypeName() == block_type)): |
814 | 1435 |
return True |
1436 |
if self.transitions: |
|
1437 |
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
|
1438 |
result = transition.hasblock(name, block_type) |
814 | 1439 |
if result: |
1440 |
return result |
|
1441 |
if self.actions: |
|
1442 |
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
|
1443 |
result = action.hasblock(name, block_type) |
814 | 1444 |
if result: |
1445 |
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
|
1446 |
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
|
1447 |
return self.body[0].hasblock(block_type) |
814 | 1448 |
return False |
1449 |
setattr(cls, "hasblock", hasblock) |
|
1450 |
||
1451 |
def addtransition(self, name, type): |
|
1452 |
if not self.transitions: |
|
1453 |
self.addtransitions() |
|
1454 |
self.transitions.settransition([]) |
|
1455 |
transition = PLCOpenClasses["transitions_transition"]() |
|
1456 |
transition.setname(name) |
|
1457 |
transition.setbodyType(type) |
|
1458 |
if type == "ST": |
|
1459 |
transition.settext(":= ;") |
|
1460 |
elif type == "IL": |
|
1461 |
transition.settext("\tST\t%s"%name) |
|
1462 |
self.transitions.appendtransition(transition) |
|
1463 |
setattr(cls, "addtransition", addtransition) |
|
1464 |
||
1465 |
def gettransition(self, name): |
|
1466 |
if self.transitions: |
|
1467 |
for transition in self.transitions.gettransition(): |
|
1468 |
if transition.getname() == name: |
|
1469 |
return transition |
|
1470 |
return None |
|
1471 |
setattr(cls, "gettransition", gettransition) |
|
1472 |
||
1473 |
def gettransitionList(self): |
|
1474 |
if self.transitions: |
|
1475 |
return self.transitions.gettransition() |
|
1476 |
return [] |
|
1477 |
setattr(cls, "gettransitionList", gettransitionList) |
|
1478 |
||
1479 |
def removetransition(self, name): |
|
1480 |
if self.transitions: |
|
1481 |
transitions = self.transitions.gettransition() |
|
1482 |
i = 0 |
|
1483 |
removed = False |
|
1484 |
while i < len(transitions) and not removed: |
|
1485 |
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
|
1486 |
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
|
1487 |
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
|
1488 |
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
|
1489 |
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
|
1490 |
instance.getinstanceName()) |
814 | 1491 |
transitions.pop(i) |
1492 |
removed = True |
|
1493 |
i += 1 |
|
1494 |
if not removed: |
|
1495 |
raise ValueError, _("Transition with name %s doesn't exist!")%name |
|
1496 |
setattr(cls, "removetransition", removetransition) |
|
1497 |
||
1498 |
def addaction(self, name, type): |
|
1499 |
if not self.actions: |
|
1500 |
self.addactions() |
|
1501 |
self.actions.setaction([]) |
|
1502 |
action = PLCOpenClasses["actions_action"]() |
|
1503 |
action.setname(name) |
|
1504 |
action.setbodyType(type) |
|
1505 |
self.actions.appendaction(action) |
|
1506 |
setattr(cls, "addaction", addaction) |
|
1507 |
||
1508 |
def getaction(self, name): |
|
1509 |
if self.actions: |
|
1510 |
for action in self.actions.getaction(): |
|
1511 |
if action.getname() == name: |
|
1512 |
return action |
|
1513 |
return None |
|
1514 |
setattr(cls, "getaction", getaction) |
|
1515 |
||
1516 |
def getactionList(self): |
|
1517 |
if self.actions: |
|
1518 |
return self.actions.getaction() |
|
1519 |
return [] |
|
1520 |
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
|
1521 |
|
814 | 1522 |
def removeaction(self, name): |
1523 |
if self.actions: |
|
1524 |
actions = self.actions.getaction() |
|
1525 |
i = 0 |
|
1526 |
removed = False |
|
1527 |
while i < len(actions) and not removed: |
|
1528 |
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
|
1529 |
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
|
1530 |
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
|
1531 |
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
|
1532 |
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
|
1533 |
instance.getinstanceName()) |
814 | 1534 |
actions.pop(i) |
1535 |
removed = True |
|
1536 |
i += 1 |
|
1537 |
if not removed: |
|
1538 |
raise ValueError, _("Action with name %s doesn't exist!")%name |
|
1539 |
setattr(cls, "removeaction", removeaction) |
|
1540 |
||
1541 |
def updateElementName(self, old_name, new_name): |
|
1542 |
if self.interface: |
|
1543 |
for content in self.interface.getcontent(): |
|
1544 |
for var in content["value"].getvariable(): |
|
1545 |
var_address = var.getaddress() |
|
1546 |
if var_address is not None: |
|
1547 |
if var_address == old_name: |
|
1548 |
var.setaddress(new_name) |
|
1549 |
if var.getname() == old_name: |
|
1550 |
var.setname(new_name) |
|
1551 |
var_type_content = var.gettype().getcontent() |
|
1552 |
if var_type_content["name"] == "derived": |
|
1553 |
if var_type_content["value"].getname() == old_name: |
|
1554 |
var_type_content["value"].setname(new_name) |
|
1555 |
self.body[0].updateElementName(old_name, new_name) |
|
1556 |
for action in self.getactionList(): |
|
1557 |
action.updateElementName(old_name, new_name) |
|
1558 |
for transition in self.gettransitionList(): |
|
1559 |
transition.updateElementName(old_name, new_name) |
|
1560 |
setattr(cls, "updateElementName", updateElementName) |
|
1561 |
||
1562 |
def updateElementAddress(self, address_model, new_leading): |
|
1563 |
if self.interface: |
|
1564 |
for content in self.interface.getcontent(): |
|
1565 |
for var in content["value"].getvariable(): |
|
1566 |
var_address = var.getaddress() |
|
1567 |
if var_address is not None: |
|
1568 |
var.setaddress(update_address(var_address, address_model, new_leading)) |
|
1569 |
self.body[0].updateElementAddress(address_model, new_leading) |
|
1570 |
for action in self.getactionList(): |
|
1571 |
action.updateElementAddress(address_model, new_leading) |
|
1572 |
for transition in self.gettransitionList(): |
|
1573 |
transition.updateElementAddress(address_model, new_leading) |
|
1574 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
1575 |
||
1576 |
def removeVariableByAddress(self, address): |
|
1577 |
if self.interface: |
|
1578 |
for content in self.interface.getcontent(): |
|
1579 |
variables = content["value"].getvariable() |
|
1580 |
for i in xrange(len(variables)-1, -1, -1): |
|
1581 |
if variables[i].getaddress() == address: |
|
1582 |
variables.pop(i) |
|
1583 |
setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
|
1584 |
||
1585 |
def removeVariableByFilter(self, address_model): |
|
1586 |
if self.interface: |
|
1587 |
for content in self.interface.getcontent(): |
|
1588 |
variables = content["value"].getvariable() |
|
1589 |
for i in xrange(len(variables)-1, -1, -1): |
|
1590 |
var_address = variables[i].getaddress() |
|
1591 |
if var_address is not None: |
|
1592 |
result = address_model.match(var_address) |
|
1593 |
if result is not None: |
|
1594 |
variables.pop(i) |
|
1595 |
setattr(cls, "removeVariableByFilter", removeVariableByFilter) |
|
1596 |
||
1597 |
def Search(self, criteria, parent_infos=[]): |
|
1598 |
search_result = [] |
|
1599 |
filter = criteria["filter"] |
|
1600 |
if filter == "all" or self.getpouType() in filter: |
|
1601 |
parent_infos = parent_infos + ["P::%s" % self.getname()] |
|
1602 |
search_result.extend(_Search([("name", self.getname())], criteria, parent_infos)) |
|
1603 |
if self.interface is not None: |
|
1604 |
var_number = 0 |
|
1605 |
for content in self.interface.getcontent(): |
|
1606 |
variable_type = searchResultVarTypes.get(content["value"], "var_local") |
|
1607 |
variables = content["value"].getvariable() |
|
1608 |
for modifier, has_modifier in [("constant", content["value"].getconstant()), |
|
1609 |
("retain", content["value"].getretain()), |
|
1610 |
("non_retain", content["value"].getnonretain())]: |
|
1611 |
if has_modifier: |
|
1612 |
for result in TestTextElement(modifier, criteria): |
|
1613 |
search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result) |
|
1614 |
break |
|
1615 |
for variable in variables: |
|
1616 |
search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number])) |
|
1617 |
var_number += 1 |
|
1618 |
if len(self.body) > 0: |
|
1619 |
search_result.extend(self.body[0].Search(criteria, parent_infos)) |
|
1620 |
for action in self.getactionList(): |
|
1621 |
search_result.extend(action.Search(criteria, parent_infos)) |
|
1622 |
for transition in self.gettransitionList(): |
|
1623 |
search_result.extend(transition.Search(criteria, parent_infos)) |
|
1624 |
return search_result |
|
1625 |
setattr(cls, "Search", Search) |
|
1626 |
||
1627 |
def setbodyType(self, type): |
|
1628 |
if type == "IL": |
|
1629 |
self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
1630 |
elif type == "ST": |
|
1631 |
self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1632 |
elif type == "LD": |
|
1633 |
self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
1634 |
elif type == "FBD": |
|
1635 |
self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
1636 |
elif type == "SFC": |
|
1637 |
self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
1638 |
else: |
|
1639 |
raise ValueError, "%s isn't a valid body type!"%type |
|
1640 |
||
1641 |
def getbodyType(self): |
|
1642 |
return self.body.getcontent()["name"] |
|
1643 |
||
1644 |
def resetexecutionOrder(self): |
|
1645 |
self.body.resetexecutionOrder() |
|
1646 |
||
1647 |
def compileexecutionOrder(self): |
|
1648 |
self.body.compileexecutionOrder() |
|
1649 |
||
1650 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1651 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
1652 |
||
1653 |
def addinstance(self, name, instance): |
|
1654 |
self.body.appendcontentInstance(name, instance) |
|
1655 |
||
1656 |
def getinstances(self): |
|
1657 |
return self.body.getcontentInstances() |
|
1658 |
||
1659 |
def getinstance(self, id): |
|
1660 |
return self.body.getcontentInstance(id) |
|
1661 |
||
1662 |
def getrandomInstance(self, exclude): |
|
1663 |
return self.body.getcontentRandomInstance(exclude) |
|
1664 |
||
1665 |
def getinstanceByName(self, name): |
|
1666 |
return self.body.getcontentInstanceByName(name) |
|
1667 |
||
1668 |
def removeinstance(self, id): |
|
1669 |
self.body.removecontentInstance(id) |
|
1670 |
||
1671 |
def settext(self, text): |
|
1672 |
self.body.settext(text) |
|
1673 |
||
1674 |
def gettext(self): |
|
1675 |
return self.body.gettext() |
|
1676 |
||
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1677 |
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
|
1678 |
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
|
1679 |
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
|
1680 |
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
|
1681 |
(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
|
1682 |
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
|
1683 |
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
|
1684 |
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
|
1685 |
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
|
1686 |
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
|
1687 |
|
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1688 |
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
|
1689 |
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
|
1690 |
|
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1691 |
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
|
1692 |
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
|
1693 |
|
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1694 |
|
814 | 1695 |
cls = PLCOpenClasses.get("transitions_transition", None) |
1696 |
if cls: |
|
1697 |
setattr(cls, "setbodyType", setbodyType) |
|
1698 |
setattr(cls, "getbodyType", getbodyType) |
|
1699 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1700 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1701 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1702 |
setattr(cls, "addinstance", addinstance) |
|
1703 |
setattr(cls, "getinstances", getinstances) |
|
1704 |
setattr(cls, "getinstance", getinstance) |
|
1705 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1706 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1707 |
setattr(cls, "removeinstance", removeinstance) |
|
1708 |
setattr(cls, "settext", settext) |
|
1709 |
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
|
1710 |
setattr(cls, "hasblock", hasblock) |
814 | 1711 |
setattr(cls, "updateElementName", updateElementName) |
1712 |
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
|
1713 |
|
814 | 1714 |
def Search(self, criteria, parent_infos): |
1715 |
search_result = [] |
|
1716 |
parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
|
1717 |
for result in TestTextElement(self.getname(), criteria): |
|
1718 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
|
1719 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
|
1720 |
return search_result |
|
1721 |
setattr(cls, "Search", Search) |
|
1722 |
||
1723 |
cls = PLCOpenClasses.get("actions_action", None) |
|
1724 |
if cls: |
|
1725 |
setattr(cls, "setbodyType", setbodyType) |
|
1726 |
setattr(cls, "getbodyType", getbodyType) |
|
1727 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1728 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1729 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1730 |
setattr(cls, "addinstance", addinstance) |
|
1731 |
setattr(cls, "getinstances", getinstances) |
|
1732 |
setattr(cls, "getinstance", getinstance) |
|
1733 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1734 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1735 |
setattr(cls, "removeinstance", removeinstance) |
|
1736 |
setattr(cls, "settext", settext) |
|
1737 |
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
|
1738 |
setattr(cls, "hasblock", hasblock) |
814 | 1739 |
setattr(cls, "updateElementName", updateElementName) |
1740 |
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
|
1741 |
|
814 | 1742 |
def Search(self, criteria, parent_infos): |
1743 |
search_result = [] |
|
1744 |
parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())] |
|
1745 |
for result in TestTextElement(self.getname(), criteria): |
|
1746 |
search_result.append((tuple(parent_infos + ["name"]),) + result) |
|
1747 |
search_result.extend(self.body.Search(criteria, parent_infos)) |
|
1748 |
return search_result |
|
1749 |
setattr(cls, "Search", Search) |
|
1750 |
||
1751 |
cls = PLCOpenClasses.get("body", None) |
|
1752 |
if cls: |
|
1753 |
cls.currentExecutionOrderId = 0 |
|
1754 |
||
1755 |
def resetcurrentExecutionOrderId(self): |
|
1756 |
object.__setattr__(self, "currentExecutionOrderId", 0) |
|
1757 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
|
1758 |
||
1759 |
def getnewExecutionOrderId(self): |
|
1760 |
object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
|
1761 |
return self.currentExecutionOrderId |
|
1762 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
|
1763 |
||
1764 |
def resetexecutionOrder(self): |
|
1765 |
if self.content["name"] == "FBD": |
|
1766 |
for element in self.content["value"].getcontent(): |
|
1767 |
if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
|
1768 |
PLCOpenClasses.get("commonObjects_connector", None), |
|
1769 |
PLCOpenClasses.get("commonObjects_continuation", None))): |
|
1770 |
element["value"].setexecutionOrderId(0) |
|
1771 |
else: |
|
1772 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
|
1773 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1774 |
||
1775 |
def compileexecutionOrder(self): |
|
1776 |
if self.content["name"] == "FBD": |
|
1777 |
self.resetexecutionOrder() |
|
1778 |
self.resetcurrentExecutionOrderId() |
|
1779 |
for element in self.content["value"].getcontent(): |
|
1780 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
|
1781 |
connections = element["value"].connectionPointIn.getconnections() |
|
1782 |
if connections and len(connections) == 1: |
|
1783 |
self.compileelementExecutionOrder(connections[0]) |
|
1784 |
element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
|
1785 |
else: |
|
1786 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
|
1787 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1788 |
||
1789 |
def compileelementExecutionOrder(self, link): |
|
1790 |
if self.content["name"] == "FBD": |
|
1791 |
localid = link.getrefLocalId() |
|
1792 |
instance = self.getcontentInstance(localid) |
|
1793 |
if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
|
1794 |
for variable in instance.inputVariables.getvariable(): |
|
1795 |
connections = variable.connectionPointIn.getconnections() |
|
1796 |
if connections and len(connections) == 1: |
|
1797 |
self.compileelementExecutionOrder(connections[0]) |
|
1798 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
|
1799 |
elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
|
1800 |
name = instance.getname() |
|
1801 |
for tmp_instance in self.getcontentInstances(): |
|
1802 |
if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
|
1803 |
connections = tmp_instance.connectionPointIn.getconnections() |
|
1804 |
if connections and len(connections) == 1: |
|
1805 |
self.compileelementExecutionOrder(connections[0]) |
|
1806 |
else: |
|
1807 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
|
1808 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
|
1809 |
||
1810 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1811 |
if self.content["name"] == "FBD": |
|
1812 |
old_executionOrder = instance.getexecutionOrderId() |
|
1813 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
|
1814 |
for element in self.content["value"].getcontent(): |
|
1815 |
if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
|
1816 |
element_executionOrder = element["value"].getexecutionOrderId() |
|
1817 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
|
1818 |
element["value"].setexecutionOrderId(element_executionOrder - 1) |
|
1819 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
|
1820 |
element["value"].setexecutionOrderId(element_executionOrder + 1) |
|
1821 |
instance.setexecutionOrderId(new_executionOrder) |
|
1822 |
else: |
|
1823 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
|
1824 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1825 |
||
1826 |
def appendcontentInstance(self, name, instance): |
|
1827 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1828 |
self.content["value"].appendcontent({"name" : name, "value" : instance}) |
|
1829 |
else: |
|
1830 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1831 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
|
1832 |
||
1833 |
def getcontentInstances(self): |
|
1834 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1835 |
instances = [] |
|
1836 |
for element in self.content["value"].getcontent(): |
|
1837 |
instances.append(element["value"]) |
|
1838 |
return instances |
|
1839 |
else: |
|
1840 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1841 |
setattr(cls, "getcontentInstances", getcontentInstances) |
|
1842 |
||
1843 |
def getcontentInstance(self, id): |
|
1844 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1845 |
for element in self.content["value"].getcontent(): |
|
1846 |
if element["value"].getlocalId() == id: |
|
1847 |
return element["value"] |
|
1848 |
return None |
|
1849 |
else: |
|
1850 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1851 |
setattr(cls, "getcontentInstance", getcontentInstance) |
|
1852 |
||
1853 |
def getcontentRandomInstance(self, exclude): |
|
1854 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1855 |
for element in self.content["value"].getcontent(): |
|
1856 |
if element["value"].getlocalId() not in exclude: |
|
1857 |
return element["value"] |
|
1858 |
return None |
|
1859 |
else: |
|
1860 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1861 |
setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
|
1862 |
||
1863 |
def getcontentInstanceByName(self, name): |
|
1864 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1865 |
for element in self.content["value"].getcontent(): |
|
1866 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
|
1867 |
return element["value"] |
|
1868 |
else: |
|
1869 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
|
1870 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
|
1871 |
||
1872 |
def removecontentInstance(self, id): |
|
1873 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
1874 |
i = 0 |
|
1875 |
removed = False |
|
1876 |
elements = self.content["value"].getcontent() |
|
1877 |
while i < len(elements) and not removed: |
|
1878 |
if elements[i]["value"].getlocalId() == id: |
|
1879 |
self.content["value"].removecontent(i) |
|
1880 |
removed = True |
|
1881 |
i += 1 |
|
1882 |
if not removed: |
|
1883 |
raise ValueError, _("Instance with id %d doesn't exist!")%id |
|
1884 |
else: |
|
1885 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
1886 |
setattr(cls, "removecontentInstance", removecontentInstance) |
|
1887 |
||
1888 |
def settext(self, text): |
|
1889 |
if self.content["name"] in ["IL","ST"]: |
|
1890 |
self.content["value"].settext(text) |
|
1891 |
else: |
|
1892 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
|
1893 |
setattr(cls, "settext", settext) |
|
1894 |
||
1895 |
def gettext(self): |
|
1896 |
if self.content["name"] in ["IL","ST"]: |
|
1897 |
return self.content["value"].gettext() |
|
1898 |
else: |
|
1899 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
|
1900 |
setattr(cls, "gettext", gettext) |
|
1901 |
||
1142
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1902 |
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
|
1903 |
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
|
1904 |
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
|
1905 |
else: |
8ded55ada6d6
Fixed functions used by one or more POU not showing question dialog when trying to delete
Laurent Bessard
parents:
990
diff
changeset
|
1906 |
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
|
1907 |
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
|
1908 |
|
814 | 1909 |
def updateElementName(self, old_name, new_name): |
1910 |
if self.content["name"] in ["IL", "ST"]: |
|
1911 |
self.content["value"].updateElementName(old_name, new_name) |
|
1912 |
else: |
|
1913 |
for element in self.content["value"].getcontent(): |
|
1914 |
element["value"].updateElementName(old_name, new_name) |
|
1915 |
setattr(cls, "updateElementName", updateElementName) |
|
1916 |
||
1917 |
def updateElementAddress(self, address_model, new_leading): |
|
1918 |
if self.content["name"] in ["IL", "ST"]: |
|
1919 |
self.content["value"].updateElementAddress(address_model, new_leading) |
|
1920 |
else: |
|
1921 |
for element in self.content["value"].getcontent(): |
|
1922 |
element["value"].updateElementAddress(address_model, new_leading) |
|
1923 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
1924 |
||
1925 |
def Search(self, criteria, parent_infos=[]): |
|
1926 |
if self.content["name"] in ["IL", "ST"]: |
|
1927 |
search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0]) |
|
1928 |
else: |
|
1929 |
search_result = [] |
|
1930 |
for element in self.content["value"].getcontent(): |
|
1931 |
search_result.extend(element["value"].Search(criteria, parent_infos)) |
|
1932 |
return search_result |
|
1933 |
setattr(cls, "Search", Search) |
|
1934 |
||
1935 |
def getx(self): |
|
1936 |
return self.position.getx() |
|
1937 |
||
1938 |
def gety(self): |
|
1939 |
return self.position.gety() |
|
1940 |
||
1941 |
def setx(self, x): |
|
1942 |
self.position.setx(x) |
|
1943 |
||
1944 |
def sety(self, y): |
|
1945 |
self.position.sety(y) |
|
1946 |
||
1947 |
def _getBoundingBox(self): |
|
1948 |
return rect(self.getx(), self.gety(), self.getwidth(), self.getheight()) |
|
1949 |
||
1950 |
def _getConnectionsBoundingBox(connectionPointIn): |
|
1951 |
bbox = rect() |
|
1952 |
connections = connectionPointIn.getconnections() |
|
1953 |
if connections is not None: |
|
1954 |
for connection in connections: |
|
1955 |
for x, y in connection.getpoints(): |
|
1956 |
bbox.update(x, y) |
|
1957 |
return bbox |
|
1958 |
||
1959 |
def _getBoundingBoxSingle(self): |
|
1960 |
bbox = _getBoundingBox(self) |
|
1961 |
if self.connectionPointIn is not None: |
|
1962 |
bbox.union(_getConnectionsBoundingBox(self.connectionPointIn)) |
|
1963 |
return bbox |
|
1964 |
||
1965 |
def _getBoundingBoxMultiple(self): |
|
1966 |
bbox = _getBoundingBox(self) |
|
1967 |
for connectionPointIn in self.getconnectionPointIn(): |
|
1968 |
bbox.union(_getConnectionsBoundingBox(connectionPointIn)) |
|
1969 |
return bbox |
|
1970 |
||
1971 |
def _filterConnections(connectionPointIn, localId, connections): |
|
1972 |
in_connections = connectionPointIn.getconnections() |
|
1973 |
if in_connections is not None: |
|
1974 |
to_delete = [] |
|
1975 |
for i, connection in enumerate(in_connections): |
|
1976 |
connected = connection.getrefLocalId() |
|
1977 |
if not connections.has_key((localId, connected)) and \ |
|
1978 |
not connections.has_key((connected, localId)): |
|
1979 |
to_delete.append(i) |
|
1980 |
to_delete.reverse() |
|
1981 |
for i in to_delete: |
|
1982 |
connectionPointIn.removeconnection(i) |
|
1983 |
||
1984 |
def _filterConnectionsSingle(self, connections): |
|
1985 |
if self.connectionPointIn is not None: |
|
1986 |
_filterConnections(self.connectionPointIn, self.localId, connections) |
|
1987 |
||
1988 |
def _filterConnectionsMultiple(self, connections): |
|
1989 |
for connectionPointIn in self.getconnectionPointIn(): |
|
1990 |
_filterConnections(connectionPointIn, self.localId, connections) |
|
1991 |
||
1992 |
def _getconnectionsdefinition(instance, connections_end): |
|
1993 |
id = instance.getlocalId() |
|
1994 |
return dict([((id, end), True) for end in connections_end]) |
|
1995 |
||
1996 |
def _updateConnectionsId(connectionPointIn, translation): |
|
1997 |
connections_end = [] |
|
1998 |
connections = connectionPointIn.getconnections() |
|
1999 |
if connections is not None: |
|
2000 |
for connection in connections: |
|
2001 |
refLocalId = connection.getrefLocalId() |
|
2002 |
new_reflocalId = translation.get(refLocalId, refLocalId) |
|
2003 |
connection.setrefLocalId(new_reflocalId) |
|
2004 |
connections_end.append(new_reflocalId) |
|
2005 |
return connections_end |
|
2006 |
||
2007 |
def _updateConnectionsIdSingle(self, translation): |
|
2008 |
connections_end = [] |
|
2009 |
if self.connectionPointIn is not None: |
|
2010 |
connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
|
2011 |
return _getconnectionsdefinition(self, connections_end) |
|
2012 |
||
2013 |
def _updateConnectionsIdMultiple(self, translation): |
|
2014 |
connections_end = [] |
|
2015 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2016 |
connections_end.extend(_updateConnectionsId(connectionPointIn, translation)) |
|
2017 |
return _getconnectionsdefinition(self, connections_end) |
|
2018 |
||
2019 |
def _translate(self, dx, dy): |
|
2020 |
self.setx(self.getx() + dx) |
|
2021 |
self.sety(self.gety() + dy) |
|
2022 |
||
2023 |
def _translateConnections(connectionPointIn, dx, dy): |
|
2024 |
connections = connectionPointIn.getconnections() |
|
2025 |
if connections is not None: |
|
2026 |
for connection in connections: |
|
2027 |
for position in connection.getposition(): |
|
2028 |
position.setx(position.getx() + dx) |
|
2029 |
position.sety(position.gety() + dy) |
|
2030 |
||
2031 |
def _translateSingle(self, dx, dy): |
|
2032 |
_translate(self, dx, dy) |
|
2033 |
if self.connectionPointIn is not None: |
|
2034 |
_translateConnections(self.connectionPointIn, dx, dy) |
|
2035 |
||
2036 |
def _translateMultiple(self, dx, dy): |
|
2037 |
_translate(self, dx, dy) |
|
2038 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2039 |
_translateConnections(connectionPointIn, dx, dy) |
|
2040 |
||
2041 |
def _updateElementName(self, old_name, new_name): |
|
2042 |
pass |
|
2043 |
||
2044 |
def _updateElementAddress(self, address_model, new_leading): |
|
2045 |
pass |
|
2046 |
||
2047 |
def _SearchInElement(self, criteria, parent_infos=[]): |
|
2048 |
return [] |
|
2049 |
||
2050 |
_connectionsFunctions = { |
|
2051 |
"bbox": {"none": _getBoundingBox, |
|
2052 |
"single": _getBoundingBoxSingle, |
|
2053 |
"multiple": _getBoundingBoxMultiple}, |
|
2054 |
"translate": {"none": _translate, |
|
2055 |
"single": _translateSingle, |
|
2056 |
"multiple": _translateMultiple}, |
|
2057 |
"filter": {"none": lambda self, connections: None, |
|
2058 |
"single": _filterConnectionsSingle, |
|
2059 |
"multiple": _filterConnectionsMultiple}, |
|
2060 |
"update": {"none": lambda self, translation: {}, |
|
2061 |
"single": _updateConnectionsIdSingle, |
|
2062 |
"multiple": _updateConnectionsIdMultiple}, |
|
2063 |
} |
|
2064 |
||
2065 |
def _initElementClass(name, classname, connectionPointInType="none"): |
|
2066 |
ElementNameToClass[name] = classname |
|
2067 |
cls = PLCOpenClasses.get(classname, None) |
|
2068 |
if cls: |
|
2069 |
setattr(cls, "getx", getx) |
|
2070 |
setattr(cls, "gety", gety) |
|
2071 |
setattr(cls, "setx", setx) |
|
2072 |
setattr(cls, "sety", sety) |
|
2073 |
setattr(cls, "updateElementName", _updateElementName) |
|
2074 |
setattr(cls, "updateElementAddress", _updateElementAddress) |
|
2075 |
setattr(cls, "getBoundingBox", _connectionsFunctions["bbox"][connectionPointInType]) |
|
2076 |
setattr(cls, "translate", _connectionsFunctions["translate"][connectionPointInType]) |
|
2077 |
setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
|
2078 |
setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
|
2079 |
setattr(cls, "Search", _SearchInElement) |
|
2080 |
return cls |
|
2081 |
||
2082 |
def _getexecutionOrder(instance, specific_values): |
|
2083 |
executionOrder = instance.getexecutionOrderId() |
|
2084 |
if executionOrder is None: |
|
2085 |
executionOrder = 0 |
|
2086 |
specific_values["executionOrder"] = executionOrder |
|
2087 |
||
2088 |
def _getdefaultmodifiers(instance, infos): |
|
2089 |
infos["negated"] = instance.getnegated() |
|
2090 |
infos["edge"] = instance.getedge() |
|
2091 |
||
2092 |
def _getinputmodifiers(instance, infos): |
|
2093 |
infos["negated"] = instance.getnegatedIn() |
|
2094 |
infos["edge"] = instance.getedgeIn() |
|
2095 |
||
2096 |
def _getoutputmodifiers(instance, infos): |
|
2097 |
infos["negated"] = instance.getnegatedOut() |
|
2098 |
infos["edge"] = instance.getedgeOut() |
|
2099 |
||
2100 |
MODIFIERS_FUNCTIONS = {"default": _getdefaultmodifiers, |
|
2101 |
"input": _getinputmodifiers, |
|
2102 |
"output": _getoutputmodifiers} |
|
2103 |
||
2104 |
def _getconnectioninfos(instance, connection, links=False, modifiers=None, parameter=False): |
|
2105 |
infos = {"position": connection.getrelPositionXY()} |
|
2106 |
if parameter: |
|
2107 |
infos["name"] = instance.getformalParameter() |
|
2108 |
MODIFIERS_FUNCTIONS.get(modifiers, lambda x, y: None)(instance, infos) |
|
2109 |
if links: |
|
2110 |
infos["links"] = [] |
|
2111 |
connections = connection.getconnections() |
|
2112 |
if connections is not None: |
|
2113 |
for link in connections: |
|
2114 |
dic = {"refLocalId": link.getrefLocalId(), |
|
2115 |
"points": link.getpoints(), |
|
2116 |
"formalParameter": link.getformalParameter()} |
|
2117 |
infos["links"].append(dic) |
|
2118 |
return infos |
|
2119 |
||
2120 |
def _getelementinfos(instance): |
|
2121 |
return {"id": instance.getlocalId(), |
|
2122 |
"x": instance.getx(), |
|
2123 |
"y": instance.gety(), |
|
2124 |
"height": instance.getheight(), |
|
2125 |
"width": instance.getwidth(), |
|
2126 |
"specific_values": {}, |
|
2127 |
"inputs": [], |
|
2128 |
"outputs": []} |
|
2129 |
||
2130 |
def _getvariableinfosFunction(type, input, output): |
|
2131 |
def getvariableinfos(self): |
|
2132 |
infos = _getelementinfos(self) |
|
2133 |
infos["type"] = type |
|
2134 |
specific_values = infos["specific_values"] |
|
2135 |
specific_values["name"] = self.getexpression() |
|
2136 |
_getexecutionOrder(self, specific_values) |
|
2137 |
if input and output: |
|
2138 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
|
2139 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
|
2140 |
elif input: |
|
2141 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "default")) |
|
2142 |
elif output: |
|
2143 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
|
2144 |
return infos |
|
2145 |
return getvariableinfos |
|
2146 |
||
2147 |
def _getconnectorinfosFunction(type): |
|
2148 |
def getvariableinfos(self): |
|
2149 |
infos = _getelementinfos(self) |
|
2150 |
infos["type"] = type |
|
2151 |
infos["specific_values"]["name"] = self.getname() |
|
2152 |
if type == "connector": |
|
2153 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2154 |
elif type == "continuation": |
|
2155 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2156 |
return infos |
|
2157 |
return getvariableinfos |
|
2158 |
||
2159 |
def _getpowerrailinfosFunction(type): |
|
2160 |
def getpowerrailinfos(self): |
|
2161 |
infos = _getelementinfos(self) |
|
2162 |
infos["type"] = type |
|
2163 |
if type == "rightPowerRail": |
|
2164 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2165 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
|
2166 |
infos["specific_values"]["connectors"] = len(infos["inputs"]) |
|
2167 |
elif type == "leftPowerRail": |
|
2168 |
for connectionPointOut in self.getconnectionPointOut(): |
|
2169 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
|
2170 |
infos["specific_values"]["connectors"] = len(infos["outputs"]) |
|
2171 |
return infos |
|
2172 |
return getpowerrailinfos |
|
2173 |
||
2174 |
def _getldelementinfosFunction(type): |
|
2175 |
def getldelementinfos(self): |
|
2176 |
infos = _getelementinfos(self) |
|
2177 |
infos["type"] = type |
|
2178 |
specific_values = infos["specific_values"] |
|
2179 |
specific_values["name"] = self.getvariable() |
|
2180 |
_getexecutionOrder(self, specific_values) |
|
2181 |
specific_values["negated"] = self.getnegated() |
|
2182 |
specific_values["edge"] = self.getedge() |
|
2183 |
if type == "coil": |
|
2184 |
specific_values["storage"] = self.getstorage() |
|
2185 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2186 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2187 |
return infos |
|
2188 |
return getldelementinfos |
|
2189 |
||
2190 |
DIVERGENCE_TYPES = {(True, True): "simultaneousDivergence", |
|
2191 |
(True, False): "selectionDivergence", |
|
2192 |
(False, True): "simultaneousConvergence", |
|
2193 |
(False, False): "selectionConvergence"} |
|
2194 |
||
2195 |
def _getdivergenceinfosFunction(divergence, simultaneous): |
|
2196 |
def getdivergenceinfos(self): |
|
2197 |
infos = _getelementinfos(self) |
|
2198 |
infos["type"] = DIVERGENCE_TYPES[(divergence, simultaneous)] |
|
2199 |
if divergence: |
|
2200 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2201 |
for connectionPointOut in self.getconnectionPointOut(): |
|
2202 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
|
2203 |
infos["specific_values"]["connectors"] = len(infos["outputs"]) |
|
2204 |
else: |
|
2205 |
for connectionPointIn in self.getconnectionPointIn(): |
|
2206 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
|
2207 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2208 |
infos["specific_values"]["connectors"] = len(infos["inputs"]) |
|
2209 |
return infos |
|
2210 |
return getdivergenceinfos |
|
2211 |
||
2212 |
cls = _initElementClass("comment", "commonObjects_comment") |
|
2213 |
if cls: |
|
2214 |
def getinfos(self): |
|
2215 |
infos = _getelementinfos(self) |
|
2216 |
infos["type"] = "comment" |
|
2217 |
infos["specific_values"]["content"] = self.getcontentText() |
|
2218 |
return infos |
|
2219 |
setattr(cls, "getinfos", getinfos) |
|
2220 |
||
2221 |
def setcontentText(self, text): |
|
2222 |
self.content.settext(text) |
|
2223 |
setattr(cls, "setcontentText", setcontentText) |
|
2224 |
||
2225 |
def getcontentText(self): |
|
2226 |
return self.content.gettext() |
|
2227 |
setattr(cls, "getcontentText", getcontentText) |
|
2228 |
||
2229 |
def updateElementName(self, old_name, new_name): |
|
2230 |
self.content.updateElementName(old_name, new_name) |
|
2231 |
setattr(cls, "updateElementName", updateElementName) |
|
2232 |
||
2233 |
def updateElementAddress(self, address_model, new_leading): |
|
2234 |
self.content.updateElementAddress(address_model, new_leading) |
|
2235 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2236 |
||
2237 |
def Search(self, criteria, parent_infos=[]): |
|
2238 |
return self.content.Search(criteria, parent_infos + ["comment", self.getlocalId(), "content"]) |
|
2239 |
setattr(cls, "Search", Search) |
|
2240 |
||
2241 |
cls = _initElementClass("block", "fbdObjects_block") |
|
2242 |
if cls: |
|
2243 |
def getBoundingBox(self): |
|
2244 |
bbox = _getBoundingBox(self) |
|
2245 |
for input in self.inputVariables.getvariable(): |
|
2246 |
bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
|
2247 |
return bbox |
|
2248 |
setattr(cls, "getBoundingBox", getBoundingBox) |
|
2249 |
||
2250 |
def getinfos(self): |
|
2251 |
infos = _getelementinfos(self) |
|
2252 |
infos["type"] = self.gettypeName() |
|
2253 |
specific_values = infos["specific_values"] |
|
2254 |
specific_values["name"] = self.getinstanceName() |
|
2255 |
_getexecutionOrder(self, specific_values) |
|
2256 |
for variable in self.inputVariables.getvariable(): |
|
2257 |
infos["inputs"].append(_getconnectioninfos(variable, variable.connectionPointIn, True, "default", True)) |
|
2258 |
for variable in self.outputVariables.getvariable(): |
|
2259 |
infos["outputs"].append(_getconnectioninfos(variable, variable.connectionPointOut, False, "default", True)) |
|
2260 |
return infos |
|
2261 |
setattr(cls, "getinfos", getinfos) |
|
2262 |
||
2263 |
def updateElementName(self, old_name, new_name): |
|
2264 |
if self.typeName == old_name: |
|
2265 |
self.typeName = new_name |
|
2266 |
setattr(cls, "updateElementName", updateElementName) |
|
2267 |
||
2268 |
def filterConnections(self, connections): |
|
2269 |
for input in self.inputVariables.getvariable(): |
|
2270 |
_filterConnections(input.connectionPointIn, self.localId, connections) |
|
2271 |
setattr(cls, "filterConnections", filterConnections) |
|
2272 |
||
2273 |
def updateConnectionsId(self, translation): |
|
2274 |
connections_end = [] |
|
2275 |
for input in self.inputVariables.getvariable(): |
|
2276 |
connections_end.extend(_updateConnectionsId(input.connectionPointIn, translation)) |
|
2277 |
return _getconnectionsdefinition(self, connections_end) |
|
2278 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
|
2279 |
||
2280 |
def translate(self, dx, dy): |
|
2281 |
_translate(self, dx, dy) |
|
2282 |
for input in self.inputVariables.getvariable(): |
|
2283 |
_translateConnections(input.connectionPointIn, dx, dy) |
|
2284 |
setattr(cls, "translate", translate) |
|
2285 |
||
2286 |
def Search(self, criteria, parent_infos=[]): |
|
2287 |
parent_infos = parent_infos + ["block", self.getlocalId()] |
|
2288 |
search_result = _Search([("name", self.getinstanceName()), |
|
2289 |
("type", self.gettypeName())], |
|
2290 |
criteria, parent_infos) |
|
2291 |
for i, variable in enumerate(self.inputVariables.getvariable()): |
|
2292 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
|
2293 |
search_result.append((tuple(parent_infos + ["input", i]),) + result) |
|
2294 |
for i, variable in enumerate(self.outputVariables.getvariable()): |
|
2295 |
for result in TestTextElement(variable.getformalParameter(), criteria): |
|
2296 |
search_result.append((tuple(parent_infos + ["output", i]),) + result) |
|
2297 |
return search_result |
|
2298 |
setattr(cls, "Search", Search) |
|
2299 |
||
2300 |
cls = _initElementClass("leftPowerRail", "ldObjects_leftPowerRail") |
|
2301 |
if cls: |
|
2302 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("leftPowerRail")) |
|
2303 |
||
2304 |
cls = _initElementClass("rightPowerRail", "ldObjects_rightPowerRail", "multiple") |
|
2305 |
if cls: |
|
2306 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
|
2307 |
||
2308 |
cls = _initElementClass("contact", "ldObjects_contact", "single") |
|
2309 |
if cls: |
|
2310 |
setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
|
2311 |
||
2312 |
def updateElementName(self, old_name, new_name): |
|
2313 |
if self.variable == old_name: |
|
2314 |
self.variable = new_name |
|
2315 |
setattr(cls, "updateElementName", updateElementName) |
|
2316 |
||
2317 |
def updateElementAddress(self, address_model, new_leading): |
|
2318 |
self.variable = update_address(self.variable, address_model, new_leading) |
|
2319 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2320 |
||
2321 |
def Search(self, criteria, parent_infos=[]): |
|
2322 |
return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()]) |
|
2323 |
setattr(cls, "Search", Search) |
|
2324 |
||
2325 |
cls = _initElementClass("coil", "ldObjects_coil", "single") |
|
2326 |
if cls: |
|
2327 |
setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
|
2328 |
||
2329 |
def updateElementName(self, old_name, new_name): |
|
2330 |
if self.variable == old_name: |
|
2331 |
self.variable = new_name |
|
2332 |
setattr(cls, "updateElementName", updateElementName) |
|
2333 |
||
2334 |
def updateElementAddress(self, address_model, new_leading): |
|
2335 |
self.variable = update_address(self.variable, address_model, new_leading) |
|
2336 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2337 |
||
2338 |
def Search(self, criteria, parent_infos=[]): |
|
2339 |
return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()]) |
|
2340 |
setattr(cls, "Search", Search) |
|
2341 |
||
2342 |
cls = _initElementClass("step", "sfcObjects_step", "single") |
|
2343 |
if cls: |
|
2344 |
def getinfos(self): |
|
2345 |
infos = _getelementinfos(self) |
|
2346 |
infos["type"] = "step" |
|
2347 |
specific_values = infos["specific_values"] |
|
2348 |
specific_values["name"] = self.getname() |
|
2349 |
specific_values["initial"] = self.getinitialStep() |
|
2350 |
if self.connectionPointIn: |
|
2351 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2352 |
if self.connectionPointOut: |
|
2353 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2354 |
if self.connectionPointOutAction: |
|
2355 |
specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction) |
|
2356 |
return infos |
|
2357 |
setattr(cls, "getinfos", getinfos) |
|
2358 |
||
2359 |
def Search(self, criteria, parent_infos=[]): |
|
2360 |
return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
|
2361 |
setattr(cls, "Search", Search) |
|
2362 |
||
2363 |
cls = PLCOpenClasses.get("transition_condition", None) |
|
2364 |
if cls: |
|
2365 |
def compatibility(self, tree): |
|
2366 |
connections = [] |
|
2367 |
for child in tree.childNodes: |
|
2368 |
if child.nodeName == "connection": |
|
2369 |
connections.append(child) |
|
2370 |
if len(connections) > 0: |
|
2371 |
node = CreateNode("connectionPointIn") |
|
2372 |
relPosition = CreateNode("relPosition") |
|
2373 |
NodeSetAttr(relPosition, "x", "0") |
|
2374 |
NodeSetAttr(relPosition, "y", "0") |
|
2375 |
node.childNodes.append(relPosition) |
|
2376 |
node.childNodes.extend(connections) |
|
2377 |
tree.childNodes = [node] |
|
2378 |
setattr(cls, "compatibility", compatibility) |
|
2379 |
||
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2380 |
cls = _initElementClass("transition", "sfcObjects_transition") |
814 | 2381 |
if cls: |
2382 |
def getinfos(self): |
|
2383 |
infos = _getelementinfos(self) |
|
2384 |
infos["type"] = "transition" |
|
2385 |
specific_values = infos["specific_values"] |
|
2386 |
priority = self.getpriority() |
|
2387 |
if priority is None: |
|
2388 |
priority = 0 |
|
2389 |
specific_values["priority"] = priority |
|
2390 |
condition = self.getconditionContent() |
|
2391 |
specific_values["condition_type"] = condition["type"] |
|
2392 |
if specific_values["condition_type"] == "connection": |
|
2393 |
specific_values["connection"] = _getconnectioninfos(self, condition["value"], True) |
|
2394 |
else: |
|
2395 |
specific_values["condition"] = condition["value"] |
|
2396 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2397 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2398 |
return infos |
|
2399 |
setattr(cls, "getinfos", getinfos) |
|
2400 |
||
2401 |
def setconditionContent(self, type, value): |
|
2402 |
if not self.condition: |
|
2403 |
self.addcondition() |
|
2404 |
if type == "reference": |
|
2405 |
condition = PLCOpenClasses["condition_reference"]() |
|
2406 |
condition.setname(value) |
|
2407 |
elif type == "inline": |
|
2408 |
condition = PLCOpenClasses["condition_inline"]() |
|
2409 |
condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2410 |
condition.settext(value) |
|
2411 |
elif type == "connection": |
|
2412 |
type = "connectionPointIn" |
|
2413 |
condition = PLCOpenClasses["connectionPointIn"]() |
|
2414 |
self.condition.setcontent({"name" : type, "value" : condition}) |
|
2415 |
setattr(cls, "setconditionContent", setconditionContent) |
|
2416 |
||
2417 |
def getconditionContent(self): |
|
2418 |
if self.condition: |
|
2419 |
content = self.condition.getcontent() |
|
2420 |
values = {"type" : content["name"]} |
|
2421 |
if values["type"] == "reference": |
|
2422 |
values["value"] = content["value"].getname() |
|
2423 |
elif values["type"] == "inline": |
|
2424 |
values["value"] = content["value"].gettext() |
|
2425 |
elif values["type"] == "connectionPointIn": |
|
2426 |
values["type"] = "connection" |
|
2427 |
values["value"] = content["value"] |
|
2428 |
return values |
|
2429 |
return "" |
|
2430 |
setattr(cls, "getconditionContent", getconditionContent) |
|
2431 |
||
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2432 |
def getconditionConnection(self): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2433 |
if self.condition: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2434 |
content = self.condition.getcontent() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2435 |
if content["name"] == "connectionPointIn": |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2436 |
return content["value"] |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2437 |
return None |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2438 |
setattr(cls, "getconditionConnection", getconditionConnection) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2439 |
|
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2440 |
def getBoundingBox(self): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2441 |
bbox = _getBoundingBoxSingle(self) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2442 |
condition_connection = self.getconditionConnection() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2443 |
if condition_connection: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2444 |
bbox.union(_getConnectionsBoundingBox(condition_connection)) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2445 |
return bbox |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2446 |
setattr(cls, "getBoundingBox", getBoundingBox) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2447 |
|
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2448 |
def translate(self, dx, dy): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2449 |
_translateSingle(self, dx, dy) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2450 |
condition_connection = self.getconditionConnection() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2451 |
if condition_connection: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2452 |
_translateConnections(condition_connection, dx, dy) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2453 |
setattr(cls, "translate", translate) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2454 |
|
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2455 |
def filterConnections(self, connections): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2456 |
_filterConnectionsSingle(self, connections) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2457 |
condition_connection = self.getconditionConnection() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2458 |
if condition_connection: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2459 |
_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
|
2460 |
setattr(cls, "filterConnections", filterConnections) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2461 |
|
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2462 |
def updateConnectionsId(self, translation): |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2463 |
connections_end = [] |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2464 |
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
|
2465 |
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
|
2466 |
condition_connection = self.getconditionConnection() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2467 |
if condition_connection: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2468 |
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
|
2469 |
return _getconnectionsdefinition(self, connections_end) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2470 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2471 |
|
814 | 2472 |
def updateElementName(self, old_name, new_name): |
2473 |
if self.condition: |
|
2474 |
content = self.condition.getcontent() |
|
2475 |
if content["name"] == "reference": |
|
2476 |
if content["value"].getname() == old_name: |
|
2477 |
content["value"].setname(new_name) |
|
2478 |
elif content["name"] == "inline": |
|
2479 |
content["value"].updateElementName(old_name, new_name) |
|
2480 |
setattr(cls, "updateElementName", updateElementName) |
|
2481 |
||
2482 |
def updateElementAddress(self, address_model, new_leading): |
|
2483 |
if self.condition: |
|
2484 |
content = self.condition.getcontent() |
|
2485 |
if content["name"] == "reference": |
|
2486 |
content["value"].setname(update_address(content["value"].getname(), address_model, new_leading)) |
|
2487 |
elif content["name"] == "inline": |
|
2488 |
content["value"].updateElementAddress(address_model, new_leading) |
|
2489 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2490 |
||
2491 |
def getconnections(self): |
|
891
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2492 |
condition_connection = self.getconditionConnection() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2493 |
if condition_connection: |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2494 |
return condition_connection.getconnections() |
39f355a535d8
Fix bug when copying transition and the connected FBD or LD diagram
Laurent Bessard
parents:
854
diff
changeset
|
2495 |
return None |
814 | 2496 |
setattr(cls, "getconnections", getconnections) |
2497 |
||
2498 |
def Search(self, criteria, parent_infos=[]): |
|
2499 |
parent_infos = parent_infos + ["transition", self.getlocalId()] |
|
2500 |
search_result = [] |
|
2501 |
content = self.condition.getcontent() |
|
2502 |
if content["name"] == "reference": |
|
2503 |
search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos)) |
|
2504 |
elif content["name"] == "inline": |
|
2505 |
search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"])) |
|
2506 |
return search_result |
|
2507 |
setattr(cls, "Search", Search) |
|
2508 |
||
2509 |
cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
|
2510 |
if cls: |
|
2511 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
|
2512 |
||
2513 |
cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
|
2514 |
if cls: |
|
2515 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
|
2516 |
||
2517 |
cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
|
2518 |
if cls: |
|
2519 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
|
2520 |
||
2521 |
cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
|
2522 |
if cls: |
|
2523 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
|
2524 |
||
2525 |
cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
|
2526 |
if cls: |
|
2527 |
def getinfos(self): |
|
2528 |
infos = _getelementinfos(self) |
|
2529 |
infos["type"] = "jump" |
|
2530 |
infos["specific_values"]["target"] = self.gettargetName() |
|
2531 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2532 |
return infos |
|
2533 |
setattr(cls, "getinfos", getinfos) |
|
2534 |
||
2535 |
def Search(self, criteria, parent_infos): |
|
2536 |
return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
|
2537 |
setattr(cls, "Search", Search) |
|
2538 |
||
2539 |
cls = PLCOpenClasses.get("actionBlock_action", None) |
|
2540 |
if cls: |
|
2541 |
def compatibility(self, tree): |
|
2542 |
relPosition = reduce(lambda x, y: x | (y.nodeName == "relPosition"), tree.childNodes, False) |
|
2543 |
if not tree.hasAttribute("localId"): |
|
2544 |
NodeSetAttr(tree, "localId", "0") |
|
2545 |
if not relPosition: |
|
2546 |
node = CreateNode("relPosition") |
|
2547 |
NodeSetAttr(node, "x", "0") |
|
2548 |
NodeSetAttr(node, "y", "0") |
|
2549 |
tree.childNodes.insert(0, node) |
|
2550 |
setattr(cls, "compatibility", compatibility) |
|
2551 |
||
2552 |
def setreferenceName(self, name): |
|
2553 |
if self.reference: |
|
2554 |
self.reference.setname(name) |
|
2555 |
setattr(cls, "setreferenceName", setreferenceName) |
|
2556 |
||
2557 |
def getreferenceName(self): |
|
2558 |
if self.reference: |
|
2559 |
return self.reference.getname() |
|
2560 |
return None |
|
2561 |
setattr(cls, "getreferenceName", getreferenceName) |
|
2562 |
||
2563 |
def setinlineContent(self, content): |
|
2564 |
if self.inline: |
|
2565 |
self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
2566 |
self.inline.settext(content) |
|
2567 |
setattr(cls, "setinlineContent", setinlineContent) |
|
2568 |
||
2569 |
def getinlineContent(self): |
|
2570 |
if self.inline: |
|
2571 |
return self.inline.gettext() |
|
2572 |
return None |
|
2573 |
setattr(cls, "getinlineContent", getinlineContent) |
|
2574 |
||
2575 |
def updateElementName(self, old_name, new_name): |
|
2576 |
if self.reference and self.reference.getname() == old_name: |
|
2577 |
self.reference.setname(new_name) |
|
2578 |
if self.inline: |
|
2579 |
self.inline.updateElementName(old_name, new_name) |
|
2580 |
setattr(cls, "updateElementName", updateElementName) |
|
2581 |
||
2582 |
def updateElementAddress(self, address_model, new_leading): |
|
2583 |
if self.reference: |
|
2584 |
self.reference.setname(update_address(self.reference.getname(), address_model, new_leading)) |
|
2585 |
if self.inline: |
|
2586 |
self.inline.updateElementAddress(address_model, new_leading) |
|
2587 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2588 |
||
2589 |
def Search(self, criteria, parent_infos=[]): |
|
2590 |
qualifier = self.getqualifier() |
|
2591 |
if qualifier is None: |
|
2592 |
qualifier = "N" |
|
2593 |
return _Search([("inline", self.getinlineContent()), |
|
2594 |
("reference", self.getreferenceName()), |
|
2595 |
("qualifier", qualifier), |
|
2596 |
("duration", self.getduration()), |
|
2597 |
("indicator", self.getindicator())], |
|
2598 |
criteria, parent_infos) |
|
2599 |
setattr(cls, "Search", Search) |
|
2600 |
||
2601 |
cls = _initElementClass("actionBlock", "commonObjects_actionBlock", "single") |
|
2602 |
if cls: |
|
2603 |
def compatibility(self, tree): |
|
2604 |
for child in tree.childNodes[:]: |
|
2605 |
if child.nodeName == "connectionPointOut": |
|
2606 |
tree.childNodes.remove(child) |
|
2607 |
setattr(cls, "compatibility", compatibility) |
|
2608 |
||
2609 |
def getinfos(self): |
|
2610 |
infos = _getelementinfos(self) |
|
2611 |
infos["type"] = "actionBlock" |
|
2612 |
infos["specific_values"]["actions"] = self.getactions() |
|
2613 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2614 |
return infos |
|
2615 |
setattr(cls, "getinfos", getinfos) |
|
2616 |
||
2617 |
def setactions(self, actions): |
|
2618 |
self.action = [] |
|
2619 |
for params in actions: |
|
2620 |
action = PLCOpenClasses["actionBlock_action"]() |
|
2621 |
action.setqualifier(params["qualifier"]) |
|
2622 |
if params["type"] == "reference": |
|
2623 |
action.addreference() |
|
2624 |
action.setreferenceName(params["value"]) |
|
2625 |
else: |
|
2626 |
action.addinline() |
|
2627 |
action.setinlineContent(params["value"]) |
|
2628 |
if params.has_key("duration"): |
|
2629 |
action.setduration(params["duration"]) |
|
2630 |
if params.has_key("indicator"): |
|
2631 |
action.setindicator(params["indicator"]) |
|
2632 |
self.action.append(action) |
|
2633 |
setattr(cls, "setactions", setactions) |
|
2634 |
||
2635 |
def getactions(self): |
|
2636 |
actions = [] |
|
2637 |
for action in self.action: |
|
2638 |
params = {} |
|
2639 |
params["qualifier"] = action.getqualifier() |
|
2640 |
if params["qualifier"] is None: |
|
2641 |
params["qualifier"] = "N" |
|
2642 |
if action.getreference(): |
|
2643 |
params["type"] = "reference" |
|
2644 |
params["value"] = action.getreferenceName() |
|
2645 |
elif action.getinline(): |
|
2646 |
params["type"] = "inline" |
|
2647 |
params["value"] = action.getinlineContent() |
|
2648 |
duration = action.getduration() |
|
2649 |
if duration: |
|
2650 |
params["duration"] = duration |
|
2651 |
indicator = action.getindicator() |
|
2652 |
if indicator: |
|
2653 |
params["indicator"] = indicator |
|
2654 |
actions.append(params) |
|
2655 |
return actions |
|
2656 |
setattr(cls, "getactions", getactions) |
|
2657 |
||
2658 |
def updateElementName(self, old_name, new_name): |
|
2659 |
for action in self.action: |
|
2660 |
action.updateElementName(old_name, new_name) |
|
2661 |
setattr(cls, "updateElementName", updateElementName) |
|
2662 |
||
2663 |
def updateElementAddress(self, address_model, new_leading): |
|
2664 |
for action in self.action: |
|
2665 |
action.updateElementAddress(address_model, new_leading) |
|
2666 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2667 |
||
2668 |
def Search(self, criteria, parent_infos=[]): |
|
2669 |
parent_infos = parent_infos + ["action_block", self.getlocalId()] |
|
2670 |
search_result = [] |
|
2671 |
for idx, action in enumerate(self.action): |
|
2672 |
search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
|
2673 |
return search_result |
|
2674 |
setattr(cls, "Search", Search) |
|
2675 |
||
2676 |
def _SearchInIOVariable(self, criteria, parent_infos=[]): |
|
2677 |
return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
|
2678 |
||
2679 |
cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
|
2680 |
if cls: |
|
2681 |
setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
|
2682 |
||
2683 |
def updateElementName(self, old_name, new_name): |
|
2684 |
if self.expression == old_name: |
|
2685 |
self.expression = new_name |
|
2686 |
setattr(cls, "updateElementName", updateElementName) |
|
2687 |
||
2688 |
def updateElementAddress(self, address_model, new_leading): |
|
2689 |
self.expression = update_address(self.expression, address_model, new_leading) |
|
2690 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2691 |
||
2692 |
setattr(cls, "Search", _SearchInIOVariable) |
|
2693 |
||
2694 |
cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
|
2695 |
if cls: |
|
2696 |
setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
|
2697 |
||
2698 |
def updateElementName(self, old_name, new_name): |
|
2699 |
if self.expression == old_name: |
|
2700 |
self.expression = new_name |
|
2701 |
setattr(cls, "updateElementName", updateElementName) |
|
2702 |
||
2703 |
def updateElementAddress(self, address_model, new_leading): |
|
2704 |
self.expression = update_address(self.expression, address_model, new_leading) |
|
2705 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2706 |
||
2707 |
setattr(cls, "Search", _SearchInIOVariable) |
|
2708 |
||
2709 |
cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
|
2710 |
if cls: |
|
2711 |
setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
|
2712 |
||
2713 |
def updateElementName(self, old_name, new_name): |
|
2714 |
if self.expression == old_name: |
|
2715 |
self.expression = new_name |
|
2716 |
setattr(cls, "updateElementName", updateElementName) |
|
2717 |
||
2718 |
def updateElementAddress(self, address_model, new_leading): |
|
2719 |
self.expression = update_address(self.expression, address_model, new_leading) |
|
2720 |
setattr(cls, "updateElementAddress", updateElementAddress) |
|
2721 |
||
2722 |
setattr(cls, "Search", _SearchInIOVariable) |
|
2723 |
||
2724 |
||
2725 |
def _SearchInConnector(self, criteria, parent_infos=[]): |
|
2726 |
return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
|
2727 |
||
2728 |
cls = _initElementClass("continuation", "commonObjects_continuation") |
|
2729 |
if cls: |
|
2730 |
setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
|
2731 |
setattr(cls, "Search", _SearchInConnector) |
|
2732 |
||
2733 |
def updateElementName(self, old_name, new_name): |
|
2734 |
if self.name == old_name: |
|
2735 |
self.name = new_name |
|
2736 |
setattr(cls, "updateElementName", updateElementName) |
|
2737 |
||
2738 |
cls = _initElementClass("connector", "commonObjects_connector", "single") |
|
2739 |
if cls: |
|
2740 |
setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
|
2741 |
setattr(cls, "Search", _SearchInConnector) |
|
2742 |
||
2743 |
def updateElementName(self, old_name, new_name): |
|
2744 |
if self.name == old_name: |
|
2745 |
self.name = new_name |
|
2746 |
setattr(cls, "updateElementName", updateElementName) |
|
2747 |
||
2748 |
cls = PLCOpenClasses.get("connection", None) |
|
2749 |
if cls: |
|
2750 |
def setpoints(self, points): |
|
2751 |
self.position = [] |
|
2752 |
for point in points: |
|
2753 |
position = PLCOpenClasses["position"]() |
|
2754 |
position.setx(point.x) |
|
2755 |
position.sety(point.y) |
|
2756 |
self.position.append(position) |
|
2757 |
setattr(cls, "setpoints", setpoints) |
|
2758 |
||
2759 |
def getpoints(self): |
|
2760 |
points = [] |
|
2761 |
for position in self.position: |
|
2762 |
points.append((position.getx(),position.gety())) |
|
2763 |
return points |
|
2764 |
setattr(cls, "getpoints", getpoints) |
|
2765 |
||
2766 |
cls = PLCOpenClasses.get("connectionPointIn", None) |
|
2767 |
if cls: |
|
2768 |
def setrelPositionXY(self, x, y): |
|
2769 |
self.relPosition = PLCOpenClasses["position"]() |
|
2770 |
self.relPosition.setx(x) |
|
2771 |
self.relPosition.sety(y) |
|
2772 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2773 |
||
2774 |
def getrelPositionXY(self): |
|
2775 |
if self.relPosition: |
|
2776 |
return self.relPosition.getx(), self.relPosition.gety() |
|
2777 |
else: |
|
2778 |
return self.relPosition |
|
2779 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
|
2780 |
||
2781 |
def addconnection(self): |
|
2782 |
if not self.content: |
|
2783 |
self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
|
2784 |
else: |
|
2785 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
2786 |
setattr(cls, "addconnection", addconnection) |
|
2787 |
||
2788 |
def removeconnection(self, idx): |
|
2789 |
if self.content: |
|
2790 |
self.content["value"].pop(idx) |
|
2791 |
if len(self.content["value"]) == 0: |
|
2792 |
self.content = None |
|
2793 |
setattr(cls, "removeconnection", removeconnection) |
|
2794 |
||
2795 |
def removeconnections(self): |
|
2796 |
if self.content: |
|
2797 |
self.content = None |
|
2798 |
setattr(cls, "removeconnections", removeconnections) |
|
2799 |
||
2800 |
def getconnections(self): |
|
2801 |
if self.content: |
|
2802 |
return self.content["value"] |
|
2803 |
setattr(cls, "getconnections", getconnections) |
|
2804 |
||
2805 |
def setconnectionId(self, idx, id): |
|
2806 |
if self.content: |
|
2807 |
self.content["value"][idx].setrefLocalId(id) |
|
2808 |
setattr(cls, "setconnectionId", setconnectionId) |
|
2809 |
||
2810 |
def getconnectionId(self, idx): |
|
2811 |
if self.content: |
|
2812 |
return self.content["value"][idx].getrefLocalId() |
|
2813 |
return None |
|
2814 |
setattr(cls, "getconnectionId", getconnectionId) |
|
2815 |
||
2816 |
def setconnectionPoints(self, idx, points): |
|
2817 |
if self.content: |
|
2818 |
self.content["value"][idx].setpoints(points) |
|
2819 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
2820 |
||
2821 |
def getconnectionPoints(self, idx): |
|
2822 |
if self.content: |
|
2823 |
return self.content["value"][idx].getpoints() |
|
2824 |
return None |
|
2825 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
|
2826 |
||
2827 |
def setconnectionParameter(self, idx, parameter): |
|
2828 |
if self.content: |
|
2829 |
self.content["value"][idx].setformalParameter(parameter) |
|
2830 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
2831 |
||
2832 |
def getconnectionParameter(self, idx): |
|
2833 |
if self.content: |
|
2834 |
return self.content["value"][idx].getformalParameter() |
|
2835 |
return None |
|
2836 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
|
2837 |
||
2838 |
cls = PLCOpenClasses.get("connectionPointOut", None) |
|
2839 |
if cls: |
|
2840 |
def setrelPositionXY(self, x, y): |
|
2841 |
self.relPosition = PLCOpenClasses["position"]() |
|
2842 |
self.relPosition.setx(x) |
|
2843 |
self.relPosition.sety(y) |
|
2844 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2845 |
||
2846 |
def getrelPositionXY(self): |
|
2847 |
if self.relPosition: |
|
2848 |
return self.relPosition.getx(), self.relPosition.gety() |
|
2849 |
return self.relPosition |
|
2850 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
|
2851 |
||
2852 |
cls = PLCOpenClasses.get("value", None) |
|
2853 |
if cls: |
|
2854 |
def setvalue(self, value): |
|
2855 |
value = value.strip() |
|
2856 |
if value.startswith("[") and value.endswith("]"): |
|
2857 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
|
2858 |
self.content = {"name" : "arrayValue", "value" : arrayValue} |
|
2859 |
elif value.startswith("(") and value.endswith(")"): |
|
2860 |
structValue = PLCOpenClasses["value_structValue"]() |
|
2861 |
self.content = {"name" : "structValue", "value" : structValue} |
|
2862 |
else: |
|
2863 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
2864 |
self.content = {"name" : "simpleValue", "value": simpleValue} |
|
2865 |
self.content["value"].setvalue(value) |
|
2866 |
setattr(cls, "setvalue", setvalue) |
|
2867 |
||
2868 |
def getvalue(self): |
|
2869 |
return self.content["value"].getvalue() |
|
2870 |
setattr(cls, "getvalue", getvalue) |
|
2871 |
||
2872 |
def extractValues(values): |
|
2873 |
items = values.split(",") |
|
2874 |
i = 1 |
|
2875 |
while i < len(items): |
|
2876 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
2877 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
2878 |
if opened > closed: |
|
2879 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
2880 |
elif opened == closed: |
|
2881 |
i += 1 |
|
2882 |
else: |
|
2883 |
raise ValueError, _("\"%s\" is an invalid value!")%value |
|
2884 |
return items |
|
2885 |
||
2886 |
cls = PLCOpenClasses.get("value_arrayValue", None) |
|
2887 |
if cls: |
|
2888 |
arrayValue_model = re.compile("([0-9]*)\((.*)\)$") |
|
2889 |
||
2890 |
def setvalue(self, value): |
|
2891 |
self.value = [] |
|
2892 |
for item in extractValues(value[1:-1]): |
|
2893 |
item = item.strip() |
|
2894 |
element = PLCOpenClasses["arrayValue_value"]() |
|
2895 |
result = arrayValue_model.match(item) |
|
2896 |
if result is not None: |
|
2897 |
groups = result.groups() |
|
2898 |
element.setrepetitionValue(groups[0]) |
|
2899 |
element.setvalue(groups[1].strip()) |
|
2900 |
else: |
|
2901 |
element.setvalue(item) |
|
2902 |
self.value.append(element) |
|
2903 |
setattr(cls, "setvalue", setvalue) |
|
2904 |
||
2905 |
def getvalue(self): |
|
2906 |
values = [] |
|
2907 |
for element in self.value: |
|
2908 |
repetition = element.getrepetitionValue() |
|
2909 |
if repetition is not None and int(repetition) > 1: |
|
2910 |
value = element.getvalue() |
|
2911 |
if value is None: |
|
2912 |
value = "" |
|
2913 |
values.append("%s(%s)"%(repetition, value)) |
|
2914 |
else: |
|
2915 |
values.append(element.getvalue()) |
|
2916 |
return "[%s]"%", ".join(values) |
|
2917 |
setattr(cls, "getvalue", getvalue) |
|
2918 |
||
2919 |
cls = PLCOpenClasses.get("value_structValue", None) |
|
2920 |
if cls: |
|
2921 |
structValue_model = re.compile("(.*):=(.*)") |
|
2922 |
||
2923 |
def setvalue(self, value): |
|
2924 |
self.value = [] |
|
2925 |
for item in extractValues(value[1:-1]): |
|
2926 |
result = structValue_model.match(item) |
|
2927 |
if result is not None: |
|
2928 |
groups = result.groups() |
|
2929 |
element = PLCOpenClasses["structValue_value"]() |
|
2930 |
element.setmember(groups[0].strip()) |
|
2931 |
element.setvalue(groups[1].strip()) |
|
2932 |
self.value.append(element) |
|
2933 |
setattr(cls, "setvalue", setvalue) |
|
2934 |
||
2935 |
def getvalue(self): |
|
2936 |
values = [] |
|
2937 |
for element in self.value: |
|
2938 |
values.append("%s := %s"%(element.getmember(), element.getvalue())) |
|
2939 |
return "(%s)"%", ".join(values) |
|
2940 |
setattr(cls, "getvalue", getvalue) |