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
|
2020-04-03 20:47:02 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-17 23:35:18 +00:00
|
|
|
* 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
|
|
|
|
2020-10-26 02:29:53 +00:00
|
|
|
#include <eda_units.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <base_units.h>
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2020-07-07 04:15:10 +00:00
|
|
|
#include <origin_transforms.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 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,
|
2020-10-02 20:51:24 +00:00
|
|
|
bool aAllowEval = true );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2020-04-22 19:44:20 +00:00
|
|
|
~UNIT_BINDER() override;
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
virtual void SetUnits( EDA_UNITS aUnits );
|
2018-10-05 14:41:17 +00:00
|
|
|
|
2020-06-26 02:18:29 +00:00
|
|
|
/**
|
|
|
|
* Used to override the datatype of the displayed property (default is DISTANCE)
|
|
|
|
* @param aDataType is the datatype to use for the units text display
|
|
|
|
*/
|
|
|
|
void SetDataType( EDA_DATA_TYPE aDataType );
|
|
|
|
|
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 );
|
|
|
|
|
2020-02-29 02:21:18 +00:00
|
|
|
/**
|
|
|
|
* Function SetDoubleValue
|
|
|
|
* Sets new value (in Internal Units) for the text field, taking care of units conversion.
|
|
|
|
* @param aValue is the new value.
|
|
|
|
*/
|
|
|
|
virtual void SetDoubleValue( double aValue );
|
|
|
|
|
2018-09-09 18:04:10 +00:00
|
|
|
/**
|
|
|
|
* Function ChangeValue
|
|
|
|
* Changes the value (in Internal Units) for the text field, taking care of units conversion
|
|
|
|
* but does not trigger the update routine
|
|
|
|
* @param aValue is the new value.
|
|
|
|
*/
|
|
|
|
virtual void ChangeValue( int aValue );
|
|
|
|
|
2020-05-05 15:40:18 +00:00
|
|
|
void ChangeValue( const wxString& aValue );
|
2018-09-09 18:04:10 +00:00
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
/**
|
|
|
|
* Function GetValue
|
|
|
|
* Returns the current value in Internal Units.
|
|
|
|
*/
|
2019-09-03 23:38:58 +00:00
|
|
|
virtual long long int GetValue();
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2020-02-29 02:21:18 +00:00
|
|
|
/**
|
|
|
|
* Function GetValue
|
|
|
|
* Returns the current value in Internal Units.
|
|
|
|
*/
|
|
|
|
virtual double GetDoubleValue();
|
|
|
|
|
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;
|
|
|
|
|
2020-04-03 20:47:02 +00:00
|
|
|
/**
|
|
|
|
* Function GetOriginalText
|
|
|
|
* Returns the pre-evaluated text (or the current text if evaluation is not supported).
|
|
|
|
* Used primarily to remember values between dialog invocations.
|
|
|
|
*/
|
|
|
|
wxString GetOriginalText() const;
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
/**
|
|
|
|
* Function Validate
|
2018-11-29 18:59:38 +00:00
|
|
|
* Validates the control against the given range, informing the user of any errors found.
|
2018-02-03 09:09:53 +00:00
|
|
|
*
|
2020-06-14 15:08:47 +00:00
|
|
|
* @param aMin a minimum value for validation
|
|
|
|
* @param aMax a maximum value for validation
|
|
|
|
* @param aUnits the units of the min/max parameters (use UNSCALED for internal units)
|
2018-11-29 18:59:38 +00:00
|
|
|
* @return false on error.
|
2015-07-09 11:35:50 +00:00
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
|
2015-07-09 11:35:50 +00:00
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
void SetLabel( const wxString& aLabel );
|
|
|
|
|
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.
|
2019-04-14 17:58:35 +00:00
|
|
|
*
|
|
|
|
* @param aShow called for the Show() routine in wx
|
|
|
|
* @param aResize if true, the element will be sized to 0 on hide and -1 on show
|
2018-05-23 06:11:47 +00:00
|
|
|
*/
|
2019-04-14 17:58:35 +00:00
|
|
|
void Show( bool aShow, bool aResize = false );
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2020-07-07 04:15:10 +00:00
|
|
|
/**
|
|
|
|
* Get the origin transforms coordinate type
|
|
|
|
*
|
|
|
|
* @returns the origin transforms coordinate type
|
|
|
|
*/
|
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
|
|
|
|
{
|
|
|
|
return m_coordType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetOriginTransform
|
|
|
|
* Sets the current origin transform mode
|
|
|
|
*/
|
|
|
|
void SetCoordType( ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType )
|
|
|
|
{
|
|
|
|
m_coordType = aCoordType;
|
|
|
|
}
|
|
|
|
|
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 );
|
2018-11-23 14:58:38 +00:00
|
|
|
void delayedFocusHandler( wxCommandEvent& aEvent );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2020-04-22 19:44:20 +00:00
|
|
|
void onUnitsChanged( wxCommandEvent& aEvent );
|
|
|
|
|
|
|
|
EDA_DRAW_FRAME* m_frame;
|
|
|
|
|
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.
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS m_units;
|
2020-06-26 02:18:29 +00:00
|
|
|
EDA_DATA_TYPE m_dataType;
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
///> Validation support.
|
2018-10-30 23:12:55 +00:00
|
|
|
wxString m_errorMessage;
|
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;
|
2018-10-08 11:58:10 +00:00
|
|
|
bool m_needsEval;
|
2019-09-07 23:00:15 +00:00
|
|
|
|
|
|
|
///> Selection start and end of the original text
|
|
|
|
long m_selStart;
|
|
|
|
long m_selEnd;
|
2020-07-07 04:15:10 +00:00
|
|
|
|
|
|
|
/// A reference to an ORIGIN_TRANSFORMS object
|
|
|
|
ORIGIN_TRANSFORMS& m_originTransforms;
|
|
|
|
|
|
|
|
/// Type of coordinate for display origin transforms
|
|
|
|
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType;
|
2015-02-17 23:35:18 +00:00
|
|
|
};
|
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
#endif /* __UNIT_BINDER_H_ */
|