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:
PCB_TOOL_BASE 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)
 
int Main (const TOOL_EVENT &aEvent)
 The main loop. More...
 
PCB_SELECTIONGetSelection ()
 Return the set of currently selected items. More...
 
PCB_SELECTIONRequestSelection (CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
 Return the current selection set, filtered according to aFlags and 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)
 Item selection event handler. More...
 
int SelectItem (const TOOL_EVENT &aEvent)
 
void AddItemToSel (BOARD_ITEM *aItem, bool aQuietMode=false)
 Select all items on the board. More...
 
int SelectAll (const TOOL_EVENT &aEvent)
 Multiple item selection event handler. More...
 
int SelectItems (const TOOL_EVENT &aEvent)
 Item unselection event handler. More...
 
int UnselectItem (const TOOL_EVENT &aEvent)
 
void RemoveItemFromSel (BOARD_ITEM *aItem, bool aQuietMode=false)
 Multiple item unselection event handler. More...
 
int UnselectItems (const TOOL_EVENT &aEvent)
 
void BrightenItem (BOARD_ITEM *aItem)
 
void UnbrightenItem (BOARD_ITEM *aItem)
 
void select (BOARD_ITEM *aItem)
 Take necessary action mark an item as selected. More...
 
bool Selectable (const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
 Check conditions for an item to be selected. 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...
 
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 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 ()
 
BOARDGetBoard () const
 
void EnterGroup ()
 
void ExitGroup (bool aSelectGroup=false)
 Leave the currently entered group. More...
 
PCB_GROUPGetEnteredGroup ()
 
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 FilterCollectedItems (GENERAL_COLLECTOR &aCollector)
 
void SetIsFootprintEditor (bool aEnabled)
 Function SetIsFootprintEditor() More...
 
bool IsFootprintEditor () const
 
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 Types

enum  INTERACTIVE_PLACEMENT_OPTIONS { IPO_ROTATE = 0x01, IPO_FLIP = 0x02, IPO_SINGLE_CLICK = 0x04, IPO_REPEAT = 0x08 }
 Options for placing items interactively. More...
 

Protected Member Functions

void doInteractiveItemPlacement (const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
 Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc. More...
 
KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
FOOTPRINTfootprint () const
 
const PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const PCB_SELECTIONselection () const
 
PCB_SELECTIONselection ()
 
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_isFootprintEditor
 
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

void setModifiersState (bool aShiftState, bool aCtrlState, bool aAltState)
 Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics and m_highlight_modifier from the state of modifier keys SHIFT, CTRL, ALT and depending on the OS. More...
 
bool selectPoint (const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Select an item pointed by the parameter aWhere. More...
 
bool selectCursor (bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Select an item under the cursor unless there is something already selected or aSelectAlways is true. More...
 
bool selectMultiple ()
 Handle drawing a selection box that allows one to select many items at the same time. More...
 
bool doSelectionMenu (GENERAL_COLLECTOR *aItems)
 Allow the selection of a single item from a list via pop-up menu. More...
 
int expandConnection (const TOOL_EVENT &aEvent)
 Expand the current track selection to the next boundary (junctions, pads, or all) More...
 
int selectNet (const TOOL_EVENT &aEvent)
 Select all copper connections belonging to the same net(s) as the items in the selection. More...
 
void selectConnectedTracks (BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
 Select connected tracks and vias. More...
 
void selectAllItemsOnNet (int aNetCode, bool aSelect=true)
 Select all items with the given net code. More...
 
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)
 Find dialog callback. More...
 
void findCallback (BOARD_ITEM *aItem)
 Find an item. More...
 
int find (const TOOL_EVENT &aEvent)
 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)
 
void unselect (BOARD_ITEM *aItem)
 Take necessary action mark an item as unselected. More...
 
void highlight (BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
 Highlight the item visually. More...
 
void unhighlight (BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
 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...
 
int UpdateMenu (const TOOL_EVENT &aEvent)
 Pass the selection to a conditional menu for updating. More...
 
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide () const
 
void highlightInternal (BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
 
void unhighlightInternal (BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
PCB_SELECTION m_selection
 
SELECTION_FILTER_OPTIONS m_filter
 
bool m_additive
 
bool m_subtractive
 
bool m_exclusive_or
 
bool m_multiple
 
bool m_skip_heuristics
 
bool m_highlight_modifier
 
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 63 of file pcb_selection_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Options for placing items interactively.

Enumerator
IPO_ROTATE 

Handle the rotate action in the loop by calling the item's rotate method.

IPO_FLIP 

Handle flip action in the loop by calling the item's flip method.

IPO_SINGLE_CLICK 

Create an item immediately on placement starting, otherwise show the pencil cursor until the item is created.

IPO_REPEAT 

Allow repeat placement of the item.

Definition at line 110 of file pcb_tool_base.h.

110  {
112  IPO_ROTATE = 0x01,
113 
115  IPO_FLIP = 0x02,
116 
119  IPO_SINGLE_CLICK = 0x04,
120 
122  IPO_REPEAT = 0x08
123  };
Handle flip action in the loop by calling the item's flip method.
Allow repeat placement of the item.
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
Handle the rotate action in the loop by calling the item's rotate method.

◆ 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,
80  MODEL_RELOAD,
81  GAL_SWITCH
82  };
Model changes (required full reload)
Definition: tool_base.h:80
Tool is invoked after being inactive.
Definition: tool_base.h:79
Rendering engine changes.
Definition: tool_base.h:81

◆ 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 264 of file pcb_selection_tool.h.

265  {
274  STOP_AT_PAD,
276  STOP_NEVER
277  };
Stop at any place where more than two traces meet.
Stop when reaching a pad.

Constructor & Destructor Documentation

◆ PCB_SELECTION_TOOL()

PCB_SELECTION_TOOL::PCB_SELECTION_TOOL ( )

Definition at line 102 of file pcb_selection_tool.cpp.

102  :
103  PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
104  m_frame( NULL ),
105  m_additive( false ),
106  m_subtractive( false ),
107  m_exclusive_or( false ),
108  m_multiple( false ),
109  m_skip_heuristics( false ),
110  m_highlight_modifier( false ),
112  m_enteredGroup( nullptr ),
113  m_priv( std::make_unique<PRIV>() )
114 {
115  m_filter.lockedItems = false;
116  m_filter.footprints = true;
117  m_filter.text = true;
118  m_filter.tracks = true;
119  m_filter.vias = true;
120  m_filter.pads = true;
121  m_filter.graphics = true;
122  m_filter.zones = true;
123  m_filter.keepouts = true;
124  m_filter.dimensions = true;
125  m_filter.otherItems = true;
126 }
bool otherItems
Anything not fitting one of the above categories.
PCB_BASE_FRAME * m_frame
bool text
Text (free or attached to a footprint)
#define NULL
bool dimensions
Dimension items.
SELECTION_FILTER_OPTIONS m_filter
bool graphics
Graphic lines, shapes, polygons.
bool footprints
Allow selecting entire footprints.
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:77
std::unique_ptr< PRIV > m_priv
bool lockedItems
Allow selecting locked items.

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 129 of file pcb_selection_tool.cpp.

130 {
131  getView()->Remove( &m_selection );
133 }
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:352
KIGFX::VIEW_GROUP m_enteredGroupOverlay
PCB_SELECTION m_selection
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, 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(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_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(), 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(), PCB_PICKER_TOOL::Main(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), LIB_TREE::onContextMenu(), PCB_POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC_TOOL::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ AddItemToSel()

void PCB_SELECTION_TOOL::AddItemToSel ( BOARD_ITEM aItem,
bool  aQuietMode = false 
)

Select all items on the board.

Definition at line 1000 of file pcb_selection_tool.cpp.

1001 {
1002  if( aItem )
1003  {
1004  select( aItem );
1005 
1006  // Inform other potentially interested tools
1007  if( !aQuietMode )
1009  }
1010 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
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(), select(), and EVENTS::SelectedEvent.

Referenced by PCB_CONTROL::DeleteItemCursor(), EDIT_TOOL::FilletTracks(), and SelectItem().

◆ 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 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 159 of file pcb_tool_base.h.

159 { return getModel<BOARD>(); }

Referenced by PCB_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), BOARD_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportNetlist(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), filterSelection(), PCB_TOOL_BASE::footprint(), GetBoard(), getCollectorsGuide(), GROUP_TOOL::Group(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::highlightNet(), DRAWING_TOOL::InteractivePlaceWithPreview(), PCB_CONTROL::LayerNext(), PCB_CONTROL::LayerPrev(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::MoveExact(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), PCB_CONTROL::Paste(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PAD_TOOL::PlacePad(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), RebuildSelection(), PAD_TOOL::recombinePad(), BOARD_EDITOR_CONTROL::RepairBoard(), FOOTPRINT_EDITOR_CONTROL::RepairFootprint(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), Selectable(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), selectionContains(), selectPoint(), PCB_CONTROL::TrackDisplayMode(), GROUP_TOOL::Ungroup(), PCB_CONTROL::ViaDisplayMode(), PCB_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), BOARD_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ BrightenItem()

void PCB_SELECTION_TOOL::BrightenItem ( BOARD_ITEM aItem)

Definition at line 1049 of file pcb_selection_tool.cpp.

1050 {
1051  highlight( aItem, BRIGHTENED );
1052 }
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
#define BRIGHTENED
item is drawn with a bright contour

References BRIGHTENED, and highlight().

Referenced by PCB_CONTROL::DeleteItemCursor().

◆ canvas()

◆ ClearSelection() [1/2]

int PCB_SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

◆ ClearSelection() [2/2]

void PCB_SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Item selection event handler.

Definition at line 1698 of file pcb_selection_tool.cpp.

1699 {
1700  if( m_selection.Empty() )
1701  return;
1702 
1703  while( m_selection.GetSize() )
1704  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1705 
1706  view()->Update( &m_selection );
1707 
1708  m_selection.SetIsHover( false );
1710 
1711  // Inform other potentially interested tools
1712  if( !aQuietMode )
1713  {
1716  }
1717 }
void ClearReferencePoint()
Definition: selection.h:191
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void SetIsHover(bool aIsHover)
Definition: selection.h:68
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
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
KIGFX::PCB_VIEW * view() const
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:201
#define SELECTED
PCB_SELECTION m_selection
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:460
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
EDA_ITEM * Front() const
Definition: selection.h:144

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

◆ controls()

◆ CursorSelection()

int PCB_SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 921 of file pcb_selection_tool.cpp.

922 {
924 
925  selectCursor( false, aClientFilter );
926 
927  return 0;
928 }
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:427
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item under the cursor unless there is something already selected or aSelectAlways is true.

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

Referenced by setTransitions().

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

Definition at line 294 of file pcb_tool_base.cpp.

295 {
296  return frame()->GetDisplayOptions();
297 }
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
PCB_BASE_EDIT_FRAME * frame() const

References PCB_TOOL_BASE::frame(), and PCB_BASE_FRAME::GetDisplayOptions().

Referenced by BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), PCB_CONTROL::HighContrastMode(), PCB_CONTROL::HighContrastModeCycle(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), PNS::TOOL_BASE::pickSingleItem(), PCB_CONTROL::ToggleRatsnest(), PCB_CONTROL::TrackDisplayMode(), PCB_CONTROL::ViaDisplayMode(), and PCB_CONTROL::ZoneDisplayMode().

◆ doInteractiveItemPlacement()

void PCB_TOOL_BASE::doInteractiveItemPlacement ( const std::string &  aTool,
INTERACTIVE_PLACER_BASE aPlacer,
const wxString &  aCommitMessage,
int  aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT 
)
protectedinherited

Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc.

More complex interactive processes are not supported here, you should implement a customised event loop for those.

Parameters
aItemCreatorthe callable that will attempt to create the item
aCommitMessagethe message used on a successful commit

Definition at line 35 of file pcb_tool_base.cpp.

38 {
39  using namespace std::placeholders;
40  std::unique_ptr<BOARD_ITEM> newItem;
41 
42  frame()->PushTool( aTool );
43  Activate();
44 
45  BOARD_COMMIT commit( frame() );
46 
48 
49  // do not capture or auto-pan until we start placing an item
50  controls()->ShowCursor( true );
51 
52  // Add a VIEW_GROUP that serves as a preview for the new item
53  PCB_SELECTION preview;
54  view()->Add( &preview );
55 
56  aPlacer->m_board = board();
57  aPlacer->m_frame = frame();
58  aPlacer->m_modifiers = 0;
59 
60  auto makeNewItem =
61  [&]( VECTOR2I aPosition )
62  {
63  if( frame()->GetModel() )
64  newItem = aPlacer->CreateItem();
65 
66  if( newItem )
67  {
68  newItem->SetPosition( (wxPoint) aPosition );
69  preview.Add( newItem.get() );
70 
71  if( newItem->Type() == PCB_FOOTPRINT_T )
72  {
73  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
74 
75  // footprints have more drawable parts
76  fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
77  }
78  }
79  };
80 
81  if( aOptions & IPO_SINGLE_CLICK )
82  makeNewItem( controls()->GetCursorPosition() );
83 
84  auto setCursor =
85  [&]()
86  {
87  if( !newItem )
89  else
91  };
92 
93  // Set initial cursor
94  setCursor();
95 
96  // Main loop: keep receiving events
97  while( TOOL_EVENT* evt = Wait() )
98  {
99  setCursor();
100 
101  VECTOR2I cursorPos = controls()->GetCursorPosition();
102  aPlacer->m_modifiers = evt->Modifier();
103 
104  auto cleanup =
105  [&] ()
106  {
107  newItem = nullptr;
108  preview.Clear();
109  view()->Update( &preview );
110  controls()->SetAutoPan( false );
111  controls()->CaptureCursor( false );
112  controls()->ShowCursor( true );
113  };
114 
115  if( evt->IsCancelInteractive() )
116  {
117  if( aOptions & IPO_SINGLE_CLICK )
118  {
119  cleanup();
120  frame()->PopTool( aTool );
121  break;
122  }
123  else if( newItem )
124  {
125  cleanup();
126  }
127  else
128  {
129  frame()->PopTool( aTool );
130  break;
131  }
132  }
133  else if( evt->IsActivate() )
134  {
135  if( newItem )
136  cleanup();
137 
138  if( evt->IsPointEditor() )
139  {
140  // don't exit (the point editor runs in the background)
141  }
142  else if( evt->IsMoveTool() )
143  {
144  // leave ourselves on the stack so we come back after the move
145  break;
146  }
147  else
148  {
149  frame()->PopTool( aTool );
150  break;
151  }
152  }
153  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
154  {
155  if( !newItem )
156  {
157  // create the item if possible
158  makeNewItem( cursorPos );
159 
160  // no item created, so wait for another click
161  if( !newItem )
162  continue;
163 
164  controls()->CaptureCursor( true );
165  controls()->SetAutoPan( true );
166  }
167  else
168  {
169  auto oldFlags = newItem->GetFlags();
170  newItem->ClearFlags();
171 
172  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
173  {
174  newItem->SetFlags( oldFlags );
175  continue;
176  }
177 
178  preview.Clear();
179  newItem.release();
180  commit.Push( aCommitMessage );
181 
182  controls()->CaptureCursor( false );
183  controls()->SetAutoPan( false );
184  controls()->ShowCursor( true );
185 
186  if( !( aOptions & IPO_REPEAT ) )
187  break;
188 
189  if( aOptions & IPO_SINGLE_CLICK )
190  makeNewItem( controls()->GetCursorPosition() );
191 
192  setCursor();
193  }
194  }
195  else if( evt->IsClick( BUT_RIGHT ) )
196  {
198  }
199  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
200  {
202  }
203  else if( newItem && evt->Category() == TC_COMMAND )
204  {
205  /*
206  * Handle any events that can affect the item as we move it around
207  */
208  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
209  {
210  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
211  newItem->Rotate( newItem->GetPosition(), rotationAngle );
212  view()->Update( &preview );
213  }
214  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
215  {
216  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
217  view()->Update( &preview );
218  }
219  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
220  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
221  {
222  // Refresh preview after event runs
224  }
225  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
226  {
227  frame()->OnEditItemRequest( newItem.get() );
228 
229  // Notify other tools of the changes
231  }
232  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
233  {
234  preview.Clear();
235  newItem.release();
236 
237  makeNewItem( (wxPoint) cursorPos );
238  aPlacer->SnapItem( newItem.get() );
239  view()->Update( &preview );
240  }
241  else
242  {
243  evt->SetPassEvent();
244  }
245  }
246  else if( newItem && evt->IsMotion() )
247  {
248  // track the cursor
249  newItem->SetPosition( (wxPoint) cursorPos );
250  aPlacer->SnapItem( newItem.get() );
251 
252  // Show a preview of the item
253  view()->Update( &preview );
254  }
255  else
256  {
257  evt->SetPassEvent();
258  }
259  }
260 
261  view()->Remove( &preview );
263  controls()->SetAutoPan( false );
264  controls()->CaptureCursor( false );
265 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:82
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
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.
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Handle flip action in the loop by calling the item's flip method.
BOARD * board() const
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:31
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:299
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:302
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
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
const PCB_SELECTION & selection() const
Allow repeat placement of the item.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
KIGFX::PCB_VIEW * view() const
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:56
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
PCBNEW_SETTINGS & Settings()
void Activate()
Run the tool.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all BOARD_ITEMs that belong to the footprint (pads, drawings,...
Definition: footprint.cpp:1179
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:300
static TOOL_ACTION refreshPreview
Definition: actions.h:106
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

References TOOL_INTERACTIVE::Activate(), KIGFX::PCB_VIEW::Add(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_TOOL_BASE::controls(), INTERACTIVE_PLACER_BASE::CreateItem(), PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_FRAME::GetModel(), PCB_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, PCBNEW_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, TOOL_BASE::m_toolMgr, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PCB_FOOTPRINT_T, PENCIL, PLACE, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::ProcessEvent(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), FOOTPRINT::RunOnChildren(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, PCB_ACTIONS::trackViaSizeChanged, KIGFX::PCB_VIEW::Update(), PCB_ACTIONS::viaSizeDec, PCB_ACTIONS::viaSizeInc, PCB_TOOL_BASE::view(), and TOOL_INTERACTIVE::Wait().

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint(), DRAWING_TOOL::DrawVia(), and PAD_TOOL::PlacePad().

◆ doSelectionMenu()

bool PCB_SELECTION_TOOL::doSelectionMenu ( GENERAL_COLLECTOR aItems)
private

Allow the selection of a single item from a list via pop-up menu.

The items are highlighted on the canvas when hovered in the menu. The collector is trimmed to the picked item.

Returns
true if an item was picked

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

Definition at line 1774 of file pcb_selection_tool.cpp.

1775 {
1776  BOARD_ITEM* current = nullptr;
1777  PCB_SELECTION highlightGroup;
1778  bool selectAll = false;
1779  bool expandSelection = false;
1780 
1781  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1782  getView()->Add( &highlightGroup );
1783 
1784  do
1785  {
1787  if( expandSelection )
1788  aCollector->Combine();
1789 
1790  expandSelection = false;
1791 
1792  int limit = std::min( 9, aCollector->GetCount() );
1793  ACTION_MENU menu( true );
1794 
1795  for( int i = 0; i < limit; ++i )
1796  {
1797  wxString text;
1798  BOARD_ITEM* item = ( *aCollector )[i];
1800 
1801  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1802  menu.Add( menuText, i + 1, item->GetMenuImage() );
1803  }
1804 
1805  menu.AppendSeparator();
1806  menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
1807 
1808  if( !expandSelection && aCollector->HasAdditionalItems() )
1809  menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
1810 
1811  if( aCollector->m_MenuTitle.Length() )
1812  {
1813  menu.SetTitle( aCollector->m_MenuTitle );
1814  menu.SetIcon( BITMAPS::info );
1815  menu.DisplayTitle( true );
1816  }
1817  else
1818  {
1819  menu.DisplayTitle( false );
1820  }
1821 
1822  SetContextMenu( &menu, CMENU_NOW );
1823 
1824  while( TOOL_EVENT* evt = Wait() )
1825  {
1826  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1827  {
1828  if( selectAll )
1829  {
1830  for( int i = 0; i < aCollector->GetCount(); ++i )
1831  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1832  }
1833  else if( current )
1834  unhighlight( current, BRIGHTENED, &highlightGroup );
1835 
1836  int id = *evt->GetCommandId();
1837 
1838  // User has pointed an item, so show it in a different way
1839  if( id > 0 && id <= limit )
1840  {
1841  current = ( *aCollector )[id - 1];
1842  highlight( current, BRIGHTENED, &highlightGroup );
1843  }
1844  else
1845  current = nullptr;
1846 
1847  // User has pointed on the "Select All" option
1848  if( id == limit + 1 )
1849  {
1850  for( int i = 0; i < aCollector->GetCount(); ++i )
1851  highlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1852  selectAll = true;
1853  }
1854  else
1855  selectAll = false;
1856  }
1857  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1858  {
1859  if( selectAll )
1860  {
1861  for( int i = 0; i < aCollector->GetCount(); ++i )
1862  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1863  }
1864  else if( current )
1865  unhighlight( current, BRIGHTENED, &highlightGroup );
1866 
1867  OPT<int> id = evt->GetCommandId();
1868 
1869  // User has selected the "Select All" option
1870  if( id == limit + 1 )
1871  {
1872  selectAll = true;
1873  current = nullptr;
1874  }
1875  else if( id == limit + 2 )
1876  {
1877  expandSelection = true;
1878  selectAll = false;
1879  current = nullptr;
1880  }
1881  // User has selected an item, so this one will be returned
1882  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1883  {
1884  selectAll = false;
1885  current = ( *aCollector )[*id - 1];
1886  }
1887  else
1888  {
1889  selectAll = false;
1890  current = nullptr;
1891  }
1892  }
1893  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1894  {
1895  break;
1896  }
1897  }
1898  } while( expandSelection );
1899 
1900  getView()->Remove( &highlightGroup );
1901 
1902  if( selectAll )
1903  return true;
1904  else if( current )
1905  {
1906  aCollector->Empty();
1907  aCollector->Append( current );
1908  return true;
1909  }
1910 
1911  return false;
1912 }
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.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:352
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
PCB_BASE_FRAME * m_frame
Generic, UI-independent tool event.
Definition: tool_event.h:152
#define _(s)
virtual void SetLayer(int aLayer)
Set layer used to draw the group.
Definition: view_group.h:108
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
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
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:109
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:208
currently selected items overlay
boost::optional< T > OPT
Definition: optional.h:7
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:322
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
#define BRIGHTENED
item is drawn with a bright contour

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

Referenced by SelectionMenu(), and selectPoint().

◆ EnterGroup()

void PCB_SELECTION_TOOL::EnterGroup ( )

Definition at line 479 of file pcb_selection_tool.cpp.

480 {
481  wxCHECK_RET( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T,
482  "EnterGroup called when selection is not a single group" );
483  PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
484 
485  if( m_enteredGroup != NULL )
486  ExitGroup();
487 
488  ClearSelection();
489  m_enteredGroup = aGroup;
491  m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem )
492  {
493  select( titem );
494  } );
495 
497 }
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
#define NULL
KIGFX::VIEW_GROUP m_enteredGroupOverlay
PCB_SELECTION m_selection
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:56
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
#define ENTERED
indicates a group has been entered
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all members of the group.
Definition: pcb_group.cpp:327
int ClearSelection(const TOOL_EVENT &aEvent)

References KIGFX::VIEW_GROUP::Add(), ClearSelection(), ENTERED, ExitGroup(), SELECTION::GetSize(), m_enteredGroup, m_enteredGroupOverlay, m_selection, NULL, PCB_GROUP_T, PCB_GROUP::RunOnChildren(), select(), and EDA_ITEM::SetFlags().

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

◆ ExitGroup()

void PCB_SELECTION_TOOL::ExitGroup ( bool  aSelectGroup = false)

Leave the currently entered group.

Parameters
aSelectGroupwhen true will select the group after leaving

Definition at line 500 of file pcb_selection_tool.cpp.

501 {
502  // Only continue if there is a group entered
503  if( m_enteredGroup == nullptr )
504  return;
505 
507  ClearSelection();
508 
509  if( aSelectGroup )
511 
513  m_enteredGroup = nullptr;
514 }
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:75
KIGFX::VIEW_GROUP m_enteredGroupOverlay
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
#define ENTERED
indicates a group has been entered
int ClearSelection(const TOOL_EVENT &aEvent)

References KIGFX::VIEW_GROUP::Clear(), EDA_ITEM::ClearFlags(), ClearSelection(), ENTERED, m_enteredGroup, m_enteredGroupOverlay, and select().

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

◆ expandConnection()

int PCB_SELECTION_TOOL::expandConnection ( const TOOL_EVENT aEvent)
private

Expand the current track selection to the next boundary (junctions, pads, or all)

Definition at line 1081 of file pcb_selection_tool.cpp.

1082 {
1083  unsigned initialCount = 0;
1084 
1085  for( auto item : m_selection.GetItems() )
1086  {
1087  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
1088  initialCount++;
1089  }
1090 
1091  if( initialCount == 0 )
1093 
1094  for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
1095  {
1096  // copy the selection, since we're going to iterate and modify
1097  std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
1098 
1099  for( EDA_ITEM* item : selectedItems )
1100  item->ClearTempFlags();
1101 
1102  for( EDA_ITEM* item : selectedItems )
1103  {
1104  PCB_TRACK* trackItem = dynamic_cast<PCB_TRACK*>( item );
1105 
1106  // Track items marked SKIP_STRUCT have already been visited
1107  if( trackItem && !( trackItem->GetFlags() & SKIP_STRUCT ) )
1108  selectConnectedTracks( *trackItem, stopCondition );
1109  }
1110 
1111  if( m_selection.GetItems().size() > initialCount )
1112  break;
1113  }
1114 
1115  // Inform other potentially interested tools
1116  if( m_selection.Size() > 0 )
1118 
1119  return 0;
1120 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
Stop at any place where more than two traces meet.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
Stop when reaching a pad.
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:108
PCB_SELECTION m_selection
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:155
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item under the cursor unless there is something already selected or aSelectAlways is true.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
int Size() const
Returns the number of selected parts.
Definition: selection.h:103
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100

References connectedItemFilter(), EDA_ITEM::GetFlags(), SELECTION::GetItems(), m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), selectConnectedTracks(), selectCursor(), EVENTS::SelectedEvent, SELECTION::Size(), SKIP_STRUCT, STOP_AT_JUNCTION, STOP_AT_PAD, and STOP_NEVER.

Referenced by setTransitions().

◆ FilterCollectedItems()

void PCB_SELECTION_TOOL::FilterCollectedItems ( GENERAL_COLLECTOR aCollector)

Definition at line 1600 of file pcb_selection_tool.cpp.

1601 {
1602  if( aCollector.GetCount() == 0 )
1603  return;
1604 
1605  std::set<BOARD_ITEM*> rejected;
1606 
1607  for( EDA_ITEM* i : aCollector )
1608  {
1609  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1610 
1611  if( !itemPassesFilter( item ) )
1612  rejected.insert( item );
1613  }
1614 
1615  for( BOARD_ITEM* item : rejected )
1616  aCollector.Remove( item );
1617 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
bool itemPassesFilter(BOARD_ITEM *aItem)

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

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

◆ 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.Apply the SELECTION_FILTER_OPTIONS to a collection of items

Definition at line 2527 of file pcb_selection_tool.cpp.

2529 {
2530  std::unordered_set<BOARD_ITEM*> toAdd;
2531 
2532  // Set TEMP_SELECTED on all parents which are included in the GENERAL_COLLECTOR. This
2533  // algorithm is O3n, whereas checking for the parent inclusion could potentially be On^2.
2534 
2535  for( int j = 0; j < aCollector.GetCount(); j++ )
2536  {
2537  if( aCollector[j]->GetParent() )
2538  aCollector[j]->GetParent()->ClearFlags( TEMP_SELECTED );
2539  }
2540 
2541  if( aMultiselect )
2542  {
2543  for( int j = 0; j < aCollector.GetCount(); j++ )
2544  aCollector[j]->SetFlags( TEMP_SELECTED );
2545  }
2546 
2547  for( int j = 0; j < aCollector.GetCount(); )
2548  {
2549  BOARD_ITEM* item = aCollector[j];
2550  BOARD_ITEM* parent = item->GetParent();
2551  BOARD_ITEM* start = item;
2552 
2553  if( !m_isFootprintEditor && parent && parent->Type() == PCB_FOOTPRINT_T )
2554  start = parent;
2555 
2556  // If any element is a member of a group, replace those elements with the top containing
2557  // group.
2559 
2560  if( aTop )
2561  {
2562  if( aTop != item )
2563  {
2564  toAdd.insert( aTop );
2565  aTop->SetFlags( TEMP_SELECTED );
2566 
2567  aCollector.Remove( item );
2568  continue;
2569  }
2570  }
2571  else if( m_enteredGroup
2573  {
2574  // If a group is entered, disallow selections of objects outside the group.
2575  aCollector.Remove( item );
2576  continue;
2577  }
2578 
2579  // Footprints are a bit easier as they can't be nested.
2580  if( parent && parent->GetFlags() & TEMP_SELECTED )
2581  {
2582  // Remove children of selected items
2583  aCollector.Remove( item );
2584  continue;
2585  }
2586 
2587  ++j;
2588  }
2589 
2590  for( BOARD_ITEM* item : toAdd )
2591  {
2592  if( !aCollector.HasItem( item ) )
2593  aCollector.Append( item );
2594  }
2595 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:99
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:115
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:105
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
bool HasItem(const EDA_ITEM *aItem) const
Tests if aItem has already been collected.
Definition: collector.h:203
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:107
bool m_isFootprintEditor
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:155
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
#define TEMP_SELECTED
flag indicating that the structure has already selected
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

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

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

◆ 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 1568 of file pcb_selection_tool.cpp.

1569 {
1570  const BOARD& board = *getModel<BOARD>();
1571  DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
1572  DIALOG_FILTER_SELECTION dlg( m_frame, opts );
1573 
1574  const int cmd = dlg.ShowModal();
1575 
1576  if( cmd != wxID_OK )
1577  return 0;
1578 
1579  // copy current selection
1580  std::deque<EDA_ITEM*> selection = m_selection.GetItems();
1581 
1582  ClearSelection( true /*quiet mode*/ );
1583 
1584  // re-select items from the saved selection according to the dialog options
1585  for( EDA_ITEM* i : selection )
1586  {
1587  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1588  bool include = itemIsIncludedByFilter( *item, board, opts );
1589 
1590  if( include )
1591  select( item );
1592  }
1593 
1595 
1596  return 0;
1597 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
BOARD * board() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
Struct that will be set with the result of the user choices in the dialog.
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Function itemIsIncludedByFilter()
PCB_BASE_FRAME * m_frame
const PCB_SELECTION & selection() const
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:108
PCB_SELECTION m_selection
std::unique_ptr< PRIV > m_priv
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
int ClearSelection(const TOOL_EVENT &aEvent)

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

Referenced by setTransitions().

◆ find()

int PCB_SELECTION_TOOL::find ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection.

Definition at line 1488 of file pcb_selection_tool.cpp.

1489 {
1490  DIALOG_FIND dlg( m_frame );
1491  dlg.SetCallback( std::bind( &PCB_SELECTION_TOOL::findCallback, this, _1 ) );
1492  dlg.ShowModal();
1493 
1494  return 0;
1495 }
PCB_BASE_FRAME * m_frame
void findCallback(BOARD_ITEM *aItem)
Find an item.

References findCallback(), m_frame, and DIALOG_FIND::SetCallback().

Referenced by setTransitions().

◆ findCallback()

void PCB_SELECTION_TOOL::findCallback ( BOARD_ITEM aItem)
private

Find an item.

Definition at line 1459 of file pcb_selection_tool.cpp.

1460 {
1461  bool cleared = false;
1462 
1463  if( m_selection.GetSize() > 0 )
1464  {
1465  // Don't fire an event now; most of the time it will be redundant as we're about to
1466  // fire a SelectedEvent.
1467  cleared = true;
1468  ClearSelection( true /*quiet mode*/ );
1469  }
1470 
1471  if( aItem )
1472  {
1473  select( aItem );
1474  m_frame->FocusOnLocation( aItem->GetPosition() );
1475 
1476  // Inform other potentially interested tools
1478  }
1479  else if( cleared )
1480  {
1482  }
1483 
1485 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
void ForceRefresh()
Force a redraw.
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
PCB_BASE_FRAME * m_frame
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:201
PCB_SELECTION m_selection
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
int ClearSelection(const TOOL_EVENT &aEvent)
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions.

References EVENTS::ClearedEvent, ClearSelection(), EDA_DRAW_FRAME::FocusOnLocation(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), EDA_ITEM::GetPosition(), SELECTION::GetSize(), m_frame, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), and EVENTS::SelectedEvent.

Referenced by find().

◆ footprint()

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 154 of file pcb_tool_base.h.

155  {
156  return getEditFrame<PCB_BASE_EDIT_FRAME>();
157  }

Referenced by PCB_POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_CONTROL::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), ROUTER_TOOL::DpDimensionsDialog(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawVia(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EditPad(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::HighlightItem(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), BOARD_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_TOOL::Init(), SCRIPTING_TOOL::Init(), Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), PCB_PICKER_TOOL::Main(), Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MoveExact(), PCB_POINT_EDITOR::OnSelectionChange(), PCB_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), GROUP_TOOL::PickNewMember(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), PAD_TOOL::recombinePad(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), SCRIPTING_TOOL::reloadPlugins(), PCB_POINT_EDITOR::removeCorner(), RequestSelection(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), PCB_POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), EDIT_TOOL::updateModificationPoint(), BOARD_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ GetBoard()

BOARD* PCB_SELECTION_TOOL::GetBoard ( ) const
inline

Definition at line 175 of file pcb_selection_tool.h.

176  {
177  return board();
178  }
BOARD * board() const

References PCB_TOOL_BASE::board().

Referenced by GROUP_CONTEXT_MENU::update().

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE PCB_SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 650 of file pcb_selection_tool.cpp.

651 {
652  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
653  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
654 
655  bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
656 
657  // account for the globals
658  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
659  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
660  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
661  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
662  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
663  guide.SetIgnorePadsOnBack( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_BK ) );
664  guide.SetIgnorePadsOnFront( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_FR ) );
665  guide.SetIgnoreThroughHolePads( padsDisabled || ! board()->IsElementVisible( LAYER_PADS_TH ) );
666  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
667  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
668  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIAS ) );
669  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIAS ) );
670  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIAS ) );
671  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
672 
673  return guide;
674 }
BOARD * board() const
multilayer pads, usually with holes
show footprints on back
show footprints values (when texts are visible)
show footprints on front
PCB_LAYER_ID
A quick note on layer IDs:
Meta control for all pads opacity/visibility (color ignored)
KIGFX::PCB_VIEW * view() const
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:531
smd pads, front layer
Meta control for all vias opacity/visibility.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377
show footprints references (when texts are visible)

References PCB_TOOL_BASE::board(), BOARD::IsElementVisible(), LAYER_MOD_BK, LAYER_MOD_FR, LAYER_MOD_REFERENCES, LAYER_MOD_TEXT_BK, LAYER_MOD_TEXT_FR, 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 PCB_TOOL_BASE::view().

Referenced by selectionContains(), 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 siezure 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().

◆ GetEnteredGroup()

PCB_GROUP* PCB_SELECTION_TOOL::GetEnteredGroup ( )
inline

Definition at line 189 of file pcb_selection_tool.h.

189 { return m_enteredGroup; }

References m_enteredGroup.

Referenced by PCB_CONTROL::placeBoardItems(), and EDIT_TOOL::Remove().

◆ 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  }
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209

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

Return the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER or NULL if there is no associated tool manager.

Definition at line 143 of file tool_base.h.

144  {
145  return m_toolMgr;
146  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ACTION_MENU::getToolManager(), LIB_TREE::onContextMenu(), ZONE_CREATE_HELPER::OnFirstPoint(), ACTION_MENU::OnMenuEvent(), and ZONE_CREATE_HELPER::performZoneCutout().

◆ 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().

◆ 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(), and TOOL_MANAGER::runTool().

◆ GetSelection()

◆ 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:283
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

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

Referenced by EE_POINT_EDITOR::addCornerCondition(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), COMMON_TOOLS::CenterContents(), SCH_EDIT_TOOL::ChangeTextType(), EE_INSPECTION_TOOL::CheckSymbol(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::CollectHits(), SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint(), COMMON_TOOLS::CursorControl(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), EDIT_TOOL::doMoveSelection(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), ROUTER_TOOL::getStartLayer(), PCB_CONTROL::GridResetOrigin(), PCB_CONTROL::GridSetOrigin(), ROUTER_TOOL::handleCommonEvents(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), BOARD_INSPECTION_TOOL::highlightNet(), hitTestDistance(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineDrag(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), PL_EDIT_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), PL_EDIT_TOOL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), ROUTER_TOOL::performRouting(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PL_DRAWING_TOOLS::PlaceItem(), BOARD_EDITOR_CONTROL::PlaceTarget(), ROUTER_TOOL::prepareInteractive(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), BOARD_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), Selectable(), SelectAll(), EE_SELECTION_TOOL::SelectAll(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), SCH_DRAWING_TOOLS::TwoClickPlace(), PL_SELECTION_TOOL::unhighlight(), EE_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< SCH_BASE_FRAME >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCB_VIEWER_TOOLS::view(), PCB_TOOL_BASE::view(), 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 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:285

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(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), EDIT_TOOL::copyToClipboard(), SCH_DRAWING_TOOLS::createSheetPin(), COMMON_TOOLS::CursorControl(), 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(), 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_DRAWING_TOOLS::GetCanvasFreeAreaPixels(), BOARD_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), SCH_EDIT_TOOL::Init(), EDIT_TOOL::Init(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), 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(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), PCB_POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), selectCursor(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PCB_PICKER_TOOL::setControls(), PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), PCB_POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_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 128 of file tool_interactive.h.

130 {
131  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
132 
133  goInternal( sptr, aConditions );
134 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by AUTOPLACE_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), BOARD_REANNOTATE_TOOL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), PCB_PICKER_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), SYMBOL_EDITOR_PIN_TOOL::setTransitions(), SYMBOL_EDITOR_MOVE_TOOL::setTransitions(), SCRIPTING_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), COMMON_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), PAD_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), FOOTPRINT_EDITOR_CONTROL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), PCB_CONTROL::setTransitions(), DRC_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), PICKER_TOOL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), DRAWING_TOOL::setTransitions(), and EE_SELECTION_TOOL::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
aCollectoris the collector that has a list of items to be queried.
aWhereis the selection point to consider

Definition at line 2358 of file pcb_selection_tool.cpp.

2360 {
2361  std::set<BOARD_ITEM*> preferred;
2362  std::set<BOARD_ITEM*> rejected;
2363  wxPoint where( aWhere.x, aWhere.y );
2364 
2365  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
2366  LSET silkLayers( 2, B_SilkS, F_SilkS );
2367 
2368  if( silkLayers[activeLayer] )
2369  {
2370  for( int i = 0; i < aCollector.GetCount(); ++i )
2371  {
2372  BOARD_ITEM* item = aCollector[i];
2373  KICAD_T type = item->Type();
2374 
2375  if( ( type == PCB_FP_TEXT_T || type == PCB_TEXT_T || type == PCB_SHAPE_T )
2376  && silkLayers[item->GetLayer()] )
2377  {
2378  preferred.insert( item );
2379  }
2380  }
2381 
2382  if( preferred.size() > 0 )
2383  {
2384  aCollector.Empty();
2385 
2386  for( BOARD_ITEM* item : preferred )
2387  aCollector.Append( item );
2388 
2389  return;
2390  }
2391  }
2392 
2393  // Prefer exact hits to sloppy ones
2394 
2395  constexpr int MAX_SLOP = 5;
2396 
2397  int pixel = (int) aCollector.GetGuide()->OnePixelInIU();
2398  int minSlop = INT_MAX;
2399 
2400  std::map<BOARD_ITEM*, int> itemsBySloppiness;
2401 
2402  for( int i = 0; i < aCollector.GetCount(); ++i )
2403  {
2404  BOARD_ITEM* item = aCollector[i];
2405  int itemSlop = hitTestDistance( where, item, MAX_SLOP * pixel );
2406 
2407  itemsBySloppiness[ item ] = itemSlop;
2408 
2409  if( itemSlop < minSlop )
2410  minSlop = itemSlop;
2411  }
2412 
2413  // Prune sloppier items
2414 
2415  if( minSlop < INT_MAX )
2416  {
2417  for( std::pair<BOARD_ITEM*, int> pair : itemsBySloppiness )
2418  {
2419  if( pair.second > minSlop + pixel )
2420  aCollector.Transfer( pair.first );
2421  }
2422  }
2423 
2424  // If the user clicked on a small item within a much larger one then it's pretty clear
2425  // they're trying to select the smaller one.
2426 
2427  constexpr double sizeRatio = 1.5;
2428 
2429  std::vector<std::pair<BOARD_ITEM*, double>> itemsByArea;
2430 
2431  for( int i = 0; i < aCollector.GetCount(); ++i )
2432  {
2433  BOARD_ITEM* item = aCollector[i];
2434  double area;
2435 
2436  if( ( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
2437  && static_cast<ZONE*>( item )->HitTestForEdge( where, MAX_SLOP * pixel / 2 ) )
2438  {
2439  // Zone borders are very specific, so make them "small"
2440  area = MAX_SLOP * SEG::Square( pixel );
2441  }
2442  else if( item->Type() == PCB_VIA_T )
2443  {
2444  // Vias rarely hide other things, and we don't want them deferring to short track
2445  // segments -- so make them artificially small by dropping the π from πr².
2446  area = SEG::Square( static_cast<PCB_VIA*>( item )->GetDrill() / 2 );
2447  }
2448  else
2449  {
2450  try
2451  {
2452  area = FOOTPRINT::GetCoverageArea( item, aCollector );
2453  }
2454  catch( const ClipperLib::clipperException& e )
2455  {
2456  wxLogError( "A clipper exception %s was detected.", e.what() );
2457  }
2458  }
2459 
2460  itemsByArea.emplace_back( item, area );
2461  }
2462 
2463  std::sort( itemsByArea.begin(), itemsByArea.end(),
2464  []( const std::pair<BOARD_ITEM*, double>& lhs,
2465  const std::pair<BOARD_ITEM*, double>& rhs ) -> bool
2466  {
2467  return lhs.second < rhs.second;
2468  } );
2469 
2470  bool rejecting = false;
2471 
2472  for( int i = 1; i < (int) itemsByArea.size(); ++i )
2473  {
2474  if( itemsByArea[i].second > itemsByArea[i-1].second * sizeRatio )
2475  rejecting = true;
2476 
2477  if( rejecting )
2478  rejected.insert( itemsByArea[i].first );
2479  }
2480 
2481  // Special case: if a footprint is completely covered with other features then there's no
2482  // way to select it -- so we need to leave it in the list for user disambiguation.
2483 
2484  constexpr double maxCoverRatio = 0.70;
2485 
2486  for( int i = 0; i < aCollector.GetCount(); ++i )
2487  {
2488  if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aCollector[i] ) )
2489  {
2490  if( footprint->CoverageRatio( aCollector ) > maxCoverRatio )
2491  rejected.erase( footprint );
2492  }
2493  }
2494 
2495  // Hopefully we've now got what the user wanted.
2496 
2497  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2498  {
2499  for( BOARD_ITEM* item : rejected )
2500  aCollector.Transfer( item );
2501  }
2502 
2503  // Finally, what we are left with is a set of items of similar coverage area. We now reject
2504  // any that are not on the active layer, to reduce the number of disambiguation menus shown.
2505  // If the user wants to force-disambiguate, they can either switch layers or use the modifier
2506  // key to force the menu.
2507  if( aCollector.GetCount() > 1 )
2508  {
2509  bool haveItemOnActive = false;
2510  rejected.clear();
2511 
2512  for( int i = 0; i < aCollector.GetCount(); ++i )
2513  {
2514  if( !aCollector[i]->IsOnLayer( activeLayer ) )
2515  rejected.insert( aCollector[i] );
2516  else
2517  haveItemOnActive = true;
2518  }
2519 
2520  if( haveItemOnActive )
2521  for( BOARD_ITEM* item : rejected )
2522  aCollector.Transfer( item );
2523  }
2524 }
void Empty()
Clear the list.
Definition: collector.h:95
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:1753
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
virtual double OnePixelInIU() const =0
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
double CoverageRatio(const GENERAL_COLLECTOR &aCollector) const
Calculate the ratio of total area of the footprint pads and graphical items to the area of the footpr...
Definition: footprint.cpp:1835
static SEG::ecoord Square(int a)
Definition: seg.h:122
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:105
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
void Transfer(int aIndex)
Move the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:159
PCB_LAYER_ID
A quick note on layer IDs:
const COLLECTORS_GUIDE * GetGuide() const
Definition: collectors.h:339
LSET is a set of PCB_LAYER_IDs.
virtual int GetTopLayer() const
Definition: view.cpp:829
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
class ZONE, a copper pour area
Definition: typeinfo.h:105
int hitTestDistance(const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
class ZONE, managed by a footprint
Definition: typeinfo.h:94
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References COLLECTOR::Append(), B_SilkS, FOOTPRINT::CoverageRatio(), COLLECTOR::Empty(), F_SilkS, PCB_TOOL_BASE::footprint(), COLLECTOR::GetCount(), FOOTPRINT::GetCoverageArea(), GENERAL_COLLECTOR::GetGuide(), BOARD_ITEM::GetLayer(), KIGFX::VIEW::GetTopLayer(), hitTestDistance(), COLLECTORS_GUIDE::OnePixelInIU(), PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_VIA_T, PCB_ZONE_T, SEG::Square(), COLLECTOR::Transfer(), EDA_ITEM::Type(), PCB_TOOL_BASE::view(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ highlight()

void PCB_SELECTION_TOOL::highlight ( BOARD_ITEM aItem,
int  aHighlightMode,
PCB_SELECTION aGroup = nullptr 
)
private

Highlight the item visually.

Parameters
aItemis an item to be be highlighted.
aHighlightModeshould be either SELECTED or BRIGHTENED
aGroupis the group to add the item to in the BRIGHTENED mode.

Definition at line 2151 of file pcb_selection_tool.cpp.

2152 {
2153  if( aGroup )
2154  aGroup->Add( aItem );
2155 
2156  highlightInternal( aItem, aMode, aGroup != nullptr );
2157  view()->Update( aItem, KIGFX::REPAINT );
2158 
2159  // Many selections are very temporal and updating the display each time just
2160  // creates noise.
2161  if( aMode == BRIGHTENED )
2163 }
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:31
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
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
Item needs to be redrawn.
Definition: view_item.h:57
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:575
KIGFX::PCB_VIEW * view() const
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
#define BRIGHTENED
item is drawn with a bright contour

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

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

◆ highlightInternal()

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

Definition at line 2166 of file pcb_selection_tool.cpp.

2167 {
2168  if( aMode == SELECTED )
2169  aItem->SetSelected();
2170  else if( aMode == BRIGHTENED )
2171  aItem->SetBrightened();
2172 
2173  if( aUsingOverlay )
2174  view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
2175 
2176  if( aItem->Type() == PCB_FOOTPRINT_T )
2177  {
2178  static_cast<FOOTPRINT*>( aItem )->RunOnChildren(
2179  [&]( BOARD_ITEM* aChild )
2180  {
2181  highlightInternal( aChild, aMode, aUsingOverlay );
2182  } );
2183  }
2184  else if( aItem->Type() == PCB_GROUP_T )
2185  {
2186  static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
2187  [&]( BOARD_ITEM* aChild )
2188  {
2189  highlightInternal( aChild, aMode, aUsingOverlay );
2190  } );
2191  }
2192 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1471
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
void SetBrightened()
Definition: eda_item.h:130
void SetSelected()
Definition: eda_item.h:129
KIGFX::PCB_VIEW * view() const
#define SELECTED
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
#define BRIGHTENED
item is drawn with a bright contour

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

Referenced by highlight().

◆ hitTestDistance()

int PCB_SELECTION_TOOL::hitTestDistance ( const wxPoint &  aWhere,
BOARD_ITEM aItem,
int  aMaxDistance 
) const
private

Definition at line 2265 of file pcb_selection_tool.cpp.

2267 {
2268  BOX2D viewportD = getView()->GetViewport();
2269  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2270  int distance = INT_MAX;
2271  SEG loc( aWhere, aWhere );
2272 
2273  switch( aItem->Type() )
2274  {
2275  case PCB_TEXT_T:
2276  {
2277  PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
2278  text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2279  }
2280  break;
2281 
2282  case PCB_FP_TEXT_T:
2283  {
2284  FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
2285  text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance );
2286  }
2287  break;
2288 
2289  case PCB_ZONE_T:
2290  {
2291  ZONE* zone = static_cast<ZONE*>( aItem );
2292 
2293  // Zone borders are very specific
2294  if( zone->HitTestForEdge( aWhere, aMaxDistance / 2 ) )
2295  distance = 0;
2296  else if( zone->HitTestForEdge( aWhere, aMaxDistance ) )
2297  distance = aMaxDistance / 2;
2298  else
2299  aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
2300  }
2301  break;
2302 
2303  case PCB_FOOTPRINT_T:
2304  {
2305  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
2306  EDA_RECT bbox = footprint->GetBoundingBox( false, false );
2307 
2308  footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance );
2309 
2310  // Consider footprints larger than the viewport only as a last resort
2311  if( bbox.GetHeight() > viewport.GetHeight() || bbox.GetWidth() > viewport.GetWidth() )
2312  distance = INT_MAX / 2;
2313  }
2314  break;
2315 
2316  case PCB_MARKER_T:
2317  {
2318  PCB_MARKER* marker = static_cast<PCB_MARKER*>( aItem );
2319  SHAPE_LINE_CHAIN polygon;
2320 
2321  marker->ShapeToPolygon( polygon );
2322  polygon.Move( marker->GetPos() );
2323  polygon.Collide( loc, aMaxDistance, &distance );
2324  }
2325  break;
2326 
2327  case PCB_GROUP_T:
2328  {
2329  PCB_GROUP* group = static_cast<PCB_GROUP*>( aItem );
2330 
2331  for( BOARD_ITEM* member : group->GetItems() )
2332  distance = std::min( distance, hitTestDistance( aWhere, member, aMaxDistance ) );
2333  }
2334  break;
2335 
2336  default:
2337  aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
2338  break;
2339  }
2340 
2341  return distance;
2342 }
const wxPoint & GetPos() const
Definition: marker_base.h:84
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:514
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
Definition: footprint.cpp:743
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void Move(const VECTOR2I &aVector) override
int GetWidth() const
Definition: eda_rect.h:109
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
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.
FOOTPRINT * footprint() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
int GetHeight() const
Definition: eda_rect.h:110
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
const Vec & GetPosition() const
Definition: box2.h:184
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:40
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,...
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:98
bool HitTestForEdge(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Test if the given wxPoint is near a segment defined by 2 corners.
Definition: zone.cpp:439
SHAPE_LINE_CHAIN.
int hitTestDistance(const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:635
Handle the component boundary box.
Definition: eda_rect.h:42
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:157
const Vec & GetSize() const
Definition: box2.h:179
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

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

Referenced by GuessSelectionCandidates().

◆ Init()

bool PCB_SELECTION_TOOL::Init ( void  )
overridevirtual

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

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

Reimplemented from PCB_TOOL_BASE.

Definition at line 136 of file pcb_selection_tool.cpp.

137 {
138  auto frame = getEditFrame<PCB_BASE_FRAME>();
139 
142  {
144  return true;
145  }
146 
147  auto selectMenu = std::make_shared<SELECT_MENU>();
148  selectMenu->SetTool( this );
149  m_menu.AddSubMenu( selectMenu );
150 
151  auto& menu = m_menu.GetMenu();
152 
153  auto activeToolCondition =
154  [ frame ] ( const SELECTION& aSel )
155  {
156  return !frame->ToolStackIsEmpty();
157  };
158 
159  auto inGroupCondition =
160  [this] ( const SELECTION& )
161  {
162  return m_enteredGroup != nullptr;
163  };
164 
165  if( frame && frame->IsType( FRAME_PCB_EDITOR ) )
166  {
167  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
168  menu.AddSeparator( 1000 );
169  }
170 
171  // "Cancel" goes at the top of the context menu when a tool is active
172  menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
173  menu.AddItem( PCB_ACTIONS::groupLeave, inGroupCondition, 1 );
174  menu.AddSeparator( 1 );
175 
176  if( frame )
178 
179  return true;
180 }
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:38
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
static TOOL_ACTION groupLeave
Definition: pcb_actions.h:431
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
PCB_BASE_EDIT_FRAME * frame() const
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
bool IsType(FRAME_T aType) const
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Store a submenu of this menu model.
Definition: tool_menu.cpp:52

References PCB_GROUP::AddItem(), EDA_DRAW_FRAME::AddStandardSubMenus(), TOOL_MENU::AddSubMenu(), ACTIONS::cancelInteractive, PCB_TOOL_BASE::frame(), FRAME_FOOTPRINT_VIEWER, FRAME_FOOTPRINT_VIEWER_MODAL, FRAME_PCB_EDITOR, TOOL_MENU::GetMenu(), PCB_ACTIONS::groupLeave, EDA_BASE_FRAME::IsType(), m_enteredGroup, TOOL_INTERACTIVE::m_menu, SELECTION_CONDITIONS::NotEmpty(), and TOOLS_HOLDER::ToolStackIsEmpty().

◆ IsFootprintEditor()

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

32 {
33  return m_toolMgr->IsToolActive( m_toolId );
34 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209
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 ROUTER_TOOL::handleLayerSwitch(), EDIT_TOOL::isRouterActive(), Main(), BOARD_EDITOR_CONTROL::TrackWidthDec(), and BOARD_EDITOR_CONTROL::TrackWidthInc().

◆ itemPassesFilter()

bool PCB_SELECTION_TOOL::itemPassesFilter ( BOARD_ITEM aItem)
private

Definition at line 1620 of file pcb_selection_tool.cpp.

1621 {
1622  if( aItem->IsLocked() && !m_filter.lockedItems && aItem->Type() != PCB_PAD_T )
1623  return false;
1624 
1625  switch( aItem->Type() )
1626  {
1627  case PCB_FOOTPRINT_T:
1628  if( !m_filter.footprints )
1629  return false;
1630 
1631  break;
1632 
1633  case PCB_PAD_T:
1634  if( !m_filter.pads )
1635  return false;
1636 
1637  break;
1638 
1639  case PCB_TRACE_T:
1640  case PCB_ARC_T:
1641  if( !m_filter.tracks )
1642  return false;
1643 
1644  break;
1645 
1646  case PCB_VIA_T:
1647  if( !m_filter.vias )
1648  return false;
1649 
1650  break;
1651 
1652  case PCB_FP_ZONE_T:
1653  case PCB_ZONE_T:
1654  {
1655  ZONE* zone = static_cast<ZONE*>( aItem );
1656 
1657  if( ( !m_filter.zones && !zone->GetIsRuleArea() )
1658  || ( !m_filter.keepouts && zone->GetIsRuleArea() ) )
1659  {
1660  return false;
1661  }
1662  }
1663  break;
1664 
1665  case PCB_FP_SHAPE_T:
1666  case PCB_SHAPE_T:
1667  case PCB_TARGET_T:
1668  if( !m_filter.graphics )
1669  return false;
1670 
1671  break;
1672 
1673  case PCB_FP_TEXT_T:
1674  case PCB_TEXT_T:
1675  if( !m_filter.text )
1676  return false;
1677 
1678  break;
1679 
1680  case PCB_DIM_ALIGNED_T:
1681  case PCB_DIM_CENTER_T:
1682  case PCB_DIM_ORTHOGONAL_T:
1683  case PCB_DIM_LEADER_T:
1684  if( !m_filter.dimensions )
1685  return false;
1686 
1687  break;
1688 
1689  default:
1690  if( !m_filter.otherItems )
1691  return false;
1692  }
1693 
1694  return true;
1695 }
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
bool otherItems
Anything not fitting one of the above categories.
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:730
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
bool text
Text (free or attached to a footprint)
bool dimensions
Dimension items.
SELECTION_FILTER_OPTIONS m_filter
bool graphics
Graphic lines, shapes, polygons.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
bool footprints
Allow selecting entire footprints.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual bool IsLocked() const
Definition: board_item.h:247
bool lockedItems
Allow selecting locked items.
class ZONE, managed by a footprint
Definition: typeinfo.h:94
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References SELECTION_FILTER_OPTIONS::dimensions, SELECTION_FILTER_OPTIONS::footprints, ZONE::GetIsRuleArea(), 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_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_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 288 of file pcb_selection_tool.cpp.

289 {
290  // Main loop: keep receiving events
291  while( TOOL_EVENT* evt = Wait() )
292  {
293  MOUSE_DRAG_ACTION dragAction = m_frame->GetDragAction();
295 
296  // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
297  setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
298  evt->Modifier( MD_ALT ) );
299 
300  bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
301  PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
302  bool brd_editor = frame && frame->IsType( FRAME_PCB_EDITOR );
304 
305  // If the router tool is active, don't override
306  if( router && router->IsToolActive() )
307  {
308  evt->SetPassEvent();
309  }
310  // Single click? Select single object
311  else if( evt->IsClick( BUT_LEFT ) )
312  {
313  if( m_highlight_modifier && brd_editor )
315  else
316  {
317  m_frame->FocusOnItem( nullptr );
318  selectPoint( evt->Position() );
319  }
320  }
321  else if( evt->IsClick( BUT_RIGHT ) )
322  {
323  // Right click? if there is any object - show the context menu
324  bool selectionCancelled = false;
325 
326  if( m_selection.Empty() )
327  {
328  selectPoint( evt->Position(), false, &selectionCancelled );
329  m_selection.SetIsHover( true );
330  }
331 
332  if( !selectionCancelled )
334  }
335  else if( evt->IsDblClick( BUT_LEFT ) )
336  {
337  // Double click? Display the properties window
338  m_frame->FocusOnItem( nullptr );
339 
340  if( m_selection.Empty() )
341  selectPoint( evt->Position() );
342 
343  if( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T )
344  {
345  EnterGroup();
346  }
347  else
348  {
350  }
351  }
352  else if( evt->IsDblClick( BUT_MIDDLE ) )
353  {
354  // Middle double click? Do zoom to fit or zoom to objects
355  if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
357  else
359  }
360  else if( evt->IsDrag( BUT_LEFT ) )
361  {
362  // Is another tool already moving a new object? Don't allow a drag start
363  if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
364  {
365  evt->SetPassEvent();
366  continue;
367  }
368 
369  // Drag with LMB? Select multiple objects (or at least draw a selection box)
370  // or drag them
371  m_frame->FocusOnItem( nullptr );
373 
374  if( modifier_enabled || dragAction == MOUSE_DRAG_ACTION::SELECT )
375  {
376  selectMultiple();
377  }
378  else if( m_selection.Empty() && dragAction != MOUSE_DRAG_ACTION::DRAG_ANY )
379  {
380  selectMultiple();
381  }
382  else
383  {
384  // Don't allow starting a drag from a zone filled area that isn't already selected
385  auto zoneFilledAreaFilter =
386  []( const VECTOR2I& aWhere, GENERAL_COLLECTOR& aCollector,
387  PCB_SELECTION_TOOL* aTool )
388  {
389  wxPoint location = wxPoint( aWhere );
390  int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
391  std::set<EDA_ITEM*> remove;
392 
393  for( EDA_ITEM* item : aCollector )
394  {
395  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
396  {
397  ZONE* zone = static_cast<ZONE*>( item );
398 
399  if( !zone->HitTestForCorner( location, accuracy * 2 ) &&
400  !zone->HitTestForEdge( location, accuracy ) )
401  remove.insert( zone );
402  }
403  }
404 
405  for( EDA_ITEM* item : remove )
406  aCollector.Remove( item );
407  };
408 
409  // Selection is empty? try to start dragging the item under the point where drag
410  // started
411  if( m_selection.Empty() && selectCursor( false, zoneFilledAreaFilter ) )
412  m_selection.SetIsHover( true );
413 
414  // Check if dragging has started within any of selected items bounding box.
415  // We verify "HasPosition()" first to protect against edge case involving
416  // moving off menus that causes problems (issue #5250)
417  if( evt->HasPosition() && selectionContains( evt->Position() ) )
418  {
419  // Yes -> run the move tool and wait till it finishes
420  PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( m_selection.GetItem( 0 ) );
421 
422  // If there is only item in the selection and it's a track, then we need to route it
423  bool doRouting = ( track && ( 1 == m_selection.GetSize() ) );
424 
425  if( doRouting && trackDragAction == TRACK_DRAG_ACTION::DRAG )
427  else if( doRouting && trackDragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
429  else
431  }
432  else
433  {
434  // No -> drag a selection box
435  selectMultiple();
436  }
437  }
438  }
439  else if( evt->IsCancel() )
440  {
441  m_frame->FocusOnItem( nullptr );
442 
443  if( m_enteredGroup )
444  ExitGroup();
445 
446  ClearSelection();
447  }
448  else
449  {
450  evt->SetPassEvent();
451  }
452 
453 
454  if( m_frame->ToolStackIsEmpty() )
455  {
456  // move cursor prediction
457  if( !modifier_enabled
458  && dragAction == MOUSE_DRAG_ACTION::DRAG_SELECTED
459  && !m_selection.Empty()
460  && evt->HasPosition()
461  && selectionContains( evt->Position() ) )
462  {
464  }
465  else
466  {
468  }
469  }
470  }
471 
472  // Shutting down; clear the selection
473  m_selection.Clear();
474 
475  return 0;
476 }
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:82
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 IS_NEW
New item, just created.
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:138
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item pointed by the parameter aWhere.
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:137
static TOOL_ACTION zoomFitObjects
Definition: actions.h:97
TRACK_DRAG_ACTION
bool HitTestForCorner(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Test if the given wxPoint is near a corner.
Definition: zone.cpp:425
void SetIsHover(bool aIsHover)
Definition: selection.h:68
PCB_BASE_FRAME * m_frame
PCB_BASE_EDIT_FRAME * frame() const
MOUSE_DRAG_ACTION
MOUSE_DRAG_ACTION GetDragAction() const
Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) objects.
Definition: tools_holder.h:133
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
#define IS_MOVING
Item being moved.
TRACK_DRAG_ACTION m_TrackDragAction
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
Generic, UI-independent tool event.
Definition: tool_event.h:152
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
PCB_SELECTION m_selection
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item under the cursor unless there is something already selected or aSelectAlways is true.
bool HitTestForEdge(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Test if the given wxPoint is near a segment defined by 2 corners.
Definition: zone.cpp:439
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics and m_highlight...
static TOOL_ACTION highlightNet
Definition: pcb_actions.h:450
bool IsType(FRAME_T aType) const
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:52
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool IsToolActive() const
Definition: tool_base.cpp:31
class ZONE, managed by a footprint
Definition: typeinfo.h:94
PCBNEW_SETTINGS & Settings()
The selection tool: currently supports:
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:70
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
static const TOOL_EVENT InhibitSelectionEditing
Definition: actions.h:210
bool selectionContains(const VECTOR2I &aPoint) const
int ClearSelection(const TOOL_EVENT &aEvent)
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
void FocusOnItem(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.

References ARROW, BUT_LEFT, BUT_MIDDLE, BUT_RIGHT, SELECTION::Clear(), ClearSelection(), DRAG, PCB_ACTIONS::drag45Degree, DRAG_ANY, DRAG_FREE_ANGLE, DRAG_SELECTED, PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), EnterGroup(), ExitGroup(), PCB_BASE_FRAME::FocusOnItem(), PCB_TOOL_BASE::frame(), FRAME_PCB_EDITOR, TOOLS_HOLDER::GetDragAction(), SELECTION::GetItem(), SELECTION::GetSize(), TOOL_MANAGER::GetTool(), PCB_ACTIONS::highlightNet, ZONE::HitTestForCorner(), ZONE::HitTestForEdge(), EVENTS::InhibitSelectionEditing, IS_MOVING, IS_NEW, TOOL_BASE::IsToolActive(), EDA_BASE_FRAME::IsType(), KiROUND(), m_additive, m_enteredGroup, m_exclusive_or, m_frame, m_highlight_modifier, TOOL_INTERACTIVE::m_menu, m_nonModifiedCursor, m_selection, 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, TOOL_MANAGER::RunAction(), SELECT, selectCursor(), selectionContains(), selectMultiple(), selectPoint(), SELECTION::SetIsHover(), setModifiersState(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), TOOLS_HOLDER::ToolStackIsEmpty(), TOOL_INTERACTIVE::Wait(), ACTIONS::zoomFitObjects, and ACTIONS::zoomFitScreen.

Referenced by setTransitions().

◆ OnIdle()

void PCB_SELECTION_TOOL::OnIdle ( wxIdleEvent &  aEvent)

Definition at line 267 of file pcb_selection_tool.cpp.

268 {
269  if( m_frame->ToolStackIsEmpty() && !m_multiple )
270  {
271  wxMouseState keyboardState = wxGetMouseState();
272 
273  setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
274  keyboardState.AltDown() );
275 
276  if( m_additive )
278  else if( m_subtractive )
280  else if( m_exclusive_or )
282  else
284  }
285 }
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_BASE_FRAME * m_frame
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics and m_highlight...

References ADD, PCB_BASE_FRAME::GetCanvas(), m_additive, m_exclusive_or, m_frame, m_multiple, m_nonModifiedCursor, m_subtractive, EDA_DRAW_PANEL_GAL::SetCurrentCursor(), 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 1720 of file pcb_selection_tool.cpp.

1721 {
1722  m_selection.Clear();
1723 
1724  bool enteredGroupFound = false;
1725 
1726  INSPECTOR_FUNC inspector =
1727  [&]( EDA_ITEM* item, void* testData )
1728  {
1729  if( item->IsSelected() )
1730  {
1731  EDA_ITEM* parent = item->GetParent();
1732 
1733  // Let selected parents handle their children.
1734  if( parent && parent->IsSelected() )
1735  return SEARCH_RESULT::CONTINUE;
1736 
1737  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1738  }
1739 
1740  if( item == m_enteredGroup )
1741  {
1742  item->SetFlags( ENTERED );
1743  enteredGroupFound = true;
1744  }
1745  else
1746  {
1747  item->ClearFlags( ENTERED );
1748  }
1749 
1750  return SEARCH_RESULT::CONTINUE;
1751  };
1752 
1755 
1756  if( !enteredGroupFound )
1757  {
1759  m_enteredGroup = nullptr;
1760  }
1761 }
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:293
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:82
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
BOARD * board() const
bool IsSelected() const
Definition: eda_item.h:123
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:75
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const 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:1199
std::function< SEARCH_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:69
KIGFX::VIEW_GROUP m_enteredGroupOverlay
EDA_ITEM * GetParent() const
Definition: eda_item.h:115
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
#define SELECTED
PCB_SELECTION m_selection
bool m_isFootprintEditor
#define ENTERED
indicates a group has been entered
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::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, PCB_TOOL_BASE::m_isFootprintEditor, m_selection, SELECTED, EDA_ITEM::SetFlags(), and BOARD::Visit().

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

◆ RemoveItemFromSel()

void PCB_SELECTION_TOOL::RemoveItemFromSel ( BOARD_ITEM aItem,
bool  aQuietMode = false 
)

Multiple item unselection event handler.

Definition at line 1037 of file pcb_selection_tool.cpp.

1038 {
1039  if( aItem )
1040  {
1041  unselect( aItem );
1042 
1043  // Inform other potentially interested tools
1045  }
1046 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void unselect(BOARD_ITEM *aItem)
Take necessary action mark an item as unselected.

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

Referenced by BOARD_COMMIT::Push(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), and UnselectItem().

◆ RequestSelection()

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

Return the current selection set, filtered according to aFlags and aClientFilter.

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

Parameters
aConfirmLockedItemsif true the user will be prompted 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 523 of file pcb_selection_tool.cpp.

525 {
526  bool selectionEmpty = m_selection.Empty();
527  m_selection.SetIsHover( selectionEmpty );
528 
529  if( selectionEmpty )
530  {
531  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
533  }
534 
535  if( aClientFilter )
536  {
537  enum DISPOSITION { BEFORE = 1, AFTER, BOTH };
538 
539  std::map<EDA_ITEM*, DISPOSITION> itemDispositions;
540  GENERAL_COLLECTOR collector;
541 
542  for( EDA_ITEM* item : m_selection )
543  {
544  collector.Append( item );
545  itemDispositions[ item ] = BEFORE;
546  }
547 
548  aClientFilter( VECTOR2I(), collector, this );
549 
550  for( EDA_ITEM* item : collector )
551  {
552  if( itemDispositions.count( item ) )
553  itemDispositions[ item ] = BOTH;
554  else
555  itemDispositions[ item ] = AFTER;
556  }
557 
558  // Unhighlight the BEFORE items before highlighting the AFTER items.
559  // This is so that in the case of groups, if aClientFilter replaces a selection
560  // with the enclosing group, the unhighlight of the element doesn't undo the
561  // recursive highlighting of that element by the group.
562 
563  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
564  {
565  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
566  DISPOSITION disposition = itemDisposition.second;
567 
568  if( disposition == BEFORE )
569  {
570  unhighlight( item, SELECTED, &m_selection );
571  }
572  }
573 
574  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
575  {
576  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
577  DISPOSITION disposition = itemDisposition.second;
578 
579  if( disposition == AFTER )
580  {
581  highlight( item, SELECTED, &m_selection );
582  }
583  else if( disposition == BOTH )
584  {
585  // nothing to do
586  }
587  }
588 
590  }
591 
592  if( aConfirmLockedItems )
593  {
594  std::vector<BOARD_ITEM*> lockedItems;
595 
596  for( EDA_ITEM* item : m_selection )
597  {
598  BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
599 
600  if( boardItem->Type() == PCB_GROUP_T )
601  {
602  PCB_GROUP* group = static_cast<PCB_GROUP*>( boardItem );
603  bool lockedDescendant = false;
604 
605  group->RunOnDescendants(
606  [&lockedDescendant]( BOARD_ITEM* child )
607  {
608  if( child->IsLocked() )
609  lockedDescendant = true;
610  } );
611 
612  if( lockedDescendant )
613  lockedItems.push_back( group );
614  }
615  else if( boardItem->IsLocked() )
616  {
617  lockedItems.push_back( boardItem );
618  }
619  }
620 
621  if( !lockedItems.empty() )
622  {
623  DIALOG_LOCKED_ITEMS_QUERY dlg( frame(), lockedItems.size() );
624 
625  switch( dlg.ShowModal() )
626  {
627  case wxID_OK:
628  // remove locked items from selection
629  for( BOARD_ITEM* item : lockedItems )
630  unselect( item );
631 
632  break;
633 
634  case wxID_CANCEL:
635  // cancel operation
636  ClearSelection();
637  break;
638 
639  case wxID_APPLY:
640  // continue with operation with current selection
641  break;
642  }
643  }
644  }
645 
646  return m_selection;
647 }
void ClearReferencePoint()
Definition: selection.h:191
void ForceRefresh()
Force a redraw.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
void SetIsHover(bool aIsHover)
Definition: selection.h:68
PCB_BASE_FRAME * m_frame
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:105
PCB_BASE_EDIT_FRAME * frame() const
#define SELECTED
PCB_SELECTION m_selection
void unselect(BOARD_ITEM *aItem)
Take necessary action mark an item as unselected.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
virtual bool IsLocked() const
Definition: board_item.h:247
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
int ClearSelection(const TOOL_EVENT &aEvent)
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:56
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

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

Referenced by EDIT_TOOL::ChangeTrackWidth(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), 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::FilletTracks(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), GROUP_TOOL::Group(), CONVERT_TOOL::LinesToPoly(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), GROUP_TOOL::PickNewMember(), CONVERT_TOOL::PolyToLines(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), CONVERT_TOOL::SegmentToArc(), and POSITION_RELATIVE_TOOL::SelectPositionRelativeItem().

◆ 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.

Reimplemented from PCB_TOOL_BASE.

Definition at line 183 of file pcb_selection_tool.cpp.

184 {
185  m_frame = getEditFrame<PCB_BASE_FRAME>();
186 
187  if( m_enteredGroup )
188  ExitGroup();
189 
190  if( aReason == TOOL_BASE::MODEL_RELOAD )
191  {
192  // Deselect any item being currently in edit, to avoid unexpected behavior
193  // and remove pointers to the selected items from containers
194  // without changing their properties (as they are already deleted
195  // while a new board is loaded)
196  ClearSelection( true );
197 
198  getView()->GetPainter()->GetSettings()->SetHighlight( false );
199  }
200  else
201  {
202  // Restore previous properties of selected items and remove them from containers
203  ClearSelection( true );
204  }
205 
206  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
207  view()->Remove( &m_selection );
208  view()->Add( &m_selection );
209 
212 }
Model changes (required full reload)
Definition: tool_base.h:80
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
PCB_BASE_FRAME * m_frame
KIGFX::VIEW_GROUP m_enteredGroupOverlay
KIGFX::PCB_VIEW * view() const
PCB_SELECTION m_selection
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
int ClearSelection(const TOOL_EVENT &aEvent)

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

◆ 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 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
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 ( BOARD_ITEM aItem)

Take necessary action mark an item as selected.

Parameters
aItemis an item to be selected.

Definition at line 2128 of file pcb_selection_tool.cpp.

2129 {
2130  if( aItem->IsSelected() )
2131  return;
2132 
2133  if( aItem->Type() == PCB_PAD_T )
2134  {
2135  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
2136 
2137  if( m_selection.Contains( footprint ) )
2138  return;
2139  }
2140 
2141  highlight( aItem, SELECTED, &m_selection );
2142 }
bool IsSelected() const
Definition: eda_item.h:123
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
class PAD, a pad in a footprint
Definition: typeinfo.h:89
bool Contains(EDA_ITEM *aItem) const
Definition: selection.cpp:61
FOOTPRINT * footprint() const
#define SELECTED
PCB_SELECTION m_selection
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

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

Referenced by AddItemToSel(), EnterGroup(), ExitGroup(), filterSelection(), findCallback(), GROUP_TOOL::Group(), SelectAll(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), SelectItems(), selectMultiple(), selectNet(), and selectPoint().

◆ Selectable()

bool PCB_SELECTION_TOOL::Selectable ( const BOARD_ITEM aItem,
bool  checkVisibilityOnly = false 
) const

Check conditions for an item to be selected.

Returns
True if the item fulfills conditions to be selected.

Definition at line 1915 of file pcb_selection_tool.cpp.

1916 {
1917  const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
1918 
1919  if( settings->GetHighContrast() )
1920  {
1921  std::set<unsigned int> activeLayers = settings->GetHighContrastLayers();
1922  bool onActiveLayer = false;
1923 
1924  for( unsigned int layer : activeLayers )
1925  {
1926  // NOTE: Only checking the regular layers (not GAL meta-layers)
1927  if( layer < PCB_LAYER_ID_COUNT && aItem->IsOnLayer( ToLAYER_ID( layer ) ) )
1928  {
1929  onActiveLayer = true;
1930  break;
1931  }
1932  }
1933 
1934  if( !onActiveLayer ) // We do not want to select items that are in the background
1935  return false;
1936  }
1937 
1938  if( aItem->Type() == PCB_FOOTPRINT_T )
1939  {
1940  // In footprint editor, we do not want to select the footprint itself.
1941  if( m_isFootprintEditor )
1942  return false;
1943 
1944  // Allow selection of footprints if some part of the footprint is visible.
1945 
1946  const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
1947 
1948  for( const BOARD_ITEM* item : footprint->GraphicalItems() )
1949  {
1950  if( Selectable( item, true ) )
1951  return true;
1952  }
1953 
1954  for( const PAD* pad : footprint->Pads() )
1955  {
1956  if( Selectable( pad, true ) )
1957  return true;
1958  }
1959 
1960  for( const ZONE* zone : footprint->Zones() )
1961  {
1962  if( Selectable( zone, true ) )
1963  return true;
1964  }
1965 
1966  return false;
1967  }
1968  else if( aItem->Type() == PCB_GROUP_T )
1969  {
1970  PCB_GROUP* group = const_cast<PCB_GROUP*>( static_cast<const PCB_GROUP*>( aItem ) );
1971 
1972  // Similar to logic for footprint, a group is selectable if any of its members are.
1973  // (This recurses.)
1974  for( BOARD_ITEM* item : group->GetItems() )
1975  {
1976  if( Selectable( item, true ) )
1977  return true;
1978  }
1979 
1980  return false;
1981  }
1982 
1983  const ZONE* zone = nullptr;
1984  const PCB_VIA* via = nullptr;
1985  const PAD* pad = nullptr;
1986 
1987  switch( aItem->Type() )
1988  {
1989  case PCB_ZONE_T:
1990  case PCB_FP_ZONE_T:
1991  if( !board()->IsElementVisible( LAYER_ZONES ) )
1992  return false;
1993 
1994  zone = static_cast<const ZONE*>( aItem );
1995 
1996  // A footprint zone is only selectable within the footprint editor
1997  if( zone->GetParent()
1998  && zone->GetParent()->Type() == PCB_FOOTPRINT_T
2000  && !checkVisibilityOnly )
2001  {
2002  return false;
2003  }
2004 
2005  // zones can exist on multiple layers!
2006  if( !( zone->GetLayerSet() & board()->GetVisibleLayers() ).any() )
2007  return false;
2008 
2009  break;
2010 
2011  case PCB_TRACE_T:
2012  case PCB_ARC_T:
2013  if( !board()->IsElementVisible( LAYER_TRACKS ) )
2014  return false;
2015 
2016  if( m_isFootprintEditor )
2017  {
2018  if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2019  return false;
2020  }
2021  else
2022  {
2023  if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2024  return false;
2025  }
2026 
2027  break;
2028 
2029  case PCB_VIA_T:
2030  if( !board()->IsElementVisible( LAYER_VIAS ) )
2031  return false;
2032 
2033  via = static_cast<const PCB_VIA*>( aItem );
2034 
2035  // For vias it is enough if only one of its layers is visible
2036  if( !( board()->GetVisibleLayers() & via->GetLayerSet() ).any() )
2037  return false;
2038 
2039  break;
2040 
2041  case PCB_FP_TEXT_T:
2042  if( m_isFootprintEditor )
2043  {
2044  if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2045  return false;
2046  }
2047  else
2048  {
2049  if( !view()->IsVisible( aItem ) )
2050  return false;
2051 
2052  if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2053  return false;
2054  }
2055 
2056  break;
2057 
2058  case PCB_FP_SHAPE_T:
2059  if( m_isFootprintEditor )
2060  {
2061  if( !view()->IsLayerVisible( aItem->GetLayer() ) )
2062  return false;
2063  }
2064  else
2065  {
2066  // Footprint shape selections are only allowed in footprint editor mode.
2067  if( !checkVisibilityOnly )
2068  return false;
2069 
2070  if( !board()->IsLayerVisible( aItem->GetLayer() ) )
2071  return false;
2072  }
2073 
2074  break;
2075 
2076  case PCB_PAD_T:
2077  // Multiple selection is only allowed in footprint editor mode. In pcbnew, you have to
2078  // select footprint subparts one by one, rather than with a drag selection. This is so
2079  // you can pick up items under an (unlocked) footprint without also moving the
2080  // footprint's sub-parts.
2081  if( !m_isFootprintEditor && !checkVisibilityOnly )
2082  {
2083  if( m_multiple )
2084  return false;
2085  }
2086 
2087  pad = static_cast<const PAD*>( aItem );
2088 
2089  if( pad->GetAttribute() == PAD_ATTRIB::PTH || pad->GetAttribute() == PAD_ATTRIB::NPTH )
2090  {
2091  // Check render mode (from the Items tab) first
2092  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
2093  return false;
2094 
2095  // A pad's hole is visible on every layer the pad is visible on plus many layers the
2096  // pad is not visible on -- so we only need to check for any visible hole layers.
2097  if( !( board()->GetVisibleLayers() & LSET::PhysicalLayersMask() ).any() )
2098  return false;
2099  }
2100  else
2101  {
2102  // Check render mode (from the Items tab) first
2103  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
2104  return false;
2105  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
2106  return false;
2107 
2108  if( !( pad->GetLayerSet() & board()->GetVisibleLayers() ).any() )
2109  return false;
2110  }
2111 
2112  break;
2113 
2114  // These are not selectable
2115  case PCB_NETINFO_T:
2116  case NOT_USED:
2117  case TYPE_NOT_INIT:
2118  return false;
2119 
2120  default: // Suppress warnings
2121  break;
2122  }
2123 
2124  return aItem->ViewGetLOD( aItem->GetLayer(), view() ) < view()->GetScale();
2125 }
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
BOARD * board() const
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
multilayer pads, usually with holes
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
Control for copper zone opacity/visibility (color ignored)
the 3d code uses this value
Definition: typeinfo.h:79
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:291
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:479
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:159
Plated through hole pad.
FP_ZONES & Zones()
Definition: footprint.h:165
like PAD_PTH, but not plated
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1490
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:105
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:531
bool GetHighContrast() const
static LSET PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition: lset.cpp:849
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
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:471
smd pads, front layer
Meta control for all vias opacity/visibility.
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:107
class ZONE, managed by a footprint
Definition: typeinfo.h:94
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57
double GetScale() const
Definition: view.h:263
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:137
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:404

References B_Cu, PCB_TOOL_BASE::board(), F_Cu, PCB_TOOL_BASE::footprint(), KIGFX::RENDER_SETTINGS::GetHighContrast(), KIGFX::RENDER_SETTINGS::GetHighContrastLayers(), BOARD_ITEM::GetLayer(), ZONE::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), FOOTPRINT::GraphicalItems(), group, BOARD::IsElementVisible(), KIGFX::VIEW::IsLayerVisible(), BOARD::IsLayerVisible(), KIGFX::VIEW::IsVisible(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIAS, LAYER_ZONES, PCB_TOOL_BASE::m_isFootprintEditor, m_multiple, NOT_USED, NPTH, pad, FOOTPRINT::Pads(), PCB_ARC_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_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, ToLAYER_ID(), EDA_ITEM::Type(), TYPE_NOT_INIT, via, PCB_TOOL_BASE::view(), KIGFX::VIEW_ITEM::ViewGetLOD(), and FOOTPRINT::Zones().

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

◆ SelectAll()

int PCB_SELECTION_TOOL::SelectAll ( const TOOL_EVENT aEvent)

Multiple item selection event handler.

Definition at line 963 of file pcb_selection_tool.cpp.

964 {
965  KIGFX::VIEW* view = getView();
966 
967  // hold all visible items
968  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
969 
970  // Filter the view items based on the selection box
971  BOX2I selectionBox;
972 
973  // Intermediate step to allow filtering against hierarchy
974  GENERAL_COLLECTOR collection;
975 
976  selectionBox.SetMaximum();
977  view->Query( selectionBox, selectedItems ); // Get the list of selected items
978 
979  for( const KIGFX::VIEW::LAYER_ITEM_PAIR& item_pair : selectedItems )
980  {
981  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( item_pair.first );
982 
983  if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
984  continue;
985 
986  collection.Append( item );
987  }
988 
989  FilterCollectorForHierarchy( collection, true );
990 
991  for( EDA_ITEM* item : collection )
992  select( static_cast<BOARD_ITEM*>( item ) );
993 
995 
996  return 0;
997 }
void ForceRefresh()
Force a redraw.
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_BASE_FRAME * m_frame
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:105
void SetMaximum()
Definition: box2.h:63
KIGFX::PCB_VIEW * view() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
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.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:72
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
bool itemPassesFilter(BOARD_ITEM *aItem)
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:428
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67

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

Referenced by setTransitions().

◆ selectAllItemsOnNet()

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

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 1242 of file pcb_selection_tool.cpp.

1243 {
1244  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT };
1245  auto connectivity = board()->GetConnectivity();
1246 
1247  for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
1248  if( itemPassesFilter( item ) )
1249  aSelect ? select( item ) : unselect( item );
1250 }
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
BOARD * board() const
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:344
void unselect(BOARD_ITEM *aItem)
Take necessary action mark an item as unselected.
bool itemPassesFilter(BOARD_ITEM *aItem)
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

References PCB_TOOL_BASE::board(), EOT, BOARD::GetConnectivity(), itemPassesFilter(), PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, select(), and unselect().

Referenced by 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 1288 of file pcb_selection_tool.cpp.

1289 {
1290  std::list<FOOTPRINT*> footprintList;
1291 
1292  // store all footprints that are on that sheet path
1293  for( FOOTPRINT* footprint : board()->Footprints() )
1294  {
1295  if( footprint == nullptr )
1296  continue;
1297 
1298  wxString footprint_path = footprint->GetPath().AsString().BeforeLast('/');
1299 
1300  if( aSheetPath.IsEmpty() )
1301  aSheetPath += '/';
1302 
1303  if( footprint_path == aSheetPath )
1304  footprintList.push_back( footprint );
1305  }
1306 
1307  //Generate a list of all pads, and of all nets they belong to.
1308  std::list<int> netcodeList;
1309  std::list<PAD*> padList;
1310 
1311  for( FOOTPRINT* footprint : footprintList )
1312  {
1313  for( PAD* pad : footprint->Pads() )
1314  {
1315  if( pad->IsConnected() )
1316  {
1317  netcodeList.push_back( pad->GetNetCode() );
1318  padList.push_back( pad );
1319  }
1320  }
1321  }
1322  // remove all duplicates
1323  netcodeList.sort();
1324  netcodeList.unique();
1325 
1326  for( PAD* pad : padList )
1328 
1329  // now we need to find all footprints that are connected to each of these nets then we need
1330  // to determine if these footprints are in the list of footprints belonging to this sheet
1331  std::list<int> removeCodeList;
1332  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1333 
1334  for( int netCode : netcodeList )
1335  {
1336  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1337  {
1338  if( mitem->Type() == PCB_PAD_T && !alg::contains( footprintList, mitem->GetParent() ) )
1339  {
1340  // if we cannot find the footprint of the pad in the footprintList then we can
1341  // assume that that footprint is not located in the same schematic, therefore
1342  // invalidate this netcode.
1343  removeCodeList.push_back( netCode );
1344  break;
1345  }
1346  }
1347  }
1348 
1349  // remove all duplicates
1350  removeCodeList.sort();
1351  removeCodeList.unique();
1352 
1353  for( int removeCode : removeCodeList )
1354  {
1355  netcodeList.remove( removeCode );
1356  }
1357 
1358  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1359  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT };
1360 
1361  for( int netCode : netcodeList )
1362  {
1363  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1364  localConnectionList.push_back( item );
1365  }
1366 
1367  for( BOARD_ITEM* i : footprintList )
1368  {
1369  if( i != NULL )
1370  select( i );
1371  }
1372 
1373  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1374  {
1375  if( i != NULL )
1376  select( i );
1377  }
1378 }
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
BOARD * board() const
const KIID_PATH & GetPath() const
Definition: footprint.h:194
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:159
#define NULL
FOOTPRINT * footprint() const
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
wxString AsString() const
Definition: kiid.cpp:277
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57

References KIID_PATH::AsString(), PCB_TOOL_BASE::board(), alg::contains(), EOT, PCB_TOOL_BASE::footprint(), FOOTPRINT::GetPath(), NULL, pad, FOOTPRINT::Pads(), PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), selectConnectedTracks(), and STOP_NEVER.

Referenced by selectSameSheet(), and selectSheetContents().

◆ selectConnectedTracks()

void PCB_SELECTION_TOOL::selectConnectedTracks ( BOARD_CONNECTED_ITEM aSourceItem,
STOP_CONDITION  aStopCondition 
)
private

Select connected tracks and vias.

Parameters
aStopConditionwhere to stop selecting more items

Definition at line 1123 of file pcb_selection_tool.cpp.

1125 {
1126  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT };
1127 
1128  auto connectivity = board()->GetConnectivity();
1129  auto connectedItems = connectivity->GetConnectedItems( &aStartItem, types, true );
1130 
1131  std::map<wxPoint, std::vector<PCB_TRACK*>> trackMap;
1132  std::map<wxPoint, PCB_VIA*> viaMap;
1133  std::map<wxPoint, PAD*> padMap;
1134 
1135  // Build maps of connected items
1136  for( BOARD_CONNECTED_ITEM* item : connectedItems )
1137  {
1138  switch( item->Type() )
1139  {
1140  case PCB_ARC_T:
1141  case PCB_TRACE_T:
1142  {
1143  PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
1144  trackMap[ track->GetStart() ].push_back( track );
1145  trackMap[ track->GetEnd() ].push_back( track );
1146  }
1147  break;
1148 
1149  case PCB_VIA_T:
1150  {
1151  PCB_VIA* via = static_cast<PCB_VIA*>( item );
1152  viaMap[ via->GetStart() ] = via;
1153  }
1154  break;
1155 
1156  case PCB_PAD_T:
1157  {
1158  PAD* pad = static_cast<PAD*>( item );
1159  padMap[ pad->GetPosition() ] = pad;
1160  }
1161  break;
1162 
1163  default:
1164  break;
1165  }
1166 
1167  item->SetState( SKIP_STRUCT, false );
1168  }
1169 
1170  std::vector<wxPoint> activePts;
1171 
1172  // Set up the initial active points
1173  switch( aStartItem.Type() )
1174  {
1175  case PCB_ARC_T:
1176  case PCB_TRACE_T:
1177  activePts.push_back( static_cast<PCB_TRACK*>( &aStartItem )->GetStart() );
1178  activePts.push_back( static_cast<PCB_TRACK*>( &aStartItem )->GetEnd() );
1179  break;
1180 
1181  case PCB_VIA_T:
1182  activePts.push_back( static_cast<PCB_TRACK*>( &aStartItem )->GetStart() );
1183  break;
1184 
1185  case PCB_PAD_T:
1186  activePts.push_back( aStartItem.GetPosition() );
1187  break;
1188 
1189  default:
1190  break;
1191  }
1192 
1193  bool expand = true;
1194 
1195  // Iterative push from all active points
1196  while( expand )
1197  {
1198  expand = false;
1199 
1200  for( int i = activePts.size() - 1; i >= 0; --i )
1201  {
1202  wxPoint pt = activePts[i];
1203  size_t pt_count = trackMap[ pt ].size() + viaMap.count( pt );
1204 
1205  if( pt_count > 2 && aStopCondition == STOP_AT_JUNCTION )
1206  {
1207  activePts.erase( activePts.begin() + i );
1208  continue;
1209  }
1210 
1211  if( padMap.count( pt ) && aStopCondition != STOP_NEVER )
1212  {
1213  activePts.erase( activePts.begin() + i );
1214  continue;
1215  }
1216 
1217  for( PCB_TRACK* track : trackMap[ pt ] )
1218  {
1219  if( track->GetState( SKIP_STRUCT ) )
1220  continue;
1221 
1222  track->SetState( SKIP_STRUCT, true );
1223  select( track );
1224 
1225  if( track->GetStart() == pt )
1226  activePts.push_back( track->GetEnd() );
1227  else
1228  activePts.push_back( track->GetStart() );
1229 
1230  expand = true;
1231  }
1232 
1233  if( viaMap.count( pt ) && !viaMap[ pt ]->IsSelected() && aStopCondition != STOP_AT_JUNCTION )
1234  select( viaMap[ pt ] );
1235 
1236  activePts.erase( activePts.begin() + i );
1237  }
1238  }
1239 }
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
BOARD * board() const
const wxPoint & GetEnd() const
Definition: pcb_track.h:105
Stop at any place where more than two traces meet.
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:142
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:344
int GetState(EDA_ITEM_FLAGS type) const
Definition: eda_item.h:137
#define SKIP_STRUCT
flag indicating that the structure should be ignored
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57
const wxPoint & GetStart() const
Definition: pcb_track.h:108

References PCB_TOOL_BASE::board(), EOT, BOARD::GetConnectivity(), PCB_TRACK::GetEnd(), EDA_ITEM::GetPosition(), PCB_TRACK::GetStart(), pad, PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), SKIP_STRUCT, STOP_AT_JUNCTION, STOP_NEVER, EDA_ITEM::Type(), and via.

Referenced by expandConnection(), and selectAllItemsOnSheet().

◆ selectCursor()

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

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

Parameters
aForceSelectforces to select an item even if there is an item already selected.
aClientFilterallows the client to perform tool- or action-specific filtering.
Returns
true if eventually there is an item selected, false otherwise.

Definition at line 776 of file pcb_selection_tool.cpp.

777 {
778  if( aForceSelect || m_selection.Empty() )
779  {
780  ClearSelection( true /*quiet mode*/ );
781  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
782  }
783 
784  return !m_selection.Empty();
785 }
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item pointed by the parameter aWhere.
#define NULL
PCB_SELECTION m_selection
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
int ClearSelection(const TOOL_EVENT &aEvent)

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

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

◆ selection() [1/2]

const PCB_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 305 of file pcb_tool_base.cpp.

306 {
308 
309  return selTool->GetSelection();
310 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
The selection tool: currently supports:

References GetSelection(), TOOL_MANAGER::GetTool(), and TOOL_BASE::m_toolMgr.

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), BOARD_INSPECTION_TOOL::doHideNet(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Drag(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawZone(), EDIT_TOOL::Duplicate(), BOARD_EDITOR_CONTROL::EditFpInFpEditor(), PAD_TOOL::EditPad(), GROUP_TOOL::EnterGroup(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::FilletTracks(), filterSelection(), EDIT_TOOL::Flip(), DRAWING_TOOL::getSourceZoneForAction(), GROUP_TOOL::Group(), BOARD_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), BOARD_INSPECTION_TOOL::InspectClearance(), BOARD_INSPECTION_TOOL::InspectConstraints(), DRAWING_TOOL::InteractivePlaceWithPreview(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), PCB_POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), DRAWING_TOOL::PlaceImportedGraphics(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), BOARD_REANNOTATE_TOOL::ReannotateDuplicatesInSelection(), GROUP_TOOL::RemoveFromGroup(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), selectNet(), DRAWING_TOOL::SetAnchor(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), GROUP_TOOL::Ungroup(), PCB_CONTROL::UpdateMessagePanel(), BOARD_INSPECTION_TOOL::UpdateSelectionRatsnest(), BOARD_EDITOR_CONTROL::ViaSizeDec(), BOARD_EDITOR_CONTROL::ViaSizeInc(), BOARD_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), BOARD_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

◆ selection() [2/2]

PCB_SELECTION & PCB_TOOL_BASE::selection ( )
protectedinherited

Definition at line 313 of file pcb_tool_base.cpp.

314 {
316 
317  return selTool->GetSelection();
318 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
The selection tool: currently supports:

References GetSelection(), TOOL_MANAGER::GetTool(), and TOOL_BASE::m_toolMgr.

◆ 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 box.

Definition at line 2239 of file pcb_selection_tool.cpp.

2240 {
2242  GENERAL_COLLECTOR collector;
2243 
2244  // Since we're just double-checking, we want a considerably sloppier check than the initial
2245  // selection (for which most tools use 5 pixels). So we increase this to an effective 20
2246  // pixels by artificially inflating the value of a pixel by 4X.
2247  guide.SetOnePixelInIU( guide.OnePixelInIU() * 4 );
2248 
2251  (wxPoint) aPoint, guide );
2252 
2253  for( int i = collector.GetCount() - 1; i >= 0; --i )
2254  {
2255  BOARD_ITEM* item = collector[i];
2256 
2257  if( item->IsSelected() && item->HitTest( (wxPoint) aPoint, 5 * guide.OnePixelInIU() ) )
2258  return true;
2259  }
2260 
2261  return false;
2262 }
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:293
void SetOnePixelInIU(double aValue)
Definition: collectors.h:571
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
BOARD * board() const
bool IsSelected() const
Definition: eda_item.h:123
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:567
double OnePixelInIU() const override
Definition: collectors.h:570
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:225
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
bool m_isFootprintEditor
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), GENERAL_COLLECTOR::Collect(), GENERAL_COLLECTOR::FootprintItems, getCollectorsGuide(), COLLECTOR::GetCount(), EDA_ITEM::HitTest(), EDA_ITEM::IsSelected(), PCB_TOOL_BASE::m_isFootprintEditor, GENERAL_COLLECTORS_GUIDE::OnePixelInIU(), and GENERAL_COLLECTORS_GUIDE::SetOnePixelInIU().

Referenced by Main().

◆ SelectionMenu()

int PCB_SELECTION_TOOL::SelectionMenu ( const TOOL_EVENT aEvent)

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 1764 of file pcb_selection_tool.cpp.

1765 {
1766  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1767 
1768  doSelectionMenu( collector );
1769 
1770  return 0;
1771 }
bool doSelectionMenu(GENERAL_COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:427
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240

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

Referenced by setTransitions().

◆ SelectItem()

int PCB_SELECTION_TOOL::SelectItem ( const TOOL_EVENT aEvent)

Definition at line 956 of file pcb_selection_tool.cpp.

957 {
958  AddItemToSel( aEvent.Parameter<BOARD_ITEM*>() );
959  return 0;
960 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Select all items on the board.
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:427

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

Referenced by setTransitions().

◆ SelectItems()

int PCB_SELECTION_TOOL::SelectItems ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 939 of file pcb_selection_tool.cpp.

940 {
941  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
942 
943  if( items )
944  {
945  // Perform individual selection of each item before processing the event.
946  for( BOARD_ITEM* item : *items )
947  select( item );
948 
950  }
951 
952  return 0;
953 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:427

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

Referenced by 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 788 of file pcb_selection_tool.cpp.

789 {
790  bool cancelled = false; // Was the tool cancelled while it was running?
791  m_multiple = true; // Multiple selection mode is active
792  KIGFX::VIEW* view = getView();
793 
795  view->Add( &area );
796 
797  bool anyAdded = false;
798  bool anySubtracted = false;
799 
800  while( TOOL_EVENT* evt = Wait() )
801  {
802  int width = area.GetEnd().x - area.GetOrigin().x;
803 
804  /* Selection mode depends on direction of drag-selection:
805  * Left > Right : Select objects that are fully enclosed by selection
806  * Right > Left : Select objects that are crossed by selection
807  */
808  bool windowSelection = width >= 0 ? true : false;
809 
810  if( view->IsMirroredX() )
811  windowSelection = !windowSelection;
812 
815 
816  if( evt->IsCancelInteractive() || evt->IsActivate() )
817  {
818  cancelled = true;
819  break;
820  }
821 
822  if( evt->IsDrag( BUT_LEFT ) )
823  {
825  {
826  if( m_selection.GetSize() > 0 )
827  {
828  anySubtracted = true;
829  ClearSelection( true /*quiet mode*/ );
830  }
831  }
832 
833  // Start drawing a selection box
834  area.SetOrigin( evt->DragOrigin() );
835  area.SetEnd( evt->Position() );
836  area.SetAdditive( m_additive );
839 
840  view->SetVisible( &area, true );
841  view->Update( &area );
842  getViewControls()->SetAutoPan( true );
843  }
844 
845  if( evt->IsMouseUp( BUT_LEFT ) )
846  {
847  getViewControls()->SetAutoPan( false );
848 
849  // End drawing the selection box
850  view->SetVisible( &area, false );
851 
852  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> candidates;
853  BOX2I selectionBox = area.ViewBBox();
854  view->Query( selectionBox, candidates ); // Get the list of nearby items
855 
856  int height = area.GetEnd().y - area.GetOrigin().y;
857 
858  // Construct an EDA_RECT to determine BOARD_ITEM selection
859  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
860 
861  selectionRect.Normalize();
862 
863  GENERAL_COLLECTOR collector;
864 
865  for( auto it = candidates.begin(), it_end = candidates.end(); it != it_end; ++it )
866  {
867  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
868 
869  if( item && Selectable( item ) && item->HitTest( selectionRect, windowSelection ) )
870  collector.Append( item );
871  }
872 
873  // Apply the stateful filter
874  FilterCollectedItems( collector );
875 
876  FilterCollectorForHierarchy( collector, true );
877 
878  for( EDA_ITEM* i : collector )
879  {
880  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
881 
882  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
883  {
884  unselect( item );
885  anySubtracted = true;
886  }
887  else
888  {
889  select( item );
890  anyAdded = true;
891  }
892  }
893 
894  m_selection.SetIsHover( false );
895 
896  // Inform other potentially interested tools
897  if( anyAdded )
899  else if( anySubtracted )
901 
902  break; // Stop waiting for events
903  }
904  }
905 
906  getViewControls()->SetAutoPan( false );
907 
908  // Stop drawing the selection box
909  view->Remove( &area );
910  m_multiple = false; // Multiple selection mode is inactive
911 
912  if( !cancelled )
914 
916 
917  return cancelled;
918 }
void ClearReferencePoint()
Definition: selection.h:191
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
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.
bool IsSelected() const
Definition: eda_item.h:123
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void SetOrigin(VECTOR2I aOrigin)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
void SetExclusiveOr(bool aExclusiveOr)
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
void SetIsHover(bool aIsHover)
Definition: selection.h:68
PCB_BASE_FRAME * m_frame
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:105
void SetAdditive(bool aAdditive)
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:225
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
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
Generic, UI-independent tool event.
Definition: tool_event.h:152
const BOX2I ViewBBox() const override
Set the origin of the rectangle (the fixed corner)
KIGFX::PCB_VIEW * view() const
static const TOOL_EVENT UninhibitSelectionEditing
Definition: actions.h:211
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
PCB_SELECTION m_selection
void unselect(BOARD_ITEM *aItem)
Take necessary action mark an item as unselected.
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
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:237
void SetSubtractive(bool aSubtractive)
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
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.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1450
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
virtual void Add(VIEW_ITEM *aItem, int aDraw