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