814
|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
|
|
3 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
|
|
4 |
#based on the plcopen standard.
|
|
5 |
#
|
|
6 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
|
|
7 |
#
|
|
8 |
#See COPYING file for copyrights details.
|
|
9 |
#
|
|
10 |
#This library is free software; you can redistribute it and/or
|
|
11 |
#modify it under the terms of the GNU General Public
|
|
12 |
#License as published by the Free Software Foundation; either
|
|
13 |
#version 2.1 of the License, or (at your option) any later version.
|
|
14 |
#
|
|
15 |
#This library is distributed in the hope that it will be useful,
|
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 |
#General Public License for more details.
|
|
19 |
#
|
|
20 |
#You should have received a copy of the GNU General Public
|
|
21 |
#License along with this library; if not, write to the Free Software
|
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 |
|
|
24 |
import wx
|
|
25 |
|
1252
|
26 |
from graphics.SFC_Objects import SFC_Transition
|
|
27 |
from BlockPreviewDialog import BlockPreviewDialog
|
814
|
28 |
|
|
29 |
#-------------------------------------------------------------------------------
|
1252
|
30 |
# Set Transition Parameters Dialog
|
814
|
31 |
#-------------------------------------------------------------------------------
|
|
32 |
|
1252
|
33 |
"""
|
|
34 |
Class that implements a dialog for defining parameters of a transition graphic
|
|
35 |
element
|
|
36 |
"""
|
|
37 |
|
|
38 |
class SFCTransitionDialog(BlockPreviewDialog):
|
|
39 |
|
|
40 |
def __init__(self, parent, controller, tagname, connection=True):
|
|
41 |
"""
|
|
42 |
Constructor
|
|
43 |
@param parent: Parent wx.Window of dialog for modal
|
|
44 |
@param controller: Reference to project controller
|
|
45 |
@param tagname: Tagname of project POU edited
|
|
46 |
@param connection: True if transition value can be defined by a
|
|
47 |
connection (default: True)
|
|
48 |
"""
|
|
49 |
BlockPreviewDialog.__init__(self, parent, controller, tagname,
|
814
|
50 |
size=wx.Size(350, 300), title=_('Edit transition'))
|
|
51 |
|
1252
|
52 |
# Init common sizers
|
|
53 |
self._init_sizers(2, 0, 8, None, 2, 1)
|
|
54 |
|
|
55 |
# Create label for transition type
|
814
|
56 |
type_label = wx.StaticText(self, label=_('Type:'))
|
1252
|
57 |
self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
|
|
58 |
|
|
59 |
# Create combo box for selecting reference value
|
|
60 |
reference = wx.ComboBox(self, style=wx.CB_READONLY)
|
|
61 |
reference.Append("")
|
|
62 |
for transition in controller.GetEditedElementTransitions(tagname):
|
|
63 |
reference.Append(transition)
|
|
64 |
self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, reference)
|
|
65 |
|
|
66 |
# Create Text control for defining inline value
|
|
67 |
inline = wx.TextCtrl(self)
|
|
68 |
self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline)
|
|
69 |
|
|
70 |
# Create radio buttons for selecting power rail type
|
|
71 |
self.TypeRadioButtons = {}
|
|
72 |
first = True
|
|
73 |
for type, label, control in [('reference', _('Reference'), reference),
|
|
74 |
('inline', _('Inline'), inline),
|
|
75 |
('connection', _('Connection'), None)]:
|
|
76 |
radio_button = wx.RadioButton(self, label=label,
|
|
77 |
style=(wx.RB_GROUP if first else 0))
|
|
78 |
radio_button.SetValue(first)
|
|
79 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
|
|
80 |
self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
|
|
81 |
if control is not None:
|
|
82 |
control.Enable(first)
|
|
83 |
self.LeftGridSizer.AddWindow(control, flag=wx.GROW)
|
|
84 |
self.TypeRadioButtons[type] = (radio_button, control)
|
|
85 |
first = False
|
|
86 |
|
|
87 |
# Create label for transition priority
|
814
|
88 |
priority_label = wx.StaticText(self, label=_('Priority:'))
|
1252
|
89 |
self.LeftGridSizer.AddWindow(priority_label, flag=wx.GROW)
|
|
90 |
|
|
91 |
# Create spin control for defining priority value
|
814
|
92 |
self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
|
|
93 |
self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority)
|
1252
|
94 |
self.LeftGridSizer.AddWindow(self.Priority, flag=wx.GROW)
|
|
95 |
|
|
96 |
# Add preview panel and associated label to sizers
|
|
97 |
self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
|
|
98 |
self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
|
|
99 |
|
|
100 |
# Add buttons sizer to sizers
|
|
101 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20,
|
814
|
102 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
|
|
103 |
|
1252
|
104 |
# Reference radio button is default control having keyboard focus
|
|
105 |
self.TypeRadioButtons["reference"][0].SetFocus()
|
|
106 |
|
|
107 |
def GetTransitionType(self):
|
|
108 |
"""
|
|
109 |
Return type selected for SFC transition and associated value
|
|
110 |
@return: Type selected and associated value (None if no value)
|
|
111 |
"""
|
|
112 |
# Go through radio buttons and return type and value associated to the
|
|
113 |
# one that is selected
|
|
114 |
for type, (radio, control) in self.TypeRadioButtons.iteritems():
|
|
115 |
if radio.GetValue():
|
|
116 |
if isinstance(control, wx.ComboBox):
|
|
117 |
return type, control.GetStringSelection()
|
|
118 |
elif isinstance(control, wx.TextCtrl):
|
|
119 |
return type, control.GetValue()
|
|
120 |
else:
|
|
121 |
return type, None
|
|
122 |
return None, None
|
|
123 |
|
|
124 |
def SetValues(self, values):
|
|
125 |
"""
|
|
126 |
Set default SFC transition parameters
|
|
127 |
@param values: Transition parameters values
|
|
128 |
"""
|
|
129 |
# Extract transition value according to type
|
|
130 |
type_value = values.get("value", None)
|
|
131 |
|
|
132 |
# For each parameters defined, set corresponding control value
|
|
133 |
for name, value in values.items():
|
|
134 |
|
|
135 |
# Parameter is SFC transition priority
|
|
136 |
if name == "priority":
|
|
137 |
self.Priority.SetValue(values["priority"])
|
|
138 |
|
|
139 |
# Parameter is SFC transition type
|
|
140 |
elif name == "type":
|
|
141 |
for type, (radio, control) in self.TypeRadioButtons.iteritems():
|
|
142 |
radio.SetValue(type == value)
|
|
143 |
if control is not None:
|
|
144 |
# Enable associated control to type and set value
|
|
145 |
control.Enable(type == value)
|
|
146 |
if type == value:
|
|
147 |
if isinstance(control, wx.ComboBox):
|
|
148 |
control.SetStringSelection(type_value)
|
|
149 |
elif isinstance(control, wx.TextCtrl):
|
|
150 |
control.ChangeValue(type_value)
|
|
151 |
|
|
152 |
# Refresh preview panel
|
|
153 |
self.RefreshPreview()
|
|
154 |
|
|
155 |
def GetValues(self):
|
|
156 |
"""
|
|
157 |
Return SFC transition parameters defined in dialog
|
|
158 |
@return: {parameter_name: parameter_value,...}
|
|
159 |
"""
|
|
160 |
values = {"priority" : self.Priority.GetValue()}
|
|
161 |
values["type"], values["value"] = self.GetTransitionType()
|
|
162 |
values["width"], values["height"] = self.Element.GetSize()
|
|
163 |
return values
|
|
164 |
|
|
165 |
def OnOK(self, event):
|
|
166 |
"""
|
|
167 |
Called when dialog OK button is pressed
|
|
168 |
Test if parameters defined are valid
|
|
169 |
@param event: wx.Event from OK button
|
|
170 |
"""
|
|
171 |
message = None
|
|
172 |
|
|
173 |
# Get transition type and value associated
|
|
174 |
type, value = self.GetTransitionType()
|
|
175 |
|
|
176 |
# Test that value associated to type is defined
|
|
177 |
if type != "connection" and value == "":
|
|
178 |
message = _("Form isn't complete. %s must be filled!") % type
|
|
179 |
|
|
180 |
# Show error message if an error is detected
|
|
181 |
if message is not None:
|
|
182 |
self.ShowErrorMessage(message)
|
|
183 |
|
|
184 |
else:
|
|
185 |
# Call BlockPreviewDialog function
|
|
186 |
BlockPreviewDialog.OnOK(self, event)
|
|
187 |
|
|
188 |
def OnTypeChanged(self, event):
|
|
189 |
"""
|
|
190 |
Called when transition type changed
|
|
191 |
@param event: wx.RadioButtonEvent
|
|
192 |
"""
|
|
193 |
# Refresh sensibility of control associated to transition types
|
|
194 |
for type, (radio, control) in self.TypeRadioButtons.iteritems():
|
|
195 |
if control is not None:
|
|
196 |
control.Enable(radio.GetValue())
|
|
197 |
|
|
198 |
# Refresh preview panel
|
|
199 |
self.RefreshPreview()
|
|
200 |
event.Skip()
|
|
201 |
|
|
202 |
def OnReferenceChanged(self, event):
|
|
203 |
"""
|
|
204 |
Called when SFC transition reference value changed
|
|
205 |
@param event: wx.ComboBoxEvent
|
|
206 |
"""
|
|
207 |
self.RefreshPreview()
|
|
208 |
event.Skip()
|
|
209 |
|
|
210 |
def OnInlineChanged(self, event):
|
|
211 |
"""
|
|
212 |
Called when SFC transition inline value changed
|
|
213 |
@param event: wx.TextEvent
|
|
214 |
"""
|
|
215 |
self.RefreshPreview()
|
|
216 |
event.Skip()
|
|
217 |
|
|
218 |
def OnPriorityChanged(self, event):
|
|
219 |
"""
|
|
220 |
Called when block inputs number changed
|
|
221 |
@param event: wx.SpinEvent
|
|
222 |
"""
|
|
223 |
self.RefreshPreview()
|
|
224 |
event.Skip()
|
|
225 |
|
|
226 |
def RefreshPreview(self):
|
|
227 |
"""
|
|
228 |
Refresh preview panel of graphic element
|
|
229 |
Override BlockPreviewDialog function
|
|
230 |
"""
|
|
231 |
# Set graphic element displayed, creating a SFC transition
|
814
|
232 |
self.Element = SFC_Transition(self.Preview)
|
1252
|
233 |
self.Element.SetType(*self.GetTransitionType())
|
|
234 |
self.Element.SetPriority(self.Priority.GetValue())
|
|
235 |
|
|
236 |
# Call BlockPreviewDialog function
|
|
237 |
BlockPreviewDialog.RefreshPreview(self)
|