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