diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index 6af6a66e79..5001147a1c 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -175,23 +175,19 @@ BITMAP_DEF SCH_MARKER::GetMenuImage() const void SCH_MARKER::Rotate( wxPoint aPosition ) { - RotatePoint( &m_Pos, aPosition, 900 ); + // Marker geometry isn't user-editable } void SCH_MARKER::MirrorX( int aXaxis_position ) { - m_Pos.y -= aXaxis_position; - m_Pos.y = -m_Pos.y; - m_Pos.y += aXaxis_position; + // Marker geometry isn't user-editable } void SCH_MARKER::MirrorY( int aYaxis_position ) { - m_Pos.x -= aYaxis_position; - m_Pos.x = -m_Pos.x; - m_Pos.x += aYaxis_position; + // Marker geometry isn't user-editable } diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 5a1e5a4975..177c21dadf 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -131,6 +131,18 @@ PAD& PAD::operator=( const PAD &aOther ) } +bool PAD::IsLocked() const +{ + if( GetParent() ) + { + FOOTPRINT* fp = static_cast( GetParent() ); + return fp->IsLocked() || fp->PadsLocked(); + } + + return false; +}; + + LSET PAD::PTHMask() { static LSET saved = LSET::AllCuMask() | LSET( 2, F_Mask, B_Mask ); diff --git a/pcbnew/pad.h b/pcbnew/pad.h index bd8eb64d85..9fc3ddcdb7 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -105,6 +105,8 @@ public: FOOTPRINT* GetParent() const; + bool IsLocked() const override; + /** * Imports the pad settings from aMasterPad. * The result is "this" has the same settinds (sizes, shapes ... ) diff --git a/pcbnew/pcb_marker.cpp b/pcbnew/pcb_marker.cpp index 988b52686e..a852c39b16 100644 --- a/pcbnew/pcb_marker.cpp +++ b/pcbnew/pcb_marker.cpp @@ -114,18 +114,15 @@ void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorIsLocked() ) - { - KIDIALOG dlg( frame(), _( "The selected item is locked." ), _( "Confirmation" ), - wxOK | wxCANCEL | wxICON_WARNING ); - dlg.SetOKLabel( _( "Drag Anyway" ) ); - dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); - - if( dlg.ShowModal() == wxID_CANCEL ) - return 0; - } - GAL* gal = m_toolMgr->GetView()->GetGAL(); VECTOR2I p0 = controls()->GetCursorPosition( false ); VECTOR2I p = p0; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b37cdedae8..aa71a6eeb7 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -65,62 +64,6 @@ using namespace std::placeholders; #include -void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags, - SELECTION_TOOL* selectionTool ) -{ - // Iterate from the back so we don't have to worry about removals. - for( int i = aCollector.GetCount() - 1; i >= 0; --i ) - { - BOARD_ITEM* item = aCollector[ i ]; - - if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() ) - { - aCollector.Remove( item ); - } - else if( item->Type() == PCB_FP_ZONE_T ) - { - FOOTPRINT* fp = static_cast( item->GetParent() ); - - // case 1: handle locking - if( ( aFlags & EXCLUDE_LOCKED ) && fp && fp->IsLocked() ) - aCollector.Remove( item ); - - // case 2: selection contains both the footprint and its pads - remove the pads - if( !( aFlags & INCLUDE_PADS_AND_FOOTPRINTS ) && fp && aCollector.HasItem( fp ) ) - aCollector.Remove( item ); - } - else if( item->Type() == PCB_PAD_T ) - { - FOOTPRINT* fp = static_cast( item->GetParent() ); - - // case 1: handle locking - if( ( aFlags & EXCLUDE_LOCKED ) && fp && fp->IsLocked() ) - { - aCollector.Remove( item ); - } - else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && fp && fp->PadsLocked() ) - { - // Pad locking is considerably "softer" than item locking - aCollector.Remove( item ); - - if( !fp->IsLocked() && !aCollector.HasItem( fp ) ) - aCollector.Append( fp ); - } - - // case 2: selection contains both the footprint and its pads - remove the pads - if( !( aFlags & INCLUDE_PADS_AND_FOOTPRINTS ) && fp && aCollector.HasItem( fp ) ) - aCollector.Remove( item ); - } - else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T ) - { - aCollector.Remove( item ); - } - } - - selectionTool->FilterCollectorForGroups( aCollector ); -} - - EDIT_TOOL::EDIT_TOOL() : PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), @@ -302,7 +245,22 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[ i ]; + + // We don't operate on pads; convert them to footprint selections + if( item->Type() == PCB_PAD_T ) + { + aCollector.Remove( item ); + + if( item->GetParent() && !aCollector.HasItem( item->GetParent() ) ) + aCollector.Append( item->GetParent() ); + } + } + + sTool->FilterCollectorForGroups( aCollector ); }, true /* prompt user regarding locked items */ ); @@ -352,22 +310,37 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[ i ]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } } ); if( m_dragging || selection.Empty() ) return 0; LSET item_layers = selection.GetSelectionLayers(); - bool unselect = selection.IsHover(); // N.B. This must be saved before the re-selection below + bool unselect = selection.IsHover(); // N.B. This must be saved before the re-selection + // below VECTOR2I pickedReferencePoint; - // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need - // the item_layers when a pad is the selection front. + // Now filter out locked and grouped items. We cannot do this in the first RequestSelection() + // as we need the item_layers when a pad is the selection front. selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[ i ]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -657,7 +630,14 @@ int EDIT_TOOL::ChangeTrackWidth( const TOOL_EVENT& aEvent ) const auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[ i ]; + + if( !dynamic_cast( item ) ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -723,15 +703,20 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent ) auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( !dynamic_cast( item ) ) + aCollector.Remove( item ); + } }, !m_dragging /* prompt user regarding locked items */ ); if( selection.Size() < 2 ) { - frame()->ShowInfoBarMsg( - _( "A minimum of two straight track segments must be selected." ) ); + frame()->ShowInfoBarMsg( _( "At least two straight track segments must be selected." ) ); return 0; } @@ -804,8 +789,8 @@ int EDIT_TOOL::FilletTracks( const TOOL_EVENT& aEvent ) } else { - // User requested to fillet these two tracks but not possible as there are other - // elements connected at that point + // User requested to fillet these two tracks but not possible as + // there are other elements connected at that point didOneAttemptFail = true; } } @@ -919,7 +904,6 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) const PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); } ); // Tracks & vias are treated in a special way: @@ -973,8 +957,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); }, !m_dragging /* prompt user regarding locked items */ ); @@ -989,7 +971,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) if( IsFootprintEditor() ) m_commit->Modify( selection.Front() ); - for( auto item : selection ) + for( EDA_ITEM* item : selection ) { if( !item->IsNew() && !IsFootprintEditor() ) { @@ -1075,8 +1057,6 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); }, !m_dragging /* prompt user regarding locked items */ ); @@ -1174,8 +1154,22 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + // We don't operate on pads; convert them to footprint selections + if( item->Type() == PCB_PAD_T ) + { + aCollector.Remove( item ); + + if( item->GetParent() && !aCollector.HasItem( item->GetParent() ) ) + aCollector.Append( item->GetParent() ); + } + } + + sTool->FilterCollectorForGroups( aCollector ); }, !m_dragging /* prompt user regarding locked items */ ); @@ -1262,8 +1256,6 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) selectionCopy = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); }, true /* prompt user regarding locked items */ ); } @@ -1446,8 +1438,14 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) const auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -1544,12 +1542,31 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement ); // Be sure that there is at least one item that we can modify - const auto& selection = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) - { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); - } ); + const auto& selection = + m_isFootprintEditor ? m_selectionTool->RequestSelection( + []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) + { + } ) + /*is board editor*/ : m_selectionTool->RequestSelection( + []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) + { + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; i-- ) + { + BOARD_ITEM* item = static_cast( aCollector[i] ); + + // Promote pad selections to footprint selections + if( item->Type() == PCB_PAD_T ) + { + aCollector.Remove( item ); + + if( item->GetParent() && !aCollector.HasItem( item->GetParent() ) ) + aCollector.Append( item->GetParent() ); + } + } + + sTool->FilterCollectorForGroups( aCollector ); + } ); if( selection.Empty() ) return 0; @@ -1677,12 +1694,31 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) return 0; } - const auto& selection = m_selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) - { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); - } ); + const auto& selection = + m_isFootprintEditor ? m_selectionTool->RequestSelection( + []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) + { + } ) + /*is board editor*/ : m_selectionTool->RequestSelection( + []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) + { + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; i-- ) + { + BOARD_ITEM* item = static_cast( aCollector[i] ); + + // Promote pad selections to footprint selections + if( item->Type() == PCB_PAD_T ) + { + aCollector.Remove( item ); + + if( item->GetParent() && !aCollector.HasItem( item->GetParent() ) ) + aCollector.Append( item->GetParent() ); + } + } + + sTool->FilterCollectorForGroups( aCollector ); + } ); if( selection.Empty() ) return 0; @@ -1834,9 +1870,8 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, - sTool ); - } ); + }, + aEvent.IsAction( &ACTIONS::cut ) /* prompt user regarding locked items */ ); if( !selection.Empty() ) { diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 27bd1e40a1..8064a37ef9 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -1,7 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013-2015 CERN + * Copyright (C) 2013-2020 CERN + * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * @author Tomasz Wlostowski * @@ -37,26 +38,14 @@ class BOARD_ITEM; class CONNECTIVITY_DATA; class STATUS_TEXT_POPUP; -namespace KIGFX { - namespace PREVIEW { +namespace KIGFX +{ + namespace PREVIEW + { class RULER_ITEM; } } -/** - * Function EditToolSelectionFilter - * - * A CLIENT_SELECTION_FILTER which promotes pad selections to their parent footprints and - * optionally excludes locked items and/or transient items (such as markers). - */ - -#define EXCLUDE_LOCKED 0x0001 -#define EXCLUDE_LOCKED_PADS 0x0002 -#define EXCLUDE_TRANSIENTS 0x0004 -#define INCLUDE_PADS_AND_FOOTPRINTS 0x0008 - -void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags, SELECTION_TOOL* sTool ); - class SPECIAL_TOOLS_CONTEXT_MENU : public CONDITIONAL_MENU { @@ -64,11 +53,11 @@ public: SPECIAL_TOOLS_CONTEXT_MENU( TOOL_INTERACTIVE* aTool ); }; - /** +/** * EDIT_TOOL * - * The interactive edit tool. Allows one to move, rotate, flip and change properties of items selected - * using the pcbnew.InteractiveSelection tool. + * The interactive edit tool. Allows one to move, rotate, flip and change properties of items s + * elected using the pcbnew.InteractiveSelection tool. */ class EDIT_TOOL : public PCB_TOOL_BASE @@ -162,7 +151,8 @@ public: * Function FootprintFilter() * A selection filter which prunes the selection to contain only items of type PCB_MODULE_T */ - static void FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ); + static void FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, + SELECTION_TOOL* sTool ); /** * Function PadFilter() @@ -170,6 +160,9 @@ public: */ static void PadFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ); + BOARD_COMMIT* GetCurrentCommit() const { return m_commit.get(); } + +private: ///> Sets up handlers for various events. void setTransitions() override; @@ -187,9 +180,6 @@ public: */ int cutToClipboard( const TOOL_EVENT& aEvent ); - BOARD_COMMIT* GetCurrentCommit() const { return m_commit.get(); } - -private: ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. bool updateModificationPoint( PCBNEW_SELECTION& aSelection ); @@ -204,15 +194,12 @@ private: const wxString& aCanceledMessage, VECTOR2I& aReferencePoint ); private: - SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items - - bool m_dragging; // Indicates objects are being dragged right now - VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() - // to avoid changes of edit reference point). - - std::unique_ptr m_commit; - - std::unique_ptr m_statusPopup; + SELECTION_TOOL* m_selectionTool; + std::unique_ptr m_commit; + bool m_dragging; // Indicates objects are currently being dragged + VECTOR2I m_cursor; // Last cursor position (so getModificationPoint() + // can avoid changes of edit reference point). + std::unique_ptr m_statusPopup; }; #endif diff --git a/pcbnew/tools/global_edit_tool.cpp b/pcbnew/tools/global_edit_tool.cpp index 9865cce44c..f43bfd348b 100644 --- a/pcbnew/tools/global_edit_tool.cpp +++ b/pcbnew/tools/global_edit_tool.cpp @@ -202,7 +202,7 @@ int GLOBAL_EDIT_TOOL::RemoveUnusedPads( const TOOL_EVENT& aEvent ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + sTool->FilterCollectorForGroups( aCollector ); } ); DIALOG_UNUSED_PAD_LAYERS dlg( editFrame, selection, *m_commit ); diff --git a/pcbnew/tools/group_tool.cpp b/pcbnew/tools/group_tool.cpp index 45296b3b57..8acc7d7118 100644 --- a/pcbnew/tools/group_tool.cpp +++ b/pcbnew/tools/group_tool.cpp @@ -287,7 +287,6 @@ int GROUP_TOOL::PickNewMember( const TOOL_EVENT& aEvent ) const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); } ); if( sel.Empty() ) diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index a59766d629..f43977ed42 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -145,7 +145,14 @@ size_t ALIGN_DISTRIBUTE_TOOL::GetSelections( ALIGNMENT_RECTS& aItems, ALIGNMENT_ PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } } ); std::vector lockedItems; @@ -161,7 +168,14 @@ size_t ALIGN_DISTRIBUTE_TOOL::GetSelections( ALIGNMENT_RECTS& aItems, ALIGNMENT_ selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -455,7 +469,14 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -567,7 +588,14 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index 5fed5caa5f..7cebd28e63 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -69,7 +69,14 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) const auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool ); + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( item->Type() == PCB_MARKER_T ) + aCollector.Remove( item ); + } }, true /* prompt user regarding locked items */ ); @@ -145,9 +152,6 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { - EditToolSelectionFilter( aCollector, - EXCLUDE_TRANSIENTS | INCLUDE_PADS_AND_FOOTPRINTS, - sTool ); } ); if( sel.Empty() ) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 784c8373a7..97f98a410c 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -473,43 +473,6 @@ PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aCli m_selection.ClearReferencePoint(); } - if( aConfirmLockedItems ) - { - std::vector lockedItems; - - for( EDA_ITEM* item : m_selection ) - { - BOARD_ITEM* boardItem = static_cast( item ); - - if( boardItem->IsLocked() ) - lockedItems.push_back( boardItem ); - } - - if( !lockedItems.empty() ) - { - DIALOG_LOCKED_ITEMS_QUERY dlg( frame(), lockedItems.size() ); - - switch( dlg.ShowModal() ) - { - case wxID_OK: - // remove locked items from selection - for( BOARD_ITEM* item : lockedItems ) - unselect( item ); - - break; - - case wxID_CANCEL: - // cancel operation - ClearSelection(); - break; - - case wxID_APPLY: - // continue with operation with current selection - break; - } - } - } - if( aClientFilter ) { enum DISPOSITION { BEFORE = 1, AFTER, BOTH }; @@ -567,6 +530,43 @@ PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aCli m_frame->GetCanvas()->ForceRefresh(); } + if( aConfirmLockedItems ) + { + std::vector lockedItems; + + for( EDA_ITEM* item : m_selection ) + { + BOARD_ITEM* boardItem = static_cast( item ); + + if( boardItem->IsLocked() ) + lockedItems.push_back( boardItem ); + } + + if( !lockedItems.empty() ) + { + DIALOG_LOCKED_ITEMS_QUERY dlg( frame(), lockedItems.size() ); + + switch( dlg.ShowModal() ) + { + case wxID_OK: + // remove locked items from selection + for( BOARD_ITEM* item : lockedItems ) + unselect( item ); + + break; + + case wxID_CANCEL: + // cancel operation + ClearSelection(); + break; + + case wxID_APPLY: + // continue with operation with current selection + break; + } + } + } + return m_selection; } @@ -627,8 +627,8 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, m_selection.ClearReferencePoint(); - // Allow the client to do tool- or action-specific filtering to see if we - // can get down to a single item + // Allow the client to do tool- or action-specific filtering to see if we can get down + // to a single item if( aClientFilter ) aClientFilter( aWhere, collector, this ); @@ -639,9 +639,7 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, // Apply some ugly heuristics to avoid disambiguation menus whenever possible if( collector.GetCount() > 1 && !m_skip_heuristics ) - { GuessSelectionCandidates( collector, aWhere ); - } // If still more than one item we're going to have to ask the user. if( collector.GetCount() > 1 )