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
|
2021-01-25 12:42:36 +00:00
|
|
|
* Copyright (C) 2020-2021 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-07-07 04:15:10 +00:00
|
|
|
#include <origin_transforms.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <libeval/numeric_evaluator.h>
|
2021-06-06 14:47:29 +00:00
|
|
|
#include <wx/event.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
class EDA_BASE_FRAME;
|
2021-06-06 14:47:29 +00:00
|
|
|
class EDA_DRAW_FRAME;
|
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:
|
|
|
|
|
|
|
|
/**
|
2021-08-29 23:33:08 +00:00
|
|
|
* @param aParent is the parent EDA_BASE_FRAME, used to fetch units and coordinate systems.
|
2018-02-03 09:09:53 +00:00
|
|
|
* @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)
|
2020-12-10 14:46:20 +00:00
|
|
|
* @param aValueCtrl is the control used to edit or display the given value (wxTextCtrl,
|
2018-03-07 12:48:08 +00:00
|
|
|
* wxComboBox, wxStaticText, etc.).
|
2018-02-03 09:09:53 +00:00
|
|
|
* @param aUnitLabel is the units label displayed after the text input widget
|
2020-12-10 14:46:20 +00:00
|
|
|
* Can be nullptr.
|
2018-02-03 09:09:53 +00:00
|
|
|
* @param aAllowEval indicates \a aTextInput's content should be eval'ed before storing
|
2015-02-17 23:35:18 +00:00
|
|
|
*/
|
2022-09-16 04:38:10 +00:00
|
|
|
UNIT_BINDER( EDA_DRAW_FRAME* aParent,
|
2020-12-10 14:46:20 +00:00
|
|
|
wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
|
2020-10-02 20:51:24 +00:00
|
|
|
bool aAllowEval = true );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, wxStaticText* aLabel, wxWindow* aValueCtrl,
|
|
|
|
wxStaticText* aUnitLabel, bool aAllowEval = true );
|
|
|
|
|
2020-04-22 19:44:20 +00:00
|
|
|
~UNIT_BINDER() override;
|
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2021-08-06 14:26:08 +00:00
|
|
|
virtual void SetNegativeZero() { m_negativeZero = true; }
|
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
/**
|
|
|
|
* Normally not needed, but can be used to set the precision when using
|
|
|
|
* internal units that are floats (not integers) like DEGREES or PERCENT.
|
|
|
|
* Not used for integer values in IU
|
|
|
|
* @param aLength is the number of digits for mantissa (0 = no truncation)
|
|
|
|
* must be <= 6
|
|
|
|
*/
|
|
|
|
virtual void SetPrecision( int aLength );
|
|
|
|
|
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
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set new value (in Internal Units) for the text field, taking care of units conversion.
|
2015-02-17 23:35:18 +00:00
|
|
|
*/
|
2022-06-01 01:50:52 +00:00
|
|
|
virtual void SetValue( long long int aValue );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void SetValue( const wxString& aValue );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-02-29 02:21:18 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set new value (in Internal Units) for the text field, taking care of units conversion.
|
|
|
|
*
|
2021-08-06 14:26:08 +00:00
|
|
|
* The value will be truncated according to the precision set by SetPrecision() (if not <= 0).
|
2020-02-29 02:21:18 +00:00
|
|
|
*/
|
|
|
|
virtual void SetDoubleValue( double aValue );
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
virtual void SetAngleValue( const EDA_ANGLE& aValue );
|
|
|
|
|
2018-09-09 18:04:10 +00:00
|
|
|
/**
|
2021-08-06 14:26:08 +00:00
|
|
|
* Set new value (in Internal Units) for the text field, taking care of units conversion
|
|
|
|
* WITHOUT triggering the update routine.
|
2018-09-09 18:04:10 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
2021-08-06 14:26:08 +00:00
|
|
|
/**
|
|
|
|
* Set new value (in Internal Units) for the text field, taking care of units conversion
|
|
|
|
* WITHOUT triggering the update routine.
|
|
|
|
*
|
|
|
|
* The value will be truncated according to the precision set by SetPrecision() (if not <= 0).
|
|
|
|
*/
|
|
|
|
virtual void ChangeDoubleValue( double aValue );
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
virtual void ChangeAngleValue( const EDA_ANGLE& aValue );
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return the current value in Internal Units.
|
2015-02-17 23:35:18 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return the current value in Internal Units.
|
|
|
|
*
|
|
|
|
* The returned value will be truncated according to the precision set by
|
2020-12-10 14:46:20 +00:00
|
|
|
* SetPrecision() (if not <= 0)
|
2020-02-29 02:21:18 +00:00
|
|
|
*/
|
|
|
|
virtual double GetDoubleValue();
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
virtual EDA_ANGLE GetAngleValue();
|
|
|
|
|
2015-07-09 11:35:50 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return true if the control holds the indeterminate value (for instance, if it
|
2018-02-03 09:09:53 +00:00
|
|
|
* represents a multiple selection of differing values).
|
|
|
|
*/
|
|
|
|
bool IsIndeterminate() const;
|
|
|
|
|
2020-04-03 20:47:02 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return the pre-evaluated text (or the current text if evaluation is not supported).
|
2020-04-03 20:47:02 +00:00
|
|
|
* Used primarily to remember values between dialog invocations.
|
|
|
|
*/
|
|
|
|
wxString GetOriginalText() const;
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Validate 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
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Enable/disable 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
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Show/hide 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set the current origin transform mode
|
2020-07-07 04:15:10 +00:00
|
|
|
*/
|
|
|
|
void SetCoordType( ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType )
|
|
|
|
{
|
|
|
|
m_coordType = aCoordType;
|
|
|
|
}
|
|
|
|
|
2022-02-04 17:37:30 +00:00
|
|
|
/**
|
|
|
|
* Force the binder to evaluate the text
|
|
|
|
*/
|
|
|
|
void RequireEval()
|
|
|
|
{
|
|
|
|
m_needsEval = true;
|
|
|
|
}
|
|
|
|
|
2015-02-17 23:35:18 +00:00
|
|
|
protected:
|
2022-03-15 23:51:50 +00:00
|
|
|
void onClick( wxMouseEvent& aEvent );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
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 );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
/**
|
|
|
|
* When m_precision > 0 truncate the value aValue to show only
|
2020-12-10 14:46:20 +00:00
|
|
|
* m_precision digits in mantissa.
|
|
|
|
* used in GetDoubleValue to return a rounded value.
|
|
|
|
* Mainly for units set to DEGREES.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-10 14:46:20 +00:00
|
|
|
* @param aValue is the value to modify.
|
|
|
|
* @param aValueUsesUserUnits must be set to true if aValue is a user value,
|
|
|
|
* and set to false if aValue is a internal unit value.
|
|
|
|
* @return the "rounded" value.
|
|
|
|
*/
|
|
|
|
double setPrecision( double aValue, bool aValueUsesUserUnits );
|
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
EDA_BASE_FRAME* m_frame;
|
2020-04-22 19:44:20 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< The bound widgets
|
2018-03-07 12:48:08 +00:00
|
|
|
wxStaticText* m_label;
|
2020-12-10 14:46:20 +00:00
|
|
|
wxWindow* m_valueCtrl;
|
2021-08-06 14:26:08 +00:00
|
|
|
wxStaticText* m_unitLabel; ///< Can be nullptr
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Currently used units.
|
2022-09-16 04:38:10 +00:00
|
|
|
const EDA_IU_SCALE& m_iuScale;
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS m_units;
|
2021-08-06 14:26:08 +00:00
|
|
|
bool m_negativeZero; ///< Indicates "-0" should be displayed for 0.
|
2020-06-26 02:18:29 +00:00
|
|
|
EDA_DATA_TYPE m_dataType;
|
2021-08-06 14:26:08 +00:00
|
|
|
int m_precision; ///< 0 to 6
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2018-10-30 23:12:55 +00:00
|
|
|
wxString m_errorMessage;
|
2015-02-17 23:35:18 +00:00
|
|
|
|
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
|
|
|
|
2021-08-06 14:26:08 +00:00
|
|
|
long m_selStart; ///< Selection start and end of the original text
|
2019-09-07 23:00:15 +00:00
|
|
|
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_ */
|