author | Laurent Bessard |
Tue, 11 Jun 2013 23:50:44 +0200 | |
changeset 1247 | 92588e69d853 |
parent 1244 | 336d515096b1 |
child 1250 | 7e6de17c687a |
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 |
||
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
25 |
import re |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
26 |
|
814 | 27 |
import wx |
28 |
||
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
29 |
from graphics.FBD_Objects import FBD_Block |
814 | 30 |
from controls.LibraryPanel import LibraryPanel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
31 |
from BlockPreviewDialog import BlockPreviewDialog |
814 | 32 |
|
33 |
#------------------------------------------------------------------------------- |
|
1244 | 34 |
# Helpers |
35 |
#------------------------------------------------------------------------------- |
|
36 |
||
37 |
def GetBlockTypeDefaultNameModel(blocktype): |
|
38 |
return re.compile("%s[0-9]+" % blocktype if blocktype is not None else ".*") |
|
39 |
||
40 |
#------------------------------------------------------------------------------- |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
41 |
# Set Block Parameters Dialog |
814 | 42 |
#------------------------------------------------------------------------------- |
43 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
44 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
45 |
Class that implements a dialog for defining parameters of a FBD block graphic |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
46 |
element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
47 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
48 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
49 |
class FBDBlockDialog(BlockPreviewDialog): |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
50 |
|
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
51 |
def __init__(self, parent, controller, tagname): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
52 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
53 |
Constructor |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
54 |
@param parent: Parent wx.Window of dialog for modal |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
55 |
@param controller: Reference to project controller |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
56 |
@param tagname: Tagname of project POU edited |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
57 |
""" |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
58 |
BlockPreviewDialog.__init__(self, parent, controller, tagname, |
814 | 59 |
size=wx.Size(600, 450), title=_('Block Properties')) |
60 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
61 |
# Create dialog main sizer |
814 | 62 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10) |
63 |
main_sizer.AddGrowableCol(0) |
|
64 |
main_sizer.AddGrowableRow(0) |
|
65 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
66 |
# Create a sizer for dividing FBD block parameters in two columns |
814 | 67 |
column_sizer = wx.BoxSizer(wx.HORIZONTAL) |
68 |
main_sizer.AddSizer(column_sizer, border=20, |
|
69 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
70 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
71 |
# Create static box around library panel |
814 | 72 |
type_staticbox = wx.StaticBox(self, label=_('Type:')) |
73 |
left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL) |
|
74 |
column_sizer.AddSizer(left_staticboxsizer, 1, border=5, |
|
75 |
flag=wx.GROW|wx.RIGHT) |
|
76 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
77 |
# Create Library panel and add it to static box |
814 | 78 |
self.LibraryPanel = LibraryPanel(self) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
79 |
# Set function to call when selection in Library panel changed |
814 | 80 |
setattr(self.LibraryPanel, "_OnTreeItemSelected", |
81 |
self.OnLibraryTreeItemSelected) |
|
82 |
left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, |
|
83 |
flag=wx.GROW|wx.TOP) |
|
84 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
85 |
# Create sizer for other block parameters and preview panle |
814 | 86 |
right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) |
87 |
right_gridsizer.AddGrowableCol(0) |
|
88 |
right_gridsizer.AddGrowableRow(2) |
|
89 |
column_sizer.AddSizer(right_gridsizer, 1, border=5, |
|
90 |
flag=wx.GROW|wx.LEFT) |
|
91 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
92 |
# Create sizer for other block parameters |
814 | 93 |
top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5) |
94 |
top_right_gridsizer.AddGrowableCol(1) |
|
95 |
right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW) |
|
96 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
97 |
# Create label for block name |
814 | 98 |
name_label = wx.StaticText(self, label=_('Name:')) |
99 |
top_right_gridsizer.AddWindow(name_label, |
|
100 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
101 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
102 |
# Create text control for defining block name |
814 | 103 |
self.BlockName = wx.TextCtrl(self) |
104 |
self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName) |
|
105 |
top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW) |
|
106 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
107 |
# Create label for extended block input number |
814 | 108 |
inputs_label = wx.StaticText(self, label=_('Inputs:')) |
109 |
top_right_gridsizer.AddWindow(inputs_label, |
|
110 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
111 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
112 |
# Create spin control for defining extended block input number |
814 | 113 |
self.Inputs = wx.SpinCtrl(self, min=2, max=20, |
114 |
style=wx.SP_ARROW_KEYS) |
|
115 |
self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs) |
|
116 |
top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW) |
|
117 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
118 |
# Create label for block execution order |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
119 |
execution_order_label = wx.StaticText(self, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
120 |
label=_('Execution Order:')) |
814 | 121 |
top_right_gridsizer.AddWindow(execution_order_label, |
122 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
123 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
124 |
# Create spin control for defining block execution order |
814 | 125 |
self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
126 |
self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
127 |
self.ExecutionOrder) |
814 | 128 |
top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW) |
129 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
130 |
# Create label for block execution control |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
131 |
execution_control_label = wx.StaticText(self, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
132 |
label=_('Execution Control:')) |
814 | 133 |
top_right_gridsizer.AddWindow(execution_control_label, |
134 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
135 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
136 |
# Create check box to enable block execution control |
814 | 137 |
self.ExecutionControl = wx.CheckBox(self) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
138 |
self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
139 |
self.ExecutionControl) |
814 | 140 |
top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW) |
141 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
142 |
# Add preview panel and associated label to sizers |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
143 |
right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
814 | 144 |
right_gridsizer.AddWindow(self.Preview, flag=wx.GROW) |
145 |
||
1244 | 146 |
# Add buttons sizer to sizers |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
147 |
main_sizer.AddSizer(self.ButtonSizer, border=20, |
814 | 148 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
149 |
||
150 |
self.SetSizer(main_sizer) |
|
151 |
||
1244 | 152 |
# Dictionary containing correspondence between parameter exchanged and |
153 |
# control to fill with parameter value |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
154 |
self.ParamsControl = { |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
155 |
"extension": self.Inputs, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
156 |
"executionOrder": self.ExecutionOrder, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
157 |
"executionControl": self.ExecutionControl |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
158 |
} |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
159 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
160 |
# Init controls value and sensibility |
814 | 161 |
self.BlockName.SetValue("") |
162 |
self.BlockName.Enable(False) |
|
163 |
self.Inputs.Enable(False) |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
164 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
165 |
# Variable containing last name typed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
166 |
self.CurrentBlockName = None |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
167 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
168 |
# Refresh Library panel values |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
169 |
self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname)) |
814 | 170 |
self.LibraryPanel.SetFocus() |
171 |
||
172 |
def OnOK(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
173 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
174 |
Called when dialog OK button is pressed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
175 |
Test if parameters defined are valid |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
176 |
@param event: wx.Event from OK button |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
177 |
""" |
814 | 178 |
message = None |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
179 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
180 |
# Get block type selected |
814 | 181 |
selected = self.LibraryPanel.GetSelectedBlock() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
182 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
183 |
# Get block type name and if block is a function block |
814 | 184 |
block_name = self.BlockName.GetValue() |
185 |
name_enabled = self.BlockName.IsEnabled() |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
186 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
187 |
# Test that a type has been selected for block |
814 | 188 |
if selected is None: |
189 |
message = _("Form isn't complete. Valid block type must be selected!") |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
190 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
191 |
# Test, if block is a function block, that a name have been defined |
814 | 192 |
elif name_enabled and block_name == "": |
193 |
message = _("Form isn't complete. Name must be filled!") |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
194 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
195 |
# Show error message if an error is detected |
814 | 196 |
if message is not None: |
1244 | 197 |
self.ShowErrorMessage(message) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
198 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
199 |
# Test block name validity if necessary |
1244 | 200 |
elif not name_enabled or self.TestElementName(block_name): |
201 |
# Call BlockPreviewDialog function |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
202 |
BlockPreviewDialog.OnOK(self, event) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
203 |
|
814 | 204 |
def SetValues(self, values): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
205 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
206 |
Set default block parameters |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
207 |
@param values: Block parameters values |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
208 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
209 |
# Extract block type defined in parameters |
814 | 210 |
blocktype = values.get("type", None) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
211 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
212 |
# Define regular expression for determine if block name is block |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
213 |
# default name |
1244 | 214 |
default_name_model = GetBlockTypeDefaultNameModel(blocktype) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
215 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
216 |
# For each parameters defined, set corresponding control value |
814 | 217 |
for name, value in values.items(): |
1244 | 218 |
|
219 |
# Parameter is block name |
|
814 | 220 |
if name == "name": |
1237
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
221 |
if value != "": |
1244 | 222 |
# Set default graphic element name for testing |
223 |
self.DefaultElementName = value |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
224 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
225 |
# Test if block name is type default block name and save |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
226 |
# block name if not (name have been typed by user) |
1237
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
227 |
if default_name_model.match(value) is None: |
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
228 |
self.CurrentBlockName = value |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
229 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
230 |
self.BlockName.ChangeValue(value) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
231 |
|
1244 | 232 |
# Set value of other controls |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
233 |
else: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
234 |
control = self.ParamsControl.get(name, None) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
235 |
if control is not None: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
236 |
control.SetValue(value) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
237 |
|
1244 | 238 |
# Select block type in library panel |
239 |
if blocktype is not None: |
|
240 |
self.LibraryPanel.SelectTreeItem(blocktype, |
|
241 |
values.get("inputs", None)) |
|
242 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
243 |
# Refresh preview panel |
814 | 244 |
self.RefreshPreview() |
245 |
||
246 |
def GetValues(self): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
247 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
248 |
Return block parameters defined in dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
249 |
@return: {parameter_name: parameter_value,...} |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
250 |
""" |
814 | 251 |
values = self.LibraryPanel.GetSelectedBlock() |
252 |
if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "": |
|
253 |
values["name"] = self.BlockName.GetValue() |
|
1244 | 254 |
values["width"], values["height"] = self.Element.GetSize() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
255 |
values.update({ |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
256 |
name: control.GetValue() |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
257 |
for name, control in self.ParamsControl.iteritems()}) |
814 | 258 |
return values |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
259 |
|
814 | 260 |
def OnLibraryTreeItemSelected(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
261 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
262 |
Called when block type selected in library panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
263 |
@param event: wx.TreeEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
264 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
265 |
# Get type selected in library panel |
814 | 266 |
values = self.LibraryPanel.GetSelectedBlock() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
267 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
268 |
# Get block type informations |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
269 |
blocktype = (self.Controller.GetBlockType(values["type"], |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
270 |
values["inputs"]) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
271 |
if values is not None else None) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
272 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
273 |
# Set input number spin control according to block type informations |
814 | 274 |
if blocktype is not None: |
275 |
self.Inputs.SetValue(len(blocktype["inputs"])) |
|
276 |
self.Inputs.Enable(blocktype["extensible"]) |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
277 |
else: |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
278 |
self.Inputs.SetValue(2) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
279 |
self.Inputs.Enable(False) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
280 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
281 |
# Update block name with default value if block type is a function and |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
282 |
# current block name wasn't typed by user |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
283 |
if blocktype is not None and blocktype["type"] != "function": |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
284 |
self.BlockName.Enable(True) |
1244 | 285 |
|
286 |
if self.CurrentBlockName is None: |
|
287 |
# Generate new block name according to block type, taking |
|
288 |
# default element name if it was already a default name for this |
|
289 |
# block type |
|
290 |
default_name_model = GetBlockTypeDefaultNameModel(values["type"]) |
|
291 |
block_name = ( |
|
292 |
self.DefaultElementName |
|
293 |
if (self.DefaultElementName is not None and |
|
294 |
default_name_model.match(self.DefaultElementName)) |
|
295 |
else self.Controller.GenerateNewName( |
|
296 |
self.TagName, None, values["type"]+"%d", 0)) |
|
297 |
else: |
|
298 |
block_name = self.CurrentBlockName |
|
299 |
||
300 |
self.BlockName.ChangeValue(block_name) |
|
814 | 301 |
else: |
302 |
self.BlockName.Enable(False) |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
303 |
self.BlockName.ChangeValue("") |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
304 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
305 |
# Refresh preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
306 |
self.RefreshPreview() |
814 | 307 |
|
308 |
def OnNameChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
309 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
310 |
Called when block name value changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
311 |
@param event: wx.TextEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
312 |
""" |
814 | 313 |
if self.BlockName.IsEnabled(): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
314 |
# Save block name typed by user |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
315 |
self.CurrentBlockName = self.BlockName.GetValue() |
814 | 316 |
self.RefreshPreview() |
317 |
event.Skip() |
|
318 |
||
319 |
def OnInputsChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
320 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
321 |
Called when block inputs number changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
322 |
@param event: wx.SpinEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
323 |
""" |
814 | 324 |
if self.Inputs.IsEnabled(): |
325 |
self.RefreshPreview() |
|
326 |
event.Skip() |
|
327 |
||
328 |
def OnExecutionOrderChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
329 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
330 |
Called when block execution order value changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
331 |
@param event: wx.SpinEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
332 |
""" |
814 | 333 |
self.RefreshPreview() |
334 |
event.Skip() |
|
335 |
||
336 |
def OnExecutionControlChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
337 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
338 |
Called when block execution control value changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
339 |
@param event: wx.SpinEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
340 |
""" |
814 | 341 |
self.RefreshPreview() |
342 |
event.Skip() |
|
343 |
||
344 |
def RefreshPreview(self): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
345 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
346 |
Refresh preview panel of graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
347 |
Override BlockPreviewDialog function |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
348 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
349 |
# Get type selected in library panel |
814 | 350 |
values = self.LibraryPanel.GetSelectedBlock() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
351 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
352 |
# If a block type is selected in library panel |
814 | 353 |
if values is not None: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
354 |
# Set graphic element displayed, creating a FBD block element |
1244 | 355 |
self.Element = FBD_Block(self.Preview, values["type"], |
356 |
(self.BlockName.GetValue() |
|
357 |
if self.BlockName.IsEnabled() |
|
358 |
else ""), |
|
814 | 359 |
extension = self.Inputs.GetValue(), |
360 |
inputs = values["inputs"], |
|
361 |
executionControl = self.ExecutionControl.GetValue(), |
|
362 |
executionOrder = self.ExecutionOrder.GetValue()) |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
363 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
364 |
# Reset graphic element displayed |
814 | 365 |
else: |
1244 | 366 |
self.Element = None |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
367 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
368 |
# Call BlockPreviewDialog function |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
369 |
BlockPreviewDialog.RefreshPreview(self) |