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