From 5ede4061e3e7f9415fbc7b818e345fd37729a0b7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 3 Nov 2020 22:45:26 +0000 Subject: [PATCH] Bug fixes and enhancements for dimensions. 1) Make them easier to select. 2) Mirror text when flipping to other side of board. 3) Flip around a more "known" point (the text position isn't really here nor there). Fixes https://gitlab.com/kicad/code/kicad/issues/6219 --- pcbnew/class_dimension.cpp | 15 ++------------- pcbnew/class_dimension.h | 5 ++--- pcbnew/collectors.cpp | 28 +++++++++++++++++++++++++--- pcbnew/tools/edit_tool.cpp | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index c4d85a085f..61bf022122 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -65,18 +65,6 @@ void DIMENSION::SetParent( EDA_ITEM* aParent ) } -void DIMENSION::SetPosition( const wxPoint& aPos ) -{ - m_text.SetTextPos( aPos ); -} - - -wxPoint DIMENSION::GetPosition() const -{ - return m_text.GetTextPos(); -} - - void DIMENSION::updateText() { wxString text = m_overrideTextEnabled ? m_valueString : GetValueText(); @@ -271,7 +259,6 @@ void DIMENSION::Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight ) wxPoint newPos = m_text.GetTextPos(); #define INVERT( pos ) ( ( pos ) = axis - ( ( pos ) - axis ) ) - if( aMirrorLeftRight ) INVERT( newPos.x ); else @@ -293,6 +280,8 @@ void DIMENSION::Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight ) INVERT( m_end.y ); } + m_text.SetMirrored( !m_text.IsMirrored() ); + Update(); } diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index 1a9838d689..99de756ce5 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -129,9 +129,8 @@ public: virtual const wxPoint& GetEnd() const { return m_end; } virtual void SetEnd( const wxPoint& aPoint ); - // These deal with the text position - wxPoint GetPosition() const override; - void SetPosition( const wxPoint& aPos ) override; + wxPoint GetPosition() const override { return m_start; } + void SetPosition( const wxPoint& aPos ) override { m_start = aPos; } bool GetOverrideTextEnabled() const { return m_overrideTextEnabled; } void SetOverrideTextEnabled( bool aOverride ) { m_overrideTextEnabled = aOverride; } diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index 14c7df49e9..fdecda4c7b 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -30,13 +30,13 @@ #include #include #include +#include #include #include #include #include #include // for KiROUND - /* This module contains out of line member functions for classes given in * collectors.h. Those classes augment the functionality of class PCB_EDIT_FRAME. */ @@ -196,6 +196,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) MARKER_PCB* marker = nullptr; ZONE_CONTAINER* zone = nullptr; PCB_SHAPE* shape = nullptr; + DIMENSION* dimension = nullptr; #if 0 // debugging static int breakhere = 0; @@ -324,6 +325,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) case PCB_DIM_CENTER_T: case PCB_DIM_ORTHOGONAL_T: case PCB_DIM_LEADER_T: + dimension = static_cast( item ); break; case PCB_TARGET_T: @@ -493,7 +495,17 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { if( shape->HitTest( m_refPos, accuracy ) ) { - Append( item ); + Append( shape ); + goto exit; + } + } + else if( dimension ) + { + // Dimensions feels particularly hard to select, probably due to their + // noisy shape making it feel like they should have a larger bounary. + if( dimension->HitTest( m_refPos, KiROUND( accuracy * 1.5 ) ) ) + { + Append( dimension ); goto exit; } } @@ -557,7 +569,17 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { if( shape->HitTest( m_refPos, accuracy ) ) { - Append( item ); + Append( shape ); + goto exit; + } + } + else if( dimension ) + { + // Dimensions feels particularly hard to select, probably due to their + // noisy shape making it feel like they should have a larger bounary. + if( dimension->HitTest( m_refPos, KiROUND( accuracy * 1.5 ) ) ) + { + Append( dimension ); goto exit; } } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 86feb53f6b..d01d0882fa 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1162,7 +1162,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) // of the bounding box center) to avoid moving the item anchor if( selection.GetSize() == 1 ) { - if( selection.HasReferencePoint() ) + if( m_dragging && selection.HasReferencePoint() ) modPoint = selection.GetReferencePoint(); else modPoint = static_cast( selection.GetItem( 0 ) )->GetPosition();