KiCad PCB EDA Suite
PCB_SELECTION_TOOL Class Reference

The selection tool: currently supports: More...

#include <pcb_selection_tool.h>

Inheritance diagram for PCB_SELECTION_TOOL:
SELECTION_TOOL TOOL_INTERACTIVE TOOL_BASE

Classes

class  PRIV
 Private implementation of firewalled private data. More...
 

Public Types

enum  RESET_REASON { RUN , MODEL_RELOAD , GAL_SWITCH }
 Determine the reason of reset for a tool. More...
 

Public Member Functions

 PCB_SELECTION_TOOL ()
 
 ~PCB_SELECTION_TOOL ()
 
bool Init () override
 Init() is called once upon a registration of the tool. More...
 
void Reset (RESET_REASON aReason) override
 Bring the tool to a known, initial state. More...
 
void OnIdle (wxIdleEvent &aEvent)
 
bool IsFootprintEditor ()
 
int Main (const TOOL_EVENT &aEvent)
 The main loop. More...
 
PCB_SELECTIONGetSelection ()
 
PCB_SELECTIONRequestSelection (CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
 Return the current selection, filtered according to aClientFilter. More...
 
int CursorSelection (const TOOL_EVENT &aEvent)
 Clear current selection event handler. More...
 
int ClearSelection (const TOOL_EVENT &aEvent)
 
void ClearSelection (bool aQuietMode=false)
 Select all items on the board. More...
 
int SelectAll (const TOOL_EVENT &aEvent)
 
void FindItem (BOARD_ITEM *aItem)
 Take necessary actions to mark an item as found. More...
 
void select (EDA_ITEM *aItem) override
 Take necessary action mark an item as selected. More...
 
bool Selectable (const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
 
void SelectAllItemsOnNet (int aNetCode, bool aSelect=true)
 Select all items with the given net code. More...
 
void GuessSelectionCandidates (GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
 Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead heuristics. More...
 
void RebuildSelection ()
 Rebuild the selection from the EDA_ITEMs' selection flags. More...
 
SELECTION_FILTER_OPTIONSGetFilter ()
 Set up handlers for various events. More...
 
void setTransitions () override
 Zoom the screen to center and fit the current selection. More...
 
void zoomFitSelection ()
 Zoom the screen to fit the bounding box for cross probing/selection sync. More...
 
void ZoomFitCrossProbeBBox (const BOX2I &bbox)
 
void EnterGroup ()
 Enter the group at the head of the current selection. More...
 
void ExitGroup (bool aSelectGroup=false)
 Leave the currently-entered group. More...
 
PCB_GROUPGetEnteredGroup ()
 
PCB_LAYER_ID GetActiveLayer ()
 
void FilterCollectorForHierarchy (GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
 In general we don't want to select both a parent and any of it's children. More...
 
void FilterCollectorForFreePads (GENERAL_COLLECTOR &aCollector) const
 Check the "allow free pads" setting and if disabled, replace any pads in the collector with their parent footprints. More...
 
void FilterCollectorForMarkers (GENERAL_COLLECTOR &aCollector) const
 Drop any PCB_MARKERs from the collector. More...
 
void FilterCollectedItems (GENERAL_COLLECTOR &aCollector, bool aMultiSelect)
 Apply the SELECTION_FITLER_OPTIONS to the collector. More...
 
int UpdateMenu (const TOOL_EVENT &aEvent)
 Update a menu's state based on the current selection. More...
 
int AddItemToSel (const TOOL_EVENT &aEvent)
 
void AddItemToSel (EDA_ITEM *aItem, bool aQuietMode=false)
 
int AddItemsToSel (const TOOL_EVENT &aEvent)
 
void AddItemsToSel (EDA_ITEMS *aList, bool aQuietMode=false)
 
int RemoveItemFromSel (const TOOL_EVENT &aEvent)
 
void RemoveItemFromSel (EDA_ITEM *aItem, bool aQuietMode=false)
 
int RemoveItemsFromSel (const TOOL_EVENT &aEvent)
 
void RemoveItemsFromSel (EDA_ITEMS *aList, bool aQuietMode=false)
 
void RemoveItemsFromSel (std::vector< KIID > *aList, bool aQuietMode=false)
 A safer version of RemoveItemsFromSel( EDA_ITEMS ) which doesn't require the items to still exist. More...
 
void BrightenItem (EDA_ITEM *aItem)
 
void UnbrightenItem (EDA_ITEM *aItem)
 
int SelectionMenu (const TOOL_EVENT &aEvent)
 Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item. More...
 
void Activate ()
 Run the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Assign a context menu and tells when it should be activated. More...
 
void RunMainStack (std::function< void()> aFunc)
 Call a function using the main stack. More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Define which state (aStateFunc) to go when a certain event arrives (aConditions). More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Suspend execution of the tool until an event specified in aEventList arrives. More...
 
TOOL_TYPE GetType () const
 Return the type of the tool. More...
 
TOOL_ID GetId () const
 Return the unique identifier of the tool. More...
 
const std::string & GetName () const
 Return the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Return the instance of TOOL_MANAGER that takes care of the tool. More...
 
bool IsToolActive () const
 

Protected Member Functions

KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
virtual bool ctrlClickHighlights () override
 Determines if ctrl-click is highlight net or XOR selection. More...
 
SELECTIONselection () override
 Return a reference to the selection. More...
 
void onDisambiguationExpire (wxTimerEvent &aEvent)
 Start the process to show our disambiguation menu once the user has kept the mouse down for the minimum time. More...
 
void setModifiersState (bool aShiftState, bool aCtrlState, bool aAltState)
 Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state of modifier keys SHIFT, CTRL, ALT and depending on the OS. More...
 
bool doSelectionMenu (COLLECTOR *aCollector)
 
void attachManager (TOOL_MANAGER *aManager)
 Set the TOOL_MANAGER the tool will belong to. More...
 
KIGFX::VIEWgetView () const
 Returns the instance of #VIEW object used in the application. More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Return the instance of VIEW_CONTROLS object used in the application. More...
 
template<typename T >
T * getEditFrame () const
 Return the application window object, casted to requested user type. More...
 
template<typename T >
T * getModel () const
 Return the model object if it matches the requested type. More...
 

Protected Attributes

bool m_additive
 
bool m_subtractive
 
bool m_exclusive_or
 
bool m_multiple
 
bool m_skip_heuristics
 
bool m_highlight_modifier
 
bool m_drag_additive
 
bool m_drag_subtractive
 
bool m_canceledMenu
 
wxTimer m_disambiguateTimer
 
VECTOR2I m_originalCursor
 
TOOL_MENU m_menu
 The functions below are not yet implemented - their interface may change. More...
 
TOOL_TYPE m_type
 Unique identifier for the tool, assigned by a TOOL_MANAGER instance. More...
 
TOOL_ID m_toolId
 Name of the tool. More...
 
std::string m_toolName
 
TOOL_MANAGERm_toolMgr
 

Private Types

enum  STOP_CONDITION { STOP_AT_JUNCTION , STOP_AT_PAD , STOP_NEVER }
 

Private Member Functions

bool selectPoint (const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=nullptr, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
 Select an item pointed by the parameter aWhere. More...
 
bool selectCursor (bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
 Select an item under the cursor unless there is something already selected. More...
 
bool selectMultiple ()
 Handle drawing a selection box that allows one to select many items at the same time. More...
 
int disambiguateCursor (const TOOL_EVENT &aEvent)
 Handle disambiguation actions including displaying the menu. More...
 
int expandConnection (const TOOL_EVENT &aEvent)
 Expand the current connected-item selection to the next boundary (junctions, pads, or all) More...
 
int unrouteSelected (const TOOL_EVENT &aEvent)
 Unroute the selected board connected items. More...
 
int selectNet (const TOOL_EVENT &aEvent)
 Select all copper connections belonging to the same net(s) as the items in the selection. More...
 
int selectUnconnected (const TOOL_EVENT &aEvent)
 Select nearest unconnected footprints on same net as selected items. More...
 
int grabUnconnected (const TOOL_EVENT &aEvent)
 Select and move other nearest footprint unconnected on same net as selected items. More...
 
void selectAllConnectedTracks (const std::vector< BOARD_CONNECTED_ITEM * > &aStartItems, STOP_CONDITION aStopCondition)
 Select connected tracks and vias. More...
 
void selectConnections (const std::vector< BOARD_ITEM * > &aItems)
 
void selectAllItemsOnSheet (wxString &aSheetPath)
 Select all items with the given sheet timestamp/UUID name (the sheet path). More...
 
int selectSheetContents (const TOOL_EVENT &aEvent)
 Select all footprints belonging to same hierarchical sheet as the selected footprint (same sheet path). More...
 
int selectSameSheet (const TOOL_EVENT &aEvent)
 Set selection to items passed by parameter and connected nets (optionally). More...
 
int syncSelection (const TOOL_EVENT &aEvent)
 
int syncSelectionWithNets (const TOOL_EVENT &aEvent)
 
void doSyncSelection (const std::vector< BOARD_ITEM * > &aItems, bool aWithNets)
 Invoke filter dialog and modify current selection. More...
 
int filterSelection (const TOOL_EVENT &aEvent)
 Return true if the given item passes the current SELECTION_FILTER_OPTIONS. More...
 
bool itemPassesFilter (BOARD_ITEM *aItem, bool aMultiSelect)
 
void unselect (EDA_ITEM *aItem) override
 Take necessary action mark an item as unselected. More...
 
void highlight (EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
 Highlight the item visually. More...
 
void unhighlight (EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
 Unhighlight the item visually. More...
 
bool selectionContains (const VECTOR2I &aPoint) const
 
int hitTestDistance (const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
 
int updateSelection (const TOOL_EVENT &aEvent)
 Event handler to update the selection VIEW_ITEM. More...
 
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide () const
 
void highlightInternal (EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
 
void unhighlightInternal (EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
 
void resetTransitions ()
 Clear the current transition map and restores the default one created by setTransitions(). More...
 
void goInternal (TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
 
EDA_ITEMgetModelInt () const
 
TOOLS_HOLDERgetToolHolderInt () const
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
bool m_isFootprintEditor
 
PCB_SELECTION m_selection
 
SELECTION_FILTER_OPTIONS m_filter
 
KICURSOR m_nonModifiedCursor
 
PCB_GROUPm_enteredGroup
 
KIGFX::VIEW_GROUP m_enteredGroupOverlay
 
std::unique_ptr< PRIVm_priv
 

Detailed Description

The selection tool: currently supports:

  • pick single objects (click LMB)
  • add objects to existing selection (Shift+LMB)
  • draw selection box (drag LMB)
  • handles FOOTPRINTs properly (i.e. selects either FOOTPRINT or its PADs, TEXTs, etc.)
  • takes into account high-contrast & layer visibility settings
  • invokes InteractiveEdit tool when user starts to drag selected items

Definition at line 64 of file pcb_selection_tool.h.

Member Enumeration Documentation

◆ RESET_REASON

enum TOOL_BASE::RESET_REASON
inherited

Determine the reason of reset for a tool.

Enumerator
RUN 

Tool is invoked after being inactive.

MODEL_RELOAD 

Model changes (required full reload)

GAL_SWITCH 

Rendering engine changes.

Definition at line 77 of file tool_base.h.

78 {
79 RUN,
82 };
@ MODEL_RELOAD
Model changes (required full reload)
Definition: tool_base.h:80
@ GAL_SWITCH
Rendering engine changes.
Definition: tool_base.h:81
@ RUN
Tool is invoked after being inactive.
Definition: tool_base.h:79

◆ STOP_CONDITION

Enumerator
STOP_AT_JUNCTION 

Stop at any place where more than two traces meet.

Because vias are also traces, this makes selection stop at a via if there is a trace on another layer as well, but a via with only one connection will be selected.

STOP_AT_PAD 

Stop when reaching a pad.

STOP_NEVER 

Select the entire net.

Definition at line 311 of file pcb_selection_tool.h.

312 {
324 };
@ STOP_AT_PAD
Stop when reaching a pad.
@ STOP_NEVER
Select the entire net.
@ STOP_AT_JUNCTION
Stop at any place where more than two traces meet.

Constructor & Destructor Documentation

◆ PCB_SELECTION_TOOL()

PCB_SELECTION_TOOL::PCB_SELECTION_TOOL ( )

Definition at line 114 of file pcb_selection_tool.cpp.

114 :
115 SELECTION_TOOL( "pcbnew.InteractiveSelection" ),
116 m_frame( nullptr ),
117 m_isFootprintEditor( false ),
119 m_enteredGroup( nullptr ),
120 m_priv( std::make_unique<PRIV>() )
121{
122 m_filter.lockedItems = false;
123 m_filter.footprints = true;
124 m_filter.text = true;
125 m_filter.tracks = true;
126 m_filter.vias = true;
127 m_filter.pads = true;
128 m_filter.graphics = true;
129 m_filter.zones = true;
130 m_filter.keepouts = true;
131 m_filter.dimensions = true;
132 m_filter.otherItems = true;
133}
std::unique_ptr< PRIV > m_priv
PCB_BASE_FRAME * m_frame
SELECTION_FILTER_OPTIONS m_filter
SELECTION_TOOL(const std::string &aName)
bool graphics
Graphic lines, shapes, polygons.
bool text
Text (free or attached to a footprint)
bool lockedItems
Allow selecting locked items.
bool footprints
Allow selecting entire footprints.
bool dimensions
Dimension items.
bool otherItems
Anything not fitting one of the above categories.

References ARROW, SELECTION_FILTER_OPTIONS::dimensions, SELECTION_FILTER_OPTIONS::footprints, SELECTION_FILTER_OPTIONS::graphics, SELECTION_FILTER_OPTIONS::keepouts, SELECTION_FILTER_OPTIONS::lockedItems, m_filter, SELECTION_FILTER_OPTIONS::otherItems, SELECTION_FILTER_OPTIONS::pads, SELECTION_FILTER_OPTIONS::text, SELECTION_FILTER_OPTIONS::tracks, SELECTION_FILTER_OPTIONS::vias, and SELECTION_FILTER_OPTIONS::zones.

◆ ~PCB_SELECTION_TOOL()

PCB_SELECTION_TOOL::~PCB_SELECTION_TOOL ( )

Definition at line 136 of file pcb_selection_tool.cpp.

137{
140
141 Disconnect( wxEVT_TIMER, wxTimerEventHandler( PCB_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
142}
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:346
KIGFX::VIEW_GROUP m_enteredGroupOverlay
PCB_SELECTION m_selection
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36

References TOOL_BASE::getView(), m_enteredGroupOverlay, m_selection, SELECTION_TOOL::onDisambiguationExpire(), and KIGFX::VIEW::Remove().

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Run the tool.

After activation, the tool starts receiving events until it is finished.

Definition at line 51 of file tool_interactive.cpp.

52{
54}
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.

References TOOL_MANAGER::InvokeTool(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

Referenced by AUTOPLACE_TOOL::autoplace(), EDIT_TOOL::copyToClipboard(), SCH_EDIT_TOOL::DeleteItemCursor(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCB_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EE_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PICKER_TOOL::Main(), PL_EDIT_TOOL::Main(), PL_POINT_EDITOR::Main(), PCB_PICKER_TOOL::Main(), LENGTH_TUNER_TOOL::MainLoop(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), PCB_POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), ROUTER_TOOL::RouteSelected(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC_TOOL::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ AddItemsToSel() [1/2]

int SELECTION_TOOL::AddItemsToSel ( const TOOL_EVENT aEvent)
inherited

Definition at line 122 of file selection_tool.cpp.

123{
124 AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
125 selection().SetIsHover( false );
126 return 0;
127}
int AddItemsToSel(const TOOL_EVENT &aEvent)
virtual SELECTION & selection()=0
Return a reference to the selection.
void SetIsHover(bool aIsHover)
Definition: selection.h:76
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:442
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:526

References SELECTION_TOOL::AddItemsToSel(), TOOL_EVENT::Parameter(), SELECTION_TOOL::selection(), and SELECTION::SetIsHover().

Referenced by SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), and setTransitions().

◆ AddItemsToSel() [2/2]

void SELECTION_TOOL::AddItemsToSel ( EDA_ITEMS aList,
bool  aQuietMode = false 
)
inherited

Definition at line 130 of file selection_tool.cpp.

131{
132 if( aList )
133 {
134 for( EDA_ITEM* item : *aList )
135 select( item );
136
137 // Inform other potentially interested tools
138 if( !aQuietMode )
140 }
141}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
virtual void select(EDA_ITEM *aItem)=0
Take necessary action mark an item as selected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).

References TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), SELECTION_TOOL::select(), and EVENTS::SelectedEvent.

◆ AddItemToSel() [1/2]

◆ AddItemToSel() [2/2]

void SELECTION_TOOL::AddItemToSel ( EDA_ITEM aItem,
bool  aQuietMode = false 
)
inherited

Definition at line 109 of file selection_tool.cpp.

110{
111 if( aItem )
112 {
113 select( aItem );
114
115 // Inform other potentially interested tools
116 if( !aQuietMode )
118 }
119}

References TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), SELECTION_TOOL::select(), and EVENTS::SelectedEvent.

◆ attachManager()

void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Set the TOOL_MANAGER the tool will belong to.

Called by TOOL_MANAGER::RegisterTool()

Definition at line 60 of file tool_base.cpp.

61{
62 m_toolMgr = aManager;
63}

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD * PCB_SELECTION_TOOL::board ( ) const
inlineprotected

◆ BrightenItem()

void SELECTION_TOOL::BrightenItem ( EDA_ITEM aItem)
inherited

Definition at line 201 of file selection_tool.cpp.

202{
203 highlight( aItem, BRIGHTENED );
204}
virtual void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)=0
Highlight the item visually.
#define BRIGHTENED
item is drawn with a bright contour

References BRIGHTENED, and SELECTION_TOOL::highlight().

Referenced by SCH_EDIT_TOOL::DeleteItemCursor(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), and SCH_EDITOR_CONTROL::UpdateFind().

◆ canvas()

PCB_DRAW_PANEL_GAL * PCB_SELECTION_TOOL::canvas ( ) const
inlineprotected

Definition at line 235 of file pcb_selection_tool.h.

236 {
237 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
238 }
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_BASE_EDIT_FRAME * frame() const

References frame(), and PCB_BASE_FRAME::GetCanvas().

Referenced by FindItem().

◆ ClearSelection() [1/2]

void PCB_SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Select all items on the board.

Definition at line 2259 of file pcb_selection_tool.cpp.

2260{
2261 if( m_selection.Empty() )
2262 return;
2263
2264 while( m_selection.GetSize() )
2266
2267 view()->Update( &m_selection );
2268
2269 m_selection.SetIsHover( false );
2271
2272 // Inform other potentially interested tools
2273 if( !aQuietMode )
2274 {
2277 }
2278}
static const TOOL_EVENT ClearedEvent
Definition: actions.h:208
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:507
KIGFX::PCB_VIEW * view() const
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:97
EDA_ITEM * Front() const
Definition: selection.h:206
void ClearReferencePoint()
Definition: selection.h:263
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:107
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
#define SELECTED
Item was manually selected by the user.

References EVENTS::ClearedEvent, SELECTION::ClearReferencePoint(), SELECTION::Empty(), SELECTION::Front(), SELECTION::GetSize(), PCB_ACTIONS::hideLocalRatsnest, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), SELECTED, SELECTION::SetIsHover(), unhighlight(), KIGFX::PCB_VIEW::Update(), and view().

◆ ClearSelection() [2/2]

◆ controls()

KIGFX::VIEW_CONTROLS * PCB_SELECTION_TOOL::controls ( ) const
inlineprotected

Definition at line 220 of file pcb_selection_tool.h.

221 {
222 return getViewControls();
223 }
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42

References TOOL_BASE::getViewControls().

◆ ctrlClickHighlights()

bool PCB_SELECTION_TOOL::ctrlClickHighlights ( )
overrideprotectedvirtual

Determines if ctrl-click is highlight net or XOR selection.

Reimplemented from SELECTION_TOOL.

Definition at line 707 of file pcb_selection_tool.cpp.

708{
710}
PCBNEW_SETTINGS * GetPcbNewSettings() const

References PCB_BASE_FRAME::GetPcbNewSettings(), PCBNEW_SETTINGS::m_CtrlClickHighlight, m_frame, and m_isFootprintEditor.

◆ CursorSelection()

int PCB_SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 1035 of file pcb_selection_tool.cpp.

1036{
1038
1039 selectCursor( false, aClientFilter );
1040
1041 return 0;
1042}
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
Select an item under the cursor unless there is something already selected.
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)

References TOOL_EVENT::Parameter(), and selectCursor().

Referenced by setTransitions().

◆ disambiguateCursor()

int PCB_SELECTION_TOOL::disambiguateCursor ( const TOOL_EVENT aEvent)
private

Handle disambiguation actions including displaying the menu.

Definition at line 1019 of file pcb_selection_tool.cpp.

1020{
1021 wxMouseState keyboardState = wxGetMouseState();
1022
1023 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
1024 keyboardState.AltDown() );
1025
1026 m_skip_heuristics = true;
1028 m_skip_heuristics = false;
1029
1030 return 0;
1031}
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=nullptr, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
Select an item pointed by the parameter aWhere.
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state ...
VECTOR2I m_originalCursor

References SELECTION_TOOL::m_canceledMenu, SELECTION_TOOL::m_originalCursor, SELECTION_TOOL::m_skip_heuristics, selectPoint(), and SELECTION_TOOL::setModifiersState().

Referenced by setTransitions().

◆ doSelectionMenu()

bool SELECTION_TOOL::doSelectionMenu ( COLLECTOR aCollector)
protectedinherited

The user has requested the full, non-limited list of selection items

Definition at line 239 of file selection_tool.cpp.

240{
241 UNITS_PROVIDER* unitsProvider = getEditFrame<EDA_DRAW_FRAME>();
242 EDA_ITEM* current = nullptr;
243 SELECTION highlightGroup;
244 bool selectAll = false;
245 bool expandSelection = false;
246
247 highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
248 getView()->Add( &highlightGroup );
249
250 do
251 {
253 if( expandSelection )
254 aCollector->Combine();
255
256 expandSelection = false;
257
258 int limit = std::min( 100, aCollector->GetCount() );
259 ACTION_MENU menu( true );
260
261 for( int i = 0; i < limit; ++i )
262 {
263 EDA_ITEM* item = ( *aCollector )[i];
264 wxString menuText;
265
266 if( i < 9 )
267 {
268#ifdef __WXMAC__
269 menuText = wxString::Format( "%s\t%d",
270 item->GetSelectMenuText( unitsProvider ),
271 i + 1 );
272#else
273 menuText = wxString::Format( "&%d %s\t%d",
274 i + 1,
275 item->GetSelectMenuText( unitsProvider ),
276 i + 1 );
277#endif
278 }
279 else
280 {
281 menuText = item->GetSelectMenuText( unitsProvider );
282 }
283
284 menu.Add( menuText, i + 1, item->GetMenuImage() );
285 }
286
287 menu.AppendSeparator();
288 menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
289
290 if( !expandSelection && aCollector->HasAdditionalItems() )
291 menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
292
293 if( aCollector->m_MenuTitle.Length() )
294 {
295 menu.SetTitle( aCollector->m_MenuTitle );
296 menu.SetIcon( BITMAPS::info );
297 menu.DisplayTitle( true );
298 }
299 else
300 {
301 menu.DisplayTitle( false );
302 }
303
304 SetContextMenu( &menu, CMENU_NOW );
305
306 while( TOOL_EVENT* evt = Wait() )
307 {
308 if( evt->Action() == TA_CHOICE_MENU_UPDATE )
309 {
310 if( selectAll )
311 {
312 for( int i = 0; i < aCollector->GetCount(); ++i )
313 unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
314 }
315 else if( current )
316 {
317 unhighlight( current, BRIGHTENED, &highlightGroup );
318 }
319
320 int id = *evt->GetCommandId();
321
322 // User has pointed an item, so show it in a different way
323 if( id > 0 && id <= limit )
324 {
325 current = ( *aCollector )[id - 1];
326 highlight( current, BRIGHTENED, &highlightGroup );
327 }
328 else
329 {
330 current = nullptr;
331 }
332
333 // User has pointed on the "Select All" option
334 if( id == limit + 1 )
335 {
336 for( int i = 0; i < aCollector->GetCount(); ++i )
337 highlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
338
339 selectAll = true;
340 }
341 else
342 {
343 selectAll = false;
344 }
345 }
346 else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
347 {
348 if( selectAll )
349 {
350 for( int i = 0; i < aCollector->GetCount(); ++i )
351 unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
352 }
353 else if( current )
354 {
355 unhighlight( current, BRIGHTENED, &highlightGroup );
356 }
357
358 std::optional<int> id = evt->GetCommandId();
359
360 // User has selected the "Select All" option
361 if( id == limit + 1 )
362 {
363 selectAll = true;
364 current = nullptr;
365 }
366 // User has selected the "Expand Selection" option
367 else if( id == limit + 2 )
368 {
369 selectAll = false;
370 current = nullptr;
371 expandSelection = true;
372 }
373 // User has selected an item, so this one will be returned
374 else if( id && ( *id > 0 ) && ( *id <= limit ) )
375 {
376 selectAll = false;
377 current = ( *aCollector )[*id - 1];
378 }
379 // User has cancelled the menu (either by <esc> or clicking out of it)
380 else
381 {
382 selectAll = false;
383 current = nullptr;
384 }
385 }
386 else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
387 {
388 break;
389 }
390 }
391 } while( expandSelection );
392
393 getView()->Remove( &highlightGroup );
394
395 if( selectAll )
396 {
397 return true;
398 }
399 else if( current )
400 {
401 aCollector->Empty();
402 aCollector->Append( current );
403 return true;
404 }
405
406 return false;
407}
@ INVALID_BITMAP
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void Empty()
Clear the list.
Definition: collector.h:89
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
wxString m_MenuTitle
Definition: collector.h:236
bool HasAdditionalItems()
Test if the collector has heuristic backup items.
Definition: collector.h:132
void Combine()
Re-combine the backup list into the main list of the collector.
Definition: collector.h:140
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:99
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:269
virtual wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:108
virtual void SetLayer(int aLayer)
Set layer used to draw the group.
Definition: view_group.h:98
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
virtual void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr)=0
Unhighlight the item visually.
Generic, UI-independent tool event.
Definition: tool_event.h:156
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
#define _(s)
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:219
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
@ CMENU_NOW
Definition: tool_event.h:148
@ TA_CHOICE_MENU_CHOICE
Definition: tool_event.h:93
@ TA_CHOICE_MENU_UPDATE
Definition: tool_event.h:89
@ TA_CHOICE_MENU_CLOSED
Definition: tool_event.h:96

References _, ACTION_MENU::Add(), KIGFX::VIEW::Add(), COLLECTOR::Append(), BRIGHTENED, CMENU_NOW, COLLECTOR::Combine(), ACTION_MENU::DisplayTitle(), COLLECTOR::Empty(), Format(), COLLECTOR::GetCount(), EDA_ITEM::GetMenuImage(), EDA_ITEM::GetSelectMenuText(), TOOL_BASE::getView(), COLLECTOR::HasAdditionalItems(), SELECTION_TOOL::highlight(), info, INVALID_BITMAP, LAYER_SELECT_OVERLAY, COLLECTOR::m_MenuTitle, KIGFX::VIEW::Remove(), TOOL_INTERACTIVE::SetContextMenu(), ACTION_MENU::SetIcon(), KIGFX::VIEW_GROUP::SetLayer(), ACTION_MENU::SetTitle(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_CLOSED, TA_CHOICE_MENU_UPDATE, SELECTION_TOOL::unhighlight(), and TOOL_INTERACTIVE::Wait().

Referenced by SELECTION_TOOL::SelectionMenu(), GERBVIEW_SELECTION_TOOL::selectPoint(), PL_SELECTION_TOOL::SelectPoint(), selectPoint(), and EE_SELECTION_TOOL::selectPoint().

◆ doSyncSelection()

void PCB_SELECTION_TOOL::doSyncSelection ( const std::vector< BOARD_ITEM * > &  aItems,
bool  aWithNets 
)
private

Invoke filter dialog and modify current selection.

Definition at line 1717 of file pcb_selection_tool.cpp.

1718{
1719 ClearSelection( true /*quiet mode*/ );
1720
1721 // Perform individual selection of each item before processing the event.
1722 for( BOARD_ITEM* item : aItems )
1723 select( item );
1724
1725 if( aWithNets )
1726 selectConnections( aItems );
1727
1729
1730 if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
1731 {
1733 {
1735 ZoomFitCrossProbeBBox( bbox );
1736
1737 m_frame->FocusOnLocation( bbox.Centre() );
1738 }
1739 }
1740
1742
1744
1745 if( m_selection.Size() > 0 )
1747}
CROSS_PROBING_SETTINGS m_CrossProbing
Definition: app_settings.h:179
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
Vec Centre() const
Definition: box2.h:70
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
void ForceRefresh()
Force a redraw.
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:758
void ZoomFitCrossProbeBBox(const BOX2I &bbox)
void select(EDA_ITEM *aItem) override
Take necessary action mark an item as selected.
void selectConnections(const std::vector< BOARD_ITEM * > &aItems)
int Size() const
Returns the number of selected parts.
Definition: selection.h:113
virtual BOX2I GetBoundingBox() const
Definition: selection.cpp:123
bool zoom_to_fit
Zoom to fit items (ignored if center_on_items is off)
Definition: app_settings.h:34
bool center_on_items
Automatically pan to cross-probed items.
Definition: app_settings.h:33

References CROSS_PROBING_SETTINGS::center_on_items, BOX2< Vec >::Centre(), ClearSelection(), EDA_DRAW_FRAME::FocusOnLocation(), EDA_DRAW_PANEL_GAL::ForceRefresh(), SELECTION::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), BOX2< Vec >::GetHeight(), PCB_BASE_FRAME::GetPcbNewSettings(), BOX2< Vec >::GetWidth(), APP_SETTINGS_BASE::m_CrossProbing, m_frame, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), selectConnections(), EVENTS::SelectedEvent, SELECTION::Size(), KIGFX::VIEW::UpdateAllLayersColor(), view(), CROSS_PROBING_SETTINGS::zoom_to_fit, and ZoomFitCrossProbeBBox().

Referenced by syncSelection(), and syncSelectionWithNets().

◆ EnterGroup()

void PCB_SELECTION_TOOL::EnterGroup ( )

Enter the group at the head of the current selection.

Definition at line 503 of file pcb_selection_tool.cpp.

504{
505 wxCHECK_RET( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T,
506 wxT( "EnterGroup called when selection is not a single group" ) );
507 PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
508
509 if( m_enteredGroup != nullptr )
510 ExitGroup();
511
513 m_enteredGroup = aGroup;
516 {
517 select( titem );
518 } );
519
521
522 view()->Hide( m_enteredGroup, true );
525}
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:57
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1545
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all members of the group.
Definition: pcb_group.cpp:407
void ExitGroup(bool aSelectGroup=false)
Leave the currently-entered group.
#define ENTERED
indicates a group has been entered
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115

References KIGFX::VIEW_GROUP::Add(), ClearSelection(), ENTERED, ExitGroup(), SELECTION::GetSize(), KIGFX::VIEW::Hide(), m_enteredGroup, m_enteredGroupOverlay, m_selection, TOOL_BASE::m_toolMgr, PCB_GROUP_T, TOOL_MANAGER::ProcessEvent(), PCB_GROUP::RunOnChildren(), select(), EVENTS::SelectedEvent, EDA_ITEM::SetFlags(), KIGFX::PCB_VIEW::Update(), and view().

Referenced by GROUP_TOOL::EnterGroup(), and Main().

◆ ExitGroup()

void PCB_SELECTION_TOOL::ExitGroup ( bool  aSelectGroup = false)

Leave the currently-entered group.

Parameters
aSelectGroup[optional] Select the group after leaving.

Definition at line 528 of file pcb_selection_tool.cpp.

529{
530 // Only continue if there is a group entered
531 if( m_enteredGroup == nullptr )
532 return;
533
535 view()->Hide( m_enteredGroup, false );
537
538 if( aSelectGroup )
539 {
542 }
543
545 m_enteredGroup = nullptr;
547}
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:143
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:69

References KIGFX::VIEW_GROUP::Clear(), EDA_ITEM::ClearFlags(), ClearSelection(), ENTERED, KIGFX::VIEW::Hide(), m_enteredGroup, m_enteredGroupOverlay, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), EVENTS::SelectedEvent, KIGFX::PCB_VIEW::Update(), and view().

Referenced by EDIT_TOOL::DeleteItems(), EnterGroup(), Main(), Reset(), and selectPoint().

◆ expandConnection()

int PCB_SELECTION_TOOL::expandConnection ( const TOOL_EVENT aEvent)
private

Expand the current connected-item selection to the next boundary (junctions, pads, or all)

Definition at line 1151 of file pcb_selection_tool.cpp.

1152{
1153 unsigned initialCount = 0;
1154
1155 for( const EDA_ITEM* item : m_selection.GetItems() )
1156 {
1157 if( item->Type() == PCB_FOOTPRINT_T || BOARD_CONNECTED_ITEM::ClassOf( item ) )
1158 initialCount++;
1159 }
1160
1161 if( initialCount == 0 )
1163
1164 m_frame->SetStatusText( _( "Select/Expand Connection..." ) );
1165
1166 for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
1167 {
1168 std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
1169
1170 for( EDA_ITEM* item : selectedItems )
1171 item->ClearTempFlags();
1172
1173 std::vector<BOARD_CONNECTED_ITEM*> startItems;
1174
1175 for( EDA_ITEM* item : selectedItems )
1176 {
1177 if( item->Type() == PCB_FOOTPRINT_T )
1178 {
1179 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
1180
1181 for( PAD* pad : footprint->Pads() )
1182 startItems.push_back( pad );
1183 }
1184 else if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
1185 {
1186 startItems.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
1187 }
1188 }
1189
1190 selectAllConnectedTracks( startItems, stopCondition );
1191
1192 if( m_selection.GetItems().size() > initialCount )
1193 break;
1194 }
1195
1196 m_frame->SetStatusText( wxEmptyString );
1197
1198 // Inform other potentially interested tools
1200
1201 return 0;
1202}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
static bool ClassOf(const EDA_ITEM *aItem)
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
PADS & Pads()
Definition: footprint.h:170
Definition: pad.h:59
void selectAllConnectedTracks(const std::vector< BOARD_CONNECTED_ITEM * > &aStartItems, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:118
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86

References _, BOARD_CONNECTED_ITEM::ClassOf(), connectedItemFilter(), SELECTION::GetItems(), m_frame, m_selection, TOOL_BASE::m_toolMgr, pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, TOOL_MANAGER::ProcessEvent(), selectAllConnectedTracks(), selectCursor(), EVENTS::SelectedEvent, STOP_AT_JUNCTION, STOP_AT_PAD, and STOP_NEVER.

Referenced by setTransitions().

◆ FilterCollectedItems()

void PCB_SELECTION_TOOL::FilterCollectedItems ( GENERAL_COLLECTOR aCollector,
bool  aMultiSelect 
)

Apply the SELECTION_FITLER_OPTIONS to the collector.

Definition at line 2138 of file pcb_selection_tool.cpp.

2139{
2140 if( aCollector.GetCount() == 0 )
2141 return;
2142
2143 std::set<BOARD_ITEM*> rejected;
2144
2145 for( EDA_ITEM* i : aCollector )
2146 {
2147 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
2148
2149 if( !itemPassesFilter( item, aMultiSelect ) )
2150 rejected.insert( item );
2151 }
2152
2153 for( BOARD_ITEM* item : rejected )
2154 aCollector.Remove( item );
2155}
bool itemPassesFilter(BOARD_ITEM *aItem, bool aMultiSelect)

References COLLECTOR::GetCount(), itemPassesFilter(), and COLLECTOR::Remove().

Referenced by BOARD_INSPECTION_TOOL::highlightNet(), selectMultiple(), and selectPoint().

◆ FilterCollectorForFreePads()

void PCB_SELECTION_TOOL::FilterCollectorForFreePads ( GENERAL_COLLECTOR aCollector) const

Check the "allow free pads" setting and if disabled, replace any pads in the collector with their parent footprints.

Definition at line 3092 of file pcb_selection_tool.cpp.

3093{
3094 std::set<BOARD_ITEM*> to_add;
3095
3096 // Iterate from the back so we don't have to worry about removals.
3097 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
3098 {
3099 BOARD_ITEM* item = aCollector[i];
3100
3101 if( !m_isFootprintEditor && item->Type() == PCB_PAD_T
3102 && !frame()->GetPcbNewSettings()->m_AllowFreePads )
3103 {
3104 if( !aCollector.HasItem( item->GetParent() ) )
3105 to_add.insert( item->GetParent() );
3106
3107 aCollector.Remove( item );
3108 }
3109 }
3110
3111 for( BOARD_ITEM* item : to_add )
3112 aCollector.Append( item );
3113}
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:163
bool HasItem(const EDA_ITEM *aItem) const
Tests if aItem has already been collected.
Definition: collector.h:195
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:109
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87

References COLLECTOR::Append(), frame(), COLLECTOR::GetCount(), BOARD_ITEM::GetParent(), COLLECTOR::HasItem(), m_isFootprintEditor, PCB_PAD_T, COLLECTOR::Remove(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Drag(), EDIT_TOOL::Flip(), EDIT_TOOL::Mirror(), EDIT_TOOL::Remove(), EDIT_TOOL::Rotate(), and EDIT_TOOL::Swap().

◆ FilterCollectorForHierarchy()

void PCB_SELECTION_TOOL::FilterCollectorForHierarchy ( GENERAL_COLLECTOR aCollector,
bool  aMultiselect 
) const

In general we don't want to select both a parent and any of it's children.

This includes both footprints and their items, and groups and their members.

Definition at line 3024 of file pcb_selection_tool.cpp.

3026{
3027 std::unordered_set<BOARD_ITEM*> toAdd;
3028
3029 // Set CANDIDATE on all parents which are included in the GENERAL_COLLECTOR. This
3030 // algorithm is O(3n), whereas checking for the parent inclusion could potentially be O(n^2).
3031 for( int j = 0; j < aCollector.GetCount(); j++ )
3032 {
3033 if( aCollector[j]->GetParent() )
3034 aCollector[j]->GetParent()->ClearFlags( CANDIDATE );
3035 }
3036
3037 if( aMultiselect )
3038 {
3039 for( int j = 0; j < aCollector.GetCount(); j++ )
3040 aCollector[j]->SetFlags( CANDIDATE );
3041 }
3042
3043 for( int j = 0; j < aCollector.GetCount(); )
3044 {
3045 BOARD_ITEM* item = aCollector[j];
3046 BOARD_ITEM* parent = item->GetParent();
3047 BOARD_ITEM* start = item;
3048
3049 if( !m_isFootprintEditor && parent && parent->Type() == PCB_FOOTPRINT_T )
3050 start = parent;
3051
3052 // If a group is entered, disallow selections of objects outside the group.
3054 {
3055 aCollector.Remove( item );
3056 continue;
3057 }
3058
3059 // If any element is a member of a group, replace those elements with the top containing
3060 // group.
3062 {
3063 if( top != item )
3064 {
3065 toAdd.insert( top );
3066 top->SetFlags(CANDIDATE );
3067
3068 aCollector.Remove( item );
3069 continue;
3070 }
3071 }
3072
3073 // Footprints are a bit easier as they can't be nested.
3074 if( parent && ( parent->GetFlags() & CANDIDATE ) )
3075 {
3076 // Remove children of selected items
3077 aCollector.Remove( item );
3078 continue;
3079 }
3080
3081 ++j;
3082 }
3083
3084 for( BOARD_ITEM* item : toAdd )
3085 {
3086 if( !aCollector.HasItem( item ) )
3087 aCollector.Append( item );
3088 }
3089}
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:144
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:156
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:150
#define CANDIDATE
flag indicating that the structure is connected

References COLLECTOR::Append(), CANDIDATE, COLLECTOR::GetCount(), EDA_ITEM::GetFlags(), BOARD_ITEM::GetParent(), COLLECTOR::HasItem(), m_enteredGroup, m_isFootprintEditor, PCB_FOOTPRINT_T, COLLECTOR::Remove(), PCB_GROUP::TopLevelGroup(), EDA_ITEM::Type(), and PCB_GROUP::WithinScope().

Referenced by EDIT_TOOL::CreateArray(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Drag(), EDIT_TOOL::Duplicate(), EDIT_TOOL::Flip(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), POSITION_RELATIVE_TOOL::PositionRelative(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), SelectAll(), selectMultiple(), selectPoint(), and EDIT_TOOL::Swap().

◆ FilterCollectorForMarkers()

void PCB_SELECTION_TOOL::FilterCollectorForMarkers ( GENERAL_COLLECTOR aCollector) const

Drop any PCB_MARKERs from the collector.

Definition at line 3116 of file pcb_selection_tool.cpp.

3117{
3118 // Iterate from the back so we don't have to worry about removals.
3119 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
3120 {
3121 BOARD_ITEM* item = aCollector[i];
3122
3123 if( item->Type() == PCB_MARKER_T )
3124 aCollector.Remove( item );
3125 }
3126}
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:104

References COLLECTOR::GetCount(), PCB_MARKER_T, COLLECTOR::Remove(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::CreateArray(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Duplicate(), EDIT_TOOL::Flip(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Rotate(), and EDIT_TOOL::Swap().

◆ filterSelection()

int PCB_SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Return true if the given item passes the current SELECTION_FILTER_OPTIONS.

Definition at line 2106 of file pcb_selection_tool.cpp.

2107{
2108 const BOARD& board = *getModel<BOARD>();
2109 DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
2110 DIALOG_FILTER_SELECTION dlg( m_frame, opts );
2111
2112 const int cmd = dlg.ShowModal();
2113
2114 if( cmd != wxID_OK )
2115 return 0;
2116
2117 // copy current selection
2118 std::deque<EDA_ITEM*> selection = m_selection.GetItems();
2119
2120 ClearSelection( true /*quiet mode*/ );
2121
2122 // re-select items from the saved selection according to the dialog options
2123 for( EDA_ITEM* i : selection )
2124 {
2125 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
2126 bool include = itemIsIncludedByFilter( *item, board, opts );
2127
2128 if( include )
2129 select( item );
2130 }
2131
2133
2134 return 0;
2135}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
SELECTION & selection() override
Return a reference to the selection.
BOARD * board() const
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Determine if an item is included by the filter specified.
Struct that will be set with the result of the user choices in the dialog.

References board(), ClearSelection(), SELECTION::GetItems(), itemIsIncludedByFilter(), m_frame, m_priv, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), EVENTS::SelectedEvent, and selection().

Referenced by setTransitions().

◆ FindItem()

void PCB_SELECTION_TOOL::FindItem ( BOARD_ITEM aItem)

Take necessary actions to mark an item as found.

Parameters
aItemThe item that was found and needs to be highlighted/focused/etc.

Definition at line 1955 of file pcb_selection_tool.cpp.

1956{
1957 bool cleared = false;
1958
1959 if( m_selection.GetSize() > 0 )
1960 {
1961 // Don't fire an event now; most of the time it will be redundant as we're about to
1962 // fire a SelectedEvent.
1963 cleared = true;
1964 ClearSelection( true /*quiet mode*/ );
1965 }
1966
1967 if( aItem )
1968 {
1969 switch( aItem->Type() )
1970 {
1971 case PCB_NETINFO_T:
1972 {
1973 int netCode = static_cast<NETINFO_ITEM*>( aItem )->GetNetCode();
1974
1975 if( netCode > 0 )
1976 {
1977 SelectAllItemsOnNet( netCode, true );
1978 m_frame->FocusOnLocation( aItem->GetCenter() );
1979 }
1980 break;
1981 }
1982
1983 default:
1984 select( aItem );
1985 m_frame->FocusOnLocation( aItem->GetPosition() );
1986 }
1987
1988 // If the item has a bounding box, then zoom out if needed
1989 if( aItem->GetBoundingBox().GetHeight() > 0 && aItem->GetBoundingBox().GetWidth() > 0 )
1990 {
1991 // This adds some margin
1992 double marginFactor = 2;
1993
1994 KIGFX::PCB_VIEW* pcbView = canvas()->GetView();
1995 BOX2D screenBox = pcbView->GetViewport();
1996 VECTOR2I screenSize = screenBox.GetSize();
1997 BOX2I screenRect( screenBox.GetOrigin(), screenSize / marginFactor );
1998
1999 if( !screenRect.Contains( aItem->GetBoundingBox() ) )
2000 {
2001 double scaleX = screenSize.x / static_cast<double>( aItem->GetBoundingBox().GetWidth() );
2002 double scaleY = screenSize.y / static_cast<double>( aItem->GetBoundingBox().GetHeight() );
2003
2004 scaleX /= marginFactor;
2005 scaleY /= marginFactor;
2006
2007 double scale = scaleX > scaleY ? scaleY : scaleX;
2008
2009 if( scale < 1 ) // Don't zoom in, only zoom out
2010 {
2011 pcbView->SetScale( pcbView->GetScale() * ( scale ) );
2012
2013 //Let's refocus because there is an algorithm to avoid dialogs in there.
2014 m_frame->FocusOnLocation( aItem->GetCenter() );
2015 }
2016 }
2017 }
2018 // Inform other potentially interested tools
2020 }
2021 else if( cleared )
2022 {
2024 }
2025
2027}
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:93
const Vec & GetOrigin() const
Definition: box2.h:183
const Vec & GetSize() const
Definition: box2.h:179
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:251
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
double GetScale() const
Definition: view.h:269
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:508
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:548
Handle the data for a net.
Definition: netinfo.h:66
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
PCB_DRAW_PANEL_GAL * canvas() const
void SelectAllItemsOnNet(int aNetCode, bool aSelect=true)
Select all items with the given net code.
const int scale
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:114

References canvas(), EVENTS::ClearedEvent, ClearSelection(), BOX2< Vec >::Contains(), EDA_DRAW_FRAME::FocusOnLocation(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_ITEM::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), BOARD_ITEM::GetCenter(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetOrigin(), EDA_ITEM::GetPosition(), KIGFX::VIEW::GetScale(), BOX2< Vec >::GetSize(), SELECTION::GetSize(), PCB_DRAW_PANEL_GAL::GetView(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), m_frame, m_selection, TOOL_BASE::m_toolMgr, PCB_NETINFO_T, TOOL_MANAGER::ProcessEvent(), scale, select(), SelectAllItemsOnNet(), EVENTS::SelectedEvent, KIGFX::VIEW::SetScale(), EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_EDIT_FRAME::ShowFindDialog().

◆ frame()

PCB_BASE_EDIT_FRAME * PCB_SELECTION_TOOL::frame ( ) const
inlineprotected

Definition at line 225 of file pcb_selection_tool.h.

226 {
227 return getEditFrame<PCB_BASE_EDIT_FRAME>();
228 }

Referenced by canvas(), FilterCollectorForFreePads(), Init(), Main(), and RequestSelection().

◆ GetActiveLayer()

PCB_LAYER_ID PCB_SELECTION_TOOL::GetActiveLayer ( )
inline

Definition at line 190 of file pcb_selection_tool.h.

190{ return m_frame->GetActiveLayer(); }
virtual PCB_LAYER_ID GetActiveLayer() const

References PCB_BASE_FRAME::GetActiveLayer(), and m_frame.

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE PCB_SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 680 of file pcb_selection_tool.cpp.

681{
682 GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
683 (PCB_LAYER_ID) view()->GetTopLayer(), view() );
684
685 bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
686
687 // account for the globals
688 guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
689 guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT ) );
690 guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT ) );
691 guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
692 guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
693 guide.SetIgnorePadsOnBack( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_BK ) );
694 guide.SetIgnorePadsOnFront( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_FR ) );
695 guide.SetIgnoreThroughHolePads( padsDisabled || ! board()->IsElementVisible( LAYER_PADS_TH ) );
696 guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
697 guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
698 guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIAS ) );
699 guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIAS ) );
700 guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIAS ) );
701 guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
702
703 return guide;
704}
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:592
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:326
@ LAYER_MOD_TEXT_INVISIBLE
text marked as invisible
Definition: layer_ids.h:200
@ LAYER_PAD_FR
smd pads, front layer
Definition: layer_ids.h:202
@ LAYER_MOD_TEXT
Definition: layer_ids.h:198
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored)
Definition: layer_ids.h:230
@ LAYER_TRACKS
Definition: layer_ids.h:212
@ LAYER_MOD_FR
show footprints on front
Definition: layer_ids.h:208
@ LAYER_PAD_BK
smd pads, back layer
Definition: layer_ids.h:203
@ LAYER_MOD_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:210
@ LAYER_PADS_TH
multilayer pads, usually with holes
Definition: layer_ids.h:213
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:193
@ LAYER_MOD_BK
show footprints on back
Definition: layer_ids.h:209
@ LAYER_MOD_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:211
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59

References board(), BOARD::IsElementVisible(), LAYER_MOD_BK, LAYER_MOD_FR, LAYER_MOD_REFERENCES, LAYER_MOD_TEXT, LAYER_MOD_TEXT_INVISIBLE, LAYER_MOD_VALUES, LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIAS, GENERAL_COLLECTORS_GUIDE::SetIgnoreBlindBuriedVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMicroVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesRefs(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesVals(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsMarkedNoShow(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnorePadsOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnorePadsOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnoreThroughHolePads(), GENERAL_COLLECTORS_GUIDE::SetIgnoreThroughVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreTracks(), and view().

Referenced by RequestSelection(), and selectPoint().

◆ getEditFrame()

template<typename T >
T * TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Return the application window object, casted to requested user type.

Definition at line 184 of file tool_base.h.

185 {
186#if !defined( QA_TEST ) // Dynamic casts give the linker a seizure in the test framework
187 wxASSERT( dynamic_cast<T*>( getToolHolderInt() ) );
188#endif
189 return static_cast<T*>( getToolHolderInt() );
190 }
TOOLS_HOLDER * getToolHolderInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getToolHolderInt().

Referenced by ZONE_CREATE_HELPER::createNewZone(), and ZONE_CREATE_HELPER::setUniquePriority().

◆ GetEnteredGroup()

PCB_GROUP * PCB_SELECTION_TOOL::GetEnteredGroup ( )
inline
Returns
the currently-entered group.

Definition at line 188 of file pcb_selection_tool.h.

188{ return m_enteredGroup; }

References m_enteredGroup.

Referenced by EDIT_TOOL::DeleteItems(), PCB_CONTROL::placeBoardItems(), and BOARD_COMMIT::Push().

◆ GetFilter()

◆ GetId()

TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Return the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 120 of file tool_base.h.

121 {
122 return m_toolId;
123 }

References TOOL_BASE::m_toolId.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::isActive(), TOOL_MANAGER::RegisterTool(), ACTION_MANAGER::RunHotKey(), TOOL_MANAGER::runTool(), TOOL_MANAGER::saveViewControls(), and TOOL_MANAGER::ShutdownTool().

◆ GetManager()

TOOL_MANAGER * TOOL_BASE::GetManager ( ) const
inlineinherited

◆ getModel()

template<typename T >
T * TOOL_BASE::getModel ( ) const
inlineprotectedinherited

Return the model object if it matches the requested type.

Store the type of the tool.

Definition at line 196 of file tool_base.h.

References TOOL_BASE::getModelInt().

Referenced by ZONE_CREATE_HELPER::commitZone(), and ZONE_CREATE_HELPER::createZoneFromExisting().

◆ getModelInt()

EDA_ITEM * TOOL_BASE::getModelInt ( ) const
privateinherited

Definition at line 54 of file tool_base.cpp.

55{
56 return m_toolMgr->GetModel();
57}
EDA_ITEM * GetModel() const
Definition: tool_manager.h:292

References TOOL_MANAGER::GetModel(), and TOOL_BASE::m_toolMgr.

Referenced by TOOL_BASE::getModel().

◆ GetName()

const std::string & TOOL_BASE::GetName ( void  ) const
inlineinherited

Return the name of the tool.

Tool names are expected to obey the format: application.ToolName (eg. pcbnew.InteractiveSelection).

Returns
The name of the tool.

Definition at line 133 of file tool_base.h.

134 {
135 return m_toolName;
136 }
std::string m_toolName
Definition: tool_base.h:213

References TOOL_BASE::m_toolName.

Referenced by TOOL_MANAGER::dispatchInternal(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::invokeTool(), TOOL_MANAGER::RegisterTool(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::ShutdownTool().

◆ GetSelection()

◆ getToolHolderInt()

TOOLS_HOLDER * TOOL_BASE::getToolHolderInt ( ) const
privateinherited

Definition at line 48 of file tool_base.cpp.

49{
50 return m_toolMgr->GetToolHolder();
51}
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:296

References TOOL_MANAGER::GetToolHolder(), and TOOL_BASE::m_toolMgr.

Referenced by TOOL_BASE::getEditFrame().

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Return the type of the tool.

Returns
The type of the tool.

Definition at line 108 of file tool_base.h.

109 {
110 return m_type;
111 }
TOOL_TYPE m_type
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:206

References TOOL_BASE::m_type.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InvokeTool(), TOOL_MANAGER::ResetTools(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::ShutdownTool().

◆ getView()

KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Returns the instance of #VIEW object used in the application.

It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 36 of file tool_base.cpp.

37{
38 return m_toolMgr->GetView();
39}
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:285

References TOOL_MANAGER::GetView(), and TOOL_BASE::m_toolMgr.

Referenced by EE_POINT_EDITOR::addCornerCondition(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), SCH_EDITOR_CONTROL::AssignNetclass(), COMMON_TOOLS::CenterContents(), SCH_EDIT_TOOL::ChangeTextType(), EE_INSPECTION_TOOL::CheckSymbol(), GERBVIEW_CONTROL::ClearAllLayers(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::CollectHits(), SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint(), COMMON_TOOLS::CursorControl(), SCH_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), EDIT_TOOL::DeleteItems(), PL_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), SELECTION_TOOL::doSelectionMenu(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::drawShape(), DRAWING_TOOL::DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), PCB_CONTROL::GridResetOrigin(), PCB_CONTROL::GridSetOrigin(), EE_SELECTION_TOOL::GuessSelectionCandidates(), ROUTER_TOOL::handleCommonEvents(), EE_SELECTION_TOOL::highlight(), PL_SELECTION_TOOL::highlight(), highlight(), GERBVIEW_CONTROL::HighlightControl(), BOARD_INSPECTION_TOOL::highlightNet(), PNS::TOOL_BASE::highlightNets(), hitTestDistance(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), EE_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), PCB_PICKER_TOOL::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), PL_EDIT_TOOL::moveItem(), SCH_MOVE_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), SCH_EDITOR_CONTROL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), ROUTER_TOOL::performRouting(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), DRAWING_TOOL::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EE_SELECTION_TOOL::Reset(), EE_TOOL_BASE< T >::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), PNS::TOOL_BASE::Reset(), BOARD_EDITOR_CONTROL::Reset(), DRAWING_TOOL::Reset(), PCB_CONTROL::Reset(), Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), Selectable(), EE_SELECTION_TOOL::SelectAll(), SelectAll(), EE_SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectionContains(), selectionContains(), EE_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::selectMultiple(), selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), EE_SELECTION_TOOL::selectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDITOR_CONTROL::ToggleERCErrors(), SCH_EDITOR_CONTROL::ToggleERCExclusions(), SCH_EDITOR_CONTROL::ToggleERCWarnings(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), SCH_DRAWING_TOOLS::TwoClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), EE_SELECTION_TOOL::unhighlight(), PL_SELECTION_TOOL::unhighlight(), unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PL_POINT_EDITOR::updateItem(), PCB_POINT_EDITOR::updateItem(), EE_TOOL_BASE< T >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), updateSelection(), PNS::TOOL_BASE::updateStartItem(), view(), PCB_TOOL_BASE::view(), PCB_VIEWER_TOOLS::view(), EE_SELECTION_TOOL::ZoomFitCrossProbeBBox(), ZoomFitCrossProbeBBox(), zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and ~PCB_SELECTION_TOOL().

◆ getViewControls()

KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited

Return the instance of VIEW_CONTROLS object used in the application.

It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.).

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

43{
44 return m_toolMgr->GetViewControls();
45}
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:287

References TOOL_MANAGER::GetViewControls(), and TOOL_BASE::m_toolMgr.

Referenced by EE_POINT_EDITOR::addCorner(), PCB_POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDITOR_CONTROL::AssignNetclass(), EE_SELECTION_TOOL::autostartEvent(), SCH_EDIT_TOOL::BreakWire(), controls(), PCB_TOOL_BASE::controls(), EDIT_TOOL::copyToClipboard(), SCH_DRAWING_TOOLS::createSheetPin(), COMMON_TOOLS::CursorControl(), EDIT_TOOL::DeleteItems(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_EDITOR_CONTROL::HighlightNet(), BOARD_INSPECTION_TOOL::HighlightNet(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), EE_POINT_EDITOR::Main(), EE_SELECTION_TOOL::Main(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PICKER_TOOL::Main(), PL_EDIT_TOOL::Main(), PL_POINT_EDITOR::Main(), PCB_PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), SCH_EDITOR_CONTROL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), DRAWING_TOOL::Reset(), PCB_POINT_EDITOR::Reset(), COMMON_TOOLS::ResetLocalCoords(), ROUTER_TOOL::RouteSelected(), selectCursor(), EE_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::selectMultiple(), selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PICKER_TOOL::setControls(), PCB_PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), PCB_POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateItem(), PL_EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

◆ Go()

template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited

Define which state (aStateFunc) to go when a certain event arrives (aConditions).

No conditions means any event.

Definition at line 147 of file tool_interactive.h.

149{
150 TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
151
152 goInternal( sptr, aConditions );
153}
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58

References TOOL_INTERACTIVE::goInternal().

Referenced by EDA_3D_CONTROLLER::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), EE_POINT_EDITOR::setTransitions(), EE_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), SCH_EDIT_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SYMBOL_EDITOR_MOVE_TOOL::setTransitions(), SYMBOL_EDITOR_PIN_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), COMMON_CONTROL::setTransitions(), COMMON_TOOLS::setTransitions(), PICKER_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), PL_EDIT_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), PL_POINT_EDITOR::setTransitions(), PL_SELECTION_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), SCRIPTING_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), BOARD_REANNOTATE_TOOL::setTransitions(), CONVERT_TOOL::setTransitions(), DRAWING_TOOL::setTransitions(), DRC_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), FOOTPRINT_EDITOR_CONTROL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PAD_TOOL::setTransitions(), PCB_CONTROL::setTransitions(), PCB_PICKER_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), PROPERTIES_TOOL::setTransitions(), and ZONE_FILLER_TOOL::setTransitions().

◆ goInternal()

void TOOL_INTERACTIVE::goInternal ( TOOL_STATE_FUNC aState,
const TOOL_EVENT_LIST aConditions 
)
privateinherited

Definition at line 70 of file tool_interactive.cpp.

71{
72 m_toolMgr->ScheduleNextState( this, aState, aConditions );
73}
void ScheduleNextState(TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
Define a state transition.

References TOOL_BASE::m_toolMgr, and TOOL_MANAGER::ScheduleNextState().

Referenced by TOOL_INTERACTIVE::Go().

◆ grabUnconnected()

int PCB_SELECTION_TOOL::grabUnconnected ( const TOOL_EVENT aEvent)
private

Select and move other nearest footprint unconnected on same net as selected items.

Definition at line 1469 of file pcb_selection_tool.cpp.

1470{
1471 PCB_SELECTION originalSelection = m_selection;
1472
1473 // Get all pads
1474 std::vector<PAD*> pads;
1475
1476 for( EDA_ITEM* item : m_selection.GetItems() )
1477 {
1478 if( item->Type() == PCB_FOOTPRINT_T )
1479 {
1480 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
1481 pads.push_back( pad );
1482 }
1483 else if( item->Type() == PCB_PAD_T )
1484 {
1485 pads.push_back( static_cast<PAD*>( item ) );
1486 }
1487 }
1488
1490
1491 // Select every footprint on the end of the ratsnest for each pad in our selection
1492 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
1493
1494 for( PAD* pad : pads )
1495 {
1496 const std::vector<CN_EDGE> edges = conn->GetRatsnestForPad( pad );
1497
1498 // Need to have something unconnected to grab
1499 if( edges.size() == 0 )
1500 continue;
1501
1502 double currentDistance = DBL_MAX;
1503 FOOTPRINT* nearest = nullptr;
1504
1505 // Check every ratsnest line for the nearest one
1506 for( const CN_EDGE& edge : edges )
1507 {
1508 // Figure out if we are the source or the target node on the ratnest
1509 const CN_ANCHOR* other = edge.GetSourceNode()->Parent() == pad ? edge.GetTargetNode().get()
1510 : edge.GetSourceNode().get();
1511
1512 // We only want to grab footprints, so the ratnest has to point to a pad
1513 if( other->Parent()->Type() != PCB_PAD_T )
1514 continue;
1515
1516 if( edge.GetLength() < currentDistance )
1517 {
1518 currentDistance = edge.GetLength();
1519 nearest = static_cast<PAD*>( other->Parent() )->GetParent();
1520 }
1521 }
1522
1523 if( nearest != nullptr )
1524 select( nearest );
1525 }
1526
1528
1529 return 0;
1530}
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:424
CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via endpoint.
BOARD_CONNECTED_ITEM * Parent() const
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
static TOOL_ACTION moveIndividually
move items one-by-one
Definition: pcb_actions.h:113

References board(), ClearSelection(), BOARD::GetConnectivity(), SELECTION::GetItems(), m_selection, TOOL_BASE::m_toolMgr, PCB_ACTIONS::moveIndividually, pad, CN_ANCHOR::Parent(), PCB_FOOTPRINT_T, PCB_PAD_T, TOOL_MANAGER::RunAction(), select(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ GuessSelectionCandidates()

void PCB_SELECTION_TOOL::GuessSelectionCandidates ( GENERAL_COLLECTOR aCollector,
const VECTOR2I aWhere 
) const

Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead heuristics.

Parameters
aCollector[in, out] The collector that has a list of items to be narrowed.
aWhereThe selection point to consider.

Definition at line 2855 of file pcb_selection_tool.cpp.

2857{
2858 std::set<BOARD_ITEM*> preferred;
2859 std::set<BOARD_ITEM*> rejected;
2860 wxPoint where( aWhere.x, aWhere.y );
2861
2862 PCB_LAYER_ID activeLayer = m_frame->GetActiveLayer();
2863 LSET silkLayers( 2, B_SilkS, F_SilkS );
2864
2865 if( silkLayers[activeLayer] )
2866 {
2867 for( int i = 0; i < aCollector.GetCount(); ++i )
2868 {
2869 BOARD_ITEM* item = aCollector[i];
2870 KICAD_T type = item->Type();
2871
2872 if( ( type == PCB_TEXT_T || type == PCB_TEXTBOX_T || type == PCB_SHAPE_T )
2873 && silkLayers[item->GetLayer()] )
2874 {
2875 preferred.insert( item );
2876 }
2877 }
2878
2879 if( preferred.size() > 0 )
2880 {
2881 aCollector.Empty();
2882
2883 for( BOARD_ITEM* item : preferred )
2884 aCollector.Append( item );
2885
2886 return;
2887 }
2888 }
2889
2890 // Prefer exact hits to sloppy ones
2891 constexpr int MAX_SLOP = 5;
2892
2893 int pixel = (int) aCollector.GetGuide()->OnePixelInIU();
2894 int minSlop = INT_MAX;
2895
2896 std::map<BOARD_ITEM*, int> itemsBySloppiness;
2897
2898 for( int i = 0; i < aCollector.GetCount(); ++i )
2899 {
2900 BOARD_ITEM* item = aCollector[i];
2901 int itemSlop = hitTestDistance( where, item, MAX_SLOP * pixel );
2902
2903 itemsBySloppiness[ item ] = itemSlop;
2904
2905 if( itemSlop < minSlop )
2906 minSlop = itemSlop;
2907 }
2908
2909 // Prune sloppier items
2910 if( minSlop < INT_MAX )
2911 {
2912 for( std::pair<BOARD_ITEM*, int> pair : itemsBySloppiness )
2913 {
2914 if( pair.second > minSlop + pixel )
2915 aCollector.Transfer( pair.first );
2916 }
2917 }
2918
2919 // If the user clicked on a small item within a much larger one then it's pretty clear
2920 // they're trying to select the smaller one.
2921 constexpr double sizeRatio = 1.5;
2922
2923 std::vector<std::pair<BOARD_ITEM*, double>> itemsByArea;
2924
2925 for( int i = 0; i < aCollector.GetCount(); ++i )
2926 {
2927 BOARD_ITEM* item = aCollector[i];
2928 double area = 0.0;
2929
2930 if( ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
2931 && static_cast<ZONE*>( item )->HitTestForEdge( where, MAX_SLOP * pixel / 2 ) )
2932 {
2933 // Zone borders are very specific, so make them "small"
2934 area = MAX_SLOP * SEG::Square( pixel );
2935 }
2936 else if( item->Type() == PCB_VIA_T )
2937 {
2938 // Vias rarely hide other things, and we don't want them deferring to short track
2939 // segments underneath them -- so artificially reduce their size from πr² to 1.5r².
2940 area = SEG::Square( static_cast<PCB_VIA*>( item )->GetDrill() / 2 ) * 1.5;
2941 }
2942 else if( item->Type() == PCB_BITMAP_T )
2943 {
2944 VECTOR2D size = static_cast<const PCB_BITMAP*>( item )->GetSize();
2945 area = size.x * size.y;
2946 }
2947 else
2948 {
2949 try
2950 {
2951 area = FOOTPRINT::GetCoverageArea( item, aCollector );
2952 }
2953 catch( const ClipperLib::clipperException& e )
2954 {
2955 wxLogError( wxT( "A clipper exception %s was detected." ), e.what() );
2956 }
2957 }
2958
2959 itemsByArea.emplace_back( item, area );
2960 }
2961
2962 std::sort( itemsByArea.begin(), itemsByArea.end(),
2963 []( const std::pair<BOARD_ITEM*, double>& lhs,
2964 const std::pair<BOARD_ITEM*, double>& rhs ) -> bool
2965 {
2966 return lhs.second < rhs.second;
2967 } );
2968
2969 bool rejecting = false;
2970
2971 for( int i = 1; i < (int) itemsByArea.size(); ++i )
2972 {
2973 if( itemsByArea[i].second > itemsByArea[i-1].second * sizeRatio )
2974 rejecting = true;
2975
2976 if( rejecting )
2977 rejected.insert( itemsByArea[i].first );
2978 }
2979
2980 // Special case: if a footprint is completely covered with other features then there's no
2981 // way to select it -- so we need to leave it in the list for user disambiguation.
2982 constexpr double maxCoverRatio = 0.70;
2983
2984 for( int i = 0; i < aCollector.GetCount(); ++i )
2985 {
2986 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aCollector[i] ) )
2987 {
2988 if( footprint->CoverageRatio( aCollector ) > maxCoverRatio )
2989 rejected.erase( footprint );
2990 }
2991 }
2992
2993 // Hopefully we've now got what the user wanted.
2994 if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2995 {
2996 for( BOARD_ITEM* item : rejected )
2997 aCollector.Transfer( item );
2998 }
2999
3000 // Finally, what we are left with is a set of items of similar coverage area. We now reject
3001 // any that are not on the active layer, to reduce the number of disambiguation menus shown.
3002 // If the user wants to force-disambiguate, they can either switch layers or use the modifier
3003 // key to force the menu.
3004 if( aCollector.GetCount() > 1 )
3005 {
3006 bool haveItemOnActive = false;
3007 rejected.clear();
3008
3009 for( int i = 0; i < aCollector.GetCount(); ++i )
3010 {
3011 if( !aCollector[i]->IsOnLayer( activeLayer ) )
3012 rejected.insert( aCollector[i] );
3013 else
3014 haveItemOnActive = true;
3015 }
3016
3017 if( haveItemOnActive )
3018 for( BOARD_ITEM* item : rejected )
3019 aCollector.Transfer( item );
3020 }
3021}
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
virtual double OnePixelInIU() const =0
void Transfer(int aIndex)
Move the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:151
static double GetCoverageArea(const BOARD_ITEM *aItem, const GENERAL_COLLECTOR &aCollector)
Return the initial comments block or NULL if none, without transfer of ownership.
Definition: footprint.cpp:2016
const COLLECTORS_GUIDE * GetGuide() const
Definition: collectors.h:295
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
Object to handle a bitmap image that can be inserted in a PCB.
Definition: pcb_bitmap.h:42
int hitTestDistance(const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
static SEG::ecoord Square(int a)
Definition: seg.h:123
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
bool HitTestForEdge(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a segment defined by 2 corners.
Definition: zone.cpp:419
@ F_SilkS
Definition: layer_ids.h:104
@ B_SilkS
Definition: layer_ids.h:103
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89

References COLLECTOR::Append(), B_SilkS, COLLECTOR::Empty(), F_SilkS, PCB_BASE_FRAME::GetActiveLayer(), COLLECTOR::GetCount(), FOOTPRINT::GetCoverageArea(), GENERAL_COLLECTOR::GetGuide(), BOARD_ITEM::GetLayer(), hitTestDistance(), ZONE::HitTestForEdge(), m_frame, COLLECTORS_GUIDE::OnePixelInIU(), PCB_BITMAP_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_VIA_T, PCB_ZONE_T, SEG::Square(), COLLECTOR::Transfer(), EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_CONTROL::DeleteItemCursor(), EDIT_TOOL::Drag(), and selectPoint().

◆ highlight()

void PCB_SELECTION_TOOL::highlight ( EDA_ITEM aItem,
int  aHighlightMode,
SELECTION aGroup = nullptr 
)
overrideprivatevirtual

Highlight the item visually.

Parameters
aItemThe item to be highlighted.
aHighlightModeEither SELECTED or BRIGHTENED
aGroup[optional A group to add the item to.

Implements SELECTION_TOOL.

Definition at line 2613 of file pcb_selection_tool.cpp.

2614{
2615 if( aGroup )
2616 aGroup->Add( aItem );
2617
2618 highlightInternal( aItem, aMode, aGroup != nullptr );
2619 view()->Update( aItem, KIGFX::REPAINT );
2620
2621 // Many selections are very temporal and updating the display each time just
2622 // creates noise.
2623 if( aMode == BRIGHTENED )
2625}
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:617
void highlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50

References SELECTION::Add(), BRIGHTENED, TOOL_BASE::getView(), highlightInternal(), KIGFX::VIEW::MarkTargetDirty(), KIGFX::REPAINT, KIGFX::TARGET_OVERLAY, KIGFX::PCB_VIEW::Update(), and view().

Referenced by RebuildSelection(), RequestSelection(), and select().

◆ highlightInternal()

void PCB_SELECTION_TOOL::highlightInternal ( EDA_ITEM aItem,
int  aHighlightMode,
bool  aUsingOverlay 
)
private

Definition at line 2628 of file pcb_selection_tool.cpp.

2629{
2630 if( aMode == SELECTED )
2631 aItem->SetSelected();
2632 else if( aMode == BRIGHTENED )
2633 aItem->SetBrightened();
2634
2635 if( aUsingOverlay && aMode != BRIGHTENED )
2636 view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
2637
2638 if( aItem->Type() == PCB_FOOTPRINT_T )
2639 {
2640 static_cast<FOOTPRINT*>( aItem )->RunOnChildren(
2641 [&]( BOARD_ITEM* aChild )
2642 {
2643 highlightInternal( aChild, aMode, aUsingOverlay );
2644 } );
2645 }
2646 else if( aItem->Type() == PCB_GROUP_T )
2647 {
2648 static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
2649 [&]( BOARD_ITEM* aChild )
2650 {
2651 highlightInternal( aChild, aMode, aUsingOverlay );
2652 } );
2653 }
2654}
void SetSelected()
Definition: eda_item.h:118
void SetBrightened()
Definition: eda_item.h:119

References BRIGHTENED, KIGFX::VIEW::Hide(), highlightInternal(), PCB_FOOTPRINT_T, PCB_GROUP_T, SELECTED, EDA_ITEM::SetBrightened(), EDA_ITEM::SetSelected(), EDA_ITEM::Type(), and view().

Referenced by highlight(), and highlightInternal().

◆ hitTestDistance()

int PCB_SELECTION_TOOL::hitTestDistance ( const wxPoint &  aWhere,
BOARD_ITEM aItem,
int  aMaxDistance 
) const
private
Returns
the distance from wWhere to aItem, up to and including aMaxDistance.

Definition at line 2736 of file pcb_selection_tool.cpp.

2738{
2739 BOX2D viewportD = getView()->GetViewport();
2740 BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2741 int distance = INT_MAX;
2742 SEG loc( aWhere, aWhere );
2743
2744 switch( aItem->Type() )
2745 {
2746 case PCB_TEXT_T:
2747 {
2748 PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
2749 text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2750 break;
2751 }
2752
2753 case PCB_TEXTBOX_T:
2754 {
2755 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( aItem );
2756 textbox->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2757 break;
2758 }
2759
2760 case PCB_FP_TEXT_T:
2761 {
2762 FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
2763 text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2764 break;
2765 }
2766
2767 case PCB_FP_TEXTBOX_T:
2768 {
2769 FP_TEXTBOX* textbox = static_cast<FP_TEXTBOX*>( aItem );
2770 textbox->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2771 break;
2772 }
2773
2774 case PCB_ZONE_T:
2775 {
2776 ZONE* zone = static_cast<ZONE*>( aItem );
2777
2778 // Zone borders are very specific
2779 if( zone->HitTestForEdge( aWhere, aMaxDistance / 2 ) )
2780 distance = 0;
2781 else if( zone->HitTestForEdge( aWhere, aMaxDistance ) )
2782 distance = aMaxDistance / 2;
2783 else
2784 aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
2785
2786 break;
2787 }
2788
2789 case PCB_FOOTPRINT_T:
2790 {
2791 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
2792 BOX2I bbox = footprint->GetBoundingBox( false, false );
2793
2794 try
2795 {
2796 footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance );
2797 }
2798 catch( const ClipperLib::clipperException& exc )
2799 {
2800 // This may be overkill and could be an assertion but we are more likely to find
2801 // any clipper errors this way.
2802 wxLogError( wxT( "Clipper library exception '%s' occurred." ), exc.what() );
2803 }
2804
2805 // Consider footprints larger than the viewport only as a last resort
2806 if( bbox.GetHeight() > viewport.GetHeight() || bbox.GetWidth() > viewport.GetWidth() )
2807 distance = INT_MAX / 2;
2808
2809 break;
2810 }
2811
2812 case PCB_MARKER_T:
2813 {
2814 PCB_MARKER* marker = static_cast<PCB_MARKER*>( aItem );
2815 SHAPE_LINE_CHAIN polygon;
2816
2817 marker->ShapeToPolygon( polygon );
2818 polygon.Move( marker->GetPos() );
2819 polygon.Collide( loc, aMaxDistance, &distance );
2820 break;
2821 }
2822
2823 case PCB_GROUP_T:
2824 {
2825 PCB_GROUP* group = static_cast<PCB_GROUP*>( aItem );
2826
2827 for( BOARD_ITEM* member : group->GetItems() )
2828 distance = std::min( distance, hitTestDistance( aWhere, member, aMaxDistance ) );
2829
2830 break;
2831 }
2832
2833 default:
2834 aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
2835 break;
2836 }
2837
2838 return distance;
2839}
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:219
const Vec & GetPosition() const
Definition: box2.h:184
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, bool aUseTextRotation=true) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
Definition: eda_text.cpp:853
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
Definition: footprint.cpp:925
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:794
const VECTOR2I & GetPos() const
Definition: marker_base.h:87
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
Definition: seg.h:42
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References SHAPE_POLY_SET::Collide(), SHAPE_LINE_CHAIN::Collide(), distance(), FOOTPRINT::GetBoundingBox(), FOOTPRINT::GetBoundingHull(), BOARD_ITEM::GetEffectiveShape(), EDA_TEXT::GetEffectiveTextShape(), BOX2< Vec >::GetHeight(), MARKER_BASE::GetPos(), BOX2< Vec >::GetPosition(), BOX2< Vec >::GetSize(), TOOL_BASE::getView(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), group, hitTestDistance(), ZONE::HitTestForEdge(), SHAPE_LINE_CHAIN::Move(), PCB_FOOTPRINT_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_GROUP_T, PCB_MARKER_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_ZONE_T, MARKER_BASE::ShapeToPolygon(), text, and EDA_ITEM::Type().

Referenced by GuessSelectionCandidates(), and hitTestDistance().

◆ Init()

bool PCB_SELECTION_TOOL::Init ( )
overridevirtual

Init() is called once upon a registration of the tool.

Returns
True if the initialization went fine, false - otherwise.

Reimplemented from TOOL_BASE.

Definition at line 145 of file pcb_selection_tool.cpp.

146{
147 PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
148
151 {
153 return true;
154 }
155
156 std::shared_ptr<SELECT_MENU> selectMenu = std::make_shared<SELECT_MENU>();
157 selectMenu->SetTool( this );
158 m_menu.RegisterSubMenu( selectMenu );
159
160 auto& menu = m_menu.GetMenu();
161
162 auto activeToolCondition =
163 [ frame ] ( const SELECTION& aSel )
164 {
165 return !frame->ToolStackIsEmpty();
166 };
167
168 auto haveHighlight =
169 [&]( const SELECTION& sel )
170 {
172
173 return !cfg->GetHighlightNetCodes().empty();
174 };
175
176 auto groupEnterCondition =
178
179 auto inGroupCondition =
180 [this] ( const SELECTION& )
181 {
182 return m_enteredGroup != nullptr;
183 };
184
186 {
187 menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
188 menu.AddSeparator( 1000 );
189 }
190
191 // "Cancel" goes at the top of the context menu when a tool is active
192 menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
193 menu.AddItem( PCB_ACTIONS::groupEnter, groupEnterCondition, 1 );
194 menu.AddItem( PCB_ACTIONS::groupLeave, inGroupCondition, 1 );
195 menu.AddItem( PCB_ACTIONS::clearHighlight, haveHighlight, 1 );
196
197 menu.AddSeparator( 1 );
198
199 if( frame )
201
202 m_disambiguateTimer.SetOwner( this );
203 Connect( wxEVT_TIMER, wxTimerEventHandler( PCB_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
204
205 return true;
206}
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
bool IsType(FRAME_T aType) const
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
static TOOL_ACTION groupLeave
Definition: pcb_actions.h:478
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:496
static TOOL_ACTION groupEnter
Definition: pcb_actions.h:477
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:80
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
wxTimer m_disambiguateTimer
bool ToolStackIsEmpty()
Definition: tools_holder.h:128
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
void RegisterSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Store a submenu of this menu model.
Definition: tool_menu.cpp:50
@ FRAME_PCB_EDITOR
Definition: frame_type.h:40
@ FRAME_FOOTPRINT_VIEWER_MODAL
Definition: frame_type.h:43
@ FRAME_FOOTPRINT_VIEWER
Definition: frame_type.h:42

References PCB_GROUP::AddItem(), EDA_DRAW_FRAME::AddStandardSubMenus(), ACTIONS::cancelInteractive, PCB_ACTIONS::clearHighlight, SELECTION_CONDITIONS::Count(), frame(), FRAME_FOOTPRINT_VIEWER, FRAME_FOOTPRINT_VIEWER_MODAL, FRAME_PCB_EDITOR, KIGFX::RENDER_SETTINGS::GetHighlightNetCodes(), TOOL_MENU::GetMenu(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetView(), PCB_ACTIONS::groupEnter, PCB_ACTIONS::groupLeave, SELECTION_CONDITIONS::HasType(), EDA_BASE_FRAME::IsType(), SELECTION_TOOL::m_disambiguateTimer, m_enteredGroup, TOOL_INTERACTIVE::m_menu, TOOL_BASE::m_toolMgr, SELECTION_CONDITIONS::NotEmpty(), SELECTION_TOOL::onDisambiguationExpire(), PCB_GROUP_T, TOOL_MENU::RegisterSubMenu(), and TOOLS_HOLDER::ToolStackIsEmpty().

◆ IsFootprintEditor()

bool PCB_SELECTION_TOOL::IsFootprintEditor ( )
inline

Definition at line 78 of file pcb_selection_tool.h.

79 {
81 }

References m_isFootprintEditor.

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

32{
34}
bool IsToolActive(TOOL_ID aId) const
Return true if a tool with given id is active (executing)

References TOOL_MANAGER::IsToolActive(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

Referenced by EDIT_TOOL::Drag(), ROUTER_TOOL::handleLayerSwitch(), Main(), BOARD_EDITOR_CONTROL::TrackWidthDec(), and BOARD_EDITOR_CONTROL::TrackWidthInc().

◆ itemPassesFilter()

bool PCB_SELECTION_TOOL::itemPassesFilter ( BOARD_ITEM aItem,
bool  aMultiSelect 
)
private

Definition at line 2158 of file pcb_selection_tool.cpp.

2159{
2160 if( !m_filter.lockedItems )
2161 {
2162 if( aItem->IsLocked() || ( aItem->GetParent() && aItem->GetParent()->IsLocked() ) )
2163 {
2164 if( aItem->Type() == PCB_PAD_T && !aMultiSelect )
2165 {
2166 // allow a single pad to be selected -- there are a lot of operations that
2167 // require this so we allow this one inconsistency
2168 }
2169 else
2170 {
2171 return false;
2172 }
2173 }
2174 }
2175
2176 switch( aItem->Type() )
2177 {
2178 case PCB_FOOTPRINT_T:
2179 if( !m_filter.footprints )
2180 return false;
2181
2182 break;
2183
2184 case PCB_PAD_T:
2185 if( !m_filter.pads )
2186 return false;
2187
2188 break;
2189
2190 case PCB_TRACE_T:
2191 case PCB_ARC_T:
2192 if( !m_filter.tracks )
2193 return false;
2194
2195 break;
2196
2197 case PCB_VIA_T:
2198 if( !m_filter.vias )
2199 return false;
2200
2201 break;
2202
2203 case PCB_FP_ZONE_T:
2204 case PCB_ZONE_T:
2205 {
2206 ZONE* zone = static_cast<ZONE*>( aItem );
2207
2208 if( ( !m_filter.zones && !zone->GetIsRuleArea() )
2209 || ( !m_filter.keepouts && zone->GetIsRuleArea() ) )
2210 {
2211 return false;
2212 }
2213
2214 break;
2215 }
2216
2217 case PCB_FP_SHAPE_T:
2218 case PCB_SHAPE_T:
2219 case PCB_TARGET_T:
2220 case PCB_BITMAP_T:
2221 if( !m_filter.graphics )
2222 return false;
2223
2224 break;
2225
2226 case PCB_FP_TEXT_T:
2227 case PCB_FP_TEXTBOX_T:
2228 case PCB_TEXT_T:
2229 case PCB_TEXTBOX_T:
2230 if( !m_filter.text )
2231 return false;
2232
2233 break;
2234
2235 case PCB_DIM_ALIGNED_T:
2236 case PCB_DIM_CENTER_T:
2237 case PCB_DIM_RADIAL_T:
2239 case PCB_DIM_LEADER_T:
2245 if( !m_filter.dimensions )
2246 return false;
2247
2248 break;
2249
2250 default:
2251 if( !m_filter.otherItems )
2252 return false;
2253 }
2254
2255 return true;
2256}
virtual bool IsLocked() const
Definition: board_item.cpp:71
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
@ PCB_FP_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:95
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:110
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:111
@ PCB_FP_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:99
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:106
@ PCB_FP_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:98
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:109

References SELECTION_FILTER_OPTIONS::dimensions, SELECTION_FILTER_OPTIONS::footprints, ZONE::GetIsRuleArea(), BOARD_ITEM::GetParent(), SELECTION_FILTER_OPTIONS::graphics, BOARD_ITEM::IsLocked(), SELECTION_FILTER_OPTIONS::keepouts, SELECTION_FILTER_OPTIONS::lockedItems, m_filter, SELECTION_FILTER_OPTIONS::otherItems, SELECTION_FILTER_OPTIONS::pads, PCB_ARC_T, PCB_BITMAP_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_DIM_RADIAL_T, PCB_FOOTPRINT_T, PCB_FP_DIM_ALIGNED_T, PCB_FP_DIM_CENTER_T, PCB_FP_DIM_LEADER_T, PCB_FP_DIM_ORTHOGONAL_T, PCB_FP_DIM_RADIAL_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_ZONE_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, SELECTION_FILTER_OPTIONS::text, SELECTION_FILTER_OPTIONS::tracks, EDA_ITEM::Type(), SELECTION_FILTER_OPTIONS::vias, and SELECTION_FILTER_OPTIONS::zones.

Referenced by FilterCollectedItems(), SelectAll(), and SelectAllItemsOnNet().

◆ Main()

int PCB_SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

The main loop.

Definition at line 263 of file pcb_selection_tool.cpp.

264{
265 // Main loop: keep receiving events
266 while( TOOL_EVENT* evt = Wait() )
267 {
270
271 // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
272 setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
273 evt->Modifier( MD_ALT ) );
274
275 bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
276 PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
277 bool brd_editor = frame && frame->IsType( FRAME_PCB_EDITOR );
279
280 // If the router tool is active, don't override
281 if( router && router->IsToolActive() && router->RoutingInProgress() )
282 {
283 evt->SetPassEvent();
284 }
285 else if( evt->IsMouseDown( BUT_LEFT ) )
286 {
287 // Avoid triggering when running under other tools
289
290 if( m_frame->ToolStackIsEmpty() && pt_tool && !pt_tool->HasPoint() )
291 {
293 m_disambiguateTimer.StartOnce( 500 );
294 }
295 }
296 else if( evt->IsClick( BUT_LEFT ) )
297 {
298 // If there is no disambiguation, this routine is still running and will
299 // register a `click` event when released
300 if( m_disambiguateTimer.IsRunning() )
301 {
302 m_disambiguateTimer.Stop();
303
304 // Single click? Select single object
305 if( m_highlight_modifier && brd_editor )
306 {
308 }
309 else
310 {
311 m_frame->FocusOnItem( nullptr );
312 selectPoint( evt->Position() );
313 }
314 }
315
316 m_canceledMenu = false;
317 }
318 else if( evt->IsClick( BUT_RIGHT ) )
319 {
320 m_disambiguateTimer.Stop();
321
322 // Right click? if there is any object - show the context menu
323 bool selectionCancelled = false;
324
325 if( m_selection.Empty() )
326 {
327 selectPoint( evt->Position(), false, &selectionCancelled );
328 m_selection.SetIsHover( true );
329 }
330
331 if( !selectionCancelled )
333 }
334 else if( evt->IsDblClick( BUT_LEFT ) )
335 {
336 m_disambiguateTimer.Stop();
337
338 // Double click? Display the properties window
339 m_frame->FocusOnItem( nullptr );
340
341 if( m_selection.Empty() )
342 selectPoint( evt->Position() );
343
344 if( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T )
345 EnterGroup();
346 else
348 }
349 else if( evt->IsDblClick( BUT_MIDDLE ) )
350 {
351 // Middle double click? Do zoom to fit or zoom to objects
352 if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
354 else
356 }
357 else if( evt->IsDrag( BUT_LEFT ) )
358 {
359 m_disambiguateTimer.Stop();
360
361 // Is another tool already moving a new object? Don't allow a drag start
362 if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
363 {
364 evt->SetPassEvent();
365 continue;
366 }
367
368 // Drag with LMB? Select multiple objects (or at least draw a selection box)
369 // or drag them
370 m_frame->FocusOnItem( nullptr );
372
373 if( modifier_enabled || dragAction == MOUSE_DRAG_ACTION::SELECT )
374 {
376 }
377 else if( m_selection.Empty() && dragAction != MOUSE_DRAG_ACTION::DRAG_ANY )
378 {
380 }
381 else
382 {
383 // Don't allow starting a drag from a zone filled area that isn't already selected
384 auto zoneFilledAreaFilter =
385 []( const VECTOR2I& aWhere, GENERAL_COLLECTOR& aCollector,
386 PCB_SELECTION_TOOL* aTool )
387 {
388 VECTOR2I location = aWhere;
389 int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
390 std::set<EDA_ITEM*> remove;
391
392 for( EDA_ITEM* item : aCollector )
393 {
394 if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
395 {
396 ZONE* zone = static_cast<ZONE*>( item );
397
398 if( !zone->HitTestForCorner( location, accuracy * 2 )
399 && !zone->HitTestForEdge( location, accuracy ) )
400 {
401 remove.insert( zone );
402 }
403 }
404 }
405
406 for( EDA_ITEM* item : remove )
407 aCollector.Remove( item );
408 };
409
410 // See if we can drag before falling back to selectMultiple()
411 bool doDrag = false;
412
413 if( evt->HasPosition() )
414 {
415 if( m_selection.Empty()
416 && selectPoint( evt->DragOrigin(), false, nullptr, zoneFilledAreaFilter ) )
417 {
418 m_selection.SetIsHover( true );
419 doDrag = true;
420 }
421 // Check if dragging has started within any of selected items bounding box.
422 else if( selectionContains( evt->DragOrigin() ) )
423 {
424 doDrag = true;
425 }
426 }
427
428 if( doDrag )
429 {
430 bool haveTrack = m_selection.GetSize() == 1
431 && dynamic_cast<PCB_TRACK*>( m_selection.GetItem( 0 ) );
432
433 if( haveTrack && trackDragAction == TRACK_DRAG_ACTION::DRAG )
435 else if( haveTrack && trackDragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
437 else
439 }
440 else
441 {
442 // Otherwise drag a selection box
444 }
445 }
446 }
447 else if( evt->IsCancel() )
448 {
449 m_disambiguateTimer.Stop();
450 m_frame->FocusOnItem( nullptr );
451
452 if( !GetSelection().Empty() )
453 {
455 }
456 else if( evt->FirstResponder() == this && evt->GetCommandId() == (int) WXK_ESCAPE )
457 {
458 if( m_enteredGroup )
459 {
460 ExitGroup();
461 }
462 else
463 {
465
467 controller->ClearHighlight( *evt );
468 }
469 }
470 }
471 else
472 {
473 evt->SetPassEvent();
474 }
475
476
478 {
479 // move cursor prediction
480 if( !modifier_enabled
481 && dragAction == MOUSE_DRAG_ACTION::DRAG_SELECTED
482 && !m_selection.Empty()
483 && evt->HasPosition()
484 && selectionContains( evt->Position() ) )
485 {
487 }
488 else
489 {
491 }
492 }
493 }
494
495 // Shutting down; clear the selection
497 m_disambiguateTimer.Stop();
498
499 return 0;
500}
static TOOL_ACTION zoomFitScreen
Definition: actions.h:98
static TOOL_ACTION zoomFitObjects
Definition: actions.h:99
Tool for pcb inspection.
int ClearHighlight(const TOOL_EVENT &aEvent)
Perform the appropriate action in response to an Eeschema cross-probe.
static const TOOL_EVENT InhibitSelectionEditing
Definition: actions.h:219
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:204
TRACK_DRAG_ACTION m_TrackDragAction
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:166
static TOOL_ACTION highlightNet
Definition: pcb_actions.h:497
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:149
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:167
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:110
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Tool that displays edit points allowing to modify items by dragging the points.
bool HasPoint()
Indicate the cursor is over an edit point.
The selection tool: currently supports:
bool selectionContains(const VECTOR2I &aPoint) const
void EnterGroup()
Enter the group at the head of the current selection.
PCB_SELECTION & GetSelection()
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
bool RoutingInProgress()
Returns whether routing is currently active.
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:65
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:90
MOUSE_DRAG_ACTION GetDragAction() const
Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) objects.
Definition: tools_holder.h:147
bool IsToolActive() const
Definition: tool_base.cpp:31
VECTOR2D GetMousePosition() const
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:57
bool HitTestForCorner(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a corner.
Definition: zone.cpp:412
MOUSE_DRAG_ACTION
#define IS_NEW
New item, just created.
#define IS_MOVING
Item being moved.
TRACK_DRAG_ACTION
@ MD_ALT
Definition: tool_event.h:140
@ MD_CTRL
Definition: tool_event.h:139
@ MD_SHIFT
Definition: tool_event.h:138
@ BUT_MIDDLE
Definition: tool_event.h:129
@ BUT_LEFT
Definition: tool_event.h:127
@ BUT_RIGHT
Definition: tool_event.h:128
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References ARROW, BUT_LEFT, BUT_MIDDLE, BUT_RIGHT, SELECTION::Clear(), BOARD_INSPECTION_TOOL::ClearHighlight(), ClearSelection(), DRAG, PCB_ACTIONS::drag45Degree, DRAG_ANY, DRAG_FREE_ANGLE, DRAG_SELECTED, PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), EnterGroup(), ExitGroup(), PCB_BASE_FRAME::FocusOnItem(), frame(), FRAME_PCB_EDITOR, TOOLS_HOLDER::GetDragAction(), SELECTION::GetItem(), TOOL_MANAGER::GetMousePosition(), PCB_BASE_FRAME::GetPcbNewSettings(), GetSelection(), SELECTION::GetSize(), TOOL_MANAGER::GetTool(), PCB_POINT_EDITOR::HasPoint(), PCB_ACTIONS::highlightNet, ZONE::HitTestForCorner(), ZONE::HitTestForEdge(), EVENTS::InhibitSelectionEditing, IS_MOVING, IS_NEW, TOOL_BASE::IsToolActive(), EDA_BASE_FRAME::IsType(), KiROUND(), SELECTION_TOOL::m_additive, SELECTION_TOOL::m_canceledMenu, SELECTION_TOOL::m_disambiguateTimer, m_enteredGroup, PCBNEW_SETTINGS::m_ESCClearsNetHighlight, SELECTION_TOOL::m_exclusive_or, m_frame, SELECTION_TOOL::m_highlight_modifier, TOOL_INTERACTIVE::m_menu, m_nonModifiedCursor, SELECTION_TOOL::m_originalCursor, m_selection, SELECTION_TOOL::m_subtractive, TOOL_BASE::m_toolMgr, PCBNEW_SETTINGS::m_TrackDragAction, MD_ALT, MD_CTRL, MD_SHIFT, PCB_ACTIONS::move, MOVING, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_ZONE_T, TOOL_MANAGER::ProcessEvent(), PCB_ACTIONS::properties, ROUTER_TOOL::RoutingInProgress(), TOOL_MANAGER::RunAction(), SELECT, selectionContains(), selectMultiple(), selectPoint(), SELECTION::SetIsHover(), SELECTION_TOOL::setModifiersState(), TOOL_MENU::ShowContextMenu(), TOOLS_HOLDER::ToolStackIsEmpty(), TOOL_INTERACTIVE::Wait(), ACTIONS::zoomFitObjects, and ACTIONS::zoomFitScreen.

Referenced by setTransitions().

◆ onDisambiguationExpire()

void SELECTION_TOOL::onDisambiguationExpire ( wxTimerEvent &  aEvent)
protectedinherited

Start the process to show our disambiguation menu once the user has kept the mouse down for the minimum time.

Parameters
aEvent

Definition at line 213 of file selection_tool.cpp.

214{
215 // If there is a multiple selection then it's more likely that we're seeing a paused drag
216 // than a long-click.
217 if( selection().GetSize() >= 2 )
218 return;
219
220 // If another tool has since started running then we don't want to interrupt
221 if( !getEditFrame<EDA_DRAW_FRAME>()->ToolStackIsEmpty() )
222 return;
223
225}
static const TOOL_EVENT DisambiguatePoint
Definition: actions.h:223

References EVENTS::DisambiguatePoint, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), and SELECTION_TOOL::selection().

Referenced by EE_SELECTION_TOOL::Init(), PL_SELECTION_TOOL::Init(), Init(), and ~PCB_SELECTION_TOOL().

◆ OnIdle()

void PCB_SELECTION_TOOL::OnIdle ( wxIdleEvent &  aEvent)

Definition at line 242 of file pcb_selection_tool.cpp.

243{
245 {
246 wxMouseState keyboardState = wxGetMouseState();
247
248 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
249 keyboardState.AltDown() );
250
251 if( m_additive )
253 else if( m_subtractive )
255 else if( m_exclusive_or )
257 else
259 }
260}
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.

References ADD, PCB_BASE_FRAME::GetCanvas(), SELECTION_TOOL::m_additive, SELECTION_TOOL::m_exclusive_or, m_frame, SELECTION_TOOL::m_multiple, m_nonModifiedCursor, SELECTION_TOOL::m_subtractive, EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION_TOOL::setModifiersState(), SUBTRACT, TOOLS_HOLDER::ToolStackIsEmpty(), and XOR.

Referenced by PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME().

◆ RebuildSelection()

void PCB_SELECTION_TOOL::RebuildSelection ( )

Rebuild the selection from the EDA_ITEMs' selection flags.

Commonly called after rolling back an undo state to make sure there aren't any stale pointers.

Definition at line 2281 of file pcb_selection_tool.cpp.

2282{
2284
2285 bool enteredGroupFound = false;
2286
2287 INSPECTOR_FUNC inspector =
2288 [&]( EDA_ITEM* item, void* testData )
2289 {
2290 if( item->IsSelected() )
2291 {
2292 EDA_ITEM* parent = item->GetParent();
2293
2294 // Let selected parents handle their children.
2295 if( parent && parent->IsSelected() )
2297
2298 highlight( item, SELECTED, &m_selection );
2299 }
2300
2301 if( item == m_enteredGroup )
2302 {
2303 item->SetFlags( ENTERED );
2304 enteredGroupFound = true;
2305 }
2306 else
2307 {
2308 item->ClearFlags( ENTERED );
2309 }
2310
2312 };
2313
2316
2317 if( !enteredGroupFound )
2318 {
2320 m_enteredGroup = nullptr;
2321 }
2322}
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: board.cpp:1291
bool IsSelected() const
Definition: eda_item.h:107
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition: collectors.h:224
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition: collectors.h:250
void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
std::function< INSPECT_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition: eda_item.h:75

References GENERAL_COLLECTOR::AllBoardItems, board(), KIGFX::VIEW_GROUP::Clear(), SELECTION::Clear(), EDA_ITEM::ClearFlags(), CONTINUE, ENTERED, GENERAL_COLLECTOR::FootprintItems, EDA_ITEM::GetParent(), highlight(), EDA_ITEM::IsSelected(), m_enteredGroup, m_enteredGroupOverlay, m_isFootprintEditor, m_selection, SELECTED, EDA_ITEM::SetFlags(), and BOARD::Visit().

Referenced by EDIT_TOOL::doMoveSelection(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), and BOARD_COMMIT::Revert().

◆ RemoveItemFromSel() [1/2]

◆ RemoveItemFromSel() [2/2]

void SELECTION_TOOL::RemoveItemFromSel ( EDA_ITEM aItem,
bool  aQuietMode = false 
)
inherited

Definition at line 152 of file selection_tool.cpp.

153{
154 if( aItem )
155 {
156 unselect( aItem );
157
158 // Inform other potentially interested tools
159 if( !aQuietMode )
161 }
162}
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
virtual void unselect(EDA_ITEM *aItem)=0
Take necessary action mark an item as unselected.

References TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), SELECTION_TOOL::unselect(), and EVENTS::UnselectedEvent.

◆ RemoveItemsFromSel() [1/3]

int SELECTION_TOOL::RemoveItemsFromSel ( const TOOL_EVENT aEvent)
inherited

◆ RemoveItemsFromSel() [2/3]

void SELECTION_TOOL::RemoveItemsFromSel ( EDA_ITEMS aList,
bool  aQuietMode = false 
)
inherited

Definition at line 173 of file selection_tool.cpp.

174{
175 if( aList )
176 {
177 for( EDA_ITEM* item : *aList )
178 unselect( item );
179
180 // Inform other potentially interested tools
181 if( !aQuietMode )
183 }
184}

References TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), SELECTION_TOOL::unselect(), and EVENTS::UnselectedEvent.

◆ RemoveItemsFromSel() [3/3]

void SELECTION_TOOL::RemoveItemsFromSel ( std::vector< KIID > *  aList,
bool  aQuietMode = false 
)
inherited

A safer version of RemoveItemsFromSel( EDA_ITEMS ) which doesn't require the items to still exist.

Definition at line 187 of file selection_tool.cpp.

188{
189 EDA_ITEMS removeItems;
190
191 for( EDA_ITEM* item : selection() )
192 {
193 if( alg::contains( *aList, item->m_Uuid ) )
194 removeItems.push_back( item );
195 }
196
197 RemoveItemsFromSel( &removeItems, aQuietMode );
198}
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99

References alg::contains(), SELECTION_TOOL::RemoveItemsFromSel(), and SELECTION_TOOL::selection().

◆ RequestSelection()

PCB_SELECTION & PCB_SELECTION_TOOL::RequestSelection ( CLIENT_SELECTION_FILTER  aClientFilter,
bool  aConfirmLockedItems = false 
)

Return the current selection, filtered according to aClientFilter.

If the set is empty, performs the legacy-style hover selection.

Parameters
aClientFilterA callback to allow tool- or action-specific filtering.
aConfirmLockedItems[optional] Signals that the user shall be asked if they want to drop locked items from the selection or override the locks. Select a single item under cursor event handler.

Definition at line 556 of file pcb_selection_tool.cpp.

558{
559 bool selectionEmpty = m_selection.Empty();
560 m_selection.SetIsHover( selectionEmpty );
561
562 if( selectionEmpty )
563 {
564 m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
566 }
567
568 if( aClientFilter )
569 {
570 enum DISPOSITION { BEFORE = 1, AFTER, BOTH };
571
572 std::map<EDA_ITEM*, DISPOSITION> itemDispositions;
574 GENERAL_COLLECTOR collector;
575
576 collector.SetGuide( &guide );
577
578 for( EDA_ITEM* item : m_selection )
579 {
580 collector.Append( item );
581 itemDispositions[ item ] = BEFORE;
582 }
583
584 aClientFilter( VECTOR2I(), collector, this );
585
586 for( EDA_ITEM* item : collector )
587 {
588 if( itemDispositions.count( item ) )
589 itemDispositions[ item ] = BOTH;
590 else
591 itemDispositions[ item ] = AFTER;
592 }
593
594 // Unhighlight the BEFORE items before highlighting the AFTER items.
595 // This is so that in the case of groups, if aClientFilter replaces a selection
596 // with the enclosing group, the unhighlight of the element doesn't undo the
597 // recursive highlighting of that element by the group.
598
599 for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
600 {
601 EDA_ITEM* item = itemDisposition.first;
602 DISPOSITION disposition = itemDisposition.second;
603
604 if( disposition == BEFORE )
606 }
607
608 for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
609 {
610 EDA_ITEM* item = itemDisposition.first;
611 DISPOSITION disposition = itemDisposition.second;
612
613 // Note that we must re-highlight even previously-highlighted items
614 // (ie: disposition BOTH) in case we removed any of their children.
615 if( disposition == AFTER || disposition == BOTH )
616 highlight( item, SELECTED, &m_selection );
617 }
618
620 }
621
622 if( aConfirmLockedItems )
623 {
624 std::vector<BOARD_ITEM*> lockedItems;
625
626 for( EDA_ITEM* item : m_selection )
627 {
628 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
629
630 if( boardItem->Type() == PCB_GROUP_T )
631 {
632 PCB_GROUP* group = static_cast<PCB_GROUP*>( boardItem );
633 bool lockedDescendant = false;
634
635 group->RunOnDescendants(
636 [&lockedDescendant]( BOARD_ITEM* child )
637 {
638 if( child->IsLocked() )
639 lockedDescendant = true;
640 } );
641
642 if( lockedDescendant )
643 lockedItems.push_back( group );
644 }
645 else if( boardItem->IsLocked() )
646 {
647 lockedItems.push_back( boardItem );
648 }
649 }
650
651 if( !lockedItems.empty() )
652 {
653 DIALOG_LOCKED_ITEMS_QUERY dlg( frame(), lockedItems.size() );
654
655 switch( dlg.ShowModal() )
656 {
657 case wxID_OK:
658 // remove locked items from selection
659 for( BOARD_ITEM* item : lockedItems )
660 unselect( item );
661
662 break;
663
664 case wxID_CANCEL:
665 // cancel operation
667 break;
668
669 case wxID_APPLY:
670 // continue with operation with current selection
671 break;
672 }
673 }
674 }
675
676 return m_selection;
677}
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition: collectors.h:293
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:56
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
void unselect(EDA_ITEM *aItem) override
Take necessary action mark an item as unselected.

References COLLECTOR::Append(), SELECTION::ClearReferencePoint(), ClearSelection(), SELECTION::Empty(), EDA_DRAW_PANEL_GAL::ForceRefresh(), frame(), PCB_BASE_FRAME::GetCanvas(), getCollectorsGuide(), group, highlight(), BOARD_ITEM::IsLocked(), m_frame, m_selection, TOOL_BASE::m_toolMgr, PCB_GROUP_T, TOOL_MANAGER::RunAction(), SELECTED, PCB_ACTIONS::selectionCursor, GENERAL_COLLECTOR::SetGuide(), SELECTION::SetIsHover(), DIALOG_LOCKED_ITEMS_QUERY::ShowModal(), EDA_ITEM::Type(), unhighlight(), and unselect().

Referenced by BOARD_EDITOR_CONTROL::AssignNetclass(), EDIT_TOOL::ChangeTrackWidth(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), CONVERT_TOOL::CreateLines(), CONVERT_TOOL::CreatePolys(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Drag(), EDIT_TOOL::Duplicate(), BOARD_EDITOR_CONTROL::EditFpInFpEditor(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::FilletLines(), EDIT_TOOL::FilletTracks(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), GROUP_TOOL::Group(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), EDIT_TOOL::PackAndMoveFootprints(), GROUP_TOOL::PickNewMember(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), CONVERT_TOOL::SegmentToArc(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), and EDIT_TOOL::Swap().

◆ Reset()

void PCB_SELECTION_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Bring the tool to a known, initial state.

If the tool claimed anything from the model or the view, it must release it when its reset.

Parameters
aReasoncontains information about the reason of tool reset.

Implements TOOL_BASE.

Definition at line 209 of file pcb_selection_tool.cpp.

210{
211 m_frame = getEditFrame<PCB_BASE_FRAME>();
213
214 if( m_enteredGroup )
215 ExitGroup();
216
217 if( aReason == TOOL_BASE::MODEL_RELOAD )
218 {
219 // Deselect any item being currently in edit, to avoid unexpected behavior
220 // and remove pointers to the selected items from containers
221 // without changing their properties (as they are already deleted
222 // while a new board is loaded)
223 ClearSelection( true );
224
225 getView()->GetPainter()->GetSettings()->SetHighlight( false );
226 }
227 else
228 {
229 // Restore previous properties of selected items and remove them from containers
230 ClearSelection( true );
231 }
232
233 // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
234 view()->Remove( &m_selection );
235 view()->Add( &m_selection );
236
239}
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:41

References KIGFX::PCB_VIEW::Add(), ClearSelection(), ExitGroup(), FRAME_FOOTPRINT_EDITOR, KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), EDA_BASE_FRAME::IsType(), m_enteredGroup, m_enteredGroupOverlay, m_frame, m_isFootprintEditor, m_selection, TOOL_BASE::MODEL_RELOAD, KIGFX::PCB_VIEW::Remove(), KIGFX::RENDER_SETTINGS::SetHighlight(), and view().

◆ resetTransitions()

void TOOL_INTERACTIVE::resetTransitions ( )
privateinherited

Clear the current transition map and restores the default one created by setTransitions().

Definition at line 63 of file tool_interactive.cpp.

64{
67}
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
void ClearTransitions(TOOL_BASE *aTool)
Clear the state transition map for a tool.

References TOOL_MANAGER::ClearTransitions(), TOOL_BASE::m_toolMgr, and TOOL_INTERACTIVE::setTransitions().

◆ RunMainStack()

void TOOL_INTERACTIVE::RunMainStack ( std::function< void()>  aFunc)
inherited

Call a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 87 of file tool_interactive.cpp.

88{
89 m_toolMgr->RunMainStack( this, std::move( aFunc ) );
90}
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)

References TOOL_BASE::m_toolMgr, and TOOL_MANAGER::RunMainStack().

Referenced by DRAWING_TOOL::PlaceText().

◆ select()

void PCB_SELECTION_TOOL::select ( EDA_ITEM aItem)
overridevirtual

Take necessary action mark an item as selected.

Parameters
aItemThe item to be selected.

Implements SELECTION_TOOL.

Definition at line 2590 of file pcb_selection_tool.cpp.

2591{
2592 if( aItem->IsSelected() )
2593 return;
2594
2595 if( aItem->Type() == PCB_PAD_T )
2596 {
2597 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
2598
2599 if( m_selection.Contains( footprint ) )
2600 return;
2601 }
2602
2603 highlight( aItem, SELECTED, &m_selection );
2604}
bool Contains(EDA_ITEM *aItem) const
Definition: selection.cpp:74

References SELECTION::Contains(), EDA_ITEM::GetParent(), highlight(), EDA_ITEM::IsSelected(), m_selection, PCB_PAD_T, SELECTED, and EDA_ITEM::Type().

Referenced by doSyncSelection(), EnterGroup(), ExitGroup(), filterSelection(), FindItem(), grabUnconnected(), GROUP_TOOL::Group(), SelectAll(), selectAllConnectedTracks(), SelectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnections(), selectMultiple(), selectNet(), selectPoint(), selectUnconnected(), and unrouteSelected().

◆ Selectable()

bool PCB_SELECTION_TOOL::Selectable ( const BOARD_ITEM aItem,
bool  checkVisibilityOnly = false 
) const
Returns
true if an item fulfills conditions to be selected.

Definition at line 2325 of file pcb_selection_tool.cpp.

2326{
2327 const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
2328
2329 auto visibleLayers =
2330 [&]()
2331 {
2333 {
2334 LSET set;
2335
2336 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
2337 set.set( layer, view()->IsLayerVisible( layer ) );
2338
2339 return set;
2340 }
2341 else
2342 {
2343 return board()->GetVisibleLayers();
2344 }
2345 };
2346
2347 if( settings->GetHighContrast() )
2348 {
2349 std::set<unsigned int> activeLayers = settings->GetHighContrastLayers();
2350 bool onActiveLayer = false;
2351
2352 for( unsigned int layer : activeLayers )
2353 {
2354 // NOTE: Only checking the regular layers (not GAL meta-layers)
2355 if( layer < PCB_LAYER_ID_COUNT && aItem->IsOnLayer( ToLAYER_ID( layer ) ) )
2356 {
2357 onActiveLayer = true;
2358 break;
2359 }
2360 }
2361
2362 if( !onActiveLayer ) // We do not want to select items that are in the background
2363 return false;
2364 }
2365
2366 if( aItem->Type() == PCB_FOOTPRINT_T )
2367 {
2368 // In footprint editor, we do not want to select the footprint itself.
2370 return false;
2371
2372 // Allow selection of footprints if some part of the footprint is visible.
2373 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
2374 LSET boardSide = footprint->IsFlipped() ? LSET::BackMask() : LSET::FrontMask();
2375
2376 if( !( visibleLayers() & boardSide ).any() && !m_skip_heuristics )
2377 return false;
2378
2379 // If the footprint has no items except the reference and value fields, include the
2380 // footprint in the selections.
2381 if( footprint->GraphicalItems().empty()
2382 && footprint->Pads().empty()
2383 && footprint->Zones().empty() )
2384 {
2385 return true;
2386 }
2387
2388 for( const BOARD_ITEM* item : footprint->GraphicalItems() )
2389 {
2390 if( Selectable( item, true ) )
2391 return true;
2392 }
2393
2394 for( const PAD* pad : footprint->Pads() )
2395 {
2396 if( Selectable( pad, true ) )
2397 return true;
2398 }
2399
2400 for( const ZONE* zone : footprint->Zones() )
2401 {
2402 if( Selectable( zone, true ) )
2403 return true;
2404 }
2405
2406 return false;
2407 }
2408 else if( aItem->Type() == PCB_GROUP_T )
2409 {
2410 PCB_GROUP* group = const_cast<PCB_GROUP*>( static_cast<const PCB_GROUP*>( aItem ) );
2411
2412 // Similar to logic for footprint, a group is selectable if any of its members are.
2413 // (This recurses.)
2414 for( BOARD_ITEM* item : group->GetItems() )
2415 {
2416 if( Selectable( item, true ) )
2417 return true;
2418 }
2419
2420 return false;
2421 }
2422
2423 const ZONE* zone = nullptr;
2424 const PCB_VIA* via = nullptr;
2425 const PAD* pad = nullptr;
2426 const FP_TEXT* text = nullptr;
2427
2428 switch( aItem->Type() )
2429 {
2430 case PCB_ZONE_T:
2431 case PCB_FP_ZONE_T:
2433 return false;
2434
2435 zone = static_cast<const ZONE*>( aItem );
2436
2437 // A footprint zone is only selectable within the footprint editor
2438 if( zone->GetParent()
2439 && zone->GetParent()->Type() == PCB_FOOTPRINT_T
2441 && !checkVisibilityOnly )
2442 {
2443 return false;
2444 }
2445
2446 // zones can exist on multiple layers!
2447 if( !( zone->GetLayerSet() & visibleLayers() ).any() )
2448 return false;
2449
2450 break;
2451
2452 case PCB_TRACE_T:
2453 case PCB_ARC_T:
2455 return false;
2456
2458 {
2459 if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2460 return false;
2461 }
2462 else
2463 {
2464 if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2465 return false;
2466 }
2467
2468 break;
2469
2470 case PCB_VIA_T:
2471 if( !board()->IsElementVisible( LAYER_VIAS ) )
2472 return false;
2473
2474 via = static_cast<const PCB_VIA*>( aItem );
2475
2476 // For vias it is enough if only one of its layers is visible
2477 if( !( visibleLayers() & via->GetLayerSet() ).any() )
2478 return false;
2479
2480 break;
2481
2482 case PCB_FP_TEXT_T:
2484 {
2485 text = static_cast<const FP_TEXT*>( aItem );
2486
2487 if( !text->IsVisible() && !view()->IsLayerVisible( LAYER_MOD_TEXT_INVISIBLE ) )
2488 return false;
2489
2490 if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2491 return false;
2492 }
2493 else
2494 {
2495 if( !view()->IsVisible( aItem ) )
2496 return false;
2497
2498 if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2499 return false;
2500
2501 int controlLayer = UNDEFINED_LAYER;
2502
2503 switch( static_cast<const FP_TEXT*>( aItem )->GetType() )
2504 {
2505 case FP_TEXT::TEXT_is_REFERENCE: controlLayer = LAYER_MOD_REFERENCES; break;
2506 case FP_TEXT::TEXT_is_VALUE: controlLayer = LAYER_MOD_VALUES; break;
2507 case FP_TEXT::TEXT_is_DIVERS: controlLayer = LAYER_MOD_TEXT; break;
2508 }
2509
2510 if( controlLayer == UNDEFINED_LAYER )
2511 return false;
2512
2513 if( !view()->IsLayerVisible( controlLayer ) )
2514 return false;
2515 }
2516
2517 break;
2518
2519 case PCB_FP_SHAPE_T:
2520 case PCB_FP_TEXTBOX_T:
2522 {
2523 if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2524 return false;
2525 }
2526 else
2527 {
2528 // Footprint shape selections are only allowed in footprint editor mode.
2529 if( !checkVisibilityOnly )
2530 return false;
2531
2532 if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2533 return false;
2534 }
2535
2536 break;
2537
2538 case PCB_PAD_T:
2539 // Multiple selection is only allowed in footprint editor mode. In pcbnew, you have to
2540 // select footprint subparts one by one, rather than with a drag selection. This is so
2541 // you can pick up items under an (unlocked) footprint without also moving the
2542 // footprint's sub-parts.
2543 if( !m_isFootprintEditor && !checkVisibilityOnly )
2544 {
2545 if( m_multiple )
2546 return false;
2547 }
2548
2549 pad = static_cast<const PAD*>( aItem );
2550
2551 if( pad->GetAttribute() == PAD_ATTRIB::PTH || pad->GetAttribute() == PAD_ATTRIB::NPTH )
2552 {
2553 // Check render mode (from the Items tab) first
2555 return false;
2556
2557 // A pad's hole is visible on every layer the pad is visible on plus many layers the
2558 // pad is not visible on -- so we only need to check for any visible hole layers.
2559 if( !( visibleLayers() & LSET::PhysicalLayersMask() ).any() )
2560 return false;
2561 }
2562 else
2563 {
2564 // Check render mode (from the Items tab) first
2565 if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
2566 return false;
2567 else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
2568 return false;
2569
2570 if( !( pad->GetLayerSet() & visibleLayers() ).any() )
2571 return false;
2572 }
2573
2574 break;
2575
2576 // These are not selectable
2577 case PCB_NETINFO_T:
2578 case NOT_USED:
2579 case TYPE_NOT_INIT:
2580 return false;
2581
2582 default: // Suppress warnings
2583 break;
2584 }
2585
2586 return true;
2587}
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:540
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:532
bool IsFlipped() const
Definition: footprint.h:324
FP_ZONES & Zones()
Definition: footprint.h:176
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
@ TEXT_is_REFERENCE
Definition: fp_text.h:49
@ TEXT_is_DIVERS
Definition: fp_text.h:51
@ TEXT_is_VALUE
Definition: fp_text.h:50
TEXT_TYPE GetType() const
Definition: fp_text.h:120
bool GetHighContrast() const
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:410
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1564
static LSET AllLayersMask()
Definition: lset.cpp:808
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
static LSET PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition: lset.cpp:870
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:902
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored)
Definition: layer_ids.h:231
@ B_Cu
Definition: layer_ids.h:95
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
@ NPTH
like PAD_PTH, but not plated
@ PTH
Plated through hole pad.
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79

References LSET::AllLayersMask(), B_Cu, LSET::BackMask(), board(), F_Cu, LSET::FrontMask(), KIGFX::RENDER_SETTINGS::GetHighContrast(), KIGFX::RENDER_SETTINGS::GetHighContrastLayers(), BOARD_ITEM::GetLayer(), ZONE::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::PAINTER::GetSettings(), FP_TEXT::GetType(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), FOOTPRINT::GraphicalItems(), group, BOARD::IsElementVisible(), FOOTPRINT::IsFlipped(), KIGFX::VIEW::IsLayerVisible(), BOARD::IsLayerVisible(), KIGFX::VIEW::IsVisible(), LAYER_MOD_REFERENCES, LAYER_MOD_TEXT, LAYER_MOD_TEXT_INVISIBLE, LAYER_MOD_VALUES, LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIAS, LAYER_ZONES, m_isFootprintEditor, SELECTION_TOOL::m_multiple, SELECTION_TOOL::m_skip_heuristics, NOT_USED, NPTH, pad, FOOTPRINT::Pads(), PCB_ARC_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_NETINFO_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, LSET::PhysicalLayersMask(), PTH, Selectable(), LSET::Seq(), text, FP_TEXT::TEXT_is_DIVERS, FP_TEXT::TEXT_is_REFERENCE, FP_TEXT::TEXT_is_VALUE, ToLAYER_ID(), EDA_ITEM::Type(), TYPE_NOT_INIT, UNDEFINED_LAYER, via, view(), and FOOTPRINT::Zones().

Referenced by PCB_CONTROL::DeleteItemCursor(), Selectable(), SelectAll(), selectMultiple(), and selectPoint().

◆ SelectAll()

int PCB_SELECTION_TOOL::SelectAll ( const TOOL_EVENT aEvent)

Definition at line 1053 of file pcb_selection_tool.cpp.

1054{
1056
1057 // hold all visible items
1058 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
1059
1060 // Filter the view items based on the selection box
1061 BOX2I selectionBox;
1062
1063 // Intermediate step to allow filtering against hierarchy
1064 GENERAL_COLLECTOR collection;
1065
1066 selectionBox.SetMaximum();
1067 view->Query( selectionBox, selectedItems ); // Get the list of selected items
1068
1069 for( const KIGFX::VIEW::LAYER_ITEM_PAIR& item_pair : selectedItems )
1070 {
1071 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( item_pair.first );
1072
1073 if( !item || !Selectable( item ) || !itemPassesFilter( item, true ) )
1074 continue;
1075
1076 collection.Append( item );
1077 }
1078
1079 FilterCollectorForHierarchy( collection, true );
1080
1081 for( EDA_ITEM* item : collection )
1082 select( item );
1083
1085
1087
1088 return 0;
1089}
void SetMaximum()
Definition: box2.h:63
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:422
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:73
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.

References COLLECTOR::Append(), FilterCollectorForHierarchy(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), TOOL_BASE::getView(), itemPassesFilter(), m_frame, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), KIGFX::VIEW::Query(), select(), Selectable(), EVENTS::SelectedEvent, BOX2< Vec >::SetMaximum(), and view().

Referenced by setTransitions().

◆ selectAllConnectedTracks()

void PCB_SELECTION_TOOL::selectAllConnectedTracks ( const std::vector< BOARD_CONNECTED_ITEM * > &  aStartItems,
STOP_CONDITION  aStopCondition 
)
private

Select connected tracks and vias.

Parameters
aStopConditionIndicates where to stop selecting more items.

Definition at line 1205 of file pcb_selection_tool.cpp.

1207{
1208 const LSET allCuMask = LSET::AllCuMask();
1209
1210 PROF_TIMER refreshTimer;
1211 double refreshIntervalMs = 500; // Refresh display with this interval to indicate progress
1212 int lastSelectionSize = m_selection.GetSize();
1213
1214 auto connectivity = board()->GetConnectivity();
1215
1216 std::map<VECTOR2I, std::vector<PCB_TRACK*>> trackMap;
1217 std::map<VECTOR2I, PCB_VIA*> viaMap;
1218 std::map<VECTOR2I, PAD*> padMap;
1219 std::set<PAD*> startPadSet;
1220 std::vector<BOARD_CONNECTED_ITEM*> cleanupItems;
1221 std::vector<std::pair<VECTOR2I, LSET>> activePts;
1222
1223 for( BOARD_CONNECTED_ITEM* startItem : aStartItems )
1224 {
1225 // Track starting pads
1226 if( startItem->Type() == PCB_PAD_T )
1227 startPadSet.insert( static_cast<PAD*>( startItem ) );
1228 }
1229
1230 for( BOARD_CONNECTED_ITEM* startItem : aStartItems )
1231 {
1232 if( startItem->HasFlag( SKIP_STRUCT ) ) // Skip already visited items
1233 continue;
1234
1235 auto connectedItems = connectivity->GetConnectedItems( startItem,
1237
1238 // Build maps of connected items
1239 for( BOARD_CONNECTED_ITEM* item : connectedItems )
1240 {
1241 switch( item->Type() )
1242 {
1243 case PCB_ARC_T:
1244 case PCB_TRACE_T:
1245 {
1246 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
1247 trackMap[track->GetStart()].push_back( track );
1248 trackMap[track->GetEnd()].push_back( track );
1249 break;
1250 }
1251
1252 case PCB_VIA_T:
1253 {
1254 PCB_VIA* via = static_cast<PCB_VIA*>( item );
1255 viaMap[via->GetStart()] = via;
1256 break;
1257 }
1258
1259 case PCB_PAD_T:
1260 {
1261 PAD* pad = static_cast<PAD*>( item );
1262 padMap[pad->GetPosition()] = pad;
1263 break;
1264 }
1265
1266 default:
1267 break;
1268 }
1269 }
1270
1271 // Set up the initial active points
1272 switch( startItem->Type() )
1273 {
1274 case PCB_ARC_T:
1275 case PCB_TRACE_T:
1276 {
1277 PCB_TRACK* track = static_cast<PCB_TRACK*>( startItem );
1278
1279 activePts.push_back( { track->GetStart(), track->GetLayerSet() } );
1280 activePts.push_back( { track->GetEnd(), track->GetLayerSet() } );
1281 break;
1282 }
1283
1284 case PCB_VIA_T:
1285 activePts.push_back( { startItem->GetPosition(), startItem->GetLayerSet() } );
1286 break;
1287
1288 case PCB_PAD_T:
1289 activePts.push_back( { startItem->GetPosition(), startItem->GetLayerSet() } );
1290 break;
1291
1292 default:
1293 break;
1294 }
1295
1296 bool expand = true;
1297 int failSafe = 0;
1298
1299 // Iterative push from all active points
1300 while( expand && failSafe++ < 100000 )
1301 {
1302 expand = false;
1303
1304 for( int i = activePts.size() - 1; i >= 0; --i )
1305 {
1306 VECTOR2I pt = activePts[i].first;
1307 LSET layerSetCu = activePts[i].second & allCuMask;
1308
1309 auto viaIt = viaMap.find( pt );
1310 auto padIt = padMap.find( pt );
1311
1312 bool gotVia = ( viaIt != viaMap.end() )
1313 && ( layerSetCu & ( viaIt->second->GetLayerSet() ) ).any();
1314
1315 bool gotPad = ( padIt != padMap.end() )
1316 && ( layerSetCu & ( padIt->second->GetLayerSet() ) ).any();
1317
1318 bool gotNonStartPad =
1319 gotPad && ( startPadSet.find( padIt->second ) == startPadSet.end() );
1320
1321 if( aStopCondition == STOP_AT_JUNCTION )
1322 {
1323 size_t pt_count = 0;
1324
1325 for( PCB_TRACK* track : trackMap[pt] )
1326 {
1327 if( track->GetStart() != track->GetEnd()
1328 && layerSetCu.Contains( track->GetLayer() ) )
1329 {
1330 pt_count++;
1331 }
1332 }
1333
1334 if( pt_count > 2 || gotVia || gotNonStartPad )
1335 {
1336 activePts.erase( activePts.begin() + i );
1337 continue;
1338 }
1339 }
1340 else if( aStopCondition == STOP_AT_PAD )
1341 {
1342 if( gotNonStartPad )
1343 {
1344 activePts.erase( activePts.begin() + i );
1345 continue;
1346 }
1347 }
1348
1349 if( gotPad )
1350 {
1351 PAD* pad = padIt->second;
1352
1353 if( !pad->HasFlag( SKIP_STRUCT ) )
1354 {
1355 pad->SetFlags( SKIP_STRUCT );
1356 cleanupItems.push_back( pad );
1357
1358 activePts.push_back( { pad->GetPosition(), pad->GetLayerSet() } );
1359 expand = true;
1360 }
1361 }
1362
1363 for( PCB_TRACK* track : trackMap[pt] )
1364 {
1365 if( !layerSetCu.Contains( track->GetLayer() ) )
1366 continue;
1367
1368 if( !track->IsSelected() )
1369 select( track );
1370
1371 if( !track->HasFlag( SKIP_STRUCT ) )
1372 {
1373 track->SetFlags( SKIP_STRUCT );
1374 cleanupItems.push_back( track );
1375
1376 if( track->GetStart() == pt )
1377 activePts.push_back( { track->GetEnd(), track->GetLayerSet() } );
1378 else
1379 activePts.push_back( { track->GetStart(), track->GetLayerSet() } );
1380
1381 expand = true;
1382 }
1383 }
1384
1385 if( viaMap.count( pt ) )
1386 {
1387 PCB_VIA* via = viaMap[pt];
1388
1389 if( !via->IsSelected() )
1390 select( via );
1391
1392 if( !via->HasFlag( SKIP_STRUCT ) )
1393 {
1394 via->SetFlags( SKIP_STRUCT );
1395 cleanupItems.push_back( via );
1396
1397 activePts.push_back( { via->GetPosition(), via->GetLayerSet() } );
1398 expand = true;
1399 }
1400 }
1401
1402 activePts.erase( activePts.begin() + i );
1403 }
1404
1405 // Refresh display for the feel of progress
1406 if( refreshTimer.msecs() >= refreshIntervalMs )
1407 {
1408 if( m_selection.Size() != lastSelectionSize )
1409 {
1411 lastSelectionSize = m_selection.Size();
1412 }
1413
1414 refreshTimer.Start();
1415 }
1416 }
1417 }
1418
1419 for( BOARD_CONNECTED_ITEM* item : cleanupItems )
1420 item->ClearFlags( SKIP_STRUCT );
1421}
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:185
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:145
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:600
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
const VECTOR2I & GetStart() const
Definition: pcb_track.h:112
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:109
A small class to help profiling.
Definition: profile.h:47
void Start()
Start or restart the counter.
Definition: profile.h:75
double msecs(bool aSinceLast=false)
Definition: profile.h:147
#define SKIP_STRUCT
flag indicating that the structure should be ignored

References LSET::AllCuMask(), board(), LSET::Contains(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), BOARD::GetConnectivity(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayerSet(), SELECTION::GetSize(), PCB_TRACK::GetStart(), m_frame, m_selection, PROF_TIMER::msecs(), pad, PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), SELECTION::Size(), SKIP_STRUCT, PROF_TIMER::Start(), STOP_AT_JUNCTION, STOP_AT_PAD, and via.

Referenced by expandConnection(), selectConnections(), and unrouteSelected().

◆ SelectAllItemsOnNet()

void PCB_SELECTION_TOOL::SelectAllItemsOnNet ( int  aNetCode,
bool  aSelect = true 
)

Select all items with the given net code.

Parameters
aNetCodeis the target net to select
aSelectis true to add the items to the selection, false to remove them (deselect)

Definition at line 1533 of file pcb_selection_tool.cpp.

1534{
1535 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
1536
1537 for( BOARD_ITEM* item : conn->GetNetItems( aNetCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) )
1538 {
1539 if( itemPassesFilter( item, true ) )
1540 aSelect ? select( item ) : unselect( item );
1541 }
1542}

References board(), BOARD::GetConnectivity(), itemPassesFilter(), select(), and unselect().

Referenced by BOARD_EDITOR_CONTROL::AssignNetclass(), FindItem(), and selectNet().

◆ selectAllItemsOnSheet()

void PCB_SELECTION_TOOL::selectAllItemsOnSheet ( wxString &  aSheetPath)
private

Select all items with the given sheet timestamp/UUID name (the sheet path).

The path of the root sheet is "/". Select all footprints belonging to same sheet, from Eeschema using cross-probing.

Definition at line 1580 of file pcb_selection_tool.cpp.

1581{
1582 std::vector<BOARD_ITEM*> footprints;
1583
1584 // store all footprints that are on that sheet path
1585 for( FOOTPRINT* footprint : board()->Footprints() )
1586 {
1587 if( footprint == nullptr )
1588 continue;
1589
1590 wxString footprint_path = footprint->GetPath().AsString().BeforeLast( '/' );
1591
1592 if( footprint_path.IsEmpty() )
1593 footprint_path += '/';
1594
1595 if( footprint_path == aSheetPath )
1596 footprints.push_back( footprint );
1597 }
1598
1599 for( BOARD_ITEM* i : footprints )
1600 {
1601 if( i != nullptr )
1602 select( i );
1603 }
1604
1605 selectConnections( footprints );
1606}

References board(), select(), and selectConnections().

Referenced by selectSameSheet(), and selectSheetContents().

◆ selectConnections()

void PCB_SELECTION_TOOL::selectConnections ( const std::vector< BOARD_ITEM * > &  aItems)
private

Definition at line 1609 of file pcb_selection_tool.cpp.

1610{
1611 // Generate a list of all pads, and of all nets they belong to.
1612 std::list<int> netcodeList;
1613 std::vector<BOARD_CONNECTED_ITEM*> padList;
1614
1615 for( BOARD_ITEM* item : aItems )
1616 {
1617 switch( item->Type() )
1618 {
1619 case PCB_FOOTPRINT_T:
1620 {
1621 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
1622 {
1623 if( pad->IsConnected() )
1624 {
1625 netcodeList.push_back( pad->GetNetCode() );
1626 padList.push_back( pad );
1627 }
1628 }
1629
1630 break;
1631 }
1632
1633 case PCB_PAD_T:
1634 {
1635 PAD* pad = static_cast<PAD*>( item );
1636
1637 if( pad->IsConnected() )
1638 {
1639 netcodeList.push_back( pad->GetNetCode() );
1640 padList.push_back( pad );
1641 }
1642
1643 break;
1644 }
1645
1646 default:
1647 break;
1648 }
1649 }
1650
1651 // Sort for binary search
1652 std::sort( padList.begin(), padList.end() );
1653
1654 // remove all duplicates
1655 netcodeList.sort();
1656 netcodeList.unique();
1657
1659
1660 // now we need to find all footprints that are connected to each of these nets then we need
1661 // to determine if these footprints are in the list of footprints
1662 std::vector<int> removeCodeList;
1663 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
1664
1665 for( int netCode : netcodeList )
1666 {
1667 for( BOARD_CONNECTED_ITEM* pad : conn->GetNetItems( netCode, { PCB_PAD_T } ) )
1668 {
1669 if( !std::binary_search( padList.begin(), padList.end(), pad ) )
1670 {
1671 // if we cannot find the pad in the padList then we can assume that that pad
1672 // should not be used, therefore invalidate this netcode.
1673 removeCodeList.push_back( netCode );
1674 break;
1675 }
1676 }
1677 }
1678
1679 for( int removeCode : removeCodeList )
1680 netcodeList.remove( removeCode );
1681
1682 std::unordered_set<BOARD_ITEM*> localConnectionList;
1683
1684 for( int netCode : netcodeList )
1685 {
1686 for( BOARD_ITEM* item : conn->GetNetItems( netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) )
1687 localConnectionList.insert( item );
1688 }
1689
1690 for( BOARD_ITEM* item : localConnectionList )
1691 select( item );
1692}

References board(), BOARD::GetConnectivity(), pad, PCB_FOOTPRINT_T, PCB_PAD_T, select(), selectAllConnectedTracks(), and STOP_AT_PAD.

Referenced by doSyncSelection(), and selectAllItemsOnSheet().

◆ selectCursor()

bool PCB_SELECTION_TOOL::selectCursor ( bool  aForceSelect = false,
CLIENT_SELECTION_FILTER  aClientFilter = nullptr 
)
private

Select an item under the cursor unless there is something already selected.

Parameters
aForceSelect[optional] Forces an item to be selected even if there is already a selection.
aClientFilterA callback to allow tool- or action-specific filtering.
Returns
whether or not the selection is empty.

Definition at line 827 of file pcb_selection_tool.cpp.

828{
829 if( aForceSelect || m_selection.Empty() )
830 {
831 ClearSelection( true /*quiet mode*/ );
832 selectPoint( getViewControls()->GetCursorPosition( false ), false, nullptr, aClientFilter );
833 }
834
835 return !m_selection.Empty();
836}

References ClearSelection(), SELECTION::Empty(), TOOL_BASE::getViewControls(), m_selection, and selectPoint().

Referenced by CursorSelection(), expandConnection(), and selectNet().

◆ selection()

SELECTION & PCB_SELECTION_TOOL::selection ( )
inlineoverrideprotectedvirtual

Return a reference to the selection.

Implements SELECTION_TOOL.

Definition at line 242 of file pcb_selection_tool.h.

242{ return m_selection; }

References m_selection.

Referenced by filterSelection(), and selectNet().

◆ selectionContains()

bool PCB_SELECTION_TOOL::selectionContains ( const VECTOR2I aPoint) const
private
Returns
true if the given point is contained in any of selected items' bounding boxes.

Definition at line 2700 of file pcb_selection_tool.cpp.

2701{
2702 const unsigned GRIP_MARGIN = 20;
2703 double margin = getView()->ToWorld( GRIP_MARGIN );
2704
2705 // Check if the point is located close to any of the currently selected items
2706 for( EDA_ITEM* item : m_selection )
2707 {
2708 BOX2I itemBox = item->ViewBBox();
2709 itemBox.Inflate( margin ); // Give some margin for gripping an item
2710
2711 if( itemBox.Contains( aPoint ) )
2712 {
2713 if( item->HitTest( aPoint, margin ) )
2714 return true;
2715
2716 if( PCB_GROUP* group = dyn_cast<PCB_GROUP*>( item ) )
2717 {
2718 bool found = false;
2719
2720 group->RunOnChildren( [&] ( BOARD_ITEM* aItem )
2721 {
2722 if( aItem->HitTest( aPoint, margin ) )
2723 found = true;
2724 } );
2725
2726 if( found )
2727 return true;
2728 }
2729 }
2730 }
2731
2732 return false;
2733}
bool Contains(const Vec &aPoint) const
Definition: box2.h:141
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:224
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:445

References BOX2< Vec >::Contains(), TOOL_BASE::getView(), group, EDA_ITEM::HitTest(), BOX2< Vec >::Inflate(), m_selection, and KIGFX::VIEW::ToWorld().

Referenced by Main().

◆ SelectionMenu()

int SELECTION_TOOL::SelectionMenu ( const TOOL_EVENT aEvent)
inherited

Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.

Note
This routine does not modify the selection.

Definition at line 228 of file selection_tool.cpp.

229{
230 COLLECTOR* collector = aEvent.Parameter<COLLECTOR*>();
231
232 if( !doSelectionMenu( collector ) )
233 collector->m_MenuCancelled = true;
234
235 return 0;
236}
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:48
bool m_MenuCancelled
Definition: collector.h:237
bool doSelectionMenu(COLLECTOR *aCollector)

References SELECTION_TOOL::doSelectionMenu(), COLLECTOR::m_MenuCancelled, and TOOL_EVENT::Parameter().

Referenced by EE_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), and setTransitions().

◆ selectMultiple()

bool PCB_SELECTION_TOOL::selectMultiple ( )
private

Handle drawing a selection box that allows one to select many items at the same time.

Returns
true if the function was canceled (i.e. CancelEvent was received).

Definition at line 852 of file pcb_selection_tool.cpp.

853{
854 bool cancelled = false; // Was the tool cancelled while it was running?
855 m_multiple = true; // Multiple selection mode is active
857
859 view->Add( &area );
860
861 bool anyAdded = false;
862 bool anySubtracted = false;
863
864 while( TOOL_EVENT* evt = Wait() )
865 {
866 int width = area.GetEnd().x - area.GetOrigin().x;
867
868 /* Selection mode depends on direction of drag-selection:
869 * Left > Right : Select objects that are fully enclosed by selection
870 * Right > Left : Select objects that are crossed by selection
871 */
872 bool greedySelection = width >= 0 ? false : true;
873
874 if( view->IsMirroredX() )
875 greedySelection = !greedySelection;
876
879
880 if( evt->IsCancelInteractive() || evt->IsActivate() )
881 {
882 cancelled = true;
883 break;
884 }
885
886 if( evt->IsDrag( BUT_LEFT ) )
887 {
889 {
890 if( m_selection.GetSize() > 0 )
891 {
892 anySubtracted = true;
893 ClearSelection( true /*quiet mode*/ );
894 }
895 }
896
897 // Start drawing a selection box
898 area.SetOrigin( evt->DragOrigin() );
899 area.SetEnd( evt->Position() );
902 area.SetExclusiveOr( false );
903
904 view->SetVisible( &area, true );
905 view->Update( &area );
906 getViewControls()->SetAutoPan( true );
907 }
908
909 if( evt->IsMouseUp( BUT_LEFT ) )
910 {
911 getViewControls()->SetAutoPan( false );
912
913 // End drawing the selection box
914 view->SetVisible( &area, false );
915
916 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> candidates;
917 BOX2I selectionBox = area.ViewBBox();
918 view->Query( selectionBox, candidates ); // Get the list of nearby items
919
920 int height = area.GetEnd().y - area.GetOrigin().y;
921
922 // Construct a BOX2I to determine BOARD_ITEM selection
923 BOX2I selectionRect( area.GetOrigin(), VECTOR2I( width, height ) );
924
925 selectionRect.Normalize();
926
927 GENERAL_COLLECTOR collector;
928 std::set<BOARD_ITEM*> group_items;
929
930 for( PCB_GROUP* group : board()->Groups() )
931 {
932 // The currently entered group does not get limited
933 if( m_enteredGroup == group )
934 continue;
935
936 std::unordered_set<BOARD_ITEM*>& newset = group->GetItems();
937
938 // If we are not greedy and have selected the whole group, add just one item
939 // to allow it to be promoted to the group later
940 if( !greedySelection && selectionRect.Contains( group->GetBoundingBox() )
941 && newset.size() )
942 {
943 collector.Append( *newset.begin() );
944 }
945
946 for( BOARD_ITEM* group_item : newset )
947 group_items.emplace( group_item );
948 }
949
950 for( auto it = candidates.begin(), it_end = candidates.end(); it != it_end; ++it )
951 {
952 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
953
954 if( item && Selectable( item ) && item->HitTest( selectionRect, !greedySelection )
955 && ( greedySelection || !group_items.count( item ) ) )
956 {
957 collector.Append( item );
958 }
959 }
960
961 // Apply the stateful filter
962 FilterCollectedItems( collector, true );
963
964 FilterCollectorForHierarchy( collector, true );
965
966 for( EDA_ITEM* i : collector )
967 {
968 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
969
970 if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
971 {
972 unselect( item );
973 anySubtracted = true;
974 }
975 else
976 {
977 select( item );
978 anyAdded = true;
979 }
980 }
981
982 m_selection.SetIsHover( false );
983
984 // Inform other potentially interested tools
985 if( anyAdded )
987 else if( anySubtracted )
989
990 break; // Stop waiting for events
991 }
992
993 // Allow some actions for navigation
994 for( int i = 0; allowedActions[i]; ++i )
995 {
996 if( evt->IsAction( allowedActions[i] ) )
997 {
998 evt->SetPassEvent();
999 break;
1000 }
1001 }
1002 }
1003
1004 getViewControls()->SetAutoPan( false );
1005
1006 // Stop drawing the selection box
1007 view->Remove( &area );
1008 m_multiple = false; // Multiple selection mode is inactive
1009
1010 if( !cancelled )
1012
1014
1015 return cancelled;
1016}
static const TOOL_EVENT UninhibitSelectionEditing
Used to inform tool that it should display the disambiguation menu.
Definition: actions.h:220
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
void SetSubtractive(bool aSubtractive)
void SetAdditive(bool aAdditive)
void SetOrigin(const VECTOR2I &aOrigin)
const BOX2I ViewBBox() const override
Set the origin of the rectangle (the fixed corner)
void SetExclusiveOr(bool aExclusiveOr)
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:243
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1524
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector, bool aMultiSelect)
Apply the SELECTION_FITLER_OPTIONS to the collector.
const TOOL_ACTION * allowedActions[]

References KIGFX::PCB_VIEW::Add(), allowedActions, COLLECTOR::Append(), board(), BUT_LEFT, SELECTION::ClearReferencePoint(), ClearSelection(), BOX2< Vec >::Contains(), FilterCollectedItems(), FilterCollectorForHierarchy(), PCB_BASE_FRAME::GetCanvas(), KIGFX::PREVIEW::SELECTION_AREA::GetEnd(), KIGFX::PREVIEW::SELECTION_AREA::GetOrigin(), SELECTION::GetSize(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), group, EDA_ITEM::HitTest(), KIGFX::VIEW::IsMirroredX(), EDA_ITEM::IsSelected(), SELECTION_TOOL::m_drag_additive, SELECTION_TOOL::m_drag_subtractive, m_enteredGroup, SELECTION_TOOL::m_exclusive_or, m_frame, SELECTION_TOOL::m_multiple, m_selection, SELECTION_TOOL::m_subtractive, TOOL_BASE::m_toolMgr, BOX2< Vec >::Normalize(), TOOL_MANAGER::ProcessEvent(), KIGFX::VIEW::Query(), KIGFX::PCB_VIEW::Remove(), select(), SELECT_LASSO, SELECT_WINDOW, Selectable(), EVENTS::SelectedEvent, KIGFX::PREVIEW::SELECTION_AREA::SetAdditive(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), KIGFX::PREVIEW::SELECTION_AREA::SetEnd(), KIGFX::PREVIEW::SELECTION_AREA::SetExclusiveOr(), SELECTION::SetIsHover(), KIGFX::PREVIEW::SELECTION_AREA::SetOrigin(), KIGFX::PREVIEW::SELECTION_AREA::SetSubtractive(), KIGFX::VIEW::SetVisible(), EVENTS::UninhibitSelectionEditing, unselect(), EVENTS::UnselectedEvent, KIGFX::PCB_VIEW::Update(), view(), KIGFX::PREVIEW::SELECTION_AREA::ViewBBox(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Main().

◆ selectNet()

int PCB_SELECTION_TOOL::selectNet ( const TOOL_EVENT aEvent)
private

Select all copper connections belonging to the same net(s) as the items in the selection.

Definition at line 1545 of file pcb_selection_tool.cpp.

1546{
1547 bool select = aEvent.IsAction( &PCB_ACTIONS::selectNet );
1548
1549 // If we've been passed an argument, just select that netcode1
1550 int netcode = aEvent.Parameter<intptr_t>();
1551
1552 if( netcode > 0 )
1553 {
1554 SelectAllItemsOnNet( netcode, select );
1555 return 0;
1556 }
1557
1558 if( !selectCursor() )
1559 return 0;
1560
1561 // copy the selection, since we're going to iterate and modify
1563
1564 for( EDA_ITEM* i : selection )
1565 {
1566 BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
1567
1568 if( connItem )
1569 SelectAllItemsOnNet( connItem->GetNetCode(), select );
1570 }
1571
1572 // Inform other potentially interested tools
1573 if( m_selection.Size() > 0 )
1575
1576 return 0;
1577}
static TOOL_ACTION selectNet
Select all connections belonging to a single net.
Definition: pcb_actions.h:86
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88

References SELECTION::GetItems(), BOARD_CONNECTED_ITEM::GetNetCode(), TOOL_EVENT::IsAction(), m_selection, TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), select(), SelectAllItemsOnNet(), selectCursor(), EVENTS::SelectedEvent, selection(), PCB_ACTIONS::selectNet, and SELECTION::Size().

Referenced by setTransitions().

◆ selectPoint()

bool PCB_SELECTION_TOOL::selectPoint ( const VECTOR2I aWhere,
bool  aOnDrag = false,
bool *  aSelectionCancelledFlag = nullptr,
CLIENT_SELECTION_FILTER  aClientFilter = nullptr 
)
private

Select an item pointed by the parameter aWhere.

If there is more than one item at that place, there is a menu displayed that allows one to choose the item.

Parameters
aWhereis the place where the item should be selected.
aOnDragindicates whether a drag operation is being performed.
aSelectionCancelledFlagallows the function to inform its caller that a selection was canceled (for instance, by clicking outside of the disambiguation menu).
aClientFiltera callback to allow tool- or action-specific filtering.
Returns
whether or not the selection is empty.

Definition at line 713 of file pcb_selection_tool.cpp.

716{
718 GENERAL_COLLECTOR collector;
719 const PCB_DISPLAY_OPTIONS& displayOpts = m_frame->GetDisplayOptions();
720
722
724 ExitGroup();
725
728 aWhere, guide );
729
730 // Remove unselectable items
731 for( int i = collector.GetCount() - 1; i >= 0; --i )
732 {
733 if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
734 collector.Remove( i );
735 }
736
738
739 // Allow the client to do tool- or action-specific filtering to see if we can get down
740 // to a single item
741 if( aClientFilter )
742 aClientFilter( aWhere, collector, this );
743
744 FilterCollectorForHierarchy( collector, false );
745
746 // Apply the stateful filter
747 FilterCollectedItems( collector, false );
748
749 // For subtracting, we only want items that are selected
750 if( m_subtractive )
751 {
752 for( int i = collector.GetCount() - 1; i >= 0; --i )
753 {
754 if( !collector[i]->IsSelected() )
755 collector.Remove( i );
756 }
757 }
758
759 // Apply some ugly heuristics to avoid disambiguation menus whenever possible
760 if( collector.GetCount() > 1 && !m_skip_heuristics )
761 GuessSelectionCandidates( collector, aWhere );
762
763 // If still more than one item we're going to have to ask the user.
764 if( collector.GetCount() > 1 )
765 {
766 if( aOnDrag )
768
769 if( !doSelectionMenu( &collector ) )
770 {
771 if( aSelectionCancelledFlag )
772 *aSelectionCancelledFlag = true;
773
774 return false;
775 }
776 }
777
778 int addedCount = 0;
779 bool anySubtracted = false;
780
782 {
783 if( m_selection.GetSize() > 0 )
784 {
785 ClearSelection( true /*quiet mode*/ );
786 anySubtracted = true;
787 }
788 }
789
790 if( collector.GetCount() > 0 )
791 {
792 for( int i = 0; i < collector.GetCount(); ++i )
793 {
794 if( m_subtractive || ( m_exclusive_or && collector[i]->IsSelected() ) )
795 {
796 unselect( collector[i] );
797 anySubtracted = true;
798 }
799 else
800 {
801 select( collector[i] );
802 addedCount++;
803 }
804 }
805 }
806
807 if( addedCount == 1 )
808 {
810 return true;
811 }
812 else if( addedCount > 1 )
813 {
815 return true;
816 }
817 else if( anySubtracted )
818 {
820 return true;
821 }
822
823 return false;
824}
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:205
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:480
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:596
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
ZONE_DISPLAY_MODE m_ZoneDisplayMode
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_group.cpp:276
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead h...
@ TA_MOUSE_UP
Definition: tool_event.h:64
@ TC_ANY
Definition: tool_event.h:55

References GENERAL_COLLECTOR::AllBoardItems, board(), BUT_LEFT, SELECTION::ClearReferencePoint(), ClearSelection(), GENERAL_COLLECTOR::Collect(), BOX2< Vec >::Contains(), SELECTION_TOOL::doSelectionMenu(), ExitGroup(), FilterCollectedItems(), FilterCollectorForHierarchy(), GENERAL_COLLECTOR::FootprintItems, PCB_GROUP::GetBoundingBox(), getCollectorsGuide(), COLLECTOR::GetCount(), PCB_BASE_FRAME::GetDisplayOptions(), SELECTION::GetSize(), GuessSelectionCandidates(), SELECTION_TOOL::m_additive, m_enteredGroup, SELECTION_TOOL::m_exclusive_or, m_frame, m_isFootprintEditor, m_selection, SELECTION_TOOL::m_skip_heuristics, SELECTION_TOOL::m_subtractive, TOOL_BASE::m_toolMgr, PCB_DISPLAY_OPTIONS::m_ZoneDisplayMode, EVENTS::PointSelectedEvent, TOOL_MANAGER::ProcessEvent(), COLLECTOR::Remove(), select(), Selectable(), EVENTS::SelectedEvent, GENERAL_COLLECTORS_GUIDE::SetIgnoreZoneFills(), SHOW_FILLED, TA_MOUSE_UP, TC_ANY, unselect(), EVENTS::UnselectedEvent, and TOOL_INTERACTIVE::Wait().

Referenced by disambiguateCursor(), Main(), and selectCursor().

◆ selectSameSheet()

int PCB_SELECTION_TOOL::selectSameSheet ( const TOOL_EVENT aEvent)
private

Set selection to items passed by parameter and connected nets (optionally).

Zooms to fit, if enabled

Definition at line 1766 of file pcb_selection_tool.cpp.

1767{
1768 // this function currently only supports footprints since they are only on one sheet.
1769 EDA_ITEM* item = m_selection.Front();
1770
1771 if( !item )
1772 return 0;
1773
1774 if( item->Type() != PCB_FOOTPRINT_T )
1775 return 0;
1776
1777 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
1778
1779 if( !footprint || footprint->GetPath().empty() )
1780 return 0;
1781
1782 ClearSelection( true /*quiet mode*/ );
1783
1784 // get the sheet path only.
1785 wxString sheetPath = footprint->GetPath().AsString().BeforeLast( '/' );
1786
1787 if( sheetPath.IsEmpty() )
1788 sheetPath += '/';
1789
1790 selectAllItemsOnSheet( sheetPath );
1791
1792 // Inform other potentially interested tools
1793 if( m_selection.Size() > 0 )
1795
1796 return 0;
1797}
const KIID_PATH & GetPath() const
Definition: footprint.h:224
wxString AsString() const
Definition: kiid.cpp:332
void selectAllItemsOnSheet(wxString &aSheetPath)
Select all items with the given sheet timestamp/UUID name (the sheet path).

References KIID_PATH::AsString(), ClearSelection(), SELECTION::Front(), FOOTPRINT::GetPath(), m_selection, TOOL_BASE::m_toolMgr, PCB_FOOTPRINT_T, TOOL_MANAGER::ProcessEvent(), selectAllItemsOnSheet(), EVENTS::SelectedEvent, SELECTION::Size(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ selectSheetContents()

int PCB_SELECTION_TOOL::selectSheetContents ( const TOOL_EVENT aEvent)
private

Select all footprints belonging to same hierarchical sheet as the selected footprint (same sheet path).

Definition at line 1750 of file pcb_selection_tool.cpp.

1751{
1752 ClearSelection( true /*quiet mode*/ );
1753 wxString sheetPath = *aEvent.Parameter<wxString*>();
1754
1755 selectAllItemsOnSheet( sheetPath );
1756
1758
1759 if( m_selection.Size() > 0 )
1761
1762 return 0;
1763}
void zoomFitSelection()
Zoom the screen to fit the bounding box for cross probing/selection sync.

References ClearSelection(), m_selection, TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), TOOL_MANAGER::ProcessEvent(), selectAllItemsOnSheet(), EVENTS::SelectedEvent, SELECTION::Size(), and zoomFitSelection().

Referenced by setTransitions().

◆ selectUnconnected()

int PCB_SELECTION_TOOL::selectUnconnected ( const TOOL_EVENT aEvent)
private

Select nearest unconnected footprints on same net as selected items.

Definition at line 1424 of file pcb_selection_tool.cpp.

1425{
1426 // Get all pads
1427 std::vector<PAD*> pads;
1428
1429 for( EDA_ITEM* item : m_selection.GetItems() )
1430 {
1431 if( item->Type() == PCB_FOOTPRINT_T )
1432 {
1433 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
1434 pads.push_back( pad );
1435 }
1436 else if( item->Type() == PCB_PAD_T )
1437 {
1438 pads.push_back( static_cast<PAD*>( item ) );
1439 }
1440 }
1441
1442 // Select every footprint on the end of the ratsnest for each pad in our selection
1443 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
1444
1445 for( PAD* pad : pads )
1446 {
1447 for( const CN_EDGE& edge : conn->GetRatsnestForPad( pad ) )
1448 {
1449 BOARD_CONNECTED_ITEM* sourceParent = edge.GetSourceNode()->Parent();
1450 BOARD_CONNECTED_ITEM* targetParent = edge.GetTargetNode()->Parent();
1451
1452 if( sourceParent == pad )
1453 {
1454 if( targetParent->Type() == PCB_PAD_T )
1455 select( static_cast<PAD*>( targetParent )->GetParent() );
1456 }
1457 else if( targetParent == pad )
1458 {
1459 if( sourceParent->Type() == PCB_PAD_T )
1460 select( static_cast<PAD*>( sourceParent )->GetParent() );
1461 }
1462 }
1463 }
1464
1465 return 0;
1466}

References board(), BOARD::GetConnectivity(), SELECTION::GetItems(), m_selection, pad, PCB_FOOTPRINT_T, PCB_PAD_T, select(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ SetContextMenu()

void TOOL_INTERACTIVE::SetContextMenu ( ACTION_MENU aMenu,
CONTEXT_MENU_TRIGGER  aTrigger = CMENU_BUTTON 
)
inherited

Assign a context menu and tells when it should be activated.

Parameters
aMenuis the menu to be assigned.
aTriggerdetermines conditions upon which the context menu is activated.

Definition at line 76 of file tool_interactive.cpp.

77{
78 if( aMenu )
79 aMenu->SetTool( this );
80 else
81 aTrigger = CMENU_OFF;
82
83 m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
84}
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
void ScheduleContextMenu(TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Set behavior of the tool's context popup menu.
@ CMENU_OFF
Definition: tool_event.h:149

References CMENU_OFF, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ScheduleContextMenu(), and ACTION_MENU::SetTool().

Referenced by SELECTION_TOOL::doSelectionMenu(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ setModifiersState()

void SELECTION_TOOL::setModifiersState ( bool  aShiftState,
bool  aCtrlState,
bool  aAltState 
)
protectedinherited

Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state of modifier keys SHIFT, CTRL, ALT and depending on the OS.

Definition at line 48 of file selection_tool.cpp.

49{
50 // Set the configuration of m_additive, m_subtractive, m_exclusive_or from the state of
51 // modifier keys SHIFT and CTRL
52
53 // ALT key cannot be used on MSW because of a conflict with the system menu
54
55 m_subtractive = aCtrlState && aShiftState;
56 m_additive = !aCtrlState && aShiftState;
57
59 {
60 m_exclusive_or = false;
61 m_highlight_modifier = aCtrlState && !aShiftState;
62 }
63 else
64 {
65 m_exclusive_or = aCtrlState && !aShiftState;
67 }
68
69 // Drag is more forgiving and allows either Ctrl+Drag or Shift+Drag to add to the selection
70 // Note, however that we cannot provide disambiguation at the same time as the box selection
71 m_drag_additive = ( aCtrlState || aShiftState ) && !aAltState;
72 m_drag_subtractive = aCtrlState && aShiftState && !aAltState;
73
74 // While the ALT key has some conflicts under MSW (and some flavors of Linux WMs), it remains
75 // useful for users who only use tap-click rather than holding the button. We disable it for
76 // windows because it flashes the disambiguation menu without showing data
77#ifndef __WINDOWS__
78 m_skip_heuristics = aAltState;
79#else
80 m_skip_heuristics = false;
81#endif
82
83}
virtual bool ctrlClickHighlights()
Determines if ctrl-click is highlight net or XOR selection.

References SELECTION_TOOL::ctrlClickHighlights(), SELECTION_TOOL::m_additive, SELECTION_TOOL::m_drag_additive, SELECTION_TOOL::m_drag_subtractive, SELECTION_TOOL::m_exclusive_or, SELECTION_TOOL::m_highlight_modifier, SELECTION_TOOL::m_skip_heuristics, and SELECTION_TOOL::m_subtractive.

Referenced by EE_SELECTION_TOOL::disambiguateCursor(), PL_SELECTION_TOOL::disambiguateCursor(), disambiguateCursor(), EE_SELECTION_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), Main(), EE_SELECTION_TOOL::OnIdle(), and OnIdle().

◆ setTransitions()

void PCB_SELECTION_TOOL::setTransitions ( )
overridevirtual

Zoom the screen to center and fit the current selection.

Implements TOOL_INTERACTIVE.

Definition at line 3138 of file pcb_selection_tool.cpp.

3139{
3141
3145
3151
3167
3169
3171}
static TOOL_ACTION updateMenu
Definition: actions.h:171
static TOOL_ACTION selectAll
Definition: actions.h:71
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:213
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition: actions.h:216
static TOOL_ACTION unrouteSelected
Removes all tracks from the selected items to the first pad.
Definition: pcb_actions.h:83
static TOOL_ACTION grabUnconnected
Select and move nearest unconnected footprint from ratsnest of selection.
Definition: pcb_actions.h:95
static TOOL_ACTION filterSelection
Filter the items in the current selection (invokes dialog)
Definition: pcb_actions.h:107
static TOOL_ACTION unselectItem
Definition: pcb_actions.h:63
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
static TOOL_ACTION selectOnSheetFromEeschema
Select all components on sheet from Eeschema crossprobing.
Definition: pcb_actions.h:98
static TOOL_ACTION selectConnection
Select tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:80
static TOOL_ACTION unselectItems
Definition: pcb_actions.h:67
static TOOL_ACTION selectUnconnected
Select unconnected footprints from ratsnest of selection.
Definition: pcb_actions.h:92
static TOOL_ACTION syncSelection
Sets selection to specified items, zooms to fit, if enabled.
Definition: pcb_actions.h:70
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
static TOOL_ACTION selectSameSheet
Select all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:101
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:53
static TOOL_ACTION syncSelectionWithNets
Sets selection to specified items with connected nets, zooms to fit, if enabled.
Definition: pcb_actions.h:73
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:66
static TOOL_ACTION deselectNet
Remove all connections belonging to a single net from the active selection.
Definition: pcb_actions.h:89
static TOOL_ACTION selectionMenu
Run a selection menu to select from a list of items.
Definition: pcb_actions.h:76
int syncSelectionWithNets(const TOOL_EVENT &aEvent)
int syncSelection(const TOOL_EVENT &aEvent)
int selectNet(const TOOL_EVENT &aEvent)
Select all copper connections belonging to the same net(s) as the items in the selection.
int filterSelection(const TOOL_EVENT &aEvent)
Return true if the given item passes the current SELECTION_FILTER_OPTIONS.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
int unrouteSelected(const TOOL_EVENT &aEvent)
Unroute the selected board connected items.
int grabUnconnected(const TOOL_EVENT &aEvent)
Select and move other nearest footprint unconnected on same net as selected items.
int expandConnection(const TOOL_EVENT &aEvent)
Expand the current connected-item selection to the next boundary (junctions, pads,...
int selectUnconnected(const TOOL_EVENT &aEvent)
Select nearest unconnected footprints on same net as selected items.
int selectSheetContents(const TOOL_EVENT &aEvent)
Select all footprints belonging to same hierarchical sheet as the selected footprint (same sheet path...
int selectSameSheet(const TOOL_EVENT &aEvent)
Set selection to items passed by parameter and connected nets (optionally).
int CursorSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int Main(const TOOL_EVENT &aEvent)
The main loop.
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
int SelectAll(const TOOL_EVENT &aEvent)
int UpdateMenu(const TOOL_EVENT &aEvent)
Update a menu's state based on the current selection.
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).

References SELECTION_TOOL::AddItemsToSel(), SELECTION_TOOL::AddItemToSel(), ClearSelection(), CursorSelection(), PCB_ACTIONS::deselectNet, disambiguateCursor(), EVENTS::DisambiguatePoint, expandConnection(), PCB_ACTIONS::filterSelection, filterSelection(), TOOL_INTERACTIVE::Go(), PCB_ACTIONS::grabUnconnected, grabUnconnected(), Main(), SELECTION_TOOL::RemoveItemFromSel(), SELECTION_TOOL::RemoveItemsFromSel(), ACTIONS::selectAll, SelectAll(), PCB_ACTIONS::selectConnection, EVENTS::SelectedItemsModified, EVENTS::SelectedItemsMoved, PCB_ACTIONS::selectionActivate, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionCursor, SELECTION_TOOL::SelectionMenu(), PCB_ACTIONS::selectionMenu, PCB_ACTIONS::selectItem, PCB_ACTIONS::selectItems, PCB_ACTIONS::selectNet, selectNet(), PCB_ACTIONS::selectOnSheetFromEeschema, PCB_ACTIONS::selectSameSheet, selectSameSheet(), selectSheetContents(), PCB_ACTIONS::selectUnconnected, selectUnconnected(), PCB_ACTIONS::syncSelection, syncSelection(), PCB_ACTIONS::syncSelectionWithNets, syncSelectionWithNets(), PCB_ACTIONS::unrouteSelected, unrouteSelected(), PCB_ACTIONS::unselectItem, PCB_ACTIONS::unselectItems, ACTIONS::updateMenu, SELECTION_TOOL::UpdateMenu(), and updateSelection().

◆ syncSelection()

int PCB_SELECTION_TOOL::syncSelection ( const TOOL_EVENT aEvent)
private

Definition at line 1695 of file pcb_selection_tool.cpp.

1696{
1697 std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
1698
1699 if( items )
1700 doSyncSelection( *items, false );
1701
1702 return 0;
1703}
void doSyncSelection(const std::vector< BOARD_ITEM * > &aItems, bool aWithNets)
Invoke filter dialog and modify current selection.

References doSyncSelection(), and TOOL_EVENT::Parameter().

Referenced by setTransitions().

◆ syncSelectionWithNets()

int PCB_SELECTION_TOOL::syncSelectionWithNets ( const TOOL_EVENT aEvent)
private

Definition at line 1706 of file pcb_selection_tool.cpp.

1707{
1708 std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
1709
1710 if( items )
1711 doSyncSelection( *items, true );
1712
1713 return 0;
1714}

References doSyncSelection(), and TOOL_EVENT::Parameter().

Referenced by setTransitions().

◆ UnbrightenItem()

◆ unhighlight()

void PCB_SELECTION_TOOL::unhighlight ( EDA_ITEM aItem,
int  aHighlightMode,
SELECTION aGroup = nullptr 
)
overrideprivatevirtual

Unhighlight the item visually.

Parameters
aItemThe item to be highlighted.
aHighlightModeEither SELECTED or BRIGHTENED
aGroup[optional] A group to remove the item from.

Implements SELECTION_TOOL.

Definition at line 2657 of file pcb_selection_tool.cpp.

2658{
2659 if( aGroup )
2660 aGroup->Remove( aItem );
2661
2662 unhighlightInternal( aItem, aMode, aGroup != nullptr );
2663 view()->Update( aItem, KIGFX::REPAINT );
2664
2665 // Many selections are very temporal and updating the display each time just creates noise.
2666 if( aMode == BRIGHTENED )
2668}
void unhighlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:50

References BRIGHTENED, TOOL_BASE::getView(), KIGFX::VIEW::MarkTargetDirty(), SELECTION::Remove(), KIGFX::REPAINT, KIGFX::TARGET_OVERLAY, unhighlightInternal(), KIGFX::PCB_VIEW::Update(), and view().

Referenced by ClearSelection(), RequestSelection(), and unselect().

◆ unhighlightInternal()

void PCB_SELECTION_TOOL::unhighlightInternal ( EDA_ITEM aItem,
int  aHighlightMode,
bool  aUsingOverlay 
)
private

Definition at line 2671 of file pcb_selection_tool.cpp.

2672{
2673 if( aMode == SELECTED )
2674 aItem->ClearSelected();
2675 else if( aMode == BRIGHTENED )
2676 aItem->ClearBrightened();
2677
2678 if( aUsingOverlay && aMode != BRIGHTENED )
2679 view()->Hide( aItem, false ); // // Restore original item visibility
2680
2681 if( aItem->Type() == PCB_FOOTPRINT_T )
2682 {
2683 static_cast<FOOTPRINT*>( aItem )->RunOnChildren(
2684 [&]( BOARD_ITEM* aChild )
2685 {
2686 unhighlightInternal( aChild, aMode, aUsingOverlay );
2687 } );
2688 }
2689 else if( aItem->Type() == PCB_GROUP_T )
2690 {
2691 static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
2692 [&]( BOARD_ITEM* aChild )
2693 {
2694 unhighlightInternal( aChild, aMode, aUsingOverlay );
2695 } );
2696 }
2697}
void ClearSelected()
Definition: eda_item.h:121
void ClearBrightened()
Definition: eda_item.h:122

References BRIGHTENED, EDA_ITEM::ClearBrightened(), EDA_ITEM::ClearSelected(), KIGFX::VIEW::Hide(), PCB_FOOTPRINT_T, PCB_GROUP_T, SELECTED, EDA_ITEM::Type(), unhighlightInternal(), and view().

Referenced by unhighlight(), and unhighlightInternal().

◆ unrouteSelected()

int PCB_SELECTION_TOOL::unrouteSelected ( const TOOL_EVENT aEvent)
private

Unroute the selected board connected items.

Definition at line 1113 of file pcb_selection_tool.cpp.

1114{
1115 std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
1116
1117 // Get all footprints and pads
1118 std::vector<BOARD_CONNECTED_ITEM*> toUnroute;
1119
1120 for( EDA_ITEM* item : selectedItems )
1121 {
1122 if( item->Type() == PCB_FOOTPRINT_T )
1123 {
1124 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
1125 toUnroute.push_back( pad );
1126 }
1127 else if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
1128 {
1129 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
1130 }
1131 }
1132
1133 // Clear selection so we don't delete our footprints/pads
1134 ClearSelection( true );
1135
1136 // Get the tracks on our list of pads, then delete them
1137 selectAllConnectedTracks( toUnroute, STOP_CONDITION::STOP_AT_PAD );
1139
1140 // Reselect our footprint/pads as they were in our original selection
1141 for( EDA_ITEM* item : selectedItems )
1142 {
1143 if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_PAD_T )
1144 select( item );
1145 }
1146
1147 return 0;
1148}
static TOOL_ACTION doDelete
Definition: actions.h:73

References BOARD_CONNECTED_ITEM::ClassOf(), ClearSelection(), ACTIONS::doDelete, SELECTION::GetItems(), m_selection, TOOL_BASE::m_toolMgr, pad, PCB_FOOTPRINT_T, PCB_PAD_T, TOOL_MANAGER::RunAction(), select(), and selectAllConnectedTracks().

Referenced by setTransitions().

◆ unselect()

void PCB_SELECTION_TOOL::unselect ( EDA_ITEM aItem)
overrideprivatevirtual

Take necessary action mark an item as unselected.

Parameters
aItemis an item to be unselected.

Implements SELECTION_TOOL.

Definition at line 2607 of file pcb_selection_tool.cpp.

2608{
2609 unhighlight( aItem, SELECTED, &