dialogs/ConnectionDialog.py
author Laurent Bessard
Wed, 12 Jun 2013 09:36:59 +0200
changeset 1249 b956c924cbbd
parent 1247 92588e69d853
child 1250 7e6de17c687a
permissions -rw-r--r--
Rewrite LDPowerRailDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#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
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    27
from graphics.GraphicCommons import CONNECTOR, CONTINUATION
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    28
from graphics.FBD_Objects import FBD_Connector
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    29
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    32
#                       Set Connection Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    35
"""
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    36
Class that implements a dialog for defining parameters of a connection graphic
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    37
element
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    38
"""
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    39
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    40
class ConnectionDialog(BlockPreviewDialog):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
    
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    42
    def __init__(self, parent, controller, tagname, apply_button=False):
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    43
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    44
        Constructor
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    45
        @param parent: Parent wx.Window of dialog for modal
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    46
        @param controller: Reference to project controller
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    47
        @param tagname: Tagname of project POU edited
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    48
        @param apply_button: Enable button for applying connector modification
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    49
        to all connector having the same name in POU (default: False)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    50
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    51
        BlockPreviewDialog.__init__(self, parent, controller, tagname, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
              size=wx.Size(350, 220), title=_('Connection Properties'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    54
        # Create dialog main sizer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        main_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    59
        # Create a sizer for dividing FBD connection parameters in two columns
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        main_sizer.AddSizer(column_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    64
        # Create a sizer for left column
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        left_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        column_sizer.AddSizer(left_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
              flag=wx.GROW|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    70
        # Create label for connection type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        type_label = wx.StaticText(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        left_gridsizer.AddWindow(type_label, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    74
        # Create radio buttons for selecting connection type
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
    75
        self.TypeRadioButtons = {}
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    76
        first = True
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    77
        for type, label in [(CONNECTOR, _('Connector')),
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    78
                            (CONTINUATION, _('Continuation'))]:
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    79
            radio_button = wx.RadioButton(self, label=label, 
1247
92588e69d853 Fixed bug in newly rewritten dialogs
Laurent Bessard
parents: 1246
diff changeset
    80
                  style=(wx.RB_GROUP if first else 0))
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    81
            radio_button.SetValue(first)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    82
            self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    83
            left_gridsizer.AddWindow(radio_button, flag=wx.GROW)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
    84
            self.TypeRadioButtons[type] = radio_button
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    85
            first = False
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    86
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    87
        # Create label for connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        name_label = wx.StaticText(self, label=_('Name:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        left_gridsizer.AddWindow(name_label, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    91
        # Create text control for defining connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.ConnectionName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        left_gridsizer.AddWindow(self.ConnectionName, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    96
        # Create a sizer for right column
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        right_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        right_gridsizer.AddGrowableRow(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
              flag=wx.GROW|wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   103
        # Add preview panel and associated label to sizers
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   104
        right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   107
        # Add buttons sizer to sizers
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   108
        main_sizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   111
        # Add button for applying connection name modification to all connection
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   112
        # of POU
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   113
        if apply_button:
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   114
            self.ApplyToAllButton = wx.Button(self, label=_("Propagate Name"))
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   115
            self.ApplyToAllButton.SetToolTipString(
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   116
                _("Apply name modification to all continuations with the same name"))
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   117
            self.Bind(wx.EVT_BUTTON, self.OnApplyToAll, self.ApplyToAllButton)
1247
92588e69d853 Fixed bug in newly rewritten dialogs
Laurent Bessard
parents: 1246
diff changeset
   118
            self.ButtonSizer.AddWindow(self.ApplyToAllButton, 
92588e69d853 Fixed bug in newly rewritten dialogs
Laurent Bessard
parents: 1246
diff changeset
   119
                    border=(3 if wx.Platform == '__WXMSW__' else 10),
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   120
                    flag=wx.LEFT)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   121
        else:
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   122
            self.ConnectionName.ChangeValue(
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   123
                controller.GenerateNewName(
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   124
                        tagname, None, "Connection%d", 0))
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   125
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   128
        # Connector radio button is default control having keyboard focus
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
   129
        self.TypeRadioButtons[CONNECTOR].SetFocus()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
    
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   131
    def GetConnectionType(self):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   132
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   133
        Return type selected for connection
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   134
        @return: Type selected (CONNECTOR or CONTINUATION)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   135
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   136
        return (CONNECTOR
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   137
                if self.TypeRadioButtons[CONNECTOR].GetValue()
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   138
                else CONTINUATION)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   139
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
    def SetValues(self, values):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   141
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   142
        Set default connection parameters
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   143
        @param values: Connection parameters values
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   144
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   145
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        for name, value in values.items():
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   147
            
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   148
            # Parameter is connection type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
            if name == "type":
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
   150
                self.TypeRadioButtons[value].SetValue(True)
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   151
            
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   152
            # Parameter is connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
            elif name == "name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
                self.ConnectionName.SetValue(value)
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   155
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   156
        # Refresh preview panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
    def GetValues(self):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   160
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   161
        Return connection parameters defined in dialog
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   162
        @return: {parameter_name: parameter_value,...}
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   163
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   164
        values = {
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   165
            "type": self.GetConnectionType(),
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   166
            "name": self.ConnectionName.GetValue()}
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   167
        values["width"], values["height"] = self.Element.GetSize()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
        return values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   170
    def TestConnectionName(self):
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   171
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   172
        Test that connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   173
        @return: True if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   174
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        message = None
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   176
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   177
        # Get connection name typed by user
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        connection_name = self.ConnectionName.GetValue()
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   179
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   180
        # Test that a name have been defined
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
        if connection_name == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
            message = _("Form isn't complete. Name must be filled!")
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   183
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   184
        # If an error have been identify, show error message dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
        if message is not None:
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   186
            self.ShowErrorMessage(message)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   187
            # Test failed
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   188
            return False
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   189
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   190
        # Return result of element name test
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   191
        return self.TestElementName(connection_name)
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   192
        
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   193
    def OnOK(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   194
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   195
        Called when dialog OK button is pressed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   196
        Test if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   197
        @param event: wx.Event from OK button
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   198
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   199
        # Close dialog if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   200
        if self.TestConnectionName():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
            self.EndModal(wx.ID_OK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   203
    def OnApplyToAll(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   204
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   205
        Called when Apply To All button is pressed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   206
        Test if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   207
        @param event: wx.Event from OK button
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   208
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   209
        # Close dialog if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   210
        if self.TestConnectionName():
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   211
            self.EndModal(wx.ID_YESTOALL)
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   212
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
    def OnTypeChanged(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   214
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   215
        Called when connection type changed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   216
        @param event: wx.RadioButtonEvent
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   217
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
    def OnNameChanged(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   222
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   223
        Called when connection name value changed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   224
        @param event: wx.TextEvent
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   225
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
    def RefreshPreview(self):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   230
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   231
        Refresh preview panel of graphic element
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   232
        Override BlockPreviewDialog function
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   233
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   234
        # Set graphic element displayed, creating a FBD connection element
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   235
        self.Element = FBD_Connector(self.Preview, 
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   236
                self.GetConnectionType(),
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   237
                self.ConnectionName.GetValue())
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   238
        
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   239
        # Call BlockPreviewDialog function
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   240
        BlockPreviewDialog.RefreshPreview(self)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   241