From 8d7255aae30760be5c438d2e3261ee97830092c0 Mon Sep 17 00:00:00 2001 From: Josue Date: Tue, 27 Jun 2023 00:21:16 -0500 Subject: [PATCH] truncate angle values in Segment properties --- libs/kimath/include/geometry/eda_angle.h | 8 ++++++++ pcbnew/dialogs/dialog_graphic_item_properties.cpp | 13 +++++++------ .../dialogs/dialog_graphic_item_properties_base.cpp | 8 ++++++++ .../dialogs/dialog_graphic_item_properties_base.fbp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libs/kimath/include/geometry/eda_angle.h b/libs/kimath/include/geometry/eda_angle.h index 9a916ed594..cda7dd4c69 100644 --- a/libs/kimath/include/geometry/eda_angle.h +++ b/libs/kimath/include/geometry/eda_angle.h @@ -309,6 +309,14 @@ public: EDA_ANGLE KeepUpright() const; + EDA_ANGLE& Truncate( int digits ) const + { + EDA_ANGLE angle( *this ); + double truncated = KiROUND( angle.AsDegrees() * pow( 10.0, digits ) ) / pow( 10.0, digits ); + angle = EDA_ANGLE( truncated , DEGREES_T ); + return angle; + } + EDA_ANGLE& operator+=( const EDA_ANGLE& aAngle ) { *this = EDA_ANGLE( AsDegrees() + aAngle.AsDegrees(), DEGREES_T ); diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp index fca88cc480..0de8b9c199 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp @@ -126,6 +126,7 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR m_segmentLength.SetUnits( EDA_UNITS::MILLIMETRES ); m_segmentAngle.SetUnits( EDA_UNITS::DEGREES ); + m_segmentAngle.SetPrecision( 4 ); m_rectangleHeight.SetUnits( EDA_UNITS::MILLIMETRES ); m_rectangleWidth.SetUnits( EDA_UNITS::MILLIMETRES ); @@ -402,7 +403,7 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() if( m_item->GetShape() == SHAPE_T::SEGMENT ) { segment_length = m_item->GetLength(); - segment_angle = m_item->GetSegmentAngle(); + segment_angle = m_item->GetSegmentAngle().Truncate( 3 ); } if( m_item->GetShape() == SHAPE_T::RECT ) @@ -443,17 +444,17 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() bool change_end = ( end_point != m_item->GetEnd() ); bool change_length = ( segment_length != m_segmentLength.GetValue() ); EDA_ANGLE difference = segment_angle - m_segmentAngle.GetAngleValue(); - + if( difference.AsRadians() < 0 ) difference = -difference; bool change_angle = - ( difference > EDA_ANGLE( 0.00001, TENTHS_OF_A_DEGREE_T ) ); + ( difference > EDA_ANGLE( 0.0005, DEGREES_T ) ); if( !( change_begin && change_end ) ) { segment_length = m_segmentLength.GetValue(); - segment_angle = m_segmentAngle.GetAngleValue(); + segment_angle = m_segmentAngle.GetAngleValue().Truncate( 3 ); if( change_length || change_angle ) { @@ -480,9 +481,9 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow() m_item->SetLength( m_item->GetLength() ); if( change_angle ) - m_item->SetAngle( m_segmentAngle.GetAngleValue() ); + m_item->SetAngle( m_segmentAngle.GetAngleValue().Truncate( 3 ) ); else - m_item->SetAngle( m_item->GetSegmentAngle() ); + m_item->SetAngle( m_item->GetSegmentAngle().Truncate( 3 ) ); } diff --git a/pcbnew/dialogs/dialog_graphic_item_properties_base.cpp b/pcbnew/dialogs/dialog_graphic_item_properties_base.cpp index a694430a04..418d44dfa9 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties_base.cpp +++ b/pcbnew/dialogs/dialog_graphic_item_properties_base.cpp @@ -157,6 +157,14 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( wxWind gbSizer2->Add( m_segmentAngleLabel, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 ); m_segmentAngleCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + #ifdef __WXGTK__ + if ( !m_segmentAngleCtrl->HasFlag( wxTE_MULTILINE ) ) + { + m_segmentAngleCtrl->SetMaxLength( 7 ); + } + #else + m_segmentAngleCtrl->SetMaxLength( 7 ); + #endif gbSizer2->Add( m_segmentAngleCtrl, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxEXPAND|wxTOP, 5 ); m_segmentAngleUnits = new wxStaticText( this, wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/pcbnew/dialogs/dialog_graphic_item_properties_base.fbp b/pcbnew/dialogs/dialog_graphic_item_properties_base.fbp index 7df9e9a87b..68befce936 100644 --- a/pcbnew/dialogs/dialog_graphic_item_properties_base.fbp +++ b/pcbnew/dialogs/dialog_graphic_item_properties_base.fbp @@ -2720,7 +2720,7 @@ 0 - 0 + 7 0