From 676d35f559e6efb9591ef607a5d241eb15cbc988 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 9 Dec 2020 19:38:35 +0100 Subject: [PATCH] Replace wxFloatingPointValidator by our UNIT_BINDER in DIALOG_TEXT_PROPERTIES. wxFloatingPointValidator has some limitations, but mainly the change is a try to fix an annoying issue (#6670) we cannot reproduce but is probably related to a locale issue. --- common/widgets/unit_binder.cpp | 21 +++++++++++++++------ include/widgets/unit_binder.h | 1 + pcbnew/dialogs/dialog_text_properties.cpp | 13 +++++++------ pcbnew/dialogs/dialog_text_properties.h | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 8504997b46..465f8e3d9d 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -57,7 +57,8 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, textEntry->ChangeValue( wxT( "0" ) ); } - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); + if( m_unitLabel ) + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this ); m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this ); @@ -69,7 +70,9 @@ void UNIT_BINDER::SetUnits( EDA_UNITS_T aUnits, bool aUseMils ) { m_units = aUnits; m_useMils = aUseMils; - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); + + if( m_unitLabel ) + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); } @@ -208,7 +211,8 @@ void UNIT_BINDER::SetValue( wxString aValue ) if( m_allowEval ) m_eval.Clear(); - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); + if( m_unitLabel ) + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); } @@ -231,7 +235,8 @@ void UNIT_BINDER::ChangeValue( wxString aValue ) if( m_allowEval ) m_eval.Clear(); - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); + if( m_unitLabel ) + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_useMils ) ); } @@ -278,7 +283,9 @@ void UNIT_BINDER::Enable( bool aEnable ) { m_label->Enable( aEnable ); m_value->Enable( aEnable ); - m_unitLabel->Enable( aEnable ); + + if( m_unitLabel ) + m_unitLabel->Enable( aEnable ); } @@ -286,6 +293,8 @@ void UNIT_BINDER::Show( bool aShow ) { m_label->Show( aShow ); m_value->Show( aShow ); - m_unitLabel->Show( aShow ); + + if( m_unitLabel ) + m_unitLabel->Show( aShow ); } diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index ba4b80b3ce..2d5264cf18 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -48,6 +48,7 @@ public: * @param aValue is the control used to edit or display the given value (wxTextCtrl, * wxComboBox, wxStaticText, etc.). * @param aUnitLabel is the units label displayed after the text input widget + * can be nullptr * @param aUseMils specifies the use of mils for imperial units (instead of inches) * @param aAllowEval indicates \a aTextInput's content should be eval'ed before storing */ diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index ccd949fca6..5146b0be49 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -65,7 +65,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_posY( aParent, m_PositionYLabel, m_PositionYCtrl, m_PositionYUnits ), m_linesThickness( aParent, m_LinesThicknessLabel, m_LinesThicknessCtrl, m_LinesThicknessUnits, true ), - m_OrientValidator( 1, &m_OrientValue ) + m_orientation( aParent, m_OrientLabel, m_OrientCtrl, nullptr, true ) { wxString title; @@ -140,9 +140,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO m_LayerSelectionCtrl->Resync(); m_OrientValue = 0.0; - m_OrientValidator.SetRange( -360.0, 360.0 ); - m_OrientCtrl->SetValidator( m_OrientValidator ); - m_OrientValidator.SetWindow( m_OrientCtrl ); + m_orientation.SetUnits( DEGREES ); // Handle decimal separators in combo dropdown for( size_t i = 0; i < m_OrientCtrl->GetCount(); ++i ) @@ -344,7 +342,8 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() m_Italic->SetValue( m_edaText->IsItalic() ); EDA_TEXT_HJUSTIFY_T hJustify = m_edaText->GetHorizJustify(); m_JustifyChoice->SetSelection( (int) hJustify + 1 ); - m_OrientValue = m_edaText->GetTextAngleDegrees(); + m_OrientValue = m_edaText->GetTextAngle(); + m_orientation.SetValue( m_OrientValue ); m_Mirrored->SetValue( m_edaText->IsMirrored() ); if( m_modText ) @@ -436,7 +435,9 @@ bool DIALOG_TEXT_PROPERTIES::TransferDataFromWindow() m_edaText->SetVisible( m_Visible->GetValue() ); m_edaText->SetItalic( m_Italic->GetValue() ); - m_edaText->SetTextAngle( KiROUND( m_OrientValue * 10.0 ) ); + m_OrientValue = m_orientation.GetValue(); + NORMALIZE_ANGLE_180( m_OrientValue ); + m_edaText->SetTextAngle( m_OrientValue ); m_edaText->SetMirrored( m_Mirrored->GetValue() ); if( m_modText ) diff --git a/pcbnew/dialogs/dialog_text_properties.h b/pcbnew/dialogs/dialog_text_properties.h index 52a81f6589..9ee70dfb11 100644 --- a/pcbnew/dialogs/dialog_text_properties.h +++ b/pcbnew/dialogs/dialog_text_properties.h @@ -57,8 +57,8 @@ private: UNIT_BINDER m_posX; UNIT_BINDER m_posY; UNIT_BINDER m_linesThickness; // lines thikness for dimension graphic + UNIT_BINDER m_orientation; // rotation in degrees - wxFloatingPointValidator m_OrientValidator; double m_OrientValue; bool TransferDataToWindow() override;