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