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 |
|
1251
|
26 |
from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
|
|
27 |
SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE
|
|
28 |
from graphics.SFC_Objects import SFC_Divergence
|
|
29 |
from BlockPreviewDialog import BlockPreviewDialog
|
814
|
30 |
|
|
31 |
#-------------------------------------------------------------------------------
|
|
32 |
# Create New Divergence Dialog
|
|
33 |
#-------------------------------------------------------------------------------
|
|
34 |
|
1251
|
35 |
"""
|
|
36 |
Class that implements a dialog for defining parameters for creating a new
|
|
37 |
divergence graphic element
|
|
38 |
"""
|
|
39 |
|
|
40 |
class SFCDivergenceDialog(BlockPreviewDialog):
|
814
|
41 |
|
1251
|
42 |
def __init__(self, parent, controller, tagname):
|
|
43 |
"""
|
|
44 |
Constructor
|
|
45 |
@param parent: Parent wx.Window of dialog for modal
|
|
46 |
@param controller: Reference to project controller
|
|
47 |
@param tagname: Tagname of project POU edited
|
|
48 |
"""
|
|
49 |
BlockPreviewDialog.__init__(self, parent, controller, tagname,
|
|
50 |
size=wx.Size(500, 300),
|
814
|
51 |
title=_('Create a new divergence or convergence'))
|
|
52 |
|
1251
|
53 |
# Init common sizers
|
|
54 |
self._init_sizers(2, 0, 7, None, 2, 1)
|
814
|
55 |
|
1251
|
56 |
# Create label for divergence type
|
|
57 |
type_label = wx.StaticText(self, label=_('Type:'))
|
|
58 |
self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
|
814
|
59 |
|
1251
|
60 |
# Create radio buttons for selecting divergence type
|
|
61 |
self.TypeRadioButtons = {}
|
|
62 |
first = True
|
|
63 |
for type, label in [
|
|
64 |
(SELECTION_DIVERGENCE, _('Selection Divergence')),
|
|
65 |
(SELECTION_CONVERGENCE, _('Selection Convergence')),
|
|
66 |
(SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')),
|
|
67 |
(SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))]:
|
|
68 |
radio_button = wx.RadioButton(self, label=label,
|
|
69 |
style=(wx.RB_GROUP if first else 0))
|
|
70 |
radio_button.SetValue(first)
|
|
71 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
|
|
72 |
self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
|
|
73 |
self.TypeRadioButtons[type] = radio_button
|
|
74 |
first = False
|
814
|
75 |
|
1251
|
76 |
# Create label for number of divergence sequences
|
814
|
77 |
sequences_label = wx.StaticText(self,
|
|
78 |
label=_('Number of sequences:'))
|
1251
|
79 |
self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW)
|
814
|
80 |
|
1251
|
81 |
# Create spin control for defining number of divergence sequences
|
814
|
82 |
self.Sequences = wx.SpinCtrl(self, min=2, max=20)
|
|
83 |
self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences)
|
1251
|
84 |
self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW)
|
814
|
85 |
|
1251
|
86 |
# Add preview panel and associated label to sizers
|
|
87 |
self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
|
|
88 |
self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
|
814
|
89 |
|
1251
|
90 |
# Add buttons sizer to sizers
|
|
91 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20,
|
|
92 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
|
814
|
93 |
|
1251
|
94 |
# Selection divergence radio button is default control having keyboard
|
|
95 |
# focus
|
|
96 |
self.TypeRadioButtons[SELECTION_DIVERGENCE].SetFocus()
|
814
|
97 |
|
1251
|
98 |
def GetMinElementSize(self):
|
|
99 |
"""
|
|
100 |
Get minimal graphic element size
|
|
101 |
@return: Tuple containing minimal size (width, height) or None if no
|
|
102 |
element defined
|
|
103 |
"""
|
|
104 |
return self.Element.GetSize()
|
|
105 |
|
|
106 |
def GetDivergenceType(self):
|
|
107 |
"""
|
|
108 |
Return type selected for SFC divergence
|
|
109 |
@return: Type selected (None if not found)
|
|
110 |
"""
|
|
111 |
# Go through radio buttons and return type associated to the one that
|
|
112 |
# is selected
|
|
113 |
for type, control in self.TypeRadioButtons.iteritems():
|
|
114 |
if control.GetValue():
|
|
115 |
return type
|
|
116 |
return None
|
814
|
117 |
|
|
118 |
def GetValues(self):
|
1251
|
119 |
"""
|
|
120 |
Set default SFC divergence parameters
|
|
121 |
@param values: Divergence parameters values
|
|
122 |
"""
|
|
123 |
return {"type": self.GetDivergenceType(),
|
|
124 |
"number": self.Sequences.GetValue()}
|
814
|
125 |
|
|
126 |
def OnTypeChanged(self, event):
|
1251
|
127 |
"""
|
|
128 |
Called when SFC divergence type changed
|
|
129 |
@param event: wx.RadioButtonEvent
|
|
130 |
"""
|
814
|
131 |
self.RefreshPreview()
|
|
132 |
event.Skip()
|
|
133 |
|
|
134 |
def OnSequencesChanged(self, event):
|
1251
|
135 |
"""
|
|
136 |
Called when SFC divergence number of sequences changed
|
|
137 |
@param event: wx.SpinEvent
|
|
138 |
"""
|
814
|
139 |
self.RefreshPreview()
|
|
140 |
event.Skip()
|
|
141 |
|
|
142 |
def RefreshPreview(self):
|
1251
|
143 |
"""
|
|
144 |
Refresh preview panel of graphic element
|
|
145 |
Override BlockPreviewDialog function
|
|
146 |
"""
|
|
147 |
# Set graphic element displayed, creating a SFC divergence
|
|
148 |
self.Element = SFC_Divergence(self.Preview,
|
|
149 |
self.GetDivergenceType(),
|
|
150 |
self.Sequences.GetValue())
|
|
151 |
|
|
152 |
# Call BlockPreviewDialog function
|
|
153 |
BlockPreviewDialog.RefreshPreview(self)
|
|
154 |
|