Laurent@814: # -*- coding: utf-8 -*- Laurent@814: Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@814: #based on the plcopen standard. Laurent@814: # Laurent@814: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # Laurent@814: #See COPYING file for copyrights details. Laurent@814: # Laurent@814: #This library is free software; you can redistribute it and/or Laurent@814: #modify it under the terms of the GNU General Public Laurent@814: #License as published by the Free Software Foundation; either Laurent@814: #version 2.1 of the License, or (at your option) any later version. Laurent@814: # Laurent@814: #This library is distributed in the hope that it will be useful, Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: #General Public License for more details. Laurent@814: # Laurent@814: #You should have received a copy of the GNU General Public Laurent@814: #License along with this library; if not, write to the Free Software Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@814: Laurent@814: import wx Laurent@814: Laurent@1251: from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ Laurent@1251: SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE Laurent@1251: from graphics.SFC_Objects import SFC_Divergence Laurent@1251: from BlockPreviewDialog import BlockPreviewDialog Laurent@814: Laurent@814: #------------------------------------------------------------------------------- Laurent@814: # Create New Divergence Dialog Laurent@814: #------------------------------------------------------------------------------- Laurent@814: Laurent@1251: """ Laurent@1251: Class that implements a dialog for defining parameters for creating a new Laurent@1251: divergence graphic element Laurent@1251: """ Laurent@1251: Laurent@1251: class SFCDivergenceDialog(BlockPreviewDialog): Laurent@814: Laurent@1251: def __init__(self, parent, controller, tagname): Laurent@1251: """ Laurent@1251: Constructor Laurent@1251: @param parent: Parent wx.Window of dialog for modal Laurent@1251: @param controller: Reference to project controller Laurent@1251: @param tagname: Tagname of project POU edited Laurent@1251: """ Laurent@1251: BlockPreviewDialog.__init__(self, parent, controller, tagname, Laurent@1251: size=wx.Size(500, 300), Laurent@814: title=_('Create a new divergence or convergence')) Laurent@814: Laurent@1251: # Init common sizers Laurent@1251: self._init_sizers(2, 0, 7, None, 2, 1) Laurent@814: Laurent@1251: # Create label for divergence type Laurent@1251: type_label = wx.StaticText(self, label=_('Type:')) Laurent@1251: self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) Laurent@814: Laurent@1251: # Create radio buttons for selecting divergence type Laurent@1251: self.TypeRadioButtons = {} Laurent@1251: first = True Laurent@1251: for type, label in [ Laurent@1251: (SELECTION_DIVERGENCE, _('Selection Divergence')), Laurent@1251: (SELECTION_CONVERGENCE, _('Selection Convergence')), Laurent@1251: (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')), Laurent@1251: (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))]: Laurent@1251: radio_button = wx.RadioButton(self, label=label, Laurent@1251: style=(wx.RB_GROUP if first else 0)) Laurent@1251: radio_button.SetValue(first) Laurent@1251: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) Laurent@1251: self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) Laurent@1251: self.TypeRadioButtons[type] = radio_button Laurent@1251: first = False Laurent@814: Laurent@1251: # Create label for number of divergence sequences Laurent@814: sequences_label = wx.StaticText(self, Laurent@814: label=_('Number of sequences:')) Laurent@1251: self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW) Laurent@814: Laurent@1251: # Create spin control for defining number of divergence sequences Laurent@814: self.Sequences = wx.SpinCtrl(self, min=2, max=20) Laurent@814: self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences) Laurent@1251: self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW) Laurent@814: Laurent@1251: # Add preview panel and associated label to sizers Laurent@1251: self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) Laurent@1251: self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) Laurent@814: Laurent@1251: # Add buttons sizer to sizers Laurent@1251: self.MainSizer.AddSizer(self.ButtonSizer, border=20, Laurent@1251: flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) Laurent@814: Laurent@1251: # Selection divergence radio button is default control having keyboard Laurent@1251: # focus Laurent@1251: self.TypeRadioButtons[SELECTION_DIVERGENCE].SetFocus() Laurent@814: Laurent@1251: def GetMinElementSize(self): Laurent@1251: """ Laurent@1251: Get minimal graphic element size Laurent@1251: @return: Tuple containing minimal size (width, height) or None if no Laurent@1251: element defined Laurent@1251: """ Laurent@1251: return self.Element.GetSize() Laurent@1251: Laurent@1251: def GetDivergenceType(self): Laurent@1251: """ Laurent@1251: Return type selected for SFC divergence Laurent@1251: @return: Type selected (None if not found) Laurent@1251: """ Laurent@1251: # Go through radio buttons and return type associated to the one that Laurent@1251: # is selected Laurent@1251: for type, control in self.TypeRadioButtons.iteritems(): Laurent@1251: if control.GetValue(): Laurent@1251: return type Laurent@1251: return None Laurent@814: Laurent@814: def GetValues(self): Laurent@1251: """ Laurent@1251: Set default SFC divergence parameters Laurent@1251: @param values: Divergence parameters values Laurent@1251: """ Laurent@1251: return {"type": self.GetDivergenceType(), Laurent@1251: "number": self.Sequences.GetValue()} Laurent@814: Laurent@814: def OnTypeChanged(self, event): Laurent@1251: """ Laurent@1251: Called when SFC divergence type changed Laurent@1251: @param event: wx.RadioButtonEvent Laurent@1251: """ Laurent@814: self.RefreshPreview() Laurent@814: event.Skip() Laurent@814: Laurent@814: def OnSequencesChanged(self, event): Laurent@1251: """ Laurent@1251: Called when SFC divergence number of sequences changed Laurent@1251: @param event: wx.SpinEvent Laurent@1251: """ Laurent@814: self.RefreshPreview() Laurent@814: event.Skip() Laurent@814: Laurent@814: def RefreshPreview(self): Laurent@1251: """ Laurent@1251: Refresh preview panel of graphic element Laurent@1251: Override BlockPreviewDialog function Laurent@1251: """ Laurent@1251: # Set graphic element displayed, creating a SFC divergence Laurent@1251: self.Element = SFC_Divergence(self.Preview, Laurent@1251: self.GetDivergenceType(), Laurent@1251: self.Sequences.GetValue()) Laurent@1251: Laurent@1251: # Call BlockPreviewDialog function Laurent@1251: BlockPreviewDialog.RefreshPreview(self) Laurent@1251: