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 |
# Create New Divergence Dialog
|
|
30 |
#-------------------------------------------------------------------------------
|
|
31 |
|
|
32 |
class SFCDivergenceDialog(wx.Dialog):
|
|
33 |
|
|
34 |
def __init__(self, parent, controller):
|
|
35 |
wx.Dialog.__init__(self, parent, size=wx.Size(500, 300),
|
|
36 |
title=_('Create a new divergence or convergence'))
|
|
37 |
|
|
38 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
|
|
39 |
main_sizer.AddGrowableCol(0)
|
|
40 |
main_sizer.AddGrowableRow(0)
|
|
41 |
|
|
42 |
column_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
43 |
main_sizer.AddSizer(column_sizer, border=20,
|
|
44 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
|
|
45 |
|
|
46 |
left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=7, vgap=5)
|
|
47 |
left_gridsizer.AddGrowableCol(0)
|
|
48 |
column_sizer.AddSizer(left_gridsizer, 1, border=5,
|
|
49 |
flag=wx.GROW|wx.RIGHT)
|
|
50 |
|
|
51 |
type_label = wx.StaticText(self, label=_('Type:'))
|
|
52 |
left_gridsizer.AddWindow(type_label, flag=wx.GROW)
|
|
53 |
|
|
54 |
self.SelectionDivergence = wx.RadioButton(self,
|
|
55 |
label=_('Selection Divergence'), style=wx.RB_GROUP)
|
|
56 |
self.SelectionDivergence.SetValue(True)
|
|
57 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged,
|
|
58 |
self.SelectionDivergence)
|
|
59 |
left_gridsizer.AddWindow(self.SelectionDivergence, flag=wx.GROW)
|
|
60 |
|
|
61 |
self.SelectionConvergence = wx.RadioButton(self,
|
|
62 |
label=_('Selection Convergence'))
|
|
63 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged,
|
|
64 |
self.SelectionConvergence)
|
|
65 |
left_gridsizer.AddWindow(self.SelectionConvergence, flag=wx.GROW)
|
|
66 |
|
|
67 |
self.SimultaneousDivergence = wx.RadioButton(self,
|
|
68 |
label=_('Simultaneous Divergence'))
|
|
69 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged,
|
|
70 |
self.SimultaneousDivergence)
|
|
71 |
left_gridsizer.AddWindow(self.SimultaneousDivergence, flag=wx.GROW)
|
|
72 |
|
|
73 |
self.SimultaneousConvergence = wx.RadioButton(self,
|
|
74 |
label=_('Simultaneous Convergence'))
|
|
75 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged,
|
|
76 |
self.SimultaneousConvergence)
|
|
77 |
left_gridsizer.AddWindow(self.SimultaneousConvergence, flag=wx.GROW)
|
|
78 |
|
|
79 |
sequences_label = wx.StaticText(self,
|
|
80 |
label=_('Number of sequences:'))
|
|
81 |
left_gridsizer.AddWindow(sequences_label, flag=wx.GROW)
|
|
82 |
|
|
83 |
self.Sequences = wx.SpinCtrl(self, min=2, max=20)
|
|
84 |
self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences)
|
|
85 |
left_gridsizer.AddWindow(self.Sequences, flag=wx.GROW)
|
|
86 |
|
|
87 |
right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
|
|
88 |
right_gridsizer.AddGrowableCol(0)
|
|
89 |
right_gridsizer.AddGrowableRow(1)
|
|
90 |
column_sizer.AddSizer(right_gridsizer, 1, border=5,
|
|
91 |
flag=wx.GROW|wx.LEFT)
|
|
92 |
|
|
93 |
preview_label = wx.StaticText(self, label=_('Preview:'))
|
|
94 |
right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
|
|
95 |
|
|
96 |
self.Preview = wx.Panel(self, style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
|
|
97 |
self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
|
|
98 |
self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
99 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
|
|
100 |
setattr(self.Preview, "IsOfType", controller.IsOfType)
|
|
101 |
right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
|
|
102 |
|
|
103 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
|
|
104 |
main_sizer.AddSizer(button_sizer, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
|
|
105 |
|
|
106 |
self.SetSizer(main_sizer)
|
|
107 |
|
|
108 |
self.Divergence = None
|
|
109 |
self.MinSize = (0, 0)
|
|
110 |
|
|
111 |
self.SelectionDivergence.SetFocus()
|
|
112 |
|
|
113 |
def SetPreviewFont(self, font):
|
|
114 |
self.Preview.SetFont(font)
|
|
115 |
|
|
116 |
def GetValues(self):
|
|
117 |
values = {}
|
|
118 |
if self.SelectionDivergence.GetValue():
|
|
119 |
values["type"] = SELECTION_DIVERGENCE
|
|
120 |
elif self.SelectionConvergence.GetValue():
|
|
121 |
values["type"] = SELECTION_CONVERGENCE
|
|
122 |
elif self.SimultaneousDivergence.GetValue():
|
|
123 |
values["type"] = SIMULTANEOUS_DIVERGENCE
|
|
124 |
else:
|
|
125 |
values["type"] = SIMULTANEOUS_CONVERGENCE
|
|
126 |
values["number"] = self.Sequences.GetValue()
|
|
127 |
return values
|
|
128 |
|
|
129 |
def SetMinSize(self, size):
|
|
130 |
self.MinSize = size
|
|
131 |
|
|
132 |
def OnTypeChanged(self, event):
|
|
133 |
self.RefreshPreview()
|
|
134 |
event.Skip()
|
|
135 |
|
|
136 |
def OnSequencesChanged(self, event):
|
|
137 |
self.RefreshPreview()
|
|
138 |
event.Skip()
|
|
139 |
|
|
140 |
def RefreshPreview(self):
|
|
141 |
dc = wx.ClientDC(self.Preview)
|
|
142 |
dc.SetFont(self.Preview.GetFont())
|
|
143 |
dc.Clear()
|
|
144 |
if self.SelectionDivergence.GetValue():
|
|
145 |
self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue())
|
|
146 |
elif self.SelectionConvergence.GetValue():
|
|
147 |
self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue())
|
|
148 |
elif self.SimultaneousDivergence.GetValue():
|
|
149 |
self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue())
|
|
150 |
else:
|
|
151 |
self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue())
|
|
152 |
width, height = self.Divergence.GetSize()
|
|
153 |
min_width, min_height = max(width, self.MinSize[0]), max(height, self.MinSize[1])
|
|
154 |
self.Divergence.SetSize(min_width, min_height)
|
|
155 |
clientsize = self.Preview.GetClientSize()
|
|
156 |
x = (clientsize.width - min_width) / 2
|
|
157 |
y = (clientsize.height - min_height) / 2
|
|
158 |
self.Divergence.SetPosition(x, y)
|
|
159 |
self.Divergence.Draw(dc)
|
|
160 |
|
|
161 |
def OnPaint(self, event):
|
|
162 |
self.RefreshPreview()
|
|
163 |
event.Skip()
|