KiCad PCB EDA Suite
pl_selection_tool.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #include <bitmaps.h>
27 #include <view/view.h>
28 #include <view/view_controls.h>
30 #include <pl_editor_frame.h>
31 #include <tool/tool_event.h>
32 #include <tool/tool_manager.h>
33 #include <tool/selection.h>
34 #include <tools/pl_actions.h>
35 #include <ws_data_model.h>
36 #include <ws_draw_item.h>
37 #include <collector.h>
38 #include "pl_selection_tool.h"
39 #include <math/util.h> // for KiROUND
40 
45 #define MAX_SELECT_ITEM_IDS 40
46 
47 
48 SELECTION_CONDITION PL_CONDITIONS::Idle = [] (const SELECTION& aSelection )
49 {
50  return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
51 };
52 
53 
54 #define HITTEST_THRESHOLD_PIXELS 3
55 
56 
58  TOOL_INTERACTIVE( "plEditor.InteractiveSelection" ),
59  m_frame( nullptr ),
60  m_additive( false ),
61  m_subtractive( false ),
62  m_exclusive_or( false ),
63  m_multiple( false ),
64  m_skip_heuristics( false )
65 {
66 }
67 
68 
70 {
71  m_frame = getEditFrame<PL_EDITOR_FRAME>();
72 
73  auto& menu = m_menu.GetMenu();
74 
75  menu.AddSeparator( 200 );
76  menu.AddItem( PL_ACTIONS::drawLine, PL_CONDITIONS::Idle, 250 );
77  menu.AddItem( PL_ACTIONS::drawRectangle, PL_CONDITIONS::Idle, 250 );
78  menu.AddItem( PL_ACTIONS::placeText, PL_CONDITIONS::Idle, 250 );
79  menu.AddItem( PL_ACTIONS::placeImage, PL_CONDITIONS::Idle, 250 );
81 
82  menu.AddSeparator( 1000 );
84 
85  return true;
86 }
87 
88 
90 {
91  if( aReason == MODEL_RELOAD )
92  m_frame = getEditFrame<PL_EDITOR_FRAME>();
93 }
94 
95 
97 {
98  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
99  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
100 
101  if( conditionalMenu )
102  conditionalMenu->Evaluate( m_selection );
103 
104  if( actionMenu )
105  actionMenu->UpdateAll();
106 
107  return 0;
108 }
109 
110 
112 {
113  // Main loop: keep receiving events
114  while( TOOL_EVENT* evt = Wait() )
115  {
116  if( m_frame->ToolStackIsEmpty() )
117  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
118 
120 
121  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
122  m_subtractive = true;
123  else if( evt->Modifier( MD_SHIFT ) )
124  m_additive = true;
125  else if( evt->Modifier( MD_CTRL ) )
126  m_exclusive_or = true;
127 
128  // Is the user requesting that the selection list include all possible
129  // items without removing less likely selection candidates
130  m_skip_heuristics = !!evt->Modifier( MD_ALT );
131 
132  // Single click? Select single object
133  if( evt->IsClick( BUT_LEFT ) )
134  {
135  SelectPoint( evt->Position());
136  }
137 
138  // right click? if there is any object - show the context menu
139  else if( evt->IsClick( BUT_RIGHT ) )
140  {
141  bool selectionCancelled = false;
142 
143  if( m_selection.Empty() )
144  {
145  SelectPoint( evt->Position(), &selectionCancelled );
146  m_selection.SetIsHover( true );
147  }
148 
149  if( !selectionCancelled )
151  }
152 
153  // double click? Display the properties window
154  else if( evt->IsDblClick( BUT_LEFT ) )
155  {
156  // No double-click actions currently defined
157  }
158 
159  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
160  else if( evt->IsDrag( BUT_LEFT ) )
161  {
163  {
164  selectMultiple();
165  }
166  else
167  {
168  // Check if dragging has started within any of selected items bounding box
169  if( selectionContains( evt->Position() ) )
170  {
171  // Yes -> run the move tool and wait till it finishes
172  m_toolMgr->InvokeTool( "plEditor.InteractiveEdit" );
173  }
174  else
175  {
176  // No -> clear the selection list
177  ClearSelection();
178  }
179  }
180  }
181 
182  else if( evt->IsCancelInteractive() )
183  {
184  ClearSelection();
185  }
186 
187  else if( evt->Action() == TA_UNDO_REDO_PRE )
188  {
189  ClearSelection();
190  }
191 
192  else
193  evt->SetPassEvent();
194  }
195 
196  return 0;
197 }
198 
199 
201 {
202  return m_selection;
203 }
204 
205 
206 EDA_ITEM* PL_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag )
207 {
208  int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
209 
210  // locate items.
211  COLLECTOR collector;
212 
213  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
214  {
215  for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() )
216  {
217  if( drawItem->HitTest( (wxPoint) aWhere, threshold ) )
218  collector.Append( drawItem );
219  }
220  }
221 
223 
224  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
225  if( collector.GetCount() > 1 && !m_skip_heuristics )
226  {
227  guessSelectionCandidates( collector, aWhere );
228  }
229 
230  // If still more than one item we're going to have to ask the user.
231  if( collector.GetCount() > 1 )
232  {
233  collector.m_MenuTitle = _( "Clarify Selection" );
234 
235  // Must call selectionMenu via RunAction() to avoid event-loop contention
236  m_toolMgr->RunAction( PL_ACTIONS::selectionMenu, true, &collector );
237 
238  if( collector.m_MenuCancelled )
239  {
240  if( aSelectionCancelledFlag )
241  *aSelectionCancelledFlag = true;
242 
243  return nullptr;
244  }
245  }
246 
248  ClearSelection();
249 
250  if( collector.GetCount() == 1 )
251  {
252  EDA_ITEM* item = collector[ 0 ];
253 
254  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
255  {
256  unselect( item );
258  return nullptr;
259  }
260  else
261  {
262  select( item );
264  return item;
265  }
266  }
267 
268  return nullptr;
269 }
270 
271 
273 {
274  // There are certain conditions that can be handled automatically.
275 
276  // Prefer an exact hit to a sloppy one
277  for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
278  {
279  EDA_ITEM* item = collector[ i ];
280  EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
281 
282  if( item->HitTest( (wxPoint) aPos, 0 ) && !other->HitTest( (wxPoint) aPos, 0 ) )
283  collector.Transfer( other );
284  }
285 }
286 
287 
289 {
290  // If nothing is selected do a hover selection
291  if( m_selection.Empty() )
292  {
293  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
294 
295  ClearSelection();
296  SelectPoint( cursorPos );
297  m_selection.SetIsHover( true );
298  }
299 
300  return m_selection;
301 }
302 
303 
305 {
306  bool cancelled = false; // Was the tool cancelled while it was running?
307  m_multiple = true; // Multiple selection mode is active
308  KIGFX::VIEW* view = getView();
309 
311  view->Add( &area );
312 
313  while( TOOL_EVENT* evt = Wait() )
314  {
315  if( evt->IsCancelInteractive() || evt->IsActivate() )
316  {
317  cancelled = true;
318  break;
319  }
320 
321  if( evt->IsDrag( BUT_LEFT ) )
322  {
324  ClearSelection();
325 
326  // Start drawing a selection box
327  area.SetOrigin( evt->DragOrigin() );
328  area.SetEnd( evt->Position() );
329  area.SetAdditive( m_additive );
332 
333  view->SetVisible( &area, true );
334  view->Update( &area );
335  getViewControls()->SetAutoPan( true );
336  }
337 
338  if( evt->IsMouseUp( BUT_LEFT ) )
339  {
340  getViewControls()->SetAutoPan( false );
341 
342  // End drawing the selection box
343  view->SetVisible( &area, false );
344 
345  int width = area.GetEnd().x - area.GetOrigin().x;
346  int height = area.GetEnd().y - area.GetOrigin().y;
347 
348  /* Selection mode depends on direction of drag-selection:
349  * Left > Right : Select objects that are fully enclosed by selection
350  * Right > Left : Select objects that are crossed by selection
351  */
352  bool windowSelection = width >= 0 ? true : false;
353  bool anyAdded = false;
354  bool anySubtracted = false;
355 
356  // Construct an EDA_RECT to determine EDA_ITEM selection
357  EDA_RECT selectionRect( (wxPoint)area.GetOrigin(), wxSize( width, height ) );
358 
359  selectionRect.Normalize();
360 
361  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
362  {
363  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
364  {
365  if( item->HitTest( selectionRect, windowSelection ) )
366  {
367  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
368  {
369  unselect( item );
370  anySubtracted = true;
371  }
372  else
373  {
374  select( item );
375  anyAdded = true;
376  }
377  }
378  }
379  }
380 
381  // Inform other potentially interested tools
382  if( anyAdded )
384 
385  if( anySubtracted )
387 
388  break; // Stop waiting for events
389  }
390  }
391 
392  getViewControls()->SetAutoPan( false );
393 
394  // Stop drawing the selection box
395  view->Remove( &area );
396  m_multiple = false; // Multiple selection mode is inactive
397 
398  if( !cancelled )
400 
401  return cancelled;
402 }
403 
404 
406 {
407  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
408  return 0;
409 }
410 
411 
412 void PL_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
413 {
414  if( aItem )
415  {
416  select( aItem );
417 
418  // Inform other potentially interested tools
419  if( !aQuietMode )
421  }
422 }
423 
424 
426 {
427  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
428  return 0;
429 }
430 
431 
432 void PL_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
433 {
434  if( aList )
435  {
436  for( EDA_ITEM* item : *aList )
437  select( item );
438 
439  // Inform other potentially interested tools
440  if( !aQuietMode )
442  }
443 }
444 
445 
447 {
448  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
449  return 0;
450 }
451 
452 
453 void PL_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
454 {
455  if( aItem )
456  {
457  unselect( aItem );
458 
459  // Inform other potentially interested tools
460  if( !aQuietMode )
462  }
463 }
464 
465 
467 {
468  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
469  return 0;
470 }
471 
472 
473 void PL_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
474 {
475  if( aList )
476  {
477  for( EDA_ITEM* item : *aList )
478  unselect( item );
479 
480  // Inform other potentially interested tools
481  if( !aQuietMode )
483  }
484 }
485 
486 
488 {
489  highlight( aItem, BRIGHTENED );
490 }
491 
492 
494 {
495  unhighlight( aItem, BRIGHTENED );
496 }
497 
498 
500 {
501  ClearSelection();
502  return 0;
503 }
504 
505 
507 {
508  m_selection.Clear();
509 
510  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
511  {
512  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
513  {
514  if( item->IsSelected() )
515  select( item );
516  }
517  }
518 }
519 
520 
522 {
523  COLLECTOR* collector = aEvent.Parameter<COLLECTOR*>();
524 
525  if( !doSelectionMenu( collector ) )
526  collector->m_MenuCancelled = true;
527 
528  return 0;
529 }
530 
531 
533 {
534  EDA_ITEM* current = nullptr;
535  ACTION_MENU menu( true );
536 
537  int limit = std::min( MAX_SELECT_ITEM_IDS, aCollector->GetCount() );
538 
539  for( int i = 0; i < limit; ++i )
540  {
541  wxString text;
542  EDA_ITEM* item = ( *aCollector )[i];
543  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
544 
545  wxString menuText = wxString::Format("&%d. %s", i + 1, text );
546  menu.Add( menuText, i + 1, item->GetMenuImage() );
547  }
548 
549  if( aCollector->m_MenuTitle.Length() )
550  menu.SetTitle( aCollector->m_MenuTitle );
551 
552  menu.SetIcon( info_xpm );
553  menu.DisplayTitle( true );
554  SetContextMenu( &menu, CMENU_NOW );
555 
556  while( TOOL_EVENT* evt = Wait() )
557  {
558  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
559  {
560  if( current )
561  unhighlight( current, BRIGHTENED );
562 
563  int id = *evt->GetCommandId();
564 
565  // User has pointed an item, so show it in a different way
566  if( id > 0 && id <= limit )
567  {
568  current = ( *aCollector )[id - 1];
569  highlight( current, BRIGHTENED );
570  }
571  else
572  {
573  current = NULL;
574  }
575  }
576  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
577  {
578  if( current )
579  unhighlight( current, BRIGHTENED );
580 
581  OPT<int> id = evt->GetCommandId();
582 
583  // User has selected an item, so this one will be returned
584  if( id && ( *id > 0 ) )
585  current = ( *aCollector )[*id - 1];
586  else
587  current = NULL;
588  }
589  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
590  {
591  break;
592  }
593 
594  getView()->UpdateItems();
595  m_frame->GetCanvas()->Refresh();
596  }
597 
598  if( current )
599  {
600  unhighlight( current, BRIGHTENED );
601 
602  getView()->UpdateItems();
603  m_frame->GetCanvas()->Refresh();
604 
605  aCollector->Empty();
606  aCollector->Append( current );
607  return true;
608  }
609 
610  return false;
611 }
612 
613 
615 {
616  if( m_selection.Empty() )
617  return;
618 
619  while( m_selection.GetSize() )
621 
622  getView()->Update( &m_selection );
623 
624  m_selection.SetIsHover( false );
626 
627  // Inform other potentially interested tools
629 }
630 
631 
633 {
634  highlight( aItem, SELECTED, &m_selection );
635 }
636 
637 
639 {
640  unhighlight( aItem, SELECTED, &m_selection );
641 }
642 
643 
644 void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup )
645 {
646  if( aMode == SELECTED )
647  aItem->SetSelected();
648  else if( aMode == BRIGHTENED )
649  aItem->SetBrightened();
650 
651  if( aGroup )
652  aGroup->Add( aItem );
653 
654  getView()->Update( aItem );
655 }
656 
657 
658 void PL_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup )
659 {
660  if( aMode == SELECTED )
661  aItem->ClearSelected();
662  else if( aMode == BRIGHTENED )
663  aItem->ClearBrightened();
664 
665  if( aGroup )
666  aGroup->Remove( aItem );
667 
668  getView()->Update( aItem );
669 }
670 
671 
673 {
674  const unsigned GRIP_MARGIN = 20;
675  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
676 
677  // Check if the point is located within any of the currently selected items bounding boxes
678  for( auto item : m_selection )
679  {
680  BOX2I itemBox = item->ViewBBox();
681  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
682 
683  if( itemBox.Contains( aPoint ) )
684  return true;
685  }
686 
687  return false;
688 }
689 
690 
692 {
694 
697 
703 }
704 
705 
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:110
void ClearReferencePoint()
Definition: selection.h:250
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
#define MAX_SELECT_ITEM_IDS
The maximum number of items in the clarify selection context menu.
static const TOOL_EVENT SelectedEvent
Definition: actions.h:203
void SetEnd(VECTOR2I aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
COLLECTOR class definition.
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:95
void RebuildSelection()
Rebuild the selection from the flags in the view items.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Work sheet structure type definitions.
Definition: ws_data_item.h:93
bool IsSelected() const
Definition: base_struct.h:203
Model changes (required full reload)
Definition: tool_base.h:82
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:204
ACTION_MENU.
Definition: action_menu.h:44
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
void SetOrigin(VECTOR2I aOrigin)
Set the origin of the rectange (the fixed corner)
static TOOL_ACTION drawLine
Definition: pl_actions.h:67
void ClearSelected()
Definition: base_struct.h:211
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: pl_actions.h:56
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
VIEW_CONTROLS class definition.
int UpdateMenu(const TOOL_EVENT &aEvent)
static TOOL_ACTION placeImage
Definition: pl_actions.h:65
void BrightenItem(EDA_ITEM *aItem)
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
void SetBrightened()
Definition: base_struct.h:209
static SELECTION_CONDITION Idle
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
void SetExclusiveOr(bool aExclusiveOr)
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
static TOOL_ACTION placeText
Definition: pl_actions.h:64
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
PL_EDITOR_FRAME * m_frame
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int AddItemToSel(const TOOL_EVENT &aEvent)
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
PL_SELECTION & GetSelection()
Function GetSelection()
void SetIsHover(bool aIsHover)
Definition: selection.h:66
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:76
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void ClearBrightened()
Definition: base_struct.h:212
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:120
void SetAdditive(bool aAdditive)
bool m_MenuCancelled
Definition: collector.h:70
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:307
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: pl_actions.h:46
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
#define SELECTED
Definition: base_struct.h:124
static TOOL_ACTION addItemToSel
Selects an item (specified as the event parameter).
Definition: pl_actions.h:52
void Transfer(int aIndex)
Moves the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:174
static TOOL_ACTION removeItemsFromSel
Definition: pl_actions.h:57
bool doSelectionMenu(COLLECTOR *aItems)
Allows the selection of a single item from a list via pop-up menu.
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
#define NULL
void SetSelected()
Definition: base_struct.h:208
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
void unselect(EDA_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:587
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:150
TOOL_EVENT.
Definition: tool_event.h:171
void guessSelectionCandidates(COLLECTOR &collector, const VECTOR2I &aWhere)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
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 selectionMenu
Runs a selection menu to select from a list of items.
Definition: pl_actions.h:60
bool ToolStackIsEmpty()
Definition: tools_holder.h:84
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:139
static const TOOL_EVENT ClearedEvent
Definition: actions.h:205
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
void UpdateItems()
Function UpdateItems() Iterates through the list of items that asked for updating and updates them.
Definition: view.cpp:1421
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:66
static TOOL_ACTION updateMenu
Definition: actions.h:163
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
const BITMAP_OPAQUE info_xpm[1]
Definition: info.cpp:75
EDA_ITEM * SelectPoint(const VECTOR2I &aWhere, bool *aSelectionCancelledFlag=nullptr)
Function selectPoint() Selects an item pointed by the parameter aWhere.
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: pl_actions.h:49
wxString m_MenuTitle
Definition: collector.h:69
void SetSubtractive(bool aSubtractive)
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
void Normalize()
Function Normalize ensures that the height ant width are positive.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
static TOOL_ACTION removeItemFromSel
Definition: pl_actions.h:53
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
PL_SELECTION m_selection
int Main(const TOOL_EVENT &aEvent)
Function Main()
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void UnbrightenItem(EDA_ITEM *aItem)
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
COLLECTOR is an abstract class that will find and hold all the objects according to an inspection don...
Definition: collector.h:55
static TOOL_ACTION appendImportedWorksheet
Definition: pl_actions.h:68
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
void highlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1486
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, PL_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.
void setTransitions() override
Sets up handlers for various events.
int AddItemsToSel(const TOOL_EVENT &aEvent)
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VIEW.
Definition: view.h:61
#define HITTEST_THRESHOLD_PIXELS
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
PL_SELECTION & RequestSelection()
Function RequestSelection()
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:184
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
Definition: action_menu.cpp:99
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:87