KiCad PCB EDA Suite
SELECTION_TOOL Class Reference

SELECTION_TOOL. More...

#include <selection_tool.h>

Inheritance diagram for 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 }
 

Determines the reason of reset for a tool

More...
 

Public Member Functions

 SELECTION_TOOL ()
 
 ~SELECTION_TOOL ()
 
bool Init () override
 Function Init() Init() is called once upon a registration of the tool. More...
 
void Reset (RESET_REASON aReason) override
 Function Reset() Brings the tool to a known, initial state. More...
 
int Main (const TOOL_EVENT &aEvent)
 Function Main() More...
 
PCBNEW_SELECTIONGetSelection ()
 Function GetSelection() More...
 
PCBNEW_SELECTIONRequestSelection (CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
 Function RequestSelection() More...
 
SELECTION_LOCK_FLAGS CheckLock ()
 

Checks if the user has agreed to modify locked items for the given selection.

More...
 
int CursorSelection (const TOOL_EVENT &aEvent)
 

Select a single item under cursor event handler.

More...
 
int ClearSelection (const TOOL_EVENT &aEvent)
 

Clear current selection event handler.

More...
 
void ClearSelection (bool aQuietMode=false)
 
int SelectItem (const TOOL_EVENT &aEvent)
 

Item selection event handler.

More...
 
void AddItemToSel (BOARD_ITEM *aItem, bool aQuietMode=false)
 
int SelectAll (const TOOL_EVENT &aEvent)
 

Select all items on the board

More...
 
int SelectItems (const TOOL_EVENT &aEvent)
 

Multiple item selection event handler

More...
 
int UnselectItem (const TOOL_EVENT &aEvent)
 

Item unselection event handler.

More...
 
void RemoveItemFromSel (BOARD_ITEM *aItem, bool aQuietMode=false)
 
int UnselectItems (const TOOL_EVENT &aEvent)
 

Multiple item unselection event handler

More...
 
void BrightenItem (BOARD_ITEM *aItem)
 
void UnbrightenItem (BOARD_ITEM *aItem)
 
void select (BOARD_ITEM *aItem)
 Function select() Takes necessary action mark an item as selected. More...
 
bool Selectable (const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
 Function selectable() Checks conditions for an item to be selected. More...
 
void GuessSelectionCandidates (GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
 Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items are clicked, by doing some brain-dead heuristics. More...
 
int SelectionMenu (const TOOL_EVENT &aEvent)
 Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item. More...
 
void RebuildSelection ()
 Rebuilds the selection from the EDA_ITEMs' selection flags. More...
 
SELECTION_FILTER_OPTIONSGetFilter ()
 
void setTransitions () override
 

Sets up handlers for various events.

More...
 
void zoomFitSelection ()
 

Zooms the screen to center and fit the current selection.

More...
 
BOARDGetBoard () const
 
void EnterGroup ()
 
void ExitGroup (bool aSelectGroup=false)
 Leave the currently entered group. More...
 
void FilterCollectorForGroups (GENERAL_COLLECTOR &aCollector) const
 
PCB_GROUPGetEnteredGroup ()
 
void FilterCollectedItems (GENERAL_COLLECTOR &aCollector)
 

Applies the SELECTION_FILTER_OPTIONS to a collection of items

More...
 
void SetIsFootprintEditor (bool aEnabled)
 Function SetIsFootprintEditor() More...
 
bool IsFootprintEditor () const
 
void Activate ()
 Function Activate() Runs the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Function SetContextMenu() More...
 
void RunMainStack (std::function< void()> aFunc)
 Function RunMainStack() More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Go() More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Wait() More...
 
TOOL_TYPE GetType () const
 Function GetType() Returns the type of the tool. More...
 
TOOL_ID GetId () const
 Function GetId() Returns the unique identifier of the tool. More...
 
const std::string & GetName () const
 Function GetName() Returns the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Function GetManager() Returns 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 PCBNEW_SELECTIONselection () const
 
PCBNEW_SELECTIONselection ()
 
void attachManager (TOOL_MANAGER *aManager)
 Function attachManager() More...
 
KIGFX::VIEWgetView () const
 Function getView() More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Function getViewControls() More...
 
template<typename T >
T * getEditFrame () const
 Function getEditFrame() More...
 
template<typename T >
T * getModel () const
 Function getModel() More...
 

Protected Attributes

bool m_isFootprintEditor
 
TOOL_MENU m_menu
 functions below are not yet implemented - their interface may change More...
 
TOOL_TYPE m_type
 

Stores the type of the tool.

More...
 
TOOL_ID m_toolId
 

Unique identifier for the tool, assigned by a TOOL_MANAGER instance.

More...
 
std::string m_toolName
 

Name of the tool.

More...
 
TOOL_MANAGERm_toolMgr
 

Private Types

enum  STOP_CONDITION { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER }
 

Private Member Functions

bool selectPoint (const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Function selectPoint() Selects an item pointed by the parameter aWhere. More...
 
bool selectCursor (bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Function selectCursor() Selects an item under the cursor unless there is something already selected or aSelectAlways is true. More...
 
bool selectMultiple ()
 Function selectMultiple() Handles drawing a selection box that allows one to select many items at the same time. More...
 
bool doSelectionMenu (GENERAL_COLLECTOR *aItems, const wxString &aTitle)
 Allows the selection of a single item from a list via pop-up menu. More...
 
int expandConnection (const TOOL_EVENT &aEvent)
 Expands the current track selection to the next boundary (junctions, pads, or all) More...
 
int selectNet (const TOOL_EVENT &aEvent)
 Selects 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)
 Selects connecteed tracks and vias. More...
 
void selectAllItemsOnNet (int aNetCode, bool aSelect=true)
 Selects all items with the given net code. More...
 
void selectAllItemsOnSheet (wxString &aSheetPath)
 Selects all items with the given sheet timestamp/UUID name (the sheet path) The path of the root sheet is "/". More...
 
int selectSheetContents (const TOOL_EVENT &aEvent)
 

Selects all footprints belonging to same sheet, from Eeschema, using crossprobing

More...
 
int selectSameSheet (const TOOL_EVENT &aEvent)
 

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

More...
 
void findCallback (BOARD_ITEM *aItem)
 

Find dialog callback.

More...
 
int find (const TOOL_EVENT &aEvent)
 

Find an item.

More...
 
int filterSelection (const TOOL_EVENT &aEvent)
 

Invoke filter dialog and modify current selection

More...
 
bool itemPassesFilter (BOARD_ITEM *aItem)
 

Returns true if the given item passes the current SELECTION_FILTER_OPTIONS

More...
 
BOARD_ITEMpickSmallestComponent (GENERAL_COLLECTOR *aCollector)
 Function pickSmallestComponent() Allows one to find the smallest (in terms of bounding box area) item from the list. More...
 
void unselect (BOARD_ITEM *aItem)
 Function unselect() Takes necessary action mark an item as unselected. More...
 
void highlight (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
 Function highlight() Highlights the item visually. More...
 
void unhighlight (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
 Function unhighlight() Unhighlights the item visually. More...
 
bool selectionContains (const VECTOR2I &aPoint) const
 Function selectionContains() More...
 
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, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)
 
void unhighlightInternal (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
PCBNEW_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_locked
 
PCB_GROUPm_enteredGroup
 
KIGFX::VIEW_GROUP m_enteredGroupOverlay
 
std::unique_ptr< PRIVm_priv
 

Detailed Description

SELECTION_TOOL.

Our sample selection tool: currently supports:

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

Definition at line 64 of file 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 111 of file pcb_tool_base.h.

111  {
113  IPO_ROTATE = 0x01,
114 
116  IPO_FLIP = 0x02,
117 
120  IPO_SINGLE_CLICK = 0x04,
121 
123  IPO_REPEAT = 0x08
124  };
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

Determines 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 79 of file tool_base.h.

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

◆ 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 261 of file selection_tool.h.

262  {
270  STOP_AT_PAD,
272  STOP_NEVER
273  };
Select the entire net.
Stop at any place where more than two traces meet.
Stop when reaching a pad.

Constructor & Destructor Documentation

◆ SELECTION_TOOL()

SELECTION_TOOL::SELECTION_TOOL ( )

Definition at line 97 of file selection_tool.cpp.

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

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

◆ ~SELECTION_TOOL()

SELECTION_TOOL::~SELECTION_TOOL ( )

Definition at line 123 of file selection_tool.cpp.

124 {
125  getView()->Remove( &m_selection );
127 }
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
PCBNEW_SELECTION m_selection
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
KIGFX::VIEW_GROUP m_enteredGroupOverlay

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

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs 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:219
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls 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(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), SCH_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC_TOOL::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ AddItemToSel()

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

Definition at line 885 of file selection_tool.cpp.

886 {
887  if( aItem )
888  {
889  select( aItem );
890 
891  // Inform other potentially interested tools
892  if( !aQuietMode )
894  }
895 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates 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 PCBNEW_CONTROL::DeleteItemCursor(), EDIT_TOOL::FilletTracks(), and SelectItem().

◆ attachManager()

void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Function attachManager()

Sets 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:219

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 160 of file pcb_tool_base.h.

160 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), PCB_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), FOOTPRINT_EDITOR_TOOLS::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), filterSelection(), PCB_TOOL_BASE::footprint(), GetBoard(), getCollectorsGuide(), GROUP_TOOL::Group(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::MoveExact(), FOOTPRINT_EDITOR_TOOLS::NewFootprint(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PAD_TOOL::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), RebuildSelection(), PAD_TOOL::recombinePad(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::RepairBoard(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), Selectable(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), selectPoint(), PCBNEW_CONTROL::TrackDisplayMode(), GROUP_TOOL::Ungroup(), PCBNEW_CONTROL::ViaDisplayMode(), PCBNEW_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ BrightenItem()

void SELECTION_TOOL::BrightenItem ( BOARD_ITEM aItem)

Definition at line 934 of file selection_tool.cpp.

935 {
936  highlight( aItem, BRIGHTENED );
937 }
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129

References BRIGHTENED, and highlight().

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

◆ canvas()

◆ CheckLock()

SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock ( )

Checks if the user has agreed to modify locked items for the given selection.

Definition at line 770 of file selection_tool.cpp.

771 {
772  if( !m_locked || m_isFootprintEditor )
773  return SELECTION_UNLOCKED;
774 
775  bool containsLocked = false;
776 
777  // Check if the selection contains locked items
778  for( EDA_ITEM* item : m_selection )
779  {
780  switch( item->Type() )
781  {
782  case PCB_FOOTPRINT_T:
783  if( static_cast<FOOTPRINT*>( item )->IsLocked() )
784  containsLocked = true;
785  break;
786 
787  case PCB_FP_SHAPE_T:
788  case PCB_FP_TEXT_T:
789  case PCB_FP_ZONE_T:
790  if( static_cast<FOOTPRINT*>( item->GetParent() )->IsLocked() )
791  containsLocked = true;
792  break;
793 
794  default: // suppress warnings
795  break;
796  }
797  }
798 
799  if( containsLocked )
800  {
801  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
802  {
803  m_locked = false;
805  }
806  else
807  return SELECTION_LOCKED;
808  }
809 
810  return SELECTION_UNLOCKED;
811 }
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
PCBNEW_SELECTION m_selection
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
PCB_BASE_FRAME * m_frame
bool m_isFootprintEditor
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
#define _(s)
Definition: 3d_actions.cpp:33
class ZONE, managed by a footprint
Definition: typeinfo.h:95
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:284

References _, IsOK(), m_frame, PCB_TOOL_BASE::m_isFootprintEditor, m_locked, m_selection, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, SELECTION_LOCK_OVERRIDE, SELECTION_LOCKED, and SELECTION_UNLOCKED.

Referenced by EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Drag(), and RequestSelection().

◆ ClearSelection() [1/2]

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 824 of file selection_tool.cpp.

825 {
826  ClearSelection();
827 
828  return 0;
829 }
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.

Referenced by EnterGroup(), ExitGroup(), filterSelection(), findCallback(), GROUP_TOOL::Group(), Main(), RequestSelection(), Reset(), selectCursor(), selectMultiple(), selectPoint(), selectSameSheet(), selectSheetContents(), and setTransitions().

◆ ClearSelection() [2/2]

void SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Definition at line 1577 of file selection_tool.cpp.

1578 {
1579  if( m_selection.Empty() )
1580  return;
1581 
1582  while( m_selection.GetSize() )
1583  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1584 
1585  view()->Update( &m_selection );
1586 
1587  m_selection.SetIsHover( false );
1589 
1590  m_locked = true;
1591 
1592  // Inform other potentially interested tools
1593  if( !aQuietMode )
1594  {
1597  }
1598 }
void ClearReferencePoint()
Definition: selection.h:267
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void SetIsHover(bool aIsHover)
Definition: selection.h:65
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:94
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
#define SELECTED
Definition: eda_item.h:113
KIGFX::PCB_VIEW * view() const
static const TOOL_EVENT ClearedEvent
Definition: actions.h:210
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:452
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_ITEM * Front() const
Definition: selection.h:201

References EVENTS::ClearedEvent, SELECTION::ClearReferencePoint(), SELECTION::Empty(), SELECTION::Front(), SELECTION::GetSize(), PCB_ACTIONS::hideDynamicRatsnest, m_locked, 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 SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Select a single item under cursor event handler.

Definition at line 814 of file selection_tool.cpp.

815 {
817 
818  selectCursor( false, aClientFilter );
819 
820  return 0;
821 }
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, SELECTION_TOOL *)

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

Referenced by setTransitions().

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

◆ 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 36 of file pcb_tool_base.cpp.

39 {
40  using namespace std::placeholders;
41  std::unique_ptr<BOARD_ITEM> newItem;
42 
43  frame()->PushTool( aTool );
44  Activate();
45 
46  BOARD_COMMIT commit( frame() );
47 
49 
50  // do not capture or auto-pan until we start placing an item
51  controls()->ShowCursor( true );
52 
53  // Add a VIEW_GROUP that serves as a preview for the new item
54  PCBNEW_SELECTION preview;
55  view()->Add( &preview );
56 
57  aPlacer->m_board = board();
58  aPlacer->m_frame = frame();
59  aPlacer->m_modifiers = 0;
60 
61  auto makeNewItem =
62  [&]( VECTOR2I aPosition )
63  {
64  if( frame()->GetModel() )
65  newItem = aPlacer->CreateItem();
66 
67  if( newItem )
68  {
69  newItem->SetPosition( (wxPoint) aPosition );
70  preview.Add( newItem.get() );
71 
72  if( newItem->Type() == PCB_FOOTPRINT_T )
73  {
74  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
75 
76  // footprints have more drawable parts
77  fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
78  }
79  }
80  };
81 
82  if( aOptions & IPO_SINGLE_CLICK )
83  makeNewItem( controls()->GetCursorPosition() );
84 
85  auto setCursor =
86  [&]()
87  {
88  if( !newItem )
90  else
92  };
93 
94  // Set initial cursor
95  setCursor();
96 
97  // Main loop: keep receiving events
98  while( TOOL_EVENT* evt = Wait() )
99  {
100  setCursor();
101 
102  VECTOR2I cursorPos = controls()->GetCursorPosition();
103  aPlacer->m_modifiers = evt->Modifier();
104 
105  auto cleanup =
106  [&] ()
107  {
108  newItem = nullptr;
109  preview.Clear();
110  view()->Update( &preview );
111  controls()->SetAutoPan( false );
112  controls()->CaptureCursor( false );
113  controls()->ShowCursor( true );
114  };
115 
116  if( evt->IsCancelInteractive() )
117  {
118  if( aOptions & IPO_SINGLE_CLICK )
119  {
120  cleanup();
121  frame()->PopTool( aTool );
122  break;
123  }
124  else if( newItem )
125  cleanup();
126  else
127  {
128  frame()->PopTool( aTool );
129  break;
130  }
131  }
132  else if( evt->IsActivate() )
133  {
134  if( newItem )
135  cleanup();
136 
137  if( evt->IsPointEditor() )
138  {
139  // don't exit (the point editor runs in the background)
140  }
141  else if( evt->IsMoveTool() )
142  {
143  // leave ourselves on the stack so we come back after the move
144  break;
145  }
146  else
147  {
148  frame()->PopTool( aTool );
149  break;
150  }
151  }
152  else if( evt->IsClick( BUT_LEFT ) )
153  {
154  if( !newItem )
155  {
156  // create the item if possible
157  makeNewItem( cursorPos );
158 
159  // no item created, so wait for another click
160  if( !newItem )
161  continue;
162 
163  controls()->CaptureCursor( true );
164  controls()->SetAutoPan( true );
165  }
166  else
167  {
168  auto oldFlags = newItem->GetFlags();
169  newItem->ClearFlags();
170 
171  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
172  {
173  newItem->SetFlags( oldFlags );
174  continue;
175  }
176 
177  preview.Clear();
178  newItem.release();
179  commit.Push( aCommitMessage );
180 
181  controls()->CaptureCursor( false );
182  controls()->SetAutoPan( false );
183  controls()->ShowCursor( true );
184 
185  if( !( aOptions & IPO_REPEAT ) )
186  break;
187 
188  if( aOptions & IPO_SINGLE_CLICK )
189  makeNewItem( controls()->GetCursorPosition() );
190 
191  setCursor();
192  }
193  }
194  else if( evt->IsClick( BUT_RIGHT ) )
195  {
197  }
198  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
199  {
201  }
202  else if( newItem && evt->Category() == TC_COMMAND )
203  {
204  /*
205  * Handle any events that can affect the item as we move it around
206  */
207  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
208  {
209  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
210  newItem->Rotate( newItem->GetPosition(), rotationAngle );
211  view()->Update( &preview );
212  }
213  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
214  {
215  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
216  view()->Update( &preview );
217  }
218  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
219  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
220  {
221  // Refresh preview after event runs
223  }
224  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
225  {
226  preview.Clear();
227  newItem.release();
228 
229  makeNewItem( (wxPoint) cursorPos );
230  aPlacer->SnapItem( newItem.get() );
231  view()->Update( &preview );
232  }
233  }
234  else if( newItem && evt->IsMotion() )
235  {
236  // track the cursor
237  newItem->SetPosition( (wxPoint) cursorPos );
238  aPlacer->SnapItem( newItem.get() );
239 
240  // Show a preview of the item
241  view()->Update( &preview );
242  }
243  else
244  {
245  evt->SetPassEvent();
246  }
247  }
248 
249  view()->Remove( &preview );
251 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
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
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:296
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:219
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:299
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
TOOL_MANAGER * GetManager() const
Function GetManager() Returns 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, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:94
const PCBNEW_SELECTION & selection() const
Allow repeat placement of the item.
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
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)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:108
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
PCBNEW_SETTINGS & Settings()
void Activate()
Function Activate() Runs the tool.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Function RunOnChildren.
Definition: footprint.cpp:1089
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:59
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:65
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:297
static TOOL_ACTION refreshPreview
Definition: actions.h:104
VECTOR2D GetCursorPosition() const
Returns 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_FOOTPRINT_T, PENCIL, PLACE, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), FOOTPRINT::RunOnChildren(), 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 SELECTION_TOOL::doSelectionMenu ( GENERAL_COLLECTOR aItems,
const wxString &  aTitle 
)
private

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

Parameters
aTitle(optional) Allows the menu to be titled (ie: "Clarify Selection").
Returns
true if an item was picked

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

Definition at line 1636 of file selection_tool.cpp.

1637 {
1638  BOARD_ITEM* current = nullptr;
1639  PCBNEW_SELECTION highlightGroup;
1640  bool selectAll = false;
1641  bool expandSelection = false;
1642 
1643  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1644  getView()->Add( &highlightGroup );
1645 
1646  do
1647  {
1649  if( expandSelection )
1650  aCollector->Combine();
1651 
1652  expandSelection = false;
1653 
1654  int limit = std::min( 9, aCollector->GetCount() );
1655  ACTION_MENU menu( true );
1656 
1657  for( int i = 0; i < limit; ++i )
1658  {
1659  wxString text;
1660  BOARD_ITEM* item = ( *aCollector )[i];
1661  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1662 
1663  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1664  menu.Add( menuText, i + 1, item->GetMenuImage() );
1665  }
1666 
1667  menu.AppendSeparator();
1668  menu.Add( _( "Select &All\tA" ), limit + 1, plus_xpm );
1669 
1670  if( !expandSelection && aCollector->HasAdditionalItems() )
1671  menu.Add( _( "&Expand Selection\tE" ), limit + 2, nullptr );
1672 
1673  if( aTitle.Length() )
1674  {
1675  menu.SetTitle( aTitle );
1676  menu.SetIcon( info_xpm );
1677  menu.DisplayTitle( true );
1678  }
1679  else
1680  menu.DisplayTitle( false );
1681 
1682  SetContextMenu( &menu, CMENU_NOW );
1683 
1684  while( TOOL_EVENT* evt = Wait() )
1685  {
1686  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1687  {
1688  if( selectAll )
1689  {
1690  for( int i = 0; i < aCollector->GetCount(); ++i )
1691  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1692  }
1693  else if( current )
1694  unhighlight( current, BRIGHTENED, &highlightGroup );
1695 
1696  int id = *evt->GetCommandId();
1697 
1698  // User has pointed an item, so show it in a different way
1699  if( id > 0 && id <= limit )
1700  {
1701  current = ( *aCollector )[id - 1];
1702  highlight( current, BRIGHTENED, &highlightGroup );
1703  }
1704  else
1705  current = nullptr;
1706 
1707  // User has pointed on the "Select All" option
1708  if( id == limit + 1 )
1709  {
1710  for( int i = 0; i < aCollector->GetCount(); ++i )
1711  highlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1712  selectAll = true;
1713  }
1714  else
1715  selectAll = false;
1716  }
1717  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1718  {
1719  if( selectAll )
1720  {
1721  for( int i = 0; i < aCollector->GetCount(); ++i )
1722  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1723  }
1724  else if( current )
1725  unhighlight( current, BRIGHTENED, &highlightGroup );
1726 
1727  OPT<int> id = evt->GetCommandId();
1728 
1729  // User has selected the "Select All" option
1730  if( id == limit + 1 )
1731  {
1732  selectAll = true;
1733  current = nullptr;
1734  }
1735  else if( id == limit + 2 )
1736  {
1737  expandSelection = true;
1738  selectAll = false;
1739  current = nullptr;
1740  }
1741  // User has selected an item, so this one will be returned
1742  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1743  {
1744  selectAll = false;
1745  current = ( *aCollector )[*id - 1];
1746  }
1747  else
1748  {
1749  selectAll = false;
1750  current = nullptr;
1751  }
1752  }
1753  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1754  {
1755  break;
1756  }
1757  }
1758  } while( expandSelection );
1759 
1760  getView()->Remove( &highlightGroup );
1761 
1762  if( selectAll )
1763  return true;
1764  else if( current )
1765  {
1766  aCollector->Empty();
1767  aCollector->Append( current );
1768  return true;
1769  }
1770 
1771  return false;
1772 }
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129
TOOL_EVENT.
Definition: tool_event.h:171
PCB_BASE_FRAME * m_frame
const BITMAP_OPAQUE info_xpm[1]
Definition: info.cpp:75
virtual void SetLayer(int aLayer)
Function SetLayer() Sets layer used to draw the group.
Definition: view_group.h:115
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: eda_item.cpp:123
currently selected items overlay
boost::optional< T > OPT
Definition: optional.h:7
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: eda_item.cpp:221
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
const BITMAP_OPAQUE plus_xpm[1]
Definition: plus.cpp:66

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_xpm, LAYER_SELECT_OVERLAY, m_frame, plus_xpm, KIGFX::VIEW::Remove(), TOOL_INTERACTIVE::SetContextMenu(), KIGFX::VIEW_GROUP::SetLayer(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_CLOSED, TA_CHOICE_MENU_UPDATE, unhighlight(), and TOOL_INTERACTIVE::Wait().

Referenced by SelectionMenu(), and selectPoint().

◆ EnterGroup()

void SELECTION_TOOL::EnterGroup ( )

Definition at line 369 of file selection_tool.cpp.

370 {
371  wxCHECK_RET( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T,
372  "EnterGroup called when selection is not a single group" );
373  PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
374 
375  if( m_enteredGroup != NULL )
376  ExitGroup();
377 
378  ClearSelection();
379  m_enteredGroup = aGroup;
380  m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem )
381  {
382  select( titem );
383  } );
384 
386 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
PCBNEW_SELECTION m_selection
PCB_GROUP * m_enteredGroup
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
#define NULL
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invokes a function on all members of the group.
Definition: pcb_group.cpp:313
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
KIGFX::VIEW_GROUP m_enteredGroupOverlay

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

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

◆ ExitGroup()

void SELECTION_TOOL::ExitGroup ( bool  aSelectGroup = false)

Leave the currently entered group.

Parameters
aSelectGroupwhen true will select the group after leaving

Definition at line 389 of file selection_tool.cpp.

390 {
391  // Only continue if there is a group entered
392  if( m_enteredGroup == nullptr )
393  return;
394 
395  ClearSelection();
396 
397  if( aSelectGroup )
399 
401  m_enteredGroup = nullptr;
402 }
virtual void Clear()
Function Clear() Removes all the stored items from the group.
Definition: view_group.cpp:74
PCB_GROUP * m_enteredGroup
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
KIGFX::VIEW_GROUP m_enteredGroupOverlay

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

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

◆ expandConnection()

int SELECTION_TOOL::expandConnection ( const TOOL_EVENT aEvent)
private

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

Definition at line 965 of file selection_tool.cpp.

966 {
967  unsigned initialCount = 0;
968 
969  for( auto item : m_selection.GetItems() )
970  {
971  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
972  initialCount++;
973  }
974 
975  if( initialCount == 0 )
977 
978  for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
979  {
980  // copy the selection, since we're going to iterate and modify
981  std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
982 
983  for( EDA_ITEM* item : selectedItems )
984  item->ClearTempFlags();
985 
986  for( EDA_ITEM* item : selectedItems )
987  {
988  TRACK* trackItem = dynamic_cast<TRACK*>( item );
989 
990  // Track items marked SKIP_STRUCT have already been visited
991  if( trackItem && !( trackItem->GetFlags() & SKIP_STRUCT ) )
992  selectConnectedTracks( *trackItem, stopCondition );
993  }
994 
995  if( m_selection.GetItems().size() > initialCount )
996  break;
997  }
998 
999  // Inform other potentially interested tools
1000  if( m_selection.Size() > 0 )
1002 
1003  return 0;
1004 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
Select the entire net.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
Stop at any place where more than two traces meet.
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Selects connecteed tracks and vias.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
Stop when reaching a pad.
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, SELECTION_TOOL *sTool)
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
STATUS_FLAGS GetFlags() const
Definition: eda_item.h:222
Definition: track.h:83

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 SELECTION_TOOL::FilterCollectedItems ( GENERAL_COLLECTOR aCollector)

Applies the SELECTION_FILTER_OPTIONS to a collection of items

Definition at line 1481 of file selection_tool.cpp.

1482 {
1483  if( aCollector.GetCount() == 0 )
1484  return;
1485 
1486  std::set<BOARD_ITEM*> rejected;
1487 
1488  for( EDA_ITEM* i : aCollector )
1489  {
1490  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1491 
1492  if( !itemPassesFilter( item ) )
1493  rejected.insert( item );
1494  }
1495 
1496  for( BOARD_ITEM* item : rejected )
1497  aCollector.Remove( item );
1498 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
bool itemPassesFilter(BOARD_ITEM *aItem)
Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:104
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148

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

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

◆ FilterCollectorForGroups()

void SELECTION_TOOL::FilterCollectorForGroups ( GENERAL_COLLECTOR aCollector) const

Definition at line 2582 of file selection_tool.cpp.

2583 {
2584  std::unordered_set<BOARD_ITEM*> toAdd;
2585 
2586  // If any element is a member of a group, replace those elements with the top containing group.
2587  for( int j = 0; j < aCollector.GetCount(); )
2588  {
2589  BOARD_ITEM* item = aCollector[j];
2591 
2592  if( aTop != NULL )
2593  {
2594  if( aTop != item )
2595  {
2596  toAdd.insert( aTop );
2597  aCollector.Remove( item );
2598  continue;
2599  }
2600  }
2601  else if( m_enteredGroup && !PCB_GROUP::WithinScope( item, m_enteredGroup ) )
2602  {
2603  // If a group is entered, disallow selections of objects outside the group.
2604  aCollector.Remove( item );
2605  continue;
2606  }
2607 
2608  ++j;
2609  }
2610 
2611  for( BOARD_ITEM* item : toAdd )
2612  {
2613  if( !aCollector.HasItem( item ) )
2614  aCollector.Append( item );
2615  }
2616 }
static bool WithinScope(BOARD_ITEM *item, PCB_GROUP *scope)
Definition: pcb_group.cpp:86
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
PCB_GROUP * m_enteredGroup
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:133
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:104
#define NULL
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:219
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *item, PCB_GROUP *scope)
Definition: pcb_group.cpp:72

References COLLECTOR::Append(), COLLECTOR::GetCount(), COLLECTOR::HasItem(), m_enteredGroup, NULL, COLLECTOR::Remove(), PCB_GROUP::TopLevelGroup(), and PCB_GROUP::WithinScope().

Referenced by EditToolSelectionFilter(), selectMultiple(), and selectPoint().

◆ filterSelection()

int SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection

Definition at line 1449 of file selection_tool.cpp.

1450 {
1451  const BOARD& board = *getModel<BOARD>();
1452  DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
1453  DIALOG_FILTER_SELECTION dlg( m_frame, opts );
1454 
1455  const int cmd = dlg.ShowModal();
1456 
1457  if( cmd != wxID_OK )
1458  return 0;
1459 
1460  // copy current selection
1461  std::deque<EDA_ITEM*> selection = m_selection.GetItems();
1462 
1463  ClearSelection( true /*quiet mode*/ );
1464 
1465  // re-select items from the saved selection according to the dialog options
1466  for( EDA_ITEM* i : selection )
1467  {
1468  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1469  bool include = itemIsIncludedByFilter( *item, board, opts );
1470 
1471  if( include )
1472  select( item );
1473  }
1474 
1476 
1477  return 0;
1478 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
BOARD * board() const
std::unique_ptr< PRIV > m_priv
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
Struct that will be set with the result of the user choices in the dialog.
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
const PCBNEW_SELECTION & selection() const
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
PCB_BASE_FRAME * m_frame
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Function itemIsIncludedByFilter()
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148

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 SELECTION_TOOL::find ( const TOOL_EVENT aEvent)
private

Find an item.

Definition at line 1371 of file selection_tool.cpp.

1372 {
1373  DIALOG_FIND dlg( m_frame );
1374  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1375  dlg.ShowModal();
1376 
1377  return 0;
1378 }
void findCallback(BOARD_ITEM *aItem)
Find dialog callback.
PCB_BASE_FRAME * m_frame

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

Referenced by setTransitions().

◆ findCallback()

void SELECTION_TOOL::findCallback ( BOARD_ITEM aItem)
private

Find dialog callback.

Definition at line 1342 of file selection_tool.cpp.

1343 {
1344  bool cleared = false;
1345 
1346  if( m_selection.GetSize() > 0 )
1347  {
1348  // Don't fire an event now; most of the time it will be redundant as we're about to
1349  // fire a SelectedEvent.
1350  cleared = true;
1351  ClearSelection( true /*quiet mode*/ );
1352  }
1353 
1354  if( aItem )
1355  {
1356  select( aItem );
1357  m_frame->FocusOnLocation( aItem->GetPosition() );
1358 
1359  // Inform other potentially interested tools
1361  }
1362  else if( cleared )
1363  {
1365  }
1366 
1368 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
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:219
PCBNEW_SELECTION m_selection
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
PCB_BASE_FRAME * m_frame
static const TOOL_EVENT ClearedEvent
Definition: actions.h:210
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...

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 155 of file pcb_tool_base.h.

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

Referenced by POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_TOOLS::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), 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(), PCB_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), EDIT_TOOL::FilletTracks(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), FOOTPRINT_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_TOOL::Init(), Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCBNEW_PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), GROUP_TOOL::PickNewMember(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), PAD_TOOL::recombinePad(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), PCB_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ GetBoard()

BOARD* SELECTION_TOOL::GetBoard ( ) const
inline

Definition at line 182 of file selection_tool.h.

183  {
184  return board();
185  }
BOARD * board() const

References PCB_TOOL_BASE::board().

Referenced by GROUP_CONTEXT_MENU::update().

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 494 of file selection_tool.cpp.

495 {
496  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
497  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
498 
499  bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
500 
501  // account for the globals
502  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
503  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
504  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
505  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
506  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
507  guide.SetIgnorePadsOnBack( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_BK ) );
508  guide.SetIgnorePadsOnFront( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_FR ) );
509  guide.SetIgnoreThroughHolePads( padsDisabled || ! board()->IsElementVisible( LAYER_PADS_TH ) );
510  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
511  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
512  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIAS ) );
513  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIAS ) );
514  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIAS ) );
515  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
516 
517  return guide;
518 }
BOARD * board() const
multilayer pads, usually with holes
show footprints on back
show footprints values (when texts are visibles)
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:497
smd pads, front layer
Meta control for all vias opacity/visibility.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:376
show footprints references (when texts are visibles)

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

◆ getEditFrame()

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

Function getEditFrame()

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

Definition at line 187 of file tool_base.h.

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

References TOOL_BASE::getToolHolderInt().

Referenced by ZONE_CREATE_HELPER::createNewZone().

◆ GetEnteredGroup()

PCB_GROUP* SELECTION_TOOL::GetEnteredGroup ( )
inline

Definition at line 198 of file selection_tool.h.

198 { return m_enteredGroup; }
PCB_GROUP * m_enteredGroup

References m_enteredGroup.

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

◆ GetFilter()

SELECTION_FILTER_OPTIONS& SELECTION_TOOL::GetFilter ( )
inline

Definition at line 171 of file selection_tool.h.

172  {
173  return m_filter;
174  }
SELECTION_FILTER_OPTIONS m_filter

References m_filter.

Referenced by PANEL_SELECTION_FILTER::OnFilterChanged(), and PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER().

◆ GetId()

TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Function GetId() Returns the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 121 of file tool_base.h.

122  {
123  return m_toolId;
124  }
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214

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

Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER. If there is no TOOL_MANAGER associated, it returns NULL.

Definition at line 143 of file tool_base.h.

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

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

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 201 of file tool_base.h.

202  {
203  EDA_ITEM* m = getModelInt();
204 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
205  wxASSERT( dynamic_cast<T*>( m ) );
206 #endif
207  return static_cast<T*>( m );
208  }
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:54
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148

References TOOL_BASE::getModelInt().

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

◆ GetName()

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

Function GetName() Returns 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 132 of file tool_base.h.

133  {
134  return m_toolName;
135  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:218

References TOOL_BASE::m_toolName.

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

◆ GetSelection()

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 110 of file tool_base.h.

111  {
112  return m_type;
113  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:211

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

Function getView()

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:290
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219

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(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_EDIT_TOOL::DoDelete(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), MICROWAVE_TOOL::drawMicrowaveInductor(), PL_DRAWING_TOOLS::DrawShape(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_EDITOR_CONTROL::FindComponentAndItem(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), GuessSelectionCandidates(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCB_INSPECTION_TOOL::highlightNet(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::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(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_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(), selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), 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(), POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PL_POINT_EDITOR::updateItem(), 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(), 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 ~SELECTION_TOOL().

◆ getViewControls()

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

Function getViewControls()

Returns 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:219
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:292

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

Referenced by EE_POINT_EDITOR::addCorner(), 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(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), FOOTPRINT_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), SCH_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), LIB_DRAWING_TOOLS::PlaceAnchor(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_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(), 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(), PICKER_TOOL::setControls(), PCBNEW_PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateItem(), PL_EDIT_TOOL::updateModificationPoint(), 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

Function Go()

Defines which state (aStateFunc) to go when a certain event arrives (aConditions). No conditions means any event.

Definition at line 129 of file tool_interactive.h.

131 {
132  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
133 
134  goInternal( sptr, aConditions );
135 }
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 ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), PCB_REANNOTATE_TOOL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), LIB_PIN_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), DRC_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), POINT_EDITOR::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), PAD_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), PL_EDIT_TOOL::setTransitions(), FOOTPRINT_EDITOR_TOOLS::setTransitions(), SCH_EDIT_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), DRAWING_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), setTransitions(), PL_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ GuessSelectionCandidates()

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

Function guessSelectionCandidates() Tries 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 2244 of file selection_tool.cpp.

2246 {
2247  std::set<BOARD_ITEM*> preferred;
2248  std::set<BOARD_ITEM*> rejected;
2249  wxPoint where( aWhere.x, aWhere.y );
2250 
2251  // footprints which are below this percentage of the largest footprint will be considered
2252  // for selection; all others will not
2253  constexpr double footprintToFootprintMinRatio = 0.20;
2254  // pads which are below this percentage of their parent's area will exclude their parent
2255  constexpr double padToFootprintMinRatio = 0.45;
2256  // footprints containing items with items-to-footprint area ratio higher than this will be
2257  // forced to stay on the list
2258  constexpr double footprintMaxCoverRatio = 0.90;
2259  constexpr double viaToPadMinRatio = 0.50;
2260  constexpr double trackViaLengthRatio = 2.0;
2261  constexpr double trackTrackLengthRatio = 0.3;
2262  constexpr double textToFeatureMinRatio = 0.2;
2263  constexpr double textToFootprintMinRatio = 0.4;
2264  // If the common area of two compared items is above the following threshold, they cannot
2265  // be rejected (it means they overlap and it might be hard to pick one by selecting
2266  // its unique area).
2267  constexpr double commonAreaRatio = 0.6;
2268 
2269  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
2270  LSET silkLayers( 2, B_SilkS, F_SilkS );
2271 
2272  if( silkLayers[activeLayer] )
2273  {
2274  for( int i = 0; i < aCollector.GetCount(); ++i )
2275  {
2276  BOARD_ITEM* item = aCollector[i];
2277  KICAD_T type = item->Type();
2278 
2279  if( ( type == PCB_FP_TEXT_T || type == PCB_TEXT_T || type == PCB_SHAPE_T )
2280  && silkLayers[item->GetLayer()] )
2281  {
2282  preferred.insert( item );
2283  }
2284  }
2285 
2286  if( preferred.size() > 0 )
2287  {
2288  aCollector.Empty();
2289 
2290  for( BOARD_ITEM* item : preferred )
2291  aCollector.Append( item );
2292  return;
2293  }
2294  }
2295 
2296  // Zone edges are very specific; zone fills much less so.
2297  if( aCollector.CountType( PCB_ZONE_T ) > 0 )
2298  {
2299  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2300  {
2301  if( aCollector[i]->Type() == PCB_ZONE_T )
2302  {
2303  ZONE* zone = static_cast<ZONE*>( aCollector[i] );
2304 
2305  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
2306  preferred.insert( zone );
2307  else
2308  rejected.insert( zone );
2309  }
2310  }
2311 
2312  if( preferred.size() > 0 )
2313  {
2314  aCollector.Empty();
2315 
2316  for( BOARD_ITEM* item : preferred )
2317  aCollector.Append( item );
2318  return;
2319  }
2320  }
2321 
2322  if( aCollector.CountType( PCB_FP_TEXT_T ) > 0 )
2323  {
2324  for( int i = 0; i < aCollector.GetCount(); ++i )
2325  {
2326  if( FP_TEXT* txt = dyn_cast<FP_TEXT*>( aCollector[i] ) )
2327  {
2328  double textArea = calcArea( txt );
2329 
2330  for( int j = 0; j < aCollector.GetCount(); ++j )
2331  {
2332  if( i == j )
2333  continue;
2334 
2335  BOARD_ITEM* item = aCollector[j];
2336  double itemArea = calcArea( item );
2337  double areaRatio = calcRatio( textArea, itemArea );
2338  double commonArea = calcCommonArea( txt, item );
2339  double itemCommonRatio = calcRatio( commonArea, itemArea );
2340  double txtCommonRatio = calcRatio( commonArea, textArea );
2341 
2342  if( item->Type() == PCB_FOOTPRINT_T )
2343  {
2344  // when text area is small compared to an overlapping footprint,
2345  // then it's a clear sign the text is the selection target
2346  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
2347  rejected.insert( item );
2348  }
2349 
2350  switch( item->Type() )
2351  {
2352  case PCB_TRACE_T:
2353  case PCB_ARC_T:
2354  case PCB_PAD_T:
2355  case PCB_SHAPE_T:
2356  case PCB_VIA_T:
2357  case PCB_FOOTPRINT_T:
2358  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
2359  rejected.insert( txt );
2360  break;
2361  default:
2362  break;
2363  }
2364  }
2365  }
2366  }
2367  }
2368 
2369  if( aCollector.CountType( PCB_FP_SHAPE_T ) + aCollector.CountType( PCB_SHAPE_T ) > 1 )
2370  {
2371  // Prefer exact hits to sloppy ones
2372  int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
2373  bool found = false;
2374 
2375  for( int dist = 0; dist < accuracy; ++dist )
2376  {
2377  for( int i = 0; i < aCollector.GetCount(); ++i )
2378  {
2379  if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aCollector[i] ) )
2380  {
2381  if( shape->HitTest( where, dist ) )
2382  {
2383  found = true;
2384  break;
2385  }
2386  }
2387  }
2388 
2389  if( found )
2390  {
2391  // throw out everything that is more sloppy than what we found
2392  for( int i = 0; i < aCollector.GetCount(); ++i )
2393  {
2394  if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aCollector[i] ) )
2395  {
2396  if( !shape->HitTest( where, dist ) )
2397  rejected.insert( shape );
2398  }
2399  }
2400 
2401  // we're done now
2402  break;
2403  }
2404  }
2405  }
2406 
2407  if( aCollector.CountType( PCB_PAD_T ) > 0 )
2408  {
2409  for( int i = 0; i < aCollector.GetCount(); ++i )
2410  {
2411  if( PAD* pad = dyn_cast<PAD*>( aCollector[i] ) )
2412  {
2413  FOOTPRINT* parent = pad->GetParent();
2414  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
2415 
2416  // when pad area is small compared to the parent footprint,
2417  // then it is a clear sign the pad is the selection target
2418  if( ratio < padToFootprintMinRatio )
2419  rejected.insert( pad->GetParent() );
2420  }
2421  }
2422  }
2423 
2424  bool hasNonModules = false;
2425 
2426  for( int i = 0; i < aCollector.GetCount(); ++i )
2427  {
2428  if( aCollector[i]->Type() != PCB_FOOTPRINT_T )
2429  {
2430  hasNonModules = true;
2431  break;
2432  }
2433  }
2434 
2435  if( aCollector.CountType( PCB_FOOTPRINT_T ) > 0 )
2436  {
2437  double maxArea = calcMaxArea( aCollector, PCB_FOOTPRINT_T );
2438  BOX2D viewportD = getView()->GetViewport();
2439  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2440  double maxCoverRatio = footprintMaxCoverRatio;
2441 
2442  // FOOTPRINT::CoverageRatio() doesn't take zone handles & borders into account so just
2443  // use a more aggressive cutoff point if zones are involved.
2444  if( aCollector.CountType( PCB_ZONE_T ) )
2445  maxCoverRatio /= 2;
2446 
2447  for( int i = 0; i < aCollector.GetCount(); ++i )
2448  {
2449  if( FOOTPRINT* footprint = dyn_cast<FOOTPRINT*>( aCollector[i] ) )
2450  {
2451  // filter out components larger than the viewport
2452  if( footprint->ViewBBox().GetHeight() > viewport.GetHeight()
2453  || footprint->ViewBBox().GetWidth() > viewport.GetWidth() )
2454  {
2455  rejected.insert( footprint );
2456  }
2457  // footprints completely covered with other features have no other
2458  // means of selection, so must be kept
2459  else if( footprint->CoverageRatio( aCollector ) > maxCoverRatio )
2460  {
2461  rejected.erase( footprint );
2462  }
2463  // if a footprint is much smaller than the largest overlapping
2464  // footprint then it should be considered for selection
2465  else if( calcRatio( calcArea( footprint ), maxArea ) <= footprintToFootprintMinRatio )
2466  {
2467  continue;
2468  }
2469  // reject ALL OTHER footprints if there's still something else left
2470  // to select
2471  else if( hasNonModules )
2472  {
2473  rejected.insert( footprint );
2474  }
2475  }
2476  }
2477  }
2478 
2479  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2480  {
2481  for( int i = 0; i < aCollector.GetCount(); ++i )
2482  {
2483  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2484  {
2485  double viaArea = calcArea( via );
2486 
2487  for( int j = 0; j < aCollector.GetCount(); ++j )
2488  {
2489  if( i == j )
2490  continue;
2491 
2492  BOARD_ITEM* item = aCollector[j];
2493  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2494 
2495  if( item->Type() == PCB_FOOTPRINT_T && areaRatio < padToFootprintMinRatio )
2496  rejected.insert( item );
2497 
2498  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2499  rejected.insert( item );
2500 
2501  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2502  {
2503  if( track->GetNetCode() != via->GetNetCode() )
2504  continue;
2505 
2506  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2507  (double) via->GetWidth();
2508 
2509  if( lenRatio > trackViaLengthRatio )
2510  rejected.insert( track );
2511  }
2512  }
2513  }
2514  }
2515  }
2516 
2517  int nTracks = aCollector.CountType( PCB_TRACE_T );
2518 
2519  if( nTracks > 0 )
2520  {
2521  double maxLength = 0.0;
2522  double minLength = std::numeric_limits<double>::max();
2523  double maxArea = 0.0;
2524  const TRACK* maxTrack = nullptr;
2525 
2526  for( int i = 0; i < aCollector.GetCount(); ++i )
2527  {
2528  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2529  {
2530  maxLength = std::max( track->GetLength(), maxLength );
2531  maxLength = std::max( (double) track->GetWidth(), maxLength );
2532 
2533  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2534 
2535  double area = track->GetLength() * track->GetWidth();
2536 
2537  if( area > maxArea )
2538  {
2539  maxArea = area;
2540  maxTrack = track;
2541  }
2542  }
2543  }
2544 
2545  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2546  {
2547  for( int i = 0; i < aCollector.GetCount(); ++i )
2548  {
2549  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2550  {
2551  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2552 
2553  if( ratio > trackTrackLengthRatio )
2554  rejected.insert( track );
2555  }
2556  }
2557  }
2558 
2559  for( int j = 0; j < aCollector.GetCount(); ++j )
2560  {
2561  if( FOOTPRINT* footprint = dyn_cast<FOOTPRINT*>( aCollector[j] ) )
2562  {
2563  double ratio = calcRatio( maxArea, footprint->GetFootprintRect().GetArea() );
2564 
2565  if( ratio < padToFootprintMinRatio
2566  && calcCommonArea( maxTrack, footprint ) < commonAreaRatio )
2567  {
2568  rejected.insert( footprint );
2569  }
2570  }
2571  }
2572  }
2573 
2574  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2575  {
2576  for( BOARD_ITEM* item : rejected )
2577  aCollector.Transfer( item );
2578  }
2579 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:113
Definition: track.h:354
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:519
static double calcCommonArea(const BOARD_ITEM *aItem, const BOARD_ITEM *aOther)
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
virtual double OnePixelInIU() const =0
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
double CoverageRatio(const GENERAL_COLLECTOR &aCollector) const
Function CoverageRatio Calculates the ratio of total area of the footprint pads and graphical items t...
Definition: footprint.cpp:1640
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class PAD, a pad in a footprint
Definition: typeinfo.h:90
const COLLECTORS_GUIDE * GetGuide()
Definition: collectors.h:338
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
int CountType(KICAD_T aType)
Function CountType counts the number of items matching aType.
Definition: collector.h:252
static double calcArea(const BOARD_ITEM *aItem)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:104
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Build and returns the boundary box of the footprint excluding any text.
Definition: footprint.cpp:579
void Transfer(int aIndex)
Moves the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:175
PCB_LAYER_ID
A quick note on layer IDs:
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
Definition: footprint.cpp:1205
LSET is a set of PCB_LAYER_IDs.
static double calcMaxArea(GENERAL_COLLECTOR &aCollector, KICAD_T aType)
virtual int GetTopLayer() const
Definition: view.cpp:829
coord_type GetWidth() const
Definition: box2.h:197
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:106
double GetArea() const
Function GetArea returns the area of the rectangle.
Definition: eda_rect.cpp:481
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
const Vec & GetPosition() const
Definition: box2.h:194
bool HitTestForEdge(const wxPoint &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX &aCornerHit) const
Function HitTestForEdge tests if the given wxPoint is near a segment defined by 2 corners.
Definition: zone.cpp:436
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:68
coord_type GetHeight() const
Definition: box2.h:198
double calcRatio(double a, double b)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const Vec & GetSize() const
Definition: box2.h:189
Definition: pad.h:59
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:179
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Definition: board_item.h:185
Definition: track.h:83
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References COLLECTOR::Append(), B_SilkS, calcArea(), calcCommonArea(), calcMaxArea(), calcRatio(), COLLECTOR::CountType(), FOOTPRINT::CoverageRatio(), COLLECTOR::Empty(), F_SilkS, PCB_TOOL_BASE::footprint(), EDA_RECT::GetArea(), COLLECTOR::GetCount(), FOOTPRINT::GetFootprintRect(), GENERAL_COLLECTOR::GetGuide(), BOX2< Vec >::GetHeight(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetParent(), BOX2< Vec >::GetPosition(), BOX2< Vec >::GetSize(), KIGFX::VIEW::GetTopLayer(), TOOL_BASE::getView(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), ZONE::HitTestForEdge(), KiROUND(), COLLECTORS_GUIDE::OnePixelInIU(), PCB_ARC_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, COLLECTOR::Transfer(), EDA_ITEM::Type(), PCB_TOOL_BASE::view(), FOOTPRINT::ViewBBox(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ highlight()

void SELECTION_TOOL::highlight ( BOARD_ITEM aItem,
int  aHighlightMode,
PCBNEW_SELECTION aGroup = nullptr 
)
private

Function highlight() Highlights 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 2031 of file selection_tool.cpp.

2032 {
2033  highlightInternal( aItem, aMode, aGroup, false );
2034 
2035  view()->Update( aItem, KIGFX::REPAINT );
2036 
2037  // Many selections are very temporal and updating the display each time just
2038  // creates noise.
2039  if( aMode == BRIGHTENED )
2041 }
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:94
Item is being added to the view.
Definition: view_item.h:62
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:571
KIGFX::PCB_VIEW * view() const
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)

References 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 SELECTION_TOOL::highlightInternal ( BOARD_ITEM aItem,
int  aHighlightMode,
PCBNEW_SELECTION aSelectionViewGroup,
bool  isChild 
)
private

Definition at line 2044 of file selection_tool.cpp.

2046 {
2047  if( aMode == SELECTED )
2048  aItem->SetSelected();
2049  else if( aMode == BRIGHTENED )
2050  aItem->SetBrightened();
2051 
2052  if( aSelectionViewGroup )
2053  {
2054  // Hide the original item, so it is shown only on overlay
2055  view()->Hide( aItem, true );
2056 
2057  if( !isChild || aMode == BRIGHTENED )
2058  aSelectionViewGroup->Add( aItem );
2059  }
2060 
2061  // footprints are treated in a special way - when they are highlighted, we have to highlight
2062  // all the parts that make the footprint, not the footprint itself
2063  if( aItem->Type() == PCB_FOOTPRINT_T )
2064  {
2065  static_cast<FOOTPRINT*>( aItem )->RunOnChildren(
2066  [&]( BOARD_ITEM* aChild )
2067  {
2068  highlightInternal( aChild, aMode, aSelectionViewGroup, true );
2069  } );
2070  }
2071  else if( aItem->Type() == PCB_GROUP_T )
2072  {
2073  static_cast<PCB_GROUP*>( aItem )->RunOnChildren(
2074  [&]( BOARD_ITEM* aChild )
2075  {
2076  highlightInternal( aChild, aMode, aSelectionViewGroup, true );
2077  } );
2078  }
2079 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1480
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
void SetBrightened()
Definition: eda_item.h:197
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129
void SetSelected()
Definition: eda_item.h:196
#define SELECTED
Definition: eda_item.h:113
KIGFX::PCB_VIEW * view() const
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References SELECTION::Add(), 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().

◆ Init()

bool SELECTION_TOOL::Init ( void  )
overridevirtual

Function Init() 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 130 of file selection_tool.cpp.

131 {
132  auto frame = getEditFrame<PCB_BASE_FRAME>();
133 
136  {
138  return true;
139  }
140 
141  auto selectMenu = std::make_shared<SELECT_MENU>();
142  selectMenu->SetTool( this );
143  m_menu.AddSubMenu( selectMenu );
144 
145  auto& menu = m_menu.GetMenu();
146 
147  auto activeToolCondition =
148  [ frame ] ( const SELECTION& aSel )
149  {
150  return !frame->ToolStackIsEmpty();
151  };
152 
153  auto inGroupCondition =
154  [this] ( const SELECTION& )
155  {
156  return m_enteredGroup != nullptr;
157  };
158 
159  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
160  menu.AddSeparator( 1000 );
161 
162  // "Cancel" goes at the top of the context menu when a tool is active
163  menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
164  menu.AddItem( PCB_ACTIONS::groupLeave, inGroupCondition, 1);
165  menu.AddSeparator( 1 );
166 
167  if( frame )
169 
170  return true;
171 }
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
bool AddItem(BOARD_ITEM *aItem)
Adds item to group.
Definition: pcb_group.cpp:38
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
static TOOL_ACTION groupLeave
Definition: pcb_actions.h:423
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
PCB_GROUP * m_enteredGroup
static bool NotEmpty(const SELECTION &aSelection)
Tests if there are any items selected.
PCB_BASE_EDIT_FRAME * frame() const
bool ToolStackIsEmpty()
Definition: tools_holder.h:136
bool IsType(FRAME_T aType) const
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
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, TOOL_MENU::GetMenu(), PCB_ACTIONS::groupLeave, EDA_BASE_FRAME::IsType(), m_enteredGroup, TOOL_INTERACTIVE::m_menu, SELECTION_CONDITIONS::NotEmpty(), and TOOLS_HOLDER::ToolStackIsEmpty().

◆ IsFootprintEditor()

bool PCB_TOOL_BASE::IsFootprintEditor ( ) const
inlineinherited

◆ 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:219
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214
bool IsToolActive(TOOL_ID aId) const
Function IsToolActive() Returns true if a tool with given id is active (executing)

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

Referenced by EDIT_TOOL::isRouterActive(), and ROUTER_TOOL::onViaCommand().

◆ itemPassesFilter()

bool SELECTION_TOOL::itemPassesFilter ( BOARD_ITEM aItem)
private

Returns true if the given item passes the current SELECTION_FILTER_OPTIONS

Definition at line 1501 of file selection_tool.cpp.

1502 {
1503  if( aItem->IsLocked() && !m_filter.lockedItems )
1504  return false;
1505 
1506  switch( aItem->Type() )
1507  {
1508  case PCB_FOOTPRINT_T:
1509  if( !m_filter.footprints )
1510  return false;
1511 
1512  break;
1513 
1514  case PCB_PAD_T:
1515  if( !m_filter.pads )
1516  return false;
1517 
1518  break;
1519 
1520  case PCB_TRACE_T:
1521  case PCB_ARC_T:
1522  if( !m_filter.tracks )
1523  return false;
1524 
1525  break;
1526 
1527  case PCB_VIA_T:
1528  if( !m_filter.vias )
1529  return false;
1530 
1531  break;
1532 
1533  case PCB_ZONE_T:
1534  {
1535  ZONE* zone = static_cast<ZONE*>( aItem );
1536 
1537  if( ( !m_filter.zones && !zone->GetIsRuleArea() )
1538  || ( !m_filter.keepouts && zone->GetIsRuleArea() ) )
1539  {
1540  return false;
1541  }
1542  }
1543  break;
1544 
1545  case PCB_SHAPE_T:
1546  case PCB_TARGET_T:
1547  if( !m_filter.graphics )
1548  return false;
1549 
1550  break;
1551 
1552  case PCB_FP_TEXT_T:
1553  case PCB_TEXT_T:
1554  if( !m_filter.text )
1555  return false;
1556 
1557  break;
1558 
1559  case PCB_DIM_ALIGNED_T:
1560  case PCB_DIM_CENTER_T:
1561  case PCB_DIM_ORTHOGONAL_T:
1562  case PCB_DIM_LEADER_T:
1563  if( !m_filter.dimensions )
1564  return false;
1565 
1566  break;
1567 
1568  default:
1569  if( !m_filter.otherItems )
1570  return false;
1571  }
1572 
1573  return true;
1574 }
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
bool otherItems
Anything not fitting one of the above categories.
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:747
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class PAD, a pad in a footprint
Definition: typeinfo.h:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
bool text
Text (free or attached to a footprint)
bool dimensions
Dimension items.
bool graphics
Graphic lines, shapes, polygons.
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:106
bool footprints
Allow selecting entire footprints.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
virtual bool IsLocked() const
Function IsLocked.
Definition: board_item.h:259
bool lockedItems
Allow selecting locked items.
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
SELECTION_FILTER_OPTIONS m_filter
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

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_TEXT_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 SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

The main loop.

Definition at line 207 of file selection_tool.cpp.

208 {
209  // Main loop: keep receiving events
210  while( TOOL_EVENT* evt = Wait() )
211  {
212  bool dragAlwaysSelects = getEditFrame<PCB_BASE_FRAME>()->GetDragSelects();
213  TRACK_DRAG_ACTION dragAction = getEditFrame<PCB_BASE_FRAME>()->Settings().m_TrackDragAction;
215 
216  // OSX uses CTRL for context menu, and SHIFT is exclusive-or
217 #ifdef __WXOSX_MAC__
218  if( evt->Modifier( MD_SHIFT ) )
219  m_exclusive_or = true;
220 #else
221  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
222  m_subtractive = true;
223  else if( evt->Modifier( MD_SHIFT ) )
224  m_additive = true;
225  else if( evt->Modifier( MD_CTRL ) )
226  m_exclusive_or = true;
227 #endif
228 
229  bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
230 
231  // Is the user requesting that the selection list include all possible
232  // items without removing less likely selection candidates
233  m_skip_heuristics = !!evt->Modifier( MD_ALT );
234 
235  // Single click? Select single object
236  if( evt->IsClick( BUT_LEFT ) )
237  {
238  m_frame->FocusOnItem( nullptr );
239 
240  selectPoint( evt->Position() );
241  }
242 
243  // Right click? if there is any object - show the context menu
244  else if( evt->IsClick( BUT_RIGHT ) )
245  {
246  bool selectionCancelled = false;
247 
248  if( m_selection.Empty() )
249  {
250  selectPoint( evt->Position(), false, &selectionCancelled );
251  m_selection.SetIsHover( true );
252  }
253 
254  if( !selectionCancelled )
256  }
257 
258  // Double click? Display the properties window
259  else if( evt->IsDblClick( BUT_LEFT ) )
260  {
261  m_frame->FocusOnItem( nullptr );
262 
263  if( m_selection.Empty() )
264  selectPoint( evt->Position() );
265 
266  if( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T )
267  {
268  EnterGroup();
269  }
270  else
271  {
273  }
274  }
275 
276  // Middle double click? Do zoom to fit or zoom to objects
277  else if( evt->IsDblClick( BUT_MIDDLE ) )
278  {
279  if( m_exclusive_or ) // Is CTRL key down?
281  else
283  }
284 
285  // Drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
286  else if( evt->IsDrag( BUT_LEFT ) )
287  {
288  m_frame->FocusOnItem( nullptr );
290 
291  if( modifier_enabled || dragAlwaysSelects )
292  {
293  selectMultiple();
294  }
295  else
296  {
297  // Selection is empty? try to start dragging the item under the point where drag
298  // started
299  if( m_selection.Empty() && selectCursor() )
300  m_selection.SetIsHover( true );
301 
302  // Check if dragging has started within any of selected items bounding box.
303  // We verify "HasPosition()" first to protect against edge case involving
304  // moving off menus that causes problems (issue #5250)
305  if( evt->HasPosition() && selectionContains( evt->Position() ) )
306  {
307  // Yes -> run the move tool and wait till it finishes
308  TRACK* track = dynamic_cast<TRACK*>( m_selection.GetItem( 0 ) );
309 
310  if( track && dragAction == TRACK_DRAG_ACTION::DRAG )
312  else if( track && dragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
314  else
316  }
317  else
318  {
319  // No -> drag a selection box
320  selectMultiple();
321  }
322  }
323  }
324 
325  else if( evt->IsCancel() )
326  {
327  m_frame->FocusOnItem( nullptr );
328 
329  if( m_enteredGroup )
330  ExitGroup();
331 
332  ClearSelection();
333 
334  if( evt->FirstResponder() == this )
336  }
337 
338  else
339  evt->SetPassEvent();
340 
341 
342  if( m_frame->ToolStackIsEmpty() )
343  {
344  //move cursor prediction
345  if( !modifier_enabled && !dragAlwaysSelects && !m_selection.Empty()
346  && evt->HasPosition() && selectionContains( evt->Position() ) )
348  else
349  {
350  if( m_additive )
352  else if( m_subtractive )
354  else if( m_exclusive_or )
356  else
358  }
359  }
360  }
361 
362  // Shutting down; clear the selection
363  m_selection.Clear();
364 
365  return 0;
366 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:95
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:141
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:140
static TOOL_ACTION zoomFitObjects
Definition: actions.h:95
PCB_GROUP * m_enteredGroup
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
TRACK_DRAG_ACTION
void SetIsHover(bool aIsHover)
Definition: selection.h:65
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectPoint() Selects an item pointed by the parameter aWhere.
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_EVENT.
Definition: tool_event.h:171
bool ToolStackIsEmpty()
Definition: tools_holder.h:136
PCB_BASE_FRAME * m_frame
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:104
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:441
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
static const TOOL_EVENT InhibitSelectionEditing
Used to inform tools that the selection should temporarily be non-editable
Definition: actions.h:219
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
void FocusOnItem(BOARD_ITEM *aItem)
Definition: track.h:83

References ADD, ARROW, BUT_LEFT, BUT_MIDDLE, BUT_RIGHT, SELECTION::Clear(), PCB_ACTIONS::clearHighlight, ClearSelection(), DRAG, PCB_ACTIONS::drag45Degree, DRAG_FREE_ANGLE, PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), EnterGroup(), ExitGroup(), PCB_BASE_FRAME::FocusOnItem(), PCB_BASE_FRAME::GetCanvas(), SELECTION::GetItem(), SELECTION::GetSize(), EVENTS::InhibitSelectionEditing, m_additive, m_enteredGroup, m_exclusive_or, m_frame, TOOL_INTERACTIVE::m_menu, m_selection, m_skip_heuristics, m_subtractive, TOOL_BASE::m_toolMgr, MD_ALT, MD_CTRL, MD_SHIFT, PCB_ACTIONS::move, MOVING, PCB_GROUP_T, TOOL_MANAGER::ProcessEvent(), PCB_ACTIONS::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), SUBTRACT, TOOLS_HOLDER::ToolStackIsEmpty(), TOOL_INTERACTIVE::Wait(), XOR, ACTIONS::zoomFitObjects, and ACTIONS::zoomFitScreen.

Referenced by setTransitions().

◆ pickSmallestComponent()

BOARD_ITEM * SELECTION_TOOL::pickSmallestComponent ( GENERAL_COLLECTOR aCollector)
private

Function pickSmallestComponent() Allows one to find the smallest (in terms of bounding box area) item from the list.

Parameters
aCollectorcontaines the list of items.

Definition at line 1775 of file selection_tool.cpp.

1776 {
1777  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1778 
1779  if( 0 == count )
1780  count = aCollector->GetCount();
1781 
1782  for( int i = 0; i < count; ++i )
1783  {
1784  if(( *aCollector )[i]->Type() != PCB_FOOTPRINT_T )
1785  return NULL;
1786  }
1787 
1788  // All are footprints, now find smallest FOOTPRINT
1789  int minDim = 0x7FFFFFFF;
1790  int minNdx = 0;
1791 
1792  for( int i = 0; i < count; ++i )
1793  {
1794  FOOTPRINT* footprint = (FOOTPRINT*) ( *aCollector )[i];
1795 
1796  int lx = footprint->GetFootprintRect().GetWidth();
1797  int ly = footprint->GetFootprintRect().GetHeight();
1798 
1799  int lmin = std::min( lx, ly );
1800 
1801  if( lmin < minDim )
1802  {
1803  minDim = lmin;
1804  minNdx = i;
1805  }
1806  }
1807 
1808  return (*aCollector)[minNdx];
1809 }
int GetWidth() const
Definition: eda_rect.h:119
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:104
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Build and returns the boundary box of the footprint excluding any text.
Definition: footprint.cpp:579
#define NULL
FOOTPRINT * footprint() const
int GetHeight() const
Definition: eda_rect.h:120
class FOOTPRINT, a footprint
Definition: typeinfo.h:89

References PCB_TOOL_BASE::footprint(), COLLECTOR::GetCount(), FOOTPRINT::GetFootprintRect(), EDA_RECT::GetHeight(), GENERAL_COLLECTOR::GetPrimaryCount(), EDA_RECT::GetWidth(), NULL, and PCB_FOOTPRINT_T.

◆ RebuildSelection()

void SELECTION_TOOL::RebuildSelection ( )

Rebuilds 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 1601 of file selection_tool.cpp.

1602 {
1603  m_selection.Clear();
1604 
1605  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1606  {
1607  if( item->IsSelected() )
1608  {
1609  EDA_ITEM* parent = item->GetParent();
1610 
1611  // Flags on footprint children might be set only because the parent is selected.
1612  if( parent && parent->Type() == PCB_FOOTPRINT_T && parent->IsSelected() )
1613  return SEARCH_RESULT::CONTINUE;
1614 
1615  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1616  }
1617 
1618  return SEARCH_RESULT::CONTINUE;
1619  };
1620 
1623 }
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:294
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:268
BOARD * board() const
bool IsSelected() const
Definition: eda_item.h:191
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
PCBNEW_SELECTION m_selection
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
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:1090
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: eda_item.h:69
#define SELECTED
Definition: eda_item.h:113
EDA_ITEM * GetParent() const
Definition: eda_item.h:183
bool m_isFootprintEditor
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), SELECTION::Clear(), CONTINUE, GENERAL_COLLECTOR::FootprintItems, EDA_ITEM::GetParent(), highlight(), EDA_ITEM::IsSelected(), PCB_TOOL_BASE::m_isFootprintEditor, m_selection, PCB_FOOTPRINT_T, SELECTED, EDA_ITEM::Type(), and BOARD::Visit().

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

◆ RemoveItemFromSel()

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

Definition at line 922 of file selection_tool.cpp.

923 {
924  if( aItem )
925  {
926  unselect( aItem );
927 
928  // Inform other potentially interested tools
930  }
931 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:209
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes 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_FP_EDITOR::TransferDataFromWindow(), and UnselectItem().

◆ RequestSelection()

PCBNEW_SELECTION & SELECTION_TOOL::RequestSelection ( CLIENT_SELECTION_FILTER  aClientFilter,
std::vector< BOARD_ITEM * > *  aFiltered = nullptr,
bool  aConfirmLockedItems = false 
)

Function RequestSelection()

Returns the current selection set, filtered according to aFlags and aClientFilter. If the set is empty, performs the legacy-style hover selection.

Parameters
aFilteredis an optional vector, that is filled with items removed by the filter

Definition at line 411 of file selection_tool.cpp.

414 {
415  bool selectionEmpty = m_selection.Empty();
416  m_selection.SetIsHover( selectionEmpty );
417 
418  if( selectionEmpty )
419  {
420  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
422  }
423 
424  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
425  {
426  ClearSelection();
427  return m_selection;
428  }
429 
430  if( aClientFilter )
431  {
432  enum DISPOSITION { BEFORE = 1, AFTER, BOTH };
433 
434  std::map<EDA_ITEM*, DISPOSITION> itemDispositions;
435  GENERAL_COLLECTOR collector;
436 
437  for( EDA_ITEM* item : m_selection )
438  {
439  collector.Append( item );
440  itemDispositions[ item ] = BEFORE;
441  }
442 
443  aClientFilter( VECTOR2I(), collector, this );
444 
445  for( EDA_ITEM* item : collector )
446  {
447  if( itemDispositions.count( item ) )
448  itemDispositions[ item ] = BOTH;
449  else
450  itemDispositions[ item ] = AFTER;
451  }
452 
453  // Unhighlight the BEFORE items before highlighting the AFTER items.
454  // This is so that in the case of groups, if aClientFilter replaces a selection
455  // with the enclosing group, the unhighlight of the element doesn't undo the
456  // recursive highlighting of that elemetn by the group.
457 
458  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
459  {
460  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
461  DISPOSITION disposition = itemDisposition.second;
462 
463  if( disposition == BEFORE )
464  {
465  if( aFiltered )
466  aFiltered->push_back( item );
467 
468  unhighlight( item, SELECTED, &m_selection );
469  }
470  }
471 
472  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
473  {
474  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
475  DISPOSITION disposition = itemDisposition.second;
476 
477  if( disposition == AFTER )
478  {
479  highlight( item, SELECTED, &m_selection );
480  }
481  else if( disposition == BOTH )
482  {
483  // nothing to do
484  }
485  }
486 
488  }
489 
490  return m_selection;
491 }
void ClearReferencePoint()
Definition: selection.h:267
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
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:219
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetIsHover(bool aIsHover)
Definition: selection.h:65
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
#define SELECTED
Definition: eda_item.h:113
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:59
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.

References COLLECTOR::Append(), CheckLock(), SELECTION::ClearReferencePoint(), ClearSelection(), SELECTION::Empty(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), highlight(), m_frame, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::RunAction(), SELECTED, SELECTION_LOCKED, PCB_ACTIONS::selectionCursor, SELECTION::SetIsHover(), and unhighlight().

Referenced by EDIT_TOOL::ChangeTrackWidth(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Duplicate(), PCB_EDITOR_CONTROL::EditFpInFpEditor(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::FilletTracks(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), 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 SELECTION_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Function Reset() Brings 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 174 of file selection_tool.cpp.

175 {
176  m_frame = getEditFrame<PCB_BASE_FRAME>();
177  m_locked = true;
178 
179  if( m_enteredGroup )
180  ExitGroup();
181 
182  if( aReason == TOOL_BASE::MODEL_RELOAD )
183  {
184  // Deselect any item being currently in edit, to avoid unexpected behavior
185  // and remove pointers to the selected items from containers
186  // without changing their properties (as they are already deleted
187  // while a new board is loaded)
188  ClearSelection( true );
189 
190  getView()->GetPainter()->GetSettings()->SetHighlight( false );
191  }
192  else
193  {
194  // Restore previous properties of selected items and remove them from containers
195  ClearSelection( true );
196  }
197 
198  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
199  view()->Remove( &m_selection );
200  view()->Add( &m_selection );
201 
204 }
Model changes (required full reload)
Definition: tool_base.h:82
PCBNEW_SELECTION m_selection
PCB_GROUP * m_enteredGroup
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
KIGFX::PCB_VIEW * view() const
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:59
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
KIGFX::VIEW_GROUP m_enteredGroupOverlay

References KIGFX::PCB_VIEW::Add(), ClearSelection(), ExitGroup(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), m_enteredGroup, m_enteredGroupOverlay, m_frame, m_locked, 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

Function RunMainStack()

Calls 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:219
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 SELECTION_TOOL::select ( BOARD_ITEM aItem)

Function select() Takes necessary action mark an item as selected.

Parameters
aItemis an item to be selected.

Definition at line 2003 of file selection_tool.cpp.

2004 {
2005  if( aItem->IsSelected() )
2006  {
2007  return;
2008  }
2009 
2010  if( aItem->Type() == PCB_PAD_T )
2011  {
2012  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
2013 
2014  if( m_selection.Contains( footprint ) )
2015  return;
2016  }
2017 
2018  highlight( aItem, SELECTED, &m_selection );
2019 }
bool IsSelected() const
Definition: eda_item.h:191
PCBNEW_SELECTION m_selection
class PAD, a pad in a footprint
Definition: typeinfo.h:90
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define SELECTED
Definition: eda_item.h:113
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:112
FOOTPRINT * footprint() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:179
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

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 SELECTION_TOOL::Selectable ( const BOARD_ITEM aItem,
bool  checkVisibilityOnly = false 
) const

Function selectable() Checks conditions for an item to be selected.

Returns
True if the item fulfills conditions to be selected.

Definition at line 1812 of file selection_tool.cpp.

1813 {
1814  const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
1815 
1816  if( settings->GetHighContrast() )
1817  {
1818  std::set<unsigned int> activeLayers = settings->GetHighContrastLayers();
1819  bool onActiveLayer = false;
1820 
1821  for( unsigned int layer : activeLayers )
1822  {
1823  // NOTE: Only checking the regular layers (not GAL meta-layers)
1824  if( layer < PCB_LAYER_ID_COUNT && aItem->IsOnLayer( ToLAYER_ID( layer ) ) )
1825  {
1826  onActiveLayer = true;
1827  break;
1828  }
1829  }
1830 
1831  if( !onActiveLayer ) // We do not want to select items that are in the background
1832  return false;
1833  }
1834 
1835  switch( aItem->Type() )
1836  {
1837  case PCB_ZONE_T:
1838  case PCB_FP_ZONE_T:
1839  {
1840  if( !board()->IsElementVisible( LAYER_ZONES ) )
1841  return false;
1842 
1843  const ZONE* zone = static_cast<const ZONE*>( aItem );
1844 
1845  // Check to see if this keepout is part of a footprint
1846  // If it is, and we are not editing the footprint, it should not be selectable
1847  bool zoneInFootprint = zone->GetParent() && zone->GetParent()->Type() == PCB_FOOTPRINT_T;
1848 
1849  if( zoneInFootprint && !m_isFootprintEditor && !checkVisibilityOnly )
1850  return false;
1851 
1852  // zones can exist on multiple layers!
1853  return ( zone->GetLayerSet() & board()->GetVisibleLayers() ).any();
1854  }
1855  break;
1856 
1857  case PCB_TRACE_T:
1858  case PCB_ARC_T:
1859  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1860  return false;
1861  break;
1862 
1863  case PCB_VIA_T:
1864  {
1865  if( !board()->IsElementVisible( LAYER_VIAS ) )
1866  return false;
1867 
1868  const VIA* via = static_cast<const VIA*>( aItem );
1869 
1870  // For vias it is enough if only one of its layers is visible
1871  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1872  }
1873 
1874  case PCB_FOOTPRINT_T:
1875  {
1876  // In footprint editor, we do not want to select the footprint itself.
1877  if( m_isFootprintEditor )
1878  return false;
1879 
1880  // Allow selection of footprints if some part of the footprint is visible.
1881 
1882  FOOTPRINT* footprint = const_cast<FOOTPRINT*>( static_cast<const FOOTPRINT*>( aItem ) );
1883 
1884  for( BOARD_ITEM* item : footprint->GraphicalItems() )
1885  {
1886  if( Selectable( item, true ) )
1887  return true;
1888  }
1889 
1890  for( PAD* pad : footprint->Pads() )
1891  {
1892  if( Selectable( pad, true ) )
1893  return true;
1894  }
1895 
1896  for( ZONE* zone : footprint->Zones() )
1897  {
1898  if( Selectable( zone, true ) )
1899  return true;
1900  }
1901 
1902  return false;
1903  }
1904 
1905  case PCB_FP_TEXT_T:
1906  // Multiple selection is only allowed in footprint editor mode. In pcbnew, you have to
1907  // select footprint subparts one by one, rather than with a drag selection. This is so
1908  // you can pick up items under an (unlocked) footprint without also moving the
1909  // footprint's sub-parts.
1910  if( !m_isFootprintEditor && !checkVisibilityOnly )
1911  {
1912  if( m_multiple && !settings->GetHighContrast() )
1913  return false;
1914  }
1915 
1916  if( !m_isFootprintEditor && !view()->IsVisible( aItem ) )
1917  return false;
1918 
1919  break;
1920 
1921  case PCB_FP_SHAPE_T:
1922  // Footprint shape selections are only allowed in footprint editor mode.
1923  if( !m_isFootprintEditor && !checkVisibilityOnly )
1924  return false;
1925 
1926  break;
1927 
1928  case PCB_PAD_T:
1929  {
1930  // Multiple selection is only allowed in footprint editor mode. In pcbnew, you have to
1931  // select footprint subparts one by one, rather than with a drag selection. This is so
1932  // you can pick up items under an (unlocked) footprint without also moving the
1933  // footprint's sub-parts.
1934  if( !m_isFootprintEditor && !checkVisibilityOnly )
1935  {
1936  if( m_multiple )
1937  return false;
1938  }
1939 
1940  if( aItem->Type() == PCB_PAD_T )
1941  {
1942  const PAD* pad = static_cast<const PAD*>( aItem );
1943 
1944  // Check render mode (from the Items tab) first
1945  switch( pad->GetAttribute() )
1946  {
1947  case PAD_ATTRIB_PTH:
1948  case PAD_ATTRIB_NPTH:
1949  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1950  return false;
1951  break;
1952 
1953  case PAD_ATTRIB_CONN:
1954  case PAD_ATTRIB_SMD:
1955  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1956  return false;
1957  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1958  return false;
1959  break;
1960  }
1961 
1962  // Otherwise, pads are selectable if any draw layer is visible
1963  return ( pad->GetLayerSet() & board()->GetVisibleLayers() ).any();
1964  }
1965 
1966  break;
1967  }
1968 
1969  case PCB_GROUP_T:
1970  {
1971  PCB_GROUP* group = const_cast<PCB_GROUP*>( static_cast<const PCB_GROUP*>( aItem ) );
1972 
1973  // Similar to logic for footprint, a group is selectable if any of its members are.
1974  // (This recurses.)
1975  for( BOARD_ITEM* item : group->GetItems() )
1976  {
1977  if( Selectable( item, true ) )
1978  return true;
1979  }
1980 
1981  return false;
1982  }
1983 
1984  case PCB_MARKER_T: // Always selectable
1985  return true;
1986 
1987  // These are not selectable
1988  case PCB_NETINFO_T:
1989  case NOT_USED:
1990  case TYPE_NOT_INIT:
1991  return false;
1992 
1993  default: // Suppress warnings
1994  break;
1995  }
1996 
1997  // All other items are selected only if the layer on which they exist is visible
1998  return board()->IsLayerVisible( aItem->GetLayer() )
1999  && aItem->ViewGetLOD( aItem->GetLayer(), view() ) < view()->GetScale();
2000 }
const std::set< unsigned int > GetHighContrastLayers() const
Function GetHighContrastLayers() Returns the set of currently high-contrast layers.
Definition: track.h:354
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: track.cpp:363
BOARD * board() const
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
multilayer pads, usually with holes
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_GROUP is 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:80
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:288
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:451
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: pad.h:544
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class PAD, a pad in a footprint
Definition: typeinfo.h:90
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
const std::unordered_set< BOARD_ITEM * > & GetItems() const
Definition: pcb_group.h:68
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
PADS & Pads()
Definition: footprint.h:182
PAD_ATTR_T GetAttribute() const
Definition: pad.h:348
FP_ZONES & Zones()
Definition: footprint.h:188
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1499
FOOTPRINT * footprint() const
KIGFX::PCB_VIEW * view() const
DRAWINGS & GraphicalItems()
Definition: footprint.h:185
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: pad.h:345
class ZONE, a copper pour area
Definition: typeinfo.h:106
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:82
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:497
bool GetHighContrast() const
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns 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:443
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
smd pads, front layer
Meta control for all vias opacity/visibility.
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:108
class ZONE, managed by a footprint
Definition: typeinfo.h:95
Plated through hole pad.
Definition: pad_shapes.h:80
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
Definition: pad.h:59
double GetScale() const
Function GetScale()
Definition: view.h:259
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:179
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Definition: board_item.h:185
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:898
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:141
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References B_Cu, PCB_TOOL_BASE::board(), F_Cu, PCB_TOOL_BASE::footprint(), PAD::GetAttribute(), KIGFX::RENDER_SETTINGS::GetHighContrast(), KIGFX::RENDER_SETTINGS::GetHighContrastLayers(), PCB_GROUP::GetItems(), BOARD_ITEM::GetLayer(), ZONE::GetLayerSet(), PAD::GetLayerSet(), VIA::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), FOOTPRINT::GraphicalItems(), BOARD::IsElementVisible(), BOARD::IsLayerVisible(), PAD::IsOnLayer(), 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, PAD_ATTRIB_CONN, PAD_ATTRIB_NPTH, PAD_ATTRIB_PTH, PAD_ATTRIB_SMD, FOOTPRINT::Pads(), PCB_ARC_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_MARKER_T, PCB_NETINFO_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, ToLAYER_ID(), EDA_ITEM::Type(), TYPE_NOT_INIT, PCB_TOOL_BASE::view(), KIGFX::VIEW_ITEM::ViewGetLOD(), and FOOTPRINT::Zones().

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

◆ SelectAll()

int SELECTION_TOOL::SelectAll ( const TOOL_EVENT aEvent)

Select all items on the board

Definition at line 856 of file selection_tool.cpp.

857 {
858  KIGFX::VIEW* view = getView();
859 
860  // hold all visible items
861  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
862 
863  // Filter the view items based on the selection box
864  BOX2I selectionBox;
865 
866  selectionBox.SetMaximum();
867  view->Query( selectionBox, selectedItems ); // Get the list of selected items
868 
869  for( const KIGFX::VIEW::LAYER_ITEM_PAIR& item_pair : selectedItems )
870  {
871  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( item_pair.first );
872 
873  if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
874  continue;
875 
876  select( item );
877  }
878 
880 
881  return 0;
882 }
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool itemPassesFilter(BOARD_ITEM *aItem)
Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
void SetMaximum()
Definition: box2.h:73
KIGFX::PCB_VIEW * view() const
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:68
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:433
VIEW.
Definition: view.h:63

References 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 SELECTION_TOOL::selectAllItemsOnNet ( int  aNetCode,
bool  aSelect = true 
)
private

Selects 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 1125 of file selection_tool.cpp.

1126 {
1127  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT };
1128  auto connectivity = board()->GetConnectivity();
1129 
1130  for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
1131  if( itemPassesFilter( item ) )
1132  aSelect ? select( item ) : unselect( item );
1133 }
BOARD * board() const
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
bool itemPassesFilter(BOARD_ITEM *aItem)
Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:382
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

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 SELECTION_TOOL::selectAllItemsOnSheet ( wxString &  aSheetPath)
private

Selects all items with the given sheet timestamp/UUID name (the sheet path) The path of the root sheet is "/".

Definition at line 1171 of file selection_tool.cpp.

1172 {
1173  std::list<FOOTPRINT*> footprintList;
1174 
1175  // store all footprints that are on that sheet path
1176  for( FOOTPRINT* footprint : board()->Footprints() )
1177  {
1178  if( footprint == nullptr )
1179  continue;
1180 
1181  wxString footprint_path = footprint->GetPath().AsString().BeforeLast('/');
1182 
1183  if( aSheetPath.IsEmpty() )
1184  aSheetPath += '/';
1185 
1186  if( footprint_path == aSheetPath )
1187  footprintList.push_back( footprint );
1188  }
1189 
1190  //Generate a list of all pads, and of all nets they belong to.
1191  std::list<int> netcodeList;
1192  std::list<PAD*> padList;
1193 
1194  for( FOOTPRINT* footprint : footprintList )
1195  {
1196  for( PAD* pad : footprint->Pads() )
1197  {
1198  if( pad->IsConnected() )
1199  {
1200  netcodeList.push_back( pad->GetNetCode() );
1201  padList.push_back( pad );
1202  }
1203  }
1204  }
1205  // remove all duplicates
1206  netcodeList.sort();
1207  netcodeList.unique();
1208 
1209  for( PAD* pad : padList )
1211 
1212  // now we need to find all footprints that are connected to each of these nets then we need
1213  // to determine if these footprints are in the list of footprints belonging to this sheet
1214  std::list<int> removeCodeList;
1215  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1216 
1217  for( int netCode : netcodeList )
1218  {
1219  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1220  {
1221  if( mitem->Type() == PCB_PAD_T && !alg::contains( footprintList, mitem->GetParent() ) )
1222  {
1223  // if we cannot find the footprint of the pad in the footprintList then we can
1224  // assume that that footprint is not located in the same schematic, therefore
1225  // invalidate this netcode.
1226  removeCodeList.push_back( netCode );
1227  break;
1228  }
1229  }
1230  }
1231 
1232  // remove all duplicates
1233  removeCodeList.sort();
1234  removeCodeList.unique();
1235 
1236  for( int removeCode : removeCodeList )
1237  {
1238  netcodeList.remove( removeCode );
1239  }
1240 
1241  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1242  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, EOT };
1243 
1244  for( int netCode : netcodeList )
1245  {
1246  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1247  localConnectionList.push_back( item );
1248  }
1249 
1250  for( BOARD_ITEM* i : footprintList )
1251  {
1252  if( i != NULL )
1253  select( i );
1254  }
1255 
1256  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1257  {
1258  if( i != NULL )
1259  select( i );
1260  }
1261 }
BOARD * board() const
const KIID_PATH & GetPath() const
Definition: footprint.h:217
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
Select the entire net.
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class PAD, a pad in a footprint
Definition: typeinfo.h:90
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
PADS & Pads()
Definition: footprint.h:182
#define NULL
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Selects connecteed tracks and vias.
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:206
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
Definition: pad.h:59

References KIID_PATH::AsString(), PCB_TOOL_BASE::board(), alg::contains(), EOT, PCB_TOOL_BASE::footprint(), FOOTPRINT::GetPath(), NULL, 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 SELECTION_TOOL::selectConnectedTracks ( BOARD_CONNECTED_ITEM aSourceItem,
STOP_CONDITION  aStopCondition 
)
private

Selects connecteed tracks and vias.

Parameters
aStopConditionwhere to stop selecting more items

Definition at line 1007 of file selection_tool.cpp.

1009 {
1010  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT };
1011 
1012  auto connectivity = board()->GetConnectivity();
1013  auto connectedItems = connectivity->GetConnectedItems( &aStartItem, types );
1014 
1015  std::map<wxPoint, std::vector<TRACK*>> trackMap;
1016  std::map<wxPoint, VIA*> viaMap;
1017  std::map<wxPoint, PAD*> padMap;
1018 
1019  // Build maps of connected items
1020  for( BOARD_CONNECTED_ITEM* item : connectedItems )
1021  {
1022  switch( item->Type() )
1023  {
1024  case PCB_ARC_T:
1025  case PCB_TRACE_T:
1026  {
1027  TRACK* track = static_cast<TRACK*>( item );
1028  trackMap[ track->GetStart() ].push_back( track );
1029  trackMap[ track->GetEnd() ].push_back( track );
1030  }
1031  break;
1032 
1033  case PCB_VIA_T:
1034  {
1035  VIA* via = static_cast<VIA*>( item );
1036  viaMap[ via->GetStart() ] = via;
1037  }
1038  break;
1039 
1040  case PCB_PAD_T:
1041  {
1042  PAD* pad = static_cast<PAD*>( item );
1043  padMap[ pad->GetPosition() ] = pad;
1044  }
1045  break;
1046 
1047  default:
1048  break;
1049  }
1050 
1051  item->SetState( SKIP_STRUCT, false );
1052  }
1053 
1054  std::vector<wxPoint> activePts;
1055 
1056  // Set up the initial active points
1057  switch( aStartItem.Type() )
1058  {
1059  case PCB_ARC_T:
1060  case PCB_TRACE_T:
1061  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
1062  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetEnd() );
1063  break;
1064 
1065  case PCB_VIA_T:
1066  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
1067  break;
1068 
1069  case PCB_PAD_T:
1070  activePts.push_back( aStartItem.GetPosition() );
1071  break;
1072 
1073  default:
1074  break;
1075  }
1076 
1077  bool expand = true;
1078 
1079  // Iterative push from all active points
1080  while( expand )
1081  {
1082  expand = false;
1083 
1084  for( int i = activePts.size() - 1; i >= 0; --i )
1085  {
1086  wxPoint pt = activePts[i];
1087 
1088  if( trackMap[ pt ].size() > 2 && aStopCondition == STOP_AT_JUNCTION )
1089  {
1090  activePts.erase( activePts.begin() + i );
1091  continue;
1092  }
1093 
1094  if( padMap.count( pt ) && aStopCondition != STOP_NEVER )
1095  {
1096  activePts.erase( activePts.begin() + i );
1097  continue;
1098  }
1099 
1100  for( TRACK* track : trackMap[ pt ] )
1101  {
1102  if( track->GetState( SKIP_STRUCT ) )
1103  continue;
1104 
1105  track->SetState( SKIP_STRUCT, true );
1106  select( track );
1107 
1108  if( track->GetStart() == pt )
1109  activePts.push_back( track->GetEnd() );
1110  else
1111  activePts.push_back( track->GetStart() );
1112 
1113  expand = true;
1114  }
1115 
1116  if( viaMap.count( pt ) && !viaMap[ pt ]->IsSelected() )
1117  select( viaMap[ pt ] );
1118 
1119  activePts.erase( activePts.begin() + i );
1120  }
1121  }
1122 }
Definition: track.h:354
BOARD * board() const
const wxPoint & GetStart() const
Definition: track.h:116
Select the entire net.
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class PAD, a pad in a footprint
Definition: typeinfo.h:90
Stop at any place where more than two traces meet.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:382
void SetState(int type, int state)
Definition: eda_item.h:209
wxPoint GetPosition() const override
Definition: pad.h:167
const wxPoint & GetEnd() const
Definition: track.h:113
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
Definition: pad.h:59
int GetState(int type) const
Definition: eda_item.h:204
Definition: track.h:83

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

Referenced by expandConnection(), and selectAllItemsOnSheet().

◆ selectCursor()

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

Function selectCursor() Selects 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 625 of file selection_tool.cpp.

626 {
627  if( aForceSelect || m_selection.Empty() )
628  {
629  ClearSelection( true /*quiet mode*/ );
630  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
631  }
632 
633  return !m_selection.Empty();
634 }
PCBNEW_SELECTION m_selection
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectPoint() Selects an item pointed by the parameter aWhere.
#define NULL
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42

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

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

◆ selection() [1/2]

const PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 291 of file pcb_tool_base.cpp.

292 {
294 
295  return selTool->GetSelection();
296 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION & GetSelection()
Function GetSelection()

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), PCB_INSPECTION_TOOL::doHideNet(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawZone(), EDIT_TOOL::Duplicate(), PCB_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(), PCB_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::InspectClearance(), PCB_INSPECTION_TOOL::InspectConstraints(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), PCBNEW_CONTROL::placeBoardItems(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), GROUP_TOOL::RemoveFromGroup(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), selectNet(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), GROUP_TOOL::Ungroup(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

◆ selection() [2/2]

PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( )
protectedinherited

Definition at line 299 of file pcb_tool_base.cpp.

300 {
302 
303  return selTool->GetSelection();
304 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION & GetSelection()
Function GetSelection()

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

◆ selectionContains()

bool SELECTION_TOOL::selectionContains ( const VECTOR2I aPoint) const
private

Function selectionContains()

Returns
True if the given point is contained in any of selected items' bounding box.

Definition at line 2137 of file selection_tool.cpp.

2138 {
2139  const unsigned GRIP_MARGIN = 20;
2140  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
2141 
2142  // Check if the point is located within any of the currently selected items bounding boxes
2143  for( auto item : m_selection )
2144  {
2145  BOX2I itemBox = item->ViewBBox();
2146  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
2147 
2148  if( itemBox.Contains( aPoint ) )
2149  return true;
2150  }
2151 
2152  return false;
2153 }
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:456
PCBNEW_SELECTION m_selection
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:151
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:302

References BOX2< Vec >::Contains(), TOOL_BASE::getView(), BOX2< Vec >::Inflate(), m_selection, KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Main().

◆ SelectionMenu()

int SELECTION_TOOL::SelectionMenu ( const TOOL_EVENT aEvent)

Function SelectionMenu() Shows 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 1626 of file selection_tool.cpp.

1627 {
1628  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1629 
1630  doSelectionMenu( collector, wxEmptyString );
1631 
1632  return 0;
1633 }
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
bool doSelectionMenu(GENERAL_COLLECTOR *aItems, const wxString &aTitle)
Allows the selection of a single item from a list via pop-up menu.

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

Referenced by setTransitions().

◆ SelectItem()

int SELECTION_TOOL::SelectItem ( const TOOL_EVENT aEvent)

Item selection event handler.

Definition at line 849 of file selection_tool.cpp.

850 {
851  AddItemToSel( aEvent.Parameter<BOARD_ITEM*>() );
852  return 0;
853 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)

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

Referenced by setTransitions().

◆ SelectItems()

int SELECTION_TOOL::SelectItems ( const TOOL_EVENT aEvent)

Multiple item selection event handler

Definition at line 832 of file selection_tool.cpp.

833 {
834  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
835 
836  if( items )
837  {
838  // Perform individual selection of each item before processing the event.
839  for( BOARD_ITEM* item : *items )
840  select( item );
841 
843  }
844 
845  return 0;
846 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435

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

Referenced by setTransitions().

◆ selectMultiple()

bool SELECTION_TOOL::selectMultiple ( )
private

Function selectMultiple() Handles drawing a selection box that allows one to select many items at the same time.

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

Definition at line 637 of file selection_tool.cpp.

638 {
639  bool cancelled = false; // Was the tool cancelled while it was running?
640  m_multiple = true; // Multiple selection mode is active
641  KIGFX::VIEW* view = getView();
642 
644  view->Add( &area );
645 
646  bool anyAdded = false;
647  bool anySubtracted = false;
648 
649  while( TOOL_EVENT* evt = Wait() )
650  {
651  int width = area.GetEnd().x - area.GetOrigin().x;
652 
653  /* Selection mode depends on direction of drag-selection:
654  * Left > Right : Select objects that are fully enclosed by selection
655  * Right > Left : Select objects that are crossed by selection
656  */
657  bool windowSelection = width >= 0 ? true : false;
658 
659  if( view->IsMirroredX() )
660  windowSelection = !windowSelection;
661 
663  windowSelection ? KICURSOR::SELECT_WINDOW : KICURSOR::SELECT_LASSO );
664 
665  if( evt->IsCancelInteractive() || evt->IsActivate() )
666  {
667  cancelled = true;
668  break;
669  }
670 
671  if( evt->IsDrag( BUT_LEFT ) )
672  {
674  {
675  if( m_selection.GetSize() > 0 )
676  {
677  anySubtracted = true;
678  ClearSelection( true /*quiet mode*/ );
679  }
680  }
681 
682  // Start drawing a selection box
683  area.SetOrigin( evt->DragOrigin() );
684  area.SetEnd( evt->Position() );
685  area.SetAdditive( m_additive );
688 
689  view->SetVisible( &area, true );
690  view->Update( &area );
691  getViewControls()->SetAutoPan( true );
692  }
693 
694  if( evt->IsMouseUp( BUT_LEFT ) )
695  {
696  getViewControls()->SetAutoPan( false );
697 
698  // End drawing the selection box
699  view->SetVisible( &area, false );
700 
701  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> candidates;
702  BOX2I selectionBox = area.ViewBBox();
703  view->Query( selectionBox, candidates ); // Get the list of nearby items
704 
705  int height = area.GetEnd().y - area.GetOrigin().y;
706 
707  // Construct an EDA_RECT to determine BOARD_ITEM selection
708  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
709 
710  selectionRect.Normalize();
711 
712  GENERAL_COLLECTOR collector;
713 
714  for( auto it = candidates.begin(), it_end = candidates.end(); it != it_end; ++it )
715  {
716  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
717 
718  if( item && Selectable( item ) && item->HitTest( selectionRect, windowSelection ) )
719  collector.Append( item );
720  }
721 
722  // Apply the stateful filter
723  FilterCollectedItems( collector );
724 
725  FilterCollectorForGroups( collector );
726 
727  for( EDA_ITEM* i : collector )
728  {
729  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
730 
731  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
732  {
733  unselect( item );
734  anySubtracted = true;
735  }
736  else
737  {
738  select( item );
739  anyAdded = true;
740  }
741  }
742 
743  m_selection.SetIsHover( false );
744 
745  // Inform other potentially interested tools
746  if( anyAdded )
748  else if( anySubtracted )
750 
751  break; // Stop waiting for events
752  }
753  }
754 
755  getViewControls()->SetAutoPan( false );
756 
757  // Stop drawing the selection box
758  view->Remove( &area );
759  m_multiple = false; // Multiple selection mode is inactive
760 
761  if( !cancelled )
763 
765 
766  return cancelled;
767 }
void ClearReferencePoint()
Definition: selection.h:267
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector)
Applies the SELECTION_FILTER_OPTIONS to a collection of items
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
bool IsSelected() const
Definition: eda_item.h:191
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:209
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
void SetOrigin(VECTOR2I aOrigin)
Set the origin of the rectange (the fixed corner)
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:219
PCBNEW_SELECTION m_selection
void SetExclusiveOr(bool aExclusiveOr)
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
void SetIsHover(bool aIsHover)
Definition: selection.h:65
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
void SetAdditive(bool aAdditive)
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:295
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:94
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_EVENT.
Definition: tool_event.h:171
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
KIGFX::PCB_VIEW * view() const
void FilterCollectorForGroups(GENERAL_COLLECTOR &aCollector) const
static const TOOL_EVENT UninhibitSelectionEditing
Definition: actions.h:220
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:232
void SetSubtractive(bool aSubtractive)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1459
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:59
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:433
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VIEW.
Definition: view.h:63

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

Referenced by Main().

◆ selectNet()

int SELECTION_TOOL::selectNet ( const TOOL_EVENT aEvent)
private

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

Definition at line 1136 of file selection_tool.cpp.

1137 {
1138  bool select = aEvent.IsAction( &PCB_ACTIONS::selectNet );
1139 
1140  // If we've been passed an argument, just select that netcode1
1141  int netcode = aEvent.Parameter<intptr_t>();
1142 
1143  if( netcode > 0 )
1144  {
1145  selectAllItemsOnNet( netcode, select );
1146  return 0;
1147  }
1148 
1149  if( !selectCursor() )
1150  return 0;
1151 
1152  // copy the selection, since we're going to iterate and modify
1153  auto selection = m_selection.GetItems();
1154 
1155  for( EDA_ITEM* i : selection )
1156  {
1157  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
1158 
1159  if( connItem )
1160  selectAllItemsOnNet( connItem->GetNetCode(), select );
1161  }
1162 
1163  // Inform other potentially interested tools
1164  if( m_selection.Size() > 0 )
1166 
1167  return 0;
1168 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:208
int GetNetCode() const
Function GetNetCode.
void selectAllItemsOnNet(int aNetCode, bool aSelect=true)
Selects all items with the given net code.
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:80
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:67
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
const PCBNEW_SELECTION & selection() const
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148

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

Referenced by setTransitions().

◆ selectPoint()

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

Function selectPoint() Selects an item pointed by the parameter aWhere.

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

Parameters
aWhereis the place where the item should be selected.
aOnDragindicates whether a drag operation is being performed.
aSelectionCancelledFlagallows the function to inform its caller that a selection was cancelled (for instance, by clicking outside of the disambiguation menu).
aClientFilterallows the client to perform tool- or action-specific filtering.
Returns
True if an item was selected, false otherwise.

Definition at line 521 of file selection_tool.cpp.

524 {
526  GENERAL_COLLECTOR collector;
527  const PCB_DISPLAY_OPTIONS& displayOpts = m_frame->GetDisplayOptions();
528 
530 
531  if( m_enteredGroup &&
532  !m_enteredGroup->GetBoundingBox().Contains( wxPoint( aWhere.x, aWhere.y ) ) )
533  {
534  ExitGroup();
535  }
536 
539  (wxPoint) aWhere, guide );
540 
541  // Remove unselectable items
542  for( int i = collector.GetCount() - 1; i >= 0; --i )
543  {
544  if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
545  collector.Remove( i );
546  }
547 
549 
550  // Allow the client to do tool- or action-specific filtering to see if we
551  // can get down to a single item
552  if( aClientFilter )
553  aClientFilter( aWhere, collector, this );
554 
555  // Apply the stateful filter
556  FilterCollectedItems( collector );
557 
558  FilterCollectorForGroups( collector );
559 
560  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
561  if( collector.GetCount() > 1 && !m_skip_heuristics )
562  {
563  GuessSelectionCandidates( collector, aWhere );
564  }
565 
566  // If still more than one item we're going to have to ask the user.
567  if( collector.GetCount() > 1 )
568  {
569  if( aOnDrag )
571 
572  if( !doSelectionMenu( &collector, wxEmptyString ) )
573  {
574  if( aSelectionCancelledFlag )
575  *aSelectionCancelledFlag = true;
576 
577  return false;
578  }
579  }