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>
28 #include <ee_actions.h>
29 #include <ee_collectors.h>
30 #include <ee_selection_tool.h>
31 #include <eeschema_id.h> // For MAX_SELECT_ITEM_IDS
32 #include <symbol_edit_frame.h>
33 #include <lib_item.h>
34 #include <symbol_viewer_frame.h>
35 #include <math/util.h>
36 #include <geometry/shape_rect.h>
37 #include <menus_helpers.h>
38 #include <painter.h>
40 #include <sch_base_frame.h>
41 #include <sch_symbol.h>
42 #include <sch_field.h>
43 #include <sch_edit_frame.h>
44 #include <sch_item.h>
45 #include <sch_line.h>
46 #include <sch_junction.h>
47 #include <sch_sheet.h>
48 #include <sch_sheet_pin.h>
49 #include <schematic.h>
50 #include <tool/tool_event.h>
51 #include <tool/tool_manager.h>
52 #include <tools/ee_grid_helper.h>
53 #include <tools/ee_point_editor.h>
55 #include <trigo.h>
56 #include <view/view.h>
57 #include <view/view_controls.h>
58 
60 {
61  if( aSel.GetSize() == 1 )
62  {
63  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
64 
65  if( symbol )
66  return !symbol->GetLibSymbolRef() || !symbol->GetLibSymbolRef()->IsPower();
67  }
68 
69  return false;
70 };
71 
72 
74 {
75  return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_SYMBOL_T;
76 };
77 
78 
80 {
81  if( aSel.GetSize() == 1 )
82  {
83  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
84 
85  if( symbol )
86  return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->HasConversion();
87  }
88 
89  return false;
90 };
91 
92 
94 {
95  if( aSel.GetSize() == 1 )
96  {
97  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
98 
99  if( symbol )
100  return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->GetUnitCount() >= 2;
101  }
102 
103  return false;
104 };
105 
106 
107 #define HITTEST_THRESHOLD_PIXELS 5
108 
109 
111  TOOL_INTERACTIVE( "eeschema.InteractiveSelection" ),
112  m_frame( nullptr ),
113  m_nonModifiedCursor( KICURSOR::ARROW ),
114  m_isSymbolEditor( false ),
115  m_isSymbolViewer( false ),
116  m_unit( 0 ),
117  m_convert( 0 )
118 {
119  m_selection.Clear();
120 }
121 
122 
124 {
125  getView()->Remove( &m_selection );
126 }
127 
128 
130 
131 
133 {
134  m_frame = getEditFrame<SCH_BASE_FRAME>();
135 
136  SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
137  SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
138 
139  if( symbolEditorFrame )
140  {
141  m_isSymbolEditor = true;
142  m_unit = symbolEditorFrame->GetUnit();
143  m_convert = symbolEditorFrame->GetConvert();
144  }
145  else
146  {
147  m_isSymbolViewer = symbolViewerFrame != nullptr;
148  }
149 
150  static KICAD_T wireOrBusTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
151  static KICAD_T connectedTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T,
154 
155  auto wireSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T );
156  auto busSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T );
157  auto wireOrBusSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( wireOrBusTypes );
158  auto connectedSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( connectedTypes );
159  auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
160 
161  auto schEditSheetPageNumberCondition =
162  [&] ( const SELECTION& aSel )
163  {
165  return false;
166 
167  return E_C::LessThan( 2 )( aSel ) && E_C::OnlyType( SCH_SHEET_T )( aSel );
168  };
169 
170  auto schEditCondition =
171  [this] ( const SELECTION& aSel )
172  {
174  };
175 
176  auto belowRootSheetCondition =
177  [&]( const SELECTION& aSel )
178  {
179  SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
180 
181  return editFrame
182  && editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
183  };
184 
185  auto haveSymbolCondition =
186  [&]( const SELECTION& sel )
187  {
188  return m_isSymbolEditor &&
189  static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
190  };
191 
192  auto& menu = m_menu.GetMenu();
193 
194  menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 1 );
195  menu.AddItem( EE_ACTIONS::explicitCrossProbe, sheetSelection && EE_CONDITIONS::Idle, 1 );
196  menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 1 );
197 
198  menu.AddSeparator( 100 );
199  menu.AddItem( EE_ACTIONS::drawWire, schEditCondition && EE_CONDITIONS::Empty, 100 );
200  menu.AddItem( EE_ACTIONS::drawBus, schEditCondition && EE_CONDITIONS::Empty, 100 );
201 
202  menu.AddSeparator( 100 );
204 
205  menu.AddSeparator( 100 );
207 
208  menu.AddSeparator( 200 );
209  menu.AddItem( EE_ACTIONS::selectConnection, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
210  menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
211  menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
212  menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
213  menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
214  menu.AddItem( EE_ACTIONS::breakWire, wireSelection && EE_CONDITIONS::Idle, 250 );
215  menu.AddItem( EE_ACTIONS::breakBus, busSelection && EE_CONDITIONS::Idle, 250 );
216  menu.AddItem( EE_ACTIONS::importSingleSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
217  menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
218  menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
219 
220  menu.AddSeparator( 400 );
221  menu.AddItem( EE_ACTIONS::symbolProperties,
222  haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
223  menu.AddItem( EE_ACTIONS::pinTable,
224  haveSymbolCondition && EE_CONDITIONS::Empty, 400 );
225 
226  menu.AddSeparator( 1000 );
228 
229  m_disambiguateTimer.SetOwner( this );
230  Connect( wxEVT_TIMER, wxTimerEventHandler( EE_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
231 
232  return true;
233 }
234 
235 
237 {
238  m_frame = getEditFrame<SCH_BASE_FRAME>();
239 
240  if( aReason == TOOL_BASE::MODEL_RELOAD )
241  {
242  // Remove pointers to the selected items from containers without changing their
243  // properties (as they are already deleted while a new sheet is loaded)
244  m_selection.Clear();
245  getView()->GetPainter()->GetSettings()->SetHighlight( false );
246 
247  SYMBOL_EDIT_FRAME* symbolEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
248  SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
249 
250  if( symbolEditFrame )
251  {
252  m_isSymbolEditor = true;
253  m_unit = symbolEditFrame->GetUnit();
254  m_convert = symbolEditFrame->GetConvert();
255  }
256  else
257  m_isSymbolViewer = symbolViewerFrame != nullptr;
258  }
259  else
260  // Restore previous properties of selected items and remove them from containers
261  ClearSelection();
262 
263  // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
264  getView()->Remove( &m_selection );
265  getView()->Add( &m_selection );
266 }
267 
268 
270 {
271  ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
272  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
273 
274  if( conditionalMenu )
275  conditionalMenu->Evaluate( m_selection );
276 
277  if( actionMenu )
278  actionMenu->UpdateAll();
279 
280  return 0;
281 }
282 
283 
285 {
286  SCH_MARKER_T,
291  SCH_LINE_T,
292  SCH_BITMAP_T,
293  SCH_TEXT_T,
294  SCH_LABEL_T,
297  SCH_FIELD_T,
298  SCH_SYMBOL_T,
300  SCH_SHEET_T,
301  EOT
302 };
303 
304 
306 {
307  LIB_SHAPE_T,
308  LIB_TEXT_T,
309  LIB_PIN_T,
310  LIB_FIELD_T,
311  EOT
312 };
313 
314 
316 {
317  LIB_FIELD_T,
318  EOT
319 };
320 
321 
323 {
325 
326  KIID lastRolloverItem = niluuid;
327 
328  // Main loop: keep receiving events
329  while( TOOL_EVENT* evt = Wait() )
330  {
331  bool displayWireCursor = false;
332  bool displayBusCursor = false;
333  bool displayLineCursor = false;
334  KIID rolloverItem = lastRolloverItem;
335 
336  // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
337  setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
338  evt->Modifier( MD_ALT ) );
339 
340  bool modifier_enabled = m_subtractive || m_additive || m_exclusive_or;
341 
342  MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
344 
345  if( evt->IsMouseDown( BUT_LEFT ) )
346  {
347  // Avoid triggering when running under other tools
349 
350  if( m_frame->ToolStackIsEmpty() && pt_tool && !pt_tool->HasPoint() )
351  {
353  m_disambiguateTimer.StartOnce( 500 );
354  }
355  }
356  // Single click? Select single object
357  else if( evt->IsClick( BUT_LEFT ) )
358  {
359  // If the timer has stopped, then we have already run the disambiguate routine
360  // and we don't want to register an extra click here
361  if( !m_disambiguateTimer.IsRunning() )
362  {
363  evt->SetPassEvent();
364  continue;
365  }
366 
367  m_disambiguateTimer.Stop();
368 
369 
370  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
371  schframe->FocusOnItem( nullptr );
372 
373  EE_COLLECTOR collector;
374  bool continueSelect = true;
375 
376  // Collect items at the clicked location (doesn't select them yet)
377  if( CollectHits( collector, evt->Position()) )
378  {
379  narrowSelection( collector, evt->Position(), false, false );
380 
381  if( collector.GetCount() == 1 && !m_isSymbolEditor && !modifier_enabled )
382  {
383  // Check if we want to auto start wires
384  VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
385  LAYER_CONNECTABLE, nullptr );
386 
388 
390  && pt_tool && !pt_tool->HasPoint()
391  && collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
392  {
393  OPT_TOOL_EVENT newEvt;
394  SCH_CONNECTION* connection = collector[0]->Connection();
395 
396  if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
397  || collector[0]->Type() == SCH_SYMBOL_T )
398  {
399  newEvt = EE_ACTIONS::drawWire.MakeEvent();
400  }
401  else if( connection && connection->IsBus() )
402  {
403  newEvt = EE_ACTIONS::drawBus.MakeEvent();
404  }
405  else if( collector[0]->Type() == SCH_LINE_T
406  && static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
407  {
408  newEvt = EE_ACTIONS::drawLines.MakeEvent();
409  }
410 
411  auto* params = newEvt->Parameter<DRAW_SEGMENT_EVENT_PARAMS*>();
412  auto* newParams = new DRAW_SEGMENT_EVENT_PARAMS();
413 
414  *newParams= *params;
415  newParams->quitOnDraw = true;
416  newEvt->SetParameter( newParams );
417 
418  getViewControls()->ForceCursorPosition( true, snappedCursorPos );
419  newEvt->SetMousePosition( snappedCursorPos );
420  newEvt->SetHasPosition( true );
421  newEvt->SetForceImmediate( true );
422  m_toolMgr->ProcessEvent( *newEvt );
423 
424  continueSelect = false;
425  }
426  else if( collector[0]->IsHypertext() )
427  {
428  collector[0]->DoHypertextMenu( m_frame );
429  continueSelect = false;
430  }
431  }
432  }
433 
434  if( continueSelect )
435  {
436  // If we didn't click on an anchor, we perform a normal select, pass in the
437  // items we previously collected
438  selectPoint( collector, nullptr, nullptr, m_additive, m_subtractive,
439  m_exclusive_or );
440  }
441  }
442  else if( evt->IsClick( BUT_RIGHT ) )
443  {
444  m_disambiguateTimer.Stop();
445 
446  // right click? if there is any object - show the context menu
447  bool selectionCancelled = false;
448 
449  if( m_selection.Empty() )
450  {
451  ClearSelection();
452  SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
453  &selectionCancelled );
454  m_selection.SetIsHover( true );
455  }
456  // If the cursor has moved off the bounding box of the selection by more than
457  // a grid square, check to see if there is another item available for selection
458  // under the cursor. If there is, the user likely meant to get the context menu
459  // for that item. If there is no new item, then keep the original selection and
460  // show the context menu for it.
461  else if( !m_selection.GetBoundingBox().Inflate(
462  grid.GetGrid().x, grid.GetGrid().y ).Contains(
463  (wxPoint) evt->Position() ) )
464  {
465  EE_SELECTION saved_selection = m_selection;
466 
467  for( const auto& item : saved_selection )
468  RemoveItemFromSel( item, true );
469 
470  SelectPoint( evt->Position(), EE_COLLECTOR::AllItems, nullptr,
471  &selectionCancelled );
472 
473  if( m_selection.Empty() )
474  {
475  m_selection.SetIsHover( false );
476 
477  for( const auto& item : saved_selection )
478  AddItemToSel( item, true);
479  }
480  else
481  {
482  m_selection.SetIsHover( true );
483  }
484  }
485 
486  if( !selectionCancelled )
488  }
489  else if( evt->IsDblClick( BUT_LEFT ) )
490  {
491  m_disambiguateTimer.Stop();
492 
493  // double click? Display the properties window
494  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
495  schframe->FocusOnItem( nullptr );
496 
497  if( m_selection.Empty() )
498  SelectPoint( evt->Position() );
499 
500  EDA_ITEM* item = m_selection.Front();
501 
502  if( item && item->Type() == SCH_SHEET_T )
504  else
506  }
507  else if( evt->IsDblClick( BUT_MIDDLE ) )
508  {
509  m_disambiguateTimer.Stop();
510 
511  // Middle double click? Do zoom to fit or zoom to objects
512  if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
514  else
516  }
517  else if( evt->IsDrag( BUT_LEFT ) )
518  {
519  m_disambiguateTimer.Stop();
520 
521  // Is another tool already moving a new object? Don't allow a drag start
522  if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
523  {
524  evt->SetPassEvent();
525  continue;
526  }
527 
528  // drag with LMB? Select multiple objects (or at least draw a selection box) or
529  // drag them
530  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
531  schframe->FocusOnItem( nullptr );
532 
533  if( modifier_enabled || drag_action == MOUSE_DRAG_ACTION::SELECT )
534  {
535  selectMultiple();
536  }
537  else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
538  {
539  selectMultiple();
540  }
541  else
542  {
543  if( m_isSymbolEditor )
544  {
545  if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
547  else
549  }
550  else
551  {
553  }
554 
555  // Check if dragging has started within any of selected items bounding box
556  if( selectionContains( evt->Position() ) )
557  {
558  // Yes -> run the move tool and wait till it finishes
559  if( m_isSymbolEditor )
560  m_toolMgr->InvokeTool( "eeschema.SymbolMoveTool" );
561  else
562  m_toolMgr->InvokeTool( "eeschema.InteractiveMove" );
563  }
564  else
565  {
566  // No -> drag a selection box
567  selectMultiple();
568  }
569  }
570  }
571  else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
572  {
573  m_disambiguateTimer.Stop();
574 
575  // context sub-menu selection? Handle unit selection or bus unfolding
576  if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
577  && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_SYM_MAX )
578  {
579  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
580  int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
581 
582  if( symbol )
583  static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( symbol, unit );
584  }
585  else if( evt->GetCommandId().get() >= ID_POPUP_SCH_UNFOLD_BUS
586  && evt->GetCommandId().get() <= ID_POPUP_SCH_UNFOLD_BUS_END )
587  {
588  wxString* net = new wxString( *evt->Parameter<wxString*>() );
590  }
591 
592  }
593  else if( evt->IsCancelInteractive() )
594  {
595  m_disambiguateTimer.Stop();
596 
597  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
598  schframe->FocusOnItem( nullptr );
599 
600  ClearSelection();
601  }
602  else if( evt->Action() == TA_UNDO_REDO_PRE )
603  {
604  if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
605  schframe->FocusOnItem( nullptr );
606 
607  ClearSelection();
608  }
609  else if( evt->IsMotion() && !m_isSymbolEditor && m_frame->ToolStackIsEmpty() )
610  {
611  rolloverItem = niluuid;
612  EE_COLLECTOR collector;
613 
614  // We are checking if we should display a pencil when hovering over anchors
615  // for "auto starting" wires when clicked
617 
618  if( CollectHits( collector, evt->Position() ) )
619  {
620  narrowSelection( collector, evt->Position(), false, false );
621 
622  if( collector.GetCount() == 1 && !modifier_enabled )
623  {
624  VECTOR2I snappedCursorPos = grid.BestSnapAnchor( evt->Position(),
625  LAYER_CONNECTABLE, nullptr );
626 
628 
630  && pt_tool && !pt_tool->HasPoint()
631  && collector[0]->IsPointClickableAnchor( (wxPoint) snappedCursorPos ) )
632  {
633  SCH_CONNECTION* connection = collector[0]->Connection();
634 
635  if( ( connection && ( connection->IsNet() || connection->IsUnconnected() ) )
636  || collector[0]->Type() == SCH_SYMBOL_T )
637  {
638  displayWireCursor = true;
639  }
640  else if( connection && connection->IsBus() )
641  {
642  displayBusCursor = true;
643  }
644  else if( collector[0]->Type() == SCH_LINE_T
645  && static_cast<SCH_LINE*>( collector[0] )->IsGraphicLine() )
646  {
647  displayLineCursor = true;
648  }
649 
650  getViewControls()->ForceCursorPosition( true, snappedCursorPos );
651  }
652  else if( collector[0]->IsHypertext()
653  && !collector[0]->IsSelected()
655  {
656  rolloverItem = collector[0]->m_Uuid;
657  }
658  }
659  }
660  }
661  else
662  {
663  evt->SetPassEvent();
664  }
665 
666  if( rolloverItem != lastRolloverItem )
667  {
668  EDA_ITEM* item = m_frame->GetItem( lastRolloverItem );
669 
670  if( item )
671  {
672  item->ClearFlags( IS_ROLLOVER );
673  lastRolloverItem = niluuid;
674 
675  if( item->Type() == SCH_FIELD_T )
676  m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
677  else
678  m_frame->GetCanvas()->GetView()->Update( item );
679  }
680 
681  item = m_frame->GetItem( rolloverItem );
682 
683  if( item )
684  {
685  item->SetFlags( IS_ROLLOVER );
686  lastRolloverItem = rolloverItem;
687 
688  if( item->Type() == SCH_FIELD_T )
689  m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
690  else
691  m_frame->GetCanvas()->GetView()->Update( item );
692  }
693  }
694 
695  if( m_frame->ToolStackIsEmpty() )
696  {
697  if( displayWireCursor )
698  {
700  }
701  else if( displayBusCursor )
702  {
704  }
705  else if( displayLineCursor )
706  {
708  }
709  else if( rolloverItem != niluuid )
710  {
712  }
713  else if( !m_selection.Empty()
714  && drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
715  && evt->HasPosition()
716  && selectionContains( evt->Position() ) ) //move/drag option prediction
717  {
719  }
720  else
721  {
723  }
724  }
725  }
726 
727  m_disambiguateTimer.Stop();
728 
729  // Shutting down; clear the selection
730  m_selection.Clear();
731 
732  return 0;
733 }
734 
735 
737 {
738  m_skip_heuristics = true;
741  m_skip_heuristics = false;
742 
743  return 0;
744 }
745 
746 
747 void EE_SELECTION_TOOL::onDisambiguationExpire( wxTimerEvent& aEvent )
748 {
750 }
751 
752 
753 void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
754 {
755  if( m_frame->ToolStackIsEmpty() && !m_multiple )
756  {
757  wxMouseState keyboardState = wxGetMouseState();
758 
759  setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
760  keyboardState.AltDown() );
761 
762  if( m_additive )
764  else if( m_subtractive )
766  else if( m_exclusive_or )
768  else
770  }
771 }
772 
773 
775 {
776  return m_selection;
777 }
778 
779 
780 bool EE_SELECTION_TOOL::CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
781  const KICAD_T* aFilterList )
782 {
783  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
784  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
785  aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
786 
787  if( m_isSymbolEditor )
788  {
789  LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
790 
791  if( !symbol )
792  return false;
793 
794  aCollector.Collect( symbol->GetDrawItems(), aFilterList, (wxPoint) aWhere, m_unit,
795  m_convert );
796  }
797  else
798  {
799  aCollector.Collect( m_frame->GetScreen(), aFilterList, (wxPoint) aWhere, m_unit,
800  m_convert );
801  }
802 
803  return aCollector.GetCount() > 0;
804 }
805 
806 
808  bool aCheckLocked, bool aSelectPoints )
809 {
810  for( int i = collector.GetCount() - 1; i >= 0; --i )
811  {
812  if( !Selectable( collector[i], &aWhere ) )
813  {
814  collector.Remove( i );
815  continue;
816  }
817 
818  if( aCheckLocked && collector[i]->IsLocked() )
819  {
820  collector.Remove( i );
821  continue;
822  }
823 
824  // SelectPoint, unlike other selection routines, can select line ends
825  if( aSelectPoints && collector[i]->Type() == SCH_LINE_T )
826  {
827  SCH_LINE* line = (SCH_LINE*) collector[i];
828  line->ClearFlags( STARTPOINT | ENDPOINT );
829 
830  if( HitTestPoints( line->GetStartPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
831  line->SetFlags( STARTPOINT );
832  else if( HitTestPoints( line->GetEndPoint(), (wxPoint) aWhere, collector.m_Threshold ) )
833  line->SetFlags( ENDPOINT );
834  else
835  line->SetFlags( STARTPOINT | ENDPOINT );
836  }
837  }
838 
839  // Apply some ugly heuristics to avoid disambiguation menus whenever possible
840  if( collector.GetCount() > 1 && !m_skip_heuristics )
841  {
842  GuessSelectionCandidates( collector, aWhere );
843  }
844 }
845 
846 
848  bool* aSelectionCancelledFlag, bool aAdd, bool aSubtract,
849  bool aExclusiveOr )
850 {
852 
853  // If still more than one item we're going to have to ask the user.
854  if( aCollector.GetCount() > 1 )
855  {
856  // Try to call selectionMenu via RunAction() to avoid event-loop contention
857  // But it we cannot handle the event, then we don't have an active tool loop, so
858  // handle it directly.
859  if( !m_toolMgr->RunAction( EE_ACTIONS::selectionMenu, true, &aCollector ) )
860  {
861  if( !doSelectionMenu( &aCollector ) )
862  aCollector.m_MenuCancelled = true;
863  }
864 
865  if( aCollector.m_MenuCancelled )
866  {
867  if( aSelectionCancelledFlag )
868  *aSelectionCancelledFlag = true;
869 
870  return false;
871  }
872  }
873 
874  if( !aAdd && !aSubtract && !aExclusiveOr )
875  ClearSelection();
876 
877  bool anyAdded = false;
878  bool anySubtracted = false;
879 
880  if( aCollector.GetCount() > 0 )
881  {
882  for( int i = 0; i < aCollector.GetCount(); ++i )
883  {
884  if( aSubtract || ( aExclusiveOr && aCollector[i]->IsSelected() ) )
885  {
886  unselect( aCollector[i] );
887  anySubtracted = true;
888  }
889  else
890  {
891  select( aCollector[i] );
892  anyAdded = true;
893  }
894  }
895  }
896 
897  if( anyAdded )
898  {
900 
901  if( aItem && aCollector.GetCount() == 1 )
902  *aItem = aCollector[0];
903 
904  return true;
905  }
906  else if( anySubtracted )
907  {
909  return true;
910  }
911 
912  return false;
913 }
914 
915 
916 bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList,
917  EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
918  bool aCheckLocked, bool aAdd, bool aSubtract,
919  bool aExclusiveOr )
920 {
921  EE_COLLECTOR collector;
922 
923  if( !CollectHits( collector, aWhere, aFilterList ) )
924  return false;
925 
926  narrowSelection( collector, aWhere, aCheckLocked, true );
927 
928  return selectPoint( collector, aItem, aSelectionCancelledFlag, aAdd, aSubtract, aExclusiveOr );
929 }
930 
931 
933 {
934  m_multiple = true; // Multiple selection mode is active
935  KIGFX::VIEW* view = getView();
936 
937  // hold all visible items
938  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
939  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
940 
941  // Filter the view items based on the selection box
942  BOX2I selectionBox;
943 
944  selectionBox.SetMaximum();
945  view->Query( selectionBox, selectedItems ); // Get the list of selected items
946 
947  // Sheet pins aren't in the view; add them by hand
948  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
949  {
950  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
951 
952  if( sheet )
953  {
954  int layer = pair.second;
955 
956  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
957  sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
958  }
959  }
960 
961  selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
962 
963  for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
964  {
965  if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
966  {
967  if( Selectable( item ) )
968  select( item );
969  }
970  }
971 
972  m_multiple = false;
973 
974  return 0;
975 }
976 
977 
979 {
980  // Prefer exact hits to sloppy ones
981  std::set<EDA_ITEM*> exactHits;
982 
983  for( int i = collector.GetCount() - 1; i >= 0; --i )
984  {
985  EDA_ITEM* item = collector[ i ];
986  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
987 
988  // Lines are hard to hit. Give them a bit more slop to still be considered "exact".
989 
990  if( line )
991  {
992  if( line->HitTest( (wxPoint) aPos, Mils2iu( DANGLING_SYMBOL_SIZE ) ) )
993  exactHits.insert( line );
994  }
995  else
996  {
997  if( item->HitTest( (wxPoint) aPos, 0 ) )
998  exactHits.insert( item );
999  }
1000  }
1001 
1002  if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
1003  {
1004  for( int i = collector.GetCount() - 1; i >= 0; --i )
1005  {
1006  EDA_ITEM* item = collector[ i ];
1007 
1008  if( !exactHits.count( item ) )
1009  collector.Transfer( item );
1010  }
1011  }
1012 
1013  // Find the closest item. (Note that at this point all hits are either exact or non-exact.)
1014  EDA_ITEM* closest = nullptr;
1015  int closestDist = INT_MAX;
1016 
1017  for( EDA_ITEM* item : collector )
1018  {
1019  EDA_RECT bbox = item->GetBoundingBox();
1020  int dist;
1021 
1022  if( exactHits.count( item ) )
1023  {
1024  if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
1025  {
1026  closest = item;
1027  break;
1028  }
1029 
1030  wxPoint pos( aPos );
1031  SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1032 
1033  if( line )
1034  dist = DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos );
1035  else
1036  dist = EuclideanNorm( bbox.GetCenter() - pos ) * 2;
1037  }
1038  else
1039  {
1040  SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1041  rect.Collide( SEG( aPos, aPos ), collector.m_Threshold, &dist );
1042  }
1043 
1044  if( item->IsType( EE_COLLECTOR::FieldOwners ) )
1045  dist += INT_MAX / 4;
1046 
1047  if( dist < closestDist )
1048  {
1049  closestDist = dist;
1050  closest = item;
1051  }
1052  }
1053 
1054  // Construct a tight box (1/2 height and width) around the center of the closest item.
1055  // All items which exist at least partly outside this box have sufficient other areas
1056  // for selection and can be dropped.
1057  if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
1058  {
1059  EDA_RECT tightBox = closest->GetBoundingBox();
1060  tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
1061 
1062  for( int i = collector.GetCount() - 1; i >= 0; --i )
1063  {
1064  EDA_ITEM* item = collector[i];
1065 
1066  if( item == closest )
1067  continue;
1068 
1069  if( !item->HitTest( tightBox, true ) )
1070  collector.Transfer( item );
1071  }
1072  }
1073 }
1074 
1075 
1077 {
1078  if( m_selection.Empty() )
1079  {
1080  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
1081 
1082  ClearSelection();
1083  SelectPoint( cursorPos, aFilterList );
1084  m_selection.SetIsHover( true );
1086  }
1087  else // Trim an existing selection by aFilterList
1088  {
1089  for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
1090  {
1091  EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
1092 
1093  if( !item->IsType( aFilterList ) )
1094  {
1095  unselect( item );
1097  }
1098  }
1099  }
1100 
1102 
1103  return m_selection;
1104 }
1105 
1106 
1108 {
1109  VECTOR2I refP( 0, 0 );
1110 
1111  if( m_selection.Size() > 0 )
1112  {
1113  if( m_isSymbolEditor )
1114  refP = static_cast<LIB_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1115  else
1116  refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1117  }
1118 
1120 }
1121 
1122 
1124 {
1125  bool cancelled = false; // Was the tool canceled while it was running?
1126  m_multiple = true; // Multiple selection mode is active
1127  KIGFX::VIEW* view = getView();
1128 
1130  view->Add( &area );
1131 
1132  while( TOOL_EVENT* evt = Wait() )
1133  {
1134  int width = area.GetEnd().x - area.GetOrigin().x;
1135 
1136  /* Selection mode depends on direction of drag-selection:
1137  * Left > Right : Select objects that are fully enclosed by selection
1138  * Right > Left : Select objects that are crossed by selection
1139  */
1140  bool windowSelection = width >= 0;
1141 
1142  if( view->IsMirroredX() )
1143  windowSelection = !windowSelection;
1144 
1147 
1148  if( evt->IsCancelInteractive() || evt->IsActivate() )
1149  {
1150  cancelled = true;
1151  break;
1152  }
1153 
1154  if( evt->IsDrag( BUT_LEFT ) )
1155  {
1157  ClearSelection();
1158 
1159  // Start drawing a selection box
1160  area.SetOrigin( evt->DragOrigin() );
1161  area.SetEnd( evt->Position() );
1162  area.SetAdditive( m_drag_additive );
1164  area.SetExclusiveOr( false );
1165 
1166  view->SetVisible( &area, true );
1167  view->Update( &area );
1168  getViewControls()->SetAutoPan( true );
1169  }
1170 
1171  if( evt->IsMouseUp( BUT_LEFT ) )
1172  {
1173  getViewControls()->SetAutoPan( false );
1174 
1175  // End drawing the selection box
1176  view->SetVisible( &area, false );
1177 
1178  // Mark items within the selection box as selected
1179  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
1180  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> children;
1181 
1182  // Filter the view items based on the selection box
1183  BOX2I selectionBox = area.ViewBBox();
1184  view->Query( selectionBox, selectedItems ); // Get the list of selected items
1185 
1186  // Some children aren't in the view; add them by hand.
1187  // DO NOT add them directly to selectedItems. If we add enough to cause the vector
1188  // to grow it will re-allocate and invalidate the top-level for-loop iterator.
1189  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
1190  {
1191  SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
1192 
1193  if( sheet )
1194  {
1195  int layer = pair.second;
1196 
1197  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1198  children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
1199  }
1200 
1201  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( pair.first );
1202 
1203  if( symbol )
1204  {
1205  int layer = pair.second;
1206 
1207  for( SCH_FIELD& field : symbol->GetFields() )
1208  children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &field, layer ) );
1209  }
1210 
1211  SCH_GLOBALLABEL* gLabel = dynamic_cast<SCH_GLOBALLABEL*>( pair.first );
1212 
1213  if( gLabel )
1214  {
1215  int layer = pair.second;
1216  SCH_FIELD* intersheetRef = gLabel->GetIntersheetRefs();
1217 
1218  children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( intersheetRef, layer ) );
1219  }
1220  }
1221 
1222  selectedItems.insert( selectedItems.end(), children.begin(), children.end() );
1223 
1224  int height = area.GetEnd().y - area.GetOrigin().y;
1225 
1226  bool anyAdded = false;
1227  bool anySubtracted = false;
1228 
1229  // Construct an EDA_RECT to determine EDA_ITEM selection
1230  EDA_RECT selectionRect( (wxPoint) area.GetOrigin(), wxSize( width, height ) );
1231 
1232  selectionRect.Normalize();
1233 
1234  for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
1235  {
1236  EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first );
1237 
1238  if( item && Selectable( item ) && item->HitTest( selectionRect, windowSelection ) )
1239  {
1240  if( m_subtractive || ( m_exclusive_or && item->IsSelected() ) )
1241  {
1242  unselect( item );
1243  anySubtracted = true;
1244  }
1245  else
1246  {
1247  select( item );
1248  item->SetFlags( STARTPOINT | ENDPOINT );
1249  anyAdded = true;
1250  }
1251  }
1252  }
1253 
1254  m_selection.SetIsHover( false );
1255 
1256  // Inform other potentially interested tools
1257  if( anyAdded )
1259 
1260  if( anySubtracted )
1262 
1263  break; // Stop waiting for events
1264  }
1265  }
1266 
1267  getViewControls()->SetAutoPan( false );
1268 
1269  // Stop drawing the selection box
1270  view->Remove( &area );
1271  m_multiple = false; // Multiple selection mode is inactive
1272 
1273  if( !cancelled )
1275 
1276  return cancelled;
1277 }
1278 
1279 
1280 static KICAD_T nodeTypes[] =
1281 {
1283  SCH_PIN_T,
1288  SCH_LABEL_T,
1293  EOT
1294 };
1295 
1296 
1298 {
1299  EE_COLLECTOR collector;
1300 
1301  //TODO(snh): Reimplement after exposing KNN interface
1302  int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1303  int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
1304  int thresholdMax = std::max( pixelThreshold, gridThreshold );
1305 
1306  for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
1307  {
1308  collector.m_Threshold = threshold;
1309  collector.Collect( m_frame->GetScreen(), nodeTypes, (wxPoint) aPosition );
1310 
1311  if( collector.GetCount() > 0 )
1312  break;
1313  }
1314 
1315  return collector.GetCount() ? collector[ 0 ] : nullptr;
1316 }
1317 
1318 
1320 {
1321  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
1322 
1323  SelectPoint( cursorPos, nodeTypes );
1324 
1325  return 0;
1326 }
1327 
1328 
1330 {
1331  static KICAD_T wiresAndBuses[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT };
1332 
1333  RequestSelection( wiresAndBuses );
1334 
1335  if( m_selection.Empty() )
1336  return 0;
1337 
1338  SCH_LINE* line = (SCH_LINE*) m_selection.Front();
1339  EDA_ITEMS items;
1340 
1342  std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line );
1343 
1344  for( SCH_ITEM* item : conns )
1345  select( item );
1346 
1347  if( m_selection.GetSize() > 1 )
1349 
1350  return 0;
1351 }
1352 
1353 
1355 {
1356  AddItemToSel( aEvent.Parameter<EDA_ITEM*>() );
1357  m_selection.SetIsHover( false );
1358  return 0;
1359 }
1360 
1361 
1362 void EE_SELECTION_TOOL::AddItemToSel( EDA_ITEM* aItem, bool aQuietMode )
1363 {
1364  if( aItem )
1365  {
1366  select( aItem );
1367 
1368  // Inform other potentially interested tools
1369  if( !aQuietMode )
1371  }
1372 }
1373 
1374 
1376 {
1377  AddItemsToSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1378  m_selection.SetIsHover( false );
1379  return 0;
1380 }
1381 
1382 
1383 void EE_SELECTION_TOOL::AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode )
1384 {
1385  if( aList )
1386  {
1387  for( EDA_ITEM* item : *aList )
1388  select( item );
1389 
1390  // Inform other potentially interested tools
1391  if( !aQuietMode )
1393  }
1394 }
1395 
1396 
1398 {
1399  RemoveItemFromSel( aEvent.Parameter<EDA_ITEM*>() );
1400  m_selection.SetIsHover( false );
1401  return 0;
1402 }
1403 
1404 
1405 void EE_SELECTION_TOOL::RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode )
1406 {
1407  if( aItem )
1408  {
1409  unselect( aItem );
1410 
1411  // Inform other potentially interested tools
1412  if( !aQuietMode )
1414  }
1415 }
1416 
1417 
1419 {
1420  RemoveItemsFromSel( aEvent.Parameter<EDA_ITEMS*>(), false );
1421  m_selection.SetIsHover( false );
1422  return 0;
1423 }
1424 
1425 
1426 void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode )
1427 {
1428  if( aList )
1429  {
1430  for( EDA_ITEM* item : *aList )
1431  unselect( item );
1432 
1433  // Inform other potentially interested tools
1434  if( !aQuietMode )
1436  }
1437 }
1438 
1439 
1440 void EE_SELECTION_TOOL::RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode )
1441 {
1442  EDA_ITEMS removeItems;
1443 
1444  for( EDA_ITEM* item : m_selection )
1445  {
1446  if( alg::contains( *aList, item->m_Uuid ) )
1447  removeItems.push_back( item );
1448  }
1449 
1450  RemoveItemsFromSel( &removeItems, aQuietMode );
1451 }
1452 
1453 
1455 {
1456  highlight( aItem, BRIGHTENED );
1457 }
1458 
1459 
1461 {
1462  unhighlight( aItem, BRIGHTENED );
1463 }
1464 
1465 
1467 {
1468  ClearSelection();
1469 
1470  return 0;
1471 }
1472 
1473 
1475 {
1476  m_selection.Clear();
1477 
1478  if( m_isSymbolEditor )
1479  {
1480  LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
1481 
1482  for( LIB_ITEM& item : start->GetDrawItems() )
1483  {
1484  if( item.IsSelected() )
1485  select( static_cast<EDA_ITEM*>( &item ) );
1486  }
1487  }
1488  else
1489  {
1490  for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
1491  {
1492  // If the field and symbol are selected, only use the symbol
1493  if( item->IsSelected() )
1494  {
1495  select( item );
1496  }
1497  else
1498  {
1499  item->RunOnChildren(
1500  [&]( SCH_ITEM* aChild )
1501  {
1502  if( aChild->IsSelected() )
1503  select( aChild );
1504  } );
1505  }
1506  }
1507  }
1508 
1510 
1511  // Inform other potentially interested tools
1513 }
1514 
1515 
1517 {
1518  EE_COLLECTOR* collector = aEvent.Parameter<EE_COLLECTOR*>();
1519 
1520  if( !doSelectionMenu( collector ) )
1521  collector->m_MenuCancelled = true;
1522 
1523  return 0;
1524 }
1525 
1526 
1528 {
1529  EDA_ITEM* current = nullptr;
1530  bool selectAll = false;
1531  bool expandSelection = false;
1532 
1533  do
1534  {
1536  if( expandSelection )
1537  aCollector->Combine();
1538 
1539  expandSelection = false;
1540 
1541  int limit = std::min( 9, aCollector->GetCount() );
1542  ACTION_MENU menu( true );
1543 
1544  for( int i = 0; i < limit; ++i )
1545  {
1546  wxString text;
1547  EDA_ITEM* item = ( *aCollector )[i];
1549 
1550  wxString menuText = wxString::Format( "&%d. %s\t%d", i + 1, text, i + 1 );
1551  menu.Add( menuText, i + 1, item->GetMenuImage() );
1552  }
1553 
1554  menu.AppendSeparator();
1555  menu.Add( _( "Select &All\tA" ), limit + 1, BITMAPS::INVALID_BITMAP );
1556 
1557  if( !expandSelection && aCollector->HasAdditionalItems() )
1558  menu.Add( _( "&Expand Selection\tE" ), limit + 2, BITMAPS::INVALID_BITMAP );
1559 
1560  if( aCollector->m_MenuTitle.Length() )
1561  {
1562  menu.SetTitle( aCollector->m_MenuTitle );
1563  menu.SetIcon( BITMAPS::info );
1564  menu.DisplayTitle( true );
1565  }
1566  else
1567  {
1568  menu.DisplayTitle( false );
1569  }
1570 
1571  SetContextMenu( &menu, CMENU_NOW );
1572 
1573  while( TOOL_EVENT* evt = Wait() )
1574  {
1575  if( evt->Action() == TA_CHOICE_MENU_UPDATE )
1576  {
1577  if( selectAll )
1578  {
1579  for( int i = 0; i < aCollector->GetCount(); ++i )
1580  unhighlight( ( *aCollector )[i], BRIGHTENED );
1581  }
1582  else if( current )
1583  {
1584  unhighlight( current, BRIGHTENED );
1585  }
1586 
1587  int id = *evt->GetCommandId();
1588 
1589  // User has pointed an item, so show it in a different way
1590  if( id > 0 && id <= limit )
1591  {
1592  current = ( *aCollector )[id - 1];
1593  highlight( current, BRIGHTENED );
1594  }
1595  else
1596  {
1597  current = nullptr;
1598  }
1599 
1600  // User has pointed on the "Select All" option
1601  if( id == limit + 1 )
1602  {
1603  for( int i = 0; i < aCollector->GetCount(); ++i )
1604  highlight( ( *aCollector )[i], BRIGHTENED );
1605  selectAll = true;
1606  }
1607  else
1608  {
1609  selectAll = false;
1610  }
1611  }
1612  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1613  {
1614  if( selectAll )
1615  {
1616  for( int i = 0; i < aCollector->GetCount(); ++i )
1617  unhighlight( ( *aCollector )[i], BRIGHTENED );
1618  }
1619  else if( current )
1620  unhighlight( current, BRIGHTENED );
1621 
1622  OPT<int> id = evt->GetCommandId();
1623 
1624  // User has selected the "Select All" option
1625  if( id == limit + 1 )
1626  {
1627  selectAll = true;
1628  current = nullptr;
1629  }
1630  else if( id == limit + 2 )
1631  {
1632  selectAll = false;
1633  current = nullptr;
1634  expandSelection = true;
1635  }
1636  // User has selected an item, so this one will be returned
1637  else if( id && ( *id > 0 ) && ( *id <= limit ) )
1638  {
1639  selectAll = false;
1640  current = ( *aCollector )[*id - 1];
1641  }
1642  // User has cancelled the menu (either by <esc> or clicking out of it)
1643  else
1644  {
1645  selectAll = false;
1646  current = nullptr;
1647  }
1648  }
1649  else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
1650  {
1651  break;
1652  }
1653 
1654  getView()->UpdateItems();
1655  m_frame->GetCanvas()->Refresh();
1656  }
1657  } while( expandSelection );
1658 
1659  if( selectAll )
1660  return true;
1661  else if( current )
1662  {
1663  unhighlight( current, BRIGHTENED );
1664 
1665  getView()->UpdateItems();
1666  m_frame->GetCanvas()->Refresh();
1667 
1668  aCollector->Empty();
1669  aCollector->Append( current );
1670  return true;
1671  }
1672 
1673  return false;
1674 }
1675 
1676 
1677 bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
1678  bool checkVisibilityOnly ) const
1679 {
1680  // NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
1681 
1682  SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
1683 
1684  // Do not allow selection of anything except fields when the current symbol in the symbol
1685  // editor is a derived symbol.
1686  if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != LIB_FIELD_T )
1687  return false;
1688 
1689  switch( aItem->Type() )
1690  {
1691  case SCH_PIN_T:
1692  {
1693  const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
1694 
1695  if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
1696  return false;
1697 
1699  {
1700  // Pin anchors have to be allowed for auto-starting wires.
1701  if( aPos )
1702  {
1704  VECTOR2I cursorPos = grid.BestSnapAnchor( *aPos, LAYER_CONNECTABLE, nullptr );
1705 
1706  if( pin->IsPointClickableAnchor( (wxPoint) cursorPos ) )
1707  return true;
1708  }
1709 
1710  return false;
1711  }
1712  }
1713  break;
1714 
1715  case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
1716  return false;
1717 
1718  case LIB_FIELD_T: // LIB_FIELD object can always be edited.
1719  break;
1720 
1721  case LIB_SHAPE_T:
1722  case LIB_TEXT_T:
1723  case LIB_PIN_T:
1724  if( symEditFrame )
1725  {
1726  LIB_ITEM* lib_item = (LIB_ITEM*) aItem;
1727 
1728  if( lib_item->GetUnit() && lib_item->GetUnit() != symEditFrame->GetUnit() )
1729  return false;
1730 
1731  if( lib_item->GetConvert() && lib_item->GetConvert() != symEditFrame->GetConvert() )
1732  return false;
1733  }
1734 
1735  break;
1736 
1737  case SCH_MARKER_T: // Always selectable
1738  return true;
1739 
1740  default: // Suppress warnings
1741  break;
1742  }
1743 
1744  return true;
1745 }
1746 
1747 
1749 {
1750  if( m_selection.Empty() )
1751  return;
1752 
1753  while( m_selection.GetSize() )
1755 
1756  getView()->Update( &m_selection );
1757 
1758  m_selection.SetIsHover( false );
1760 
1761  // Inform other potentially interested tools
1763 }
1764 
1765 
1767 {
1768  highlight( aItem, SELECTED, &m_selection );
1769 }
1770 
1771 
1773 {
1774  unhighlight( aItem, SELECTED, &m_selection );
1775 }
1776 
1777 
1778 void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1779 {
1780  KICAD_T itemType = aItem->Type();
1781 
1782  if( aMode == SELECTED )
1783  aItem->SetSelected();
1784  else if( aMode == BRIGHTENED )
1785  aItem->SetBrightened();
1786 
1787  if( aGroup )
1788  aGroup->Add( aItem );
1789 
1790  // Highlight pins and fields. (All the other symbol children are currently only
1791  // represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
1792  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1793  {
1794  sch_item->RunOnChildren(
1795  [&]( SCH_ITEM* aChild )
1796  {
1797  if( aMode == SELECTED )
1798  aChild->SetSelected();
1799  else if( aMode == BRIGHTENED )
1800  aChild->SetBrightened();
1801  } );
1802  }
1803 
1804  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1805  getView()->Update( aItem->GetParent() );
1806  else
1807  getView()->Update( aItem );
1808 }
1809 
1810 
1811 void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup )
1812 {
1813  KICAD_T itemType = aItem->Type();
1814 
1815  if( aMode == SELECTED )
1816  aItem->ClearSelected();
1817  else if( aMode == BRIGHTENED )
1818  aItem->ClearBrightened();
1819 
1820  if( aGroup )
1821  aGroup->Remove( aItem );
1822 
1823  // Unhighlight pins and fields. (All the other symbol children are currently only
1824  // represented in the LIB_SYMBOL.)
1825  if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1826  {
1827  sch_item->RunOnChildren(
1828  [&]( SCH_ITEM* aChild )
1829  {
1830  if( aMode == SELECTED )
1831  aChild->ClearSelected();
1832  else if( aMode == BRIGHTENED )
1833  aChild->ClearBrightened();
1834  } );
1835  }
1836 
1837  if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T )
1838  getView()->Update( aItem->GetParent() );
1839  else
1840  getView()->Update( aItem );
1841 }
1842 
1843 
1845 {
1846  const unsigned GRIP_MARGIN = 20;
1847  VECTOR2I margin = getView()->ToWorld( VECTOR2I( GRIP_MARGIN, GRIP_MARGIN ), false );
1848 
1849  // Check if the point is located within any of the currently selected items bounding boxes
1850  for( EDA_ITEM* item : m_selection )
1851  {
1852  BOX2I itemBox = item->ViewBBox();
1853  itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item
1854 
1855  if( itemBox.Contains( aPoint ) )
1856  return true;
1857  }
1858 
1859  return false;
1860 }
1861 
1862 
1864 {
1866 
1871 
1877 
1879 
1881 }
1882 
1883 
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:192
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
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
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:199
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 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:123
Model changes (required full reload)
Definition: tool_base.h:80
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
#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:447
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
static const TOOL_EVENT DisambiguatePoint
Definition: actions.h:214
void ClearSelected()
Definition: eda_item.h:132
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:348
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:711
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
void SetBrightened()
Definition: eda_item.h:130
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
#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
void SetExclusiveOr(bool aExclusiveOr)
static const KICAD_T FieldOwners[]
Definition: ee_collectors.h:48
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 removeItemsFromSel
Definition: ee_actions.h:64
static TOOL_ACTION importSingleSheetPin
Definition: ee_actions.h:187
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:623
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).
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
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_line.cpp:772
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:184
void ClearBrightened()
Definition: eda_item.h:133
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.
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 contained within or on the bounding box of an item.
Definition: eda_item.h:225
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:187
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:129
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:198
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
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...
void SetMaximum()
Definition: box2.h:57
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:115
#define _(s)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
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:201
#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:183
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:1406
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:507
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
int GetConvert() const
Definition: lib_item.h:261
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:473
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:184
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
SCH_FIELD * GetIntersheetRefs()
Definition: sch_text.h:413
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)
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
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
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:211
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
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 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:100
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
static TOOL_ACTION enterSheet
Definition: ee_actions.h:183
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1458
static SELECTION_CONDITION SingleSymbolOrPower
void Combine()
Re-combine the backup list into the main list of the collector.
Definition: collector.h:141
SCH_SHEET_PATH & GetCurrentSheet() const
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
VECTOR2I m_originalCursor
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
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:827
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:424
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)
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:1512
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:113
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