author | lbessard |
Wed, 24 Oct 2007 16:01:06 +0200 | |
changeset 114 | 06454545e5d0 |
parent 108 | 9aa1fdfb7cb2 |
child 118 | 0c53d6a36013 |
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 |
|
94 | 425 |
def changePouVar(self, old_type, old_name, new_type, new_name): |
426 |
content = self.interface.getContent() |
|
427 |
for varlist in content: |
|
428 |
variables = varlist["value"].getVariable() |
|
429 |
for var in variables: |
|
430 |
if var.getName() == old_name: |
|
431 |
var_type = var.getType().getValue() |
|
432 |
if isinstance(var_type, PLCOpenClasses["derived"]) and var_type.getName() == old_type: |
|
433 |
var.setName(new_name) |
|
434 |
var.getType().getValue().setName(new_type) |
|
435 |
return |
|
436 |
setattr(cls, "changePouVar", changePouVar) |
|
437 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
438 |
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
|
439 |
content = self.interface.getContent() |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
440 |
for varlist in content: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
441 |
variables = varlist["value"].getVariable() |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
442 |
for var in variables: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
443 |
if var.getName() == name: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
444 |
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
|
445 |
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
|
446 |
variables.remove(var) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
447 |
break |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
448 |
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
|
449 |
content.remove(varlist) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
450 |
break |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
451 |
setattr(cls, "removePouVar", removePouVar) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
452 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
453 |
def hasBlock(self, name): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
454 |
if self.getBodyType() in ["FBD", "LD", "SFC"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
455 |
for instance in self.getInstances(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
456 |
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
|
457 |
return True |
89 | 458 |
if self.transitions: |
459 |
for transition in self.transitions.getTransition(): |
|
460 |
result = transition.hasBlock(name) |
|
461 |
if result: |
|
462 |
return result |
|
463 |
if self.actions: |
|
464 |
for action in self.actions.getAction(): |
|
465 |
result = action.hasBlock(name) |
|
466 |
if result: |
|
467 |
return result |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
468 |
return False |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
469 |
setattr(cls, "hasBlock", hasBlock) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
470 |
|
2 | 471 |
def addTransition(self, name, type): |
472 |
if not self.transitions: |
|
473 |
self.addTransitions() |
|
474 |
self.transitions.setTransition([]) |
|
475 |
transition = PLCOpenClasses["transitions_transition"]() |
|
476 |
transition.setName(name) |
|
477 |
transition.setBodyType(type) |
|
478 |
self.transitions.appendTransition(transition) |
|
479 |
setattr(cls, "addTransition", addTransition) |
|
480 |
||
481 |
def getTransition(self, name): |
|
482 |
if self.transitions: |
|
483 |
for transition in self.transitions.getTransition(): |
|
484 |
if transition.getName() == name: |
|
485 |
return transition |
|
486 |
return None |
|
487 |
setattr(cls, "getTransition", getTransition) |
|
488 |
||
489 |
def getTransitionList(self): |
|
490 |
if self.transitions: |
|
491 |
return self.transitions.getTransition() |
|
492 |
return [] |
|
493 |
setattr(cls, "getTransitionList", getTransitionList) |
|
494 |
||
495 |
def removeTransition(self, name): |
|
496 |
if self.transitions: |
|
497 |
transitions = self.transitions.getTransition() |
|
498 |
i = 0 |
|
499 |
removed = False |
|
500 |
while i < len(transitions) and not removed: |
|
501 |
if transitions[i].getName() == name: |
|
46 | 502 |
transitions.pop(i) |
2 | 503 |
removed = True |
504 |
i += 1 |
|
505 |
if not removed: |
|
506 |
raise ValueError, "Transition with name %s doesn't exists!"%name |
|
507 |
setattr(cls, "removeTransition", removeTransition) |
|
508 |
||
509 |
def addAction(self, name, type): |
|
510 |
if not self.actions: |
|
511 |
self.addActions() |
|
512 |
self.actions.setAction([]) |
|
513 |
action = PLCOpenClasses["actions_action"]() |
|
514 |
action.setName(name) |
|
515 |
action.setBodyType(type) |
|
516 |
self.actions.appendAction(action) |
|
517 |
setattr(cls, "addAction", addAction) |
|
518 |
||
519 |
def getAction(self, name): |
|
520 |
if self.actions: |
|
521 |
for action in self.actions.getAction(): |
|
522 |
if action.getName() == name: |
|
523 |
return action |
|
524 |
return None |
|
525 |
setattr(cls, "getAction", getAction) |
|
526 |
||
527 |
def getActionList(self): |
|
528 |
if self.actions: |
|
529 |
return self.actions.getAction() |
|
530 |
return [] |
|
531 |
setattr(cls, "getActionList", getActionList) |
|
532 |
||
533 |
def removeAction(self, name): |
|
534 |
if self.actions: |
|
535 |
actions = self.actions.getAction() |
|
536 |
i = 0 |
|
537 |
removed = False |
|
538 |
while i < len(actions) and not removed: |
|
539 |
if actions[i].getName() == name: |
|
46 | 540 |
actions.pop(i) |
2 | 541 |
removed = True |
542 |
i += 1 |
|
543 |
if not removed: |
|
544 |
raise ValueError, "Action with name %s doesn't exists!"%name |
|
545 |
setattr(cls, "removeAction", removeAction) |
|
546 |
||
58 | 547 |
def updateElementName(self, old_name, new_name): |
548 |
self.body.updateElementName(old_name, new_name) |
|
549 |
for action in self.getActionList(): |
|
550 |
action.updateElementName(old_name, new_name) |
|
551 |
for transition in self.getTransitionList(): |
|
552 |
transition.updateElementName(old_name, new_name) |
|
553 |
setattr(cls, "updateElementName", updateElementName) |
|
554 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
555 |
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
|
556 |
if cls: |
2 | 557 |
setattr(cls, "setBodyType", setBodyType) |
558 |
setattr(cls, "getBodyType", getBodyType) |
|
559 |
setattr(cls, "addInstance", addInstance) |
|
560 |
setattr(cls, "getInstances", getInstances) |
|
561 |
setattr(cls, "getInstance", getInstance) |
|
562 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
563 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
564 |
setattr(cls, "removeInstance", removeInstance) |
|
565 |
setattr(cls, "setText", setText) |
|
566 |
setattr(cls, "getText", getText) |
|
567 |
||
58 | 568 |
def updateElementName(self, old_name, new_name): |
569 |
self.body.updateElementName(old_name, new_name) |
|
570 |
setattr(cls, "updateElementName", updateElementName) |
|
571 |
||
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
572 |
def hasBlock(self, name): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
573 |
if self.getBodyType() in ["FBD", "LD", "SFC"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
574 |
for instance in self.getInstances(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
575 |
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
|
576 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
577 |
return False |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
578 |
setattr(cls, "hasBlock", hasBlock) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
579 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
580 |
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
|
581 |
if cls: |
2 | 582 |
setattr(cls, "setBodyType", setBodyType) |
583 |
setattr(cls, "getBodyType", getBodyType) |
|
584 |
setattr(cls, "addInstance", addInstance) |
|
585 |
setattr(cls, "getInstances", getInstances) |
|
586 |
setattr(cls, "getInstance", getInstance) |
|
587 |
setattr(cls, "getRandomInstance", getRandomInstance) |
|
588 |
setattr(cls, "getInstanceByName", getInstanceByName) |
|
589 |
setattr(cls, "removeInstance", removeInstance) |
|
590 |
setattr(cls, "setText", setText) |
|
591 |
setattr(cls, "getText", getText) |
|
592 |
||
58 | 593 |
def updateElementName(self, old_name, new_name): |
594 |
self.body.updateElementName(old_name, new_name) |
|
595 |
setattr(cls, "updateElementName", updateElementName) |
|
596 |
||
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
597 |
def hasBlock(self, name): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
598 |
if self.getBodyType() in ["FBD", "LD", "SFC"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
599 |
for instance in self.getInstances(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
600 |
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
|
601 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
602 |
return False |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
603 |
setattr(cls, "hasBlock", hasBlock) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
604 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
605 |
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
|
606 |
if cls: |
2 | 607 |
def appendContentInstance(self, name, instance): |
608 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
609 |
self.content["value"].appendContent(name, instance) |
|
610 |
else: |
|
611 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
612 |
setattr(cls, "appendContentInstance", appendContentInstance) |
|
613 |
||
614 |
def getContentInstances(self): |
|
615 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
616 |
instances = [] |
|
617 |
for element in self.content["value"].getContent(): |
|
618 |
instances.append(element["value"]) |
|
619 |
return instances |
|
620 |
else: |
|
621 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
622 |
setattr(cls, "getContentInstances", getContentInstances) |
|
623 |
||
624 |
def getContentInstance(self, id): |
|
625 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
626 |
for element in self.content["value"].getContent(): |
|
627 |
if element["value"].getLocalId() == id: |
|
628 |
return element["value"] |
|
0 | 629 |
return None |
2 | 630 |
else: |
631 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
632 |
setattr(cls, "getContentInstance", getContentInstance) |
|
633 |
||
634 |
def getContentRandomInstance(self, exclude): |
|
635 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
636 |
for element in self.content["value"].getContent(): |
|
637 |
if element["value"].getLocalId() not in exclude: |
|
638 |
return element["value"] |
|
639 |
return None |
|
640 |
else: |
|
641 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
642 |
setattr(cls, "getContentRandomInstance", getContentRandomInstance) |
|
643 |
||
644 |
def getContentInstanceByName(self, name): |
|
645 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
646 |
for element in self.content["value"].getContent(): |
|
647 |
if element["value"].getLocalId() == name: |
|
648 |
return element["value"] |
|
649 |
else: |
|
650 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
651 |
setattr(cls, "getContentInstanceByName", getContentInstanceByName) |
|
652 |
||
653 |
def removeContentInstance(self, id): |
|
654 |
if self.content["name"] in ["LD","FBD","SFC"]: |
|
655 |
i = 0 |
|
656 |
removed = False |
|
657 |
elements = self.content["value"].getContent() |
|
658 |
while i < len(elements) and not removed: |
|
659 |
if elements[i]["value"].getLocalId() == id: |
|
660 |
self.content["value"].removeContent(i) |
|
661 |
removed = True |
|
662 |
i += 1 |
|
663 |
if not removed: |
|
664 |
raise ValueError, "Instance with id %d doesn't exists!"%id |
|
665 |
else: |
|
666 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
667 |
setattr(cls, "removeContentInstance", removeContentInstance) |
|
668 |
||
669 |
def setText(self, text): |
|
670 |
if self.content["name"] in ["IL","ST"]: |
|
671 |
self.content["value"].setText(text) |
|
672 |
else: |
|
673 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
674 |
setattr(cls, "setText", setText) |
|
675 |
||
676 |
def getText(self): |
|
677 |
if self.content["name"] in ["IL","ST"]: |
|
678 |
return self.content["value"].getText() |
|
679 |
else: |
|
680 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
681 |
setattr(cls, "getText", getText) |
|
58 | 682 |
|
683 |
def updateElementName(self, old_name, new_name): |
|
684 |
if self.content["name"] in ["IL", "ST"]: |
|
685 |
self.content["value"].updateElementName(old_name, new_name) |
|
686 |
else: |
|
687 |
for element in self.content["value"].getContent(): |
|
688 |
element["value"].updateElementName(old_name, new_name) |
|
689 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 690 |
|
691 |
def getX(self): |
|
692 |
return self.position.getX() |
|
693 |
||
694 |
def getY(self): |
|
695 |
return self.position.getY() |
|
696 |
||
697 |
def setX(self, x): |
|
698 |
self.position.setX(x) |
|
699 |
||
700 |
def setY(self, y): |
|
701 |
self.position.setY(y) |
|
702 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
703 |
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
|
704 |
if cls: |
2 | 705 |
setattr(cls, "getX", getX) |
706 |
setattr(cls, "getY", getY) |
|
707 |
setattr(cls, "setX", setX) |
|
708 |
setattr(cls, "setY", setY) |
|
709 |
||
710 |
def setContentText(self, text): |
|
711 |
self.content.setText(text) |
|
712 |
setattr(cls, "setContentText", setContentText) |
|
0 | 713 |
|
2 | 714 |
def getContentText(self): |
715 |
return self.content.getText() |
|
716 |
setattr(cls, "getContentText", getContentText) |
|
58 | 717 |
|
718 |
def updateElementName(self, old_name, new_name): |
|
719 |
self.content.updateElementName(old_name, new_name) |
|
720 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 721 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
722 |
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
|
723 |
if cls: |
2 | 724 |
setattr(cls, "getX", getX) |
725 |
setattr(cls, "getY", getY) |
|
726 |
setattr(cls, "setX", setX) |
|
727 |
setattr(cls, "setY", setY) |
|
728 |
||
58 | 729 |
def updateElementName(self, old_name, new_name): |
730 |
if self.typeName == old_name: |
|
731 |
self.typeName = new_name |
|
732 |
setattr(cls, "updateElementName", updateElementName) |
|
733 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
734 |
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
|
735 |
if cls: |
2 | 736 |
def setConnectorEdge(self, edge): |
737 |
if not self.edge: |
|
738 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
739 |
self.edge.setValue(edge) |
|
740 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
741 |
||
742 |
def getConnectorEdge(self): |
|
743 |
if self.edge: |
|
744 |
return self.edge.getValue() |
|
745 |
return None |
|
746 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
747 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
748 |
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
|
749 |
if cls: |
2 | 750 |
def setConnectorEdge(self, edge): |
751 |
if not self.edge: |
|
752 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
753 |
self.edge.setValue(edge) |
|
754 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
755 |
||
756 |
def getConnectorEdge(self): |
|
757 |
if self.edge: |
|
758 |
return self.edge.getValue() |
|
759 |
return None |
|
760 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
761 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
762 |
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
|
763 |
if cls: |
2 | 764 |
setattr(cls, "getX", getX) |
765 |
setattr(cls, "getY", getY) |
|
766 |
setattr(cls, "setX", setX) |
|
767 |
setattr(cls, "setY", setY) |
|
768 |
||
58 | 769 |
def updateElementName(self, old_name, new_name): |
770 |
pass |
|
771 |
setattr(cls, "updateElementName", updateElementName) |
|
772 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
773 |
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
|
774 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
775 |
setattr(cls, "getX", getX) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
776 |
setattr(cls, "getY", getY) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
777 |
setattr(cls, "setX", setX) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
778 |
setattr(cls, "setY", setY) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
779 |
|
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
780 |
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
|
781 |
pass |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
782 |
setattr(cls, "updateElementName", updateElementName) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
783 |
|
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
784 |
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
|
785 |
if cls: |
2 | 786 |
setattr(cls, "getX", getX) |
787 |
setattr(cls, "getY", getY) |
|
788 |
setattr(cls, "setX", setX) |
|
789 |
setattr(cls, "setY", setY) |
|
790 |
||
791 |
def setContactEdge(self, edge): |
|
792 |
if not self.edge: |
|
793 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
794 |
self.edge.setValue(edge) |
|
795 |
setattr(cls, "setContactEdge", setContactEdge) |
|
796 |
||
797 |
def getContactEdge(self): |
|
798 |
if self.edge: |
|
799 |
return self.edge.getValue() |
|
800 |
return None |
|
801 |
setattr(cls, "getContactEdge", getContactEdge) |
|
802 |
||
58 | 803 |
def updateElementName(self, old_name, new_name): |
804 |
if self.variable == old_name: |
|
805 |
self.variable = new_name |
|
806 |
setattr(cls, "updateElementName", updateElementName) |
|
807 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
808 |
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
|
809 |
if cls: |
2 | 810 |
setattr(cls, "getX", getX) |
811 |
setattr(cls, "getY", getY) |
|
812 |
setattr(cls, "setX", setX) |
|
813 |
setattr(cls, "setY", setY) |
|
814 |
||
815 |
def setCoilStorage(self, edge): |
|
816 |
if not self.storage: |
|
817 |
self.storage = PLCOpenClasses["storageModifierType"]() |
|
818 |
self.storage.setValue(edge) |
|
819 |
setattr(cls, "setCoilStorage", setCoilStorage) |
|
820 |
||
821 |
def getCoilStorage(self): |
|
822 |
if self.storage: |
|
823 |
return self.storage.getValue() |
|
824 |
return None |
|
825 |
setattr(cls, "getCoilStorage", getCoilStorage) |
|
826 |
||
58 | 827 |
def updateElementName(self, old_name, new_name): |
828 |
if self.variable == old_name: |
|
829 |
self.variable = new_name |
|
830 |
setattr(cls, "updateElementName", updateElementName) |
|
831 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
832 |
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
|
833 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
834 |
setattr(cls, "getX", getX) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
835 |
setattr(cls, "getY", getY) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
836 |
setattr(cls, "setX", setX) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
837 |
setattr(cls, "setY", setY) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
838 |
|
58 | 839 |
def updateElementName(self, old_name, new_name): |
840 |
pass |
|
841 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 842 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
843 |
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
|
844 |
if cls: |
2 | 845 |
setattr(cls, "getX", getX) |
846 |
setattr(cls, "getY", getY) |
|
847 |
setattr(cls, "setX", setX) |
|
848 |
setattr(cls, "setY", setY) |
|
849 |
||
850 |
def setConditionContent(self, type, value): |
|
851 |
if not self.condition: |
|
852 |
self.addCondition() |
|
853 |
if type == "reference": |
|
854 |
condition = PLCOpenClasses["condition_reference"]() |
|
855 |
condition.setName(value) |
|
856 |
elif type == "inline": |
|
857 |
condition = PLCOpenClasses["condition_inline"]() |
|
858 |
condition.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
859 |
condition.setText(value) |
|
69 | 860 |
elif type == "connection": |
861 |
condition = [] |
|
2 | 862 |
self.condition.setContent(type, condition) |
863 |
setattr(cls, "setConditionContent", setConditionContent) |
|
0 | 864 |
|
2 | 865 |
def getConditionContent(self): |
866 |
if self.condition: |
|
867 |
content = self.condition.getContent() |
|
868 |
values = {"type" : content["name"]} |
|
869 |
if values["type"] == "reference": |
|
870 |
values["value"] = content["value"].getName() |
|
871 |
elif values["type"] == "inline": |
|
872 |
values["value"] = content["value"].getText() |
|
873 |
return values |
|
874 |
return "" |
|
875 |
setattr(cls, "getConditionContent", getConditionContent) |
|
876 |
||
58 | 877 |
def updateElementName(self, old_name, new_name): |
878 |
if self.condition: |
|
879 |
content = self.condition.getContent() |
|
880 |
if content["name"] == "reference": |
|
881 |
if content["value"].getName() == old_name: |
|
882 |
content["value"].setName(new_name) |
|
883 |
elif content["name"] == "inline": |
|
884 |
content["value"].updateElementName(old_name, new_name) |
|
885 |
setattr(cls, "updateElementName", updateElementName) |
|
886 |
||
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
887 |
def addConnection(self): |
69 | 888 |
if self.condition: |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
889 |
content = self.condition.getContent() |
69 | 890 |
if content["name"] != "connection": |
891 |
self.condition.setContent("connection", []) |
|
892 |
content = self.condition.getContent() |
|
893 |
content["value"].append(PLCOpenClasses["connection"]()) |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
894 |
setattr(cls, "addConnection", addConnection) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
895 |
|
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
896 |
def removeConnection(self, idx): |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
897 |
if self.condition: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
898 |
content = self.condition.getContent() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
899 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
900 |
content["value"].pop(idx) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
901 |
setattr(cls, "removeConnection", removeConnection) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
902 |
|
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
903 |
def removeConnections(self): |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
904 |
if self.condition: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
905 |
content = self.condition.getContent() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
906 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
907 |
content["value"] = [] |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
908 |
setattr(cls, "removeConnections", removeConnections) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
909 |
|
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
910 |
def getConnections(self): |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
911 |
if self.condition: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
912 |
content = self.condition.getContent() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
913 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
914 |
return content["value"] |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
915 |
setattr(cls, "getConnections", getConnections) |
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 setConnectionId(self, idx, id): |
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].setRefLocalId(id) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
922 |
setattr(cls, "setConnectionId", setConnectionId) |
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 getConnectionId(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].getRefLocalId() |
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, "getConnectionId", getConnectionId) |
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 setConnectionPoints(self, idx, points): |
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].setPoints(points) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
937 |
setattr(cls, "setConnectionPoints", setConnectionPoints) |
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 getConnectionPoints(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].getPoints() |
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, "getConnectionPoints", getConnectionPoints) |
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 |
def setConnectionParameter(self, idx, parameter): |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
948 |
if self.condition: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
949 |
content = self.condition.getContent() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
950 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
951 |
content["value"][idx].setFormalParameter(parameter) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
952 |
setattr(cls, "setConnectionParameter", setConnectionParameter) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
953 |
|
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
954 |
def getConnectionParameter(self, idx): |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
955 |
if self.condition: |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
956 |
content = self.condition.getContent() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
957 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
958 |
return content["value"][idx].getFormalParameter() |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
959 |
return None |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
960 |
setattr(cls, "getConnectionParameter", getConnectionParameter) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
961 |
|
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
962 |
setattr(cls, "addConnection", addConnection) |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
963 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
964 |
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
|
965 |
if cls: |
2 | 966 |
setattr(cls, "getX", getX) |
967 |
setattr(cls, "getY", getY) |
|
968 |
setattr(cls, "setX", setX) |
|
969 |
setattr(cls, "setY", setY) |
|
970 |
||
58 | 971 |
def updateElementName(self, old_name, new_name): |
972 |
pass |
|
973 |
setattr(cls, "updateElementName", updateElementName) |
|
974 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
975 |
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
|
976 |
if cls: |
2 | 977 |
setattr(cls, "getX", getX) |
978 |
setattr(cls, "getY", getY) |
|
979 |
setattr(cls, "setX", setX) |
|
980 |
setattr(cls, "setY", setY) |
|
981 |
||
58 | 982 |
def updateElementName(self, old_name, new_name): |
983 |
pass |
|
984 |
setattr(cls, "updateElementName", updateElementName) |
|
985 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
986 |
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
|
987 |
if cls: |
2 | 988 |
setattr(cls, "getX", getX) |
989 |
setattr(cls, "getY", getY) |
|
990 |
setattr(cls, "setX", setX) |
|
991 |
setattr(cls, "setY", setY) |
|
992 |
||
58 | 993 |
def updateElementName(self, old_name, new_name): |
994 |
pass |
|
995 |
setattr(cls, "updateElementName", updateElementName) |
|
996 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
997 |
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
|
998 |
if cls: |
2 | 999 |
setattr(cls, "getX", getX) |
1000 |
setattr(cls, "getY", getY) |
|
1001 |
setattr(cls, "setX", setX) |
|
1002 |
setattr(cls, "setY", setY) |
|
58 | 1003 |
|
1004 |
def updateElementName(self, old_name, new_name): |
|
1005 |
pass |
|
1006 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1007 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1008 |
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
|
1009 |
if cls: |
2 | 1010 |
setattr(cls, "getX", getX) |
1011 |
setattr(cls, "getY", getY) |
|
1012 |
setattr(cls, "setX", setX) |
|
1013 |
setattr(cls, "setY", setY) |
|
58 | 1014 |
|
1015 |
def updateElementName(self, old_name, new_name): |
|
1016 |
pass |
|
1017 |
setattr(cls, "updateElementName", updateElementName) |
|
1018 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1019 |
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
|
1020 |
if cls: |
2 | 1021 |
def setQualifierValue(self, value): |
1022 |
if self.qualifier: |
|
1023 |
self.qualifier.setValue(value) |
|
1024 |
setattr(cls, "setQualifierValue", setQualifierValue) |
|
1025 |
||
1026 |
def getQualifierValue(self): |
|
1027 |
if self.qualifier: |
|
1028 |
return self.qualifier.getValue() |
|
1029 |
return None |
|
1030 |
setattr(cls, "getQualifierValue", getQualifierValue) |
|
1031 |
||
1032 |
def setReferenceName(self, name): |
|
1033 |
if self.reference: |
|
1034 |
self.reference.setName(name) |
|
1035 |
setattr(cls, "setReferenceName", setReferenceName) |
|
1036 |
||
1037 |
def getReferenceName(self): |
|
1038 |
if self.reference: |
|
1039 |
return self.reference.getName() |
|
1040 |
return None |
|
1041 |
setattr(cls, "getReferenceName", getReferenceName) |
|
1042 |
||
1043 |
def setInlineContent(self, content): |
|
1044 |
if self.inline: |
|
1045 |
self.inline.setContent("ST", PLCOpenClasses["formattedText"]()) |
|
1046 |
self.inline.setText(content) |
|
1047 |
setattr(cls, "setInlineContent", setInlineContent) |
|
1048 |
||
1049 |
def getInlineContent(self): |
|
1050 |
if self.inline: |
|
1051 |
return self.inline.getText() |
|
1052 |
return None |
|
1053 |
setattr(cls, "getInlineContent", getInlineContent) |
|
1054 |
||
58 | 1055 |
def updateElementName(self, old_name, new_name): |
1056 |
if self.reference and self.reference.getName() == old_name: |
|
1057 |
self.reference.setName(new_name) |
|
1058 |
if self.inline: |
|
1059 |
self.inline.updateElementName(old_name, new_name) |
|
1060 |
setattr(cls, "updateElementName", updateElementName) |
|
1061 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1062 |
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
|
1063 |
if cls: |
2 | 1064 |
setattr(cls, "getX", getX) |
1065 |
setattr(cls, "getY", getY) |
|
1066 |
setattr(cls, "setX", setX) |
|
1067 |
setattr(cls, "setY", setY) |
|
1068 |
||
1069 |
def setActions(self, actions): |
|
1070 |
self.action = [] |
|
1071 |
for params in actions: |
|
1072 |
action = PLCOpenClasses["actionBlock_action"]() |
|
1073 |
action.addQualifier() |
|
1074 |
action.setQualifierValue(params["qualifier"]) |
|
1075 |
if params["type"] == "reference": |
|
1076 |
action.addReference() |
|
1077 |
action.setReferenceName(params["value"]) |
|
0 | 1078 |
else: |
2 | 1079 |
action.addInline() |
1080 |
action.setInlineContent(params["value"]) |
|
1081 |
if "duration" in params: |
|
1082 |
action.setDuration(params["duration"]) |
|
1083 |
if "indicator" in params: |
|
1084 |
action.setIndicator(params["indicator"]) |
|
1085 |
self.action.append(action) |
|
1086 |
setattr(cls, "setActions", setActions) |
|
1087 |
||
1088 |
def getActions(self): |
|
1089 |
actions = [] |
|
1090 |
for action in self.action: |
|
1091 |
params = {} |
|
1092 |
params["qualifier"] = action.getQualifierValue() |
|
108 | 1093 |
if params["qualifier"] is None: |
1094 |
params["qualifier"] = "N" |
|
2 | 1095 |
if action.getReference(): |
1096 |
params["type"] = "reference" |
|
1097 |
params["value"] = action.getReferenceName() |
|
1098 |
elif action.getInline(): |
|
1099 |
params["type"] = "inline" |
|
1100 |
params["value"] = action.getInlineContent() |
|
1101 |
duration = action.getDuration() |
|
1102 |
if duration: |
|
1103 |
params["duration"] = duration |
|
1104 |
indicator = action.getIndicator() |
|
1105 |
if indicator: |
|
1106 |
params["indicator"] = indicator |
|
1107 |
actions.append(params) |
|
1108 |
return actions |
|
1109 |
setattr(cls, "getActions", getActions) |
|
1110 |
||
58 | 1111 |
def updateElementName(self, old_name, new_name): |
1112 |
for action in self.action: |
|
1113 |
action.updateElementName(old_name, new_name) |
|
1114 |
setattr(cls, "updateElementName", updateElementName) |
|
1115 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1116 |
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
|
1117 |
if cls: |
2 | 1118 |
setattr(cls, "getX", getX) |
1119 |
setattr(cls, "getY", getY) |
|
1120 |
setattr(cls, "setX", setX) |
|
1121 |
setattr(cls, "setY", setY) |
|
1122 |
||
1123 |
def setConnectorEdge(self, edge): |
|
1124 |
if not self.edge: |
|
1125 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
1126 |
self.edge.setValue(edge) |
|
1127 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
1128 |
||
1129 |
def getConnectorEdge(self): |
|
1130 |
if self.edge: |
|
1131 |
return self.edge.getValue() |
|
1132 |
return None |
|
1133 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
58 | 1134 |
|
1135 |
def updateElementName(self, old_name, new_name): |
|
1136 |
if self.expression == old_name: |
|
1137 |
self.expression = new_name |
|
1138 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1139 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1140 |
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
|
1141 |
if cls: |
2 | 1142 |
setattr(cls, "getX", getX) |
1143 |
setattr(cls, "getY", getY) |
|
1144 |
setattr(cls, "setX", setX) |
|
1145 |
setattr(cls, "setY", setY) |
|
1146 |
||
1147 |
def setConnectorEdge(self, edge): |
|
1148 |
if not self.edge: |
|
1149 |
self.edge = PLCOpenClasses["edgeModifierType"]() |
|
1150 |
self.edge.setValue(edge) |
|
1151 |
setattr(cls, "setConnectorEdge", setConnectorEdge) |
|
1152 |
||
1153 |
def getConnectorEdge(self): |
|
1154 |
if self.edge: |
|
1155 |
return self.edge.getValue() |
|
1156 |
return None |
|
1157 |
setattr(cls, "getConnectorEdge", getConnectorEdge) |
|
1158 |
||
58 | 1159 |
def updateElementName(self, old_name, new_name): |
1160 |
if self.expression == old_name: |
|
1161 |
self.expression = new_name |
|
1162 |
setattr(cls, "updateElementName", updateElementName) |
|
1163 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1164 |
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
|
1165 |
if cls: |
2 | 1166 |
setattr(cls, "getX", getX) |
1167 |
setattr(cls, "getY", getY) |
|
1168 |
setattr(cls, "setX", setX) |
|
1169 |
setattr(cls, "setY", setY) |
|
1170 |
||
1171 |
def setInputEdge(self, edge): |
|
1172 |
if not self.edgeIn: |
|
1173 |
self.edgeIn = PLCOpenClasses["edgeModifierType"]() |
|
1174 |
self.edgeIn.setValue(edge) |
|
1175 |
setattr(cls, "setInputEdge", setInputEdge) |
|
1176 |
||
1177 |
def getInputEdge(self): |
|
1178 |
if self.edgeIn: |
|
1179 |
return self.edgeIn.getValue() |
|
1180 |
return None |
|
1181 |
setattr(cls, "getInputEdge", getInputEdge) |
|
1182 |
||
1183 |
def setOutputEdge(self, edge): |
|
1184 |
if not self.edgeOut: |
|
1185 |
self.edgeOut = PLCOpenClasses["edgeModifierType"]() |
|
1186 |
self.edgeOut.setValue(edge) |
|
1187 |
setattr(cls, "setInputEdge", setInputEdge) |
|
1188 |
||
1189 |
def getOutputEdge(self): |
|
1190 |
if self.edgeOut: |
|
1191 |
return self.edgeOut.getValue() |
|
1192 |
return None |
|
1193 |
setattr(cls, "getOutputEdge", getOutputEdge) |
|
1194 |
||
58 | 1195 |
def updateElementName(self, old_name, new_name): |
1196 |
if self.expression == old_name: |
|
1197 |
self.expression = new_name |
|
1198 |
setattr(cls, "updateElementName", updateElementName) |
|
1199 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1200 |
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
|
1201 |
if cls: |
2 | 1202 |
setattr(cls, "getX", getX) |
1203 |
setattr(cls, "getY", getY) |
|
1204 |
setattr(cls, "setX", setX) |
|
1205 |
setattr(cls, "setY", setY) |
|
58 | 1206 |
|
1207 |
def updateElementName(self, old_name, new_name): |
|
1208 |
pass |
|
1209 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1210 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1211 |
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
|
1212 |
if cls: |
2 | 1213 |
setattr(cls, "getX", getX) |
1214 |
setattr(cls, "getY", getY) |
|
1215 |
setattr(cls, "setX", setX) |
|
1216 |
setattr(cls, "setY", setY) |
|
58 | 1217 |
|
1218 |
def updateElementName(self, old_name, new_name): |
|
1219 |
pass |
|
1220 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1221 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1222 |
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
|
1223 |
if cls: |
2 | 1224 |
def setPoints(self, points): |
1225 |
self.position = [] |
|
1226 |
for point in points: |
|
1227 |
position = PLCOpenClasses["position"]() |
|
1228 |
position.setX(point.x) |
|
1229 |
position.setY(point.y) |
|
1230 |
self.position.append(position) |
|
1231 |
setattr(cls, "setPoints", setPoints) |
|
1232 |
||
1233 |
def getPoints(self): |
|
1234 |
points = [] |
|
1235 |
for position in self.position: |
|
1236 |
points.append((position.getX(),position.getY())) |
|
1237 |
return points |
|
1238 |
setattr(cls, "getPoints", getPoints) |
|
1239 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1240 |
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
|
1241 |
if cls: |
2 | 1242 |
def setRelPosition(self, x, y): |
1243 |
self.relPosition = PLCOpenClasses["position"]() |
|
1244 |
self.relPosition.setX(x) |
|
1245 |
self.relPosition.setY(y) |
|
1246 |
setattr(cls, "setRelPosition", setRelPosition) |
|
1247 |
||
1248 |
def getRelPosition(self): |
|
1249 |
if self.relPosition: |
|
1250 |
return self.relPosition.getX(), self.relPosition.getY() |
|
1251 |
else: |
|
0 | 1252 |
return self.relPosition |
2 | 1253 |
setattr(cls, "getRelPosition", getRelPosition) |
1254 |
||
1255 |
def addConnection(self): |
|
1256 |
if not self.content: |
|
1257 |
self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]} |
|
1258 |
else: |
|
1259 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
1260 |
setattr(cls, "addConnection", addConnection) |
|
1261 |
||
1262 |
def removeConnection(self, idx): |
|
1263 |
if self.content: |
|
1264 |
self.content["value"].pop(idx) |
|
1265 |
if len(self.content["value"]) == 0: |
|
1266 |
self.content = None |
|
1267 |
setattr(cls, "removeConnection", removeConnection) |
|
1268 |
||
1269 |
def removeConnections(self): |
|
1270 |
if self.content: |
|
1271 |
self.content = None |
|
1272 |
setattr(cls, "removeConnections", removeConnections) |
|
1273 |
||
1274 |
def getConnections(self): |
|
1275 |
if self.content: |
|
1276 |
return self.content["value"] |
|
1277 |
setattr(cls, "getConnections", getConnections) |
|
1278 |
||
1279 |
def setConnectionId(self, idx, id): |
|
1280 |
if self.content: |
|
1281 |
self.content["value"][idx].setRefLocalId(id) |
|
1282 |
setattr(cls, "setConnectionId", setConnectionId) |
|
1283 |
||
1284 |
def getConnectionId(self, idx): |
|
1285 |
if self.content: |
|
1286 |
return self.content["value"][idx].getRefLocalId() |
|
1287 |
return None |
|
1288 |
setattr(cls, "getConnectionId", getConnectionId) |
|
1289 |
||
1290 |
def setConnectionPoints(self, idx, points): |
|
1291 |
if self.content: |
|
1292 |
self.content["value"][idx].setPoints(points) |
|
1293 |
setattr(cls, "setConnectionPoints", setConnectionPoints) |
|
1294 |
||
1295 |
def getConnectionPoints(self, idx): |
|
1296 |
if self.content: |
|
1297 |
return self.content["value"][idx].getPoints() |
|
1298 |
return None |
|
1299 |
setattr(cls, "getConnectionPoints", getConnectionPoints) |
|
1300 |
||
27 | 1301 |
def setConnectionParameter(self, idx, parameter): |
1302 |
if self.content: |
|
1303 |
self.content["value"][idx].setFormalParameter(parameter) |
|
1304 |
setattr(cls, "setConnectionParameter", setConnectionParameter) |
|
1305 |
||
1306 |
def getConnectionParameter(self, idx): |
|
1307 |
if self.content: |
|
1308 |
return self.content["value"][idx].getFormalParameter() |
|
1309 |
return None |
|
1310 |
setattr(cls, "getConnectionParameter", getConnectionParameter) |
|
1311 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1312 |
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
|
1313 |
if cls: |
2 | 1314 |
def setRelPosition(self, x, y): |
1315 |
self.relPosition = PLCOpenClasses["position"]() |
|
1316 |
self.relPosition.setX(x) |
|
1317 |
self.relPosition.setY(y) |
|
1318 |
setattr(cls, "setRelPosition", setRelPosition) |
|
1319 |
||
1320 |
def getRelPosition(self): |
|
1321 |
if self.relPosition: |
|
1322 |
return self.relPosition.getX(), self.relPosition.getY() |
|
1323 |
return self.relPosition |
|
1324 |
setattr(cls, "getRelPosition", getRelPosition) |
|
1325 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1326 |
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
|
1327 |
if cls: |
2 | 1328 |
def setValue(self, value): |
1329 |
try: |
|
1330 |
value = eval(value) |
|
1331 |
except: |
|
1332 |
pass |
|
1333 |
if type(value) == ListType: |
|
1334 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
|
1335 |
arrayValue.setValue(value) |
|
1336 |
self.content = {"name":"arrayValue","value":arrayValue} |
|
1337 |
elif type(value) == DictType: |
|
1338 |
structValue = PLCOpenClasses["value_structValue"]() |
|
1339 |
structValue.setValue(value) |
|
1340 |
self.content = {"name":"structValue","value":structValue} |
|
1341 |
else: |
|
1342 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
1343 |
simpleValue.setValue(str(value)) |
|
1344 |
self.content = {"name":"simpleValue","value":simpleValue} |
|
1345 |
setattr(cls, "setValue", setValue) |
|
1346 |
||
1347 |
def getValue(self): |
|
1348 |
value = self.content["value"].getValue() |
|
1349 |
try: |
|
1350 |
value = eval(value) |
|
1351 |
except: |
|
1352 |
pass |
|
1353 |
return value |
|
1354 |
setattr(cls, "getValue", getValue) |
|
1355 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1356 |
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
|
1357 |
if cls: |
2 | 1358 |
def setValue(self, array): |
1359 |
self.value = [] |
|
1360 |
for value in array: |
|
1361 |
element = PLCOpenClasses["arrayValue_value"]() |
|
1362 |
element.setValue(value) |
|
1363 |
self.value.append(element) |
|
1364 |
setattr(cls, "setValue", setValue) |
|
1365 |
||
1366 |
def getValue(self): |
|
1367 |
return [element.getValue() for element in self.value] |
|
1368 |
setattr(cls, "getValue", getValue) |
|
1369 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1370 |
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
|
1371 |
if cls: |
2 | 1372 |
def setValue(self, dict): |
1373 |
self.value = [] |
|
1374 |
for name,value in dict.items(): |
|
1375 |
element = PLCOpenClasses["structValue_value"]() |
|
1376 |
element.setMember(name) |
|
1377 |
element.setValue(value) |
|
1378 |
self.value.append(element) |
|
1379 |
setattr(cls, "setValue", setValue) |
|
1380 |
||
1381 |
def getValue(self): |
|
1382 |
value = {} |
|
1383 |
for element in self.value: |
|
1384 |
value[element.getMember()] = element.getValue() |
|
1385 |
return value |
|
1386 |
setattr(cls, "getValue", getValue) |