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 
44 #define MAX_SELECT_ITEM_IDS 40
45 
46 
47 SELECTION_CONDITION PL_CONDITIONS::Idle = [] (const SELECTION& aSelection )
48 {
49  return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
50 };
51 
52 
53 #define HITTEST_THRESHOLD_PIXELS 5
54 
55 
57  TOOL_INTERACTIVE( "plEditor.InteractiveSelection" ),
58  m_frame( nullptr ),
59  m_additive( false ),
60  m_subtractive( false ),
61  m_exclusive_or( false ),
62  m_multiple( false ),
63  m_skip_heuristics( false )
64 {
65 }
66 
67 
69 {
70  m_frame = getEditFrame<PL_EDITOR_FRAME>();
71 
72  auto& menu = m_menu.GetMenu();
73 
74  menu.AddSeparator( 200 );
75  menu.AddItem( PL_ACTIONS::drawLine, PL_CONDITIONS::Idle, 250 );
76  menu.AddItem( PL_ACTIONS::drawRectangle, PL_CONDITIONS::Idle, 250 );
77  menu.AddItem( PL_ACTIONS::placeText, PL_CONDITIONS::Idle, 250 );
78  menu.AddItem( PL_ACTIONS::placeImage, PL_CONDITIONS::Idle, 250 );
80 
81  menu.AddSeparator( 1000 );
83 
84  return true;
85 }
86 
87 
89 {
90  if( aReason == MODEL_RELOAD )
91  m_frame = getEditFrame<PL_EDITOR_FRAME>();
92 }
93 
94 
96 {
97  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
98  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
99 
100  if( conditionalMenu )
101  conditionalMenu->Evaluate( m_selection );
102 
103  if( actionMenu )
104  actionMenu->UpdateAll();
105 
106  return 0;
107 }
108 
109 
111 {
112  // Main loop: keep receiving events
113  while( TOOL_EVENT* evt = Wait() )
114  {
115  if( m_frame->ToolStackIsEmpty() )
116  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
117 
119 
120  if( evt->Modifier( MD_SHIFT ) && evt->Modifier( MD_CTRL ) )
121  m_subtractive = true;
122  else if( evt->Modifier( MD_SHIFT ) )
123  m_additive = true;
124  else if( evt->Modifier( MD_CTRL ) )
125  m_exclusive_or = true;
126 
127  // Is the user requesting that the selection list include all possible
128  // items without removing less likely selection candidates
129  m_skip_heuristics = !!evt->Modifier( MD_ALT );
130 
131  // Single click? Select single object
132  if( evt->IsClick( BUT_LEFT ) )
133  {
134  SelectPoint( evt->Position());
135  }
136 
137  // right click? if there is any object - show the context menu
138  else if( evt->IsClick( BUT_RIGHT ) )
139  {
140  bool selectionCancelled = false;
141 
142  if( m_selection.Empty() )
143  {
144  SelectPoint( evt->Position(), &selectionCancelled );
145  m_selection.SetIsHover( true );
146  }
147 
148  if( !selectionCancelled )
150  }
151 
152  // double click? Display the properties window
153  else if( evt->IsDblClick( BUT_LEFT ) )
154  {
155  // No double-click actions currently defined
156  }
157 
158  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
159  else if( evt->IsDrag( BUT_LEFT ) )
160  {
162  {
163  selectMultiple();
164  }
165  else
166  {
167  // Check if dragging has started within any of selected items bounding box
168  if( selectionContains( evt->Position() ) )
169  {
170  // Yes -> run the move tool and wait till it finishes
171  m_toolMgr->InvokeTool( "plEditor.InteractiveEdit" );
172  }
173  else
174  {
175  // No -> clear the selection list
176  ClearSelection();
177  }
178  }
179  }
180 
181  else if( evt->IsCancelInteractive() )
182  {
183  ClearSelection();
184  }
185 
186  else if( evt->Action() == TA_UNDO_REDO_PRE )
187  {
188  ClearSelection();
189  }
190 
191  else
192  evt->SetPassEvent();
193  }
194 
195  // This tool is supposed to be active forever
196  assert( false );
197 
198  return 0;
199 }
200 
201 
203 {
204  return m_selection;
205 }
206 
207 
208 EDA_ITEM* PL_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag )
209 {
210  int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
211 
212  // locate items.
213  COLLECTOR collector;
214 
215  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
216  {
217  for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() )
218  {
219  if( drawItem->HitTest( (wxPoint) aWhere, threshold ) )
220  collector.Append( drawItem );
221  }
222  }
223 
225 
226  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
227  if( collector.GetCount() > 1 && !m_skip_heuristics )
228  {
229  guessSelectionCandidates( collector, aWhere );
230  }
231 
232  // If still more than one item we're going to have to ask the user.
233  if( collector.GetCount() > 1 )
234  {
235  collector.m_MenuTitle = _( "Clarify Selection" );
236 
237  // Must call selectionMenu via RunAction() to avoid event-loop contention
238  m_toolMgr->RunAction( PL_ACTIONS::selectionMenu, true, &collector );
239 
240  if( collector.m_MenuCancelled )
241  {
242  if( aSelectionCancelledFlag )
243  *aSelectionCancelledFlag = true;
244 
245  return nullptr;
246  }
247  }
248 
250  ClearSelection();
251 
252  if( collector.GetCount() == 1 )
253  {
254  EDA_ITEM* item = collector[ 0 ];
255 
256  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
257  {
258  unselect( item );
260  return nullptr;
261  }
262  else
263  {
264  select( item );
266  return item;
267  }
268  }
269 
270  return nullptr;
271 }
272 
273 
275 {
276  // There are certain conditions that can be handled automatically.
277 
278  // Prefer an exact hit to a sloppy one
279  for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
280  {
281  EDA_ITEM* item = collector[ i ];
282  EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
283 
284  if( item->HitTest( (wxPoint) aPos, 0 ) && !other->HitTest( (wxPoint) aPos, 0 ) )
285  collector.Remove( other );
286  }
287 }
288 
289 
291 {
292  // If nothing is selected do a hover selection
293  if( m_selection.Empty() )
294  {
295  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
296 
297  ClearSelection();
298  SelectPoint( cursorPos );
299  m_selection.SetIsHover( true );
300  }
301 
302  return m_selection;
303 }
304 
305 
307 {
308  bool cancelled = false; // Was the tool cancelled while it was running?
309  m_multiple = true; // Multiple selection mode is active
310  KIGFX::VIEW* view = getView();
311 
313  view->Add( &area );
314 
315  while( TOOL_EVENT* evt = Wait() )
316  {
317  if( evt->IsCancelInteractive() || evt->IsActivate() )
318  {
319  cancelled = true;
320  break;
321  }
322 
323  if( evt->IsDrag( BUT_LEFT ) )
324  {
326  ClearSelection();
327 
328  // Start drawing a selection box
329  area.SetOrigin( evt->DragOrigin() );
330  area.SetEnd( evt->Position() );
331  area.SetAdditive( m_additive );
334 
335  view->SetVisible( &area, true );
336  view->Update( &area );
337  getViewControls()->SetAutoPan( true );
338  }
339 
340  if( evt->IsMouseUp( BUT_LEFT ) )
341  {
342  getViewControls()->SetAutoPan( false );
343 
344  // End drawing the selection box
345  view->SetVisible( &area, false );
346 
347  int width = area.GetEnd().x - area.GetOrigin().x;
348  int height = area.GetEnd().y - area.GetOrigin().y;
349 
350  /* Selection mode depends on direction of drag-selection:
351  * Left > Right : Select objects that are fully enclosed by selection
352  * Right > Left : Select objects that are crossed by selection
353  */
354  bool windowSelection = width >= 0 ? true : false;
355  bool anyAdded = false;
356  bool anySubtracted = false;
357 
358  // Construct an EDA_RECT to determine EDA_ITEM selection
359  EDA_RECT selectionRect( (wxPoint)area.GetOrigin(), wxSize( width, height ) );
360 
361  selectionRect.Normalize();
362 
363  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
364  {
365  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
366  {
367  if( item->HitTest( selectionRect, windowSelection ) )
368  {
369  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
370  {
371  unselect( item );
372  anySubtracted = true;
373  }
374  else
375  {
376  select( item );
377  anyAdded = true;
378  }
379  }
380  }
381  }
382 
383  // Inform other potentially interested tools
384  if( anyAdded )
386 
387  if( anySubtracted )
389 
390  break; // Stop waiting for events
391  }
392  }
393 
394  getViewControls()->SetAutoPan( false );
395 
396  // Stop drawing the selection box
397  view->Remove( &area );
398  m_multiple = false; // Multiple selection mode is inactive
399 
400  if( !cancelled )
402 
403  return cancelled;
404 }
405 
406 
408 {
409  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
410  return 0;
411 }
412 
413 
414 void PL_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
415 {
416  if( aItem )
417  {
418  select( aItem );
419 
420  // Inform other potentially interested tools
421  if( !aQuietMode )
423  }
424 }
425 
426 
428 {
429  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
430  return 0;
431 }
432 
433 
434 void PL_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
435 {
436  if( aList )
437  {
438  for( EDA_ITEM* item : *aList )
439  select( item );
440 
441  // Inform other potentially interested tools
442  if( !aQuietMode )
444  }
445 }
446 
447 
449 {
450  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
451  return 0;
452 }
453 
454 
455 void PL_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
456 {
457  if( aItem )
458  {
459  unselect( aItem );
460 
461  // Inform other potentially interested tools
462  if( !aQuietMode )
464  }
465 }
466 
467 
469 {
470  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
471  return 0;
472 }
473 
474 
475 void PL_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
476 {
477  if( aList )
478  {
479  for( EDA_ITEM* item : *aList )
480  unselect( item );
481 
482  // Inform other potentially interested tools
483  if( !aQuietMode )
485  }
486 }
487 
488 
490 {
491  highlight( aItem, BRIGHTENED );
492 }
493 
494 
496 {
497  unhighlight( aItem, BRIGHTENED );
498 }
499 
500 
502 {
503  ClearSelection();
504  return 0;
505 }
506 
507 
509 {
510  m_selection.Clear();
511 
512  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
513  {
514  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
515  {
516  if( item->IsSelected() )
517  select( item );
518  }
519  }
520 }
521 
522 
524 {
525  COLLECTOR* collector = aEvent.Parameter<COLLECTOR*>();
526 
527  if( !doSelectionMenu( collector ) )
528  collector->m_MenuCancelled = true;
529 
530  return 0;
531 }
532 
533 
535 {
536  EDA_ITEM* current = nullptr;
537  ACTION_MENU menu( true );
538 
539  int limit = std::min( MAX_SELECT_ITEM_IDS, aCollector->GetCount() );
540 
541  for( int i = 0; i < limit; ++i )
542  {
543  wxString text;
544  EDA_ITEM* item = ( *aCollector )[i];
545  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
546 
547  wxString menuText = wxString::Format("&%d. %s", i + 1, text );
548  menu.Add( menuText, i + 1, item->GetMenuImage() );
549  }
550 
551  if( aCollector->m_MenuTitle.Length() )
552  menu.SetTitle( aCollector->m_MenuTitle );
553 
554  menu.SetIcon( info_xpm );
555  menu.DisplayTitle( true );
556  SetContextMenu( &menu, CMENU_NOW );
557 
558  while( TOOL_EVENT* evt = Wait() )
559  {
560  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
561  {
562  if( current )
563  unhighlight( current, BRIGHTENED );
564 
565  int id = *evt->GetCommandId();
566 
567  // User has pointed an item, so show it in a different way
568  if( id > 0 && id <= limit )
569  {
570  current = ( *aCollector )[id - 1];
571  highlight( current, BRIGHTENED );
572  }
573  else
574  {
575  current = NULL;
576  }
577  }
578  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
579  {
580  if( current )
581  unhighlight( current, BRIGHTENED );
582 
583  OPT<int> id = evt->GetCommandId();
584 
585  // User has selected an item, so this one will be returned
586  if( id && ( *id > 0 ) )
587  current = ( *aCollector )[*id - 1];
588  else
589  current = NULL;
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:122
void ClearReferencePoint()
Definition: selection.h:248
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:196
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:93
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
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
bool IsSelected() const
Definition: base_struct.h:233
Model changes (required full reload)
Definition: tool_base.h:82
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:197
Class ACTION_MENU.
Definition: action_menu.h:43
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:243
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:241
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:109
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:587
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)
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:142
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:64
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:74
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void ClearBrightened()
Definition: base_struct.h:245
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:132
void SetAdditive(bool aAdditive)
bool m_MenuCancelled
Definition: collector.h:71
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:339
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:113
#define SELECTED
Definition: base_struct.h:127
static TOOL_ACTION addItemToSel
Selects an item (specified as the event parameter).
Definition: pl_actions.h:52
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() Checks if the given point is placed within any of selected items' boundi...
void SetSelected()
Definition: base_struct.h:239
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:622
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:427
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:68
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:149
Class TOOL_EVENT.
Definition: tool_event.h:168
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
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:143
static const TOOL_EVENT ClearedEvent
Definition: actions.h:198
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:157
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
#define _(s)
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:119
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: pl_actions.h:49
wxString m_MenuTitle
Definition: collector.h:70
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:98
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:300
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:86
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
bool ToolStackIsEmpty()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
void UnbrightenItem(EDA_ITEM *aItem)
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspecti...
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.
Class SELECTION_AREA.
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
Class 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()
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:182
#define min(a, b)
Definition: auxiliary.h:85
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
Definition: action_menu.cpp:97
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:85