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