author | lbessard |
Fri, 03 Aug 2007 18:02:54 +0200 | |
changeset 62 | 1908c45f21ef |
parent 58 | 39cd981ff242 |
child 63 | 04a02b4b2a57 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
2 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
2 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
2 | 25 |
from xmlclass import * |
6 | 26 |
import os, sys |
0 | 27 |
|
28 |
""" |
|
29 |
Dictionary that makes the relation between var names in plcopen and displayed values |
|
30 |
""" |
|
31 |
VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars", |
|
32 |
"Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars", |
|
33 |
"Global" : "globalVars", "Access" : "accessVars"} |
|
34 |
||
35 |
""" |
|
36 |
Define in which order var types must be displayed |
|
37 |
""" |
|
38 |
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"] |
|
39 |
||
40 |
""" |
|
41 |
Define which action qualifier must be associated with a duration |
|
42 |
""" |
|
43 |
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, |
|
44 |
"P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True} |
|
45 |
||
2 | 46 |
PLCOpenClasses = {} |
47 |
PLCOpenTypes = {} |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
48 |
base_folder = "" |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
49 |
for path in sys.path: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
50 |
if os.path.isfile(os.path.join(path, "plcopen/TC6_XML_V10_B.xsd")): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
51 |
base_folder = path |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
52 |
GenerateClassesFromXSD(os.path.join(base_folder, "plcopen/TC6_XML_V10_B.xsd")) |
2 | 53 |
CreateClasses(PLCOpenClasses, PLCOpenTypes) |
54 |
||
55 |
if "dataType" in PLCOpenClasses: |
|
56 |
cls = PLCOpenClasses["dataType"] |
|
57 |
cls.value = None |
|
58 |
||
59 |
def getValue(self): |
|
60 |
return self.value |
|
61 |
setattr(cls, "getValue", getValue) |
|
62 |
||
63 |
def setValue(self, value): |
|
64 |
self.value = value |
|
65 |
setattr(cls, "setValue", setValue) |
|
66 |
||
67 |
def loadXMLTree(self, tree): |
|
68 |
self.value = tree.childNodes[1].nodeName |
|
69 |
setattr(cls, "loadXMLTree", loadXMLTree) |
|
70 |
||
71 |
def generateXMLText(self, name, indent, extras = {}): |
|
72 |
ind1, ind2 = getIndent(indent, name) |
|
73 |
text = ind1 + "<%s>\n"%name |
|
74 |
ind3, ind4 = getIndent(indent + 1, self.value) |
|
75 |
text += ind3 + "<%s/>\n"%self.value |
|
76 |
text += ind1 + "</%s>\n"%name |
|
77 |
return text |
|
78 |
setattr(cls, "generateXMLText", generateXMLText) |
|
79 |
||
80 |
if "formattedText" in PLCOpenClasses: |
|
81 |
cls = PLCOpenClasses["formattedText"] |
|
82 |
cls.text = "" |
|
83 |
||
84 |
def getText(self): |
|
85 |
return self.text |
|
86 |
setattr(cls, "getText", getText) |
|
87 |
||
88 |
def setText(self, text): |
|
89 |
self.text = text |
|
90 |
setattr(cls, "setText", setText) |
|
91 |
||
92 |
def loadXMLTree(self, tree): |
|
93 |
self.text = GetAttributeValue(tree) |
|
94 |
if len(self.text.splitlines()) > 1: |
|
95 |
self.text = self.text[1:].rstrip() |
|
96 |
setattr(cls, "loadXMLTree", loadXMLTree) |
|
97 |
||
98 |
def generateXMLText(self, name, indent, extras = {}): |
|
99 |
ind1, ind2 = getIndent(indent, name) |
|
100 |
if len(self.text.splitlines()) > 1: |
|
0 | 101 |
text = ind1 + "<%s>\n"%name |
2 | 102 |
text += "%s\n"%self.text |
0 | 103 |
text += ind1 + "</%s>\n"%name |
104 |
return text |
|
2 | 105 |
else: |
106 |
return ind1 + "<%s>%s</%s>\n"%(name, self.text, name) |
|
107 |
setattr(cls, "generateXMLText", generateXMLText) |
|
108 |
||
58 | 109 |
def updateElementName(self, old_name, new_name): |
110 |
index = self.text.find(old_name) |
|
111 |
while index != -1: |
|
112 |
if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): |
|
113 |
index = self.text.find(old_name, index + len(old_name)) |
|
114 |
elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): |
|
115 |
index = self.text.find(old_name, index + len(old_name)) |
|
116 |
else: |
|
117 |
self.text = self.text[:index] + new_name + self.text[index + len(old_name):] |
|
118 |
index = self.text.find(old_name, index + len(new_name)) |
|
119 |
setattr(cls, "updateElementName", updateElementName) |
|
120 |
||
2 | 121 |
if "project" in PLCOpenClasses: |
122 |
cls = PLCOpenClasses["project"] |
|
123 |
cls.singleLineAttributes = False |
|
124 |
||
125 |
def getFileHeader(self): |
|
126 |
fileheader = {} |
|
127 |
fileheader["companyName"] = self.fileHeader.getCompanyName() |
|
128 |
if self.fileHeader.getCompanyURL(): |
|
129 |
fileheader["companyURL"] = self.fileHeader.getCompanyURL() |
|
130 |
fileheader["productName"] = self.fileHeader.getProductName() |
|
131 |
fileheader["productVersion"] = self.fileHeader.getProductVersion() |
|
132 |
if self.fileHeader.getProductRelease(): |
|
133 |
fileheader["productRelease"] = self.fileHeader.getProductRelease() |
|
134 |
fileheader["creationDateTime"] = self.fileHeader.getCreationDateTime() |
|
135 |
if self.fileHeader.getContentDescription(): |
|
136 |
fileheader["contentDescription"] = self.fileHeader.getContentDescription() |
|
137 |
return fileheader |
|
138 |
setattr(cls, "getFileHeader", getFileHeader) |
|
139 |
||
140 |
def setFileHeader(self, fileheader): |
|
141 |
self.fileHeader.setCompanyName(fileheader["companyName"]) |
|
142 |
if "companyURL" in fileheader: |
|
143 |
self.fileHeader.setCompanyURL(fileheader["companyURL"]) |
|
144 |
self.fileHeader.setProductName(fileheader["productName"]) |
|
145 |
self.fileHeader.setProductVersion(fileheader["productVersion"]) |
|
146 |
if "productRelease" in fileheader: |
|
147 |
self.fileHeader.setProductRelease(fileheader["productRelease"]) |
|
148 |
self.fileHeader.setCreationDateTime(fileheader["creationDateTime"]) |
|
149 |
if "contentDescription" in fileheader: |
|
150 |
self.fileHeader.setContentDescription(fileheader["contentDescription"]) |
|
151 |
setattr(cls, "setFileHeader", setFileHeader) |
|
152 |
||
153 |
def setName(self, name): |
|
154 |
self.contentHeader.setName(name) |
|
155 |
setattr(cls, "setName", setName) |
|
0 | 156 |
|
2 | 157 |
def getName(self): |
158 |
return self.contentHeader.getName() |
|
159 |
setattr(cls, "getName", getName) |
|
160 |
||
161 |
def getPous(self): |
|
162 |
return self.types.getPouElements() |
|
163 |
setattr(cls, "getPous", getPous) |
|
164 |
||
165 |
def getPou(self, name): |
|
166 |
return self.types.getPouElement(name) |
|
167 |
setattr(cls, "getPou", getPou) |
|
168 |
||
169 |
def appendPou(self, name, pou_type, body_type): |
|
170 |
self.types.appendPouElement(name, pou_type, body_type) |
|
171 |
setattr(cls, "appendPou", appendPou) |
|
0 | 172 |
|
2 | 173 |
def insertPou(self, index, pou): |
174 |
self.types.insertPouElement(index, pou) |
|
175 |
setattr(cls, "insertPou", insertPou) |
|
176 |
||
177 |
def removePou(self, name): |
|
178 |
self.types.removePouElement(name) |
|
179 |
setattr(cls, "removePou", removePou) |
|
180 |
||
181 |
def getConfigurations(self): |
|
182 |
configurations = self.instances.configurations.getConfiguration() |
|
183 |
if configurations: |
|
184 |
return configurations |
|
185 |
return [] |
|
186 |
setattr(cls, "getConfigurations", getConfigurations) |
|
187 |
||
188 |
def getConfiguration(self, name): |
|
189 |
for configuration in self.instances.configurations.getConfiguration(): |
|
190 |
if configuration.getName() == name: |
|
191 |
return configuration |
|
192 |
return None |
|
193 |
setattr(cls, "getConfiguration", getConfiguration) |
|
194 |
||
195 |
def addConfiguration(self, name): |
|
196 |
for configuration in self.instances.configurations.getConfiguration(): |
|
197 |
if configuration.getName() == name: |
|
198 |
raise ValueError, "\"%s\" configuration already exists !!!"%name |
|
199 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
200 |
new_configuration.setName(name) |
|
201 |
self.instances.configurations.appendConfiguration(new_configuration) |
|
202 |
setattr(cls, "addConfiguration", addConfiguration) |
|
203 |
||
204 |
def removeConfiguration(self, name): |
|
205 |
found = False |
|
206 |
for idx, configuration in enumerate(self.instances.configurations.getConfiguration()): |
|
207 |
if configuration.getName() == name: |
|
208 |
self.instances.configurations.removeConfiguration(idx) |
|
209 |
found = True |
|
210 |
break |
|
211 |
if not found: |
|
212 |
raise ValueError, "\"%s\" configuration doesn't exist !!!"%name |
|
213 |
setattr(cls, "removeConfiguration", removeConfiguration) |
|
214 |
||
215 |
def getConfigurationResource(self, config_name, name): |
|
216 |
configuration = self.getConfiguration(config_name) |
|
217 |
if configuration: |
|
218 |
for resource in configuration.getResource(): |
|
219 |
if resource.getName() == name: |
|
220 |
return resource |
|
221 |
return None |
|
222 |
setattr(cls, "getConfigurationResource", getConfigurationResource) |
|
223 |
||
224 |
def addConfigurationResource(self, config_name, name): |
|
225 |
configuration = self.getConfiguration(config_name) |
|
226 |
if configuration: |
|
227 |
for resource in configuration.getResource(): |
|
228 |
if resource.getName() == name: |
|
229 |
raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) |
|
230 |
new_resource = PLCOpenClasses["configuration_resource"]() |
|
231 |
new_resource.setName(name) |
|
232 |
configuration.appendResource(new_resource) |
|
233 |
setattr(cls, "addConfigurationResource", addConfigurationResource) |
|
234 |
||
235 |
def removeConfigurationResource(self, config_name, name): |
|
236 |
configuration = self.getConfiguration(config_name) |
|
237 |
if configuration: |
|
0 | 238 |
found = False |
2 | 239 |
for idx, resource in enumerate(configuration.getResource()): |
240 |
if resource.getName() == name: |
|
241 |
configuration.removeResource(idx) |
|
0 | 242 |
found = True |
243 |
break |
|
244 |
if not found: |
|
2 | 245 |
raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name) |
246 |
setattr(cls, "removeConfigurationResource", removeConfigurationResource) |
|
247 |
||
58 | 248 |
def updateElementName(self, old_name, new_name): |
249 |
for pou in self.types.getPouElements(): |
|
250 |
pou.updateElementName(old_name, new_name) |
|
251 |
for configuration in self.instances.configurations.getConfiguration(): |
|
252 |
configuration.updateElementName(old_name, new_name) |
|
253 |
setattr(cls, "updateElementName", updateElementName) |
|
254 |
||
2 | 255 |
PLCOpenClasses["project_fileHeader"].singleLineAttributes = False |
256 |
||
58 | 257 |
if "configurations_configuration" in PLCOpenClasses: |
258 |
cls = PLCOpenClasses["configurations_configuration"] |
|
259 |
||
260 |
def updateElementName(self, old_name, new_name): |
|
261 |
for resource in self.getResource(): |
|
262 |
resource.updateElementName(old_name, new_name) |
|
263 |
setattr(cls, "updateElementName", updateElementName) |
|
264 |
||
265 |
||
266 |
if "configuration_resource" in PLCOpenClasses: |
|
267 |
cls = PLCOpenClasses["configuration_resource"] |
|
268 |
||
269 |
def updateElementName(self, old_name, new_name): |
|
270 |
for instance in self.getPouInstance(): |
|
271 |
instance.updateElementName(old_name, new_name) |
|
272 |
for task in self.getTask(): |
|
273 |
task.updateElementName(old_name, new_name) |
|
274 |
setattr(cls, "updateElementName", updateElementName) |
|
275 |
||
276 |
if "resource_task" in PLCOpenClasses: |
|
277 |
cls = PLCOpenClasses["resource_task"] |
|
278 |
||
279 |
def updateElementName(self, old_name, new_name): |
|
280 |
if self.single == old_name: |
|
281 |
self.single = new_name |
|
282 |
for instance in self.getPouInstance(): |
|
283 |
instance.updateElementName(old_name, new_name) |
|
284 |
setattr(cls, "updateElementName", updateElementName) |
|
285 |
||
286 |
if "pouInstance" in PLCOpenClasses: |
|
287 |
cls = PLCOpenClasses["pouInstance"] |
|
288 |
||
289 |
def updateElementName(self, old_name, new_name): |
|
290 |
if self.type == old_name: |
|
291 |
self.type = new_name |
|
292 |
setattr(cls, "updateElementName", updateElementName) |
|
293 |
||
2 | 294 |
if "project_types" in PLCOpenClasses: |
295 |
cls = PLCOpenClasses["project_types"] |
|
296 |
||
297 |
def getPouElements(self): |
|
298 |
return self.pous.getPou() |
|
299 |
setattr(cls, "getPouElements", getPouElements) |
|
300 |
||
301 |
def getPouElement(self, name): |
|
302 |
elements = self.pous.getPou() |
|
303 |
for element in elements: |
|
304 |
if element.getName() == name: |
|
305 |
return element |
|
306 |
return None |
|
307 |
setattr(cls, "getPouElement", getPouElement) |
|
308 |
||
309 |
def appendPouElement(self, name, pou_type, body_type): |
|
310 |
for element in self.pous.getPou(): |
|
311 |
if element.getName() == name: |
|
312 |
raise ValueError, "\"%s\" POU already exists !!!"%name |
|
313 |
new_pou = PLCOpenClasses["pous_pou"]() |
|
314 |
new_pou.setName(name) |
|
315 |
new_pou.pouType.setValue(pou_type) |
|
316 |
new_pou.setBody(PLCOpenClasses["body"]()) |
|
317 |
new_pou.setBodyType(body_type) |
|
318 |
self.pous.appendPou(new_pou) |
|
319 |
setattr(cls, "appendPouElement", appendPouElement) |
|
320 |
||
321 |
def insertPouElement(self, index, pou): |
|
322 |
self.pous.insertPou(index, pou) |
|
323 |
setattr(cls, "insertPouElement", insertPouElement) |
|
324 |
||
325 |
def removePouElement(self, name): |
|
326 |
found = False |
|
327 |
for idx, element in enumerate(self.pous.getPou()): |
|
328 |
if element.getName() == name: |
|
329 |
self.pous.removePou(idx) |
|
330 |
found = True |
|
331 |
break |
|
332 |
if not found: |
|
333 |
raise ValueError, "\"%s\" POU doesn't exist !!!"%name |
|
334 |
setattr(cls, "removePouElement", removePouElement) |
|
335 |
||
336 |
def setBodyType(self, type): |
|
337 |
if type == "IL": |
|
338 |
self.body.setContent("IL", PLCOpenClasses["formattedText"]()) |
|
339 |
elif type == "ST": |
|
340 |
self.body.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
341 |
elif type == "LD": |
|
342 |
self.body.setContent("LD", PLCOpenClasses["body_LD"]()) |
|
343 |
elif type == "FBD": |
|
344 |
self.body.setContent("FBD", PLCOpenClasses["body_FBD"]()) |
|
345 |
elif type == "SFC": |
|
346 |
self.body.setContent("SFC", PLCOpenClasses["body_SFC"]()) |
|
347 |
else: |
|
348 |
raise ValueError, "%s isn't a valid body type!"%type |
|
349 |
||
350 |
def getBodyType(self): |
|
351 |
return self.body.getContent()["name"] |
|
352 |
||
353 |
def addInstance(self, name, instance): |
|
354 |
self.body.appendContentInstance(name, instance) |
|
355 |
||
356 |
def getInstances(self): |
|
357 |
return self.body.getContentInstances() |
|
358 |
||
359 |
def getInstance(self, id): |
|
360 |
return self.body.getContentInstance(id) |
|
361 |
||
362 |
def getRandomInstance(self, exclude): |
|
363 |
return self.body.getContentRandomInstance(exclude) |
|
364 |
||
365 |
def getInstanceByName(self, name): |
|
366 |
return self.body.getContentInstanceByName(name) |
|
367 |
||
368 |
def removeInstance(self, id): |
|
369 |
self.body.removeContentInstance(id) |
|
370 |
||
371 |
def setText(self, text): |
|
372 |
self.body.setText(text) |
|
373 |
||
374 |
def getText(self): |
|
375 |
return self.body.getText() |
|
376 |
setattr(cls, "getText", getText) |
|
377 |
||
378 |
if "pous_pou" in PLCOpenClasses: |
|
379 |
cls = PLCOpenClasses["pous_pou"] |
|
380 |
||
381 |
setattr(cls, "setBodyType", setBodyType) |
|
382 |
setattr(cls, "getBodyType", getBodyType) |
|
383 |
setattr(cls, "addInstance", addInstance) |
|
384 |
setattr(cls, "getInstances", getInstances) |
|
385 |
setattr(cls, "getInstance", getInstance) |
|
386 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
387 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
388 |
setattr(cls, "removeInstance", removeInstance) |
|
389 |
setattr(cls, "setText", setText) |
|
390 |
setattr(cls, "getText", getText) |
|
391 |
||
392 |
def getVars(self): |
|
393 |
vars = [] |
|
394 |
reverse_types = {} |
|
395 |
for name, value in VarTypes.items(): |
|
396 |
reverse_types[value] = name |
|
397 |
for varlist in self.interface.getContent(): |
|
398 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
|
399 |
return vars |
|
400 |
setattr(cls, "getVars", getVars) |
|
401 |
||
402 |
def setVars(self, vars): |
|
403 |
self.interface.setContent([]) |
|
404 |
for vartype, varlist in vars: |
|
405 |
self.interface.appendContent(VarTypes[vartype], varlist) |
|
406 |
setattr(cls, "setVars", setVars) |
|
407 |
||
408 |
def addTransition(self, name, type): |
|
409 |
if not self.transitions: |
|
410 |
self.addTransitions() |
|
411 |
self.transitions.setTransition([]) |
|
412 |
transition = PLCOpenClasses["transitions_transition"]() |
|
413 |
transition.setName(name) |
|
414 |
transition.setBodyType(type) |
|
415 |
self.transitions.appendTransition(transition) |
|
416 |
setattr(cls, "addTransition", addTransition) |
|
417 |
||
418 |
def getTransition(self, name): |
|
419 |
if self.transitions: |
|
420 |
for transition in self.transitions.getTransition(): |
|
421 |
if transition.getName() == name: |
|
422 |
return transition |
|
423 |
return None |
|
424 |
setattr(cls, "getTransition", getTransition) |
|
425 |
||
426 |
def getTransitionList(self): |
|
427 |
if self.transitions: |
|
428 |
return self.transitions.getTransition() |
|
429 |
return [] |
|
430 |
setattr(cls, "getTransitionList", getTransitionList) |
|
431 |
||
432 |
def removeTransition(self, name): |
|
433 |
if self.transitions: |
|
434 |
transitions = self.transitions.getTransition() |
|
435 |
i = 0 |
|
436 |
removed = False |
|
437 |
while i < len(transitions) and not removed: |
|
438 |
if transitions[i].getName() == name: |
|
46 | 439 |
transitions.pop(i) |
2 | 440 |
removed = True |
441 |
i += 1 |
|
442 |
if not removed: |
|
443 |
raise ValueError, "Transition with name %s doesn't exists!"%name |
|
444 |
setattr(cls, "removeTransition", removeTransition) |
|
445 |
||
446 |
def addAction(self, name, type): |
|
447 |
if not self.actions: |
|
448 |
self.addActions() |
|
449 |
self.actions.setAction([]) |
|
450 |
action = PLCOpenClasses["actions_action"]() |
|
451 |
action.setName(name) |
|
452 |
action.setBodyType(type) |
|
453 |
self.actions.appendAction(action) |
|
454 |
setattr(cls, "addAction", addAction) |
|
455 |
||
456 |
def getAction(self, name): |
|
457 |
if self.actions: |
|
458 |
for action in self.actions.getAction(): |
|
459 |
if action.getName() == name: |
|
460 |
return action |
|
461 |
return None |
|
462 |
setattr(cls, "getAction", getAction) |
|
463 |
||
464 |
def getActionList(self): |
|
465 |
if self.actions: |
|
466 |
return self.actions.getAction() |
|
467 |
return [] |
|
468 |
setattr(cls, "getActionList", getActionList) |
|
469 |
||
470 |
def removeAction(self, name): |
|
471 |
if self.actions: |
|
472 |
actions = self.actions.getAction() |
|
473 |
i = 0 |
|
474 |
removed = False |
|
475 |
while i < len(actions) and not removed: |
|
476 |
if actions[i].getName() == name: |
|
46 | 477 |
actions.pop(i) |
2 | 478 |
removed = True |
479 |
i += 1 |
|
480 |
if not removed: |
|
481 |
raise ValueError, "Action with name %s doesn't exists!"%name |
|
482 |
setattr(cls, "removeAction", removeAction) |
|
483 |
||
58 | 484 |
def updateElementName(self, old_name, new_name): |
485 |
self.body.updateElementName(old_name, new_name) |
|
486 |
for action in self.getActionList(): |
|
487 |
action.updateElementName(old_name, new_name) |
|
488 |
for transition in self.getTransitionList(): |
|
489 |
transition.updateElementName(old_name, new_name) |
|
490 |
setattr(cls, "updateElementName", updateElementName) |
|
491 |
||
2 | 492 |
if "transitions_transition" in PLCOpenClasses: |
493 |
cls = PLCOpenClasses["transitions_transition"] |
|
494 |
||
495 |
setattr(cls, "setBodyType", setBodyType) |
|
496 |
setattr(cls, "getBodyType", getBodyType) |
|
497 |
setattr(cls, "addInstance", addInstance) |
|
498 |
setattr(cls, "getInstances", getInstances) |
|
499 |
setattr(cls, "getInstance", getInstance) |
|
500 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
501 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
502 |
setattr(cls, "removeInstance", removeInstance) |
|
503 |
setattr(cls, "setText", setText) |
|
504 |
setattr(cls, "getText", getText) |
|
505 |
||
58 | 506 |
def updateElementName(self, old_name, new_name): |
507 |
self.body.updateElementName(old_name, new_name) |
|
508 |
setattr(cls, "updateElementName", updateElementName) |
|
509 |
||
2 | 510 |
if "actions_action" in PLCOpenClasses: |
511 |
cls = PLCOpenClasses["actions_action"] |
|
512 |
||
513 |
setattr(cls, "setBodyType", setBodyType) |
|
514 |
setattr(cls, "getBodyType", getBodyType) |
|
515 |
setattr(cls, "addInstance", addInstance) |
|
516 |
setattr(cls, "getInstances", getInstances) |
|
517 |
setattr(cls, "getInstance", getInstance) |
|
518 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
519 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
520 |
setattr(cls, "removeInstance", removeInstance) |
|
521 |
setattr(cls, "setText", setText) |
|
522 |
setattr(cls, "getText", getText) |
|
523 |
||
58 | 524 |
def updateElementName(self, old_name, new_name): |
525 |
self.body.updateElementName(old_name, new_name) |
|
526 |
setattr(cls, "updateElementName", updateElementName) |
|
527 |
||
2 | 528 |
if "body" in PLCOpenClasses: |
529 |
cls = PLCOpenClasses["body"] |
|
530 |
||
531 |
def appendContentInstance(self, name, instance): |
|
532 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
533 |
self.content["value"].appendContent(name, instance) |
|
534 |
else: |
|
535 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
536 |
setattr(cls, "appendContentInstance", appendContentInstance) |
|
537 |
||
538 |
def getContentInstances(self): |
|
539 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
540 |
instances = [] |
|
541 |
for element in self.content["value"].getContent(): |
|
542 |
instances.append(element["value"]) |
|
543 |
return instances |
|
544 |
else: |
|
545 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
546 |
setattr(cls, "getContentInstances", getContentInstances) |
|
547 |
||
548 |
def getContentInstance(self, id): |
|
549 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
550 |
for element in self.content["value"].getContent(): |
|
551 |
if element["value"].getLocalId() == id: |
|
552 |
return element["value"] |
|
0 | 553 |
return None |
2 | 554 |
else: |
555 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
556 |
setattr(cls, "getContentInstance", getContentInstance) |
|
557 |
||
558 |
def getContentRandomInstance(self, exclude): |
|
559 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
560 |
for element in self.content["value"].getContent(): |
|
561 |
if element["value"].getLocalId() not in exclude: |
|
562 |
return element["value"] |
|
563 |
return None |
|
564 |
else: |
|
565 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
566 |
setattr(cls, "getContentRandomInstance", getContentRandomInstance) |
|
567 |
||
568 |
def getContentInstanceByName(self, name): |
|
569 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
570 |
for element in self.content["value"].getContent(): |
|
571 |
if element["value"].getLocalId() == name: |
|
572 |
return element["value"] |
|
573 |
else: |
|
574 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
575 |
setattr(cls, "getContentInstanceByName", getContentInstanceByName) |
|
576 |
||
577 |
def removeContentInstance(self, id): |
|
578 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
579 |
i = 0 |
|
580 |
removed = False |
|
581 |
elements = self.content["value"].getContent() |
|
582 |
while i < len(elements) and not removed: |
|
583 |
if elements[i]["value"].getLocalId() == id: |
|
584 |
self.content["value"].removeContent(i) |
|
585 |
removed = True |
|
586 |
i += 1 |
|
587 |
if not removed: |
|
588 |
raise ValueError, "Instance with id %d doesn't exists!"%id |
|
589 |
else: |
|
590 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
591 |
setattr(cls, "removeContentInstance", removeContentInstance) |
|
592 |
||
593 |
def setText(self, text): |
|
594 |
if self.content["name"] in ["IL","ST"]: |
|
595 |
self.content["value"].setText(text) |
|
596 |
else: |
|
597 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
598 |
setattr(cls, "setText", setText) |
|
599 |
||
600 |
def getText(self): |
|
601 |
if self.content["name"] in ["IL","ST"]: |
|
602 |
return self.content["value"].getText() |
|
603 |
else: |
|
604 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
605 |
setattr(cls, "getText", getText) |
|
58 | 606 |
|
607 |
def updateElementName(self, old_name, new_name): |
|
608 |
if self.content["name"] in ["IL", "ST"]: |
|
609 |
self.content["value"].updateElementName(old_name, new_name) |
|
610 |
else: |
|
611 |
for element in self.content["value"].getContent(): |
|
612 |
element["value"].updateElementName(old_name, new_name) |
|
613 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 614 |
|
615 |
def getX(self): |
|
616 |
return self.position.getX() |
|
617 |
||
618 |
def getY(self): |
|
619 |
return self.position.getY() |
|
620 |
||
621 |
def setX(self, x): |
|
622 |
self.position.setX(x) |
|
623 |
||
624 |
def setY(self, y): |
|
625 |
self.position.setY(y) |
|
626 |
||
627 |
if "comment" in PLCOpenClasses: |
|
628 |
cls = PLCOpenClasses["comment"] |
|
629 |
setattr(cls, "getX", getX) |
|
630 |
setattr(cls, "getY", getY) |
|
631 |
setattr(cls, "setX", setX) |
|
632 |
setattr(cls, "setY", setY) |
|
633 |
||
634 |
def setContentText(self, text): |
|
635 |
self.content.setText(text) |
|
636 |
setattr(cls, "setContentText", setContentText) |
|
0 | 637 |
|
2 | 638 |
def getContentText(self): |
639 |
return self.content.getText() |
|
640 |
setattr(cls, "getContentText", getContentText) |
|
58 | 641 |
|
642 |
def updateElementName(self, old_name, new_name): |
|
643 |
self.content.updateElementName(old_name, new_name) |
|
644 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 645 |
|
646 |
if "block" in PLCOpenClasses: |
|
647 |
cls = PLCOpenClasses["block"] |
|
648 |
setattr(cls, "getX", getX) |
|
649 |
setattr(cls, "getY", getY) |
|
650 |
setattr(cls, "setX", setX) |
|
651 |
setattr(cls, "setY", setY) |
|
652 |
||
58 | 653 |
def updateElementName(self, old_name, new_name): |
654 |
if self.typeName == old_name: |
|
655 |
self.typeName = new_name |
|
656 |
setattr(cls, "updateElementName", updateElementName) |
|
657 |
||
2 | 658 |
if "inputVariables_variable" in PLCOpenClasses: |
659 |
cls = PLCOpenClasses["inputVariables_variable"] |
|
660 |
||
661 |
def setConnectorEdge(self, edge): |
|
662 |
if not self.edge: |
|
663 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
664 |
self.edge.setValue(edge) |
|
665 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
666 |
||
667 |
def getConnectorEdge(self): |
|
668 |
if self.edge: |
|
669 |
return self.edge.getValue() |
|
670 |
return None |
|
671 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
672 |
||
673 |
if "outputVariables_variable" in PLCOpenClasses: |
|
674 |
cls = PLCOpenClasses["outputVariables_variable"] |
|
675 |
||
676 |
def setConnectorEdge(self, edge): |
|
677 |
if not self.edge: |
|
678 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
679 |
self.edge.setValue(edge) |
|
680 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
681 |
||
682 |
def getConnectorEdge(self): |
|
683 |
if self.edge: |
|
684 |
return self.edge.getValue() |
|
685 |
return None |
|
686 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
687 |
||
688 |
if "leftPowerRail" in PLCOpenClasses: |
|
689 |
cls = PLCOpenClasses["leftPowerRail"] |
|
690 |
setattr(cls, "getX", getX) |
|
691 |
setattr(cls, "getY", getY) |
|
692 |
setattr(cls, "setX", setX) |
|
693 |
setattr(cls, "setY", setY) |
|
694 |
||
58 | 695 |
def updateElementName(self, old_name, new_name): |
696 |
pass |
|
697 |
setattr(cls, "updateElementName", updateElementName) |
|
698 |
||
2 | 699 |
if "contact" in PLCOpenClasses: |
700 |
cls = PLCOpenClasses["contact"] |
|
701 |
setattr(cls, "getX", getX) |
|
702 |
setattr(cls, "getY", getY) |
|
703 |
setattr(cls, "setX", setX) |
|
704 |
setattr(cls, "setY", setY) |
|
705 |
||
706 |
def setContactEdge(self, edge): |
|
707 |
if not self.edge: |
|
708 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
709 |
self.edge.setValue(edge) |
|
710 |
setattr(cls, "setContactEdge", setContactEdge) |
|
711 |
||
712 |
def getContactEdge(self): |
|
713 |
if self.edge: |
|
714 |
return self.edge.getValue() |
|
715 |
return None |
|
716 |
setattr(cls, "getContactEdge", getContactEdge) |
|
717 |
||
58 | 718 |
def updateElementName(self, old_name, new_name): |
719 |
if self.variable == old_name: |
|
720 |
self.variable = new_name |
|
721 |
setattr(cls, "updateElementName", updateElementName) |
|
722 |
||
2 | 723 |
if "coil" in PLCOpenClasses: |
724 |
cls = PLCOpenClasses["coil"] |
|
725 |
setattr(cls, "getX", getX) |
|
726 |
setattr(cls, "getY", getY) |
|
727 |
setattr(cls, "setX", setX) |
|
728 |
setattr(cls, "setY", setY) |
|
729 |
||
730 |
def setCoilStorage(self, edge): |
|
731 |
if not self.storage: |
|
732 |
self.storage = PLCOpenClasses["storageModifierType"]() |
|
733 |
self.storage.setValue(edge) |
|
734 |
setattr(cls, "setCoilStorage", setCoilStorage) |
|
735 |
||
736 |
def getCoilStorage(self): |
|
737 |
if self.storage: |
|
738 |
return self.storage.getValue() |
|
739 |
return None |
|
740 |
setattr(cls, "getCoilStorage", getCoilStorage) |
|
741 |
||
58 | 742 |
def updateElementName(self, old_name, new_name): |
743 |
if self.variable == old_name: |
|
744 |
self.variable = new_name |
|
745 |
setattr(cls, "updateElementName", updateElementName) |
|
746 |
||
2 | 747 |
if "rightPowerRail" in PLCOpenClasses: |
748 |
cls = PLCOpenClasses["rightPowerRail"] |
|
749 |
setattr(cls, "getX", getX) |
|
750 |
setattr(cls, "getY", getY) |
|
751 |
setattr(cls, "setX", setX) |
|
752 |
setattr(cls, "setY", setY) |
|
58 | 753 |
|
754 |
def updateElementName(self, old_name, new_name): |
|
755 |
pass |
|
756 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 757 |
|
758 |
if "step" in PLCOpenClasses: |
|
759 |
cls = PLCOpenClasses["step"] |
|
760 |
setattr(cls, "getX", getX) |
|
761 |
setattr(cls, "getY", getY) |
|
762 |
setattr(cls, "setX", setX) |
|
763 |
setattr(cls, "setY", setY) |
|
764 |
||
58 | 765 |
def updateElementName(self, old_name, new_name): |
766 |
pass |
|
767 |
setattr(cls, "updateElementName", updateElementName) |
|
768 |
||
2 | 769 |
if "transition" in PLCOpenClasses: |
770 |
cls = PLCOpenClasses["transition"] |
|
771 |
setattr(cls, "getX", getX) |
|
772 |
setattr(cls, "getY", getY) |
|
773 |
setattr(cls, "setX", setX) |
|
774 |
setattr(cls, "setY", setY) |
|
775 |
||
776 |
def setConditionContent(self, type, value): |
|
777 |
if not self.condition: |
|
778 |
self.addCondition() |
|
779 |
if type == "reference": |
|
780 |
condition = PLCOpenClasses["condition_reference"]() |
|
781 |
condition.setName(value) |
|
782 |
elif type == "inline": |
|
783 |
condition = PLCOpenClasses["condition_inline"]() |
|
784 |
condition.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
785 |
condition.setText(value) |
|
786 |
self.condition.setContent(type, condition) |
|
787 |
setattr(cls, "setConditionContent", setConditionContent) |
|
0 | 788 |
|
2 | 789 |
def getConditionContent(self): |
790 |
if self.condition: |
|
791 |
content = self.condition.getContent() |
|
792 |
values = {"type" : content["name"]} |
|
793 |
if values["type"] == "reference": |
|
794 |
values["value"] = content["value"].getName() |
|
795 |
elif values["type"] == "inline": |
|
796 |
values["value"] = content["value"].getText() |
|
797 |
return values |
|
798 |
return "" |
|
799 |
setattr(cls, "getConditionContent", getConditionContent) |
|
800 |
||
58 | 801 |
def updateElementName(self, old_name, new_name): |
802 |
if self.condition: |
|
803 |
content = self.condition.getContent() |
|
804 |
if content["name"] == "reference": |
|
805 |
if content["value"].getName() == old_name: |
|
806 |
content["value"].setName(new_name) |
|
807 |
elif content["name"] == "inline": |
|
808 |
content["value"].updateElementName(old_name, new_name) |
|
809 |
setattr(cls, "updateElementName", updateElementName) |
|
810 |
||
2 | 811 |
if "selectionDivergence" in PLCOpenClasses: |
812 |
cls = PLCOpenClasses["selectionDivergence"] |
|
813 |
setattr(cls, "getX", getX) |
|
814 |
setattr(cls, "getY", getY) |
|
815 |
setattr(cls, "setX", setX) |
|
816 |
setattr(cls, "setY", setY) |
|
817 |
||
58 | 818 |
def updateElementName(self, old_name, new_name): |
819 |
pass |
|
820 |
setattr(cls, "updateElementName", updateElementName) |
|
821 |
||
2 | 822 |
if "selectionConvergence" in PLCOpenClasses: |
823 |
cls = PLCOpenClasses["selectionConvergence"] |
|
824 |
setattr(cls, "getX", getX) |
|
825 |
setattr(cls, "getY", getY) |
|
826 |
setattr(cls, "setX", setX) |
|
827 |
setattr(cls, "setY", setY) |
|
828 |
||
58 | 829 |
def updateElementName(self, old_name, new_name): |
830 |
pass |
|
831 |
setattr(cls, "updateElementName", updateElementName) |
|
832 |
||
2 | 833 |
if "simultaneousDivergence" in PLCOpenClasses: |
834 |
cls = PLCOpenClasses["simultaneousDivergence"] |
|
835 |
setattr(cls, "getX", getX) |
|
836 |
setattr(cls, "getY", getY) |
|
837 |
setattr(cls, "setX", setX) |
|
838 |
setattr(cls, "setY", setY) |
|
839 |
||
58 | 840 |
def updateElementName(self, old_name, new_name): |
841 |
pass |
|
842 |
setattr(cls, "updateElementName", updateElementName) |
|
843 |
||
2 | 844 |
if "simultaneousDivergence" in PLCOpenClasses: |
845 |
cls = PLCOpenClasses["simultaneousConvergence"] |
|
846 |
setattr(cls, "getX", getX) |
|
847 |
setattr(cls, "getY", getY) |
|
848 |
setattr(cls, "setX", setX) |
|
849 |
setattr(cls, "setY", setY) |
|
58 | 850 |
|
851 |
def updateElementName(self, old_name, new_name): |
|
852 |
pass |
|
853 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 854 |
|
855 |
if "jumpStep" in PLCOpenClasses: |
|
856 |
cls = PLCOpenClasses["jumpStep"] |
|
857 |
setattr(cls, "getX", getX) |
|
858 |
setattr(cls, "getY", getY) |
|
859 |
setattr(cls, "setX", setX) |
|
860 |
setattr(cls, "setY", setY) |
|
58 | 861 |
|
862 |
def updateElementName(self, old_name, new_name): |
|
863 |
pass |
|
864 |
setattr(cls, "updateElementName", updateElementName) |
|
865 |
||
2 | 866 |
|
867 |
if "actionBlock_action" in PLCOpenClasses: |
|
868 |
cls = PLCOpenClasses["actionBlock_action"] |
|
869 |
||
870 |
def setQualifierValue(self, value): |
|
871 |
if self.qualifier: |
|
872 |
self.qualifier.setValue(value) |
|
873 |
setattr(cls, "setQualifierValue", setQualifierValue) |
|
874 |
||
875 |
def getQualifierValue(self): |
|
876 |
if self.qualifier: |
|
877 |
return self.qualifier.getValue() |
|
878 |
return None |
|
879 |
setattr(cls, "getQualifierValue", getQualifierValue) |
|
880 |
||
881 |
def setReferenceName(self, name): |
|
882 |
if self.reference: |
|
883 |
self.reference.setName(name) |
|
884 |
setattr(cls, "setReferenceName", setReferenceName) |
|
885 |
||
886 |
def getReferenceName(self): |
|
887 |
if self.reference: |
|
888 |
return self.reference.getName() |
|
889 |
return None |
|
890 |
setattr(cls, "getReferenceName", getReferenceName) |
|
891 |
||
892 |
def setInlineContent(self, content): |
|
893 |
if self.inline: |
|
894 |
self.inline.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
895 |
self.inline.setText(content) |
|
896 |
setattr(cls, "setInlineContent", setInlineContent) |
|
897 |
||
898 |
def getInlineContent(self): |
|
899 |
if self.inline: |
|
900 |
return self.inline.getText() |
|
901 |
return None |
|
902 |
setattr(cls, "getInlineContent", getInlineContent) |
|
903 |
||
58 | 904 |
def updateElementName(self, old_name, new_name): |
905 |
if self.reference and self.reference.getName() == old_name: |
|
906 |
self.reference.setName(new_name) |
|
907 |
if self.inline: |
|
908 |
self.inline.updateElementName(old_name, new_name) |
|
909 |
setattr(cls, "updateElementName", updateElementName) |
|
910 |
||
2 | 911 |
if "actionBlock" in PLCOpenClasses: |
912 |
cls = PLCOpenClasses["actionBlock"] |
|
913 |
setattr(cls, "getX", getX) |
|
914 |
setattr(cls, "getY", getY) |
|
915 |
setattr(cls, "setX", setX) |
|
916 |
setattr(cls, "setY", setY) |
|
917 |
||
918 |
def setActions(self, actions): |
|
919 |
self.action = [] |
|
920 |
for params in actions: |
|
921 |
action = PLCOpenClasses["actionBlock_action"]() |
|
922 |
action.addQualifier() |
|
923 |
action.setQualifierValue(params["qualifier"]) |
|
924 |
if params["type"] == "reference": |
|
925 |
action.addReference() |
|
926 |
action.setReferenceName(params["value"]) |
|
0 | 927 |
else: |
2 | 928 |
action.addInline() |
929 |
action.setInlineContent(params["value"]) |
|
930 |
if "duration" in params: |
|
931 |
action.setDuration(params["duration"]) |
|
932 |
if "indicator" in params: |
|
933 |
action.setIndicator(params["indicator"]) |
|
934 |
self.action.append(action) |
|
935 |
setattr(cls, "setActions", setActions) |
|
936 |
||
937 |
def getActions(self): |
|
938 |
actions = [] |
|
939 |
for action in self.action: |
|
940 |
params = {} |
|
941 |
params["qualifier"] = action.getQualifierValue() |
|
942 |
if action.getReference(): |
|
943 |
params["type"] = "reference" |
|
944 |
params["value"] = action.getReferenceName() |
|
945 |
elif action.getInline(): |
|
946 |
params["type"] = "inline" |
|
947 |
params["value"] = action.getInlineContent() |
|
948 |
duration = action.getDuration() |
|
949 |
if duration: |
|
950 |
params["duration"] = duration |
|
951 |
indicator = action.getIndicator() |
|
952 |
if indicator: |
|
953 |
params["indicator"] = indicator |
|
954 |
actions.append(params) |
|
955 |
return actions |
|
956 |
setattr(cls, "getActions", getActions) |
|
957 |
||
58 | 958 |
def updateElementName(self, old_name, new_name): |
959 |
for action in self.action: |
|
960 |
action.updateElementName(old_name, new_name) |
|
961 |
setattr(cls, "updateElementName", updateElementName) |
|
962 |
||
2 | 963 |
if "inVariable" in PLCOpenClasses: |
964 |
cls = PLCOpenClasses["inVariable"] |
|
965 |
setattr(cls, "getX", getX) |
|
966 |
setattr(cls, "getY", getY) |
|
967 |
setattr(cls, "setX", setX) |
|
968 |
setattr(cls, "setY", setY) |
|
969 |
||
970 |
def setConnectorEdge(self, edge): |
|
971 |
if not self.edge: |
|
972 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
973 |
self.edge.setValue(edge) |
|
974 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
975 |
||
976 |
def getConnectorEdge(self): |
|
977 |
if self.edge: |
|
978 |
return self.edge.getValue() |
|
979 |
return None |
|
980 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
58 | 981 |
|
982 |
def updateElementName(self, old_name, new_name): |
|
983 |
if self.expression == old_name: |
|
984 |
self.expression = new_name |
|
985 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 986 |
|
987 |
if "outVariable" in PLCOpenClasses: |
|
988 |
cls = PLCOpenClasses["outVariable"] |
|
989 |
setattr(cls, "getX", getX) |
|
990 |
setattr(cls, "getY", getY) |
|
991 |
setattr(cls, "setX", setX) |
|
992 |
setattr(cls, "setY", setY) |
|
993 |
||
994 |
def setConnectorEdge(self, edge): |
|
995 |
if not self.edge: |
|
996 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
997 |
self.edge.setValue(edge) |
|
998 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
999 |
||
1000 |
def getConnectorEdge(self): |
|
1001 |
if self.edge: |
|
1002 |
return self.edge.getValue() |
|
1003 |
return None |
|
1004 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
1005 |
||
58 | 1006 |
def updateElementName(self, old_name, new_name): |
1007 |
if self.expression == old_name: |
|
1008 |
self.expression = new_name |
|
1009 |
setattr(cls, "updateElementName", updateElementName) |
|
1010 |
||
2 | 1011 |
if "inOutVariable" in PLCOpenClasses: |
1012 |
cls = PLCOpenClasses["inOutVariable"] |
|
1013 |
setattr(cls, "getX", getX) |
|
1014 |
setattr(cls, "getY", getY) |
|
1015 |
setattr(cls, "setX", setX) |
|
1016 |
setattr(cls, "setY", setY) |
|
1017 |
||
1018 |
def setInputEdge(self, edge): |
|
1019 |
if not self.edgeIn: |
|
1020 |
self.edgeIn = PLCOpenClasses["edgeModifierType"]() |
|
1021 |
self.edgeIn.setValue(edge) |
|
1022 |
setattr(cls, "setInputEdge", setInputEdge) |
|
1023 |
||
1024 |
def getInputEdge(self): |
|
1025 |
if self.edgeIn: |
|
1026 |
return self.edgeIn.getValue() |
|
1027 |
return None |
|
1028 |
setattr(cls, "getInputEdge", getInputEdge) |
|
1029 |
||
1030 |
def setOutputEdge(self, edge): |
|
1031 |
if not self.edgeOut: |
|
1032 |
self.edgeOut = PLCOpenClasses["edgeModifierType"]() |
|
1033 |
self.edgeOut.setValue(edge) |
|
1034 |
setattr(cls, "setInputEdge", setInputEdge) |
|
1035 |
||
1036 |
def getOutputEdge(self): |
|
1037 |
if self.edgeOut: |
|
1038 |
return self.edgeOut.getValue() |
|
1039 |
return None |
|
1040 |
setattr(cls, "getOutputEdge", getOutputEdge) |
|
1041 |
||
58 | 1042 |
def updateElementName(self, old_name, new_name): |
1043 |
if self.expression == old_name: |
|
1044 |
self.expression = new_name |
|
1045 |
setattr(cls, "updateElementName", updateElementName) |
|
1046 |
||
2 | 1047 |
if "continuation" in PLCOpenClasses: |
1048 |
cls = PLCOpenClasses["continuation"] |
|
1049 |
setattr(cls, "getX", getX) |
|
1050 |
setattr(cls, "getY", getY) |
|
1051 |
setattr(cls, "setX", setX) |
|
1052 |
setattr(cls, "setY", setY) |
|
58 | 1053 |
|
1054 |
def updateElementName(self, old_name, new_name): |
|
1055 |
pass |
|
1056 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1057 |
|
1058 |
if "connector" in PLCOpenClasses: |
|
1059 |
cls = PLCOpenClasses["connector"] |
|
1060 |
setattr(cls, "getX", getX) |
|
1061 |
setattr(cls, "getY", getY) |
|
1062 |
setattr(cls, "setX", setX) |
|
1063 |
setattr(cls, "setY", setY) |
|
58 | 1064 |
|
1065 |
def updateElementName(self, old_name, new_name): |
|
1066 |
pass |
|
1067 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1068 |
|
1069 |
if "connection" in PLCOpenClasses: |
|
1070 |
cls = PLCOpenClasses["connection"] |
|
1071 |
||
1072 |
def setPoints(self, points): |
|
1073 |
self.position = [] |
|
1074 |
for point in points: |
|
1075 |
position = PLCOpenClasses["position"]() |
|
1076 |
position.setX(point.x) |
|
1077 |
position.setY(point.y) |
|
1078 |
self.position.append(position) |
|
1079 |
setattr(cls, "setPoints", setPoints) |
|
1080 |
||
1081 |
def getPoints(self): |
|
1082 |
points = [] |
|
1083 |
for position in self.position: |
|
1084 |
points.append((position.getX(),position.getY())) |
|
1085 |
return points |
|
1086 |
setattr(cls, "getPoints", getPoints) |
|
1087 |
||
1088 |
if "connectionPointIn" in PLCOpenClasses: |
|
1089 |
cls = PLCOpenClasses["connectionPointIn"] |
|
1090 |
||
1091 |
def setRelPosition(self, x, y): |
|
1092 |
self.relPosition = PLCOpenClasses["position"]() |
|
1093 |
self.relPosition.setX(x) |
|
1094 |
self.relPosition.setY(y) |
|
1095 |
setattr(cls, "setRelPosition", setRelPosition) |
|
1096 |
||
1097 |
def getRelPosition(self): |
|
1098 |
if self.relPosition: |
|
1099 |
return self.relPosition.getX(), self.relPosition.getY() |
|
1100 |
else: |
|
0 | 1101 |
return self.relPosition |
2 | 1102 |
setattr(cls, "getRelPosition", getRelPosition) |
1103 |
||
1104 |
def addConnection(self): |
|
1105 |
if not self.content: |
|
1106 |
self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]} |
|
1107 |
else: |
|
1108 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
1109 |
setattr(cls, "addConnection", addConnection) |
|
1110 |
||
1111 |
def removeConnection(self, idx): |
|
1112 |
if self.content: |
|
1113 |
self.content["value"].pop(idx) |
|
1114 |
if len(self.content["value"]) == 0: |
|
1115 |
self.content = None |
|
1116 |
setattr(cls, "removeConnection", removeConnection) |
|
1117 |
||
1118 |
def removeConnections(self): |
|
1119 |
if self.content: |
|
1120 |
self.content = None |
|
1121 |
setattr(cls, "removeConnections", removeConnections) |
|
1122 |
||
1123 |
def getConnections(self): |
|
1124 |
if self.content: |
|
1125 |
return self.content["value"] |
|
1126 |
setattr(cls, "getConnections", getConnections) |
|
1127 |
||
1128 |
def setConnectionId(self, idx, id): |
|
1129 |
if self.content: |
|
1130 |
self.content["value"][idx].setRefLocalId(id) |
|
1131 |
setattr(cls, "setConnectionId", setConnectionId) |
|
1132 |
||
1133 |
def getConnectionId(self, idx): |
|
1134 |
if self.content: |
|
1135 |
return self.content["value"][idx].getRefLocalId() |
|
1136 |
return None |
|
1137 |
setattr(cls, "getConnectionId", getConnectionId) |
|
1138 |
||
1139 |
def setConnectionPoints(self, idx, points): |
|
1140 |
if self.content: |
|
1141 |
self.content["value"][idx].setPoints(points) |
|
1142 |
setattr(cls, "setConnectionPoints", setConnectionPoints) |
|
1143 |
||
1144 |
def getConnectionPoints(self, idx): |
|
1145 |
if self.content: |
|
1146 |
return self.content["value"][idx].getPoints() |
|
1147 |
return None |
|
1148 |
setattr(cls, "getConnectionPoints", getConnectionPoints) |
|
1149 |
||
27 | 1150 |
def setConnectionParameter(self, idx, parameter): |
1151 |
if self.content: |
|
1152 |
self.content["value"][idx].setFormalParameter(parameter) |
|
1153 |
setattr(cls, "setConnectionParameter", setConnectionParameter) |
|
1154 |
||
1155 |
def getConnectionParameter(self, idx): |
|
1156 |
if self.content: |
|
1157 |
return self.content["value"][idx].getFormalParameter() |
|
1158 |
return None |
|
1159 |
setattr(cls, "getConnectionParameter", getConnectionParameter) |
|
1160 |
||
2 | 1161 |
if "connectionPointOut" in PLCOpenClasses: |
1162 |
cls = PLCOpenClasses["connectionPointOut"] |
|
1163 |
||
1164 |
def setRelPosition(self, x, y): |
|
1165 |
self.relPosition = PLCOpenClasses["position"]() |
|
1166 |
self.relPosition.setX(x) |
|
1167 |
self.relPosition.setY(y) |
|
1168 |
setattr(cls, "setRelPosition", setRelPosition) |
|
1169 |
||
1170 |
def getRelPosition(self): |
|
1171 |
if self.relPosition: |
|
1172 |
return self.relPosition.getX(), self.relPosition.getY() |
|
1173 |
return self.relPosition |
|
1174 |
setattr(cls, "getRelPosition", getRelPosition) |
|
1175 |
||
1176 |
if "value" in PLCOpenClasses: |
|
1177 |
cls = PLCOpenClasses["value"] |
|
1178 |
||
1179 |
def setValue(self, value): |
|
1180 |
try: |
|
1181 |
value = eval(value) |
|
1182 |
except: |
|
1183 |
pass |
|
1184 |
if type(value) == ListType: |
|
1185 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
|
1186 |
arrayValue.setValue(value) |
|
1187 |
self.content = {"name":"arrayValue","value":arrayValue} |
|
1188 |
elif type(value) == DictType: |
|
1189 |
structValue = PLCOpenClasses["value_structValue"]() |
|
1190 |
structValue.setValue(value) |
|
1191 |
self.content = {"name":"structValue","value":structValue} |
|
1192 |
else: |
|
1193 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
1194 |
simpleValue.setValue(str(value)) |
|
1195 |
self.content = {"name":"simpleValue","value":simpleValue} |
|
1196 |
setattr(cls, "setValue", setValue) |
|
1197 |
||
1198 |
def getValue(self): |
|
1199 |
value = self.content["value"].getValue() |
|
1200 |
try: |
|
1201 |
value = eval(value) |
|
1202 |
except: |
|
1203 |
pass |
|
1204 |
return value |
|
1205 |
setattr(cls, "getValue", getValue) |
|
1206 |
||
1207 |
if "value_arrayValue" in PLCOpenClasses: |
|
1208 |
cls = PLCOpenClasses["value_arrayValue"] |
|
1209 |
||
1210 |
def setValue(self, array): |
|
1211 |
self.value = [] |
|
1212 |
for value in array: |
|
1213 |
element = PLCOpenClasses["arrayValue_value"]() |
|
1214 |
element.setValue(value) |
|
1215 |
self.value.append(element) |
|
1216 |
setattr(cls, "setValue", setValue) |
|
1217 |
||
1218 |
def getValue(self): |
|
1219 |
return [element.getValue() for element in self.value] |
|
1220 |
setattr(cls, "getValue", getValue) |
|
1221 |
||
1222 |
if "value_structValue" in PLCOpenClasses: |
|
1223 |
cls = PLCOpenClasses["value_structValue"] |
|
1224 |
||
1225 |
def setValue(self, dict): |
|
1226 |
self.value = [] |
|
1227 |
for name,value in dict.items(): |
|
1228 |
element = PLCOpenClasses["structValue_value"]() |
|
1229 |
element.setMember(name) |
|
1230 |
element.setValue(value) |
|
1231 |
self.value.append(element) |
|
1232 |
setattr(cls, "setValue", setValue) |
|
1233 |
||
1234 |
def getValue(self): |
|
1235 |
value = {} |
|
1236 |
for element in self.value: |
|
1237 |
value[element.getMember()] = element.getValue() |
|
1238 |
return value |
|
1239 |
setattr(cls, "getValue", getValue) |