2015-02-17 23:35:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2015 CERN
|
|
|
|
* Author: Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
#ifndef __UNIT_BINDER_H_
|
|
|
|
#define __UNIT_BINDER_H_
|
2015-02-17 23:35:18 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <base_units.h>
|
2018-04-10 10:52:12 +00:00
|
|
|
#include <base_struct.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <libeval/numeric_evaluator.h>
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2017-08-25 14:46:49 +00:00
|
|
|
class wxTextEntry;
|
2015-02-17 23:35:18 +00:00
|
|
|
class wxSpinButton;
|
|
|
|
class wxStaticText;
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
class UNIT_BINDER : public wxEvtHandler
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2018-02-03 09:09:53 +00:00
|
|
|
* @param aParent is the parent EDA_DRAW_FRAME.
|
|
|
|
* @param aLabel is the static text used to label the text input widget (note: the label
|
|
|
|
* text, trimmed of its colon, will also be used in error messages)
|
2018-03-07 12:48:08 +00:00
|
|
|
* @param aValue is the control used to edit or display the given value (wxTextCtrl,
|
|
|
|
* wxComboBox, wxStaticText, etc.).
|
2018-02-03 09:09:53 +00:00
|
|
|
* @param aUnitLabel is the units label displayed after the text input widget
|
|
|
|
* @param aUseMils specifies the use of mils for imperial units (instead of inches)
|
|
|
|
* @param aMin a minimum value (in internal units) for validation
|
|
|
|
* @param aMax a maximum value (in internal units) for validation
|
|
|
|
* @param aAllowEval indicates \a aTextInput's content should be eval'ed before storing
|
2015-02-17 23:35:18 +00:00
|
|
|
*/
|
2018-02-03 09:09:53 +00:00
|
|
|
UNIT_BINDER( EDA_DRAW_FRAME* aParent,
|
2018-03-07 12:48:08 +00:00
|
|
|
wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
|
2018-02-03 09:09:53 +00:00
|
|
|
bool aUseMils = false,
|
|
|
|
int aMin = INT_MIN, int aMax = INT_MAX,
|
|
|
|
bool aAllowEval = true );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
/**
|
|
|
|
* Function SetUnits
|
|
|
|
* Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be
|
|
|
|
* used to set to DEGREES for angular controls.
|
|
|
|
*/
|
|
|
|
virtual void SetUnits( EDA_UNITS_T aUnits, bool aUseMils = false );
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
/**
|
|
|
|
* Function SetValue
|
|
|
|
* Sets new value (in Internal Units) for the text field, taking care of units conversion.
|
|
|
|
* @param aValue is the new value.
|
|
|
|
*/
|
|
|
|
virtual void SetValue( int aValue );
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
void SetValue( wxString aValue );
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
/**
|
|
|
|
* Function GetValue
|
|
|
|
* Returns the current value in Internal Units.
|
|
|
|
*/
|
|
|
|
virtual int GetValue() const;
|
|
|
|
|
2015-07-09 11:35:50 +00:00
|
|
|
/**
|
2018-02-03 09:09:53 +00:00
|
|
|
* Function IsIndeterminate
|
|
|
|
* Returns true if the control holds the indeterminate value (for instance, if it
|
|
|
|
* represents a multiple selection of differing values).
|
|
|
|
*/
|
|
|
|
bool IsIndeterminate() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Validate
|
|
|
|
* Validates the control, informing the user of any errors found.
|
|
|
|
*
|
|
|
|
* When called from an OK handler, \a setFocusOnError should be set to true. A negative
|
|
|
|
* return value indicates an error.
|
2015-07-09 11:35:50 +00:00
|
|
|
*/
|
2018-02-03 09:09:53 +00:00
|
|
|
virtual bool Validate( bool setFocusOnError = false );
|
2015-07-09 11:35:50 +00:00
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
/**
|
|
|
|
* Function Enable
|
2018-05-23 06:11:47 +00:00
|
|
|
* Enables/diasables the label, widget and units label.
|
2015-02-17 23:35:18 +00:00
|
|
|
*/
|
2015-02-18 16:53:46 +00:00
|
|
|
void Enable( bool aEnable );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* Shows/hides the label, widget and units label.
|
|
|
|
*/
|
|
|
|
void Show( bool aShow );
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
protected:
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
void onSetFocus( wxFocusEvent& aEvent );
|
|
|
|
void onKillFocus( wxFocusEvent& aEvent );
|
|
|
|
void onTextEnter( wxCommandEvent& aEvent );
|
|
|
|
void delayedFocusHandler( wxIdleEvent& aEvent );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
void evaluate();
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
///> The bound widgets
|
2018-03-07 12:48:08 +00:00
|
|
|
wxStaticText* m_label;
|
|
|
|
wxWindow* m_value;
|
|
|
|
wxStaticText* m_unitLabel;
|
2015-02-17 23:35:18 +00:00
|
|
|
|
|
|
|
///> Currently used units.
|
2018-03-07 12:48:08 +00:00
|
|
|
EDA_UNITS_T m_units;
|
|
|
|
bool m_useMils;
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
///> Validation support.
|
2018-03-07 12:48:08 +00:00
|
|
|
int m_min;
|
|
|
|
int m_max;
|
|
|
|
bool m_showMessage;
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
///> Evaluator
|
2018-02-25 16:14:24 +00:00
|
|
|
NUMERIC_EVALUATOR m_eval;
|
2018-03-07 12:48:08 +00:00
|
|
|
bool m_allowEval;
|
2015-02-17 23:35:18 +00:00
|
|
|
};
|
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
#endif /* __UNIT_BINDER_H_ */
|