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...
 
SELECTIONGetSelection ()
 Function GetSelection() More...
 
SELECTIONRequestSelection (CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=NULL, bool aConfirmLockedItems=false)
 Function RequestSelection() More...
 
TOOL_MENUGetToolMenu ()
 
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...
 
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 RebuildSelection ()
 Rebuilds the selection from the EDA_ITEMs' selection flags. 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 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...
 
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...
 
OPT_TOOL_EVENT Wait (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_PROPERTIES = 4, IPO_SINGLE_CLICK = 8,
  IPO_REPEAT = 16
}
 

Protected Member Functions

void doInteractiveItemPlacement (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_EDIT_FRAMEframe () const
 
BOARDboard () const
 
MODULEmodule () const
 
PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const SELECTIONselection () const
 
SELECTIONselection ()
 
const TOOL_EVENT evActivate (std::string aToolName="")
 functions below are not yet implemented - their interface may change More...
 
const TOOL_EVENT evCommand (int aCommandId=-1)
 
const TOOL_EVENT evCommand (std::string aCommandStr="")
 
const TOOL_EVENT evMotion ()
 
const TOOL_EVENT evClick (int aButton=BUT_ANY)
 
const TOOL_EVENT evDrag (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonUp (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonDown (int aButton=BUT_ANY)
 
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_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. More...
 
void selectAllItemsConnectedToItem (BOARD_CONNECTED_ITEM &aSourceItem)
 Selects all items connected (by copper) to the given item. 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 findMove (const TOOL_EVENT &aEvent)
 

Find an item and start moving.

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 toggleSelection (BOARD_ITEM *aItem, bool aForce=false)
 Function toggleSelection() Changes selection status of a given item. More...
 
bool selectable (const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
 Function selectable() Checks conditions for an item to be selected. 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, SELECTION &aGroup)
 Function highlight() Highlights the item visually. More...
 
void unhighlight (BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
 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...
 
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 braindead heuristics. 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
 
SELECTION m_selection
 
bool m_additive
 
bool m_subtractive
 
bool m_multiple
 
bool m_skip_heuristics
 
bool m_locked
 
TOOL_MENU m_menu
 
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 64 of file selection_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Enumerator
IPO_ROTATE 
IPO_FLIP 
IPO_PROPERTIES 
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 80 of file tool_base.h.

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

Constructor & Destructor Documentation

◆ SELECTION_TOOL()

SELECTION_TOOL::SELECTION_TOOL ( )

Definition at line 195 of file selection_tool.cpp.

195  :
196  PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
197  m_frame( NULL ),
198  m_additive( false ),
199  m_subtractive( false ),
200  m_multiple( false ),
201  m_skip_heuristics( false ),
202  m_locked( true ),
203  m_menu( *this ),
204  m_priv( std::make_unique<PRIV>() )
205 {
206 }
std::unique_ptr< PRIV > m_priv
PCB_BASE_FRAME * m_frame
TOOL_MENU m_menu
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 209 of file selection_tool.cpp.

210 {
211  getView()->Remove( &m_selection );
212 }
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
SELECTION m_selection
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35

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 49 of file tool_interactive.cpp.

50 {
52 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:211
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(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), EDIT_TOOL::doCopyToClipboard(), SCH_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_DRAWING_TOOLS::doPlaceComponent(), SCH_DRAWING_TOOLS::doSingleClickPlace(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), EDIT_TOOL::pickCopyReferencePoint(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::ShowLocalRatsnest(), SCH_WIRE_BUS_TOOL::StartBus(), SCH_WIRE_BUS_TOOL::StartWire(), and SCH_WIRE_BUS_TOOL::UnfoldBus().

◆ 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 59 of file tool_base.cpp.

60 {
61  m_toolMgr = aManager;
62  m_toolSettings = TOOL_SETTINGS( this );
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:217
friend class TOOL_SETTINGS
Definition: tool_base.h:155

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

140 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_EDITOR_CONTROL::calculateSelectionRatsnest(), EDIT_TOOL::changeTrackWidthOnClick(), PCB_EDITOR_CONTROL::ClearHighlight(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), EDIT_TOOL::doCopyToClipboard(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), MODULE_EDITOR_TOOLS::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), filterSelection(), POINT_EDITOR::finishItem(), getCollectorsGuide(), PCBNEW_CONTROL::GraphicDisplayMode(), PAD_TOOL::haveFootprints(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_TOOL_BASE::module(), PCBNEW_CONTROL::ModuleEdgeOutlines(), PCBNEW_CONTROL::ModuleTextOutlines(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::PasteItemsFromClipboard(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), RebuildSelection(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), selectable(), selectAllItemsConnectedToItem(), selectAllItemsConnectedToTrack(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectPoint(), PCB_EDITOR_CONTROL::ShowLocalRatsnest(), PCBNEW_CONTROL::TrackDisplayMode(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCBNEW_CONTROL::ViaDisplayMode(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), PCBNEW_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), ZONE_FILLER_TOOL::ZoneFillAll(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

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

701 {
702  if( !m_locked || m_editModules )
703  return SELECTION_UNLOCKED;
704 
705  bool containsLocked = false;
706 
707  // Check if the selection contains locked items
708  for( const auto& item : m_selection )
709  {
710  switch( item->Type() )
711  {
712  case PCB_MODULE_T:
713  if( static_cast<MODULE*>( item )->IsLocked() )
714  containsLocked = true;
715  break;
716 
717  case PCB_MODULE_EDGE_T:
718  case PCB_MODULE_TEXT_T:
719  if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
720  containsLocked = true;
721  break;
722 
723  default: // suppress warnings
724  break;
725  }
726  }
727 
728  if( containsLocked )
729  {
730  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
731  {
732  m_locked = false;
734  }
735  else
736  return SELECTION_LOCKED;
737  }
738 
739  return SELECTION_UNLOCKED;
740 }
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class MODULE, a footprint
Definition: typeinfo.h:89
SELECTION m_selection
PCB_BASE_FRAME * m_frame
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays 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::Main(), and RequestSelection().

◆ ClearSelection()

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 753 of file selection_tool.cpp.

754 {
755  clearSelection();
756 
757  return 0;
758 }
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 1358 of file selection_tool.cpp.

1359 {
1360  if( m_selection.Empty() )
1361  return;
1362 
1363  while( m_selection.GetSize() )
1364  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, m_selection );
1365 
1366  view()->Update( &m_selection );
1367 
1368  m_selection.SetIsHover( false );
1370 
1371  if( m_frame )
1372  m_frame->SetCurItem( NULL );
1373 
1374  m_locked = true;
1375 
1376  // Inform other potentially interested tools
1379 }
void ClearReferencePoint()
Definition: selection.h:213
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:216
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void SetIsHover(bool aIsHover)
Definition: selection.h:64
#define SELECTED
Definition: base_struct.h:121
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:323
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
KIGFX::PCB_VIEW * view() const
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function unhighlight() Unhighlights the item visually.
SELECTION m_selection
PCB_BASE_FRAME * m_frame
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
Definition: actions.h:134
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
EDA_ITEM * Front() const
Definition: selection.h:155

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

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

◆ controls()

◆ CursorSelection()

int SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Select a single item under cursor event handler.

Definition at line 743 of file selection_tool.cpp.

744 {
746 
747  selectCursor( false, aClientFilter );
748 
749  return 0;
750 }
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:378

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

Referenced by setTransitions().

◆ displayOptions()

◆ doInteractiveItemPlacement()

void PCB_TOOL_BASE::doInteractiveItemPlacement ( 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 39 of file pcb_tool_base.cpp.

42 {
43  using namespace std::placeholders;
44  std::unique_ptr<BOARD_ITEM> newItem;
45 
46  Activate();
47 
48  BOARD_COMMIT commit( frame() );
49 
51 
52  // do not capture or auto-pan until we start placing an item
53  controls()->ShowCursor( true );
54  controls()->SetSnapping( true );
55 
56  // Add a VIEW_GROUP that serves as a preview for the new item
57  SELECTION preview;
58  view()->Add( &preview );
59 
60  aPlacer->m_board = board();
61  aPlacer->m_frame = frame();
62  aPlacer->m_modifiers = 0;
63 
64  if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
65  {
66  VECTOR2I cursorPos = controls()->GetCursorPosition();
67 
68  newItem = aPlacer->CreateItem();
69 
70  if( newItem )
71  {
72  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
73  preview.Add( newItem.get() );
74  }
75  }
76 
77  // Main loop: keep receiving events
78  while( OPT_TOOL_EVENT evt = Wait() )
79  {
80  VECTOR2I cursorPos = controls()->GetCursorPosition();
81  aPlacer->m_modifiers = evt->Modifier();
82 
84  {
85  if( newItem )
86  {
87  // Delete the old item and have another try
88  newItem = nullptr;
89 
90  preview.Clear();
91 
92  if( aOptions & IPO_SINGLE_CLICK )
93  break;
94 
95  controls()->SetAutoPan( false );
96  controls()->CaptureCursor( false );
97  controls()->ShowCursor( true );
98  }
99  else
100  {
101  break;
102  }
103 
104  if( evt->IsActivate() ) // now finish unconditionally
105  break;
106  }
107  else if( evt->IsClick( BUT_LEFT ) )
108  {
109  if( !newItem )
110  {
111  // create the item if possible
112  newItem = aPlacer->CreateItem();
113 
114  // no item created, so wait for another click
115  if( !newItem )
116  continue;
117 
118  controls()->CaptureCursor( true );
119  controls()->SetAutoPan( true );
120 
121  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
122 
123  preview.Add( newItem.get() );
124 
125  if( newItem->Type() == PCB_MODULE_T )
126  {
127  auto module = dyn_cast<MODULE*>( newItem.get() );
128 
129  // modules have more drawable parts
130  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
131  }
132  }
133  else
134  {
135  auto oldFlags = newItem->GetFlags();
136  newItem->ClearFlags();
137 
138  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
139  {
140  newItem->SetFlags( oldFlags );
141  continue;
142  }
143 
144  preview.Remove( newItem.get() );
145 
146  if( newItem->Type() == PCB_MODULE_T )
147  {
148  auto module = dyn_cast<MODULE*>( newItem.get() );
149  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) );
150  }
151 
152  newItem.release();
153  commit.Push( aCommitMessage );
154 
155  controls()->CaptureCursor( false );
156  controls()->SetAutoPan( false );
157  controls()->ShowCursor( true );
158 
159  if( !( aOptions & IPO_REPEAT ) )
160  break;
161 
162  if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) )
163  {
165 
166  newItem = aPlacer->CreateItem();
167 
168  if( newItem )
169  {
170  newItem->SetPosition( wxPoint( pos.x, pos.y ) );
171  preview.Add( newItem.get() );
172  }
173  }
174  }
175  }
176  else if( evt->IsClick( BUT_RIGHT ) )
177  {
179  }
180  else if( newItem && evt->Category() == TC_COMMAND )
181  {
182  /*
183  * Handle any events that can affect the item as we move
184  * it around, eg rotate and flip
185  */
186 
187  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
188  {
189  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
190  newItem->Rotate( newItem->GetPosition(), rotationAngle );
191  view()->Update( &preview );
192  }
193  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
194  {
195  newItem->Flip( newItem->GetPosition() );
196  view()->Update( &preview );
197  }
198  }
199 
200  else if( newItem && evt->IsMotion() )
201  {
202  // track the cursor
203  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
204  aPlacer->SnapItem( newItem.get() );
205 
206  // Show a preview of the item
207  view()->Update( &preview );
208  }
209  }
210 
211  view()->Remove( &preview );
212 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
TOOL_MENU m_menu
Menu model displayed by the tool.
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.
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
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
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:125
PCB_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:58
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:144
virtual void SnapItem(BOARD_ITEM *aItem)
class MODULE, a footprint
Definition: typeinfo.h:89
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
KIGFX::PCB_VIEW * view() const
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
Definition: tool_event.cpp:177
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
PCB_EDIT_FRAME * frame() const
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:99
KIGFX::VIEW_CONTROLS * controls() const
MODULE * module() const
void Activate()
Function Activate() Runs the tool.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
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.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:85

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_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_PROPERTIES, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsCancelInteractive(), TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, INTERACTIVE_PLACER_BASE::m_frame, PCB_TOOL_BASE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, PCB_TOOL_BASE::module(), PCB_MODULE_T, INTERACTIVE_PLACER_BASE::PlaceItem(), BOARD_COMMIT::Push(), KIGFX::PCB_VIEW::Remove(), KIGFX::VIEW_GROUP::Remove(), SELECTION::Remove(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetSnapping(), 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 1417 of file selection_tool.cpp.

1418 {
1419  BOARD_ITEM* current = nullptr;
1420  SELECTION highlightGroup;
1421  ACTION_MENU menu;
1422 
1423  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1424  getView()->Add( &highlightGroup );
1425 
1426  int limit = std::min( 9, aCollector->GetCount() );
1427 
1428  for( int i = 0; i < limit; ++i )
1429  {
1430  wxString text;
1431  BOARD_ITEM* item = ( *aCollector )[i];
1432  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1433 
1434  wxString menuText = wxString::Format("&%d. %s", i + 1, text );
1435  menu.Add( menuText, i + 1, item->GetMenuImage() );
1436  }
1437 
1438  if( aTitle.Length() )
1439  menu.SetTitle( aTitle );
1440 
1441  menu.SetIcon( info_xpm );
1442  menu.DisplayTitle( true );
1443  SetContextMenu( &menu, CMENU_NOW );
1444 
1445  while( OPT_TOOL_EVENT evt = Wait() )
1446  {
1447  if( evt->Action() == TA_CONTEXT_MENU_UPDATE )
1448  {
1449  if( current )
1450  unhighlight( current, BRIGHTENED, highlightGroup );
1451 
1452  int id = *evt->GetCommandId();
1453 
1454  // User has pointed an item, so show it in a different way
1455  if( id > 0 && id <= limit )
1456  {
1457  current = ( *aCollector )[id - 1];
1458  highlight( current, BRIGHTENED, highlightGroup );
1459  }
1460  else
1461  {
1462  current = NULL;
1463  }
1464  }
1465  else if( evt->Action() == TA_CONTEXT_MENU_CHOICE )
1466  {
1467  if( current )
1468  unhighlight( current, BRIGHTENED, highlightGroup );
1469 
1470  OPT<int> id = evt->GetCommandId();
1471 
1472  // User has selected an item, so this one will be returned
1473  if( id && ( *id > 0 ) )
1474  current = ( *aCollector )[*id - 1];
1475  else
1476  current = NULL;
1477 
1478  break;
1479  }
1480  }
1481  getView()->Remove( &highlightGroup );
1482 
1483  if( current )
1484  {
1485  aCollector->Empty();
1486  aCollector->Append( current );
1487  return true;
1488  }
1489 
1490  return false;
1491 }
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
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void highlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function highlight() Highlights the item visually.
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:82
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function unhighlight() Unhighlights the item visually.
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:137
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:35
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:96
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
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
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
Function Add() Adds an entry to the menu.
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.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486
#define min(a, b)
Definition: auxiliary.h:85
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.

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_DRAW_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_CONTEXT_MENU_CHOICE, TA_CONTEXT_MENU_UPDATE, unhighlight(), and TOOL_INTERACTIVE::Wait().

Referenced by SelectionMenu(), and selectPoint().

◆ EditingModules()

bool PCB_TOOL_BASE::EditingModules ( ) const
inlineinherited

◆ evActivate()

const TOOL_EVENT TOOL_INTERACTIVE::evActivate ( std::string  aToolName = "")
protectedinherited

functions below are not yet implemented - their interface may change

◆ evButtonDown()

const TOOL_EVENT TOOL_INTERACTIVE::evButtonDown ( int  aButton = BUT_ANY)
protectedinherited

◆ evButtonUp()

const TOOL_EVENT TOOL_INTERACTIVE::evButtonUp ( int  aButton = BUT_ANY)
protectedinherited

◆ evClick()

const TOOL_EVENT TOOL_INTERACTIVE::evClick ( int  aButton = BUT_ANY)
protectedinherited

◆ evCommand() [1/2]

const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( int  aCommandId = -1)
protectedinherited

◆ evCommand() [2/2]

const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( std::string  aCommandStr = "")
protectedinherited

◆ evDrag()

const TOOL_EVENT TOOL_INTERACTIVE::evDrag ( int  aButton = BUT_ANY)
protectedinherited

◆ evMotion()

const TOOL_EVENT TOOL_INTERACTIVE::evMotion ( )
protectedinherited

◆ expandConnection()

int SELECTION_TOOL::expandConnection ( const TOOL_EVENT aEvent)
private

Expands the current selection to select a connection between two junctions

Definition at line 856 of file selection_tool.cpp.

857 {
858  // copy the selection, since we're going to iterate and modify
859  auto selection = m_selection.GetItems();
860 
861  // We use the BUSY flag to mark connections
862  for( auto item : selection )
863  item->SetState( BUSY, false );
864 
865  for( auto item : selection )
866  {
867  TRACK* trackItem = dynamic_cast<TRACK*>( item );
868 
869  // Track items marked BUSY have already been visited
870  // therefore their connections have already been marked
871  if( trackItem && !trackItem->GetState( BUSY ) )
872  selectAllItemsConnectedToTrack( *trackItem );
873  }
874 
875  // Inform other potentially interested tools
876  if( m_selection.Size() > 0 )
878 
879  return 0;
880 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
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
SELECTION m_selection
void selectAllItemsConnectedToTrack(TRACK &aSourceTrack)
Selects all items connected by copper tracks to the given TRACK.
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
const SELECTION & selection() const
int GetState(int type) const
Definition: base_struct.h:243

References BUSY, SELECTION::GetItems(), EDA_ITEM::GetState(), m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), 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 1324 of file selection_tool.cpp.

1325 {
1326  auto& opts = m_priv->m_filterOpts;
1327  DIALOG_BLOCK_OPTIONS dlg( m_frame, opts, false, _( "Filter selection" ) );
1328 
1329  const int cmd = dlg.ShowModal();
1330 
1331  if( cmd != wxID_OK )
1332  return 0;
1333 
1334  const auto& board = *getModel<BOARD>();
1335 
1336  // copy current selection
1337  auto selection = m_selection.GetItems();
1338 
1339  // clear current selection
1340  clearSelection();
1341 
1342  // copy selection items from the saved selection
1343  // according to the dialog options
1344  for( auto i : selection )
1345  {
1346  auto item = static_cast<BOARD_ITEM*>( i );
1347  bool include = itemIsIncludedByFilter( *item, board, opts );
1348 
1349  if( include )
1350  {
1351  select( item );
1352  }
1353  }
1354  return 0;
1355 }
BOARD * board() const
std::unique_ptr< PRIV > m_priv
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:130
SELECTION m_selection
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()
size_t i
Definition: json11.cpp:597
const SELECTION & selection() const

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

1201 {
1202  DIALOG_FIND dlg( m_frame );
1203  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1204  dlg.ShowModal();
1205 
1206  return 0;
1207 }
void findCallback(BOARD_ITEM *aItem)
Find dialog callback.
PCB_BASE_FRAME * m_frame

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

Referenced by setTransitions().

◆ findCallback()

void SELECTION_TOOL::findCallback ( BOARD_ITEM aItem)
private

Find dialog callback.

Definition at line 1183 of file selection_tool.cpp.

1184 {
1185  clearSelection();
1186 
1187  if( aItem )
1188  {
1189  select( aItem );
1190  getView()->SetCenter( aItem->GetPosition() );
1191 
1192  // Inform other potentially interested tools
1194  }
1195 
1197 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
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
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual const wxPoint GetPosition() const =0

References clearSelection(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), BOARD_ITEM::GetPosition(), TOOL_BASE::getView(), m_frame, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), EVENTS::SelectedEvent, and KIGFX::VIEW::SetCenter().

Referenced by find().

◆ findMove()

int SELECTION_TOOL::findMove ( const TOOL_EVENT aEvent)
private

Find an item and start moving.

Definition at line 1210 of file selection_tool.cpp.

1211 {
1213 
1214  if( module )
1215  {
1216  KIGFX::VIEW_CONTROLS* viewCtrls = getViewControls();
1217  clearSelection();
1218  toggleSelection( module, true );
1219 
1220  auto cursorPosition = viewCtrls->GetCursorPosition( false );
1221 
1222  // Set a reference point so InteractiveEdit will move it to the
1223  // cursor before waiting for mouse move events
1225 
1226  // Place event on module origin first, so the generic anchor snap
1227  // doesn't just choose the closest pin for us
1228  viewCtrls->ForceCursorPosition( true, module->GetPosition() );
1229 
1230  // pick the component up and start moving
1231  m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
1232 
1233  // restore the previous cursor position
1234  viewCtrls->SetCursorPosition( cursorPosition, false );
1235  }
1236 
1237  return 0;
1238 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:208
SELECTION m_selection
void toggleSelection(BOARD_ITEM *aItem, bool aForce=false)
Function toggleSelection() Changes selection status of a given item.
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
MODULE * module() const
MODULE * GetFootprintFromBoardByReference()
Function GetFootprintFromBoardByReference.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
const wxPoint GetPosition() const override
Definition: class_module.h:183
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false)=0
Moves cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References clearSelection(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetFootprintFromBoardByReference(), MODULE::GetPosition(), TOOL_BASE::getViewControls(), TOOL_MANAGER::InvokeTool(), m_frame, m_selection, TOOL_BASE::m_toolMgr, PCB_TOOL_BASE::module(), KIGFX::VIEW_CONTROLS::SetCursorPosition(), SELECTION::SetReferencePoint(), and toggleSelection().

Referenced by setTransitions().

◆ frame()

PCB_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 139 of file pcb_tool_base.h.

139 { return getEditFrame<PCB_EDIT_FRAME>(); }

Referenced by POINT_EDITOR::addCorner(), MICROWAVE_TOOL::addMicrowaveFootprint(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), EDIT_TOOL::changeTrackWidthOnClick(), PNS::TOOL_BASE::checkSnap(), PCB_EDITOR_CONTROL::ClearHighlight(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_TOOL_BASE::displayOptions(), EDIT_TOOL::doCopyToClipboard(), 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(), MODULE_EDITOR_TOOLS::EnumeratePads(), EDIT_TOOL::ExchangeFootprints(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ROUTER_TOOL::finishInteractive(), PAD_TOOL::Init(), EDIT_TOOL::Init(), Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PICKER_TOOL::Main(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PasteItemsFromClipboard(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), MODULE_EDITOR_TOOLS::PlacePad(), 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::RouteDiffPair(), ROUTER_TOOL::RouteSingleTrace(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ROUTER_TOOL::SettingsDialog(), ROUTER_TOOL::switchLayerOnViaPlacement(), LENGTH_TUNER_TOOL::TuneDiffPair(), LENGTH_TUNER_TOOL::TuneDiffPairSkew(), LENGTH_TUNER_TOOL::TuneSingleTrace(), 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 486 of file selection_tool.cpp.

487 {
488  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
489  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
490 
491  // account for the globals
492  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
493  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
494  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
495  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
496  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
497  guide.SetIgnorePadsOnBack( ! board()->IsElementVisible( LAYER_PAD_BK ) );
498  guide.SetIgnorePadsOnFront( ! board()->IsElementVisible( LAYER_PAD_FR ) );
499  guide.SetIgnoreThroughHolePads( ! board()->IsElementVisible( LAYER_PADS_TH ) );
500  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
501  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
502  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIA_THROUGH ) );
503  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIA_BBLIND ) );
504  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIA_MICROVIA ) );
505  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
506 
507  return guide;
508 }
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:386
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 188 of file tool_base.h.

189  {
190  return static_cast<T*>( getEditFrameInt() );
191  }
wxWindow * getEditFrameInt() const
Definition: tool_base.cpp:47

References TOOL_BASE::getEditFrameInt().

Referenced by ZONE_CREATE_HELPER::commitZone(), 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 122 of file tool_base.h.

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

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

145  {
146  return m_toolMgr;
147  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ACTION_MENU::getToolManager(), 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 199 of file tool_base.h.

200  {
201  EDA_ITEM* m = getModelInt();
202  wxASSERT( dynamic_cast<T*>( m ) );
203 
204  return static_cast<T*>( m );
205  }
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:53
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157

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

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

References TOOL_BASE::m_toolName.

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

◆ GetSelection()

◆ GetSettings()

TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 77 of file tool_base.cpp.

78 {
79  return m_toolSettings;
80 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:217

References TOOL_BASE::m_toolSettings.

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

◆ GetToolMenu()

TOOL_MENU& SELECTION_TOOL::GetToolMenu ( )
inline

Definition at line 102 of file selection_tool.h.

103  {
104  return m_menu;
105  }
TOOL_MENU m_menu

References m_menu.

Referenced by PAD_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), and EDIT_TOOL::Init().

◆ 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 111 of file tool_base.h.

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

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 35 of file tool_base.cpp.

36 {
37  return m_toolMgr->GetView();
38 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216

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(), EE_SELECTION_TOOL::clearSelection(), PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), COMMON_TOOLS::CursorControl(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), COMMON_TOOLS::doGridPreset(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), MODULE_EDITOR_TOOLS::EnumeratePads(), findCallback(), ROUTER_TOOL::getStartLayer(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), guessSelectionCandidates(), EE_SELECTION_TOOL::highlight(), highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCBNEW_CONTROL::LayerAlphaDec(), PCBNEW_CONTROL::LayerAlphaInc(), EE_POINT_EDITOR::Main(), CVPCB_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), selectable(), GERBVIEW_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), selectionContains(), GERBVIEW_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), EE_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), COMMON_TOOLS::ToggleGrid(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), EE_SELECTION_TOOL::unhighlight(), unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), PCBNEW_CONTROL::updateGrid(), EE_POINT_EDITOR::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_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(), GERBVIEW_SELECTION_TOOL::zoomFitSelection(), zoomFitSelection(), CVPCB_SELECTION_TOOL::~CVPCB_SELECTION_TOOL(), 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 41 of file tool_base.cpp.

42 {
43  return m_toolMgr->GetViewControls();
44 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:257

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_WIRE_BUS_TOOL::doDrawSegments(), SCH_DRAWING_TOOLS::doPlaceComponent(), SCH_DRAWING_TOOLS::doSingleClickPlace(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), COMMON_TOOLS::doZoomToPreset(), MICROWAVE_TOOL::drawMicrowaveInductor(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), MODULE_EDITOR_TOOLS::EnumeratePads(), findMove(), SCH_WIRE_BUS_TOOL::finishSegments(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNetCursor(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EE_PICKER_TOOL::Main(), PICKER_TOOL::Main(), CVPCB_SELECTION_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EDIT_TOOL::Main(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceImage(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), CVPCB_CONTROL::ResetCoords(), GERBVIEW_CONTROL::ResetCoords(), PCBNEW_CONTROL::ResetCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), selectCursor(), GERBVIEW_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), EE_PICKER_TOOL::setControls(), PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), LIB_MOVE_TOOL::updateModificationPoint(), SCH_MOVE_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 135 of file tool_interactive.h.

137 {
138  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
139 
140  goInternal( sptr, aConditions );
141 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:59
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), EE_POINT_EDITOR::setTransitions(), LIB_CONTROL::setTransitions(), LIB_PIN_TOOL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), LIB_MOVE_TOOL::setTransitions(), POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), CVPCB_SELECTION_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), MODULE_EDITOR_TOOLS::setTransitions(), SCH_WIRE_BUS_TOOL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), EE_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), setTransitions(), EDIT_TOOL::setTransitions(), DRAWING_TOOL::setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ guessSelectionCandidates()

void SELECTION_TOOL::guessSelectionCandidates ( GENERAL_COLLECTOR aCollector,
const VECTOR2I aWhere 
) const
private

Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items are clicked, by doing some braindead heuristics.

Parameters
aCollectoris the collector that has a list of items to be queried.
aWhereis the selection point to consider

Definition at line 1989 of file selection_tool.cpp.

1991 {
1992  std::set<BOARD_ITEM*> preferred;
1993  std::set<BOARD_ITEM*> rejected;
1994  std::set<BOARD_ITEM*> forced;
1995  wxPoint where( aWhere.x, aWhere.y );
1996 
1997  // footprints which are below this percentage of the largest footprint will be considered
1998  // for selection; all others will not
1999  constexpr double footprintToFootprintMinRatio = 0.20;
2000  // pads which are below this percentage of their parent's area will exclude their parent
2001  constexpr double padToFootprintMinRatio = 0.45;
2002  // footprints containing items with items-to-footprint area ratio higher than this will be
2003  // forced to stay on the list
2004  constexpr double footprintMaxCoverRatio = 0.80;
2005  constexpr double viaToPadMinRatio = 0.50;
2006  constexpr double trackViaLengthRatio = 2.0;
2007  constexpr double trackTrackLengthRatio = 0.3;
2008  constexpr double textToFeatureMinRatio = 0.2;
2009  constexpr double textToFootprintMinRatio = 0.4;
2010  // If the common area of two compared items is above the following threshold, they cannot
2011  // be rejected (it means they overlap and it might be hard to pick one by selecting
2012  // its unique area).
2013  constexpr double commonAreaRatio = 0.6;
2014 
2015  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
2016  LSET silkLayers( 2, B_SilkS, F_SilkS );
2017 
2018  if( silkLayers[activeLayer] )
2019  {
2020  for( int i = 0; i < aCollector.GetCount(); ++i )
2021  {
2022  BOARD_ITEM* item = aCollector[i];
2023  KICAD_T type = item->Type();
2024 
2025  if( ( type == PCB_MODULE_TEXT_T || type == PCB_TEXT_T || type == PCB_LINE_T )
2026  && silkLayers[item->GetLayer()] )
2027  {
2028  preferred.insert( item );
2029  }
2030  }
2031 
2032  if( preferred.size() > 0 )
2033  {
2034  aCollector.Empty();
2035 
2036  for( BOARD_ITEM* item : preferred )
2037  aCollector.Append( item );
2038  return;
2039  }
2040  }
2041 
2042  int numZones = aCollector.CountType( PCB_ZONE_AREA_T );
2043 
2044  // Zone edges are very specific; zone fills much less so.
2045  if( numZones > 0 )
2046  {
2047  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2048  {
2049  if( aCollector[i]->Type() == PCB_ZONE_AREA_T )
2050  {
2051  auto zone = static_cast<ZONE_CONTAINER*>( aCollector[i] );
2052 
2053  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
2054  preferred.insert( zone );
2055  else
2056  rejected.insert( zone );
2057  }
2058  }
2059 
2060  if( preferred.size() > 0 )
2061  {
2062  aCollector.Empty();
2063 
2064  for( BOARD_ITEM* item : preferred )
2065  aCollector.Append( item );
2066  return;
2067  }
2068  }
2069 
2070  if( aCollector.CountType( PCB_MODULE_TEXT_T ) > 0 )
2071  {
2072  for( int i = 0; i < aCollector.GetCount(); ++i )
2073  {
2074  if( TEXTE_MODULE* txt = dyn_cast<TEXTE_MODULE*>( aCollector[i] ) )
2075  {
2076  double textArea = calcArea( txt );
2077 
2078  for( int j = 0; j < aCollector.GetCount(); ++j )
2079  {
2080  if( i == j )
2081  continue;
2082 
2083  BOARD_ITEM* item = aCollector[j];
2084  double itemArea = calcArea( item );
2085  double areaRatio = calcRatio( textArea, itemArea );
2086  double commonArea = calcCommonArea( txt, item );
2087  double itemCommonRatio = calcRatio( commonArea, itemArea );
2088  double txtCommonRatio = calcRatio( commonArea, textArea );
2089 
2090  if( item->Type() == PCB_MODULE_T )
2091  {
2092  // when text area is small compared to an overlapping footprint,
2093  // then it's a clear sign the text is the selection target
2094  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
2095  rejected.insert( item );
2096  }
2097 
2098  switch( item->Type() )
2099  {
2100  case PCB_TRACE_T:
2101  case PCB_PAD_T:
2102  case PCB_LINE_T:
2103  case PCB_VIA_T:
2104  case PCB_MODULE_T:
2105  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
2106  rejected.insert( txt );
2107  break;
2108  default:
2109  break;
2110  }
2111  }
2112  }
2113  }
2114  }
2115 
2116  if( aCollector.CountType( PCB_PAD_T ) > 0 )
2117  {
2118  for( int i = 0; i < aCollector.GetCount(); ++i )
2119  {
2120  if( D_PAD* pad = dyn_cast<D_PAD*>( aCollector[i] ) )
2121  {
2122  MODULE* parent = pad->GetParent();
2123  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
2124 
2125  // when pad area is small compared to the parent footprint,
2126  // then it is a clear sign the pad is the selection target
2127  if( ratio < padToFootprintMinRatio )
2128  rejected.insert( pad->GetParent() );
2129  }
2130  }
2131  }
2132 
2133  int moduleCount = aCollector.CountType( PCB_MODULE_T );
2134 
2135  if( moduleCount > 0 )
2136  {
2137  double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
2138  BOX2D viewportD = getView()->GetViewport();
2139  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2140  double maxCoverRatio = footprintMaxCoverRatio;
2141 
2142  // MODULE::CoverageRatio() doesn't take zone handles & borders into account so just
2143  // use a more aggressive cutoff point if zones are involved.
2144  if( aCollector.CountType( PCB_ZONE_AREA_T ) )
2145  maxCoverRatio /= 2;
2146 
2147  for( int i = 0; i < aCollector.GetCount(); ++i )
2148  {
2149  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
2150  {
2151  // filter out components larger than the viewport
2152  if( mod->ViewBBox().Contains( viewport ) )
2153  rejected.insert( mod );
2154  // footprints completely covered with other features have no other
2155  // means of selection, so must be kept
2156  else if( mod->CoverageRatio( aCollector ) > maxCoverRatio )
2157  rejected.erase( mod );
2158  // if a footprint is much smaller than the largest overlapping
2159  // footprint then it should be considered for selection
2160  else if( calcRatio( calcArea( mod ), maxArea ) <= footprintToFootprintMinRatio )
2161  continue;
2162  // if there are multiple footprints for selection at this point, prefer
2163  // one that is on the active layer
2164  else if( moduleCount > 1 && mod->GetLayer() == activeLayer )
2165  preferred.insert( mod );
2166  // reject ALL OTHER footprints if there's still something else left
2167  // to select
2168  else if( (int)( rejected.size() + 1 ) < aCollector.GetCount() )
2169  rejected.insert( mod );
2170  }
2171  }
2172  }
2173 
2174  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2175  {
2176  for( int i = 0; i < aCollector.GetCount(); ++i )
2177  {
2178  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2179  {
2180  double viaArea = calcArea( via );
2181 
2182  for( int j = 0; j < aCollector.GetCount(); ++j )
2183  {
2184  if( i == j )
2185  continue;
2186 
2187  BOARD_ITEM* item = aCollector[j];
2188  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2189 
2190  if( item->Type() == PCB_MODULE_T && areaRatio < padToFootprintMinRatio )
2191  rejected.insert( item );
2192 
2193  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2194  rejected.insert( item );
2195 
2196  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2197  {
2198  if( track->GetNetCode() != via->GetNetCode() )
2199  continue;
2200 
2201  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2202  (double) via->GetWidth();
2203 
2204  if( lenRatio > trackViaLengthRatio )
2205  rejected.insert( track );
2206  }
2207  }
2208  }
2209  }
2210  }
2211 
2212  int nTracks = aCollector.CountType( PCB_TRACE_T );
2213 
2214  if( nTracks > 0 )
2215  {
2216  double maxLength = 0.0;
2217  double minLength = std::numeric_limits<double>::max();
2218  double maxArea = 0.0;
2219  const TRACK* maxTrack = nullptr;
2220 
2221  for( int i = 0; i < aCollector.GetCount(); ++i )
2222  {
2223  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2224  {
2225  maxLength = std::max( track->GetLength(), maxLength );
2226  maxLength = std::max( (double) track->GetWidth(), maxLength );
2227 
2228  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2229 
2230  double area = track->GetLength() * track->GetWidth();
2231 
2232  if( area > maxArea )
2233  {
2234  maxArea = area;
2235  maxTrack = track;
2236  }
2237  }
2238  }
2239 
2240  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2241  {
2242  for( int i = 0; i < aCollector.GetCount(); ++i )
2243  {
2244  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2245  {
2246  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2247 
2248  if( ratio > trackTrackLengthRatio )
2249  rejected.insert( track );
2250  }
2251  }
2252  }
2253 
2254  for( int j = 0; j < aCollector.GetCount(); ++j )
2255  {
2256  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[j] ) )
2257  {
2258  double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() );
2259 
2260  if( ratio < padToFootprintMinRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio )
2261  rejected.insert( mod );
2262  }
2263  }
2264  }
2265 
2266  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2267  {
2268  for( BOARD_ITEM* item : rejected )
2269  {
2270  aCollector.Remove( item );
2271  }
2272  }
2273 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:123
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:265
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:143
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:133
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
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:850
KIGFX::PCB_VIEW * view() const
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
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:204
#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 selectPoint().

◆ highlight()

void SELECTION_TOOL::highlight ( BOARD_ITEM aItem,
int  aHighlightMode,
SELECTION aGroup 
)
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 1807 of file selection_tool.cpp.

1808 {
1809  if( aMode == SELECTED )
1810  aItem->SetSelected();
1811  else if( aMode == BRIGHTENED )
1812  aItem->SetBrightened();
1813 
1814  // Hide the original item, so it is shown only on overlay
1815  view()->Hide( aItem, true );
1816 
1817  aGroup.Add( aItem );
1818 
1819  // Modules are treated in a special way - when they are highlighted, we have to
1820  // highlight all the parts that make the module, not the module itself
1821  if( aItem->Type() == PCB_MODULE_T )
1822  {
1823  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1824  {
1825  if( aMode == SELECTED )
1826  item->SetSelected();
1827  else if( aMode == BRIGHTENED )
1828  {
1829  item->SetBrightened();
1830  aGroup.Add( item );
1831  }
1832  view()->Hide( item, true );
1833  });
1834  }
1835 
1836  // Many selections are very temporal and updating the display each time just
1837  // creates noise.
1838  if( aMode == BRIGHTENED )
1840 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1506
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:235
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
#define SELECTED
Definition: base_struct.h:121
class MODULE, a footprint
Definition: typeinfo.h:89
void SetSelected()
Definition: base_struct.h:233
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:596
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:137
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:35
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

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(), and PCB_TOOL_BASE::view().

Referenced by 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 215 of file selection_tool.cpp.

216 {
217  auto frame = getEditFrame<PCB_BASE_FRAME>();
218 
221  {
223  return true;
224  }
225 
226  auto selectMenu = std::make_shared<SELECT_MENU>();
227  selectMenu->SetTool( this );
228  m_menu.AddSubMenu( selectMenu );
229 
230  auto& menu = m_menu.GetMenu();
231 
232  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
233  menu.AddSeparator( SELECTION_CONDITIONS::NotEmpty, 1000 );
234 
235  if( frame )
237 
238  return true;
239 }
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
void AddStandardSubMenus(EDA_DRAW_FRAME *aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:83
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.
TOOL_MENU m_menu
PCB_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(), TOOL_MENU::AddStandardSubMenus(), TOOL_MENU::AddSubMenu(), PCB_TOOL_BASE::frame(), FRAME_PCB_MODULE_VIEWER, FRAME_PCB_MODULE_VIEWER_MODAL, TOOL_MENU::GetMenu(), EDA_BASE_FRAME::IsType(), m_menu, and SELECTION_CONDITIONS::NotEmpty().

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 30 of file tool_base.cpp.

31 {
32  return m_toolMgr->IsToolActive( m_toolId );
33 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:211
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 267 of file selection_tool.cpp.

268 {
269  // Main loop: keep receiving events
270  while( OPT_TOOL_EVENT evt = Wait() )
271  {
272  // Should selected items be added to the current selection or
273  // become the new selection (discarding previously selected items)
274  m_additive = evt->Modifier( MD_SHIFT );
275 
276  // Should selected items be REMOVED from the current selection?
277  // This will be ignored if the SHIFT modifier is pressed
278  m_subtractive = !m_additive && evt->Modifier( MD_CTRL );
279 
280  // Is the user requesting that the selection list include all possible
281  // items without removing less likely selection candidates
282  m_skip_heuristics = !!evt->Modifier( MD_ALT );
283 
284  // Single click? Select single object
285  if( evt->IsClick( BUT_LEFT ) )
286  {
287  if( evt->Modifier( MD_CTRL ) && !m_editModules )
288  {
290  }
291  else
292  {
293  // If no modifier keys are pressed, clear the selection
294  if( !m_additive )
295  clearSelection();
296 
297  selectPoint( evt->Position() );
298  }
299  }
300 
301  // right click? if there is any object - show the context menu
302  else if( evt->IsClick( BUT_RIGHT ) )
303  {
304  bool selectionCancelled = false;
305 
306  if( m_selection.Empty() )
307  {
308  selectPoint( evt->Position(), false, &selectionCancelled );
309  m_selection.SetIsHover( true );
310  }
311 
312  if( !selectionCancelled )
314  }
315 
316  // double click? Display the properties window
317  else if( evt->IsDblClick( BUT_LEFT ) )
318  {
319  if( m_selection.Empty() )
320  selectPoint( evt->Position() );
321 
323  }
324 
325  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
326  else if( evt->IsDrag( BUT_LEFT ) )
327  {
328  if( m_additive || m_subtractive )
329  {
330  selectMultiple();
331  }
332  else if( m_selection.Empty() )
333  {
334  // There is nothing selected, so try to select something
335  if( getEditFrame<PCB_BASE_FRAME>()->Settings().m_dragSelects || !selectCursor() )
336  {
337  // If nothings has been selected, user wants to select more or selection
338  // box is preferred to dragging - draw selection box
339  selectMultiple();
340  }
341  else
342  {
343  m_selection.SetIsHover( true );
344  m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
345  }
346  }
347 
348  else
349  {
350  // Check if dragging has started within any of selected items bounding box
351  if( selectionContains( evt->Position() ) )
352  {
353  // Yes -> run the move tool and wait till it finishes
354  m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
355  }
356  else
357  {
358  // No -> clear the selection list
359  clearSelection();
360  }
361  }
362  }
363 
364  else if( evt->Action() == TA_UNDO_REDO_PRE )
365  {
366  clearSelection();
367  }
368 
369  else if( evt->IsCancel() )
370  {
371  clearSelection();
373  }
374 
375  else if( evt->Action() == TA_CONTEXT_MENU_CLOSED )
376  {
377  m_menu.CloseContextMenu( evt );
378  }
379  }
380 
381  // This tool is supposed to be active forever
382  assert( false );
383 
384  return 0;
385 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:105
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
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...
SELECTION m_selection
void clearSelection()
Function clearSelection() Clears the current selection.
TOOL_MENU m_menu
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:311
void CloseContextMenu(OPT_TOOL_EVENT &evt)
Function CloseContextMenu.
Definition: tool_menu.cpp:75
static TOOL_ACTION highlightNet
Definition: pcb_actions.h:312
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486

References BUT_LEFT, BUT_RIGHT, PCB_ACTIONS::clearHighlight, clearSelection(), TOOL_MENU::CloseContextMenu(), SELECTION::Empty(), PCB_ACTIONS::highlightNet, TOOL_MANAGER::InvokeTool(), m_additive, PCB_TOOL_BASE::m_editModules, m_menu, m_selection, m_skip_heuristics, m_subtractive, TOOL_BASE::m_toolMgr, MD_ALT, MD_CTRL, MD_SHIFT, PCB_ACTIONS::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TA_CONTEXT_MENU_CLOSED, TA_UNDO_REDO_PRE, 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 1494 of file selection_tool.cpp.

1495 {
1496  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1497 
1498  if( 0 == count )
1499  count = aCollector->GetCount();
1500 
1501  for( int i = 0; i < count; ++i )
1502  {
1503  if( ( *aCollector )[i]->Type() != PCB_MODULE_T )
1504  return NULL;
1505  }
1506 
1507  // All are modules, now find smallest MODULE
1508  int minDim = 0x7FFFFFFF;
1509  int minNdx = 0;
1510 
1511  for( int i = 0; i < count; ++i )
1512  {
1513  MODULE* module = (MODULE*) ( *aCollector )[i];
1514 
1515  int lx = module->GetFootprintRect().GetWidth();
1516  int ly = module->GetFootprintRect().GetHeight();
1517 
1518  int lmin = std::min( lx, ly );
1519 
1520  if( lmin < minDim )
1521  {
1522  minDim = lmin;
1523  minNdx = i;
1524  }
1525  }
1526 
1527  return (*aCollector)[minNdx];
1528 }
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:114
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 1382 of file selection_tool.cpp.

1383 {
1384  m_selection.Clear();
1385 
1386  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1387  {
1388  if( item->IsSelected() )
1389  {
1390  EDA_ITEM* parent = item->GetParent();
1391 
1392  // Flags on module children might be set only because the parent is selected.
1393  if( parent && parent->Type() == PCB_MODULE_T && parent->IsSelected() )
1394  return SEARCH_CONTINUE;
1395 
1397  }
1398 
1399  return SEARCH_CONTINUE;
1400  };
1401 
1402  board()->Visit( inspector, nullptr, m_editModules ? GENERAL_COLLECTOR::ModuleItems
1404 }
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:77
static const KICAD_T AllBoardItems[]
A scan list for all editable board items, like PcbGeneralLocateAndDisplay()
Definition: collectors.h:267
BOARD * board() const
bool IsSelected() const
Definition: base_struct.h:227
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void highlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
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:121
class MODULE, a footprint
Definition: typeinfo.h:89
SELECTION m_selection
EDA_ITEM * GetParent() const
Definition: base_struct.h:214
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:157
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

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

SELECTION & SELECTION_TOOL::RequestSelection ( CLIENT_SELECTION_FILTER  aClientFilter,
std::vector< BOARD_ITEM * > *  aFiltered = NULL,
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 394 of file selection_tool.cpp.

396 {
397  bool selectionEmpty = m_selection.Empty();
398  m_selection.SetIsHover( selectionEmpty );
399 
400  if( selectionEmpty )
401  {
402  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
404  }
405 
406  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
407  {
408  clearSelection();
409  }
410 
411  if( aClientFilter )
412  {
413  GENERAL_COLLECTOR collector;
414 
415  for( auto item : m_selection )
416  collector.Append( item );
417 
418  aClientFilter( VECTOR2I(), collector );
419 
420  /*
421  * The first step is to find the items that may have been added by the client filter
422  * This can happen if the locked pads select the module instead
423  */
424  std::vector<EDA_ITEM*> new_items;
425  std::set_difference( collector.begin(), collector.end(), m_selection.begin(), m_selection.end(),
426  std::back_inserter( new_items ) );
427 
431  std::vector<EDA_ITEM*> diff;
432  std::set_difference( m_selection.begin(), m_selection.end(), collector.begin(), collector.end(),
433  std::back_inserter( diff ) );
434 
435  if( aFiltered )
436  {
437  for( auto item : diff )
438  aFiltered->push_back( static_cast<BOARD_ITEM*>( item ) );
439  }
440 
445  for( auto item : diff )
446  unhighlight( static_cast<BOARD_ITEM*>( item ), SELECTED, m_selection );
447 
448  for( auto item : new_items )
449  highlight( static_cast<BOARD_ITEM*>( item ), SELECTED, m_selection );
450 
452  }
453 
454  return m_selection;
455 }
void ClearReferencePoint()
Definition: selection.h:213
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.
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
ITER end()
Definition: selection.h:60
ITER begin()
Definition: collector.h:92
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
ITER end()
Definition: collector.h:93
void highlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function highlight() Highlights the item visually.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void SetIsHover(bool aIsHover)
Definition: selection.h:64
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:133
#define SELECTED
Definition: base_struct.h:121
ITER begin()
Definition: selection.h:59
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function unhighlight() Unhighlights the item visually.
SELECTION m_selection
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:50

References COLLECTOR::Append(), SELECTION::begin(), COLLECTOR::begin(), CheckLock(), SELECTION::ClearReferencePoint(), clearSelection(), SELECTION::Empty(), SELECTION::end(), COLLECTOR::end(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), 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::CreateArray(), deleteItem(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::doCopyToClipboard(), EDIT_TOOL::Duplicate(), EDIT_TOOL::editFootprintInFpEditor(), EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), EDIT_TOOL::Main(), EDIT_TOOL::Mirror(), 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 242 of file selection_tool.cpp.

243 {
244  m_frame = getEditFrame<PCB_BASE_FRAME>();
245  m_locked = true;
246 
247  if( aReason == TOOL_BASE::MODEL_RELOAD )
248  {
249  // Remove pointers to the selected items from containers
250  // without changing their properties (as they are already deleted
251  // while a new board is loaded)
252  m_selection.Clear();
253  getView()->GetPainter()->GetSettings()->SetHighlight( false );
254  }
255  else
256  {
257  // Restore previous properties of selected items and remove them from containers
258  clearSelection();
259  }
260 
261  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
262  view()->Remove( &m_selection );
263  view()->Add( &m_selection );
264 }
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:83
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
KIGFX::PCB_VIEW * view() const
SELECTION m_selection
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
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
void SetHighlight(bool aEnabled, int aNetcode=-1)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
Definition: painter.h:140

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 85 of file tool_interactive.cpp.

86 {
87  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
88 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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 1760 of file selection_tool.cpp.

1761 {
1762  if( aItem->IsSelected() )
1763  {
1764  return;
1765  }
1766 
1767  if( aItem->Type() == PCB_PAD_T )
1768  {
1769  MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
1770 
1771  if( m_selection.Contains( module ) )
1772  return;
1773  }
1774 
1775  highlight( aItem, SELECTED, m_selection );
1776  view()->Update( &m_selection );
1777 
1778  if( m_frame )
1779  {
1780  if( m_selection.Size() == 1 )
1781  {
1782  // Set as the current item, so the information about selection is displayed
1783  m_frame->SetCurItem( aItem, true );
1784  }
1785  else if( m_selection.Size() == 2 ) // Check only for 2, so it will not be
1786  { // called for every next selected item
1787  // If multiple items are selected, do not show the information about the selected item
1788  m_frame->SetCurItem( NULL, true );
1789  }
1790  }
1791 }
bool IsSelected() const
Definition: base_struct.h:227
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
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void highlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function highlight() Highlights the item visually.
#define SELECTED
Definition: base_struct.h:121
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:111
KIGFX::PCB_VIEW * view() const
SELECTION m_selection
PCB_BASE_FRAME * m_frame
MODULE * module() const
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204

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

Referenced by filterSelection(), findCallback(), selectAllItemsConnectedToItem(), selectAllItemsConnectedToTrack(), selectAllItemsOnNet(), selectAllItemsOnSheet(), SelectItem(), SelectItems(), selectMultiple(), and toggleSelection().

◆ selectable()

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

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

Returns
True if the item fulfills conditions to be selected.

Definition at line 1531 of file selection_tool.cpp.

1532 {
1533  // Is high contrast mode enabled?
1534  bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast();
1535 
1536  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
1537 
1538  // Filter out items that do not belong to active layers
1539  std::set<unsigned int> activeLayers = getView()->GetPainter()->GetSettings()->GetActiveLayers();
1540 
1541  // The markers layer is considered to be always active
1542  activeLayers.insert( (unsigned int) LAYER_DRC );
1543 
1544  aItem->ViewGetLayers( layers, layers_count );
1545 
1546  if( highContrast )
1547  {
1548  bool onActive = false; // Is the item on any of active layers?
1549 
1550  for( int i = 0; i < layers_count; ++i )
1551  {
1552  if( activeLayers.count( layers[i] ) > 0 ) // Item is on at least one of the active layers
1553  {
1554  onActive = true;
1555  break;
1556  }
1557  }
1558 
1559  if( !onActive ) // We do not want to select items that are in the background
1560  {
1561  return false;
1562  }
1563  }
1564 
1565  switch( aItem->Type() )
1566  {
1567  case PCB_ZONE_AREA_T:
1568  // Keepout zones can exist on multiple layers!
1569  {
1570  auto* zone = static_cast<const ZONE_CONTAINER*>( aItem );
1571 
1572  if( zone->GetIsKeepout() )
1573  {
1574  auto zoneLayers = zone->GetLayerSet().Seq();
1575 
1576  for( unsigned int i = 0; i < zoneLayers.size(); i++ )
1577  {
1578  if( board()->IsLayerVisible( zoneLayers[i] ) )
1579  {
1580  return true;
1581  }
1582  }
1583 
1584  // No active layers selected!
1585  return false;
1586  }
1587  }
1588  break;
1589 
1590  case PCB_TRACE_T:
1591  {
1592  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1593  return false;
1594  }
1595  break;
1596 
1597  case PCB_VIA_T:
1598  {
1599  const VIA* via = static_cast<const VIA*>( aItem );
1600 
1601  // Check if appropriate element layer is visible
1602  switch( via->GetViaType() )
1603  {
1604  case VIA_THROUGH:
1606  return false;
1607  break;
1608 
1609  case VIA_BLIND_BURIED:
1611  return false;
1612  break;
1613 
1614  case VIA_MICROVIA:
1616  return false;
1617  break;
1618 
1619  default:
1620  wxFAIL;
1621  return false;
1622  }
1623 
1624  // For vias it is enough if only one of its layers is visible
1625  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1626  }
1627 
1628  case PCB_MODULE_T:
1629  {
1630  // In modedit, we do not want to select the module itself.
1631  if( m_editModules )
1632  return false;
1633 
1634  // Allow selection of footprints if some part of the footprint is visible.
1635 
1636  MODULE* module = const_cast<MODULE*>( static_cast<const MODULE*>( aItem ) );
1637 
1638  for( auto item : module->GraphicalItems() )
1639  {
1640  if( selectable( item, true ) )
1641  return true;
1642  }
1643 
1644  for( auto pad : module->Pads() )
1645  {
1646  if( selectable( pad, true ) )
1647  return true;
1648  }
1649 
1650  return false;
1651  }
1652 
1653  case PCB_MODULE_TEXT_T:
1654  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1655  // module subparts one by one, rather than with a drag selection. This is so you can
1656  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1657  if( !m_editModules && !checkVisibilityOnly )
1658  {
1659  if( m_multiple )
1660  return false;
1661  }
1662 
1663  if( !m_editModules && !view()->IsVisible( aItem ) )
1664  return false;
1665 
1666  break;
1667 
1668  case PCB_MODULE_EDGE_T:
1669  case PCB_PAD_T:
1670  {
1671  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1672  // module subparts one by one, rather than with a drag selection. This is so you can
1673  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1674  if( !m_editModules && !checkVisibilityOnly )
1675  {
1676  if( m_multiple )
1677  return false;
1678  }
1679 
1680  if( aItem->Type() == PCB_PAD_T )
1681  {
1682  auto pad = static_cast<const D_PAD*>( aItem );
1683 
1684  // In pcbnew, locked modules prevent individual pad selection.
1685  // In modedit, we don't enforce this as the module is assumed to be edited by design.
1686  if( !m_editModules && !checkVisibilityOnly )
1687  {
1688  if( pad->GetParent() && pad->GetParent()->IsLocked() )
1689  return false;
1690  }
1691 
1692  // Check render mode (from the Items tab) first
1693  switch( pad->GetAttribute() )
1694  {
1695  case PAD_ATTRIB_STANDARD:
1697  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1698  return false;
1699  break;
1700 
1701  case PAD_ATTRIB_CONN:
1702  case PAD_ATTRIB_SMD:
1703  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1704  return false;
1705  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1706  return false;
1707  break;
1708  }
1709 
1710  // Otherwise, pads are selectable if any draw layer is visible
1711 
1712  // Shortcut: check copper layer visibility
1713  if( board()->IsLayerVisible( F_Cu ) && pad->IsOnLayer( F_Cu ) )
1714  return true;
1715 
1716  if( board()->IsLayerVisible( B_Cu ) && pad->IsOnLayer( B_Cu ) )
1717  return true;
1718 
1719  // Now check the non-copper layers
1720 
1721  bool draw_layer_visible = false;
1722 
1723  int pad_layers[KIGFX::VIEW::VIEW_MAX_LAYERS], pad_layers_count;
1724  pad->ViewGetLayers( pad_layers, pad_layers_count );
1725 
1726  for( int i = 0; i < pad_layers_count; ++i )
1727  {
1728  // NOTE: Only checking the regular layers (not GAL meta-layers)
1729  if( ( ( pad_layers[i] < PCB_LAYER_ID_COUNT ) &&
1730  board()->IsLayerVisible( static_cast<PCB_LAYER_ID>( pad_layers[i] ) ) ) )
1731  {
1732  draw_layer_visible = true;
1733  }
1734  }
1735 
1736  return draw_layer_visible;
1737  }
1738 
1739  break;
1740  }
1741 
1742 
1743  case PCB_MARKER_T: // Always selectable
1744  return true;
1745 
1746  // These are not selectable
1747  case NOT_USED:
1748  case TYPE_NOT_INIT:
1749  return false;
1750 
1751  default: // Suppress warnings
1752  break;
1753  }
1754 
1755  // All other items are selected only if the layer on which they exist is visible
1756  return board()->IsLayerVisible( aItem->GetLayer() );
1757 }
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.
DLIST_ITERATOR_WRAPPER< D_PAD > Pads()
Definition: class_module.h:168
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
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:712
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > GraphicalItems()
Definition: class_module.h:173
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:1525
to draw usual through hole vias
KIGFX::PCB_VIEW * view() const
VIATYPE_T GetViaType() const
Definition: class_track.h:437
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:35
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:161
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:453
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:204
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 selectMultiple(), selectPoint(), and toggleSelection().

◆ selectAllItemsConnectedToItem()

void SELECTION_TOOL::selectAllItemsConnectedToItem ( BOARD_CONNECTED_ITEM aSourceItem)
private

Selects all items connected (by copper) to the given item.

Definition at line 949 of file selection_tool.cpp.

950 {
951  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_PAD_T, EOT };
952  auto connectivity = board()->GetConnectivity();
953 
954  for( auto item : connectivity->GetConnectedItems( &aSourceItem, types ) )
955  {
956  // We want to select items connected through pads but not pads
957  // otherwise, the common use case of "Select Copper"->Delete will
958  // remove footprints in addition to traces and vias
959  if( item->Type() != PCB_PAD_T )
960  select( item );
961  }
962 }
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:292
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 selectCopper().

◆ selectAllItemsConnectedToTrack()

void SELECTION_TOOL::selectAllItemsConnectedToTrack ( TRACK aSourceTrack)
private

Selects all items connected by copper tracks to the given TRACK.

Definition at line 935 of file selection_tool.cpp.

936 {
937  int segmentCount;
938  TRACK* trackList = board()->MarkTrace( board()->m_Track, &aSourceTrack, &segmentCount,
939  nullptr, nullptr, true );
940 
941  for( int i = 0; i < segmentCount; ++i )
942  {
943  select( trackList );
944  trackList = trackList->Next();
945  }
946 }
BOARD * board() const
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
TRACK * Next() const
Definition: class_track.h:110
size_t i
Definition: json11.cpp:597
TRACK * MarkTrace(TRACK *aTrackList, TRACK *aTrace, int *aCount, double *aTraceLength, double *aInPackageLength, bool aReorder)
Function MarkTrace marks a chain of trace segments, connected to aTrace.

References PCB_TOOL_BASE::board(), i, BOARD::MarkTrace(), TRACK::Next(), and select().

Referenced by expandConnection(), and selectAllItemsOnSheet().

◆ selectAllItemsOnNet()

void SELECTION_TOOL::selectAllItemsOnNet ( int  aNetCode)
private

Selects all items with the given net code.

Definition at line 965 of file selection_tool.cpp.

966 {
967  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
968  auto connectivity = board()->GetConnectivity();
969 
970  for( auto item : connectivity->GetNetItems( aNetCode, types ) )
971  select( item );
972 }
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:292
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 1004 of file selection_tool.cpp.

1005 {
1006  auto modules = board()->m_Modules.GetFirst();
1007  std::list<MODULE*> modList;
1008 
1009  // store all modules that are on that sheet
1010  for( MODULE* mitem = modules; mitem; mitem = mitem->Next() )
1011  {
1012  if( mitem != NULL && mitem->GetPath().Contains( aSheetpath ) )
1013  {
1014  modList.push_back( mitem );
1015  }
1016  }
1017 
1018  //Generate a list of all pads, and of all nets they belong to.
1019  std::list<int> netcodeList;
1020  std::list<BOARD_CONNECTED_ITEM*> padList;
1021  for( MODULE* mmod : modList )
1022  {
1023  for( auto pad : mmod->Pads() )
1024  {
1025  if( pad->IsConnected() )
1026  {
1027  netcodeList.push_back( pad->GetNetCode() );
1028  padList.push_back( pad );
1029  }
1030  }
1031  }
1032  // remove all duplicates
1033  netcodeList.sort();
1034  netcodeList.unique();
1035 
1036  // auto select trivial connections segments which are launched from the pads
1037  std::list<TRACK*> launchTracks;
1038 
1039  for( auto pad : padList )
1040  {
1041  launchTracks = board()->GetTracksByPosition( pad->GetPosition() );
1042 
1043  for( auto track : launchTracks )
1044  {
1046  }
1047  }
1048 
1049  // now we need to find all modules that are connected to each of these nets
1050  // then we need to determine if these modules are in the list of modules
1051  // belonging to this sheet ( modList )
1052  std::list<int> removeCodeList;
1053  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1054 
1055  for( int netCode : netcodeList )
1056  {
1057  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1058  {
1059  if( mitem->Type() == PCB_PAD_T)
1060  {
1061  bool found = ( std::find( modList.begin(), modList.end(),
1062  mitem->GetParent() ) != modList.end() );
1063 
1064  if( !found )
1065  {
1066  // if we cannot find the module of the pad in the modList
1067  // then we can assume that that module is not located in the same
1068  // schematic, therefore invalidate this netcode.
1069  removeCodeList.push_back( netCode );
1070  break;
1071  }
1072  }
1073  }
1074  }
1075 
1076  // remove all duplicates
1077  removeCodeList.sort();
1078  removeCodeList.unique();
1079 
1080  for( int removeCode : removeCodeList )
1081  {
1082  netcodeList.remove( removeCode );
1083  }
1084 
1085  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1086  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
1087 
1088  for( int netCode : netcodeList )
1089  {
1090  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1091  {
1092  localConnectionList.push_back( item );
1093  }
1094  }
1095 
1096  for( BOARD_ITEM* i : modList )
1097  {
1098  if( i != NULL )
1099  select( i );
1100  }
1101 
1102  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1103  {
1104  if( i != NULL )
1105  select( i );
1106  }
1107 }
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
std::list< TRACK * > GetTracksByPosition(const wxPoint &aPosition, PCB_LAYER_ID aLayer=PCB_LAYER_ID(-1)) const
Function GetTracksByPosition finds the list of tracks that starts or ends at aPosition on aLayer.
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty.
Definition: dlist.h:163
void selectAllItemsConnectedToTrack(TRACK &aSourceTrack)
Selects all items connected by copper tracks to the given TRACK.
DLIST< MODULE > m_Modules
Definition: class_board.h:248
size_t i
Definition: json11.cpp:597
MODULE * Next() const
Definition: class_module.h:122
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96

References PCB_TOOL_BASE::board(), EOT, DLIST< T >::GetFirst(), BOARD::GetTracksByPosition(), i, BOARD::m_Modules, MODULE::Next(), PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), and selectAllItemsConnectedToTrack().

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

845 {
848 
850  return 0;
851 
852  return expandConnection( aEvent );
853 }
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:185
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...
SELECTION m_selection
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 903 of file selection_tool.cpp.

904 {
905  bool haveCopper = false;
906 
907  for( auto item : m_selection.GetItems() )
908  {
909  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
910  haveCopper = true;;
911  }
912 
913  if( !haveCopper )
915 
916  // copy the selection, since we're going to iterate and modify
917  auto selection = m_selection.GetItems();
918 
919  for( auto item : selection )
920  {
921  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item );
922 
923  if( connItem )
924  selectAllItemsConnectedToItem( *connItem );
925  }
926 
927  // Inform other potentially interested tools
928  if( m_selection.Size() > 0 )
930 
931  return 0;
932 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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...
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
SELECTION m_selection
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
const SELECTION & selection() const
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item.

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

580 {
581  if( aForceSelect || m_selection.Empty() )
582  {
583  clearSelection();
584  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
585  }
586 
587  return !m_selection.Empty();
588 }
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.
SELECTION m_selection
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:41

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

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

◆ selection() [1/2]

const SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 251 of file pcb_tool_base.cpp.

252 {
253  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
254  const auto& selection = selTool->GetSelection();
255  return selection;
256 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
const SELECTION & selection() const

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_EDITOR_CONTROL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::changeTrackWidthOnClick(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::CreateArray(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_EDITOR_CONTROL::CrossProbePcbToSch(), EDIT_TOOL::doCopyToClipboard(), EDIT_TOOL::Duplicate(), EDIT_TOOL::editFootprintInFpEditor(), EDIT_TOOL::ExchangeFootprints(), expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), filterSelection(), EDIT_TOOL::Flip(), DRAWING_TOOL::getSourceZoneForAction(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EDIT_TOOL::Rotate(), selectCopper(), PCB_TOOL_BASE::selection(), selectNet(), PCB_EDITOR_CONTROL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

◆ selection() [2/2]

SELECTION & PCB_TOOL_BASE::selection ( )
protectedinherited

Definition at line 258 of file pcb_tool_base.cpp.

259 {
260  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
261  auto& selection = selTool->GetSelection();
262  return selection;
263 }
Class SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
const 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 1882 of file selection_tool.cpp.

1883 {
1884  const unsigned GRIP_MARGIN = 20;
1885  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1886 
1887  // Check if the point is located within any of the currently selected items bounding boxes
1888  for( auto item : m_selection )
1889  {
1890  BOX2I itemBox = item->ViewBBox();
1891  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1892 
1893  if( itemBox.Contains( aPoint ) )
1894  return true;
1895  }
1896 
1897  return false;
1898 }
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
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
SELECTION m_selection
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
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 1407 of file selection_tool.cpp.

1408 {
1409  GENERAL_COLLECTOR* collector = aEvent.Parameter<GENERAL_COLLECTOR*>();
1410 
1411  doSelectionMenu( collector, wxEmptyString );
1412 
1413  return 0;
1414 }
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:378
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 778 of file selection_tool.cpp.

779 {
780  // Check if there is an item to be selected
781  BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
782 
783  if( item )
784  {
785  select( item );
786 
787  // Inform other potentially interested tools
789  }
790 
791  return 0;
792 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
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:216
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:378

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

Referenced by setTransitions().

◆ SelectItems()

int SELECTION_TOOL::SelectItems ( const TOOL_EVENT aEvent)

Multiple item selection event handler

Definition at line 761 of file selection_tool.cpp.

762 {
763  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
764 
765  if( items )
766  {
767  // Perform individual selection of each item before processing the event.
768  for( auto item : *items )
769  select( item );
770 
772  }
773 
774  return 0;
775 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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:378

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

592 {
593  bool cancelled = false; // Was the tool cancelled while it was running?
594  m_multiple = true; // Multiple selection mode is active
595  KIGFX::VIEW* view = getView();
596 
598  view->Add( &area );
599 
600  while( OPT_TOOL_EVENT evt = Wait() )
601  {
603  {
604  cancelled = true;
605  break;
606  }
607 
608  if( evt->IsDrag( BUT_LEFT ) )
609  {
610  // Start drawing a selection box
611  area.SetOrigin( evt->DragOrigin() );
612  area.SetEnd( evt->Position() );
613  area.SetAdditive( m_additive );
615 
616  view->SetVisible( &area, true );
617  view->Update( &area );
618  getViewControls()->SetAutoPan( true );
619  }
620 
621  if( evt->IsMouseUp( BUT_LEFT ) )
622  {
623  getViewControls()->SetAutoPan( false );
624 
625  // End drawing the selection box
626  view->SetVisible( &area, false );
627 
628  // Mark items within the selection box as selected
629  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
630 
631  // Filter the view items based on the selection box
632  BOX2I selectionBox = area.ViewBBox();
633  view->Query( selectionBox, selectedItems ); // Get the list of selected items
634 
635  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
636 
637  int width = area.GetEnd().x - area.GetOrigin().x;
638  int height = area.GetEnd().y - area.GetOrigin().y;
639 
640  /* Selection mode depends on direction of drag-selection:
641  * Left > Right : Select objects that are fully enclosed by selection
642  * Right > Left : Select objects that are crossed by selection
643  */
644  bool windowSelection = width >= 0 ? true : false;
645 
646  if( view->IsMirroredX() )
647  windowSelection = !windowSelection;
648 
649  // Construct an EDA_RECT to determine BOARD_ITEM selection
650  EDA_RECT selectionRect( wxPoint( area.GetOrigin().x, area.GetOrigin().y ),
651  wxSize( width, height ) );
652 
653  selectionRect.Normalize();
654 
655  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
656  {
657  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
658 
659  if( !item || !selectable( item ) )
660  continue;
661 
662  if( item->HitTest( selectionRect, windowSelection ) )
663  {
664  if( m_subtractive )
665  unselect( item );
666  else
667  select( item );
668  }
669  }
670 
671  if( m_frame )
672  {
673  if( m_selection.Size() == 1 )
674  m_frame->SetCurItem( static_cast<BOARD_ITEM*>( m_selection.Front() ) );
675  else
676  m_frame->SetCurItem( NULL );
677  }
678 
679  // Inform other potentially interested tools
680  if( !m_selection.Empty() )
682 
683  break; // Stop waiting for events
684  }
685  }
686 
687  getViewControls()->SetAutoPan( false );
688 
689  // Stop drawing the selection box
690  view->Remove( &area );
691  m_multiple = false; // Multiple selection mode is inactive
692 
693  if( !cancelled )
695 
696  return cancelled;
697 }
void ClearReferencePoint()
Definition: selection.h:213
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
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:216
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
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
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:333
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
KIGFX::PCB_VIEW * view() const
SELECTION m_selection
PCB_BASE_FRAME * m_frame
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
Definition: tool_event.cpp:177
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
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 SetSubtractive(bool aSubtractive)
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
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1485
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:41
Class VIEW.
Definition: view.h:61
void SetAdditive(bool aAdditive)
EDA_ITEM * Front() const
Definition: selection.h:155
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486

References KIGFX::PCB_VIEW::Add(), BUT_LEFT, SELECTION::ClearReferencePoint(), SELECTION::Empty(), SELECTION::Front(), KIGFX::PREVIEW::SELECTION_AREA::GetEnd(), KIGFX::PREVIEW::SELECTION_AREA::GetOrigin(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), EDA_ITEM::HitTest(), TOOL_EVT_UTILS::IsCancelInteractive(), KIGFX::VIEW::IsMirroredX(), m_additive, m_frame, m_multiple, m_selection, m_subtractive, TOOL_BASE::m_toolMgr, EDA_RECT::Normalize(), TOOL_MANAGER::ProcessEvent(), KIGFX::VIEW::Query(), KIGFX::PCB_VIEW::Remove(), select(), selectable(), EVENTS::SelectedEvent, KIGFX::PREVIEW::SELECTION_AREA::SetAdditive(), KIGFX::VIEW_CONTROLS::SetAutoPan(), PCB_BASE_FRAME::SetCurItem(), KIGFX::PREVIEW::SELECTION_AREA::SetEnd(), KIGFX::PREVIEW::SELECTION_AREA::SetOrigin(), KIGFX::PREVIEW::SELECTION_AREA::SetSubtractive(), KIGFX::VIEW::SetVisible(), SELECTION::Size(), unselect(), 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 975 of file selection_tool.cpp.

976 {
977  if( !selectCursor() )
978  return 0;
979 
980  // copy the selection, since we're going to iterate and modify
981  auto selection = m_selection.GetItems();
982 
983  for( auto i : selection )
984  {
985  auto item = static_cast<BOARD_ITEM*>( i );
986 
987  // only connected items get a net code
988  if( item->IsConnected() )
989  {
990  auto& connItem = static_cast<BOARD_CONNECTED_ITEM&>( *item );
991 
992  selectAllItemsOnNet( connItem.GetNetCode() );
993  }
994  }
995 
996  // Inform other potentially interested tools
997  if( m_selection.Size() > 0 )
999 
1000  return 0;
1001 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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 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
SELECTION m_selection
size_t i
Definition: json11.cpp:597
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
const SELECTION & selection() const

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

514 {
515  auto guide = getCollectorsGuide();
516  GENERAL_COLLECTOR collector;
517  auto displayOpts = (PCB_DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
518 
519  guide.SetIgnoreZoneFills( displayOpts->m_DisplayZonesMode != 0 );
520 
521  collector.Collect( board(),
523  wxPoint( aWhere.x, aWhere.y ), guide );
524 
525  bool anyCollected = collector.GetCount() != 0;
526 
527  // Remove unselectable items
528  for( int i = collector.GetCount() - 1; i >= 0; --i )
529  {
530  if( !selectable( collector[i] ) || ( aOnDrag && collector[i]->IsLocked() ) )
531  collector.Remove( i );
532  }
533 
535 
536  // Allow the client to do tool- or action-specific filtering to see if we
537  // can get down to a single item
538  if( aClientFilter )
539  aClientFilter( aWhere, collector );
540 
541  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
542  if( collector.GetCount() > 1 && !m_skip_heuristics )
543  {
544  guessSelectionCandidates( collector, aWhere );
545  }
546 
547  // If still more than one item we're going to have to ask the user.
548  if( collector.GetCount() > 1 )
549  {
550  if( aOnDrag )
551  {
553  }
554 
555  if( !doSelectionMenu( &collector, _( "Clarify Selection" ) ) )
556  {
557  if( aSelectionCancelledFlag )
558  *aSelectionCancelledFlag = true;
559 
560  return false;
561  }
562  }
563 
564  if( collector.GetCount() == 1 )
565  {
566  BOARD_ITEM* item = collector[ 0 ];
567 
568  toggleSelection( item );
569  return true;
570  }
571 
572  if( !m_additive && anyCollected )
573  clearSelection();
574 
575  return false;
576 }
void ClearReferencePoint()
Definition: selection.h:213
static const KICAD_T AllBoardItems[]
A scan list for all editable board items, like PcbGeneralLocateAndDisplay()
Definition: collectors.h:267
BOARD * board() const
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:473
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:143
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:114
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Class TOOL_EVENT.
Definition: tool_event.h:167
SELECTION m_selection
void toggleSelection(BOARD_ITEM *aItem, bool aForce=false)
Function toggleSelection() Changes selection status of a given item.
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
bool selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
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 guessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
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, m_additive, PCB_TOOL_BASE::m_editModules, m_frame, m_selection, m_skip_heuristics, GENERAL_COLLECTOR::ModuleItems, COLLECTOR::Remove(), selectable(), TA_MOUSE_UP, TC_ANY, toggleSelection(), 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 1149 of file selection_tool.cpp.

1150 {
1151  if( !selectCursor( true ) )
1152  return 0;
1153 
1154  // this function currently only supports modules since they are only
1155  // on one sheet.
1156  auto item = m_selection.Front();
1157 
1158  if( !item )
1159  return 0;
1160 
1161  if( item->Type() != PCB_MODULE_T )
1162  return 0;
1163 
1164  auto mod = dynamic_cast<MODULE*>( item );
1165 
1166  clearSelection();
1167 
1168  // get the lowest subsheet name for this.
1169  wxString sheetPath = mod->GetPath();
1170  sheetPath = sheetPath.BeforeLast( '/' );
1171  sheetPath = sheetPath.AfterLast( '/' );
1172 
1173  selectAllItemsOnSheet( sheetPath );
1174 
1175  // Inform other potentially interested tools
1176  if( m_selection.Size() > 0 )
1178 
1179  return 0;
1180 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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).
SELECTION m_selection
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:155

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

1134 {
1135  clearSelection();
1136  wxString* sheetpath = aEvent.Parameter<wxString*>();
1137 
1138  selectAllItemsOnSheet( *sheetpath );
1139 
1140  zoomFitSelection();
1141 
1142  if( m_selection.Size() > 0 )
1144 
1145  return 0;
1146 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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:378
SELECTION m_selection
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 74 of file tool_interactive.cpp.

75 {
76  if( aMenu )
77  aMenu->SetTool( this );
78  else
79  aTrigger = CMENU_OFF;
80 
81  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
82 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), TOOL_MENU::ShowContextMenu(), and SCH_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 2299 of file selection_tool.cpp.

2300 {
2302 
2306 
2312 
2313  Go( &SELECTION_TOOL::find, PCB_ACTIONS::find.MakeEvent() );
2315 
2324 }
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:60
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pcb_actions.h:47
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:57
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:76
static TOOL_ACTION unselectItems
Definition: pcb_actions.h:61
int find(const TOOL_EVENT &aEvent)
Find an item.
int findMove(const TOOL_EVENT &aEvent)
Find an item and start moving.
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:64
static TOOL_ACTION selectConnection
Selects a connection between junctions.
Definition: pcb_actions.h:67
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:136
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
static TOOL_ACTION find
Find an item.
Definition: pcb_actions.h:327
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:73
static TOOL_ACTION updateMenu
Definition: actions.h:49
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:70
static TOOL_ACTION filterSelection
Filters the items in the current selection (invokes dialog)
Definition: pcb_actions.h:85
static TOOL_ACTION selectOnSheetFromEeschema
Selects all components on sheet from Eeschema crossprobing.
Definition: pcb_actions.h:79
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
int SelectItems(const TOOL_EVENT &aEvent)
Multiple item selection event handler
static TOOL_ACTION findMove
Find an item and start moving.
Definition: pcb_actions.h:330
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:50
static TOOL_ACTION selectSameSheet
Selects all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:82

References ClearSelection(), CursorSelection(), expandConnection(), PCB_ACTIONS::expandSelectedConnection, PCB_ACTIONS::filterSelection, filterSelection(), find(), PCB_ACTIONS::find, findMove(), PCB_ACTIONS::findMove, 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().

◆ toggleSelection()

void SELECTION_TOOL::toggleSelection ( BOARD_ITEM aItem,
bool  aForce = false 
)
private

Function toggleSelection() Changes selection status of a given item.

Parameters
aItemis the item to have selection status changed.
aForcecauses the toggle to happen without checking selectability

Definition at line 458 of file selection_tool.cpp.

459 {
460  if( aItem->IsSelected() )
461  {
462  unselect( aItem );
463 
464  // Inform other potentially interested tools
466  }
467  else
468  {
469  if( !m_additive )
470  clearSelection();
471 
472  // Prevent selection of invisible or inactive items
473  if( aForce || selectable( aItem ) )
474  {
475  select( aItem );
476 
477  // Inform other potentially interested tools
479  }
480  }
481 
482  if( m_frame )
484 }
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
Definition: actions.h:132
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
bool IsSelected() const
Definition: base_struct.h:227
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
Definition: actions.h:133
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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
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.

References clearSelection(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), EDA_ITEM::IsSelected(), m_additive, m_frame, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), selectable(), EVENTS::SelectedEvent, unselect(), and EVENTS::UnselectedEvent.

Referenced by findMove(), and selectPoint().

◆ unhighlight()

void SELECTION_TOOL::unhighlight ( BOARD_ITEM aItem,
int  aHighlightMode,
SELECTION aGroup 
)
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 1843 of file selection_tool.cpp.

1844 {
1845  if( aMode == SELECTED )
1846  aItem->ClearSelected();
1847  else if( aMode == BRIGHTENED )
1848  aItem->ClearBrightened();
1849 
1850  aGroup.Remove( aItem );
1851 
1852  // Restore original item visibility
1853  view()->Hide( aItem, false );
1854  view()->Update( aItem );
1855 
1856  // Modules are treated in a special way - when they are highlighted, we have to
1857  // highlight all the parts that make the module, not the module itself
1858  if( aItem->Type() == PCB_MODULE_T )
1859  {
1860  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1861  {
1862  if( aMode == SELECTED )
1863  item->ClearSelected();
1864  else if( aMode == BRIGHTENED )
1865  item->ClearBrightened();
1866 
1867  // N.B. if we clear the selection flag for sub-elements, we need to also
1868  // remove the element from the selection group (if it exists)
1869  aGroup.Remove( item );
1870  view()->Hide( item, false );
1871  view()->Update( item );
1872  });
1873  }
1874 
1875  // Many selections are very temporal and updating the display each time just
1876  // creates noise.
1877  if( aMode == BRIGHTENED )
1879 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1506
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:237
void ClearBrightened()
Definition: base_struct.h:239
#define SELECTED
Definition: base_struct.h:121
class MODULE, a footprint
Definition: typeinfo.h:89
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:596
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:137
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:35
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204
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(), 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 1794 of file selection_tool.cpp.

1795 {
1796  unhighlight( aItem, SELECTED, m_selection );
1797  view()->Update( &m_selection );
1798 
1799  if( m_frame && m_frame->GetCurItem() == aItem )
1800  m_frame->SetCurItem( NULL );
1801 
1802  if( m_selection.Empty() )
1803  m_locked = true;
1804 }
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
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
#define SELECTED
Definition: base_struct.h:121
KIGFX::PCB_VIEW * view() const
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function unhighlight() Unhighlights the item visually.
SELECTION m_selection
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
BOARD_ITEM * GetCurItem()

References SELECTION::Empty(), PCB_BASE_FRAME::GetCurItem(), m_frame, m_locked, m_selection, SELECTED, PCB_BASE_FRAME::SetCurItem(), unhighlight(), KIGFX::PCB_VIEW::Update(), and PCB_TOOL_BASE::view().

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

◆ UnselectItem()

int SELECTION_TOOL::UnselectItem ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 812 of file selection_tool.cpp.

813 {
814  // Check if there is an item to be selected
815  BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
816 
817  if( item )
818  {
819  unselect( item );
820 
821  // Inform other potentially interested tools
823  }
824 
825  return 0;
826 }
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
Definition: actions.h:133
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:216
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:378
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 795 of file selection_tool.cpp.

796 {
797  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
798 
799  if( items )
800  {
801  // Perform individual unselection of each item before processing the event
802  for( auto item : *items )
803  unselect( item );
804 
806  }
807 
808  return 0;
809 }
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
Definition: actions.h:133
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
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:378
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 2284 of file selection_tool.cpp.

2285 {
2286  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
2287  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
2288 
2289  if( conditionalMenu )
2290  conditionalMenu->Evaluate( m_selection );
2291 
2292  if( actionMenu )
2293  actionMenu->UpdateAll();
2294 
2295  return 0;
2296 }
Class ACTION_MENU.
Definition: action_menu.h:43
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:378
SELECTION m_selection

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

2277 {
2278  getView()->Update( &m_selection );
2279 
2280  return 0;
2281 }
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:1539
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35

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

Referenced by setTransitions().

◆ view()

◆ Wait()

OPT_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 55 of file tool_interactive.cpp.

56 {
57  return m_toolMgr->ScheduleWait( this, aEventList );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
OPT< 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 LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SCH_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_DRAWING_TOOLS::doPlaceComponent(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), SCH_DRAWING_TOOLS::doSingleClickPlace(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EE_PICKER_TOOL::Main(), PICKER_TOOL::Main(), CVPCB_SELECTION_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), EDIT_TOOL::Main(), Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), CVPCB_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), GERBVIEW_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), GERBVIEW_SELECTION_TOOL::selectPoint(), selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::ShowLocalRatsnest(), and SCH_WIRE_BUS_TOOL::UnfoldBus().

◆ zoomFitSelection()

void SELECTION_TOOL::zoomFitSelection ( )

Zooms the screen to center and fit the current selection.

Definition at line 1110 of file selection_tool.cpp.

1111 {
1112  //Should recalculate the view to zoom in on the selection
1113  auto selectionBox = m_selection.ViewBBox();
1114  auto canvas = m_frame->GetGalCanvas();
1115  auto view = getView();
1116 
1117  VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false );
1118 
1119  if( !( selectionBox.GetWidth() == 0 ) || !( selectionBox.GetHeight() == 0 ) )
1120  {
1121  VECTOR2D vsize = selectionBox.GetSize();
1122  double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
1123  fabs( vsize.y / screenSize.y ) );
1124  view->SetScale( scale );
1125  view->SetCenter( selectionBox.Centre() );
1126  view->Add( &m_selection );
1127  }
1128 
1130 }
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
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:931
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
KIGFX::PCB_VIEW * view() const
SELECTION m_selection
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
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:268
PCB_DRAW_PANEL_GAL * canvas() const

References KIGFX::PCB_VIEW::Add(), PCB_TOOL_BASE::canvas(), EDA_DRAW_PANEL_GAL::ForceRefresh(), EDA_DRAW_FRAME::GetGalCanvas(), 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 349 of file selection_tool.h.

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

◆ m_editModules

◆ m_frame

◆ m_locked

bool SELECTION_TOOL::m_locked
private

Definition at line 353 of file selection_tool.h.

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

◆ m_menu

TOOL_MENU SELECTION_TOOL::m_menu
private

Definition at line 355 of file selection_tool.h.

Referenced by GetToolMenu(), Init(), and Main().

◆ m_multiple

bool SELECTION_TOOL::m_multiple
private

Definition at line 351 of file selection_tool.h.

Referenced by selectable(), and selectMultiple().

◆ m_priv

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

Definition at line 358 of file selection_tool.h.

Referenced by filterSelection().

◆ m_selection

◆ m_skip_heuristics

bool SELECTION_TOOL::m_skip_heuristics
private

Definition at line 352 of file selection_tool.h.

Referenced by Main(), and selectPoint().

◆ m_subtractive

bool SELECTION_TOOL::m_subtractive
private

Definition at line 350 of file selection_tool.h.

Referenced by Main(), and selectMultiple().

◆ m_toolId

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 211 of file tool_base.h.

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

◆ m_toolMgr