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::Count( 1 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T );
169  auto busSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T );
170  auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( wireOrBusTypes );
171  auto connectedSelection = E_C::Count( 1 ) && 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, connectedSelection && 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  wxMouseState keyboardState = wxGetMouseState();
758 
759  setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
760  keyboardState.AltDown() );
761 
762  m_skip_heuristics = true;
765  m_skip_heuristics = false;
766 
767  return 0;
768 }
769 
770 
771 void EE_SELECTION_TOOL::onDisambiguationExpire( wxTimerEvent& aEvent )
772 {
774 }
775 
776 
777 void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
778 {
779  if( m_frame->ToolStackIsEmpty() && !m_multiple )
780  {
781  wxMouseState keyboardState = wxGetMouseState();
782 
783  setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
784  keyboardState.AltDown() );
785 
786  if( m_additive )
788  else if( m_subtractive )
790  else if( m_exclusive_or )
792  else
794  }
795 }
796 
797 
799 {
800  return m_selection;
801 }
802 
803 
804 bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
805  const KICAD_T* aFilterList )
806 {
807  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
808  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 );
809  aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
810 
811  if( m_isSymbolEditor )
812  {
813  LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
814 
815  if( !symbol )
816  return false;
817 
818  aCollector.Collect( symbol->GetDrawItems(), aFilterList, (wxPoint) aWhere, m_unit,
819  m_convert );
820  }
821  else
822  {
823  aCollector.Collect( m_frame->GetScreen(), aFilterList, (wxPoint) aWhere, m_unit,
824  m_convert );
825  }
826 
827  return aCollector.GetCount() > 0;
828 }
829 
830 
832  bool aCheckLocked, bool aSelectPoints )
833 {
834  for( int i = collector.GetCount() - 1; i >= 0; --i )
835  {
836  if( !Selectable( collector[i], &aWhere ) )
837  {
838  collector.Remove( i );
839  continue;
840  }
841 
842  if( aCheckLocked && collector[i]->IsLocked() )
843  {
844  collector.Remove( i );
845  continue;
846  }
847 
848  // SelectPoint, unlike other selection routines, can select line ends
849  if( aSelectPoints && collector[i]->Type() == SCH_LINE_T )
850  {
851  SCH_LINE* line = (SCH_LINE*) collector[i];
852  line->ClearFlags( STARTPOINT | ENDPOINT );
853 
854  if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
855  line->SetFlags( STARTPOINT );
856  else if( HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
857  line->SetFlags( ENDPOINT );
858  else
859  line->SetFlags( STARTPOINT | ENDPOINT );
860  }
861  }
862 
863  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
864  if( collector.GetCount() > 1 && !m_skip_heuristics )
865  {
866  GuessSelectionCandidates( collector, aWhere );
867  }
868 }
869 
870 
872  bool* aSelectionCancelledFlag, bool aAdd, bool aSubtract,
873  bool aExclusiveOr )
874 {
876 
877  // If still more than one item we're going to have to ask the user.
878  if( aCollector.GetCount() > 1 )
879  {
880  // Try to call selectionMenu via RunAction() to avoid event-loop contention
881  // But it we cannot handle the event, then we don't have an active tool loop, so
882  // handle it directly.
883  if( !m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &aCollector ) )
884  {
885  if( !doSelectionMenu( &aCollector ) )
886  aCollector.m_MenuCancelled = true;
887  }
888 
889  if( aCollector.m_MenuCancelled )
890  {
891  if( aSelectionCancelledFlag )
892  *aSelectionCancelledFlag = true;
893 
894  return false;
895  }
896  }
897 
898  if( !aAdd && !aSubtract && !aExclusiveOr )
899  ClearSelection();
900 
901  bool anyAdded = false;
902  bool anySubtracted = false;
903 
904  if( aCollector.GetCount() > 0 )
905  {
906  for( int i = 0; i < aCollector.GetCount(); ++i )
907  {
908  if( aSubtract || ( aExclusiveOr && aCollector[i]->IsSelected() ) )
909  {
910  unselect( aCollector[i] );
911  anySubtracted = true;
912  }
913  else
914  {
915  select( aCollector[i] );
916  anyAdded = true;
917  }
918  }
919  }
920 
921  if( anyAdded )
922  {
924 
925  if( aItem && aCollector.GetCount() == 1 )
926  *aItem = aCollector[0];
927 
928  return true;
929  }
930  else if( anySubtracted )
931  {
933  return true;
934  }
935 
936  return false;
937 }
938 
939 
940 bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
941  EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
942  bool aCheckLocked, bool aAdd, bool aSubtract,
943  bool aExclusiveOr )
944 {
945  EE_COLLECTOR collector;
946 
947  if( !CollectHits( collector, aWhere, aFilterList ) )
948  return false;
949 
950  narrowSelection( collector, aWhere, aCheckLocked, true );
951 
952  return selectPoint( collector, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr );
953 }
954 
955 
957 {
958  m_multiple = true; // Multiple selection mode is active
959  KIGFX::VIEW* view = getView();
960 
961  // hold all visible items
962  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
963  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
964 
965  // Filter the view items based on the selection box
966  BOX2I selectionBox;
967 
968  selectionBox.SetMaximum();
969  view->Query( selectionBox, selectedItems ); // Get the list of selected items
970 
971  // Sheet pins aren't in the view; add them by hand
972  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
973  {
974  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
975 
976  if( sheet )
977  {
978  int layer = pair.second;
979 
980  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
981  sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
982  }
983  }
984 
985  selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
986 
987  for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
988  {
989  if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
990  {
991  if( Selectable( item ) )
992  select( item );
993  }
994  }
995 
996  m_multiple = false;
997 
998  return 0;
999 }
1000 
1001 
1003 {
1004  // Prefer exact hits to sloppy ones
1005  std::set<EDA_ITEM*> exactHits;
1006 
1007  for( int i = collector.GetCount() - 1; i >= 0; --i )
1008  {
1009  EDA_ITEM* item = collector[ i ];
1010  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1011  LIB_SHAPE* shape = dynamic_cast<LIB_SHAPE*>( item );
1012 
1013  // Lines are hard to hit. Give them a bit more slop to still be considered "exact".
1014 
1015  if( line || ( shape && shape->GetShape() == SHAPE_T::POLY ) )
1016  {
1017  if( item->HitTest( (wxPoint) aPos, Mils2iu( DANGLING_SYMBOL_SIZE ) ) )
1018  exactHits.insert( item );
1019  }
1020  else
1021  {
1022  if( item->HitTest( (wxPoint) aPos, 0 ) )
1023  exactHits.insert( item );
1024  }
1025  }
1026 
1027  if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
1028  {
1029  for( int i = collector.GetCount() - 1; i >= 0; --i )
1030  {
1031  EDA_ITEM* item = collector[ i ];
1032 
1033  if( !exactHits.count( item ) )
1034  collector.Transfer( item );
1035  }
1036  }
1037 
1038  // Find the closest item. (Note that at this point all hits are either exact or non-exact.)
1039  wxPoint pos( aPos );
1040  SEG poss( m_isSymbolEditor ? mapCoords( pos ) : pos,
1041  m_isSymbolEditor ? mapCoords( pos ) : pos );
1042  EDA_ITEM* closest = nullptr;
1043  int closestDist = INT_MAX / 2;
1044 
1045  for( EDA_ITEM* item : collector )
1046  {
1047  EDA_RECT bbox = item->GetBoundingBox();
1048  int dist = INT_MAX / 2;
1049 
1050  if( exactHits.count( item ) )
1051  {
1052  if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
1053  {
1054  closest = item;
1055  break;
1056  }
1057 
1058  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1059  EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
1060  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1061 
1062  if( line )
1063  {
1064  dist = DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos );
1065  }
1066  else if( text )
1067  {
1068  text->GetEffectiveTextShape()->Collide( poss, closestDist, &dist );
1069  }
1070  else if( symbol )
1071  {
1072  try
1073  {
1074  bbox = symbol->GetBodyBoundingBox();
1075  }
1076  catch( const boost::bad_pointer& exc )
1077  {
1078  // This may be overkill and could be an assertion but we are more likely to
1079  // find any boost pointer container errors this way.
1080  wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
1081  }
1082 
1083  SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1084 
1085  if( bbox.Contains( pos ) )
1086  dist = EuclideanNorm( bbox.GetCenter() - pos );
1087  else
1088  rect.Collide( poss, closestDist, &dist );
1089  }
1090  else
1091  {
1092  dist = EuclideanNorm( bbox.GetCenter() - pos );
1093  }
1094  }
1095  else
1096  {
1097  SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1098  rect.Collide( poss, collector.m_Threshold, &dist );
1099  }
1100 
1101  if( dist < closestDist )
1102  {
1103  closestDist = dist;
1104  closest = item;
1105  }
1106  }
1107 
1108  // Construct a tight box (1/2 height and width) around the center of the closest item.
1109  // All items which exist at least partly outside this box have sufficient other areas
1110  // for selection and can be dropped.
1111  if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
1112  {
1113  EDA_RECT tightBox = closest->GetBoundingBox();
1114  tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
1115 
1116  for( int i = collector.GetCount() - 1; i >= 0; --i )
1117  {
1118  EDA_ITEM* item = collector[i];
1119 
1120  if( item == closest )
1121  continue;
1122 
1123  if( !item->HitTest( tightBox, true ) )
1124  collector.Transfer( item );
1125  }
1126  }
1127 }
1128 
1129 
1131 {
1132  if( m_selection.Empty() )
1133  {
1134  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
1135 
1136  ClearSelection();
1137  SelectPoint( cursorPos, aFilterList );
1138  m_selection.SetIsHover( true );
1140  }
1141  else // Trim an existing selection by aFilterList
1142  {
1143  bool isMoving = false;
1144 
1145  for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
1146  {
1147  EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
1148  isMoving |= static_cast<SCH_ITEM*>( item )->IsMoving();
1149 
1150  if( !item->IsType( aFilterList ) )
1151  {
1152  unselect( item );
1154  }
1155  }
1156 
1157  if( !isMoving )
1159  }
1160 
1161  return m_selection;
1162 }
1163 
1164 
1166 {
1167  VECTOR2I refP( 0, 0 );
1168 
1169  if( m_selection.Size() > 0 )
1170  {
1171  if( m_isSymbolEditor )
1172  refP = static_cast<LIB_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1173  else
1174  refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1175  }
1176 
1178 }
1179 
1180 
1181 // Some navigation actions are allowed in selectMultiple
1191  &ACTIONS::zoomFitObjects, nullptr };
1192 
1193 
1195 {
1196  bool cancelled = false; // Was the tool canceled while it was running?
1197  m_multiple = true; // Multiple selection mode is active
1198  KIGFX::VIEW* view = getView();
1199 
1201  view->Add( &area );
1202 
1203  while( TOOL_EVENT* evt = Wait() )
1204  {
1205  int width = area.GetEnd().x - area.GetOrigin().x;
1206  int height = area.GetEnd().y - area.GetOrigin().y;
1207 
1208  /* Selection mode depends on direction of drag-selection:
1209  * Left > Right : Select objects that are fully enclosed by selection
1210  * Right > Left : Select objects that are crossed by selection
1211  */
1212  bool isWindowSelection = width >= 0;
1213 
1214  if( view->IsMirroredX() )
1215  isWindowSelection = !isWindowSelection;
1216 
1219 
1220  if( evt->IsCancelInteractive() || evt->IsActivate() )
1221  {
1222  cancelled = true;
1223  break;
1224  }
1225 
1226  if( evt->IsDrag( BUT_LEFT ) )
1227  {
1229  ClearSelection();
1230 
1231  // Start drawing a selection box
1232  area.SetOrigin( evt->DragOrigin() );
1233  area.SetEnd( evt->Position() );
1234  area.SetAdditive( m_drag_additive );
1236  area.SetExclusiveOr( false );
1237 
1238  view->SetVisible( &area, true );
1239  view->Update( &area );
1240  getViewControls()->SetAutoPan( true );
1241  }
1242 
1243  if( evt->IsMouseUp( BUT_LEFT ) )
1244  {
1245  getViewControls()->SetAutoPan( false );
1246 
1247  // End drawing the selection box
1248  view->SetVisible( &area, false );
1249 
1250  // Fetch items from the RTree that are in our area of interest
1251  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> nearbyViewItems;
1252  view->Query( area.ViewBBox(), nearbyViewItems );
1253 
1254  // Build lists of nearby items and their children
1255  std::vector<EDA_ITEM*> nearbyItems;
1256  std::vector<EDA_ITEM*> nearbyChildren;
1257 
1258  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems )
1259  {
1260  EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first );
1261 
1262  if( item )
1263  {
1265  nearbyItems.push_back( item );
1266  }
1267 
1268  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
1269  {
1270  sch_item->RunOnChildren(
1271  [&]( SCH_ITEM* aChild )
1272  {
1273  nearbyChildren.push_back( aChild );
1274  } );
1275  }
1276  }
1277 
1278  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
1279  selectionRect.Normalize();
1280 
1281  bool anyAdded = false;
1282  bool anySubtracted = false;
1283  auto selectItem =
1284  [&]( EDA_ITEM* aItem )
1285  {
1286  if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
1287  {
1288  unselect( aItem );
1289  anySubtracted = true;
1290  }
1291  else
1292  {
1293  select( aItem );
1294  aItem->SetFlags( STARTPOINT | ENDPOINT );
1295  anyAdded = true;
1296  }
1297  };
1298 
1299  for( EDA_ITEM* item : nearbyItems )
1300  {
1301  if( Selectable( item ) && item->HitTest( selectionRect, isWindowSelection ) )
1302  {
1303  item->SetFlags( TEMP_SELECTED );
1304  selectItem( item );
1305  }
1306  }
1307 
1308  for( EDA_ITEM* item : nearbyChildren )
1309  {
1310  if( Selectable( item )
1311  && !item->GetParent()->HasFlag( TEMP_SELECTED )
1312  && item->HitTest( selectionRect, isWindowSelection ) )
1313  {
1314  selectItem( item );
1315  }
1316  }
1317 
1318  m_selection.SetIsHover( false );
1319 
1320  // Inform other potentially interested tools
1321  if( anyAdded )
1323 
1324  if( anySubtracted )
1326 
1327  break; // Stop waiting for events
1328  }
1329 
1330  // Allow some actions for navigation
1331  for( int i = 0; allowedActions[i]; ++i )
1332  {
1333  if( evt->IsAction( allowedActions[i] ) )
1334  {
1335  evt->SetPassEvent();
1336  break;
1337  }
1338  }
1339  }
1340 
1341  getViewControls()->SetAutoPan( false );
1342 
1343  // Stop drawing the selection box
1344  view->Remove( &area );
1345  m_multiple = false; // Multiple selection mode is inactive
1346 
1347  if( !cancelled )
1349 
1350  return cancelled;
1351 }
1352 
1353 
1354 static KICAD_T nodeTypes[] =
1355 {
1357  SCH_PIN_T,
1362  SCH_LABEL_T,
1367  EOT
1368 };
1369 
1370 
1372 {
1373  EE_COLLECTOR collector;
1374 
1375  //TODO(snh): Reimplement after exposing KNN interface
1376  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1377  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
1378  int thresholdMax = std::max( pixelThreshold, gridThreshold );
1379 
1380  for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
1381  {
1382  collector.m_Threshold = threshold;
1383  collector.Collect( m_frame->GetScreen(), nodeTypes, (wxPoint) aPosition );
1384 
1385  if( collector.GetCount() > 0 )
1386  break;
1387  }
1388 
1389  return collector.GetCount() ? collector[ 0 ] : nullptr;
1390 }
1391 
1392 
1394 {
1395  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
1396 
1397  SelectPoint( cursorPos, nodeTypes );
1398 
1399  return 0;
1400 }
1401 
1402 
1404 {
1405  static KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
1406 
1407  RequestSelection( wiresAndBuses );
1408 
1409  if( m_selection.Empty() )
1410  return 0;
1411 
1412  SCH_LINE* line = (SCH_LINE*) m_selection.Front();
1413  EDA_ITEMS items;
1414 
1416  std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line );
1417 
1418  for( SCH_ITEM* item : conns )
1419  select( item );
1420 
1421  if( m_selection.GetSize() > 1 )
1423 
1424  return 0;
1425 }
1426 
1427 
1429 {
1430  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
1431  m_selection.SetIsHover( false );
1432  return 0;
1433 }
1434 
1435 
1436 void EE_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
1437 {
1438  if( aItem )
1439  {
1440  select( aItem );
1441 
1442  // Inform other potentially interested tools
1443  if( !aQuietMode )
1445  }
1446 }
1447 
1448 
1450 {
1451  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1452  m_selection.SetIsHover( false );
1453  return 0;
1454 }
1455 
1456 
1457 void EE_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
1458 {
1459  if( aList )
1460  {
1461  for( EDA_ITEM* item : *aList )
1462  select( item );
1463 
1464  // Inform other potentially interested tools
1465  if( !aQuietMode )
1467  }
1468 }
1469 
1470 
1472 {
1473  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
1474  m_selection.SetIsHover( false );
1475  return 0;
1476 }
1477 
1478 
1479 void EE_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
1480 {
1481  if( aItem )
1482  {
1483  unselect( aItem );
1484 
1485  // Inform other potentially interested tools
1486  if( !aQuietMode )
1488  }
1489 }
1490 
1491 
1493 {
1494  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1495  m_selection.SetIsHover( false );
1496  return 0;
1497 }
1498 
1499 
1500 void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
1501 {
1502  if( aList )
1503  {
1504  for( EDA_ITEM* item : *aList )
1505  unselect( item );
1506 
1507  // Inform other potentially interested tools
1508  if( !aQuietMode )
1510  }
1511 }
1512 
1513 
1514 void EE_SELECTION_TOOL::RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode )
1515 {
1516  EDA_ITEMS removeItems;
1517 
1518  for( EDA_ITEM* item : m_selection )
1519  {
1520  if( alg::contains( *aList, item->m_Uuid ) )
1521  removeItems.push_back( item );
1522  }
1523 
1524  RemoveItemsFromSel( &removeItems, aQuietMode );
1525 }
1526 
1527 
1529 {
1530  highlight( aItem, BRIGHTENED );
1531 }
1532 
1533 
1535 {
1536  unhighlight( aItem, BRIGHTENED );
1537 }
1538 
1539 
1541 {
1542  ClearSelection();
1543 
1544  return 0;
1545 }
1546 
1547 
1549 {
1550  m_selection.Clear();
1551 
1552  if( m_isSymbolEditor )
1553  {
1554  LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
1555 
1556  for( LIB_ITEM& item : start->GetDrawItems() )
1557  {
1558  if( item.IsSelected() )
1559  select( static_cast<EDA_ITEM*>( &item ) );
1560  }
1561  }
1562  else
1563  {
1564  for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
1565  {
1566  // If the field and symbol are selected, only use the symbol
1567  if( item->IsSelected() )
1568  {
1569  select( item );
1570  }
1571  else
1572  {
1573  item->RunOnChildren(
1574  [&]( SCH_ITEM* aChild )
1575  {
1576  if( aChild->IsSelected() )
1577  select( aChild );
1578  } );
1579  }
1580  }
1581  }
1582 
1584 
1585  // Inform other potentially interested tools
1587 }
1588 
1589 
1591 {
1592  EE_COLLECTOR* collector = aEvent.Parameter<EE_COLLECTOR*>();
1593 
1594  if( !doSelectionMenu( collector ) )
1595  collector->m_MenuCancelled = true;
1596 
1597  return 0;
1598 }
1599 
1600 
1602 {
1603  EDA_ITEM* current = nullptr;
1604  bool selectAll = false;
1605  bool expandSelection = false;
1606 
1607  do
1608  {
1610  if( expandSelection )
1611  aCollector->Combine();
1612 
1613  expandSelection = false;
1614 
1615  int limit = std::min( 9, aCollector->GetCount() );
1616  ACTION_MENU menu( true );
1617 
1618  for( int i = 0; i < limit; ++i )
1619  {
1620  wxString text;
1621  EDA_ITEM* item = ( *aCollector )[i];
1623 
1624  wxString menuText = wxString::Format( wxT( "&%d. %s\t%d" ), i + 1, text, i + 1 );
1625  menu.Add( menuText, i + 1, item->GetMenuImage() );
1626  }
1627 
1628  menu.AppendSeparator();
1629  menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
1630 
1631  if( !expandSelection && aCollector->HasAdditionalItems() )
1632  menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
1633 
1634  if( aCollector->m_MenuTitle.Length() )
1635  {
1636  menu.SetTitle( aCollector->m_MenuTitle );
1637  menu.SetIcon( BITMAPS::info );
1638  menu.DisplayTitle( true );
1639  }
1640  else
1641  {
1642  menu.DisplayTitle( false );
1643  }
1644 
1645  SetContextMenu( &menu, CMENU_NOW );
1646 
1647  while( TOOL_EVENT* evt = Wait() )
1648  {
1649  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1650  {
1651  if( selectAll )
1652  {
1653  for( int i = 0; i < aCollector->GetCount(); ++i )
1654  unhighlight( ( *aCollector )[i], BRIGHTENED );
1655  }
1656  else if( current )
1657  {
1658  unhighlight( current, BRIGHTENED );
1659  }
1660 
1661  int id = *evt->GetCommandId();
1662 
1663  // User has pointed an item, so show it in a different way
1664  if( id > 0 && id <= limit )
1665  {
1666  current = ( *aCollector )[id - 1];
1667  highlight( current, BRIGHTENED );
1668  }
1669  else
1670  {
1671  current = nullptr;
1672  }
1673 
1674  // User has pointed on the "Select All" option
1675  if( id == limit + 1 )
1676  {
1677  for( int i = 0; i < aCollector->GetCount(); ++i )
1678  highlight( ( *aCollector )[i], BRIGHTENED );
1679  selectAll = true;
1680  }
1681  else
1682  {
1683  selectAll = false;
1684  }
1685  }
1686  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1687  {
1688  if( selectAll )
1689  {
1690  for( int i = 0; i < aCollector->GetCount(); ++i )
1691  unhighlight( ( *aCollector )[i], BRIGHTENED );
1692  }
1693  else if( current )
1694  unhighlight( current, BRIGHTENED );
1695 
1696  OPT<int> id = evt->GetCommandId();
1697 
1698  // User has selected the "Select All" option
1699  if( id == limit + 1 )
1700  {
1701  selectAll = true;
1702  current = nullptr;
1703  }
1704  else if( id == limit + 2 )
1705  {
1706  selectAll = false;
1707  current = nullptr;
1708  expandSelection = true;
1709  }
1710  // User has selected an item, so this one will be returned
1711  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1712  {
1713  selectAll = false;
1714  current = ( *aCollector )[*id - 1];
1715  }
1716  // User has cancelled the menu (either by <esc> or clicking out of it)
1717  else
1718  {
1719  selectAll = false;
1720  current = nullptr;
1721  }
1722  }
1723  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1724  {
1725  break;
1726  }
1727 
1728  getView()->UpdateItems();
1729  m_frame->GetCanvas()->Refresh();
1730  }
1731  } while( expandSelection );
1732 
1733  if( selectAll )
1734  return true;
1735  else if( current )
1736  {
1737  unhighlight( current, BRIGHTENED );
1738 
1739  getView()->UpdateItems();
1740  m_frame->GetCanvas()->Refresh();
1741 
1742  aCollector->Empty();
1743  aCollector->Append( current );
1744  return true;
1745  }
1746 
1747  return false;
1748 }
1749 
1750 
1751 bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
1752  bool checkVisibilityOnly ) const
1753 {
1754  // NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
1755 
1756  SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
1757 
1758  // Do not allow selection of anything except fields when the current symbol in the symbol
1759  // editor is a derived symbol.
1760  if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != LIB_FIELD_T )
1761  return false;
1762 
1763  switch( aItem->Type() )
1764  {
1765  case SCH_PIN_T:
1766  {
1767  const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
1768 
1769  if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
1770  return false;
1771 
1773  {
1774  // Pin anchors have to be allowed for auto-starting wires.
1775  if( aPos )
1776  {
1778  VECTOR2I cursorPos = grid.BestSnapAnchor( *aPos, LAYER_CONNECTABLE, nullptr );
1779 
1780  if( pin->IsPointClickableAnchor( (wxPoint) cursorPos ) )
1781  return true;
1782  }
1783 
1784  return false;
1785  }
1786  }
1787  break;
1788 
1789  case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
1790  return false;
1791 
1792  case LIB_FIELD_T: // LIB_FIELD object can always be edited.
1793  break;
1794 
1795  case LIB_SHAPE_T:
1796  case LIB_TEXT_T:
1797  case LIB_PIN_T:
1798  if( symEditFrame )
1799  {
1800  LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
1801 
1802  if( lib_item->GetUnit() && lib_item->GetUnit() != symEditFrame->GetUnit() )
1803  return false;
1804 
1805  if( lib_item->GetConvert() && lib_item->GetConvert() != symEditFrame->GetConvert() )
1806  return false;
1807  }
1808 
1809  break;
1810 
1811  case SCH_MARKER_T: // Always selectable
1812  return true;
1813 
1814  default: // Suppress warnings
1815  break;
1816  }
1817 
1818  return true;
1819 }
1820 
1821 
1823 {
1824  if( m_selection.Empty() )
1825  return;
1826 
1827  while( m_selection.GetSize() )
1829 
1830  getView()->Update( &m_selection );
1831 
1832  m_selection.SetIsHover( false );
1834 
1835  // Inform other potentially interested tools
1837 }
1838 
1839 
1841 {
1842  highlight( aItem, SELECTED, &m_selection );
1843 }
1844 
1845 
1847 {
1848  unhighlight( aItem, SELECTED, &m_selection );
1849 }
1850 
1851 
1852 void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1853 {
1854  KICAD_T itemType = aItem->Type();
1855 
1856  if( aMode == SELECTED )
1857  aItem->SetSelected();
1858  else if( aMode == BRIGHTENED )
1859  aItem->SetBrightened();
1860 
1861  if( aGroup )
1862  aGroup->Add( aItem );
1863 
1864  // Highlight pins and fields. (All the other symbol children are currently only
1865  // represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
1866  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1867  {
1868  sch_item->RunOnChildren(
1869  [&]( SCH_ITEM* aChild )
1870  {
1871  if( aMode == SELECTED )
1872  aChild->SetSelected();
1873  else if( aMode == BRIGHTENED )
1874  aChild->SetBrightened();
1875  } );
1876  }
1877 
1878  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1879  getView()->Update( aItem->GetParent() );
1880  else
1881  getView()->Update( aItem );
1882 }
1883 
1884 
1885 void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1886 {
1887  KICAD_T itemType = aItem->Type();
1888 
1889  if( aMode == SELECTED )
1890  aItem->ClearSelected();
1891  else if( aMode == BRIGHTENED )
1892  aItem->ClearBrightened();
1893 
1894  if( aGroup )
1895  aGroup->Remove( aItem );
1896 
1897  // Unhighlight pins and fields. (All the other symbol children are currently only
1898  // represented in the LIB_SYMBOL.)
1899  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1900  {
1901  sch_item->RunOnChildren(
1902  [&]( SCH_ITEM* aChild )
1903  {
1904  if( aMode == SELECTED )
1905  aChild->ClearSelected();
1906  else if( aMode == BRIGHTENED )
1907  aChild->ClearBrightened();
1908  } );
1909  }
1910 
1911  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1912  getView()->Update( aItem->GetParent() );
1913  else
1914  getView()->Update( aItem );
1915 }
1916 
1917 
1919 {
1920  const unsigned GRIP_MARGIN = 20;
1921  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1922 
1923  // Check if the point is located within any of the currently selected items bounding boxes
1924  for( EDA_ITEM* item : m_selection )
1925  {
1926  BOX2I itemBox = item->ViewBBox();
1927  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1928 
1929  if( itemBox.Contains( aPoint ) )
1930  return true;
1931  }
1932 
1933  return false;
1934 }
1935 
1936 
1938 {
1940 
1945 
1951 
1953 
1955 }
1956 
1957 
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:155
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:197
static TOOL_ACTION pinTable
Definition: ee_actions.h:146
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:121
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:135
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
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:88
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:84
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:118
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:82
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:189
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:134
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:165
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:186
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:192
int GetUnit() const
Definition: lib_item.h:266
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:80
#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:200
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:111
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:145
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:269
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:119
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:81
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:183
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:86
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:152
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:185
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:92
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:101
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:113
bool IsBus() const
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:87
static TOOL_ACTION finishBus
Definition: ee_actions.h:96
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:95
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