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