diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 3ad5a12f23..55435c9993 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -268,7 +268,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) if( m_dragging || selection.Empty() ) return 0; - LSET item_layers = static_cast( selection.Front() )->GetLayerSet(); + LSET item_layers = selection.GetSelectionLayers(); bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need @@ -408,18 +408,18 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) selection.SetReferencePoint( m_cursor ); } - else if( selection.Size() == 1 ) - { - // Set the current cursor position to the first dragged item origin, so the - // movement vector could be computed later - updateModificationPoint( selection ); - m_cursor = grid.BestDragOrigin( originalCursorPos, curr_item ); - grid.SetAuxAxes( true, m_cursor ); - } else { - updateModificationPoint( selection ); - m_cursor = grid.Align( m_cursor ); + std::vector items; + + for( auto item : selection.Items() ) + items.push_back( static_cast( item ) ); + + // Set the current cursor position to the first dragged item origin, so the + // movement vector could be computed later + m_cursor = grid.BestDragOrigin( originalCursorPos, items ); + selection.SetReferencePoint( m_cursor ); + grid.SetAuxAxes( true, m_cursor ); } controls->SetCursorPosition( m_cursor, false ); diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index 8d139e46c5..152aea7673 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -167,10 +167,12 @@ VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg ) } -VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, BOARD_ITEM* aItem ) +VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector& aItems ) { clearAnchors(); - computeAnchors( aItem, aMousePos, true ); + + for( auto item : aItems ) + computeAnchors( item, aMousePos, true ); double worldScale = m_frame->GetCanvas()->GetGAL()->GetWorldScale(); double lineSnapMinCornerDistance = 50.0 / worldScale; @@ -211,7 +213,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, BOARD_ITEM* aIt std::set GRID_HELPER::queryVisible( const BOX2I& aArea, - const std::vector aSkip ) const + const std::vector& aSkip ) const { std::set items; std::vector selectedItems; @@ -256,7 +258,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDrag VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, - const std::vector aSkip ) + const std::vector& aSkip ) { double worldScale = m_frame->GetCanvas()->GetGAL()->GetWorldScale(); int snapRange = (int) ( m_snapSize / worldScale ); diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h index e36b85bf81..8510198976 100644 --- a/pcbnew/tools/grid_helper.h +++ b/pcbnew/tools/grid_helper.h @@ -58,10 +58,10 @@ public: VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg ); - VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem ); + VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector& aItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, - const std::vector aSkip = {} ); + const std::vector& aSkip = {} ); void SetSnap( bool aSnap ) { @@ -102,7 +102,7 @@ private: std::vector m_anchors; std::set queryVisible( const BOX2I& aArea, - const std::vector aSkip ) const; + const std::vector& aSkip ) const; void addAnchor( const VECTOR2I& aPos, int aFlags, BOARD_ITEM* aItem ) { diff --git a/pcbnew/tools/pcbnew_selection.cpp b/pcbnew/tools/pcbnew_selection.cpp index 9b0b36b557..21aa14a571 100644 --- a/pcbnew/tools/pcbnew_selection.cpp +++ b/pcbnew/tools/pcbnew_selection.cpp @@ -108,3 +108,19 @@ const KIGFX::VIEW_GROUP::ITEMS PCBNEW_SELECTION::updateDrawList() const return items; } + + +const LSET PCBNEW_SELECTION::GetSelectionLayers() +{ + LSET retval; + + for( auto item : m_items ) + { + auto board_item = dynamic_cast( item ); + + if( board_item ) + retval |= board_item->GetLayerSet(); + } + + return retval; +} diff --git a/pcbnew/tools/pcbnew_selection.h b/pcbnew/tools/pcbnew_selection.h index c8b7059aee..b5d8b32353 100644 --- a/pcbnew/tools/pcbnew_selection.h +++ b/pcbnew/tools/pcbnew_selection.h @@ -24,6 +24,7 @@ #ifndef PCBNEW_SELECTION_H #define PCBNEW_SELECTION_H +#include #include @@ -33,6 +34,8 @@ public: EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const override; const KIGFX::VIEW_GROUP::ITEMS updateDrawList() const override; + + const LSET GetSelectionLayers(); }; -#endif // PCBNEW_SELECTION_H \ No newline at end of file +#endif // PCBNEW_SELECTION_H