author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 11 Jan 2017 12:57:40 +0300 | |
changeset 1624 | bc84d659894f |
parent 1571 | 486f94a8032c |
child 1696 | 8043f32de7b8 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
8 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
10 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
15 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
19 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
20 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1327
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 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 |
||
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
61 |
# Init common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
62 |
self._init_sizers(2, 0, 1, 0, 3, 2) |
814 | 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) |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
67 |
self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW) |
814 | 68 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
69 |
# Create Library panel and add it to static box |
814 | 70 |
self.LibraryPanel = LibraryPanel(self) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
71 |
# Set function to call when selection in Library panel changed |
814 | 72 |
setattr(self.LibraryPanel, "_OnTreeItemSelected", |
73 |
self.OnLibraryTreeItemSelected) |
|
74 |
left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, |
|
75 |
flag=wx.GROW|wx.TOP) |
|
76 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
77 |
# Create sizer for other block parameters |
814 | 78 |
top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5) |
79 |
top_right_gridsizer.AddGrowableCol(1) |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
80 |
self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW) |
814 | 81 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
82 |
# Create label for block name |
814 | 83 |
name_label = wx.StaticText(self, label=_('Name:')) |
84 |
top_right_gridsizer.AddWindow(name_label, |
|
85 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
86 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
87 |
# Create text control for defining block name |
814 | 88 |
self.BlockName = wx.TextCtrl(self) |
89 |
self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName) |
|
90 |
top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW) |
|
91 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
92 |
# Create label for extended block input number |
814 | 93 |
inputs_label = wx.StaticText(self, label=_('Inputs:')) |
94 |
top_right_gridsizer.AddWindow(inputs_label, |
|
95 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
96 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
97 |
# Create spin control for defining extended block input number |
814 | 98 |
self.Inputs = wx.SpinCtrl(self, min=2, max=20, |
99 |
style=wx.SP_ARROW_KEYS) |
|
100 |
self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs) |
|
101 |
top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW) |
|
102 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
103 |
# Create label for block execution order |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
104 |
execution_order_label = wx.StaticText(self, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
105 |
label=_('Execution Order:')) |
814 | 106 |
top_right_gridsizer.AddWindow(execution_order_label, |
107 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
108 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
109 |
# Create spin control for defining block execution order |
814 | 110 |
self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
111 |
self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
112 |
self.ExecutionOrder) |
814 | 113 |
top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW) |
114 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
115 |
# Create label for block execution control |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
116 |
execution_control_label = wx.StaticText(self, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
117 |
label=_('Execution Control:')) |
814 | 118 |
top_right_gridsizer.AddWindow(execution_control_label, |
119 |
flag=wx.ALIGN_CENTER_VERTICAL) |
|
120 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
121 |
# Create check box to enable block execution control |
814 | 122 |
self.ExecutionControl = wx.CheckBox(self) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
123 |
self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
124 |
self.ExecutionControl) |
814 | 125 |
top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW) |
126 |
||
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
127 |
# Add preview panel and associated label to sizers |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
128 |
self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
129 |
self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
814 | 130 |
|
1244 | 131 |
# Add buttons sizer to sizers |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
132 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
814 | 133 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
134 |
||
1244 | 135 |
# Dictionary containing correspondence between parameter exchanged and |
136 |
# control to fill with parameter value |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
137 |
self.ParamsControl = { |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
138 |
"extension": self.Inputs, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
139 |
"executionOrder": self.ExecutionOrder, |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
140 |
"executionControl": self.ExecutionControl |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
141 |
} |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
142 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
143 |
# Init controls value and sensibility |
814 | 144 |
self.BlockName.SetValue("") |
145 |
self.BlockName.Enable(False) |
|
146 |
self.Inputs.Enable(False) |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
147 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
148 |
# Variable containing last name typed |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
149 |
self.CurrentBlockName = None |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
150 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
151 |
# Refresh Library panel values |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
152 |
self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname)) |
814 | 153 |
self.LibraryPanel.SetFocus() |
154 |
||
155 |
def SetValues(self, values): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
156 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
157 |
Set default block parameters |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
158 |
@param values: Block parameters values |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
159 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
160 |
# Extract block type defined in parameters |
814 | 161 |
blocktype = values.get("type", None) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
162 |
|
1327
632780979432
Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents:
1250
diff
changeset
|
163 |
# Select block type in library panel |
632780979432
Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents:
1250
diff
changeset
|
164 |
if blocktype is not None: |
632780979432
Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents:
1250
diff
changeset
|
165 |
self.LibraryPanel.SelectTreeItem(blocktype, |
632780979432
Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents:
1250
diff
changeset
|
166 |
values.get("inputs", None)) |
632780979432
Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents:
1250
diff
changeset
|
167 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
168 |
# Define regular expression for determine if block name is block |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
169 |
# default name |
1244 | 170 |
default_name_model = GetBlockTypeDefaultNameModel(blocktype) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
171 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
172 |
# For each parameters defined, set corresponding control value |
814 | 173 |
for name, value in values.items(): |
1244 | 174 |
|
175 |
# Parameter is block name |
|
814 | 176 |
if name == "name": |
1237
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
177 |
if value != "": |
1244 | 178 |
# Set default graphic element name for testing |
179 |
self.DefaultElementName = value |
|
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 name is type default block name and save |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
182 |
# 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
|
183 |
if default_name_model.match(value) is None: |
0c8b8ef9559b
Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1236
diff
changeset
|
184 |
self.CurrentBlockName = value |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
185 |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
186 |
self.BlockName.ChangeValue(value) |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
187 |
|
1244 | 188 |
# Set value of other controls |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
189 |
else: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
190 |
control = self.ParamsControl.get(name, None) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
191 |
if control is not None: |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
192 |
control.SetValue(value) |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
193 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
194 |
# Refresh preview panel |
814 | 195 |
self.RefreshPreview() |
196 |
||
197 |
def GetValues(self): |
|
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 |
Return block parameters defined in dialog |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
200 |
@return: {parameter_name: parameter_value,...} |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
201 |
""" |
814 | 202 |
values = self.LibraryPanel.GetSelectedBlock() |
203 |
if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "": |
|
204 |
values["name"] = self.BlockName.GetValue() |
|
1244 | 205 |
values["width"], values["height"] = self.Element.GetSize() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
206 |
values.update({ |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
207 |
name: control.GetValue() |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
208 |
for name, control in self.ParamsControl.iteritems()}) |
814 | 209 |
return values |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
210 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
211 |
def OnOK(self, event): |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
212 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
213 |
Called when dialog OK button is pressed |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
214 |
Test if parameters defined are valid |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
215 |
@param event: wx.Event from OK button |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
216 |
""" |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
217 |
message = None |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
218 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
219 |
# Get block type selected |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
220 |
selected = self.LibraryPanel.GetSelectedBlock() |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
221 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
222 |
# Get block type name and if block is a function block |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
223 |
block_name = self.BlockName.GetValue() |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
224 |
name_enabled = self.BlockName.IsEnabled() |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
225 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
226 |
# Test that a type has been selected for block |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
227 |
if selected is None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
228 |
message = _("Form isn't complete. Valid block type must be selected!") |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
229 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
230 |
# Test, if block is a function block, that a name have been defined |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
231 |
elif name_enabled and block_name == "": |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
232 |
message = _("Form isn't complete. Name must be filled!") |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
233 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
234 |
# Show error message if an error is detected |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
235 |
if message is not None: |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
236 |
self.ShowErrorMessage(message) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
237 |
|
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
238 |
# Test block name validity if necessary |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
239 |
elif not name_enabled or self.TestElementName(block_name): |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
240 |
# Call BlockPreviewDialog function |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
241 |
BlockPreviewDialog.OnOK(self, event) |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1244
diff
changeset
|
242 |
|
814 | 243 |
def OnLibraryTreeItemSelected(self, event): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
244 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
245 |
Called when block type selected in library panel |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
246 |
@param event: wx.TreeEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
247 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
248 |
# Get type selected in library panel |
814 | 249 |
values = self.LibraryPanel.GetSelectedBlock() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
250 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
251 |
# Get block type informations |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
252 |
blocktype = (self.Controller.GetBlockType(values["type"], |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
253 |
values["inputs"]) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
254 |
if values is not None else None) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
255 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
256 |
# Set input number spin control according to block type informations |
814 | 257 |
if blocktype is not None: |
258 |
self.Inputs.SetValue(len(blocktype["inputs"])) |
|
259 |
self.Inputs.Enable(blocktype["extensible"]) |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
260 |
else: |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
261 |
self.Inputs.SetValue(2) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
262 |
self.Inputs.Enable(False) |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
263 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
264 |
# Update block name with default value if block type is a function and |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
265 |
# 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
|
266 |
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
|
267 |
self.BlockName.Enable(True) |
1244 | 268 |
|
269 |
if self.CurrentBlockName is None: |
|
270 |
# Generate new block name according to block type, taking |
|
271 |
# default element name if it was already a default name for this |
|
272 |
# block type |
|
273 |
default_name_model = GetBlockTypeDefaultNameModel(values["type"]) |
|
274 |
block_name = ( |
|
275 |
self.DefaultElementName |
|
276 |
if (self.DefaultElementName is not None and |
|
277 |
default_name_model.match(self.DefaultElementName)) |
|
278 |
else self.Controller.GenerateNewName( |
|
279 |
self.TagName, None, values["type"]+"%d", 0)) |
|
280 |
else: |
|
281 |
block_name = self.CurrentBlockName |
|
282 |
||
283 |
self.BlockName.ChangeValue(block_name) |
|
814 | 284 |
else: |
285 |
self.BlockName.Enable(False) |
|
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
286 |
self.BlockName.ChangeValue("") |
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
287 |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
288 |
# Refresh preview panel |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
289 |
self.RefreshPreview() |
814 | 290 |
|
291 |
def OnNameChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
292 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
293 |
Called when block name value changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
294 |
@param event: wx.TextEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
295 |
""" |
814 | 296 |
if self.BlockName.IsEnabled(): |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
297 |
# Save block name typed by user |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
298 |
self.CurrentBlockName = self.BlockName.GetValue() |
814 | 299 |
self.RefreshPreview() |
300 |
event.Skip() |
|
301 |
||
302 |
def OnInputsChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
303 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
304 |
Called when block inputs number changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
305 |
@param event: wx.SpinEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
306 |
""" |
814 | 307 |
if self.Inputs.IsEnabled(): |
308 |
self.RefreshPreview() |
|
309 |
event.Skip() |
|
310 |
||
311 |
def OnExecutionOrderChanged(self, event): |
|
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
312 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
313 |
Called when block execution order value changed |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
314 |
@param event: wx.SpinEvent |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
315 |
""" |
814 | 316 |
self.RefreshPreview() |
317 |
event.Skip() |
|
318 |
||
319 |
def OnExecutionControlChanged(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 execution control value 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 |
self.RefreshPreview() |
325 |
event.Skip() |
|
326 |
||
327 |
def RefreshPreview(self): |
|
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 |
Refresh preview panel of graphic element |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
330 |
Override BlockPreviewDialog function |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
331 |
""" |
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
332 |
# Get type selected in library panel |
814 | 333 |
values = self.LibraryPanel.GetSelectedBlock() |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
334 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
335 |
# If a block type is selected in library panel |
814 | 336 |
if values is not None: |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
337 |
# Set graphic element displayed, creating a FBD block element |
1244 | 338 |
self.Element = FBD_Block(self.Preview, values["type"], |
339 |
(self.BlockName.GetValue() |
|
340 |
if self.BlockName.IsEnabled() |
|
341 |
else ""), |
|
814 | 342 |
extension = self.Inputs.GetValue(), |
343 |
inputs = values["inputs"], |
|
344 |
executionControl = self.ExecutionControl.GetValue(), |
|
345 |
executionOrder = self.ExecutionOrder.GetValue()) |
|
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 |
# Reset graphic element displayed |
814 | 348 |
else: |
1244 | 349 |
self.Element = None |
1242
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
350 |
|
ec2c415fc65e
Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents:
1237
diff
changeset
|
351 |
# Call BlockPreviewDialog function |
1236
a5d1d2a2f366
Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents:
1230
diff
changeset
|
352 |
BlockPreviewDialog.RefreshPreview(self) |