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 <tool/tool_event.h>
31 #include <tool/tool_manager.h>
32 #include <tool/selection.h>
36 #include <collector.h>
37 #include <math/util.h> // for KiROUND
38 
39 #include "pl_editor_frame.h"
40 #include "pl_selection_tool.h"
41 #include "tools/pl_actions.h"
42 
47 #define MAX_SELECT_ITEM_IDS 40
48 
49 
50 SELECTION_CONDITION PL_CONDITIONS::Idle = [] (const SELECTION& aSelection )
51 {
52  return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
53 };
54 
55 
56 #define HITTEST_THRESHOLD_PIXELS 3
57 
58 
60  TOOL_INTERACTIVE( "plEditor.InteractiveSelection" ),
61  m_frame( nullptr ),
62  m_additive( false ),
63  m_subtractive( false ),
64  m_exclusive_or( false ),
65  m_multiple( false ),
66  m_skip_heuristics( false )
67 {
68 }
69 
70 
72 {
73  m_frame = getEditFrame<PL_EDITOR_FRAME>();
74 
75  auto& menu = m_menu.GetMenu();
76 
77  menu.AddSeparator( 200 );
78  menu.AddItem( PL_ACTIONS::drawLine, PL_CONDITIONS::Idle, 250 );
79  menu.AddItem( PL_ACTIONS::drawRectangle, PL_CONDITIONS::Idle, 250 );
80  menu.AddItem( PL_ACTIONS::placeText, PL_CONDITIONS::Idle, 250 );
81  menu.AddItem( PL_ACTIONS::placeImage, PL_CONDITIONS::Idle, 250 );
83 
84  menu.AddSeparator( 1000 );
86 
87  return true;
88 }
89 
90 
92 {
93  if( aReason == MODEL_RELOAD )
94  m_frame = getEditFrame<PL_EDITOR_FRAME>();
95 }
96 
97 
99 {
100  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
101  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
102 
103  if( conditionalMenu )
104  conditionalMenu->Evaluate( m_selection );
105 
106  if( actionMenu )
107  actionMenu->UpdateAll();
108 
109  return 0;
110 }
111 
112 
114 {
115  // Main loop: keep receiving events
116  while( TOOL_EVENT* evt = Wait() )
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  bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
128 
129  // Is the user requesting that the selection list include all possible
130  // items without removing less likely selection candidates
131  m_skip_heuristics = !!evt->Modifier( MD_ALT );
132 
133  // Single click? Select single object
134  if( evt->IsClick( BUT_LEFT ) )
135  {
136  SelectPoint( evt->Position() );
137  }
138 
139  // right click? if there is any object - show the context menu
140  else if( evt->IsClick( BUT_RIGHT ) )
141  {
142  bool selectionCancelled = false;
143 
144  if( m_selection.Empty() )
145  {
146  SelectPoint( evt->Position(), &selectionCancelled );
147  m_selection.SetIsHover( true );
148  }
149 
150  if( !selectionCancelled )
152  }
153 
154  // double click? Display the properties window
155  else if( evt->IsDblClick( BUT_LEFT ) )
156  {
157  // No double-click actions currently defined
158  }
159 
160  // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
161  else if( evt->IsDrag( BUT_LEFT ) )
162  {
163  if( modifier_enabled || m_selection.Empty() )
164  {
165  selectMultiple();
166  }
167  else
168  {
169  // Check if dragging has started within any of selected items bounding box
170  if( selectionContains( evt->Position() ) )
171  {
172  // Yes -> run the move tool and wait till it finishes
173  m_toolMgr->RunAction( "plEditor.InteractiveMove.move", true );
174  }
175  else
176  {
177  // No -> clear the selection list
178  ClearSelection();
179  }
180  }
181  }
182 
183  // Middle double click? Do zoom to fit or zoom to objects
184  else if( evt->IsDblClick( BUT_MIDDLE ) )
185  {
187  }
188 
189  else if( evt->IsCancelInteractive() )
190  {
191  ClearSelection();
192  }
193 
194  else if( evt->Action() == TA_UNDO_REDO_PRE )
195  {
196  ClearSelection();
197  }
198 
199  else
200  evt->SetPassEvent();
201 
202 
203  if( m_frame->ToolStackIsEmpty() )
204  {
205  if( !modifier_enabled && !m_selection.Empty() && !m_frame->GetDragSelects()
206  && evt->HasPosition() && selectionContains( evt->Position() ) )
208  else
209  {
210  if( m_additive )
212  else if( m_subtractive )
214  else if( m_exclusive_or )
216  else
218  }
219  }
220  }
221 
222  return 0;
223 }
224 
225 
227 {
228  return m_selection;
229 }
230 
231 
232 void PL_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, bool* aSelectionCancelledFlag )
233 {
234  int threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
235 
236  // locate items.
237  COLLECTOR collector;
238 
239  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
240  {
241  for( WS_DRAW_ITEM_BASE* drawItem : dataItem->GetDrawItems() )
242  {
243  if( drawItem->HitTest( (wxPoint) aWhere, threshold ) )
244  collector.Append( drawItem );
245  }
246  }
247 
249 
250  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
251  if( collector.GetCount() > 1 && !m_skip_heuristics )
252  {
253  guessSelectionCandidates( collector, aWhere );
254  }
255 
256  // If still more than one item we're going to have to ask the user.
257  if( collector.GetCount() > 1 )
258  {
259  collector.m_MenuTitle = _( "Clarify Selection" );
260 
261  // Must call selectionMenu via RunAction() to avoid event-loop contention
262  m_toolMgr->RunAction( PL_ACTIONS::selectionMenu, true, &collector );
263 
264  if( collector.m_MenuCancelled )
265  {
266  if( aSelectionCancelledFlag )
267  *aSelectionCancelledFlag = true;
268 
269  return;
270  }
271  }
272 
274  ClearSelection();
275 
276  bool anyAdded = false;
277  bool anySubtracted = false;
278 
279  if( collector.GetCount() > 0 )
280  {
281  for( int i = 0; i < collector.GetCount(); ++i )
282  {
283  if( m_subtractive || ( m_exclusive_or && collector[i]->IsSelected() ) )
284  {
285  unselect( collector[i] );
286  anySubtracted = true;
287  }
288  else
289  {
290  select( collector[i] );
291  anyAdded = true;
292  }
293  }
294  }
295 
296  if( anyAdded )
298 
299  if( anySubtracted )
301 }
302 
303 
305 {
306  // There are certain conditions that can be handled automatically.
307 
308  // Prefer an exact hit to a sloppy one
309  for( int i = 0; collector.GetCount() == 2 && i < 2; ++i )
310  {
311  EDA_ITEM* item = collector[ i ];
312  EDA_ITEM* other = collector[ ( i + 1 ) % 2 ];
313 
314  if( item->HitTest( (wxPoint) aPos, 0 ) && !other->HitTest( (wxPoint) aPos, 0 ) )
315  collector.Transfer( other );
316  }
317 }
318 
319 
321 {
322  // If nothing is selected do a hover selection
323  if( m_selection.Empty() )
324  {
325  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
326 
327  ClearSelection();
328  SelectPoint( cursorPos );
329  m_selection.SetIsHover( true );
330  }
331 
332  return m_selection;
333 }
334 
335 
337 {
338  bool cancelled = false; // Was the tool cancelled while it was running?
339  m_multiple = true; // Multiple selection mode is active
340  KIGFX::VIEW* view = getView();
341 
343  view->Add( &area );
344 
345  while( TOOL_EVENT* evt = Wait() )
346  {
347  int width = area.GetEnd().x - area.GetOrigin().x;
348 
349  /* Selection mode depends on direction of drag-selection:
350  * Left > Right : Select objects that are fully enclosed by selection
351  * Right > Left : Select objects that are crossed by selection
352  */
353  bool windowSelection = width >= 0 ? true : false;
354 
356  windowSelection ? KICURSOR::SELECT_WINDOW : KICURSOR::SELECT_LASSO );
357 
358  if( evt->IsCancelInteractive() || evt->IsActivate() )
359  {
360  cancelled = true;
361  break;
362  }
363 
364  if( evt->IsDrag( BUT_LEFT ) )
365  {
367  ClearSelection();
368 
369  // Start drawing a selection box
370  area.SetOrigin( evt->DragOrigin() );
371  area.SetEnd( evt->Position() );
372  area.SetAdditive( m_additive );
375 
376  view->SetVisible( &area, true );
377  view->Update( &area );
378  getViewControls()->SetAutoPan( true );
379  }
380 
381  if( evt->IsMouseUp( BUT_LEFT ) )
382  {
383  getViewControls()->SetAutoPan( false );
384 
385  // End drawing the selection box
386  view->SetVisible( &area, false );
387 
388  int height = area.GetEnd().y - area.GetOrigin().y;
389 
390  bool anyAdded = false;
391  bool anySubtracted = false;
392 
393  // Construct an EDA_RECT to determine EDA_ITEM selection
394  EDA_RECT selectionRect( (wxPoint)area.GetOrigin(), wxSize( width, height ) );
395 
396  selectionRect.Normalize();
397 
398  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
399  {
400  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
401  {
402  if( item->HitTest( selectionRect, windowSelection ) )
403  {
404  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
405  {
406  unselect( item );
407  anySubtracted = true;
408  }
409  else
410  {
411  select( item );
412  anyAdded = true;
413  }
414  }
415  }
416  }
417 
418  // Inform other potentially interested tools
419  if( anyAdded )
421 
422  if( anySubtracted )
424 
425  break; // Stop waiting for events
426  }
427  }
428 
429  getViewControls()->SetAutoPan( false );
430 
431  // Stop drawing the selection box
432  view->Remove( &area );
433  m_multiple = false; // Multiple selection mode is inactive
434 
435  if( !cancelled )
437 
438  return cancelled;
439 }
440 
441 
443 {
444  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
445  return 0;
446 }
447 
448 
449 void PL_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
450 {
451  if( aItem )
452  {
453  select( aItem );
454 
455  // Inform other potentially interested tools
456  if( !aQuietMode )
458  }
459 }
460 
461 
463 {
464  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
465  return 0;
466 }
467 
468 
469 void PL_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
470 {
471  if( aList )
472  {
473  for( EDA_ITEM* item : *aList )
474  select( item );
475 
476  // Inform other potentially interested tools
477  if( !aQuietMode )
479  }
480 }
481 
482 
484 {
485  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
486  return 0;
487 }
488 
489 
490 void PL_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
491 {
492  if( aItem )
493  {
494  unselect( aItem );
495 
496  // Inform other potentially interested tools
497  if( !aQuietMode )
499  }
500 }
501 
502 
504 {
505  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
506  return 0;
507 }
508 
509 
510 void PL_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
511 {
512  if( aList )
513  {
514  for( EDA_ITEM* item : *aList )
515  unselect( item );
516 
517  // Inform other potentially interested tools
518  if( !aQuietMode )
520  }
521 }
522 
523 
525 {
526  highlight( aItem, BRIGHTENED );
527 }
528 
529 
531 {
532  unhighlight( aItem, BRIGHTENED );
533 }
534 
535 
537 {
538  ClearSelection();
539  return 0;
540 }
541 
542 
544 {
545  m_selection.Clear();
546 
547  for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
548  {
549  for( WS_DRAW_ITEM_BASE* item : dataItem->GetDrawItems() )
550  {
551  if( item->IsSelected() )
552  select( item );
553  }
554  }
555 }
556 
557 
559 {
560  COLLECTOR* collector = aEvent.Parameter<COLLECTOR*>();
561 
562  if( !doSelectionMenu( collector ) )
563  collector->m_MenuCancelled = true;
564 
565  return 0;
566 }
567 
568 
570 {
571  EDA_ITEM* current = nullptr;
572  ACTION_MENU menu( true );
573 
574  // ID limit is `MAX_SELECT_ITEM_IDS+1` because the last item is "select all"
575  // and the first item has ID of 1.
576  int limit = std::min( MAX_SELECT_ITEM_IDS + 1, aCollector->GetCount() );
577 
578  for( int i = 0; i < limit; ++i )
579  {
580  wxString text;
581  EDA_ITEM* item = ( *aCollector )[i];
582  text = item->GetSelectMenuText( m_frame->GetUserUnits() );
583 
584  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
585  menu.Add( menuText, i + 1, item->GetMenuImage() );
586  }
587 
588  menu.AppendSeparator();
589  menu.Add( _( "Select &All\tA" ), limit + 1, plus_xpm );
590 
591  if( aCollector->m_MenuTitle.Length() )
592  menu.SetTitle( aCollector->m_MenuTitle );
593 
594  menu.SetIcon( info_xpm );
595  menu.DisplayTitle( true );
596  SetContextMenu( &menu, CMENU_NOW );
597 
598  bool selectAll = false;
599 
600  while( TOOL_EVENT* evt = Wait() )
601  {
602  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
603  {
604  if( selectAll )
605  {
606  for( int i = 0; i < aCollector->GetCount(); ++i )
607  unhighlight( ( *aCollector )[i], BRIGHTENED );
608  }
609  else if( current )
610  {
611  unhighlight( current, BRIGHTENED );
612  }
613 
614  int id = *evt->GetCommandId();
615 
616  // User has pointed an item, so show it in a different way
617  if( id > 0 && id <= limit )
618  {
619  current = ( *aCollector )[id - 1];
620  highlight( current, BRIGHTENED );
621  }
622  else
623  {
624  current = nullptr;
625  }
626 
627  if( id == limit + 1 )
628  {
629  for( int i = 0; i < aCollector->GetCount(); ++i )
630  highlight( ( *aCollector )[i], BRIGHTENED );
631 
632  selectAll = true;
633  }
634  else
635  {
636  selectAll = false;
637  }
638  }
639  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
640  {
641  if( selectAll )
642  {
643  for( int i = 0; i < aCollector->GetCount(); ++i )
644  unhighlight( ( *aCollector )[i], BRIGHTENED );
645  }
646  else if( current )
647  {
648  unhighlight( current, BRIGHTENED );
649  }
650 
651  OPT<int> id = evt->GetCommandId();
652 
653  // User has selected an item, so this one will be returned
654  if( id == limit + 1 )
655  {
656  selectAll = true;
657  current = nullptr;
658  }
659  else if( id && ( *id > 0 ) && ( *id <= limit ) )
660  {
661  selectAll = false;
662  current = ( *aCollector )[*id - 1];
663  }
664  else
665  {
666  selectAll = false;
667  current = nullptr;
668  }
669  }
670  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
671  {
672  break;
673  }
674 
675  getView()->UpdateItems();
676  m_frame->GetCanvas()->Refresh();
677  }
678 
679  if( selectAll )
680  {
681  return true;
682  }
683  else if( current )
684  {
685  unhighlight( current, BRIGHTENED );
686 
687  getView()->UpdateItems();
688  m_frame->GetCanvas()->Refresh();
689 
690  aCollector->Empty();
691  aCollector->Append( current );
692  return true;
693  }
694 
695  return false;
696 }
697 
698 
700 {
701  if( m_selection.Empty() )
702  return;
703 
704  while( m_selection.GetSize() )
706 
707  getView()->Update( &m_selection );
708 
709  m_selection.SetIsHover( false );
711 
712  // Inform other potentially interested tools
714 }
715 
716 
718 {
719  highlight( aItem, SELECTED, &m_selection );
720 }
721 
722 
724 {
725  unhighlight( aItem, SELECTED, &m_selection );
726 }
727 
728 
729 void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup )
730 {
731  if( aMode == SELECTED )
732  aItem->SetSelected();
733  else if( aMode == BRIGHTENED )
734  aItem->SetBrightened();
735 
736  if( aGroup )
737  aGroup->Add( aItem );
738 
739  getView()->Update( aItem );
740 }
741 
742 
743 void PL_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup )
744 {
745  if( aMode == SELECTED )
746  aItem->ClearSelected();
747  else if( aMode == BRIGHTENED )
748  aItem->ClearBrightened();
749 
750  if( aGroup )
751  aGroup->Remove( aItem );
752 
753  getView()->Update( aItem );
754 }
755 
756 
758 {
759  const unsigned GRIP_MARGIN = 20;
760  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
761 
762  // Check if the point is located within any of the currently selected items bounding boxes
763  for( auto item : m_selection )
764  {
765  BOX2I itemBox = item->ViewBBox();
766  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
767 
768  if( itemBox.Contains( aPoint ) )
769  return true;
770  }
771 
772  return false;
773 }
774 
775 
777 {
779 
782 
788 }
789 
790 
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:113
void ClearReferencePoint()
Definition: selection.h:267
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
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:213
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:94
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:97
Model changes (required full reload)
Definition: tool_base.h:82
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:214
Defines the structure of a menu based on ACTIONs.
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:456
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: eda_item.h:199
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: pl_actions.h:56
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:357
void SetBrightened()
Definition: eda_item.h:197
static SELECTION_CONDITION Idle
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void SetExclusiveOr(bool aExclusiveOr)
void select(EDA_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
void 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()
void SelectPoint(const VECTOR2I &aWhere, bool *aSelectionCancelledFlag=nullptr)
Function selectPoint() Selects an item pointed by the parameter aWhere.
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)
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
PL_SELECTION & GetSelection()
Function GetSelection()
void SetIsHover(bool aIsHover)
Definition: selection.h:65
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void ClearBrightened()
Definition: eda_item.h:200
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
void SetAdditive(bool aAdditive)
bool m_MenuCancelled
Definition: collector.h:69
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: eda_item.h:295
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:104
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:175
static TOOL_ACTION removeItemsFromSel
Definition: pl_actions.h:57
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129
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()
void SetSelected()
Definition: eda_item.h:196
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.
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)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:151
#define SELECTED
Definition: eda_item.h:113
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:136
bool GetDragSelects() const
Indicates that a drag should draw a selection rectangle, even when started over an item.
Definition: tools_holder.h:153
static const TOOL_EVENT ClearedEvent
Definition: actions.h:215
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:1394
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:576
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:66
static TOOL_ACTION updateMenu
Definition: actions.h:172
const BITMAP_OPAQUE info_xpm[1]
Definition: info.cpp:75
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:120
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: pl_actions.h:49
wxString m_MenuTitle
Definition: collector.h:68
void SetSubtractive(bool aSubtractive)
void AddSeparator(int aOrder=ANY_ORDER)
Adds a separator to the menu.
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
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:302
PL_SELECTION m_selection
int Main(const TOOL_EVENT &aEvent)
Function Main()
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
#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...
Definition: eda_item.cpp:123
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: eda_item.h:148
COLLECTOR is an abstract class that will find and hold all the objects according to an inspection don...
Definition: collector.h:54
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
Helper classes to handle basic graphic items used to draw/plot title blocks and frame references segm...
Definition: ws_draw_item.h:56
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1459
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:327
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
VIEW.
Definition: view.h:63
#define HITTEST_THRESHOLD_PIXELS
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: eda_item.cpp:221
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:201
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
const BITMAP_OPAQUE plus_xpm[1]
Definition: plus.cpp:66
void DisplayTitle(bool aDisplay=true)
Decides whether a title for a pop up menu should be displayed.
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:86