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