dialogs/FBDBlockDialog.py
author Edouard Tisserant
Thu, 12 Jun 2014 18:15:04 +0200
changeset 1419 d6adca8b6697
parent 1327 632780979432
child 1571 486f94a8032c
permissions -rw-r--r--
Updated tests/python : added derivated return type function declaration+call and re-enabled refrences to global FB interfaces
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
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    25
import re
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    26
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    29
from graphics.FBD_Objects import FBD_Block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
from controls.LibraryPanel import LibraryPanel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    31
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    34
#                                    Helpers
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    35
#-------------------------------------------------------------------------------
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    36
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    37
def GetBlockTypeDefaultNameModel(blocktype):
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    38
    return re.compile("%s[0-9]+" % blocktype if blocktype is not None else ".*")
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    39
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    40
#-------------------------------------------------------------------------------
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    41
#                         Set Block Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    44
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    45
Class that implements a dialog for defining parameters of a FBD block graphic
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    46
element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    47
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    48
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    49
class FBDBlockDialog(BlockPreviewDialog):
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    50
    
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    51
    def __init__(self, parent, controller, tagname):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    52
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    53
        Constructor
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    54
        @param parent: Parent wx.Window of dialog for modal
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    55
        @param controller: Reference to project controller
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    56
        @param tagname: Tagname of project POU edited
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    57
        """
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    58
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
              size=wx.Size(600, 450), title=_('Block Properties'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    61
        # Init common sizers
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    62
        self._init_sizers(2, 0, 1, 0, 3, 2)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    64
        # Create static box around library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        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
    67
        self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    69
        # Create Library panel and add it to static box
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        self.LibraryPanel = LibraryPanel(self)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    71
        # Set function to call when selection in Library panel changed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        setattr(self.LibraryPanel, "_OnTreeItemSelected", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
              self.OnLibraryTreeItemSelected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
              flag=wx.GROW|wx.TOP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    77
        # Create sizer for other block parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        top_right_gridsizer.AddGrowableCol(1)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    80
        self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    82
        # Create label for block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        name_label = wx.StaticText(self, label=_('Name:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        top_right_gridsizer.AddWindow(name_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    87
        # Create text control for defining block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        self.BlockName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    92
        # Create label for extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        top_right_gridsizer.AddWindow(inputs_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    97
        # Create spin control for defining extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   103
        # Create label for block execution order
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   104
        execution_order_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   105
              label=_('Execution Order:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        top_right_gridsizer.AddWindow(execution_order_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   109
        # Create spin control for defining block execution order
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   111
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   112
                  self.ExecutionOrder)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
                
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   115
        # Create label for block execution control
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   116
        execution_control_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   117
              label=_('Execution Control:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        top_right_gridsizer.AddWindow(execution_control_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   121
        # Create check box to enable block execution control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        self.ExecutionControl = wx.CheckBox(self)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   123
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   124
                  self.ExecutionControl)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   127
        # 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
   128
        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
   129
        self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   131
        # Add buttons sizer to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   132
        self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   135
        # Dictionary containing correspondence between parameter exchanged and
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   136
        # control to fill with parameter value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   137
        self.ParamsControl = {
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   138
            "extension": self.Inputs,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   139
            "executionOrder": self.ExecutionOrder,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   140
            "executionControl": self.ExecutionControl
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   141
        }
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   142
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   143
        # Init controls value and sensibility
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
        self.BlockName.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
        self.BlockName.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        self.Inputs.Enable(False)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   147
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   148
        # Variable containing last name typed
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   149
        self.CurrentBlockName = None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   150
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   151
        # Refresh Library panel values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   152
        self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.LibraryPanel.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
    def SetValues(self, values):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   156
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   157
        Set default block parameters
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   158
        @param values: Block parameters values
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   159
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   160
        # Extract block type defined in parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        blocktype = values.get("type", None)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   162
        
1327
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   163
        # Select block type in library panel    
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   164
        if blocktype is not None:
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   165
            self.LibraryPanel.SelectTreeItem(blocktype, 
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   166
                                             values.get("inputs", None))
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   167
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   168
        # Define regular expression for determine if block name is block
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   169
        # default name
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   170
        default_name_model = GetBlockTypeDefaultNameModel(blocktype)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   171
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   172
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
        for name, value in values.items():
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   174
            
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   175
            # Parameter is block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
            if name == "name":
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   177
                if value != "":
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   178
                    # Set default graphic element name for testing
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   179
                    self.DefaultElementName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   180
                    
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   181
                    # Test if block name is type default block name and save
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   182
                    # 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
   183
                    if default_name_model.match(value) is None:
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   184
                        self.CurrentBlockName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   185
            
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   186
                self.BlockName.ChangeValue(value)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   187
            
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   188
            # Set value of other controls
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   189
            else:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   190
                control = self.ParamsControl.get(name, None)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   191
                if control is not None:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   192
                    control.SetValue(value)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   193
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   194
        # Refresh preview panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
    def GetValues(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   198
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   199
        Return block parameters defined in dialog
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   200
        @return: {parameter_name: parameter_value,...}
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   201
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
            values["name"] = self.BlockName.GetValue()
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   205
        values["width"], values["height"] = self.Element.GetSize()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   206
        values.update({
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   207
            name: control.GetValue()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   208
            for name, control in self.ParamsControl.iteritems()})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
        return values
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   210
    
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   211
    def OnOK(self, event):
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   212
        """
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   213
        Called when dialog OK button is pressed
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   214
        Test if parameters defined are valid
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   215
        @param event: wx.Event from OK button
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
        message = None
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   218
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   219
        # Get block type selected
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   220
        selected = self.LibraryPanel.GetSelectedBlock()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   221
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   222
        # 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
   223
        block_name = self.BlockName.GetValue()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   224
        name_enabled = self.BlockName.IsEnabled()
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
        # 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
   227
        if selected is None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   228
            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
   229
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   230
        # 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
   231
        elif name_enabled and block_name == "":
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   232
            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
   233
        
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   234
        # 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
   235
        if message is not None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   236
            self.ShowErrorMessage(message)
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
        # Test block name validity if necessary
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   239
        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
   240
            # Call BlockPreviewDialog function
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   241
            BlockPreviewDialog.OnOK(self, event)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   242
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
    def OnLibraryTreeItemSelected(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   244
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   245
        Called when block type selected in library panel
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   246
        @param event: wx.TreeEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   247
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   248
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
        values = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   250
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   251
        # Get block type informations
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   252
        blocktype = (self.Controller.GetBlockType(values["type"], 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   253
                                                  values["inputs"])
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   254
                     if values is not None else None)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   255
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   256
        # Set input number spin control according to block type informations
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
        if blocktype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
            self.Inputs.SetValue(len(blocktype["inputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
            self.Inputs.Enable(blocktype["extensible"])
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   260
        else:
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   261
            self.Inputs.SetValue(2)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   262
            self.Inputs.Enable(False)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   263
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   264
        # Update block name with default value if block type is a function and
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   265
        # 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
   266
        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
   267
            self.BlockName.Enable(True)
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   268
            
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   269
            if self.CurrentBlockName is None:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   270
                # Generate new block name according to block type, taking
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   271
                # default element name if it was already a default name for this
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   272
                # block type
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   273
                default_name_model = GetBlockTypeDefaultNameModel(values["type"])
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   274
                block_name = (
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   275
                    self.DefaultElementName
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   276
                    if (self.DefaultElementName is not None and 
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   277
                        default_name_model.match(self.DefaultElementName))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   278
                    else self.Controller.GenerateNewName(
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   279
                        self.TagName, None, values["type"]+"%d", 0))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   280
            else:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   281
                block_name = self.CurrentBlockName
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   282
                
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   283
            self.BlockName.ChangeValue(block_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
            self.BlockName.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   286
            self.BlockName.ChangeValue("")
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   287
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   288
        # Refresh preview panel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   289
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
    def OnNameChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   292
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   293
        Called when block name value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   294
        @param event: wx.TextEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   295
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
        if self.BlockName.IsEnabled():
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   297
            # Save block name typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   298
            self.CurrentBlockName = self.BlockName.GetValue()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
    def OnInputsChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   303
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   304
        Called when block inputs number changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   305
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   306
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
        if self.Inputs.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
    def OnExecutionOrderChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   312
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   313
        Called when block execution order value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   314
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   315
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
    def OnExecutionControlChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   320
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   321
        Called when block execution control value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   322
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   323
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
    def RefreshPreview(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   328
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   329
        Refresh preview panel of graphic element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   330
        Override BlockPreviewDialog function
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   331
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   332
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
        values = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   334
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   335
        # If a block type is selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
        if values is not None:
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   337
            # Set graphic element displayed, creating a FBD block element
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   338
            self.Element = FBD_Block(self.Preview, values["type"], 
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   339
                    (self.BlockName.GetValue()
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   340
                     if self.BlockName.IsEnabled()
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   341
                     else ""), 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
                    extension = self.Inputs.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
                    inputs = values["inputs"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
                    executionControl = self.ExecutionControl.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
                    executionOrder = self.ExecutionOrder.GetValue())
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   346
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   347
        # Reset graphic element displayed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        else:
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   349
            self.Element = None 
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
        # Call BlockPreviewDialog function
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   352
        BlockPreviewDialog.RefreshPreview(self)