dialogs/FBDBlockDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 27 Jun 2017 13:30:48 +0300
changeset 1709 1e8900fc8ddb
parent 1696 8043f32de7b8
child 1730 64d8f52bc8c8
permissions -rwxr-xr-x
fix build problem when make command have trailing whitespace(s)

whitespaces at the end are replaced with "", that causes make problem
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
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
     9
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    10
# See COPYING file for copyrights details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    11
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    15
# of the License, or (at your option) any later version.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    16
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    20
# GNU General Public License for more details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    21
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    26
import re
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    27
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    30
from graphics.FBD_Objects import FBD_Block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
from controls.LibraryPanel import LibraryPanel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    32
from BlockPreviewDialog import BlockPreviewDialog
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
#-------------------------------------------------------------------------------
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    35
#                                    Helpers
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    36
#-------------------------------------------------------------------------------
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    37
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    38
def GetBlockTypeDefaultNameModel(blocktype):
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    39
    return re.compile("%s[0-9]+" % blocktype if blocktype is not None else ".*")
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    40
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    41
#-------------------------------------------------------------------------------
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    42
#                         Set Block Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    45
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    46
Class that implements a dialog for defining parameters of a FBD block graphic
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    47
element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    48
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    49
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    50
class FBDBlockDialog(BlockPreviewDialog):
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    51
    
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    52
    def __init__(self, parent, controller, tagname):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    53
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    54
        Constructor
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    55
        @param parent: Parent wx.Window of dialog for modal
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    56
        @param controller: Reference to project controller
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    57
        @param tagname: Tagname of project POU edited
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    58
        """
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    59
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    60
              title=_('Block Properties'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    62
        # Init common sizers
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    63
        self._init_sizers(2, 0, 1, 0, 3, 2)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    65
        # Create static box around library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    68
        self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    70
        # Create Library panel and add it to static box
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        self.LibraryPanel = LibraryPanel(self)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    72
        self.LibraryPanel.SetInitialSize(wx.Size(-1, 400))
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    73
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    74
        # Set function to call when selection in Library panel changed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        setattr(self.LibraryPanel, "_OnTreeItemSelected", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
              self.OnLibraryTreeItemSelected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
              flag=wx.GROW|wx.TOP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    80
        # Create sizer for other block parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        top_right_gridsizer.AddGrowableCol(1)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    83
        self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    85
        # Create label for block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        name_label = wx.StaticText(self, label=_('Name:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        top_right_gridsizer.AddWindow(name_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    90
        # Create text control for defining block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.BlockName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    95
        # Create label for extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        top_right_gridsizer.AddWindow(inputs_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   100
        # Create spin control for defining extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   106
        # Create label for block execution order
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   107
        execution_order_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   108
              label=_('Execution Order:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        top_right_gridsizer.AddWindow(execution_order_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   112
        # Create spin control for defining block execution order
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   114
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   115
                  self.ExecutionOrder)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
                
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   118
        # Create label for block execution control
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   119
        execution_control_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   120
              label=_('Execution Control:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        top_right_gridsizer.AddWindow(execution_control_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   124
        # Create check box to enable block execution control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        self.ExecutionControl = wx.CheckBox(self)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   126
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   127
                  self.ExecutionControl)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   130
        # Add preview panel and associated label to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   131
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   132
        self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
        
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   134
        # Add buttons sizer to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   135
        self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   138
        # Dictionary containing correspondence between parameter exchanged and
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   139
        # control to fill with parameter value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   140
        self.ParamsControl = {
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   141
            "extension": self.Inputs,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   142
            "executionOrder": self.ExecutionOrder,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   143
            "executionControl": self.ExecutionControl
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   144
        }
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   145
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   146
        # Init controls value and sensibility
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        self.BlockName.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
        self.BlockName.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
        self.Inputs.Enable(False)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   150
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   151
        # Variable containing last name typed
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   152
        self.CurrentBlockName = None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   153
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   154
        # Refresh Library panel values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   155
        self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   156
        self.Fit()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.LibraryPanel.SetFocus()
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 SetValues(self, values):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   160
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   161
        Set default block parameters
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   162
        @param values: Block parameters values
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   163
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   164
        # Extract block type defined in parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
        blocktype = values.get("type", None)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   166
        
1327
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   167
        # Select block type in library panel    
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   168
        if blocktype is not None:
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   169
            self.LibraryPanel.SelectTreeItem(blocktype, 
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   170
                                             values.get("inputs", None))
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   171
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   172
        # Define regular expression for determine if block name is block
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   173
        # default name
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   174
        default_name_model = GetBlockTypeDefaultNameModel(blocktype)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   175
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   176
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
        for name, value in values.items():
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   178
            
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   179
            # Parameter is block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
            if name == "name":
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   181
                if value != "":
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   182
                    # Set default graphic element name for testing
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   183
                    self.DefaultElementName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   184
                    
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   185
                    # Test if block name is type default block name and save
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   186
                    # block name if not (name have been typed by user)
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   187
                    if default_name_model.match(value) is None:
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   188
                        self.CurrentBlockName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   189
            
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   190
                self.BlockName.ChangeValue(value)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   191
            
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   192
            # Set value of other controls
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   193
            else:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   194
                control = self.ParamsControl.get(name, None)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   195
                if control is not None:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   196
                    control.SetValue(value)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   197
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   198
        # Refresh preview panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
    def GetValues(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   202
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   203
        Return block parameters defined in dialog
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   204
        @return: {parameter_name: parameter_value,...}
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   205
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
            values["name"] = self.BlockName.GetValue()
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   209
        values["width"], values["height"] = self.Element.GetSize()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   210
        values.update({
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   211
            name: control.GetValue()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   212
            for name, control in self.ParamsControl.iteritems()})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
        return values
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   214
    
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   215
    def OnOK(self, event):
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   216
        """
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   217
        Called when dialog OK button is pressed
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   218
        Test if parameters defined are valid
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   219
        @param event: wx.Event from OK button
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   220
        """
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   221
        message = None
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   222
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   223
        # Get block type selected
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   224
        selected = self.LibraryPanel.GetSelectedBlock()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   225
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   226
        # Get block type name and if block is a function block
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   227
        block_name = self.BlockName.GetValue()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   228
        name_enabled = self.BlockName.IsEnabled()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   229
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   230
        # Test that a type has been selected for block
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   231
        if selected is None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   232
            message = _("Form isn't complete. Valid block type must be selected!")
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   233
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   234
        # Test, if block is a function block, that a name have been defined
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   235
        elif name_enabled and block_name == "":
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   236
            message = _("Form isn't complete. Name must be filled!")
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   237
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   238
        # Show error message if an error is detected
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   239
        if message is not None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   240
            self.ShowErrorMessage(message)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   241
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   242
        # Test block name validity if necessary
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   243
        elif not name_enabled or self.TestElementName(block_name):
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   244
            # Call BlockPreviewDialog function
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   245
            BlockPreviewDialog.OnOK(self, event)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   246
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
    def OnLibraryTreeItemSelected(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   248
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   249
        Called when block type selected in library panel
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   250
        @param event: wx.TreeEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   251
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   252
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
        values = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   254
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   255
        # Get block type informations
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   256
        blocktype = (self.Controller.GetBlockType(values["type"], 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   257
                                                  values["inputs"])
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   258
                     if values is not None else None)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   259
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   260
        # Set input number spin control according to block type informations
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
        if blocktype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
            self.Inputs.SetValue(len(blocktype["inputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
            self.Inputs.Enable(blocktype["extensible"])
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   264
        else:
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   265
            self.Inputs.SetValue(2)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   266
            self.Inputs.Enable(False)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   267
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   268
        # Update block name with default value if block type is a function and
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   269
        # current block name wasn't typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   270
        if blocktype is not None and blocktype["type"] != "function":
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   271
            self.BlockName.Enable(True)
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   272
            
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   273
            if self.CurrentBlockName is None:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   274
                # Generate new block name according to block type, taking
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   275
                # default element name if it was already a default name for this
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   276
                # block type
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   277
                default_name_model = GetBlockTypeDefaultNameModel(values["type"])
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   278
                block_name = (
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   279
                    self.DefaultElementName
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   280
                    if (self.DefaultElementName is not None and 
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   281
                        default_name_model.match(self.DefaultElementName))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   282
                    else self.Controller.GenerateNewName(
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   283
                        self.TagName, None, values["type"]+"%d", 0))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   284
            else:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   285
                block_name = self.CurrentBlockName
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   286
                
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   287
            self.BlockName.ChangeValue(block_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
            self.BlockName.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   290
            self.BlockName.ChangeValue("")
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   291
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   292
        # Refresh preview panel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   293
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
    def OnNameChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   296
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   297
        Called when block name value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   298
        @param event: wx.TextEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   299
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        if self.BlockName.IsEnabled():
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   301
            # Save block name typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   302
            self.CurrentBlockName = self.BlockName.GetValue()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
    def OnInputsChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   307
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   308
        Called when block inputs number changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   309
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   310
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
        if self.Inputs.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
    def OnExecutionOrderChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   316
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   317
        Called when block execution order value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   318
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   319
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
    def OnExecutionControlChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   324
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   325
        Called when block execution control value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   326
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   327
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
    def RefreshPreview(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   332
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   333
        Refresh preview panel of graphic element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   334
        Override BlockPreviewDialog function
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   335
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   336
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
        values = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   338
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   339
        # If a block type is selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
        if values is not None:
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   341
            # Set graphic element displayed, creating a FBD block element
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   342
            self.Element = FBD_Block(self.Preview, values["type"], 
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   343
                    (self.BlockName.GetValue()
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   344
                     if self.BlockName.IsEnabled()
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   345
                     else ""), 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                    extension = self.Inputs.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
                    inputs = values["inputs"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
                    executionControl = self.ExecutionControl.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
                    executionOrder = self.ExecutionOrder.GetValue())
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   350
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   351
        # Reset graphic element displayed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        else:
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   353
            self.Element = None 
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   354
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   355
        # Call BlockPreviewDialog function
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   356
        BlockPreviewDialog.RefreshPreview(self)