KiCad PCB EDA Suite
SELECTION_TOOL Class Reference

Class 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...
 
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...
 
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...
 
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...
 
TOOL_SETTINGSGetSettings ()
 
bool IsToolActive () const
 

Protected Types

enum  INTERACTIVE_PLACEMENT_OPTIONS { IPO_ROTATE = 1, IPO_FLIP = 2, IPO_SINGLE_CLICK = 4, IPO_REPEAT = 8 }
 

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
 
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
 
TOOL_SETTINGS m_toolSettings
 

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 selectConnection (const TOOL_EVENT &aEvent)
 

Selects a trivial connection (between two junctions) of items in selection

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

Expands the current selection to select a connection between two junctions

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

Selects items with a continuous copper connection to items in selection

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 selectAllItemsConnectedToTrack (TRACK &aSourceTrack)
 Selects all items connected by copper tracks to the given TRACK This selects tracks and vias but stops at pads. More...
 
void selectAllItemsConnectedToItem (BOARD_CONNECTED_ITEM &aSourceItem)
 Selects all items connected (by copper) to the given item This selects tracks and vias and continues through pads without selecting. 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 name (the sheet path) 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.

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 clearSelection ()
 Function clearSelection() Clears the current selection. 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() Checks if the given point is placed within any of selected items' bounding box. 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
 
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

Class 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 63 of file selection_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Enumerator
IPO_ROTATE 
IPO_FLIP 
IPO_SINGLE_CLICK 
IPO_REPEAT 

Definition at line 109 of file pcb_tool_base.h.

◆ 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

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 }
std::unique_ptr< PRIV > m_priv
PCB_BASE_FRAME * m_frame
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:71

◆ ~SELECTION_TOOL()

SELECTION_TOOL::~SELECTION_TOOL ( )

Definition at line 126 of file selection_tool.cpp.

127 {
128  getView()->Remove( &m_selection );
129 }
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(), 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(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_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 674 of file selection_tool.cpp.

675 {
676  if( aItem )
677  {
678  select( aItem );
679 
680  // Inform other potentially interested tools
681  if( !aQuietMode )
683  }
684 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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  m_toolSettings = TOOL_SETTINGS( this );
64 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220
friend class TOOL_SETTINGS
Definition: tool_base.h:154

References TOOL_BASE::m_toolMgr, TOOL_BASE::m_toolSettings, and TOOL_BASE::TOOL_SETTINGS.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 151 of file pcb_tool_base.h.

151 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::changeTrackWidthOnClick(), ZONE_FILLER_TOOL::CheckAllZones(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), PCB_INSPECTION_TOOL::ClearHighlight(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PAD_TOOL::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ZONE_FILLER_TOOL::FillAllZones(), filterSelection(), getCollectorsGuide(), PCBNEW_CONTROL::GraphicDisplayMode(), PAD_TOOL::haveFootprints(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PCB_TOOL_BASE::module(), PCBNEW_CONTROL::ModuleEdgeOutlines(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), RebuildSelection(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), Selectable(), selectAllItemsConnectedToItem(), selectAllItemsConnectedToTrack(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectPoint(), DRC::testDisabledLayers(), DRC::TestZoneToZoneOutline(), PCBNEW_CONTROL::TrackDisplayMode(), 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 721 of file selection_tool.cpp.

722 {
723  highlight( aItem, BRIGHTENED );
724 }
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:143

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

590 {
591  if( !m_locked || m_editModules )
592  return SELECTION_UNLOCKED;
593 
594  bool containsLocked = false;
595 
596  // Check if the selection contains locked items
597  for( const auto& item : m_selection )
598  {
599  switch( item->Type() )
600  {
601  case PCB_MODULE_T:
602  if( static_cast<MODULE*>( item )->IsLocked() )
603  containsLocked = true;
604  break;
605 
606  case PCB_MODULE_EDGE_T:
607  case PCB_MODULE_TEXT_T:
608  if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
609  containsLocked = true;
610  break;
611 
612  default: // suppress warnings
613  break;
614  }
615  }
616 
617  if( containsLocked )
618  {
619  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
620  {
621  m_locked = false;
623  }
624  else
625  return SELECTION_LOCKED;
626  }
627 
628  return SELECTION_UNLOCKED;
629 }
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
#define _(s)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:294

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

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

◆ ClearSelection()

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 642 of file selection_tool.cpp.

643 {
644  clearSelection();
645 
646  return 0;
647 }
void clearSelection()
Function clearSelection() Clears the current selection.

References clearSelection().

Referenced by setTransitions().

◆ clearSelection()

void SELECTION_TOOL::clearSelection ( )
private

Function clearSelection() Clears the current selection.

Definition at line 1227 of file selection_tool.cpp.

1228 {
1229  if( m_selection.Empty() )
1230  return;
1231 
1232  while( m_selection.GetSize() )
1233  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1234 
1235  view()->Update( &m_selection );
1236 
1237  m_selection.SetIsHover( false );
1239 
1240  m_locked = true;
1241 
1242  // Inform other potentially interested tools
1245 }
void ClearReferencePoint()
Definition: selection.h:248
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:109
void SetIsHover(bool aIsHover)
Definition: selection.h:64
#define SELECTED
Definition: base_struct.h:127
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:198
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:417
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:98
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_ITEM * Front() const
Definition: selection.h:182

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

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

◆ controls()

◆ CursorSelection()

int SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Select a single item under cursor event handler.

Definition at line 632 of file selection_tool.cpp.

633 {
635 
636  selectCursor( false, aClientFilter );
637 
638  return 0;
639 }
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:427

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

Referenced by setTransitions().

◆ displayOptions()

◆ doInteractiveItemPlacement()

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

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

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

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

Definition at line 36 of file pcb_tool_base.cpp.

39 {
40  using namespace std::placeholders;
41  std::unique_ptr<BOARD_ITEM> newItem;
42 
43  frame()->PushTool( aTool );
44  Activate();
45 
46  BOARD_COMMIT commit( frame() );
47 
49 
50  // do not capture or auto-pan until we start placing an item
51  controls()->ShowCursor( true );
52  controls()->SetSnapping( true );
53 
54  // Add a VIEW_GROUP that serves as a preview for the new item
55  PCBNEW_SELECTION preview;
56  view()->Add( &preview );
57 
58  aPlacer->m_board = board();
59  aPlacer->m_frame = frame();
60  aPlacer->m_modifiers = 0;
61 
62  auto makeNewItem = [&] ( VECTOR2I aPosition )
63  {
64  if( frame()->GetModel() )
65  newItem = aPlacer->CreateItem();
66 
67  if( newItem )
68  {
69  newItem->SetPosition( (wxPoint) aPosition );
70  preview.Add( newItem.get() );
71 
72  if( newItem->Type() == PCB_MODULE_T )
73  {
74  auto module = dyn_cast<MODULE*>( newItem.get() );
75 
76  // modules have more drawable parts
77  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
78  }
79  }
80  };
81 
82  if( aOptions & IPO_SINGLE_CLICK )
83  makeNewItem( controls()->GetCursorPosition() );
84 
85  // Main loop: keep receiving events
86  while( TOOL_EVENT* evt = Wait() )
87  {
88  VECTOR2I cursorPos = controls()->GetCursorPosition();
89  aPlacer->m_modifiers = evt->Modifier();
90 
91  auto cleanup = [&] ()
92  {
93  newItem = nullptr;
94  preview.Clear();
95  view()->Update( &preview );
96  controls()->SetAutoPan( false );
97  controls()->CaptureCursor( false );
98  controls()->ShowCursor( true );
99  };
100 
101  if( evt->IsCancelInteractive() )
102  {
103  if( aOptions & IPO_SINGLE_CLICK )
104  {
105  cleanup();
106  frame()->PopTool( aTool );
107  break;
108  }
109  else if( newItem )
110  cleanup();
111  else
112  {
113  frame()->PopTool( aTool );
114  break;
115  }
116  }
117  else if( evt->IsActivate() )
118  {
119  if( newItem )
120  cleanup();
121 
122  if( evt->IsPointEditor() )
123  {
124  // don't exit (the point editor runs in the background)
125  }
126  else if( evt->IsMoveTool() )
127  {
128  // leave ourselves on the stack so we come back after the move
129  break;
130  }
131  else
132  {
133  frame()->PopTool( aTool );
134  break;
135  }
136  }
137  else if( evt->IsClick( BUT_LEFT ) )
138  {
139  if( !newItem )
140  {
141  // create the item if possible
142  makeNewItem( cursorPos );
143 
144  // no item created, so wait for another click
145  if( !newItem )
146  continue;
147 
148  controls()->CaptureCursor( true );
149  controls()->SetAutoPan( true );
150  }
151  else
152  {
153  auto oldFlags = newItem->GetFlags();
154  newItem->ClearFlags();
155 
156  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
157  {
158  newItem->SetFlags( oldFlags );
159  continue;
160  }
161 
162  preview.Clear();
163  newItem.release();
164  commit.Push( aCommitMessage );
165 
166  controls()->CaptureCursor( false );
167  controls()->SetAutoPan( false );
168  controls()->ShowCursor( true );
169 
170  if( !( aOptions & IPO_REPEAT ) )
171  break;
172 
173  if( aOptions & IPO_SINGLE_CLICK )
174  makeNewItem( controls()->GetCursorPosition() );
175  }
176  }
177  else if( evt->IsClick( BUT_RIGHT ) )
178  {
180  }
181  else if( newItem && evt->Category() == TC_COMMAND )
182  {
183  /*
184  * Handle any events that can affect the item as we move
185  * it around, eg rotate and flip
186  */
187 
188  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
189  {
190  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
191  newItem->Rotate( newItem->GetPosition(), rotationAngle );
192  view()->Update( &preview );
193  }
194  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
195  {
196  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
197  view()->Update( &preview );
198  }
199  }
200 
201  else if( newItem && evt->IsMotion() )
202  {
203  // track the cursor
204  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
205  aPlacer->SnapItem( newItem.get() );
206 
207  // Show a preview of the item
208  view()->Update( &preview );
209  }
210 
211  else
212  evt->SetPassEvent();
213  }
214 
215  view()->Remove( &preview );
216 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
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:93
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)
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
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
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:109
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:74
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
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PCB_GENERAL_SETTINGS & Settings()
Class TOOL_EVENT.
Definition: tool_event.h:168
KIGFX::PCB_VIEW * view() const
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.
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:115
KIGFX::VIEW_CONTROLS * controls() const
MODULE * module() const
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
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:58
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
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(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_EDIT_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, PCB_GENERAL_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, PCB_TOOL_BASE::module(), PCB_MODULE_T, INTERACTIVE_PLACER_BASE::PlaceItem(), EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), 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_TOOL_BASE::view(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint(), DRAWING_TOOL::DrawVia(), and MODULE_EDITOR_TOOLS::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 1283 of file selection_tool.cpp.

1284 {
1285  BOARD_ITEM* current = nullptr;
1286  PCBNEW_SELECTION highlightGroup;
1287  ACTION_MENU menu( true );
1288 
1289  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1290  getView()->Add( &highlightGroup );
1291 
1292  int limit = std::min( 9, aCollector->GetCount() );
1293 
1294  for( int i = 0; i < limit; ++i )
1295  {
1296  wxString text;
1297  BOARD_ITEM* item = ( *aCollector )[i];
1298  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1299 
1300  wxString menuText = wxString::Format("&%d. %s", i + 1, text );
1301  menu.Add( menuText, i + 1, item->GetMenuImage() );
1302  }
1303 
1304  if( aTitle.Length() )
1305  menu.SetTitle( aTitle );
1306 
1307  menu.SetIcon( info_xpm );
1308  menu.DisplayTitle( true );
1309  SetContextMenu( &menu, CMENU_NOW );
1310 
1311  while( TOOL_EVENT* evt = Wait() )
1312  {
1313  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1314  {
1315  if( current )
1316  unhighlight( current, BRIGHTENED, &highlightGroup );
1317 
1318  int id = *evt->GetCommandId();
1319 
1320  // User has pointed an item, so show it in a different way
1321  if( id > 0 && id <= limit )
1322  {
1323  current = ( *aCollector )[id - 1];
1324  highlight( current, BRIGHTENED, &highlightGroup );
1325  }
1326  else
1327  {
1328  current = NULL;
1329  }
1330  }
1331  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1332  {
1333  if( current )
1334  unhighlight( current, BRIGHTENED, &highlightGroup );
1335 
1336  OPT<int> id = evt->GetCommandId();
1337 
1338  // User has selected an item, so this one will be returned
1339  if( id && ( *id > 0 ) )
1340  current = ( *aCollector )[*id - 1];
1341  else
1342  current = NULL;
1343 
1344  break;
1345  }
1346  }
1347  getView()->Remove( &highlightGroup );
1348 
1349  if( current )
1350  {
1351  aCollector->Empty();
1352  aCollector->Append( current );
1353  return true;
1354  }
1355 
1356  return false;
1357 }
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Class ACTION_MENU.
Definition: action_menu.h:43
Class 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()
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
Class TOOL_EVENT.
Definition: tool_event.h:168
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
PCB_BASE_FRAME * m_frame
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
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
size_t i
Definition: json11.cpp:597
virtual wxString GetSelectMenuText(EDA_UNITS_T 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.
#define min(a, b)
Definition: auxiliary.h:85

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(), i, LAYER_SELECT_OVERLAY, m_frame, min, 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 selection to select a connection between two junctions

Definition at line 760 of file selection_tool.cpp.

761 {
762  // copy the selection, since we're going to iterate and modify
763  auto selection = m_selection.GetItems();
764 
765  // We use the BUSY flag to mark connections
766  for( auto item : selection )
767  item->SetState( BUSY, false );
768 
769  for( auto item : selection )
770  {
771  TRACK* trackItem = dynamic_cast<TRACK*>( item );
772 
773  // Track items marked BUSY have already been visited
774  // therefore their connections have already been marked
775  if( trackItem && !trackItem->GetState( BUSY ) )
776  {
777  if( aEvent.GetCommandId()
779  selectAllItemsConnectedToItem( *trackItem );
780  else
781  selectAllItemsConnectedToTrack( *trackItem );
782  }
783  }
784 
785  // Inform other potentially interested tools
786  if( m_selection.Size() > 0 )
788 
789  return 0;
790 }
OPT< int > GetCommandId() const
Definition: tool_event.h:450
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:140
const PCBNEW_SELECTION & selection() const
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:130
static TOOL_ACTION expandSelectedConnection
Expands the current selection to select a connection between two junctions.
Definition: pcb_actions.h:90
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
void selectAllItemsConnectedToTrack(TRACK &aSourceTrack)
Selects all items connected by copper tracks to the given TRACK This selects tracks and vias but stop...
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
int GetState(int type) const
Definition: base_struct.h:249
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item This selects tracks and vias and continues ...

References BUSY, PCB_ACTIONS::expandSelectedConnection, TOOL_EVENT::GetCommandId(), TOOL_ACTION::GetId(), SELECTION::GetItems(), EDA_ITEM::GetState(), m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), selectAllItemsConnectedToItem(), selectAllItemsConnectedToTrack(), EVENTS::SelectedEvent, PCB_TOOL_BASE::selection(), and SELECTION::Size().

Referenced by selectConnection(), and setTransitions().

◆ filterSelection()

int SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection

Definition at line 1193 of file selection_tool.cpp.

1194 {
1195  auto& opts = m_priv->m_filterOpts;
1196  DIALOG_BLOCK_OPTIONS dlg( m_frame, opts, false, _( "Filter selection" ) );
1197 
1198  const int cmd = dlg.ShowModal();
1199 
1200  if( cmd != wxID_OK )
1201  return 0;
1202 
1203  const auto& board = *getModel<BOARD>();
1204 
1205  // copy current selection
1206  auto selection = m_selection.GetItems();
1207 
1208  // clear current selection
1209  clearSelection();
1210 
1211  // copy selection items from the saved selection
1212  // according to the dialog options
1213  for( auto i : selection )
1214  {
1215  auto item = static_cast<BOARD_ITEM*>( i );
1216  bool include = itemIsIncludedByFilter( *item, board, opts );
1217 
1218  if( include )
1219  {
1220  select( item );
1221  }
1222  }
1223  return 0;
1224 }
BOARD * board() const
std::unique_ptr< PRIV > m_priv
PCBNEW_SELECTION m_selection
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
const PCBNEW_SELECTION & selection() const
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:130
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_BLOCK_OPTIONS::OPTIONS &aBlockOpts)
Function itemIsIncludedByFilter()
#define _(s)
size_t i
Definition: json11.cpp:597

References _, PCB_TOOL_BASE::board(), clearSelection(), SELECTION::GetItems(), i, itemIsIncludedByFilter(), m_frame, m_priv, m_selection, select(), and PCB_TOOL_BASE::selection().

Referenced by setTransitions().

◆ find()

int SELECTION_TOOL::find ( const TOOL_EVENT aEvent)
private

Find an item.

Definition at line 1100 of file selection_tool.cpp.

1101 {
1102  DIALOG_FIND dlg( m_frame );
1103  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1104  dlg.ShowModal();
1105 
1106  return 0;
1107 }
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 1083 of file selection_tool.cpp.

1084 {
1085  clearSelection();
1086 
1087  if( aItem )
1088  {
1089  select( aItem );
1090  m_frame->FocusOnLocation( aItem->GetPosition() );
1091 
1092  // Inform other potentially interested tools
1094  }
1095 
1097 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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
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).
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
virtual const wxPoint GetPosition() const =0
void FocusOnLocation(const wxPoint &aPos, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...

References clearSelection(), EDA_DRAW_FRAME::FocusOnLocation(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), BOARD_ITEM::GetPosition(), m_frame, 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 146 of file pcb_tool_base.h.

147  {
148  return getEditFrame<PCB_BASE_EDIT_FRAME>();
149  }

Referenced by POINT_EDITOR::addCorner(), MICROWAVE_TOOL::addMicrowaveFootprint(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), EDIT_TOOL::changeTrackWidthOnClick(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), MODULE_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::EnumeratePads(), PCB_EDITOR_CONTROL::ExportSpecctraDSN(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), MODULE_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), PAD_TOOL::Init(), Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCBNEW_PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), 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(), 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(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 361 of file selection_tool.cpp.

362 {
363  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
364  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
365 
366  // account for the globals
367  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
368  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
369  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
370  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
371  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
372  guide.SetIgnorePadsOnBack( ! board()->IsElementVisible( LAYER_PAD_BK ) );
373  guide.SetIgnorePadsOnFront( ! board()->IsElementVisible( LAYER_PAD_FR ) );
374  guide.SetIgnoreThroughHolePads( ! board()->IsElementVisible( LAYER_PADS_TH ) );
375  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
376  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
377  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIA_THROUGH ) );
378  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIA_BBLIND ) );
379  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIA_MICROVIA ) );
380  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
381 
382  return guide;
383 }
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*>( getEditFrameInt() ) );
191 #endif
192  return static_cast<T*>( getEditFrameInt() );
193  }
EDA_BASE_FRAME * getEditFrameInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getEditFrameInt().

Referenced by ZONE_CREATE_HELPER::createNewZone(), and TOOL_SETTINGS::getConfigBase().

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

◆ 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
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163

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_SETTINGS::getKeyName(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::invokeTool(), and TOOL_MANAGER::RegisterTool().

◆ GetSelection()

◆ GetSettings()

TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 78 of file tool_base.cpp.

79 {
80  return m_toolSettings;
81 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220

References TOOL_BASE::m_toolSettings.

Referenced by ROUTER_TOOL::Init(), GERBVIEW_SELECTION_TOOL::selectable(), and ROUTER_TOOL::~ROUTER_TOOL().

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

◆ 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:241
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(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), 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(), MICROWAVE_TOOL::drawMicrowaveInductor(), PL_DRAWING_TOOLS::DrawShape(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), COMMON_TOOLS::GridPreset(), 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(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), PL_EDIT_TOOL::moveItem(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), Selectable(), GERBVIEW_SELECTION_TOOL::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(), COMMON_TOOLS::ToggleGrid(), 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(), PCBNEW_CONTROL::updateGrid(), EE_POINT_EDITOR::updateItem(), PL_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_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:246

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(), 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(), COMMON_TOOLS::GridPreset(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), 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::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(), MICROWAVE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_CONTROL::setTransitions(), LIB_PIN_TOOL::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), COMMON_CONTROL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), SCH_MOVE_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), POINT_EDITOR::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), LIB_CONTROL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), MODULE_EDITOR_TOOLS::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), DRAWING_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), EE_SELECTION_TOOL::setTransitions(), and DRC::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 1855 of file selection_tool.cpp.

1857 {
1858  std::set<BOARD_ITEM*> preferred;
1859  std::set<BOARD_ITEM*> rejected;
1860  std::set<BOARD_ITEM*> forced;
1861  wxPoint where( aWhere.x, aWhere.y );
1862 
1863  // footprints which are below this percentage of the largest footprint will be considered
1864  // for selection; all others will not
1865  constexpr double footprintToFootprintMinRatio = 0.20;
1866  // pads which are below this percentage of their parent's area will exclude their parent
1867  constexpr double padToFootprintMinRatio = 0.45;
1868  // footprints containing items with items-to-footprint area ratio higher than this will be
1869  // forced to stay on the list
1870  constexpr double footprintMaxCoverRatio = 0.80;
1871  constexpr double viaToPadMinRatio = 0.50;
1872  constexpr double trackViaLengthRatio = 2.0;
1873  constexpr double trackTrackLengthRatio = 0.3;
1874  constexpr double textToFeatureMinRatio = 0.2;
1875  constexpr double textToFootprintMinRatio = 0.4;
1876  // If the common area of two compared items is above the following threshold, they cannot
1877  // be rejected (it means they overlap and it might be hard to pick one by selecting
1878  // its unique area).
1879  constexpr double commonAreaRatio = 0.6;
1880 
1881  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
1882  LSET silkLayers( 2, B_SilkS, F_SilkS );
1883 
1884  if( silkLayers[activeLayer] )
1885  {
1886  for( int i = 0; i < aCollector.GetCount(); ++i )
1887  {
1888  BOARD_ITEM* item = aCollector[i];
1889  KICAD_T type = item->Type();
1890 
1891  if( ( type == PCB_MODULE_TEXT_T || type == PCB_TEXT_T || type == PCB_LINE_T )
1892  && silkLayers[item->GetLayer()] )
1893  {
1894  preferred.insert( item );
1895  }
1896  }
1897 
1898  if( preferred.size() > 0 )
1899  {
1900  aCollector.Empty();
1901 
1902  for( BOARD_ITEM* item : preferred )
1903  aCollector.Append( item );
1904  return;
1905  }
1906  }
1907 
1908  int numZones = aCollector.CountType( PCB_ZONE_AREA_T );
1909 
1910  // Zone edges are very specific; zone fills much less so.
1911  if( numZones > 0 )
1912  {
1913  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1914  {
1915  if( aCollector[i]->Type() == PCB_ZONE_AREA_T )
1916  {
1917  auto zone = static_cast<ZONE_CONTAINER*>( aCollector[i] );
1918 
1919  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
1920  preferred.insert( zone );
1921  else
1922  rejected.insert( zone );
1923  }
1924  }
1925 
1926  if( preferred.size() > 0 )
1927  {
1928  aCollector.Empty();
1929 
1930  for( BOARD_ITEM* item : preferred )
1931  aCollector.Append( item );
1932  return;
1933  }
1934  }
1935 
1936  if( aCollector.CountType( PCB_MODULE_TEXT_T ) > 0 )
1937  {
1938  for( int i = 0; i < aCollector.GetCount(); ++i )
1939  {
1940  if( TEXTE_MODULE* txt = dyn_cast<TEXTE_MODULE*>( aCollector[i] ) )
1941  {
1942  double textArea = calcArea( txt );
1943 
1944  for( int j = 0; j < aCollector.GetCount(); ++j )
1945  {
1946  if( i == j )
1947  continue;
1948 
1949  BOARD_ITEM* item = aCollector[j];
1950  double itemArea = calcArea( item );
1951  double areaRatio = calcRatio( textArea, itemArea );
1952  double commonArea = calcCommonArea( txt, item );
1953  double itemCommonRatio = calcRatio( commonArea, itemArea );
1954  double txtCommonRatio = calcRatio( commonArea, textArea );
1955 
1956  if( item->Type() == PCB_MODULE_T )
1957  {
1958  // when text area is small compared to an overlapping footprint,
1959  // then it's a clear sign the text is the selection target
1960  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
1961  rejected.insert( item );
1962  }
1963 
1964  switch( item->Type() )
1965  {
1966  case PCB_TRACE_T:
1967  case PCB_PAD_T:
1968  case PCB_LINE_T:
1969  case PCB_VIA_T:
1970  case PCB_MODULE_T:
1971  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
1972  rejected.insert( txt );
1973  break;
1974  default:
1975  break;
1976  }
1977  }
1978  }
1979  }
1980  }
1981 
1982  if( aCollector.CountType( PCB_PAD_T ) > 0 )
1983  {
1984  for( int i = 0; i < aCollector.GetCount(); ++i )
1985  {
1986  if( D_PAD* pad = dyn_cast<D_PAD*>( aCollector[i] ) )
1987  {
1988  MODULE* parent = pad->GetParent();
1989  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
1990 
1991  // when pad area is small compared to the parent footprint,
1992  // then it is a clear sign the pad is the selection target
1993  if( ratio < padToFootprintMinRatio )
1994  rejected.insert( pad->GetParent() );
1995  }
1996  }
1997  }
1998 
1999  int moduleCount = aCollector.CountType( PCB_MODULE_T );
2000 
2001  if( moduleCount > 0 )
2002  {
2003  double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
2004  BOX2D viewportD = getView()->GetViewport();
2005  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2006  double maxCoverRatio = footprintMaxCoverRatio;
2007 
2008  // MODULE::CoverageRatio() doesn't take zone handles & borders into account so just
2009  // use a more aggressive cutoff point if zones are involved.
2010  if( aCollector.CountType( PCB_ZONE_AREA_T ) )
2011  maxCoverRatio /= 2;
2012 
2013  for( int i = 0; i < aCollector.GetCount(); ++i )
2014  {
2015  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
2016  {
2017  // filter out components larger than the viewport
2018  if( mod->ViewBBox().Contains( viewport ) )
2019  rejected.insert( mod );
2020  // footprints completely covered with other features have no other
2021  // means of selection, so must be kept
2022  else if( mod->CoverageRatio( aCollector ) > maxCoverRatio )
2023  rejected.erase( mod );
2024  // if a footprint is much smaller than the largest overlapping
2025  // footprint then it should be considered for selection
2026  else if( calcRatio( calcArea( mod ), maxArea ) <= footprintToFootprintMinRatio )
2027  continue;
2028  // if there are multiple footprints for selection at this point, prefer
2029  // one that is on the active layer
2030  else if( moduleCount > 1 && mod->GetLayer() == activeLayer )
2031  preferred.insert( mod );
2032  // reject ALL OTHER footprints if there's still something else left
2033  // to select
2034  else if( (int)( rejected.size() + 1 ) < aCollector.GetCount() )
2035  rejected.insert( mod );
2036  }
2037  }
2038  }
2039 
2040  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2041  {
2042  for( int i = 0; i < aCollector.GetCount(); ++i )
2043  {
2044  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2045  {
2046  double viaArea = calcArea( via );
2047 
2048  for( int j = 0; j < aCollector.GetCount(); ++j )
2049  {
2050  if( i == j )
2051  continue;
2052 
2053  BOARD_ITEM* item = aCollector[j];
2054  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2055 
2056  if( item->Type() == PCB_MODULE_T && areaRatio < padToFootprintMinRatio )
2057  rejected.insert( item );
2058 
2059  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2060  rejected.insert( item );
2061 
2062  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2063  {
2064  if( track->GetNetCode() != via->GetNetCode() )
2065  continue;
2066 
2067  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2068  (double) via->GetWidth();
2069 
2070  if( lenRatio > trackViaLengthRatio )
2071  rejected.insert( track );
2072  }
2073  }
2074  }
2075  }
2076  }
2077 
2078  int nTracks = aCollector.CountType( PCB_TRACE_T );
2079 
2080  if( nTracks > 0 )
2081  {
2082  double maxLength = 0.0;
2083  double minLength = std::numeric_limits<double>::max();
2084  double maxArea = 0.0;
2085  const TRACK* maxTrack = nullptr;
2086 
2087  for( int i = 0; i < aCollector.GetCount(); ++i )
2088  {
2089  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2090  {
2091  maxLength = std::max( track->GetLength(), maxLength );
2092  maxLength = std::max( (double) track->GetWidth(), maxLength );
2093 
2094  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2095 
2096  double area = track->GetLength() * track->GetWidth();
2097 
2098  if( area > maxArea )
2099  {
2100  maxArea = area;
2101  maxTrack = track;
2102  }
2103  }
2104  }
2105 
2106  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2107  {
2108  for( int i = 0; i < aCollector.GetCount(); ++i )
2109  {
2110  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2111  {
2112  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2113 
2114  if( ratio > trackTrackLengthRatio )
2115  rejected.insert( track );
2116  }
2117  }
2118  }
2119 
2120  for( int j = 0; j < aCollector.GetCount(); ++j )
2121  {
2122  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[j] ) )
2123  {
2124  double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() );
2125 
2126  if( ratio < padToFootprintMinRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio )
2127  rejected.insert( mod );
2128  }
2129  }
2130  }
2131 
2132  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2133  {
2134  for( BOARD_ITEM* item : rejected )
2135  {
2136  aCollector.Remove( item );
2137  }
2138  }
2139 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:122
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)
Class 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:100
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
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:587
int CountType(KICAD_T aType)
Function CountType counts the number of items matching aType.
Definition: collector.h:264
static double calcArea(const BOARD_ITEM *aItem)
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:142
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:95
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:132
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_LAYER_ID
A quick note on layer IDs:
Class 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:192
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
double calcRatio(double a, double b)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
const Vec & GetSize() const
Definition: box2.h:187
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.
#define mod(a, n)
Definition: greymap.cpp:24
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
#define min(a, b)
Definition: auxiliary.h:85

References COLLECTOR::Append(), B_SilkS, calcArea(), calcCommonArea(), calcMaxArea(), calcRatio(), COLLECTOR::CountType(), 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(), i, max, min, mod, COLLECTORS_GUIDE::OnePixelInIU(), PCB_LINE_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 1656 of file selection_tool.cpp.

1657 {
1658  if( aMode == SELECTED )
1659  aItem->SetSelected();
1660  else if( aMode == BRIGHTENED )
1661  aItem->SetBrightened();
1662 
1663  if( aGroup )
1664  {
1665  // Hide the original item, so it is shown only on overlay
1666  view()->Hide( aItem, true );
1667 
1668  aGroup->Add( aItem );
1669  }
1670 
1671  // Modules are treated in a special way - when they are highlighted, we have to
1672  // highlight all the parts that make the module, not the module itself
1673  if( aItem->Type() == PCB_MODULE_T )
1674  {
1675  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1676  {
1677  if( aMode == SELECTED )
1678  item->SetSelected();
1679  else if( aMode == BRIGHTENED )
1680  {
1681  item->SetBrightened();
1682 
1683  if( aGroup )
1684  aGroup->Add( item );
1685  }
1686 
1687  if( aGroup )
1688  view()->Hide( item, true );
1689  });
1690  }
1691 
1692  view()->Update( aItem );
1693 
1694  // Many selections are very temporal and updating the display each time just
1695  // creates noise.
1696  if( aMode == BRIGHTENED )
1698 }
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
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetBrightened()
Definition: base_struct.h:241
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
#define SELECTED
Definition: base_struct.h:127
class MODULE, a footprint
Definition: typeinfo.h:89
void SetSelected()
Definition: base_struct.h:239
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:143
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:210

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

133 {
134  auto frame = getEditFrame<PCB_BASE_FRAME>();
135 
138  {
140  return true;
141  }
142 
143  auto selectMenu = std::make_shared<SELECT_MENU>();
144  selectMenu->SetTool( this );
145  m_menu.AddSubMenu( selectMenu );
146 
147  auto& menu = m_menu.GetMenu();
148 
149  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
150  menu.AddSeparator( 1000 );
151 
152  if( frame )
154 
155  return true;
156 }
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_PCB_MODULE_VIEWER, FRAME_PCB_MODULE_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.

◆ Main()

int SELECTION_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

The main loop.

Definition at line 184 of file selection_tool.cpp.

185 {
186  // Main loop: keep receiving events
187  while( TOOL_EVENT* evt = Wait() )
188  {
189  if( m_frame->ToolStackIsEmpty() )
190  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
191 
192  bool dragAlwaysSelects = getEditFrame<PCB_BASE_FRAME>()->GetDragSelects();
194 
195  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
196  m_subtractive = true;
197  else if( evt->Modifier( MD_SHIFT ) )
198  m_additive = true;
199  else if( evt->Modifier( MD_CTRL ) )
200  m_exclusive_or = true;
201 
202  // Is the user requesting that the selection list include all possible
203  // items without removing less likely selection candidates
204  m_skip_heuristics = !!evt->Modifier( MD_ALT );
205 
206  // Single click? Select single object
207  if( evt->IsClick( BUT_LEFT ) )
208  {
209  selectPoint( evt->Position() );
210  }
211 
212  // right click? if there is any object - show the context menu
213  else if( evt->IsClick( BUT_RIGHT ) )
214  {
215  bool selectionCancelled = false;
216 
217  if( m_selection.Empty() )
218  {
219  selectPoint( evt->Position(), false, &selectionCancelled );
220  m_selection.SetIsHover( true );
221  }
222 
223  if( !selectionCancelled )
225  }
226 
227  // double click? Display the properties window
228  else if( evt->IsDblClick( BUT_LEFT ) )
229  {
230  if( m_selection.Empty() )
231  selectPoint( evt->Position() );
232 
234  }
235 
236  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
237  else if( evt->IsDrag( BUT_LEFT ) )
238  {
239  if( m_additive || m_subtractive || m_exclusive_or || dragAlwaysSelects )
240  {
241  selectMultiple();
242  }
243  else
244  {
245  // selection is empty? try to start dragging the item under the point where drag
246  // started
247  if( m_selection.Empty() && selectCursor() )
248  m_selection.SetIsHover( true );
249 
250  // Check if dragging has started within any of selected items bounding box
251  if( selectionContains( evt->Position() ) )
252  {
253  // Yes -> run the move tool and wait till it finishes
255  }
256  else
257  {
258  // No -> drag a selection box
259  selectMultiple();
260  }
261  }
262  }
263 
264  else if( evt->IsCancel() )
265  {
266  clearSelection();
267 
268  if( evt->FirstResponder() == this )
270  }
271 
272  else if( evt->Action() == TA_UNDO_REDO_PRE )
273  {
274  clearSelection();
275  }
276 
277  else
278  evt->SetPassEvent();
279  }
280 
281  // This tool is supposed to be active forever
282  assert( false );
283 
284  return 0;
285 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
static TOOL_ACTION move
move an item
Definition: pcb_actions.h:108
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.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
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:109
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
void SetIsHover(bool aIsHover)
Definition: selection.h:64
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...
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
Class TOOL_EVENT.
Definition: tool_event.h:168
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:404
bool ToolStackIsEmpty()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59

References BUT_LEFT, BUT_RIGHT, PCB_ACTIONS::clearHighlight, clearSelection(), SELECTION::Empty(), PCB_BASE_FRAME::GetCanvas(), 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::move, PCB_ACTIONS::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TA_UNDO_REDO_PRE, EDA_BASE_FRAME::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 1360 of file selection_tool.cpp.

1361 {
1362  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1363 
1364  if( 0 == count )
1365  count = aCollector->GetCount();
1366 
1367  for( int i = 0; i < count; ++i )
1368  {
1369  if( ( *aCollector )[i]->Type() != PCB_MODULE_T )
1370  return NULL;
1371  }
1372 
1373  // All are modules, now find smallest MODULE
1374  int minDim = 0x7FFFFFFF;
1375  int minNdx = 0;
1376 
1377  for( int i = 0; i < count; ++i )
1378  {
1379  MODULE* module = (MODULE*) ( *aCollector )[i];
1380 
1381  int lx = module->GetFootprintRect().GetWidth();
1382  int ly = module->GetFootprintRect().GetHeight();
1383 
1384  int lmin = std::min( lx, ly );
1385 
1386  if( lmin < minDim )
1387  {
1388  minDim = lmin;
1389  minNdx = i;
1390  }
1391  }
1392 
1393  return (*aCollector)[minNdx];
1394 }
int GetWidth() const
Definition: eda_rect.h:117
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:113
class MODULE, a footprint
Definition: typeinfo.h:89
int GetHeight() const
Definition: eda_rect.h:118
MODULE * module() const
size_t i
Definition: json11.cpp:597
#define min(a, b)
Definition: auxiliary.h:85

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

1249 {
1250  m_selection.Clear();
1251 
1252  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1253  {
1254  if( item->IsSelected() )
1255  {
1256  EDA_ITEM* parent = item->GetParent();
1257 
1258  // Flags on module children might be set only because the parent is selected.
1259  if( parent && parent->Type() == PCB_MODULE_T && parent->IsSelected() )
1260  return SEARCH_CONTINUE;
1261 
1262  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1263  }
1264 
1265  return SEARCH_CONTINUE;
1266  };
1267 
1268  board()->Visit( inspector, nullptr, m_editModules ? GENERAL_COLLECTOR::ModuleItems
1270 }
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
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:83
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:233
Class 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:127
class MODULE, a footprint
Definition: typeinfo.h:89
EDA_ITEM * GetParent() const
Definition: base_struct.h:220
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), SELECTION::Clear(), EDA_ITEM::GetParent(), highlight(), EDA_ITEM::IsSelected(), PCB_TOOL_BASE::m_editModules, m_selection, GENERAL_COLLECTOR::ModuleItems, PCB_MODULE_T, SEARCH_CONTINUE, SELECTED, EDA_ITEM::Type(), and BOARD::Visit().

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

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

297 {
298  bool selectionEmpty = m_selection.Empty();
299  m_selection.SetIsHover( selectionEmpty );
300 
301  if( selectionEmpty )
302  {
303  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
305  }
306 
307  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
308  {
309  clearSelection();
310  }
311 
312  if( aClientFilter )
313  {
314  GENERAL_COLLECTOR collector;
315 
316  for( auto item : m_selection )
317  collector.Append( item );
318 
319  aClientFilter( VECTOR2I(), collector );
320 
321  /*
322  * The first step is to find the items that may have been added by the client filter
323  * This can happen if the locked pads select the module instead
324  */
325  std::vector<EDA_ITEM*> new_items;
326  std::set_difference( collector.begin(), collector.end(),
328  std::back_inserter( new_items ) );
329 
333  std::vector<EDA_ITEM*> diff;
334  std::set_difference( m_selection.begin(), m_selection.end(),
335  collector.begin(), collector.end(),
336  std::back_inserter( diff ) );
337 
338  if( aFiltered )
339  {
340  for( auto item : diff )
341  aFiltered->push_back( static_cast<BOARD_ITEM*>( item ) );
342  }
343 
348  for( auto item : diff )
349  unhighlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
350 
351  for( auto item : new_items )
352  highlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
353 
355  }
356 
357  return m_selection;
358 }
void ClearReferencePoint()
Definition: selection.h:248
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:60
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:109
ITER end()
Definition: collector.h:92
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void SetIsHover(bool aIsHover)
Definition: selection.h:64
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:132
#define SELECTED
Definition: base_struct.h:127
ITER begin()
Definition: selection.h:59
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
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:70
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::copyToClipboard(), EDIT_TOOL::CreateArray(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::Duplicate(), EDIT_TOOL::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 159 of file selection_tool.cpp.

160 {
161  m_frame = getEditFrame<PCB_BASE_FRAME>();
162  m_locked = true;
163 
164  if( aReason == TOOL_BASE::MODEL_RELOAD )
165  {
166  // Remove pointers to the selected items from containers
167  // without changing their properties (as they are already deleted
168  // while a new board is loaded)
169  m_selection.Clear();
170  getView()->GetPainter()->GetSettings()->SetHighlight( false );
171  }
172  else
173  {
174  // Restore previous properties of selected items and remove them from containers
175  clearSelection();
176  }
177 
178  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
179  view()->Remove( &m_selection );
180  view()->Add( &m_selection );
181 }
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:93
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
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aHighlightItems=false)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer,...
Definition: painter.h:141
KIGFX::PCB_VIEW * view() const
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
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(), SELECTION::Clear(), 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 1626 of file selection_tool.cpp.

1627 {
1628  if( aItem->IsSelected() )
1629  {
1630  return;
1631  }
1632 
1633  if( aItem->Type() == PCB_PAD_T )
1634  {
1635  MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
1636 
1637  if( m_selection.Contains( module ) )
1638  return;
1639  }
1640 
1641  highlight( aItem, SELECTED, &m_selection );
1642  view()->Update( &m_selection );
1643 }
bool IsSelected() const
Definition: base_struct.h:233
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
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:127
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:111
KIGFX::PCB_VIEW * view() const
MODULE * module() const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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

Referenced by AddItemToSel(), filterSelection(), findCallback(), selectAllItemsConnectedToItem(), selectAllItemsConnectedToTrack(), selectAllItemsOnNet(), selectAllItemsOnSheet(), 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 1397 of file selection_tool.cpp.

1398 {
1399  // Is high contrast mode enabled?
1400  bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast();
1401 
1402  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
1403 
1404  // Filter out items that do not belong to active layers
1405  std::set<unsigned int> activeLayers = getView()->GetPainter()->GetSettings()->GetActiveLayers();
1406 
1407  // The markers layer is considered to be always active
1408  activeLayers.insert( (unsigned int) LAYER_DRC );
1409 
1410  aItem->ViewGetLayers( layers, layers_count );
1411 
1412  if( highContrast )
1413  {
1414  bool onActive = false; // Is the item on any of active layers?
1415 
1416  for( int i = 0; i < layers_count; ++i )
1417  {
1418  if( activeLayers.count( layers[i] ) > 0 ) // Item is on at least one of the active layers
1419  {
1420  onActive = true;
1421  break;
1422  }
1423  }
1424 
1425  if( !onActive ) // We do not want to select items that are in the background
1426  {
1427  return false;
1428  }
1429  }
1430 
1431  switch( aItem->Type() )
1432  {
1433  case PCB_ZONE_AREA_T:
1434  // Keepout zones can exist on multiple layers!
1435  {
1436  auto* zone = static_cast<const ZONE_CONTAINER*>( aItem );
1437 
1438  if( zone->GetIsKeepout() )
1439  {
1440  auto zoneLayers = zone->GetLayerSet().Seq();
1441 
1442  for( unsigned int i = 0; i < zoneLayers.size(); i++ )
1443  {
1444  if( board()->IsLayerVisible( zoneLayers[i] ) )
1445  {
1446  return true;
1447  }
1448  }
1449 
1450  // No active layers selected!
1451  return false;
1452  }
1453  }
1454  break;
1455 
1456  case PCB_TRACE_T:
1457  {
1458  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1459  return false;
1460  }
1461  break;
1462 
1463  case PCB_VIA_T:
1464  {
1465  const VIA* via = static_cast<const VIA*>( aItem );
1466 
1467  // Check if appropriate element layer is visible
1468  switch( via->GetViaType() )
1469  {
1470  case VIA_THROUGH:
1472  return false;
1473  break;
1474 
1475  case VIA_BLIND_BURIED:
1477  return false;
1478  break;
1479 
1480  case VIA_MICROVIA:
1482  return false;
1483  break;
1484 
1485  default:
1486  wxFAIL;
1487  return false;
1488  }
1489 
1490  // For vias it is enough if only one of its layers is visible
1491  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1492  }
1493 
1494  case PCB_MODULE_T:
1495  {
1496  // In modedit, we do not want to select the module itself.
1497  if( m_editModules )
1498  return false;
1499 
1500  // Allow selection of footprints if some part of the footprint is visible.
1501 
1502  MODULE* module = const_cast<MODULE*>( static_cast<const MODULE*>( aItem ) );
1503 
1504  for( auto item : module->GraphicalItems() )
1505  {
1506  if( Selectable( item, true ) )
1507  return true;
1508  }
1509 
1510  for( auto pad : module->Pads() )
1511  {
1512  if( Selectable( pad, true ) )
1513  return true;
1514  }
1515 
1516  return false;
1517  }
1518 
1519  case PCB_MODULE_TEXT_T:
1520  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1521  // module subparts one by one, rather than with a drag selection. This is so you can
1522  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1523  if( !m_editModules && !checkVisibilityOnly )
1524  {
1525  if( m_multiple )
1526  return false;
1527  }
1528 
1529  if( !m_editModules && !view()->IsVisible( aItem ) )
1530  return false;
1531 
1532  break;
1533 
1534  case PCB_MODULE_EDGE_T:
1535  case PCB_PAD_T:
1536  {
1537  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1538  // module subparts one by one, rather than with a drag selection. This is so you can
1539  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1540  if( !m_editModules && !checkVisibilityOnly )
1541  {
1542  if( m_multiple )
1543  return false;
1544  }
1545 
1546  if( aItem->Type() == PCB_PAD_T )
1547  {
1548  auto pad = static_cast<const D_PAD*>( aItem );
1549 
1550  // In pcbnew, locked modules prevent individual pad selection.
1551  // In modedit, we don't enforce this as the module is assumed to be edited by design.
1552  if( !m_editModules && !checkVisibilityOnly )
1553  {
1554  if( pad->GetParent() && pad->GetParent()->IsLocked() )
1555  return false;
1556  }
1557 
1558  // Check render mode (from the Items tab) first
1559  switch( pad->GetAttribute() )
1560  {
1561  case PAD_ATTRIB_STANDARD:
1563  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1564  return false;
1565  break;
1566 
1567  case PAD_ATTRIB_CONN:
1568  case PAD_ATTRIB_SMD:
1569  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1570  return false;
1571  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1572  return false;
1573  break;
1574  }
1575 
1576  // Otherwise, pads are selectable if any draw layer is visible
1577 
1578  // Shortcut: check copper layer visibility
1579  if( board()->IsLayerVisible( F_Cu ) && pad->IsOnLayer( F_Cu ) )
1580  return true;
1581 
1582  if( board()->IsLayerVisible( B_Cu ) && pad->IsOnLayer( B_Cu ) )
1583  return true;
1584 
1585  // Now check the non-copper layers
1586 
1587  bool draw_layer_visible = false;
1588 
1589  int pad_layers[KIGFX::VIEW::VIEW_MAX_LAYERS], pad_layers_count;
1590  pad->ViewGetLayers( pad_layers, pad_layers_count );
1591 
1592  for( int i = 0; i < pad_layers_count; ++i )
1593  {
1594  // NOTE: Only checking the regular layers (not GAL meta-layers)
1595  if( ( ( pad_layers[i] < PCB_LAYER_ID_COUNT ) &&
1596  board()->IsLayerVisible( static_cast<PCB_LAYER_ID>( pad_layers[i] ) ) ) )
1597  {
1598  draw_layer_visible = true;
1599  }
1600  }
1601 
1602  return draw_layer_visible;
1603  }
1604 
1605  break;
1606  }
1607 
1608 
1609  case PCB_MARKER_T: // Always selectable
1610  return true;
1611 
1612  // These are not selectable
1613  case NOT_USED:
1614  case TYPE_NOT_INIT:
1615  return false;
1616 
1617  default: // Suppress warnings
1618  break;
1619  }
1620 
1621  // All other items are selected only if the layer on which they exist is visible
1622  return board()->IsLayerVisible( aItem->GetLayer() );
1623 }
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:66
multilayer pads, usually with holes
the 3d code uses this value
Definition: typeinfo.h:80
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
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:163
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:173
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:95
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
VIATYPE_T GetViaType() const
Definition: class_track.h:346
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
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
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:163
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings 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 ...
Definition: class_board.h:459
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:97
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.
size_t i
Definition: json11.cpp:597
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
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:210
const std::set< unsigned int > GetActiveLayers()
Function GetActiveLayers() Returns the set of currently active layers.
Definition: painter.h:89

References B_Cu, PCB_TOOL_BASE::board(), F_Cu, KIGFX::RENDER_SETTINGS::GetActiveLayers(), KIGFX::RENDER_SETTINGS::GetHighContrast(), BOARD_ITEM::GetLayer(), VIA::GetLayerSet(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), VIA::GetViaType(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), MODULE::GraphicalItems(), i, BOARD::IsElementVisible(), BOARD::IsLayerVisible(), KIGFX::VIEW::IsVisible(), LAYER_DRC, 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, PCB_TOOL_BASE::module(), NOT_USED, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, MODULE::Pads(), PCB_LAYER_ID_COUNT, PCB_MARKER_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, EDA_ITEM::Type(), TYPE_NOT_INIT, VIA_BLIND_BURIED, VIA_MICROVIA, VIA_THROUGH, PCB_TOOL_BASE::view(), KIGFX::VIEW::VIEW_MAX_LAYERS, and BOARD_ITEM::ViewGetLayers().

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

◆ selectAllItemsConnectedToItem()

void SELECTION_TOOL::selectAllItemsConnectedToItem ( BOARD_CONNECTED_ITEM aSourceItem)
private

Selects all items connected (by copper) to the given item This selects tracks and vias and continues through pads without selecting.

Definition at line 856 of file selection_tool.cpp.

857 {
858  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_PAD_T, EOT };
859  auto connectivity = board()->GetConnectivity();
860 
861  for( auto item : connectivity->GetConnectedItems( &aSourceItem, types ) )
862  {
863  // We want to select items connected through pads but not pads
864  // otherwise, the common use case of "Select Copper"->Delete will
865  // remove footprints in addition to traces and vias
866  if( item->Type() != PCB_PAD_T )
867  select( item );
868  }
869 }
BOARD * board() const
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
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:95
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:310
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

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

Referenced by expandConnection(), selectAllItemsOnSheet(), and selectCopper().

◆ selectAllItemsConnectedToTrack()

void SELECTION_TOOL::selectAllItemsConnectedToTrack ( TRACK aSourceTrack)
private

Selects all items connected by copper tracks to the given TRACK This selects tracks and vias but stops at pads.

Definition at line 845 of file selection_tool.cpp.

846 {
847  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
848  auto connectivity = board()->GetConnectivity();
849 
850  for( auto item : connectivity->GetConnectedItems(
851  static_cast<BOARD_CONNECTED_ITEM*>( &aSourceTrack ), types ) )
852  select( item );
853 }
BOARD * board() const
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:95
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:310
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

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

Referenced by expandConnection().

◆ selectAllItemsOnNet()

void SELECTION_TOOL::selectAllItemsOnNet ( int  aNetCode)
private

Selects all items with the given net code.

Definition at line 872 of file selection_tool.cpp.

873 {
874  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
875  auto connectivity = board()->GetConnectivity();
876 
877  for( auto item : connectivity->GetNetItems( aNetCode, types ) )
878  select( item );
879 }
BOARD * board() const
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:95
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:310
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

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 name (the sheet path)

Definition at line 911 of file selection_tool.cpp.

912 {
913  std::list<MODULE*> modList;
914 
915  // store all modules that are on that sheet
916  for( auto mitem : board()->Modules() )
917  {
918  if( mitem != NULL && mitem->GetPath().Contains( aSheetpath ) )
919  {
920  modList.push_back( mitem );
921  }
922  }
923 
924  //Generate a list of all pads, and of all nets they belong to.
925  std::list<int> netcodeList;
926  std::list<BOARD_CONNECTED_ITEM*> padList;
927  for( MODULE* mmod : modList )
928  {
929  for( auto pad : mmod->Pads() )
930  {
931  if( pad->IsConnected() )
932  {
933  netcodeList.push_back( pad->GetNetCode() );
934  padList.push_back( pad );
935  }
936  }
937  }
938  // remove all duplicates
939  netcodeList.sort();
940  netcodeList.unique();
941 
942  // auto select trivial connections segments which are launched from the pads
943  std::list<TRACK*> launchTracks;
944 
945  for( auto pad : padList )
946  {
948  }
949 
950  // now we need to find all modules that are connected to each of these nets
951  // then we need to determine if these modules are in the list of modules
952  // belonging to this sheet ( modList )
953  std::list<int> removeCodeList;
954  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
955 
956  for( int netCode : netcodeList )
957  {
958  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
959  {
960  if( mitem->Type() == PCB_PAD_T)
961  {
962  bool found = ( std::find( modList.begin(), modList.end(),
963  mitem->GetParent() ) != modList.end() );
964 
965  if( !found )
966  {
967  // if we cannot find the module of the pad in the modList
968  // then we can assume that that module is not located in the same
969  // schematic, therefore invalidate this netcode.
970  removeCodeList.push_back( netCode );
971  break;
972  }
973  }
974  }
975  }
976 
977  // remove all duplicates
978  removeCodeList.sort();
979  removeCodeList.unique();
980 
981  for( int removeCode : removeCodeList )
982  {
983  netcodeList.remove( removeCode );
984  }
985 
986  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
987  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
988 
989  for( int netCode : netcodeList )
990  {
991  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
992  {
993  localConnectionList.push_back( item );
994  }
995  }
996 
997  for( BOARD_ITEM* i : modList )
998  {
999  if( i != NULL )
1000  select( i );
1001  }
1002 
1003  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1004  {
1005  if( i != NULL )
1006  select( i );
1007  }
1008 }
BOARD * board() const
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
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:95
size_t i
Definition: json11.cpp:597
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item This selects tracks and vias and continues ...

References PCB_TOOL_BASE::board(), EOT, i, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), and selectAllItemsConnectedToItem().

Referenced by selectSameSheet(), and selectSheetContents().

◆ selectConnection()

int SELECTION_TOOL::selectConnection ( const TOOL_EVENT aEvent)
private

Selects a trivial connection (between two junctions) of items in selection

Definition at line 748 of file selection_tool.cpp.

749 {
752 
754  return 0;
755 
756  return expandConnection( aEvent );
757 }
void connectedTrackFilter(const VECTOR2I &aPt, GENERAL_COLLECTOR &aCollector)
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
Definition: selection.h:212
PCBNEW_SELECTION m_selection
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
int expandConnection(const TOOL_EVENT &aEvent)
Expands the current selection to select a connection between two junctions
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...
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

References connectedTrackFilter(), expandConnection(), SELECTION::HasType(), m_selection, PCB_TRACE_T, PCB_VIA_T, and selectCursor().

Referenced by setTransitions().

◆ selectCopper()

int SELECTION_TOOL::selectCopper ( const TOOL_EVENT aEvent)
private

Selects items with a continuous copper connection to items in selection

Definition at line 813 of file selection_tool.cpp.

814 {
815  bool haveCopper = false;
816 
817  for( auto item : m_selection.GetItems() )
818  {
819  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
820  haveCopper = true;;
821  }
822 
823  if( !haveCopper )
825 
826  // copy the selection, since we're going to iterate and modify
827  auto selection = m_selection.GetItems();
828 
829  for( auto item : selection )
830  {
831  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item );
832 
833  if( connItem )
834  selectAllItemsConnectedToItem( *connItem );
835  }
836 
837  // Inform other potentially interested tools
838  if( m_selection.Size() > 0 )
840 
841  return 0;
842 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
const PCBNEW_SELECTION & selection() const
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:130
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item This selects tracks and vias and continues ...

References connectedItemFilter(), SELECTION::GetItems(), m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), selectAllItemsConnectedToItem(), selectCursor(), EVENTS::SelectedEvent, PCB_TOOL_BASE::selection(), and SELECTION::Size().

Referenced by setTransitions().

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

461 {
462  if( aForceSelect || m_selection.Empty() )
463  {
464  clearSelection();
465  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
466  }
467 
468  return !m_selection.Empty();
469 }
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.
void clearSelection()
Function clearSelection() Clears the current selection.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42

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

Referenced by CursorSelection(), Main(), selectConnection(), selectCopper(), selectNet(), and selectSameSheet().

◆ selection() [1/2]

const PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 257 of file pcb_tool_base.cpp.

258 {
259  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
260  const auto& selection = selTool->GetSelection();
261  return selection;
262 }
Class 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::changeTrackWidthOnClick(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), 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(), EDIT_TOOL::EditFpInFpEditor(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), 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(), selectCopper(), 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 265 of file pcb_tool_base.cpp.

266 {
267  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
268  auto& selection = selTool->GetSelection();
269  return selection;
270 }
Class 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() Checks if the given point is placed within any of selected items' bounding box.

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

Definition at line 1748 of file selection_tool.cpp.

1749 {
1750  const unsigned GRIP_MARGIN = 20;
1751  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1752 
1753  // Check if the point is located within any of the currently selected items bounding boxes
1754  for( auto item : m_selection )
1755  {
1756  BOX2I itemBox = item->ViewBBox();
1757  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1758 
1759  if( itemBox.Contains( aPoint ) )
1760  return true;
1761  }
1762 
1763  return false;
1764 }
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:587
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
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:300

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

1274 {
1275  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1276 
1277  doSelectionMenu( collector, wxEmptyString );
1278 
1279  return 0;
1280 }
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
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 667 of file selection_tool.cpp.

668 {
669  AddItemToSel( aEvent.Parameter<BOARD_ITEM*>() );
670  return 0;
671 }
Class 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:427
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 650 of file selection_tool.cpp.

651 {
652  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
653 
654  if( items )
655  {
656  // Perform individual selection of each item before processing the event.
657  for( auto item : *items )
658  select( item );
659 
661  }
662 
663  return 0;
664 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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:427

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

473 {
474  bool cancelled = false; // Was the tool cancelled while it was running?
475  m_multiple = true; // Multiple selection mode is active
476  KIGFX::VIEW* view = getView();
477 
479  view->Add( &area );
480 
481  while( TOOL_EVENT* evt = Wait() )
482  {
483  if( evt->IsCancelInteractive() || evt->IsActivate() )
484  {
485  cancelled = true;
486  break;
487  }
488 
489  if( evt->IsDrag( BUT_LEFT ) )
490  {
492  clearSelection();
493 
494  // Start drawing a selection box
495  area.SetOrigin( evt->DragOrigin() );
496  area.SetEnd( evt->Position() );
497  area.SetAdditive( m_additive );
500 
501  view->SetVisible( &area, true );
502  view->Update( &area );
503  getViewControls()->SetAutoPan( true );
504  }
505 
506  if( evt->IsMouseUp( BUT_LEFT ) )
507  {
508  getViewControls()->SetAutoPan( false );
509 
510  // End drawing the selection box
511  view->SetVisible( &area, false );
512 
513  // Mark items within the selection box as selected
514  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
515 
516  // Filter the view items based on the selection box
517  BOX2I selectionBox = area.ViewBBox();
518  view->Query( selectionBox, selectedItems ); // Get the list of selected items
519 
520  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
521 
522  int width = area.GetEnd().x - area.GetOrigin().x;
523  int height = area.GetEnd().y - area.GetOrigin().y;
524 
525  /* Selection mode depends on direction of drag-selection:
526  * Left > Right : Select objects that are fully enclosed by selection
527  * Right > Left : Select objects that are crossed by selection
528  */
529  bool windowSelection = width >= 0 ? true : false;
530  bool anyAdded = false;
531  bool anySubtracted = false;
532 
533  if( view->IsMirroredX() )
534  windowSelection = !windowSelection;
535 
536  // Construct an EDA_RECT to determine BOARD_ITEM selection
537  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
538 
539  selectionRect.Normalize();
540 
541  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
542  {
543  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
544 
545  if( !item || !Selectable( item ) )
546  continue;
547 
548  if( item->HitTest( selectionRect, windowSelection ) )
549  {
550  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
551  {
552  unselect( item );
553  anySubtracted = true;
554  }
555  else
556  {
557  select( item );
558  anyAdded = true;
559  }
560  }
561  }
562 
563  m_selection.SetIsHover( false );
564 
565  // Inform other potentially interested tools
566  if( anyAdded )
568 
569  if( anySubtracted )
571 
572  break; // Stop waiting for events
573  }
574  }
575 
576  getViewControls()->SetAutoPan( false );
577 
578  // Stop drawing the selection box
579  view->Remove( &area );
580  m_multiple = false; // Multiple selection mode is inactive
581 
582  if( !cancelled )
584 
585  return cancelled;
586 }
void ClearReferencePoint()
Definition: selection.h:248
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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:233
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
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
Class 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
void SetIsHover(bool aIsHover)
Definition: selection.h:64
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:339
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
Class TOOL_EVENT.
Definition: tool_event.h:168
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
KIGFX::PCB_VIEW * view() const
void clearSelection()
Function clearSelection() Clears the current selection.
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)
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.
Class 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
Class SELECTION_AREA.
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
Class 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(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), EDA_ITEM::HitTest(), KIGFX::VIEW::IsMirroredX(), EDA_ITEM::IsSelected(), 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 882 of file selection_tool.cpp.

883 {
884  if( !selectCursor() )
885  return 0;
886 
887  // copy the selection, since we're going to iterate and modify
888  auto selection = m_selection.GetItems();
889 
890  for( auto i : selection )
891  {
892  auto item = static_cast<BOARD_ITEM*>( i );
893 
894  // only connected items get a net code
895  if( item->IsConnected() )
896  {
897  auto& connItem = static_cast<BOARD_CONNECTED_ITEM&>( *item );
898 
899  selectAllItemsOnNet( connItem.GetNetCode() );
900  }
901  }
902 
903  // Inform other potentially interested tools
904  if( m_selection.Size() > 0 )
906 
907  return 0;
908 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
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:130
size_t i
Definition: json11.cpp:597
int Size() const
Returns the number of selected parts.
Definition: selection.h:125

References SELECTION::GetItems(), i, 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 386 of file selection_tool.cpp.

389 {
390  auto guide = getCollectorsGuide();
391  GENERAL_COLLECTOR collector;
392  auto displayOpts = (PCB_DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
393 
394  guide.SetIgnoreZoneFills( displayOpts->m_DisplayZonesMode != 0 );
395 
396  collector.Collect( board(),
398  wxPoint( aWhere.x, aWhere.y ), guide );
399 
400  // Remove unselectable items
401  for( int i = collector.GetCount() - 1; i >= 0; --i )
402  {
403  if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
404  collector.Remove( i );
405  }
406 
408 
409  // Allow the client to do tool- or action-specific filtering to see if we
410  // can get down to a single item
411  if( aClientFilter )
412  aClientFilter( aWhere, collector );
413 
414  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
415  if( collector.GetCount() > 1 && !m_skip_heuristics )
416  {
417  GuessSelectionCandidates( collector, aWhere );
418  }
419 
420  // If still more than one item we're going to have to ask the user.
421  if( collector.GetCount() > 1 )
422  {
423  if( aOnDrag )
425 
426  if( !doSelectionMenu( &collector, _( "Clarify Selection" ) ) )
427  {
428  if( aSelectionCancelledFlag )
429  *aSelectionCancelledFlag = true;
430 
431  return false;
432  }
433  }
434 
436  clearSelection();
437 
438  if( collector.GetCount() == 1 )
439  {
440  BOARD_ITEM* item = collector[ 0 ];
441 
442  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
443  {
444  unselect( item );
446  return false;
447  }
448  else
449  {
450  select( item );
452  return true;
453  }
454  }
455 
456  return false;
457 }
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:248
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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
bool IsSelected() const
Definition: base_struct.h:233
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
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:474
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
PCBNEW_SELECTION m_selection
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:142
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
Class TOOL_EVENT.
Definition: tool_event.h:168
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
#define _(s)
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
size_t i
Definition: json11.cpp:597
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.

References _, GENERAL_COLLECTOR::AllBoardItems, PCB_TOOL_BASE::board(), BUT_LEFT, SELECTION::ClearReferencePoint(), clearSelection(), GENERAL_COLLECTOR::Collect(), doSelectionMenu(), getCollectorsGuide(), COLLECTOR::GetCount(), PCB_BASE_FRAME::GetDisplayOptions(), GuessSelectionCandidates(), i, EDA_ITEM::IsSelected(), 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, 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.

Definition at line 1049 of file selection_tool.cpp.

1050 {
1051  if( !selectCursor( true ) )
1052  return 0;
1053 
1054  // this function currently only supports modules since they are only
1055  // on one sheet.
1056  auto item = m_selection.Front();
1057 
1058  if( !item )
1059  return 0;
1060 
1061  if( item->Type() != PCB_MODULE_T )
1062  return 0;
1063 
1064  auto mod = dynamic_cast<MODULE*>( item );
1065 
1066  clearSelection();
1067 
1068  // get the lowest subsheet name for this.
1069  wxString sheetPath = mod->GetPath();
1070  sheetPath = sheetPath.BeforeLast( '/' );
1071  sheetPath = sheetPath.AfterLast( '/' );
1072 
1073  selectAllItemsOnSheet( sheetPath );
1074 
1075  // Inform other potentially interested tools
1076  if( m_selection.Size() > 0 )
1078 
1079  return 0;
1080 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
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...
void selectAllItemsOnSheet(wxString &aSheetpath)
Selects all items with the given sheet timestamp name (the sheet path)
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void clearSelection()
Function clearSelection() Clears the current selection.
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
#define mod(a, n)
Definition: greymap.cpp:24
EDA_ITEM * Front() const
Definition: selection.h:182

References clearSelection(), SELECTION::Front(), m_selection, TOOL_BASE::m_toolMgr, mod, 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 1033 of file selection_tool.cpp.

1034 {
1035  clearSelection();
1036  wxString* sheetpath = aEvent.Parameter<wxString*>();
1037 
1038  selectAllItemsOnSheet( *sheetpath );
1039 
1040  zoomFitSelection();
1041 
1042  if( m_selection.Size() > 0 )
1044 
1045  return 0;
1046 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:196
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
PCBNEW_SELECTION m_selection
void selectAllItemsOnSheet(wxString &aSheetpath)
Selects all items with the given sheet timestamp name (the sheet path)
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:427
void clearSelection()
Function clearSelection() Clears the current selection.
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
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 97 of file pcb_tool_base.h.

98  {
99  m_editModules = aEnabled;
100  }

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

2166 {
2168 
2172 
2178 
2179  Go( &SELECTION_TOOL::find, ACTIONS::find.MakeEvent() );
2180 
2189 }
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:80
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:67
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.
static TOOL_ACTION unselectItem
Definition: pcb_actions.h:77
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:96
static TOOL_ACTION unselectItems
Definition: pcb_actions.h:81
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:84
static TOOL_ACTION selectConnection
Selects a connection between junctions.
Definition: pcb_actions.h:87
static TOOL_ACTION find
Definition: actions.h:77
int selectConnection(const TOOL_EVENT &aEvent)
Selects a trivial connection (between two junctions) of items in selection
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:200
int selectCopper(const TOOL_EVENT &aEvent)
Selects items with a continuous copper connection to items in selection
int filterSelection(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection
int expandConnection(const TOOL_EVENT &aEvent)
Expands the current selection to select a connection between two junctions
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 selectCopper
Selects whole copper connection.
Definition: pcb_actions.h:93
static TOOL_ACTION updateMenu
Definition: actions.h:157
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 expandSelectedConnection
Expands the current selection to select a connection between two junctions.
Definition: pcb_actions.h:90
static TOOL_ACTION filterSelection
Filters the items in the current selection (invokes dialog)
Definition: pcb_actions.h:105
static TOOL_ACTION selectOnSheetFromEeschema
Selects all components on sheet from Eeschema crossprobing.
Definition: pcb_actions.h:99
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
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:70
static TOOL_ACTION selectSameSheet
Selects all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:102

References ClearSelection(), CursorSelection(), expandConnection(), PCB_ACTIONS::expandSelectedConnection, PCB_ACTIONS::filterSelection, filterSelection(), ACTIONS::find, find(), TOOL_INTERACTIVE::Go(), Main(), PCB_ACTIONS::selectConnection, selectConnection(), PCB_ACTIONS::selectCopper, selectCopper(), 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 727 of file selection_tool.cpp.

728 {
729  unhighlight( aItem, BRIGHTENED );
730 }
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
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 1701 of file selection_tool.cpp.

1702 {
1703  if( aMode == SELECTED )
1704  aItem->ClearSelected();
1705  else if( aMode == BRIGHTENED )
1706  aItem->ClearBrightened();
1707 
1708  if( aGroup )
1709  {
1710  aGroup->Remove( aItem );
1711 
1712  // Restore original item visibility
1713  view()->Hide( aItem, false );
1714  }
1715 
1716  // Modules are treated in a special way - when they are highlighted, we have to
1717  // highlight all the parts that make the module, not the module itself
1718  if( aItem->Type() == PCB_MODULE_T )
1719  {
1720  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1721  {
1722  if( aMode == SELECTED )
1723  item->ClearSelected();
1724  else if( aMode == BRIGHTENED )
1725  item->ClearBrightened();
1726 
1727  // N.B. if we clear the selection flag for sub-elements, we need to also
1728  // remove the element from the selection group (if it exists)
1729  if( aGroup )
1730  {
1731  aGroup->Remove( item );
1732 
1733  view()->Hide( item, false );
1734  view()->Update( item );
1735  }
1736  });
1737  }
1738 
1739  view()->Update( aItem );
1740 
1741  // Many selections are very temporal and updating the display each time just
1742  // creates noise.
1743  if( aMode == BRIGHTENED )
1745 }
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
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ClearSelected()
Definition: base_struct.h:243
void ClearBrightened()
Definition: base_struct.h:245
#define SELECTED
Definition: base_struct.h:127
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:143
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:210
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:85

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

1647 {
1648  unhighlight( aItem, SELECTED, &m_selection );
1649  view()->Update( &m_selection );
1650 
1651  if( m_selection.Empty() )
1652  m_locked = true;
1653 }
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
PCBNEW_SELECTION m_selection
#define SELECTED
Definition: base_struct.h:127
KIGFX::PCB_VIEW * view() const
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
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, unhighlight(), KIGFX::PCB_VIEW::Update(), and PCB_TOOL_BASE::view().

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

◆ UnselectItem()

int SELECTION_TOOL::UnselectItem ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 704 of file selection_tool.cpp.

705 {
706  // Check if there is an item to be selected
707  BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
708 
709  if( item )
710  {
711  unselect( item );
712 
713  // Inform other potentially interested tools
715  }
716 
717  return 0;
718 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
Class 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
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:427
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.

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

Referenced by setTransitions().

◆ UnselectItems()

int SELECTION_TOOL::UnselectItems ( const TOOL_EVENT aEvent)

Multiple item unselection event handler

Definition at line 687 of file selection_tool.cpp.

688 {
689  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
690 
691  if( items )
692  {
693  // Perform individual unselection of each item before processing the event
694  for( auto item : *items )
695  unselect( item );
696 
698  }
699 
700  return 0;
701 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
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).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.

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

Referenced by setTransitions().

◆ UpdateMenu()

int SELECTION_TOOL::UpdateMenu ( const TOOL_EVENT aEvent)
private

Pass the selection to a conditional menu for updating.

Definition at line 2150 of file selection_tool.cpp.

2151 {
2152  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
2153  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
2154 
2155  if( conditionalMenu )
2156  conditionalMenu->Evaluate( m_selection );
2157 
2158  if( actionMenu )
2159  actionMenu->UpdateAll();
2160 
2161  return 0;
2162 }
Class ACTION_MENU.
Definition: action_menu.h:43
PCBNEW_SELECTION m_selection
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427

References m_selection, TOOL_EVENT::Parameter(), and ACTION_MENU::UpdateAll().

Referenced by setTransitions().

◆ updateSelection()

int SELECTION_TOOL::updateSelection ( const TOOL_EVENT aEvent)
private

Event handler to update the selection VIEW_ITEM.

Definition at line 2142 of file selection_tool.cpp.

2143 {
2144  getView()->Update( &m_selection );
2145 
2146  return 0;
2147 }
PCBNEW_SELECTION m_selection
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1540
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36

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

Referenced by setTransitions().

◆ view()

◆ Wait()

TOOL_EVENT * TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST aEventList = TOOL_EVENTTC_ANYTA_ANY ))
inherited

Function Wait()

Suspends execution of the tool until an event specified in aEventList arrives. No parameters means waiting for any event.

Definition at line 57 of file tool_interactive.cpp.

58 {
59  return m_toolMgr->ScheduleWait( this, aEventList );
60 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_EVENT * ScheduleWait(TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
Pauses execution of a given tool until one or more events matching aConditions arrives.

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), PL_EDIT_TOOL::Main(), CVPCB_CONTROL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), 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(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), GERBVIEW_SELECTION_TOOL::selectPoint(), selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ zoomFitSelection()

void SELECTION_TOOL::zoomFitSelection ( )

Zooms the screen to center and fit the current selection.

Definition at line 1011 of file selection_tool.cpp.

1012 {
1013  //Should recalculate the view to zoom in on the selection
1014  auto selectionBox = m_selection.ViewBBox();
1015  auto view = getView();
1016 
1017  VECTOR2D screenSize = view->ToWorld( m_frame->GetCanvas()->GetClientSize(), false );
1018 
1019  if( selectionBox.GetWidth() != 0 || selectionBox.GetHeight() != 0 )
1020  {
1021  VECTOR2D vsize = selectionBox.GetSize();
1022  double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
1023  fabs( vsize.y / screenSize.y ) );
1024  view->SetScale( scale );
1025  view->SetCenter( selectionBox.Centre() );
1026  view->Add( &m_selection );
1027  }
1028 
1030 }
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
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
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCBNEW_SELECTION m_selection
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:604
KIGFX::PCB_VIEW * view() const
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:578
const int scale
#define max(a, b)
Definition: auxiliary.h:86
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
double GetScale() const
Function GetScale()
Definition: view.h:257
virtual const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers.
Definition: selection.h:141

References KIGFX::PCB_VIEW::Add(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW::GetScale(), TOOL_BASE::getView(), m_frame, m_selection, max, scale, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), PCB_TOOL_BASE::view(), SELECTION::ViewBBox(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by selectSheetContents().

Member Data Documentation

◆ m_additive

bool SELECTION_TOOL::m_additive
private

Definition at line 336 of file selection_tool.h.

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

◆ m_editModules

◆ m_exclusive_or

bool SELECTION_TOOL::m_exclusive_or
private

Definition at line 338 of file selection_tool.h.

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

◆ m_frame

◆ m_locked

bool SELECTION_TOOL::m_locked
private

Definition at line 341 of file selection_tool.h.

Referenced by CheckLock(), clearSelection(), Reset(), and unselect().

◆ m_menu

TOOL_MENU TOOL_INTERACTIVE::m_menu
protectedinherited

functions below are not yet implemented - their interface may change

Definition at line 108 of file tool_interactive.h.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), TOOL_INTERACTIVE::GetToolMenu(), PICKER_TOOL::Init(), SCH_EDIT_TOOL::Init(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init(), PL_EDIT_TOOL::Init(), LIB_DRAWING_TOOLS::Init(), MODULE_EDITOR_TOOLS::Init(), PL_DRAWING_TOOLS::Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), SCH_DRAWING_TOOLS::Init(), GERBVIEW_SELECTION_TOOL::Init(), DRAWING_TOOL::Init(), PL_SELECTION_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), Init(), EDIT_TOOL::Init(), PCB_TOOL_BASE::Init(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), 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(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ m_multiple

bool SELECTION_TOOL::m_multiple
private

Definition at line 339 of file selection_tool.h.

Referenced by Selectable(), and selectMultiple().

◆ m_priv

std::unique_ptr<PRIV> SELECTION_TOOL::m_priv
private

Definition at line 344 of file selection_tool.h.

Referenced by filterSelection().

◆ m_selection

◆ m_skip_heuristics

bool SELECTION_TOOL::m_skip_heuristics
private

Definition at line 340 of file selection_tool.h.

Referenced by Main(), and selectPoint().

◆ m_subtractive

bool SELECTION_TOOL::m_subtractive
private

Definition at line 337 of file selection_tool.h.

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

◆ m_toolId

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 214 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), TOOL_BASE::GetId(), and TOOL_BASE::IsToolActive().

◆ m_toolMgr

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 219 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), PL_SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::AddItemsToSel(), PL_SELECTION_TOOL::AddItemToSel(), EE_SELECTION_TOOL::AddItemToSel(), AddItemToSel(), CVPCB_ASSOCIATION_TOOL::Associate(), TOOL_BASE::attachManager(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), PCB_INSPECTION_TOOL::ClearHighlight(), SCH_EDITOR_CONTROL::ClearHighlight(), PL_SELECTION_TOOL::ClearSelection(), GERBVIEW_SELECTION_TOOL::clearSelection(), EE_SELECTION_TOOL::ClearSelection(), clearSelection(), SCH_EDIT_TOOL::ConvertDeMorgan(), LIB_EDIT_TOOL::Copy(), PL_EDIT_TOOL::Copy(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), COMMON_TOOLS::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), SCH_EDITOR_CONTROL::Cut(), LIB_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), LIB_EDIT_TOOL::DoDelete(), SCH_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::Duplicate(), EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::editComponentFieldText(), EDIT_TOOL::EditFpInFpEditor(), LIB_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithLibEdit(), SCH_EDITOR_CONTROL::EnterSheet(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), findCallback(), SCH_EDITOR_CONTROL::FindComponentAndItem(), POINT_EDITOR::finishItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), EDIT_TOOL::Flip(), EDIT_TOOL::GetAndPlace(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), GERBVIEW_CONTROL::HighlightControl(), PCB_INSPECTION_TOOL::HighlightItem(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), PL_EDIT_TOOL::ImportWorksheetContent(), LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), PAD_TOOL::Init(), GLOBAL_EDIT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), PL_DRAWING_TOOLS::Init(), LIB_CONTROL::Init(), PL_POINT_EDITOR::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), POSITION_RELATIVE_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), TOOL_BASE::IsToolActive(), SCH_EDITOR_CONTROL::LeaveSheet(), COMMON_CONTROL::ListHotKeys(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PL_EDIT_TOOL::Main(), SCH_MOVE_TOOL::Main(), CVPCB_CONTROL::Main(), LIB_MOVE_TOOL::Main(), PL_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LIB_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), LIB_CONTROL::OnDeMorgan(), LIB_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), EDIT_TOOL::pickCopyReferencePoint(), LIB_EDIT_TOOL::PinTable(), PCBNEW_CONTROL::placeBoardItems(), 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(), PCBNEW_CONTROL::Print(), GERBVIEW_CONTROL::Print(), LIB_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EE_SELECTION_TOOL::RebuildSelection(), LIB_EDIT_TOOL::Redo(), SCH_EDITOR_CONTROL::Redo(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PL_SELECTION_TOOL::RemoveItemFromSel(), EE_SELECTION_TOOL::RemoveItemFromSel(), PL_SELECTION_TOOL::RemoveItemsFromSel(), EE_SELECTION_TOOL::RemoveItemsFromSel(), SCH_EDIT_TOOL::RepeatDrawItem(), LIB_DRAWING_TOOLS::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), RequestSelection(), COMMON_TOOLS::ResetLocalCoords(), TOOL_INTERACTIVE::resetTransitions(), LIB_EDIT_TOOL::Rotate(), SCH_EDIT_TOOL::Rotate(), EDIT_TOOL::Rotate(), TOOL_INTERACTIVE::RunMainStack(), DRC::RunTests(), EE_SELECTION_TOOL::SelectConnection(), selectCopper(), PCB_TOOL_BASE::selection(), COMMON_TOOLS::SelectionTool(), GERBVIEW_SELECTION_TOOL::SelectItem(), GERBVIEW_SELECTION_TOOL::SelectItems(), SelectItems(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), selectNet(), PL_SELECTION_TOOL::SelectPoint(), GERBVIEW_SELECTION_TOOL::selectPoint(), EE_SELECTION_TOOL::SelectPoint(), selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), selectSameSheet(), selectSheetContents(), DRAWING_TOOL::SetAnchor(), TOOL_INTERACTIVE::SetContextMenu(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), LIB_EDIT_TOOL::Undo(), SCH_EDITOR_CONTROL::Undo(), SCH_LINE_WIRE_BUS_TOOL::UnfoldBus(), GERBVIEW_SELECTION_TOOL::UnselectItem(), UnselectItem(), GERBVIEW_SELECTION_TOOL::UnselectItems(), UnselectItems(), EE_INSPECTION_TOOL::UpdateMessagePanel(), GERBVIEW_CONTROL::UpdateMessagePanel(), PL_EDITOR_CONTROL::UpdateMessagePanel(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), and PCB_EDITOR_CONTROL::ZoneMerge().