diff --git a/pcbnew/dialogs/dialog_position_relative.cpp b/pcbnew/dialogs/dialog_position_relative.cpp index 719e1c1979..9534f85daf 100644 --- a/pcbnew/dialogs/dialog_position_relative.cpp +++ b/pcbnew/dialogs/dialog_position_relative.cpp @@ -156,12 +156,16 @@ void DIALOG_POSITION_RELATIVE::updateDialogControls( bool aPolar ) m_xOffset.SetLabel( _( "Distance:" ) ); // Polar radius m_yOffset.SetLabel( _( "Angle:" ) ); // Polar theta or angle m_yOffset.SetUnits( EDA_UNITS::DEGREES ); + m_clearX->SetToolTip( _( "Reset to the current distance from the reference position." ) ); + m_clearY->SetToolTip( _( "Reset to the current angle from the reference position." ) ); } else { m_xOffset.SetLabel( _( "Offset X:" ) ); m_yOffset.SetLabel( _( "Offset Y:" ) ); m_yOffset.SetUnits( GetUserUnits() ); + m_clearX->SetToolTip( _( "Reset to the current X offset from the reference position." ) ); + m_clearY->SetToolTip( _( "Reset to the current Y offset from the reference position." ) ); } } @@ -169,14 +173,43 @@ void DIALOG_POSITION_RELATIVE::updateDialogControls( bool aPolar ) void DIALOG_POSITION_RELATIVE::OnClear( wxCommandEvent& event ) { wxObject* obj = event.GetEventObject(); + POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool(); + wxASSERT( posrelTool ); + + wxPoint offset = posrelTool->GetSelectionAnchorPosition() - m_anchor_position; + double r, q; + ToPolarDeg( offset.x, offset.y, r, q ); + if( obj == m_clearX ) { - m_xOffset.SetValue( 0 ); + m_stateX = offset.x; + m_xOffset.SetDoubleValue( r ); + m_stateRadius = m_xOffset.GetDoubleValue(); + + if( m_polarCoords->IsChecked() ) + { + m_xOffset.SetDoubleValue( m_stateRadius ); + } + else + { + m_xOffset.SetValue( m_stateX ); + } } else if( obj == m_clearY ) { - m_yOffset.SetValue( 0 ); + m_stateY = offset.y; + m_yOffset.SetDoubleValue( q * 10 ); + m_stateTheta = m_yOffset.GetDoubleValue(); + + if( m_polarCoords->IsChecked() ) + { + m_yOffset.SetDoubleValue( m_stateTheta ); + } + else + { + m_yOffset.SetValue( m_stateY ); + } } } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 387941a283..046c2a0ebb 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -87,7 +87,7 @@ void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags ) } // case 2: selection contains both the module and its pads - remove the pads - if( mod && aCollector.HasItem( mod ) ) + if( !( aFlags & INCLUDE_PADS_AND_MODULES ) && mod && aCollector.HasItem( mod ) ) aCollector.Remove( item ); } else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T ) diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index bb965efca5..a60bf7f40d 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -50,9 +50,10 @@ namespace KIGFX { * optionally excludes locked items and/or transient items (such as markers). */ -#define EXCLUDE_LOCKED 0x0001 +#define EXCLUDE_LOCKED 0x0001 #define EXCLUDE_LOCKED_PADS 0x0002 -#define EXCLUDE_TRANSIENTS 0x0004 +#define EXCLUDE_TRANSIENTS 0x0004 +#define INCLUDE_PADS_AND_MODULES 0x0008 void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags ); diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index 2d84ed0216..34639ef41b 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -92,21 +92,15 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) return 0; } +wxPoint POSITION_RELATIVE_TOOL::GetSelectionAnchorPosition() const +{ + return static_cast( m_selection.GetTopLeftItem() )->GetPosition(); +} + int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint aPosAnchor, wxPoint aTranslation ) { - wxPoint aSelAnchor( INT_MAX, INT_MAX ); - - // Find top-left item anchor in selection - for( auto item : m_selection ) - { - wxPoint itemAnchor = static_cast( item )->GetPosition(); - - if( EuclideanNorm( itemAnchor ) < EuclideanNorm( aSelAnchor ) ) - aSelAnchor = itemAnchor; - } - - wxPoint aggregateTranslation = aPosAnchor + aTranslation - aSelAnchor; + wxPoint aggregateTranslation = aPosAnchor + aTranslation - GetSelectionAnchorPosition(); for( auto item : m_selection ) { @@ -146,10 +140,10 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) - { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); - } ); + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { + EditToolSelectionFilter( + aCollector, EXCLUDE_TRANSIENTS | INCLUDE_PADS_AND_MODULES ); + } ); if( sel.Empty() ) return true; // still looking for an item diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h index 04ca200546..3b60686a09 100644 --- a/pcbnew/tools/position_relative_tool.h +++ b/pcbnew/tools/position_relative_tool.h @@ -67,6 +67,14 @@ public: */ int SelectPositionRelativeItem( const TOOL_EVENT& aEvent ); + /** + * Function GetSelectionAnchorPosition() + * + * Returns the postion of the selected item(s) + * + */ + wxPoint GetSelectionAnchorPosition() const; + /** * Function RelativeItemSelectionMove() *