From d299ddbc7e27e1fdb8fb673092e8f2b4512685c7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 27 Feb 2022 11:54:03 +0000 Subject: [PATCH] Cleanup. --- common/base_units.cpp | 9 +++ common/eda_shape.cpp | 8 +-- include/base_units.h | 2 + pcbnew/tools/edit_tool.cpp | 116 ++++++++++++++++++------------------- 4 files changed, 72 insertions(+), 63 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 681564c9d1..275550fc44 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -115,6 +115,15 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAdd } +wxString MessageTextFromValue( EDA_ANGLE aValue, bool aAddUnitLabel ) +{ + if( aAddUnitLabel ) + return wxString::Format( wxT( "%.1f°" ), aValue.AsDegrees() ); + else + return wxString::Format( wxT( "%.1f" ), aValue.AsDegrees() ); +} + + // A lower-precision (for readability) version of StringFromValue() wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType ) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index 66c60095ee..dbc4e51895 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -557,7 +557,7 @@ void EDA_SHAPE::ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorType() != PCB_ARC_T ) return 0; - PCB_ARC* theArc = static_cast( selection.Front() ); - double arcAngleDegrees = std::abs( theArc->GetAngle().AsDegrees() ); + PCB_ARC* theArc = static_cast( selection.Front() ); + EDA_ANGLE maxTangentDeviation( ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation, DEGREES_T ); - if( arcAngleDegrees + ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation >= 180.0 ) + if( theArc->GetAngle() + maxTangentDeviation >= ANGLE_180 ) { - frame()->ShowInfoBarError( - wxString::Format( _( "Unable to resize arc tracks %.1f degrees or greater." ), - 180.0 - ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation ) ); + wxString msg = wxString::Format( _( "Unable to resize arc tracks of %s or greater." ), + MessageTextFromValue( ANGLE_180 - maxTangentDeviation ) ); + frame()->ShowInfoBarError( msg ); + return 0; // don't bother with > 180 degree arcs } @@ -367,55 +368,52 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent ) KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; auto getUniqueTrackAtAnchorCollinear = - [&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK* - { - auto conn = board()->GetConnectivity(); - - // Allow items at a distance within the width of the arc track - int allowedDeviation = theArc->GetWidth(); - - std::vector itemsOnAnchor; - - for( int i = 0; i < 3; i++ ) + [&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK* { - itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor, track_types, - allowedDeviation ); - allowedDeviation /= 2; + auto conn = board()->GetConnectivity(); - if( itemsOnAnchor.size() == 1 ) - break; - } + // Allow items at a distance within the width of the arc track + int allowedDeviation = theArc->GetWidth(); - PCB_TRACK* retval = nullptr; + std::vector itemsOnAnchor; - if( itemsOnAnchor.size() == 1 && itemsOnAnchor.front()->Type() == PCB_TRACE_T ) - { - retval = static_cast( itemsOnAnchor.front() ); - SEG trackSeg( retval->GetStart(), retval->GetEnd() ); - - // Allow deviations in colinearity as defined in ADVANCED_CFG - if( trackSeg.Angle( aCollinearSeg ) - > EDA_ANGLE( ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation, DEGREES_T ) ) + for( int i = 0; i < 3; i++ ) { - retval = nullptr; + itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor, track_types, + allowedDeviation ); + allowedDeviation /= 2; + + if( itemsOnAnchor.size() == 1 ) + break; } - } - if( !retval ) - { - retval = new PCB_TRACK( theArc->GetParent() ); - retval->SetStart( aAnchor ); - retval->SetEnd( aAnchor ); - retval->SetNet( theArc->GetNet() ); - retval->SetLayer( theArc->GetLayer() ); - retval->SetWidth( theArc->GetWidth() ); - retval->SetLocked( theArc->IsLocked() ); - retval->SetFlags( IS_NEW ); - getView()->Add( retval ); - } + PCB_TRACK* retval = nullptr; - return retval; - }; + if( itemsOnAnchor.size() == 1 && itemsOnAnchor.front()->Type() == PCB_TRACE_T ) + { + retval = static_cast( itemsOnAnchor.front() ); + SEG trackSeg( retval->GetStart(), retval->GetEnd() ); + + // Allow deviations in colinearity as defined in ADVANCED_CFG + if( trackSeg.Angle( aCollinearSeg ) > maxTangentDeviation ) + retval = nullptr; + } + + if( !retval ) + { + retval = new PCB_TRACK( theArc->GetParent() ); + retval->SetStart( aAnchor ); + retval->SetEnd( aAnchor ); + retval->SetNet( theArc->GetNet() ); + retval->SetLayer( theArc->GetLayer() ); + retval->SetWidth( theArc->GetWidth() ); + retval->SetLocked( theArc->IsLocked() ); + retval->SetFlags( IS_NEW ); + getView()->Add( retval ); + } + + return retval; + }; PCB_TRACK* trackOnStart = getUniqueTrackAtAnchorCollinear( theArc->GetStart(), tanStart); PCB_TRACK* trackOnEnd = getUniqueTrackAtAnchorCollinear( theArc->GetEnd(), tanEnd ); @@ -441,13 +439,13 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent ) tanIntersect = tanStart.IntersectLines( tanEnd ).get(); auto isTrackStartClosestToArcStart = - [&]( PCB_TRACK* aTrack ) -> bool - { - double trackStartToArcStart = GetLineLength( aTrack->GetStart(), theArc->GetStart() ); - double trackEndToArcStart = GetLineLength( aTrack->GetEnd(), theArc->GetStart() ); + [&]( PCB_TRACK* aTrack ) -> bool + { + double trackStartToArcStart = GetLineLength( aTrack->GetStart(), theArc->GetStart() ); + double trackEndToArcStart = GetLineLength( aTrack->GetEnd(), theArc->GetStart() ); - return trackStartToArcStart < trackEndToArcStart; - }; + return trackStartToArcStart < trackEndToArcStart; + }; bool isStartTrackOnStartPt = isTrackStartClosestToArcStart( trackOnStart ); bool isEndTrackOnStartPt = isTrackStartClosestToArcStart( trackOnEnd ); @@ -790,12 +788,12 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) } } - bool restore_state = false; - VECTOR2I originalPos; - VECTOR2I totalMovement; + bool restore_state = false; + VECTOR2I originalPos; + VECTOR2I totalMovement; PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); - TOOL_EVENT* evt = &aEvent; - VECTOR2I prevPos; + TOOL_EVENT* evt = &aEvent; + VECTOR2I prevPos; bool lock45 = false; bool eatFirstMouseUp = true; @@ -1151,7 +1149,7 @@ int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent ) } } - m_commit->Push( _("Edit track width/via size") ); + m_commit->Push( _( "Edit track width/via size" ) ); if( selection.IsHover() ) {