dialogs/LDElementDialog.py
author Sergey Surkov <surkovsv93@gmail.com>
Tue, 18 Oct 2016 17:44:08 +0300
changeset 1544 2969c2123105
parent 1493 6dbebfcec074
child 1571 486f94a8032c
permissions -rw-r--r--
Fix bug with two or more wires connected to one input. Now only one wire can be connected to one input, except BOOLean signals in LD and SFC. If user trying to connect wire with already connected input, wire highlight will become red.
Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    27
from graphics.GraphicCommons import CONTACT_NORMAL, CONTACT_REVERSE, \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    28
    CONTACT_RISING, CONTACT_FALLING, COIL_NORMAL, COIL_REVERSE, COIL_SET, \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    29
    COIL_RESET, COIL_RISING, COIL_FALLING
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    30
from graphics.LD_Objects import LD_Contact, LD_Coil
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
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
#-------------------------------------------------------------------------------
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    34
#                       Set Ladder Element Parmeters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    37
"""
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    38
Class that implements a dialog for defining parameters of a LD contact or coil
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    39
graphic element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    40
"""
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    41
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    42
class LDElementDialog(BlockPreviewDialog):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
    
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    44
    def __init__(self, parent, controller, tagname, type):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    45
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    46
        Constructor
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    47
        @param parent: Parent wx.Window of dialog for modal
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    48
        @param controller: Reference to project controller
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    49
        @param tagname: Tagname of project POU edited
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    50
        @param type: Type of LD element ('contact or 'coil')
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    51
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    52
        BlockPreviewDialog.__init__(self, parent, controller, tagname, 
1493
6dbebfcec074 increase height of some dialog windows so they have enough space for buttons
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1370
diff changeset
    53
              size=wx.Size(350, 320 if type == "contact" else 380),
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    54
              title=(_("Edit Contact Values")
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    55
                     if type == "contact"
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    56
                     else _("Edit Coil Values")))
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    57
        
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    58
        # Init common sizers
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    59
        self._init_sizers(2, 0, 
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    60
              (7 if type == "contact" else 9), None, 2, 1)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    62
        # Create label for LD element modifier
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        modifier_label = wx.StaticText(self, label=_('Modifier:'))
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    64
        self.LeftGridSizer.AddWindow(modifier_label, border=5, 
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    65
              flag=wx.GROW|wx.BOTTOM)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    66
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    67
        # Create radio buttons for selecting LD element modifier
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    68
        self.ModifierRadioButtons = {}
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    69
        first = True
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    70
        element_modifiers = ([CONTACT_NORMAL, CONTACT_REVERSE, 
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    71
                              CONTACT_RISING, CONTACT_FALLING]
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    72
                             if type == "contact"
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    73
                             else [COIL_NORMAL, COIL_REVERSE, COIL_SET,
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    74
                                   COIL_RESET, COIL_RISING, COIL_FALLING])
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    75
        modifiers_label = [_("Normal"), _("Negated")] + \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    76
                          ([_("Set"), _("Reset")] if type == "coil" else []) + \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    77
                          [_("Rising Edge"), _("Falling Edge")]
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    78
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    79
        for modifier, label in zip(element_modifiers, modifiers_label):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    80
            radio_button = wx.RadioButton(self, label=label, 
1247
92588e69d853 Fixed bug in newly rewritten dialogs
Laurent Bessard
parents: 1246
diff changeset
    81
                  style=(wx.RB_GROUP if first else 0))
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    82
            radio_button.SetValue(first)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    83
            self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    84
            self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    85
            self.ModifierRadioButtons[modifier] = radio_button
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    86
            first = False
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    87
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    88
        # Create label for LD element variable
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    89
        element_variable_label = wx.StaticText(self, label=_('Variable:'))
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    90
        self.LeftGridSizer.AddWindow(element_variable_label, border=5,
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    91
              flag=wx.GROW|wx.TOP)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    92
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    93
        # Create a combo box for defining LD element variable
1370
ee795a8d4404 Fixed coil and contact dialog to let user select a complex type variable for contact and coil expression
Laurent Bessard
parents: 1259
diff changeset
    94
        self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    95
        self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, 
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    96
                  self.ElementVariable)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    97
        self.LeftGridSizer.AddWindow(self.ElementVariable, border=5,
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    98
             flag=wx.GROW|wx.TOP)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    99
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   100
        # Add preview panel and associated label to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
   101
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
   102
        self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   104
        # Add buttons sizer to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
   105
        self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   108
        # Save LD element class
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   109
        self.ElementClass = (LD_Contact if type == "contact" else LD_Coil)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   110
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   111
        # Extract list of variables defined in POU
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   112
        self.RefreshVariableList()
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   113
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   114
        # Set values in ElementVariable
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   115
        for name, (var_type, value_type) in self.VariableList.iteritems():
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   116
            # Only select BOOL variable and avoid input for coil
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   117
            if (type == "contact" or var_type != "Input") and \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   118
               value_type == "BOOL":
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   119
                self.ElementVariable.Append(name)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   120
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   121
        # Normal radio button is default control having keyboard focus
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   122
        self.ModifierRadioButtons[element_modifiers[0]].SetFocus()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
    
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   124
    def GetElementModifier(self):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   125
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   126
        Return modifier selected for LD element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   127
        @return: Modifier selected (None if not found)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   128
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   129
        # Go through radio buttons and return modifier associated to the one
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   130
        # that is selected
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   131
        for modifier, control in self.ModifierRadioButtons.iteritems():
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   132
            if control.GetValue():
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   133
                return modifier
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   134
        return None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
    def SetValues(self, values):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   137
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   138
        Set default LD element parameters
1252
18cd1357e8d3 Rewrite SFCTransitionDialog
Laurent Bessard
parents: 1250
diff changeset
   139
        @param values: LD element parameters values
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   140
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   141
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        for name, value in values.items():
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   143
            
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   144
            # Parameter is LD element variable
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   145
            if name == "variable":
1370
ee795a8d4404 Fixed coil and contact dialog to let user select a complex type variable for contact and coil expression
Laurent Bessard
parents: 1259
diff changeset
   146
                self.ElementVariable.SetValue(value)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   147
            
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   148
            # Set value of other controls
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   149
            elif name == "modifier":
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   150
                self.ModifierRadioButtons[value].SetValue(True)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   151
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   152
        # Refresh preview panel
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   153
        self.RefreshPreview()
814
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 GetValues(self):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   156
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   157
        Return LD element parameters defined in dialog
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   158
        @return: {parameter_name: parameter_value,...}
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   159
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   160
        values = {
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   161
            "variable": self.ElementVariable.GetValue(),
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   162
            "modifier": self.GetElementModifier()}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        values["width"], values["height"] = self.Element.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        return values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   166
    def OnModifierChanged(self, event):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   167
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   168
        Called when LD element modifier changed
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   169
        @param event: wx.RadioButtonEvent
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   170
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   174
    def OnVariableChanged(self, event):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   175
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   176
        Called when LD element associated variable changed
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   177
        @param event: wx.ComboBoxEvent
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   178
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
    def RefreshPreview(self):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   183
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   184
        Refresh preview panel of graphic element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   185
        Override BlockPreviewDialog function
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   186
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   187
        # Set graphic element displayed, creating a LD element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   188
        self.Element = self.ElementClass(
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   189
                self.Preview, 
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   190
                self.GetElementModifier(),
1370
ee795a8d4404 Fixed coil and contact dialog to let user select a complex type variable for contact and coil expression
Laurent Bessard
parents: 1259
diff changeset
   191
                self.ElementVariable.GetValue())
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   192
        
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   193
        # Call BlockPreviewDialog function
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   194
        BlockPreviewDialog.RefreshPreview(self)