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