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-07-15 19:26:35 +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
|
|
|
|
*/
|
|
|
|
|
2019-09-07 23:00:15 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2015-02-17 23:35:18 +00:00
|
|
|
#include <wx/stattext.h>
|
2017-08-25 14:46:49 +00:00
|
|
|
#include <wx/textentry.h>
|
2015-02-17 23:35:18 +00:00
|
|
|
#include <limits>
|
|
|
|
#include <base_units.h>
|
2019-06-08 22:14:57 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2018-02-03 09:09:53 +00:00
|
|
|
#include <confirm.h>
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
#include "widgets/unit_binder.h"
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2018-11-23 14:58:38 +00:00
|
|
|
wxDEFINE_EVENT( DELAY_FOCUS, wxCommandEvent );
|
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValueCtrl,
|
2020-11-07 21:40:56 +00:00
|
|
|
wxStaticText* aUnitLabel, bool allowEval ) :
|
2020-04-22 19:44:20 +00:00
|
|
|
m_frame( aParent ),
|
|
|
|
m_label( aLabel ),
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl( aValueCtrl ),
|
2020-04-22 19:44:20 +00:00
|
|
|
m_unitLabel( aUnitLabel ),
|
2021-08-06 14:26:08 +00:00
|
|
|
m_negativeZero( false ),
|
|
|
|
m_dataType( EDA_DATA_TYPE::DISTANCE ),
|
|
|
|
m_precision( 0 ),
|
2020-10-02 20:51:24 +00:00
|
|
|
m_eval( aParent->GetUserUnits() ),
|
2020-07-07 04:15:10 +00:00
|
|
|
m_originTransforms( aParent->GetOriginTransforms() ),
|
|
|
|
m_coordType( ORIGIN_TRANSFORMS::NOT_A_COORD )
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
2020-06-26 02:18:29 +00:00
|
|
|
m_units = aParent->GetUserUnits();
|
2020-12-10 14:46:20 +00:00
|
|
|
m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2018-10-08 11:58:10 +00:00
|
|
|
m_needsEval = false;
|
2020-06-26 02:18:29 +00:00
|
|
|
m_selStart = 0;
|
|
|
|
m_selEnd = 0;
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
|
2018-03-07 12:48:08 +00:00
|
|
|
if( textEntry )
|
2018-07-21 08:41:38 +00:00
|
|
|
{
|
|
|
|
// Use ChangeValue() instead of SetValue() so we don't generate events.
|
2021-08-06 14:26:08 +00:00
|
|
|
if( m_negativeZero )
|
|
|
|
textEntry->ChangeValue( wxT( "-0" ) );
|
|
|
|
else
|
|
|
|
textEntry->ChangeValue( wxT( "0" ) );
|
2018-07-21 08:41:38 +00:00
|
|
|
}
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
if( m_unitLabel )
|
2021-08-07 23:02:07 +00:00
|
|
|
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ),
|
|
|
|
nullptr, this );
|
|
|
|
m_valueCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ),
|
|
|
|
nullptr, this );
|
2022-03-15 23:51:50 +00:00
|
|
|
m_valueCtrl->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( UNIT_BINDER::onClick ), nullptr,
|
|
|
|
this );
|
2021-07-15 19:26:35 +00:00
|
|
|
Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), nullptr,
|
|
|
|
this );
|
2020-04-22 19:44:20 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
|
|
|
|
nullptr, this );
|
2020-04-22 19:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UNIT_BINDER::~UNIT_BINDER()
|
|
|
|
{
|
2021-07-15 19:26:35 +00:00
|
|
|
m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
|
|
|
|
nullptr, this );
|
2015-02-17 23:35:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
void UNIT_BINDER::SetUnits( EDA_UNITS aUnits )
|
2018-05-23 06:11:47 +00:00
|
|
|
{
|
|
|
|
m_units = aUnits;
|
2020-12-10 14:46:20 +00:00
|
|
|
|
|
|
|
if( m_unitLabel )
|
2021-08-07 23:02:07 +00:00
|
|
|
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
|
2020-12-10 14:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::SetPrecision( int aLength )
|
|
|
|
{
|
|
|
|
m_precision = std::min( aLength, 6 );
|
2020-06-26 02:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::SetDataType( EDA_DATA_TYPE aDataType )
|
|
|
|
{
|
|
|
|
m_dataType = aDataType;
|
2020-12-10 14:46:20 +00:00
|
|
|
|
|
|
|
if( m_unitLabel )
|
2021-08-07 23:02:07 +00:00
|
|
|
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
|
2018-05-23 06:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-22 19:44:20 +00:00
|
|
|
void UNIT_BINDER::onUnitsChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
2021-12-31 23:31:18 +00:00
|
|
|
if( m_units != EDA_UNITS::UNSCALED
|
|
|
|
&& m_units != EDA_UNITS::DEGREES
|
|
|
|
&& m_units != EDA_UNITS::PERCENT )
|
|
|
|
{
|
|
|
|
int temp = (int) GetValue();
|
2020-04-22 19:44:20 +00:00
|
|
|
|
2021-12-31 23:31:18 +00:00
|
|
|
SetUnits( m_frame->GetUserUnits() );
|
2020-04-22 19:44:20 +00:00
|
|
|
|
2021-12-31 23:31:18 +00:00
|
|
|
SetValue( temp );
|
|
|
|
}
|
2020-04-22 19:44:20 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-15 23:51:50 +00:00
|
|
|
void UNIT_BINDER::onClick( wxMouseEvent& aEvent )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2018-03-07 12:48:08 +00:00
|
|
|
|
2022-03-15 23:51:50 +00:00
|
|
|
if( textEntry && ( textEntry->GetValue() == INDETERMINATE_ACTION
|
|
|
|
|| textEntry->GetValue() == INDETERMINATE_STATE ) )
|
|
|
|
{
|
|
|
|
// These are tokens, not strings, so do a select all
|
|
|
|
textEntry->SelectAll();
|
|
|
|
}
|
2022-03-19 09:22:41 +00:00
|
|
|
|
|
|
|
// Needed at least on Windows to avoid hanging
|
|
|
|
aEvent.Skip();
|
2022-03-15 23:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::onSetFocus( wxFocusEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2022-03-15 23:51:50 +00:00
|
|
|
if( textEntry )
|
|
|
|
{
|
|
|
|
if( m_allowEval )
|
2019-09-07 23:00:15 +00:00
|
|
|
{
|
2022-03-15 23:51:50 +00:00
|
|
|
wxString oldStr = m_eval.OriginalText();
|
|
|
|
|
|
|
|
if( oldStr.length() && oldStr != textEntry->GetValue() )
|
|
|
|
{
|
|
|
|
textEntry->SetValue( oldStr );
|
|
|
|
textEntry->SetSelection( m_selStart, m_selEnd );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_needsEval = true;
|
2019-09-07 23:00:15 +00:00
|
|
|
}
|
2018-10-08 11:58:10 +00:00
|
|
|
|
2022-03-15 23:51:50 +00:00
|
|
|
if( textEntry->GetValue() == INDETERMINATE_ACTION
|
|
|
|
|| textEntry->GetValue() == INDETERMINATE_STATE )
|
|
|
|
{
|
|
|
|
// These are tokens, not strings, so do a select all
|
|
|
|
textEntry->SelectAll();
|
|
|
|
}
|
2018-02-03 09:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::onKillFocus( wxFocusEvent& aEvent )
|
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2018-10-08 11:58:10 +00:00
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
if( m_allowEval && textEntry )
|
|
|
|
{
|
|
|
|
if( m_eval.Process( textEntry->GetValue() ) )
|
2019-09-07 23:00:15 +00:00
|
|
|
{
|
|
|
|
textEntry->GetSelection( &m_selStart, &m_selEnd );
|
|
|
|
wxString sel = textEntry->GetStringSelection();
|
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
textEntry->ChangeValue( m_eval.Result() );
|
2018-11-27 17:08:11 +00:00
|
|
|
|
2019-09-07 23:00:15 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
// Manually copy the selected text to the primary selection clipboard
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
|
|
|
|
wxTheClipboard->UsePrimarySelection( true );
|
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( sel ) );
|
|
|
|
wxTheClipboard->UsePrimarySelection( clipTarget );
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-11-29 18:59:38 +00:00
|
|
|
m_needsEval = false;
|
2018-11-27 17:08:11 +00:00
|
|
|
}
|
2018-03-07 12:48:08 +00:00
|
|
|
|
2018-10-08 11:58:10 +00:00
|
|
|
aEvent.Skip();
|
2018-02-03 09:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString valueDescriptionFromLabel( wxStaticText* aLabel )
|
|
|
|
{
|
|
|
|
wxString desc = aLabel->GetLabel();
|
|
|
|
|
|
|
|
desc.EndsWith( wxT( ":" ), &desc );
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-23 14:58:38 +00:00
|
|
|
void UNIT_BINDER::delayedFocusHandler( wxCommandEvent& )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2018-10-30 23:12:55 +00:00
|
|
|
if( !m_errorMessage.IsEmpty() )
|
2020-12-10 14:46:20 +00:00
|
|
|
DisplayError( m_valueCtrl->GetParent(), m_errorMessage );
|
2018-10-30 23:12:55 +00:00
|
|
|
|
|
|
|
m_errorMessage = wxEmptyString;
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl->SetFocus();
|
2018-02-03 09:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
bool UNIT_BINDER::Validate( double aMin, double aMax, EDA_UNITS aUnits )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2018-03-07 12:48:08 +00:00
|
|
|
|
2020-05-05 15:40:18 +00:00
|
|
|
if( !textEntry
|
|
|
|
|| textEntry->GetValue() == INDETERMINATE_ACTION
|
|
|
|
|| textEntry->GetValue() == INDETERMINATE_STATE )
|
|
|
|
{
|
2018-03-07 12:48:08 +00:00
|
|
|
return true;
|
2020-05-05 15:40:18 +00:00
|
|
|
}
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-06-29 16:16:37 +00:00
|
|
|
// TODO: Validate() does not currently support m_dataType being anything other than DISTANCE
|
2020-07-08 08:27:31 +00:00
|
|
|
// Note: aMin and aMax are not always given in internal units
|
2020-10-02 20:51:24 +00:00
|
|
|
if( GetValue() < From_User_Unit( aUnits, aMin ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2020-10-02 20:51:24 +00:00
|
|
|
double val_min_iu = From_User_Unit( aUnits, aMin );
|
2018-11-29 18:59:38 +00:00
|
|
|
m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
|
2018-10-30 23:12:55 +00:00
|
|
|
valueDescriptionFromLabel( m_label ),
|
2020-10-02 20:51:24 +00:00
|
|
|
StringFromValue( m_units, val_min_iu, true ) );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
textEntry->SelectAll();
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
// Don't focus directly; we might be inside a KillFocus event handler
|
|
|
|
wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
if( GetValue() > From_User_Unit( aUnits, aMax ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2020-10-02 20:51:24 +00:00
|
|
|
double val_max_iu = From_User_Unit( aUnits, aMax );
|
2018-11-29 18:59:38 +00:00
|
|
|
m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
|
2018-10-30 23:12:55 +00:00
|
|
|
valueDescriptionFromLabel( m_label ),
|
2020-10-02 20:51:24 +00:00
|
|
|
StringFromValue( m_units, val_max_iu, true ) );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
textEntry->SelectAll();
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
// Don't focus directly; we might be inside a KillFocus event handler
|
|
|
|
wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
void UNIT_BINDER::SetValue( int aValue )
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
2020-07-07 04:15:10 +00:00
|
|
|
double value = aValue;
|
|
|
|
double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
|
|
|
SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
|
|
|
|
else
|
|
|
|
SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
|
2018-02-03 09:09:53 +00:00
|
|
|
}
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2015-07-09 11:35:50 +00:00
|
|
|
|
2020-02-29 02:21:18 +00:00
|
|
|
void UNIT_BINDER::SetDoubleValue( double aValue )
|
|
|
|
{
|
2020-07-07 04:15:10 +00:00
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
2020-12-10 14:46:20 +00:00
|
|
|
displayValue = setPrecision( displayValue, false );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
|
|
|
SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
|
|
|
|
else
|
|
|
|
SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
|
2020-02-29 02:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
void UNIT_BINDER::SetAngleValue( const EDA_ANGLE& aValue )
|
|
|
|
{
|
2022-01-18 23:20:48 +00:00
|
|
|
SetDoubleValue( aValue.AsDegrees() );
|
2022-01-15 00:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
void UNIT_BINDER::SetValue( const wxString& aValue )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
|
|
|
wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
|
|
|
|
if( textEntry )
|
2018-10-08 11:58:10 +00:00
|
|
|
textEntry->SetValue( aValue );
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( staticText )
|
2018-10-08 11:58:10 +00:00
|
|
|
staticText->SetLabel( aValue );
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
if( m_allowEval )
|
2018-09-09 18:04:10 +00:00
|
|
|
m_eval.Clear();
|
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
if( m_unitLabel )
|
2021-08-07 23:02:07 +00:00
|
|
|
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
|
2018-09-09 18:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::ChangeValue( int aValue )
|
|
|
|
{
|
2020-07-07 04:15:10 +00:00
|
|
|
double value = aValue;
|
|
|
|
double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
|
|
|
ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false ) );
|
|
|
|
else
|
|
|
|
ChangeValue( StringFromValue( m_units, displayValue, false ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::ChangeDoubleValue( double aValue )
|
|
|
|
{
|
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
|
|
|
displayValue = setPrecision( displayValue, false );
|
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
|
|
|
ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
|
|
|
|
else
|
|
|
|
ChangeValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
|
2018-09-09 18:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
void UNIT_BINDER::ChangeAngleValue( const EDA_ANGLE& aValue )
|
|
|
|
{
|
2022-01-18 23:20:48 +00:00
|
|
|
ChangeDoubleValue( aValue.AsDegrees() );
|
2022-01-15 00:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-05 15:40:18 +00:00
|
|
|
void UNIT_BINDER::ChangeValue( const wxString& aValue )
|
2018-09-09 18:04:10 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
|
|
|
wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
|
|
|
|
if( textEntry )
|
2018-10-08 11:58:10 +00:00
|
|
|
textEntry->ChangeValue( aValue );
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( staticText )
|
2018-10-08 11:58:10 +00:00
|
|
|
staticText->SetLabel( aValue );
|
2018-09-09 18:04:10 +00:00
|
|
|
|
|
|
|
if( m_allowEval )
|
2018-02-25 16:14:24 +00:00
|
|
|
m_eval.Clear();
|
2018-02-03 09:09:53 +00:00
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
if( m_unitLabel )
|
2021-08-07 23:02:07 +00:00
|
|
|
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
|
2015-02-17 23:35:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
long long int UNIT_BINDER::GetValue()
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
|
|
|
wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
wxString value;
|
2018-03-07 12:48:08 +00:00
|
|
|
|
2020-05-05 15:40:18 +00:00
|
|
|
if( textEntry )
|
2018-10-08 11:58:10 +00:00
|
|
|
{
|
2018-10-30 22:56:52 +00:00
|
|
|
if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
|
|
|
|
value = m_eval.Result();
|
|
|
|
else
|
|
|
|
value = textEntry->GetValue();
|
2018-10-08 11:58:10 +00:00
|
|
|
}
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( staticText )
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2018-10-30 22:56:52 +00:00
|
|
|
value = staticText->GetLabel();
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2018-10-08 11:58:10 +00:00
|
|
|
else
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2018-10-08 11:58:10 +00:00
|
|
|
return 0;
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2018-10-30 22:56:52 +00:00
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
long long int displayValue = ValueFromString( m_units, value, m_dataType );
|
2020-07-07 04:15:10 +00:00
|
|
|
return m_originTransforms.FromDisplay( displayValue, m_coordType );
|
2015-02-17 23:35:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
double UNIT_BINDER::setPrecision( double aValue, bool aValueUsesUserUnits )
|
|
|
|
{
|
|
|
|
if( m_precision > 1 )
|
|
|
|
{
|
|
|
|
int scale = pow( 10, m_precision );
|
|
|
|
long long tmp = aValueUsesUserUnits ? aValue : To_User_Unit( m_units, aValue ) * scale;
|
|
|
|
aValue = static_cast<double>( tmp ) / scale;
|
|
|
|
|
|
|
|
if( !aValueUsesUserUnits )
|
|
|
|
aValue = From_User_Unit( m_units, aValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 02:21:18 +00:00
|
|
|
double UNIT_BINDER::GetDoubleValue()
|
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
|
|
|
wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
wxString value;
|
2020-02-29 02:21:18 +00:00
|
|
|
|
2020-05-05 15:40:18 +00:00
|
|
|
if( textEntry )
|
2020-02-29 02:21:18 +00:00
|
|
|
{
|
|
|
|
if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
|
|
|
|
value = m_eval.Result();
|
|
|
|
else
|
|
|
|
value = textEntry->GetValue();
|
|
|
|
}
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( staticText )
|
2020-11-07 21:40:56 +00:00
|
|
|
{
|
2020-02-29 02:21:18 +00:00
|
|
|
value = staticText->GetLabel();
|
2020-11-07 21:40:56 +00:00
|
|
|
}
|
2020-02-29 02:21:18 +00:00
|
|
|
else
|
2020-11-07 21:40:56 +00:00
|
|
|
{
|
2020-02-29 02:21:18 +00:00
|
|
|
return 0.0;
|
2020-11-07 21:40:56 +00:00
|
|
|
}
|
2020-02-29 02:21:18 +00:00
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
double displayValue = DoubleValueFromString( m_units, value, m_dataType );
|
2020-12-10 14:46:20 +00:00
|
|
|
displayValue = setPrecision( displayValue, false );
|
|
|
|
|
2020-07-07 04:15:10 +00:00
|
|
|
return m_originTransforms.FromDisplay( displayValue, m_coordType );
|
2020-02-29 02:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-15 00:20:02 +00:00
|
|
|
EDA_ANGLE UNIT_BINDER::GetAngleValue()
|
|
|
|
{
|
2022-01-18 23:20:48 +00:00
|
|
|
return EDA_ANGLE( GetDoubleValue(), DEGREES_T );
|
2022-01-15 00:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-03 09:09:53 +00:00
|
|
|
bool UNIT_BINDER::IsIndeterminate() const
|
2015-07-09 11:35:50 +00:00
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* te = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
|
|
|
|
if( te )
|
|
|
|
return te->GetValue() == INDETERMINATE_STATE || te->GetValue() == INDETERMINATE_ACTION;
|
2018-03-07 12:48:08 +00:00
|
|
|
|
|
|
|
return false;
|
2015-07-09 11:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 20:47:02 +00:00
|
|
|
wxString UNIT_BINDER::GetOriginalText() const
|
|
|
|
{
|
2020-12-10 14:46:20 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
|
|
|
wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
|
2020-05-05 15:40:18 +00:00
|
|
|
|
2020-04-03 20:47:02 +00:00
|
|
|
if( m_allowEval )
|
|
|
|
return m_eval.OriginalText();
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( textEntry )
|
2020-04-04 11:24:54 +00:00
|
|
|
return textEntry->GetValue();
|
2020-05-05 15:40:18 +00:00
|
|
|
else if( staticText )
|
2020-04-04 11:24:54 +00:00
|
|
|
return staticText->GetLabel();
|
2020-04-03 20:47:02 +00:00
|
|
|
else
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-12 07:36:35 +00:00
|
|
|
void UNIT_BINDER::SetLabel( const wxString& aLabel )
|
|
|
|
{
|
|
|
|
m_label->SetLabel( aLabel );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-10 23:27:46 +00:00
|
|
|
void UNIT_BINDER::Enable( bool aEnable )
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
2018-02-03 09:09:53 +00:00
|
|
|
m_label->Enable( aEnable );
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl->Enable( aEnable );
|
|
|
|
|
|
|
|
if( m_unitLabel )
|
|
|
|
m_unitLabel->Enable( aEnable );
|
2015-03-11 16:04:20 +00:00
|
|
|
}
|
2017-08-25 14:46:49 +00:00
|
|
|
|
2018-05-23 06:11:47 +00:00
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
void UNIT_BINDER::Show( bool aShow, bool aResize )
|
2018-05-23 06:11:47 +00:00
|
|
|
{
|
|
|
|
m_label->Show( aShow );
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl->Show( aShow );
|
|
|
|
|
|
|
|
if( m_unitLabel )
|
|
|
|
m_unitLabel->Show( aShow );
|
2019-04-14 17:58:35 +00:00
|
|
|
|
|
|
|
if( aResize )
|
|
|
|
{
|
|
|
|
if( aShow )
|
|
|
|
{
|
|
|
|
m_label->SetSize( -1, -1 );
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl->SetSize( -1, -1 );
|
|
|
|
|
|
|
|
if( m_unitLabel )
|
|
|
|
m_unitLabel->SetSize( -1, -1 );
|
2019-04-14 17:58:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_label->SetSize( 0, 0 );
|
2020-12-10 14:46:20 +00:00
|
|
|
m_valueCtrl->SetSize( 0, 0 );
|
|
|
|
|
|
|
|
if( m_unitLabel )
|
|
|
|
m_unitLabel->SetSize( 0, 0 );
|
2019-04-14 17:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-23 06:11:47 +00:00
|
|
|
}
|
|
|
|
|