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 |
|
|
26 |
from graphics import *
|
|
27 |
|
|
28 |
#-------------------------------------------------------------------------------
|
|
29 |
# Edit Transition Content Dialog
|
|
30 |
#-------------------------------------------------------------------------------
|
|
31 |
|
|
32 |
class SFCTransitionDialog(wx.Dialog):
|
|
33 |
|
|
34 |
def __init__(self, parent, controller, connection):
|
|
35 |
self.Connection = connection
|
|
36 |
|
|
37 |
wx.Dialog.__init__(self, parent,
|
|
38 |
size=wx.Size(350, 300), title=_('Edit transition'))
|
|
39 |
|
|
40 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
|
|
41 |
main_sizer.AddGrowableCol(0)
|
|
42 |
main_sizer.AddGrowableRow(0)
|
|
43 |
|
|
44 |
column_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
45 |
main_sizer.AddSizer(column_sizer, border=20,
|
|
46 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
|
|
47 |
|
|
48 |
left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5)
|
|
49 |
left_gridsizer.AddGrowableCol(0)
|
|
50 |
column_sizer.AddSizer(left_gridsizer, 1, border=5,
|
|
51 |
flag=wx.GROW|wx.RIGHT)
|
|
52 |
|
|
53 |
type_label = wx.StaticText(self, label=_('Type:'))
|
|
54 |
left_gridsizer.AddWindow(type_label, flag=wx.GROW)
|
|
55 |
|
|
56 |
self.ReferenceRadioButton = wx.RadioButton(self,
|
|
57 |
label=_('Reference'), style=wx.RB_GROUP)
|
|
58 |
self.ReferenceRadioButton.SetValue(True)
|
|
59 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ReferenceRadioButton)
|
|
60 |
left_gridsizer.AddWindow(self.ReferenceRadioButton, flag=wx.GROW)
|
|
61 |
|
|
62 |
self.Reference = wx.ComboBox(self, style=wx.CB_READONLY)
|
|
63 |
self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, self.Reference)
|
|
64 |
left_gridsizer.AddWindow(self.Reference, flag=wx.GROW)
|
|
65 |
|
|
66 |
self.InlineRadioButton = wx.RadioButton(self, label=_('Inline'))
|
|
67 |
self.InlineRadioButton.SetValue(False)
|
|
68 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.InlineRadioButton)
|
|
69 |
left_gridsizer.AddWindow(self.InlineRadioButton, flag=wx.GROW)
|
|
70 |
|
|
71 |
self.Inline = wx.TextCtrl(self)
|
|
72 |
self.Inline.Enable(False)
|
|
73 |
self.Bind(wx.EVT_TEXT, self.OnInlineChanged, self.Inline)
|
|
74 |
left_gridsizer.AddWindow(self.Inline, flag=wx.GROW)
|
|
75 |
|
|
76 |
self.ConnectionRadioButton = wx.RadioButton(self, label=_('Connection'))
|
|
77 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ConnectionRadioButton)
|
|
78 |
self.ConnectionRadioButton.SetValue(False)
|
|
79 |
if not self.Connection:
|
|
80 |
self.ConnectionRadioButton.Hide()
|
|
81 |
left_gridsizer.AddWindow(self.ConnectionRadioButton, flag=wx.GROW)
|
|
82 |
|
|
83 |
priority_label = wx.StaticText(self, label=_('Priority:'))
|
|
84 |
left_gridsizer.AddWindow(priority_label, flag=wx.GROW)
|
|
85 |
|
|
86 |
self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
|
|
87 |
self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority)
|
|
88 |
left_gridsizer.AddWindow(self.Priority, flag=wx.GROW)
|
|
89 |
|
|
90 |
right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
|
|
91 |
right_gridsizer.AddGrowableCol(0)
|
|
92 |
right_gridsizer.AddGrowableRow(1)
|
|
93 |
column_sizer.AddSizer(right_gridsizer, 1, border=5,
|
|
94 |
flag=wx.GROW|wx.LEFT)
|
|
95 |
|
|
96 |
preview_label = wx.StaticText(self, label=_('Preview:'))
|
|
97 |
right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
|
|
98 |
|
|
99 |
self.Preview = wx.Panel(self,
|
|
100 |
style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
|
|
101 |
self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
|
|
102 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
|
|
103 |
setattr(self.Preview, "RefreshTransitionModel", lambda x:None)
|
|
104 |
setattr(self.Preview, "GetScaling", lambda:None)
|
|
105 |
setattr(self.Preview, "IsOfType", controller.IsOfType)
|
|
106 |
self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
107 |
right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
|
|
108 |
|
|
109 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
|
|
110 |
self.Bind(wx.EVT_BUTTON, self.OnOK,
|
|
111 |
button_sizer.GetAffirmativeButton())
|
|
112 |
main_sizer.AddSizer(button_sizer, border=20,
|
|
113 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
|
|
114 |
|
|
115 |
self.SetSizer(main_sizer)
|
|
116 |
|
|
117 |
self.Transition = None
|
|
118 |
self.MinTransitionSize = None
|
|
119 |
|
|
120 |
self.Element = SFC_Transition(self.Preview)
|
|
121 |
|
|
122 |
self.ReferenceRadioButton.SetFocus()
|
|
123 |
|
|
124 |
def SetPreviewFont(self, font):
|
|
125 |
self.Preview.SetFont(font)
|
|
126 |
|
|
127 |
def SetElementSize(self, size):
|
|
128 |
min_width, min_height = self.Element.GetMinSize()
|
|
129 |
width, height = max(min_width, size[0]), max(min_height, size[1])
|
|
130 |
self.Element.SetSize(width, height)
|
|
131 |
|
|
132 |
def OnOK(self, event):
|
|
133 |
error = []
|
|
134 |
if self.ReferenceRadioButton.GetValue() and self.Reference.GetStringSelection() == "":
|
|
135 |
error.append(_("Reference"))
|
|
136 |
if self.InlineRadioButton.GetValue() and self.Inline.GetValue() == "":
|
|
137 |
error.append(_("Inline"))
|
|
138 |
if len(error) > 0:
|
|
139 |
text = ""
|
|
140 |
for i, item in enumerate(error):
|
|
141 |
if i == 0:
|
|
142 |
text += item
|
|
143 |
elif i == len(error) - 1:
|
|
144 |
text += _(" and %s")%item
|
|
145 |
else:
|
|
146 |
text += _(", %s")%item
|
|
147 |
dialog = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
|
|
148 |
dialog.ShowModal()
|
|
149 |
dialog.Destroy()
|
|
150 |
else:
|
|
151 |
self.EndModal(wx.ID_OK)
|
|
152 |
|
|
153 |
def OnTypeChanged(self, event):
|
|
154 |
if self.ReferenceRadioButton.GetValue():
|
|
155 |
self.Element.SetType("reference", self.Reference.GetStringSelection())
|
|
156 |
self.Reference.Enable(True)
|
|
157 |
self.Inline.Enable(False)
|
|
158 |
elif self.InlineRadioButton.GetValue():
|
|
159 |
self.Element.SetType("inline", self.Inline.GetValue())
|
|
160 |
self.Reference.Enable(False)
|
|
161 |
self.Inline.Enable(True)
|
|
162 |
else:
|
|
163 |
self.Element.SetType("connection")
|
|
164 |
self.Reference.Enable(False)
|
|
165 |
self.Inline.Enable(False)
|
|
166 |
self.RefreshPreview()
|
|
167 |
event.Skip()
|
|
168 |
|
|
169 |
def OnReferenceChanged(self, event):
|
|
170 |
self.Element.SetType("reference", self.Reference.GetStringSelection())
|
|
171 |
self.RefreshPreview()
|
|
172 |
event.Skip()
|
|
173 |
|
|
174 |
def OnInlineChanged(self, event):
|
|
175 |
self.Element.SetType("inline", self.Inline.GetValue())
|
|
176 |
self.RefreshPreview()
|
|
177 |
event.Skip()
|
|
178 |
|
|
179 |
def OnPriorityChanged(self, event):
|
|
180 |
self.Element.SetPriority(int(self.Priority.GetValue()))
|
|
181 |
self.RefreshPreview()
|
|
182 |
event.Skip()
|
|
183 |
|
|
184 |
def SetTransitions(self, transitions):
|
|
185 |
self.Reference.Append("")
|
|
186 |
for transition in transitions:
|
|
187 |
self.Reference.Append(transition)
|
|
188 |
|
|
189 |
def SetValues(self, values):
|
|
190 |
if values["type"] == "reference":
|
|
191 |
self.ReferenceRadioButton.SetValue(True)
|
|
192 |
self.InlineRadioButton.SetValue(False)
|
|
193 |
self.ConnectionRadioButton.SetValue(False)
|
|
194 |
self.Reference.Enable(True)
|
|
195 |
self.Inline.Enable(False)
|
|
196 |
self.Reference.SetStringSelection(values["value"])
|
|
197 |
self.Element.SetType("reference", values["value"])
|
|
198 |
elif values["type"] == "inline":
|
|
199 |
self.ReferenceRadioButton.SetValue(False)
|
|
200 |
self.InlineRadioButton.SetValue(True)
|
|
201 |
self.ConnectionRadioButton.SetValue(False)
|
|
202 |
self.Reference.Enable(False)
|
|
203 |
self.Inline.Enable(True)
|
|
204 |
self.Inline.SetValue(values["value"])
|
|
205 |
self.Element.SetType("inline", values["value"])
|
|
206 |
elif values["type"] == "connection" and self.Connection:
|
|
207 |
self.ReferenceRadioButton.SetValue(False)
|
|
208 |
self.InlineRadioButton.SetValue(False)
|
|
209 |
self.ConnectionRadioButton.SetValue(True)
|
|
210 |
self.Reference.Enable(False)
|
|
211 |
self.Inline.Enable(False)
|
|
212 |
self.Element.SetType("connection")
|
|
213 |
self.Priority.SetValue(values["priority"])
|
|
214 |
self.Element.SetPriority(values["priority"])
|
|
215 |
self.RefreshPreview()
|
|
216 |
|
|
217 |
def GetValues(self):
|
|
218 |
values = {"priority" : int(self.Priority.GetValue())}
|
|
219 |
if self.ReferenceRadioButton.GetValue():
|
|
220 |
values["type"] = "reference"
|
|
221 |
values["value"] = self.Reference.GetStringSelection()
|
|
222 |
elif self.InlineRadioButton.GetValue():
|
|
223 |
values["type"] = "inline"
|
|
224 |
values["value"] = self.Inline.GetValue()
|
|
225 |
else:
|
|
226 |
values["type"] = "connection"
|
|
227 |
values["value"] = None
|
|
228 |
return values
|
|
229 |
|
|
230 |
def RefreshPreview(self):
|
|
231 |
dc = wx.ClientDC(self.Preview)
|
|
232 |
dc.SetFont(self.Preview.GetFont())
|
|
233 |
dc.Clear()
|
|
234 |
clientsize = self.Preview.GetClientSize()
|
|
235 |
posx, posy = self.Element.GetPosition()
|
|
236 |
rect = self.Element.GetBoundingBox()
|
|
237 |
diffx, diffy = posx - rect.x, posy - rect.y
|
|
238 |
self.Element.SetPosition((clientsize.width - rect.width) / 2 + diffx, (clientsize.height - rect.height) / 2 + diffy)
|
|
239 |
self.Element.Draw(dc)
|
|
240 |
|
|
241 |
def OnPaint(self, event):
|
|
242 |
self.RefreshPreview()
|
|
243 |
event.Skip()
|