dialogs/FBDBlockDialog.py
author Laurent Bessard
Mon, 10 Jun 2013 01:15:39 +0200
changeset 1237 0c8b8ef9559b
parent 1236 a5d1d2a2f366
child 1242 ec2c415fc65e
permissions -rw-r--r--
Fixed support for default function block name in FBDBlockDialog
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
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
#                          Create New Block Dialog
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    37
class FBDBlockDialog(BlockPreviewDialog):
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    38
    
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    39
    def __init__(self, parent, controller, tagname):
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    40
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
              size=wx.Size(600, 450), title=_('Block Properties'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        main_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
        main_sizer.AddSizer(column_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        column_sizer.AddSizer(left_staticboxsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
              flag=wx.GROW|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        self.LibraryPanel = LibraryPanel(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        setattr(self.LibraryPanel, "_OnTreeItemSelected", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
              self.OnLibraryTreeItemSelected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
              flag=wx.GROW|wx.TOP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        right_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        right_gridsizer.AddGrowableRow(2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
              flag=wx.GROW|wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        top_right_gridsizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
        right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        name_label = wx.StaticText(self, label=_('Name:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        top_right_gridsizer.AddWindow(name_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        self.BlockName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        top_right_gridsizer.AddWindow(inputs_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        execution_order_label = wx.StaticText(self, label=_('Execution Order:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        top_right_gridsizer.AddWindow(execution_order_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, self.ExecutionOrder)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        execution_control_label = wx.StaticText(self, label=_('Execution Control:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        top_right_gridsizer.AddWindow(execution_control_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        self.ExecutionControl = wx.CheckBox(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, self.ExecutionControl)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   105
        right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   108
        main_sizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        self.BlockName.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        self.BlockName.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        self.Inputs.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   116
        self.CurrentBlockName = None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   117
        
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   118
        self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
        self.LibraryPanel.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
    def OnOK(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        selected = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
        block_name = self.BlockName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        name_enabled = self.BlockName.IsEnabled()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        if selected is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
            message = _("Form isn't complete. Valid block type must be selected!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        elif name_enabled and block_name == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
            message = _("Form isn't complete. Name must be filled!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        if message is not None:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   131
            self.ShowMessage(message)
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   132
        elif not name_enabled or self.TestBlockName(block_name):
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   133
            BlockPreviewDialog.OnOK(self, event)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   134
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
    def SetValues(self, values):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        blocktype = values.get("type", None)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   137
        default_name_model = re.compile("%s[0-9]+" % blocktype)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        if blocktype is not None:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   139
            self.LibraryPanel.SelectTreeItem(blocktype, 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   140
                                             values.get("inputs", None))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        for name, value in values.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
            if name == "name":
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   143
                if value != "":
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   144
                    self.DefaultBlockName = value
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   145
                    if default_name_model.match(value) is None:
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   146
                        self.CurrentBlockName = value
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   147
                self.BlockName.ChangeValue(value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            elif name == "extension":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
                self.Inputs.SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
            elif name == "executionOrder":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
                self.ExecutionOrder.SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
            elif name == "executionControl":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
                   self.ExecutionControl.SetValue(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
    def GetValues(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
            values["name"] = self.BlockName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        values["width"], values["height"] = self.Block.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        values["extension"] = self.Inputs.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
        values["executionOrder"] = self.ExecutionOrder.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        values["executionControl"] = self.ExecutionControl.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        return values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   165
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
    def OnLibraryTreeItemSelected(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        values = self.LibraryPanel.GetSelectedBlock()
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   168
        blocktype = (self.Controller.GetBlockType(values["type"], 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   169
                                                  values["inputs"])
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   170
                     if values is not None else None)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   171
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        if blocktype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
            self.Inputs.SetValue(len(blocktype["inputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
            self.Inputs.Enable(blocktype["extensible"])
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   175
        else:
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   176
            self.Inputs.SetValue(2)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   177
            self.Inputs.Enable(False)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   178
        
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   179
        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
   180
            self.BlockName.Enable(True)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   181
            self.BlockName.ChangeValue(
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   182
                self.CurrentBlockName
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   183
                if self.CurrentBlockName is not None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   184
                else self.Controller.GenerateNewName(
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   185
                    self.TagName, None, values["type"]+"%d", 0))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
            self.BlockName.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   188
            self.BlockName.ChangeValue("")
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   189
        
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   190
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
    def OnNameChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
        if self.BlockName.IsEnabled():
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   194
            self.CurrentBlockName = self.BlockName.GetValue()
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
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
    def OnInputsChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
        if self.Inputs.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
    def OnExecutionOrderChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
    def OnExecutionControlChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
    def RefreshPreview(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
        if values is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
            if self.BlockName.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                blockname = self.BlockName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                blockname = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
            self.Block = FBD_Block(self.Preview, values["type"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                    blockname, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
                    extension = self.Inputs.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                    inputs = values["inputs"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
                    executionControl = self.ExecutionControl.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                    executionOrder = self.ExecutionOrder.GetValue())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
        else:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   225
            self.Block = None 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   226
        BlockPreviewDialog.RefreshPreview(self)