author | edouard |
Mon, 02 Nov 2009 18:51:27 +0100 | |
changeset 457 | 91b28dd0c9c9 |
parent 435 | 893d04aff708 |
child 461 | 649a8465148d |
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 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
48 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
49 |
def _init_and_compare(function, v1, v2): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
50 |
if v1 is None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
51 |
return v2 |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
52 |
if v2 is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
53 |
return function(v1, v2) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
54 |
return v1 |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
55 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
56 |
""" |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
57 |
Helper class for bounding_box calculation |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
58 |
""" |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
59 |
class rect: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
60 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
61 |
def __init__(self, x=None, y=None, width=None, height=None): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
62 |
self.x_min = x |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
63 |
self.x_max = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
64 |
self.y_min = y |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
65 |
self.y_max = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
66 |
if width is not None and x is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
67 |
self.x_max = x + width |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
68 |
if height is not None and y is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
69 |
self.y_max = y + height |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
70 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
71 |
def update(self, x, y): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
72 |
self.x_min = _init_and_compare(min, self.x_min, x) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
73 |
self.x_max = _init_and_compare(max, self.x_max, x) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
74 |
self.y_min = _init_and_compare(min, self.y_min, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
75 |
self.y_max = _init_and_compare(max, self.y_max, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
76 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
77 |
def union(self, rect): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
78 |
self.x_min = _init_and_compare(min, self.x_min, rect.x_min) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
79 |
self.x_max = _init_and_compare(max, self.x_max, rect.x_max) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
80 |
self.y_min = _init_and_compare(min, self.y_min, rect.y_min) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
81 |
self.y_max = _init_and_compare(max, self.y_max, rect.y_max) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
82 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
83 |
def bounding_box(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
84 |
width = height = None |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
85 |
if self.x_min is not None and self.x_max is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
86 |
width = self.x_max - self.x_min |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
87 |
if self.y_min is not None and self.y_max is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
88 |
height = self.y_max - self.y_min |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
89 |
return self.x_min, self.y_min, width, height |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
90 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
91 |
|
389 | 92 |
PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
2 | 93 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
94 |
ElementNameToClass = {} |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
95 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
96 |
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
|
97 |
if cls: |
58 | 98 |
def updateElementName(self, old_name, new_name): |
99 |
index = self.text.find(old_name) |
|
100 |
while index != -1: |
|
101 |
if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): |
|
102 |
index = self.text.find(old_name, index + len(old_name)) |
|
103 |
elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): |
|
104 |
index = self.text.find(old_name, index + len(old_name)) |
|
105 |
else: |
|
106 |
self.text = self.text[:index] + new_name + self.text[index + len(old_name):] |
|
107 |
index = self.text.find(old_name, index + len(new_name)) |
|
108 |
setattr(cls, "updateElementName", updateElementName) |
|
109 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
110 |
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
|
111 |
if cls: |
2 | 112 |
cls.singleLineAttributes = False |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
113 |
cls.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
114 |
cls.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
115 |
cls.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
116 |
cls.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
117 |
cls.CustomBlockTypes = [] |
2 | 118 |
|
151 | 119 |
def setname(self, name): |
120 |
self.contentHeader.setname(name) |
|
121 |
setattr(cls, "setname", setname) |
|
145 | 122 |
|
151 | 123 |
def getname(self): |
124 |
return self.contentHeader.getname() |
|
125 |
setattr(cls, "getname", getname) |
|
126 |
||
127 |
def getfileHeader(self): |
|
2 | 128 |
fileheader = {} |
151 | 129 |
fileheader["companyName"] = self.fileHeader.getcompanyName() |
130 |
if self.fileHeader.getcompanyURL(): |
|
131 |
fileheader["companyURL"] = self.fileHeader.getcompanyURL() |
|
132 |
fileheader["productName"] = self.fileHeader.getproductName() |
|
133 |
fileheader["productVersion"] = self.fileHeader.getproductVersion() |
|
134 |
if self.fileHeader.getproductRelease(): |
|
135 |
fileheader["productRelease"] = self.fileHeader.getproductRelease() |
|
136 |
fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime() |
|
137 |
if self.fileHeader.getcontentDescription(): |
|
138 |
fileheader["contentDescription"] = self.fileHeader.getcontentDescription() |
|
2 | 139 |
return fileheader |
151 | 140 |
setattr(cls, "getfileHeader", getfileHeader) |
141 |
||
142 |
def setfileHeader(self, fileheader): |
|
143 |
self.fileHeader.setcompanyName(fileheader["companyName"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
144 |
if fileheader.has_key("companyURL"): |
151 | 145 |
self.fileHeader.setcompanyURL(fileheader["companyURL"]) |
146 |
self.fileHeader.setproductName(fileheader["productName"]) |
|
147 |
self.fileHeader.setproductVersion(fileheader["productVersion"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
148 |
if fileheader.has_key("productRelease"): |
151 | 149 |
self.fileHeader.setproductRelease(fileheader["productRelease"]) |
150 |
self.fileHeader.setcreationDateTime(fileheader["creationDateTime"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
151 |
if fileheader.has_key("contentDescription"): |
151 | 152 |
self.fileHeader.setcontentDescription(fileheader["contentDescription"]) |
153 |
setattr(cls, "setfileHeader", setfileHeader) |
|
154 |
||
155 |
def getcontentHeader(self): |
|
145 | 156 |
contentheader = {} |
151 | 157 |
contentheader["projectName"] = self.contentHeader.getname() |
158 |
if self.contentHeader.getversion(): |
|
159 |
contentheader["projectVersion"] = self.contentHeader.getversion() |
|
160 |
if self.contentHeader.getmodificationDateTime(): |
|
161 |
contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime() |
|
162 |
if self.contentHeader.getorganization(): |
|
163 |
contentheader["organization"] = self.contentHeader.getorganization() |
|
164 |
if self.contentHeader.getauthor(): |
|
165 |
contentheader["authorName"] = self.contentHeader.getauthor() |
|
166 |
if self.contentHeader.getlanguage(): |
|
167 |
contentheader["language"] = self.contentHeader.getlanguage() |
|
168 |
contentheader["pageSize"] = self.contentHeader.getpageSize() |
|
169 |
contentheader["scaling"] = self.contentHeader.getscaling() |
|
145 | 170 |
return contentheader |
151 | 171 |
setattr(cls, "getcontentHeader", getcontentHeader) |
172 |
||
173 |
def setcontentHeader(self, contentheader): |
|
174 |
self.contentHeader.setname(contentheader["projectName"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
175 |
if contentheader.has_key("projectVersion"): |
151 | 176 |
self.contentHeader.setversion(contentheader["projectVersion"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
177 |
if contentheader.has_key("modificationDateTime"): |
151 | 178 |
self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
179 |
if contentheader.has_key("organization"): |
151 | 180 |
self.contentHeader.setorganization(contentheader["organization"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
181 |
if contentheader.has_key("authorName"): |
151 | 182 |
self.contentHeader.setauthor(contentheader["authorName"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
183 |
if contentheader.has_key("language"): |
151 | 184 |
self.contentHeader.setlanguage(contentheader["language"]) |
185 |
self.contentHeader.setpageSize(*contentheader["pageSize"]) |
|
186 |
self.contentHeader.setscaling(contentheader["scaling"]) |
|
187 |
setattr(cls, "setcontentHeader", setcontentHeader) |
|
188 |
||
189 |
def getdataTypes(self): |
|
190 |
return self.types.getdataTypeElements() |
|
191 |
setattr(cls, "getdataTypes", getdataTypes) |
|
192 |
||
193 |
def getdataType(self, name): |
|
194 |
return self.types.getdataTypeElement(name) |
|
195 |
setattr(cls, "getdataType", getdataType) |
|
196 |
||
197 |
def appenddataType(self, name): |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
198 |
if self.CustomTypeHierarchy.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
199 |
raise ValueError, "\"%s\" Data Type already exists !!!"%name |
151 | 200 |
self.types.appenddataTypeElement(name) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
201 |
self.AddCustomDataType(self.getdataType(name)) |
151 | 202 |
setattr(cls, "appenddataType", appenddataType) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
203 |
|
151 | 204 |
def insertdataType(self, index, datatype): |
205 |
self.types.insertdataTypeElement(index, datatype) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
206 |
self.AddCustomDataType(datatype) |
151 | 207 |
setattr(cls, "insertdataType", insertdataType) |
208 |
||
209 |
def removedataType(self, name): |
|
210 |
self.types.removedataTypeElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
211 |
self.RefreshDataTypeHierarchy() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
212 |
self.RefreshElementUsingTree() |
151 | 213 |
setattr(cls, "removedataType", removedataType) |
214 |
||
215 |
def getpous(self): |
|
216 |
return self.types.getpouElements() |
|
217 |
setattr(cls, "getpous", getpous) |
|
218 |
||
219 |
def getpou(self, name): |
|
220 |
return self.types.getpouElement(name) |
|
221 |
setattr(cls, "getpou", getpou) |
|
222 |
||
223 |
def appendpou(self, name, pou_type, body_type): |
|
224 |
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
|
225 |
self.AddCustomBlockType(self.getpou(name)) |
151 | 226 |
setattr(cls, "appendpou", appendpou) |
0 | 227 |
|
151 | 228 |
def insertpou(self, index, pou): |
229 |
self.types.insertpouElement(index, pou) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
230 |
self.AddCustomBlockType(pou) |
151 | 231 |
setattr(cls, "insertpou", insertpou) |
232 |
||
233 |
def removepou(self, name): |
|
234 |
self.types.removepouElement(name) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
235 |
self.RefreshCustomBlockTypes() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
236 |
self.RefreshElementUsingTree() |
151 | 237 |
setattr(cls, "removepou", removepou) |
238 |
||
239 |
def getconfigurations(self): |
|
240 |
configurations = self.instances.configurations.getconfiguration() |
|
2 | 241 |
if configurations: |
242 |
return configurations |
|
243 |
return [] |
|
151 | 244 |
setattr(cls, "getconfigurations", getconfigurations) |
245 |
||
246 |
def getconfiguration(self, name): |
|
247 |
for configuration in self.instances.configurations.getconfiguration(): |
|
248 |
if configuration.getname() == name: |
|
2 | 249 |
return configuration |
250 |
return None |
|
151 | 251 |
setattr(cls, "getconfiguration", getconfiguration) |
252 |
||
253 |
def addconfiguration(self, name): |
|
254 |
for configuration in self.instances.configurations.getconfiguration(): |
|
255 |
if configuration.getname() == name: |
|
391 | 256 |
raise ValueError, _("\"%s\" configuration already exists !!!")%name |
2 | 257 |
new_configuration = PLCOpenClasses["configurations_configuration"]() |
151 | 258 |
new_configuration.setname(name) |
259 |
self.instances.configurations.appendconfiguration(new_configuration) |
|
260 |
setattr(cls, "addconfiguration", addconfiguration) |
|
261 |
||
262 |
def removeconfiguration(self, name): |
|
2 | 263 |
found = False |
151 | 264 |
for idx, configuration in enumerate(self.instances.configurations.getconfiguration()): |
265 |
if configuration.getname() == name: |
|
266 |
self.instances.configurations.removeconfiguration(idx) |
|
2 | 267 |
found = True |
268 |
break |
|
269 |
if not found: |
|
391 | 270 |
raise ValueError, ("\"%s\" configuration doesn't exist !!!")%name |
151 | 271 |
setattr(cls, "removeconfiguration", removeconfiguration) |
272 |
||
273 |
def getconfigurationResource(self, config_name, name): |
|
274 |
configuration = self.getconfiguration(config_name) |
|
2 | 275 |
if configuration: |
151 | 276 |
for resource in configuration.getresource(): |
277 |
if resource.getname() == name: |
|
2 | 278 |
return resource |
279 |
return None |
|
151 | 280 |
setattr(cls, "getconfigurationResource", getconfigurationResource) |
281 |
||
282 |
def addconfigurationResource(self, config_name, name): |
|
283 |
configuration = self.getconfiguration(config_name) |
|
2 | 284 |
if configuration: |
151 | 285 |
for resource in configuration.getresource(): |
286 |
if resource.getname() == name: |
|
391 | 287 |
raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!")%(name, config_name) |
2 | 288 |
new_resource = PLCOpenClasses["configuration_resource"]() |
151 | 289 |
new_resource.setname(name) |
290 |
configuration.appendresource(new_resource) |
|
291 |
setattr(cls, "addconfigurationResource", addconfigurationResource) |
|
292 |
||
293 |
def removeconfigurationResource(self, config_name, name): |
|
294 |
configuration = self.getconfiguration(config_name) |
|
2 | 295 |
if configuration: |
0 | 296 |
found = False |
151 | 297 |
for idx, resource in enumerate(configuration.getresource()): |
298 |
if resource.getname() == name: |
|
299 |
configuration.removeresource(idx) |
|
0 | 300 |
found = True |
301 |
break |
|
302 |
if not found: |
|
391 | 303 |
raise ValueError, _("\"%s\" resource doesn't exist in \"%s\" configuration !!!")%(name, config_name) |
151 | 304 |
setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
305 |
||
306 |
def updateElementName(self, old_name, new_name): |
|
348
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
307 |
for datatype in self.types.getdataTypeElements(): |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
308 |
datatype_content = datatype.baseType.getcontent() |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
309 |
if datatype_content["name"] == "derived" and datatype_content["value"].getname() == old_name: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
310 |
datatype_content["value"].setname(new_name) |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
311 |
elif datatype_content["name"] in ["array", "subrangeSigned", "subrangeUnsigned"]: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
312 |
basetype_content = datatype_content["value"].baseType.getcontent() |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
313 |
if basetype_content["name"] == "derived" and basetype_content["value"].getname() == old_name: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
314 |
basetype_content["value"].setname(new_name) |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
315 |
elif datatype_content["name"] == "struct": |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
316 |
for element in datatype_content["value"].getvariable(): |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
317 |
element_type = element.type.getcontent() |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
318 |
if element_type["name"] == "derived" and element_type["value"].getname() == old_name: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
319 |
element_type["value"].setname(new_name) |
151 | 320 |
for pou in self.types.getpouElements(): |
58 | 321 |
pou.updateElementName(old_name, new_name) |
151 | 322 |
for configuration in self.instances.configurations.getconfiguration(): |
58 | 323 |
configuration.updateElementName(old_name, new_name) |
324 |
setattr(cls, "updateElementName", updateElementName) |
|
325 |
||
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
326 |
def RefreshDataTypeHierarchy(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
327 |
self.EnumeratedDataTypeValues = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
328 |
self.CustomDataTypeRange = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
329 |
self.CustomTypeHierarchy = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
330 |
for datatype in self.getdataTypes(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
331 |
self.AddCustomDataType(datatype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
332 |
setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
333 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
334 |
def AddCustomDataType(self, datatype): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
335 |
name = datatype.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
336 |
basetype_content = datatype.getbaseType().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
337 |
if basetype_content["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
338 |
self.CustomTypeHierarchy[name] = basetype_content["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
339 |
elif basetype_content["name"] in ["string", "wstring"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
340 |
self.CustomTypeHierarchy[name] = basetype_content["name"].upper() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
341 |
elif basetype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
342 |
self.CustomTypeHierarchy[name] = basetype_content["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
343 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
344 |
range = (basetype_content["value"].range.getlower(), |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
345 |
basetype_content["value"].range.getupper()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
346 |
self.CustomDataTypeRange[name] = range |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
347 |
base_type = basetype_content["value"].baseType.getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
348 |
if base_type["value"] is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
349 |
self.CustomTypeHierarchy[name] = base_type["name"] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
350 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
351 |
self.CustomTypeHierarchy[name] = base_type["value"].getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
352 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
353 |
if basetype_content["name"] == "enum": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
354 |
values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
355 |
for value in basetype_content["value"].values.getvalue(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
356 |
values.append(value.getname()) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
357 |
self.EnumeratedDataTypeValues[name] = values |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
358 |
self.CustomTypeHierarchy[name] = "ANY_DERIVED" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
359 |
setattr(cls, "AddCustomDataType", AddCustomDataType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
360 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
361 |
# Update Block types with user-defined pou added |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
362 |
def RefreshCustomBlockTypes(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
363 |
# 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
|
364 |
self.CustomBlockTypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
365 |
for pou in self.getpous(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
366 |
self.AddCustomBlockType(pou) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
367 |
setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
368 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
369 |
def AddCustomBlockType(self, pou): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
370 |
pou_name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
371 |
pou_type = pou.getpouType() |
286 | 372 |
block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False, |
373 |
"inputs" : [], "outputs" : [], "comment" : "", |
|
374 |
"generate" : generate_block, "initialise" : initialise_block} |
|
375 |
if pou.getinterface(): |
|
376 |
return_type = pou.interface.getreturnType() |
|
377 |
if return_type: |
|
378 |
var_type = return_type.getcontent() |
|
379 |
if var_type["name"] == "derived": |
|
380 |
block_infos["outputs"].append(("", var_type["value"].getname(), "none")) |
|
381 |
elif var_type["name"] in ["string", "wstring"]: |
|
382 |
block_infos["outputs"].append(("", var_type["name"].upper(), "none")) |
|
383 |
else: |
|
384 |
block_infos["outputs"].append(("", var_type["name"], "none")) |
|
385 |
for type, varlist in pou.getvars(): |
|
386 |
if type == "InOut": |
|
387 |
for var in varlist.getvariable(): |
|
388 |
var_type = var.type.getcontent() |
|
389 |
if var_type["name"] == "derived": |
|
390 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
391 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
392 |
elif var_type["name"] in ["string", "wstring"]: |
|
393 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
394 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
395 |
else: |
|
396 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
397 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
398 |
elif type == "Input": |
|
399 |
for var in varlist.getvariable(): |
|
400 |
var_type = var.type.getcontent() |
|
401 |
if var_type["name"] == "derived": |
|
402 |
block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
403 |
elif var_type["name"] in ["string", "wstring"]: |
|
404 |
block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
405 |
else: |
|
406 |
block_infos["inputs"].append((var.getname(), var_type["name"], "none")) |
|
407 |
elif type == "Output": |
|
408 |
for var in varlist.getvariable(): |
|
409 |
var_type = var.type.getcontent() |
|
410 |
if var_type["name"] == "derived": |
|
411 |
block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none")) |
|
412 |
elif var_type["name"] in ["string", "wstring"]: |
|
413 |
block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none")) |
|
414 |
else: |
|
415 |
block_infos["outputs"].append((var.getname(), var_type["name"], "none")) |
|
416 |
if pou.getbodyType() in ["FBD","LD","SFC"]: |
|
417 |
for instance in pou.getinstances(): |
|
418 |
if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)): |
|
419 |
block_infos["comment"] = instance.getcontentText() |
|
420 |
self.CustomBlockTypes.append(block_infos) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
421 |
setattr(cls, "AddCustomBlockType", AddCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
422 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
423 |
def RefreshElementUsingTree(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
424 |
# 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
|
425 |
self.ElementUsingTree = {} |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
426 |
pous = self.getpous() |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
427 |
datatypes = self.getdataTypes() |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
428 |
# 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
|
429 |
# user-defined elemnt cross-use |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
430 |
elementnames = [datatype.getname() for datatype in datatypes] + \ |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
431 |
[pou.getname() for pou in pous] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
432 |
for name in elementnames: |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
433 |
self.ElementUsingTree[name] = [] |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
434 |
# Analyze each datatype |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
435 |
for datatype in datatypes: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
436 |
name = datatype.getname() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
437 |
basetype_content = datatype.baseType.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
438 |
if basetype_content["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
439 |
typename = basetype_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
440 |
if name in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
441 |
self.ElementUsingTree[typename].append(name) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
442 |
elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
443 |
base_type = basetype_content["value"].baseType.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
444 |
if base_type["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
445 |
typename = base_type["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
446 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
447 |
self.ElementUsingTree[typename].append(name) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
448 |
elif basetype_content["name"] == "struct": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
449 |
for element in basetype_content["value"].getvariable(): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
450 |
type_content = element.type.getcontent() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
451 |
if type_content["name"] == "derived": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
452 |
typename = type_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
453 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
454 |
self.ElementUsingTree[typename].append(name) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
455 |
# Analyze each pou |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
456 |
for pou in pous: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
457 |
name = pou.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
458 |
if pou.interface: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
459 |
# Extract variables from every varLists |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
460 |
for type, varlist in pou.getvars(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
461 |
for var in varlist.getvariable(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
462 |
vartype_content = var.gettype().getcontent() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
463 |
if vartype_content["name"] == "derived": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
464 |
typename = vartype_content["value"].getname() |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
465 |
if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]: |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
466 |
self.ElementUsingTree[typename].append(name) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
467 |
setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
468 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
469 |
def GetParentType(self, type): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
470 |
if self.CustomTypeHierarchy.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
471 |
return self.CustomTypeHierarchy[type] |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
472 |
elif TypeHierarchy.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
473 |
return TypeHierarchy[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
474 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
475 |
setattr(cls, "GetParentType", GetParentType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
476 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
477 |
def GetBaseType(self, type): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
478 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
479 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
480 |
if parent_type.startswith("ANY"): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
481 |
return type |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
482 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
483 |
return self.GetBaseType(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
484 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
485 |
setattr(cls, "GetBaseType", GetBaseType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
486 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
487 |
def GetSubrangeBaseTypes(self, exclude): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
488 |
derived = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
489 |
for type in self.CustomTypeHierarchy.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
490 |
for base_type in DataTypeRange.keys(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
491 |
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
|
492 |
derived.append(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
493 |
break |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
494 |
return DataTypeRange.keys() + derived |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
495 |
setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
496 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
497 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
498 |
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
|
499 |
""" |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
500 |
def IsOfType(self, type, reference): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
501 |
if reference is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
502 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
503 |
elif type == reference: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
504 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
505 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
506 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
507 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
508 |
return self.IsOfType(parent_type, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
509 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
510 |
setattr(cls, "IsOfType", IsOfType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
511 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
512 |
# 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
|
513 |
def ElementIsUsed(self, name): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
514 |
if self.ElementUsingTree.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
515 |
return len(self.ElementUsingTree[name]) > 0 |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
516 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
517 |
setattr(cls, "ElementIsUsed", ElementIsUsed) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
518 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
519 |
def DataTypeIsDerived(self, name): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
520 |
return name in self.CustomTypeHierarchy.values() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
521 |
setattr(cls, "DataTypeIsDerived", DataTypeIsDerived) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
522 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
523 |
# 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
|
524 |
def ElementIsUsedBy(self, name, reference): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
525 |
if self.ElementUsingTree.has_key(name): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
526 |
list = self.ElementUsingTree[name] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
527 |
# Test if pou is directly used by reference |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
528 |
if reference in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
529 |
return True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
530 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
531 |
# 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
|
532 |
# 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
|
533 |
used = False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
534 |
for element in list: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
535 |
used |= self.ElementIsUsedBy(element, reference) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
536 |
return used |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
537 |
return False |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
538 |
setattr(cls, "ElementIsUsedBy", ElementIsUsedBy) |
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 |
def GetDataTypeRange(self, type): |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
541 |
if self.CustomDataTypeRange.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
542 |
return self.CustomDataTypeRange[type] |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
543 |
elif DataTypeRange.has_key(type): |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
544 |
return DataTypeRange[type] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
545 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
546 |
parent_type = self.GetParentType(type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
547 |
if parent_type is not None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
548 |
return self.GetDataTypeRange(parent_type) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
549 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
550 |
setattr(cls, "GetDataTypeRange", GetDataTypeRange) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
551 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
552 |
def GetEnumeratedDataTypeValues(self, type = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
553 |
if type is None: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
554 |
all_values = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
555 |
for values in self.EnumeratedDataTypeValues.values(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
556 |
all_values.extend(values) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
557 |
return all_values |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
558 |
elif self.EnumeratedDataTypeValues.has_key(type): |
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
559 |
return self.EnumeratedDataTypeValues[type] |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
560 |
return [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
561 |
setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
562 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
563 |
# 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
|
564 |
def GetCustomBlockType(self, type, inputs = None): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
565 |
for customblocktype in self.CustomBlockTypes: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
566 |
if inputs: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
567 |
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
|
568 |
same_inputs = inputs == customblock_inputs |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
569 |
else: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
570 |
same_inputs = True |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
571 |
if customblocktype["name"] == type and same_inputs: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
572 |
return customblocktype |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
573 |
return None |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
574 |
setattr(cls, "GetCustomBlockType", GetCustomBlockType) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
575 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
576 |
# 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
|
577 |
def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False): |
238
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
578 |
type = None |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
579 |
if exclude != "": |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
580 |
pou = self.getpou(exclude) |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
581 |
if pou is not None: |
389f2046e495
Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents:
225
diff
changeset
|
582 |
type = pou.getpouType() |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
583 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
584 |
for customblocktype in self.CustomBlockTypes: |
286 | 585 |
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
|
586 |
customblocktypes.append(customblocktype) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
587 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
588 |
setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
589 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
590 |
# Return Function Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
591 |
def GetCustomFunctionBlockTypes(self, exclude = ""): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
592 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
593 |
for customblocktype in self.CustomBlockTypes: |
286 | 594 |
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
|
595 |
customblocktypes.append(customblocktype["name"]) |
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
596 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
597 |
setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
598 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
599 |
# Return Block types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
600 |
def GetCustomBlockResource(self): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
601 |
customblocktypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
602 |
for customblocktype in self.CustomBlockTypes: |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
603 |
if customblocktype["type"] == "program": |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
604 |
customblocktypes.append(customblocktype["name"]) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
605 |
return customblocktypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
606 |
setattr(cls, "GetCustomBlockResource", GetCustomBlockResource) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
607 |
|
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
608 |
# Return Data Types checking for recursion |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
609 |
def GetCustomDataTypes(self, exclude = ""): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
610 |
customdatatypes = [] |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
611 |
for customdatatype in self.getdataTypes(): |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
612 |
customdatatype_name = customdatatype.getname() |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
613 |
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
|
614 |
customdatatypes.append(customdatatype_name) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
615 |
return customdatatypes |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
616 |
setattr(cls, "GetCustomDataTypes", GetCustomDataTypes) |
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
617 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
618 |
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
|
619 |
if cls: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
620 |
cls.singleLineAttributes = False |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
621 |
|
145 | 622 |
cls = PLCOpenClasses.get("project_contentHeader", None) |
623 |
if cls: |
|
624 |
cls.singleLineAttributes = False |
|
625 |
||
151 | 626 |
def setpageSize(self, width, height): |
627 |
self.coordinateInfo.setpageSize(width, height) |
|
628 |
setattr(cls, "setpageSize", setpageSize) |
|
629 |
||
630 |
def getpageSize(self): |
|
631 |
return self.coordinateInfo.getpageSize() |
|
632 |
setattr(cls, "getpageSize", getpageSize) |
|
633 |
||
634 |
def setscaling(self, scaling): |
|
145 | 635 |
for language, (x, y) in scaling.items(): |
151 | 636 |
self.coordinateInfo.setscaling(language, x, y) |
637 |
setattr(cls, "setscaling", setscaling) |
|
638 |
||
639 |
def getscaling(self): |
|
145 | 640 |
scaling = {} |
151 | 641 |
scaling["FBD"] = self.coordinateInfo.getscaling("FBD") |
642 |
scaling["LD"] = self.coordinateInfo.getscaling("LD") |
|
643 |
scaling["SFC"] = self.coordinateInfo.getscaling("SFC") |
|
145 | 644 |
return scaling |
151 | 645 |
setattr(cls, "getscaling", getscaling) |
145 | 646 |
|
647 |
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None) |
|
648 |
if cls: |
|
151 | 649 |
def setpageSize(self, width, height): |
145 | 650 |
if width == 0 and height == 0: |
151 | 651 |
self.deletepageSize() |
145 | 652 |
else: |
653 |
if self.pageSize is None: |
|
151 | 654 |
self.addpageSize() |
655 |
self.pageSize.setx(width) |
|
656 |
self.pageSize.sety(height) |
|
657 |
setattr(cls, "setpageSize", setpageSize) |
|
658 |
||
659 |
def getpageSize(self): |
|
145 | 660 |
if self.pageSize is not None: |
151 | 661 |
return self.pageSize.getx(), self.pageSize.gety() |
145 | 662 |
return 0, 0 |
151 | 663 |
setattr(cls, "getpageSize", getpageSize) |
664 |
||
665 |
def setscaling(self, language, x, y): |
|
145 | 666 |
if language == "FBD": |
151 | 667 |
self.fbd.scaling.setx(x) |
668 |
self.fbd.scaling.sety(y) |
|
145 | 669 |
elif language == "LD": |
151 | 670 |
self.ld.scaling.setx(x) |
671 |
self.ld.scaling.sety(y) |
|
145 | 672 |
elif language == "SFC": |
151 | 673 |
self.sfc.scaling.setx(x) |
674 |
self.sfc.scaling.sety(y) |
|
675 |
setattr(cls, "setscaling", setscaling) |
|
676 |
||
677 |
def getscaling(self, language): |
|
145 | 678 |
if language == "FBD": |
151 | 679 |
return self.fbd.scaling.getx(), self.fbd.scaling.gety() |
145 | 680 |
elif language == "LD": |
151 | 681 |
return self.ld.scaling.getx(), self.ld.scaling.gety() |
145 | 682 |
elif language == "SFC": |
151 | 683 |
return self.sfc.scaling.getx(), self.sfc.scaling.gety() |
145 | 684 |
return 0, 0 |
151 | 685 |
setattr(cls, "getscaling", getscaling) |
145 | 686 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
687 |
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
|
688 |
if cls: |
58 | 689 |
def updateElementName(self, old_name, new_name): |
151 | 690 |
for resource in self.getresource(): |
58 | 691 |
resource.updateElementName(old_name, new_name) |
692 |
setattr(cls, "updateElementName", updateElementName) |
|
693 |
||
694 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
695 |
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
|
696 |
if cls: |
58 | 697 |
def updateElementName(self, old_name, new_name): |
187 | 698 |
for instance in self.getpouInstance(): |
58 | 699 |
instance.updateElementName(old_name, new_name) |
187 | 700 |
for task in self.gettask(): |
58 | 701 |
task.updateElementName(old_name, new_name) |
702 |
setattr(cls, "updateElementName", updateElementName) |
|
703 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
704 |
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
|
705 |
if cls: |
389 | 706 |
def compatibility(self, tree): |
707 |
if tree.hasAttribute("interval"): |
|
708 |
interval = GetAttributeValue(tree._attrs["interval"]) |
|
709 |
result = time_model.match(interval) |
|
710 |
if result is not None: |
|
711 |
values = result.groups() |
|
712 |
time_values = [int(v) for v in values[:2]] |
|
713 |
seconds = float(values[2]) |
|
714 |
time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
|
715 |
text = "t#" |
|
716 |
if time_values[0] != 0: |
|
717 |
text += "%dh"%time_values[0] |
|
718 |
if time_values[1] != 0: |
|
719 |
text += "%dm"%time_values[1] |
|
720 |
if time_values[2] != 0: |
|
721 |
text += "%ds"%time_values[2] |
|
722 |
if time_values[3] != 0: |
|
723 |
if time_values[3] % 1000 != 0: |
|
724 |
text += "%.3fms"%(float(time_values[3]) / 1000) |
|
725 |
else: |
|
726 |
text += "%dms"%(time_values[3] / 1000) |
|
727 |
NodeSetAttr(tree, "interval", text) |
|
728 |
setattr(cls, "compatibility", compatibility) |
|
729 |
||
58 | 730 |
def updateElementName(self, old_name, new_name): |
731 |
if self.single == old_name: |
|
732 |
self.single = new_name |
|
187 | 733 |
for instance in self.getpouInstance(): |
58 | 734 |
instance.updateElementName(old_name, new_name) |
735 |
setattr(cls, "updateElementName", updateElementName) |
|
736 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
737 |
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
|
738 |
if cls: |
389 | 739 |
def compatibility(self, tree): |
740 |
if tree.hasAttribute("type"): |
|
741 |
NodeRenameAttr(tree, "type", "typeName") |
|
742 |
setattr(cls, "compatibility", compatibility) |
|
743 |
||
58 | 744 |
def updateElementName(self, old_name, new_name): |
417
218142afdb53
fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents:
394
diff
changeset
|
745 |
if self.typeName == old_name: |
218142afdb53
fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents:
394
diff
changeset
|
746 |
self.typeName = new_name |
58 | 747 |
setattr(cls, "updateElementName", updateElementName) |
748 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
749 |
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
|
750 |
if cls: |
151 | 751 |
def getdataTypeElements(self): |
752 |
return self.dataTypes.getdataType() |
|
753 |
setattr(cls, "getdataTypeElements", getdataTypeElements) |
|
754 |
||
755 |
def getdataTypeElement(self, name): |
|
756 |
elements = self.dataTypes.getdataType() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
757 |
for element in elements: |
151 | 758 |
if element.getname() == name: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
759 |
return element |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
760 |
return None |
151 | 761 |
setattr(cls, "getdataTypeElement", getdataTypeElement) |
762 |
||
763 |
def appenddataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
764 |
new_datatype = PLCOpenClasses["dataTypes_dataType"]() |
151 | 765 |
new_datatype.setname(name) |
766 |
new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None}) |
|
767 |
self.dataTypes.appenddataType(new_datatype) |
|
768 |
setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
|
225
7726c8ffda42
Moving Data types and POU types informations into project model
lbessard
parents:
200
diff
changeset
|
769 |
|
151 | 770 |
def insertdataTypeElement(self, index, dataType): |
771 |
self.dataTypes.insertdataType(index, dataType) |
|
772 |
setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
|
773 |
||
774 |
def removedataTypeElement(self, name): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
775 |
found = False |
151 | 776 |
for idx, element in enumerate(self.dataTypes.getdataType()): |
777 |
if element.getname() == name: |
|
778 |
self.dataTypes.removedataType(idx) |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
779 |
found = True |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
780 |
break |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
781 |
if not found: |
391 | 782 |
raise ValueError, _("\"%s\" Data Type doesn't exist !!!")%name |
151 | 783 |
setattr(cls, "removedataTypeElement", removedataTypeElement) |
784 |
||
785 |
def getpouElements(self): |
|
786 |
return self.pous.getpou() |
|
787 |
setattr(cls, "getpouElements", getpouElements) |
|
788 |
||
789 |
def getpouElement(self, name): |
|
790 |
elements = self.pous.getpou() |
|
2 | 791 |
for element in elements: |
151 | 792 |
if element.getname() == name: |
2 | 793 |
return element |
794 |
return None |
|
151 | 795 |
setattr(cls, "getpouElement", getpouElement) |
796 |
||
797 |
def appendpouElement(self, name, pou_type, body_type): |
|
798 |
for element in self.pous.getpou(): |
|
799 |
if element.getname() == name: |
|
391 | 800 |
raise ValueError, _("\"%s\" POU already exists !!!")%name |
2 | 801 |
new_pou = PLCOpenClasses["pous_pou"]() |
151 | 802 |
new_pou.setname(name) |
803 |
new_pou.setpouType(pou_type) |
|
389 | 804 |
new_pou.appendbody(PLCOpenClasses["body"]()) |
151 | 805 |
new_pou.setbodyType(body_type) |
806 |
self.pous.appendpou(new_pou) |
|
807 |
setattr(cls, "appendpouElement", appendpouElement) |
|
2 | 808 |
|
151 | 809 |
def insertpouElement(self, index, pou): |
810 |
self.pous.insertpou(index, pou) |
|
811 |
setattr(cls, "insertpouElement", insertpouElement) |
|
812 |
||
813 |
def removepouElement(self, name): |
|
2 | 814 |
found = False |
151 | 815 |
for idx, element in enumerate(self.pous.getpou()): |
816 |
if element.getname() == name: |
|
817 |
self.pous.removepou(idx) |
|
2 | 818 |
found = True |
819 |
break |
|
820 |
if not found: |
|
391 | 821 |
raise ValueError, _("\"%s\" POU doesn't exist !!!")%name |
151 | 822 |
setattr(cls, "removepouElement", removepouElement) |
823 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
824 |
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
|
825 |
if cls: |
389 | 826 |
|
827 |
def setbodyType(self, type): |
|
828 |
if len(self.body) > 0: |
|
829 |
if type == "IL": |
|
830 |
self.body[0].setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
831 |
elif type == "ST": |
|
832 |
self.body[0].setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
833 |
elif type == "LD": |
|
834 |
self.body[0].setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
835 |
elif type == "FBD": |
|
836 |
self.body[0].setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
837 |
elif type == "SFC": |
|
838 |
self.body[0].setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
839 |
else: |
|
840 |
raise ValueError, "%s isn't a valid body type!"%type |
|
151 | 841 |
setattr(cls, "setbodyType", setbodyType) |
389 | 842 |
|
843 |
def getbodyType(self): |
|
844 |
if len(self.body) > 0: |
|
845 |
return self.body[0].getcontent()["name"] |
|
151 | 846 |
setattr(cls, "getbodyType", getbodyType) |
389 | 847 |
|
848 |
def resetexecutionOrder(self): |
|
849 |
if len(self.body) > 0: |
|
850 |
self.body[0].resetexecutionOrder() |
|
151 | 851 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
389 | 852 |
|
853 |
def compileexecutionOrder(self): |
|
854 |
if len(self.body) > 0: |
|
855 |
self.body[0].compileexecutionOrder() |
|
151 | 856 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
389 | 857 |
|
858 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
859 |
if len(self.body) > 0: |
|
860 |
self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
|
151 | 861 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
389 | 862 |
|
863 |
def addinstance(self, name, instance): |
|
864 |
if len(self.body) > 0: |
|
865 |
self.body[0].appendcontentInstance(name, instance) |
|
151 | 866 |
setattr(cls, "addinstance", addinstance) |
389 | 867 |
|
868 |
def getinstances(self): |
|
869 |
if len(self.body) > 0: |
|
870 |
return self.body[0].getcontentInstances() |
|
871 |
return [] |
|
151 | 872 |
setattr(cls, "getinstances", getinstances) |
389 | 873 |
|
874 |
def getinstance(self, id): |
|
875 |
if len(self.body) > 0: |
|
876 |
return self.body[0].getcontentInstance(id) |
|
877 |
return None |
|
151 | 878 |
setattr(cls, "getinstance", getinstance) |
389 | 879 |
|
880 |
def getrandomInstance(self, exclude): |
|
881 |
if len(self.body) > 0: |
|
882 |
return self.body[0].getcontentRandomInstance(exclude) |
|
883 |
return None |
|
151 | 884 |
setattr(cls, "getrandomInstance", getrandomInstance) |
389 | 885 |
|
886 |
def getinstanceByName(self, name): |
|
887 |
if len(self.body) > 0: |
|
888 |
return self.body[0].getcontentInstanceByName(name) |
|
889 |
return None |
|
151 | 890 |
setattr(cls, "getinstanceByName", getinstanceByName) |
389 | 891 |
|
892 |
def removeinstance(self, id): |
|
893 |
if len(self.body) > 0: |
|
894 |
self.body[0].removecontentInstance(id) |
|
151 | 895 |
setattr(cls, "removeinstance", removeinstance) |
389 | 896 |
|
897 |
def settext(self, text): |
|
898 |
if len(self.body) > 0: |
|
899 |
self.body[0].settext(text) |
|
151 | 900 |
setattr(cls, "settext", settext) |
389 | 901 |
|
902 |
def gettext(self): |
|
903 |
if len(self.body) > 0: |
|
904 |
return self.body[0].gettext() |
|
905 |
return "" |
|
151 | 906 |
setattr(cls, "gettext", gettext) |
907 |
||
908 |
def getvars(self): |
|
2 | 909 |
vars = [] |
282 | 910 |
if self.interface is not None: |
911 |
reverse_types = {} |
|
912 |
for name, value in VarTypes.items(): |
|
913 |
reverse_types[value] = name |
|
914 |
for varlist in self.interface.getcontent(): |
|
915 |
vars.append((reverse_types[varlist["name"]], varlist["value"])) |
|
2 | 916 |
return vars |
151 | 917 |
setattr(cls, "getvars", getvars) |
918 |
||
919 |
def setvars(self, vars): |
|
282 | 920 |
if self.interface is None: |
921 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
151 | 922 |
self.interface.setcontent([]) |
2 | 923 |
for vartype, varlist in vars: |
151 | 924 |
self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist}) |
925 |
setattr(cls, "setvars", setvars) |
|
926 |
||
435
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
927 |
def addpouVar(self, type, name, location="", description=""): |
282 | 928 |
if self.interface is None: |
929 |
self.interface = PLCOpenClasses["pou_interface"]() |
|
151 | 930 |
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
|
931 |
if len(content) == 0 or content[-1]["name"] != "localVars": |
151 | 932 |
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
|
933 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
934 |
varlist = content[-1]["value"] |
151 | 935 |
variables = varlist.getvariable() |
936 |
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
|
937 |
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
|
938 |
var = PLCOpenClasses["varListPlain_variable"]() |
151 | 939 |
var.setname(name) |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
940 |
var_type = PLCOpenClasses["dataType"]() |
435
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
941 |
if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
942 |
if type == "STRING": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
943 |
var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
944 |
elif type == "WSTRING": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
945 |
var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
946 |
else: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
947 |
var_type.setcontent({"name" : type, "value" : None}) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
948 |
else: |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
949 |
derived_type = PLCOpenClasses["derivedTypes_derived"]() |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
950 |
derived_type.setname(type) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
951 |
var_type.setcontent({"name" : "derived", "value" : derived_type}) |
151 | 952 |
var.settype(var_type) |
435
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
953 |
if location != "": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
954 |
var.setaddress(location) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
955 |
if description != "": |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
956 |
ft = PLCOpenClasses["formattedText"]() |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
957 |
ft.settext(description) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
958 |
var.setdocumentation(ft) |
893d04aff708
Adding support for individually adding variable to POU interface
laurent
parents:
427
diff
changeset
|
959 |
|
151 | 960 |
content[-1]["value"].appendvariable(var) |
961 |
setattr(cls, "addpouVar", addpouVar) |
|
962 |
||
963 |
def changepouVar(self, old_type, old_name, new_type, new_name): |
|
282 | 964 |
if self.interface is not None: |
965 |
content = self.interface.getcontent() |
|
966 |
for varlist in content: |
|
967 |
variables = varlist["value"].getvariable() |
|
968 |
for var in variables: |
|
969 |
if var.getname() == old_name: |
|
970 |
vartype_content = var.gettype().getcontent() |
|
971 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type: |
|
972 |
var.setname(new_name) |
|
973 |
vartype_content["value"].setname(new_type) |
|
974 |
return |
|
151 | 975 |
setattr(cls, "changepouVar", changepouVar) |
976 |
||
977 |
def removepouVar(self, type, name): |
|
282 | 978 |
if self.interface is not None: |
979 |
content = self.interface.getcontent() |
|
980 |
for varlist in content: |
|
981 |
variables = varlist["value"].getvariable() |
|
982 |
for var in variables: |
|
983 |
if var.getname() == name: |
|
984 |
vartype_content = var.gettype().getcontent() |
|
985 |
if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type: |
|
986 |
variables.remove(var) |
|
987 |
break |
|
988 |
if len(varlist["value"].getvariable()) == 0: |
|
989 |
content.remove(varlist) |
|
990 |
break |
|
151 | 991 |
setattr(cls, "removepouVar", removepouVar) |
992 |
||
993 |
def hasblock(self, name): |
|
994 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
995 |
for instance in self.getinstances(): |
|
996 |
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
|
997 |
return True |
89 | 998 |
if self.transitions: |
151 | 999 |
for transition in self.transitions.gettransition(): |
1000 |
result = transition.hasblock(name) |
|
89 | 1001 |
if result: |
1002 |
return result |
|
1003 |
if self.actions: |
|
151 | 1004 |
for action in self.actions.getaction(): |
1005 |
result = action.hasblock(name) |
|
89 | 1006 |
if result: |
1007 |
return result |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1008 |
return False |
151 | 1009 |
setattr(cls, "hasblock", hasblock) |
1010 |
||
1011 |
def addtransition(self, name, type): |
|
2 | 1012 |
if not self.transitions: |
151 | 1013 |
self.addtransitions() |
1014 |
self.transitions.settransition([]) |
|
2 | 1015 |
transition = PLCOpenClasses["transitions_transition"]() |
151 | 1016 |
transition.setname(name) |
1017 |
transition.setbodyType(type) |
|
200 | 1018 |
if type == "ST": |
1019 |
transition.settext(":= ;") |
|
1020 |
elif type == "IL": |
|
1021 |
transition.settext("\tST\t%s"%name) |
|
151 | 1022 |
self.transitions.appendtransition(transition) |
1023 |
setattr(cls, "addtransition", addtransition) |
|
1024 |
||
1025 |
def gettransition(self, name): |
|
2 | 1026 |
if self.transitions: |
151 | 1027 |
for transition in self.transitions.gettransition(): |
1028 |
if transition.getname() == name: |
|
2 | 1029 |
return transition |
1030 |
return None |
|
151 | 1031 |
setattr(cls, "gettransition", gettransition) |
2 | 1032 |
|
151 | 1033 |
def gettransitionList(self): |
2 | 1034 |
if self.transitions: |
151 | 1035 |
return self.transitions.gettransition() |
2 | 1036 |
return [] |
151 | 1037 |
setattr(cls, "gettransitionList", gettransitionList) |
1038 |
||
1039 |
def removetransition(self, name): |
|
2 | 1040 |
if self.transitions: |
151 | 1041 |
transitions = self.transitions.gettransition() |
2 | 1042 |
i = 0 |
1043 |
removed = False |
|
1044 |
while i < len(transitions) and not removed: |
|
151 | 1045 |
if transitions[i].getname() == name: |
46 | 1046 |
transitions.pop(i) |
2 | 1047 |
removed = True |
1048 |
i += 1 |
|
1049 |
if not removed: |
|
427 | 1050 |
raise ValueError, _("Transition with name %s doesn't exist!")%name |
151 | 1051 |
setattr(cls, "removetransition", removetransition) |
1052 |
||
1053 |
def addaction(self, name, type): |
|
2 | 1054 |
if not self.actions: |
151 | 1055 |
self.addactions() |
1056 |
self.actions.setaction([]) |
|
2 | 1057 |
action = PLCOpenClasses["actions_action"]() |
151 | 1058 |
action.setname(name) |
1059 |
action.setbodyType(type) |
|
1060 |
self.actions.appendaction(action) |
|
1061 |
setattr(cls, "addaction", addaction) |
|
1062 |
||
1063 |
def getaction(self, name): |
|
2 | 1064 |
if self.actions: |
151 | 1065 |
for action in self.actions.getaction(): |
1066 |
if action.getname() == name: |
|
2 | 1067 |
return action |
1068 |
return None |
|
151 | 1069 |
setattr(cls, "getaction", getaction) |
1070 |
||
1071 |
def getactionList(self): |
|
2 | 1072 |
if self.actions: |
151 | 1073 |
return self.actions.getaction() |
2 | 1074 |
return [] |
151 | 1075 |
setattr(cls, "getactionList", getactionList) |
2 | 1076 |
|
151 | 1077 |
def removeaction(self, name): |
2 | 1078 |
if self.actions: |
151 | 1079 |
actions = self.actions.getaction() |
2 | 1080 |
i = 0 |
1081 |
removed = False |
|
1082 |
while i < len(actions) and not removed: |
|
151 | 1083 |
if actions[i].getname() == name: |
46 | 1084 |
actions.pop(i) |
2 | 1085 |
removed = True |
1086 |
i += 1 |
|
1087 |
if not removed: |
|
427 | 1088 |
raise ValueError, _("Action with name %s doesn't exist!")%name |
151 | 1089 |
setattr(cls, "removeaction", removeaction) |
2 | 1090 |
|
58 | 1091 |
def updateElementName(self, old_name, new_name): |
348
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1092 |
if self.interface: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1093 |
for content in self.interface.getcontent(): |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1094 |
for var in content["value"].getvariable(): |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1095 |
var_type_content = var.gettype().getcontent() |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1096 |
if var_type_content["name"] == "derived": |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1097 |
if var_type_content["value"].getname() == old_name: |
09fdd7616a86
Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents:
295
diff
changeset
|
1098 |
var_type_content["value"].setname(new_name) |
394 | 1099 |
self.body[0].updateElementName(old_name, new_name) |
151 | 1100 |
for action in self.getactionList(): |
58 | 1101 |
action.updateElementName(old_name, new_name) |
151 | 1102 |
for transition in self.gettransitionList(): |
58 | 1103 |
transition.updateElementName(old_name, new_name) |
1104 |
setattr(cls, "updateElementName", updateElementName) |
|
1105 |
||
389 | 1106 |
def setbodyType(self, type): |
1107 |
if type == "IL": |
|
1108 |
self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()}) |
|
1109 |
elif type == "ST": |
|
1110 |
self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1111 |
elif type == "LD": |
|
1112 |
self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()}) |
|
1113 |
elif type == "FBD": |
|
1114 |
self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()}) |
|
1115 |
elif type == "SFC": |
|
1116 |
self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()}) |
|
1117 |
else: |
|
1118 |
raise ValueError, "%s isn't a valid body type!"%type |
|
1119 |
||
1120 |
def getbodyType(self): |
|
1121 |
return self.body.getcontent()["name"] |
|
1122 |
||
1123 |
def resetexecutionOrder(self): |
|
1124 |
self.body.resetexecutionOrder() |
|
1125 |
||
1126 |
def compileexecutionOrder(self): |
|
1127 |
self.body.compileexecutionOrder() |
|
1128 |
||
1129 |
def setelementExecutionOrder(self, instance, new_executionOrder): |
|
1130 |
self.body.setelementExecutionOrder(instance, new_executionOrder) |
|
1131 |
||
1132 |
def addinstance(self, name, instance): |
|
1133 |
self.body.appendcontentInstance(name, instance) |
|
1134 |
||
1135 |
def getinstances(self): |
|
1136 |
return self.body.getcontentInstances() |
|
1137 |
||
1138 |
def getinstance(self, id): |
|
1139 |
return self.body.getcontentInstance(id) |
|
1140 |
||
1141 |
def getrandomInstance(self, exclude): |
|
1142 |
return self.body.getcontentRandomInstance(exclude) |
|
1143 |
||
1144 |
def getinstanceByName(self, name): |
|
1145 |
return self.body.getcontentInstanceByName(name) |
|
1146 |
||
1147 |
def removeinstance(self, id): |
|
1148 |
self.body.removecontentInstance(id) |
|
1149 |
||
1150 |
def settext(self, text): |
|
1151 |
self.body.settext(text) |
|
1152 |
||
1153 |
def gettext(self): |
|
1154 |
return self.body.gettext() |
|
1155 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1156 |
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
|
1157 |
if cls: |
151 | 1158 |
setattr(cls, "setbodyType", setbodyType) |
1159 |
setattr(cls, "getbodyType", getbodyType) |
|
1160 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1161 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1162 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1163 |
setattr(cls, "addinstance", addinstance) |
|
1164 |
setattr(cls, "getinstances", getinstances) |
|
1165 |
setattr(cls, "getinstance", getinstance) |
|
1166 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1167 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1168 |
setattr(cls, "removeinstance", removeinstance) |
|
1169 |
setattr(cls, "settext", settext) |
|
1170 |
setattr(cls, "gettext", gettext) |
|
2 | 1171 |
|
58 | 1172 |
def updateElementName(self, old_name, new_name): |
1173 |
self.body.updateElementName(old_name, new_name) |
|
1174 |
setattr(cls, "updateElementName", updateElementName) |
|
1175 |
||
151 | 1176 |
def hasblock(self, name): |
1177 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1178 |
for instance in self.getinstances(): |
|
1179 |
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
|
1180 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1181 |
return False |
151 | 1182 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1183 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1184 |
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
|
1185 |
if cls: |
151 | 1186 |
setattr(cls, "setbodyType", setbodyType) |
1187 |
setattr(cls, "getbodyType", getbodyType) |
|
1188 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
|
1189 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
|
1190 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
|
1191 |
setattr(cls, "addinstance", addinstance) |
|
1192 |
setattr(cls, "getinstances", getinstances) |
|
1193 |
setattr(cls, "getinstance", getinstance) |
|
1194 |
setattr(cls, "getrandomInstance", getrandomInstance) |
|
1195 |
setattr(cls, "getinstanceByName", getinstanceByName) |
|
1196 |
setattr(cls, "removeinstance", removeinstance) |
|
1197 |
setattr(cls, "settext", settext) |
|
1198 |
setattr(cls, "gettext", gettext) |
|
2 | 1199 |
|
58 | 1200 |
def updateElementName(self, old_name, new_name): |
1201 |
self.body.updateElementName(old_name, new_name) |
|
1202 |
setattr(cls, "updateElementName", updateElementName) |
|
1203 |
||
151 | 1204 |
def hasblock(self, name): |
1205 |
if self.getbodyType() in ["FBD", "LD", "SFC"]: |
|
1206 |
for instance in self.getinstances(): |
|
1207 |
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
|
1208 |
return True |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1209 |
return False |
151 | 1210 |
setattr(cls, "hasblock", hasblock) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
1211 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1212 |
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
|
1213 |
if cls: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1214 |
cls.currentExecutionOrderId = 0 |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
108
diff
changeset
|
1215 |
|
151 | 1216 |
def resetcurrentExecutionOrderId(self): |
200 | 1217 |
object.__setattr__(self, "currentExecutionOrderId", 0) |
151 | 1218 |
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId) |
1219 |
||
1220 |
def getnewExecutionOrderId(self): |
|
200 | 1221 |
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
|
1222 |
return self.currentExecutionOrderId |
151 | 1223 |
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId) |
1224 |
||
1225 |
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
|
1226 |
if self.content["name"] == "FBD": |
151 | 1227 |
for element in self.content["value"].getcontent(): |
1228 |
if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), |
|
1229 |
PLCOpenClasses.get("commonObjects_connector", None), |
|
1230 |
PLCOpenClasses.get("commonObjects_continuation", None))): |
|
1231 |
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
|
1232 |
else: |
391 | 1233 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1234 |
setattr(cls, "resetexecutionOrder", resetexecutionOrder) |
1235 |
||
1236 |
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
|
1237 |
if self.content["name"] == "FBD": |
151 | 1238 |
self.resetexecutionOrder() |
1239 |
self.resetcurrentExecutionOrderId() |
|
1240 |
for element in self.content["value"].getcontent(): |
|
200 | 1241 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0: |
151 | 1242 |
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
|
1243 |
if connections and len(connections) == 1: |
151 | 1244 |
self.compileelementExecutionOrder(connections[0]) |
1245 |
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
|
1246 |
else: |
391 | 1247 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1248 |
setattr(cls, "compileexecutionOrder", compileexecutionOrder) |
1249 |
||
1250 |
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
|
1251 |
if self.content["name"] == "FBD": |
151 | 1252 |
localid = link.getrefLocalId() |
1253 |
instance = self.getcontentInstance(localid) |
|
1254 |
if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0: |
|
1255 |
for variable in instance.inputVariables.getvariable(): |
|
1256 |
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
|
1257 |
if connections and len(connections) == 1: |
151 | 1258 |
self.compileelementExecutionOrder(connections[0]) |
1259 |
instance.setexecutionOrderId(self.getnewExecutionOrderId()) |
|
1260 |
elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0: |
|
1261 |
name = instance.getname() |
|
1262 |
for tmp_instance in self.getcontentInstances(): |
|
1263 |
if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0: |
|
1264 |
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
|
1265 |
if connections and len(connections) == 1: |
151 | 1266 |
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
|
1267 |
else: |
391 | 1268 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1269 |
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1270 |
||
1271 |
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
|
1272 |
if self.content["name"] == "FBD": |
151 | 1273 |
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
|
1274 |
if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: |
151 | 1275 |
for element in self.content["value"].getcontent(): |
1276 |
if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)): |
|
1277 |
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
|
1278 |
if old_executionOrder <= element_executionOrder <= new_executionOrder: |
151 | 1279 |
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
|
1280 |
if new_executionOrder <= element_executionOrder <= old_executionOrder: |
151 | 1281 |
element["value"].setexecutionOrderId(element_executionOrder + 1) |
1282 |
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
|
1283 |
else: |
391 | 1284 |
raise TypeError, _("Can only generate execution order on FBD networks!") |
151 | 1285 |
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1286 |
||
1287 |
def appendcontentInstance(self, name, instance): |
|
2 | 1288 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1289 |
self.content["value"].appendcontent({"name" : name, "value" : instance}) |
2 | 1290 |
else: |
391 | 1291 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1292 |
setattr(cls, "appendcontentInstance", appendcontentInstance) |
1293 |
||
1294 |
def getcontentInstances(self): |
|
2 | 1295 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1296 |
instances = [] |
|
151 | 1297 |
for element in self.content["value"].getcontent(): |
2 | 1298 |
instances.append(element["value"]) |
1299 |
return instances |
|
1300 |
else: |
|
391 | 1301 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1302 |
setattr(cls, "getcontentInstances", getcontentInstances) |
1303 |
||
1304 |
def getcontentInstance(self, id): |
|
2 | 1305 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1306 |
for element in self.content["value"].getcontent(): |
1307 |
if element["value"].getlocalId() == id: |
|
2 | 1308 |
return element["value"] |
0 | 1309 |
return None |
2 | 1310 |
else: |
391 | 1311 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1312 |
setattr(cls, "getcontentInstance", getcontentInstance) |
1313 |
||
1314 |
def getcontentRandomInstance(self, exclude): |
|
2 | 1315 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1316 |
for element in self.content["value"].getcontent(): |
1317 |
if element["value"].getlocalId() not in exclude: |
|
2 | 1318 |
return element["value"] |
1319 |
return None |
|
1320 |
else: |
|
391 | 1321 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1322 |
setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1323 |
||
1324 |
def getcontentInstanceByName(self, name): |
|
2 | 1325 |
if self.content["name"] in ["LD","FBD","SFC"]: |
151 | 1326 |
for element in self.content["value"].getcontent(): |
193 | 1327 |
if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name: |
2 | 1328 |
return element["value"] |
1329 |
else: |
|
391 | 1330 |
raise TypeError, _("%s body don't have instances!")%self.content["name"] |
151 | 1331 |
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1332 |
||
1333 |
def removecontentInstance(self, id): |
|
2 | 1334 |
if self.content["name"] in ["LD","FBD","SFC"]: |
1335 |
i = 0 |
|
1336 |
removed = False |
|
151 | 1337 |
elements = self.content["value"].getcontent() |
2 | 1338 |
while i < len(elements) and not removed: |
151 | 1339 |
if elements[i]["value"].getlocalId() == id: |
1340 |
self.content["value"].removecontent(i) |
|
2 | 1341 |
removed = True |
1342 |
i += 1 |
|
1343 |
if not removed: |
|
427 | 1344 |
raise ValueError, _("Instance with id %d doesn't exist!")%id |
2 | 1345 |
else: |
1346 |
raise TypeError, "%s body don't have instances!"%self.content["name"] |
|
151 | 1347 |
setattr(cls, "removecontentInstance", removecontentInstance) |
1348 |
||
1349 |
def settext(self, text): |
|
2 | 1350 |
if self.content["name"] in ["IL","ST"]: |
151 | 1351 |
self.content["value"].settext(text) |
2 | 1352 |
else: |
391 | 1353 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
151 | 1354 |
setattr(cls, "settext", settext) |
1355 |
||
1356 |
def gettext(self): |
|
2 | 1357 |
if self.content["name"] in ["IL","ST"]: |
151 | 1358 |
return self.content["value"].gettext() |
2 | 1359 |
else: |
391 | 1360 |
raise TypeError, _("%s body don't have text!")%self.content["name"] |
151 | 1361 |
setattr(cls, "gettext", gettext) |
58 | 1362 |
|
1363 |
def updateElementName(self, old_name, new_name): |
|
1364 |
if self.content["name"] in ["IL", "ST"]: |
|
1365 |
self.content["value"].updateElementName(old_name, new_name) |
|
1366 |
else: |
|
151 | 1367 |
for element in self.content["value"].getcontent(): |
58 | 1368 |
element["value"].updateElementName(old_name, new_name) |
1369 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1370 |
|
151 | 1371 |
def getx(self): |
1372 |
return self.position.getx() |
|
1373 |
||
1374 |
def gety(self): |
|
1375 |
return self.position.gety() |
|
1376 |
||
1377 |
def setx(self, x): |
|
1378 |
self.position.setx(x) |
|
1379 |
||
1380 |
def sety(self, y): |
|
1381 |
self.position.sety(y) |
|
1382 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1383 |
def _getBoundingBox(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1384 |
return rect(self.getx(), self.gety(), self.getwidth(), self.getheight()) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1385 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1386 |
def _getConnectionsBoundingBox(connectionPointIn): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1387 |
bbox = rect() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1388 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1389 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1390 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1391 |
for x, y in connection.getpoints(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1392 |
bbox.update(x, y) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1393 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1394 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1395 |
def _getBoundingBoxSingle(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1396 |
bbox = _getBoundingBox(self) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1397 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1398 |
bbox.union(_getConnectionsBoundingBox(self.connectionPointIn)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1399 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1400 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1401 |
def _getBoundingBoxMultiple(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1402 |
bbox = _getBoundingBox(self) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1403 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1404 |
bbox.union(_getConnectionsBoundingBox(connectionPointIn)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1405 |
return bbox |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1406 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1407 |
def _filterConnections(connectionPointIn, localId, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1408 |
in_connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1409 |
if in_connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1410 |
to_delete = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1411 |
for i, connection in enumerate(in_connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1412 |
connected = connection.getrefLocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1413 |
if not connections.has_key((localId, connected)) and \ |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1414 |
not connections.has_key((connected, localId)): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1415 |
to_delete.append(i) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1416 |
to_delete.reverse() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1417 |
for i in to_delete: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1418 |
connectionPointIn.removeconnection(i) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1419 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1420 |
def _filterConnectionsSingle(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1421 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1422 |
_filterConnections(self.connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1423 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1424 |
def _filterConnectionsMultiple(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1425 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1426 |
_filterConnections(connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1427 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1428 |
def _getconnectionsdefinition(instance, connections_end): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1429 |
id = instance.getlocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1430 |
return dict([((id, end), True) for end in connections_end]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1431 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1432 |
def _updateConnectionsId(connectionPointIn, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1433 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1434 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1435 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1436 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1437 |
refLocalId = connection.getrefLocalId() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1438 |
new_reflocalId = translation.get(refLocalId, refLocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1439 |
connection.setrefLocalId(new_reflocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1440 |
connections_end.append(new_reflocalId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1441 |
return connections_end |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1442 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1443 |
def _updateConnectionsIdSingle(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1444 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1445 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1446 |
connections_end = _updateConnectionsId(self.connectionPointIn, translation) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1447 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1448 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1449 |
def _updateConnectionsIdMultiple(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1450 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1451 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1452 |
connections_end.extend(_updateConnectionsId(connectionPointIn, translation)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1453 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1454 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1455 |
def _translate(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1456 |
self.setx(self.getx() + dx) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1457 |
self.sety(self.gety() + dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1458 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1459 |
def _translateConnections(connectionPointIn, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1460 |
connections = connectionPointIn.getconnections() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1461 |
if connections is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1462 |
for connection in connections: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1463 |
for position in connection.getposition(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1464 |
position.setx(position.getx() + dx) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1465 |
position.sety(position.gety() + dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1466 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1467 |
def _translateSingle(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1468 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1469 |
if self.connectionPointIn is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1470 |
_translateConnections(self.connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1471 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1472 |
def _translateMultiple(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1473 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1474 |
for connectionPointIn in self.getconnectionPointIn(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1475 |
_translateConnections(connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1476 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1477 |
def _updateElementName(self, old_name, new_name): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1478 |
pass |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1479 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1480 |
_connectionsFunctions = { |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1481 |
"bbox": {"none": _getBoundingBox, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1482 |
"single": _getBoundingBoxSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1483 |
"multiple": _getBoundingBoxMultiple}, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1484 |
"translate": {"none": _translate, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1485 |
"single": _translateSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1486 |
"multiple": _translateMultiple}, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1487 |
"filter": {"none": lambda self, connections: None, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1488 |
"single": _filterConnectionsSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1489 |
"multiple": _filterConnectionsMultiple}, |
387 | 1490 |
"update": {"none": lambda self, translation: {}, |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1491 |
"single": _updateConnectionsIdSingle, |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1492 |
"multiple": _updateConnectionsIdMultiple} |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1493 |
} |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1494 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1495 |
def _initElementClass(name, classname, connectionPointInType="none"): |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1496 |
ElementNameToClass[name] = classname |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1497 |
cls = PLCOpenClasses.get(classname, None) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1498 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1499 |
setattr(cls, "getx", getx) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1500 |
setattr(cls, "gety", gety) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1501 |
setattr(cls, "setx", setx) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1502 |
setattr(cls, "sety", sety) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1503 |
setattr(cls, "updateElementName", _updateElementName) |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1504 |
setattr(cls, "getBoundingBox", _connectionsFunctions["bbox"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1505 |
setattr(cls, "translate", _connectionsFunctions["translate"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1506 |
setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1507 |
setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1508 |
return cls |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1509 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1510 |
def _getexecutionOrder(instance, specific_values): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1511 |
executionOrder = instance.getexecutionOrderId() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1512 |
if executionOrder is None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1513 |
executionOrder = 0 |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1514 |
specific_values["executionOrder"] = executionOrder |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1515 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1516 |
def _getdefaultmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1517 |
infos["negated"] = instance.getnegated() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1518 |
infos["edge"] = instance.getedge() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1519 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1520 |
def _getinputmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1521 |
infos["negated"] = instance.getnegatedIn() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1522 |
infos["edge"] = instance.getedgeIn() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1523 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1524 |
def _getoutputmodifiers(instance, infos): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1525 |
infos["negated"] = instance.getnegatedOut() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1526 |
infos["edge"] = instance.getedgeOut() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1527 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1528 |
MODIFIERS_FUNCTIONS = {"default": _getdefaultmodifiers, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1529 |
"input": _getinputmodifiers, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1530 |
"output": _getoutputmodifiers} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1531 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1532 |
def _getconnectioninfos(instance, connection, links=False, modifiers=None, parameter=False): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1533 |
infos = {"position": connection.getrelPositionXY()} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1534 |
if parameter: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1535 |
infos["name"] = instance.getformalParameter() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1536 |
MODIFIERS_FUNCTIONS.get(modifiers, lambda x, y: None)(instance, infos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1537 |
if links: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1538 |
infos["links"] = [] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1539 |
connections = connection.getconnections() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1540 |
if connections is not None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1541 |
for link in connections: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1542 |
dic = {"refLocalId": link.getrefLocalId(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1543 |
"points": link.getpoints(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1544 |
"formalParameter": link.getformalParameter()} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1545 |
infos["links"].append(dic) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1546 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1547 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1548 |
def _getelementinfos(instance): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1549 |
return {"id": instance.getlocalId(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1550 |
"x": instance.getx(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1551 |
"y": instance.gety(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1552 |
"height": instance.getheight(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1553 |
"width": instance.getwidth(), |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1554 |
"specific_values": {}, |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1555 |
"inputs": [], |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1556 |
"outputs": []} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1557 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1558 |
def _getvariableinfosFunction(type, input, output): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1559 |
def getvariableinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1560 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1561 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1562 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1563 |
specific_values["name"] = self.getexpression() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1564 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1565 |
if input and output: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1566 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1567 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1568 |
elif input: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1569 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "default")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1570 |
elif output: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1571 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1572 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1573 |
return getvariableinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1574 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1575 |
def _getconnectorinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1576 |
def getvariableinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1577 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1578 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1579 |
infos["specific_values"]["name"] = self.getname() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1580 |
if type == "connector": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1581 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1582 |
elif type == "continuation": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1583 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1584 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1585 |
return getvariableinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1586 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1587 |
def _getpowerrailinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1588 |
def getpowerrailinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1589 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1590 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1591 |
if type == "rightPowerRail": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1592 |
for connectionPointIn in self.getconnectionPointIn(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1593 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1594 |
infos["specific_values"]["connectors"] = [True for input in infos["inputs"]] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1595 |
elif type == "leftPowerRail": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1596 |
for connectionPointOut in self.getconnectionPointOut(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1597 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1598 |
infos["specific_values"]["connectors"] = [True for output in infos["outputs"]] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1599 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1600 |
return getpowerrailinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1601 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1602 |
def _getldelementinfosFunction(type): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1603 |
def getldelementinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1604 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1605 |
infos["type"] = type |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1606 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1607 |
specific_values["name"] = self.getvariable() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1608 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1609 |
specific_values["negated"] = self.getnegated() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1610 |
specific_values["edge"] = self.getedge() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1611 |
if type == "coil": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1612 |
specific_values["storage"] = self.getstorage() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1613 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1614 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1615 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1616 |
return getldelementinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1617 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1618 |
DIVERGENCE_TYPES = {(True, True): "simultaneousDivergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1619 |
(True, False): "selectionDivergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1620 |
(False, True): "simultaneousConvergence", |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1621 |
(False, False): "selectionConvergence"} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1622 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1623 |
def _getdivergenceinfosFunction(divergence, simultaneous): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1624 |
def getdivergenceinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1625 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1626 |
infos["type"] = DIVERGENCE_TYPES[(divergence, simultaneous)] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1627 |
if divergence: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1628 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1629 |
for connectionPointOut in self.getconnectionPointOut(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1630 |
infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1631 |
infos["specific_values"]["connectors"] = len(infos["outputs"]) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1632 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1633 |
for connectionPointIn in self.getconnectionPointIn(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1634 |
infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1635 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1636 |
infos["specific_values"]["connectors"] = len(infos["inputs"]) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1637 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1638 |
return getdivergenceinfos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1639 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1640 |
cls = _initElementClass("comment", "commonObjects_comment") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1641 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1642 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1643 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1644 |
infos["type"] = "comment" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1645 |
infos["specific_values"]["content"] = self.getcontentText() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1646 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1647 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1648 |
|
151 | 1649 |
def setcontentText(self, text): |
1650 |
self.content.settext(text) |
|
1651 |
setattr(cls, "setcontentText", setcontentText) |
|
0 | 1652 |
|
151 | 1653 |
def getcontentText(self): |
1654 |
return self.content.gettext() |
|
1655 |
setattr(cls, "getcontentText", getcontentText) |
|
58 | 1656 |
|
1657 |
def updateElementName(self, old_name, new_name): |
|
1658 |
self.content.updateElementName(old_name, new_name) |
|
1659 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1660 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1661 |
cls = _initElementClass("block", "fbdObjects_block") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1662 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1663 |
def getBoundingBox(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1664 |
bbox = _getBoundingBox(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1665 |
for input in self.inputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1666 |
bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1667 |
return bbox |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1668 |
setattr(cls, "getBoundingBox", getBoundingBox) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1669 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1670 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1671 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1672 |
infos["type"] = self.gettypeName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1673 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1674 |
specific_values["name"] = self.getinstanceName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1675 |
_getexecutionOrder(self, specific_values) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1676 |
for variable in self.inputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1677 |
infos["inputs"].append(_getconnectioninfos(variable, variable.connectionPointIn, True, "default", True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1678 |
for variable in self.outputVariables.getvariable(): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1679 |
infos["outputs"].append(_getconnectioninfos(variable, variable.connectionPointOut, False, "default", True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1680 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1681 |
setattr(cls, "getinfos", getinfos) |
2 | 1682 |
|
58 | 1683 |
def updateElementName(self, old_name, new_name): |
1684 |
if self.typeName == old_name: |
|
1685 |
self.typeName = new_name |
|
1686 |
setattr(cls, "updateElementName", updateElementName) |
|
1687 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1688 |
def filterConnections(self, connections): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1689 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1690 |
_filterConnections(input.connectionPointIn, self.localId, connections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1691 |
setattr(cls, "filterConnections", filterConnections) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1692 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1693 |
def updateConnectionsId(self, translation): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1694 |
connections_end = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1695 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1696 |
connections_end.extend(_updateConnectionsId(input.connectionPointIn, translation)) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1697 |
return _getconnectionsdefinition(self, connections_end) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1698 |
setattr(cls, "updateConnectionsId", updateConnectionsId) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1699 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1700 |
def translate(self, dx, dy): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1701 |
_translate(self, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1702 |
for input in self.inputVariables.getvariable(): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1703 |
_translateConnections(input.connectionPointIn, dx, dy) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1704 |
setattr(cls, "translate", translate) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
383
diff
changeset
|
1705 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1706 |
cls = _initElementClass("leftPowerRail", "ldObjects_leftPowerRail") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1707 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1708 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("leftPowerRail")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1709 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1710 |
cls = _initElementClass("rightPowerRail", "ldObjects_rightPowerRail", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1711 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1712 |
setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1713 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1714 |
cls = _initElementClass("contact", "ldObjects_contact", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1715 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1716 |
setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1717 |
|
58 | 1718 |
def updateElementName(self, old_name, new_name): |
1719 |
if self.variable == old_name: |
|
1720 |
self.variable = new_name |
|
1721 |
setattr(cls, "updateElementName", updateElementName) |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1722 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1723 |
cls = _initElementClass("coil", "ldObjects_coil", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1724 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1725 |
setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1726 |
|
58 | 1727 |
def updateElementName(self, old_name, new_name): |
1728 |
if self.variable == old_name: |
|
1729 |
self.variable = new_name |
|
1730 |
setattr(cls, "updateElementName", updateElementName) |
|
1731 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1732 |
cls = _initElementClass("step", "sfcObjects_step", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1733 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1734 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1735 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1736 |
infos["type"] = "step" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1737 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1738 |
specific_values["name"] = self.getname() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1739 |
specific_values["initial"] = self.getinitialStep() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1740 |
if self.connectionPointIn: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1741 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1742 |
if self.connectionPointOut: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1743 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1744 |
if self.connectionPointOutAction: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1745 |
specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1746 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1747 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1748 |
|
389 | 1749 |
cls = PLCOpenClasses.get("transition_condition", None) |
1750 |
if cls: |
|
1751 |
def compatibility(self, tree): |
|
1752 |
connections = [] |
|
1753 |
for child in tree.childNodes: |
|
1754 |
if child.nodeName == "connection": |
|
1755 |
connections.append(child) |
|
1756 |
if len(connections) > 0: |
|
1757 |
node = CreateNode("connectionPointIn") |
|
1758 |
relPosition = CreateNode("relPosition") |
|
1759 |
NodeSetAttr(relPosition, "x", "0") |
|
1760 |
NodeSetAttr(relPosition, "y", "0") |
|
1761 |
node.childNodes.append(relPosition) |
|
1762 |
node.childNodes.extend(connections) |
|
1763 |
tree.childNodes = [node] |
|
1764 |
setattr(cls, "compatibility", compatibility) |
|
1765 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1766 |
cls = _initElementClass("transition", "sfcObjects_transition", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1767 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1768 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1769 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1770 |
infos["type"] = "transition" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1771 |
specific_values = infos["specific_values"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1772 |
priority = self.getpriority() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1773 |
if priority is None: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1774 |
priority = 0 |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1775 |
specific_values["priority"] = priority |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1776 |
condition = self.getconditionContent() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1777 |
specific_values["condition_type"] = condition["type"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1778 |
if specific_values["condition_type"] == "connection": |
389 | 1779 |
specific_values["connection"] = _getconnectioninfos(self, condition["value"], True) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1780 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1781 |
specific_values["condition"] = condition["value"] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1782 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1783 |
infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1784 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1785 |
setattr(cls, "getinfos", getinfos) |
151 | 1786 |
|
1787 |
def setconditionContent(self, type, value): |
|
2 | 1788 |
if not self.condition: |
151 | 1789 |
self.addcondition() |
2 | 1790 |
if type == "reference": |
1791 |
condition = PLCOpenClasses["condition_reference"]() |
|
151 | 1792 |
condition.setname(value) |
2 | 1793 |
elif type == "inline": |
1794 |
condition = PLCOpenClasses["condition_inline"]() |
|
151 | 1795 |
condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
1796 |
condition.settext(value) |
|
69 | 1797 |
elif type == "connection": |
389 | 1798 |
type = "connectionPointIn" |
1799 |
condition = PLCOpenClasses["connectionPointIn"]() |
|
151 | 1800 |
self.condition.setcontent({"name" : type, "value" : condition}) |
1801 |
setattr(cls, "setconditionContent", setconditionContent) |
|
0 | 1802 |
|
151 | 1803 |
def getconditionContent(self): |
2 | 1804 |
if self.condition: |
151 | 1805 |
content = self.condition.getcontent() |
2 | 1806 |
values = {"type" : content["name"]} |
1807 |
if values["type"] == "reference": |
|
151 | 1808 |
values["value"] = content["value"].getname() |
2 | 1809 |
elif values["type"] == "inline": |
151 | 1810 |
values["value"] = content["value"].gettext() |
389 | 1811 |
elif values["type"] == "connectionPointIn": |
1812 |
values["type"] = "connection" |
|
1813 |
values["value"] = content["value"] |
|
2 | 1814 |
return values |
1815 |
return "" |
|
151 | 1816 |
setattr(cls, "getconditionContent", getconditionContent) |
2 | 1817 |
|
58 | 1818 |
def updateElementName(self, old_name, new_name): |
1819 |
if self.condition: |
|
151 | 1820 |
content = self.condition.getcontent() |
58 | 1821 |
if content["name"] == "reference": |
151 | 1822 |
if content["value"].getname() == old_name: |
1823 |
content["value"].setname(new_name) |
|
58 | 1824 |
elif content["name"] == "inline": |
1825 |
content["value"].updateElementName(old_name, new_name) |
|
1826 |
setattr(cls, "updateElementName", updateElementName) |
|
1827 |
||
151 | 1828 |
def getconnections(self): |
63
04a02b4b2a57
Adding support for connecting transition to LD rung and FBD network
lbessard
parents:
58
diff
changeset
|
1829 |
if self.condition: |
151 | 1830 |
content = self.condition.getcontent() |
389 | 1831 |
if content["name"] == "connectionPointIn": |
1832 |
return content["value"].getconnections() |
|
151 | 1833 |
setattr(cls, "getconnections", getconnections) |
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1834 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1835 |
cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1836 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1837 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1838 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1839 |
cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1840 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1841 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1842 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1843 |
cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1844 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1845 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1846 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1847 |
cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1848 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1849 |
setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1850 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1851 |
cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1852 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1853 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1854 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1855 |
infos["type"] = "jump" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1856 |
infos["specific_values"]["target"] = self.gettargetName() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1857 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1858 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1859 |
setattr(cls, "getinfos", getinfos) |
58 | 1860 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
1861 |
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
|
1862 |
if cls: |
389 | 1863 |
def compatibility(self, tree): |
1864 |
relPosition = reduce(lambda x, y: x | (y.nodeName == "relPosition"), tree.childNodes, False) |
|
1865 |
if not tree.hasAttribute("localId"): |
|
1866 |
NodeSetAttr(tree, "localId", "0") |
|
1867 |
if not relPosition: |
|
1868 |
node = CreateNode("relPosition") |
|
1869 |
NodeSetAttr(node, "x", "0") |
|
1870 |
NodeSetAttr(node, "y", "0") |
|
1871 |
tree.childNodes.insert(0, node) |
|
1872 |
setattr(cls, "compatibility", compatibility) |
|
1873 |
||
151 | 1874 |
def setreferenceName(self, name): |
1875 |
if self.reference: |
|
1876 |
self.reference.setname(name) |
|
1877 |
setattr(cls, "setreferenceName", setreferenceName) |
|
1878 |
||
1879 |
def getreferenceName(self): |
|
1880 |
if self.reference: |
|
1881 |
return self.reference.getname() |
|
2 | 1882 |
return None |
151 | 1883 |
setattr(cls, "getreferenceName", getreferenceName) |
1884 |
||
1885 |
def setinlineContent(self, content): |
|
1886 |
if self.inline: |
|
1887 |
self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()}) |
|
1888 |
self.inline.settext(content) |
|
1889 |
setattr(cls, "setinlineContent", setinlineContent) |
|
1890 |
||
1891 |
def getinlineContent(self): |
|
1892 |
if self.inline: |
|
1893 |
return self.inline.gettext() |
|
2 | 1894 |
return None |
151 | 1895 |
setattr(cls, "getinlineContent", getinlineContent) |
1896 |
||
1897 |
def updateElementName(self, old_name, new_name): |
|
1898 |
if self.reference and self.reference.getname() == old_name: |
|
1899 |
self.reference.setname(new_name) |
|
58 | 1900 |
if self.inline: |
1901 |
self.inline.updateElementName(old_name, new_name) |
|
1902 |
setattr(cls, "updateElementName", updateElementName) |
|
1903 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1904 |
cls = _initElementClass("actionBlock", "commonObjects_actionBlock", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1905 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1906 |
def compatibility(self, tree): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1907 |
for child in tree.childNodes[:]: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1908 |
if child.nodeName == "connectionPointOut": |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1909 |
tree.childNodes.remove(child) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1910 |
setattr(cls, "compatibility", compatibility) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1911 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1912 |
def getinfos(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1913 |
infos = _getelementinfos(self) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1914 |
infos["type"] = "actionBlock" |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1915 |
infos["specific_values"]["actions"] = self.getactions() |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1916 |
infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1917 |
return infos |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1918 |
setattr(cls, "getinfos", getinfos) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1919 |
|
151 | 1920 |
def setactions(self, actions): |
2 | 1921 |
self.action = [] |
1922 |
for params in actions: |
|
1923 |
action = PLCOpenClasses["actionBlock_action"]() |
|
151 | 1924 |
action.setqualifier(params["qualifier"]) |
2 | 1925 |
if params["type"] == "reference": |
151 | 1926 |
action.addreference() |
1927 |
action.setreferenceName(params["value"]) |
|
0 | 1928 |
else: |
151 | 1929 |
action.addinline() |
1930 |
action.setinlineContent(params["value"]) |
|
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
1931 |
if params.has_key("duration"): |
151 | 1932 |
action.setduration(params["duration"]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
348
diff
changeset
|
1933 |
if params.has_key("indicator"): |
151 | 1934 |
action.setindicator(params["indicator"]) |
2 | 1935 |
self.action.append(action) |
151 | 1936 |
setattr(cls, "setactions", setactions) |
1937 |
||
1938 |
def getactions(self): |
|
2 | 1939 |
actions = [] |
1940 |
for action in self.action: |
|
1941 |
params = {} |
|
151 | 1942 |
params["qualifier"] = action.getqualifier() |
108 | 1943 |
if params["qualifier"] is None: |
1944 |
params["qualifier"] = "N" |
|
151 | 1945 |
if action.getreference(): |
2 | 1946 |
params["type"] = "reference" |
151 | 1947 |
params["value"] = action.getreferenceName() |
1948 |
elif action.getinline(): |
|
2 | 1949 |
params["type"] = "inline" |
151 | 1950 |
params["value"] = action.getinlineContent() |
1951 |
duration = action.getduration() |
|
2 | 1952 |
if duration: |
1953 |
params["duration"] = duration |
|
151 | 1954 |
indicator = action.getindicator() |
2 | 1955 |
if indicator: |
1956 |
params["indicator"] = indicator |
|
1957 |
actions.append(params) |
|
1958 |
return actions |
|
151 | 1959 |
setattr(cls, "getactions", getactions) |
2 | 1960 |
|
58 | 1961 |
def updateElementName(self, old_name, new_name): |
1962 |
for action in self.action: |
|
1963 |
action.updateElementName(old_name, new_name) |
|
1964 |
setattr(cls, "updateElementName", updateElementName) |
|
1965 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1966 |
cls = _initElementClass("inVariable", "fbdObjects_inVariable") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1967 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1968 |
setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
58 | 1969 |
|
1970 |
def updateElementName(self, old_name, new_name): |
|
1971 |
if self.expression == old_name: |
|
1972 |
self.expression = new_name |
|
1973 |
setattr(cls, "updateElementName", updateElementName) |
|
2 | 1974 |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1975 |
cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1976 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1977 |
setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1978 |
|
58 | 1979 |
def updateElementName(self, old_name, new_name): |
1980 |
if self.expression == old_name: |
|
1981 |
self.expression = new_name |
|
1982 |
setattr(cls, "updateElementName", updateElementName) |
|
1983 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1984 |
cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1985 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1986 |
setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1987 |
|
58 | 1988 |
def updateElementName(self, old_name, new_name): |
1989 |
if self.expression == old_name: |
|
1990 |
self.expression = new_name |
|
1991 |
setattr(cls, "updateElementName", updateElementName) |
|
1992 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1993 |
cls = _initElementClass("continuation", "commonObjects_continuation") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1994 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1995 |
setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1996 |
|
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1997 |
cls = _initElementClass("connector", "commonObjects_connector", "single") |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1998 |
if cls: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
1999 |
setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
2 | 2000 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2001 |
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
|
2002 |
if cls: |
151 | 2003 |
def setpoints(self, points): |
2 | 2004 |
self.position = [] |
2005 |
for point in points: |
|
2006 |
position = PLCOpenClasses["position"]() |
|
151 | 2007 |
position.setx(point.x) |
2008 |
position.sety(point.y) |
|
2 | 2009 |
self.position.append(position) |
151 | 2010 |
setattr(cls, "setpoints", setpoints) |
2011 |
||
2012 |
def getpoints(self): |
|
2 | 2013 |
points = [] |
2014 |
for position in self.position: |
|
151 | 2015 |
points.append((position.getx(),position.gety())) |
2 | 2016 |
return points |
151 | 2017 |
setattr(cls, "getpoints", getpoints) |
2 | 2018 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2019 |
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
|
2020 |
if cls: |
151 | 2021 |
def setrelPositionXY(self, x, y): |
2 | 2022 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 2023 |
self.relPosition.setx(x) |
2024 |
self.relPosition.sety(y) |
|
2025 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2026 |
||
2027 |
def getrelPositionXY(self): |
|
2 | 2028 |
if self.relPosition: |
151 | 2029 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 2030 |
else: |
0 | 2031 |
return self.relPosition |
151 | 2032 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2033 |
||
2034 |
def addconnection(self): |
|
2 | 2035 |
if not self.content: |
151 | 2036 |
self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]} |
2 | 2037 |
else: |
2038 |
self.content["value"].append(PLCOpenClasses["connection"]()) |
|
151 | 2039 |
setattr(cls, "addconnection", addconnection) |
2040 |
||
2041 |
def removeconnection(self, idx): |
|
2 | 2042 |
if self.content: |
2043 |
self.content["value"].pop(idx) |
|
2044 |
if len(self.content["value"]) == 0: |
|
2045 |
self.content = None |
|
151 | 2046 |
setattr(cls, "removeconnection", removeconnection) |
2047 |
||
2048 |
def removeconnections(self): |
|
2 | 2049 |
if self.content: |
2050 |
self.content = None |
|
151 | 2051 |
setattr(cls, "removeconnections", removeconnections) |
2052 |
||
2053 |
def getconnections(self): |
|
2 | 2054 |
if self.content: |
2055 |
return self.content["value"] |
|
151 | 2056 |
setattr(cls, "getconnections", getconnections) |
2057 |
||
2058 |
def setconnectionId(self, idx, id): |
|
2 | 2059 |
if self.content: |
151 | 2060 |
self.content["value"][idx].setrefLocalId(id) |
2061 |
setattr(cls, "setconnectionId", setconnectionId) |
|
2062 |
||
2063 |
def getconnectionId(self, idx): |
|
2 | 2064 |
if self.content: |
151 | 2065 |
return self.content["value"][idx].getrefLocalId() |
2 | 2066 |
return None |
151 | 2067 |
setattr(cls, "getconnectionId", getconnectionId) |
2068 |
||
2069 |
def setconnectionPoints(self, idx, points): |
|
2 | 2070 |
if self.content: |
151 | 2071 |
self.content["value"][idx].setpoints(points) |
2072 |
setattr(cls, "setconnectionPoints", setconnectionPoints) |
|
2073 |
||
2074 |
def getconnectionPoints(self, idx): |
|
2 | 2075 |
if self.content: |
151 | 2076 |
return self.content["value"][idx].getpoints() |
2 | 2077 |
return None |
151 | 2078 |
setattr(cls, "getconnectionPoints", getconnectionPoints) |
2079 |
||
2080 |
def setconnectionParameter(self, idx, parameter): |
|
27 | 2081 |
if self.content: |
151 | 2082 |
self.content["value"][idx].setformalParameter(parameter) |
2083 |
setattr(cls, "setconnectionParameter", setconnectionParameter) |
|
2084 |
||
2085 |
def getconnectionParameter(self, idx): |
|
27 | 2086 |
if self.content: |
151 | 2087 |
return self.content["value"][idx].getformalParameter() |
27 | 2088 |
return None |
151 | 2089 |
setattr(cls, "getconnectionParameter", getconnectionParameter) |
27 | 2090 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2091 |
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
|
2092 |
if cls: |
151 | 2093 |
def setrelPositionXY(self, x, y): |
2 | 2094 |
self.relPosition = PLCOpenClasses["position"]() |
151 | 2095 |
self.relPosition.setx(x) |
2096 |
self.relPosition.sety(y) |
|
2097 |
setattr(cls, "setrelPositionXY", setrelPositionXY) |
|
2098 |
||
2099 |
def getrelPositionXY(self): |
|
2 | 2100 |
if self.relPosition: |
151 | 2101 |
return self.relPosition.getx(), self.relPosition.gety() |
2 | 2102 |
return self.relPosition |
151 | 2103 |
setattr(cls, "getrelPositionXY", getrelPositionXY) |
2 | 2104 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2105 |
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
|
2106 |
if cls: |
151 | 2107 |
def setvalue(self, value): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2108 |
if value.startswith("[") and value.endswith("]"): |
2 | 2109 |
arrayValue = PLCOpenClasses["value_arrayValue"]() |
151 | 2110 |
self.content = {"name" : "arrayValue", "value" : arrayValue} |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2111 |
elif value.startswith("(") and value.endswith(")"): |
2 | 2112 |
structValue = PLCOpenClasses["value_structValue"]() |
151 | 2113 |
self.content = {"name" : "structValue", "value" : structValue} |
2 | 2114 |
else: |
2115 |
simpleValue = PLCOpenClasses["value_simpleValue"]() |
|
151 | 2116 |
self.content = {"name" : "simpleValue", "value": simpleValue} |
2117 |
self.content["value"].setvalue(value) |
|
2118 |
setattr(cls, "setvalue", setvalue) |
|
2119 |
||
2120 |
def getvalue(self): |
|
2121 |
return self.content["value"].getvalue() |
|
2122 |
setattr(cls, "getvalue", getvalue) |
|
2 | 2123 |
|
147 | 2124 |
def extractValues(values): |
145 | 2125 |
items = values.split(",") |
2126 |
i = 1 |
|
2127 |
while i < len(items): |
|
2128 |
opened = items[i - 1].count("(") + items[i - 1].count("[") |
|
2129 |
closed = items[i - 1].count(")") + items[i - 1].count("]") |
|
2130 |
if opened > closed: |
|
2131 |
items[i - 1] = ','.join([items[i - 1], items.pop(i)]) |
|
2132 |
elif opened == closed: |
|
2133 |
i += 1 |
|
2134 |
else: |
|
391 | 2135 |
raise ValueError, _("\"%s\" is an invalid value!")%value |
145 | 2136 |
return items |
2137 |
||
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2138 |
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
|
2139 |
if cls: |
145 | 2140 |
arrayValue_model = re.compile("([0-9]*)\((.*)\)$") |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2141 |
|
151 | 2142 |
def setvalue(self, value): |
2 | 2143 |
self.value = [] |
145 | 2144 |
for item in extractValues(value[1:-1]): |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2145 |
item = item.strip() |
2 | 2146 |
element = PLCOpenClasses["arrayValue_value"]() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2147 |
result = arrayValue_model.match(item) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2148 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2149 |
groups = result.groups() |
389 | 2150 |
element.setrepetitionValue(groups[0]) |
151 | 2151 |
element.setvalue(groups[1].strip()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2152 |
else: |
151 | 2153 |
element.setvalue(item) |
2 | 2154 |
self.value.append(element) |
151 | 2155 |
setattr(cls, "setvalue", setvalue) |
2156 |
||
2157 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2158 |
values = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2159 |
for element in self.value: |
151 | 2160 |
repetition = element.getrepetitionValue() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2161 |
if repetition is not None and repetition > 1: |
389 | 2162 |
values.append("%s(%s)"%(repetition, element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2163 |
else: |
151 | 2164 |
values.append(element.getvalue()) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2165 |
return "[%s]"%", ".join(values) |
151 | 2166 |
setattr(cls, "getvalue", getvalue) |
2 | 2167 |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
63
diff
changeset
|
2168 |
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
|
2169 |
if cls: |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2170 |
structValue_model = re.compile("(.*):=(.*)") |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2171 |
|
151 | 2172 |
def setvalue(self, value): |
2 | 2173 |
self.value = [] |
145 | 2174 |
for item in extractValues(value[1:-1]): |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
2175 |
result = structValue_model.match(item) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2176 |
if result is not None: |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2177 |
groups = result.groups() |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2178 |
element = PLCOpenClasses["structValue_value"]() |
151 | 2179 |
element.setmember(groups[0].strip()) |
2180 |
element.setvalue(groups[1].strip()) |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
286
diff
changeset
|
2181 |
self.value.append(element) |
151 | 2182 |
setattr(cls, "setvalue", setvalue) |
2183 |
||
2184 |
def getvalue(self): |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2185 |
values = [] |
2 | 2186 |
for element in self.value: |
151 | 2187 |
values.append("%s := %s"%(element.getmember(), element.getvalue())) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
118
diff
changeset
|
2188 |
return "(%s)"%", ".join(values) |
151 | 2189 |
setattr(cls, "getvalue", getvalue) |