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
|
2022-10-11 17:01:47 +00:00
|
|
|
* Copyright (C) 2020-2022 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>
|
2022-09-28 03:13:55 +00:00
|
|
|
#include <eda_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
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValueCtrl,
|
2022-11-06 23:26:17 +00:00
|
|
|
wxStaticText* aUnitLabel, bool allowEval, bool aBindFrameEvents ) :
|
|
|
|
UNIT_BINDER( aParent, aParent->GetIuScale(), aLabel, aValueCtrl, aUnitLabel, allowEval,
|
|
|
|
aBindFrameEvents )
|
2022-09-16 04:38:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale,
|
|
|
|
wxStaticText* aLabel, wxWindow* aValueCtrl,
|
2022-11-06 23:26:17 +00:00
|
|
|
wxStaticText* aUnitLabel, bool allowEval, bool aBindFrameEvents ) :
|
2020-04-22 19:44:20 +00:00
|
|
|
m_frame( aParent ),
|
2022-11-06 23:26:17 +00:00
|
|
|
m_bindFrameEvents( aBindFrameEvents ),
|
2020-04-22 19:44:20 +00:00
|
|
|
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 ),
|
2022-09-16 04:38:10 +00:00
|
|
|
m_iuScale( aIUScale ),
|
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
|
|
|
{
|
2022-11-06 23:26:17 +00:00
|
|
|
init();
|
2022-11-03 02:50:49 +00:00
|
|
|
m_allowEval = allowEval && ( !m_valueCtrl || dynamic_cast<wxTextEntry*>( m_valueCtrl ) );
|
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 )
|
2022-09-19 09:25:20 +00:00
|
|
|
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
|
2015-02-17 23:35:18 +00:00
|
|
|
|
2022-11-03 02:50:49 +00:00
|
|
|
if( m_valueCtrl )
|
|
|
|
{
|
|
|
|
m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ),
|
|
|
|
nullptr, this );
|
|
|
|
m_valueCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ),
|
|
|
|
nullptr, this );
|
|
|
|
m_valueCtrl->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( UNIT_BINDER::onClick ), nullptr,
|
|
|
|
this );
|
|
|
|
}
|
|
|
|
|
2022-11-06 23:26:17 +00:00
|
|
|
if( m_bindFrameEvents )
|
|
|
|
{
|
|
|
|
Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), nullptr,
|
|
|
|
this );
|
2020-04-22 19:44:20 +00:00
|
|
|
|
2022-11-06 23:26:17 +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()
|
|
|
|
{
|
2022-11-06 23:26:17 +00:00
|
|
|
if( m_bindFrameEvents )
|
|
|
|
{
|
|
|
|
m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
|
|
|
|
nullptr, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::init()
|
|
|
|
{
|
|
|
|
m_units = m_frame->GetUserUnits();
|
|
|
|
m_needsEval = false;
|
|
|
|
m_selStart = 0;
|
|
|
|
m_selEnd = 0;
|
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
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
m_eval.SetDefaultUnits( m_units );
|
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
if( m_unitLabel )
|
2022-09-19 09:25:20 +00:00
|
|
|
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
|
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 )
|
2022-09-19 09:25:20 +00:00
|
|
|
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
|
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 );
|
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() )
|
|
|
|
{
|
2022-07-25 11:07:57 +00:00
|
|
|
wxString sel = textEntry->GetStringSelection();
|
2019-09-07 23:00:15 +00:00
|
|
|
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
|
2022-09-16 04:38:10 +00:00
|
|
|
if( GetValue() < EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMin ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
double val_min_iu = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, 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 ),
|
2022-09-19 09:25:20 +00:00
|
|
|
EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, 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;
|
|
|
|
}
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
if( GetValue() > EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, aUnits, aMax ) )
|
2018-02-03 09:09:53 +00:00
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
double val_max_iu = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, 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 ),
|
2022-09-19 09:25:20 +00:00
|
|
|
EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-01 01:50:52 +00:00
|
|
|
void UNIT_BINDER::SetValue( long long int aValue )
|
2015-02-17 23:35:18 +00:00
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
|
|
|
wxString textValue = EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units, displayValue,
|
|
|
|
false, m_dataType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
2022-09-19 09:25:20 +00:00
|
|
|
SetValue( wxT( "-" ) + textValue );
|
2021-08-06 14:26:08 +00:00
|
|
|
else
|
2022-09-19 09:25:20 +00:00
|
|
|
SetValue( textValue );
|
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 )
|
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
|
|
|
wxString textValue = EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
|
|
|
|
setPrecision( displayValue, false ),
|
|
|
|
false, m_dataType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
2022-09-19 09:25:20 +00:00
|
|
|
SetValue( wxT( "-" ) + textValue );
|
2021-08-06 14:26:08 +00:00
|
|
|
else
|
2022-09-19 09:25:20 +00:00
|
|
|
SetValue( textValue );
|
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 )
|
2022-09-19 09:25:20 +00:00
|
|
|
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
|
2018-09-09 18:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::ChangeValue( int aValue )
|
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
|
|
|
wxString textValue = EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
|
|
|
|
setPrecision( displayValue, false ),
|
|
|
|
false, m_dataType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
2022-09-19 09:25:20 +00:00
|
|
|
ChangeValue( wxT( "-" ) + textValue );
|
2021-08-06 14:26:08 +00:00
|
|
|
else
|
2022-09-19 09:25:20 +00:00
|
|
|
ChangeValue( textValue );
|
2021-08-06 14:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UNIT_BINDER::ChangeDoubleValue( double aValue )
|
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
|
|
|
|
wxString textValue = EDA_UNIT_UTILS::UI::StringFromValue( m_iuScale, m_units,
|
|
|
|
setPrecision( displayValue, false ),
|
|
|
|
false, m_dataType );
|
2021-08-06 14:26:08 +00:00
|
|
|
|
|
|
|
if( displayValue == 0 && m_negativeZero )
|
2022-09-19 09:25:20 +00:00
|
|
|
ChangeValue( wxT( "-" ) + textValue );
|
2021-08-06 14:26:08 +00:00
|
|
|
else
|
2022-09-19 09:25:20 +00:00
|
|
|
ChangeValue( textValue );
|
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 )
|
2022-09-19 09:25:20 +00:00
|
|
|
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
|
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
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
long long int displayValue = EDA_UNIT_UTILS::UI::ValueFromString( m_iuScale, 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 );
|
2022-09-16 04:38:10 +00:00
|
|
|
int64_t tmp = aValue;
|
|
|
|
if( !aValueUsesUserUnits )
|
|
|
|
{
|
|
|
|
tmp = EDA_UNIT_UTILS::UI::ToUserUnit( m_iuScale, m_units, aValue ) * scale;
|
|
|
|
}
|
|
|
|
|
2020-12-10 14:46:20 +00:00
|
|
|
aValue = static_cast<double>( tmp ) / scale;
|
|
|
|
|
|
|
|
if( !aValueUsesUserUnits )
|
2022-09-16 04:38:10 +00:00
|
|
|
aValue = EDA_UNIT_UTILS::UI::FromUserUnit( m_iuScale, m_units, aValue );
|
2020-12-10 14:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
double displayValue = EDA_UNIT_UTILS::UI::DoubleValueFromString( m_iuScale, 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
|
|
|
|
2022-11-06 23:27:18 +00:00
|
|
|
if( te )
|
2020-05-05 15:40:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-03 02:50:49 +00:00
|
|
|
|
|
|
|
PROPERTY_EDITOR_UNIT_BINDER::PROPERTY_EDITOR_UNIT_BINDER( EDA_DRAW_FRAME* aParent ) :
|
2022-11-06 23:26:17 +00:00
|
|
|
UNIT_BINDER( aParent, nullptr, nullptr, nullptr, true, false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PROPERTY_EDITOR_UNIT_BINDER::~PROPERTY_EDITOR_UNIT_BINDER()
|
2022-11-03 02:50:49 +00:00
|
|
|
{
|
|
|
|
}
|