author | lbessard |
Fri, 20 Jul 2007 23:04:50 +0200 | |
changeset 51 | 47c72c77590a |
parent 47 | 2b2f8d88e6d3 |
child 58 | 39cd981ff242 |
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 |
# |
|
7 |
#Copyright (C): 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 |
|
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 |
|
19 |
#Lesser General Public License for more details. |
|
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 |
||
109 |
if "project" in PLCOpenClasses: |
|
110 |
cls = PLCOpenClasses["project"] |
|
111 |
cls.singleLineAttributes = False |
|
112 |
||
113 |
def getFileHeader(self): |
|
114 |
fileheader = {} |
|
115 |
fileheader["companyName"] = self.fileHeader.getCompanyName() |
|
116 |
if self.fileHeader.getCompanyURL(): |
|
117 |
fileheader["companyURL"] = self.fileHeader.getCompanyURL() |
|
118 |
fileheader["productName"] = self.fileHeader.getProductName() |
|
119 |
fileheader["productVersion"] = self.fileHeader.getProductVersion() |
|
120 |
if self.fileHeader.getProductRelease(): |
|
121 |
fileheader["productRelease"] = self.fileHeader.getProductRelease() |
|
122 |
fileheader["creationDateTime"] = self.fileHeader.getCreationDateTime() |
|
123 |
if self.fileHeader.getContentDescription(): |
|
124 |
fileheader["contentDescription"] = self.fileHeader.getContentDescription() |
|
125 |
return fileheader |
|
126 |
setattr(cls, "getFileHeader", getFileHeader) |
|
127 |
||
128 |
def setFileHeader(self, fileheader): |
|
129 |
self.fileHeader.setCompanyName(fileheader["companyName"]) |
|
130 |
if "companyURL" in fileheader: |
|
131 |
self.fileHeader.setCompanyURL(fileheader["companyURL"]) |
|
132 |
self.fileHeader.setProductName(fileheader["productName"]) |
|
133 |
self.fileHeader.setProductVersion(fileheader["productVersion"]) |
|
134 |
if "productRelease" in fileheader: |
|
135 |
self.fileHeader.setProductRelease(fileheader["productRelease"]) |
|
136 |
self.fileHeader.setCreationDateTime(fileheader["creationDateTime"]) |
|
137 |
if "contentDescription" in fileheader: |
|
138 |
self.fileHeader.setContentDescription(fileheader["contentDescription"]) |
|
139 |
setattr(cls, "setFileHeader", setFileHeader) |
|
140 |
||
141 |
def setName(self, name): |
|
142 |
self.contentHeader.setName(name) |
|
143 |
setattr(cls, "setName", setName) |
|
0 | 144 |
|
2 | 145 |
def getName(self): |
146 |
return self.contentHeader.getName() |
|
147 |
setattr(cls, "getName", getName) |
|
148 |
||
149 |
def getPous(self): |
|
150 |
return self.types.getPouElements() |
|
151 |
setattr(cls, "getPous", getPous) |
|
152 |
||
153 |
def getPou(self, name): |
|
154 |
return self.types.getPouElement(name) |
|
155 |
setattr(cls, "getPou", getPou) |
|
156 |
||
157 |
def appendPou(self, name, pou_type, body_type): |
|
158 |
self.types.appendPouElement(name, pou_type, body_type) |
|
159 |
setattr(cls, "appendPou", appendPou) |
|
0 | 160 |
|
2 | 161 |
def insertPou(self, index, pou): |
162 |
self.types.insertPouElement(index, pou) |
|
163 |
setattr(cls, "insertPou", insertPou) |
|
164 |
||
165 |
def removePou(self, name): |
|
166 |
self.types.removePouElement(name) |
|
167 |
setattr(cls, "removePou", removePou) |
|
168 |
||
169 |
def getConfigurations(self): |
|
170 |
configurations = self.instances.configurations.getConfiguration() |
|
171 |
if configurations: |
|
172 |
return configurations |
|
173 |
return [] |
|
174 |
setattr(cls, "getConfigurations", getConfigurations) |
|
175 |
||
176 |
def getConfiguration(self, name): |
|
177 |
for configuration in self.instances.configurations.getConfiguration(): |
|
178 |
if configuration.getName() == name: |
|
179 |
return configuration |
|
180 |
return None |
|
181 |
setattr(cls, "getConfiguration", getConfiguration) |
|
182 |
||
183 |
def addConfiguration(self, name): |
|
184 |
for configuration in self.instances.configurations.getConfiguration(): |
|
185 |
if configuration.getName() == name: |
|
186 |
raise ValueError, "\"%s\" configuration already exists !!!"%name |
|
187 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
188 |
new_configuration.setName(name) |
|
189 |
self.instances.configurations.appendConfiguration(new_configuration) |
|
190 |
setattr(cls, "addConfiguration", addConfiguration) |
|
191 |
||
192 |
def removeConfiguration(self, name): |
|
193 |
found = False |
|
194 |
for idx, configuration in enumerate(self.instances.configurations.getConfiguration()): |
|
195 |
if configuration.getName() == name: |
|
196 |
self.instances.configurations.removeConfiguration(idx) |
|
197 |
found = True |
|
198 |
break |
|
199 |
if not found: |
|
200 |
raise ValueError, "\"%s\" configuration doesn't exist !!!"%name |
|
201 |
setattr(cls, "removeConfiguration", removeConfiguration) |
|
202 |
||
203 |
def getConfigurationResource(self, config_name, name): |
|
204 |
configuration = self.getConfiguration(config_name) |
|
205 |
if configuration: |
|
206 |
for resource in configuration.getResource(): |
|
207 |
if resource.getName() == name: |
|
208 |
return resource |
|
209 |
return None |
|
210 |
setattr(cls, "getConfigurationResource", getConfigurationResource) |
|
211 |
||
212 |
def addConfigurationResource(self, config_name, name): |
|
213 |
configuration = self.getConfiguration(config_name) |
|
214 |
if configuration: |
|
215 |
for resource in configuration.getResource(): |
|
216 |
if resource.getName() == name: |
|
217 |
raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) |
|
218 |
new_resource = PLCOpenClasses["configuration_resource"]() |
|
219 |
new_resource.setName(name) |
|
220 |
configuration.appendResource(new_resource) |
|
221 |
setattr(cls, "addConfigurationResource", addConfigurationResource) |
|
222 |
||
223 |
def removeConfigurationResource(self, config_name, name): |
|
224 |
configuration = self.getConfiguration(config_name) |
|
225 |
if configuration: |
|
0 | 226 |
found = False |
2 | 227 |
for idx, resource in enumerate(configuration.getResource()): |
228 |
if resource.getName() == name: |
|
229 |
configuration.removeResource(idx) |
|
0 | 230 |
found = True |
231 |
break |
|
232 |
if not found: |
|
2 | 233 |
raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name) |
234 |
setattr(cls, "removeConfigurationResource", removeConfigurationResource) |
|
235 |
||
236 |
PLCOpenClasses["project_fileHeader"].singleLineAttributes = False |
|
237 |
||
238 |
if "project_types" in PLCOpenClasses: |
|
239 |
cls = PLCOpenClasses["project_types"] |
|
240 |
||
241 |
def getPouElements(self): |
|
242 |
return self.pous.getPou() |
|
243 |
setattr(cls, "getPouElements", getPouElements) |
|
244 |
||
245 |
def getPouElement(self, name): |
|
246 |
elements = self.pous.getPou() |
|
247 |
for element in elements: |
|
248 |
if element.getName() == name: |
|
249 |
return element |
|
250 |
return None |
|
251 |
setattr(cls, "getPouElement", getPouElement) |
|
252 |
||
253 |
def appendPouElement(self, name, pou_type, body_type): |
|
254 |
for element in self.pous.getPou(): |
|
255 |
if element.getName() == name: |
|
256 |
raise ValueError, "\"%s\" POU already exists !!!"%name |
|
257 |
new_pou = PLCOpenClasses["pous_pou"]() |
|
258 |
new_pou.setName(name) |
|
259 |
new_pou.pouType.setValue(pou_type) |
|
260 |
new_pou.setBody(PLCOpenClasses["body"]()) |
|
261 |
new_pou.setBodyType(body_type) |
|
262 |
self.pous.appendPou(new_pou) |
|
263 |
setattr(cls, "appendPouElement", appendPouElement) |
|
264 |
||
265 |
def insertPouElement(self, index, pou): |
|
266 |
self.pous.insertPou(index, pou) |
|
267 |
setattr(cls, "insertPouElement", insertPouElement) |
|
268 |
||
269 |
def removePouElement(self, name): |
|
270 |
found = False |
|
271 |
for idx, element in enumerate(self.pous.getPou()): |
|
272 |
if element.getName() == name: |
|
273 |
self.pous.removePou(idx) |
|
274 |
found = True |
|
275 |
break |
|
276 |
if not found: |
|
277 |
raise ValueError, "\"%s\" POU doesn't exist !!!"%name |
|
278 |
setattr(cls, "removePouElement", removePouElement) |
|
279 |
||
280 |
def setBodyType(self, type): |
|
281 |
if type == "IL": |
|
282 |
self.body.setContent("IL", PLCOpenClasses["formattedText"]()) |
|
283 |
elif type == "ST": |
|
284 |
self.body.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
285 |
elif type == "LD": |
|
286 |
self.body.setContent("LD", PLCOpenClasses["body_LD"]()) |
|
287 |
elif type == "FBD": |
|
288 |
self.body.setContent("FBD", PLCOpenClasses["body_FBD"]()) |
|
289 |
elif type == "SFC": |
|
290 |
self.body.setContent("SFC", PLCOpenClasses["body_SFC"]()) |
|
291 |
else: |
|
292 |
raise ValueError, "%s isn't a valid body type!"%type |
|
293 |
||
294 |
def getBodyType(self): |
|
295 |
return self.body.getContent()["name"] |
|
296 |
||
297 |
def addInstance(self, name, instance): |
|
298 |
self.body.appendContentInstance(name, instance) |
|
299 |
||
300 |
def getInstances(self): |
|
301 |
return self.body.getContentInstances() |
|
302 |
||
303 |
def getInstance(self, id): |
|
304 |
return self.body.getContentInstance(id) |
|
305 |
||
306 |
def getRandomInstance(self, exclude): |
|
307 |
return self.body.getContentRandomInstance(exclude) |
|
308 |
||
309 |
def getInstanceByName(self, name): |
|
310 |
return self.body.getContentInstanceByName(name) |
|
311 |
||
312 |
def removeInstance(self, id): |
|
313 |
self.body.removeContentInstance(id) |
|
314 |
||
315 |
def setText(self, text): |
|
316 |
self.body.setText(text) |
|
317 |
||
318 |
def getText(self): |
|
319 |
return self.body.getText() |
|
320 |
setattr(cls, "getText", getText) |
|
321 |
||
322 |
if "pous_pou" in PLCOpenClasses: |
|
323 |
cls = PLCOpenClasses["pous_pou"] |
|
324 |
||
325 |
setattr(cls, "setBodyType", setBodyType) |
|
326 |
setattr(cls, "getBodyType", getBodyType) |
|
327 |
setattr(cls, "addInstance", addInstance) |
|
328 |
setattr(cls, "getInstances", getInstances) |
|
329 |
setattr(cls, "getInstance", getInstance) |
|
330 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
331 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
332 |
setattr(cls, "removeInstance", removeInstance) |
|
333 |
setattr(cls, "setText", setText) |
|
334 |
setattr(cls, "getText", getText) |
|
335 |
||
336 |
def getVars(self): |
|
337 |
vars = [] |
|
338 |
reverse_types = {} |
|
339 |
for name, value in VarTypes.items(): |
|
340 |
reverse_types[value] = name |
|
341 |
for varlist in self.interface.getContent(): |
|
342 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
|
343 |
return vars |
|
344 |
setattr(cls, "getVars", getVars) |
|
345 |
||
346 |
def setVars(self, vars): |
|
347 |
self.interface.setContent([]) |
|
348 |
for vartype, varlist in vars: |
|
349 |
self.interface.appendContent(VarTypes[vartype], varlist) |
|
350 |
setattr(cls, "setVars", setVars) |
|
351 |
||
352 |
def addTransition(self, name, type): |
|
353 |
if not self.transitions: |
|
354 |
self.addTransitions() |
|
355 |
self.transitions.setTransition([]) |
|
356 |
transition = PLCOpenClasses["transitions_transition"]() |
|
357 |
transition.setName(name) |
|
358 |
transition.setBodyType(type) |
|
359 |
self.transitions.appendTransition(transition) |
|
360 |
setattr(cls, "addTransition", addTransition) |
|
361 |
||
362 |
def getTransition(self, name): |
|
363 |
if self.transitions: |
|
364 |
for transition in self.transitions.getTransition(): |
|
365 |
if transition.getName() == name: |
|
366 |
return transition |
|
367 |
return None |
|
368 |
setattr(cls, "getTransition", getTransition) |
|
369 |
||
370 |
def getTransitionList(self): |
|
371 |
if self.transitions: |
|
372 |
return self.transitions.getTransition() |
|
373 |
return [] |
|
374 |
setattr(cls, "getTransitionList", getTransitionList) |
|
375 |
||
376 |
def removeTransition(self, name): |
|
377 |
if self.transitions: |
|
378 |
transitions = self.transitions.getTransition() |
|
379 |
i = 0 |
|
380 |
removed = False |
|
381 |
while i < len(transitions) and not removed: |
|
382 |
if transitions[i].getName() == name: |
|
46 | 383 |
transitions.pop(i) |
2 | 384 |
removed = True |
385 |
i += 1 |
|
386 |
if not removed: |
|
387 |
raise ValueError, "Transition with name %s doesn't exists!"%name |
|
388 |
setattr(cls, "removeTransition", removeTransition) |
|
389 |
||
390 |
def addAction(self, name, type): |
|
391 |
if not self.actions: |
|
392 |
self.addActions() |
|
393 |
self.actions.setAction([]) |
|
394 |
action = PLCOpenClasses["actions_action"]() |
|
395 |
action.setName(name) |
|
396 |
action.setBodyType(type) |
|
397 |
self.actions.appendAction(action) |
|
398 |
setattr(cls, "addAction", addAction) |
|
399 |
||
400 |
def getAction(self, name): |
|
401 |
if self.actions: |
|
402 |
for action in self.actions.getAction(): |
|
403 |
if action.getName() == name: |
|
404 |
return action |
|
405 |
return None |
|
406 |
setattr(cls, "getAction", getAction) |
|
407 |
||
408 |
def getActionList(self): |
|
409 |
if self.actions: |
|
410 |
return self.actions.getAction() |
|
411 |
return [] |
|
412 |
setattr(cls, "getActionList", getActionList) |
|
413 |
||
414 |
def removeAction(self, name): |
|
415 |
if self.actions: |
|
416 |
actions = self.actions.getAction() |
|
417 |
i = 0 |
|
418 |
removed = False |
|
419 |
while i < len(actions) and not removed: |
|
420 |
if actions[i].getName() == name: |
|
46 | 421 |
actions.pop(i) |
2 | 422 |
removed = True |
423 |
i += 1 |
|
424 |
if not removed: |
|
425 |
raise ValueError, "Action with name %s doesn't exists!"%name |
|
426 |
setattr(cls, "removeAction", removeAction) |
|
427 |
||
428 |
if "transitions_transition" in PLCOpenClasses: |
|
429 |
cls = PLCOpenClasses["transitions_transition"] |
|
430 |
||
431 |
setattr(cls, "setBodyType", setBodyType) |
|
432 |
setattr(cls, "getBodyType", getBodyType) |
|
433 |
setattr(cls, "addInstance", addInstance) |
|
434 |
setattr(cls, "getInstances", getInstances) |
|
435 |
setattr(cls, "getInstance", getInstance) |
|
436 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
437 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
438 |
setattr(cls, "removeInstance", removeInstance) |
|
439 |
setattr(cls, "setText", setText) |
|
440 |
setattr(cls, "getText", getText) |
|
441 |
||
442 |
if "actions_action" in PLCOpenClasses: |
|
443 |
cls = PLCOpenClasses["actions_action"] |
|
444 |
||
445 |
setattr(cls, "setBodyType", setBodyType) |
|
446 |
setattr(cls, "getBodyType", getBodyType) |
|
447 |
setattr(cls, "addInstance", addInstance) |
|
448 |
setattr(cls, "getInstances", getInstances) |
|
449 |
setattr(cls, "getInstance", getInstance) |
|
450 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
451 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
452 |
setattr(cls, "removeInstance", removeInstance) |
|
453 |
setattr(cls, "setText", setText) |
|
454 |
setattr(cls, "getText", getText) |
|
455 |
||
456 |
if "body" in PLCOpenClasses: |
|
457 |
cls = PLCOpenClasses["body"] |
|
458 |
||
459 |
def appendContentInstance(self, name, instance): |
|
460 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
461 |
self.content["value"].appendContent(name, instance) |
|
462 |
else: |
|
463 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
464 |
setattr(cls, "appendContentInstance", appendContentInstance) |
|
465 |
||
466 |
def getContentInstances(self): |
|
467 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
468 |
instances = [] |
|
469 |
for element in self.content["value"].getContent(): |
|
470 |
instances.append(element["value"]) |
|
471 |
return instances |
|
472 |
else: |
|
473 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
474 |
setattr(cls, "getContentInstances", getContentInstances) |
|
475 |
||
476 |
def getContentInstance(self, id): |
|
477 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
478 |
for element in self.content["value"].getContent(): |
|
479 |
if element["value"].getLocalId() == id: |
|
480 |
return element["value"] |
|
0 | 481 |
return None |
2 | 482 |
else: |
483 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
484 |
setattr(cls, "getContentInstance", getContentInstance) |
|
485 |
||
486 |
def getContentRandomInstance(self, exclude): |
|
487 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
488 |
for element in self.content["value"].getContent(): |
|
489 |
if element["value"].getLocalId() not in exclude: |
|
490 |
return element["value"] |
|
491 |
return None |
|
492 |
else: |
|
493 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
494 |
setattr(cls, "getContentRandomInstance", getContentRandomInstance) |
|
495 |
||
496 |
def getContentInstanceByName(self, name): |
|
497 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
498 |
for element in self.content["value"].getContent(): |
|
499 |
if element["value"].getLocalId() == name: |
|
500 |
return element["value"] |
|
501 |
else: |
|
502 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
503 |
setattr(cls, "getContentInstanceByName", getContentInstanceByName) |
|
504 |
||
505 |
def removeContentInstance(self, id): |
|
506 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
507 |
i = 0 |
|
508 |
removed = False |
|
509 |
elements = self.content["value"].getContent() |
|
510 |
while i < len(elements) and not removed: |
|
511 |
if elements[i]["value"].getLocalId() == id: |
|
512 |
self.content["value"].removeContent(i) |
|
513 |
removed = True |
|
514 |
i += 1 |
|
515 |
if not removed: |
|
516 |
raise ValueError, "Instance with id %d doesn't exists!"%id |
|
517 |
else: |
|
518 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
519 |
setattr(cls, "removeContentInstance", removeContentInstance) |
|
520 |
||
521 |
def setText(self, text): |
|
522 |
if self.content["name"] in ["IL","ST"]: |
|
523 |
self.content["value"].setText(text) |
|
524 |
else: |
|
525 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
526 |
setattr(cls, "setText", setText) |
|
527 |
||
528 |
def getText(self): |
|
529 |
if self.content["name"] in ["IL","ST"]: |
|
530 |
return self.content["value"].getText() |
|
531 |
else: |
|
532 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
533 |
setattr(cls, "getText", getText) |
|
534 |
||
535 |
def getX(self): |
|
536 |
return self.position.getX() |
|
537 |
||
538 |
def getY(self): |
|
539 |
return self.position.getY() |
|
540 |
||
541 |
def setX(self, x): |
|
542 |
self.position.setX(x) |
|
543 |
||
544 |
def setY(self, y): |
|
545 |
self.position.setY(y) |
|
546 |
||
547 |
if "comment" in PLCOpenClasses: |
|
548 |
cls = PLCOpenClasses["comment"] |
|
549 |
setattr(cls, "getX", getX) |
|
550 |
setattr(cls, "getY", getY) |
|
551 |
setattr(cls, "setX", setX) |
|
552 |
setattr(cls, "setY", setY) |
|
553 |
||
554 |
def setContentText(self, text): |
|
555 |
self.content.setText(text) |
|
556 |
setattr(cls, "setContentText", setContentText) |
|
0 | 557 |
|
2 | 558 |
def getContentText(self): |
559 |
return self.content.getText() |
|
560 |
setattr(cls, "getContentText", getContentText) |
|
561 |
||
562 |
if "block" in PLCOpenClasses: |
|
563 |
cls = PLCOpenClasses["block"] |
|
564 |
setattr(cls, "getX", getX) |
|
565 |
setattr(cls, "getY", getY) |
|
566 |
setattr(cls, "setX", setX) |
|
567 |
setattr(cls, "setY", setY) |
|
568 |
||
569 |
if "inputVariables_variable" in PLCOpenClasses: |
|
570 |
cls = PLCOpenClasses["inputVariables_variable"] |
|
571 |
||
572 |
def setConnectorEdge(self, edge): |
|
573 |
if not self.edge: |
|
574 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
575 |
self.edge.setValue(edge) |
|
576 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
577 |
||
578 |
def getConnectorEdge(self): |
|
579 |
if self.edge: |
|
580 |
return self.edge.getValue() |
|
581 |
return None |
|
582 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
583 |
||
584 |
if "outputVariables_variable" in PLCOpenClasses: |
|
585 |
cls = PLCOpenClasses["outputVariables_variable"] |
|
586 |
||
587 |
def setConnectorEdge(self, edge): |
|
588 |
if not self.edge: |
|
589 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
590 |
self.edge.setValue(edge) |
|
591 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
592 |
||
593 |
def getConnectorEdge(self): |
|
594 |
if self.edge: |
|
595 |
return self.edge.getValue() |
|
596 |
return None |
|
597 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
598 |
||
599 |
if "leftPowerRail" in PLCOpenClasses: |
|
600 |
cls = PLCOpenClasses["leftPowerRail"] |
|
601 |
setattr(cls, "getX", getX) |
|
602 |
setattr(cls, "getY", getY) |
|
603 |
setattr(cls, "setX", setX) |
|
604 |
setattr(cls, "setY", setY) |
|
605 |
||
606 |
if "contact" in PLCOpenClasses: |
|
607 |
cls = PLCOpenClasses["contact"] |
|
608 |
setattr(cls, "getX", getX) |
|
609 |
setattr(cls, "getY", getY) |
|
610 |
setattr(cls, "setX", setX) |
|
611 |
setattr(cls, "setY", setY) |
|
612 |
||
613 |
def setContactEdge(self, edge): |
|
614 |
if not self.edge: |
|
615 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
616 |
self.edge.setValue(edge) |
|
617 |
setattr(cls, "setContactEdge", setContactEdge) |
|
618 |
||
619 |
def getContactEdge(self): |
|
620 |
if self.edge: |
|
621 |
return self.edge.getValue() |
|
622 |
return None |
|
623 |
setattr(cls, "getContactEdge", getContactEdge) |
|
624 |
||
625 |
if "coil" in PLCOpenClasses: |
|
626 |
cls = PLCOpenClasses["coil"] |
|
627 |
setattr(cls, "getX", getX) |
|
628 |
setattr(cls, "getY", getY) |
|
629 |
setattr(cls, "setX", setX) |
|
630 |
setattr(cls, "setY", setY) |
|
631 |
||
632 |
def setCoilStorage(self, edge): |
|
633 |
if not self.storage: |
|
634 |
self.storage = PLCOpenClasses["storageModifierType"]() |
|
635 |
self.storage.setValue(edge) |
|
636 |
setattr(cls, "setCoilStorage", setCoilStorage) |
|
637 |
||
638 |
def getCoilStorage(self): |
|
639 |
if self.storage: |
|
640 |
return self.storage.getValue() |
|
641 |
return None |
|
642 |
setattr(cls, "getCoilStorage", getCoilStorage) |
|
643 |
||
644 |
if "rightPowerRail" in PLCOpenClasses: |
|
645 |
cls = PLCOpenClasses["rightPowerRail"] |
|
646 |
setattr(cls, "getX", getX) |
|
647 |
setattr(cls, "getY", getY) |
|
648 |
setattr(cls, "setX", setX) |
|
649 |
setattr(cls, "setY", setY) |
|
650 |
||
651 |
if "step" in PLCOpenClasses: |
|
652 |
cls = PLCOpenClasses["step"] |
|
653 |
setattr(cls, "getX", getX) |
|
654 |
setattr(cls, "getY", getY) |
|
655 |
setattr(cls, "setX", setX) |
|
656 |
setattr(cls, "setY", setY) |
|
657 |
||
658 |
if "transition" in PLCOpenClasses: |
|
659 |
cls = PLCOpenClasses["transition"] |
|
660 |
setattr(cls, "getX", getX) |
|
661 |
setattr(cls, "getY", getY) |
|
662 |
setattr(cls, "setX", setX) |
|
663 |
setattr(cls, "setY", setY) |
|
664 |
||
665 |
def setConditionContent(self, type, value): |
|
666 |
if not self.condition: |
|
667 |
self.addCondition() |
|
668 |
if type == "reference": |
|
669 |
condition = PLCOpenClasses["condition_reference"]() |
|
670 |
condition.setName(value) |
|
671 |
elif type == "inline": |
|
672 |
condition = PLCOpenClasses["condition_inline"]() |
|
673 |
condition.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
674 |
condition.setText(value) |
|
675 |
self.condition.setContent(type, condition) |
|
676 |
setattr(cls, "setConditionContent", setConditionContent) |
|
0 | 677 |
|
2 | 678 |
def getConditionContent(self): |
679 |
if self.condition: |
|
680 |
content = self.condition.getContent() |
|
681 |
values = {"type" : content["name"]} |
|
682 |
if values["type"] == "reference": |
|
683 |
values["value"] = content["value"].getName() |
|
684 |
elif values["type"] == "inline": |
|
685 |
values["value"] = content["value"].getText() |
|
686 |
return values |
|
687 |
return "" |
|
688 |
setattr(cls, "getConditionContent", getConditionContent) |
|
689 |
||
690 |
if "selectionDivergence" in PLCOpenClasses: |
|
691 |
cls = PLCOpenClasses["selectionDivergence"] |
|
692 |
setattr(cls, "getX", getX) |
|
693 |
setattr(cls, "getY", getY) |
|
694 |
setattr(cls, "setX", setX) |
|
695 |
setattr(cls, "setY", setY) |
|
696 |
||
697 |
if "selectionConvergence" in PLCOpenClasses: |
|
698 |
cls = PLCOpenClasses["selectionConvergence"] |
|
699 |
setattr(cls, "getX", getX) |
|
700 |
setattr(cls, "getY", getY) |
|
701 |
setattr(cls, "setX", setX) |
|
702 |
setattr(cls, "setY", setY) |
|
703 |
||
704 |
if "simultaneousDivergence" in PLCOpenClasses: |
|
705 |
cls = PLCOpenClasses["simultaneousDivergence"] |
|
706 |
setattr(cls, "getX", getX) |
|
707 |
setattr(cls, "getY", getY) |
|
708 |
setattr(cls, "setX", setX) |
|
709 |
setattr(cls, "setY", setY) |
|
710 |
||
711 |
if "simultaneousDivergence" in PLCOpenClasses: |
|
712 |
cls = PLCOpenClasses["simultaneousConvergence"] |
|
713 |
setattr(cls, "getX", getX) |
|
714 |
setattr(cls, "getY", getY) |
|
715 |
setattr(cls, "setX", setX) |
|
716 |
setattr(cls, "setY", setY) |
|
717 |
||
718 |
if "jumpStep" in PLCOpenClasses: |
|
719 |
cls = PLCOpenClasses["jumpStep"] |
|
720 |
setattr(cls, "getX", getX) |
|
721 |
setattr(cls, "getY", getY) |
|
722 |
setattr(cls, "setX", setX) |
|
723 |
setattr(cls, "setY", setY) |
|
724 |
||
725 |
if "actionBlock_action" in PLCOpenClasses: |
|
726 |
cls = PLCOpenClasses["actionBlock_action"] |
|
727 |
||
728 |
def setQualifierValue(self, value): |
|
729 |
if self.qualifier: |
|
730 |
self.qualifier.setValue(value) |
|
731 |
setattr(cls, "setQualifierValue", setQualifierValue) |
|
732 |
||
733 |
def getQualifierValue(self): |
|
734 |
if self.qualifier: |
|
735 |
return self.qualifier.getValue() |
|
736 |
return None |
|
737 |
setattr(cls, "getQualifierValue", getQualifierValue) |
|
738 |
||
739 |
def setReferenceName(self, name): |
|
740 |
if self.reference: |
|
741 |
self.reference.setName(name) |
|
742 |
setattr(cls, "setReferenceName", setReferenceName) |
|
743 |
||
744 |
def getReferenceName(self): |
|
745 |
if self.reference: |
|
746 |
return self.reference.getName() |
|
747 |
return None |
|
748 |
setattr(cls, "getReferenceName", getReferenceName) |
|
749 |
||
750 |
def setInlineContent(self, content): |
|
751 |
if self.inline: |
|
752 |
self.inline.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
753 |
self.inline.setText(content) |
|
754 |
setattr(cls, "setInlineContent", setInlineContent) |
|
755 |
||
756 |
def getInlineContent(self): |
|
757 |
if self.inline: |
|
758 |
return self.inline.getText() |
|
759 |
return None |
|
760 |
setattr(cls, "getInlineContent", getInlineContent) |
|
761 |
||
762 |
if "actionBlock" in PLCOpenClasses: |
|
763 |
cls = PLCOpenClasses["actionBlock"] |
|
764 |
setattr(cls, "getX", getX) |
|
765 |
setattr(cls, "getY", getY) |
|
766 |
setattr(cls, "setX", setX) |
|
767 |
setattr(cls, "setY", setY) |
|
768 |
||
769 |
def setActions(self, actions): |
|
770 |
self.action = [] |
|
771 |
for params in actions: |
|
772 |
action = PLCOpenClasses["actionBlock_action"]() |
|
773 |
action.addQualifier() |
|
774 |
action.setQualifierValue(params["qualifier"]) |
|
775 |
if params["type"] == "reference": |
|
776 |
action.addReference() |
|
777 |
action.setReferenceName(params["value"]) |
|
0 | 778 |
else: |
2 | 779 |
action.addInline() |
780 |
action.setInlineContent(params["value"]) |
|
781 |
if "duration" in params: |
|
782 |
action.setDuration(params["duration"]) |
|
783 |
if "indicator" in params: |
|
784 |
action.setIndicator(params["indicator"]) |
|
785 |
self.action.append(action) |
|
786 |
setattr(cls, "setActions", setActions) |
|
787 |
||
788 |
def getActions(self): |
|
789 |
actions = [] |
|
790 |
for action in self.action: |
|
791 |
params = {} |
|
792 |
params["qualifier"] = action.getQualifierValue() |
|
793 |
if action.getReference(): |
|
794 |
params["type"] = "reference" |
|
795 |
params["value"] = action.getReferenceName() |
|
796 |
elif action.getInline(): |
|
797 |
params["type"] = "inline" |
|
798 |
params["value"] = action.getInlineContent() |
|
799 |
duration = action.getDuration() |
|
800 |
if duration: |
|
801 |
params["duration"] = duration |
|
802 |
indicator = action.getIndicator() |
|
803 |
if indicator: |
|
804 |
params["indicator"] = indicator |
|
805 |
actions.append(params) |
|
806 |
return actions |
|
807 |
setattr(cls, "getActions", getActions) |
|
808 |
||
809 |
if "inVariable" in PLCOpenClasses: |
|
810 |
cls = PLCOpenClasses["inVariable"] |
|
811 |
setattr(cls, "getX", getX) |
|
812 |
setattr(cls, "getY", getY) |
|
813 |
setattr(cls, "setX", setX) |
|
814 |
setattr(cls, "setY", setY) |
|
815 |
||
816 |
def setConnectorEdge(self, edge): |
|
817 |
if not self.edge: |
|
818 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
819 |
self.edge.setValue(edge) |
|
820 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
821 |
||
822 |
def getConnectorEdge(self): |
|
823 |
if self.edge: |
|
824 |
return self.edge.getValue() |
|
825 |
return None |
|
826 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
827 |
||
828 |
if "outVariable" in PLCOpenClasses: |
|
829 |
cls = PLCOpenClasses["outVariable"] |
|
830 |
setattr(cls, "getX", getX) |
|
831 |
setattr(cls, "getY", getY) |
|
832 |
setattr(cls, "setX", setX) |
|
833 |
setattr(cls, "setY", setY) |
|
834 |
||
835 |
def setConnectorEdge(self, edge): |
|
836 |
if not self.edge: |
|
837 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
838 |
self.edge.setValue(edge) |
|
839 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
840 |
||
841 |
def getConnectorEdge(self): |
|
842 |
if self.edge: |
|
843 |
return self.edge.getValue() |
|
844 |
return None |
|
845 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
846 |
||
847 |
if "inOutVariable" in PLCOpenClasses: |
|
848 |
cls = PLCOpenClasses["inOutVariable"] |
|
849 |
setattr(cls, "getX", getX) |
|
850 |
setattr(cls, "getY", getY) |
|
851 |
setattr(cls, "setX", setX) |
|
852 |
setattr(cls, "setY", setY) |
|
853 |
||
854 |
def setInputEdge(self, edge): |
|
855 |
if not self.edgeIn: |
|
856 |
self.edgeIn = PLCOpenClasses["edgeModifierType"]() |
|
857 |
self.edgeIn.setValue(edge) |
|
858 |
setattr(cls, "setInputEdge", setInputEdge) |
|
859 |
||
860 |
def getInputEdge(self): |
|
861 |
if self.edgeIn: |
|
862 |
return self.edgeIn.getValue() |
|
863 |
return None |
|
864 |
setattr(cls, "getInputEdge", getInputEdge) |
|
865 |
||
866 |
def setOutputEdge(self, edge): |
|
867 |
if not self.edgeOut: |
|
868 |
self.edgeOut = PLCOpenClasses["edgeModifierType"]() |
|
869 |
self.edgeOut.setValue(edge) |
|
870 |
setattr(cls, "setInputEdge", setInputEdge) |
|
871 |
||
872 |
def getOutputEdge(self): |
|
873 |
if self.edgeOut: |
|
874 |
return self.edgeOut.getValue() |
|
875 |
return None |
|
876 |
setattr(cls, "getOutputEdge", getOutputEdge) |
|
877 |
||
878 |
if "continuation" in PLCOpenClasses: |
|
879 |
cls = PLCOpenClasses["continuation"] |
|
880 |
setattr(cls, "getX", getX) |
|
881 |
setattr(cls, "getY", getY) |
|
882 |
setattr(cls, "setX", setX) |
|
883 |
setattr(cls, "setY", setY) |
|
884 |
||
885 |
if "connector" in PLCOpenClasses: |
|
886 |
cls = PLCOpenClasses["connector"] |
|
887 |
setattr(cls, "getX", getX) |
|
888 |
setattr(cls, "getY", getY) |
|
889 |
setattr(cls, "setX", setX) |
|
890 |
setattr(cls, "setY", setY) |
|
891 |
||
892 |
if "connection" in PLCOpenClasses: |
|
893 |
cls = PLCOpenClasses["connection"] |
|
894 |
||
895 |
def setPoints(self, points): |
|
896 |
self.position = [] |
|
897 |
for point in points: |
|
898 |
position = PLCOpenClasses["position"]() |
|
899 |
position.setX(point.x) |
|
900 |
position.setY(point.y) |
|
901 |
self.position.append(position) |
|
902 |
setattr(cls, "setPoints", setPoints) |
|
903 |
||
904 |
def getPoints(self): |
|
905 |
points = [] |
|
906 |
for position in self.position: |
|
907 |
points.append((position.getX(),position.getY())) |
|
908 |
return points |
|
909 |
setattr(cls, "getPoints", getPoints) |
|
910 |
||
911 |
if "connectionPointIn" in PLCOpenClasses: |
|
912 |
cls = PLCOpenClasses["connectionPointIn"] |
|
913 |
||
914 |
def setRelPosition(self, x, y): |
|
915 |
self.relPosition = PLCOpenClasses["position"]() |
|
916 |
self.relPosition.setX(x) |
|
917 |
self.relPosition.setY(y) |
|
918 |
setattr(cls, "setRelPosition", setRelPosition) |
|
919 |
||
920 |
def getRelPosition(self): |
|
921 |
if self.relPosition: |
|
922 |
return self.relPosition.getX(), self.relPosition.getY() |
|
923 |
else: |
|
0 | 924 |
return self.relPosition |
2 | 925 |
setattr(cls, "getRelPosition", getRelPosition) |
926 |
||
927 |
def addConnection(self): |
|
928 |
if not self.content: |
|
929 |
self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]} |
|
930 |
else: |
|
931 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
932 |
setattr(cls, "addConnection", addConnection) |
|
933 |
||
934 |
def removeConnection(self, idx): |
|
935 |
if self.content: |
|
936 |
self.content["value"].pop(idx) |
|
937 |
if len(self.content["value"]) == 0: |
|
938 |
self.content = None |
|
939 |
setattr(cls, "removeConnection", removeConnection) |
|
940 |
||
941 |
def removeConnections(self): |
|
942 |
if self.content: |
|
943 |
self.content = None |
|
944 |
setattr(cls, "removeConnections", removeConnections) |
|
945 |
||
946 |
def getConnections(self): |
|
947 |
if self.content: |
|
948 |
return self.content["value"] |
|
949 |
setattr(cls, "getConnections", getConnections) |
|
950 |
||
951 |
def setConnectionId(self, idx, id): |
|
952 |
if self.content: |
|
953 |
self.content["value"][idx].setRefLocalId(id) |
|
954 |
setattr(cls, "setConnectionId", setConnectionId) |
|
955 |
||
956 |
def getConnectionId(self, idx): |
|
957 |
if self.content: |
|
958 |
return self.content["value"][idx].getRefLocalId() |
|
959 |
return None |
|
960 |
setattr(cls, "getConnectionId", getConnectionId) |
|
961 |
||
962 |
def setConnectionPoints(self, idx, points): |
|
963 |
if self.content: |
|
964 |
self.content["value"][idx].setPoints(points) |
|
965 |
setattr(cls, "setConnectionPoints", setConnectionPoints) |
|
966 |
||
967 |
def getConnectionPoints(self, idx): |
|
968 |
if self.content: |
|
969 |
return self.content["value"][idx].getPoints() |
|
970 |
return None |
|
971 |
setattr(cls, "getConnectionPoints", getConnectionPoints) |
|
972 |
||
27 | 973 |
def setConnectionParameter(self, idx, parameter): |
974 |
if self.content: |
|
975 |
self.content["value"][idx].setFormalParameter(parameter) |
|
976 |
setattr(cls, "setConnectionParameter", setConnectionParameter) |
|
977 |
||
978 |
def getConnectionParameter(self, idx): |
|
979 |
if self.content: |
|
980 |
return self.content["value"][idx].getFormalParameter() |
|
981 |
return None |
|
982 |
setattr(cls, "getConnectionParameter", getConnectionParameter) |
|
983 |
||
2 | 984 |
if "connectionPointOut" in PLCOpenClasses: |
985 |
cls = PLCOpenClasses["connectionPointOut"] |
|
986 |
||
987 |
def setRelPosition(self, x, y): |
|
988 |
self.relPosition = PLCOpenClasses["position"]() |
|
989 |
self.relPosition.setX(x) |
|
990 |
self.relPosition.setY(y) |
|
991 |
setattr(cls, "setRelPosition", setRelPosition) |
|
992 |
||
993 |
def getRelPosition(self): |
|
994 |
if self.relPosition: |
|
995 |
return self.relPosition.getX(), self.relPosition.getY() |
|
996 |
return self.relPosition |
|
997 |
setattr(cls, "getRelPosition", getRelPosition) |
|
998 |
||
999 |
if "value" in PLCOpenClasses: |
|
1000 |
cls = PLCOpenClasses["value"] |
|
1001 |
||
1002 |
def setValue(self, value): |
|
1003 |
try: |
|
1004 |
value = eval(value) |
|
1005 |
except: |
|
1006 |
pass |
|
1007 |
if type(value) == ListType: |
|
1008 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
|
1009 |
arrayValue.setValue(value) |
|
1010 |
self.content = {"name":"arrayValue","value":arrayValue} |
|
1011 |
elif type(value) == DictType: |
|
1012 |
structValue = PLCOpenClasses["value_structValue"]() |
|
1013 |
structValue.setValue(value) |
|
1014 |
self.content = {"name":"structValue","value":structValue} |
|
1015 |
else: |
|
1016 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
1017 |
simpleValue.setValue(str(value)) |
|
1018 |
self.content = {"name":"simpleValue","value":simpleValue} |
|
1019 |
setattr(cls, "setValue", setValue) |
|
1020 |
||
1021 |
def getValue(self): |
|
1022 |
value = self.content["value"].getValue() |
|
1023 |
try: |
|
1024 |
value = eval(value) |
|
1025 |
except: |
|
1026 |
pass |
|
1027 |
return value |
|
1028 |
setattr(cls, "getValue", getValue) |
|
1029 |
||
1030 |
if "value_arrayValue" in PLCOpenClasses: |
|
1031 |
cls = PLCOpenClasses["value_arrayValue"] |
|
1032 |
||
1033 |
def setValue(self, array): |
|
1034 |
self.value = [] |
|
1035 |
for value in array: |
|
1036 |
element = PLCOpenClasses["arrayValue_value"]() |
|
1037 |
element.setValue(value) |
|
1038 |
self.value.append(element) |
|
1039 |
setattr(cls, "setValue", setValue) |
|
1040 |
||
1041 |
def getValue(self): |
|
1042 |
return [element.getValue() for element in self.value] |
|
1043 |
setattr(cls, "getValue", getValue) |
|
1044 |
||
1045 |
if "value_structValue" in PLCOpenClasses: |
|
1046 |
cls = PLCOpenClasses["value_structValue"] |
|
1047 |
||
1048 |
def setValue(self, dict): |
|
1049 |
self.value = [] |
|
1050 |
for name,value in dict.items(): |
|
1051 |
element = PLCOpenClasses["structValue_value"]() |
|
1052 |
element.setMember(name) |
|
1053 |
element.setValue(value) |
|
1054 |
self.value.append(element) |
|
1055 |
setattr(cls, "setValue", setValue) |
|
1056 |
||
1057 |
def getValue(self): |
|
1058 |
value = {} |
|
1059 |
for element in self.value: |
|
1060 |
value[element.getMember()] = element.getValue() |
|
1061 |
return value |
|
1062 |
setattr(cls, "getValue", getValue) |