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