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