author | Edouard Tisserant |
Wed, 31 Jul 2013 10:45:07 +0900 | |
branch | 1.1 Korean release |
changeset 1280 | 72a826dfcfbb |
parent 1184 | 891b49d2752b |
child 1308 | ad61268dbdb6 |
permissions | -rw-r--r-- |
814 | 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 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
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 |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
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 |
||
25 |
import os |
|
26 |
import re |
|
27 |
from types import TupleType, StringType, UnicodeType |
|
28 |
||
29 |
import wx |
|
30 |
import wx.grid |
|
31 |
import wx.lib.buttons |
|
32 |
||
33 |
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS |
|
34 |
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT |
|
35 |
from dialogs.ArrayTypeDialog import ArrayTypeDialog |
|
36 |
from CustomGrid import CustomGrid |
|
37 |
from CustomTable import CustomTable |
|
38 |
from LocationCellEditor import LocationCellEditor |
|
39 |
from util.BitmapLibrary import GetBitmap |
|
40 |
||
41 |
#------------------------------------------------------------------------------- |
|
42 |
# Helpers |
|
43 |
#------------------------------------------------------------------------------- |
|
44 |
||
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
45 |
def AppendMenu(parent, help, id, kind, text): |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
46 |
if wx.VERSION >= (2, 6, 0): |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
47 |
parent.Append(help=help, id=id, kind=kind, text=text) |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
48 |
else: |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
49 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
50 |
|
814 | 51 |
[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
52 |
POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
53 |
] = range(10) |
814 | 54 |
|
55 |
def GetVariableTableColnames(location): |
|
56 |
_ = lambda x : x |
|
57 |
if location: |
|
58 |
return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")] |
|
59 |
return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")] |
|
60 |
||
61 |
def GetOptions(constant=True, retain=True, non_retain=True): |
|
62 |
_ = lambda x : x |
|
63 |
options = [""] |
|
64 |
if constant: |
|
65 |
options.append(_("Constant")) |
|
66 |
if retain: |
|
67 |
options.append(_("Retain")) |
|
68 |
if non_retain: |
|
69 |
options.append(_("Non-Retain")) |
|
70 |
return options |
|
71 |
OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()]) |
|
72 |
||
73 |
def GetFilterChoiceTransfer(): |
|
74 |
_ = lambda x : x |
|
75 |
return {_("All"): _("All"), _("Interface"): _("Interface"), |
|
76 |
_(" Input"): _("Input"), _(" Output"): _("Output"), _(" InOut"): _("InOut"), |
|
77 |
_(" External"): _("External"), _("Variables"): _("Variables"), _(" Local"): _("Local"), |
|
78 |
_(" Temp"): _("Temp"), _("Global"): _("Global")}#, _("Access") : _("Access")} |
|
79 |
VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().iterkeys()]) |
|
80 |
VARIABLE_CLASSES_DICT = dict([(_(_class), _class) for _class in GetFilterChoiceTransfer().itervalues()]) |
|
81 |
||
82 |
CheckOptionForClass = {"Local": lambda x: x, |
|
83 |
"Temp": lambda x: "", |
|
84 |
"Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
|
85 |
"InOut": lambda x: "", |
|
86 |
"Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""), |
|
87 |
"Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""), |
|
88 |
"External": lambda x: {"Constant": "Constant"}.get(x, "") |
|
89 |
} |
|
90 |
||
91 |
LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$") |
|
1122
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
92 |
VARIABLE_NAME_SUFFIX_MODEL = re.compile("([0-9]*)$") |
814 | 93 |
|
94 |
#------------------------------------------------------------------------------- |
|
95 |
# Variables Panel Table |
|
96 |
#------------------------------------------------------------------------------- |
|
97 |
||
98 |
class VariableTable(CustomTable): |
|
99 |
||
100 |
""" |
|
101 |
A custom wx.grid.Grid Table using user supplied data |
|
102 |
""" |
|
103 |
def __init__(self, parent, data, colnames): |
|
104 |
# The base class must be initialized *first* |
|
105 |
CustomTable.__init__(self, parent, data, colnames) |
|
106 |
self.old_value = None |
|
107 |
||
108 |
def GetValue(self, row, col): |
|
109 |
if row < self.GetNumberRows(): |
|
110 |
if col == 0: |
|
111 |
return self.data[row]["Number"] |
|
112 |
colname = self.GetColLabelValue(col, False) |
|
113 |
value = self.data[row].get(colname, "") |
|
114 |
if colname == "Type" and isinstance(value, TupleType): |
|
115 |
if value[0] == "array": |
|
116 |
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1]) |
|
117 |
if not isinstance(value, (StringType, UnicodeType)): |
|
118 |
value = str(value) |
|
119 |
if colname in ["Class", "Option"]: |
|
120 |
return _(value) |
|
121 |
return value |
|
122 |
||
123 |
def SetValue(self, row, col, value): |
|
124 |
if col < len(self.colnames): |
|
125 |
colname = self.GetColLabelValue(col, False) |
|
126 |
if colname == "Name": |
|
127 |
self.old_value = self.data[row][colname] |
|
128 |
elif colname == "Class": |
|
129 |
value = VARIABLE_CLASSES_DICT[value] |
|
130 |
self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option"))) |
|
131 |
if value == "External": |
|
132 |
self.SetValueByName(row, "Initial Value", "") |
|
133 |
elif colname == "Option": |
|
134 |
value = OPTIONS_DICT[value] |
|
135 |
self.data[row][colname] = value |
|
136 |
||
137 |
def GetOldValue(self): |
|
138 |
return self.old_value |
|
139 |
||
140 |
def _updateColAttrs(self, grid): |
|
141 |
""" |
|
142 |
wx.grid.Grid -> update the column attributes to add the |
|
143 |
appropriate renderer given the column name. |
|
144 |
||
145 |
Otherwise default to the default renderer. |
|
146 |
""" |
|
147 |
for row in range(self.GetNumberRows()): |
|
148 |
var_class = self.GetValueByName(row, "Class") |
|
149 |
var_type = self.GetValueByName(row, "Type") |
|
150 |
row_highlights = self.Highlights.get(row, {}) |
|
151 |
for col in range(self.GetNumberCols()): |
|
152 |
editor = None |
|
153 |
renderer = None |
|
154 |
colname = self.GetColLabelValue(col, False) |
|
155 |
if self.Parent.Debug: |
|
156 |
grid.SetReadOnly(row, col, True) |
|
157 |
else: |
|
158 |
if colname == "Option": |
|
159 |
options = GetOptions(constant = var_class in ["Local", "External", "Global"], |
|
160 |
retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
|
161 |
non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
|
162 |
if len(options) > 1: |
|
163 |
editor = wx.grid.GridCellChoiceEditor() |
|
164 |
editor.SetParameters(",".join(map(_, options))) |
|
165 |
else: |
|
166 |
grid.SetReadOnly(row, col, True) |
|
167 |
elif col != 0 and self.GetValueByName(row, "Edit"): |
|
168 |
grid.SetReadOnly(row, col, False) |
|
169 |
if colname == "Name": |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
170 |
editor = wx.grid.GridCellTextEditor() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
171 |
renderer = wx.grid.GridCellStringRenderer() |
814 | 172 |
elif colname == "Initial Value": |
173 |
if var_class not in ["External", "InOut"]: |
|
174 |
if self.Parent.Controler.IsEnumeratedType(var_type): |
|
175 |
editor = wx.grid.GridCellChoiceEditor() |
|
176 |
editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type))) |
|
177 |
else: |
|
178 |
editor = wx.grid.GridCellTextEditor() |
|
179 |
renderer = wx.grid.GridCellStringRenderer() |
|
180 |
else: |
|
181 |
grid.SetReadOnly(row, col, True) |
|
182 |
elif colname == "Location": |
|
183 |
if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type): |
|
184 |
editor = LocationCellEditor(self, self.Parent.Controler) |
|
185 |
renderer = wx.grid.GridCellStringRenderer() |
|
186 |
else: |
|
187 |
grid.SetReadOnly(row, col, True) |
|
188 |
elif colname == "Class": |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
189 |
if len(self.Parent.ClassList) == 1: |
814 | 190 |
grid.SetReadOnly(row, col, True) |
191 |
else: |
|
192 |
editor = wx.grid.GridCellChoiceEditor() |
|
193 |
excluded = [] |
|
194 |
if self.Parent.IsFunctionBlockType(var_type): |
|
195 |
excluded.extend(["Local","Temp"]) |
|
196 |
editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded])) |
|
197 |
elif colname != "Documentation": |
|
198 |
grid.SetReadOnly(row, col, True) |
|
199 |
||
200 |
grid.SetCellEditor(row, col, editor) |
|
201 |
grid.SetCellRenderer(row, col, renderer) |
|
202 |
||
831
dec885ba1f2b
Adding support for signaling that a task interval isn't well formatted
laurent
parents:
830
diff
changeset
|
203 |
if colname == "Location" and LOCATION_MODEL.match(self.GetValueByName(row, colname)) is None: |
814 | 204 |
highlight_colours = ERROR_HIGHLIGHT |
205 |
else: |
|
206 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
|
207 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
|
208 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
|
209 |
self.ResizeRow(grid, row) |
|
210 |
||
211 |
#------------------------------------------------------------------------------- |
|
212 |
# Variable Panel Drop Target |
|
213 |
#------------------------------------------------------------------------------- |
|
214 |
||
215 |
class VariableDropTarget(wx.TextDropTarget): |
|
216 |
''' |
|
217 |
This allows dragging a variable location from somewhere to the Location |
|
218 |
column of a variable row. |
|
219 |
||
220 |
The drag source should be a TextDataObject containing a Python tuple like: |
|
221 |
('%ID0.0.0', 'location', 'REAL') |
|
222 |
||
223 |
c_ext/CFileEditor.py has an example of this (you can drag a C extension |
|
224 |
variable to the Location column of the variable panel). |
|
225 |
''' |
|
226 |
def __init__(self, parent): |
|
227 |
wx.TextDropTarget.__init__(self) |
|
228 |
self.ParentWindow = parent |
|
229 |
||
230 |
def OnDropText(self, x, y, data): |
|
231 |
self.ParentWindow.ParentWindow.Select() |
|
232 |
x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y) |
|
233 |
col = self.ParentWindow.VariablesGrid.XToCol(x) |
|
234 |
row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize()) |
|
235 |
message = None |
|
236 |
element_type = self.ParentWindow.ElementType |
|
237 |
try: |
|
238 |
values = eval(data) |
|
239 |
except: |
|
240 |
message = _("Invalid value \"%s\" for variable grid element")%data |
|
241 |
values = None |
|
242 |
if not isinstance(values, TupleType): |
|
243 |
message = _("Invalid value \"%s\" for variable grid element")%data |
|
244 |
values = None |
|
245 |
if values is not None: |
|
246 |
if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
|
247 |
colname = self.ParentWindow.Table.GetColLabelValue(col, False) |
|
248 |
if colname == "Location" and values[1] == "location": |
|
249 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
250 |
message = _("Can't give a location to a function block instance") |
|
251 |
elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
|
252 |
message = _("Can only give a location to local or global variables") |
|
253 |
else: |
|
254 |
location = values[0] |
|
255 |
variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
|
256 |
base_type = self.ParentWindow.Controler.GetBaseType(variable_type) |
|
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
257 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
258 |
if values[2] is not None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
259 |
base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
260 |
if values[2] != variable_type and base_type != base_location_type: |
814 | 261 |
message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type) |
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
262 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
263 |
if message is None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
264 |
if not location.startswith("%"): |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
265 |
if location[0].isdigit() and base_type != "BOOL": |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
266 |
message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
267 |
elif location[0] not in LOCATIONDATATYPES: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
268 |
message = _("Unrecognized data size \"%s\"")%location[0] |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
269 |
elif base_type not in LOCATIONDATATYPES[location[0]]: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
270 |
message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type) |
814 | 271 |
else: |
830
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
272 |
dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
273 |
_("Select a variable class:"), _("Variable class"), |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
274 |
["Input", "Output", "Memory"], |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
275 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
276 |
if dialog.ShowModal() == wx.ID_OK: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
277 |
selected = dialog.GetSelection() |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
278 |
else: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
279 |
selected = None |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
280 |
dialog.Destroy() |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
281 |
if selected is None: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
282 |
return |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
283 |
if selected == 0: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
284 |
location = "%I" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
285 |
elif selected == 1: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
286 |
location = "%Q" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
287 |
else: |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
288 |
location = "%M" + location |
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
289 |
|
4b9df5bea400
Fix test of datatype consistency when drag'n dropping location in VariablePanel
laurent
parents:
814
diff
changeset
|
290 |
if message is None: |
814 | 291 |
self.ParentWindow.Table.SetValue(row, col, location) |
292 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
293 |
self.ParentWindow.SaveValues() |
|
294 |
elif colname == "Initial Value" and values[1] == "Constant": |
|
295 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
296 |
message = _("Can't set an initial value to a function block instance") |
|
297 |
else: |
|
298 |
self.ParentWindow.Table.SetValue(row, col, values[0]) |
|
299 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
300 |
self.ParentWindow.SaveValues() |
|
1140
80a91fc91595
Fixed bug when drag'n dropping global in function variable panel (not possible according to standard)
Laurent Bessard
parents:
1128
diff
changeset
|
301 |
elif (element_type not in ["config", "resource", "function"] and values[1] == "Global" and |
80a91fc91595
Fixed bug when drag'n dropping global in function variable panel (not possible according to standard)
Laurent Bessard
parents:
1128
diff
changeset
|
302 |
self.ParentWindow.Filter in ["All", "Interface", "External"] or |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
303 |
element_type != "function" and values[1] == "location"): |
814 | 304 |
if values[1] == "location": |
305 |
var_name = values[3] |
|
306 |
else: |
|
307 |
var_name = values[0] |
|
308 |
tagname = self.ParentWindow.GetTagName() |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
309 |
if var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
310 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
311 |
GetProjectPouNames(self.ParentWindow.Debug)]: |
814 | 312 |
message = _("\"%s\" pou already exists!")%var_name |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
313 |
elif not var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
314 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
315 |
GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
814 | 316 |
var_infos = self.ParentWindow.DefaultValue.copy() |
317 |
var_infos["Name"] = var_name |
|
318 |
var_infos["Type"] = values[2] |
|
319 |
if values[1] == "location": |
|
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
320 |
location = values[0] |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
321 |
if not location.startswith("%"): |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
322 |
dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
323 |
_("Select a variable class:"), _("Variable class"), |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
324 |
["Input", "Output", "Memory"], |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
325 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
326 |
if dialog.ShowModal() == wx.ID_OK: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
327 |
selected = dialog.GetSelection() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
328 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
329 |
selected = None |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
330 |
dialog.Destroy() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
331 |
if selected is None: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
332 |
return |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
333 |
if selected == 0: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
334 |
location = "%I" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
335 |
elif selected == 1: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
336 |
location = "%Q" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
337 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
338 |
location = "%M" + location |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
339 |
if element_type == "functionBlock": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
340 |
configs = self.ParentWindow.Controler.GetProjectConfigNames( |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
341 |
self.ParentWindow.Debug) |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
342 |
if len(configs) == 0: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
343 |
return |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
344 |
if not var_name.upper() in [name.upper() |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
345 |
for name in self.ParentWindow.Controler.\ |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
346 |
GetConfigurationVariableNames(configs[0])]: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
347 |
self.ParentWindow.Controler.AddConfigurationGlobalVar( |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
348 |
configs[0], values[2], var_name, location, "") |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
349 |
var_infos["Class"] = "External" |
1083
40af794ecd4b
Added support for adding a variable in program VariablePanel by drap'n dropping located variable like in global VariablePanel
Laurent Bessard
parents:
1016
diff
changeset
|
350 |
else: |
1171
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
351 |
if element_type == "program": |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
352 |
var_infos["Class"] = "Local" |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
353 |
else: |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
354 |
var_infos["Class"] = "Global" |
a506e4de8f84
Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents:
1140
diff
changeset
|
355 |
var_infos["Location"] = location |
814 | 356 |
else: |
357 |
var_infos["Class"] = "External" |
|
358 |
var_infos["Number"] = len(self.ParentWindow.Values) |
|
359 |
self.ParentWindow.Values.append(var_infos) |
|
360 |
self.ParentWindow.SaveValues() |
|
361 |
self.ParentWindow.RefreshValues() |
|
362 |
||
363 |
if message is not None: |
|
364 |
wx.CallAfter(self.ShowMessage, message) |
|
365 |
||
366 |
def ShowMessage(self, message): |
|
367 |
message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
368 |
message.ShowModal() |
|
369 |
message.Destroy() |
|
370 |
||
371 |
#------------------------------------------------------------------------------- |
|
372 |
# Variable Panel |
|
373 |
#------------------------------------------------------------------------------- |
|
374 |
||
375 |
class VariablePanel(wx.Panel): |
|
376 |
||
377 |
def __init__(self, parent, window, controler, element_type, debug=False): |
|
378 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
|
379 |
||
380 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0) |
|
381 |
self.MainSizer.AddGrowableCol(0) |
|
382 |
self.MainSizer.AddGrowableRow(1) |
|
383 |
||
384 |
controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
|
385 |
controls_sizer.AddGrowableCol(5) |
|
386 |
controls_sizer.AddGrowableRow(0) |
|
387 |
self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL) |
|
388 |
||
389 |
self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
|
390 |
controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
|
391 |
||
392 |
self.ReturnType = wx.ComboBox(self, |
|
393 |
size=wx.Size(145, -1), style=wx.CB_READONLY) |
|
394 |
self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
|
395 |
controls_sizer.AddWindow(self.ReturnType) |
|
396 |
||
397 |
self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
|
398 |
controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
|
399 |
||
400 |
self.Description = wx.TextCtrl(self, |
|
401 |
size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
|
402 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
|
403 |
self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
|
404 |
controls_sizer.AddWindow(self.Description) |
|
405 |
||
406 |
class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
|
407 |
controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
|
408 |
||
409 |
self.ClassFilter = wx.ComboBox(self, |
|
410 |
size=wx.Size(145, -1), style=wx.CB_READONLY) |
|
411 |
self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
|
412 |
controls_sizer.AddWindow(self.ClassFilter) |
|
413 |
||
414 |
for name, bitmap, help in [ |
|
415 |
("AddButton", "add_element", _("Add variable")), |
|
416 |
("DeleteButton", "remove_element", _("Remove variable")), |
|
417 |
("UpButton", "up", _("Move variable up")), |
|
418 |
("DownButton", "down", _("Move variable down"))]: |
|
419 |
button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
|
420 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
421 |
button.SetToolTipString(help) |
|
422 |
setattr(self, name, button) |
|
423 |
controls_sizer.AddWindow(button) |
|
424 |
||
425 |
self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
|
426 |
self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
|
427 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
428 |
self.OnVariablesGridCellChange) |
|
429 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
|
430 |
self.OnVariablesGridCellLeftClick) |
|
431 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
|
432 |
self.OnVariablesGridEditorShown) |
|
433 |
self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
|
434 |
||
435 |
self.SetSizer(self.MainSizer) |
|
436 |
||
437 |
self.ParentWindow = window |
|
438 |
self.Controler = controler |
|
439 |
self.ElementType = element_type |
|
440 |
self.Debug = debug |
|
441 |
||
442 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
443 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, |
|
444 |
self.RefreshHighlightsTimer) |
|
445 |
||
446 |
self.Filter = "All" |
|
447 |
self.FilterChoices = [] |
|
448 |
self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
|
449 |
||
450 |
self.DefaultValue = { |
|
451 |
"Name" : "", |
|
452 |
"Class" : "", |
|
453 |
"Type" : "INT", |
|
454 |
"Location" : "", |
|
863
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
455 |
"Initial Value" : "", |
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
456 |
"Option" : "", |
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
457 |
"Documentation" : "", |
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
458 |
"Edit" : True |
814 | 459 |
} |
460 |
||
461 |
if element_type in ["config", "resource"]: |
|
462 |
self.DefaultTypes = {"All" : "Global"} |
|
463 |
else: |
|
464 |
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
|
465 |
||
466 |
if element_type in ["config", "resource"] \ |
|
467 |
or element_type in ["program", "transition", "action"]: |
|
468 |
# this is an element that can have located variables |
|
469 |
self.Table = VariableTable(self, [], GetVariableTableColnames(True)) |
|
470 |
||
471 |
if element_type in ["config", "resource"]: |
|
472 |
self.FilterChoices = ["All", "Global"]#,"Access"] |
|
473 |
else: |
|
474 |
self.FilterChoices = ["All", |
|
475 |
"Interface", " Input", " Output", " InOut", " External", |
|
476 |
"Variables", " Local", " Temp"]#,"Access"] |
|
477 |
||
478 |
# these condense the ColAlignements list |
|
479 |
l = wx.ALIGN_LEFT |
|
480 |
c = wx.ALIGN_CENTER |
|
481 |
||
482 |
# Num Name Class Type Loc Init Option Doc |
|
483 |
self.ColSizes = [40, 80, 70, 80, 80, 80, 100, 80] |
|
484 |
self.ColAlignements = [c, l, l, l, l, l, l, l] |
|
485 |
||
486 |
else: |
|
487 |
# this is an element that cannot have located variables |
|
488 |
self.Table = VariableTable(self, [], GetVariableTableColnames(False)) |
|
489 |
||
490 |
if element_type == "function": |
|
491 |
self.FilterChoices = ["All", |
|
492 |
"Interface", " Input", " Output", " InOut", |
|
493 |
"Variables", " Local"] |
|
494 |
else: |
|
495 |
self.FilterChoices = ["All", |
|
496 |
"Interface", " Input", " Output", " InOut", " External", |
|
497 |
"Variables", " Local", " Temp"] |
|
498 |
||
499 |
# these condense the ColAlignements list |
|
500 |
l = wx.ALIGN_LEFT |
|
501 |
c = wx.ALIGN_CENTER |
|
502 |
||
503 |
# Num Name Class Type Init Option Doc |
|
504 |
self.ColSizes = [40, 80, 70, 80, 80, 100, 160] |
|
505 |
self.ColAlignements = [c, l, l, l, l, l, l] |
|
506 |
||
507 |
for choice in self.FilterChoices: |
|
508 |
self.ClassFilter.Append(_(choice)) |
|
509 |
||
510 |
reverse_transfer = {} |
|
511 |
for filter, choice in self.FilterChoiceTransfer.items(): |
|
512 |
reverse_transfer[choice] = filter |
|
513 |
self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter])) |
|
514 |
self.RefreshTypeList() |
|
515 |
||
516 |
self.VariablesGrid.SetTable(self.Table) |
|
517 |
self.VariablesGrid.SetButtons({"Add": self.AddButton, |
|
518 |
"Delete": self.DeleteButton, |
|
519 |
"Up": self.UpButton, |
|
520 |
"Down": self.DownButton}) |
|
521 |
self.VariablesGrid.SetEditable(not self.Debug) |
|
522 |
||
523 |
def _AddVariable(new_row): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
524 |
if new_row > 0: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
525 |
row_content = self.Values[new_row - 1].copy() |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
526 |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
527 |
result = VARIABLE_NAME_SUFFIX_MODEL.search(row_content["Name"]) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
528 |
if result is not None: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
529 |
name = row_content["Name"][:result.start(1)] |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
530 |
suffix = result.group(1) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
531 |
if suffix != "": |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
532 |
start_idx = int(suffix) |
1122
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
533 |
else: |
84de51ab40d2
Adding support for using current selected variable for generate newly added variable informations in VariablePanel
Laurent Bessard
parents:
1083
diff
changeset
|
534 |
start_idx = 0 |
814 | 535 |
else: |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
536 |
name = row_content["Name"] |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
537 |
start_idx = 0 |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
538 |
else: |
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
539 |
row_content = None |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
540 |
start_idx = 0 |
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
541 |
name = "LocalVar" |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
542 |
|
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
543 |
if row_content is not None and row_content["Edit"]: |
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
544 |
row_content = self.Values[new_row - 1].copy() |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
545 |
else: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
546 |
row_content = self.DefaultValue.copy() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
547 |
if self.Filter in self.DefaultTypes: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
548 |
row_content["Class"] = self.DefaultTypes[self.Filter] |
814 | 549 |
else: |
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
550 |
row_content["Class"] = self.Filter |
1175
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
551 |
|
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
552 |
row_content["Name"] = self.Controler.GenerateNewName( |
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
553 |
self.TagName, None, name + "%d", start_idx) |
01842255c9ff
Fixed bug when adding a variable in Variable Panel and selected variable can't be edited (generally a FB)
Laurent Bessard
parents:
1171
diff
changeset
|
554 |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
555 |
if self.Filter == "All" and len(self.Values) > 0: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
556 |
self.Values.insert(new_row, row_content) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
557 |
else: |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
558 |
self.Values.append(row_content) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
559 |
new_row = self.Table.GetNumberRows() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
560 |
self.SaveValues() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
561 |
self.RefreshValues() |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
562 |
return new_row |
814 | 563 |
setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
564 |
||
565 |
def _DeleteVariable(row): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
566 |
if self.Table.GetValueByName(row, "Edit"): |
814 | 567 |
self.Values.remove(self.Table.GetRow(row)) |
568 |
self.SaveValues() |
|
569 |
self.RefreshValues() |
|
570 |
setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
|
571 |
||
572 |
def _MoveVariable(row, move): |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
573 |
if self.Filter == "All": |
814 | 574 |
new_row = max(0, min(row + move, len(self.Values) - 1)) |
575 |
if new_row != row: |
|
576 |
self.Values.insert(new_row, self.Values.pop(row)) |
|
577 |
self.SaveValues() |
|
578 |
self.RefreshValues() |
|
579 |
return new_row |
|
580 |
return row |
|
581 |
setattr(self.VariablesGrid, "_MoveRow", _MoveVariable) |
|
582 |
||
583 |
def _RefreshButtons(): |
|
584 |
if self: |
|
585 |
table_length = len(self.Table.data) |
|
586 |
row_class = None |
|
587 |
row_edit = True |
|
588 |
row = 0 |
|
589 |
if table_length > 0: |
|
590 |
row = self.VariablesGrid.GetGridCursorRow() |
|
591 |
row_edit = self.Table.GetValueByName(row, "Edit") |
|
1128
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
592 |
self.AddButton.Enable(not self.Debug) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
593 |
self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit)) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
594 |
self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All")) |
86527a6f06fb
Removed restriction on POU interface variables modification when POU is already used
Laurent Bessard
parents:
1122
diff
changeset
|
595 |
self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All")) |
814 | 596 |
setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons) |
597 |
||
598 |
self.VariablesGrid.SetRowLabelSize(0) |
|
599 |
for col in range(self.Table.GetNumberCols()): |
|
600 |
attr = wx.grid.GridCellAttr() |
|
601 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
602 |
self.VariablesGrid.SetColAttr(col, attr) |
|
603 |
self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
|
604 |
self.VariablesGrid.AutoSizeColumn(col, False) |
|
605 |
||
606 |
def __del__(self): |
|
607 |
self.RefreshHighlightsTimer.Stop() |
|
608 |
||
609 |
def SetTagName(self, tagname): |
|
610 |
self.TagName = tagname |
|
611 |
||
612 |
def GetTagName(self): |
|
613 |
return self.TagName |
|
614 |
||
615 |
def IsFunctionBlockType(self, name): |
|
616 |
bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
|
617 |
pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
|
618 |
if poutype != "function" and bodytype in ["ST", "IL"]: |
|
619 |
return False |
|
620 |
else: |
|
621 |
return name in self.Controler.GetFunctionBlockTypes(self.TagName) |
|
622 |
||
623 |
def RefreshView(self): |
|
624 |
self.PouNames = self.Controler.GetProjectPouNames(self.Debug) |
|
625 |
returnType = None |
|
626 |
description = None |
|
627 |
||
628 |
words = self.TagName.split("::") |
|
629 |
if self.ElementType == "config": |
|
630 |
self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug) |
|
631 |
elif self.ElementType == "resource": |
|
632 |
self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug) |
|
633 |
else: |
|
634 |
if self.ElementType == "function": |
|
635 |
self.ReturnType.Clear() |
|
853
0f97bddb5a30
Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents:
831
diff
changeset
|
636 |
for data_type in self.Controler.GetDataTypes(self.TagName, debug=self.Debug): |
0f97bddb5a30
Adding datatypes defined in ConfNode as possible function return type
Laurent Bessard
parents:
831
diff
changeset
|
637 |
self.ReturnType.Append(data_type) |
814 | 638 |
returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName) |
639 |
description = self.Controler.GetPouDescription(words[1]) |
|
640 |
self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
641 |
||
642 |
if returnType is not None: |
|
643 |
self.ReturnType.SetStringSelection(returnType) |
|
644 |
self.ReturnType.Enable(not self.Debug) |
|
645 |
self.ReturnTypeLabel.Show() |
|
646 |
self.ReturnType.Show() |
|
647 |
else: |
|
648 |
self.ReturnType.Enable(False) |
|
649 |
self.ReturnTypeLabel.Hide() |
|
650 |
self.ReturnType.Hide() |
|
651 |
||
652 |
if description is not None: |
|
653 |
self.Description.SetValue(description) |
|
654 |
self.Description.Enable(not self.Debug) |
|
655 |
self.DescriptionLabel.Show() |
|
656 |
self.Description.Show() |
|
657 |
else: |
|
658 |
self.Description.Enable(False) |
|
659 |
self.DescriptionLabel.Hide() |
|
660 |
self.Description.Hide() |
|
661 |
||
662 |
self.RefreshValues() |
|
663 |
self.VariablesGrid.RefreshButtons() |
|
664 |
self.MainSizer.Layout() |
|
665 |
||
666 |
def OnReturnTypeChanged(self, event): |
|
667 |
words = self.TagName.split("::") |
|
668 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
669 |
self.Controler.BufferProject() |
|
670 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
671 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
|
672 |
event.Skip() |
|
673 |
||
674 |
def OnDescriptionChanged(self, event): |
|
675 |
words = self.TagName.split("::") |
|
676 |
old_description = self.Controler.GetPouDescription(words[1]) |
|
677 |
new_description = self.Description.GetValue() |
|
678 |
if new_description != old_description: |
|
679 |
self.Controler.SetPouDescription(words[1], new_description) |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
680 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 681 |
event.Skip() |
682 |
||
683 |
def OnClassFilter(self, event): |
|
684 |
self.Filter = self.FilterChoiceTransfer[VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]] |
|
685 |
self.RefreshTypeList() |
|
686 |
self.RefreshValues() |
|
687 |
self.VariablesGrid.RefreshButtons() |
|
688 |
event.Skip() |
|
689 |
||
690 |
def RefreshTypeList(self): |
|
691 |
if self.Filter == "All": |
|
692 |
self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
|
693 |
elif self.Filter == "Interface": |
|
694 |
self.ClassList = ["Input","Output","InOut","External"] |
|
695 |
elif self.Filter == "Variables": |
|
696 |
self.ClassList = ["Local","Temp"] |
|
697 |
else: |
|
698 |
self.ClassList = [self.Filter] |
|
699 |
||
700 |
def OnVariablesGridCellChange(self, event): |
|
701 |
row, col = event.GetRow(), event.GetCol() |
|
702 |
colname = self.Table.GetColLabelValue(col, False) |
|
703 |
value = self.Table.GetValue(row, col) |
|
704 |
message = None |
|
705 |
||
706 |
if colname == "Name" and value != "": |
|
707 |
if not TestIdentifier(value): |
|
708 |
message = _("\"%s\" is not a valid identifier!") % value |
|
709 |
elif value.upper() in IEC_KEYWORDS: |
|
710 |
message = _("\"%s\" is a keyword. It can't be used!") % value |
|
711 |
elif value.upper() in self.PouNames: |
|
712 |
message = _("A POU named \"%s\" already exists!") % value |
|
713 |
elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: |
|
714 |
message = _("A variable with \"%s\" as name already exists in this pou!") % value |
|
715 |
else: |
|
716 |
self.SaveValues(False) |
|
717 |
old_value = self.Table.GetOldValue() |
|
718 |
if old_value != "": |
|
719 |
self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
|
720 |
self.Controler.BufferProject() |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
721 |
wx.CallAfter(self.ParentWindow.RefreshView, False) |
1016
3d79c31e4697
Fixed bug with variable panel in project configuration editor
Laurent Bessard
parents:
1009
diff
changeset
|
722 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 723 |
else: |
724 |
self.SaveValues() |
|
725 |
if colname == "Class": |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
726 |
wx.CallAfter(self.ParentWindow.RefreshView, False) |
814 | 727 |
elif colname == "Location": |
728 |
wx.CallAfter(self.ParentWindow.RefreshView) |
|
729 |
||
730 |
if message is not None: |
|
731 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
732 |
dialog.ShowModal() |
|
733 |
dialog.Destroy() |
|
734 |
event.Veto() |
|
735 |
else: |
|
736 |
event.Skip() |
|
737 |
||
738 |
def OnVariablesGridEditorShown(self, event): |
|
739 |
row, col = event.GetRow(), event.GetCol() |
|
740 |
||
741 |
label_value = self.Table.GetColLabelValue(col, False) |
|
742 |
if label_value == "Type": |
|
743 |
type_menu = wx.Menu(title='') # the root menu |
|
744 |
||
745 |
# build a submenu containing standard IEC types |
|
746 |
base_menu = wx.Menu(title='') |
|
747 |
for base_type in self.Controler.GetBaseTypes(): |
|
748 |
new_id = wx.NewId() |
|
749 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
|
750 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
|
751 |
||
752 |
type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
|
753 |
||
754 |
# build a submenu containing user-defined types |
|
755 |
datatype_menu = wx.Menu(title='') |
|
863
b1ead41fbd3b
Fix bug in VariablePanel 'Type' cell editor menu entry 'User Data Types' containing ConfNodes data types
Laurent Bessard
parents:
853
diff
changeset
|
756 |
datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False) |
814 | 757 |
for datatype in datatypes: |
758 |
new_id = wx.NewId() |
|
759 |
AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
|
760 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
|
761 |
||
762 |
type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
|
763 |
||
764 |
for category in self.Controler.GetConfNodeDataTypes(): |
|
765 |
||
766 |
if len(category["list"]) > 0: |
|
767 |
# build a submenu containing confnode types |
|
768 |
confnode_datatype_menu = wx.Menu(title='') |
|
769 |
for datatype in category["list"]: |
|
770 |
new_id = wx.NewId() |
|
771 |
AppendMenu(confnode_datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
|
772 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
|
773 |
||
774 |
type_menu.AppendMenu(wx.NewId(), category["name"], confnode_datatype_menu) |
|
775 |
||
776 |
# build a submenu containing function block types |
|
777 |
bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
|
778 |
pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
|
779 |
classtype = self.Table.GetValueByName(row, "Class") |
|
780 |
||
781 |
new_id = wx.NewId() |
|
782 |
AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array")) |
|
783 |
self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id) |
|
784 |
||
785 |
if classtype in ["Input", "Output", "InOut", "External", "Global"] or \ |
|
786 |
poutype != "function" and bodytype in ["ST", "IL"]: |
|
787 |
functionblock_menu = wx.Menu(title='') |
|
788 |
fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName) |
|
789 |
for functionblock_type in fbtypes: |
|
790 |
new_id = wx.NewId() |
|
791 |
AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
|
792 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
|
793 |
||
794 |
type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
|
795 |
||
796 |
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
|
797 |
corner_x = rect.x + rect.width |
|
798 |
corner_y = rect.y + self.VariablesGrid.GetColLabelSize() |
|
799 |
||
800 |
# pop up this new menu |
|
801 |
self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y) |
|
802 |
type_menu.Destroy() |
|
803 |
event.Veto() |
|
804 |
else: |
|
805 |
event.Skip() |
|
806 |
||
807 |
def GetVariableTypeFunction(self, base_type): |
|
808 |
def VariableTypeFunction(event): |
|
809 |
row = self.VariablesGrid.GetGridCursorRow() |
|
810 |
self.Table.SetValueByName(row, "Type", base_type) |
|
811 |
self.Table.ResetView(self.VariablesGrid) |
|
812 |
self.SaveValues(False) |
|
813 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
814 |
self.Controler.BufferProject() |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
815 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 816 |
return VariableTypeFunction |
817 |
||
818 |
def VariableArrayTypeFunction(self, event): |
|
819 |
row = self.VariablesGrid.GetGridCursorRow() |
|
820 |
dialog = ArrayTypeDialog(self, |
|
821 |
self.Controler.GetDataTypes(self.TagName), |
|
822 |
self.Table.GetValueByName(row, "Type")) |
|
823 |
if dialog.ShowModal() == wx.ID_OK: |
|
824 |
self.Table.SetValueByName(row, "Type", dialog.GetValue()) |
|
825 |
self.Table.ResetView(self.VariablesGrid) |
|
826 |
self.SaveValues(False) |
|
827 |
self.ParentWindow.RefreshView(variablepanel = False) |
|
828 |
self.Controler.BufferProject() |
|
1009
741fbce41ec2
Fixed bug in VariablePanel when editing project single configuration variables
Laurent Bessard
parents:
894
diff
changeset
|
829 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 830 |
dialog.Destroy() |
831 |
||
832 |
def OnVariablesGridCellLeftClick(self, event): |
|
833 |
row = event.GetRow() |
|
834 |
if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")): |
|
835 |
var_name = self.Table.GetValueByName(row, "Name") |
|
836 |
var_class = self.Table.GetValueByName(row, "Class") |
|
837 |
var_type = self.Table.GetValueByName(row, "Type") |
|
838 |
data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName))) |
|
839 |
dragSource = wx.DropSource(self.VariablesGrid) |
|
840 |
dragSource.SetData(data) |
|
841 |
dragSource.DoDragDrop() |
|
842 |
event.Skip() |
|
843 |
||
844 |
def RefreshValues(self): |
|
845 |
data = [] |
|
846 |
for num, variable in enumerate(self.Values): |
|
847 |
if variable["Class"] in self.ClassList: |
|
848 |
variable["Number"] = num + 1 |
|
849 |
data.append(variable) |
|
850 |
self.Table.SetData(data) |
|
851 |
self.Table.ResetView(self.VariablesGrid) |
|
852 |
||
853 |
def SaveValues(self, buffer = True): |
|
854 |
words = self.TagName.split("::") |
|
855 |
if self.ElementType == "config": |
|
856 |
self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
|
857 |
elif self.ElementType == "resource": |
|
858 |
self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |
|
859 |
else: |
|
860 |
if self.ReturnType.IsEnabled(): |
|
861 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
862 |
self.Controler.SetPouInterfaceVars(words[1], self.Values) |
|
863 |
if buffer: |
|
864 |
self.Controler.BufferProject() |
|
1184
891b49d2752b
Fixed non-tested bad code in VariablePanel
Edouard Tisserant
parents:
1175
diff
changeset
|
865 |
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
814 | 866 |
|
867 |
#------------------------------------------------------------------------------- |
|
868 |
# Highlights showing functions |
|
869 |
#------------------------------------------------------------------------------- |
|
870 |
||
871 |
def OnRefreshHighlightsTimer(self, event): |
|
872 |
self.Table.ResetView(self.VariablesGrid) |
|
873 |
event.Skip() |
|
874 |
||
875 |
def AddVariableHighlight(self, infos, highlight_type): |
|
876 |
if isinstance(infos[0], TupleType): |
|
877 |
for i in xrange(*infos[0]): |
|
878 |
self.Table.AddHighlight((i,) + infos[1:], highlight_type) |
|
879 |
cell_visible = infos[0][0] |
|
880 |
else: |
|
881 |
self.Table.AddHighlight(infos, highlight_type) |
|
882 |
cell_visible = infos[0] |
|
883 |
colnames = [colname.lower() for colname in self.Table.colnames] |
|
884 |
self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1])) |
|
885 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
886 |
||
887 |
def RemoveVariableHighlight(self, infos, highlight_type): |
|
888 |
if isinstance(infos[0], TupleType): |
|
889 |
for i in xrange(*infos[0]): |
|
890 |
self.Table.RemoveHighlight((i,) + infos[1:], highlight_type) |
|
891 |
else: |
|
892 |
self.Table.RemoveHighlight(infos, highlight_type) |
|
893 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
894 |
||
895 |
def ClearHighlights(self, highlight_type=None): |
|
896 |
self.Table.ClearHighlights(highlight_type) |
|
897 |
self.Table.ResetView(self.VariablesGrid) |