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 ()
 
void EnterGroup ()
 
void ExitGroup (bool aSelectGroup=false)
 Leave the currently entered group. More...
 
void FilterCollectorForGroups (GENERAL_COLLECTOR &aCollector) const
 
PCB_GROUPGetEnteredGroup ()
 
void SetEditModules (bool aEnabled)
 Function SetEditModules() More...
 
bool EditingModules () 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
 
MODULEmodule () 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_editModules
 
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 modules belonging to same sheet, from Eeschema, using crossprobing

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

Selects all modules 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...
 
void filterCollectedItems (GENERAL_COLLECTOR &aCollector)
 

Applies the SELECTION_FILTER_OPTIONS to a collection of items

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 *aGroup, bool isChild)
 
void unhighlightInternal (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup, 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
 
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 MODULEs properly (i.e. selects either MODULE 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 116 of file pcb_tool_base.h.

116  {
118  IPO_ROTATE = 0x01,
119 
121  IPO_FLIP = 0x02,
122 
125  IPO_SINGLE_CLICK = 0x04,
126 
128  IPO_REPEAT = 0x08
129  };
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 258 of file selection_tool.h.

259  {
267  STOP_AT_PAD,
269  STOP_NEVER
270  };
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 99 of file selection_tool.cpp.

99  :
100  PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
101  m_frame( NULL ),
102  m_additive( false ),
103  m_subtractive( false ),
104  m_exclusive_or( false ),
105  m_multiple( false ),
106  m_skip_heuristics( false ),
107  m_locked( true ),
108  m_enteredGroup( NULL ),
109  m_priv( std::make_unique<PRIV>() )
110 {
111  m_filter.lockedItems = true;
112  m_filter.footprints = true;
113  m_filter.text = true;
114  m_filter.tracks = true;
115  m_filter.vias = true;
116  m_filter.pads = true;
117  m_filter.graphics = true;
118  m_filter.zones = true;
119  m_filter.keepouts = true;
120  m_filter.dimensions = true;
121  m_filter.otherItems = true;
122 }
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:75
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 125 of file selection_tool.cpp.

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

References TOOL_BASE::getView(), 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(), PCB_VIEWER_TOOLS::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), 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 833 of file selection_tool.cpp.

834 {
835  if( aItem )
836  {
837  select( aItem );
838 
839  // Inform other potentially interested tools
840  if( !aQuietMode )
842  }
843 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
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(), 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 166 of file pcb_tool_base.h.

166 { 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(), 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(), FilterCollectorForGroups(), filterSelection(), GetBoard(), getCollectorsGuide(), PCB_EDITOR_CONTROL::GroupFlattenSelected(), PCB_EDITOR_CONTROL::GroupMergeSelected(), PCB_EDITOR_CONTROL::GroupRemoveItemsSelected(), PCB_EDITOR_CONTROL::GroupSelected(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PCB_TOOL_BASE::module(), EDIT_TOOL::MoveExact(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PAD_TOOL::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), 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(), PCB_EDITOR_CONTROL::UngroupSelected(), 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 882 of file selection_tool.cpp.

883 {
884  highlight( aItem, BRIGHTENED );
885 }
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: base_struct.h:139

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

721 {
722  if( !m_locked || m_editModules )
723  return SELECTION_UNLOCKED;
724 
725  bool containsLocked = false;
726 
727  // Check if the selection contains locked items
728  for( const auto& item : m_selection )
729  {
730  switch( item->Type() )
731  {
732  case PCB_MODULE_T:
733  if( static_cast<MODULE*>( item )->IsLocked() )
734  containsLocked = true;
735  break;
736 
737  case PCB_MODULE_EDGE_T:
738  case PCB_MODULE_TEXT_T:
740  if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
741  containsLocked = true;
742  break;
743 
744  default: // suppress warnings
745  break;
746  }
747  }
748 
749  if( containsLocked )
750  {
751  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
752  {
753  m_locked = false;
755  }
756  else
757  return SELECTION_LOCKED;
758  }
759 
760  return SELECTION_UNLOCKED;
761 }
PCBNEW_SELECTION m_selection
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_BASE_FRAME * m_frame
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
#define _(s)
Definition: 3d_actions.cpp:33
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283

References _, IsOK(), PCB_TOOL_BASE::m_editModules, m_frame, m_locked, m_selection, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_MODULE_ZONE_AREA_T, SELECTION_LOCK_OVERRIDE, SELECTION_LOCKED, and SELECTION_UNLOCKED.

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

◆ ClearSelection() [1/2]

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

◆ ClearSelection() [2/2]

void SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Definition at line 1545 of file selection_tool.cpp.

1546 {
1547  if( m_selection.Empty() )
1548  return;
1549 
1550  while( m_selection.GetSize() )
1551  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1552 
1553  view()->Update( &m_selection );
1554 
1555  m_selection.SetIsHover( false );
1557 
1558  m_locked = true;
1559 
1560  // Inform other potentially interested tools
1561  if( !aQuietMode )
1562  {
1565  }
1566 }
void ClearReferencePoint()
Definition: selection.h:250
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
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:140
void SetIsHover(bool aIsHover)
Definition: selection.h:66
#define SELECTED
Definition: base_struct.h:124
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
KIGFX::PCB_VIEW * view() const
static const TOOL_EVENT ClearedEvent
Definition: actions.h:208
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:439
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_ITEM * Front() const
Definition: selection.h:184

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

765 {
767 
768  selectCursor( false, aClientFilter );
769 
770  return 0;
771 }
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 37 of file pcb_tool_base.cpp.

40 {
41  using namespace std::placeholders;
42  std::unique_ptr<BOARD_ITEM> newItem;
43 
44  frame()->PushTool( aTool );
45  Activate();
46 
47  BOARD_COMMIT commit( frame() );
48 
50 
51  // do not capture or auto-pan until we start placing an item
52  controls()->ShowCursor( true );
53 
54  // Add a VIEW_GROUP that serves as a preview for the new item
55  PCBNEW_SELECTION preview;
56  view()->Add( &preview );
57 
58  aPlacer->m_board = board();
59  aPlacer->m_frame = frame();
60  aPlacer->m_modifiers = 0;
61 
62  auto makeNewItem = [&] ( 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_MODULE_T )
73  {
74  auto module = dyn_cast<MODULE*>( newItem.get() );
75 
76  // modules have more drawable parts
77  module->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  // Main loop: keep receiving events
86  while( TOOL_EVENT* evt = Wait() )
87  {
88  if( !newItem )
89  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
90  else
91  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
92 
93  VECTOR2I cursorPos = controls()->GetCursorPosition();
94  aPlacer->m_modifiers = evt->Modifier();
95 
96  auto cleanup = [&] ()
97  {
98  newItem = nullptr;
99  preview.Clear();
100  view()->Update( &preview );
101  controls()->SetAutoPan( false );
102  controls()->CaptureCursor( false );
103  controls()->ShowCursor( true );
104  };
105 
106  if( evt->IsCancelInteractive() )
107  {
108  if( aOptions & IPO_SINGLE_CLICK )
109  {
110  cleanup();
111  frame()->PopTool( aTool );
112  break;
113  }
114  else if( newItem )
115  cleanup();
116  else
117  {
118  frame()->PopTool( aTool );
119  break;
120  }
121  }
122  else if( evt->IsActivate() )
123  {
124  if( newItem )
125  cleanup();
126 
127  if( evt->IsPointEditor() )
128  {
129  // don't exit (the point editor runs in the background)
130  }
131  else if( evt->IsMoveTool() )
132  {
133  // leave ourselves on the stack so we come back after the move
134  break;
135  }
136  else
137  {
138  frame()->PopTool( aTool );
139  break;
140  }
141  }
142  else if( evt->IsClick( BUT_LEFT ) )
143  {
144  if( !newItem )
145  {
146  // create the item if possible
147  makeNewItem( cursorPos );
148 
149  // no item created, so wait for another click
150  if( !newItem )
151  continue;
152 
153  controls()->CaptureCursor( true );
154  controls()->SetAutoPan( true );
155  }
156  else
157  {
158  auto oldFlags = newItem->GetFlags();
159  newItem->ClearFlags();
160 
161  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
162  {
163  newItem->SetFlags( oldFlags );
164  continue;
165  }
166 
167  preview.Clear();
168  newItem.release();
169  commit.Push( aCommitMessage );
170 
171  controls()->CaptureCursor( false );
172  controls()->SetAutoPan( false );
173  controls()->ShowCursor( true );
174 
175  if( !( aOptions & IPO_REPEAT ) )
176  break;
177 
178  if( aOptions & IPO_SINGLE_CLICK )
179  makeNewItem( controls()->GetCursorPosition() );
180  }
181  }
182  else if( evt->IsClick( BUT_RIGHT ) )
183  {
185  }
186  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
187  {
189  }
190  else if( newItem && evt->Category() == TC_COMMAND )
191  {
192  /*
193  * Handle any events that can affect the item as we move it around
194  */
195  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
196  {
197  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
198  newItem->Rotate( newItem->GetPosition(), rotationAngle );
199  view()->Update( &preview );
200  }
201  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
202  {
203  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
204  view()->Update( &preview );
205  }
206  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
207  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
208  {
209  // Refresh preview after event runs
211  }
212  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
213  {
214  preview.Clear();
215  newItem.release();
216 
217  makeNewItem( (wxPoint) cursorPos );
218  aPlacer->SnapItem( newItem.get() );
219  view()->Update( &preview );
220  }
221  }
222 
223  else if( newItem && evt->IsMotion() )
224  {
225  // track the cursor
226  newItem->SetPosition( (wxPoint) cursorPos );
227  aPlacer->SnapItem( newItem.get() );
228 
229  // Show a preview of the item
230  view()->Update( &preview );
231  }
232 
233  else
234  evt->SetPassEvent();
235  }
236 
237  view()->Remove( &preview );
238 }
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:95
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
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
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:283
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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:140
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:286
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
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:76
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)
class MODULE, a footprint
Definition: typeinfo.h:89
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.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
MODULE * module() const
PCBNEW_SETTINGS & Settings()
void Activate()
Function Activate() Runs the tool.
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:62
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:284
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(), 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_TOOL_BASE::module(), PCB_MODULE_T, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), MODULE::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 1604 of file selection_tool.cpp.

1605 {
1606  BOARD_ITEM* current = nullptr;
1607  PCBNEW_SELECTION highlightGroup;
1608  bool selectAll = false;
1609  bool expandSelection = false;
1610 
1611  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1612  getView()->Add( &highlightGroup );
1613 
1614  do
1615  {
1617  if( expandSelection )
1618  aCollector->Combine();
1619 
1620  expandSelection = false;
1621 
1622  int limit = std::min( 9, aCollector->GetCount() );
1623  ACTION_MENU menu( true );
1624 
1625  for( int i = 0; i < limit; ++i )
1626  {
1627  wxString text;
1628  BOARD_ITEM* item = ( *aCollector )[i];
1629  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1630 
1631  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1632  menu.Add( menuText, i + 1, item->GetMenuImage() );
1633  }
1634 
1635  menu.AppendSeparator();
1636  menu.Add( _( "Select &All\tA" ), limit + 1, net_highlight_xpm );
1637 
1638  if( !expandSelection && aCollector->HasAdditionalItems() )
1639  menu.Add( _( "&Expand Selection\tE" ), limit + 2, nullptr );
1640 
1641  if( aTitle.Length() )
1642  {
1643  menu.SetTitle( aTitle );
1644  menu.SetIcon( info_xpm );
1645  menu.DisplayTitle( true );
1646  }
1647  else
1648  menu.DisplayTitle( false );
1649 
1650  SetContextMenu( &menu, CMENU_NOW );
1651 
1652  while( TOOL_EVENT* evt = Wait() )
1653  {
1654  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1655  {
1656  if( selectAll )
1657  {
1658  for( int i = 0; i < aCollector->GetCount(); ++i )
1659  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1660  }
1661  else if( current )
1662  unhighlight( current, BRIGHTENED, &highlightGroup );
1663 
1664  int id = *evt->GetCommandId();
1665 
1666  // User has pointed an item, so show it in a different way
1667  if( id > 0 && id <= limit )
1668  {
1669  current = ( *aCollector )[id - 1];
1670  highlight( current, BRIGHTENED, &highlightGroup );
1671  }
1672  else
1673  current = nullptr;
1674 
1675  // User has pointed on the "Select All" option
1676  if( id == limit + 1 )
1677  {
1678  for( int i = 0; i < aCollector->GetCount(); ++i )
1679  highlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1680  selectAll = true;
1681  }
1682  else
1683  selectAll = false;
1684  }
1685  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1686  {
1687  if( selectAll )
1688  {
1689  for( int i = 0; i < aCollector->GetCount(); ++i )
1690  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1691  }
1692  else if( current )
1693  unhighlight( current, BRIGHTENED, &highlightGroup );
1694 
1695  OPT<int> id = evt->GetCommandId();
1696 
1697  // User has selected the "Select All" option
1698  if( id == limit + 1 )
1699  {
1700  selectAll = true;
1701  current = nullptr;
1702  }
1703  else if( id == limit + 2 )
1704  {
1705  expandSelection = true;
1706  selectAll = false;
1707  current = nullptr;
1708  }
1709  // User has selected an item, so this one will be returned
1710  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1711  {
1712  selectAll = false;
1713  current = ( *aCollector )[*id - 1];
1714  }
1715  else
1716  {
1717  selectAll = false;
1718  current = nullptr;
1719  }
1720  }
1721  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1722  {
1723  break;
1724  }
1725  }
1726  } while( expandSelection );
1727 
1728  getView()->Remove( &highlightGroup );
1729 
1730  if( selectAll )
1731  return true;
1732  else if( current )
1733  {
1734  aCollector->Empty();
1735  aCollector->Append( current );
1736  return true;
1737  }
1738 
1739  return false;
1740 }
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,...
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:375
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
const BITMAP_OPAQUE net_highlight_xpm[1]
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
TOOL_EVENT.
Definition: tool_event.h:171
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
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, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#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...
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:345
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
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.

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, net_highlight_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().

◆ EditingModules()

bool PCB_TOOL_BASE::EditingModules ( ) const
inlineinherited

◆ EnterGroup()

void SELECTION_TOOL::EnterGroup ( )

Definition at line 337 of file selection_tool.cpp.

338 {
339  wxCHECK_RET( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T,
340  "EnterGroup called when selection is not a single group" );
341  PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
342 
343  if( m_enteredGroup != NULL )
344  ExitGroup();
345 
346  ClearSelection();
347  m_enteredGroup = aGroup;
348  m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem ) { select( titem ); } );
349 }
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Invokes a function on all members of the group.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
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 unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.

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

Referenced by PCB_EDITOR_CONTROL::GroupEnterSelected(), 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 352 of file selection_tool.cpp.

353 {
354  // Only continue if there is a group entered
355  if( m_enteredGroup == nullptr )
356  return;
357 
358  ClearSelection();
359 
360  if( aSelectGroup )
362 
364 }
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.

References ClearSelection(), m_enteredGroup, NULL, 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 913 of file selection_tool.cpp.

914 {
915  unsigned initialCount = 0;
916 
917  for( auto item : m_selection.GetItems() )
918  {
919  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
920  initialCount++;
921  }
922 
923  if( initialCount == 0 )
925 
926  for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
927  {
928  // copy the selection, since we're going to iterate and modify
929  std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
930 
931  for( EDA_ITEM* item : selectedItems )
932  item->ClearTempFlags();
933 
934  for( EDA_ITEM* item : selectedItems )
935  {
936  TRACK* trackItem = dynamic_cast<TRACK*>( item );
937 
938  // Track items marked SKIP_STRUCT have already been visited
939  if( trackItem && !( trackItem->GetFlags() & SKIP_STRUCT ) )
940  selectConnectedTracks( *trackItem, stopCondition );
941  }
942 
943  if( m_selection.GetItems().size() > initialCount )
944  break;
945  }
946 
947  // Inform other potentially interested tools
948  if( m_selection.Size() > 0 )
950 
951  return 0;
952 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
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:132
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:127
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:234

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)
private

Applies the SELECTION_FILTER_OPTIONS to a collection of items

Definition at line 1444 of file selection_tool.cpp.

1445 {
1446  if( aCollector.GetCount() == 0 )
1447  return;
1448 
1449  std::set<BOARD_ITEM*> rejected;
1450 
1451  for( EDA_ITEM* i : aCollector )
1452  {
1453  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1454 
1455  if( !itemPassesFilter( item ) )
1456  rejected.insert( item );
1457  }
1458 
1459  for( BOARD_ITEM* item : rejected )
1460  aCollector.Remove( item );
1461 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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:101
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159

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

Referenced by selectPoint().

◆ FilterCollectorForGroups()

void SELECTION_TOOL::FilterCollectorForGroups ( GENERAL_COLLECTOR aCollector) const

Definition at line 2534 of file selection_tool.cpp.

2535 {
2536  std::unordered_set<BOARD_ITEM*> toAdd;
2537 
2538  // If any element is a member of a group, replace those elements with the top containing group.
2539  for( int j = 0; j < aCollector.GetCount(); ++j )
2540  {
2541  PCB_GROUP* aTop = board()->TopLevelGroup( aCollector[j], m_enteredGroup );
2542 
2543  if( aTop != NULL )
2544  {
2545  if( aTop != aCollector[j] )
2546  {
2547  toAdd.insert( aTop );
2548  aCollector.Remove( aCollector[j] );
2549  }
2550  }
2551  else if( m_enteredGroup != NULL &&
2552  m_enteredGroup->GetItems().find( aCollector[j] ) == m_enteredGroup->GetItems().end() )
2553  {
2554  // If a group is entered, no selections of objects not in the group.
2555  aCollector.Remove( aCollector[j] );
2556  }
2557  }
2558 
2559  for( BOARD_ITEM* item : toAdd )
2560  {
2561  if( !aCollector.HasItem( item ) )
2562  {
2563  aCollector.Append( item );
2564  }
2565  }
2566 }
BOARD * board() const
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
PCB_GROUP * m_enteredGroup
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:130
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:120
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
#define NULL
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:229
PCB_GROUP * TopLevelGroup(BOARD_ITEM *item, PCB_GROUP *scope)
const BOARD_ITEM_SET & GetItems() const

References COLLECTOR::Append(), PCB_TOOL_BASE::board(), COLLECTOR::GetCount(), PCB_GROUP::GetItems(), COLLECTOR::HasItem(), m_enteredGroup, NULL, COLLECTOR::Remove(), and BOARD::TopLevelGroup().

Referenced by EditToolSelectionFilter(), and GuessSelectionCandidates().

◆ filterSelection()

int SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection

Definition at line 1412 of file selection_tool.cpp.

1413 {
1414  const BOARD& board = *getModel<BOARD>();
1415  DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
1416  DIALOG_FILTER_SELECTION dlg( m_frame, opts );
1417 
1418  const int cmd = dlg.ShowModal();
1419 
1420  if( cmd != wxID_OK )
1421  return 0;
1422 
1423  // copy current selection
1424  std::deque<EDA_ITEM*> selection = m_selection.GetItems();
1425 
1426  ClearSelection( true /*quiet mode*/ );
1427 
1428  // re-select items from the saved selection according to the dialog options
1429  for( EDA_ITEM* i : selection )
1430  {
1431  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1432  bool include = itemIsIncludedByFilter( *item, board, opts );
1433 
1434  if( include )
1435  select( item );
1436  }
1437 
1439 
1440  return 0;
1441 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
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,...
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:132
PCB_BASE_FRAME * m_frame
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Function itemIsIncludedByFilter()
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159

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

1326 {
1327  DIALOG_FIND dlg( m_frame );
1328  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1329  dlg.ShowModal();
1330 
1331  return 0;
1332 }
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 1296 of file selection_tool.cpp.

1297 {
1298  bool cleared = false;
1299 
1300  if( m_selection.GetSize() > 0 )
1301  {
1302  // Don't fire an event now; most of the time it will be redundant as we're about to
1303  // fire a SelectedEvent.
1304  cleared = true;
1305  ClearSelection( true /*quiet mode*/ );
1306  }
1307 
1308  if( aItem )
1309  {
1310  select( aItem );
1311  m_frame->FocusOnLocation( aItem->GetPosition() );
1312 
1313  // Inform other potentially interested tools
1315  }
1316  else if( cleared )
1317  {
1319  }
1320 
1322 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
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: base_struct.h:337
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:208
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
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().

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 161 of file pcb_tool_base.h.

162  {
163  return getEditFrame<PCB_BASE_EDIT_FRAME>();
164  }

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(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), FOOTPRINT_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), 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(), EDIT_TOOL::pickReferencePoint(), 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 ( )
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 456 of file selection_tool.cpp.

457 {
458  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
459  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
460 
461  bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
462 
463  // account for the globals
464  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
465  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
466  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
467  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
468  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
469  guide.SetIgnorePadsOnBack( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_BK ) );
470  guide.SetIgnorePadsOnFront( padsDisabled || ! board()->IsElementVisible( LAYER_PAD_FR ) );
471  guide.SetIgnoreThroughHolePads( padsDisabled || ! board()->IsElementVisible( LAYER_PADS_TH ) );
472  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
473  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
474  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIAS ) );
475  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIAS ) );
476  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIAS ) );
477  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
478 
479  return guide;
480 }
BOARD * board() const
multilayer pads, usually with holes
show modules values (when texts are visibles)
show modules 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
Function IsElementVisible tests whether a given element category is visible.
smd pads, front layer
Meta control for all vias opacity/visibility.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:390
show modules 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 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: base_struct.h:159

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:289
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::checkPart(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), 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(), PCB_VIEWER_TOOLS::MeasureTool(), GERBVIEW_SELECTION_TOOL::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(), EE_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(), EE_POINT_EDITOR::updateItem(), PL_POINT_EDITOR::updateItem(), POINT_EDITOR::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), POINT_EDITOR::updatePoints(), updateSelection(), PNS::TOOL_BASE::updateStartItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateView(), 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:291

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(), 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(), PCB_VIEWER_TOOLS::MeasureTool(), GERBVIEW_SELECTION_TOOL::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(), LIB_MOVE_TOOL::updateModificationPoint(), 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 LENGTH_TUNER_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), PCB_REANNOTATE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), LIB_PIN_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), DRC_TOOL::setTransitions(), POINT_EDITOR::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), SCH_MOVE_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), PAD_TOOL::setTransitions(), FOOTPRINT_EDITOR_TOOLS::setTransitions(), SCH_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_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 2202 of file selection_tool.cpp.

2204 {
2205  std::set<BOARD_ITEM*> preferred;
2206  std::set<BOARD_ITEM*> rejected;
2207  std::set<BOARD_ITEM*> forced;
2208  wxPoint where( aWhere.x, aWhere.y );
2209 
2210  // footprints which are below this percentage of the largest footprint will be considered
2211  // for selection; all others will not
2212  constexpr double footprintToFootprintMinRatio = 0.20;
2213  // pads which are below this percentage of their parent's area will exclude their parent
2214  constexpr double padToFootprintMinRatio = 0.45;
2215  // footprints containing items with items-to-footprint area ratio higher than this will be
2216  // forced to stay on the list
2217  constexpr double footprintMaxCoverRatio = 0.90;
2218  constexpr double viaToPadMinRatio = 0.50;
2219  constexpr double trackViaLengthRatio = 2.0;
2220  constexpr double trackTrackLengthRatio = 0.3;
2221  constexpr double textToFeatureMinRatio = 0.2;
2222  constexpr double textToFootprintMinRatio = 0.4;
2223  // If the common area of two compared items is above the following threshold, they cannot
2224  // be rejected (it means they overlap and it might be hard to pick one by selecting
2225  // its unique area).
2226  constexpr double commonAreaRatio = 0.6;
2227 
2228  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
2229  LSET silkLayers( 2, B_SilkS, F_SilkS );
2230 
2231  if( silkLayers[activeLayer] )
2232  {
2233  for( int i = 0; i < aCollector.GetCount(); ++i )
2234  {
2235  BOARD_ITEM* item = aCollector[i];
2236  KICAD_T type = item->Type();
2237 
2238  if( ( type == PCB_MODULE_TEXT_T || type == PCB_TEXT_T || type == PCB_LINE_T )
2239  && silkLayers[item->GetLayer()] )
2240  {
2241  preferred.insert( item );
2242  }
2243  }
2244 
2245  if( preferred.size() > 0 )
2246  {
2247  aCollector.Empty();
2248 
2249  for( BOARD_ITEM* item : preferred )
2250  aCollector.Append( item );
2251  return;
2252  }
2253  }
2254 
2255  // Zone edges are very specific; zone fills much less so.
2256  if( aCollector.CountType( PCB_ZONE_AREA_T ) > 0 )
2257  {
2258  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2259  {
2260  if( aCollector[i]->Type() == PCB_ZONE_AREA_T )
2261  {
2262  auto zone = static_cast<ZONE_CONTAINER*>( aCollector[i] );
2263 
2264  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
2265  preferred.insert( zone );
2266  else
2267  rejected.insert( zone );
2268  }
2269  }
2270 
2271  if( preferred.size() > 0 )
2272  {
2273  aCollector.Empty();
2274 
2275  for( BOARD_ITEM* item : preferred )
2276  aCollector.Append( item );
2277  return;
2278  }
2279  }
2280 
2281  if( aCollector.CountType( PCB_MODULE_TEXT_T ) > 0 )
2282  {
2283  for( int i = 0; i < aCollector.GetCount(); ++i )
2284  {
2285  if( TEXTE_MODULE* txt = dyn_cast<TEXTE_MODULE*>( aCollector[i] ) )
2286  {
2287  double textArea = calcArea( txt );
2288 
2289  for( int j = 0; j < aCollector.GetCount(); ++j )
2290  {
2291  if( i == j )
2292  continue;
2293 
2294  BOARD_ITEM* item = aCollector[j];
2295  double itemArea = calcArea( item );
2296  double areaRatio = calcRatio( textArea, itemArea );
2297  double commonArea = calcCommonArea( txt, item );
2298  double itemCommonRatio = calcRatio( commonArea, itemArea );
2299  double txtCommonRatio = calcRatio( commonArea, textArea );
2300 
2301  if( item->Type() == PCB_MODULE_T )
2302  {
2303  // when text area is small compared to an overlapping footprint,
2304  // then it's a clear sign the text is the selection target
2305  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
2306  rejected.insert( item );
2307  }
2308 
2309  switch( item->Type() )
2310  {
2311  case PCB_TRACE_T:
2312  case PCB_ARC_T:
2313  case PCB_PAD_T:
2314  case PCB_LINE_T:
2315  case PCB_VIA_T:
2316  case PCB_MODULE_T:
2317  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
2318  rejected.insert( txt );
2319  break;
2320  default:
2321  break;
2322  }
2323  }
2324  }
2325  }
2326  }
2327 
2328  if( aCollector.CountType( PCB_MODULE_EDGE_T ) + aCollector.CountType( PCB_LINE_T ) > 1 )
2329  {
2330  // Prefer exact hits to sloppy ones
2331  int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
2332  bool found = false;
2333 
2334  for( int dist = 0; dist < accuracy; ++dist )
2335  {
2336  for( int i = 0; i < aCollector.GetCount(); ++i )
2337  {
2338  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2339  {
2340  if( drawSegment->HitTest( where, dist ) )
2341  {
2342  found = true;
2343  break;
2344  }
2345  }
2346  }
2347 
2348  if( found )
2349  {
2350  // throw out everything that is more sloppy than what we found
2351  for( int i = 0; i < aCollector.GetCount(); ++i )
2352  {
2353  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2354  {
2355  if( !drawSegment->HitTest( where, dist ) )
2356  rejected.insert( drawSegment );
2357  }
2358  }
2359 
2360  // we're done now
2361  break;
2362  }
2363  }
2364  }
2365 
2366  if( aCollector.CountType( PCB_PAD_T ) > 0 )
2367  {
2368  for( int i = 0; i < aCollector.GetCount(); ++i )
2369  {
2370  if( D_PAD* pad = dyn_cast<D_PAD*>( aCollector[i] ) )
2371  {
2372  MODULE* parent = pad->GetParent();
2373  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
2374 
2375  // when pad area is small compared to the parent footprint,
2376  // then it is a clear sign the pad is the selection target
2377  if( ratio < padToFootprintMinRatio )
2378  rejected.insert( pad->GetParent() );
2379  }
2380  }
2381  }
2382 
2383  bool hasNonModules = false;
2384 
2385  for( int i = 0; i < aCollector.GetCount(); ++i )
2386  {
2387  if( aCollector[i]->Type() != PCB_MODULE_T )
2388  {
2389  hasNonModules = true;
2390  break;
2391  }
2392  }
2393 
2394  if( aCollector.CountType( PCB_MODULE_T ) > 0 )
2395  {
2396  double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
2397  BOX2D viewportD = getView()->GetViewport();
2398  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2399  double maxCoverRatio = footprintMaxCoverRatio;
2400 
2401  // MODULE::CoverageRatio() doesn't take zone handles & borders into account so just
2402  // use a more aggressive cutoff point if zones are involved.
2403  if( aCollector.CountType( PCB_ZONE_AREA_T ) )
2404  maxCoverRatio /= 2;
2405 
2406  for( int i = 0; i < aCollector.GetCount(); ++i )
2407  {
2408  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
2409  {
2410  // filter out components larger than the viewport
2411  if( mod->ViewBBox().GetHeight() > viewport.GetHeight() ||
2412  mod->ViewBBox().GetWidth() > viewport.GetWidth() )
2413  rejected.insert( mod );
2414  // footprints completely covered with other features have no other
2415  // means of selection, so must be kept
2416  else if( mod->CoverageRatio( aCollector ) > maxCoverRatio )
2417  rejected.erase( mod );
2418  // if a footprint is much smaller than the largest overlapping
2419  // footprint then it should be considered for selection
2420  else if( calcRatio( calcArea( mod ), maxArea ) <= footprintToFootprintMinRatio )
2421  continue;
2422  // reject ALL OTHER footprints if there's still something else left
2423  // to select
2424  else if( hasNonModules )
2425  rejected.insert( mod );
2426  }
2427  }
2428  }
2429 
2430  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2431  {
2432  for( int i = 0; i < aCollector.GetCount(); ++i )
2433  {
2434  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2435  {
2436  double viaArea = calcArea( via );
2437 
2438  for( int j = 0; j < aCollector.GetCount(); ++j )
2439  {
2440  if( i == j )
2441  continue;
2442 
2443  BOARD_ITEM* item = aCollector[j];
2444  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2445 
2446  if( item->Type() == PCB_MODULE_T && areaRatio < padToFootprintMinRatio )
2447  rejected.insert( item );
2448 
2449  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2450  rejected.insert( item );
2451 
2452  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2453  {
2454  if( track->GetNetCode() != via->GetNetCode() )
2455  continue;
2456 
2457  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2458  (double) via->GetWidth();
2459 
2460  if( lenRatio > trackViaLengthRatio )
2461  rejected.insert( track );
2462  }
2463  }
2464  }
2465  }
2466  }
2467 
2468  int nTracks = aCollector.CountType( PCB_TRACE_T );
2469 
2470  if( nTracks > 0 )
2471  {
2472  double maxLength = 0.0;
2473  double minLength = std::numeric_limits<double>::max();
2474  double maxArea = 0.0;
2475  const TRACK* maxTrack = nullptr;
2476 
2477  for( int i = 0; i < aCollector.GetCount(); ++i )
2478  {
2479  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2480  {
2481  maxLength = std::max( track->GetLength(), maxLength );
2482  maxLength = std::max( (double) track->GetWidth(), maxLength );
2483 
2484  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2485 
2486  double area = track->GetLength() * track->GetWidth();
2487 
2488  if( area > maxArea )
2489  {
2490  maxArea = area;
2491  maxTrack = track;
2492  }
2493  }
2494  }
2495 
2496  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2497  {
2498  for( int i = 0; i < aCollector.GetCount(); ++i )
2499  {
2500  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2501  {
2502  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2503 
2504  if( ratio > trackTrackLengthRatio )
2505  rejected.insert( track );
2506  }
2507  }
2508  }
2509 
2510  for( int j = 0; j < aCollector.GetCount(); ++j )
2511  {
2512  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[j] ) )
2513  {
2514  double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() );
2515 
2516  if( ratio < padToFootprintMinRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio )
2517  rejected.insert( mod );
2518  }
2519  }
2520  }
2521 
2522  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2523  {
2524  for( BOARD_ITEM* item : rejected )
2525  {
2526  aCollector.Transfer( item );
2527  }
2528  }
2529 
2530  FilterCollectorForGroups( aCollector );
2531 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:110
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:537
static double calcCommonArea(const BOARD_ITEM *aItem, const BOARD_ITEM *aOther)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual double OnePixelInIU() const =0
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
const COLLECTORS_GUIDE * GetGuide()
Definition: collectors.h:352
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
int CountType(KICAD_T aType)
Function CountType counts the number of items matching aType.
Definition: collector.h:262
static double calcArea(const BOARD_ITEM *aItem)
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
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:120
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
class MODULE, a footprint
Definition: typeinfo.h:89
void Transfer(int aIndex)
Moves the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:174
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
static double calcMaxArea(GENERAL_COLLECTOR &aCollector, KICAD_T aType)
virtual int GetTopLayer() const
Definition: view.cpp:847
KIGFX::PCB_VIEW * view() const
void FilterCollectorForGroups(GENERAL_COLLECTOR &aCollector) const
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
const Vec & GetPosition() const
Definition: box2.h:194
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
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
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
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References COLLECTOR::Append(), B_SilkS, calcArea(), calcCommonArea(), calcMaxArea(), calcRatio(), COLLECTOR::CountType(), COLLECTOR::Empty(), F_SilkS, FilterCollectorForGroups(), COLLECTOR::GetCount(), 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(), KiROUND(), COLLECTORS_GUIDE::OnePixelInIU(), PCB_ARC_T, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, COLLECTOR::Transfer(), EDA_ITEM::Type(), PCB_TOOL_BASE::view(), 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 2000 of file selection_tool.cpp.

2001 {
2002  highlightInternal( aItem, aMode, aGroup, false );
2003 
2004  view()->Update( aItem );
2005 
2006  // Many selections are very temporal and updating the display each time just
2007  // creates noise.
2008  if( aMode == BRIGHTENED )
2010 }
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:574
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup, bool isChild)
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
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

References BRIGHTENED, TOOL_BASE::getView(), highlightInternal(), KIGFX::VIEW::MarkTargetDirty(), 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 aGroup,
bool  isChild 
)
private

Definition at line 2012 of file selection_tool.cpp.

2013 {
2014  wxLogTrace( "GRP", wxString::Format( "highlight() of %s %p",
2015  aItem->GetSelectMenuText( m_frame->GetUserUnits() ) ), aItem );
2016  if( aMode == SELECTED )
2017  aItem->SetSelected();
2018  else if( aMode == BRIGHTENED )
2019  aItem->SetBrightened();
2020 
2021  if( aGroup )
2022  {
2023  // Hide the original item, so it is shown only on overlay
2024  view()->Hide( aItem, true );
2025 
2026  if( !isChild || aMode == BRIGHTENED )
2027  aGroup->Add( aItem );
2028  }
2029 
2030  // Modules are treated in a special way - when they are highlighted, we have to
2031  // highlight all the parts that make the module, not the module itself
2032  if( aItem->Type() == PCB_MODULE_T )
2033  {
2034  static_cast<MODULE*>( aItem )->RunOnChildren( [&]( BOARD_ITEM* titem ) {
2035  highlightInternal( titem, aMode, aGroup, true ); } );
2036  }
2037  else if( aItem->Type() == PCB_GROUP_T )
2038  {
2039  static_cast<PCB_GROUP*>( aItem )->RunOnChildren( [&]( BOARD_ITEM* titem ) {
2040  highlightInternal( titem, aMode, aGroup, true ); } );
2041  }
2042 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1498
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
void SetBrightened()
Definition: base_struct.h:209
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:76
#define SELECTED
Definition: base_struct.h:124
class MODULE, a footprint
Definition: typeinfo.h:89
void SetSelected()
Definition: base_struct.h:208
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup, bool isChild)
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
PCB_BASE_FRAME * m_frame
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References SELECTION::Add(), BRIGHTENED, Format(), EDA_ITEM::GetSelectMenuText(), EDA_BASE_FRAME::GetUserUnits(), KIGFX::VIEW::Hide(), m_frame, PCB_GROUP_T, PCB_MODULE_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 131 of file selection_tool.cpp.

132 {
133  auto frame = getEditFrame<PCB_BASE_FRAME>();
134 
137  {
139  return true;
140  }
141 
142  auto selectMenu = std::make_shared<SELECT_MENU>();
143  selectMenu->SetTool( this );
144  m_menu.AddSubMenu( selectMenu );
145 
146  auto& menu = m_menu.GetMenu();
147 
148  auto activeToolCondition =
149  [ frame ] ( const SELECTION& aSel )
150  {
151  return !frame->ToolStackIsEmpty();
152  };
153 
154  auto inGroupCondition =
155  [this] ( const SELECTION& )
156  {
157  return m_enteredGroup != nullptr;
158  };
159 
160  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
161  menu.AddSeparator( 1000 );
162 
163  // "Cancel" goes at the top of the context menu when a tool is active
164  menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
165  menu.AddItem( PCB_ACTIONS::groupLeave, inGroupCondition, 1);
166  menu.AddSeparator( 1 );
167 
168  if( frame )
170 
171  return true;
172 }
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
bool AddItem(BOARD_ITEM *aItem)
Adds item to group.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
static TOOL_ACTION groupLeave
Definition: pcb_actions.h:411
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:117
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().

◆ 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 1464 of file selection_tool.cpp.

1465 {
1466  if( aItem->IsLocked() && !m_filter.lockedItems )
1467  return false;
1468 
1469  switch( aItem->Type() )
1470  {
1471  case PCB_MODULE_T:
1472  if( !m_filter.footprints )
1473  return false;
1474 
1475  break;
1476 
1477  case PCB_PAD_T:
1478  if( !m_filter.pads )
1479  return false;
1480 
1481  break;
1482 
1483  case PCB_TRACE_T:
1484  case PCB_ARC_T:
1485  if( !m_filter.tracks )
1486  return false;
1487 
1488  break;
1489 
1490  case PCB_VIA_T:
1491  if( !m_filter.vias )
1492  return false;
1493 
1494  break;
1495 
1496  case PCB_ZONE_AREA_T:
1497  {
1498  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( aItem );
1499 
1500  if( ( !m_filter.zones && !zone->GetIsKeepout() )
1501  || ( !m_filter.keepouts && zone->GetIsKeepout() ) )
1502  {
1503  return false;
1504  }
1505 
1506  break;
1507  }
1508  case PCB_LINE_T:
1509  case PCB_TARGET_T:
1510  if( !m_filter.graphics )
1511  return false;
1512 
1513  break;
1514 
1515  case PCB_MODULE_TEXT_T:
1516  case PCB_TEXT_T:
1517  if( !m_filter.text )
1518  return false;
1519 
1520  break;
1521 
1522  case PCB_DIM_ALIGNED_T:
1523  case PCB_DIM_CENTER_T:
1524  case PCB_DIM_ORTHOGONAL_T:
1525  case PCB_DIM_LEADER_T:
1526  if( !m_filter.dimensions )
1527  return false;
1528 
1529  break;
1530 
1531  default:
1532  if( !m_filter.otherItems )
1533  return false;
1534  }
1535 
1536  if( m_enteredGroup != NULL )
1537  {
1538  return m_enteredGroup->GetItems().find( aItem ) != m_enteredGroup->GetItems().end();
1539  }
1540 
1541  return true;
1542 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
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 CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCB_GROUP * m_enteredGroup
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class MODULE, a footprint
Definition: typeinfo.h:89
bool text
Text (free or attached to a footprint)
#define NULL
bool dimensions
Dimension items.
bool graphics
Graphic lines, shapes, polygons.
bool footprints
Allow selecting entire footprints.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:717
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual bool IsLocked() const
Function IsLocked.
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 DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
const BOARD_ITEM_SET & GetItems() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References SELECTION_FILTER_OPTIONS::dimensions, SELECTION_FILTER_OPTIONS::footprints, ZONE_CONTAINER::GetIsKeepout(), PCB_GROUP::GetItems(), SELECTION_FILTER_OPTIONS::graphics, BOARD_ITEM::IsLocked(), SELECTION_FILTER_OPTIONS::keepouts, SELECTION_FILTER_OPTIONS::lockedItems, m_enteredGroup, m_filter, NULL, 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_LINE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_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(), selectAllItemsOnNet(), and selectMultiple().

◆ Main()

int SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

The main loop.

Definition at line 205 of file selection_tool.cpp.

206 {
207  // Main loop: keep receiving events
208  while( TOOL_EVENT* evt = Wait() )
209  {
210  if( m_frame->ToolStackIsEmpty() )
211  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
212 
213  bool dragAlwaysSelects = getEditFrame<PCB_BASE_FRAME>()->GetDragSelects();
214  TRACK_DRAG_ACTION dragAction = getEditFrame<PCB_BASE_FRAME>()->Settings().m_TrackDragAction;
216 
217  // OSX uses CTRL for context menu, and SHIFT is exclusive-or
218 #ifdef __WXOSX_MAC__
219  if( evt->Modifier( MD_SHIFT ) )
220  m_exclusive_or = true;
221 #else
222  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
223  m_subtractive = true;
224  else if( evt->Modifier( MD_SHIFT ) )
225  m_additive = true;
226  else if( evt->Modifier( MD_CTRL ) )
227  m_exclusive_or = true;
228 #endif
229 
230  // Is the user requesting that the selection list include all possible
231  // items without removing less likely selection candidates
232  m_skip_heuristics = !!evt->Modifier( MD_ALT );
233 
234  // Single click? Select single object
235  if( evt->IsClick( BUT_LEFT ) )
236  {
237  m_frame->FocusOnItem( nullptr );
238 
239  selectPoint( evt->Position() );
240  }
241 
242  // right click? if there is any object - show the context menu
243  else if( evt->IsClick( BUT_RIGHT ) )
244  {
245  bool selectionCancelled = false;
246 
247  if( m_selection.Empty() ||
248  !m_selection.GetBoundingBox().Contains( wxPoint( evt->Position() ) ) )
249  {
250  ClearSelection();
251  selectPoint( evt->Position(), false, &selectionCancelled );
252  m_selection.SetIsHover( true );
253  }
254 
255  if( !selectionCancelled )
257  }
258 
259  // double click? Display the properties window
260  else if( evt->IsDblClick( BUT_LEFT ) )
261  {
262  m_frame->FocusOnItem( nullptr );
263 
264  if( m_selection.Empty() )
265  selectPoint( evt->Position() );
266 
267  if( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T )
268  {
269  EnterGroup();
270  }
271  else
272  {
274  }
275  }
276 
277  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
278  else if( evt->IsDrag( BUT_LEFT ) )
279  {
280  m_frame->FocusOnItem( nullptr );
281 
282  if( m_additive || m_subtractive || m_exclusive_or || dragAlwaysSelects )
283  {
284  selectMultiple();
285  }
286  else
287  {
288  // selection is empty? try to start dragging the item under the point where drag
289  // started
290  if( m_selection.Empty() && selectCursor() )
291  m_selection.SetIsHover( true );
292 
293  // Check if dragging has started within any of selected items bounding box.
294  // We verify "HasPosition()" first to protect against edge case involving
295  // moving off menus that causes problems (issue #5250)
296  if( evt->HasPosition() && selectionContains( evt->Position() ) )
297  {
298  // Yes -> run the move tool and wait till it finishes
299  TRACK* track = dynamic_cast<TRACK*>( m_selection.GetItem( 0 ) );
300 
301  if( track && dragAction == TRACK_DRAG_ACTION::DRAG )
303  else if( track && dragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
305  else
307  }
308  else
309  {
310  // No -> drag a selection box
311  selectMultiple();
312  }
313  }
314  }
315 
316  else if( evt->IsCancel() )
317  {
318  m_frame->FocusOnItem( nullptr );
319 
320  if( m_enteredGroup != NULL )
321  ExitGroup();
322 
323  ClearSelection();
324 
325  if( evt->FirstResponder() == this )
327  }
328 
329  else
330  evt->SetPassEvent();
331  }
332 
333  return 0;
334 }
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
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
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:135
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:114
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:140
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:134
PCB_GROUP * m_enteredGroup
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
bool Contains(const wxPoint &aPoint) const
Function Contains.
TRACK_DRAG_ACTION
void SetIsHover(bool aIsHover)
Definition: selection.h:66
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...
#define NULL
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...
TOOL_EVENT.
Definition: tool_event.h:171
bool ToolStackIsEmpty()
Definition: tools_holder.h:117
PCB_BASE_FRAME * m_frame
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:105
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:428
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
EDA_RECT GetBoundingBox() const
Definition: selection.h:156
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
void FocusOnItem(BOARD_ITEM *aItem)

References BUT_LEFT, BUT_RIGHT, PCB_ACTIONS::clearHighlight, ClearSelection(), EDA_RECT::Contains(), DRAG, PCB_ACTIONS::drag45Degree, DRAG_FREE_ANGLE, PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), EnterGroup(), ExitGroup(), PCB_BASE_FRAME::FocusOnItem(), SELECTION::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), SELECTION::GetItem(), SELECTION::GetSize(), 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, NULL, PCB_GROUP_T, PCB_ACTIONS::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TOOLS_HOLDER::ToolStackIsEmpty(), and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

◆ module()

◆ 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 1743 of file selection_tool.cpp.

1744 {
1745  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1746 
1747  if( 0 == count )
1748  count = aCollector->GetCount();
1749 
1750  for( int i = 0; i < count; ++i )
1751  {
1752  if( ( *aCollector )[i]->Type() != PCB_MODULE_T )
1753  return NULL;
1754  }
1755 
1756  // All are modules, now find smallest MODULE
1757  int minDim = 0x7FFFFFFF;
1758  int minNdx = 0;
1759 
1760  for( int i = 0; i < count; ++i )
1761  {
1762  MODULE* module = (MODULE*) ( *aCollector )[i];
1763 
1764  int lx = module->GetFootprintRect().GetWidth();
1765  int ly = module->GetFootprintRect().GetHeight();
1766 
1767  int lmin = std::min( lx, ly );
1768 
1769  if( lmin < minDim )
1770  {
1771  minDim = lmin;
1772  minNdx = i;
1773  }
1774  }
1775 
1776  return (*aCollector)[minNdx];
1777 }
int GetWidth() const
Definition: eda_rect.h:119
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text.
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
class MODULE, a footprint
Definition: typeinfo.h:89
#define NULL
int GetHeight() const
Definition: eda_rect.h:120
MODULE * module() const

References COLLECTOR::GetCount(), MODULE::GetFootprintRect(), EDA_RECT::GetHeight(), GENERAL_COLLECTOR::GetPrimaryCount(), EDA_RECT::GetWidth(), PCB_TOOL_BASE::module(), NULL, and PCB_MODULE_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 1569 of file selection_tool.cpp.

1570 {
1571  m_selection.Clear();
1572 
1573  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1574  {
1575  if( item->IsSelected() )
1576  {
1577  EDA_ITEM* parent = item->GetParent();
1578 
1579  // Flags on module children might be set only because the parent is selected.
1580  if( parent && parent->Type() == PCB_MODULE_T && parent->IsSelected() )
1581  return SEARCH_RESULT::CONTINUE;
1582 
1583  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1584  }
1585 
1586  return SEARCH_RESULT::CONTINUE;
1587  };
1588 
1589  board()->Visit( inspector, nullptr, m_editModules ? GENERAL_COLLECTOR::ModuleItems
1591 }
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:95
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: base_struct.h:80
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
BOARD * board() const
bool IsSelected() const
Definition: base_struct.h:203
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
#define SELECTED
Definition: base_struct.h:124
class MODULE, a footprint
Definition: typeinfo.h:89
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), SELECTION::Clear(), CONTINUE, EDA_ITEM::GetParent(), highlight(), EDA_ITEM::IsSelected(), PCB_TOOL_BASE::m_editModules, m_selection, GENERAL_COLLECTOR::ModuleItems, PCB_MODULE_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 870 of file selection_tool.cpp.

871 {
872  if( aItem )
873  {
874  unselect( aItem );
875 
876  // Inform other potentially interested tools
878  }
879 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
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(), 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 373 of file selection_tool.cpp.

376 {
377  bool selectionEmpty = m_selection.Empty();
378  m_selection.SetIsHover( selectionEmpty );
379 
380  if( selectionEmpty )
381  {
382  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
384  }
385 
386  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
387  {
388  ClearSelection();
389  return m_selection;
390  }
391 
392  if( aClientFilter )
393  {
394  enum DISPOSITION { BEFORE = 1, AFTER, BOTH };
395 
396  std::map<EDA_ITEM*, DISPOSITION> itemDispositions;
397  GENERAL_COLLECTOR collector;
398 
399  for( EDA_ITEM* item : m_selection )
400  {
401  collector.Append( item );
402  itemDispositions[ item ] = BEFORE;
403  }
404 
405  aClientFilter( VECTOR2I(), collector, this );
406 
407  for( EDA_ITEM* item : collector )
408  {
409  if( itemDispositions.count( item ) )
410  itemDispositions[ item ] = BOTH;
411  else
412  itemDispositions[ item ] = AFTER;
413  }
414 
415  // Unhighlight the BEFORE items before highlighting the AFTER items.
416  // This is so that in the case of groups, if aClientFilter replaces a selection
417  // with the enclosing group, the unhighlight of the element doesn't undo the
418  // recursive highlighting of that elemetn by the group.
419 
420  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
421  {
422  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
423  DISPOSITION disposition = itemDisposition.second;
424 
425  if( disposition == BEFORE )
426  {
427  if( aFiltered )
428  aFiltered->push_back( item );
429 
430  unhighlight( item, SELECTED, &m_selection );
431  }
432  }
433 
434  for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
435  {
436  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( itemDisposition.first );
437  DISPOSITION disposition = itemDisposition.second;
438 
439  if( disposition == AFTER )
440  {
441  highlight( item, SELECTED, &m_selection );
442  }
443  else if( disposition == BOTH )
444  {
445  // nothing to do
446  }
447  }
448 
450  }
451 
452  return m_selection;
453 }
void ClearReferencePoint()
Definition: selection.h:250
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,...
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:140
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetIsHover(bool aIsHover)
Definition: selection.h:66
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:120
#define SELECTED
Definition: base_struct.h:124
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), CONVERT_TOOL::LinesToPoly(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), 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 175 of file selection_tool.cpp.

176 {
177  m_frame = getEditFrame<PCB_BASE_FRAME>();
178  m_locked = true;
179 
180  if( m_enteredGroup != NULL )
181  ExitGroup();
182 
183  if( aReason == TOOL_BASE::MODEL_RELOAD )
184  {
185  // Deselect any item being currently in edit, to avoid unexpected behavior
186  // and remove pointers to the selected items from containers
187  // without changing their properties (as they are already deleted
188  // while a new board is loaded)
189  ClearSelection( true );
190 
191  getView()->GetPainter()->GetSettings()->SetHighlight( false );
192  }
193  else
194  {
195  // Restore previous properties of selected items and remove them from containers
196  ClearSelection( true );
197  }
198 
199  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
200  view()->Remove( &m_selection );
201  view()->Add( &m_selection );
202 }
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:199
#define NULL
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.

References KIGFX::PCB_VIEW::Add(), ClearSelection(), ExitGroup(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), m_enteredGroup, m_frame, m_locked, m_selection, TOOL_BASE::MODEL_RELOAD, NULL, 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 1973 of file selection_tool.cpp.

1974 {
1975  if( aItem->IsSelected() )
1976  {
1977  return;
1978  }
1979 
1980  if( aItem->Type() == PCB_PAD_T )
1981  {
1982  MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
1983 
1984  if( m_selection.Contains( module ) )
1985  return;
1986  }
1987 
1988  highlight( aItem, SELECTED, &m_selection );
1989 }
bool IsSelected() const
Definition: base_struct.h:203
PCBNEW_SELECTION m_selection
class D_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: base_struct.h:124
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:113
MODULE * module() const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

Referenced by AddItemToSel(), EnterGroup(), ExitGroup(), filterSelection(), findCallback(), PCB_EDITOR_CONTROL::GroupFlattenSelected(), PCB_EDITOR_CONTROL::GroupMergeSelected(), PCB_EDITOR_CONTROL::GroupSelected(), SelectAll(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), SelectItems(), selectMultiple(), selectNet(), selectPoint(), and PCB_EDITOR_CONTROL::UngroupSelected().

◆ 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 1780 of file selection_tool.cpp.

1781 {
1782  const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
1783 
1784  if( settings->GetHighContrast() )
1785  {
1786  std::set<unsigned int> activeLayers = settings->GetActiveLayers();
1787  bool onActiveLayer = false;
1788 
1789  for( unsigned int layer : activeLayers )
1790  {
1791  // NOTE: Only checking the regular layers (not GAL meta-layers)
1792  if( layer < PCB_LAYER_ID_COUNT && aItem->IsOnLayer( ToLAYER_ID( layer ) ) )
1793  {
1794  onActiveLayer = true;
1795  break;
1796  }
1797  }
1798 
1799  if( !onActiveLayer ) // We do not want to select items that are in the background
1800  return false;
1801  }
1802 
1803  switch( aItem->Type() )
1804  {
1805  case PCB_ZONE_AREA_T:
1807  {
1808  const ZONE_CONTAINER* zone = static_cast<const ZONE_CONTAINER*>( aItem );
1809 
1810  // Check to see if this keepout is part of a footprint
1811  // If it is, and we are not editing the footprint, it should not be selectable
1812  bool zoneInFootprint = zone->GetParent() && zone->GetParent()->Type() == PCB_MODULE_T;
1813 
1814  if( zoneInFootprint && !m_editModules && !checkVisibilityOnly )
1815  return false;
1816 
1817  // zones can exist on multiple layers!
1818  return ( zone->GetLayerSet() & board()->GetVisibleLayers() ).any();
1819  }
1820  break;
1821 
1822  case PCB_TRACE_T:
1823  case PCB_ARC_T:
1824  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1825  return false;
1826  break;
1827 
1828  case PCB_VIA_T:
1829  {
1830  if( !board()->IsElementVisible( LAYER_VIAS ) )
1831  return false;
1832 
1833  const VIA* via = static_cast<const VIA*>( aItem );
1834 
1835  // For vias it is enough if only one of its layers is visible
1836  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1837  }
1838 
1839  case PCB_MODULE_T:
1840  {
1841  // In modedit, we do not want to select the module itself.
1842  if( m_editModules )
1843  return false;
1844 
1845  // Allow selection of footprints if some part of the footprint is visible.
1846 
1847  MODULE* module = const_cast<MODULE*>( static_cast<const MODULE*>( aItem ) );
1848 
1849  for( BOARD_ITEM* item : module->GraphicalItems() )
1850  {
1851  if( Selectable( item, true ) )
1852  return true;
1853  }
1854 
1855  for( D_PAD* pad : module->Pads() )
1856  {
1857  if( Selectable( pad, true ) )
1858  return true;
1859  }
1860 
1861  for( ZONE_CONTAINER* zone : module->Zones() )
1862  {
1863  if( Selectable( zone, true ) )
1864  return true;
1865  }
1866 
1867  return false;
1868  }
1869 
1870  case PCB_MODULE_TEXT_T:
1871  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1872  // module subparts one by one, rather than with a drag selection. This is so you can
1873  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1874  if( !m_editModules && !checkVisibilityOnly )
1875  {
1876  if( m_multiple && !settings->GetHighContrast() )
1877  return false;
1878  }
1879 
1880  if( !m_editModules && !view()->IsVisible( aItem ) )
1881  return false;
1882 
1883  break;
1884 
1885  case PCB_MODULE_EDGE_T:
1886  // Module edge selections are only allowed in modedit mode.
1887  if( !m_editModules && !checkVisibilityOnly )
1888  return false;
1889 
1890  break;
1891 
1892  case PCB_PAD_T:
1893  {
1894  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1895  // module subparts one by one, rather than with a drag selection. This is so you can
1896  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1897  if( !m_editModules && !checkVisibilityOnly )
1898  {
1899  if( m_multiple )
1900  return false;
1901  }
1902 
1903  if( aItem->Type() == PCB_PAD_T )
1904  {
1905  auto pad = static_cast<const D_PAD*>( aItem );
1906 
1907  // In pcbnew, locked modules prevent individual pad selection.
1908  // In modedit, we don't enforce this as the module is assumed to be edited by design.
1909  if( !m_editModules && !checkVisibilityOnly )
1910  {
1911  if( pad->GetParent() && pad->GetParent()->IsLocked() )
1912  return false;
1913  }
1914 
1915  // Check render mode (from the Items tab) first
1916  switch( pad->GetAttribute() )
1917  {
1918  case PAD_ATTRIB_STANDARD:
1920  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1921  return false;
1922  break;
1923 
1924  case PAD_ATTRIB_CONN:
1925  case PAD_ATTRIB_SMD:
1926  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1927  return false;
1928  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1929  return false;
1930  break;
1931  }
1932 
1933  // Otherwise, pads are selectable if any draw layer is visible
1934  return ( pad->GetLayerSet() & board()->GetVisibleLayers() ).any();
1935  }
1936 
1937  break;
1938  }
1939 
1940  case PCB_GROUP_T:
1941  {
1942  PCB_GROUP* group = const_cast<PCB_GROUP*>( static_cast<const PCB_GROUP*>( aItem ) );
1943 
1944  // Similar to logic for module, a group is selectable if any of its
1945  // members are. (This recurses)
1946  for( auto item : group->GetItems() )
1947  {
1948  if( Selectable( item, true ) )
1949  return true;
1950  }
1951 
1952  return false;
1953  }
1954 
1955  case PCB_MARKER_T: // Always selectable
1956  return true;
1957 
1958  // These are not selectable
1959  case NOT_USED:
1960  case TYPE_NOT_INIT:
1961  return false;
1962 
1963  default: // Suppress warnings
1964  break;
1965  }
1966 
1967  // All other items are selected only if the layer on which they exist is visible
1968  return board()->IsLayerVisible( aItem->GetLayer() )
1969  && aItem->ViewGetLOD( aItem->GetLayer(), view() ) < view()->GetScale();
1970 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
BOARD * board() const
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
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,...
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
virtual unsigned int ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:141
the 3d code uses this value
Definition: typeinfo.h:80
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
PADS & Pads()
Definition: class_module.h:174
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:184
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_zone.cpp:287
class MODULE, a footprint
Definition: typeinfo.h:89
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1517
KIGFX::PCB_VIEW * view() const
const std::set< unsigned int > GetActiveLayers() const
Function GetActiveLayers() Returns the set of currently active layers.
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:82
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
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
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
smd pads, front layer
Meta control for all vias opacity/visibility.
MODULE * module() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
MODULE_ZONE_CONTAINERS & Zones()
Definition: class_module.h:194
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
double GetScale() const
Function GetScale()
Definition: view.h:257
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:856
const BOARD_ITEM_SET & GetItems() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References B_Cu, PCB_TOOL_BASE::board(), F_Cu, KIGFX::RENDER_SETTINGS::GetActiveLayers(), KIGFX::RENDER_SETTINGS::GetHighContrast(), PCB_GROUP::GetItems(), BOARD_ITEM::GetLayer(), ZONE_CONTAINER::GetLayerSet(), VIA::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), MODULE::GraphicalItems(), BOARD::IsElementVisible(), BOARD::IsLayerVisible(), KIGFX::VIEW::IsVisible(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIAS, PCB_TOOL_BASE::m_editModules, m_multiple, PCB_TOOL_BASE::module(), NOT_USED, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, MODULE::Pads(), PCB_ARC_T, PCB_GROUP_T, PCB_MARKER_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_MODULE_ZONE_AREA_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, ToLAYER_ID(), EDA_ITEM::Type(), TYPE_NOT_INIT, PCB_TOOL_BASE::view(), KIGFX::VIEW_ITEM::ViewGetLOD(), and MODULE::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 806 of file selection_tool.cpp.

807 {
808  KIGFX::VIEW* view = getView();
809 
810  // hold all visible items
811  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
812 
813  // Filter the view items based on the selection box
814  BOX2I selectionBox;
815 
816  selectionBox.SetMaximum();
817  view->Query( selectionBox, selectedItems ); // Get the list of selected items
818 
819  for( auto& item_pair : selectedItems )
820  {
821  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( item_pair.first );
822 
823  if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
824  continue;
825 
826  select( item );
827  }
828 
829  return 0;
830 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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
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.
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:451
VIEW.
Definition: view.h:61

References TOOL_BASE::getView(), itemPassesFilter(), 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 1071 of file selection_tool.cpp.

1072 {
1073  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
1074  auto connectivity = board()->GetConnectivity();
1075 
1076  for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
1077  if( itemPassesFilter( item ) )
1078  aSelect ? select( item ) : unselect( item );
1079 }
BOARD * board() const
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
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:339
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_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 1117 of file selection_tool.cpp.

1118 {
1119  std::list<MODULE*> modList;
1120 
1121  // store all modules that are on that sheet path
1122  for( MODULE* module : board()->Modules() )
1123  {
1124  if( module == nullptr )
1125  continue;
1126 
1127  wxString footprint_path = module->GetPath().AsString().BeforeLast('/');
1128 
1129  if( aSheetPath.IsEmpty() )
1130  aSheetPath += '/';
1131 
1132  if( footprint_path == aSheetPath )
1133  modList.push_back( module );
1134  }
1135 
1136  //Generate a list of all pads, and of all nets they belong to.
1137  std::list<int> netcodeList;
1138  std::list<D_PAD*> padList;
1139  for( MODULE* mmod : modList )
1140  {
1141  for( D_PAD* pad : mmod->Pads() )
1142  {
1143  if( pad->IsConnected() )
1144  {
1145  netcodeList.push_back( pad->GetNetCode() );
1146  padList.push_back( pad );
1147  }
1148  }
1149  }
1150  // remove all duplicates
1151  netcodeList.sort();
1152  netcodeList.unique();
1153 
1154  // auto select trivial connections segments which are launched from the pads
1155  std::list<TRACK*> launchTracks;
1156 
1157  for( D_PAD* pad : padList )
1159 
1160  // now we need to find all modules that are connected to each of these nets
1161  // then we need to determine if these modules are in the list of modules
1162  // belonging to this sheet ( modList )
1163  std::list<int> removeCodeList;
1164  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1165 
1166  for( int netCode : netcodeList )
1167  {
1168  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1169  {
1170  if( mitem->Type() == PCB_PAD_T)
1171  {
1172  bool found = std::find( modList.begin(), modList.end(), mitem->GetParent() ) != modList.end();
1173 
1174  if( !found )
1175  {
1176  // if we cannot find the module of the pad in the modList
1177  // then we can assume that that module is not located in the same
1178  // schematic, therefore invalidate this netcode.
1179  removeCodeList.push_back( netCode );
1180  break;
1181  }
1182  }
1183  }
1184  }
1185 
1186  // remove all duplicates
1187  removeCodeList.sort();
1188  removeCodeList.unique();
1189 
1190  for( int removeCode : removeCodeList )
1191  {
1192  netcodeList.remove( removeCode );
1193  }
1194 
1195  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1196  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
1197 
1198  for( int netCode : netcodeList )
1199  {
1200  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1201  localConnectionList.push_back( item );
1202  }
1203 
1204  for( BOARD_ITEM* i : modList )
1205  {
1206  if( i != NULL )
1207  select( i );
1208  }
1209 
1210  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1211  {
1212  if( i != NULL )
1213  select( i );
1214  }
1215 }
BOARD * board() const
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Select the entire net.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
const KIID_PATH & GetPath() const
Definition: class_module.h:230
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
#define NULL
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Selects connecteed tracks and vias.
MODULE * module() const
wxString AsString() const
Definition: common.h:137
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

References KIID_PATH::AsString(), PCB_TOOL_BASE::board(), EOT, MODULE::GetPath(), PCB_TOOL_BASE::module(), NULL, 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 955 of file selection_tool.cpp.

957 {
958  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT };
959 
960  auto connectivity = board()->GetConnectivity();
961  auto connectedItems = connectivity->GetConnectedItems( &aStartItem, types );
962 
963  std::map<wxPoint, std::vector<TRACK*>> trackMap;
964  std::map<wxPoint, VIA*> viaMap;
965  std::map<wxPoint, D_PAD*> padMap;
966 
967  // Build maps of connected items
968  for( BOARD_CONNECTED_ITEM* item : connectedItems )
969  {
970  switch( item->Type() )
971  {
972  case PCB_TRACE_T:
973  {
974  TRACK* track = static_cast<TRACK*>( item );
975  trackMap[ track->GetStart() ].push_back( track );
976  trackMap[ track->GetEnd() ].push_back( track );
977  }
978  break;
979 
980  case PCB_VIA_T:
981  {
982  VIA* via = static_cast<VIA*>( item );
983  viaMap[ via->GetStart() ] = via;
984  }
985  break;
986 
987  case PCB_PAD_T:
988  {
989  D_PAD* pad = static_cast<D_PAD*>( item );
990  padMap[ pad->GetPosition() ] = pad;
991  }
992  break;
993 
994  default:
995  break;
996  }
997 
998  item->SetState( SKIP_STRUCT, false );
999  }
1000 
1001  std::vector<wxPoint> activePts;
1002 
1003  // Set up the initial active points
1004  switch( aStartItem.Type() )
1005  {
1006  case PCB_TRACE_T:
1007  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
1008  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetEnd() );
1009  break;
1010 
1011  case PCB_VIA_T:
1012  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
1013  break;
1014 
1015  case PCB_PAD_T:
1016  activePts.push_back( aStartItem.GetPosition() );
1017  break;
1018 
1019  default:
1020  break;
1021  }
1022 
1023  bool expand = true;
1024 
1025  // Iterative push from all active points
1026  while( expand )
1027  {
1028  expand = false;
1029 
1030  for( int i = activePts.size() - 1; i >= 0; --i )
1031  {
1032  wxPoint pt = activePts[i];
1033 
1034  if( trackMap[ pt ].size() > 2 && aStopCondition == STOP_AT_JUNCTION )
1035  {
1036  activePts.erase( activePts.begin() + i );
1037  continue;
1038  }
1039 
1040  if( padMap.count( pt ) && aStopCondition != STOP_NEVER )
1041  {
1042  activePts.erase( activePts.begin() + i );
1043  continue;
1044  }
1045 
1046  for( TRACK* track : trackMap[ pt ] )
1047  {
1048  if( track->GetState( SKIP_STRUCT ) )
1049  continue;
1050 
1051  track->SetState( SKIP_STRUCT, true );
1052  select( track );
1053 
1054  if( track->GetStart() == pt )
1055  activePts.push_back( track->GetEnd() );
1056  else
1057  activePts.push_back( track->GetStart() );
1058 
1059  expand = true;
1060  }
1061 
1062  if( viaMap.count( pt ) && !viaMap[ pt ]->IsSelected() )
1063  select( viaMap[ pt ] );
1064 
1065  activePts.erase( activePts.begin() + i );
1066  }
1067  }
1068 }
BOARD * board() const
wxPoint GetPosition() const override
Definition: class_pad.h:165
const wxPoint & GetStart() const
Definition: class_track.h:116
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
Select the entire net.
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_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
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:339
void SetState(int type, int state)
Definition: base_struct.h:221
const wxPoint & GetEnd() const
Definition: class_track.h:113
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
int GetState(int type) const
Definition: base_struct.h:216

References PCB_TOOL_BASE::board(), EOT, BOARD::GetConnectivity(), TRACK::GetEnd(), D_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 585 of file selection_tool.cpp.

586 {
587  if( aForceSelect || m_selection.Empty() )
588  {
589  ClearSelection( true /*quiet mode*/ );
590  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
591  }
592 
593  return !m_selection.Empty();
594 }
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:121
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 279 of file pcb_tool_base.cpp.

280 {
281  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
282  const auto& selection = selTool->GetSelection();
283  return selection;
284 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const PCBNEW_SELECTION & selection() const

References 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(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), filterSelection(), EDIT_TOOL::Flip(), DRAWING_TOOL::getSourceZoneForAction(), PCB_EDITOR_CONTROL::GroupEnterSelected(), PCB_EDITOR_CONTROL::GroupFlattenSelected(), PCB_EDITOR_CONTROL::GroupMergeSelected(), PCB_EDITOR_CONTROL::GroupRemoveItemsSelected(), PCB_EDITOR_CONTROL::GroupSelected(), PCB_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::InspectClearance(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), 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(), GLOBAL_EDIT_TOOL::RemoveUnusedPads(), EDIT_TOOL::Rotate(), PCB_TOOL_BASE::selection(), selectNet(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCB_EDITOR_CONTROL::UngroupSelected(), 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 287 of file pcb_tool_base.cpp.

288 {
289  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
290  auto& selection = selTool->GetSelection();
291  return selection;
292 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const PCBNEW_SELECTION & selection() const

References TOOL_MANAGER::GetTool(), TOOL_BASE::m_toolMgr, and PCB_TOOL_BASE::selection().

◆ 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 2095 of file selection_tool.cpp.

2096 {
2097  const unsigned GRIP_MARGIN = 20;
2098  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
2099 
2100  // Check if the point is located within any of the currently selected items bounding boxes
2101  for( auto item : m_selection )
2102  {
2103  BOX2I itemBox = item->ViewBBox();
2104  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
2105 
2106  if( itemBox.Contains( aPoint ) )
2107  return true;
2108  }
2109 
2110  return false;
2111 }
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:474
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 1594 of file selection_tool.cpp.

1595 {
1596  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1597 
1598  doSelectionMenu( collector, wxEmptyString );
1599 
1600  return 0;
1601 }
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:240
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 799 of file selection_tool.cpp.

800 {
801  AddItemToSel( aEvent.Parameter<BOARD_ITEM*>() );
802  return 0;
803 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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 782 of file selection_tool.cpp.

783 {
784  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
785 
786  if( items )
787  {
788  // Perform individual selection of each item before processing the event.
789  for( auto item : *items )
790  select( item );
791 
793  }
794 
795  return 0;
796 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
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 597 of file selection_tool.cpp.

598 {
599  bool cancelled = false; // Was the tool cancelled while it was running?
600  m_multiple = true; // Multiple selection mode is active
601  KIGFX::VIEW* view = getView();
602 
604  view->Add( &area );
605 
606  bool anyAdded = false;
607  bool anySubtracted = false;
608 
609  while( TOOL_EVENT* evt = Wait() )
610  {
611  if( evt->IsCancelInteractive() || evt->IsActivate() )
612  {
613  cancelled = true;
614  break;
615  }
616 
617  if( evt->IsDrag( BUT_LEFT ) )
618  {
620  {
621  if( m_selection.GetSize() > 0 )
622  {
623  anySubtracted = true;
624  ClearSelection( true /*quiet mode*/ );
625  }
626  }
627 
628  // Start drawing a selection box
629  area.SetOrigin( evt->DragOrigin() );
630  area.SetEnd( evt->Position() );
631  area.SetAdditive( m_additive );
634 
635  view->SetVisible( &area, true );
636  view->Update( &area );
637  getViewControls()->SetAutoPan( true );
638  }
639 
640  if( evt->IsMouseUp( BUT_LEFT ) )
641  {
642  getViewControls()->SetAutoPan( false );
643 
644  // End drawing the selection box
645  view->SetVisible( &area, false );
646 
647  // Mark items within the selection box as selected
648  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
649 
650  // Filter the view items based on the selection box
651  BOX2I selectionBox = area.ViewBBox();
652  view->Query( selectionBox, selectedItems ); // Get the list of selected items
653 
654  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
655 
656  int width = area.GetEnd().x - area.GetOrigin().x;
657  int height = area.GetEnd().y - area.GetOrigin().y;
658 
659  /* Selection mode depends on direction of drag-selection:
660  * Left > Right : Select objects that are fully enclosed by selection
661  * Right > Left : Select objects that are crossed by selection
662  */
663  bool windowSelection = width >= 0 ? true : false;
664 
665  if( view->IsMirroredX() )
666  windowSelection = !windowSelection;
667 
668  // Construct an EDA_RECT to determine BOARD_ITEM selection
669  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
670 
671  selectionRect.Normalize();
672 
673  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
674  {
675  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
676 
677  if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
678  continue;
679 
680  if( item->HitTest( selectionRect, windowSelection ) )
681  {
682  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
683  {
684  unselect( item );
685  anySubtracted = true;
686  }
687  else
688  {
689  select( item );
690  anyAdded = true;
691  }
692  }
693  }
694 
695  m_selection.SetIsHover( false );
696 
697  // Inform other potentially interested tools
698  if( anyAdded )
700  else if( anySubtracted )
702 
703  break; // Stop waiting for events
704  }
705  }
706 
707  getViewControls()->SetAutoPan( false );
708 
709  // Stop drawing the selection box
710  view->Remove( &area );
711  m_multiple = false; // Multiple selection mode is inactive
712 
713  if( !cancelled )
715 
716  return cancelled;
717 }
void ClearReferencePoint()
Definition: selection.h:250
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
bool IsSelected() const
Definition: base_struct.h:203
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetOrigin(VECTOR2I aOrigin)
Set the origin of the rectange (the fixed corner)
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.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
bool itemPassesFilter(BOARD_ITEM *aItem)
Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
void SetIsHover(bool aIsHover)
Definition: selection.h:66
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: base_struct.h:307
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
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:230
void SetSubtractive(bool aSubtractive)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
void Normalize()
Function Normalize ensures that the height ant width are positive.
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
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
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1477
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:451
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VIEW.
Definition: view.h:61

References KIGFX::PCB_VIEW::Add(), BUT_LEFT, SELECTION::ClearReferencePoint(), ClearSelection(), 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(), itemPassesFilter(), m_additive, m_exclusive_or, m_multiple, m_selection, m_subtractive, TOOL_BASE::m_toolMgr, EDA_RECT::Normalize(), TOOL_MANAGER::ProcessEvent(), KIGFX::VIEW::Query(), KIGFX::PCB_VIEW::Remove(), select(), Selectable(), EVENTS::SelectedEvent, KIGFX::PREVIEW::SELECTION_AREA::SetAdditive(), KIGFX::VIEW_CONTROLS::SetAutoPan(), 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(), 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 1082 of file selection_tool.cpp.

1083 {
1084  bool select = aEvent.IsAction( &PCB_ACTIONS::selectNet );
1085 
1086  // If we've been passed an argument, just select that netcode1
1087  int netcode = aEvent.Parameter<intptr_t>();
1088 
1089  if( netcode > 0 )
1090  {
1091  selectAllItemsOnNet( netcode, select );
1092  return 0;
1093  }
1094 
1095  if( !selectCursor() )
1096  return 0;
1097 
1098  // copy the selection, since we're going to iterate and modify
1099  auto selection = m_selection.GetItems();
1100 
1101  for( EDA_ITEM* i : selection )
1102  {
1103  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
1104 
1105  if( connItem )
1106  selectAllItemsOnNet( connItem->GetNetCode(), select );
1107  }
1108 
1109  // Inform other potentially interested tools
1110  if( m_selection.Size() > 0 )
1112 
1113  return 0;
1114 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
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:132
int Size() const
Returns the number of selected parts.
Definition: selection.h:127
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159

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

486 {
488  GENERAL_COLLECTOR collector;
489  auto& displayOpts = m_frame->GetDisplayOptions();
490 
491  guide.SetIgnoreZoneFills( displayOpts.m_ZoneDisplayMode != ZONE_DISPLAY_MODE::SHOW_FILLED );
492 
493  if( m_enteredGroup &&
494  !m_enteredGroup->GetBoundingBox().Contains( wxPoint( aWhere.x, aWhere.y ) ) )
495  {
496  ExitGroup();
497  }
498 
499  collector.Collect( board(),
501  wxPoint( aWhere.x, aWhere.y ), guide );
502 
503  // Remove unselectable items
504  for( int i = collector.GetCount() - 1; i >= 0; --i )
505  {
506  if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
507  collector.Remove( i );
508  }
509 
511 
512  // Allow the client to do tool- or action-specific filtering to see if we
513  // can get down to a single item
514  if( aClientFilter )
515  aClientFilter( aWhere, collector, this );
516 
517  // Apply the stateful filter
518  filterCollectedItems( collector );
519 
520  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
521  if( collector.GetCount() > 1 && !m_skip_heuristics )
522  {
523  GuessSelectionCandidates( collector, aWhere );
524  }
525 
526  // If still more than one item we're going to have to ask the user.
527  if( collector.GetCount() > 1 )
528  {
529  if( aOnDrag )
531 
532  if( !doSelectionMenu( &collector, wxEmptyString ) )
533  {
534  if( aSelectionCancelledFlag )
535  *aSelectionCancelledFlag = true;
536 
537  return false;
538  }
539  }
540 
541  bool anyAdded = false;
542  bool anySubtracted = false;
543 
545  {
546  if( m_selection.GetSize() > 0 )
547  {
548  ClearSelection( true /*quiet mode*/ );
549  anySubtracted = true;
550  }
551  }
552 
553  if( collector.GetCount() > 0 )
554  {
555  for( int i = 0; i < collector.GetCount(); ++i )
556  {
557  if( m_subtractive || ( m_exclusive_or && collector[i]->IsSelected() ) )
558  {
559  unselect( collector[i] );
560  anySubtracted = true;
561  }
562  else
563  {
564  select( collector[i] );
565  anyAdded = true;
566  }
567  }
568  }
569 
570  if( anyAdded )
571  {
573  return true;
574  }
575  else if( anySubtracted )
576  {
578  return true;
579  }
580 
581  return false;
582 }
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
void ClearReferencePoint()
Definition: selection.h:250
Filled polygons are shown.
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
BOARD * board() const
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:574
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
PCBNEW_SELECTION m_selection
const EDA_RECT GetBoundingBox() const override
PCB_GROUP * m_enteredGroup
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions Display options control the way tracks, vias, outlines and other things ar...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool Contains(const wxPoint &aPoint) const
Function Contains.
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:130
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
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
PCB_BASE_FRAME * m_frame
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
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:240
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
bool doSelectionMenu(GENERAL_COLLECTOR *aItems, const wxString &aTitle)
Allows the selection of a single item from a list via pop-up menu.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:390
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:615
void filterCollectedItems(GENERAL_COLLECTOR &aCollector)
Applies the SELECTION_FILTER_OPTIONS to a collection of items

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), BUT_LEFT, SELECTION::ClearReferencePoint(), ClearSelection(), GENERAL_COLLECTOR::Collect(), EDA_RECT::Contains(), doSelectionMenu(), ExitGroup(), filterCollectedItems(), PCB_GROUP::GetBoundingBox(), getCollectorsGuide(), COLLECTOR::GetCount(), PCB_BASE_FRAME::GetDisplayOptions(), SELECTION::GetSize(), GuessSelectionCandidates(), m_additive, PCB_TOOL_BASE::m_editModules, m_enteredGroup, m_exclusive_or, m_frame, m_selection, m_skip_heuristics, m_subtractive, TOOL_BASE::m_toolMgr, GENERAL_COLLECTOR::ModuleItems, TOOL_MANAGER::ProcessEvent(), COLLECTOR::Remove(), select(), Selectable(), EVENTS::SelectedEvent, GENERAL_COLLECTORS_GUIDE::SetIgnoreZoneFills(), SHOW_FILLED, TA_MOUSE_UP, TC_ANY, unselect(), EVENTS::UnselectedEvent, TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Main(), and selectCursor().

◆ selectSameSheet()

int SELECTION_TOOL::selectSameSheet ( const TOOL_EVENT aEvent)
private

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

Definition at line 1258 of file selection_tool.cpp.

1259 {
1260  if( !selectCursor( true ) )
1261  return 0;
1262 
1263  // this function currently only supports modules since they are only
1264  // on one sheet.
1265  auto item = m_selection.Front();
1266 
1267  if( !item )
1268  return 0;
1269 
1270  if( item->Type() != PCB_MODULE_T )
1271  return 0;
1272 
1273  auto mod = dynamic_cast<MODULE*>( item );
1274 
1275  if( mod->GetPath().empty() )
1276  return 0;
1277 
1278  ClearSelection( true /*quiet mode*/ );
1279