author | lbessard |
Mon, 28 Jan 2008 11:15:24 +0100 | |
changeset 158 | 8a770e8d745a |
parent 151 | aaa80b48bead |
child 166 | de1845119cdd |
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 |
||
151 | 47 |
PLCOpenClasses = 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: |
58 | 51 |
def updateElementName(self, old_name, new_name): |
52 |
index = self.text.find(old_name) |
|
53 |
while index != -1: |
|
54 |
if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): |
|
55 |
index = self.text.find(old_name, index + len(old_name)) |
|
56 |
elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): |
|
57 |
index = self.text.find(old_name, index + len(old_name)) |
|
58 |
else: |
|
59 |
self.text = self.text[:index] + new_name + self.text[index + len(old_name):] |
|
60 |
index = self.text.find(old_name, index + len(new_name)) |
|
61 |
setattr(cls, "updateElementName", updateElementName) |
|
62 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
63 |
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
|
64 |
if cls: |
2 | 65 |
cls.singleLineAttributes = False |
66 |
||
151 | 67 |
def setname(self, name): |
68 |
self.contentHeader.setname(name) |
|
69 |
setattr(cls, "setname", setname) |
|
145 | 70 |
|
151 | 71 |
def getname(self): |
72 |
return self.contentHeader.getname() |
|
73 |
setattr(cls, "getname", getname) |
|
74 |
||
75 |
def getfileHeader(self): |
|
2 | 76 |
fileheader = {} |
151 | 77 |
fileheader["companyName"] = self.fileHeader.getcompanyName() |
78 |
if self.fileHeader.getcompanyURL(): |
|
79 |
fileheader["companyURL"] = self.fileHeader.getcompanyURL() |
|
80 |
fileheader["productName"] = self.fileHeader.getproductName() |
|
81 |
fileheader["productVersion"] = self.fileHeader.getproductVersion() |
|
82 |
if self.fileHeader.getproductRelease(): |
|
83 |
fileheader["productRelease"] = self.fileHeader.getproductRelease() |
|
84 |
fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime() |
|
85 |
if self.fileHeader.getcontentDescription(): |
|
86 |
fileheader["contentDescription"] = self.fileHeader.getcontentDescription() |
|
2 | 87 |
return fileheader |
151 | 88 |
setattr(cls, "getfileHeader", getfileHeader) |
89 |
||
90 |
def setfileHeader(self, fileheader): |
|
91 |
self.fileHeader.setcompanyName(fileheader["companyName"]) |
|
2 | 92 |
if "companyURL" in fileheader: |
151 | 93 |
self.fileHeader.setcompanyURL(fileheader["companyURL"]) |
94 |
self.fileHeader.setproductName(fileheader["productName"]) |
|
95 |
self.fileHeader.setproductVersion(fileheader["productVersion"]) |
|
2 | 96 |
if "productRelease" in fileheader: |
151 | 97 |
self.fileHeader.setproductRelease(fileheader["productRelease"]) |
98 |
self.fileHeader.setcreationDateTime(fileheader["creationDateTime"]) |
|
2 | 99 |
if "contentDescription" in fileheader: |
151 | 100 |
self.fileHeader.setcontentDescription(fileheader["contentDescription"]) |
101 |
setattr(cls, "setfileHeader", setfileHeader) |
|
102 |
||
103 |
def getcontentHeader(self): |
|
145 | 104 |
contentheader = {} |
151 | 105 |
contentheader["projectName"] = self.contentHeader.getname() |
106 |
if self.contentHeader.getversion(): |
|
107 |
contentheader["projectVersion"] = self.contentHeader.getversion() |
|
108 |
if self.contentHeader.getmodificationDateTime(): |
|
109 |
contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime() |
|
110 |
if self.contentHeader.getorganization(): |
|
111 |
contentheader["organization"] = self.contentHeader.getorganization() |
|
112 |
if self.contentHeader.getauthor(): |
|
113 |
contentheader["authorName"] = self.contentHeader.getauthor() |
|
114 |
if self.contentHeader.getlanguage(): |
|
115 |
contentheader["language"] = self.contentHeader.getlanguage() |
|
116 |
contentheader["pageSize"] = self.contentHeader.getpageSize() |
|
117 |
contentheader["scaling"] = self.contentHeader.getscaling() |
|
145 | 118 |
return contentheader |
151 | 119 |
setattr(cls, "getcontentHeader", getcontentHeader) |
120 |
||
121 |
def setcontentHeader(self, contentheader): |
|
122 |
self.contentHeader.setname(contentheader["projectName"]) |
|
145 | 123 |
if "projectVersion" in contentheader: |
151 | 124 |
self.contentHeader.setversion(contentheader["projectVersion"]) |
145 | 125 |
if "modificationDateTime" in contentheader: |
151 | 126 |
self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
145 | 127 |
if "organization" in contentheader: |
151 | 128 |
self.contentHeader.setorganization(contentheader["organization"]) |
145 | 129 |
if "authorName" in contentheader: |
151 | 130 |
self.contentHeader.setauthor(contentheader["authorName"]) |
145 | 131 |
if "language" in contentheader: |
151 | 132 |
self.contentHeader.setlanguage(contentheader["language"]) |
133 |
self.contentHeader.setpageSize(*contentheader["pageSize"]) |
|
134 |
self.contentHeader.setscaling(contentheader["scaling"]) |
|
135 |
setattr(cls, "setcontentHeader", setcontentHeader) |
|
136 |
||
137 |
def getdataTypes(self): |
|
138 |
return self.types.getdataTypeElements() |
|
139 |
setattr(cls, "getdataTypes", getdataTypes) |
|
140 |
||
141 |
def getdataType(self, name): |
|
142 |
return self.types.getdataTypeElement(name) |
|
143 |
setattr(cls, "getdataType", getdataType) |
|
144 |
||
145 |
def appenddataType(self, name): |
|
146 |
self.types.appenddataTypeElement(name) |
|
147 |
setattr(cls, "appenddataType", appenddataType) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
148 |
|
151 | 149 |
def insertdataType(self, index, datatype): |
150 |
self.types.insertdataTypeElement(index, datatype) |
|
151 |
setattr(cls, "insertdataType", insertdataType) |
|
152 |
||
153 |
def removedataType(self, name): |
|
154 |
self.types.removedataTypeElement(name) |
|
155 |
setattr(cls, "removedataType", removedataType) |
|
156 |
||
157 |
def getpous(self): |
|
158 |
return self.types.getpouElements() |
|
159 |
setattr(cls, "getpous", getpous) |
|
160 |
||
161 |
def getpou(self, name): |
|
162 |
return self.types.getpouElement(name) |
|
163 |
setattr(cls, "getpou", getpou) |
|
164 |
||
165 |
def appendpou(self, name, pou_type, body_type): |
|
166 |
self.types.appendpouElement(name, pou_type, body_type) |
|
167 |
setattr(cls, "appendpou", appendpou) |
|
0 | 168 |
|
151 | 169 |
def insertpou(self, index, pou): |
170 |
self.types.insertpouElement(index, pou) |
|
171 |
setattr(cls, "insertpou", insertpou) |
|
172 |
||
173 |
def removepou(self, name): |
|
174 |
self.types.removepouElement(name) |
|
175 |
setattr(cls, "removepou", removepou) |
|
176 |
||
177 |
def getconfigurations(self): |
|
178 |
configurations = self.instances.configurations.getconfiguration() |
|
2 | 179 |
if configurations: |
180 |
return configurations |
|
181 |
return [] |
|
151 | 182 |
setattr(cls, "getconfigurations", getconfigurations) |
183 |
||
184 |
def getconfiguration(self, name): |
|
185 |
for configuration in self.instances.configurations.getconfiguration(): |
|
186 |
if configuration.getname() == name: |
|
2 | 187 |
return configuration |
188 |
return None |
|
151 | 189 |
setattr(cls, "getconfiguration", getconfiguration) |
190 |
||
191 |
def addconfiguration(self, name): |
|
192 |
for configuration in self.instances.configurations.getconfiguration(): |
|
193 |
if configuration.getname() == name: |
|
2 | 194 |
raise ValueError, "\"%s\" configuration already exists !!!"%name |
195 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
151 | 196 |
new_configuration.setname(name) |
197 |
self.instances.configurations.appendconfiguration(new_configuration) |
|
198 |
setattr(cls, "addconfiguration", addconfiguration) |
|
199 |
||
200 |
def removeconfiguration(self, name): |
|
2 | 201 |
found = False |
151 | 202 |
for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
203 |
if configuration.getname() == name: |
|
204 |
self.instances.configurations.removeconfiguration(idx) |
|
2 | 205 |
found = True |
206 |
break |
|
207 |
if not found: |
|
208 |
raise ValueError, "\"%s\" configuration doesn't exist !!!"%name |
|
151 | 209 |
setattr(cls, "removeconfiguration", removeconfiguration) |
210 |
||
211 |
def getconfigurationResource(self, config_name, name): |
|
212 |
configuration = self.getconfiguration(config_name) |
|
2 | 213 |
if configuration: |
151 | 214 |
for resource in configuration.getresource(): |
215 |
if resource.getname() == name: |
|
2 | 216 |
return resource |
217 |
return None |
|
151 | 218 |
setattr(cls, "getconfigurationResource", getconfigurationResource) |
219 |
||
220 |
def addconfigurationResource(self, config_name, name): |
|
221 |
configuration = self.getconfiguration(config_name) |
|
2 | 222 |
if configuration: |
151 | 223 |
for resource in configuration.getresource(): |
224 |
if resource.getname() == name: |
|
2 | 225 |
raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) |
226 |
new_resource = PLCOpenClasses["configuration_resource"]() |
|
151 | 227 |
new_resource.setname(name) |
228 |
configuration.appendresource(new_resource) |
|
229 |
setattr(cls, "addconfigurationResource", addconfigurationResource) |
|
230 |
||
231 |
def removeconfigurationResource(self, config_name, name): |
|
232 |
configuration = self.getconfiguration(config_name) |
|
2 | 233 |
if configuration: |
0 | 234 |
found = False |
151 | 235 |
for idx, resource in enumerate(configuration.getresource()): |
236 |
if resource.getname() == name: |
|
237 |
configuration.removeresource(idx) |
|
0 | 238 |
found = True |
239 |
break |
|
240 |
if not found: |
|
2 | 241 |
raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name) |
151 | 242 |
setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
243 |
||
244 |
def updateElementName(self, old_name, new_name): |
|
245 |
for pou in self.types.getpouElements(): |
|
58 | 246 |
pou.updateElementName(old_name, new_name) |
151 | 247 |
for configuration in self.instances.configurations.getconfiguration(): |
58 | 248 |
configuration.updateElementName(old_name, new_name) |
249 |
setattr(cls, "updateElementName", updateElementName) |
|
250 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
251 |
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
|
252 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
253 |
cls.singleLineAttributes = False |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
254 |
|
145 | 255 |
cls = PLCOpenClasses.get("project_contentHeader", None) |
256 |
if cls: |
|
257 |
cls.singleLineAttributes = False |
|
258 |
||
151 | 259 |
def setpageSize(self, width, height): |
260 |
self.coordinateInfo.setpageSize(width, height) |
|
261 |
setattr(cls, "setpageSize", setpageSize) |
|
262 |
||
263 |
def getpageSize(self): |
|
264 |
return self.coordinateInfo.getpageSize() |
|
265 |
setattr(cls, "getpageSize", getpageSize) |
|
266 |
||
267 |
def setscaling(self, scaling): |
|
145 | 268 |
for language, (x, y) in scaling.items(): |
151 | 269 |
self.coordinateInfo.setscaling(language, x, y) |
270 |
setattr(cls, "setscaling", setscaling) |
|
271 |
||
272 |
def getscaling(self): |
|
145 | 273 |
scaling = {} |
151 | 274 |
scaling["FBD"] = self.coordinateInfo.getscaling("FBD") |
275 |
scaling["LD"] = self.coordinateInfo.getscaling("LD") |
|
276 |
scaling["SFC"] = self.coordinateInfo.getscaling("SFC") |
|
145 | 277 |
return scaling |
151 | 278 |
setattr(cls, "getscaling", getscaling) |
145 | 279 |
|
280 |
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None) |
|
281 |
if cls: |
|
151 | 282 |
def setpageSize(self, width, height): |
145 | 283 |
if width == 0 and height == 0: |
151 | 284 |
self.deletepageSize() |
145 | 285 |
else: |
286 |
if self.pageSize is None: |
|
151 | 287 |
self.addpageSize() |
288 |
self.pageSize.setx(width) |
|
289 |
self.pageSize.sety(height) |
|
290 |
setattr(cls, "setpageSize", setpageSize) |
|
291 |
||
292 |
def getpageSize(self): |
|
145 | 293 |
if self.pageSize is not None: |
151 | 294 |
return self.pageSize.getx(), self.pageSize.gety() |
145 | 295 |
return 0, 0 |
151 | 296 |
setattr(cls, "getpageSize", getpageSize) |
297 |
||
298 |
def setscaling(self, language, x, y): |
|
145 | 299 |
if language == "FBD": |
151 | 300 |
self.fbd.scaling.setx(x) |
301 |
self.fbd.scaling.sety(y) |
|
145 | 302 |
elif language == "LD": |
151 | 303 |
self.ld.scaling.setx(x) |
304 |
self.ld.scaling.sety(y) |
|
145 | 305 |
elif language == "SFC": |
151 | 306 |
self.sfc.scaling.setx(x) |
307 |
self.sfc.scaling.sety(y) |
|
308 |
setattr(cls, "setscaling", setscaling) |
|
309 |
||
310 |
def getscaling(self, language): |
|
145 | 311 |
if language == "FBD": |
151 | 312 |
return self.fbd.scaling.getx(), self.fbd.scaling.gety() |
145 | 313 |
elif language == "LD": |
151 | 314 |
return self.ld.scaling.getx(), self.ld.scaling.gety() |
145 | 315 |
elif language == "SFC": |
151 | 316 |
return self.sfc.scaling.getx(), self.sfc.scaling.gety() |
145 | 317 |
return 0, 0 |
151 | 318 |
setattr(cls, "getscaling", getscaling) |
145 | 319 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
320 |
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
|
321 |
if cls: |
58 | 322 |
def updateElementName(self, old_name, new_name): |
151 | 323 |
for resource in self.getresource(): |
58 | 324 |
resource.updateElementName(old_name, new_name) |
325 |
setattr(cls, "updateElementName", updateElementName) |
|
326 |
||
327 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
328 |
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
|
329 |
if cls: |
58 | 330 |
def updateElementName(self, old_name, new_name): |
331 |
for instance in self.getPouInstance(): |
|
332 |
instance.updateElementName(old_name, new_name) |
|
333 |
for task in self.getTask(): |
|
334 |
task.updateElementName(old_name, new_name) |
|
335 |
setattr(cls, "updateElementName", updateElementName) |
|
336 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
337 |
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
|
338 |
if cls: |
58 | 339 |
def updateElementName(self, old_name, new_name): |
340 |
if self.single == old_name: |
|
341 |
self.single = new_name |
|
342 |
for instance in self.getPouInstance(): |
|
343 |
instance.updateElementName(old_name, new_name) |
|
344 |
setattr(cls, "updateElementName", updateElementName) |
|
345 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
346 |
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
|
347 |
if cls: |
58 | 348 |
def updateElementName(self, old_name, new_name): |
349 |
if self.type == old_name: |
|
350 |
self.type = new_name |
|
351 |
setattr(cls, "updateElementName", updateElementName) |
|
352 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
353 |
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
|
354 |
if cls: |
151 | 355 |
def getdataTypeElements(self): |
356 |
return self.dataTypes.getdataType() |
|
357 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
358 |
||
359 |
def getdataTypeElement(self, name): |
|
360 |
elements = self.dataTypes.getdataType() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
361 |
for element in elements: |
151 | 362 |
if element.getname() == name: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
363 |
return element |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
364 |
return None |
151 | 365 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
366 |
||
367 |
def appenddataTypeElement(self, name): |
|
368 |
for element in self.dataTypes.getdataType(): |
|
369 |
if element.getname() == name: |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
370 |
raise ValueError, "\"%s\" Data Type already exists !!!"%name |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
371 |
new_datatype = PLCOpenClasses["dataTypes_dataType"]() |
151 | 372 |
new_datatype.setname(name) |
373 |
new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None}) |
|
374 |
self.dataTypes.appenddataType(new_datatype) |
|
375 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
376 |
|
151 | 377 |
def insertdataTypeElement(self, index, dataType): |
378 |
self.dataTypes.insertdataType(index, dataType) |
|
379 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
380 |
||
381 |
def removedataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
382 |
found = False |
151 | 383 |
for idx, element in enumerate(self.dataTypes.getdataType()): |
384 |
if element.getname() == name: |
|
385 |
self.dataTypes.removedataType(idx) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
386 |
found = True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
387 |
break |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
388 |
if not found: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
389 |
raise ValueError, "\"%s\" Data Type doesn't exist !!!"%name |
151 | 390 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
391 |
||
392 |
def getpouElements(self): |
|
393 |
return self.pous.getpou() |
|
394 |
setattr(cls, "getpouElements", getpouElements) |
|
395 |
||
396 |
def getpouElement(self, name): |
|
397 |
elements = self.pous.getpou() |
|
2 | 398 |
for element in elements: |
151 | 399 |
if element.getname() == name: |
2 | 400 |
return element |
401 |
return None |
|
151 | 402 |
setattr(cls, "getpouElement", getpouElement) |
403 |
||
404 |
def appendpouElement(self, name, pou_type, body_type): |
|
405 |
for element in self.pous.getpou(): |
|
406 |
if element.getname() == name: |
|
2 | 407 |
raise ValueError, "\"%s\" POU already exists !!!"%name |
408 |
new_pou = PLCOpenClasses["pous_pou"]() |
|
151 | 409 |
new_pou.setname(name) |
410 |
new_pou.setpouType(pou_type) |
|
411 |
new_pou.setbody(PLCOpenClasses["body"]()) |
|
412 |
new_pou.setbodyType(body_type) |
|
413 |
self.pous.appendpou(new_pou) |
|
414 |
setattr(cls, "appendpouElement", appendpouElement) |
|
2 | 415 |
|
151 | 416 |
def insertpouElement(self, index, pou): |
417 |
self.pous.insertpou(index, pou) |
|
418 |
setattr(cls, "insertpouElement", insertpouElement) |
|
419 |
||
420 |
def removepouElement(self, name): |
|
2 | 421 |
found = False |
151 | 422 |
for idx, element in enumerate(self.pous.getpou()): |
423 |
if element.getname() == name: |
|
424 |
self.pous.removepou(idx) |
|
2 | 425 |
found = True |
426 |
break |
|
427 |
if not found: |
|
428 |
raise ValueError, "\"%s\" POU doesn't exist !!!"%name |
|
151 | 429 |
setattr(cls, "removepouElement", removepouElement) |
430 |
||
431 |
def setbodyType(self, type): |
|
2 | 432 |
if type == "IL": |
151 | 433 |
self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
2 | 434 |
elif type == "ST": |
151 | 435 |
self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
2 | 436 |
elif type == "LD": |
151 | 437 |
self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
2 | 438 |
elif type == "FBD": |
151 | 439 |
self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
2 | 440 |
elif type == "SFC": |
151 | 441 |
self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
2 | 442 |
else: |
443 |
raise ValueError, "%s isn't a valid body type!"%type |
|
444 |
||
151 | 445 |
def getbodyType(self): |
446 |
return self.body.getcontent()["name"] |
|
447 |
||
448 |
def resetexecutionOrder(self): |
|
449 |
self.body.resetexecutionOrder() |
|
450 |
||
451 |
def compileexecutionOrder(self): |
|
452 |
self.body.compileexecutionOrder() |
|
453 |
||
454 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
455 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
456 |
||
457 |
def addinstance(self, name, instance): |
|
458 |
self.body.appendcontentInstance(name, instance) |
|
459 |
||
460 |
def getinstances(self): |
|
461 |
return self.body.getcontentInstances() |
|
462 |
||
463 |
def getinstance(self, id): |
|
464 |
return self.body.getcontentInstance(id) |
|
465 |
||
466 |
def getrandomInstance(self, exclude): |
|
467 |
return self.body.getcontentRandomInstance(exclude) |
|
468 |
||
469 |
def getinstanceByName(self, name): |
|
470 |
return self.body.getcontentInstanceByName(name) |
|
471 |
||
472 |
def removeinstance(self, id): |
|
473 |
self.body.removecontentInstance(id) |
|
474 |
||
475 |
def settext(self, text): |
|
476 |
self.body.settext(text) |
|
477 |
||
478 |
def gettext(self): |
|
479 |
return self.body.gettext() |
|
480 |
setattr(cls, "gettext", gettext) |
|
2 | 481 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
482 |
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
|
483 |
if cls: |
151 | 484 |
setattr(cls, "setbodyType", setbodyType) |
485 |
setattr(cls, "getbodyType", getbodyType) |
|
486 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
487 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
488 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
489 |
setattr(cls, "addinstance", addinstance) |
|
490 |
setattr(cls, "getinstances", getinstances) |
|
491 |
setattr(cls, "getinstance", getinstance) |
|
492 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
493 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
494 |
setattr(cls, "removeinstance", removeinstance) |
|
495 |
setattr(cls, "settext", settext) |
|
496 |
setattr(cls, "gettext", gettext) |
|
497 |
||
498 |
def getvars(self): |
|
2 | 499 |
vars = [] |
500 |
reverse_types = {} |
|
501 |
for name, value in VarTypes.items(): |
|
502 |
reverse_types[value] = name |
|
151 | 503 |
for varlist in self.interface.getcontent(): |
2 | 504 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
505 |
return vars |
|
151 | 506 |
setattr(cls, "getvars", getvars) |
507 |
||
508 |
def setvars(self, vars): |
|
509 |
self.interface.setcontent([]) |
|
2 | 510 |
for vartype, varlist in vars: |
151 | 511 |
self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
512 |
setattr(cls, "setvars", setvars) |
|
513 |
||
514 |
def addpouVar(self, type, name): |
|
515 |
content = self.interface.getcontent() |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
516 |
if len(content) == 0 or content[-1]["name"] != "localVars": |
151 | 517 |
content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()}) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
518 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
519 |
varlist = content[-1]["value"] |
151 | 520 |
variables = varlist.getvariable() |
521 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
522 |
content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()}) |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
523 |
var = PLCOpenClasses["varListPlain_variable"]() |
151 | 524 |
var.setname(name) |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
525 |
var_type = PLCOpenClasses["dataType"]() |
151 | 526 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
527 |
derived_type.setname(type) |
|
528 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
|
529 |
var.settype(var_type) |
|
530 |
content[-1]["value"].appendvariable(var) |
|
531 |
setattr(cls, "addpouVar", addpouVar) |
|
532 |
||
533 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
|
534 |
content = self.interface.getcontent() |
|
94 | 535 |
for varlist in content: |
151 | 536 |
variables = varlist["value"].getvariable() |
94 | 537 |
for var in variables: |
151 | 538 |
if var.getname() == old_name: |
539 |
vartype_content = var.gettype().getcontent() |
|
540 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
|
541 |
var.setname(new_name) |
|
542 |
vartype_content["value"].setname(new_type) |
|
94 | 543 |
return |
151 | 544 |
setattr(cls, "changepouVar", changepouVar) |
545 |
||
546 |
def removepouVar(self, type, name): |
|
547 |
content = self.interface.getcontent() |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
548 |
for varlist in content: |
151 | 549 |
variables = varlist["value"].getvariable() |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
550 |
for var in variables: |
151 | 551 |
if var.getname() == name: |
552 |
vartype_content = var.gettype().getcontent() |
|
553 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
554 |
variables.remove(var) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
555 |
break |
151 | 556 |
if len(varlist["value"].getvariable()) == 0: |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
557 |
content.remove(varlist) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
558 |
break |
151 | 559 |
setattr(cls, "removepouVar", removepouVar) |
560 |
||
561 |
def hasblock(self, name): |
|
562 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
563 |
for instance in self.getinstances(): |
|
564 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
565 |
return True |
89 | 566 |
if self.transitions: |
151 | 567 |
for transition in self.transitions.gettransition(): |
568 |
result = transition.hasblock(name) |
|
89 | 569 |
if result: |
570 |
return result |
|
571 |
if self.actions: |
|
151 | 572 |
for action in self.actions.getaction(): |
573 |
result = action.hasblock(name) |
|
89 | 574 |
if result: |
575 |
return result |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
576 |
return False |
151 | 577 |
setattr(cls, "hasblock", hasblock) |
578 |
||
579 |
def addtransition(self, name, type): |
|
2 | 580 |
if not self.transitions: |
151 | 581 |
self.addtransitions() |
582 |
self.transitions.settransition([]) |
|
2 | 583 |
transition = PLCOpenClasses["transitions_transition"]() |
151 | 584 |
transition.setname(name) |
585 |
transition.setbodyType(type) |
|
586 |
self.transitions.appendtransition(transition) |
|
587 |
setattr(cls, "addtransition", addtransition) |
|
588 |
||
589 |
def gettransition(self, name): |
|
2 | 590 |
if self.transitions: |
151 | 591 |
for transition in self.transitions.gettransition(): |
592 |
if transition.getname() == name: |
|
2 | 593 |
return transition |
594 |
return None |
|
151 | 595 |
setattr(cls, "gettransition", gettransition) |
2 | 596 |
|
151 | 597 |
def gettransitionList(self): |
2 | 598 |
if self.transitions: |
151 | 599 |
return self.transitions.gettransition() |
2 | 600 |
return [] |
151 | 601 |
setattr(cls, "gettransitionList", gettransitionList) |
602 |
||
603 |
def removetransition(self, name): |
|
2 | 604 |
if self.transitions: |
151 | 605 |
transitions = self.transitions.gettransition() |
2 | 606 |
i = 0 |
607 |
removed = False |
|
608 |
while i < len(transitions) and not removed: |
|
151 | 609 |
if transitions[i].getname() == name: |
46 | 610 |
transitions.pop(i) |
2 | 611 |
removed = True |
612 |
i += 1 |
|
613 |
if not removed: |
|
614 |
raise ValueError, "Transition with name %s doesn't exists!"%name |
|
151 | 615 |
setattr(cls, "removetransition", removetransition) |
616 |
||
617 |
def addaction(self, name, type): |
|
2 | 618 |
if not self.actions: |
151 | 619 |
self.addactions() |
620 |
self.actions.setaction([]) |
|
2 | 621 |
action = PLCOpenClasses["actions_action"]() |
151 | 622 |
action.setname(name) |
623 |
action.setbodyType(type) |
|
624 |
self.actions.appendaction(action) |
|
625 |
setattr(cls, "addaction", addaction) |
|
626 |
||
627 |
def getaction(self, name): |
|
2 | 628 |
if self.actions: |
151 | 629 |
for action in self.actions.getaction(): |
630 |
if action.getname() == name: |
|
2 | 631 |
return action |
632 |
return None |
|
151 | 633 |
setattr(cls, "getaction", getaction) |
634 |
||
635 |
def getactionList(self): |
|
2 | 636 |
if self.actions: |
151 | 637 |
return self.actions.getaction() |
2 | 638 |
return [] |
151 | 639 |
setattr(cls, "getactionList", getactionList) |
2 | 640 |
|
151 | 641 |
def removeaction(self, name): |
2 | 642 |
if self.actions: |
151 | 643 |
actions = self.actions.getaction() |
2 | 644 |
i = 0 |
645 |
removed = False |
|
646 |
while i < len(actions) and not removed: |
|
151 | 647 |
if actions[i].getname() == name: |
46 | 648 |
actions.pop(i) |
2 | 649 |
removed = True |
650 |
i += 1 |
|
651 |
if not removed: |
|
652 |
raise ValueError, "Action with name %s doesn't exists!"%name |
|
151 | 653 |
setattr(cls, "removeaction", removeaction) |
2 | 654 |
|
58 | 655 |
def updateElementName(self, old_name, new_name): |
656 |
self.body.updateElementName(old_name, new_name) |
|
151 | 657 |
for action in self.getactionList(): |
58 | 658 |
action.updateElementName(old_name, new_name) |
151 | 659 |
for transition in self.gettransitionList(): |
58 | 660 |
transition.updateElementName(old_name, new_name) |
661 |
setattr(cls, "updateElementName", updateElementName) |
|
662 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
663 |
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
|
664 |
if cls: |
151 | 665 |
setattr(cls, "setbodyType", setbodyType) |
666 |
setattr(cls, "getbodyType", getbodyType) |
|
667 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
668 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
669 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
670 |
setattr(cls, "addinstance", addinstance) |
|
671 |
setattr(cls, "getinstances", getinstances) |
|
672 |
setattr(cls, "getinstance", getinstance) |
|
673 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
674 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
675 |
setattr(cls, "removeinstance", removeinstance) |
|
676 |
setattr(cls, "settext", settext) |
|
677 |
setattr(cls, "gettext", gettext) |
|
2 | 678 |
|
58 | 679 |
def updateElementName(self, old_name, new_name): |
680 |
self.body.updateElementName(old_name, new_name) |
|
681 |
setattr(cls, "updateElementName", updateElementName) |
|
682 |
||
151 | 683 |
def hasblock(self, name): |
684 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
685 |
for instance in self.getinstances(): |
|
686 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
687 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
688 |
return False |
151 | 689 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
690 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
691 |
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
|
692 |
if cls: |
151 | 693 |
setattr(cls, "setbodyType", setbodyType) |
694 |
setattr(cls, "getbodyType", getbodyType) |
|
695 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
696 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
697 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
698 |
setattr(cls, "addinstance", addinstance) |
|
699 |
setattr(cls, "getinstances", getinstances) |
|
700 |
setattr(cls, "getinstance", getinstance) |
|
701 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
702 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
703 |
setattr(cls, "removeinstance", removeinstance) |
|
704 |
setattr(cls, "settext", settext) |
|
705 |
setattr(cls, "gettext", gettext) |
|
2 | 706 |
|
58 | 707 |
def updateElementName(self, old_name, new_name): |
708 |
self.body.updateElementName(old_name, new_name) |
|
709 |
setattr(cls, "updateElementName", updateElementName) |
|
710 |
||
151 | 711 |
def hasblock(self, name): |
712 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
713 |
for instance in self.getinstances(): |
|
714 |
if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name: |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
715 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
716 |
return False |
151 | 717 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
718 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
719 |
cls = PLCOpenClasses.get("body", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
720 |
if cls: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
721 |
cls.currentExecutionOrderId = 0 |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
722 |
|
151 | 723 |
def resetcurrentExecutionOrderId(self): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
724 |
self.currentExecutionOrderId = 0 |
151 | 725 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
726 |
||
727 |
def getnewExecutionOrderId(self): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
728 |
self.currentExecutionOrderId += 1 |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
729 |
return self.currentExecutionOrderId |
151 | 730 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
731 |
||
732 |
def resetexecutionOrder(self): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
733 |
if self.content["name"] == "FBD": |
151 | 734 |
for element in self.content["value"].getcontent(): |
735 |
if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
|
736 |
PLCOpenClasses.get("commonObjects_connector", None), |
|
737 |
PLCOpenClasses.get("commonObjects_continuation", None))): |
|
738 |
element["value"].setexecutionOrderId(0) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
739 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
740 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 741 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
742 |
||
743 |
def compileexecutionOrder(self): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
744 |
if self.content["name"] == "FBD": |
151 | 745 |
self.resetexecutionOrder() |
746 |
self.resetcurrentExecutionOrderId() |
|
747 |
for element in self.content["value"].getcontent(): |
|
748 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getExecutionOrderId() == 0: |
|
749 |
connections = element["value"].connectionPointIn.getconnections() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
750 |
if connections and len(connections) == 1: |
151 | 751 |
self.compileelementExecutionOrder(connections[0]) |
752 |
element["value"].setexecutionOrderId(self.getnewExecutionOrderId()) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
753 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
754 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 755 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
756 |
||
757 |
def compileelementExecutionOrder(self, link): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
758 |
if self.content["name"] == "FBD": |
151 | 759 |
localid = link.getrefLocalId() |
760 |
instance = self.getcontentInstance(localid) |
|
761 |
if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
|
762 |
for variable in instance.inputVariables.getvariable(): |
|
763 |
connections = variable.connectionPointIn.getconnections() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
764 |
if connections and len(connections) == 1: |
151 | 765 |
self.compileelementExecutionOrder(connections[0]) |
766 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
|
767 |
elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
|
768 |
name = instance.getname() |
|
769 |
for tmp_instance in self.getcontentInstances(): |
|
770 |
if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
|
771 |
connections = tmp_instance.connectionPointIn.getconnections() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
772 |
if connections and len(connections) == 1: |
151 | 773 |
self.compileelementExecutionOrder(connections[0]) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
774 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
775 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 776 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
777 |
||
778 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
779 |
if self.content["name"] == "FBD": |
151 | 780 |
old_executionOrder = instance.getexecutionOrderId() |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
781 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
151 | 782 |
for element in self.content["value"].getcontent(): |
783 |
if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
|
784 |
element_executionOrder = element["value"].getexecutionOrderId() |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
785 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
151 | 786 |
element["value"].setexecutionOrderId(element_executionOrder - 1) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
787 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
151 | 788 |
element["value"].setexecutionOrderId(element_executionOrder + 1) |
789 |
instance.setexecutionOrderId(new_executionOrder) |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
790 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
791 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 792 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
793 |
||
794 |
def appendcontentInstance(self, name, instance): |
|
2 | 795 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 796 |
self.content["value"].appendcontent({"name" : name, "value" : instance}) |
2 | 797 |
else: |
798 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 799 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
800 |
||
801 |
def getcontentInstances(self): |
|
2 | 802 |
if self.content["name"] in ["LD","FBD","SFC"]: |
803 |
instances = [] |
|
151 | 804 |
for element in self.content["value"].getcontent(): |
2 | 805 |
instances.append(element["value"]) |
806 |
return instances |
|
807 |
else: |
|
808 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 809 |
setattr(cls, "getcontentInstances", getcontentInstances) |
810 |
||
811 |
def getcontentInstance(self, id): |
|
2 | 812 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 813 |
for element in self.content["value"].getcontent(): |
814 |
if element["value"].getlocalId() == id: |
|
2 | 815 |
return element["value"] |
0 | 816 |
return None |
2 | 817 |
else: |
818 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 819 |
setattr(cls, "getcontentInstance", getcontentInstance) |
820 |
||
821 |
def getcontentRandomInstance(self, exclude): |
|
2 | 822 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 823 |
for element in self.content["value"].getcontent(): |
824 |
if element["value"].getlocalId() not in exclude: |
|
2 | 825 |
return element["value"] |
826 |
return None |
|
827 |
else: |
|
828 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 829 |
setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
830 |
||
831 |
def getcontentInstanceByName(self, name): |
|
2 | 832 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 833 |
for element in self.content["value"].getcontent(): |
2 | 834 |
if element["value"].getLocalId() == name: |
835 |
return element["value"] |
|
836 |
else: |
|
837 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 838 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
839 |
||
840 |
def removecontentInstance(self, id): |
|
2 | 841 |
if self.content["name"] in ["LD","FBD","SFC"]: |
842 |
i = 0 |
|
843 |
removed = False |
|
151 | 844 |
elements = self.content["value"].getcontent() |
2 | 845 |
while i < len(elements) and not removed: |
151 | 846 |
if elements[i]["value"].getlocalId() == id: |
847 |
self.content["value"].removecontent(i) |
|
2 | 848 |
removed = True |
849 |
i += 1 |
|
850 |
if not removed: |
|
851 |
raise ValueError, "Instance with id %d doesn't exists!"%id |
|
852 |
else: |
|
853 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 854 |
setattr(cls, "removecontentInstance", removecontentInstance) |
855 |
||
856 |
def settext(self, text): |
|
2 | 857 |
if self.content["name"] in ["IL","ST"]: |
151 | 858 |
self.content["value"].settext(text) |
2 | 859 |
else: |
860 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
151 | 861 |
setattr(cls, "settext", settext) |
862 |
||
863 |
def gettext(self): |
|
2 | 864 |
if self.content["name"] in ["IL","ST"]: |
151 | 865 |
return self.content["value"].gettext() |
2 | 866 |
else: |
867 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
151 | 868 |
setattr(cls, "gettext", gettext) |
58 | 869 |
|
870 |
def updateElementName(self, old_name, new_name): |
|
871 |
if self.content["name"] in ["IL", "ST"]: |
|
872 |
self.content["value"].updateElementName(old_name, new_name) |
|
873 |
else: |
|
151 | 874 |
for element in self.content["value"].getcontent(): |
58 | 875 |
element["value"].updateElementName(old_name, new_name) |
876 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 877 |
|
151 | 878 |
def getx(self): |
879 |
return self.position.getx() |
|
880 |
||
881 |
def gety(self): |
|
882 |
return self.position.gety() |
|
883 |
||
884 |
def setx(self, x): |
|
885 |
self.position.setx(x) |
|
886 |
||
887 |
def sety(self, y): |
|
888 |
self.position.sety(y) |
|
889 |
||
890 |
cls = PLCOpenClasses.get("commonObjects_comment", None) |
|
891 |
if cls: |
|
892 |
setattr(cls, "getx", getx) |
|
893 |
setattr(cls, "gety", gety) |
|
894 |
setattr(cls, "setx", setx) |
|
895 |
setattr(cls, "sety", sety) |
|
896 |
||
897 |
def setcontentText(self, text): |
|
898 |
self.content.settext(text) |
|
899 |
setattr(cls, "setcontentText", setcontentText) |
|
0 | 900 |
|
151 | 901 |
def getcontentText(self): |
902 |
return self.content.gettext() |
|
903 |
setattr(cls, "getcontentText", getcontentText) |
|
58 | 904 |
|
905 |
def updateElementName(self, old_name, new_name): |
|
906 |
self.content.updateElementName(old_name, new_name) |
|
907 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 908 |
|
151 | 909 |
cls = PLCOpenClasses.get("fbdObjects_block", None) |
910 |
if cls: |
|
911 |
setattr(cls, "getx", getx) |
|
912 |
setattr(cls, "gety", gety) |
|
913 |
setattr(cls, "setx", setx) |
|
914 |
setattr(cls, "sety", sety) |
|
2 | 915 |
|
58 | 916 |
def updateElementName(self, old_name, new_name): |
917 |
if self.typeName == old_name: |
|
918 |
self.typeName = new_name |
|
919 |
setattr(cls, "updateElementName", updateElementName) |
|
920 |
||
151 | 921 |
cls = PLCOpenClasses.get("ldObjects_leftPowerRail", None) |
922 |
if cls: |
|
923 |
setattr(cls, "getx", getx) |
|
924 |
setattr(cls, "gety", gety) |
|
925 |
setattr(cls, "setx", setx) |
|
926 |
setattr(cls, "sety", sety) |
|
2 | 927 |
|
58 | 928 |
def updateElementName(self, old_name, new_name): |
929 |
pass |
|
930 |
setattr(cls, "updateElementName", updateElementName) |
|
931 |
||
151 | 932 |
cls = PLCOpenClasses.get("ldObjects_rightPowerRail", None) |
933 |
if cls: |
|
934 |
setattr(cls, "getx", getx) |
|
935 |
setattr(cls, "gety", gety) |
|
936 |
setattr(cls, "setx", setx) |
|
937 |
setattr(cls, "sety", sety) |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
938 |
|
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
939 |
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
|
940 |
pass |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
941 |
setattr(cls, "updateElementName", updateElementName) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
942 |
|
151 | 943 |
cls = PLCOpenClasses.get("ldObjects_contact", None) |
944 |
if cls: |
|
945 |
setattr(cls, "getx", getx) |
|
946 |
setattr(cls, "gety", gety) |
|
947 |
setattr(cls, "setx", setx) |
|
948 |
setattr(cls, "sety", sety) |
|
2 | 949 |
|
58 | 950 |
def updateElementName(self, old_name, new_name): |
951 |
if self.variable == old_name: |
|
952 |
self.variable = new_name |
|
953 |
setattr(cls, "updateElementName", updateElementName) |
|
954 |
||
151 | 955 |
cls = PLCOpenClasses.get("ldObjects_coil", None) |
956 |
if cls: |
|
957 |
setattr(cls, "getx", getx) |
|
958 |
setattr(cls, "gety", gety) |
|
959 |
setattr(cls, "setx", setx) |
|
960 |
setattr(cls, "sety", sety) |
|
2 | 961 |
|
58 | 962 |
def updateElementName(self, old_name, new_name): |
963 |
if self.variable == old_name: |
|
964 |
self.variable = new_name |
|
965 |
setattr(cls, "updateElementName", updateElementName) |
|
966 |
||
151 | 967 |
cls = PLCOpenClasses.get("sfcObjects_step", None) |
968 |
if cls: |
|
969 |
setattr(cls, "getx", getx) |
|
970 |
setattr(cls, "gety", gety) |
|
971 |
setattr(cls, "setx", setx) |
|
972 |
setattr(cls, "sety", sety) |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
973 |
|
58 | 974 |
def updateElementName(self, old_name, new_name): |
975 |
pass |
|
976 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 977 |
|
151 | 978 |
cls = PLCOpenClasses.get("sfcObjects_transition", None) |
979 |
if cls: |
|
980 |
setattr(cls, "getx", getx) |
|
981 |
setattr(cls, "gety", gety) |
|
982 |
setattr(cls, "setx", setx) |
|
983 |
setattr(cls, "sety", sety) |
|
984 |
||
985 |
def setconditionContent(self, type, value): |
|
2 | 986 |
if not self.condition: |
151 | 987 |
self.addcondition() |
2 | 988 |
if type == "reference": |
989 |
condition = PLCOpenClasses["condition_reference"]() |
|
151 | 990 |
condition.setname(value) |
2 | 991 |
elif type == "inline": |
992 |
condition = PLCOpenClasses["condition_inline"]() |
|
151 | 993 |
condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
994 |
condition.settext(value) |
|
69 | 995 |
elif type == "connection": |
996 |
condition = [] |
|
151 | 997 |
self.condition.setcontent({"name" : type, "value" : condition}) |
998 |
setattr(cls, "setconditionContent", setconditionContent) |
|
0 | 999 |
|
151 | 1000 |
def getconditionContent(self): |
2 | 1001 |
if self.condition: |
151 | 1002 |
content = self.condition.getcontent() |
2 | 1003 |
values = {"type" : content["name"]} |
1004 |
if values["type"] == "reference": |
|
151 | 1005 |
values["value"] = content["value"].getname() |
2 | 1006 |
elif values["type"] == "inline": |
151 | 1007 |
values["value"] = content["value"].gettext() |
2 | 1008 |
return values |
1009 |
return "" |
|
151 | 1010 |
setattr(cls, "getconditionContent", getconditionContent) |
2 | 1011 |
|
58 | 1012 |
def updateElementName(self, old_name, new_name): |
1013 |
if self.condition: |
|
151 | 1014 |
content = self.condition.getcontent() |
58 | 1015 |
if content["name"] == "reference": |
151 | 1016 |
if content["value"].getname() == old_name: |
1017 |
content["value"].setname(new_name) |
|
58 | 1018 |
elif content["name"] == "inline": |
1019 |
content["value"].updateElementName(old_name, new_name) |
|
1020 |
setattr(cls, "updateElementName", updateElementName) |
|
1021 |
||
151 | 1022 |
def addconnection(self): |
69 | 1023 |
if self.condition: |
151 | 1024 |
content = self.condition.getcontent() |
69 | 1025 |
if content["name"] != "connection": |
151 | 1026 |
self.condition.setcontent({"name" : "connection", "value" : []}) |
1027 |
content = self.condition.getcontent() |
|
69 | 1028 |
content["value"].append(PLCOpenClasses["connection"]()) |
151 | 1029 |
setattr(cls, "addconnection", addconnection) |
1030 |
||
1031 |
def removeconnection(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1032 |
if self.condition: |
151 | 1033 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1034 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1035 |
content["value"].pop(idx) |
151 | 1036 |
setattr(cls, "removeconnection", removeconnection) |
1037 |
||
1038 |
def removeconnections(self): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1039 |
if self.condition: |
151 | 1040 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1041 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1042 |
content["value"] = [] |
151 | 1043 |
setattr(cls, "removeconnections", removeconnections) |
1044 |
||
1045 |
def getconnections(self): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1046 |
if self.condition: |
151 | 1047 |
content = self.condition.getcontent() |
63
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 |
return content["value"] |
151 | 1050 |
setattr(cls, "getconnections", getconnections) |
1051 |
||
1052 |
def setconnectionId(self, idx, id): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1053 |
if self.condition: |
151 | 1054 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1055 |
if content["name"] == "connection": |
151 | 1056 |
content["value"][idx].setrefLocalId(id) |
1057 |
setattr(cls, "setconnectionId", setconnectionId) |
|
1058 |
||
1059 |
def getconnectionId(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1060 |
if self.condition: |
151 | 1061 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1062 |
if content["name"] == "connection": |
151 | 1063 |
return content["value"][idx].getrefLocalId() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1064 |
return None |
151 | 1065 |
setattr(cls, "getconnectionId", getconnectionId) |
1066 |
||
1067 |
def setconnectionPoints(self, idx, points): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1068 |
if self.condition: |
151 | 1069 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1070 |
if content["name"] == "connection": |
151 | 1071 |
content["value"][idx].setpoints(points) |
1072 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
1073 |
||
1074 |
def getconnectionPoints(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1075 |
if self.condition: |
151 | 1076 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1077 |
if content["name"] == "connection": |
151 | 1078 |
return content["value"][idx].getpoints() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1079 |
return None |
151 | 1080 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
1081 |
||
1082 |
def setconnectionParameter(self, idx, parameter): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1083 |
if self.condition: |
151 | 1084 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1085 |
if content["name"] == "connection": |
151 | 1086 |
content["value"][idx].setformalParameter(parameter) |
1087 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
1088 |
||
1089 |
def getconnectionParameter(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1090 |
if self.condition: |
151 | 1091 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1092 |
if content["name"] == "connection": |
151 | 1093 |
return content["value"][idx].getformalParameter() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1094 |
return None |
151 | 1095 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
1096 |
||
1097 |
cls = PLCOpenClasses.get("sfcObjects_selectionDivergence", None) |
|
1098 |
if cls: |
|
1099 |
setattr(cls, "getx", getx) |
|
1100 |
setattr(cls, "gety", gety) |
|
1101 |
setattr(cls, "setx", setx) |
|
1102 |
setattr(cls, "sety", sety) |
|
2 | 1103 |
|
58 | 1104 |
def updateElementName(self, old_name, new_name): |
1105 |
pass |
|
1106 |
setattr(cls, "updateElementName", updateElementName) |
|
1107 |
||
151 | 1108 |
cls = PLCOpenClasses.get("sfcObjects_selectionConvergence", None) |
1109 |
if cls: |
|
1110 |
setattr(cls, "getx", getx) |
|
1111 |
setattr(cls, "gety", gety) |
|
1112 |
setattr(cls, "setx", setx) |
|
1113 |
setattr(cls, "sety", sety) |
|
2 | 1114 |
|
58 | 1115 |
def updateElementName(self, old_name, new_name): |
1116 |
pass |
|
1117 |
setattr(cls, "updateElementName", updateElementName) |
|
1118 |
||
151 | 1119 |
cls = PLCOpenClasses.get("sfcObjects_simultaneousDivergence", None) |
1120 |
if cls: |
|
1121 |
setattr(cls, "getx", getx) |
|
1122 |
setattr(cls, "gety", gety) |
|
1123 |
setattr(cls, "setx", setx) |
|
1124 |
setattr(cls, "sety", sety) |
|
2 | 1125 |
|
58 | 1126 |
def updateElementName(self, old_name, new_name): |
1127 |
pass |
|
1128 |
setattr(cls, "updateElementName", updateElementName) |
|
1129 |
||
151 | 1130 |
cls = PLCOpenClasses.get("sfcObjects_simultaneousConvergence", None) |
1131 |
if cls: |
|
1132 |
setattr(cls, "getx", getx) |
|
1133 |
setattr(cls, "gety", gety) |
|
1134 |
setattr(cls, "setx", setx) |
|
1135 |
setattr(cls, "sety", sety) |
|
58 | 1136 |
|
1137 |
def updateElementName(self, old_name, new_name): |
|
1138 |
pass |
|
1139 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1140 |
|
151 | 1141 |
cls = PLCOpenClasses.get("sfcObjects_jumpStep", None) |
1142 |
if cls: |
|
1143 |
setattr(cls, "getx", getx) |
|
1144 |
setattr(cls, "gety", gety) |
|
1145 |
setattr(cls, "setx", setx) |
|
1146 |
setattr(cls, "sety", sety) |
|
58 | 1147 |
|
1148 |
def updateElementName(self, old_name, new_name): |
|
1149 |
pass |
|
1150 |
setattr(cls, "updateElementName", updateElementName) |
|
1151 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1152 |
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
|
1153 |
if cls: |
151 | 1154 |
def setreferenceName(self, name): |
1155 |
if self.reference: |
|
1156 |
self.reference.setname(name) |
|
1157 |
setattr(cls, "setreferenceName", setreferenceName) |
|
1158 |
||
1159 |
def getreferenceName(self): |
|
1160 |
if self.reference: |
|
1161 |
return self.reference.getname() |
|
2 | 1162 |
return None |
151 | 1163 |
setattr(cls, "getreferenceName", getreferenceName) |
1164 |
||
1165 |
def setinlineContent(self, content): |
|
1166 |
if self.inline: |
|
1167 |
self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1168 |
self.inline.settext(content) |
|
1169 |
setattr(cls, "setinlineContent", setinlineContent) |
|
1170 |
||
1171 |
def getinlineContent(self): |
|
1172 |
if self.inline: |
|
1173 |
return self.inline.gettext() |
|
2 | 1174 |
return None |
151 | 1175 |
setattr(cls, "getinlineContent", getinlineContent) |
1176 |
||
1177 |
def updateElementName(self, old_name, new_name): |
|
1178 |
if self.reference and self.reference.getname() == old_name: |
|
1179 |
self.reference.setname(new_name) |
|
58 | 1180 |
if self.inline: |
1181 |
self.inline.updateElementName(old_name, new_name) |
|
1182 |
setattr(cls, "updateElementName", updateElementName) |
|
1183 |
||
151 | 1184 |
cls = PLCOpenClasses.get("commonObjects_actionBlock", None) |
1185 |
if cls: |
|
1186 |
setattr(cls, "getx", getx) |
|
1187 |
setattr(cls, "gety", gety) |
|
1188 |
setattr(cls, "setx", setx) |
|
1189 |
setattr(cls, "sety", sety) |
|
1190 |
||
1191 |
def setactions(self, actions): |
|
2 | 1192 |
self.action = [] |
1193 |
for params in actions: |
|
1194 |
action = PLCOpenClasses["actionBlock_action"]() |
|
151 | 1195 |
action.setqualifier(params["qualifier"]) |
2 | 1196 |
if params["type"] == "reference": |
151 | 1197 |
action.addreference() |
1198 |
action.setreferenceName(params["value"]) |
|
0 | 1199 |
else: |
151 | 1200 |
action.addinline() |
1201 |
action.setinlineContent(params["value"]) |
|
2 | 1202 |
if "duration" in params: |
151 | 1203 |
action.setduration(params["duration"]) |
2 | 1204 |
if "indicator" in params: |
151 | 1205 |
action.setindicator(params["indicator"]) |
2 | 1206 |
self.action.append(action) |
151 | 1207 |
setattr(cls, "setactions", setactions) |
1208 |
||
1209 |
def getactions(self): |
|
2 | 1210 |
actions = [] |
1211 |
for action in self.action: |
|
1212 |
params = {} |
|
151 | 1213 |
params["qualifier"] = action.getqualifier() |
108 | 1214 |
if params["qualifier"] is None: |
1215 |
params["qualifier"] = "N" |
|
151 | 1216 |
if action.getreference(): |
2 | 1217 |
params["type"] = "reference" |
151 | 1218 |
params["value"] = action.getreferenceName() |
1219 |
elif action.getinline(): |
|
2 | 1220 |
params["type"] = "inline" |
151 | 1221 |
params["value"] = action.getinlineContent() |
1222 |
duration = action.getduration() |
|
2 | 1223 |
if duration: |
1224 |
params["duration"] = duration |
|
151 | 1225 |
indicator = action.getindicator() |
2 | 1226 |
if indicator: |
1227 |
params["indicator"] = indicator |
|
1228 |
actions.append(params) |
|
1229 |
return actions |
|
151 | 1230 |
setattr(cls, "getactions", getactions) |
2 | 1231 |
|
58 | 1232 |
def updateElementName(self, old_name, new_name): |
1233 |
for action in self.action: |
|
1234 |
action.updateElementName(old_name, new_name) |
|
1235 |
setattr(cls, "updateElementName", updateElementName) |
|
1236 |
||
151 | 1237 |
cls = PLCOpenClasses.get("fbdObjects_inVariable", None) |
1238 |
if cls: |
|
1239 |
setattr(cls, "getx", getx) |
|
1240 |
setattr(cls, "gety", gety) |
|
1241 |
setattr(cls, "setx", setx) |
|
1242 |
setattr(cls, "sety", sety) |
|
58 | 1243 |
|
1244 |
def updateElementName(self, old_name, new_name): |
|
1245 |
if self.expression == old_name: |
|
1246 |
self.expression = new_name |
|
1247 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1248 |
|
151 | 1249 |
cls = PLCOpenClasses.get("fbdObjects_outVariable", None) |
1250 |
if cls: |
|
1251 |
setattr(cls, "getx", getx) |
|
1252 |
setattr(cls, "gety", gety) |
|
1253 |
setattr(cls, "setx", setx) |
|
1254 |
setattr(cls, "sety", sety) |
|
2 | 1255 |
|
58 | 1256 |
def updateElementName(self, old_name, new_name): |
1257 |
if self.expression == old_name: |
|
1258 |
self.expression = new_name |
|
1259 |
setattr(cls, "updateElementName", updateElementName) |
|
1260 |
||
151 | 1261 |
cls = PLCOpenClasses.get("fbdObjects_inOutVariable", None) |
1262 |
if cls: |
|
1263 |
setattr(cls, "getx", getx) |
|
1264 |
setattr(cls, "gety", gety) |
|
1265 |
setattr(cls, "setx", setx) |
|
1266 |
setattr(cls, "sety", sety) |
|
2 | 1267 |
|
58 | 1268 |
def updateElementName(self, old_name, new_name): |
1269 |
if self.expression == old_name: |
|
1270 |
self.expression = new_name |
|
1271 |
setattr(cls, "updateElementName", updateElementName) |
|
1272 |
||
151 | 1273 |
cls = PLCOpenClasses.get("commonObjects_continuation", None) |
1274 |
if cls: |
|
1275 |
setattr(cls, "getx", getx) |
|
1276 |
setattr(cls, "gety", gety) |
|
1277 |
setattr(cls, "setx", setx) |
|
1278 |
setattr(cls, "sety", sety) |
|
58 | 1279 |
|
1280 |
def updateElementName(self, old_name, new_name): |
|
1281 |
pass |
|
1282 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1283 |
|
151 | 1284 |
cls = PLCOpenClasses.get("commonObjects_connector", None) |
1285 |
if cls: |
|
1286 |
setattr(cls, "getx", getx) |
|
1287 |
setattr(cls, "gety", gety) |
|
1288 |
setattr(cls, "setx", setx) |
|
1289 |
setattr(cls, "sety", sety) |
|
58 | 1290 |
|
1291 |
def updateElementName(self, old_name, new_name): |
|
1292 |
pass |
|
1293 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1294 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1295 |
cls = PLCOpenClasses.get("connection", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1296 |
if cls: |
151 | 1297 |
def setpoints(self, points): |
2 | 1298 |
self.position = [] |
1299 |
for point in points: |
|
1300 |
position = PLCOpenClasses["position"]() |
|
151 | 1301 |
position.setx(point.x) |
1302 |
position.sety(point.y) |
|
2 | 1303 |
self.position.append(position) |
151 | 1304 |
setattr(cls, "setpoints", setpoints) |
1305 |
||
1306 |
def getpoints(self): |
|
2 | 1307 |
points = [] |
1308 |
for position in self.position: |
|
151 | 1309 |
points.append((position.getx(),position.gety())) |
2 | 1310 |
return points |
151 | 1311 |
setattr(cls, "getpoints", getpoints) |
2 | 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("connectionPointIn", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1314 |
if cls: |
151 | 1315 |
def setrelPositionXY(self, x, y): |
2 | 1316 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 1317 |
self.relPosition.setx(x) |
1318 |
self.relPosition.sety(y) |
|
1319 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
1320 |
||
1321 |
def getrelPositionXY(self): |
|
2 | 1322 |
if self.relPosition: |
151 | 1323 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 1324 |
else: |
0 | 1325 |
return self.relPosition |
151 | 1326 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
1327 |
||
1328 |
def addconnection(self): |
|
2 | 1329 |
if not self.content: |
151 | 1330 |
self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
2 | 1331 |
else: |
1332 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
151 | 1333 |
setattr(cls, "addconnection", addconnection) |
1334 |
||
1335 |
def removeconnection(self, idx): |
|
2 | 1336 |
if self.content: |
1337 |
self.content["value"].pop(idx) |
|
1338 |
if len(self.content["value"]) == 0: |
|
1339 |
self.content = None |
|
151 | 1340 |
setattr(cls, "removeconnection", removeconnection) |
1341 |
||
1342 |
def removeconnections(self): |
|
2 | 1343 |
if self.content: |
1344 |
self.content = None |
|
151 | 1345 |
setattr(cls, "removeconnections", removeconnections) |
1346 |
||
1347 |
def getconnections(self): |
|
2 | 1348 |
if self.content: |
1349 |
return self.content["value"] |
|
151 | 1350 |
setattr(cls, "getconnections", getconnections) |
1351 |
||
1352 |
def setconnectionId(self, idx, id): |
|
2 | 1353 |
if self.content: |
151 | 1354 |
self.content["value"][idx].setrefLocalId(id) |
1355 |
setattr(cls, "setconnectionId", setconnectionId) |
|
1356 |
||
1357 |
def getconnectionId(self, idx): |
|
2 | 1358 |
if self.content: |
151 | 1359 |
return self.content["value"][idx].getrefLocalId() |
2 | 1360 |
return None |
151 | 1361 |
setattr(cls, "getconnectionId", getconnectionId) |
1362 |
||
1363 |
def setconnectionPoints(self, idx, points): |
|
2 | 1364 |
if self.content: |
151 | 1365 |
self.content["value"][idx].setpoints(points) |
1366 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
1367 |
||
1368 |
def getconnectionPoints(self, idx): |
|
2 | 1369 |
if self.content: |
151 | 1370 |
return self.content["value"][idx].getpoints() |
2 | 1371 |
return None |
151 | 1372 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
1373 |
||
1374 |
def setconnectionParameter(self, idx, parameter): |
|
27 | 1375 |
if self.content: |
151 | 1376 |
self.content["value"][idx].setformalParameter(parameter) |
1377 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
1378 |
||
1379 |
def getconnectionParameter(self, idx): |
|
27 | 1380 |
if self.content: |
151 | 1381 |
return self.content["value"][idx].getformalParameter() |
27 | 1382 |
return None |
151 | 1383 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
27 | 1384 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1385 |
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
|
1386 |
if cls: |
151 | 1387 |
def setrelPositionXY(self, x, y): |
2 | 1388 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 1389 |
self.relPosition.setx(x) |
1390 |
self.relPosition.sety(y) |
|
1391 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
1392 |
||
1393 |
def getrelPositionXY(self): |
|
2 | 1394 |
if self.relPosition: |
151 | 1395 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 1396 |
return self.relPosition |
151 | 1397 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2 | 1398 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1399 |
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
|
1400 |
if cls: |
151 | 1401 |
def setvalue(self, value): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1402 |
if value.startswith("[") and value.endswith("]"): |
2 | 1403 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
151 | 1404 |
self.content = {"name" : "arrayValue", "value" : arrayValue} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1405 |
elif value.startswith("(") and value.endswith(")"): |
2 | 1406 |
structValue = PLCOpenClasses["value_structValue"]() |
151 | 1407 |
self.content = {"name" : "structValue", "value" : structValue} |
2 | 1408 |
else: |
1409 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
151 | 1410 |
self.content = {"name" : "simpleValue", "value": simpleValue} |
1411 |
self.content["value"].setvalue(value) |
|
1412 |
setattr(cls, "setvalue", setvalue) |
|
1413 |
||
1414 |
def getvalue(self): |
|
1415 |
return self.content["value"].getvalue() |
|
1416 |
setattr(cls, "getvalue", getvalue) |
|
2 | 1417 |
|
147 | 1418 |
def extractValues(values): |
145 | 1419 |
items = values.split(",") |
1420 |
i = 1 |
|
1421 |
while i < len(items): |
|
1422 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
1423 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
1424 |
if opened > closed: |
|
1425 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
1426 |
elif opened == closed: |
|
1427 |
i += 1 |
|
1428 |
else: |
|
1429 |
raise ValueError, "\"%s\" is an invalid value!"%value |
|
1430 |
return items |
|
1431 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1432 |
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
|
1433 |
if cls: |
145 | 1434 |
arrayValue_model = re.compile("([0-9]*)\((.*)\)$") |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1435 |
|
151 | 1436 |
def setvalue(self, value): |
2 | 1437 |
self.value = [] |
145 | 1438 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1439 |
item = item.strip() |
2 | 1440 |
element = PLCOpenClasses["arrayValue_value"]() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1441 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1442 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1443 |
groups = result.groups() |
151 | 1444 |
element.setrepetitionValue(int(groups[0])) |
1445 |
element.setvalue(groups[1].strip()) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1446 |
else: |
151 | 1447 |
element.setvalue(item) |
2 | 1448 |
self.value.append(element) |
151 | 1449 |
setattr(cls, "setvalue", setvalue) |
1450 |
||
1451 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1452 |
values = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1453 |
for element in self.value: |
151 | 1454 |
repetition = element.getrepetitionValue() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1455 |
if repetition is not None and repetition > 1: |
151 | 1456 |
values.append("%d(%s)"%(repetition, element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1457 |
else: |
151 | 1458 |
values.append(element.getvalue()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1459 |
return "[%s]"%", ".join(values) |
151 | 1460 |
setattr(cls, "getvalue", getvalue) |
2 | 1461 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1462 |
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
|
1463 |
if cls: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1464 |
structValue_model = re.compile("(.*):=(.*)") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1465 |
|
151 | 1466 |
def setvalue(self, value): |
2 | 1467 |
self.value = [] |
145 | 1468 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1469 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1470 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1471 |
groups = result.groups() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1472 |
element = PLCOpenClasses["structValue_value"]() |
151 | 1473 |
element.setmember(groups[0].strip()) |
1474 |
element.setvalue(groups[1].strip()) |
|
2 | 1475 |
self.value.append(element) |
151 | 1476 |
setattr(cls, "setvalue", setvalue) |
1477 |
||
1478 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1479 |
values = [] |
2 | 1480 |
for element in self.value: |
151 | 1481 |
values.append("%s := %s"%(element.getmember(), element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1482 |
return "(%s)"%", ".join(values) |
151 | 1483 |
setattr(cls, "getvalue", getvalue) |