From 78dfbca9a399f3a0f01c8ae442b0255da910284f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 3 Apr 2020 21:47:02 +0100 Subject: [PATCH] Save pre-eval values for Move Exactly dialog. Fixes https://gitlab.com/kicad/code/kicad/issues/4088 --- common/widgets/unit_binder.cpp | 14 ++++++++++++++ include/widgets/unit_binder.h | 8 ++++++++ pcbnew/dialogs/dialog_move_exact.cpp | 12 ++++++------ pcbnew/dialogs/dialog_move_exact.h | 18 +++++++++--------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 1f1eefdd7e..0d54b9a16b 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2015 CERN + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. * Author: Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -296,6 +297,19 @@ bool UNIT_BINDER::IsIndeterminate() const } +wxString UNIT_BINDER::GetOriginalText() const +{ + if( m_allowEval ) + return m_eval.OriginalText(); + else if( dynamic_cast( m_value ) ) + return dynamic_cast( m_value )->GetValue(); + else if( dynamic_cast( m_value ) ) + return dynamic_cast( m_value )->GetLabel(); + else + return wxEmptyString; +} + + void UNIT_BINDER::SetLabel( const wxString& aLabel ) { m_label->SetLabel( aLabel ); diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index d4cef5e1ba..a1e12a0082 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2015 CERN + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. * Author: Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -107,6 +108,13 @@ public: */ bool IsIndeterminate() const; + /** + * 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; + /** * Function Validate * Validates the control against the given range, informing the user of any errors found. diff --git a/pcbnew/dialogs/dialog_move_exact.cpp b/pcbnew/dialogs/dialog_move_exact.cpp index e1569c6407..8bbda19133 100644 --- a/pcbnew/dialogs/dialog_move_exact.cpp +++ b/pcbnew/dialogs/dialog_move_exact.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 John Beard, john.j.beard@gmail.com - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -70,8 +70,8 @@ DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT( PCB_BASE_FRAME *aParent, wxPoint& aTransla // and set up the entries according to the saved options m_polarCoords->SetValue( m_options.polarCoords ); - m_moveX.SetDoubleValue( m_options.entry1 ); - m_moveY.SetDoubleValue( m_options.entry2 ); + m_moveX.SetValue( m_options.entry1 ); + m_moveY.SetValue( m_options.entry2 ); m_rotate.SetUnits( EDA_UNITS::DEGREES ); m_rotate.SetValue( m_options.entryRotation ); @@ -246,9 +246,9 @@ bool DIALOG_MOVE_EXACT::TransferDataFromWindow() { // save the settings m_options.polarCoords = m_polarCoords->GetValue(); - m_options.entry1 = m_moveX.GetDoubleValue(); - m_options.entry2 = m_moveY.GetDoubleValue(); - m_options.entryRotation = m_rotate.GetValue(); + m_options.entry1 = m_moveX.GetOriginalText(); + m_options.entry2 = m_moveY.GetOriginalText(); + m_options.entryRotation = m_rotate.GetOriginalText(); m_options.entryAnchorSelection = (size_t) std::max( m_anchorOptions->GetSelection(), 0 ); return true; } diff --git a/pcbnew/dialogs/dialog_move_exact.h b/pcbnew/dialogs/dialog_move_exact.h index b9f694e01a..a74e767abb 100644 --- a/pcbnew/dialogs/dialog_move_exact.h +++ b/pcbnew/dialogs/dialog_move_exact.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 John Beard, john.j.beard@gmail.com - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -110,17 +110,17 @@ private: */ struct MOVE_EXACT_OPTIONS { - bool polarCoords; - double entry1; - double entry2; - double entryRotation; - size_t entryAnchorSelection; + bool polarCoords; + wxString entry1; + wxString entry2; + wxString entryRotation; + size_t entryAnchorSelection; MOVE_EXACT_OPTIONS(): polarCoords( false ), - entry1( 0 ), - entry2( 0 ), - entryRotation( 0 ), + entry1( wxT( "0" ) ), + entry2( wxT( "0" ) ), + entryRotation( wxT( "0" ) ), entryAnchorSelection( 0 ) { }