KiCad PCB EDA Suite
SELECTION_TOOL Class Reference

SELECTION_TOOL. More...

#include <selection_tool.h>

Inheritance diagram for SELECTION_TOOL:
PCB_TOOL_BASE TOOL_INTERACTIVE TOOL_BASE

Classes

class  PRIV
 Private implementation of firewalled private data. More...
 

Public Types

enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 

Determines the reason of reset for a tool

More...
 

Public Member Functions

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

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

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

Select a single item under cursor event handler.

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

Clear current selection event handler.

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

Item selection event handler.

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

Multiple item selection event handler

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

Item unselection event handler.

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

Multiple item unselection event handler

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

Sets up handlers for various events.

More...
 
void zoomFitSelection ()
 

Zooms the screen to center and fit the current selection.

More...
 
void SetEditModules (bool aEnabled)
 Function SetEditModules() More...
 
bool EditingModules () const
 
void Activate ()
 Function Activate() Runs the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Function SetContextMenu() More...
 
void RunMainStack (std::function< void()> aFunc)
 Function RunMainStack() More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Go() More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Wait() More...
 
TOOL_TYPE GetType () const
 Function GetType() Returns the type of the tool. More...
 
TOOL_ID GetId () const
 Function GetId() Returns the unique identifier of the tool. More...
 
const std::string & GetName () const
 Function GetName() Returns the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool. More...
 
bool IsToolActive () const
 

Protected Types

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

Protected Member Functions

void doInteractiveItemPlacement (const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
 Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc. More...
 
KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
MODULEmodule () const
 
const PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const PCBNEW_SELECTIONselection () const
 
PCBNEW_SELECTIONselection ()
 
void attachManager (TOOL_MANAGER *aManager)
 Function attachManager() More...
 
KIGFX::VIEWgetView () const
 Function getView() More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Function getViewControls() More...
 
template<typename T >
T * getEditFrame () const
 Function getEditFrame() More...
 
template<typename T >
T * getModel () const
 Function getModel() More...
 

Protected Attributes

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

Stores the type of the tool.

More...
 
TOOL_ID m_toolId
 

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

More...
 
std::string m_toolName
 

Name of the tool.

More...
 
TOOL_MANAGERm_toolMgr
 

Private Member Functions

bool selectPoint (const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Function selectPoint() Selects an item pointed by the parameter aWhere. More...
 
bool selectCursor (bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
 Function selectCursor() Selects an item under the cursor unless there is something already selected or aSelectAlways is true. More...
 
bool selectMultiple ()
 Function selectMultiple() Handles drawing a selection box that allows one to select many items at the same time. More...
 
bool doSelectionMenu (GENERAL_COLLECTOR *aItems, const wxString &aTitle)
 Allows the selection of a single item from a list via pop-up menu. More...
 
int expandConnection (const TOOL_EVENT &aEvent)
 Expands the current track selection to the next boundary (junctions, pads, or all) More...
 
int selectNet (const TOOL_EVENT &aEvent)
 Selects all copper connections belonging to the same net(s) as the items in the selection. More...
 
void selectConnectedTracks (BOARD_CONNECTED_ITEM &aSourceItem, KICAD_T aStopCondition)
 Selects connecteed tracks and vias. More...
 
void selectAllItemsOnNet (int aNetCode)
 Selects all items with the given net code. More...
 
void selectAllItemsOnSheet (wxString &aSheetID)
 Selects all items with the given sheet timestamp name (the sheet path) More...
 
int selectSheetContents (const TOOL_EVENT &aEvent)
 

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

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

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

More...
 
void findCallback (BOARD_ITEM *aItem)
 

Find dialog callback.

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

Find an item.

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

Invoke filter dialog and modify current selection

More...
 
BOARD_ITEMpickSmallestComponent (GENERAL_COLLECTOR *aCollector)
 Function pickSmallestComponent() Allows one to find the smallest (in terms of bounding box area) item from the list. More...
 
void select (BOARD_ITEM *aItem)
 Function select() Takes necessary action mark an item as selected. More...
 
void unselect (BOARD_ITEM *aItem)
 Function unselect() Takes necessary action mark an item as unselected. More...
 
void highlight (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
 Function highlight() Highlights the item visually. More...
 
void unhighlight (BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
 Function unhighlight() Unhighlights the item visually. More...
 
bool selectionContains (const VECTOR2I &aPoint) const
 Function selectionContains() More...
 
int updateSelection (const TOOL_EVENT &aEvent)
 Event handler to update the selection VIEW_ITEM. More...
 
int UpdateMenu (const TOOL_EVENT &aEvent)
 Pass the selection to a conditional menu for updating. More...
 
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide () const
 

Private Attributes

PCB_BASE_FRAMEm_frame
 
PCBNEW_SELECTION m_selection
 
bool m_additive
 
bool m_subtractive
 
bool m_exclusive_or
 
bool m_multiple
 
bool m_skip_heuristics
 
bool m_locked
 
std::unique_ptr< PRIVm_priv
 

Detailed Description

SELECTION_TOOL.

Our sample selection tool: currently supports:

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

Definition at line 63 of file selection_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Enumerator
IPO_ROTATE 
IPO_FLIP 
IPO_SINGLE_CLICK 
IPO_REPEAT 

Definition at line 113 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 78 of file tool_base.h.

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

Constructor & Destructor Documentation

◆ SELECTION_TOOL()

SELECTION_TOOL::SELECTION_TOOL ( )

Definition at line 111 of file selection_tool.cpp.

111  :
112  PCB_TOOL_BASE( "pcbnew.InteractiveSelection" ),
113  m_frame( NULL ),
114  m_additive( false ),
115  m_subtractive( false ),
116  m_exclusive_or( false ),
117  m_multiple( false ),
118  m_skip_heuristics( false ),
119  m_locked( true ),
120  m_priv( std::make_unique<PRIV>() )
121 {
122 }
std::unique_ptr< PRIV > m_priv
#define NULL
PCB_BASE_FRAME * m_frame
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:75

◆ ~SELECTION_TOOL()

SELECTION_TOOL::~SELECTION_TOOL ( )

Definition at line 125 of file selection_tool.cpp.

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

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

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

After activation, the tool starts receiving events until it is finished.

Definition at line 51 of file tool_interactive.cpp.

52 {
54 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:213
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.

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

Referenced by AUTOPLACE_TOOL::autoplace(), EDIT_TOOL::copyToClipboard(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ AddItemToSel()

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

Definition at line 707 of file selection_tool.cpp.

708 {
709  if( aItem )
710  {
711  select( aItem );
712 
713  // Inform other potentially interested tools
714  if( !aQuietMode )
716  }
717 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).

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

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

◆ attachManager()

void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Function attachManager()

Sets the TOOL_MANAGER the tool will belong to. Called by TOOL_MANAGER::RegisterTool()

Definition at line 60 of file tool_base.cpp.

61 {
62  m_toolMgr = aManager;
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 155 of file pcb_tool_base.h.

155 { return getModel<BOARD>(); }

Referenced by PCBNEW_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), EDIT_TOOL::ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), PCB_INSPECTION_TOOL::ClearHighlight(), DRAWING_TOOL::constrainDimension(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PAD_TOOL::EnumeratePads(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), ZONE_FILLER_TOOL::FillAllZones(), filterSelection(), getCollectorsGuide(), PCBNEW_CONTROL::GraphicDisplayMode(), PCB_INSPECTION_TOOL::highlightNet(), PCBNEW_CONTROL::LayerNext(), PCBNEW_CONTROL::LayerPrev(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), PCB_TOOL_BASE::module(), PCBNEW_CONTROL::ModuleEdgeOutlines(), PCBNEW_CONTROL::ModuleTextOutlines(), ROUTER_TOOL::onTrackViaSizeChanged(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::Paste(), PCBNEW_CONTROL::placeBoardItems(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), RebuildSelection(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), Selectable(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), selectPoint(), DRC::testDisabledLayers(), DRC::TestZoneToZoneOutlines(), PCBNEW_CONTROL::TrackDisplayMode(), POINT_EDITOR::updateItem(), PCBNEW_CONTROL::ViaDisplayMode(), PCBNEW_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ BrightenItem()

void SELECTION_TOOL::BrightenItem ( BOARD_ITEM aItem)

Definition at line 756 of file selection_tool.cpp.

757 {
758  highlight( aItem, BRIGHTENED );
759 }
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143

References BRIGHTENED, and highlight().

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

◆ canvas()

◆ CheckLock()

SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock ( )

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

Definition at line 622 of file selection_tool.cpp.

623 {
624  if( !m_locked || m_editModules )
625  return SELECTION_UNLOCKED;
626 
627  bool containsLocked = false;
628 
629  // Check if the selection contains locked items
630  for( const auto& item : m_selection )
631  {
632  switch( item->Type() )
633  {
634  case PCB_MODULE_T:
635  if( static_cast<MODULE*>( item )->IsLocked() )
636  containsLocked = true;
637  break;
638 
639  case PCB_MODULE_EDGE_T:
640  case PCB_MODULE_TEXT_T:
641  if( static_cast<MODULE*>( item->GetParent() )->IsLocked() )
642  containsLocked = true;
643  break;
644 
645  default: // suppress warnings
646  break;
647  }
648  }
649 
650  if( containsLocked )
651  {
652  if( IsOK( m_frame, _( "Selection contains locked items. Do you want to continue?" ) ) )
653  {
654  m_locked = false;
656  }
657  else
658  return SELECTION_LOCKED;
659  }
660 
661  return SELECTION_UNLOCKED;
662 }
PCBNEW_SELECTION m_selection
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_BASE_FRAME * m_frame
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
#define _(s)
Definition: 3d_actions.cpp:33
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283

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

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

◆ ClearSelection() [1/2]

int SELECTION_TOOL::ClearSelection ( const TOOL_EVENT aEvent)

Clear current selection event handler.

Definition at line 675 of file selection_tool.cpp.

676 {
677  ClearSelection();
678 
679  return 0;
680 }
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.

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

◆ ClearSelection() [2/2]

void SELECTION_TOOL::ClearSelection ( bool  aQuietMode = false)

Definition at line 1297 of file selection_tool.cpp.

1298 {
1299  if( m_selection.Empty() )
1300  return;
1301 
1302  while( m_selection.GetSize() )
1303  unhighlight( static_cast<BOARD_ITEM*>( m_selection.Front() ), SELECTED, &m_selection );
1304 
1305  view()->Update( &m_selection );
1306 
1307  m_selection.SetIsHover( false );
1309 
1310  m_locked = true;
1311 
1312  // Inform other potentially interested tools
1313  if( !aQuietMode )
1314  {
1317  }
1318 }
void ClearReferencePoint()
Definition: selection.h:249
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:218
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
void SetIsHover(bool aIsHover)
Definition: selection.h:65
#define SELECTED
Definition: base_struct.h:127
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
KIGFX::PCB_VIEW * view() const
static const TOOL_EVENT ClearedEvent
Definition: actions.h:203
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:421
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_ITEM * Front() const
Definition: selection.h:183

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

◆ controls()

◆ CursorSelection()

int SELECTION_TOOL::CursorSelection ( const TOOL_EVENT aEvent)

Select a single item under cursor event handler.

Definition at line 665 of file selection_tool.cpp.

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

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

Referenced by setTransitions().

◆ displayOptions()

◆ doInteractiveItemPlacement()

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

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

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

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

Definition at line 37 of file pcb_tool_base.cpp.

40 {
41  using namespace std::placeholders;
42  std::unique_ptr<BOARD_ITEM> newItem;
43 
44  frame()->PushTool( aTool );
45  Activate();
46 
47  BOARD_COMMIT commit( frame() );
48 
50 
51  // do not capture or auto-pan until we start placing an item
52  controls()->ShowCursor( true );
53  controls()->SetSnapping( true );
54 
55  // Add a VIEW_GROUP that serves as a preview for the new item
56  PCBNEW_SELECTION preview;
57  view()->Add( &preview );
58 
59  aPlacer->m_board = board();
60  aPlacer->m_frame = frame();
61  aPlacer->m_modifiers = 0;
62 
63  auto makeNewItem = [&] ( VECTOR2I aPosition )
64  {
65  if( frame()->GetModel() )
66  newItem = aPlacer->CreateItem();
67 
68  if( newItem )
69  {
70  newItem->SetPosition( (wxPoint) aPosition );
71  preview.Add( newItem.get() );
72 
73  if( newItem->Type() == PCB_MODULE_T )
74  {
75  auto module = dyn_cast<MODULE*>( newItem.get() );
76 
77  // modules have more drawable parts
78  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
79  }
80  }
81  };
82 
83  if( aOptions & IPO_SINGLE_CLICK )
84  makeNewItem( controls()->GetCursorPosition() );
85 
86  // Main loop: keep receiving events
87  while( TOOL_EVENT* evt = Wait() )
88  {
89  VECTOR2I cursorPos = controls()->GetCursorPosition();
90  aPlacer->m_modifiers = evt->Modifier();
91 
92  auto cleanup = [&] ()
93  {
94  newItem = nullptr;
95  preview.Clear();
96  view()->Update( &preview );
97  controls()->SetAutoPan( false );
98  controls()->CaptureCursor( false );
99  controls()->ShowCursor( true );
100  };
101 
102  if( evt->IsCancelInteractive() )
103  {
104  if( aOptions & IPO_SINGLE_CLICK )
105  {
106  cleanup();
107  frame()->PopTool( aTool );
108  break;
109  }
110  else if( newItem )
111  cleanup();
112  else
113  {
114  frame()->PopTool( aTool );
115  break;
116  }
117  }
118  else if( evt->IsActivate() )
119  {
120  if( newItem )
121  cleanup();
122 
123  if( evt->IsPointEditor() )
124  {
125  // don't exit (the point editor runs in the background)
126  }
127  else if( evt->IsMoveTool() )
128  {
129  // leave ourselves on the stack so we come back after the move
130  break;
131  }
132  else
133  {
134  frame()->PopTool( aTool );
135  break;
136  }
137  }
138  else if( evt->IsClick( BUT_LEFT ) )
139  {
140  if( !newItem )
141  {
142  // create the item if possible
143  makeNewItem( cursorPos );
144 
145  // no item created, so wait for another click
146  if( !newItem )
147  continue;
148 
149  controls()->CaptureCursor( true );
150  controls()->SetAutoPan( true );
151  }
152  else
153  {
154  auto oldFlags = newItem->GetFlags();
155  newItem->ClearFlags();
156 
157  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
158  {
159  newItem->SetFlags( oldFlags );
160  continue;
161  }
162 
163  preview.Clear();
164  newItem.release();
165  commit.Push( aCommitMessage );
166 
167  controls()->CaptureCursor( false );
168  controls()->SetAutoPan( false );
169  controls()->ShowCursor( true );
170 
171  if( !( aOptions & IPO_REPEAT ) )
172  break;
173 
174  if( aOptions & IPO_SINGLE_CLICK )
175  makeNewItem( controls()->GetCursorPosition() );
176  }
177  }
178  else if( evt->IsClick( BUT_RIGHT ) )
179  {
181  }
182  else if( newItem && evt->Category() == TC_COMMAND )
183  {
184  /*
185  * Handle any events that can affect the item as we move it around
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(), frame()->Settings().m_FlipLeftRight );
196  view()->Update( &preview );
197  }
198  else if( evt->IsAction( &PCB_ACTIONS::viaSizeInc )
199  || evt->IsAction( &PCB_ACTIONS::viaSizeDec ) )
200  {
201  // Refresh preview after event runs
203  }
204  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
205  {
206  preview.Clear();
207  newItem.release();
208 
209  makeNewItem( controls()->GetCursorPosition() );
210  view()->Update( &preview );
211  }
212  }
213 
214  else if( newItem && evt->IsMotion() )
215  {
216  // track the cursor
217  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
218  aPlacer->SnapItem( newItem.get() );
219 
220  // Show a preview of the item
221  view()->Update( &preview );
222  }
223 
224  else
225  evt->SetPassEvent();
226  }
227 
228  view()->Remove( &preview );
229 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
BOARD * board() const
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:284
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
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:139
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:75
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:142
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
class MODULE, a footprint
Definition: typeinfo.h:89
const PCBNEW_SELECTION & selection() const
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
TOOL_EVENT.
Definition: tool_event.h:171
KIGFX::PCB_VIEW * view() const
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:111
KIGFX::VIEW_CONTROLS * controls() const
MODULE * module() const
PCBNEW_SETTINGS & Settings()
virtual void PopTool(const std::string &actionName)
void Activate()
Function Activate() Runs the tool.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:62
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:285
static TOOL_ACTION refreshPreview
Definition: actions.h:101
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References TOOL_INTERACTIVE::Activate(), KIGFX::PCB_VIEW::Add(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_TOOL_BASE::controls(), INTERACTIVE_PLACER_BASE::CreateItem(), PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_EDIT_FRAME::GetModel(), PCB_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, PCBNEW_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, TOOL_BASE::m_toolMgr, PCB_TOOL_BASE::module(), PCB_MODULE_T, INTERACTIVE_PLACER_BASE::PlaceItem(), EDA_BASE_FRAME::PopTool(), BOARD_COMMIT::Push(), EDA_BASE_FRAME::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetSnapping(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, KIGFX::PCB_VIEW::Update(), PCB_ACTIONS::viaSizeDec, PCB_ACTIONS::viaSizeInc, PCB_TOOL_BASE::view(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

1357 {
1358  BOARD_ITEM* current = nullptr;
1359  PCBNEW_SELECTION highlightGroup;
1360  ACTION_MENU menu( true );
1361 
1362  highlightGroup.SetLayer( LAYER_SELECT_OVERLAY );
1363  getView()->Add( &highlightGroup );
1364 
1365  int limit = std::min( 9, aCollector->GetCount() );
1366 
1367  for( int i = 0; i < limit; ++i )
1368  {
1369  wxString text;
1370  BOARD_ITEM* item = ( *aCollector )[i];
1371  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
1372 
1373  wxString menuText = wxString::Format("&%d. %s", i + 1, text );
1374  menu.Add( menuText, i + 1, item->GetMenuImage() );
1375  }
1376 
1377  if( aTitle.Length() )
1378  menu.SetTitle( aTitle );
1379 
1380  menu.SetIcon( info_xpm );
1381  menu.DisplayTitle( true );
1382  SetContextMenu( &menu, CMENU_NOW );
1383 
1384  while( TOOL_EVENT* evt = Wait() )
1385  {
1386  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1387  {
1388  if( current )
1389  unhighlight( current, BRIGHTENED, &highlightGroup );
1390 
1391  int id = *evt->GetCommandId();
1392 
1393  // User has pointed an item, so show it in a different way
1394  if( id > 0 && id <= limit )
1395  {
1396  current = ( *aCollector )[id - 1];
1397  highlight( current, BRIGHTENED, &highlightGroup );
1398  }
1399  else
1400  {
1401  current = NULL;
1402  }
1403  }
1404  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1405  {
1406  if( current )
1407  unhighlight( current, BRIGHTENED, &highlightGroup );
1408 
1409  OPT<int> id = evt->GetCommandId();
1410 
1411  // User has selected an item, so this one will be returned
1412  if( id && ( *id > 0 ) )
1413  current = ( *aCollector )[*id - 1];
1414  else
1415  current = NULL;
1416 
1417  break;
1418  }
1419  }
1420  getView()->Remove( &highlightGroup );
1421 
1422  if( current )
1423  {
1424  aCollector->Empty();
1425  aCollector->Append( current );
1426  return true;
1427  }
1428 
1429  return false;
1430 }
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
ACTION_MENU.
Definition: action_menu.h:43
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define NULL
TOOL_EVENT.
Definition: tool_event.h:171
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
PCB_BASE_FRAME * m_frame
const BITMAP_OPAQUE info_xpm[1]
Definition: info.cpp:75
virtual void SetLayer(int aLayer)
Function SetLayer() Sets layer used to draw the group.
Definition: view_group.h:115
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
currently selected items overlay
boost::optional< T > OPT
Definition: optional.h:7
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References ACTION_MENU::Add(), KIGFX::VIEW::Add(), COLLECTOR::Append(), BRIGHTENED, CMENU_NOW, ACTION_MENU::DisplayTitle(), COLLECTOR::Empty(), Format(), COLLECTOR::GetCount(), EDA_ITEM::GetMenuImage(), EDA_ITEM::GetSelectMenuText(), EDA_BASE_FRAME::GetUserUnits(), TOOL_BASE::getView(), highlight(), info_xpm, LAYER_SELECT_OVERLAY, m_frame, NULL, KIGFX::VIEW::Remove(), TOOL_INTERACTIVE::SetContextMenu(), ACTION_MENU::SetIcon(), KIGFX::VIEW_GROUP::SetLayer(), ACTION_MENU::SetTitle(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, unhighlight(), and TOOL_INTERACTIVE::Wait().

Referenced by SelectionMenu(), and selectPoint().

◆ EditingModules()

bool PCB_TOOL_BASE::EditingModules ( ) const
inlineinherited

◆ expandConnection()

int SELECTION_TOOL::expandConnection ( const TOOL_EVENT aEvent)
private

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

Definition at line 787 of file selection_tool.cpp.

788 {
789  unsigned initialCount = 0;
790 
791  for( auto item : m_selection.GetItems() )
792  {
793  if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
794  initialCount++;
795  }
796 
797  if( initialCount == 0 )
799 
800  for( KICAD_T stopCondition : { PCB_VIA_T, PCB_PAD_T, EOT } )
801  {
802  // copy the selection, since we're going to iterate and modify
803  std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
804 
805  // We use the BUSY flag to mark connections
806  for( EDA_ITEM* item : selectedItems )
807  item->SetState( BUSY, false );
808 
809  for( EDA_ITEM* item : selectedItems )
810  {
811  TRACK* trackItem = dynamic_cast<TRACK*>( item );
812 
813  // Track items marked BUSY have already been visited
814  if( trackItem && !trackItem->GetState( BUSY ) )
815  selectConnectedTracks( *trackItem, stopCondition );
816  }
817 
818  if( m_selection.GetItems().size() > initialCount )
819  break;
820  }
821 
822  // Inform other potentially interested tools
823  if( m_selection.Size() > 0 )
825 
826  return 0;
827 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:140
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool 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:131
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, KICAD_T aStopCondition)
Selects connecteed tracks and vias.
int GetState(int type) const
Definition: base_struct.h:241

References BUSY, connectedItemFilter(), EOT, SELECTION::GetItems(), EDA_ITEM::GetState(), m_selection, TOOL_BASE::m_toolMgr, PCB_PAD_T, PCB_VIA_T, TOOL_MANAGER::ProcessEvent(), selectConnectedTracks(), selectCursor(), EVENTS::SelectedEvent, and SELECTION::Size().

Referenced by setTransitions().

◆ filterSelection()

int SELECTION_TOOL::filterSelection ( const TOOL_EVENT aEvent)
private

Invoke filter dialog and modify current selection

Definition at line 1265 of file selection_tool.cpp.

1266 {
1267  const BOARD& board = *getModel<BOARD>();
1268  DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
1269  DIALOG_FILTER_SELECTION dlg( m_frame, opts );
1270 
1271  const int cmd = dlg.ShowModal();
1272 
1273  if( cmd != wxID_OK )
1274  return 0;
1275 
1276  // copy current selection
1277  std::deque<EDA_ITEM*> selection = m_selection.GetItems();
1278 
1279  ClearSelection( true /*quiet mode*/ );
1280 
1281  // re-select items from the saved selection according to the dialog options
1282  for( EDA_ITEM* i : selection )
1283  {
1284  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
1285  bool include = itemIsIncludedByFilter( *item, board, opts );
1286 
1287  if( include )
1288  select( item );
1289  }
1290 
1292 
1293  return 0;
1294 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
BOARD * board() const
std::unique_ptr< PRIV > m_priv
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
Struct that will be set with the result of the user choices in the dialog.
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
const PCBNEW_SELECTION & selection() const
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
PCB_BASE_FRAME * m_frame
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Function itemIsIncludedByFilter()
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166

References PCB_TOOL_BASE::board(), ClearSelection(), SELECTION::GetItems(), itemIsIncludedByFilter(), m_frame, m_priv, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), EVENTS::SelectedEvent, and PCB_TOOL_BASE::selection().

Referenced by setTransitions().

◆ find()

int SELECTION_TOOL::find ( const TOOL_EVENT aEvent)
private

Find an item.

Definition at line 1181 of file selection_tool.cpp.

1182 {
1183  DIALOG_FIND dlg( m_frame );
1184  dlg.SetCallback( std::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
1185  dlg.ShowModal();
1186 
1187  return 0;
1188 }
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 1152 of file selection_tool.cpp.

1153 {
1154  bool cleared = false;
1155 
1156  if( m_selection.GetSize() > 0 )
1157  {
1158  // Don't fire an event now; most of the time it will be redundant as we're about to
1159  // fire a SelectedEvent.
1160  cleared = true;
1161  ClearSelection( true /*quiet mode*/ );
1162  }
1163 
1164  if( aItem )
1165  {
1166  select( aItem );
1167  m_frame->FocusOnLocation( aItem->GetPosition() );
1168 
1169  // Inform other potentially interested tools
1171  }
1172  else if( cleared )
1173  {
1175  }
1176 
1178 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
PCB_BASE_FRAME * m_frame
static const TOOL_EVENT ClearedEvent
Definition: actions.h:203
virtual const wxPoint GetPosition() const =0
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...

References EVENTS::ClearedEvent, ClearSelection(), EDA_DRAW_FRAME::FocusOnLocation(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), BOARD_ITEM::GetPosition(), SELECTION::GetSize(), m_frame, m_selection, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ProcessEvent(), select(), and EVENTS::SelectedEvent.

Referenced by find().

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 150 of file pcb_tool_base.h.

151  {
152  return getEditFrame<PCB_BASE_EDIT_FRAME>();
153  }

Referenced by POINT_EDITOR::addCorner(), MICROWAVE_TOOL::addMicrowaveFootprint(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), MODULE_EDITOR_TOOLS::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawVia(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), PCB_EDITOR_CONTROL::ExportSpecctraDSN(), ROUTER_TOOL::finishInteractive(), EDIT_TOOL::Flip(), PCB_EDITOR_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), MODULE_EDITOR_TOOLS::ImportFootprint(), PCB_EDITOR_CONTROL::ImportSpecctraSession(), Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::onViaCommand(), PCBNEW_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), PNS::TOOL_BASE::Reset(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), POINT_EDITOR::updateItem(), PCB_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ getCollectorsGuide()

const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide ( ) const
private

Definition at line 376 of file selection_tool.cpp.

377 {
378  GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(),
379  (PCB_LAYER_ID) view()->GetTopLayer(), view() );
380 
381  // account for the globals
382  guide.SetIgnoreMTextsMarkedNoShow( ! board()->IsElementVisible( LAYER_MOD_TEXT_INVISIBLE ) );
383  guide.SetIgnoreMTextsOnBack( ! board()->IsElementVisible( LAYER_MOD_TEXT_BK ) );
384  guide.SetIgnoreMTextsOnFront( ! board()->IsElementVisible( LAYER_MOD_TEXT_FR ) );
385  guide.SetIgnoreModulesOnBack( ! board()->IsElementVisible( LAYER_MOD_BK ) );
386  guide.SetIgnoreModulesOnFront( ! board()->IsElementVisible( LAYER_MOD_FR ) );
387  guide.SetIgnorePadsOnBack( ! board()->IsElementVisible( LAYER_PAD_BK ) );
388  guide.SetIgnorePadsOnFront( ! board()->IsElementVisible( LAYER_PAD_FR ) );
389  guide.SetIgnoreThroughHolePads( ! board()->IsElementVisible( LAYER_PADS_TH ) );
390  guide.SetIgnoreModulesVals( ! board()->IsElementVisible( LAYER_MOD_VALUES ) );
391  guide.SetIgnoreModulesRefs( ! board()->IsElementVisible( LAYER_MOD_REFERENCES ) );
392  guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIA_THROUGH ) );
393  guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIA_BBLIND ) );
394  guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIA_MICROVIA ) );
395  guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
396 
397  return guide;
398 }
to draw blind/buried vias
BOARD * board() const
multilayer pads, usually with holes
show modules values (when texts are visibles)
show modules on front
PCB_LAYER_ID
A quick note on layer IDs:
to draw usual through hole vias
KIGFX::PCB_VIEW * view() const
smd pads, front layer
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:385
show modules references (when texts are visibles)

References PCB_TOOL_BASE::board(), LAYER_MOD_BK, LAYER_MOD_FR, LAYER_MOD_REFERENCES, LAYER_MOD_TEXT_BK, LAYER_MOD_TEXT_FR, LAYER_MOD_TEXT_INVISIBLE, LAYER_MOD_VALUES, LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_THROUGH, GENERAL_COLLECTORS_GUIDE::SetIgnoreBlindBuriedVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMicroVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesRefs(), GENERAL_COLLECTORS_GUIDE::SetIgnoreModulesVals(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsMarkedNoShow(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnoreMTextsOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnorePadsOnBack(), GENERAL_COLLECTORS_GUIDE::SetIgnorePadsOnFront(), GENERAL_COLLECTORS_GUIDE::SetIgnoreThroughHolePads(), GENERAL_COLLECTORS_GUIDE::SetIgnoreThroughVias(), GENERAL_COLLECTORS_GUIDE::SetIgnoreTracks(), and PCB_TOOL_BASE::view().

Referenced by selectPoint().

◆ getEditFrame()

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

Function getEditFrame()

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

Definition at line 186 of file tool_base.h.

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

References TOOL_BASE::getEditFrameInt().

Referenced by ZONE_CREATE_HELPER::createNewZone().

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

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

References TOOL_BASE::m_toolId.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::isActive(), TOOL_MANAGER::RegisterTool(), ACTION_MANAGER::RunHotKey(), TOOL_MANAGER::runTool(), TOOL_MANAGER::saveViewControls(), and TOOL_MANAGER::ShutdownTool().

◆ GetManager()

TOOL_MANAGER* TOOL_BASE::GetManager ( ) const
inlineinherited

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

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

Definition at line 142 of file tool_base.h.

143  {
144  return m_toolMgr;
145  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ACTION_MENU::getToolManager(), LIB_TREE::onContextMenu(), ZONE_CREATE_HELPER::OnFirstPoint(), ACTION_MENU::OnMenuEvent(), and ZONE_CREATE_HELPER::performZoneCutout().

◆ getModel()

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

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 200 of file tool_base.h.

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

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

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

References TOOL_BASE::m_toolName.

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

◆ GetSelection()

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 109 of file tool_base.h.

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

References TOOL_BASE::m_type.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InvokeTool(), TOOL_MANAGER::ResetTools(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::ShutdownTool().

◆ getView()

KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Function getView()

Returns the instance of VIEW object used in the application. It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 36 of file tool_base.cpp.

37 {
38  return m_toolMgr->GetView();
39 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:280
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218

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(), COMMON_TOOLS::CursorControl(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), COMMON_TOOLS::GridPreset(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), GuessSelectionCandidates(), EE_SELECTION_TOOL::highlight(), highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCB_INSPECTION_TOOL::highlightNet(), EE_POINT_EDITOR::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), Selectable(), GERBVIEW_SELECTION_TOOL::selectable(), EE_SELECTION_TOOL::selectionContains(), selectionContains(), 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(), SCH_EDITOR_CONTROL::UpdateFind(), 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(), zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and ~SELECTION_TOOL().

◆ getViewControls()

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

Function getViewControls()

Returns the instance of VIEW_CONTROLS object used in the application. It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.)

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

43 {
44  return m_toolMgr->GetViewControls();
45 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:285

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), COMMON_TOOLS::GridPreset(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LIB_DRAWING_TOOLS::PlaceAnchor(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), selectCursor(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PICKER_TOOL::setControls(), PCBNEW_PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), LIB_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 129 of file tool_interactive.h.

131 {
132  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
133 
134  goInternal( sptr, aConditions );
135 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:57
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by LENGTH_TUNER_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_CONTROL::setTransitions(), LIB_PIN_TOOL::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), COMMON_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), POINT_EDITOR::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), EDA_3D_VIEWER_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), LIB_CONTROL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), MODULE_EDITOR_TOOLS::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), DRAWING_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), DRC::setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ GuessSelectionCandidates()

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

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

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

Definition at line 1940 of file selection_tool.cpp.

1942 {
1943  std::set<BOARD_ITEM*> preferred;
1944  std::set<BOARD_ITEM*> rejected;
1945  std::set<BOARD_ITEM*> forced;
1946  wxPoint where( aWhere.x, aWhere.y );
1947 
1948  // footprints which are below this percentage of the largest footprint will be considered
1949  // for selection; all others will not
1950  constexpr double footprintToFootprintMinRatio = 0.20;
1951  // pads which are below this percentage of their parent's area will exclude their parent
1952  constexpr double padToFootprintMinRatio = 0.45;
1953  // footprints containing items with items-to-footprint area ratio higher than this will be
1954  // forced to stay on the list
1955  constexpr double footprintMaxCoverRatio = 0.90;
1956  constexpr double viaToPadMinRatio = 0.50;
1957  constexpr double trackViaLengthRatio = 2.0;
1958  constexpr double trackTrackLengthRatio = 0.3;
1959  constexpr double textToFeatureMinRatio = 0.2;
1960  constexpr double textToFootprintMinRatio = 0.4;
1961  // If the common area of two compared items is above the following threshold, they cannot
1962  // be rejected (it means they overlap and it might be hard to pick one by selecting
1963  // its unique area).
1964  constexpr double commonAreaRatio = 0.6;
1965 
1966  PCB_LAYER_ID activeLayer = (PCB_LAYER_ID) view()->GetTopLayer();
1967  LSET silkLayers( 2, B_SilkS, F_SilkS );
1968 
1969  if( silkLayers[activeLayer] )
1970  {
1971  for( int i = 0; i < aCollector.GetCount(); ++i )
1972  {
1973  BOARD_ITEM* item = aCollector[i];
1974  KICAD_T type = item->Type();
1975 
1976  if( ( type == PCB_MODULE_TEXT_T || type == PCB_TEXT_T || type == PCB_LINE_T )
1977  && silkLayers[item->GetLayer()] )
1978  {
1979  preferred.insert( item );
1980  }
1981  }
1982 
1983  if( preferred.size() > 0 )
1984  {
1985  aCollector.Empty();
1986 
1987  for( BOARD_ITEM* item : preferred )
1988  aCollector.Append( item );
1989  return;
1990  }
1991  }
1992 
1993  // Zone edges are very specific; zone fills much less so.
1994  if( aCollector.CountType( PCB_ZONE_AREA_T ) > 0 )
1995  {
1996  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1997  {
1998  if( aCollector[i]->Type() == PCB_ZONE_AREA_T )
1999  {
2000  auto zone = static_cast<ZONE_CONTAINER*>( aCollector[i] );
2001 
2002  if( zone->HitTestForEdge( where, 5 * aCollector.GetGuide()->OnePixelInIU() ) )
2003  preferred.insert( zone );
2004  else
2005  rejected.insert( zone );
2006  }
2007  }
2008 
2009  if( preferred.size() > 0 )
2010  {
2011  aCollector.Empty();
2012 
2013  for( BOARD_ITEM* item : preferred )
2014  aCollector.Append( item );
2015  return;
2016  }
2017  }
2018 
2019  if( aCollector.CountType( PCB_MODULE_TEXT_T ) > 0 )
2020  {
2021  for( int i = 0; i < aCollector.GetCount(); ++i )
2022  {
2023  if( TEXTE_MODULE* txt = dyn_cast<TEXTE_MODULE*>( aCollector[i] ) )
2024  {
2025  double textArea = calcArea( txt );
2026 
2027  for( int j = 0; j < aCollector.GetCount(); ++j )
2028  {
2029  if( i == j )
2030  continue;
2031 
2032  BOARD_ITEM* item = aCollector[j];
2033  double itemArea = calcArea( item );
2034  double areaRatio = calcRatio( textArea, itemArea );
2035  double commonArea = calcCommonArea( txt, item );
2036  double itemCommonRatio = calcRatio( commonArea, itemArea );
2037  double txtCommonRatio = calcRatio( commonArea, textArea );
2038 
2039  if( item->Type() == PCB_MODULE_T )
2040  {
2041  // when text area is small compared to an overlapping footprint,
2042  // then it's a clear sign the text is the selection target
2043  if( areaRatio < textToFootprintMinRatio && itemCommonRatio < commonAreaRatio )
2044  rejected.insert( item );
2045  }
2046 
2047  switch( item->Type() )
2048  {
2049  case PCB_TRACE_T:
2050  case PCB_ARC_T:
2051  case PCB_PAD_T:
2052  case PCB_LINE_T:
2053  case PCB_VIA_T:
2054  case PCB_MODULE_T:
2055  if( areaRatio > textToFeatureMinRatio && txtCommonRatio < commonAreaRatio )
2056  rejected.insert( txt );
2057  break;
2058  default:
2059  break;
2060  }
2061  }
2062  }
2063  }
2064  }
2065 
2066  if( aCollector.CountType( PCB_MODULE_EDGE_T ) + aCollector.CountType( PCB_LINE_T ) > 1 )
2067  {
2068  // Prefer exact hits to sloppy ones
2069  int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
2070  bool found = false;
2071 
2072  for( int dist = 0; dist < accuracy; ++dist )
2073  {
2074  for( int i = 0; i < aCollector.GetCount(); ++i )
2075  {
2076  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2077  {
2078  if( drawSegment->HitTest( where, dist ) )
2079  {
2080  found = true;
2081  break;
2082  }
2083  }
2084  }
2085 
2086  if( found )
2087  {
2088  // throw out everything that is more sloppy than what we found
2089  for( int i = 0; i < aCollector.GetCount(); ++i )
2090  {
2091  if( DRAWSEGMENT* drawSegment = dynamic_cast<DRAWSEGMENT*>( aCollector[i] ) )
2092  {
2093  if( !drawSegment->HitTest( where, dist ) )
2094  rejected.insert( drawSegment );
2095  }
2096  }
2097 
2098  // we're done now
2099  break;
2100  }
2101  }
2102  }
2103 
2104  if( aCollector.CountType( PCB_PAD_T ) > 0 )
2105  {
2106  for( int i = 0; i < aCollector.GetCount(); ++i )
2107  {
2108  if( D_PAD* pad = dyn_cast<D_PAD*>( aCollector[i] ) )
2109  {
2110  MODULE* parent = pad->GetParent();
2111  double ratio = calcRatio( calcArea( pad ), calcArea( parent ) );
2112 
2113  // when pad area is small compared to the parent footprint,
2114  // then it is a clear sign the pad is the selection target
2115  if( ratio < padToFootprintMinRatio )
2116  rejected.insert( pad->GetParent() );
2117  }
2118  }
2119  }
2120 
2121  if( aCollector.CountType( PCB_MODULE_T ) > 0 )
2122  {
2123  double maxArea = calcMaxArea( aCollector, PCB_MODULE_T );
2124  BOX2D viewportD = getView()->GetViewport();
2125  BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );
2126  double maxCoverRatio = footprintMaxCoverRatio;
2127 
2128  // MODULE::CoverageRatio() doesn't take zone handles & borders into account so just
2129  // use a more aggressive cutoff point if zones are involved.
2130  if( aCollector.CountType( PCB_ZONE_AREA_T ) )
2131  maxCoverRatio /= 2;
2132 
2133  for( int i = 0; i < aCollector.GetCount(); ++i )
2134  {
2135  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
2136  {
2137  // filter out components larger than the viewport
2138  if( mod->ViewBBox().Contains( viewport ) )
2139  rejected.insert( mod );
2140  // footprints completely covered with other features have no other
2141  // means of selection, so must be kept
2142  else if( mod->CoverageRatio( aCollector ) > maxCoverRatio )
2143  rejected.erase( mod );
2144  // if a footprint is much smaller than the largest overlapping
2145  // footprint then it should be considered for selection
2146  else if( calcRatio( calcArea( mod ), maxArea ) <= footprintToFootprintMinRatio )
2147  continue;
2148  // reject ALL OTHER footprints if there's still something else left
2149  // to select
2150  else if( (int)( rejected.size() + 1 ) < aCollector.GetCount() )
2151  rejected.insert( mod );
2152  }
2153  }
2154  }
2155 
2156  if( aCollector.CountType( PCB_VIA_T ) > 0 )
2157  {
2158  for( int i = 0; i < aCollector.GetCount(); ++i )
2159  {
2160  if( VIA* via = dyn_cast<VIA*>( aCollector[i] ) )
2161  {
2162  double viaArea = calcArea( via );
2163 
2164  for( int j = 0; j < aCollector.GetCount(); ++j )
2165  {
2166  if( i == j )
2167  continue;
2168 
2169  BOARD_ITEM* item = aCollector[j];
2170  double areaRatio = calcRatio( viaArea, calcArea( item ) );
2171 
2172  if( item->Type() == PCB_MODULE_T && areaRatio < padToFootprintMinRatio )
2173  rejected.insert( item );
2174 
2175  if( item->Type() == PCB_PAD_T && areaRatio < viaToPadMinRatio )
2176  rejected.insert( item );
2177 
2178  if( TRACK* track = dyn_cast<TRACK*>( item ) )
2179  {
2180  if( track->GetNetCode() != via->GetNetCode() )
2181  continue;
2182 
2183  double lenRatio = (double) ( track->GetLength() + track->GetWidth() ) /
2184  (double) via->GetWidth();
2185 
2186  if( lenRatio > trackViaLengthRatio )
2187  rejected.insert( track );
2188  }
2189  }
2190  }
2191  }
2192  }
2193 
2194  int nTracks = aCollector.CountType( PCB_TRACE_T );
2195 
2196  if( nTracks > 0 )
2197  {
2198  double maxLength = 0.0;
2199  double minLength = std::numeric_limits<double>::max();
2200  double maxArea = 0.0;
2201  const TRACK* maxTrack = nullptr;
2202 
2203  for( int i = 0; i < aCollector.GetCount(); ++i )
2204  {
2205  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2206  {
2207  maxLength = std::max( track->GetLength(), maxLength );
2208  maxLength = std::max( (double) track->GetWidth(), maxLength );
2209 
2210  minLength = std::min( std::max( track->GetLength(), (double) track->GetWidth() ), minLength );
2211 
2212  double area = track->GetLength() * track->GetWidth();
2213 
2214  if( area > maxArea )
2215  {
2216  maxArea = area;
2217  maxTrack = track;
2218  }
2219  }
2220  }
2221 
2222  if( maxLength > 0.0 && minLength / maxLength < trackTrackLengthRatio && nTracks > 1 )
2223  {
2224  for( int i = 0; i < aCollector.GetCount(); ++i )
2225  {
2226  if( TRACK* track = dyn_cast<TRACK*>( aCollector[i] ) )
2227  {
2228  double ratio = std::max( (double) track->GetWidth(), track->GetLength() ) / maxLength;
2229 
2230  if( ratio > trackTrackLengthRatio )
2231  rejected.insert( track );
2232  }
2233  }
2234  }
2235 
2236  for( int j = 0; j < aCollector.GetCount(); ++j )
2237  {
2238  if( MODULE* mod = dyn_cast<MODULE*>( aCollector[j] ) )
2239  {
2240  double ratio = calcRatio( maxArea, mod->GetFootprintRect().GetArea() );
2241 
2242  if( ratio < padToFootprintMinRatio && calcCommonArea( maxTrack, mod ) < commonAreaRatio )
2243  rejected.insert( mod );
2244  }
2245  }
2246  }
2247 
2248  if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
2249  {
2250  for( BOARD_ITEM* item : rejected )
2251  {
2252  aCollector.Remove( item );
2253  }
2254  }
2255 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:109
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:538
static double calcCommonArea(const BOARD_ITEM *aItem, const BOARD_ITEM *aOther)
static const int dist[10][10]
Definition: ar_matrix.cpp:326
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual double OnePixelInIU() const =0
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
const COLLECTORS_GUIDE * GetGuide()
Definition: collectors.h:347
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
int CountType(KICAD_T aType)
Function CountType counts the number of items matching aType.
Definition: collector.h:216
static double calcArea(const BOARD_ITEM *aItem)
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:129
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:119
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
static double calcMaxArea(GENERAL_COLLECTOR &aCollector, KICAD_T aType)
virtual int GetTopLayer() const
Definition: view.cpp:851
KIGFX::PCB_VIEW * view() const
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
const Vec & GetPosition() const
Definition: box2.h:193
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
double calcRatio(double a, double b)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const Vec & GetSize() const
Definition: box2.h:188
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References COLLECTOR::Append(), B_SilkS, calcArea(), calcCommonArea(), calcMaxArea(), calcRatio(), COLLECTOR::CountType(), dist, COLLECTOR::Empty(), F_SilkS, COLLECTOR::GetCount(), GENERAL_COLLECTOR::GetGuide(), BOARD_ITEM::GetLayer(), BOARD_ITEM::GetParent(), BOX2< Vec >::GetPosition(), BOX2< Vec >::GetSize(), KIGFX::VIEW::GetTopLayer(), TOOL_BASE::getView(), KIGFX::VIEW::GetViewport(), KiROUND(), COLLECTORS_GUIDE::OnePixelInIU(), PCB_ARC_T, PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, COLLECTOR::Remove(), EDA_ITEM::Type(), PCB_TOOL_BASE::view(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ highlight()

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

Function highlight() Highlights the item visually.

Parameters
aItemis an item to be be highlighted.
aHighlightModeshould be either SELECTED or BRIGHTENED
aGroupis the group to add the item to in the BRIGHTENED mode.

Definition at line 1741 of file selection_tool.cpp.

1742 {
1743  if( aMode == SELECTED )
1744  aItem->SetSelected();
1745  else if( aMode == BRIGHTENED )
1746  aItem->SetBrightened();
1747 
1748  if( aGroup )
1749  {
1750  // Hide the original item, so it is shown only on overlay
1751  view()->Hide( aItem, true );
1752 
1753  aGroup->Add( aItem );
1754  }
1755 
1756  // Modules are treated in a special way - when they are highlighted, we have to
1757  // highlight all the parts that make the module, not the module itself
1758  if( aItem->Type() == PCB_MODULE_T )
1759  {
1760  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1761  {
1762  if( aMode == SELECTED )
1763  item->SetSelected();
1764  else if( aMode == BRIGHTENED )
1765  {
1766  item->SetBrightened();
1767 
1768  if( aGroup )
1769  aGroup->Add( item );
1770  }
1771 
1772  if( aGroup )
1773  view()->Hide( item, true );
1774  });
1775  }
1776 
1777  view()->Update( aItem );
1778 
1779  // Many selections are very temporal and updating the display each time just
1780  // creates noise.
1781  if( aMode == BRIGHTENED )
1783 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1507
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetBrightened()
Definition: base_struct.h:233
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
#define SELECTED
Definition: base_struct.h:127
class MODULE, a footprint
Definition: typeinfo.h:89
void SetSelected()
Definition: base_struct.h:231
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

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

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

◆ Init()

bool SELECTION_TOOL::Init ( )
overridevirtual

Function Init() Init() is called once upon a registration of the tool.

Returns
True if the initialization went fine, false - otherwise.

Reimplemented from PCB_TOOL_BASE.

Definition at line 131 of file selection_tool.cpp.

132 {
133  auto frame = getEditFrame<PCB_BASE_FRAME>();
134 
137  {
139  return true;
140  }
141 
142  auto selectMenu = std::make_shared<SELECT_MENU>();
143  selectMenu->SetTool( this );
144  m_menu.AddSubMenu( selectMenu );
145 
146  auto& menu = m_menu.GetMenu();
147 
148  menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
149  menu.AddSeparator( 1000 );
150 
151  if( frame )
153 
154  return true;
155 }
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
PCB_BASE_EDIT_FRAME * frame() const
bool IsType(FRAME_T aType) const
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52

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

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

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

186 {
187  // Main loop: keep receiving events
188  while( TOOL_EVENT* evt = Wait() )
189  {
190  if( m_frame->ToolStackIsEmpty() )
191  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
192 
193  bool dragAlwaysSelects = getEditFrame<PCB_BASE_FRAME>()->GetDragSelects();
195 
196  // OSX uses CTRL for context menu, and SHIFT is exclusive-or
197 #ifdef __WXOSX_MAC__
198  if( evt->Modifier( MD_SHIFT ) )
199  m_exclusive_or = true;
200 #else
201  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
202  m_subtractive = true;
203  else if( evt->Modifier( MD_SHIFT ) )
204  m_additive = true;
205  else if( evt->Modifier( MD_CTRL ) )
206  m_exclusive_or = true;
207 #endif
208 
209  // Is the user requesting that the selection list include all possible
210  // items without removing less likely selection candidates
211  m_skip_heuristics = !!evt->Modifier( MD_ALT );
212 
213  // Single click? Select single object
214  if( evt->IsClick( BUT_LEFT ) )
215  {
216  m_frame->FocusOnItem( nullptr );
217 
218  selectPoint( evt->Position() );
219  }
220 
221  // right click? if there is any object - show the context menu
222  else if( evt->IsClick( BUT_RIGHT ) )
223  {
224  bool selectionCancelled = false;
225 
226  if( m_selection.Empty() ||
227  !m_selection.GetBoundingBox().Contains( wxPoint( evt->Position() ) ) )
228  {
229  ClearSelection();
230  selectPoint( evt->Position(), false, &selectionCancelled );
231  m_selection.SetIsHover( true );
232  }
233 
234  if( !selectionCancelled )
236  }
237 
238  // double click? Display the properties window
239  else if( evt->IsDblClick( BUT_LEFT ) )
240  {
241  m_frame->FocusOnItem( nullptr );
242 
243  if( m_selection.Empty() )
244  selectPoint( evt->Position() );
245 
247  }
248 
249  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
250  else if( evt->IsDrag( BUT_LEFT ) )
251  {
252  m_frame->FocusOnItem( nullptr );
253 
254  if( m_additive || m_subtractive || m_exclusive_or || dragAlwaysSelects )
255  {
256  selectMultiple();
257  }
258  else
259  {
260  // selection is empty? try to start dragging the item under the point where drag
261  // started
262  if( m_selection.Empty() && selectCursor() )
263  m_selection.SetIsHover( true );
264 
265  // Check if dragging has started within any of selected items bounding box
266  if( selectionContains( evt->Position() ) )
267  {
268  // Yes -> run the move tool and wait till it finishes
270  }
271  else
272  {
273  // No -> drag a selection box
274  selectMultiple();
275  }
276  }
277  }
278 
279  else if( evt->IsCancel() )
280  {
281  m_frame->FocusOnItem( nullptr );
282 
283  ClearSelection();
284 
285  if( evt->FirstResponder() == this )
287  }
288 
289  else if( evt->Action() == TA_UNDO_REDO_PRE )
290  {
291  ClearSelection();
292  }
293 
294  else
295  evt->SetPassEvent();
296  }
297 
298  return 0;
299 }
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
bool Contains(const wxPoint &aPoint) const
Function Contains.
void SetIsHover(bool aIsHover)
Definition: selection.h:65
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectPoint() Selects an item pointed by the parameter aWhere.
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
TOOL_EVENT.
Definition: tool_event.h:171
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
static TOOL_ACTION drag
Definition: pcb_actions.h:104
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:408
bool ToolStackIsEmpty()
EDA_RECT GetBoundingBox() const
Definition: selection.h:155
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
void FocusOnItem(BOARD_ITEM *aItem)

References BUT_LEFT, BUT_RIGHT, PCB_ACTIONS::clearHighlight, ClearSelection(), EDA_RECT::Contains(), PCB_ACTIONS::drag, SELECTION::Empty(), PCB_BASE_FRAME::FocusOnItem(), SELECTION::GetBoundingBox(), PCB_BASE_FRAME::GetCanvas(), m_additive, m_exclusive_or, m_frame, TOOL_INTERACTIVE::m_menu, m_selection, m_skip_heuristics, m_subtractive, TOOL_BASE::m_toolMgr, MD_ALT, MD_CTRL, MD_SHIFT, PCB_ACTIONS::properties, TOOL_MANAGER::RunAction(), selectCursor(), selectionContains(), selectMultiple(), selectPoint(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), SELECTION::SetIsHover(), TOOL_MENU::ShowContextMenu(), TA_UNDO_REDO_PRE, EDA_BASE_FRAME::ToolStackIsEmpty(), and TOOL_INTERACTIVE::Wait().

Referenced by setTransitions().

◆ module()

◆ pickSmallestComponent()

BOARD_ITEM * SELECTION_TOOL::pickSmallestComponent ( GENERAL_COLLECTOR aCollector)
private

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

Parameters
aCollectorcontaines the list of items.

Definition at line 1433 of file selection_tool.cpp.

1434 {
1435  int count = aCollector->GetPrimaryCount(); // try to use preferred layer
1436 
1437  if( 0 == count )
1438  count = aCollector->GetCount();
1439 
1440  for( int i = 0; i < count; ++i )
1441  {
1442  if( ( *aCollector )[i]->Type() != PCB_MODULE_T )
1443  return NULL;
1444  }
1445 
1446  // All are modules, now find smallest MODULE
1447  int minDim = 0x7FFFFFFF;
1448  int minNdx = 0;
1449 
1450  for( int i = 0; i < count; ++i )
1451  {
1452  MODULE* module = (MODULE*) ( *aCollector )[i];
1453 
1454  int lx = module->GetFootprintRect().GetWidth();
1455  int ly = module->GetFootprintRect().GetHeight();
1456 
1457  int lmin = std::min( lx, ly );
1458 
1459  if( lmin < minDim )
1460  {
1461  minDim = lmin;
1462  minNdx = i;
1463  }
1464  }
1465 
1466  return (*aCollector)[minNdx];
1467 }
int GetWidth() const
Definition: eda_rect.h:119
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text.
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
class MODULE, a footprint
Definition: typeinfo.h:89
#define NULL
int GetHeight() const
Definition: eda_rect.h:120
MODULE * module() const

References COLLECTOR::GetCount(), MODULE::GetFootprintRect(), EDA_RECT::GetHeight(), GENERAL_COLLECTOR::GetPrimaryCount(), EDA_RECT::GetWidth(), PCB_TOOL_BASE::module(), NULL, and PCB_MODULE_T.

◆ RebuildSelection()

void SELECTION_TOOL::RebuildSelection ( )

Rebuilds the selection from the EDA_ITEMs' selection flags.

Commonly called after rolling back an undo state to make sure there aren't any stale pointers.

Definition at line 1321 of file selection_tool.cpp.

1322 {
1323  m_selection.Clear();
1324 
1325  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1326  {
1327  if( item->IsSelected() )
1328  {
1329  EDA_ITEM* parent = item->GetParent();
1330 
1331  // Flags on module children might be set only because the parent is selected.
1332  if( parent && parent->Type() == PCB_MODULE_T && parent->IsSelected() )
1333  return SEARCH_RESULT::CONTINUE;
1334 
1335  highlight( (BOARD_ITEM*) item, SELECTED, &m_selection );
1336  }
1337 
1338  return SEARCH_RESULT::CONTINUE;
1339  };
1340 
1341  board()->Visit( inspector, nullptr, m_editModules ? GENERAL_COLLECTOR::ModuleItems
1343 }
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:94
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: base_struct.h:83
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
BOARD * board() const
bool IsSelected() const
Definition: base_struct.h:225
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCBNEW_SELECTION m_selection
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
#define SELECTED
Definition: base_struct.h:127
class MODULE, a footprint
Definition: typeinfo.h:89
EDA_ITEM * GetParent() const
Definition: base_struct.h:217
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

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

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

◆ RemoveItemFromSel()

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

Definition at line 744 of file selection_tool.cpp.

745 {
746  if( aItem )
747  {
748  unselect( aItem );
749 
750  // Inform other potentially interested tools
752  }
753 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:202
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.

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

Referenced by BOARD_COMMIT::Push(), and UnselectItem().

◆ RequestSelection()

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

Function RequestSelection()

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

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

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

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

Definition at line 308 of file selection_tool.cpp.

311 {
312  bool selectionEmpty = m_selection.Empty();
313  m_selection.SetIsHover( selectionEmpty );
314 
315  if( selectionEmpty )
316  {
317  m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, aClientFilter );
319  }
320 
321  if ( aConfirmLockedItems && CheckLock() == SELECTION_LOCKED )
322  {
323  ClearSelection();
324  return m_selection;
325  }
326 
327  if( aClientFilter )
328  {
329  GENERAL_COLLECTOR collector;
330 
331  for( auto item : m_selection )
332  collector.Append( item );
333 
334  aClientFilter( VECTOR2I(), collector );
335 
336  /*
337  * The first step is to find the items that may have been added by the client filter
338  * This can happen if the locked pads select the module instead
339  */
340  std::vector<EDA_ITEM*> new_items;
341  std::set_difference( collector.begin(), collector.end(),
343  std::back_inserter( new_items ) );
344 
348  std::vector<EDA_ITEM*> diff;
349  std::set_difference( m_selection.begin(), m_selection.end(),
350  collector.begin(), collector.end(),
351  std::back_inserter( diff ) );
352 
353  if( aFiltered )
354  {
355  for( auto item : diff )
356  aFiltered->push_back( static_cast<BOARD_ITEM*>( item ) );
357  }
358 
363  for( auto item : diff )
364  unhighlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
365 
366  for( auto item : new_items )
367  highlight( static_cast<BOARD_ITEM*>( item ), SELECTED, &m_selection );
368 
370  }
371 
372  return m_selection;
373 }
void ClearReferencePoint()
Definition: selection.h:249
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
ITER end()
Definition: selection.h:61
ITER begin()
Definition: collector.h:91
PCBNEW_SELECTION m_selection
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
ITER end()
Definition: collector.h:92
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetIsHover(bool aIsHover)
Definition: selection.h:65
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:119
#define SELECTED
Definition: base_struct.h:127
ITER begin()
Definition: selection.h:60
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
PCB_BASE_FRAME * m_frame
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:70
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.

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

Referenced by EDIT_TOOL::ChangeTrackWidth(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::Duplicate(), EDIT_TOOL::EditFpInFpEditor(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), EDIT_TOOL::Mirror(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), EDIT_TOOL::Rotate(), and POSITION_RELATIVE_TOOL::SelectPositionRelativeItem().

◆ Reset()

void SELECTION_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Function Reset() Brings the tool to a known, initial state.

If the tool claimed anything from the model or the view, it must release it when its reset.

Parameters
aReasoncontains information about the reason of tool reset.

Reimplemented from PCB_TOOL_BASE.

Definition at line 158 of file selection_tool.cpp.

159 {
160  m_frame = getEditFrame<PCB_BASE_FRAME>();
161  m_locked = true;
162 
163  if( aReason == TOOL_BASE::MODEL_RELOAD )
164  {
165  // Deselect any item being currently in edit, to avoid unexpected behavior
166  // and remove pointers to the selected items from containers
167  // without changing their properties (as they are already deleted
168  // while a new board is loaded)
169  ClearSelection( true );
170 
171  getView()->GetPainter()->GetSettings()->SetHighlight( false );
172  }
173  else
174  {
175  // Restore previous properties of selected items and remove them from containers
176  ClearSelection( true );
177  }
178 
179  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
180  view()->Remove( &m_selection );
181  view()->Add( &m_selection );
182 }
Model changes (required full reload)
Definition: tool_base.h:81
PCBNEW_SELECTION m_selection
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aHighlightItems=false)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer,...
Definition: painter.h:136
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
KIGFX::PCB_VIEW * view() const
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58

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

◆ RunMainStack()

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

Function RunMainStack()

Calls a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 87 of file tool_interactive.cpp.

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

1714 {
1715  if( aItem->IsSelected() )
1716  {
1717  return;
1718  }
1719 
1720  if( aItem->Type() == PCB_PAD_T )
1721  {
1722  MODULE* module = static_cast<MODULE*>( aItem->GetParent() );
1723 
1724  if( m_selection.Contains( module ) )
1725  return;
1726  }
1727 
1728  highlight( aItem, SELECTED, &m_selection );
1729 }
bool IsSelected() const
Definition: base_struct.h:225
PCBNEW_SELECTION m_selection
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
#define SELECTED
Definition: base_struct.h:127
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:112
MODULE * module() const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

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

Referenced by AddItemToSel(), filterSelection(), findCallback(), selectAllItemsOnNet(), selectAllItemsOnSheet(), selectConnectedTracks(), SelectItems(), selectMultiple(), and selectPoint().

◆ Selectable()

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

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

Returns
True if the item fulfills conditions to be selected.

Definition at line 1470 of file selection_tool.cpp.

1471 {
1472  // Is high contrast mode enabled?
1473  bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast();
1474 
1475  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
1476 
1477  // Filter out items that do not belong to active layers
1478  std::set<unsigned int> activeLayers = getView()->GetPainter()->GetSettings()->GetActiveLayers();
1479 
1480  aItem->ViewGetLayers( layers, layers_count );
1481 
1482  if( highContrast )
1483  {
1484  bool onActive = false; // Is the item on any of active layers?
1485 
1486  for( int i = 0; i < layers_count; ++i )
1487  {
1488  if( activeLayers.count( layers[i] ) > 0 ) // Item is on at least one of the active layers
1489  {
1490  onActive = true;
1491  break;
1492  }
1493  }
1494 
1495  if( !onActive ) // We do not want to select items that are in the background
1496  {
1497  return false;
1498  }
1499  }
1500 
1501  switch( aItem->Type() )
1502  {
1503  case PCB_ZONE_AREA_T:
1504  {
1505  // Check to see if this keepout is part of a footprint
1506  // If it is, and we are not editing the footprint, it should not be selectable
1507  const bool zoneInFootprint =
1508  aItem->GetParent() != nullptr && aItem->GetParent()->Type() == PCB_MODULE_T;
1509  if( zoneInFootprint && !m_editModules && !checkVisibilityOnly )
1510  return false;
1511 
1512  // Keepout zones can exist on multiple layers!
1513  {
1514  auto* zone = static_cast<const ZONE_CONTAINER*>( aItem );
1515 
1516  if( zone->GetIsKeepout() )
1517  {
1518  auto zoneLayers = zone->GetLayerSet().Seq();
1519 
1520  for( unsigned int i = 0; i < zoneLayers.size(); i++ )
1521  {
1522  if( board()->IsLayerVisible( zoneLayers[i] ) )
1523  {
1524  return true;
1525  }
1526  }
1527 
1528  // No active layers selected!
1529  return false;
1530  }
1531  }
1532  }
1533  break;
1534 
1535  case PCB_TRACE_T:
1536  case PCB_ARC_T:
1537  {
1538  if( !board()->IsElementVisible( LAYER_TRACKS ) )
1539  return false;
1540  }
1541  break;
1542 
1543  case PCB_VIA_T:
1544  {
1545  const VIA* via = static_cast<const VIA*>( aItem );
1546 
1547  // Check if appropriate element layer is visible
1548  switch( via->GetViaType() )
1549  {
1550  case VIATYPE::THROUGH:
1552  return false;
1553  break;
1554 
1555  case VIATYPE::BLIND_BURIED:
1557  return false;
1558  break;
1559 
1560  case VIATYPE::MICROVIA:
1562  return false;
1563  break;
1564 
1565  default:
1566  wxFAIL;
1567  return false;
1568  }
1569 
1570  // For vias it is enough if only one of its layers is visible
1571  return ( board()->GetVisibleLayers() & via->GetLayerSet() ).any();
1572  }
1573 
1574  case PCB_MODULE_T:
1575  {
1576  // In modedit, we do not want to select the module itself.
1577  if( m_editModules )
1578  return false;
1579 
1580  // Allow selection of footprints if some part of the footprint is visible.
1581 
1582  MODULE* module = const_cast<MODULE*>( static_cast<const MODULE*>( aItem ) );
1583 
1584  for( auto item : module->GraphicalItems() )
1585  {
1586  if( Selectable( item, true ) )
1587  return true;
1588  }
1589 
1590  for( auto pad : module->Pads() )
1591  {
1592  if( Selectable( pad, true ) )
1593  return true;
1594  }
1595 
1596  for( auto zone : module->Zones() )
1597  {
1598  if( Selectable( zone, true ) )
1599  return true;
1600  }
1601 
1602  return false;
1603  }
1604 
1605  case PCB_MODULE_TEXT_T:
1606  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1607  // module subparts one by one, rather than with a drag selection. This is so you can
1608  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1609  if( !m_editModules && !checkVisibilityOnly )
1610  {
1611  if( m_multiple )
1612  return false;
1613  }
1614 
1615  if( !m_editModules && !view()->IsVisible( aItem ) )
1616  return false;
1617 
1618  break;
1619 
1620  case PCB_MODULE_EDGE_T:
1621  case PCB_PAD_T:
1622  {
1623  // Multiple selection is only allowed in modedit mode. In pcbnew, you have to select
1624  // module subparts one by one, rather than with a drag selection. This is so you can
1625  // pick up items under an (unlocked) module without also moving the module's sub-parts.
1626  if( !m_editModules && !checkVisibilityOnly )
1627  {
1628  if( m_multiple )
1629  return false;
1630  }
1631 
1632  if( aItem->Type() == PCB_PAD_T )
1633  {
1634  auto pad = static_cast<const D_PAD*>( aItem );
1635 
1636  // In pcbnew, locked modules prevent individual pad selection.
1637  // In modedit, we don't enforce this as the module is assumed to be edited by design.
1638  if( !m_editModules && !checkVisibilityOnly )
1639  {
1640  if( pad->GetParent() && pad->GetParent()->IsLocked() )
1641  return false;
1642  }
1643 
1644  // Check render mode (from the Items tab) first
1645  switch( pad->GetAttribute() )
1646  {
1647  case PAD_ATTRIB_STANDARD:
1649  if( !board()->IsElementVisible( LAYER_PADS_TH ) )
1650  return false;
1651  break;
1652 
1653  case PAD_ATTRIB_CONN:
1654  case PAD_ATTRIB_SMD:
1655  if( pad->IsOnLayer( F_Cu ) && !board()->IsElementVisible( LAYER_PAD_FR ) )
1656  return false;
1657  else if( pad->IsOnLayer( B_Cu ) && !board()->IsElementVisible( LAYER_PAD_BK ) )
1658  return false;
1659  break;
1660  }
1661 
1662  // Otherwise, pads are selectable if any draw layer is visible
1663 
1664  // Shortcut: check copper layer visibility
1665  if( board()->IsLayerVisible( F_Cu ) && pad->IsOnLayer( F_Cu ) )
1666  return true;
1667 
1668  if( board()->IsLayerVisible( B_Cu ) && pad->IsOnLayer( B_Cu ) )
1669  return true;
1670 
1671  // Now check the non-copper layers
1672 
1673  bool draw_layer_visible = false;
1674 
1675  int pad_layers[KIGFX::VIEW::VIEW_MAX_LAYERS], pad_layers_count;
1676  pad->ViewGetLayers( pad_layers, pad_layers_count );
1677 
1678  for( int i = 0; i < pad_layers_count; ++i )
1679  {
1680  // NOTE: Only checking the regular layers (not GAL meta-layers)
1681  if( ( ( pad_layers[i] < PCB_LAYER_ID_COUNT ) &&
1682  board()->IsLayerVisible( static_cast<PCB_LAYER_ID>( pad_layers[i] ) ) ) )
1683  {
1684  draw_layer_visible = true;
1685  }
1686  }
1687 
1688  return draw_layer_visible;
1689  }
1690 
1691  break;
1692  }
1693 
1694 
1695  case PCB_MARKER_T: // Always selectable
1696  return true;
1697 
1698  // These are not selectable
1699  case NOT_USED:
1700  case TYPE_NOT_INIT:
1701  return false;
1702 
1703  default: // Suppress warnings
1704  break;
1705  }
1706 
1707  // All other items are selected only if the layer on which they exist is visible
1708  return board()->IsLayerVisible( aItem->GetLayer() )
1709  && aItem->ViewGetLOD( aItem->GetLayer(), view() ) < view()->GetScale();
1710 }
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
virtual unsigned int ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:140
the 3d code uses this value
Definition: typeinfo.h:80
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
PADS & Pads()
Definition: class_module.h:173
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
class MODULE, a footprint
Definition: typeinfo.h:89
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1526
to draw usual through hole vias
KIGFX::PCB_VIEW * view() const
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:188
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:158
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:431
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
smd pads, front layer
MODULE * module() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
VIATYPE GetViaType() const
Definition: class_track.h:416
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
double GetScale() const
Function GetScale()
Definition: view.h:257
BOARD_ITEM_CONTAINER * GetParent() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
const std::set< unsigned int > GetActiveLayers()
Function GetActiveLayers() Returns the set of currently active layers.
Definition: painter.h:84

References B_Cu, BLIND_BURIED, PCB_TOOL_BASE::board(), F_Cu, KIGFX::RENDER_SETTINGS::GetActiveLayers(), KIGFX::RENDER_SETTINGS::GetHighContrast(), BOARD_ITEM::GetLayer(), VIA::GetLayerSet(), KIGFX::VIEW::GetPainter(), BOARD_ITEM::GetParent(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), VIA::GetViaType(), TOOL_BASE::getView(), BOARD::GetVisibleLayers(), MODULE::GraphicalItems(), BOARD::IsElementVisible(), BOARD::IsLayerVisible(), KIGFX::VIEW::IsVisible(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PADS_TH, LAYER_TRACKS, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA, LAYER_VIA_THROUGH, PCB_TOOL_BASE::m_editModules, m_multiple, MICROVIA, PCB_TOOL_BASE::module(), NOT_USED, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED, PAD_ATTRIB_SMD, PAD_ATTRIB_STANDARD, MODULE::Pads(), PCB_ARC_T, PCB_LAYER_ID_COUNT, PCB_MARKER_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, THROUGH, EDA_ITEM::Type(), TYPE_NOT_INIT, PCB_TOOL_BASE::view(), KIGFX::VIEW::VIEW_MAX_LAYERS, BOARD_ITEM::ViewGetLayers(), KIGFX::VIEW_ITEM::ViewGetLOD(), and MODULE::Zones().

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

◆ selectAllItemsOnNet()

void SELECTION_TOOL::selectAllItemsOnNet ( int  aNetCode)
private

Selects all items with the given net code.

Definition at line 940 of file selection_tool.cpp.

941 {
942  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
943  auto connectivity = board()->GetConnectivity();
944 
945  for( BOARD_CONNECTED_ITEM* item : connectivity->GetNetItems( aNetCode, types ) )
946  select( item );
947 }
BOARD * board() const
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:306
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

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

Referenced by selectNet().

◆ selectAllItemsOnSheet()

void SELECTION_TOOL::selectAllItemsOnSheet ( wxString &  aSheetID)
private

Selects all items with the given sheet timestamp name (the sheet path)

Definition at line 974 of file selection_tool.cpp.

975 {
976  KIID uuid( aSheetID );
977  std::list<MODULE*> modList;
978 
979  // store all modules that are on that sheet
980  for( MODULE* module : board()->Modules() )
981  {
982  if( module == nullptr )
983  continue;
984 
985  for( const KIID& pathStep : module->GetPath() )
986  {
987  if( pathStep == uuid )
988  {
989  modList.push_back( module );
990  break;
991  }
992  }
993  }
994 
995  //Generate a list of all pads, and of all nets they belong to.
996  std::list<int> netcodeList;
997  std::list<D_PAD*> padList;
998  for( MODULE* mmod : modList )
999  {
1000  for( D_PAD* pad : mmod->Pads() )
1001  {
1002  if( pad->IsConnected() )
1003  {
1004  netcodeList.push_back( pad->GetNetCode() );
1005  padList.push_back( pad );
1006  }
1007  }
1008  }
1009  // remove all duplicates
1010  netcodeList.sort();
1011  netcodeList.unique();
1012 
1013  // auto select trivial connections segments which are launched from the pads
1014  std::list<TRACK*> launchTracks;
1015 
1016  for( D_PAD* pad : padList )
1017  selectConnectedTracks( *pad, EOT );
1018 
1019  // now we need to find all modules that are connected to each of these nets
1020  // then we need to determine if these modules are in the list of modules
1021  // belonging to this sheet ( modList )
1022  std::list<int> removeCodeList;
1023  constexpr KICAD_T padType[] = { PCB_PAD_T, EOT };
1024 
1025  for( int netCode : netcodeList )
1026  {
1027  for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
1028  {
1029  if( mitem->Type() == PCB_PAD_T)
1030  {
1031  bool found = std::find( modList.begin(), modList.end(), mitem->GetParent() ) != modList.end();
1032 
1033  if( !found )
1034  {
1035  // if we cannot find the module of the pad in the modList
1036  // then we can assume that that module is not located in the same
1037  // schematic, therefore invalidate this netcode.
1038  removeCodeList.push_back( netCode );
1039  break;
1040  }
1041  }
1042  }
1043  }
1044 
1045  // remove all duplicates
1046  removeCodeList.sort();
1047  removeCodeList.unique();
1048 
1049  for( int removeCode : removeCodeList )
1050  {
1051  netcodeList.remove( removeCode );
1052  }
1053 
1054  std::list<BOARD_CONNECTED_ITEM*> localConnectionList;
1055  constexpr KICAD_T trackViaType[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
1056 
1057  for( int netCode : netcodeList )
1058  {
1059  for( BOARD_CONNECTED_ITEM* item : board()->GetConnectivity()->GetNetItems( netCode, trackViaType ) )
1060  localConnectionList.push_back( item );
1061  }
1062 
1063  for( BOARD_ITEM* i : modList )
1064  {
1065  if( i != NULL )
1066  select( i );
1067  }
1068 
1069  for( BOARD_CONNECTED_ITEM* i : localConnectionList )
1070  {
1071  if( i != NULL )
1072  select( i );
1073  }
1074 }
BOARD * board() const
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
const KIID_PATH & GetPath() const
Definition: class_module.h:228
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
Definition: common.h:65
#define NULL
MODULE * module() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, KICAD_T aStopCondition)
Selects connecteed tracks and vias.

References PCB_TOOL_BASE::board(), EOT, MODULE::GetPath(), PCB_TOOL_BASE::module(), NULL, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, select(), and selectConnectedTracks().

Referenced by selectSameSheet(), and selectSheetContents().

◆ selectConnectedTracks()

void SELECTION_TOOL::selectConnectedTracks ( BOARD_CONNECTED_ITEM aSourceItem,
KICAD_T  aStopCondition 
)
private

Selects connecteed tracks and vias.

Parameters
aStopConditionmust be one of JUNCTION_T, PAD_T, or EOT.

Definition at line 830 of file selection_tool.cpp.

832 {
833  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, EOT };
834 
835  auto connectivity = board()->GetConnectivity();
836  auto connectedItems = connectivity->GetConnectedItems( &aStartItem, types );
837 
838  std::map<wxPoint, std::vector<TRACK*>> trackMap;
839  std::map<wxPoint, VIA*> viaMap;
840  std::map<wxPoint, D_PAD*> padMap;
841 
842  // Build maps of connected items
843  for( BOARD_CONNECTED_ITEM* item : connectedItems )
844  {
845  switch( item->Type() )
846  {
847  case PCB_TRACE_T:
848  {
849  TRACK* track = static_cast<TRACK*>( item );
850  trackMap[ track->GetStart() ].push_back( track );
851  trackMap[ track->GetEnd() ].push_back( track );
852  }
853  break;
854  case PCB_VIA_T:
855  {
856  VIA* via = static_cast<VIA*>( item );
857  viaMap[ via->GetStart() ] = via;
858  }
859  break;
860  case PCB_PAD_T:
861  {
862  D_PAD* pad = static_cast<D_PAD*>( item );
863  padMap[ pad->GetPosition() ] = pad;
864  }
865  break;
866  default:
867  break;
868  }
869 
870  item->SetState( SKIP_STRUCT, false );
871  }
872 
873  std::vector<wxPoint> activePts;
874 
875  // Set up the initial active points
876  switch( aStartItem.Type() )
877  {
878  case PCB_TRACE_T:
879  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
880  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetEnd() );
881  break;
882  case PCB_VIA_T:
883  activePts.push_back( static_cast<TRACK*>( &aStartItem )->GetStart() );
884  break;
885  case PCB_PAD_T:
886  activePts.push_back( aStartItem.GetPosition() );
887  break;
888  default:
889  break;
890  }
891 
892  bool expand = true;
893 
894  // Iterative push from all active points
895  while( expand )
896  {
897  expand = false;
898 
899  for( int i = activePts.size() - 1; i >= 0; --i )
900  {
901  wxPoint pt = activePts[i];
902 
903  if( trackMap[ pt ].size() > 2 && aStopCondition == SCH_JUNCTION_T )
904  {
905  activePts.erase( activePts.begin() + i );
906  continue;
907  }
908 
909  if( padMap.count( pt ) && aStopCondition != EOT )
910  {
911  activePts.erase( activePts.begin() + i );
912  continue;
913  }
914 
915  for( TRACK* track : trackMap[ pt ] )
916  {
917  if( track->GetState( SKIP_STRUCT ) )
918  continue;
919 
920  track->SetState( SKIP_STRUCT, true );
921  select( track );
922 
923  if( track->GetStart() == pt )
924  activePts.push_back( track->GetEnd() );
925  else
926  activePts.push_back( track->GetStart() );
927 
928  expand = true;
929  }
930 
931  if( viaMap.count( pt ) && !viaMap[ pt ]->IsSelected() )
932  select( viaMap[ pt ] );
933 
934  activePts.erase( activePts.begin() + i );
935  }
936  }
937 }
BOARD * board() const
const wxPoint & GetStart() const
Definition: class_track.h:111
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:131
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:306
void SetState(int type, int state)
Definition: base_struct.h:246
const wxPoint & GetEnd() const
Definition: class_track.h:108
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxPoint GetPosition() const override
Definition: class_pad.h:241
int GetState(int type) const
Definition: base_struct.h:241

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

Referenced by expandConnection(), and selectAllItemsOnSheet().

◆ selectCursor()

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

Function selectCursor() Selects an item under the cursor unless there is something already selected or aSelectAlways is true.

Parameters
aForceSelectforces to select an item even if there is an item already selected.
aClientFilterallows the client to perform tool- or action-specific filtering.
Returns
true if eventually there is an item selected, false otherwise.

Definition at line 487 of file selection_tool.cpp.

488 {
489  if( aForceSelect || m_selection.Empty() )
490  {
491  ClearSelection( true /*quiet mode*/ );
492  selectPoint( getViewControls()->GetCursorPosition( false ), false, NULL, aClientFilter );
493  }
494 
495  return !m_selection.Empty();
496 }
PCBNEW_SELECTION m_selection
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectPoint() Selects an item pointed by the parameter aWhere.
#define NULL
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42

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

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

◆ selection() [1/2]

const PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( ) const
protectedinherited

Definition at line 270 of file pcb_tool_base.cpp.

271 {
272  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
273  const auto& selection = selTool->GetSelection();
274  return selection;
275 }
SELECTION_TOOL.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
const PCBNEW_SELECTION & selection() const

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

Referenced by AUTOPLACE_TOOL::autoplaceSelected(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PAD_TOOL::copyPadSettings(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawZone(), EDIT_TOOL::Duplicate(), EDIT_TOOL::EditFpInFpEditor(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), filterSelection(), EDIT_TOOL::Flip(), DRAWING_TOOL::getSourceZoneForAction(), PCB_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), POINT_EDITOR::OnSelectionChange(), PAD_TOOL::pastePadProperties(), PCBNEW_CONTROL::placeBoardItems(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EDIT_TOOL::Rotate(), PCB_TOOL_BASE::selection(), selectNet(), DRAWING_TOOL::SetAnchor(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), PCB_EDITOR_CONTROL::ZoneDuplicate(), ZONE_FILLER_TOOL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfill().

◆ selection() [2/2]

PCBNEW_SELECTION & PCB_TOOL_BASE::selection ( )
protectedinherited

Definition at line 278 of file pcb_tool_base.cpp.

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

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

◆ selectionContains()

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

Function selectionContains()

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

Definition at line 1833 of file selection_tool.cpp.

1834 {
1835  const unsigned GRIP_MARGIN = 20;
1836  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1837 
1838  // Check if the point is located within any of the currently selected items bounding boxes
1839  for( auto item : m_selection )
1840  {
1841  BOX2I itemBox = item->ViewBBox();
1842  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1843 
1844  if( itemBox.Contains( aPoint ) )
1845  return true;
1846  }
1847 
1848  return false;
1849 }
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:475
PCBNEW_SELECTION m_selection
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:301

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

Referenced by Main().

◆ SelectionMenu()

int SELECTION_TOOL::SelectionMenu ( const TOOL_EVENT aEvent)

Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.

NOTE: this routine DOES NOT modify the selection.

Definition at line 1346 of file selection_tool.cpp.

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

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

Referenced by setTransitions().

◆ SelectItem()

int SELECTION_TOOL::SelectItem ( const TOOL_EVENT aEvent)

Item selection event handler.

Definition at line 700 of file selection_tool.cpp.

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

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

Referenced by setTransitions().

◆ SelectItems()

int SELECTION_TOOL::SelectItems ( const TOOL_EVENT aEvent)

Multiple item selection event handler

Definition at line 683 of file selection_tool.cpp.

684 {
685  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
686 
687  if( items )
688  {
689  // Perform individual selection of each item before processing the event.
690  for( auto item : *items )
691  select( item );
692 
694  }
695 
696  return 0;
697 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435

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

Referenced by setTransitions().

◆ selectMultiple()

bool SELECTION_TOOL::selectMultiple ( )
private

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

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

Definition at line 499 of file selection_tool.cpp.

500 {
501  bool cancelled = false; // Was the tool cancelled while it was running?
502  m_multiple = true; // Multiple selection mode is active
503  KIGFX::VIEW* view = getView();
504 
506  view->Add( &area );
507 
508  bool anyAdded = false;
509  bool anySubtracted = false;
510 
511  while( TOOL_EVENT* evt = Wait() )
512  {
513  if( evt->IsCancelInteractive() || evt->IsActivate() )
514  {
515  cancelled = true;
516  break;
517  }
518 
519  if( evt->IsDrag( BUT_LEFT ) )
520  {
522  {
523  if( m_selection.GetSize() > 0 )
524  {
525  anySubtracted = true;
526  ClearSelection( true /*quiet mode*/ );
527  }
528  }
529 
530  // Start drawing a selection box
531  area.SetOrigin( evt->DragOrigin() );
532  area.SetEnd( evt->Position() );
533  area.SetAdditive( m_additive );
536 
537  view->SetVisible( &area, true );
538  view->Update( &area );
539  getViewControls()->SetAutoPan( true );
540  }
541 
542  if( evt->IsMouseUp( BUT_LEFT ) )
543  {
544  getViewControls()->SetAutoPan( false );
545 
546  // End drawing the selection box
547  view->SetVisible( &area, false );
548 
549  // Mark items within the selection box as selected
550  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
551 
552  // Filter the view items based on the selection box
553  BOX2I selectionBox = area.ViewBBox();
554  view->Query( selectionBox, selectedItems ); // Get the list of selected items
555 
556  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
557 
558  int width = area.GetEnd().x - area.GetOrigin().x;
559  int height = area.GetEnd().y - area.GetOrigin().y;
560 
561  /* Selection mode depends on direction of drag-selection:
562  * Left > Right : Select objects that are fully enclosed by selection
563  * Right > Left : Select objects that are crossed by selection
564  */
565  bool windowSelection = width >= 0 ? true : false;
566 
567  if( view->IsMirroredX() )
568  windowSelection = !windowSelection;
569 
570  // Construct an EDA_RECT to determine BOARD_ITEM selection
571  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
572 
573  selectionRect.Normalize();
574 
575  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
576  {
577  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
578 
579  if( !item || !Selectable( item ) )
580  continue;
581 
582  if( item->HitTest( selectionRect, windowSelection ) )
583  {
584  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
585  {
586  unselect( item );
587  anySubtracted = true;
588  }
589  else
590  {
591  select( item );
592  anyAdded = true;
593  }
594  }
595  }
596 
597  m_selection.SetIsHover( false );
598 
599  // Inform other potentially interested tools
600  if( anyAdded )
602  else if( anySubtracted )
604 
605  break; // Stop waiting for events
606  }
607  }
608 
609  getViewControls()->SetAutoPan( false );
610 
611  // Stop drawing the selection box
612  view->Remove( &area );
613  m_multiple = false; // Multiple selection mode is inactive
614 
615  if( !cancelled )
617 
618  return cancelled;
619 }
void ClearReferencePoint()
Definition: selection.h:249
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
bool IsSelected() const
Definition: base_struct.h:225
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:202
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetOrigin(VECTOR2I aOrigin)
Set the origin of the rectange (the fixed corner)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
void SetExclusiveOr(bool aExclusiveOr)
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
void SetIsHover(bool aIsHover)
Definition: selection.h:65
void SetAdditive(bool aAdditive)
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:332
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_EVENT.
Definition: tool_event.h:171
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
KIGFX::PCB_VIEW * view() const
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
void SetSubtractive(bool aSubtractive)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void Normalize()
Function Normalize ensures that the height ant width are positive.
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1486
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:452
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VIEW.
Definition: view.h:61

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

Referenced by Main().

◆ selectNet()

int SELECTION_TOOL::selectNet ( const TOOL_EVENT aEvent)
private

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

Definition at line 950 of file selection_tool.cpp.

951 {
952  if( !selectCursor() )
953  return 0;
954 
955  // copy the selection, since we're going to iterate and modify
956  auto selection = m_selection.GetItems();
957 
958  for( EDA_ITEM* i : selection )
959  {
960  BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
961 
962  if( connItem )
963  selectAllItemsOnNet( connItem->GetNetCode() );
964  }
965 
966  // Inform other potentially interested tools
967  if( m_selection.Size() > 0 )
969 
970  return 0;
971 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
int GetNetCode() const
Function GetNetCode.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
const PCBNEW_SELECTION & selection() const
void selectAllItemsOnNet(int aNetCode)
Selects all items with the given net code.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166

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

Referenced by setTransitions().

◆ selectPoint()

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

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

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

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

Definition at line 401 of file selection_tool.cpp.

404 {
406  GENERAL_COLLECTOR collector;
407  auto& displayOpts = m_frame->GetDisplayOptions();
408  bool cleared = false;
409 
410  guide.SetIgnoreZoneFills( displayOpts.m_DisplayZonesMode != 0 );
411 
412  collector.Collect( board(),
414  wxPoint( aWhere.x, aWhere.y ), guide );
415 
416  // Remove unselectable items
417  for( int i = collector.GetCount() - 1; i >= 0; --i )
418  {
419  if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
420  collector.Remove( i );
421  }
422 
424 
425  // Allow the client to do tool- or action-specific filtering to see if we
426  // can get down to a single item
427  if( aClientFilter )
428  aClientFilter( aWhere, collector );
429 
430  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
431  if( collector.GetCount() > 1 && !m_skip_heuristics )
432  {
433  GuessSelectionCandidates( collector, aWhere );
434  }
435 
436  // If still more than one item we're going to have to ask the user.
437  if( collector.GetCount() > 1 )
438  {
439  if( aOnDrag )
441 
442  if( !doSelectionMenu( &collector, _( "Clarify Selection" ) ) )
443  {
444  if( aSelectionCancelledFlag )
445  *aSelectionCancelledFlag = true;
446 
447  return false;
448  }
449  }
450 
452  {
453  if( m_selection.GetSize() > 0 )
454  {
455  // Don't fire an event now as it will end up redundant if we fire a SelectedEvent
456  // or an UnselectedEvent.
457  cleared = true;
458  ClearSelection( true );
459  }
460  }
461 
462  if( collector.GetCount() == 1 )
463  {
464  BOARD_ITEM* item = collector[ 0 ];
465 
466  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
467  {
468  unselect( item );
470  return false;
471  }
472  else
473  {
474  select( item );
476  return true;
477  }
478  }
479 
480  if( cleared )
482 
483  return false;
484 }
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
void ClearReferencePoint()
Definition: selection.h:249
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
Definition: collectors.h:267
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
BOARD * board() const
bool IsSelected() const
Definition: base_struct.h:225
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:202
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:535
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
PCBNEW_SELECTION m_selection
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:129
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:100
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_EVENT.
Definition: tool_event.h:171
PCB_BASE_FRAME * m_frame
static const TOOL_EVENT ClearedEvent
Definition: actions.h:203
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
#define _(s)
Definition: 3d_actions.cpp:33
static const KICAD_T ModuleItems[]
A scan list for primary module items.
Definition: collectors.h:308
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
bool doSelectionMenu(GENERAL_COLLECTOR *aItems, const wxString &aTitle)
Allows the selection of a single item from a list via pop-up menu.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:385
void SetIgnoreZoneFills(bool ignore)
Definition: collectors.h:610

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

Referenced by Main(), and selectCursor().

◆ selectSameSheet()

int SELECTION_TOOL::selectSameSheet ( const TOOL_EVENT aEvent)
private

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

Definition at line 1117 of file selection_tool.cpp.

1118 {
1119  if( !selectCursor( true ) )
1120  return 0;
1121 
1122  // this function currently only supports modules since they are only
1123  // on one sheet.
1124  auto item = m_selection.Front();
1125 
1126  if( !item )
1127  return 0;
1128 
1129  if( item->Type() != PCB_MODULE_T )
1130  return 0;
1131 
1132  auto mod = dynamic_cast<MODULE*>( item );
1133 
1134  if( mod->GetPath().empty() )
1135  return 0;
1136 
1137  ClearSelection( true /*quiet mode*/ );
1138 
1139  // get the lowest subsheet name for this.
1140  wxString sheetID = mod->GetPath().back().AsString();
1141 
1142  selectAllItemsOnSheet( sheetID );
1143 
1144  // Inform other potentially interested tools
1145  if( m_selection.Size() > 0 )
1147 
1148  return 0;
1149 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
class MODULE, a footprint
Definition: typeinfo.h:89
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
void selectAllItemsOnSheet(wxString &aSheetID)
Selects all items with the given sheet timestamp name (the sheet path)
EDA_ITEM * Front() const
Definition: selection.h:183

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

Referenced by setTransitions().

◆ selectSheetContents()

int SELECTION_TOOL::selectSheetContents ( const TOOL_EVENT aEvent)
private

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

Definition at line 1101 of file selection_tool.cpp.

1102 {
1103  ClearSelection( true /*quiet mode*/ );
1104  wxString* sheetID = aEvent.Parameter<wxString*>();
1105 
1106  selectAllItemsOnSheet( *sheetID );
1107 
1108  zoomFitSelection();
1109 
1110  if( m_selection.Size() > 0 )
1112 
1113  return 0;
1114 }
static const TOOL_EVENT SelectedEvent
Definition: actions.h:201
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
PCBNEW_SELECTION m_selection
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
void zoomFitSelection()
Zooms the screen to center and fit the current selection.
void selectAllItemsOnSheet(wxString &aSheetID)
Selects all items with the given sheet timestamp name (the sheet path)

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

Referenced by setTransitions().

◆ SetContextMenu()

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

Function SetContextMenu()

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

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

Definition at line 76 of file tool_interactive.cpp.

77 {
78  if( aMenu )
79  aMenu->SetTool( this );
80  else
81  aTrigger = CMENU_OFF;
82 
83  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
84 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
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(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ SetEditModules()

void PCB_TOOL_BASE::SetEditModules ( bool  aEnabled)
inlineinherited

Function SetEditModules()

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

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 101 of file pcb_tool_base.h.

102  {
103  m_editModules = aEnabled;
104  }

References PCB_TOOL_BASE::m_editModules.

◆ setTransitions()

void SELECTION_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from PCB_TOOL_BASE.

Definition at line 2281 of file selection_tool.cpp.

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

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

◆ UnbrightenItem()

void SELECTION_TOOL::UnbrightenItem ( BOARD_ITEM aItem)

Definition at line 762 of file selection_tool.cpp.

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

References BRIGHTENED, and unhighlight().

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

◆ unhighlight()

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

Function unhighlight() Unhighlights the item visually.

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

Definition at line 1786 of file selection_tool.cpp.

1787 {
1788  if( aMode == SELECTED )
1789  aItem->ClearSelected();
1790  else if( aMode == BRIGHTENED )
1791  aItem->ClearBrightened();
1792 
1793  if( aGroup )
1794  {
1795  aGroup->Remove( aItem );
1796 
1797  // Restore original item visibility
1798  view()->Hide( aItem, false );
1799  }
1800 
1801  // Modules are treated in a special way - when they are highlighted, we have to
1802  // highlight all the parts that make the module, not the module itself
1803  if( aItem->Type() == PCB_MODULE_T )
1804  {
1805  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1806  {
1807  if( aMode == SELECTED )
1808  item->ClearSelected();
1809  else if( aMode == BRIGHTENED )
1810  item->ClearBrightened();
1811 
1812  // N.B. if we clear the selection flag for sub-elements, we need to also
1813  // remove the element from the selection group (if it exists)
1814  if( aGroup )
1815  {
1816  aGroup->Remove( item );
1817 
1818  view()->Hide( item, false );
1819  view()->Update( item );
1820  }
1821  });
1822  }
1823 
1824  view()->Update( aItem );
1825 
1826  // Many selections are very temporal and updating the display each time just
1827  // creates noise.
1828  if( aMode == BRIGHTENED )
1830 }
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1507
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ClearSelected()
Definition: base_struct.h:235
void ClearBrightened()
Definition: base_struct.h:237
#define SELECTED
Definition: base_struct.h:127
class MODULE, a footprint
Definition: typeinfo.h:89
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:585
KIGFX::PCB_VIEW * view() const
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:86

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

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

◆ unselect()

void SELECTION_TOOL::unselect ( BOARD_ITEM aItem)
private

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

Parameters
aItemis an item to be unselected.

Definition at line 1732 of file selection_tool.cpp.

1733 {
1734  unhighlight( aItem, SELECTED, &m_selection );
1735 
1736  if( m_selection.Empty() )
1737  m_locked = true;
1738 }
PCBNEW_SELECTION m_selection
#define SELECTED
Definition: base_struct.h:127
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.

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

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

◆ UnselectItem()

int SELECTION_TOOL::UnselectItem ( const TOOL_EVENT aEvent)

Item unselection event handler.

Definition at line 737 of file selection_tool.cpp.

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

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

Referenced by setTransitions().

◆ UnselectItems()

int SELECTION_TOOL::UnselectItems ( const TOOL_EVENT aEvent)

Multiple item unselection event handler

Definition at line 720 of file selection_tool.cpp.

721 {
722  std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
723 
724  if( items )
725  {
726  // Perform individual unselection of each item before processing the event
727  for( auto item : *items )
728  unselect( item );
729 
731  }
732 
733  return 0;
734 }
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:202
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
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 2266 of file selection_tool.cpp.

2267 {
2268  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
2269  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
2270 
2271  if( conditionalMenu )
2272  conditionalMenu->Evaluate( m_selection );
2273 
2274  if( actionMenu )
2275  actionMenu->UpdateAll();
2276 
2277  return 0;
2278 }
ACTION_MENU.
Definition: action_menu.h:43
PCBNEW_SELECTION m_selection
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435

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

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

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

Referenced by setTransitions().

◆ view()

◆ Wait()

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

Function Wait()

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

Definition at line 57 of file tool_interactive.cpp.

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

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EE_SELECTION_TOOL::doSelectionMenu(), doSelectionMenu(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), CVPCB_CONTROL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), EDA_3D_VIEWER_CONTROL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), EE_SELECTION_TOOL::selectMultiple(), selectMultiple(), GERBVIEW_SELECTION_TOOL::selectPoint(), selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ zoomFitSelection()

void SELECTION_TOOL::zoomFitSelection ( )

Zooms the screen to center and fit the current selection.

Definition at line 1077 of file selection_tool.cpp.

1078 {
1079  //Should recalculate the view to zoom in on the selection
1080  auto selectionBox = m_selection.ViewBBox();
1081  auto view = getView();
1082 
1083  VECTOR2D screenSize = view->ToWorld( m_frame->GetCanvas()->GetClientSize(), false );
1084  screenSize.x = std::max( 10.0, screenSize.x );
1085  screenSize.y = std::max( 10.0, screenSize.y );
1086 
1087  if( selectionBox.GetWidth() != 0 || selectionBox.GetHeight() != 0 )
1088  {
1089  VECTOR2D vsize = selectionBox.GetSize();
1090  double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
1091  fabs( vsize.y / screenSize.y ) );
1092  view->SetScale( scale );
1093  view->SetCenter( selectionBox.Centre() );
1094  view->Add( &m_selection );
1095  }
1096 
1098 }
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:475
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCBNEW_SELECTION m_selection
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:604
KIGFX::PCB_VIEW * view() const
PCB_BASE_FRAME * m_frame
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:578
const int scale
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
double GetScale() const
Function GetScale()
Definition: view.h:257
virtual const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers.
Definition: selection.h:142

References KIGFX::PCB_VIEW::Add(), EDA_DRAW_PANEL_GAL::ForceRefresh(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW::GetScale(), TOOL_BASE::getView(), m_frame, m_selection, 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 321 of file selection_tool.h.

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

◆ m_editModules

◆ m_exclusive_or

bool SELECTION_TOOL::m_exclusive_or
private

Definition at line 323 of file selection_tool.h.

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

◆ m_frame

◆ m_locked

bool SELECTION_TOOL::m_locked
private

Definition at line 326 of file selection_tool.h.

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

◆ m_menu

TOOL_MENU TOOL_INTERACTIVE::m_menu
protectedinherited

functions below are not yet implemented - their interface may change

Definition at line 108 of file tool_interactive.h.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), TOOL_INTERACTIVE::GetToolMenu(), PICKER_TOOL::Init(), SCH_EDIT_TOOL::Init(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init(), LIB_DRAWING_TOOLS::Init(), EDA_3D_VIEWER_CONTROL::Init(), MODULE_EDITOR_TOOLS::Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), SCH_DRAWING_TOOLS::Init(), GERBVIEW_SELECTION_TOOL::Init(), DRAWING_TOOL::Init(), EE_SELECTION_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EDIT_TOOL::Init(), PCB_TOOL_BASE::Init(), SCH_MOVE_TOOL::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), EDA_3D_VIEWER_CONTROL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ m_multiple

bool SELECTION_TOOL::m_multiple
private

Definition at line 324 of file selection_tool.h.

Referenced by Selectable(), and selectMultiple().

◆ m_priv

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

Definition at line 329 of file selection_tool.h.

Referenced by filterSelection().

◆ m_selection

◆ m_skip_heuristics

bool SELECTION_TOOL::m_skip_heuristics
private

Definition at line 325 of file selection_tool.h.

Referenced by Main(), and selectPoint().

◆ m_subtractive

bool SELECTION_TOOL::m_subtractive
private

Definition at line 322 of file selection_tool.h.

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

◆ m_toolId

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 213 of file tool_base.h.

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

◆ m_toolMgr

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 218 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), EE_SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::AddItemToSel(), AddItemToSel(), CVPCB_ASSOCIATION_TOOL::Associate(), TOOL_BASE::attachManager(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PCB_INSPECTION_TOOL::ClearHighlight(), SCH_EDITOR_CONTROL::ClearHighlight(), ClearSelection(), GERBVIEW_SELECTION_TOOL::clearSelection(), EE_SELECTION_TOOL::ClearSelection(), SCH_EDIT_TOOL::ConvertDeMorgan(), LIB_EDIT_TOOL::Copy(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), COMMON_TOOLS::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), SCH_EDITOR_CONTROL::Cut(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), LIB_EDIT_TOOL::DoDelete(), SCH_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::Duplicate(), EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::editFieldText(), EDIT_TOOL::EditFpInFpEditor(), LIB_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithLibEdit(), SCH_EDITOR_CONTROL::EnterSheet(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), filterSelection(), findCallback(), SCH_EDITOR_CONTROL::FindComponentAndItem(), POINT_EDITOR::finishItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), EDIT_TOOL::Flip(), EDIT_TOOL::GetAndPlace(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), GERBVIEW_CONTROL::HighlightControl(), PCB_INSPECTION_TOOL::HighlightItem(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PAD_TOOL::Init(), GLOBAL_EDIT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), POINT_EDITOR::Init(), POSITION_RELATIVE_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), TOOL_BASE::IsToolActive(), SCH_EDITOR_CONTROL::LeaveSheet(), COMMON_CONTROL::ListHotKeys(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), SCH_MOVE_TOOL::Main(), CVPCB_CONTROL::Main(), LIB_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LIB_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), LIB_CONTROL::OnDeMorgan(), LIB_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), EDIT_TOOL::pickCopyReferencePoint(), LIB_EDIT_TOOL::PinTable(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), PCBNEW_CONTROL::Print(), GERBVIEW_CONTROL::Print(), LIB_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(),