author | lbessard |
Wed, 10 Sep 2008 16:49:49 +0200 | |
changeset 267 | a95bfb76a1eb |
parent 251 | cc5377a296ea |
child 278 | e3ed4747086f |
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 * |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
26 |
from structures import * |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
27 |
from types import * |
166 | 28 |
import os, re |
0 | 29 |
|
30 |
""" |
|
31 |
Dictionary that makes the relation between var names in plcopen and displayed values |
|
32 |
""" |
|
33 |
VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars", |
|
34 |
"Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars", |
|
35 |
"Global" : "globalVars", "Access" : "accessVars"} |
|
36 |
||
37 |
""" |
|
38 |
Define in which order var types must be displayed |
|
39 |
""" |
|
40 |
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"] |
|
41 |
||
42 |
""" |
|
43 |
Define which action qualifier must be associated with a duration |
|
44 |
""" |
|
45 |
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, |
|
46 |
"P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True} |
|
47 |
||
151 | 48 |
PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "TC6_XML_V10_B.xsd")) |
2 | 49 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
50 |
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
|
51 |
if cls: |
58 | 52 |
def updateElementName(self, old_name, new_name): |
53 |
index = self.text.find(old_name) |
|
54 |
while index != -1: |
|
55 |
if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): |
|
56 |
index = self.text.find(old_name, index + len(old_name)) |
|
57 |
elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): |
|
58 |
index = self.text.find(old_name, index + len(old_name)) |
|
59 |
else: |
|
60 |
self.text = self.text[:index] + new_name + self.text[index + len(old_name):] |
|
61 |
index = self.text.find(old_name, index + len(new_name)) |
|
62 |
setattr(cls, "updateElementName", updateElementName) |
|
63 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
64 |
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
|
65 |
if cls: |
2 | 66 |
cls.singleLineAttributes = False |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
67 |
cls.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
68 |
cls.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
69 |
cls.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
70 |
cls.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
71 |
cls.CustomBlockTypes = [] |
2 | 72 |
|
151 | 73 |
def setname(self, name): |
74 |
self.contentHeader.setname(name) |
|
75 |
setattr(cls, "setname", setname) |
|
145 | 76 |
|
151 | 77 |
def getname(self): |
78 |
return self.contentHeader.getname() |
|
79 |
setattr(cls, "getname", getname) |
|
80 |
||
81 |
def getfileHeader(self): |
|
2 | 82 |
fileheader = {} |
151 | 83 |
fileheader["companyName"] = self.fileHeader.getcompanyName() |
84 |
if self.fileHeader.getcompanyURL(): |
|
85 |
fileheader["companyURL"] = self.fileHeader.getcompanyURL() |
|
86 |
fileheader["productName"] = self.fileHeader.getproductName() |
|
87 |
fileheader["productVersion"] = self.fileHeader.getproductVersion() |
|
88 |
if self.fileHeader.getproductRelease(): |
|
89 |
fileheader["productRelease"] = self.fileHeader.getproductRelease() |
|
90 |
fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime() |
|
91 |
if self.fileHeader.getcontentDescription(): |
|
92 |
fileheader["contentDescription"] = self.fileHeader.getcontentDescription() |
|
2 | 93 |
return fileheader |
151 | 94 |
setattr(cls, "getfileHeader", getfileHeader) |
95 |
||
96 |
def setfileHeader(self, fileheader): |
|
97 |
self.fileHeader.setcompanyName(fileheader["companyName"]) |
|
2 | 98 |
if "companyURL" in fileheader: |
151 | 99 |
self.fileHeader.setcompanyURL(fileheader["companyURL"]) |
100 |
self.fileHeader.setproductName(fileheader["productName"]) |
|
101 |
self.fileHeader.setproductVersion(fileheader["productVersion"]) |
|
2 | 102 |
if "productRelease" in fileheader: |
151 | 103 |
self.fileHeader.setproductRelease(fileheader["productRelease"]) |
104 |
self.fileHeader.setcreationDateTime(fileheader["creationDateTime"]) |
|
2 | 105 |
if "contentDescription" in fileheader: |
151 | 106 |
self.fileHeader.setcontentDescription(fileheader["contentDescription"]) |
107 |
setattr(cls, "setfileHeader", setfileHeader) |
|
108 |
||
109 |
def getcontentHeader(self): |
|
145 | 110 |
contentheader = {} |
151 | 111 |
contentheader["projectName"] = self.contentHeader.getname() |
112 |
if self.contentHeader.getversion(): |
|
113 |
contentheader["projectVersion"] = self.contentHeader.getversion() |
|
114 |
if self.contentHeader.getmodificationDateTime(): |
|
115 |
contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime() |
|
116 |
if self.contentHeader.getorganization(): |
|
117 |
contentheader["organization"] = self.contentHeader.getorganization() |
|
118 |
if self.contentHeader.getauthor(): |
|
119 |
contentheader["authorName"] = self.contentHeader.getauthor() |
|
120 |
if self.contentHeader.getlanguage(): |
|
121 |
contentheader["language"] = self.contentHeader.getlanguage() |
|
122 |
contentheader["pageSize"] = self.contentHeader.getpageSize() |
|
123 |
contentheader["scaling"] = self.contentHeader.getscaling() |
|
145 | 124 |
return contentheader |
151 | 125 |
setattr(cls, "getcontentHeader", getcontentHeader) |
126 |
||
127 |
def setcontentHeader(self, contentheader): |
|
128 |
self.contentHeader.setname(contentheader["projectName"]) |
|
145 | 129 |
if "projectVersion" in contentheader: |
151 | 130 |
self.contentHeader.setversion(contentheader["projectVersion"]) |
145 | 131 |
if "modificationDateTime" in contentheader: |
151 | 132 |
self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
145 | 133 |
if "organization" in contentheader: |
151 | 134 |
self.contentHeader.setorganization(contentheader["organization"]) |
145 | 135 |
if "authorName" in contentheader: |
151 | 136 |
self.contentHeader.setauthor(contentheader["authorName"]) |
145 | 137 |
if "language" in contentheader: |
151 | 138 |
self.contentHeader.setlanguage(contentheader["language"]) |
139 |
self.contentHeader.setpageSize(*contentheader["pageSize"]) |
|
140 |
self.contentHeader.setscaling(contentheader["scaling"]) |
|
141 |
setattr(cls, "setcontentHeader", setcontentHeader) |
|
142 |
||
143 |
def getdataTypes(self): |
|
144 |
return self.types.getdataTypeElements() |
|
145 |
setattr(cls, "getdataTypes", getdataTypes) |
|
146 |
||
147 |
def getdataType(self, name): |
|
148 |
return self.types.getdataTypeElement(name) |
|
149 |
setattr(cls, "getdataType", getdataType) |
|
150 |
||
151 |
def appenddataType(self, name): |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
152 |
if name in self.CustomTypeHierarchy: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
153 |
raise ValueError, "\"%s\" Data Type already exists !!!"%name |
151 | 154 |
self.types.appenddataTypeElement(name) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
155 |
self.AddCustomDataType(self.getdataType(name)) |
151 | 156 |
setattr(cls, "appenddataType", appenddataType) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
157 |
|
151 | 158 |
def insertdataType(self, index, datatype): |
159 |
self.types.insertdataTypeElement(index, datatype) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
160 |
self.AddCustomDataType(datatype) |
151 | 161 |
setattr(cls, "insertdataType", insertdataType) |
162 |
||
163 |
def removedataType(self, name): |
|
164 |
self.types.removedataTypeElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
165 |
self.RefreshDataTypeHierarchy() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
166 |
self.RefreshElementUsingTree() |
151 | 167 |
setattr(cls, "removedataType", removedataType) |
168 |
||
169 |
def getpous(self): |
|
170 |
return self.types.getpouElements() |
|
171 |
setattr(cls, "getpous", getpous) |
|
172 |
||
173 |
def getpou(self, name): |
|
174 |
return self.types.getpouElement(name) |
|
175 |
setattr(cls, "getpou", getpou) |
|
176 |
||
177 |
def appendpou(self, name, pou_type, body_type): |
|
178 |
self.types.appendpouElement(name, pou_type, body_type) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
179 |
self.AddCustomBlockType(self.getpou(name)) |
151 | 180 |
setattr(cls, "appendpou", appendpou) |
0 | 181 |
|
151 | 182 |
def insertpou(self, index, pou): |
183 |
self.types.insertpouElement(index, pou) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
184 |
self.AddCustomBlockType(pou) |
151 | 185 |
setattr(cls, "insertpou", insertpou) |
186 |
||
187 |
def removepou(self, name): |
|
188 |
self.types.removepouElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
189 |
self.RefreshCustomBlockTypes() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
190 |
self.RefreshElementUsingTree() |
151 | 191 |
setattr(cls, "removepou", removepou) |
192 |
||
193 |
def getconfigurations(self): |
|
194 |
configurations = self.instances.configurations.getconfiguration() |
|
2 | 195 |
if configurations: |
196 |
return configurations |
|
197 |
return [] |
|
151 | 198 |
setattr(cls, "getconfigurations", getconfigurations) |
199 |
||
200 |
def getconfiguration(self, name): |
|
201 |
for configuration in self.instances.configurations.getconfiguration(): |
|
202 |
if configuration.getname() == name: |
|
2 | 203 |
return configuration |
204 |
return None |
|
151 | 205 |
setattr(cls, "getconfiguration", getconfiguration) |
206 |
||
207 |
def addconfiguration(self, name): |
|
208 |
for configuration in self.instances.configurations.getconfiguration(): |
|
209 |
if configuration.getname() == name: |
|
2 | 210 |
raise ValueError, "\"%s\" configuration already exists !!!"%name |
211 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
|
151 | 212 |
new_configuration.setname(name) |
213 |
self.instances.configurations.appendconfiguration(new_configuration) |
|
214 |
setattr(cls, "addconfiguration", addconfiguration) |
|
215 |
||
216 |
def removeconfiguration(self, name): |
|
2 | 217 |
found = False |
151 | 218 |
for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
219 |
if configuration.getname() == name: |
|
220 |
self.instances.configurations.removeconfiguration(idx) |
|
2 | 221 |
found = True |
222 |
break |
|
223 |
if not found: |
|
224 |
raise ValueError, "\"%s\" configuration doesn't exist !!!"%name |
|
151 | 225 |
setattr(cls, "removeconfiguration", removeconfiguration) |
226 |
||
227 |
def getconfigurationResource(self, config_name, name): |
|
228 |
configuration = self.getconfiguration(config_name) |
|
2 | 229 |
if configuration: |
151 | 230 |
for resource in configuration.getresource(): |
231 |
if resource.getname() == name: |
|
2 | 232 |
return resource |
233 |
return None |
|
151 | 234 |
setattr(cls, "getconfigurationResource", getconfigurationResource) |
235 |
||
236 |
def addconfigurationResource(self, config_name, name): |
|
237 |
configuration = self.getconfiguration(config_name) |
|
2 | 238 |
if configuration: |
151 | 239 |
for resource in configuration.getresource(): |
240 |
if resource.getname() == name: |
|
2 | 241 |
raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) |
242 |
new_resource = PLCOpenClasses["configuration_resource"]() |
|
151 | 243 |
new_resource.setname(name) |
244 |
configuration.appendresource(new_resource) |
|
245 |
setattr(cls, "addconfigurationResource", addconfigurationResource) |
|
246 |
||
247 |
def removeconfigurationResource(self, config_name, name): |
|
248 |
configuration = self.getconfiguration(config_name) |
|
2 | 249 |
if configuration: |
0 | 250 |
found = False |
151 | 251 |
for idx, resource in enumerate(configuration.getresource()): |
252 |
if resource.getname() == name: |
|
253 |
configuration.removeresource(idx) |
|
0 | 254 |
found = True |
255 |
break |
|
256 |
if not found: |
|
2 | 257 |
raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name) |
151 | 258 |
setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
259 |
||
260 |
def updateElementName(self, old_name, new_name): |
|
261 |
for pou in self.types.getpouElements(): |
|
58 | 262 |
pou.updateElementName(old_name, new_name) |
151 | 263 |
for configuration in self.instances.configurations.getconfiguration(): |
58 | 264 |
configuration.updateElementName(old_name, new_name) |
265 |
setattr(cls, "updateElementName", updateElementName) |
|
266 |
||
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
267 |
def RefreshDataTypeHierarchy(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
268 |
self.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
269 |
self.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
270 |
self.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
271 |
for datatype in self.getdataTypes(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
272 |
self.AddCustomDataType(datatype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
273 |
setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
274 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
275 |
def AddCustomDataType(self, datatype): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
276 |
name = datatype.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
277 |
basetype_content = datatype.getbaseType().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
278 |
if basetype_content["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
279 |
self.CustomTypeHierarchy[name] = basetype_content["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
280 |
elif basetype_content["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
281 |
self.CustomTypeHierarchy[name] = basetype_content["name"].upper() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
282 |
elif basetype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
283 |
self.CustomTypeHierarchy[name] = basetype_content["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
284 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
285 |
range = (basetype_content["value"].range.getlower(), |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
286 |
basetype_content["value"].range.getupper()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
287 |
self.CustomDataTypeRange[name] = range |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
288 |
base_type = basetype_content["value"].baseType.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
289 |
if base_type["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
290 |
self.CustomTypeHierarchy[name] = base_type["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
291 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
292 |
self.CustomTypeHierarchy[name] = base_type["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
293 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
294 |
if basetype_content["name"] == "enum": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
295 |
values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
296 |
for value in basetype_content["value"].values.getvalue(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
297 |
values.append(value.getname()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
298 |
self.EnumeratedDataTypeValues[name] = values |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
299 |
self.CustomTypeHierarchy[name] = "ANY_DERIVED" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
300 |
setattr(cls, "AddCustomDataType", AddCustomDataType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
301 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
302 |
# Update Block types with user-defined pou added |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
303 |
def RefreshCustomBlockTypes(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
304 |
# Reset the tree of user-defined pou cross-use |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
305 |
self.CustomBlockTypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
306 |
for pou in self.getpous(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
307 |
self.AddCustomBlockType(pou) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
308 |
setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
309 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
310 |
def AddCustomBlockType(self, pou): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
311 |
pou_name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
312 |
pou_type = pou.getpouType() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
313 |
if pou_type != "program": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
314 |
block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
315 |
"inputs" : [], "outputs" : [], "comment" : "", |
238
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
316 |
"generate" : generate_block, "initialise" : initialise_block} |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
317 |
if pou.getinterface(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
318 |
for type, varlist in pou.getvars(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
319 |
if type == "InOut": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
320 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
321 |
var_type = var.type.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
322 |
if var_type["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
323 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
324 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
325 |
elif var_type["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
326 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
327 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
328 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
329 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
330 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
331 |
elif type == "Input": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
332 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
333 |
var_type = var.type.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
334 |
if var_type["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
335 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
336 |
elif var_type["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
337 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
338 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
339 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
340 |
elif type == "Output": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
341 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
342 |
var_type = var.type.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
343 |
if var_type["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
344 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
345 |
elif var_type["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
346 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
347 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
348 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
349 |
return_type = pou.interface.getreturnType() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
350 |
if return_type: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
351 |
var_type = return_type.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
352 |
if var_type["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
353 |
block_infos["outputs"].append(("", var_type["value"].getname(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
354 |
elif var_type["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
355 |
block_infos["outputs"].append(("", var_type["name"].upper(), "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
356 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
357 |
block_infos["outputs"].append(("", var_type["name"], "none")) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
358 |
if pou.getbodyType() in ["FBD","LD","SFC"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
359 |
for instance in pou.getinstances(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
360 |
if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
361 |
block_infos["comment"] = instance.getcontentText() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
362 |
self.CustomBlockTypes.append(block_infos) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
363 |
setattr(cls, "AddCustomBlockType", AddCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
364 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
365 |
def RefreshElementUsingTree(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
366 |
# Reset the tree of user-defined element cross-use |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
367 |
self.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
368 |
pous = self.getpous() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
369 |
# Reference all the user-defined elementu names and initialize the tree of |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
370 |
# user-defined elemnt cross-use |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
371 |
pounames = [pou.getname() for pou in pous] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
372 |
for name in pounames: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
373 |
self.ElementUsingTree[name] = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
374 |
# Analyze each pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
375 |
for pou in pous: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
376 |
name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
377 |
if pou.interface: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
378 |
# Extract variables from every varLists |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
379 |
for type, varlist in pou.getvars(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
380 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
381 |
vartype_content = var.gettype().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
382 |
if vartype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
383 |
typename = vartype_content["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
384 |
if typename in pounames and name not in self.ElementUsingTree[typename]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
385 |
self.ElementUsingTree[typename].append(name) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
386 |
setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
387 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
388 |
def GetParentType(self, type): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
389 |
if type in self.CustomTypeHierarchy: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
390 |
return self.CustomTypeHierarchy[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
391 |
elif type in TypeHierarchy: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
392 |
return TypeHierarchy[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
393 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
394 |
setattr(cls, "GetParentType", GetParentType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
395 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
396 |
def GetBaseType(self, type): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
397 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
398 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
399 |
if parent_type.startswith("ANY"): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
400 |
return type |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
401 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
402 |
return self.GetBaseType(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
403 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
404 |
setattr(cls, "GetBaseType", GetBaseType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
405 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
406 |
def GetSubrangeBaseTypes(self, exclude): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
407 |
derived = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
408 |
for type in self.CustomTypeHierarchy.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
409 |
for base_type in DataTypeRange.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
410 |
if self.IsOfType(type, base_type) and not self.IsOfType(type, exclude): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
411 |
derived.append(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
412 |
break |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
413 |
return DataTypeRange.keys() + derived |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
414 |
setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
415 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
416 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
417 |
returns true if the given data type is the same that "reference" meta-type or one of its types. |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
418 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
419 |
def IsOfType(self, type, reference): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
420 |
if reference is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
421 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
422 |
elif type == reference: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
423 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
424 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
425 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
426 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
427 |
return self.IsOfType(parent_type, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
428 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
429 |
setattr(cls, "IsOfType", IsOfType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
430 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
431 |
# Return if pou given by name is used by another pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
432 |
def ElementIsUsed(self, name): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
433 |
if name in self.ElementUsingTree: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
434 |
return len(self.ElementUsingTree[name]) > 0 |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
435 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
436 |
setattr(cls, "ElementIsUsed", ElementIsUsed) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
437 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
438 |
def DataTypeIsDerived(self, name): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
439 |
return name in self.CustomTypeHierarchy.values() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
440 |
setattr(cls, "DataTypeIsDerived", DataTypeIsDerived) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
441 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
442 |
# Return if pou given by name is directly or undirectly used by the reference pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
443 |
def ElementIsUsedBy(self, name, reference): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
444 |
if name in self.ElementUsingTree: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
445 |
list = self.ElementUsingTree[name] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
446 |
# Test if pou is directly used by reference |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
447 |
if reference in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
448 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
449 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
450 |
# Test if pou is undirectly used by reference, by testing if pous |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
451 |
# that directly use pou is directly or undirectly used by reference |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
452 |
used = False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
453 |
for element in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
454 |
used |= self.ElementIsUsedBy(element, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
455 |
return used |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
456 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
457 |
setattr(cls, "ElementIsUsedBy", ElementIsUsedBy) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
458 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
459 |
def GetDataTypeRange(self, type): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
460 |
if type in self.CustomDataTypeRange: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
461 |
return self.CustomDataTypeRange[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
462 |
elif type in DataTypeRange: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
463 |
return DataTypeRange[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
464 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
465 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
466 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
467 |
return self.GetDataTypeRange(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
468 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
469 |
setattr(cls, "GetDataTypeRange", GetDataTypeRange) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
470 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
471 |
def GetEnumeratedDataTypeValues(self, type = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
472 |
if type is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
473 |
all_values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
474 |
for values in self.EnumeratedDataTypeValues.values(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
475 |
all_values.extend(values) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
476 |
return all_values |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
477 |
elif type in self.EnumeratedDataTypeValues: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
478 |
return self.EnumeratedDataTypeValues(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
479 |
return [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
480 |
setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
481 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
482 |
# Function that returns the block definition associated to the block type given |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
483 |
def GetCustomBlockType(self, type, inputs = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
484 |
for customblocktype in self.CustomBlockTypes: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
485 |
if inputs: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
486 |
customblock_inputs = tuple([var_type for name, var_type, modifier in customblocktype["inputs"]]) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
487 |
same_inputs = inputs == customblock_inputs |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
488 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
489 |
same_inputs = True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
490 |
if customblocktype["name"] == type and same_inputs: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
491 |
return customblocktype |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
492 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
493 |
setattr(cls, "GetCustomBlockType", GetCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
494 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
495 |
# Return Block types checking for recursion |
251
cc5377a296ea
Fix bug in popup menu and function block types in Variable Panel
lbessard
parents:
246
diff
changeset
|
496 |
def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False): |
238
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
497 |
type = None |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
498 |
if exclude != "": |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
499 |
pou = self.getpou(exclude) |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
500 |
if pou is not None: |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
501 |
type = pou.getpouType() |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
502 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
503 |
for customblocktype in self.CustomBlockTypes: |
251
cc5377a296ea
Fix bug in popup menu and function block types in Variable Panel
lbessard
parents:
246
diff
changeset
|
504 |
if customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
505 |
customblocktypes.append(customblocktype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
506 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
507 |
setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
508 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
509 |
# Return Function Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
510 |
def GetCustomFunctionBlockTypes(self, exclude = ""): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
511 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
512 |
for customblocktype in self.CustomBlockTypes: |
251
cc5377a296ea
Fix bug in popup menu and function block types in Variable Panel
lbessard
parents:
246
diff
changeset
|
513 |
if customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]): |
246
9cf9694e8d66
Bug with GetCustomFunctionBlockTypes without exclusion POU fixed
lbessard
parents:
238
diff
changeset
|
514 |
customblocktypes.append(customblocktype["name"]) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
515 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
516 |
setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
517 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
518 |
# Return Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
519 |
def GetCustomBlockResource(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
520 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
521 |
for customblocktype in self.CustomBlockTypes: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
522 |
if customblocktype["type"] == "program": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
523 |
customblocktypes.append(customblocktype["name"]) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
524 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
525 |
setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
526 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
527 |
# Return Data Types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
528 |
def GetCustomDataTypes(self, exclude = ""): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
529 |
customdatatypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
530 |
for customdatatype in self.getdataTypes(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
531 |
customdatatype_name = customdatatype.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
532 |
if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
533 |
customdatatypes.append(customdatatype_name) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
534 |
return customdatatypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
535 |
setattr(cls, "GetCustomDataTypes", GetCustomDataTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
536 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
537 |
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
|
538 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
539 |
cls.singleLineAttributes = False |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
540 |
|
145 | 541 |
cls = PLCOpenClasses.get("project_contentHeader", None) |
542 |
if cls: |
|
543 |
cls.singleLineAttributes = False |
|
544 |
||
151 | 545 |
def setpageSize(self, width, height): |
546 |
self.coordinateInfo.setpageSize(width, height) |
|
547 |
setattr(cls, "setpageSize", setpageSize) |
|
548 |
||
549 |
def getpageSize(self): |
|
550 |
return self.coordinateInfo.getpageSize() |
|
551 |
setattr(cls, "getpageSize", getpageSize) |
|
552 |
||
553 |
def setscaling(self, scaling): |
|
145 | 554 |
for language, (x, y) in scaling.items(): |
151 | 555 |
self.coordinateInfo.setscaling(language, x, y) |
556 |
setattr(cls, "setscaling", setscaling) |
|
557 |
||
558 |
def getscaling(self): |
|
145 | 559 |
scaling = {} |
151 | 560 |
scaling["FBD"] = self.coordinateInfo.getscaling("FBD") |
561 |
scaling["LD"] = self.coordinateInfo.getscaling("LD") |
|
562 |
scaling["SFC"] = self.coordinateInfo.getscaling("SFC") |
|
145 | 563 |
return scaling |
151 | 564 |
setattr(cls, "getscaling", getscaling) |
145 | 565 |
|
566 |
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None) |
|
567 |
if cls: |
|
151 | 568 |
def setpageSize(self, width, height): |
145 | 569 |
if width == 0 and height == 0: |
151 | 570 |
self.deletepageSize() |
145 | 571 |
else: |
572 |
if self.pageSize is None: |
|
151 | 573 |
self.addpageSize() |
574 |
self.pageSize.setx(width) |
|
575 |
self.pageSize.sety(height) |
|
576 |
setattr(cls, "setpageSize", setpageSize) |
|
577 |
||
578 |
def getpageSize(self): |
|
145 | 579 |
if self.pageSize is not None: |
151 | 580 |
return self.pageSize.getx(), self.pageSize.gety() |
145 | 581 |
return 0, 0 |
151 | 582 |
setattr(cls, "getpageSize", getpageSize) |
583 |
||
584 |
def setscaling(self, language, x, y): |
|
145 | 585 |
if language == "FBD": |
151 | 586 |
self.fbd.scaling.setx(x) |
587 |
self.fbd.scaling.sety(y) |
|
145 | 588 |
elif language == "LD": |
151 | 589 |
self.ld.scaling.setx(x) |
590 |
self.ld.scaling.sety(y) |
|
145 | 591 |
elif language == "SFC": |
151 | 592 |
self.sfc.scaling.setx(x) |
593 |
self.sfc.scaling.sety(y) |
|
594 |
setattr(cls, "setscaling", setscaling) |
|
595 |
||
596 |
def getscaling(self, language): |
|
145 | 597 |
if language == "FBD": |
151 | 598 |
return self.fbd.scaling.getx(), self.fbd.scaling.gety() |
145 | 599 |
elif language == "LD": |
151 | 600 |
return self.ld.scaling.getx(), self.ld.scaling.gety() |
145 | 601 |
elif language == "SFC": |
151 | 602 |
return self.sfc.scaling.getx(), self.sfc.scaling.gety() |
145 | 603 |
return 0, 0 |
151 | 604 |
setattr(cls, "getscaling", getscaling) |
145 | 605 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
606 |
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
|
607 |
if cls: |
58 | 608 |
def updateElementName(self, old_name, new_name): |
151 | 609 |
for resource in self.getresource(): |
58 | 610 |
resource.updateElementName(old_name, new_name) |
611 |
setattr(cls, "updateElementName", updateElementName) |
|
612 |
||
613 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
614 |
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
|
615 |
if cls: |
58 | 616 |
def updateElementName(self, old_name, new_name): |
187 | 617 |
for instance in self.getpouInstance(): |
58 | 618 |
instance.updateElementName(old_name, new_name) |
187 | 619 |
for task in self.gettask(): |
58 | 620 |
task.updateElementName(old_name, new_name) |
621 |
setattr(cls, "updateElementName", updateElementName) |
|
622 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
623 |
cls = PLCOpenClasses.get("resource_task", None) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
624 |
if cls: |
58 | 625 |
def updateElementName(self, old_name, new_name): |
626 |
if self.single == old_name: |
|
627 |
self.single = new_name |
|
187 | 628 |
for instance in self.getpouInstance(): |
58 | 629 |
instance.updateElementName(old_name, new_name) |
630 |
setattr(cls, "updateElementName", updateElementName) |
|
631 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
632 |
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
|
633 |
if cls: |
58 | 634 |
def updateElementName(self, old_name, new_name): |
635 |
if self.type == old_name: |
|
636 |
self.type = new_name |
|
637 |
setattr(cls, "updateElementName", updateElementName) |
|
638 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
639 |
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
|
640 |
if cls: |
151 | 641 |
def getdataTypeElements(self): |
642 |
return self.dataTypes.getdataType() |
|
643 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
644 |
||
645 |
def getdataTypeElement(self, name): |
|
646 |
elements = self.dataTypes.getdataType() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
647 |
for element in elements: |
151 | 648 |
if element.getname() == name: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
649 |
return element |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
650 |
return None |
151 | 651 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
652 |
||
653 |
def appenddataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
654 |
new_datatype = PLCOpenClasses["dataTypes_dataType"]() |
151 | 655 |
new_datatype.setname(name) |
656 |
new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None}) |
|
657 |
self.dataTypes.appenddataType(new_datatype) |
|
658 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
659 |
|
151 | 660 |
def insertdataTypeElement(self, index, dataType): |
661 |
self.dataTypes.insertdataType(index, dataType) |
|
662 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
663 |
||
664 |
def removedataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
665 |
found = False |
151 | 666 |
for idx, element in enumerate(self.dataTypes.getdataType()): |
667 |
if element.getname() == name: |
|
668 |
self.dataTypes.removedataType(idx) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
669 |
found = True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
670 |
break |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
671 |
if not found: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
672 |
raise ValueError, "\"%s\" Data Type doesn't exist !!!"%name |
151 | 673 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
674 |
||
675 |
def getpouElements(self): |
|
676 |
return self.pous.getpou() |
|
677 |
setattr(cls, "getpouElements", getpouElements) |
|
678 |
||
679 |
def getpouElement(self, name): |
|
680 |
elements = self.pous.getpou() |
|
2 | 681 |
for element in elements: |
151 | 682 |
if element.getname() == name: |
2 | 683 |
return element |
684 |
return None |
|
151 | 685 |
setattr(cls, "getpouElement", getpouElement) |
686 |
||
687 |
def appendpouElement(self, name, pou_type, body_type): |
|
688 |
for element in self.pous.getpou(): |
|
689 |
if element.getname() == name: |
|
2 | 690 |
raise ValueError, "\"%s\" POU already exists !!!"%name |
691 |
new_pou = PLCOpenClasses["pous_pou"]() |
|
151 | 692 |
new_pou.setname(name) |
693 |
new_pou.setpouType(pou_type) |
|
694 |
new_pou.setbody(PLCOpenClasses["body"]()) |
|
695 |
new_pou.setbodyType(body_type) |
|
696 |
self.pous.appendpou(new_pou) |
|
697 |
setattr(cls, "appendpouElement", appendpouElement) |
|
2 | 698 |
|
151 | 699 |
def insertpouElement(self, index, pou): |
700 |
self.pous.insertpou(index, pou) |
|
701 |
setattr(cls, "insertpouElement", insertpouElement) |
|
702 |
||
703 |
def removepouElement(self, name): |
|
2 | 704 |
found = False |
151 | 705 |
for idx, element in enumerate(self.pous.getpou()): |
706 |
if element.getname() == name: |
|
707 |
self.pous.removepou(idx) |
|
2 | 708 |
found = True |
709 |
break |
|
710 |
if not found: |
|
711 |
raise ValueError, "\"%s\" POU doesn't exist !!!"%name |
|
151 | 712 |
setattr(cls, "removepouElement", removepouElement) |
713 |
||
714 |
def setbodyType(self, type): |
|
2 | 715 |
if type == "IL": |
151 | 716 |
self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
2 | 717 |
elif type == "ST": |
151 | 718 |
self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
2 | 719 |
elif type == "LD": |
151 | 720 |
self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
2 | 721 |
elif type == "FBD": |
151 | 722 |
self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
2 | 723 |
elif type == "SFC": |
151 | 724 |
self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
2 | 725 |
else: |
726 |
raise ValueError, "%s isn't a valid body type!"%type |
|
727 |
||
151 | 728 |
def getbodyType(self): |
729 |
return self.body.getcontent()["name"] |
|
730 |
||
731 |
def resetexecutionOrder(self): |
|
732 |
self.body.resetexecutionOrder() |
|
733 |
||
734 |
def compileexecutionOrder(self): |
|
735 |
self.body.compileexecutionOrder() |
|
736 |
||
737 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
738 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
739 |
||
740 |
def addinstance(self, name, instance): |
|
741 |
self.body.appendcontentInstance(name, instance) |
|
742 |
||
743 |
def getinstances(self): |
|
744 |
return self.body.getcontentInstances() |
|
745 |
||
746 |
def getinstance(self, id): |
|
747 |
return self.body.getcontentInstance(id) |
|
748 |
||
749 |
def getrandomInstance(self, exclude): |
|
750 |
return self.body.getcontentRandomInstance(exclude) |
|
751 |
||
752 |
def getinstanceByName(self, name): |
|
753 |
return self.body.getcontentInstanceByName(name) |
|
754 |
||
755 |
def removeinstance(self, id): |
|
756 |
self.body.removecontentInstance(id) |
|
757 |
||
758 |
def settext(self, text): |
|
759 |
self.body.settext(text) |
|
760 |
||
761 |
def gettext(self): |
|
762 |
return self.body.gettext() |
|
763 |
setattr(cls, "gettext", gettext) |
|
2 | 764 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
765 |
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
|
766 |
if cls: |
151 | 767 |
setattr(cls, "setbodyType", setbodyType) |
768 |
setattr(cls, "getbodyType", getbodyType) |
|
769 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
770 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
771 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
772 |
setattr(cls, "addinstance", addinstance) |
|
773 |
setattr(cls, "getinstances", getinstances) |
|
774 |
setattr(cls, "getinstance", getinstance) |
|
775 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
776 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
777 |
setattr(cls, "removeinstance", removeinstance) |
|
778 |
setattr(cls, "settext", settext) |
|
779 |
setattr(cls, "gettext", gettext) |
|
780 |
||
781 |
def getvars(self): |
|
2 | 782 |
vars = [] |
783 |
reverse_types = {} |
|
784 |
for name, value in VarTypes.items(): |
|
785 |
reverse_types[value] = name |
|
151 | 786 |
for varlist in self.interface.getcontent(): |
2 | 787 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
788 |
return vars |
|
151 | 789 |
setattr(cls, "getvars", getvars) |
790 |
||
791 |
def setvars(self, vars): |
|
792 |
self.interface.setcontent([]) |
|
2 | 793 |
for vartype, varlist in vars: |
151 | 794 |
self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
795 |
setattr(cls, "setvars", setvars) |
|
796 |
||
797 |
def addpouVar(self, type, name): |
|
798 |
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
|
799 |
if len(content) == 0 or content[-1]["name"] != "localVars": |
151 | 800 |
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
|
801 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
802 |
varlist = content[-1]["value"] |
151 | 803 |
variables = varlist.getvariable() |
804 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
805 |
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
|
806 |
var = PLCOpenClasses["varListPlain_variable"]() |
151 | 807 |
var.setname(name) |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
808 |
var_type = PLCOpenClasses["dataType"]() |
151 | 809 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
810 |
derived_type.setname(type) |
|
811 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
|
812 |
var.settype(var_type) |
|
813 |
content[-1]["value"].appendvariable(var) |
|
814 |
setattr(cls, "addpouVar", addpouVar) |
|
815 |
||
816 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
|
817 |
content = self.interface.getcontent() |
|
94 | 818 |
for varlist in content: |
151 | 819 |
variables = varlist["value"].getvariable() |
94 | 820 |
for var in variables: |
151 | 821 |
if var.getname() == old_name: |
822 |
vartype_content = var.gettype().getcontent() |
|
823 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
|
824 |
var.setname(new_name) |
|
825 |
vartype_content["value"].setname(new_type) |
|
94 | 826 |
return |
151 | 827 |
setattr(cls, "changepouVar", changepouVar) |
828 |
||
829 |
def removepouVar(self, type, name): |
|
830 |
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
|
831 |
for varlist in content: |
151 | 832 |
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
|
833 |
for var in variables: |
151 | 834 |
if var.getname() == name: |
835 |
vartype_content = var.gettype().getcontent() |
|
836 |
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
|
837 |
variables.remove(var) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
838 |
break |
151 | 839 |
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
|
840 |
content.remove(varlist) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
841 |
break |
151 | 842 |
setattr(cls, "removepouVar", removepouVar) |
843 |
||
844 |
def hasblock(self, name): |
|
845 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
846 |
for instance in self.getinstances(): |
|
847 |
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
|
848 |
return True |
89 | 849 |
if self.transitions: |
151 | 850 |
for transition in self.transitions.gettransition(): |
851 |
result = transition.hasblock(name) |
|
89 | 852 |
if result: |
853 |
return result |
|
854 |
if self.actions: |
|
151 | 855 |
for action in self.actions.getaction(): |
856 |
result = action.hasblock(name) |
|
89 | 857 |
if result: |
858 |
return result |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
859 |
return False |
151 | 860 |
setattr(cls, "hasblock", hasblock) |
861 |
||
862 |
def addtransition(self, name, type): |
|
2 | 863 |
if not self.transitions: |
151 | 864 |
self.addtransitions() |
865 |
self.transitions.settransition([]) |
|
2 | 866 |
transition = PLCOpenClasses["transitions_transition"]() |
151 | 867 |
transition.setname(name) |
868 |
transition.setbodyType(type) |
|
200 | 869 |
if type == "ST": |
870 |
transition.settext(":= ;") |
|
871 |
elif type == "IL": |
|
872 |
transition.settext("\tST\t%s"%name) |
|
151 | 873 |
self.transitions.appendtransition(transition) |
874 |
setattr(cls, "addtransition", addtransition) |
|
875 |
||
876 |
def gettransition(self, name): |
|
2 | 877 |
if self.transitions: |
151 | 878 |
for transition in self.transitions.gettransition(): |
879 |
if transition.getname() == name: |
|
2 | 880 |
return transition |
881 |
return None |
|
151 | 882 |
setattr(cls, "gettransition", gettransition) |
2 | 883 |
|
151 | 884 |
def gettransitionList(self): |
2 | 885 |
if self.transitions: |
151 | 886 |
return self.transitions.gettransition() |
2 | 887 |
return [] |
151 | 888 |
setattr(cls, "gettransitionList", gettransitionList) |
889 |
||
890 |
def removetransition(self, name): |
|
2 | 891 |
if self.transitions: |
151 | 892 |
transitions = self.transitions.gettransition() |
2 | 893 |
i = 0 |
894 |
removed = False |
|
895 |
while i < len(transitions) and not removed: |
|
151 | 896 |
if transitions[i].getname() == name: |
46 | 897 |
transitions.pop(i) |
2 | 898 |
removed = True |
899 |
i += 1 |
|
900 |
if not removed: |
|
901 |
raise ValueError, "Transition with name %s doesn't exists!"%name |
|
151 | 902 |
setattr(cls, "removetransition", removetransition) |
903 |
||
904 |
def addaction(self, name, type): |
|
2 | 905 |
if not self.actions: |
151 | 906 |
self.addactions() |
907 |
self.actions.setaction([]) |
|
2 | 908 |
action = PLCOpenClasses["actions_action"]() |
151 | 909 |
action.setname(name) |
910 |
action.setbodyType(type) |
|
911 |
self.actions.appendaction(action) |
|
912 |
setattr(cls, "addaction", addaction) |
|
913 |
||
914 |
def getaction(self, name): |
|
2 | 915 |
if self.actions: |
151 | 916 |
for action in self.actions.getaction(): |
917 |
if action.getname() == name: |
|
2 | 918 |
return action |
919 |
return None |
|
151 | 920 |
setattr(cls, "getaction", getaction) |
921 |
||
922 |
def getactionList(self): |
|
2 | 923 |
if self.actions: |
151 | 924 |
return self.actions.getaction() |
2 | 925 |
return [] |
151 | 926 |
setattr(cls, "getactionList", getactionList) |
2 | 927 |
|
151 | 928 |
def removeaction(self, name): |
2 | 929 |
if self.actions: |
151 | 930 |
actions = self.actions.getaction() |
2 | 931 |
i = 0 |
932 |
removed = False |
|
933 |
while i < len(actions) and not removed: |
|
151 | 934 |
if actions[i].getname() == name: |
46 | 935 |
actions.pop(i) |
2 | 936 |
removed = True |
937 |
i += 1 |
|
938 |
if not removed: |
|
939 |
raise ValueError, "Action with name %s doesn't exists!"%name |
|
151 | 940 |
setattr(cls, "removeaction", removeaction) |
2 | 941 |
|
58 | 942 |
def updateElementName(self, old_name, new_name): |
943 |
self.body.updateElementName(old_name, new_name) |
|
151 | 944 |
for action in self.getactionList(): |
58 | 945 |
action.updateElementName(old_name, new_name) |
151 | 946 |
for transition in self.gettransitionList(): |
58 | 947 |
transition.updateElementName(old_name, new_name) |
948 |
setattr(cls, "updateElementName", updateElementName) |
|
949 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
950 |
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
|
951 |
if cls: |
151 | 952 |
setattr(cls, "setbodyType", setbodyType) |
953 |
setattr(cls, "getbodyType", getbodyType) |
|
954 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
955 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
956 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
957 |
setattr(cls, "addinstance", addinstance) |
|
958 |
setattr(cls, "getinstances", getinstances) |
|
959 |
setattr(cls, "getinstance", getinstance) |
|
960 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
961 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
962 |
setattr(cls, "removeinstance", removeinstance) |
|
963 |
setattr(cls, "settext", settext) |
|
964 |
setattr(cls, "gettext", gettext) |
|
2 | 965 |
|
58 | 966 |
def updateElementName(self, old_name, new_name): |
967 |
self.body.updateElementName(old_name, new_name) |
|
968 |
setattr(cls, "updateElementName", updateElementName) |
|
969 |
||
151 | 970 |
def hasblock(self, name): |
971 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
972 |
for instance in self.getinstances(): |
|
973 |
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
|
974 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
975 |
return False |
151 | 976 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
977 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
978 |
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
|
979 |
if cls: |
151 | 980 |
setattr(cls, "setbodyType", setbodyType) |
981 |
setattr(cls, "getbodyType", getbodyType) |
|
982 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
983 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
984 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
985 |
setattr(cls, "addinstance", addinstance) |
|
986 |
setattr(cls, "getinstances", getinstances) |
|
987 |
setattr(cls, "getinstance", getinstance) |
|
988 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
989 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
990 |
setattr(cls, "removeinstance", removeinstance) |
|
991 |
setattr(cls, "settext", settext) |
|
992 |
setattr(cls, "gettext", gettext) |
|
2 | 993 |
|
58 | 994 |
def updateElementName(self, old_name, new_name): |
995 |
self.body.updateElementName(old_name, new_name) |
|
996 |
setattr(cls, "updateElementName", updateElementName) |
|
997 |
||
151 | 998 |
def hasblock(self, name): |
999 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1000 |
for instance in self.getinstances(): |
|
1001 |
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
|
1002 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1003 |
return False |
151 | 1004 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1005 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1006 |
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
|
1007 |
if cls: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1008 |
cls.currentExecutionOrderId = 0 |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1009 |
|
151 | 1010 |
def resetcurrentExecutionOrderId(self): |
200 | 1011 |
object.__setattr__(self, "currentExecutionOrderId", 0) |
151 | 1012 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
1013 |
||
1014 |
def getnewExecutionOrderId(self): |
|
200 | 1015 |
object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1016 |
return self.currentExecutionOrderId |
151 | 1017 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1018 |
||
1019 |
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
|
1020 |
if self.content["name"] == "FBD": |
151 | 1021 |
for element in self.content["value"].getcontent(): |
1022 |
if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
|
1023 |
PLCOpenClasses.get("commonObjects_connector", None), |
|
1024 |
PLCOpenClasses.get("commonObjects_continuation", None))): |
|
1025 |
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
|
1026 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1027 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 1028 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1029 |
||
1030 |
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
|
1031 |
if self.content["name"] == "FBD": |
151 | 1032 |
self.resetexecutionOrder() |
1033 |
self.resetcurrentExecutionOrderId() |
|
1034 |
for element in self.content["value"].getcontent(): |
|
200 | 1035 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
151 | 1036 |
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
|
1037 |
if connections and len(connections) == 1: |
151 | 1038 |
self.compileelementExecutionOrder(connections[0]) |
1039 |
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
|
1040 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1041 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 1042 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1043 |
||
1044 |
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
|
1045 |
if self.content["name"] == "FBD": |
151 | 1046 |
localid = link.getrefLocalId() |
1047 |
instance = self.getcontentInstance(localid) |
|
1048 |
if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
|
1049 |
for variable in instance.inputVariables.getvariable(): |
|
1050 |
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
|
1051 |
if connections and len(connections) == 1: |
151 | 1052 |
self.compileelementExecutionOrder(connections[0]) |
1053 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
|
1054 |
elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
|
1055 |
name = instance.getname() |
|
1056 |
for tmp_instance in self.getcontentInstances(): |
|
1057 |
if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
|
1058 |
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
|
1059 |
if connections and len(connections) == 1: |
151 | 1060 |
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
|
1061 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1062 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 1063 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1064 |
||
1065 |
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
|
1066 |
if self.content["name"] == "FBD": |
151 | 1067 |
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
|
1068 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
151 | 1069 |
for element in self.content["value"].getcontent(): |
1070 |
if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
|
1071 |
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
|
1072 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
151 | 1073 |
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
|
1074 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
151 | 1075 |
element["value"].setexecutionOrderId(element_executionOrder + 1) |
1076 |
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
|
1077 |
else: |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1078 |
raise TypeError, "Can only generate execution order on FBD networks!" |
151 | 1079 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1080 |
||
1081 |
def appendcontentInstance(self, name, instance): |
|
2 | 1082 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1083 |
self.content["value"].appendcontent({"name" : name, "value" : instance}) |
2 | 1084 |
else: |
1085 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1086 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
1087 |
||
1088 |
def getcontentInstances(self): |
|
2 | 1089 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1090 |
instances = [] |
|
151 | 1091 |
for element in self.content["value"].getcontent(): |
2 | 1092 |
instances.append(element["value"]) |
1093 |
return instances |
|
1094 |
else: |
|
1095 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1096 |
setattr(cls, "getcontentInstances", getcontentInstances) |
1097 |
||
1098 |
def getcontentInstance(self, id): |
|
2 | 1099 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1100 |
for element in self.content["value"].getcontent(): |
1101 |
if element["value"].getlocalId() == id: |
|
2 | 1102 |
return element["value"] |
0 | 1103 |
return None |
2 | 1104 |
else: |
1105 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1106 |
setattr(cls, "getcontentInstance", getcontentInstance) |
1107 |
||
1108 |
def getcontentRandomInstance(self, exclude): |
|
2 | 1109 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1110 |
for element in self.content["value"].getcontent(): |
1111 |
if element["value"].getlocalId() not in exclude: |
|
2 | 1112 |
return element["value"] |
1113 |
return None |
|
1114 |
else: |
|
1115 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1116 |
setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1117 |
||
1118 |
def getcontentInstanceByName(self, name): |
|
2 | 1119 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1120 |
for element in self.content["value"].getcontent(): |
193 | 1121 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
2 | 1122 |
return element["value"] |
1123 |
else: |
|
1124 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1125 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1126 |
||
1127 |
def removecontentInstance(self, id): |
|
2 | 1128 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1129 |
i = 0 |
|
1130 |
removed = False |
|
151 | 1131 |
elements = self.content["value"].getcontent() |
2 | 1132 |
while i < len(elements) and not removed: |
151 | 1133 |
if elements[i]["value"].getlocalId() == id: |
1134 |
self.content["value"].removecontent(i) |
|
2 | 1135 |
removed = True |
1136 |
i += 1 |
|
1137 |
if not removed: |
|
1138 |
raise ValueError, "Instance with id %d doesn't exists!"%id |
|
1139 |
else: |
|
1140 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1141 |
setattr(cls, "removecontentInstance", removecontentInstance) |
1142 |
||
1143 |
def settext(self, text): |
|
2 | 1144 |
if self.content["name"] in ["IL","ST"]: |
151 | 1145 |
self.content["value"].settext(text) |
2 | 1146 |
else: |
1147 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
151 | 1148 |
setattr(cls, "settext", settext) |
1149 |
||
1150 |
def gettext(self): |
|
2 | 1151 |
if self.content["name"] in ["IL","ST"]: |
151 | 1152 |
return self.content["value"].gettext() |
2 | 1153 |
else: |
1154 |
raise TypeError, "%s body don't have text!"%self.content["name"] |
|
151 | 1155 |
setattr(cls, "gettext", gettext) |
58 | 1156 |
|
1157 |
def updateElementName(self, old_name, new_name): |
|
1158 |
if self.content["name"] in ["IL", "ST"]: |
|
1159 |
self.content["value"].updateElementName(old_name, new_name) |
|
1160 |
else: |
|
151 | 1161 |
for element in self.content["value"].getcontent(): |
58 | 1162 |
element["value"].updateElementName(old_name, new_name) |
1163 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1164 |
|
151 | 1165 |
def getx(self): |
1166 |
return self.position.getx() |
|
1167 |
||
1168 |
def gety(self): |
|
1169 |
return self.position.gety() |
|
1170 |
||
1171 |
def setx(self, x): |
|
1172 |
self.position.setx(x) |
|
1173 |
||
1174 |
def sety(self, y): |
|
1175 |
self.position.sety(y) |
|
1176 |
||
1177 |
cls = PLCOpenClasses.get("commonObjects_comment", None) |
|
1178 |
if cls: |
|
1179 |
setattr(cls, "getx", getx) |
|
1180 |
setattr(cls, "gety", gety) |
|
1181 |
setattr(cls, "setx", setx) |
|
1182 |
setattr(cls, "sety", sety) |
|
1183 |
||
1184 |
def setcontentText(self, text): |
|
1185 |
self.content.settext(text) |
|
1186 |
setattr(cls, "setcontentText", setcontentText) |
|
0 | 1187 |
|
151 | 1188 |
def getcontentText(self): |
1189 |
return self.content.gettext() |
|
1190 |
setattr(cls, "getcontentText", getcontentText) |
|
58 | 1191 |
|
1192 |
def updateElementName(self, old_name, new_name): |
|
1193 |
self.content.updateElementName(old_name, new_name) |
|
1194 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1195 |
|
151 | 1196 |
cls = PLCOpenClasses.get("fbdObjects_block", None) |
1197 |
if cls: |
|
1198 |
setattr(cls, "getx", getx) |
|
1199 |
setattr(cls, "gety", gety) |
|
1200 |
setattr(cls, "setx", setx) |
|
1201 |
setattr(cls, "sety", sety) |
|
2 | 1202 |
|
58 | 1203 |
def updateElementName(self, old_name, new_name): |
1204 |
if self.typeName == old_name: |
|
1205 |
self.typeName = new_name |
|
1206 |
setattr(cls, "updateElementName", updateElementName) |
|
1207 |
||
151 | 1208 |
cls = PLCOpenClasses.get("ldObjects_leftPowerRail", None) |
1209 |
if cls: |
|
1210 |
setattr(cls, "getx", getx) |
|
1211 |
setattr(cls, "gety", gety) |
|
1212 |
setattr(cls, "setx", setx) |
|
1213 |
setattr(cls, "sety", sety) |
|
2 | 1214 |
|
58 | 1215 |
def updateElementName(self, old_name, new_name): |
1216 |
pass |
|
1217 |
setattr(cls, "updateElementName", updateElementName) |
|
1218 |
||
151 | 1219 |
cls = PLCOpenClasses.get("ldObjects_rightPowerRail", None) |
1220 |
if cls: |
|
1221 |
setattr(cls, "getx", getx) |
|
1222 |
setattr(cls, "gety", gety) |
|
1223 |
setattr(cls, "setx", setx) |
|
1224 |
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
|
1225 |
|
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1226 |
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
|
1227 |
pass |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1228 |
setattr(cls, "updateElementName", updateElementName) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1229 |
|
151 | 1230 |
cls = PLCOpenClasses.get("ldObjects_contact", None) |
1231 |
if cls: |
|
1232 |
setattr(cls, "getx", getx) |
|
1233 |
setattr(cls, "gety", gety) |
|
1234 |
setattr(cls, "setx", setx) |
|
1235 |
setattr(cls, "sety", sety) |
|
2 | 1236 |
|
58 | 1237 |
def updateElementName(self, old_name, new_name): |
1238 |
if self.variable == old_name: |
|
1239 |
self.variable = new_name |
|
1240 |
setattr(cls, "updateElementName", updateElementName) |
|
1241 |
||
151 | 1242 |
cls = PLCOpenClasses.get("ldObjects_coil", None) |
1243 |
if cls: |
|
1244 |
setattr(cls, "getx", getx) |
|
1245 |
setattr(cls, "gety", gety) |
|
1246 |
setattr(cls, "setx", setx) |
|
1247 |
setattr(cls, "sety", sety) |
|
2 | 1248 |
|
58 | 1249 |
def updateElementName(self, old_name, new_name): |
1250 |
if self.variable == old_name: |
|
1251 |
self.variable = new_name |
|
1252 |
setattr(cls, "updateElementName", updateElementName) |
|
1253 |
||
151 | 1254 |
cls = PLCOpenClasses.get("sfcObjects_step", None) |
1255 |
if cls: |
|
1256 |
setattr(cls, "getx", getx) |
|
1257 |
setattr(cls, "gety", gety) |
|
1258 |
setattr(cls, "setx", setx) |
|
1259 |
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
|
1260 |
|
58 | 1261 |
def updateElementName(self, old_name, new_name): |
1262 |
pass |
|
1263 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1264 |
|
151 | 1265 |
cls = PLCOpenClasses.get("sfcObjects_transition", None) |
1266 |
if cls: |
|
1267 |
setattr(cls, "getx", getx) |
|
1268 |
setattr(cls, "gety", gety) |
|
1269 |
setattr(cls, "setx", setx) |
|
1270 |
setattr(cls, "sety", sety) |
|
1271 |
||
1272 |
def setconditionContent(self, type, value): |
|
2 | 1273 |
if not self.condition: |
151 | 1274 |
self.addcondition() |
2 | 1275 |
if type == "reference": |
1276 |
condition = PLCOpenClasses["condition_reference"]() |
|
151 | 1277 |
condition.setname(value) |
2 | 1278 |
elif type == "inline": |
1279 |
condition = PLCOpenClasses["condition_inline"]() |
|
151 | 1280 |
condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
1281 |
condition.settext(value) |
|
69 | 1282 |
elif type == "connection": |
166 | 1283 |
condition = [PLCOpenClasses["connection"]()] |
151 | 1284 |
self.condition.setcontent({"name" : type, "value" : condition}) |
1285 |
setattr(cls, "setconditionContent", setconditionContent) |
|
0 | 1286 |
|
151 | 1287 |
def getconditionContent(self): |
2 | 1288 |
if self.condition: |
151 | 1289 |
content = self.condition.getcontent() |
2 | 1290 |
values = {"type" : content["name"]} |
1291 |
if values["type"] == "reference": |
|
151 | 1292 |
values["value"] = content["value"].getname() |
2 | 1293 |
elif values["type"] == "inline": |
151 | 1294 |
values["value"] = content["value"].gettext() |
2 | 1295 |
return values |
1296 |
return "" |
|
151 | 1297 |
setattr(cls, "getconditionContent", getconditionContent) |
2 | 1298 |
|
58 | 1299 |
def updateElementName(self, old_name, new_name): |
1300 |
if self.condition: |
|
151 | 1301 |
content = self.condition.getcontent() |
58 | 1302 |
if content["name"] == "reference": |
151 | 1303 |
if content["value"].getname() == old_name: |
1304 |
content["value"].setname(new_name) |
|
58 | 1305 |
elif content["name"] == "inline": |
1306 |
content["value"].updateElementName(old_name, new_name) |
|
1307 |
setattr(cls, "updateElementName", updateElementName) |
|
1308 |
||
151 | 1309 |
def addconnection(self): |
69 | 1310 |
if self.condition: |
151 | 1311 |
content = self.condition.getcontent() |
69 | 1312 |
if content["name"] != "connection": |
166 | 1313 |
self.condition.setcontent({"name" : "connection", "value" : [PLCOpenClasses["connection"]()]}) |
151 | 1314 |
content = self.condition.getcontent() |
166 | 1315 |
else: |
1316 |
content["value"].append(PLCOpenClasses["connection"]()) |
|
151 | 1317 |
setattr(cls, "addconnection", addconnection) |
1318 |
||
1319 |
def removeconnection(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1320 |
if self.condition: |
151 | 1321 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1322 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1323 |
content["value"].pop(idx) |
151 | 1324 |
setattr(cls, "removeconnection", removeconnection) |
1325 |
||
1326 |
def removeconnections(self): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1327 |
if self.condition: |
151 | 1328 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1329 |
if content["name"] == "connection": |
166 | 1330 |
content["value"] = [PLCOpenClasses["connection"]()] |
151 | 1331 |
setattr(cls, "removeconnections", removeconnections) |
1332 |
||
1333 |
def getconnections(self): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1334 |
if self.condition: |
151 | 1335 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1336 |
if content["name"] == "connection": |
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1337 |
return content["value"] |
151 | 1338 |
setattr(cls, "getconnections", getconnections) |
1339 |
||
1340 |
def setconnectionId(self, idx, id): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1341 |
if self.condition: |
151 | 1342 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1343 |
if content["name"] == "connection": |
151 | 1344 |
content["value"][idx].setrefLocalId(id) |
1345 |
setattr(cls, "setconnectionId", setconnectionId) |
|
1346 |
||
1347 |
def getconnectionId(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1348 |
if self.condition: |
151 | 1349 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1350 |
if content["name"] == "connection": |
151 | 1351 |
return content["value"][idx].getrefLocalId() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1352 |
return None |
151 | 1353 |
setattr(cls, "getconnectionId", getconnectionId) |
1354 |
||
1355 |
def setconnectionPoints(self, idx, points): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1356 |
if self.condition: |
151 | 1357 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1358 |
if content["name"] == "connection": |
151 | 1359 |
content["value"][idx].setpoints(points) |
1360 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
1361 |
||
1362 |
def getconnectionPoints(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1363 |
if self.condition: |
151 | 1364 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1365 |
if content["name"] == "connection": |
151 | 1366 |
return content["value"][idx].getpoints() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1367 |
return None |
151 | 1368 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
1369 |
||
1370 |
def setconnectionParameter(self, idx, parameter): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1371 |
if self.condition: |
151 | 1372 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1373 |
if content["name"] == "connection": |
151 | 1374 |
content["value"][idx].setformalParameter(parameter) |
1375 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
1376 |
||
1377 |
def getconnectionParameter(self, idx): |
|
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1378 |
if self.condition: |
151 | 1379 |
content = self.condition.getcontent() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1380 |
if content["name"] == "connection": |
151 | 1381 |
return content["value"][idx].getformalParameter() |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1382 |
return None |
151 | 1383 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
1384 |
||
1385 |
cls = PLCOpenClasses.get("sfcObjects_selectionDivergence", None) |
|
1386 |
if cls: |
|
1387 |
setattr(cls, "getx", getx) |
|
1388 |
setattr(cls, "gety", gety) |
|
1389 |
setattr(cls, "setx", setx) |
|
1390 |
setattr(cls, "sety", sety) |
|
2 | 1391 |
|
58 | 1392 |
def updateElementName(self, old_name, new_name): |
1393 |
pass |
|
1394 |
setattr(cls, "updateElementName", updateElementName) |
|
1395 |
||
151 | 1396 |
cls = PLCOpenClasses.get("sfcObjects_selectionConvergence", None) |
1397 |
if cls: |
|
1398 |
setattr(cls, "getx", getx) |
|
1399 |
setattr(cls, "gety", gety) |
|
1400 |
setattr(cls, "setx", setx) |
|
1401 |
setattr(cls, "sety", sety) |
|
2 | 1402 |
|
58 | 1403 |
def updateElementName(self, old_name, new_name): |
1404 |
pass |
|
1405 |
setattr(cls, "updateElementName", updateElementName) |
|
1406 |
||
151 | 1407 |
cls = PLCOpenClasses.get("sfcObjects_simultaneousDivergence", None) |
1408 |
if cls: |
|
1409 |
setattr(cls, "getx", getx) |
|
1410 |
setattr(cls, "gety", gety) |
|
1411 |
setattr(cls, "setx", setx) |
|
1412 |
setattr(cls, "sety", sety) |
|
2 | 1413 |
|
58 | 1414 |
def updateElementName(self, old_name, new_name): |
1415 |
pass |
|
1416 |
setattr(cls, "updateElementName", updateElementName) |
|
1417 |
||
151 | 1418 |
cls = PLCOpenClasses.get("sfcObjects_simultaneousConvergence", None) |
1419 |
if cls: |
|
1420 |
setattr(cls, "getx", getx) |
|
1421 |
setattr(cls, "gety", gety) |
|
1422 |
setattr(cls, "setx", setx) |
|
1423 |
setattr(cls, "sety", sety) |
|
58 | 1424 |
|
1425 |
def updateElementName(self, old_name, new_name): |
|
1426 |
pass |
|
1427 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1428 |
|
151 | 1429 |
cls = PLCOpenClasses.get("sfcObjects_jumpStep", None) |
1430 |
if cls: |
|
1431 |
setattr(cls, "getx", getx) |
|
1432 |
setattr(cls, "gety", gety) |
|
1433 |
setattr(cls, "setx", setx) |
|
1434 |
setattr(cls, "sety", sety) |
|
58 | 1435 |
|
1436 |
def updateElementName(self, old_name, new_name): |
|
1437 |
pass |
|
1438 |
setattr(cls, "updateElementName", updateElementName) |
|
1439 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1440 |
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
|
1441 |
if cls: |
151 | 1442 |
def setreferenceName(self, name): |
1443 |
if self.reference: |
|
1444 |
self.reference.setname(name) |
|
1445 |
setattr(cls, "setreferenceName", setreferenceName) |
|
1446 |
||
1447 |
def getreferenceName(self): |
|
1448 |
if self.reference: |
|
1449 |
return self.reference.getname() |
|
2 | 1450 |
return None |
151 | 1451 |
setattr(cls, "getreferenceName", getreferenceName) |
1452 |
||
1453 |
def setinlineContent(self, content): |
|
1454 |
if self.inline: |
|
1455 |
self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1456 |
self.inline.settext(content) |
|
1457 |
setattr(cls, "setinlineContent", setinlineContent) |
|
1458 |
||
1459 |
def getinlineContent(self): |
|
1460 |
if self.inline: |
|
1461 |
return self.inline.gettext() |
|
2 | 1462 |
return None |
151 | 1463 |
setattr(cls, "getinlineContent", getinlineContent) |
1464 |
||
1465 |
def updateElementName(self, old_name, new_name): |
|
1466 |
if self.reference and self.reference.getname() == old_name: |
|
1467 |
self.reference.setname(new_name) |
|
58 | 1468 |
if self.inline: |
1469 |
self.inline.updateElementName(old_name, new_name) |
|
1470 |
setattr(cls, "updateElementName", updateElementName) |
|
1471 |
||
151 | 1472 |
cls = PLCOpenClasses.get("commonObjects_actionBlock", None) |
1473 |
if cls: |
|
1474 |
setattr(cls, "getx", getx) |
|
1475 |
setattr(cls, "gety", gety) |
|
1476 |
setattr(cls, "setx", setx) |
|
1477 |
setattr(cls, "sety", sety) |
|
1478 |
||
1479 |
def setactions(self, actions): |
|
2 | 1480 |
self.action = [] |
1481 |
for params in actions: |
|
1482 |
action = PLCOpenClasses["actionBlock_action"]() |
|
151 | 1483 |
action.setqualifier(params["qualifier"]) |
2 | 1484 |
if params["type"] == "reference": |
151 | 1485 |
action.addreference() |
1486 |
action.setreferenceName(params["value"]) |
|
0 | 1487 |
else: |
151 | 1488 |
action.addinline() |
1489 |
action.setinlineContent(params["value"]) |
|
2 | 1490 |
if "duration" in params: |
151 | 1491 |
action.setduration(params["duration"]) |
2 | 1492 |
if "indicator" in params: |
151 | 1493 |
action.setindicator(params["indicator"]) |
2 | 1494 |
self.action.append(action) |
151 | 1495 |
setattr(cls, "setactions", setactions) |
1496 |
||
1497 |
def getactions(self): |
|
2 | 1498 |
actions = [] |
1499 |
for action in self.action: |
|
1500 |
params = {} |
|
151 | 1501 |
params["qualifier"] = action.getqualifier() |
108 | 1502 |
if params["qualifier"] is None: |
1503 |
params["qualifier"] = "N" |
|
151 | 1504 |
if action.getreference(): |
2 | 1505 |
params["type"] = "reference" |
151 | 1506 |
params["value"] = action.getreferenceName() |
1507 |
elif action.getinline(): |
|
2 | 1508 |
params["type"] = "inline" |
151 | 1509 |
params["value"] = action.getinlineContent() |
1510 |
duration = action.getduration() |
|
2 | 1511 |
if duration: |
1512 |
params["duration"] = duration |
|
151 | 1513 |
indicator = action.getindicator() |
2 | 1514 |
if indicator: |
1515 |
params["indicator"] = indicator |
|
1516 |
actions.append(params) |
|
1517 |
return actions |
|
151 | 1518 |
setattr(cls, "getactions", getactions) |
2 | 1519 |
|
58 | 1520 |
def updateElementName(self, old_name, new_name): |
1521 |
for action in self.action: |
|
1522 |
action.updateElementName(old_name, new_name) |
|
1523 |
setattr(cls, "updateElementName", updateElementName) |
|
1524 |
||
151 | 1525 |
cls = PLCOpenClasses.get("fbdObjects_inVariable", None) |
1526 |
if cls: |
|
1527 |
setattr(cls, "getx", getx) |
|
1528 |
setattr(cls, "gety", gety) |
|
1529 |
setattr(cls, "setx", setx) |
|
1530 |
setattr(cls, "sety", sety) |
|
58 | 1531 |
|
1532 |
def updateElementName(self, old_name, new_name): |
|
1533 |
if self.expression == old_name: |
|
1534 |
self.expression = new_name |
|
1535 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1536 |
|
151 | 1537 |
cls = PLCOpenClasses.get("fbdObjects_outVariable", None) |
1538 |
if cls: |
|
1539 |
setattr(cls, "getx", getx) |
|
1540 |
setattr(cls, "gety", gety) |
|
1541 |
setattr(cls, "setx", setx) |
|
1542 |
setattr(cls, "sety", sety) |
|
2 | 1543 |
|
58 | 1544 |
def updateElementName(self, old_name, new_name): |
1545 |
if self.expression == old_name: |
|
1546 |
self.expression = new_name |
|
1547 |
setattr(cls, "updateElementName", updateElementName) |
|
1548 |
||
151 | 1549 |
cls = PLCOpenClasses.get("fbdObjects_inOutVariable", None) |
1550 |
if cls: |
|
1551 |
setattr(cls, "getx", getx) |
|
1552 |
setattr(cls, "gety", gety) |
|
1553 |
setattr(cls, "setx", setx) |
|
1554 |
setattr(cls, "sety", sety) |
|
2 | 1555 |
|
58 | 1556 |
def updateElementName(self, old_name, new_name): |
1557 |
if self.expression == old_name: |
|
1558 |
self.expression = new_name |
|
1559 |
setattr(cls, "updateElementName", updateElementName) |
|
1560 |
||
151 | 1561 |
cls = PLCOpenClasses.get("commonObjects_continuation", None) |
1562 |
if cls: |
|
1563 |
setattr(cls, "getx", getx) |
|
1564 |
setattr(cls, "gety", gety) |
|
1565 |
setattr(cls, "setx", setx) |
|
1566 |
setattr(cls, "sety", sety) |
|
58 | 1567 |
|
1568 |
def updateElementName(self, old_name, new_name): |
|
1569 |
pass |
|
1570 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1571 |
|
151 | 1572 |
cls = PLCOpenClasses.get("commonObjects_connector", None) |
1573 |
if cls: |
|
1574 |
setattr(cls, "getx", getx) |
|
1575 |
setattr(cls, "gety", gety) |
|
1576 |
setattr(cls, "setx", setx) |
|
1577 |
setattr(cls, "sety", sety) |
|
58 | 1578 |
|
1579 |
def updateElementName(self, old_name, new_name): |
|
1580 |
pass |
|
1581 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1582 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1583 |
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
|
1584 |
if cls: |
151 | 1585 |
def setpoints(self, points): |
2 | 1586 |
self.position = [] |
1587 |
for point in points: |
|
1588 |
position = PLCOpenClasses["position"]() |
|
151 | 1589 |
position.setx(point.x) |
1590 |
position.sety(point.y) |
|
2 | 1591 |
self.position.append(position) |
151 | 1592 |
setattr(cls, "setpoints", setpoints) |
1593 |
||
1594 |
def getpoints(self): |
|
2 | 1595 |
points = [] |
1596 |
for position in self.position: |
|
151 | 1597 |
points.append((position.getx(),position.gety())) |
2 | 1598 |
return points |
151 | 1599 |
setattr(cls, "getpoints", getpoints) |
2 | 1600 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1601 |
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
|
1602 |
if cls: |
151 | 1603 |
def setrelPositionXY(self, x, y): |
2 | 1604 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 1605 |
self.relPosition.setx(x) |
1606 |
self.relPosition.sety(y) |
|
1607 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
1608 |
||
1609 |
def getrelPositionXY(self): |
|
2 | 1610 |
if self.relPosition: |
151 | 1611 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 1612 |
else: |
0 | 1613 |
return self.relPosition |
151 | 1614 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
1615 |
||
1616 |
def addconnection(self): |
|
2 | 1617 |
if not self.content: |
151 | 1618 |
self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
2 | 1619 |
else: |
1620 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
151 | 1621 |
setattr(cls, "addconnection", addconnection) |
1622 |
||
1623 |
def removeconnection(self, idx): |
|
2 | 1624 |
if self.content: |
1625 |
self.content["value"].pop(idx) |
|
1626 |
if len(self.content["value"]) == 0: |
|
1627 |
self.content = None |
|
151 | 1628 |
setattr(cls, "removeconnection", removeconnection) |
1629 |
||
1630 |
def removeconnections(self): |
|
2 | 1631 |
if self.content: |
1632 |
self.content = None |
|
151 | 1633 |
setattr(cls, "removeconnections", removeconnections) |
1634 |
||
1635 |
def getconnections(self): |
|
2 | 1636 |
if self.content: |
1637 |
return self.content["value"] |
|
151 | 1638 |
setattr(cls, "getconnections", getconnections) |
1639 |
||
1640 |
def setconnectionId(self, idx, id): |
|
2 | 1641 |
if self.content: |
151 | 1642 |
self.content["value"][idx].setrefLocalId(id) |
1643 |
setattr(cls, "setconnectionId", setconnectionId) |
|
1644 |
||
1645 |
def getconnectionId(self, idx): |
|
2 | 1646 |
if self.content: |
151 | 1647 |
return self.content["value"][idx].getrefLocalId() |
2 | 1648 |
return None |
151 | 1649 |
setattr(cls, "getconnectionId", getconnectionId) |
1650 |
||
1651 |
def setconnectionPoints(self, idx, points): |
|
2 | 1652 |
if self.content: |
151 | 1653 |
self.content["value"][idx].setpoints(points) |
1654 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
1655 |
||
1656 |
def getconnectionPoints(self, idx): |
|
2 | 1657 |
if self.content: |
151 | 1658 |
return self.content["value"][idx].getpoints() |
2 | 1659 |
return None |
151 | 1660 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
1661 |
||
1662 |
def setconnectionParameter(self, idx, parameter): |
|
27 | 1663 |
if self.content: |
151 | 1664 |
self.content["value"][idx].setformalParameter(parameter) |
1665 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
1666 |
||
1667 |
def getconnectionParameter(self, idx): |
|
27 | 1668 |
if self.content: |
151 | 1669 |
return self.content["value"][idx].getformalParameter() |
27 | 1670 |
return None |
151 | 1671 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
27 | 1672 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1673 |
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
|
1674 |
if cls: |
151 | 1675 |
def setrelPositionXY(self, x, y): |
2 | 1676 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 1677 |
self.relPosition.setx(x) |
1678 |
self.relPosition.sety(y) |
|
1679 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
1680 |
||
1681 |
def getrelPositionXY(self): |
|
2 | 1682 |
if self.relPosition: |
151 | 1683 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 1684 |
return self.relPosition |
151 | 1685 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2 | 1686 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1687 |
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
|
1688 |
if cls: |
151 | 1689 |
def setvalue(self, value): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1690 |
if value.startswith("[") and value.endswith("]"): |
2 | 1691 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
151 | 1692 |
self.content = {"name" : "arrayValue", "value" : arrayValue} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1693 |
elif value.startswith("(") and value.endswith(")"): |
2 | 1694 |
structValue = PLCOpenClasses["value_structValue"]() |
151 | 1695 |
self.content = {"name" : "structValue", "value" : structValue} |
2 | 1696 |
else: |
1697 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
151 | 1698 |
self.content = {"name" : "simpleValue", "value": simpleValue} |
1699 |
self.content["value"].setvalue(value) |
|
1700 |
setattr(cls, "setvalue", setvalue) |
|
1701 |
||
1702 |
def getvalue(self): |
|
1703 |
return self.content["value"].getvalue() |
|
1704 |
setattr(cls, "getvalue", getvalue) |
|
2 | 1705 |
|
147 | 1706 |
def extractValues(values): |
145 | 1707 |
items = values.split(",") |
1708 |
i = 1 |
|
1709 |
while i < len(items): |
|
1710 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
1711 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
1712 |
if opened > closed: |
|
1713 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
1714 |
elif opened == closed: |
|
1715 |
i += 1 |
|
1716 |
else: |
|
1717 |
raise ValueError, "\"%s\" is an invalid value!"%value |
|
1718 |
return items |
|
1719 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1720 |
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
|
1721 |
if cls: |
145 | 1722 |
arrayValue_model = re.compile("([0-9]*)\((.*)\)$") |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1723 |
|
151 | 1724 |
def setvalue(self, value): |
2 | 1725 |
self.value = [] |
145 | 1726 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1727 |
item = item.strip() |
2 | 1728 |
element = PLCOpenClasses["arrayValue_value"]() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1729 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1730 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1731 |
groups = result.groups() |
151 | 1732 |
element.setrepetitionValue(int(groups[0])) |
1733 |
element.setvalue(groups[1].strip()) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1734 |
else: |
151 | 1735 |
element.setvalue(item) |
2 | 1736 |
self.value.append(element) |
151 | 1737 |
setattr(cls, "setvalue", setvalue) |
1738 |
||
1739 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1740 |
values = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1741 |
for element in self.value: |
151 | 1742 |
repetition = element.getrepetitionValue() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1743 |
if repetition is not None and repetition > 1: |
151 | 1744 |
values.append("%d(%s)"%(repetition, element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1745 |
else: |
151 | 1746 |
values.append(element.getvalue()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1747 |
return "[%s]"%", ".join(values) |
151 | 1748 |
setattr(cls, "getvalue", getvalue) |
2 | 1749 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1750 |
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
|
1751 |
if cls: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1752 |
structValue_model = re.compile("(.*):=(.*)") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1753 |
|
151 | 1754 |
def setvalue(self, value): |
2 | 1755 |
self.value = [] |
145 | 1756 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1757 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1758 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1759 |
groups = result.groups() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1760 |
element = PLCOpenClasses["structValue_value"]() |
151 | 1761 |
element.setmember(groups[0].strip()) |
1762 |
element.setvalue(groups[1].strip()) |
|
2 | 1763 |
self.value.append(element) |
151 | 1764 |
setattr(cls, "setvalue", setvalue) |
1765 |
||
1766 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1767 |
values = [] |
2 | 1768 |
for element in self.value: |
151 | 1769 |
values.append("%s := %s"%(element.getmember(), element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
1770 |
return "(%s)"%", ".join(values) |
151 | 1771 |
setattr(cls, "getvalue", getvalue) |