KiCad PCB EDA Suite
ee_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-2021 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 #include <bitmaps.h>
26 #include <core/typeinfo.h>
27 #include <core/kicad_algo.h>
29 #include <ee_actions.h>
30 #include <ee_collectors.h>
31 #include <ee_selection_tool.h>
32 #include <eeschema_id.h> // For MAX_SELECT_ITEM_IDS
33 #include <symbol_edit_frame.h>
34 #include <lib_item.h>
35 #include <symbol_viewer_frame.h>
36 #include <math/util.h>
37 #include <geometry/shape_rect.h>
38 #include <menus_helpers.h>
39 #include <painter.h>
41 #include <sch_base_frame.h>
42 #include <sch_symbol.h>
43 #include <sch_field.h>
44 #include <sch_edit_frame.h>
45 #include <sch_item.h>
46 #include <sch_line.h>
47 #include <sch_junction.h>
48 #include <sch_marker.h>
49 #include <sch_sheet.h>
50 #include <sch_sheet_pin.h>
51 #include <lib_shape.h>
52 #include <schematic.h>
53 #include <tool/tool_event.h>
54 #include <tool/tool_manager.h>
55 #include <tools/ee_grid_helper.h>
56 #include <tools/ee_point_editor.h>
58 #include <trigo.h>
59 #include <view/view.h>
60 #include <view/view_controls.h>
61 #include <wx/log.h>
62 
64 {
65  if( aSel.GetSize() == 1 )
66  {
67  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
68 
69  if( symbol )
70  return !symbol->GetLibSymbolRef() || !symbol->GetLibSymbolRef()->IsPower();
71  }
72 
73  return false;
74 };
75 
76 
78 {
79  return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_SYMBOL_T;
80 };
81 
82 
84 {
85  if( aSel.GetSize() == 1 )
86  {
87  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
88 
89  if( symbol )
90  return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->HasConversion();
91  }
92 
93  return false;
94 };
95 
96 
98 {
99  if( aSel.GetSize() == 1 )
100  {
101  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
102 
103  if( symbol )
104  return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->GetUnitCount() >= 2;
105  }
106 
107  return false;
108 };
109 
110 
112 {
113  if( aSel.CountType( SCH_MARKER_T ) != 1 )
114  return false;
115 
116  return !static_cast<SCH_MARKER*>( aSel.Front() )->IsExcluded();
117 };
118 
119 
120 #define HITTEST_THRESHOLD_PIXELS 5
121 
122 
124  TOOL_INTERACTIVE( "eeschema.InteractiveSelection" ),
125  m_frame( nullptr ),
126  m_nonModifiedCursor( KICURSOR::ARROW ),
127  m_isSymbolEditor( false ),
128  m_isSymbolViewer( false ),
129  m_unit( 0 ),
130  m_convert( 0 )
131 {
132  m_selection.Clear();
133 }
134 
135 
137 {
138  getView()->Remove( &m_selection );
139 }
140 
141 
143 
144 
146 {
147  m_frame = getEditFrame<SCH_BASE_FRAME>();
148 
149  SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
150  SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
151 
152  if( symbolEditorFrame )
153  {
154  m_isSymbolEditor = true;
155  m_unit = symbolEditorFrame->GetUnit();
156  m_convert = symbolEditorFrame->GetConvert();
157  }
158  else
159  {
160  m_isSymbolViewer = symbolViewerFrame != nullptr;
161  }
162 
163  static KICAD_T wireOrBusTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
164  static KICAD_T connectedTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T,
167 
168  auto wireSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T );
169  auto busSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T );
170  auto wireOrBusSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( wireOrBusTypes );
171  auto connectedSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( connectedTypes );
172  auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
173 
174  auto schEditSheetPageNumberCondition =
175  [&] ( const SELECTION& aSel )
176  {
178  return false;
179 
180  return E_C::LessThan( 2 )( aSel ) && E_C::OnlyType( SCH_SHEET_T )( aSel );
181  };
182 
183  auto schEditCondition =
184  [this] ( const SELECTION& aSel )
185  {
187  };
188 
189  auto belowRootSheetCondition =
190  [&]( const SELECTION& aSel )
191  {
192  SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
193 
194  return editFrame
195  && editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
196  };
197 
198  auto haveSymbolCondition =
199  [&]( const SELECTION& sel )
200  {
201  return m_isSymbolEditor &&
202  static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
203  };
204 
205  auto& menu = m_menu.GetMenu();
206 
207  menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 1 );
208  menu.AddItem( EE_ACTIONS::explicitCrossProbe, sheetSelection && EE_CONDITIONS::Idle, 1 );
209  menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 1 );
210 
211  menu.AddSeparator( 100 );
212  menu.AddItem( EE_ACTIONS::drawWire, schEditCondition && EE_CONDITIONS::Empty, 100 );
213  menu.AddItem( EE_ACTIONS::drawBus, schEditCondition && EE_CONDITIONS::Empty, 100 );
214 
215  menu.AddSeparator( 100 );
217 
218  menu.AddSeparator( 100 );
220 
221  menu.AddSeparator( 200 );
222  menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
223  menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
224  menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
225  menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
226  menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
227  menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 250 );
228  menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 250 );
229  menu.AddItem( EE_ACTIONS::importSingleSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
230  menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
231  menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
232 
233  menu.AddSeparator( 400 );
234  menu.AddItem( EE_ACTIONS::symbolProperties,
235  haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
236  menu.AddItem( EE_ACTIONS::pinTable,
237  haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
238 
239  menu.AddSeparator( 1000 );
241 
242  m_disambiguateTimer.SetOwner( this );
243  Connect( wxEVT_TIMER, wxTimerEventHandler( EE_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
244 
245  return true;
246 }
247 
248 
250 {
251  m_frame = getEditFrame<SCH_BASE_FRAME>();
252 
253  if( aReason == TOOL_BASE::MODEL_RELOAD )
254  {
255  // Remove pointers to the selected items from containers without changing their
256  // properties (as they are already deleted while a new sheet is loaded)
257  m_selection.Clear();
258  getView()->GetPainter()->GetSettings()->SetHighlight( false );
259 
260  SYMBOL_EDIT_FRAME* symbolEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
261  SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
262 
263  if( symbolEditFrame )
264  {
265  m_isSymbolEditor = true;
266  m_unit = symbolEditFrame->GetUnit();
267  m_convert = symbolEditFrame->GetConvert();
268  }
269  else
270  m_isSymbolViewer = symbolViewerFrame != nullptr;
271  }
272  else
273  // Restore previous properties of selected items and remove them from containers
274  ClearSelection();
275 
276  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
277  getView()->Remove( &m_selection );
278  getView()->Add( &m_selection );
279 }
280 
281 
283 {
284  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
285  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
286 
287  if( conditionalMenu )
288  conditionalMenu->Evaluate( m_selection );
289 
290  if( actionMenu )
291  actionMenu->UpdateAll();
292 
293  return 0;
294 }
295 
296 
298 {
299  SCH_MARKER_T,
304  SCH_LINE_T,
305  SCH_BITMAP_T,
306  SCH_TEXT_T,
307  SCH_LABEL_T,
310  SCH_FIELD_T,
311  SCH_SYMBOL_T,
313  SCH_SHEET_T,
314  EOT
315 };
316 
317 
319 {
320  LIB_SHAPE_T,
321  LIB_TEXT_T,
322  LIB_PIN_T,
323  LIB_FIELD_T,
324  EOT
325 };
326 
327 
329 {
330  LIB_FIELD_T,
331  EOT
332 };
333 
334 
336 {
338 
339  KIID lastRolloverItem = niluuid;
340 
341  // Main loop: keep receiving events
342  while( TOOL_EVENT* evt = Wait() )
343  {
344  bool displayWireCursor = false;
345  bool displayBusCursor = false;
346  bool displayLineCursor = false;
347  KIID rolloverItem = lastRolloverItem;
348 
349  // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
350  setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
351  evt->Modifier( MD_ALT ) );
352 
353  bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
354 
355  MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
357 
358  if( evt->IsMouseDown( BUT_LEFT ) )
359  {
360  // Avoid triggering when running under other tools
362 
363  if( m_frame->ToolStackIsEmpty() && pt_tool && !pt_tool->HasPoint() )
364  {
366  m_disambiguateTimer.StartOnce( 500 );
367  }
368  }
369  // Single click? Select single object
370  else if( evt->IsClick( BUT_LEFT ) )
371  {
372  // If the timer has stopped, then we have already run the disambiguate routine
373  // and we don't want to register an extra click here
374  if( !m_disambiguateTimer.IsRunning() )
375  {
376  evt->SetPassEvent();
377  continue;
378  }
379 
380  m_disambiguateTimer.Stop();
381 
382  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
383  schframe->FocusOnItem( nullptr );
384 
385  EE_COLLECTOR collector;
386  bool continueSelect = true;
387 
388  // Collect items at the clicked location (doesn't select them yet)
389  if( CollectHits( collector, evt->Position() ) )
390  {
391  narrowSelection( collector, evt->Position(), false, false );
392 
393  if( collector.GetCount() == 1 && !m_isSymbolEditor && !modifier_enabled )
394  {
395  // Check if we want to auto start wires
396  VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
397  LAYER_CONNECTABLE, nullptr );
398 
400 
402  && pt_tool && !pt_tool->HasPoint()
403  && collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
404  {
405  OPT_TOOL_EVENT newEvt;
406  SCH_CONNECTION* connection = collector[0]->Connection();
407 
408  if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
409  || collector[0]->Type() == SCH_SYMBOL_T )
410  {
411  newEvt = EE_ACTIONS::drawWire.MakeEvent();
412  }
413  else if( connection && connection->IsBus() )
414  {
415  newEvt = EE_ACTIONS::drawBus.MakeEvent();
416  }
417  else if( collector[0]->Type() == SCH_LINE_T
418  && static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
419  {
420  newEvt = EE_ACTIONS::drawLines.MakeEvent();
421  }
422  else
423  {
424  newEvt = EE_ACTIONS::drawLines.MakeEvent();
425  }
426 
427  auto* params = newEvt->Parameter<DRAW_SEGMENT_EVENT_PARAMS*>();
428  auto* newParams = new DRAW_SEGMENT_EVENT_PARAMS();
429 
430  *newParams= *params;
431  newParams->quitOnDraw = true;
432  newEvt->SetParameter( newParams );
433 
434  getViewControls()->ForceCursorPosition( true, snappedCursorPos );
435  newEvt->SetMousePosition( snappedCursorPos );
436  newEvt->SetHasPosition( true );
437  newEvt->SetForceImmediate( true );
438  m_toolMgr->ProcessEvent( *newEvt );
439 
440  continueSelect = false;
441  }
442  else if( collector[0]->IsHypertext() )
443  {
444  collector[0]->DoHypertextMenu( m_frame );
445  continueSelect = false;
446  }
447  }
448  }
449 
450  if( continueSelect )
451  {
452  // If we didn't click on an anchor, we perform a normal select, pass in the
453  // items we previously collected
454  selectPoint( collector, nullptr, nullptr, m_additive, m_subtractive,
455  m_exclusive_or );
456 
457  m_selection.SetIsHover( false );
458  }
459  }
460  else if( evt->IsClick( BUT_RIGHT ) )
461  {
462  m_disambiguateTimer.Stop();
463 
464  // right click? if there is any object - show the context menu
465  bool selectionCancelled = false;
466 
467  if( m_selection.Empty() )
468  {
469  ClearSelection();
470  SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
471  &selectionCancelled );
472  m_selection.SetIsHover( true );
473  }
474  // If the cursor has moved off the bounding box of the selection by more than
475  // a grid square, check to see if there is another item available for selection
476  // under the cursor. If there is, the user likely meant to get the context menu
477  // for that item. If there is no new item, then keep the original selection and
478  // show the context menu for it.
479  else if( !m_selection.GetBoundingBox().Inflate(
480  grid.GetGrid().x, grid.GetGrid().y ).Contains(
481  (wxPoint) evt->Position() ) )
482  {
483  EE_SELECTION saved_selection = m_selection;
484 
485  for( const auto& item : saved_selection )
486  RemoveItemFromSel( item, true );
487 
488  SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
489  &selectionCancelled );
490 
491  if( m_selection.Empty() )
492  {
493  m_selection.SetIsHover( false );
494 
495  for( const auto& item : saved_selection )
496  AddItemToSel( item, true);
497  }
498  else
499  {
500  m_selection.SetIsHover( true );
501  }
502  }
503 
504  if( !selectionCancelled )
506  }
507  else if( evt->IsDblClick( BUT_LEFT ) )
508  {
509  m_disambiguateTimer.Stop();
510 
511  // double click? Display the properties window
512  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
513  schframe->FocusOnItem( nullptr );
514 
515  if( m_selection.Empty() )
516  SelectPoint( evt->Position() );
517 
518  EDA_ITEM* item = m_selection.Front();
519 
520  if( item && item->Type() == SCH_SHEET_T )
522  else
524  }
525  else if( evt->IsDblClick( BUT_MIDDLE ) )
526  {
527  m_disambiguateTimer.Stop();
528 
529  // Middle double click? Do zoom to fit or zoom to objects
530  if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
532  else
534  }
535  else if( evt->IsDrag( BUT_LEFT ) )
536  {
537  m_disambiguateTimer.Stop();
538 
539  // Is another tool already moving a new object? Don't allow a drag start
540  if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
541  {
542  evt->SetPassEvent();
543  continue;
544  }
545 
546  // drag with LMB? Select multiple objects (or at least draw a selection box) or
547  // drag them
548  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
549  schframe->FocusOnItem( nullptr );
550 
551  if( modifier_enabled || drag_action == MOUSE_DRAG_ACTION::SELECT )
552  {
553  selectMultiple();
554  }
555  else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
556  {
557  selectMultiple();
558  }
559  else
560  {
561  if( m_isSymbolEditor )
562  {
563  if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
565  else
567  }
568  else
569  {
571  }
572 
573  // Check if dragging has started within any of selected items bounding box
574  if( selectionContains( evt->Position() ) )
575  {
576  // Yes -> run the move tool and wait till it finishes
577  if( m_isSymbolEditor )
578  m_toolMgr->InvokeTool( "eeschema.SymbolMoveTool" );
579  else
580  m_toolMgr->InvokeTool( "eeschema.InteractiveMove" );
581  }
582  else
583  {
584  // No -> drag a selection box
585  selectMultiple();
586  }
587  }
588  }
589  else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
590  {
591  m_disambiguateTimer.Stop();
592 
593  // context sub-menu selection? Handle unit selection or bus unfolding
594  if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
595  && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
596  {
597  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
598  int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
599 
600  if( symbol )
601  static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( symbol, unit );
602  }
603  else if( evt->GetCommandId().get() >= ID_POPUP_SCH_UNFOLD_BUS
604  && evt->GetCommandId().get() <= ID_POPUP_SCH_UNFOLD_BUS_END )
605  {
606  wxString* net = new wxString( *evt->Parameter<wxString*>() );
608  }
609 
610  }
611  else if( evt->IsCancelInteractive() )
612  {
613  m_disambiguateTimer.Stop();
614 
615  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
616  schframe->FocusOnItem( nullptr );
617 
618  ClearSelection();
619  }
620  else if( evt->Action() == TA_UNDO_REDO_PRE )
621  {
622  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
623  schframe->FocusOnItem( nullptr );
624 
625  ClearSelection();
626  }
627  else if( evt->IsMotion() && !m_isSymbolEditor && m_frame->ToolStackIsEmpty() )
628  {
629  rolloverItem = niluuid;
630  EE_COLLECTOR collector;
631 
632  // We are checking if we should display a pencil when hovering over anchors
633  // for "auto starting" wires when clicked
635 
636  if( CollectHits( collector, evt->Position() ) )
637  {
638  narrowSelection( collector, evt->Position(), false, false );
639 
640  if( collector.GetCount() == 1 && !modifier_enabled )
641  {
642  VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
643  LAYER_CONNECTABLE, nullptr );
644 
646 
648  && pt_tool && !pt_tool->HasPoint()
649  && !collector[0]->IsConnectivityDirty()
650  && collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
651  {
652  SCH_CONNECTION* connection = collector[0]->Connection();
653 
654  if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
655  || collector[0]->Type() == SCH_SYMBOL_T )
656  {
657  displayWireCursor = true;
658  }
659  else if( connection && connection->IsBus() )
660  {
661  displayBusCursor = true;
662  }
663  else if( collector[0]->Type() == SCH_LINE_T
664  && static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
665  {
666  displayLineCursor = true;
667  }
668 
669  getViewControls()->ForceCursorPosition( true, snappedCursorPos );
670  }
671  else if( collector[0]->IsHypertext()
672  && !collector[0]->IsSelected()
674  {
675  rolloverItem = collector[0]->m_Uuid;
676  }
677  }
678  }
679  }
680  else
681  {
682  evt->SetPassEvent();
683  }
684 
685  if( rolloverItem != lastRolloverItem )
686  {
687  EDA_ITEM* item = m_frame->GetItem( lastRolloverItem );
688 
689  if( item )
690  {
691  item->ClearFlags( IS_ROLLOVER );
692  lastRolloverItem = niluuid;
693 
694  if( item->Type() == SCH_FIELD_T )
695  m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
696  else
697  m_frame->GetCanvas()->GetView()->Update( item );
698  }
699 
700  item = m_frame->GetItem( rolloverItem );
701 
702  if( item )
703  {
704  item->SetFlags( IS_ROLLOVER );
705  lastRolloverItem = rolloverItem;
706 
707  if( item->Type() == SCH_FIELD_T )
708  m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
709  else
710  m_frame->GetCanvas()->GetView()->Update( item );
711  }
712  }
713 
714  if( m_frame->ToolStackIsEmpty() )
715  {
716  if( displayWireCursor )
717  {
719  }
720  else if( displayBusCursor )
721  {
723  }
724  else if( displayLineCursor )
725  {
727  }
728  else if( rolloverItem != niluuid )
729  {
731  }
732  else if( !m_selection.Empty()
733  && drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
734  && evt->HasPosition()
735  && selectionContains( evt->Position() ) ) //move/drag option prediction
736  {
738  }
739  else
740  {
742  }
743  }
744  }
745 
746  m_disambiguateTimer.Stop();
747 
748  // Shutting down; clear the selection
749  m_selection.Clear();
750 
751  return 0;
752 }
753 
754 
756 {
757  m_skip_heuristics = true;
760  m_skip_heuristics = false;
761 
762  return 0;
763 }
764 
765 
766 void EE_SELECTION_TOOL::onDisambiguationExpire( wxTimerEvent& aEvent )
767 {
769 }
770 
771 
772 void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
773 {
774  if( m_frame->ToolStackIsEmpty() && !m_multiple )
775  {
776  wxMouseState keyboardState = wxGetMouseState();
777 
778  setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
779  keyboardState.AltDown() );
780 
781  if( m_additive )
783  else if( m_subtractive )
785  else if( m_exclusive_or )
787  else
789  }
790 }
791 
792 
794 {
795  return m_selection;
796 }
797 
798 
799 bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
800  const KICAD_T* aFilterList )
801 {
802  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
803  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 );
804  aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
805 
806  if( m_isSymbolEditor )
807  {
808  LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
809 
810  if( !symbol )
811  return false;
812 
813  aCollector.Collect( symbol->GetDrawItems(), aFilterList, (wxPoint) aWhere, m_unit,
814  m_convert );
815  }
816  else
817  {
818  aCollector.Collect( m_frame->GetScreen(), aFilterList, (wxPoint) aWhere, m_unit,
819  m_convert );
820  }
821 
822  return aCollector.GetCount() > 0;
823 }
824 
825 
827  bool aCheckLocked, bool aSelectPoints )
828 {
829  for( int i = collector.GetCount() - 1; i >= 0; --i )
830  {
831  if( !Selectable( collector[i], &aWhere ) )
832  {
833  collector.Remove( i );
834  continue;
835  }
836 
837  if( aCheckLocked && collector[i]->IsLocked() )
838  {
839  collector.Remove( i );
840  continue;
841  }
842 
843  // SelectPoint, unlike other selection routines, can select line ends
844  if( aSelectPoints && collector[i]->Type() == SCH_LINE_T )
845  {
846  SCH_LINE* line = (SCH_LINE*) collector[i];
847  line->ClearFlags( STARTPOINT | ENDPOINT );
848 
849  if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
850  line->SetFlags( STARTPOINT );
851  else if( HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
852  line->SetFlags( ENDPOINT );
853  else
854  line->SetFlags( STARTPOINT | ENDPOINT );
855  }
856  }
857 
858  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
859  if( collector.GetCount() > 1 && !m_skip_heuristics )
860  {
861  GuessSelectionCandidates( collector, aWhere );
862  }
863 }
864 
865 
867  bool* aSelectionCancelledFlag, bool aAdd, bool aSubtract,
868  bool aExclusiveOr )
869 {
871 
872  // If still more than one item we're going to have to ask the user.
873  if( aCollector.GetCount() > 1 )
874  {
875  // Try to call selectionMenu via RunAction() to avoid event-loop contention
876  // But it we cannot handle the event, then we don't have an active tool loop, so
877  // handle it directly.
878  if( !m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &aCollector ) )
879  {
880  if( !doSelectionMenu( &aCollector ) )
881  aCollector.m_MenuCancelled = true;
882  }
883 
884  if( aCollector.m_MenuCancelled )
885  {
886  if( aSelectionCancelledFlag )
887  *aSelectionCancelledFlag = true;
888 
889  return false;
890  }
891  }
892 
893  if( !aAdd && !aSubtract && !aExclusiveOr )
894  ClearSelection();
895 
896  bool anyAdded = false;
897  bool anySubtracted = false;
898 
899  if( aCollector.GetCount() > 0 )
900  {
901  for( int i = 0; i < aCollector.GetCount(); ++i )
902  {
903  if( aSubtract || ( aExclusiveOr && aCollector[i]->IsSelected() ) )
904  {
905  unselect( aCollector[i] );
906  anySubtracted = true;
907  }
908  else
909  {
910  select( aCollector[i] );
911  anyAdded = true;
912  }
913  }
914  }
915 
916  if( anyAdded )
917  {
919 
920  if( aItem && aCollector.GetCount() == 1 )
921  *aItem = aCollector[0];
922 
923  return true;
924  }
925  else if( anySubtracted )
926  {
928  return true;
929  }
930 
931  return false;
932 }
933 
934 
935 bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
936  EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
937  bool aCheckLocked, bool aAdd, bool aSubtract,
938  bool aExclusiveOr )
939 {
940  EE_COLLECTOR collector;
941 
942  if( !CollectHits( collector, aWhere, aFilterList ) )
943  return false;
944 
945  narrowSelection( collector, aWhere, aCheckLocked, true );
946 
947  return selectPoint( collector, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr );
948 }
949 
950 
952 {
953  m_multiple = true; // Multiple selection mode is active
954  KIGFX::VIEW* view = getView();
955 
956  // hold all visible items
957  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
958  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
959 
960  // Filter the view items based on the selection box
961  BOX2I selectionBox;
962 
963  selectionBox.SetMaximum();
964  view->Query( selectionBox, selectedItems ); // Get the list of selected items
965 
966  // Sheet pins aren't in the view; add them by hand
967  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
968  {
969  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
970 
971  if( sheet )
972  {
973  int layer = pair.second;
974 
975  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
976  sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
977  }
978  }
979 
980  selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
981 
982  for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
983  {
984  if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
985  {
986  if( Selectable( item ) )
987  select( item );
988  }
989  }
990 
991  m_multiple = false;
992 
993  return 0;
994 }
995 
996 
998 {
999  // Prefer exact hits to sloppy ones
1000  std::set<EDA_ITEM*> exactHits;
1001 
1002  for( int i = collector.GetCount() - 1; i >= 0; --i )
1003  {
1004  EDA_ITEM* item = collector[ i ];
1005  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1006  LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( item );
1007 
1008  // Lines are hard to hit. Give them a bit more slop to still be considered "exact".
1009 
1010  if( line || ( shape && shape->GetShape() == SHAPE_T::POLY ) )
1011  {
1012  if( item->HitTest( (wxPoint) aPos, Mils2iu( DANGLING_SYMBOL_SIZE ) ) )
1013  exactHits.insert( item );
1014  }
1015  else
1016  {
1017  if( item->HitTest( (wxPoint) aPos, 0 ) )
1018  exactHits.insert( item );
1019  }
1020  }
1021 
1022  if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
1023  {
1024  for( int i = collector.GetCount() - 1; i >= 0; --i )
1025  {
1026  EDA_ITEM* item = collector[ i ];
1027 
1028  if( !exactHits.count( item ) )
1029  collector.Transfer( item );
1030  }
1031  }
1032 
1033  // Find the closest item. (Note that at this point all hits are either exact or non-exact.)
1034  wxPoint pos( aPos );
1035  SEG poss( m_isSymbolEditor ? mapCoords( pos ) : pos,
1036  m_isSymbolEditor ? mapCoords( pos ) : pos );
1037  EDA_ITEM* closest = nullptr;
1038  int closestDist = INT_MAX / 2;
1039 
1040  for( EDA_ITEM* item : collector )
1041  {
1042  EDA_RECT bbox = item->GetBoundingBox();
1043  int dist = INT_MAX / 2;
1044 
1045  if( exactHits.count( item ) )
1046  {
1047  if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
1048  {
1049  closest = item;
1050  break;
1051  }
1052 
1053  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1054  EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
1055  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1056 
1057  if( line )
1058  {
1059  dist = DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos );
1060  }
1061  else if( text )
1062  {
1063  text->GetEffectiveTextShape()->Collide( poss, closestDist, &dist );
1064  }
1065  else if( symbol )
1066  {
1067  try
1068  {
1069  bbox = symbol->GetBodyBoundingBox();
1070  }
1071  catch( const boost::bad_pointer& exc )
1072  {
1073  // This may be overkill and could be an assertion but we are more likely to
1074  // find any boost pointer container errors this way.
1075  wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
1076  }
1077 
1078  SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1079 
1080  if( bbox.Contains( pos ) )
1081  dist = EuclideanNorm( bbox.GetCenter() - pos );
1082  else
1083  rect.Collide( poss, closestDist, &dist );
1084  }
1085  else
1086  {
1087  dist = EuclideanNorm( bbox.GetCenter() - pos );
1088  }
1089  }
1090  else
1091  {
1092  SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1093  rect.Collide( poss, collector.m_Threshold, &dist );
1094  }
1095 
1096  if( dist < closestDist )
1097  {
1098  closestDist = dist;
1099  closest = item;
1100  }
1101  }
1102 
1103  // Construct a tight box (1/2 height and width) around the center of the closest item.
1104  // All items which exist at least partly outside this box have sufficient other areas
1105  // for selection and can be dropped.
1106  if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
1107  {
1108  EDA_RECT tightBox = closest->GetBoundingBox();
1109  tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
1110 
1111  for( int i = collector.GetCount() - 1; i >= 0; --i )
1112  {
1113  EDA_ITEM* item = collector[i];
1114 
1115  if( item == closest )
1116  continue;
1117 
1118  if( !item->HitTest( tightBox, true ) )
1119  collector.Transfer( item );
1120  }
1121  }
1122 }
1123 
1124 
1126 {
1127  if( m_selection.Empty() )
1128  {
1129  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
1130 
1131  ClearSelection();
1132  SelectPoint( cursorPos, aFilterList );
1133  m_selection.SetIsHover( true );
1135  }
1136  else // Trim an existing selection by aFilterList
1137  {
1138  bool isMoving = false;
1139 
1140  for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
1141  {
1142  EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
1143  isMoving |= static_cast<SCH_ITEM*>( item )->IsMoving();
1144 
1145  if( !item->IsType( aFilterList ) )
1146  {
1147  unselect( item );
1149  }
1150  }
1151 
1152  if( !isMoving )
1154  }
1155 
1156  return m_selection;
1157 }
1158 
1159 
1161 {
1162  VECTOR2I refP( 0, 0 );
1163 
1164  if( m_selection.Size() > 0 )
1165  {
1166  if( m_isSymbolEditor )
1167  refP = static_cast<LIB_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1168  else
1169  refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1170  }
1171 
1173 }
1174 
1175 
1176 // Some navigation actions are allowed in selectMultiple
1186  &ACTIONS::zoomFitObjects, nullptr };
1187 
1188 
1190 {
1191  bool cancelled = false; // Was the tool canceled while it was running?
1192  m_multiple = true; // Multiple selection mode is active
1193  KIGFX::VIEW* view = getView();
1194 
1196  view->Add( &area );
1197 
1198  while( TOOL_EVENT* evt = Wait() )
1199  {
1200  int width = area.GetEnd().x - area.GetOrigin().x;
1201  int height = area.GetEnd().y - area.GetOrigin().y;
1202 
1203  /* Selection mode depends on direction of drag-selection:
1204  * Left > Right : Select objects that are fully enclosed by selection
1205  * Right > Left : Select objects that are crossed by selection
1206  */
1207  bool isWindowSelection = width >= 0;
1208 
1209  if( view->IsMirroredX() )
1210  isWindowSelection = !isWindowSelection;
1211 
1214 
1215  if( evt->IsCancelInteractive() || evt->IsActivate() )
1216  {
1217  cancelled = true;
1218  break;
1219  }
1220 
1221  if( evt->IsDrag( BUT_LEFT ) )
1222  {
1224  ClearSelection();
1225 
1226  // Start drawing a selection box
1227  area.SetOrigin( evt->DragOrigin() );
1228  area.SetEnd( evt->Position() );
1229  area.SetAdditive( m_drag_additive );
1231  area.SetExclusiveOr( false );
1232 
1233  view->SetVisible( &area, true );
1234  view->Update( &area );
1235  getViewControls()->SetAutoPan( true );
1236  }
1237 
1238  if( evt->IsMouseUp( BUT_LEFT ) )
1239  {
1240  getViewControls()->SetAutoPan( false );
1241 
1242  // End drawing the selection box
1243  view->SetVisible( &area, false );
1244 
1245  // Fetch items from the RTree that are in our area of interest
1246  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> nearbyViewItems;
1247  view->Query( area.ViewBBox(), nearbyViewItems );
1248 
1249  // Build lists of nearby items and their children
1250  std::vector<EDA_ITEM*> nearbyItems;
1251  std::vector<EDA_ITEM*> nearbyChildren;
1252 
1253  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems )
1254  {
1255  EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first );
1256 
1257  if( item )
1258  {
1260  nearbyItems.push_back( item );
1261  }
1262 
1263  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
1264  {
1265  sch_item->RunOnChildren(
1266  [&]( SCH_ITEM* aChild )
1267  {
1268  nearbyChildren.push_back( aChild );
1269  } );
1270  }
1271  }
1272 
1273  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
1274  selectionRect.Normalize();
1275 
1276  bool anyAdded = false;
1277  bool anySubtracted = false;
1278  auto selectItem =
1279  [&]( EDA_ITEM* aItem )
1280  {
1281  if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
1282  {
1283  unselect( aItem );
1284  anySubtracted = true;
1285  }
1286  else
1287  {
1288  select( aItem );
1289  aItem->SetFlags( STARTPOINT | ENDPOINT );
1290  anyAdded = true;
1291  }
1292  };
1293 
1294  for( EDA_ITEM* item : nearbyItems )
1295  {
1296  if( Selectable( item ) && item->HitTest( selectionRect, isWindowSelection ) )
1297  {
1298  item->SetFlags( TEMP_SELECTED );
1299  selectItem( item );
1300  }
1301  }
1302 
1303  for( EDA_ITEM* item : nearbyChildren )
1304  {
1305  if( Selectable( item )
1306  && !item->GetParent()->HasFlag( TEMP_SELECTED )
1307  && item->HitTest( selectionRect, isWindowSelection ) )
1308  {
1309  selectItem( item );
1310  }
1311  }
1312 
1313  m_selection.SetIsHover( false );
1314 
1315  // Inform other potentially interested tools
1316  if( anyAdded )
1318 
1319  if( anySubtracted )
1321 
1322  break; // Stop waiting for events
1323  }
1324 
1325  // Allow some actions for navigation
1326  for( int i = 0; allowedActions[i]; ++i )
1327  {
1328  if( evt->IsAction( allowedActions[i] ) )
1329  {
1330  evt->SetPassEvent();
1331  break;
1332  }
1333  }
1334  }
1335 
1336  getViewControls()->SetAutoPan( false );
1337 
1338  // Stop drawing the selection box
1339  view->Remove( &area );
1340  m_multiple = false; // Multiple selection mode is inactive
1341 
1342  if( !cancelled )
1344 
1345  return cancelled;
1346 }
1347 
1348 
1349 static KICAD_T nodeTypes[] =
1350 {
1352  SCH_PIN_T,
1357  SCH_LABEL_T,
1362  EOT
1363 };
1364 
1365 
1367 {
1368  EE_COLLECTOR collector;
1369 
1370  //TODO(snh): Reimplement after exposing KNN interface
1371  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1372  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
1373  int thresholdMax = std::max( pixelThreshold, gridThreshold );
1374 
1375  for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
1376  {
1377  collector.m_Threshold = threshold;
1378  collector.Collect( m_frame->GetScreen(), nodeTypes, (wxPoint) aPosition );
1379 
1380  if( collector.GetCount() > 0 )
1381  break;
1382  }
1383 
1384  return collector.GetCount() ? collector[ 0 ] : nullptr;
1385 }
1386 
1387 
1389 {
1390  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
1391 
1392  SelectPoint( cursorPos, nodeTypes );
1393 
1394  return 0;
1395 }
1396 
1397 
1399 {
1400  static KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
1401 
1402  RequestSelection( wiresAndBuses );
1403 
1404  if( m_selection.Empty() )
1405  return 0;
1406 
1407  SCH_LINE* line = (SCH_LINE*) m_selection.Front();
1408  EDA_ITEMS items;
1409 
1411  std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line );
1412 
1413  for( SCH_ITEM* item : conns )
1414  select( item );
1415 
1416  if( m_selection.GetSize() > 1 )
1418 
1419  return 0;
1420 }
1421 
1422 
1424 {
1425  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
1426  m_selection.SetIsHover( false );
1427  return 0;
1428 }
1429 
1430 
1431 void EE_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
1432 {
1433  if( aItem )
1434  {
1435  select( aItem );
1436 
1437  // Inform other potentially interested tools
1438  if( !aQuietMode )
1440  }
1441 }
1442 
1443 
1445 {
1446  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1447  m_selection.SetIsHover( false );
1448  return 0;
1449 }
1450 
1451 
1452 void EE_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
1453 {
1454  if( aList )
1455  {
1456  for( EDA_ITEM* item : *aList )
1457  select( item );
1458 
1459  // Inform other potentially interested tools
1460  if( !aQuietMode )
1462  }
1463 }
1464 
1465 
1467 {
1468  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
1469  m_selection.SetIsHover( false );
1470  return 0;
1471 }
1472 
1473 
1474 void EE_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
1475 {
1476  if( aItem )
1477  {
1478  unselect( aItem );
1479 
1480  // Inform other potentially interested tools
1481  if( !aQuietMode )
1483  }
1484 }
1485 
1486 
1488 {
1489  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1490  m_selection.SetIsHover( false );
1491  return 0;
1492 }
1493 
1494 
1495 void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
1496 {
1497  if( aList )
1498  {
1499  for( EDA_ITEM* item : *aList )
1500  unselect( item );
1501 
1502  // Inform other potentially interested tools
1503  if( !aQuietMode )
1505  }
1506 }
1507 
1508 
1509 void EE_SELECTION_TOOL::RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode )
1510 {
1511  EDA_ITEMS removeItems;
1512 
1513  for( EDA_ITEM* item : m_selection )
1514  {
1515  if( alg::contains( *aList, item->m_Uuid ) )
1516  removeItems.push_back( item );
1517  }
1518 
1519  RemoveItemsFromSel( &removeItems, aQuietMode );
1520 }
1521 
1522 
1524 {
1525  highlight( aItem, BRIGHTENED );
1526 }
1527 
1528 
1530 {
1531  unhighlight( aItem, BRIGHTENED );
1532 }
1533 
1534 
1536 {
1537  ClearSelection();
1538 
1539  return 0;
1540 }
1541 
1542 
1544 {
1545  m_selection.Clear();
1546 
1547  if( m_isSymbolEditor )
1548  {
1549  LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
1550 
1551  for( LIB_ITEM& item : start->GetDrawItems() )
1552  {
1553  if( item.IsSelected() )
1554  select( static_cast<EDA_ITEM*>( &item ) );
1555  }
1556  }
1557  else
1558  {
1559  for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
1560  {
1561  // If the field and symbol are selected, only use the symbol
1562  if( item->IsSelected() )
1563  {
1564  select( item );
1565  }
1566  else
1567  {
1568  item->RunOnChildren(
1569  [&]( SCH_ITEM* aChild )
1570  {
1571  if( aChild->IsSelected() )
1572  select( aChild );
1573  } );
1574  }
1575  }
1576  }
1577 
1579 
1580  // Inform other potentially interested tools
1582 }
1583 
1584 
1586 {
1587  EE_COLLECTOR* collector = aEvent.Parameter<EE_COLLECTOR*>();
1588 
1589  if( !doSelectionMenu( collector ) )
1590  collector->m_MenuCancelled = true;
1591 
1592  return 0;
1593 }
1594 
1595 
1597 {
1598  EDA_ITEM* current = nullptr;
1599  bool selectAll = false;
1600  bool expandSelection = false;
1601 
1602  do
1603  {
1605  if( expandSelection )
1606  aCollector->Combine();
1607 
1608  expandSelection = false;
1609 
1610  int limit = std::min( 9, aCollector->GetCount() );
1611  ACTION_MENU menu( true );
1612 
1613  for( int i = 0; i < limit; ++i )
1614  {
1615  wxString text;
1616  EDA_ITEM* item = ( *aCollector )[i];
1618 
1619  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1620  menu.Add( menuText, i + 1, item->GetMenuImage() );
1621  }
1622 
1623  menu.AppendSeparator();
1624  menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
1625 
1626  if( !expandSelection && aCollector->HasAdditionalItems() )
1627  menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
1628 
1629  if( aCollector->m_MenuTitle.Length() )
1630  {
1631  menu.SetTitle( aCollector->m_MenuTitle );
1632  menu.SetIcon( BITMAPS::info );
1633  menu.DisplayTitle( true );
1634  }
1635  else
1636  {
1637  menu.DisplayTitle( false );
1638  }
1639 
1640  SetContextMenu( &menu, CMENU_NOW );
1641 
1642  while( TOOL_EVENT* evt = Wait() )
1643  {
1644  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1645  {
1646  if( selectAll )
1647  {
1648  for( int i = 0; i < aCollector->GetCount(); ++i )
1649  unhighlight( ( *aCollector )[i], BRIGHTENED );
1650  }
1651  else if( current )
1652  {
1653  unhighlight( current, BRIGHTENED );
1654  }
1655 
1656  int id = *evt->GetCommandId();
1657 
1658  // User has pointed an item, so show it in a different way
1659  if( id > 0 && id <= limit )
1660  {
1661  current = ( *aCollector )[id - 1];
1662  highlight( current, BRIGHTENED );
1663  }
1664  else
1665  {
1666  current = nullptr;
1667  }
1668 
1669  // User has pointed on the "Select All" option
1670  if( id == limit + 1 )
1671  {
1672  for( int i = 0; i < aCollector->GetCount(); ++i )
1673  highlight( ( *aCollector )[i], BRIGHTENED );
1674  selectAll = true;
1675  }
1676  else
1677  {
1678  selectAll = false;
1679  }
1680  }
1681  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1682  {
1683  if( selectAll )
1684  {
1685  for( int i = 0; i < aCollector->GetCount(); ++i )
1686  unhighlight( ( *aCollector )[i], BRIGHTENED );
1687  }
1688  else if( current )
1689  unhighlight( current, BRIGHTENED );
1690 
1691  OPT<int> id = evt->GetCommandId();
1692 
1693  // User has selected the "Select All" option
1694  if( id == limit + 1 )
1695  {
1696  selectAll = true;
1697  current = nullptr;
1698  }
1699  else if( id == limit + 2 )
1700  {
1701  selectAll = false;
1702  current = nullptr;
1703  expandSelection = true;
1704  }
1705  // User has selected an item, so this one will be returned
1706  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1707  {
1708  selectAll = false;
1709  current = ( *aCollector )[*id - 1];
1710  }
1711  // User has cancelled the menu (either by <esc> or clicking out of it)
1712  else
1713  {
1714  selectAll = false;
1715  current = nullptr;
1716  }
1717  }
1718  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1719  {
1720  break;
1721  }
1722 
1723  getView()->UpdateItems();
1724  m_frame->GetCanvas()->Refresh();
1725  }
1726  } while( expandSelection );
1727 
1728  if( selectAll )
1729  return true;
1730  else if( current )
1731  {
1732  unhighlight( current, BRIGHTENED );
1733 
1734  getView()->UpdateItems();
1735  m_frame->GetCanvas()->Refresh();
1736 
1737  aCollector->Empty();
1738  aCollector->Append( current );
1739  return true;
1740  }
1741 
1742  return false;
1743 }
1744 
1745 
1746 bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
1747  bool checkVisibilityOnly ) const
1748 {
1749  // NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
1750 
1751  SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
1752 
1753  // Do not allow selection of anything except fields when the current symbol in the symbol
1754  // editor is a derived symbol.
1755  if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != LIB_FIELD_T )
1756  return false;
1757 
1758  switch( aItem->Type() )
1759  {
1760  case SCH_PIN_T:
1761  {
1762  const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
1763 
1764  if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
1765  return false;
1766 
1768  {
1769  // Pin anchors have to be allowed for auto-starting wires.
1770  if( aPos )
1771  {
1773  VECTOR2I cursorPos = grid.BestSnapAnchor( *aPos, LAYER_CONNECTABLE, nullptr );
1774 
1775  if( pin->IsPointClickableAnchor( (wxPoint) cursorPos ) )
1776  return true;
1777  }
1778 
1779  return false;
1780  }
1781  }
1782  break;
1783 
1784  case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
1785  return false;
1786 
1787  case LIB_FIELD_T: // LIB_FIELD object can always be edited.
1788  break;
1789 
1790  case LIB_SHAPE_T:
1791  case LIB_TEXT_T:
1792  case LIB_PIN_T:
1793  if( symEditFrame )
1794  {
1795  LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
1796 
1797  if( lib_item->GetUnit() && lib_item->GetUnit() != symEditFrame->GetUnit() )
1798  return false;
1799 
1800  if( lib_item->GetConvert() && lib_item->GetConvert() != symEditFrame->GetConvert() )
1801  return false;
1802  }
1803 
1804  break;
1805 
1806  case SCH_MARKER_T: // Always selectable
1807  return true;
1808 
1809  default: // Suppress warnings
1810  break;
1811  }
1812 
1813  return true;
1814 }
1815 
1816 
1818 {
1819  if( m_selection.Empty() )
1820  return;
1821 
1822  while( m_selection.GetSize() )
1824 
1825  getView()->Update( &m_selection );
1826 
1827  m_selection.SetIsHover( false );
1829 
1830  // Inform other potentially interested tools
1832 }
1833 
1834 
1836 {
1837  highlight( aItem, SELECTED, &m_selection );
1838 }
1839 
1840 
1842 {
1843  unhighlight( aItem, SELECTED, &m_selection );
1844 }
1845 
1846 
1847 void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1848 {
1849  KICAD_T itemType = aItem->Type();
1850 
1851  if( aMode == SELECTED )
1852  aItem->SetSelected();
1853  else if( aMode == BRIGHTENED )
1854  aItem->SetBrightened();
1855 
1856  if( aGroup )
1857  aGroup->Add( aItem );
1858 
1859  // Highlight pins and fields. (All the other symbol children are currently only
1860  // represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
1861  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1862  {
1863  sch_item->RunOnChildren(
1864  [&]( SCH_ITEM* aChild )
1865  {
1866  if( aMode == SELECTED )
1867  aChild->SetSelected();
1868  else if( aMode == BRIGHTENED )
1869  aChild->SetBrightened();
1870  } );
1871  }
1872 
1873  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1874  getView()->Update( aItem->GetParent() );
1875  else
1876  getView()->Update( aItem );
1877 }
1878 
1879 
1880 void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1881 {
1882  KICAD_T itemType = aItem->Type();
1883 
1884  if( aMode == SELECTED )
1885  aItem->ClearSelected();
1886  else if( aMode == BRIGHTENED )
1887  aItem->ClearBrightened();
1888 
1889  if( aGroup )
1890  aGroup->Remove( aItem );
1891 
1892  // Unhighlight pins and fields. (All the other symbol children are currently only
1893  // represented in the LIB_SYMBOL.)
1894  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1895  {
1896  sch_item->RunOnChildren(
1897  [&]( SCH_ITEM* aChild )
1898  {
1899  if( aMode == SELECTED )
1900  aChild->ClearSelected();
1901  else if( aMode == BRIGHTENED )
1902  aChild->ClearBrightened();
1903  } );
1904  }
1905 
1906  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1907  getView()->Update( aItem->GetParent() );
1908  else
1909  getView()->Update( aItem );
1910 }
1911 
1912 
1914 {
1915  const unsigned GRIP_MARGIN = 20;
1916  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1917 
1918  // Check if the point is located within any of the currently selected items bounding boxes
1919  for( EDA_ITEM* item : m_selection )
1920  {
1921  BOX2I itemBox = item->ViewBBox();
1922  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1923 
1924  if( itemBox.Contains( aPoint ) )
1925  return true;
1926  }
1927 
1928  return false;
1929 }
1930 
1931 
1933 {
1935 
1940 
1946 
1948 
1950 }
1951 
1952 
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
void Empty()
Clear the list.
Definition: collector.h:90
static TOOL_ACTION editPageNumber
Definition: ee_actions.h:154
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition: shape_rect.h:98
void ClearReferencePoint()
Definition: selection.h:194
static TOOL_ACTION pinTable
Definition: ee_actions.h:145
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
static TOOL_ACTION properties
Definition: ee_actions.h:120
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
void OnIdle(wxIdleEvent &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:200
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
bool selectionContains(const VECTOR2I &aPoint) const
Set up handlers for various events.
int m_Threshold
Definition: collector.h:241
int UpdateMenu(const TOOL_EVENT &aEvent)
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:83
KIID niluuid(0)
bool IsUnconnected() const
static bool IsDrawingWire(const SELECTION &aSelection)
#define STARTPOINT
When a line is selected, these flags indicate which.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
int SelectAll(const TOOL_EVENT &aEvent)
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
static TOOL_ACTION zoomInCenter
Definition: actions.h:93
static TOOL_ACTION breakBus
Definition: ee_actions.h:134
static SELECTION_CONDITION SingleSymbol
wxPoint GetStartPoint() const
Definition: sch_line.h:90
bool IsSelected() const
Definition: eda_item.h:122
Model changes (required full reload)
Definition: tool_base.h:80
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:201
#define IS_NEW
New item, just created.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:449
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
static const TOOL_EVENT DisambiguatePoint
Definition: actions.h:215
void ClearSelected()
Definition: eda_item.h:131
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
void Collect(SCH_SCREEN *aScreen, const KICAD_T aFilterList[], const wxPoint &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
EDA_RECT GetBoundingBox() const override
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:63
VECTOR2D GetMousePosition() const
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
bool HasPoint()
Indicate the cursor is over an edit point.
const KICAD_T movableSymbolAliasItems[]
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:87
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
static TOOL_ACTION placeJunction
Definition: ee_actions.h:83
static TOOL_ACTION selectConnection
If current selection is a wire or bus, expand to entire connection.
Definition: ee_actions.h:53
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:350
int GetWidth() const
Definition: eda_rect.h:109
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
static TOOL_ACTION unfoldBus
Definition: ee_actions.h:81
static TOOL_ACTION cursorRight
Definition: actions.h:116
void SetBrightened()
Definition: eda_item.h:129
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
#define HITTEST_THRESHOLD_PIXELS
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION cursorRightFast
Definition: actions.h:121
void SetExclusiveOr(bool aExclusiveOr)
Symbol library viewer main window.
int AddItemsToSel(const TOOL_EVENT &aEvent)
void select(EDA_ITEM *aItem)
Take necessary action mark an item as selected.
Schematic editor (Eeschema) main window.
void UpdateAll()
Run update handlers for the menu and its submenus.
KICURSOR
Definition: cursors.h:33
static TOOL_ACTION zoomFitObjects
Definition: actions.h:97
#define ENDPOINT
ends. (Used to support dragging.)
static TOOL_ACTION panLeft
Definition: actions.h:129
static TOOL_ACTION removeItemsFromSel
Definition: ee_actions.h:64
static TOOL_ACTION importSingleSheetPin
Definition: ee_actions.h:188
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
Define a library symbol object.
Definition: lib_symbol.h:96
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:208
static TOOL_ACTION zoomOutCenter
Definition: actions.h:94
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
static TOOL_ACTION breakWire
Definition: ee_actions.h:133
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:164
void SetIsHover(bool aIsHover)
Definition: selection.h:69
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state ...
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
const KICAD_T movableSymbolItems[]
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:185
void ClearBrightened()
Definition: eda_item.h:132
static TOOL_ACTION removeItemFromSel
Definition: ee_actions.h:60
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:100
void SetAdditive(bool aAdditive)
bool m_MenuCancelled
Definition: collector.h:244
EE_SELECTION & GetSelection()
Return the set of currently selected items.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
EESCHEMA_SETTINGS * eeconfig() const
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Return either an existing selection (filtered), or the selection at the current cursor if the existin...
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:224
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
static SELECTION_CONDITION SingleDeMorganSymbol
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int SelectNode(const TOOL_EVENT &aEvent)
If node selected then expand to connection, otherwise select connection under cursor.
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:189
int GetUnit() const
Definition: lib_item.h:258
void SetOrigin(const VECTOR2I &aOrigin)
bool Init() override
Init() is called once upon a registration of the tool.
void Transfer(int aIndex)
Move the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:152
void BrightenItem(EDA_ITEM *aItem)
MOUSE_DRAG_ACTION
bool selectPoint(EE_COLLECTOR &aCollector, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This is the primary SelectPoint method that will prompt the user with a menu to disambiguate multiple...
void highlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Highlight the item visually.
MOUSE_DRAG_ACTION GetDragAction() const
Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) objects.
Definition: tools_holder.h:135
#define IS_MOVING
Item being moved.
static TOOL_ACTION addItemToSel
Selects an item (specified as the event parameter).
Definition: ee_actions.h:59
void SetSelected()
Definition: eda_item.h:128
static TOOL_ACTION panDown
Definition: actions.h:128
bool IsSymbolAlias() const
Restore the empty editor screen, without any symbol or library selected.
static TOOL_ACTION drawWire
Definition: ee_actions.h:79
#define DANGLING_SYMBOL_SIZE
< The size of the rectangle indicating an unconnected wire or label
static SELECTION_CONDITION LessThan(int aNumber)
Create a functor that tests if the number of selected items is smaller than the value given as parame...
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
static TOOL_ACTION explicitCrossProbe
Definition: ee_actions.h:199
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
const wxPoint GetPosition() const
Definition: eda_rect.h:102
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:144
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool Contains(const Vec &aPoint) const
Definition: box2.h:134
Generic, UI-independent tool event.
Definition: tool_event.h:152
static TOOL_ACTION cursorUpFast
Definition: actions.h:118
static TOOL_ACTION cursorDownFast
Definition: actions.h:119
static TOOL_ACTION cursorLeft
Definition: actions.h:115
void narrowSelection(EE_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked, bool aSelectPoints)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
static TOOL_ACTION panRight
Definition: actions.h:130
void SetMaximum()
Definition: box2.h:57
EDA_RECT GetBodyBoundingBox() const
Return a bounding box for the symbol body but not the pins or fields.
const BOX2I ViewBBox() const override
Set the origin of the rectangle (the fixed corner)
SCHEMATIC & Schematic() const
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
EDA_ITEM * GetParent() const
Definition: eda_item.h:114
const TOOL_ACTION * allowedActions[]
#define _(s)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:153
int SelectConnection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:202
#define SELECTED
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:182
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
Definition: view.cpp:1402
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
static TOOL_ACTION cursorLeftFast
Definition: actions.h:120
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Select one or more items at the location given by parameter aWhere.
wxTimer m_disambiguateTimer
static TOOL_ACTION updateMenu
Definition: actions.h:167
static SELECTION_CONDITION SingleMultiUnitSymbol
static VECTOR2D mapCoords(const wxPoint &aCoord)
int GetConvert() const
Definition: lib_item.h:261
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:484
void UnbrightenItem(EDA_ITEM *aItem)
EDA_ITEM * GetNode(VECTOR2I aPosition)
Select node under cursor.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
int GetHeight() const
Definition: eda_rect.h:110
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
static bool IsDrawingBus(const SELECTION &aSelection)
static TOOL_ACTION drawBus
Definition: ee_actions.h:80
wxString m_MenuTitle
Definition: collector.h:243
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:238
void SetSubtractive(bool aSubtractive)
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:88
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:186
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Definition: seg.h:40
static TOOL_ACTION placeLabel
Definition: ee_actions.h:85
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
void unselect(EDA_ITEM *aItem)
Take necessary action mark an item as unselected.
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281
bool IsNet() const
SCH_SHEET & Root() const
Definition: schematic.h:92
static KICAD_T nodeTypes[]
bool HasAdditionalItems()
Test if the collector has heuristic backup items.
Definition: collector.h:133
Schematic symbol object.
Definition: sch_symbol.h:78
int AddItemToSel(const TOOL_EVENT &aEvent)
#define TEMP_SELECTED
flag indicating that the structure has already selected
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
static TOOL_ACTION zoomCenter
Definition: actions.h:95
virtual bool GetShowAllPins() const
Allow some frames to show/hide hidden pins.
bool SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere before c...
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:53
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition: actions.h:113
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
#define IS_ROLLOVER
Rollover active. Used for hyperlink highlighting.
Tool that displays edit points allowing to modify items by dragging the points.
bool doSelectionMenu(EE_COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
SCH_BASE_FRAME * m_frame
static TOOL_ACTION assignNetclass
Definition: ee_actions.h:151
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:109
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:274
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:73
bool HitTestPoints(const wxPoint &pointA, const wxPoint &pointB, double threshold)
Test, if two points are near each other.
Definition: trigo.h:184
static TOOL_ACTION selectionMenu
Runs a selection menu to select from a list of items.
Definition: ee_actions.h:67
Represent a single user action.
Definition: tool_action.h:67
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:44
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Create a functor that tests if the selected items are only of given type.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Handle the component boundary box.
Definition: eda_rect.h:42
static SELECTION_CONDITION SingleNonExcludedMarker
static const KICAD_T AllItems[]
Definition: ee_collectors.h:42
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
static bool Empty(const SELECTION &aSelection)
Test if there are no items selected.
static TOOL_ACTION selectNode
Select the junction, wire or bus segment under the cursor.
Definition: ee_actions.h:49
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:73
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
static TOOL_ACTION enterSheet
Definition: ee_actions.h:184
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1516
static SELECTION_CONDITION SingleSymbolOrPower
void Combine()
Re-combine the backup list into the main list of the collector.
Definition: collector.h:141
static TOOL_ACTION panUp
Definition: actions.h:127
SCH_SHEET_PATH & GetCurrentSheet() const
static TOOL_ACTION zoomIn
Definition: actions.h:91
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
static TOOL_ACTION zoomOut
Definition: actions.h:92
VECTOR2I m_originalCursor
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:320
static TOOL_ACTION drawLines
Definition: ee_actions.h:91
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:893
SHAPE_T GetShape() const
Definition: eda_shape.h:92
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:426
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
const wxPoint GetCenter() const
Definition: eda_rect.h:104
bool IsBus() const
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:86
static TOOL_ACTION finishBus
Definition: ee_actions.h:95
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
static TOOL_ACTION cursorDown
Definition: actions.h:114
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
EE_SELECTION m_selection
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
static TOOL_ACTION selectAll
Definition: actions.h:70
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION finishWire
Definition: ee_actions.h:94
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
double DistanceLinePoint(const wxPoint &linePointA, const wxPoint &linePointB, const wxPoint &referencePoint)
Compute the distance between a line and a reference point Reference: http://mathworld....
Definition: trigo.h:163
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:145
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1570
const KICAD_T movableSchematicItems[]
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:548
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
int Main(const TOOL_EVENT &aEvent)
The main loop.
#define BRIGHTENED
item is drawn with a bright contour
The symbol library editor main window.
std::set< SCH_ITEM * > MarkConnections(SCH_LINE *aSegment)
Return all wires and junctions connected to aSegment which are not connected any symbol pin.
Definition: sch_screen.cpp:358
wxPoint GetEndPoint() const
Definition: sch_line.h:93