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