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 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)
 
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...
 
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)
 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 select (BOARD_ITEM *aItem)
 Function select() Takes necessary action mark an item as selected. 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
 

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
 
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 83 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 247 of file selection_tool.h.

248  {
256  STOP_AT_PAD,
258  STOP_NEVER
259  };
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 112 of file selection_tool.cpp.

112  :
113  PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
114  m_frame( NULL ),
115  m_additive( false ),
116  m_subtractive( false ),
117  m_exclusive_or( false ),
118  m_multiple( false ),
119  m_skip_heuristics( false ),
120  m_locked( true ),
121  m_priv( std::make_unique<PRIV>() )
122 {
123  m_filter.lockedItems = true;
124  m_filter.footprints = true;
125  m_filter.text = true;
126  m_filter.tracks = true;
127  m_filter.vias = true;
128  m_filter.pads = true;
129  m_filter.graphics = true;
130  m_filter.zones = true;
131  m_filter.keepouts = true;
132  m_filter.dimensions = true;
133  m_filter.otherItems = true;
134 }
bool otherItems
Anything not fitting one of the above categories.
std::unique_ptr< PRIV > m_priv
bool text
Text (free or attached to a footprint)
#define NULL
bool dimensions
Dimension items.
bool keepouts
Keepout zones.
bool graphics
Graphic lines, shapes, polygons.
PCB_BASE_FRAME * m_frame
bool tracks
Copper tracks.
bool zones
Copper zones.
bool footprints
Allow selecting entire footprints.
bool pads
Footprint pads.
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:75
bool vias
Vias (all types>
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 137 of file selection_tool.cpp.

138 {
139  getView()->Remove( &m_selection );
140 }
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
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(), 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(), EDIT_TOOL::Move(), 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::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 738 of file selection_tool.cpp.

739 {
740  if( aItem )
741  {
742  select( aItem );
743 
744  // Inform other potentially interested tools
745  if( !aQuietMode )
747  }
748 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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(), DRC::checkClearanceSegmToPad(), PCB_INSPECTION_TOOL::ClearHighlight(), DRAWING_TOOL::constrainDimension(), 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(), filterSelection(), getCollectorsGuide(), 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(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), Selectable(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), selectPoint(), PCBNEW_CONTROL::TrackDisplayMode(), POINT_EDITOR::updateItem(), 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 787 of file selection_tool.cpp.

788 {
789  highlight( aItem, BRIGHTENED );
790 }
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 652 of file selection_tool.cpp.

653 {
654  if( !m_locked || m_editModules )
655  return SELECTION_UNLOCKED;
656 
657  bool containsLocked = false;
658 
659  // Check if the selection contains locked items
660  for( const auto& item : m_selection )
661  {
662  switch( item->Type() )
663  {
664  case PCB_MODULE_T:
665  if( static_cast<MODULE*>( item )->IsLocked() )
666  containsLocked = true;
667  break;
668 
669  case PCB_MODULE_EDGE_T:
670  case PCB_MODULE_TEXT_T:
672  if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
673  containsLocked = true;
674  break;
675 
676  default: // suppress warnings
677  break;
678  }
679  }
680 
681  if( containsLocked )
682  {
683  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
684  {
685  m_locked = false;
687  }
688  else
689  return SELECTION_LOCKED;
690  }
691 
692  return SELECTION_UNLOCKED;
693 }
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::Move(), and RequestSelection().

◆ ClearSelection() [1/2]

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 706 of file selection_tool.cpp.

707 {
708  ClearSelection();
709 
710  return 0;
711 }
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.

Referenced by filterSelection(), findCallback(), Main(), RequestSelection(), Reset(), selectCursor(), selectMultiple(), selectPoint(), selectSameSheet(), selectSheetContents(), and setTransitions().

◆ ClearSelection() [2/2]

void SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Definition at line 1421 of file selection_tool.cpp.

1422 {
1423  if( m_selection.Empty() )
1424  return;
1425 
1426  while( m_selection.GetSize() )
1427  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1428 
1429  view()->Update( &m_selection );
1430 
1431  m_selection.SetIsHover( false );
1433 
1434  m_locked = true;
1435 
1436  // Inform other potentially interested tools
1437  if( !aQuietMode )
1438  {
1441  }
1442 }
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:91
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:204
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:418
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 696 of file selection_tool.cpp.

697 {
699 
700  selectCursor( false, aClientFilter );
701 
702  return 0;
703 }
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &)
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

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

Referenced by setTransitions().

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

Definition at line 264 of file pcb_tool_base.cpp.

265 {
266  return frame()->GetDisplayOptions();
267 }
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions Display options control the way tracks, vias, outlines and other things ar...
PCB_BASE_EDIT_FRAME * frame() const

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

Referenced by PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), PCBNEW_CONTROL::HighContrastMode(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PNS::TOOL_BASE::pickSingleItem(), PCBNEW_CONTROL::ToggleRatsnest(), PCBNEW_CONTROL::TrackDisplayMode(), PCBNEW_CONTROL::ViaDisplayMode(), and PCBNEW_CONTROL::ZoneDisplayMode().

◆ doInteractiveItemPlacement()

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

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

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

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

Definition at line 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  controls()->SetSnapping( true );
54 
55  // Add a VIEW_GROUP that serves as a preview for the new item
56  PCBNEW_SELECTION preview;
57  view()->Add( &preview );
58 
59  aPlacer->m_board = board();
60  aPlacer->m_frame = frame();
61  aPlacer->m_modifiers = 0;
62 
63  auto makeNewItem = [&] ( VECTOR2I aPosition )
64  {
65  if( frame()->GetModel() )
66  newItem = aPlacer->CreateItem();
67 
68  if( newItem )
69  {
70  newItem->SetPosition( (wxPoint) aPosition );
71  preview.Add( newItem.get() );
72 
73  if( newItem->Type() == PCB_MODULE_T )
74  {
75  auto module = dyn_cast<MODULE*>( newItem.get() );
76 
77  // modules have more drawable parts
78  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
79  }
80  }
81  };
82 
83  if( aOptions & IPO_SINGLE_CLICK )
84  makeNewItem( controls()->GetCursorPosition() );
85 
86  // Main loop: keep receiving events
87  while( TOOL_EVENT* evt = Wait() )
88  {
89  if( !newItem )
90  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
91  else
92  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
93 
94  VECTOR2I cursorPos = controls()->GetCursorPosition();
95  aPlacer->m_modifiers = evt->Modifier();
96 
97  auto cleanup = [&] ()
98  {
99  newItem = nullptr;
100  preview.Clear();
101  view()->Update( &preview );
102  controls()->SetAutoPan( false );
103  controls()->CaptureCursor( false );
104  controls()->ShowCursor( true );
105  };
106 
107  if( evt->IsCancelInteractive() )
108  {
109  if( aOptions & IPO_SINGLE_CLICK )
110  {
111  cleanup();
112  frame()->PopTool( aTool );
113  break;
114  }
115  else if( newItem )
116  cleanup();
117  else
118  {
119  frame()->PopTool( aTool );
120  break;
121  }
122  }
123  else if( evt->IsActivate() )
124  {
125  if( newItem )
126  cleanup();
127 
128  if( evt->IsPointEditor() )
129  {
130  // don't exit (the point editor runs in the background)
131  }
132  else if( evt->IsMoveTool() )
133  {
134  // leave ourselves on the stack so we come back after the move
135  break;
136  }
137  else
138  {
139  frame()->PopTool( aTool );
140  break;
141  }
142  }
143  else if( evt->IsClick( BUT_LEFT ) )
144  {
145  if( !newItem )
146  {
147  // create the item if possible
148  makeNewItem( cursorPos );
149 
150  // no item created, so wait for another click
151  if( !newItem )
152  continue;
153 
154  controls()->CaptureCursor( true );
155  controls()->SetAutoPan( true );
156  }
157  else
158  {
159  auto oldFlags = newItem->GetFlags();
160  newItem->ClearFlags();
161 
162  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
163  {
164  newItem->SetFlags( oldFlags );
165  continue;
166  }
167 
168  preview.Clear();
169  newItem.release();
170  commit.Push( aCommitMessage );
171 
172  controls()->CaptureCursor( false );
173  controls()->SetAutoPan( false );
174  controls()->ShowCursor( true );
175 
176  if( !( aOptions & IPO_REPEAT ) )
177  break;
178 
179  if( aOptions & IPO_SINGLE_CLICK )
180  makeNewItem( controls()->GetCursorPosition() );
181  }
182  }
183  else if( evt->IsClick( BUT_RIGHT ) )
184  {
186  }
187  else if( newItem && evt->Category() == TC_COMMAND )
188  {
189  /*
190  * Handle any events that can affect the item as we move it around
191  */
192  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
193  {
194  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
195  newItem->Rotate( newItem->GetPosition(), rotationAngle );
196  view()->Update( &preview );
197  }
198  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
199  {
200  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
201  view()->Update( &preview );
202  }
203  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
204  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
205  {
206  // Refresh preview after event runs
208  }
209  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
210  {
211  preview.Clear();
212  newItem.release();
213 
214  makeNewItem( controls()->GetCursorPosition() );
215  view()->Update( &preview );
216  }
217  }
218 
219  else if( newItem && evt->IsMotion() )
220  {
221  // track the cursor
222  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
223  aPlacer->SnapItem( newItem.get() );
224 
225  // Show a preview of the item
226  view()->Update( &preview );
227  }
228 
229  else
230  evt->SetPassEvent();
231  }
232 
233  view()->Remove( &preview );
234 }
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:91
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:279
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.
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
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:74
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:100
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:58
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:280
static TOOL_ACTION refreshPreview
Definition: actions.h:101
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(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, KIGFX::PCB_VIEW::Update(), PCB_ACTIONS::viaSizeDec, PCB_ACTIONS::viaSizeInc, PCB_TOOL_BASE::view(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

Definition at line 1480 of file selection_tool.cpp.

1481 {
1482  BOARD_ITEM* current = nullptr;
1483  PCBNEW_SELECTION highlightGroup;
1484  ACTION_MENU menu( true );
1485  bool selectAll = false;
1486 
1487  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1488  getView()->Add( &highlightGroup );
1489 
1490  int limit = std::min( 9, aCollector->GetCount() );
1491 
1492  for( int i = 0; i < limit; ++i )
1493  {
1494  wxString text;
1495  BOARD_ITEM* item = ( *aCollector )[i];
1496  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1497 
1498  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1499  menu.Add( menuText, i + 1, item->GetMenuImage() );
1500  }
1501 
1502  menu.AppendSeparator();
1503  menu.Add( _( "Select &All\tA" ), limit + 1, net_highlight_xpm );
1504 
1505  if( aTitle.Length() )
1506  menu.SetTitle( aTitle );
1507 
1508  menu.SetIcon( info_xpm );
1509  menu.DisplayTitle( true );
1510  SetContextMenu( &menu, CMENU_NOW );
1511 
1512  while( TOOL_EVENT* evt = Wait() )
1513  {
1514  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1515  {
1516  if( selectAll )
1517  {
1518  for( int i = 0; i < aCollector->GetCount(); ++i )
1519  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1520  }
1521  else if( current )
1522  unhighlight( current, BRIGHTENED, &highlightGroup );
1523 
1524  int id = *evt->GetCommandId();
1525 
1526  // User has pointed an item, so show it in a different way
1527  if( id > 0 && id <= limit )
1528  {
1529  current = ( *aCollector )[id - 1];
1530  highlight( current, BRIGHTENED, &highlightGroup );
1531  }
1532  else
1533  current = nullptr;
1534 
1535  // User has pointed on the "Select All" option
1536  if( id == limit + 1 )
1537  {
1538  for( int i = 0; i < aCollector->GetCount(); ++i )
1539  highlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1540  selectAll = true;
1541  }
1542  else
1543  selectAll = false;
1544  }
1545  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1546  {
1547  if( selectAll )
1548  {
1549  for( int i = 0; i < aCollector->GetCount(); ++i )
1550  unhighlight( ( *aCollector )[i], BRIGHTENED, &highlightGroup );
1551  }
1552  else if( current )
1553  unhighlight( current, BRIGHTENED, &highlightGroup );
1554 
1555  OPT<int> id = evt->GetCommandId();
1556 
1557  // User has selected the "Select All" option
1558  if( id == limit + 1 )
1559  {
1560  selectAll = true;
1561  current = nullptr;
1562  }
1563  // User has selected an item, so this one will be returned
1564  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1565  {
1566  selectAll = false;
1567  current = ( *aCollector )[*id - 1];
1568  }
1569  else
1570  {
1571  selectAll = false;
1572  current = nullptr;
1573  }
1574 
1575  break;
1576  }
1577  }
1578  getView()->Remove( &highlightGroup );
1579 
1580  if( selectAll )
1581  return true;
1582  else if( current )
1583  {
1584  aCollector->Empty();
1585  aCollector->Append( current );
1586  return true;
1587  }
1588 
1589  return false;
1590 }
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
ACTION_MENU.
Definition: action_menu.h:44
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:376
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:205
#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:346
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 _, ACTION_MENU::Add(), KIGFX::VIEW::Add(), COLLECTOR::Append(), BRIGHTENED, CMENU_NOW, ACTION_MENU::DisplayTitle(), COLLECTOR::Empty(), Format(), COLLECTOR::GetCount(), EDA_ITEM::GetMenuImage(), EDA_ITEM::GetSelectMenuText(), EDA_BASE_FRAME::GetUserUnits(), TOOL_BASE::getView(), highlight(), info_xpm, LAYER_SELECT_OVERLAY, m_frame, net_highlight_xpm, KIGFX::VIEW::Remove(), TOOL_INTERACTIVE::SetContextMenu(), ACTION_MENU::SetIcon(), KIGFX::VIEW_GROUP::SetLayer(), ACTION_MENU::SetTitle(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, unhighlight(), and TOOL_INTERACTIVE::Wait().

Referenced by SelectionMenu(), and selectPoint().

◆ EditingModules()

bool PCB_TOOL_BASE::EditingModules ( ) const
inlineinherited

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

819 {
820  unsigned initialCount = 0;
821 
822  for( auto item : m_selection.GetItems() )
823  {
824  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
825  initialCount++;
826  }
827 
828  if( initialCount == 0 )
830 
831  for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
832  {
833  // copy the selection, since we're going to iterate and modify
834  std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
835 
836  for( EDA_ITEM* item : selectedItems )
837  item->ClearTempFlags();
838 
839  for( EDA_ITEM* item : selectedItems )
840  {
841  TRACK* trackItem = dynamic_cast<TRACK*>( item );
842 
843  // Track items marked SKIP_STRUCT have already been visited
844  if( trackItem && !( trackItem->GetFlags() & SKIP_STRUCT ) )
845  selectConnectedTracks( *trackItem, stopCondition );
846  }
847 
848  if( m_selection.GetItems().size() > initialCount )
849  break;
850  }
851 
852  // Inform other potentially interested tools
853  if( m_selection.Size() > 0 )
855 
856  return 0;
857 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
#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).
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:132
Stop when reaching a pad.
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 1328 of file selection_tool.cpp.

1329 {
1330  if( aCollector.GetCount() == 0 )
1331  return;
1332 
1333  std::set<BOARD_ITEM*> rejected;
1334 
1335  for( EDA_ITEM* i : aCollector )
1336  {
1337  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1338 
1339  if( !itemPassesFilter( item ) )
1340  rejected.insert( item );
1341  }
1342 
1343  for( BOARD_ITEM* item : rejected )
1344  aCollector.Remove( item );
1345 }
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:100
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().

◆ filterSelection()

int SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection

Definition at line 1296 of file selection_tool.cpp.

1297 {
1298  const BOARD& board = *getModel<BOARD>();
1299  DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
1300  DIALOG_FILTER_SELECTION dlg( m_frame, opts );
1301 
1302  const int cmd = dlg.ShowModal();
1303 
1304  if( cmd != wxID_OK )
1305  return 0;
1306 
1307  // copy current selection
1308  std::deque<EDA_ITEM*> selection = m_selection.GetItems();
1309 
1310  ClearSelection( true /*quiet mode*/ );
1311 
1312  // re-select items from the saved selection according to the dialog options
1313  for( EDA_ITEM* i : selection )
1314  {
1315  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1316  bool include = itemIsIncludedByFilter( *item, board, opts );
1317 
1318  if( include )
1319  select( item );
1320  }
1321 
1323 
1324  return 0;
1325 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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:180
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 1212 of file selection_tool.cpp.

1213 {
1214  DIALOG_FIND dlg( m_frame );
1215  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1216  dlg.ShowModal();
1217 
1218  return 0;
1219 }
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 1183 of file selection_tool.cpp.

1184 {
1185  bool cleared = false;
1186 
1187  if( m_selection.GetSize() > 0 )
1188  {
1189  // Don't fire an event now; most of the time it will be redundant as we're about to
1190  // fire a SelectedEvent.
1191  cleared = true;
1192  ClearSelection( true /*quiet mode*/ );
1193  }
1194 
1195  if( aItem )
1196  {
1197  select( aItem );
1198  m_frame->FocusOnLocation( aItem->GetPosition() );
1199 
1200  // Inform other potentially interested tools
1202  }
1203  else if( cleared )
1204  {
1206  }
1207 
1209 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
virtual const wxPoint GetPosition() const
Definition: base_struct.h:337
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:204
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(), EDIT_TOOL::Init(), Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCBNEW_PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::Move(), 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::pickCopyReferencePoint(), 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(), POINT_EDITOR::updateItem(), PCB_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 396 of file selection_tool.cpp.

397 {
398  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
399  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
400 
401  // account for the globals
402  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
403  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
404  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
405  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
406  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
407  guide.SetIgnorePadsOnBack( ! board()->IsElementVisible( LAYER_PAD_BK ) );
408  guide.SetIgnorePadsOnFront( ! board()->IsElementVisible( LAYER_PAD_FR ) );
409  guide.SetIgnoreThroughHolePads( ! board()->IsElementVisible( LAYER_PADS_TH ) );
410  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
411  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
412  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIA_THROUGH ) );
413  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIA_BBLIND ) );
414  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIA_MICROVIA ) );
415  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
416 
417  return guide;
418 }
to draw blind/buried vias
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:
to draw usual through hole vias
KIGFX::PCB_VIEW * view() const
smd pads, front layer
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:385
show modules references (when texts are visibles)

References PCB_TOOL_BASE::board(), 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_TH, LAYER_TRACKS, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_THROUGH, 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().

◆ GetFilter()

SELECTION_FILTER_OPTIONS& SELECTION_TOOL::GetFilter ( )
inline

Definition at line 179 of file selection_tool.h.

180  {
181  return m_filter;
182  }
SELECTION_FILTER_OPTIONS m_filter

References m_filter.

Referenced by PANEL_SELECTION_FILTER::OnFilterChanged().

◆ 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::createNewZone(), 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:284
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::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(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), Selectable(), 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(), PL_EDITOR_CONTROL::ToggleBackgroundColor(), 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(), COMMON_TOOLS::ZoomFitScreen(), 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:286

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), 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(), EDIT_TOOL::Move(), COMMON_TOOLS::OnGridChanged(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), 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(), 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(), ROUTER_TOOL::setTransitions(), LIB_PIN_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), PL_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), SCH_MOVE_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), POINT_EDITOR::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), LIB_CONTROL::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(), COMMON_TOOLS::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), DRC::setTransitions(), EDIT_TOOL::setTransitions(), DRAWING_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 2094 of file selection_tool.cpp.

2096 {
2097  std::set<BOARD_ITEM*> preferred;
2098  std::set<BOARD_ITEM*> rejected;
2099  std::set<BOARD_ITEM*> forced;
2100  wxPoint where( aWhere.x, aWhere.y );
2101 
2102  // footprints which are below this percentage of the largest footprint will be considered
2103  // for selection; all others will not
2104  constexpr double footprintToFootprintMinRatio = 0.20;
2105  // pads which are below this percentage of their parent's area will exclude their parent
2106  constexpr double padToFootprintMinRatio = 0.45;
2107  // footprints containing items with items-to-footprint area ratio higher than this will be
2108  // forced to stay on the list
2109  constexpr double footprintMaxCoverRatio = 0.90;
2110  constexpr double viaToPadMinRatio = 0.50;
2111  constexpr double trackViaLengthRatio = 2.0;
2112  constexpr double trackTrackLengthRatio = 0.3;
2113  constexpr double textToFeatureMinRatio = 0.2;
2114  constexpr double textToFootprintMinRatio = 0.4;
2115  // If the common area of two compared items is above the following threshold, they cannot
2116  // be rejected (it means they overlap and it might be hard to pick one by selecting
2117  // its unique area).
2118  constexpr double commonAreaRatio = 0.6;
2119 
2120  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
2121  LSET silkLayers( 2, B_SilkS, F_SilkS );
2122 
2123  if( silkLayers[activeLayer] )
2124  {
2125  for( int i = 0; i < aCollector.GetCount(); ++i )
2126  {
2127  BOARD_ITEM* item = aCollector[i];
2128  KICAD_T type = item->Type();
2129 
2130  if( ( type == PCB_MODULE_TEXT_T || type == PCB_TEXT_T || type == PCB_LINE_T )
2131  && silkLayers[item->GetLayer()] )
2132  {
2133  preferred.insert( item );
2134  }
2135  }
2136 
2137  if( preferred.size() > 0 )
2138  {
2139  aCollector.Empty();
2140 
2141  for( BOARD_ITEM* item : preferred )
2142  aCollector.Append( item );
2143  return;
2144  }
2145  }
2146 
2147  // Zone edges are very specific; zone fills much less so.
2148  if( aCollector.CountType( PCB_ZONE_AREA_T ) > 0 )
2149  {
2150  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2151  {
2152  if( aCollector[i]->Type() == PCB_ZONE_AREA_T )
2153  {
2154  auto zone = static_cast<ZONE_CONTAINER*>( aCollector[i] );
2155 
2156  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
2157  preferred.insert( zone );
2158  else
2159  rejected.insert( zone );
2160  }
2161  }
2162 
2163  if( preferred.size() > 0 )
2164  {
2165  aCollector.Empty();
2166 
2167  for( BOARD_ITEM* item : preferred )
2168  aCollector.Append( item );
2169  return;
2170  }
2171  }
2172 
2173  if( aCollector.CountType( PCB_MODULE_TEXT_T ) > 0 )
2174  {
2175  for( int i = 0; i < aCollector.GetCount(); ++i )
2176  {
2177  if( TEXTE_MODULE* txt = dyn_cast<TEXTE_MODULE*>( aCollector[i] ) )
2178  {
2179  double textArea = calcArea( txt );
2180 
2181  for( int j = 0; j < aCollector.GetCount(); ++j )
2182  {
2183  if( i == j )
2184  continue;
2185 
2186  BOARD_ITEM* item = aCollector[j];
2187  double itemArea = calcArea( item );
2188  double areaRatio = calcRatio( textArea, itemArea );
2189  double commonArea = calcCommonArea( txt, item );
2190  double itemCommonRatio = calcRatio( commonArea, itemArea );
2191  double txtCommonRatio = calcRatio( commonArea, textArea );
2192 
2193  if( item->Type() == PCB_MODULE_T )
2194  {
2195  // when text area is small compared to an overlapping footprint,
2196  // then it's a clear sign the text is the selection target
2197  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
2198  rejected.insert( item );
2199  }
2200 
2201  switch( item->Type() )
2202  {
2203  case PCB_TRACE_T:
2204  case PCB_ARC_T:
2205  case PCB_PAD_T:
2206  case PCB_LINE_T:
2207  case PCB_VIA_T:
2208  case PCB_MODULE_T:
2209  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
2210  rejected.insert( txt );
2211  break;
2212  default:
2213  break;
2214  }
2215  }
2216  }
2217  }
2218  }
2219 
2220  if( aCollector.CountType( PCB_MODULE_EDGE_T ) + aCollector.CountType( PCB_LINE_T ) > 1 )
2221  {
2222  // Prefer exact hits to sloppy ones
2223  int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
2224  bool found = false;
2225 
2226  for( int dist = 0; dist < accuracy; ++dist )
2227  {
2228  for( int i = 0; i < aCollector.GetCount(); ++i )
2229  {
2230  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2231  {
2232  if( drawSegment->HitTest( where, dist ) )
2233  {
2234  found = true;
2235  break;
2236  }
2237  }
2238  }
2239 
2240  if( found )
2241  {
2242  // throw out everything that is more sloppy than what we found
2243  for( int i = 0; i < aCollector.GetCount(); ++i )
2244  {
2245  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2246  {
2247  if( !drawSegment->HitTest( where, dist ) )
2248  rejected.insert( drawSegment );
2249  }
2250  }
2251 
2252  // we're done now
2253  break;
2254  }
2255  }
2256  }
2257 
2258  if( aCollector.CountType( PCB_PAD_T ) > 0 )
2259  {
2260  for( int i = 0; i < aCollector.GetCount(); ++i )
2261  {
2262  if( D_PAD* pad = dyn_cast<D_PAD*>( aCollector[i] ) )
2263  {
2264  MODULE* parent = pad->GetParent();
2265  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
2266 
2267  // when pad area is small compared to the parent footprint,
2268  // then it is a clear sign the pad is the selection target
2269  if( ratio < padToFootprintMinRatio )
2270  rejected.insert( pad->GetParent() );
2271  }
2272  }
2273  }
2274 
2275  bool hasNonModules = false;
2276 
2277  for( int i = 0; i < aCollector.GetCount(); ++i )
2278  {
2279  if( aCollector[i]->Type() != PCB_MODULE_T )
2280  {
2281  hasNonModules = true;
2282  break;
2283  }
2284  }
2285 
2286  if( aCollector.CountType( PCB_MODULE_T ) > 0 )
2287  {
2288  double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
2289  BOX2D viewportD = getView()->GetViewport();
2290  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2291  double maxCoverRatio = footprintMaxCoverRatio;
2292 
2293  // MODULE::CoverageRatio() doesn't take zone handles & borders into account so just
2294  // use a more aggressive cutoff point if zones are involved.
2295  if( aCollector.CountType( PCB_ZONE_AREA_T ) )
2296  maxCoverRatio /= 2;
2297 
2298  for( int i = 0; i < aCollector.GetCount(); ++i )
2299  {
2300  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
2301  {
2302  // filter out components larger than the viewport
2303  if( mod->ViewBBox().Contains( viewport ) )
2304  rejected.insert( mod );
2305  // footprints completely covered with other features have no other
2306  // means of selection, so must be kept
2307  else if( mod->CoverageRatio( aCollector ) > maxCoverRatio )
2308  rejected.erase( mod );
2309  // if a footprint is much smaller than the largest overlapping
2310  // footprint then it should be considered for selection
2311  else if( calcRatio( calcArea( mod ), maxArea ) <= footprintToFootprintMinRatio )
2312  continue;
2313  // reject ALL OTHER footprints if there's still something else left
2314  // to select
2315  else if( hasNonModules )
2316  rejected.insert( mod );
2317  }
2318  }
2319  }
2320 
2321  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2322  {
2323  for( int i = 0; i < aCollector.GetCount(); ++i )
2324  {
2325  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2326  {
2327  double viaArea = calcArea( via );
2328 
2329  for( int j = 0; j < aCollector.GetCount(); ++j )
2330  {
2331  if( i == j )
2332  continue;
2333 
2334  BOARD_ITEM* item = aCollector[j];
2335  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2336 
2337  if( item->Type() == PCB_MODULE_T && areaRatio < padToFootprintMinRatio )
2338  rejected.insert( item );
2339 
2340  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2341  rejected.insert( item );
2342 
2343  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2344  {
2345  if( track->GetNetCode() != via->GetNetCode() )
2346  continue;
2347 
2348  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2349  (double) via->GetWidth();
2350 
2351  if( lenRatio > trackViaLengthRatio )
2352  rejected.insert( track );
2353  }
2354  }
2355  }
2356  }
2357  }
2358 
2359  int nTracks = aCollector.CountType( PCB_TRACE_T );
2360 
2361  if( nTracks > 0 )
2362  {
2363  double maxLength = 0.0;
2364  double minLength = std::numeric_limits<double>::max();
2365  double maxArea = 0.0;
2366  const TRACK* maxTrack = nullptr;
2367 
2368  for( int i = 0; i < aCollector.GetCount(); ++i )
2369  {
2370  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2371  {
2372  maxLength = std::max( track->GetLength(), maxLength );
2373  maxLength = std::max( (double) track->GetWidth(), maxLength );
2374 
2375  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2376 
2377  double area = track->GetLength() * track->GetWidth();
2378 
2379  if( area > maxArea )
2380  {
2381  maxArea = area;
2382  maxTrack = track;
2383  }
2384  }
2385  }
2386 
2387  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2388  {
2389  for( int i = 0; i < aCollector.GetCount(); ++i )
2390  {
2391  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2392  {
2393  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2394 
2395  if( ratio > trackTrackLengthRatio )
2396  rejected.insert( track );
2397  }
2398  }
2399  }
2400 
2401  for( int j = 0; j < aCollector.GetCount(); ++j )
2402  {
2403  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[j] ) )
2404  {
2405  double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() );
2406 
2407  if( ratio < padToFootprintMinRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio )
2408  rejected.insert( mod );
2409  }
2410  }
2411  }
2412 
2413  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2414  {
2415  for( BOARD_ITEM* item : rejected )
2416  {
2417  aCollector.Remove( item );
2418  }
2419  }
2420 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:109
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:538
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:102
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:347
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
int CountType(KICAD_T aType)
Function CountType counts the number of items matching aType.
Definition: collector.h:216
static double calcArea(const BOARD_ITEM *aItem)
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:129
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:119
double dist(const double ax, const double ay, const double bx, const double by)
Definition: delauney.h:168
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
class MODULE, a footprint
Definition: typeinfo.h:89
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:851
KIGFX::PCB_VIEW * view() const
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
const Vec & GetPosition() const
Definition: box2.h:193
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:188
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(), dist(), COLLECTOR::Empty(), F_SilkS, COLLECTOR::GetCount(), GENERAL_COLLECTOR::GetGuide(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetParent(), BOX2< Vec >::GetPosition(), BOX2< Vec >::GetSize(), KIGFX::VIEW::GetTopLayer(), TOOL_BASE::getView(), KIGFX::VIEW::GetViewport(), 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::Remove(), 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 1895 of file selection_tool.cpp.

1896 {
1897  if( aMode == SELECTED )
1898  aItem->SetSelected();
1899  else if( aMode == BRIGHTENED )
1900  aItem->SetBrightened();
1901 
1902  if( aGroup )
1903  {
1904  // Hide the original item, so it is shown only on overlay
1905  view()->Hide( aItem, true );
1906 
1907  aGroup->Add( aItem );
1908  }
1909 
1910  // Modules are treated in a special way - when they are highlighted, we have to
1911  // highlight all the parts that make the module, not the module itself
1912  if( aItem->Type() == PCB_MODULE_T )
1913  {
1914  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1915  {
1916  if( aMode == SELECTED )
1917  item->SetSelected();
1918  else if( aMode == BRIGHTENED )
1919  {
1920  item->SetBrightened();
1921 
1922  if( aGroup )
1923  aGroup->Add( item );
1924  }
1925 
1926  if( aGroup )
1927  view()->Hide( item, true );
1928  });
1929  }
1930 
1931  view()->Update( aItem );
1932 
1933  // Many selections are very temporal and updating the display each time just
1934  // creates noise.
1935  if( aMode == BRIGHTENED )
1937 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1507
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:91
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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 MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
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
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References SELECTION::Add(), BRIGHTENED, TOOL_BASE::getView(), KIGFX::VIEW::Hide(), KIGFX::VIEW::MarkTargetDirty(), PCB_MODULE_T, SELECTED, EDA_ITEM::SetBrightened(), EDA_ITEM::SetSelected(), KIGFX::TARGET_OVERLAY, EDA_ITEM::Type(), KIGFX::PCB_VIEW::Update(), and PCB_TOOL_BASE::view().

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

◆ Init()

bool SELECTION_TOOL::Init ( )
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 143 of file selection_tool.cpp.

144 {
145  auto frame = getEditFrame<PCB_BASE_FRAME>();
146 
149  {
151  return true;
152  }
153 
154  auto selectMenu = std::make_shared<SELECT_MENU>();
155  selectMenu->SetTool( this );
156  m_menu.AddSubMenu( selectMenu );
157 
158  auto& menu = m_menu.GetMenu();
159 
160  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
161  menu.AddSeparator( 1000 );
162 
163  if( frame )
165 
166  return true;
167 }
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
PCB_BASE_EDIT_FRAME * frame() const
bool IsType(FRAME_T aType) const
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52

References CONDITIONAL_MENU::AddMenu(), EDA_DRAW_FRAME::AddStandardSubMenus(), TOOL_MENU::AddSubMenu(), PCB_TOOL_BASE::frame(), FRAME_FOOTPRINT_VIEWER, FRAME_FOOTPRINT_VIEWER_MODAL, TOOL_MENU::GetMenu(), EDA_BASE_FRAME::IsType(), TOOL_INTERACTIVE::m_menu, and SELECTION_CONDITIONS::NotEmpty().

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

◆ itemPassesFilter()

bool SELECTION_TOOL::itemPassesFilter ( BOARD_ITEM aItem)
private

Returns true if the given item passes the current SELECTION_FILTER_OPTIONS

Definition at line 1348 of file selection_tool.cpp.

1349 {
1350  if( aItem->IsLocked() && !m_filter.lockedItems )
1351  return false;
1352 
1353  switch( aItem->Type() )
1354  {
1355  case PCB_MODULE_T:
1356  if( !m_filter.footprints )
1357  return false;
1358 
1359  break;
1360 
1361  case PCB_PAD_T:
1362  if( !m_filter.pads )
1363  return false;
1364 
1365  break;
1366 
1367  case PCB_TRACE_T:
1368  case PCB_ARC_T:
1369  if( !m_filter.tracks )
1370  return false;
1371 
1372  break;
1373 
1374  case PCB_VIA_T:
1375  if( !m_filter.vias )
1376  return false;
1377 
1378  break;
1379 
1380  case PCB_ZONE_AREA_T:
1381  {
1382  ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( aItem );
1383 
1384  if( ( !m_filter.zones && !zone->GetIsKeepout() )
1385  || ( !m_filter.keepouts && zone->GetIsKeepout() ) )
1386  {
1387  return false;
1388  }
1389 
1390  break;
1391  }
1392  case PCB_LINE_T:
1393  case PCB_TARGET_T:
1394  if( !m_filter.graphics )
1395  return false;
1396 
1397  break;
1398 
1399  case PCB_MODULE_TEXT_T:
1400  case PCB_TEXT_T:
1401  if( !m_filter.text )
1402  return false;
1403 
1404  break;
1405 
1406  case PCB_DIMENSION_T:
1407  if( !m_filter.dimensions )
1408  return false;
1409 
1410  break;
1411 
1412  default:
1413  if( !m_filter.otherItems )
1414  return false;
1415  }
1416 
1417  return true;
1418 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
bool otherItems
Anything not fitting one of the above categories.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
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
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)
bool dimensions
Dimension items.
bool keepouts
Keepout zones.
bool graphics
Graphic lines, shapes, polygons.
bool tracks
Copper tracks.
bool zones
Copper zones.
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
bool footprints
Allow selecting entire footprints.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:702
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
bool pads
Footprint pads.
bool vias
Vias (all types>
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
virtual bool IsLocked() const
Function IsLocked.
bool lockedItems
Allow selecting locked items.
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
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References SELECTION_FILTER_OPTIONS::dimensions, SELECTION_FILTER_OPTIONS::footprints, ZONE_CONTAINER::GetIsKeepout(), SELECTION_FILTER_OPTIONS::graphics, BOARD_ITEM::IsLocked(), SELECTION_FILTER_OPTIONS::keepouts, SELECTION_FILTER_OPTIONS::lockedItems, m_filter, SELECTION_FILTER_OPTIONS::otherItems, SELECTION_FILTER_OPTIONS::pads, PCB_ARC_T, PCB_DIMENSION_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(), and selectMultiple().

◆ Main()

int SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

The main loop.

Definition at line 197 of file selection_tool.cpp.

198 {
199  // Main loop: keep receiving events
200  while( TOOL_EVENT* evt = Wait() )
201  {
202  if( m_frame->ToolStackIsEmpty() )
203  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
204 
205  bool dragAlwaysSelects = getEditFrame<PCB_BASE_FRAME>()->GetDragSelects();
206  TRACK_DRAG_ACTION dragAction = getEditFrame<PCB_BASE_FRAME>()->Settings().m_TrackDragAction;
208 
209  // OSX uses CTRL for context menu, and SHIFT is exclusive-or
210 #ifdef __WXOSX_MAC__
211  if( evt->Modifier( MD_SHIFT ) )
212  m_exclusive_or = true;
213 #else
214  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
215  m_subtractive = true;
216  else if( evt->Modifier( MD_SHIFT ) )
217  m_additive = true;
218  else if( evt->Modifier( MD_CTRL ) )
219  m_exclusive_or = true;
220 #endif
221 
222  // Is the user requesting that the selection list include all possible
223  // items without removing less likely selection candidates
224  m_skip_heuristics = !!evt->Modifier( MD_ALT );
225 
226  // Single click? Select single object
227  if( evt->IsClick( BUT_LEFT ) )
228  {
229  m_frame->FocusOnItem( nullptr );
230 
231  selectPoint( evt->Position() );
232  }
233 
234  // right click? if there is any object - show the context menu
235  else if( evt->IsClick( BUT_RIGHT ) )
236  {
237  bool selectionCancelled = false;
238 
239  if( m_selection.Empty() ||
240  !m_selection.GetBoundingBox().Contains( wxPoint( evt->Position() ) ) )
241  {
242  ClearSelection();
243  selectPoint( evt->Position(), false, &selectionCancelled );
244  m_selection.SetIsHover( true );
245  }
246 
247  if( !selectionCancelled )
249  }
250 
251  // double click? Display the properties window
252  else if( evt->IsDblClick( BUT_LEFT ) )
253  {
254  m_frame->FocusOnItem( nullptr );
255 
256  if( m_selection.Empty() )
257  selectPoint( evt->Position() );
258 
260  }
261 
262  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
263  else if( evt->IsDrag( BUT_LEFT ) )
264  {
265  m_frame->FocusOnItem( nullptr );
266 
267  if( m_additive || m_subtractive || m_exclusive_or || dragAlwaysSelects )
268  {
269  selectMultiple();
270  }
271  else
272  {
273  // selection is empty? try to start dragging the item under the point where drag
274  // started
275  if( m_selection.Empty() && selectCursor() )
276  m_selection.SetIsHover( true );
277 
278  // Check if dragging has started within any of selected items bounding box
279  if( selectionContains( evt->Position() ) )
280  {
281  // Yes -> run the move tool and wait till it finishes
282  TRACK* track = dynamic_cast<TRACK*>( m_selection.GetItem( 0 ) );
283 
284  if( track && dragAction == TRACK_DRAG_ACTION::DRAG )
286  else if( track && dragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
288  else
290  }
291  else
292  {
293  // No -> drag a selection box
294  selectMultiple();
295  }
296  }
297  }
298 
299  else if( evt->IsCancel() )
300  {
301  m_frame->FocusOnItem( nullptr );
302 
303  ClearSelection();
304 
305  if( evt->FirstResponder() == this )
307  }
308 
309  else if( evt->Action() == TA_UNDO_REDO_PRE )
310  {
311  ClearSelection();
312  }
313 
314  else
315  evt->SetPassEvent();
316  }
317 
318  return 0;
319 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
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:133
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:109
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:132
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...
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:84
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 drag
Definition: pcb_actions.h:93
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:404
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::drag, PCB_ACTIONS::drag45Degree, DRAG_FREE_ANGLE, PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), PCB_BASE_FRAME::FocusOnItem(), SELECTION::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), SELECTION::GetItem(), m_additive, 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::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TA_UNDO_REDO_PRE, 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 1593 of file selection_tool.cpp.

1594 {
1595  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1596 
1597  if( 0 == count )
1598  count = aCollector->GetCount();
1599 
1600  for( int i = 0; i < count; ++i )
1601  {
1602  if( ( *aCollector )[i]->Type() != PCB_MODULE_T )
1603  return NULL;
1604  }
1605 
1606  // All are modules, now find smallest MODULE
1607  int minDim = 0x7FFFFFFF;
1608  int minNdx = 0;
1609 
1610  for( int i = 0; i < count; ++i )
1611  {
1612  MODULE* module = (MODULE*) ( *aCollector )[i];
1613 
1614  int lx = module->GetFootprintRect().GetWidth();
1615  int ly = module->GetFootprintRect().GetHeight();
1616 
1617  int lmin = std::min( lx, ly );
1618 
1619  if( lmin < minDim )
1620  {
1621  minDim = lmin;
1622  minNdx = i;
1623  }
1624  }
1625 
1626  return (*aCollector)[minNdx];
1627 }
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:100
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 1445 of file selection_tool.cpp.

1446 {
1447  m_selection.Clear();
1448 
1449  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1450  {
1451  if( item->IsSelected() )
1452  {
1453  EDA_ITEM* parent = item->GetParent();
1454 
1455  // Flags on module children might be set only because the parent is selected.
1456  if( parent && parent->Type() == PCB_MODULE_T && parent->IsSelected() )
1457  return SEARCH_RESULT::CONTINUE;
1458 
1459  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1460  }
1461 
1462  return SEARCH_RESULT::CONTINUE;
1463  };
1464 
1465  board()->Visit( inspector, nullptr, m_editModules ? GENERAL_COLLECTOR::ModuleItems
1467 }
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 775 of file selection_tool.cpp.

776 {
777  if( aItem )
778  {
779  unselect( aItem );
780 
781  // Inform other potentially interested tools
783  }
784 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:203
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

The second step is to find the items that were removed by the client filter

Once we find the adjustments to m_selection that are required by the client filter, we apply them both

Definition at line 328 of file selection_tool.cpp.

331 {
332  bool selectionEmpty = m_selection.Empty();
333  m_selection.SetIsHover( selectionEmpty );
334 
335  if( selectionEmpty )
336  {
337  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
339  }
340 
341  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
342  {
343  ClearSelection();
344  return m_selection;
345  }
346 
347  if( aClientFilter )
348  {
349  GENERAL_COLLECTOR collector;
350 
351  for( auto item : m_selection )
352  collector.Append( item );
353 
354  aClientFilter( VECTOR2I(), collector );
355 
356  /*
357  * The first step is to find the items that may have been added by the client filter
358  * This can happen if the locked pads select the module instead
359  */
360  std::vector<EDA_ITEM*> new_items;
361  std::set_difference( collector.begin(), collector.end(),
363  std::back_inserter( new_items ) );
364 
368  std::vector<EDA_ITEM*> diff;
369  std::set_difference( m_selection.begin(), m_selection.end(),
370  collector.begin(), collector.end(),
371  std::back_inserter( diff ) );
372 
373  if( aFiltered )
374  {
375  for( auto item : diff )
376  aFiltered->push_back( static_cast<BOARD_ITEM*>( item ) );
377  }
378 
383  for( auto item : diff )
384  unhighlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
385 
386  for( auto item : new_items )
387  highlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
388 
390  }
391 
392  return m_selection;
393 }
void ClearReferencePoint()
Definition: selection.h:250
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
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
ITER end()
Definition: selection.h:62
ITER begin()
Definition: collector.h:91
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
ITER end()
Definition: collector.h:92
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:119
#define SELECTED
Definition: base_struct.h:124
ITER begin()
Definition: selection.h:61
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
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(), SELECTION::begin(), COLLECTOR::begin(), CheckLock(), SELECTION::ClearReferencePoint(), ClearSelection(), SELECTION::Empty(), SELECTION::end(), COLLECTOR::end(), 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::Duplicate(), PCB_EDITOR_CONTROL::EditFpInFpEditor(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), EDIT_TOOL::Mirror(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), EDIT_TOOL::Rotate(), 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 170 of file selection_tool.cpp.

171 {
172  m_frame = getEditFrame<PCB_BASE_FRAME>();
173  m_locked = true;
174 
175  if( aReason == TOOL_BASE::MODEL_RELOAD )
176  {
177  // Deselect any item being currently in edit, to avoid unexpected behavior
178  // and remove pointers to the selected items from containers
179  // without changing their properties (as they are already deleted
180  // while a new board is loaded)
181  ClearSelection( true );
182 
183  getView()->GetPainter()->GetSettings()->SetHighlight( false );
184  }
185  else
186  {
187  // Restore previous properties of selected items and remove them from containers
188  ClearSelection( true );
189  }
190 
191  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
192  view()->Remove( &m_selection );
193  view()->Add( &m_selection );
194 }
Model changes (required full reload)
Definition: tool_base.h:82
PCBNEW_SELECTION m_selection
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
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:58

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

◆ RunMainStack()

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

Function RunMainStack()

Calls a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 87 of file tool_interactive.cpp.

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

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

Referenced by DRAWING_TOOL::PlaceText().

◆ select()

void SELECTION_TOOL::select ( BOARD_ITEM aItem)
private

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

Parameters
aItemis an item to be selected.

Definition at line 1867 of file selection_tool.cpp.

1868 {
1869  if( aItem->IsSelected() )
1870  {
1871  return;
1872  }
1873 
1874  if( aItem->Type() == PCB_PAD_T )
1875  {
1876  MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
1877 
1878  if( m_selection.Contains( module ) )
1879  return;
1880  }
1881 
1882  highlight( aItem, SELECTED, &m_selection );
1883 }
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(), filterSelection(), findCallback(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), SelectItems(), selectMultiple(), and selectPoint().

◆ Selectable()

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

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

Returns
True if the item fulfills conditions to be selected.

Definition at line 1630 of file selection_tool.cpp.

1631 {
1632  const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
1633 
1634  if( settings->GetHighContrast() )
1635  {
1636  int itemLayers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
1637  std::set<unsigned int> activeLayers = settings->GetActiveLayers();
1638 
1639  aItem->ViewGetLayers( itemLayers, layers_count );
1640 
1641  bool onActive = false; // Is the item on any of active layers?
1642 
1643  for( int i = 0; i < layers_count; ++i )
1644  {
1645  if( activeLayers.count( itemLayers[i] ) > 0 ) // Item is on at least one of the active layers
1646  {
1647  onActive = true;
1648  break;
1649  }
1650  }
1651 
1652  if( !onActive ) // We do not want to select items that are in the background
1653  {
1654  return false;
1655  }
1656  }
1657 
1658  switch( aItem->Type() )
1659  {
1660  case PCB_ZONE_AREA_T:
1662  {
1663  // Check to see if this keepout is part of a footprint
1664  // If it is, and we are not editing the footprint, it should not be selectable
1665  const bool zoneInFootprint =
1666  aItem->GetParent() != nullptr && aItem->GetParent()->Type() == PCB_MODULE_T;
1667  if( zoneInFootprint && !m_editModules && !checkVisibilityOnly )
1668  return false;
1669 
1670  // zones can exist on multiple layers!
1671  {
1672  auto* zone = static_cast<const ZONE_CONTAINER*>( aItem );
1673  auto zoneLayers = zone->GetLayerSet().Seq();
1674 
1675  for( unsigned int i = 0; i < zoneLayers.size(); i++ )
1676  {
1677  if( board()->IsLayerVisible( zoneLayers[i] ) )
1678  {
1679  return true;
1680  }
1681  }
1682 
1683  // No active layers selected!
1684  return false;
1685  }
1686  }
1687  break;
1688 
1689  case PCB_TRACE_T:
1690  case PCB_ARC_T:
1691  {
1692  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1693  return false;
1694  }
1695  break;
1696 
1697  case PCB_VIA_T:
1698  {
1699  const VIA* via = static_cast<const VIA*>( aItem );
1700 
1701  // Check if appropriate element layer is visible
1702  switch( via->GetViaType() )
1703  {
1704  case VIATYPE::THROUGH:
1706  return false;
1707  break;
1708 
1709  case VIATYPE::BLIND_BURIED:
1711  return false;
1712  break;
1713 
1714  case VIATYPE::MICROVIA:
1716  return false;
1717  break;
1718 
1719  default:
1720  wxFAIL;
1721  return false;
1722  }
1723 
1724  // For vias it is enough if only one of its layers is visible
1725  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1726  }
1727 
1728  case PCB_MODULE_T:
1729  {
1730  // In modedit, we do not want to select the module itself.
1731  if( m_editModules )
1732  return false;
1733 
1734  // Allow selection of footprints if some part of the footprint is visible.
1735 
1736  MODULE* module = const_cast<MODULE*>( static_cast<const MODULE*>( aItem ) );
1737 
1738  for( auto item : module->GraphicalItems() )
1739  {
1740  if( Selectable( item, true ) )
1741  return true;
1742  }
1743 
1744  for( auto pad : module->Pads() )
1745  {
1746  if( Selectable( pad, true ) )
1747  return true;
1748  }
1749 
1750  for( auto zone : module->Zones() )
1751  {
1752  if( Selectable( zone, true ) )
1753  return true;
1754  }
1755 
1756  return false;
1757  }
1758 
1759  case PCB_MODULE_TEXT_T:
1760  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1761  // module subparts one by one, rather than with a drag selection. This is so you can
1762  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1763  if( !m_editModules && !checkVisibilityOnly )
1764  {
1765  if( m_multiple && !settings->GetHighContrast() )
1766  return false;
1767  }
1768 
1769  if( !m_editModules && !view()->IsVisible( aItem ) )
1770  return false;
1771 
1772  break;
1773 
1774  case PCB_MODULE_EDGE_T:
1775  case PCB_PAD_T:
1776  {
1777  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1778  // module subparts one by one, rather than with a drag selection. This is so you can
1779  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1780  if( !m_editModules && !checkVisibilityOnly )
1781  {
1782  if( m_multiple )
1783  return false;
1784  }
1785 
1786  if( aItem->Type() == PCB_PAD_T )
1787  {
1788  auto pad = static_cast<const D_PAD*>( aItem );
1789 
1790  // In pcbnew, locked modules prevent individual pad selection.
1791  // In modedit, we don't enforce this as the module is assumed to be edited by design.
1792  if( !m_editModules && !checkVisibilityOnly )
1793  {
1794  if( pad->GetParent() && pad->GetParent()->IsLocked() )
1795  return false;
1796  }
1797 
1798  // Check render mode (from the Items tab) first
1799  switch( pad->GetAttribute() )
1800  {
1801  case PAD_ATTRIB_STANDARD:
1803  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1804  return false;
1805  break;
1806 
1807  case PAD_ATTRIB_CONN:
1808  case PAD_ATTRIB_SMD:
1809  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1810  return false;
1811  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1812  return false;
1813  break;
1814  }
1815 
1816  // Otherwise, pads are selectable if any draw layer is visible
1817 
1818  // Shortcut: check copper layer visibility
1819  if( board()->IsLayerVisible( F_Cu ) && pad->IsOnLayer( F_Cu ) )
1820  return true;
1821 
1822  if( board()->IsLayerVisible( B_Cu ) && pad->IsOnLayer( B_Cu ) )
1823  return true;
1824 
1825  // Now check the non-copper layers
1826 
1827  bool draw_layer_visible = false;
1828 
1829  int pad_layers[KIGFX::VIEW::VIEW_MAX_LAYERS], pad_layers_count;
1830  pad->ViewGetLayers( pad_layers, pad_layers_count );
1831 
1832  for( int i = 0; i < pad_layers_count; ++i )
1833  {
1834  // NOTE: Only checking the regular layers (not GAL meta-layers)
1835  if( ( ( pad_layers[i] < PCB_LAYER_ID_COUNT ) &&
1836  board()->IsLayerVisible( static_cast<PCB_LAYER_ID>( pad_layers[i] ) ) ) )
1837  {
1838  draw_layer_visible = true;
1839  }
1840  }
1841 
1842  return draw_layer_visible;
1843  }
1844 
1845  break;
1846  }
1847 
1848 
1849  case PCB_MARKER_T: // Always selectable
1850  return true;
1851 
1852  // These are not selectable
1853  case NOT_USED:
1854  case TYPE_NOT_INIT:
1855  return false;
1856 
1857  default: // Suppress warnings
1858  break;
1859  }
1860 
1861  // All other items are selected only if the layer on which they exist is visible
1862  return board()->IsLayerVisible( aItem->GetLayer() )
1863  && aItem->ViewGetLOD( aItem->GetLayer(), view() ) < view()->GetScale();
1864 }
to draw blind/buried vias
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
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
virtual unsigned int ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:140
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:102
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
PADS & Pads()
Definition: class_module.h:169
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:179
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
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
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:1526
to draw usual through hole vias
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
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:184
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
MODULE * module() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
VIATYPE GetViaType() const
Definition: class_track.h:368
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References B_Cu, BLIND_BURIED, PCB_TOOL_BASE::board(), F_Cu, KIGFX::RENDER_SETTINGS::GetActiveLayers(), KIGFX::RENDER_SETTINGS::GetHighContrast(), BOARD_ITEM::GetLayer(), VIA::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), VIA::GetViaType(), 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_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_THROUGH, PCB_TOOL_BASE::m_editModules, m_multiple, MICROVIA, 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_LAYER_ID_COUNT, 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, THROUGH, EDA_ITEM::Type(), TYPE_NOT_INIT, PCB_TOOL_BASE::view(), KIGFX::VIEW::VIEW_MAX_LAYERS, BOARD_ITEM::ViewGetLayers(), KIGFX::VIEW_ITEM::ViewGetLOD(), and MODULE::Zones().

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

◆ selectAllItemsOnNet()

void SELECTION_TOOL::selectAllItemsOnNet ( int  aNetCode)
private

Selects all items with the given net code.

Definition at line 970 of file selection_tool.cpp.

971 {
972  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
973  auto connectivity = board()->GetConnectivity();
974 
975  for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
976  select( item );
977 }
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
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:355
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

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

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

1005 {
1006  std::list<MODULE*> modList;
1007 
1008  // store all modules that are on that sheet path
1009  for( MODULE* module : board()->Modules() )
1010  {
1011  if( module == nullptr )
1012  continue;
1013 
1014  wxString footprint_path = module->GetPath().AsString().BeforeLast('/');
1015 
1016  if( aSheetPath.IsEmpty() )
1017  aSheetPath += '/';
1018 
1019  if( footprint_path == aSheetPath )
1020  modList.push_back( module );
1021  }
1022 
1023  //Generate a list of all pads, and of all nets they belong to.
1024  std::list<int> netcodeList;
1025  std::list<D_PAD*> padList;
1026  for( MODULE* mmod : modList )
1027  {
1028  for( D_PAD* pad : mmod->Pads() )
1029  {
1030  if( pad->IsConnected() )
1031  {
1032  netcodeList.push_back( pad->GetNetCode() );
1033  padList.push_back( pad );
1034  }
1035  }
1036  }
1037  // remove all duplicates
1038  netcodeList.sort();
1039  netcodeList.unique();
1040 
1041  // auto select trivial connections segments which are launched from the pads
1042  std::list<TRACK*> launchTracks;
1043 
1044  for( D_PAD* pad : padList )
1046 
1047  // now we need to find all modules that are connected to each of these nets
1048  // then we need to determine if these modules are in the list of modules
1049  // belonging to this sheet ( modList )
1050  std::list<int> removeCodeList;
1051  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1052 
1053  for( int netCode : netcodeList )
1054  {
1055  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1056  {
1057  if( mitem->Type() == PCB_PAD_T)
1058  {
1059  bool found = std::find( modList.begin(), modList.end(), mitem->GetParent() ) != modList.end();
1060 
1061  if( !found )
1062  {
1063  // if we cannot find the module of the pad in the modList
1064  // then we can assume that that module is not located in the same
1065  // schematic, therefore invalidate this netcode.
1066  removeCodeList.push_back( netCode );
1067  break;
1068  }
1069  }
1070  }
1071  }
1072 
1073  // remove all duplicates
1074  removeCodeList.sort();
1075  removeCodeList.unique();
1076 
1077  for( int removeCode : removeCodeList )
1078  {
1079  netcodeList.remove( removeCode );
1080  }
1081 
1082  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1083  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
1084 
1085  for( int netCode : netcodeList )
1086  {
1087  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1088  localConnectionList.push_back( item );
1089  }
1090 
1091  for( BOARD_ITEM* i : modList )
1092  {
1093  if( i != NULL )
1094  select( i );
1095  }
1096 
1097  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1098  {
1099  if( i != NULL )
1100  select( i );
1101  }
1102 }
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:224
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 860 of file selection_tool.cpp.

862 {
863  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT };
864 
865  auto connectivity = board()->GetConnectivity();
866  auto connectedItems = connectivity->GetConnectedItems( &aStartItem, types );
867 
868  std::map<wxPoint, std::vector<TRACK*>> trackMap;
869  std::map<wxPoint, VIA*> viaMap;
870  std::map<wxPoint, D_PAD*> padMap;
871 
872  // Build maps of connected items
873  for( BOARD_CONNECTED_ITEM* item : connectedItems )
874  {
875  switch( item->Type() )
876  {
877  case PCB_TRACE_T:
878  {
879  TRACK* track = static_cast<TRACK*>( item );
880  trackMap[ track->GetStart() ].push_back( track );
881  trackMap[ track->GetEnd() ].push_back( track );
882  }
883  break;
884  case PCB_VIA_T:
885  {
886  VIA* via = static_cast<VIA*>( item );
887  viaMap[ via->GetStart() ] = via;
888  }
889  break;
890  case PCB_PAD_T:
891  {
892  D_PAD* pad = static_cast<D_PAD*>( item );
893  padMap[ pad->GetPosition() ] = pad;
894  }
895  break;
896  default:
897  break;
898  }
899 
900  item->SetFlags( SKIP_STRUCT );
901  }
902 
903  std::vector<wxPoint> activePts;
904 
905  // Set up the initial active points
906  switch( aStartItem.Type() )
907  {
908  case PCB_TRACE_T:
909  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
910  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetEnd() );
911  break;
912  case PCB_VIA_T:
913  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
914  break;
915  case PCB_PAD_T:
916  activePts.push_back( aStartItem.GetPosition() );
917  break;
918  default:
919  break;
920  }
921 
922  bool expand = true;
923 
924  // Iterative push from all active points
925  while( expand )
926  {
927  expand = false;
928 
929  for( int i = activePts.size() - 1; i >= 0; --i )
930  {
931  wxPoint pt = activePts[i];
932 
933  if( trackMap[ pt ].size() > 2 && aStopCondition == STOP_AT_JUNCTION )
934  {
935  activePts.erase( activePts.begin() + i );
936  continue;
937  }
938 
939  if( padMap.count( pt ) && aStopCondition != STOP_NEVER )
940  {
941  activePts.erase( activePts.begin() + i );
942  continue;
943  }
944 
945  for( TRACK* track : trackMap[ pt ] )
946  {
947  if( track->GetState( SKIP_STRUCT ) )
948  continue;
949 
950  track->SetState( SKIP_STRUCT, true );
951  select( track );
952 
953  if( track->GetStart() == pt )
954  activePts.push_back( track->GetEnd() );
955  else
956  activePts.push_back( track->GetStart() );
957 
958  expand = true;
959  }
960 
961  if( viaMap.count( pt ) && !viaMap[ pt ]->IsSelected() )
962  select( viaMap[ pt ] );
963 
964  activePts.erase( activePts.begin() + i );
965  }
966  }
967 }
BOARD * board() const
const wxPoint & GetStart() const
Definition: class_track.h:118
#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
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void SetState(int type, int state)
Definition: base_struct.h:221
const wxPoint & GetEnd() const
Definition: class_track.h:115
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxPoint GetPosition() const override
Definition: class_pad.h:161
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::SetFlags(), 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 517 of file selection_tool.cpp.

518 {
519  if( aForceSelect || m_selection.Empty() )
520  {
521  ClearSelection( true /*quiet mode*/ );
522  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
523  }
524 
525  return !m_selection.Empty();
526 }
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 275 of file pcb_tool_base.cpp.

276 {
277  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
278  const auto& selection = selTool->GetSelection();
279  return selection;
280 }
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_TOOL_BASE::doInteractiveItemPlacement(), 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_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), 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(), EDIT_TOOL::Rotate(), PCB_TOOL_BASE::selection(), selectNet(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), 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 283 of file pcb_tool_base.cpp.

284 {
285  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
286  auto& selection = selTool->GetSelection();
287  return selection;
288 }
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 1987 of file selection_tool.cpp.

1988 {
1989  const unsigned GRIP_MARGIN = 20;
1990  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1991 
1992  // Check if the point is located within any of the currently selected items bounding boxes
1993  for( auto item : m_selection )
1994  {
1995  BOX2I itemBox = item->ViewBBox();
1996  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1997 
1998  if( itemBox.Contains( aPoint ) )
1999  return true;
2000  }
2001 
2002  return false;
2003 }
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:475
PCBNEW_SELECTION m_selection
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
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:301

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

1471 {
1472  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1473 
1474  doSelectionMenu( collector, wxEmptyString );
1475 
1476  return 0;
1477 }
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 731 of file selection_tool.cpp.

732 {
733  AddItemToSel( aEvent.Parameter<BOARD_ITEM*>() );
734  return 0;
735 }
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 714 of file selection_tool.cpp.

715 {
716  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
717 
718  if( items )
719  {
720  // Perform individual selection of each item before processing the event.
721  for( auto item : *items )
722  select( item );
723 
725  }
726 
727  return 0;
728 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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 529 of file selection_tool.cpp.

530 {
531  bool cancelled = false; // Was the tool cancelled while it was running?
532  m_multiple = true; // Multiple selection mode is active
533  KIGFX::VIEW* view = getView();
534 
536  view->Add( &area );
537 
538  bool anyAdded = false;
539  bool anySubtracted = false;
540 
541  while( TOOL_EVENT* evt = Wait() )
542  {
543  if( evt->IsCancelInteractive() || evt->IsActivate() )
544  {
545  cancelled = true;
546  break;
547  }
548 
549  if( evt->IsDrag( BUT_LEFT ) )
550  {
552  {
553  if( m_selection.GetSize() > 0 )
554  {
555  anySubtracted = true;
556  ClearSelection( true /*quiet mode*/ );
557  }
558  }
559 
560  // Start drawing a selection box
561  area.SetOrigin( evt->DragOrigin() );
562  area.SetEnd( evt->Position() );
563  area.SetAdditive( m_additive );
566 
567  view->SetVisible( &area, true );
568  view->Update( &area );
569  getViewControls()->SetAutoPan( true );
570  }
571 
572  if( evt->IsMouseUp( BUT_LEFT ) )
573  {
574  getViewControls()->SetAutoPan( false );
575 
576  // End drawing the selection box
577  view->SetVisible( &area, false );
578 
579  // Mark items within the selection box as selected
580  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
581 
582  // Filter the view items based on the selection box
583  BOX2I selectionBox = area.ViewBBox();
584  view->Query( selectionBox, selectedItems ); // Get the list of selected items
585 
586  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
587 
588  int width = area.GetEnd().x - area.GetOrigin().x;
589  int height = area.GetEnd().y - area.GetOrigin().y;
590 
591  /* Selection mode depends on direction of drag-selection:
592  * Left > Right : Select objects that are fully enclosed by selection
593  * Right > Left : Select objects that are crossed by selection
594  */
595  bool windowSelection = width >= 0 ? true : false;
596 
597  if( view->IsMirroredX() )
598  windowSelection = !windowSelection;
599 
600  // Construct an EDA_RECT to determine BOARD_ITEM selection
601  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
602 
603  selectionRect.Normalize();
604 
605  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
606  {
607  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
608 
609  if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
610  continue;
611 
612  if( item->HitTest( selectionRect, windowSelection ) )
613  {
614  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
615  {
616  unselect( item );
617  anySubtracted = true;
618  }
619  else
620  {
621  select( item );
622  anyAdded = true;
623  }
624  }
625  }
626 
627  m_selection.SetIsHover( false );
628 
629  // Inform other potentially interested tools
630  if( anyAdded )
632  else if( anySubtracted )
634 
635  break; // Stop waiting for events
636  }
637  }
638 
639  getViewControls()->SetAutoPan( false );
640 
641  // Stop drawing the selection box
642  view->Remove( &area );
643  m_multiple = false; // Multiple selection mode is inactive
644 
645  if( !cancelled )
647 
648  return cancelled;
649 }
void ClearReferencePoint()
Definition: selection.h:250
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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:203
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:91
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:74
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:1486
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
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:452
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 980 of file selection_tool.cpp.

981 {
982  if( !selectCursor() )
983  return 0;
984 
985  // copy the selection, since we're going to iterate and modify
986  auto selection = m_selection.GetItems();
987 
988  for( EDA_ITEM* i : selection )
989  {
990  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
991 
992  if( connItem )
993  selectAllItemsOnNet( connItem->GetNetCode() );
994  }
995 
996  // Inform other potentially interested tools
997  if( m_selection.Size() > 0 )
999 
1000  return 0;
1001 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
int GetNetCode() const
Function GetNetCode.
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...
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
void selectAllItemsOnNet(int aNetCode)
Selects all items with the given net code.
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
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(), m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), selectAllItemsOnNet(), selectCursor(), EVENTS::SelectedEvent, PCB_TOOL_BASE::selection(), 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 421 of file selection_tool.cpp.

424 {
426  GENERAL_COLLECTOR collector;
427  auto& displayOpts = m_frame->GetDisplayOptions();
428 
429  guide.SetIgnoreZoneFills( displayOpts.m_DisplayZonesMode != 0 );
430 
431  collector.Collect( board(),
433  wxPoint( aWhere.x, aWhere.y ), guide );
434 
435  // Remove unselectable items
436  for( int i = collector.GetCount() - 1; i >= 0; --i )
437  {
438  if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
439  collector.Remove( i );
440  }
441 
443 
444  // Allow the client to do tool- or action-specific filtering to see if we
445  // can get down to a single item
446  if( aClientFilter )
447  aClientFilter( aWhere, collector );
448 
449  // Apply the stateful filter
450  filterCollectedItems( collector );
451 
452  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
453  if( collector.GetCount() > 1 && !m_skip_heuristics )
454  {
455  GuessSelectionCandidates( collector, aWhere );
456  }
457 
458  // If still more than one item we're going to have to ask the user.
459  if( collector.GetCount() > 1 )
460  {
461  if( aOnDrag )
463 
464  if( !doSelectionMenu( &collector, _( "Clarify Selection" ) ) )
465  {
466  if( aSelectionCancelledFlag )
467  *aSelectionCancelledFlag = true;
468 
469  return false;
470  }
471  }
472 
473  bool anyAdded = false;
474  bool anySubtracted = false;
475 
477  {
478  if( m_selection.GetSize() > 0 )
479  {
480  ClearSelection( true /*quiet mode*/ );
481  anySubtracted = true;
482  }
483  }
484 
485  if( collector.GetCount() > 0 )
486  {
487  for( int i = 0; i < collector.GetCount(); ++i )
488  {
489  if( m_subtractive || ( m_exclusive_or && collector[i]->IsSelected() ) )
490  {
491  unselect( collector[i] );
492  anySubtracted = true;
493  }
494  else
495  {
496  select( collector[i] );
497  anyAdded = true;
498  }
499  }
500  }
501 
502  if( anyAdded )
503  {
505  return true;
506  }
507  else if( anySubtracted )
508  {
510  return true;
511  }
512 
513  return false;
514 }
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
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
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:203
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:539
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
PCBNEW_SELECTION m_selection
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.
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:129
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
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
#define _(s)
Definition: 3d_actions.cpp:33
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.
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:385
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:610
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(), doSelectionMenu(), filterCollectedItems(), getCollectorsGuide(), COLLECTOR::GetCount(), PCB_BASE_FRAME::GetDisplayOptions(), SELECTION::GetSize(), GuessSelectionCandidates(), m_additive, PCB_TOOL_BASE::m_editModules, 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(), 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 1145 of file selection_tool.cpp.

1146 {
1147  if( !selectCursor( true ) )
1148  return 0;
1149 
1150  // this function currently only supports modules since they are only
1151  // on one sheet.
1152  auto item = m_selection.Front();
1153 
1154  if( !item )
1155  return 0;
1156 
1157  if( item->Type() != PCB_MODULE_T )
1158  return 0;
1159 
1160  auto mod = dynamic_cast<MODULE*>( item );
1161 
1162  if( mod->GetPath().empty() )
1163  return 0;
1164 
1165  ClearSelection( true /*quiet mode*/ );
1166 
1167  // get the sheet path only.
1168  wxString sheetPath = mod->GetPath().AsString().BeforeLast( '/' );
1169 
1170  if( sheetPath.IsEmpty() )
1171  sheetPath += '/';
1172 
1173  selectAllItemsOnSheet( sheetPath );
1174 
1175  // Inform other potentially interested tools
1176  if( m_selection.Size() > 0 )
1178 
1179  return 0;
1180 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
void selectAllItemsOnSheet(wxString &aSheetPath)
Selects all items with the given sheet timestamp/UUID name (the sheet path) The path of the root shee...
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
class MODULE, a footprint
Definition: typeinfo.h:89
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
int Size() const
Returns the number of selected parts.
Definition: selection.h:127
EDA_ITEM * Front() const
Definition: selection.h:184

References ClearSelection(), SELECTION::Front(), m_selection, TOOL_BASE::m_toolMgr, PCB_MODULE_T, TOOL_MANAGER::ProcessEvent(), selectAllItemsOnSheet(), selectCursor(), EVENTS::SelectedEvent, and SELECTION::Size().

Referenced by setTransitions().

◆ selectSheetContents()

int SELECTION_TOOL::selectSheetContents ( const TOOL_EVENT aEvent)
private

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

Definition at line 1129 of file selection_tool.cpp.

1130 {
1131  ClearSelection( true /*quiet mode*/ );
1132  wxString sheetPath = *aEvent.Parameter<wxString*>();
1133 
1134  selectAllItemsOnSheet( sheetPath );
1135 
1136  zoomFitSelection();
1137 
1138  if( m_selection.Size() > 0 )
1140 
1141  return 0;
1142 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:202
void selectAllItemsOnSheet(wxString &aSheetPath)
Selects all items with the given sheet timestamp/UUID name (the sheet path) The path of the root shee...
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
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).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
int Size() const
Returns the number of selected parts.
Definition: selection.h:127
void zoomFitSelection()
Zooms the screen to center and fit the current selection.

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

Referenced by setTransitions().

◆ SetContextMenu()

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

Function SetContextMenu()

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

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

Definition at line 76 of file tool_interactive.cpp.

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

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ SetEditModules()

void PCB_TOOL_BASE::SetEditModules ( bool  aEnabled)
inlineinherited

Function SetEditModules()

Toggles edit module mode. When enabled, one may select parts of modules individually (graphics, pads, etc.), so they can be modified.

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 101 of file pcb_tool_base.h.

102  {
103  m_editModules = aEnabled;
104  }

References PCB_TOOL_BASE::m_editModules.

◆ setTransitions()

void SELECTION_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from PCB_TOOL_BASE.

Definition at line 2446 of file selection_tool.cpp.

2447 {
2449 
2453 
2459 
2460  Go( &SELECTION_TOOL::find, ACTIONS::find.MakeEvent() );
2461 
2468 }
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:69
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:56
int UnselectItem(const TOOL_EVENT &aEvent)
Item unselection event handler.
int Main(const TOOL_EVENT &aEvent)
Function Main()
int UpdateMenu(const TOOL_EVENT &aEvent)
Pass the selection to a conditional menu for updating.
int selectSameSheet(const TOOL_EVENT &aEvent)
Selects all modules belonging to same hierarchical sheet as the selected footprint (same sheet path).
static TOOL_ACTION unselectItem
Definition: pcb_actions.h:66
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:80
static TOOL_ACTION unselectItems
Definition: pcb_actions.h:70
int find(const TOOL_EVENT &aEvent)
Find an item.
int UnselectItems(const TOOL_EVENT &aEvent)
Multiple item unselection event handler
static TOOL_ACTION selectionMenu
Runs a selection menu to select from a list of items.
Definition: pcb_actions.h:73
static TOOL_ACTION selectConnection
Selects tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:77
static TOOL_ACTION find
Definition: actions.h:78
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:206
int filterSelection(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection
int expandConnection(const TOOL_EVENT &aEvent)
Expands the current track selection to the next boundary (junctions, pads, or all)
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int SelectionMenu(const TOOL_EVENT &aEvent)
Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down t...
static TOOL_ACTION updateMenu
Definition: actions.h:162
int selectSheetContents(const TOOL_EVENT &aEvent)
Selects all modules belonging to same sheet, from Eeschema, using crossprobing
int SelectItem(const TOOL_EVENT &aEvent)
Item selection event handler.
int selectNet(const TOOL_EVENT &aEvent)
Selects all copper connections belonging to the same net(s) as the items in the selection.
static TOOL_ACTION filterSelection
Filters the items in the current selection (invokes dialog)
Definition: pcb_actions.h:89
static TOOL_ACTION selectOnSheetFromEeschema
Selects all components on sheet from Eeschema crossprobing.
Definition: pcb_actions.h:83
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
int SelectItems(const TOOL_EVENT &aEvent)
Multiple item selection event handler
int CursorSelection(const TOOL_EVENT &aEvent)
Select a single item under cursor event handler.
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:59
static TOOL_ACTION selectSameSheet
Selects all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:86

References ClearSelection(), CursorSelection(), expandConnection(), PCB_ACTIONS::filterSelection, filterSelection(), ACTIONS::find, find(), TOOL_INTERACTIVE::Go(), Main(), PCB_ACTIONS::selectConnection, EVENTS::SelectedItemsModified, PCB_ACTIONS::selectionActivate, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionCursor, PCB_ACTIONS::selectionMenu, SelectionMenu(), PCB_ACTIONS::selectItem, SelectItem(), PCB_ACTIONS::selectItems, SelectItems(), PCB_ACTIONS::selectNet, selectNet(), PCB_ACTIONS::selectOnSheetFromEeschema, PCB_ACTIONS::selectSameSheet, selectSameSheet(), selectSheetContents(), PCB_ACTIONS::unselectItem, UnselectItem(), PCB_ACTIONS::unselectItems, UnselectItems(), ACTIONS::updateMenu, UpdateMenu(), and updateSelection().

◆ UnbrightenItem()

void SELECTION_TOOL::UnbrightenItem ( BOARD_ITEM aItem)

Definition at line 793 of file selection_tool.cpp.

794 {
795  unhighlight( aItem, BRIGHTENED );
796 }
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.

References BRIGHTENED, and unhighlight().

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

◆ unhighlight()

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

Function unhighlight() Unhighlights the item visually.

Parameters
aItemis an item to be be highlighted.
aHighlightModeshould be either SELECTED or BRIGHTENED
aGroupis the group to remove the item from.

Definition at line 1940 of file selection_tool.cpp.

1941 {
1942  if( aMode == SELECTED )
1943  aItem->ClearSelected();
1944  else if( aMode == BRIGHTENED )
1945  aItem->ClearBrightened();
1946 
1947  if( aGroup )
1948  {
1949  aGroup->Remove( aItem );
1950 
1951  // Restore original item visibility
1952  view()->Hide( aItem, false );
1953  }
1954 
1955  // Modules are treated in a special way - when they are highlighted, we have to
1956  // highlight all the parts that make the module, not the module itself
1957  if( aItem->Type() == PCB_MODULE_T )
1958  {
1959  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1960  {
1961  if( aMode == SELECTED )
1962  item->ClearSelected();
1963  else if( aMode == BRIGHTENED )
1964  item->ClearBrightened();
1965 
1966  // N.B. if we clear the selection flag for sub-elements, we need to also
1967  // remove the element from the selection group (if it exists)
1968  if( aGroup )
1969  {
1970  aGroup->Remove( item );
1971 
1972  view()->Hide( item, false );
1973  view()->Update( item );
1974  }
1975  });
1976  }
1977 
1978  view()->Update( aItem );
1979 
1980  // Many selections are very temporal and updating the display each time just
1981  // creates noise.
1982  if( aMode == BRIGHTENED )
1984 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1507
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:91
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ClearSelected()
Definition: base_struct.h:211
void ClearBrightened()
Definition: base_struct.h:212
#define SELECTED
Definition: base_struct.h:124
class MODULE, a footprint
Definition: typeinfo.h:89
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
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
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:87

References BRIGHTENED, EDA_ITEM::ClearBrightened(), EDA_ITEM::ClearSelected(), TOOL_BASE::getView(), KIGFX::VIEW::Hide(), KIGFX::VIEW::MarkTargetDirty(), PCB_MODULE_T, SELECTION::Remove(), SELECTED, KIGFX::TARGET_OVERLAY, EDA_ITEM::Type(), KIGFX::PCB_VIEW::Update(), and PCB_TOOL_BASE::view().

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

◆ unselect()

void SELECTION_TOOL::unselect ( BOARD_ITEM aItem)
private

Function unselect() Takes necessary action mark an item as unselected.

Parameters
aItemis an item to be unselected.

Definition at line 1886 of file selection_tool.cpp.

1887 {
1888  unhighlight( aItem, SELECTED, &m_selection );
1889 
1890  if( m_selection.Empty() )
1891  m_locked = true;
1892 }
PCBNEW_SELECTION m_selection
#define SELECTED
Definition: base_struct.h:124
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.

References SELECTION::Empty(), m_locked, m_selection, SELECTED, and unhighlight().

Referenced by RemoveItemFromSel(), selectMultiple(), selectPoint(), and UnselectItems().

◆ UnselectItem()

int SELECTION_TOOL::UnselectItem ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 768 of file selection_tool.cpp.

769 {
770  RemoveItemFromSel( aEvent.Parameter<BOARD_ITEM*>() );
771  return 0;
772 }
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 RemoveItemFromSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Definition: