KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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 <advanced_config.h>
26#include <core/typeinfo.h>
27#include <core/kicad_algo.h>
30#include <ee_actions.h>
31#include <ee_collectors.h>
32#include <ee_selection_tool.h>
33#include <eeschema_id.h>
34#include <symbol_edit_frame.h>
35#include <symbol_viewer_frame.h>
36#include <math/util.h>
37#include <geometry/shape_rect.h>
38#include <sch_painter.h>
40#include <sch_base_frame.h>
41#include <sch_commit.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_bus_entry.h>
48#include <sch_marker.h>
49#include <sch_no_connect.h>
50#include <sch_render_settings.h>
51#include <sch_sheet.h>
52#include <sch_sheet_pin.h>
53#include <sch_table.h>
54#include <sch_tablecell.h>
55#include <schematic.h>
56#include <tool/tool_event.h>
57#include <tool/tool_manager.h>
62#include <trigo.h>
63#include <view/view.h>
64#include <view/view_controls.h>
65#include <wx/log.h>
66
68
69
71{
72 if( aSel.GetSize() == 1 )
73 {
74 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
75
76 if( symbol )
77 return !symbol->GetLibSymbolRef() || !symbol->GetLibSymbolRef()->IsPower();
78 }
79
80 return false;
81};
82
83
85{
86 return aSel.GetSize() == 1 && aSel.Front()->Type() == SCH_SYMBOL_T;
87};
88
89
91{
92 if( aSel.GetSize() == 1 )
93 {
94 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
95
96 if( symbol )
97 return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->HasAlternateBodyStyle();
98 }
99
100 return false;
101};
102
103
105{
106 if( aSel.GetSize() == 1 )
107 {
108 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aSel.Front() );
109
110 if( symbol )
111 return symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->GetUnitCount() >= 2;
112 }
113
114 return false;
115};
116
117
119{
120 if( aSel.GetSize() == 1 )
121 {
122 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aSel.Front() );
123
124 if( pin && pin->GetLibPin() )
125 return !pin->GetLibPin()->GetAlternates().empty();
126 }
127
128 return false;
129};
130
131
133{
134 if( aSel.CountType( SCH_MARKER_T ) != 1 )
135 return false;
136
137 return !static_cast<SCH_MARKER*>( aSel.Front() )->IsExcluded();
138};
139
140
142{
143 return aSel.GetSize() > 1 && aSel.OnlyContains( { SCH_SYMBOL_T } );
144};
145
146
148{
149 return aSel.GetSize() >= 1 && aSel.OnlyContains( { SCH_PIN_T } );
150};
151
152
154{
155 return aSel.GetSize() >= 1 && aSel.OnlyContains( { SCH_PIN_T, SCH_SHEET_PIN_T } );
156};
157
158
159#define HITTEST_THRESHOLD_PIXELS 5
160
161
163 SELECTION_TOOL( "eeschema.InteractiveSelection" ),
164 m_frame( nullptr ),
165 m_nonModifiedCursor( KICURSOR::ARROW ),
166 m_isSymbolEditor( false ),
167 m_isSymbolViewer( false ),
168 m_unit( 0 ),
169 m_bodyStyle( 0 )
170{
173}
174
175
177{
179}
180
181
183
184
185static std::vector<KICAD_T> connectedTypes =
186{
188 SCH_PIN_T,
199};
200
201static std::vector<KICAD_T> connectedLineTypes =
202{
205};
206
207static std::vector<KICAD_T> crossProbingTypes =
208{
210 SCH_PIN_T,
212};
213
214static std::vector<KICAD_T> lineTypes = { SCH_LINE_T };
215static std::vector<KICAD_T> sheetTypes = { SCH_SHEET_T };
216static std::vector<KICAD_T> tableCellTypes = { SCH_TABLECELL_T };
217
219{
220 m_frame = getEditFrame<SCH_BASE_FRAME>();
221
222 SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
223 SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
224
225 if( symbolEditorFrame )
226 {
227 m_isSymbolEditor = true;
228 m_unit = symbolEditorFrame->GetUnit();
229 m_bodyStyle = symbolEditorFrame->GetBodyStyle();
230 }
231 else
232 {
233 m_isSymbolViewer = symbolViewerFrame != nullptr;
234 }
235
236 auto linesSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( lineTypes );
237 auto wireOrBusSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedLineTypes );
238 auto connectedSelection = E_C::Count( 1 ) && E_C::OnlyTypes( connectedTypes );
239 auto sheetSelection = E_C::Count( 1 ) && E_C::OnlyTypes( sheetTypes );
240 auto crossProbingSelection = E_C::MoreThan( 0 ) && E_C::HasTypes( crossProbingTypes );
241 auto tableCellSelection = E_C::MoreThan( 0 ) && E_C::OnlyTypes( tableCellTypes );
242
243 auto schEditSheetPageNumberCondition =
244 [&] ( const SELECTION& aSel )
245 {
247 return false;
248
249 return E_C::LessThan( 2 )( aSel ) && E_C::OnlyTypes( sheetTypes )( aSel );
250 };
251
252 auto schEditCondition =
253 [this] ( const SELECTION& aSel )
254 {
256 };
257
258 auto belowRootSheetCondition =
259 [&]( const SELECTION& aSel )
260 {
261 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
262
263 return editFrame
264 && editFrame->GetCurrentSheet().Last() != &editFrame->Schematic().Root();
265 };
266
267 auto haveHighlight =
268 [&]( const SELECTION& sel )
269 {
270 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
271
272 return editFrame && !editFrame->GetHighlightedConnection().IsEmpty();
273 };
274
275 auto haveSymbol =
276 [&]( const SELECTION& sel )
277 {
278 return m_isSymbolEditor &&
279 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
280 };
281
282 auto symbolDisplayNameIsEditable =
283 [&]( const SELECTION& sel )
284 {
285 if ( !m_isSymbolEditor )
286 return false;
287
288 SYMBOL_EDIT_FRAME* symbEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
289
290 return symbEditorFrame
291 && symbEditorFrame->GetCurSymbol()
292 && symbEditorFrame->GetCurSymbol()->IsMulti()
293 && symbEditorFrame->IsSymbolEditable()
294 && !symbEditorFrame->IsSymbolAlias();
295 };
296
297 auto& menu = m_menu->GetMenu();
298
299 menu.AddItem( EE_ACTIONS::clearHighlight, haveHighlight && EE_CONDITIONS::Idle, 1 );
300 menu.AddSeparator( haveHighlight && EE_CONDITIONS::Idle, 1 );
301
302 menu.AddItem( ACTIONS::selectColumns, tableCellSelection && EE_CONDITIONS::Idle, 2 );
303 menu.AddItem( ACTIONS::selectRows, tableCellSelection && EE_CONDITIONS::Idle, 2 );
304 menu.AddItem( ACTIONS::selectTable, tableCellSelection && EE_CONDITIONS::Idle, 2 );
305
306 menu.AddSeparator( 100 );
307 menu.AddItem( EE_ACTIONS::drawWire, schEditCondition && EE_CONDITIONS::Empty, 100 );
308 menu.AddItem( EE_ACTIONS::drawBus, schEditCondition && EE_CONDITIONS::Empty, 100 );
309
310 menu.AddSeparator( 100 );
311 menu.AddItem( ACTIONS::finishInteractive,
313
314 menu.AddItem( EE_ACTIONS::enterSheet, sheetSelection && EE_CONDITIONS::Idle, 150 );
315 menu.AddItem( EE_ACTIONS::selectOnPCB,
316 crossProbingSelection && schEditCondition && EE_CONDITIONS::Idle, 150 );
317 menu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 150 );
318
319 menu.AddSeparator( 200 );
320 menu.AddItem( EE_ACTIONS::placeJunction, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
321 menu.AddItem( EE_ACTIONS::placeLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
322 menu.AddItem( EE_ACTIONS::placeClassLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
323 menu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
324 menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
325 menu.AddItem( EE_ACTIONS::breakWire, linesSelection && EE_CONDITIONS::Idle, 250 );
326 menu.AddItem( EE_ACTIONS::slice, linesSelection && EE_CONDITIONS::Idle, 250 );
327 menu.AddItem( EE_ACTIONS::placeSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
328 menu.AddItem( EE_ACTIONS::syncSheetPins, sheetSelection && EE_CONDITIONS::Idle, 250 );
329 menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
330 menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
331
332 menu.AddSeparator( 400 );
333 menu.AddItem( EE_ACTIONS::symbolProperties, haveSymbol && EE_CONDITIONS::Empty, 400 );
334 menu.AddItem( EE_ACTIONS::pinTable, haveSymbol && EE_CONDITIONS::Empty, 400 );
335 menu.AddItem( EE_ACTIONS::setUnitDisplayName,
336 haveSymbol && symbolDisplayNameIsEditable && EE_CONDITIONS::Empty, 400 );
337
338 menu.AddSeparator( 1000 );
340
341 m_disambiguateTimer.SetOwner( this );
342 Connect( wxEVT_TIMER, wxTimerEventHandler( EE_SELECTION_TOOL::onDisambiguationExpire ),
343 nullptr, this );
344
345 return true;
346}
347
348
350{
351 m_frame = getEditFrame<SCH_BASE_FRAME>();
352
353 if( aReason != TOOL_BASE::REDRAW )
354 {
355 // Remove pointers to the selected items from containers without changing their
356 // properties (as they are already deleted while a new sheet is loaded)
358 }
359
360 if( aReason == RESET_REASON::SHUTDOWN )
361 return;
362
363 if( aReason == TOOL_BASE::MODEL_RELOAD || aReason == TOOL_BASE::SUPERMODEL_RELOAD )
364 {
365 getView()->GetPainter()->GetSettings()->SetHighlight( false );
366
367 SYMBOL_EDIT_FRAME* symbolEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
368 SYMBOL_VIEWER_FRAME* symbolViewerFrame = dynamic_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
369
370 if( symbolEditFrame )
371 {
372 m_isSymbolEditor = true;
373 m_unit = symbolEditFrame->GetUnit();
374 m_bodyStyle = symbolEditFrame->GetBodyStyle();
375 }
376 else
377 {
378 m_isSymbolViewer = symbolViewerFrame != nullptr;
379 }
380 }
381
382 // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
384 getView()->Add( &m_selection );
385}
386
387
389{
390 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
391
392 KIID lastRolloverItem = niluuid;
394
395 auto pinOrientation =
396 []( EDA_ITEM* aItem )
397 {
398 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem );
399
400 if( pin )
401 {
402 const SCH_SYMBOL* parent = dynamic_cast<const SCH_SYMBOL*>( pin->GetParentSymbol() );
403
404 if( !parent )
405 return pin->GetOrientation();
406 else
407 {
408 SCH_PIN dummy( *pin );
410 return dummy.GetOrientation();
411 }
412 }
413
414 SCH_SHEET_PIN* sheetPin = dynamic_cast<SCH_SHEET_PIN*>( aItem );
415
416 if( sheetPin )
417 {
418 switch( sheetPin->GetSide() )
419 {
420 default:
421 case SHEET_SIDE::LEFT: return PIN_ORIENTATION::PIN_RIGHT;
422 case SHEET_SIDE::RIGHT: return PIN_ORIENTATION::PIN_LEFT;
423 case SHEET_SIDE::TOP: return PIN_ORIENTATION::PIN_DOWN;
424 case SHEET_SIDE::BOTTOM: return PIN_ORIENTATION::PIN_UP;
425 }
426 }
427
428 return PIN_ORIENTATION::PIN_LEFT;
429 };
430
431 // Main loop: keep receiving events
432 while( TOOL_EVENT* evt = Wait() )
433 {
434 bool selCancelled = false;
435 bool displayWireCursor = false;
436 bool displayBusCursor = false;
437 bool displayLineCursor = false;
438 KIID rolloverItem = lastRolloverItem;
439
440 // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
441 setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ),
442 evt->Modifier( MD_ALT ) );
443
444 MOUSE_DRAG_ACTION drag_action = m_frame->GetDragAction();
445
446 if( evt->IsMouseDown( BUT_LEFT ) )
447 {
448 if( !m_frame->ToolStackIsEmpty() )
449 {
450 // Avoid triggering when running under other tools
451 }
454 {
455 // Distinguish point editor from selection modification by checking modifiers
456 if( hasModifier() )
457 {
459 m_disambiguateTimer.StartOnce( ADVANCED_CFG::GetCfg().m_DisambiguationMenuDelay );
460 }
461 }
462 else
463 {
465 m_disambiguateTimer.StartOnce( ADVANCED_CFG::GetCfg().m_DisambiguationMenuDelay );
466 }
467 }
468 // Single click? Select single object
469 else if( evt->IsClick( BUT_LEFT ) )
470 {
471 // If the timer has stopped, then we have already run the disambiguate routine
472 // and we don't want to register an extra click here
473 if( !m_disambiguateTimer.IsRunning() )
474 {
475 evt->SetPassEvent();
476 continue;
477 }
478
479 m_disambiguateTimer.Stop();
480
481 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
482 schframe->FocusOnItem( nullptr );
483
484 // Collect items at the clicked location (doesn't select them yet)
485 EE_COLLECTOR collector;
486 CollectHits( collector, evt->Position() );
487 narrowSelection( collector, evt->Position(), false );
488
489 if( collector.GetCount() == 1 && !m_isSymbolEditor && !hasModifier() )
490 {
491 OPT_TOOL_EVENT autostart = autostartEvent( evt, grid, collector[0] );
492
493 if( autostart )
494 {
496
497 params->layer = autostart->Parameter<const DRAW_SEGMENT_EVENT_PARAMS*>()->layer;
498 params->quitOnDraw = true;
499 params->sourceSegment = dynamic_cast<SCH_LINE*>( collector[0] );
500
501 autostart->SetParameter<const DRAW_SEGMENT_EVENT_PARAMS*>( params );
502 m_toolMgr->ProcessEvent( *autostart );
503
504 selCancelled = true;
505 }
506 else if( collector[0]->IsHypertext() )
507 {
508 collector[ 0 ]->DoHypertextAction( m_frame );
509 selCancelled = true;
510 }
511 else if( collector[0]->IsBrightened() )
512 {
513 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
514 {
515 NET_NAVIGATOR_ITEM_DATA itemData( schframe->GetCurrentSheet(),
516 collector[0] );
517
518 schframe->SelectNetNavigatorItem( &itemData );
519 }
520 }
521 }
522
523 if( !selCancelled )
524 {
525 selectPoint( collector, evt->Position(), nullptr, nullptr, m_additive,
527 m_selection.SetIsHover( false );
528 }
529 }
530 else if( evt->IsClick( BUT_RIGHT ) )
531 {
532 m_disambiguateTimer.Stop();
533
534 // right click? if there is any object - show the context menu
535 if( m_selection.Empty() )
536 {
538 SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
539 m_selection.SetIsHover( true );
540 }
541 // If the cursor has moved off the bounding box of the selection by more than
542 // a grid square, check to see if there is another item available for selection
543 // under the cursor. If there is, the user likely meant to get the context menu
544 // for that item. If there is no new item, then keep the original selection and
545 // show the context menu for it.
546 else if( !m_selection.GetBoundingBox().Inflate( grid.GetGrid().x, grid.GetGrid().y )
547 .Contains( evt->Position() ) )
548 {
549 EE_COLLECTOR collector;
550
551 if( CollectHits( collector, evt->Position(), { SCH_LOCATE_ANY_T } ) )
552 {
554
555 SelectPoint( evt->Position(), { SCH_LOCATE_ANY_T }, nullptr, &selCancelled );
556 m_selection.SetIsHover( true );
557 }
558 }
559
560 if( !selCancelled )
561 m_menu->ShowContextMenu( m_selection );
562 }
563 else if( evt->IsDblClick( BUT_LEFT ) )
564 {
565 m_disambiguateTimer.Stop();
566
567 // double click? Display the properties window
568 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
569 schframe->FocusOnItem( nullptr );
570
571 if( m_selection.Empty() )
572 SelectPoint( evt->Position() );
573
574 EDA_ITEM* item = m_selection.Front();
575
576 if( item && item->Type() == SCH_SHEET_T )
578 else
580 }
581 else if( evt->IsDblClick( BUT_MIDDLE ) )
582 {
583 m_disambiguateTimer.Stop();
584
585 // Middle double click? Do zoom to fit or zoom to objects
586 if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
588 else
590 }
591 else if( evt->IsDrag( BUT_LEFT ) )
592 {
593 m_disambiguateTimer.Stop();
594
595 // Is another tool already moving a new object? Don't allow a drag start
596 if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
597 {
598 evt->SetPassEvent();
599 continue;
600 }
601
602 // drag with LMB? Select multiple objects (or at least draw a selection box) or
603 // drag them
604 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
605 schframe->FocusOnItem( nullptr );
606
607 EE_COLLECTOR collector;
608
609 if( CollectHits( collector, evt->DragOrigin(), { SCH_TABLECELL_T } ) )
610 {
611 selectTableCells( static_cast<SCH_TABLE*>( collector[0]->GetParent() ) );
612 }
613 else if( hasModifier() || drag_action == MOUSE_DRAG_ACTION::SELECT )
614 {
616 }
617 else if( m_selection.Empty() && drag_action != MOUSE_DRAG_ACTION::DRAG_ANY )
618 {
620 }
621 else
622 {
623 if( m_isSymbolEditor )
624 {
625 if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
626 {
628 }
629 else
630 {
634 SCH_PIN_T,
635 SCH_FIELD_T } );
636 }
637 }
638 else
639 {
641 }
642
643 // Check if dragging has started within any of selected items bounding box
644 if( selectionContains( evt->DragOrigin() ) )
645 {
646 // drag_is_move option exists only in schematic editor, not in symbol editor
647 // (m_frame->eeconfig() returns nullptr in Symbol Editor)
650 else
652 }
653 else
654 {
655 // No -> drag a selection box
657 }
658 }
659 }
660 else if( evt->IsMouseDown( BUT_AUX1 ) )
661 {
663 }
664 else if( evt->IsMouseDown( BUT_AUX2 ) )
665 {
667 }
668 else if( evt->Action() == TA_MOUSE_WHEEL )
669 {
670 int field = -1;
671
672 if( evt->Modifier() == ( MD_SHIFT | MD_ALT ) )
673 field = 0;
674 else if( evt->Modifier() == ( MD_CTRL | MD_ALT ) )
675 field = 1;
676 // any more?
677
678 if( field >= 0 )
679 {
680 const int delta = evt->Parameter<int>();
681 ACTIONS::INCREMENT incParams{
682 delta > 0 ? 1 : -1,
683 field,
684 };
685
687 }
688 }
689 else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
690 {
691 m_disambiguateTimer.Stop();
692
693 // context sub-menu selection? Handle unit selection or bus unfolding
694 if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT
695 && *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_UNIT_END )
696 {
697 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
698 int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
699
700 if( symbol )
701 static_cast<SCH_EDIT_FRAME*>( m_frame )->SelectUnit( symbol, unit );
702 }
703 else if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_BASE
704 && *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_ALT )
705 {
706 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selection.Front() );
707 int bodyStyle = ( *evt->GetCommandId() - ID_POPUP_SCH_SELECT_BASE ) + 1;
708
709 if( symbol && symbol->GetBodyStyle() != bodyStyle )
710 static_cast<SCH_EDIT_FRAME*>( m_frame )->FlipBodyStyle( symbol );
711 }
712 else if( *evt->GetCommandId() >= ID_POPUP_SCH_ALT_PIN_FUNCTION
713 && *evt->GetCommandId() <= ID_POPUP_SCH_ALT_PIN_FUNCTION_END )
714 {
715 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( m_selection.Front() );
716 wxString alt = *evt->Parameter<wxString*>();
717
718 if( pin )
719 static_cast<SCH_EDIT_FRAME*>( m_frame )->SetAltPinFunction( pin, alt );
720 }
721 else if( *evt->GetCommandId() >= ID_POPUP_SCH_PIN_TRICKS_START
722 && *evt->GetCommandId() <= ID_POPUP_SCH_PIN_TRICKS_END
724 {
725 SCH_EDIT_FRAME* sch_frame = static_cast<SCH_EDIT_FRAME*>( m_frame );
726
727 // Keep track of new items so we make them the new selection at the end
728 EDA_ITEMS newItems;
729 SCH_COMMIT commit( sch_frame );
730
731 if( *evt->GetCommandId() == ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT )
732 {
733 for( EDA_ITEM* item : m_selection )
734 {
735 if( item->Type() != SCH_PIN_T && item->Type() != SCH_SHEET_PIN_T )
736 continue;
737
738 SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( item->GetPosition() );
739 commit.Add( nc, sch_frame->GetScreen() );
740 newItems.push_back( nc );
741 }
742
743 if( !commit.Empty() )
744 {
745 commit.Push( wxS( "No Connect Pins" ) );
747 }
748 }
749 else if( *evt->GetCommandId() == ID_POPUP_SCH_PIN_TRICKS_WIRE )
750 {
751 VECTOR2I wireGrid = grid.GetGridSize( GRID_HELPER_GRIDS::GRID_WIRES );
752
753 for( EDA_ITEM* item : m_selection )
754 {
755 if( item->Type() != SCH_PIN_T && item->Type() != SCH_SHEET_PIN_T )
756 continue;
757
758 SCH_LINE* wire = new SCH_LINE( item->GetPosition(), LAYER_WIRE );
759
760 // Add some length to the wire as nothing in our code base handles
761 // 0 length wires very well, least of all the ortho drag algorithm
762 VECTOR2I stub;
763
764 switch( pinOrientation( item ) )
765 {
766 default:
767 case PIN_ORIENTATION::PIN_RIGHT:
768 stub = VECTOR2I( -1 * wireGrid.x, 0 );
769 break;
770 case PIN_ORIENTATION::PIN_LEFT:
771 stub = VECTOR2I( 1 * wireGrid.x, 0 );
772 break;
773 case PIN_ORIENTATION::PIN_UP:
774 stub = VECTOR2I( 0, 1 * wireGrid.y );
775 break;
776 case PIN_ORIENTATION::PIN_DOWN:
777 stub = VECTOR2I( 0, -1 * wireGrid.y );
778 break;
779 }
780
781 wire->SetEndPoint( item->GetPosition() + stub );
782
783 m_frame->AddToScreen( wire, sch_frame->GetScreen() );
784 commit.Added( wire, sch_frame->GetScreen() );
785 newItems.push_back( wire );
786 }
787
788 if( !commit.Empty() )
789 {
791 AddItemsToSel( &newItems );
792
793 // Select only the ends so we can immediately start dragging them
794 for( EDA_ITEM* item : newItems )
795 static_cast<SCH_LINE*>( item )->SetFlags( ENDPOINT );
796
798
799 // Put the mouse on the nearest point of the first wire
800 SCH_LINE* first = static_cast<SCH_LINE*>( newItems[0] );
801 vc->SetCrossHairCursorPosition( first->GetEndPoint(), false );
802 vc->WarpMouseCursor( vc->GetCursorPosition(), true );
803
804 // Start the drag tool, canceling will remove the wires
805 if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::drag, &commit, false ) )
806 commit.Push( wxS( "Wire Pins" ) );
807 else
808 commit.Revert();
809 }
810 }
811 else
812 {
813 // For every pin in the selection, add a label according to menu item
814 // selected by the user
815 for( EDA_ITEM* item : m_selection )
816 {
817 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
818 SCH_SHEET_PIN* sheetPin = dynamic_cast<SCH_SHEET_PIN*>( item );
819 SCH_LABEL_BASE* label = nullptr;
820 SCH_SHEET_PATH& sheetPath = sch_frame->GetCurrentSheet();
821
822 wxString labelText;
823
824 if( pin )
825 {
826 labelText = pin->GetShownName();
827
828 if( labelText.IsEmpty() )
829 {
830 labelText.Printf( "%s_%s",
831 pin->GetParentSymbol()->GetRef( &sheetPath ),
832 pin->GetNumber() );
833 }
834 }
835 else if( sheetPin )
836 {
837 labelText = sheetPin->GetShownText( &sheetPath, false );
838 }
839 else
840 {
841 continue;
842 }
843
844 switch( *evt->GetCommandId() )
845 {
847 label = new SCH_LABEL( item->GetPosition(), labelText );
848 break;
850 label = new SCH_HIERLABEL( item->GetPosition(), labelText );
851 break;
853 label = new SCH_GLOBALLABEL( item->GetPosition(), labelText );
854 break;
855 default:
856 continue;
857 }
858
859 switch( pinOrientation( item ) )
860 {
861 default:
862 case PIN_ORIENTATION::PIN_RIGHT:
864 break;
865 case PIN_ORIENTATION::PIN_LEFT:
867 break;
868 case PIN_ORIENTATION::PIN_UP:
870 break;
871 case PIN_ORIENTATION::PIN_DOWN:
873 break;
874 }
875
876 ELECTRICAL_PINTYPE pinType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
877
878 if( pin )
879 {
880 pinType = pin->GetType();
881 }
882 else if( sheetPin )
883 {
884 switch( sheetPin->GetLabelShape() )
885 {
886 case LABEL_INPUT: pinType = ELECTRICAL_PINTYPE::PT_INPUT; break;
887 case LABEL_OUTPUT: pinType = ELECTRICAL_PINTYPE::PT_OUTPUT; break;
888 case LABEL_BIDI: pinType = ELECTRICAL_PINTYPE::PT_BIDI; break;
889 case LABEL_TRISTATE: pinType = ELECTRICAL_PINTYPE::PT_TRISTATE; break;
890 case LABEL_PASSIVE: pinType = ELECTRICAL_PINTYPE::PT_PASSIVE; break;
891 }
892 }
893
894 switch( pinType )
895 {
896 case ELECTRICAL_PINTYPE::PT_BIDI:
897 label->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
898 break;
899 case ELECTRICAL_PINTYPE::PT_INPUT:
900 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
901 break;
902 case ELECTRICAL_PINTYPE::PT_OUTPUT:
903 label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
904 break;
905 case ELECTRICAL_PINTYPE::PT_TRISTATE:
906 label->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
907 break;
908 case ELECTRICAL_PINTYPE::PT_UNSPECIFIED:
909 label->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
910 break;
911 default:
912 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
913 }
914
915 commit.Add( label, sch_frame->GetScreen() );
916 newItems.push_back( label );
917 }
918
919 if( !commit.Empty() )
920 {
921 commit.Push( wxS( "Label Pins" ) );
922
923 // Many users will want to drag these items to wire off of the pins, so
924 // pre-select them.
926 AddItemsToSel( &newItems );
927 }
928 }
929 }
930 else if( *evt->GetCommandId() >= ID_POPUP_SCH_UNFOLD_BUS
931 && *evt->GetCommandId() <= ID_POPUP_SCH_UNFOLD_BUS_END )
932 {
933 wxString* net = new wxString( *evt->Parameter<wxString*>() );
934 m_toolMgr->RunAction<wxString*>( EE_ACTIONS::unfoldBus, net );
935 }
936 }
937 else if( evt->IsCancelInteractive() )
938 {
939 m_disambiguateTimer.Stop();
940
941 // We didn't set these, but we have reports that they leak out of some other tools,
942 // so we clear them here.
943 getViewControls()->SetAutoPan( false );
944 getViewControls()->CaptureCursor( false );
945
946 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
947 schframe->FocusOnItem( nullptr );
948
949 if( !GetSelection().Empty() )
950 {
952 }
953 else if( evt->FirstResponder() == this && evt->GetCommandId() == (int) WXK_ESCAPE )
954 {
956
958 editor->ClearHighlight( *evt );
959 }
960 }
961 else if( evt->Action() == TA_UNDO_REDO_PRE )
962 {
963 if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
964 schframe->FocusOnItem( nullptr );
965 }
966 else if( evt->IsMotion() && !m_isSymbolEditor && evt->FirstResponder() == this )
967 {
968 // Update cursor and rollover item
969 rolloverItem = niluuid;
970 EE_COLLECTOR collector;
971
973
974 if( CollectHits( collector, evt->Position() ) )
975 {
976 narrowSelection( collector, evt->Position(), false );
977
978 if( collector.GetCount() == 1 && !hasModifier() )
979 {
980 OPT_TOOL_EVENT autostartEvt = autostartEvent( evt, grid, collector[0] );
981
982 if( autostartEvt )
983 {
984 if( autostartEvt->Matches( EE_ACTIONS::drawBus.MakeEvent() ) )
985 displayBusCursor = true;
986 else if( autostartEvt->Matches( EE_ACTIONS::drawWire.MakeEvent() ) )
987 displayWireCursor = true;
988 else if( autostartEvt->Matches( EE_ACTIONS::drawLines.MakeEvent() ) )
989 displayLineCursor = true;
990 }
991 else if( collector[0]->IsHypertext() && !collector[0]->IsSelected() )
992 {
993 rolloverItem = collector[0]->m_Uuid;
994 }
995 }
996 }
997 }
998 else
999 {
1000 evt->SetPassEvent();
1001 }
1002
1003 if( rolloverItem != lastRolloverItem )
1004 {
1005 if( EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ) )
1006 {
1007 item->ClearFlags( IS_ROLLOVER );
1008 lastRolloverItem = niluuid;
1009
1010 if( item->Type() == SCH_FIELD_T )
1011 m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
1012 else
1013 m_frame->GetCanvas()->GetView()->Update( item );
1014 }
1015 }
1016
1017 if( rolloverItem != niluuid )
1018 {
1019 EDA_ITEM* item = m_frame->GetItem( rolloverItem );
1020
1021 if( item && !( item->GetFlags() & IS_ROLLOVER ) )
1022 {
1023 item->SetFlags( IS_ROLLOVER );
1024 lastRolloverItem = rolloverItem;
1025
1026 if( item->Type() == SCH_FIELD_T )
1027 m_frame->GetCanvas()->GetView()->Update( item->GetParent() );
1028 else
1029 m_frame->GetCanvas()->GetView()->Update( item );
1030 }
1031 }
1032
1033 if( m_frame->ToolStackIsEmpty() )
1034 {
1035 if( displayWireCursor )
1036 {
1037 m_nonModifiedCursor = KICURSOR::LINE_WIRE_ADD;
1038 }
1039 else if( displayBusCursor )
1040 {
1041 m_nonModifiedCursor = KICURSOR::LINE_BUS;
1042 }
1043 else if( displayLineCursor )
1044 {
1045 m_nonModifiedCursor = KICURSOR::LINE_GRAPHIC;
1046 }
1047 else if( rolloverItem != niluuid )
1048 {
1049 m_nonModifiedCursor = KICURSOR::HAND;
1050 }
1051 else if( !m_selection.Empty()
1052 && drag_action == MOUSE_DRAG_ACTION::DRAG_SELECTED
1053 && evt->HasPosition()
1054 && selectionContains( evt->Position() ) ) //move/drag option prediction
1055 {
1056 m_nonModifiedCursor = KICURSOR::MOVING;
1057 }
1058 else
1059 {
1060 m_nonModifiedCursor = KICURSOR::ARROW;
1061 }
1062 }
1063 }
1064
1065 m_disambiguateTimer.Stop();
1066
1067 // Shutting down; clear the selection
1069
1070 return 0;
1071}
1072
1073
1075 SCH_ITEM* aItem )
1076{
1077 VECTOR2I pos = aGrid.BestSnapAnchor( aEvent->Position(), aGrid.GetItemGrid( aItem ) );
1078
1081 && aItem->IsPointClickableAnchor( pos ) )
1082 {
1084
1085 if( aItem->Type() == SCH_BUS_BUS_ENTRY_T )
1086 {
1087 newEvt = EE_ACTIONS::drawBus.MakeEvent();
1088 }
1089 else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
1090 {
1091 SCH_BUS_WIRE_ENTRY* busEntry = static_cast<SCH_BUS_WIRE_ENTRY*>( aItem );
1092
1093 if( !busEntry->m_connected_bus_item )
1094 newEvt = EE_ACTIONS::drawBus.MakeEvent();
1095 }
1096 else if( aItem->Type() == SCH_LINE_T )
1097 {
1098 SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
1099
1100 if( line->IsBus() )
1101 newEvt = EE_ACTIONS::drawBus.MakeEvent();
1102 else if( line->IsGraphicLine() )
1103 newEvt = EE_ACTIONS::drawLines.MakeEvent();
1104 }
1105 else if( aItem->Type() == SCH_LABEL_T || aItem->Type() == SCH_HIER_LABEL_T
1106 || aItem->Type() == SCH_SHEET_PIN_T )
1107 {
1108 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
1109 SCH_CONNECTION possibleConnection( label->Schematic()->ConnectionGraph() );
1110 possibleConnection.ConfigureFromLabel( label->GetShownText( false ) );
1111
1112 if( possibleConnection.IsBus() )
1113 newEvt = EE_ACTIONS::drawBus.MakeEvent();
1114 }
1115 else if( aItem->Type() == SCH_SYMBOL_T )
1116 {
1117 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( aItem );
1118 const SCH_PIN* pin = symbol->GetPin( pos );
1119
1120 if( !pin )
1121 return OPT_TOOL_EVENT();
1122
1123 if( !pin->IsVisible()
1126 {
1127 return OPT_TOOL_EVENT();
1128 }
1129 }
1130
1131 newEvt->SetMousePosition( pos );
1132 newEvt->SetHasPosition( true );
1133 newEvt->SetForceImmediate( true );
1134
1135 getViewControls()->ForceCursorPosition( true, pos );
1136
1137 return newEvt;
1138 }
1139
1140 return OPT_TOOL_EVENT();
1141}
1142
1143
1145{
1146 wxMouseState keyboardState = wxGetMouseState();
1147
1148 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
1149 keyboardState.AltDown() );
1150
1151 m_skip_heuristics = true;
1154 m_skip_heuristics = false;
1155
1156 return 0;
1157}
1158
1159
1160void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
1161{
1163 {
1164 wxMouseState keyboardState = wxGetMouseState();
1165
1166 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(),
1167 keyboardState.AltDown() );
1168
1169 if( m_additive )
1170 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD );
1171 else if( m_subtractive )
1172 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT );
1173 else if( m_exclusive_or )
1174 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR );
1175 else
1177 }
1178}
1179
1180
1182{
1183 return m_selection;
1184}
1185
1186
1188 const std::vector<KICAD_T>& aScanTypes )
1189{
1190 int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1191 int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() / 2 );
1192 aCollector.m_Threshold = std::max( pixelThreshold, gridThreshold );
1194
1195 if( m_isSymbolEditor )
1196 {
1197 LIB_SYMBOL* symbol = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
1198
1199 if( !symbol )
1200 return false;
1201
1202 aCollector.Collect( symbol->GetDrawItems(), aScanTypes, aWhere, m_unit, m_bodyStyle );
1203 }
1204 else
1205 {
1206 aCollector.Collect( m_frame->GetScreen(), aScanTypes, aWhere, m_unit, m_bodyStyle );
1207
1208 // If pins are disabled in the filter, they will be removed later. Let's add the parent
1209 // so that people can use pins to select symbols in this case.
1210 if( !m_filter.pins )
1211 {
1212 int originalCount = aCollector.GetCount();
1213
1214 for( int ii = 0; ii < originalCount; ++ii )
1215 {
1216 if( aCollector[ii]->Type() == SCH_PIN_T )
1217 {
1218 SCH_PIN* pin = static_cast<SCH_PIN*>( aCollector[ii] );
1219
1220 if( !aCollector.HasItem( pin->GetParentSymbol() ) )
1221 aCollector.Append( pin->GetParentSymbol() );
1222 }
1223 }
1224 }
1225 }
1226
1227 return aCollector.GetCount() > 0;
1228}
1229
1230
1232 bool aCheckLocked, bool aSelectedOnly )
1233{
1234 SYMBOL_EDIT_FRAME* symbolEditorFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
1235
1236 for( int i = collector.GetCount() - 1; i >= 0; --i )
1237 {
1238 if( symbolEditorFrame )
1239 {
1240 // Do not select invisible items if they are not displayed
1241 EDA_ITEM* item = collector[i];
1242
1243 if( item->Type() == SCH_FIELD_T )
1244 {
1245 if( !static_cast<SCH_FIELD*>( item )->IsVisible()
1246 && !symbolEditorFrame->GetShowInvisibleFields() )
1247 {
1248 collector.Remove( i );
1249 continue;
1250 }
1251 }
1252 else if( item->Type() == SCH_PIN_T )
1253 {
1254 if( !static_cast<SCH_PIN*>( item )->IsVisible()
1255 && !symbolEditorFrame->GetShowInvisiblePins() )
1256 {
1257 collector.Remove( i );
1258 continue;
1259 }
1260 }
1261 }
1262
1263 if( !Selectable( collector[i], &aWhere ) )
1264 {
1265 collector.Remove( i );
1266 continue;
1267 }
1268
1269 if( aCheckLocked && collector[i]->IsLocked() )
1270 {
1271 collector.Remove( i );
1272 continue;
1273 }
1274
1275 if( !itemPassesFilter( collector[i] ) )
1276 {
1277 collector.Remove( i );
1278 continue;
1279 }
1280
1281 if( aSelectedOnly && !collector[i]->IsSelected() )
1282 {
1283 collector.Remove( i );
1284 continue;
1285 }
1286 }
1287
1288 // Apply some ugly heuristics to avoid disambiguation menus whenever possible
1289 if( collector.GetCount() > 1 && !m_skip_heuristics )
1290 GuessSelectionCandidates( collector, aWhere );
1291}
1292
1293
1295 EDA_ITEM** aItem, bool* aSelectionCancelledFlag, bool aAdd,
1296 bool aSubtract, bool aExclusiveOr )
1297{
1299
1300 // If still more than one item we're going to have to ask the user.
1301 if( aCollector.GetCount() > 1 )
1302 {
1303 // Try to call selectionMenu via RunAction() to avoid event-loop contention
1304 // But it we cannot handle the event, then we don't have an active tool loop, so
1305 // handle it directly.
1306 if( !m_toolMgr->RunAction<COLLECTOR*>( EE_ACTIONS::selectionMenu, &aCollector ) )
1307 {
1308 if( !doSelectionMenu( &aCollector ) )
1309 aCollector.m_MenuCancelled = true;
1310 }
1311
1312 if( aCollector.m_MenuCancelled )
1313 {
1314 if( aSelectionCancelledFlag )
1315 *aSelectionCancelledFlag = true;
1316
1317 return false;
1318 }
1319 }
1320
1321 if( !aAdd && !aSubtract && !aExclusiveOr )
1323
1324 int addedCount = 0;
1325 bool anySubtracted = false;
1326
1327 if( aCollector.GetCount() > 0 )
1328 {
1329 for( int i = 0; i < aCollector.GetCount(); ++i )
1330 {
1331 EDA_ITEM_FLAGS flags = 0;
1332 bool isLine = aCollector[i]->Type() == SCH_LINE_T;
1333
1334 // Handle line ends specially
1335 if( isLine )
1336 {
1337 SCH_LINE* line = (SCH_LINE*) aCollector[i];
1338
1339 if( line->GetStartPoint().Distance( aWhere ) <= aCollector.m_Threshold )
1340 flags = STARTPOINT;
1341 else if( line->GetEndPoint().Distance( aWhere ) <= aCollector.m_Threshold )
1342 flags = ENDPOINT;
1343 else
1344 flags = STARTPOINT | ENDPOINT;
1345 }
1346
1347 if( aSubtract
1348 || ( aExclusiveOr && aCollector[i]->IsSelected()
1349 && ( !isLine || ( isLine && aCollector[i]->HasFlag( flags ) ) ) ) )
1350 {
1351 aCollector[i]->ClearFlags( flags );
1352
1353 // Need to update end shadows after ctrl-click unselecting one of two selected
1354 // endpoints.
1355 if( isLine )
1356 getView()->Update( aCollector[i] );
1357
1358 if( !aCollector[i]->HasFlag( STARTPOINT ) && !aCollector[i]->HasFlag( ENDPOINT ) )
1359 {
1360 unselect( aCollector[i] );
1361 anySubtracted = true;
1362 }
1363 }
1364 else
1365 {
1366 aCollector[i]->SetFlags( flags );
1367 select( aCollector[i] );
1368 addedCount++;
1369 }
1370 }
1371 }
1372
1373 if( addedCount == 1 )
1374 {
1376
1377 if( aItem && aCollector.GetCount() == 1 )
1378 *aItem = aCollector[0];
1379
1380 return true;
1381 }
1382 else if( addedCount > 1 )
1383 {
1385 return true;
1386 }
1387 else if( anySubtracted )
1388 {
1390 return true;
1391 }
1392
1393 return false;
1394}
1395
1396
1398 const std::vector<KICAD_T>& aScanTypes,
1399 EDA_ITEM** aItem, bool* aSelectionCancelledFlag,
1400 bool aCheckLocked, bool aAdd, bool aSubtract,
1401 bool aExclusiveOr )
1402{
1403 EE_COLLECTOR collector;
1404
1405 if( !CollectHits( collector, aWhere, aScanTypes ) )
1406 return false;
1407
1408 narrowSelection( collector, aWhere, aCheckLocked, aSubtract );
1409
1410 return selectPoint( collector, aWhere, aItem, aSelectionCancelledFlag, aAdd, aSubtract,
1411 aExclusiveOr );
1412}
1413
1414
1416{
1417 m_multiple = true; // Multiple selection mode is active
1418 KIGFX::VIEW* view = getView();
1419
1420 // hold all visible items
1421 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
1422 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> sheetPins;
1423
1424 // Filter the view items based on the selection box
1425 BOX2I selectionBox;
1426
1427 selectionBox.SetMaximum();
1428 view->Query( selectionBox, selectedItems ); // Get the list of selected items
1429
1430 // Sheet pins aren't in the view; add them by hand
1431 for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
1432 {
1433 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
1434
1435 if( sheet )
1436 {
1437 int layer = pair.second;
1438
1439 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1440 sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) );
1441 }
1442 }
1443
1444 selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() );
1445
1446 for( const std::pair<KIGFX::VIEW_ITEM*, int>& item_pair : selectedItems )
1447 {
1448 if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( item_pair.first ) )
1449 {
1450 if( Selectable( item ) && itemPassesFilter( item ) )
1451 {
1452 if( item->Type() == SCH_LINE_T )
1453 item->SetFlags( STARTPOINT | ENDPOINT );
1454
1455 select( item );
1456 }
1457 }
1458 }
1459
1460 m_multiple = false;
1461
1463
1464 return 0;
1465}
1466
1468{
1469 m_multiple = true; // Multiple selection mode is active
1470 KIGFX::VIEW* view = getView();
1471
1472 // hold all visible items
1473 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
1474
1475 // Filter the view items based on the selection box
1476 BOX2I selectionBox;
1477
1478 selectionBox.SetMaximum();
1479 view->Query( selectionBox, selectedItems ); // Get the list of selected items
1480
1481 for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems )
1482 {
1483 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( pair.first );
1484
1485 if( sheet )
1486 {
1487 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1488 {
1489 EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pin );
1490
1491 if( item && Selectable( item ) )
1492 unselect( item );
1493 }
1494 }
1495
1496 if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first ) )
1497 {
1498 if( Selectable( item ) )
1499 unselect( item );
1500 }
1501 }
1502
1503 m_multiple = false;
1504
1506
1507 return 0;
1508}
1509
1510
1512{
1513 // Prefer exact hits to sloppy ones
1514 std::set<EDA_ITEM*> exactHits;
1515
1516 for( int i = collector.GetCount() - 1; i >= 0; --i )
1517 {
1518 EDA_ITEM* item = collector[ i ];
1519 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1520 SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( item );
1521 SCH_TABLE* table = dynamic_cast<SCH_TABLE*>( item );
1522
1523 // Lines are hard to hit. Give them a bit more slop to still be considered "exact".
1524 if( line || ( shape && shape->GetShape() == SHAPE_T::POLY )
1525 || ( shape && shape->GetShape() == SHAPE_T::ARC ) )
1526 {
1527 int pixelThreshold = KiROUND( getView()->ToWorld( 6 ) );
1528
1529 if( item->HitTest( aPos, pixelThreshold ) )
1530 exactHits.insert( item );
1531 }
1532 else if( table )
1533 {
1534 // Consider table cells exact, but not the table itself
1535 }
1536 else
1537 {
1538
1540 item->SetFlags( SHOW_ELEC_TYPE );
1541
1542 if( item->HitTest( aPos, 0 ) )
1543 exactHits.insert( item );
1544
1545 item->ClearFlags( SHOW_ELEC_TYPE );
1546 }
1547 }
1548
1549 if( exactHits.size() > 0 && exactHits.size() < (unsigned) collector.GetCount() )
1550 {
1551 for( int i = collector.GetCount() - 1; i >= 0; --i )
1552 {
1553 EDA_ITEM* item = collector[ i ];
1554
1555 if( !exactHits.contains( item ) )
1556 collector.Transfer( item );
1557 }
1558 }
1559
1560 // Find the closest item. (Note that at this point all hits are either exact or non-exact.)
1561 SEG poss( aPos, aPos );
1562 EDA_ITEM* closest = nullptr;
1563 int closestDist = INT_MAX / 4;
1564
1565 for( EDA_ITEM* item : collector )
1566 {
1567 BOX2I bbox = item->GetBoundingBox();
1568 int dist = INT_MAX / 4;
1569
1570 // A dominating item is one that would unfairly win distance tests
1571 // and mask out other items. For example, a filled rectangle "wins"
1572 // with a zero distance over anything inside it.
1573 bool dominating = false;
1574
1575 if( exactHits.contains( item ) )
1576 {
1577 if( item->Type() == SCH_PIN_T || item->Type() == SCH_JUNCTION_T )
1578 {
1579 closest = item;
1580 break;
1581 }
1582
1583 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1584 SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( item );
1585 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
1586 EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( item );
1587 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1588
1589 if( line )
1590 {
1591 dist = line->GetSeg().Distance( aPos );
1592 }
1593 else if( field )
1594 {
1595 BOX2I box = field->GetBoundingBox();
1596 EDA_ANGLE orient = field->GetTextAngle();
1597
1598 if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
1599 {
1600 if( static_cast<SCH_SYMBOL*>( field->GetParent() )->GetTransform().y1 )
1601 {
1602 if( orient.IsHorizontal() )
1603 orient = ANGLE_VERTICAL;
1604 else
1605 orient = ANGLE_HORIZONTAL;
1606 }
1607 }
1608
1609 field->GetEffectiveTextShape( false, box, orient )
1610 ->Collide( poss, INT_MAX / 4, &dist );
1611 }
1612 else if( text )
1613 {
1614 text->GetEffectiveTextShape( false )->Collide( poss, INT_MAX / 4, &dist );
1615 }
1616 else if( shape )
1617 {
1618 std::vector<SHAPE*> shapes = shape->MakeEffectiveShapes();
1619
1620 for( SHAPE* s : shapes )
1621 {
1622 int shapeDist = dist;
1623 s->Collide( poss, INT_MAX / 4, &shapeDist );
1624
1625 if( shapeDist < dist )
1626 dist = shapeDist;
1627
1628 delete s;
1629 }
1630
1631 // Filled shapes win hit tests anywhere inside them
1632 dominating = shape->IsFilled();
1633 }
1634 else if( symbol )
1635 {
1636 bbox = symbol->GetBodyBoundingBox();
1637
1638 SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1639
1640 if( bbox.Contains( aPos ) )
1641 dist = bbox.GetCenter().Distance( aPos );
1642 else
1643 rect.Collide( poss, closestDist, &dist );
1644 }
1645 else
1646 {
1647 dist = bbox.GetCenter().Distance( aPos );
1648 }
1649 }
1650 else
1651 {
1652 SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
1653 rect.Collide( poss, collector.m_Threshold, &dist );
1654 }
1655
1656 // Don't promote dominating items to be the closest item
1657 // (they'll always win) - they'll still be available for selection, but they
1658 // won't boot out worthy competitors.
1659 if ( !dominating )
1660 {
1661 if( dist == closestDist )
1662 {
1663 if( item->GetParent() == closest )
1664 closest = item;
1665 }
1666 else if( dist < closestDist )
1667 {
1668 closestDist = dist;
1669 closest = item;
1670 }
1671 }
1672 }
1673
1674 // Construct a tight box (1/2 height and width) around the center of the closest item.
1675 // All items which exist at least partly outside this box have sufficient other areas
1676 // for selection and can be dropped.
1677 if( closest ) // Don't try and get a tight bbox if nothing is near the mouse pointer
1678 {
1679 BOX2I tightBox = closest->GetBoundingBox();
1680 tightBox.Inflate( -tightBox.GetWidth() / 4, -tightBox.GetHeight() / 4 );
1681
1682 for( int i = collector.GetCount() - 1; i >= 0; --i )
1683 {
1684 EDA_ITEM* item = collector[i];
1685
1686 if( item == closest )
1687 continue;
1688
1689 if( !item->HitTest( tightBox, true ) )
1690 collector.Transfer( item );
1691 }
1692 }
1693}
1694
1695
1696EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const std::vector<KICAD_T>& aScanTypes,
1697 bool aPromoteCellSelections )
1698{
1699 bool anyUnselected = false;
1700 bool anySelected = false;
1701
1702 if( m_selection.Empty() )
1703 {
1704 VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );
1705
1707 SelectPoint( cursorPos, aScanTypes );
1708 m_selection.SetIsHover( true );
1710 }
1711 else // Trim an existing selection by aFilterList
1712 {
1713 bool isMoving = false;
1714
1715 for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
1716 {
1717 EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
1718 isMoving |= static_cast<SCH_ITEM*>( item )->IsMoving();
1719
1720 if( !item->IsType( aScanTypes ) )
1721 {
1722 unselect( item );
1723 anyUnselected = true;
1724 }
1725 }
1726
1727 if( !isMoving )
1729 }
1730
1731 if( aPromoteCellSelections )
1732 {
1733 std::set<EDA_ITEM*> parents;
1734
1735 for( int i = (int) m_selection.GetSize() - 1; i >= 0; --i )
1736 {
1737 EDA_ITEM* item = (EDA_ITEM*) m_selection.GetItem( i );
1738
1739 if( item->Type() == SCH_TABLECELL_T )
1740 {
1741 parents.insert( item->GetParent() );
1742 unselect( item );
1743 anyUnselected = true;
1744 }
1745 }
1746
1747 for( EDA_ITEM* parent : parents )
1748 {
1749 if( !parent->IsSelected() )
1750 {
1751 select( parent );
1752 anySelected = true;
1753 }
1754 }
1755 }
1756
1757 if( anyUnselected )
1759
1760 if( anySelected )
1762
1763 return m_selection;
1764}
1765
1766
1768{
1769 if( !aItem )
1770 return false;
1771
1772 // Locking is not yet exposed uniformly in the schematic
1773#if 0
1774 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
1775 {
1776 if( schItem->IsLocked() && !m_filter.lockedItems )
1777 return false;
1778 }
1779#endif
1780
1781 switch( aItem->Type() )
1782 {
1783 case SCH_SYMBOL_T:
1784 case SCH_SHEET_T:
1785 if( !m_filter.symbols )
1786 return false;
1787
1788 break;
1789
1790 case SCH_PIN_T:
1791 case SCH_SHEET_PIN_T:
1792 if( !m_filter.pins )
1793 return false;
1794
1795 break;
1796
1797 case SCH_LINE_T:
1798 {
1799 switch( static_cast<SCH_LINE*>( aItem )->GetLayer() )
1800 {
1801 case LAYER_WIRE:
1802 case LAYER_BUS:
1803 if( !m_filter.wires )
1804 return false;
1805
1806 break;
1807
1808 default:
1809 if( !m_filter.graphics )
1810 return false;
1811 }
1812
1813 break;
1814 }
1815
1816 case SCH_SHAPE_T:
1817 if( !m_filter.graphics )
1818 return false;
1819
1820 break;
1821
1822 case SCH_TEXT_T:
1823 case SCH_TEXTBOX_T:
1824 case SCH_TABLE_T:
1825 case SCH_TABLECELL_T:
1826 case SCH_FIELD_T:
1827 if( !m_filter.text )
1828 return false;
1829
1830 break;
1831
1832 case SCH_LABEL_T:
1833 case SCH_GLOBAL_LABEL_T:
1834 case SCH_HIER_LABEL_T:
1835 if( !m_filter.labels )
1836 return false;
1837
1838 break;
1839
1840 case SCH_BITMAP_T:
1841 if( !m_filter.images )
1842 return false;
1843
1844 break;
1845
1846 default:
1847 if( !m_filter.otherItems )
1848 return false;
1849
1850 break;
1851 }
1852
1853 return true;
1854}
1855
1856
1858{
1859 VECTOR2I refP( 0, 0 );
1860
1861 if( m_selection.Size() > 0 )
1862 refP = static_cast<SCH_ITEM*>( m_selection.GetTopLeftItem() )->GetPosition();
1863
1865}
1866
1867
1868// Some navigation actions are allowed in selectMultiple
1878 &ACTIONS::zoomFitObjects, nullptr };
1879
1880
1882{
1883 // Block selection not allowed in symbol viewer frame: no actual code to handle
1884 // a selection, so return to avoid to draw a selection rectangle, and to avoid crashes.
1885 if( m_frame->IsType( FRAME_T::FRAME_SCH_VIEWER ) )
1886 return false;
1887
1888 bool cancelled = false; // Was the tool canceled while it was running?
1889 m_multiple = true; // Multiple selection mode is active
1890 KIGFX::VIEW* view = getView();
1891
1893 view->Add( &area );
1894
1895 while( TOOL_EVENT* evt = Wait() )
1896 {
1897 int width = area.GetEnd().x - area.GetOrigin().x;
1898 int height = area.GetEnd().y - area.GetOrigin().y;
1899
1900 /* Selection mode depends on direction of drag-selection:
1901 * Left > Right : Select objects that are fully enclosed by selection
1902 * Right > Left : Select objects that are crossed by selection
1903 */
1904 bool isGreedy = width < 0;
1905
1906 if( view->IsMirroredX() )
1907 isGreedy = !isGreedy;
1908
1909 m_frame->GetCanvas()->SetCurrentCursor( isGreedy ? KICURSOR::SELECT_LASSO
1910 : KICURSOR::SELECT_WINDOW );
1911
1912 if( evt->IsCancelInteractive() || evt->IsActivate() )
1913 {
1914 cancelled = true;
1915 break;
1916 }
1917
1918 if( evt->IsDrag( BUT_LEFT ) )
1919 {
1922
1923 // Start drawing a selection box
1924 area.SetOrigin( evt->DragOrigin() );
1925 area.SetEnd( evt->Position() );
1928 area.SetExclusiveOr( false );
1929
1930 view->SetVisible( &area, true );
1931 view->Update( &area );
1932 getViewControls()->SetAutoPan( true );
1933 }
1934
1935 if( evt->IsMouseUp( BUT_LEFT ) )
1936 {
1937 getViewControls()->SetAutoPan( false );
1938
1939 // End drawing the selection box
1940 view->SetVisible( &area, false );
1941
1942 // Fetch items from the RTree that are in our area of interest
1943 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> nearbyViewItems;
1944 view->Query( area.ViewBBox(), nearbyViewItems );
1945
1946 // Build lists of nearby items and their children
1947 std::unordered_set<EDA_ITEM*> nearbyItems;
1948 std::vector<EDA_ITEM*> nearbyChildren;
1949 std::vector<EDA_ITEM*> flaggedItems;
1950
1951 for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : nearbyViewItems )
1952 {
1953 if( EDA_ITEM* item = dynamic_cast<EDA_ITEM*>( pair.first ) )
1954 {
1955 if( nearbyItems.insert( item ).second )
1956 {
1957 item->ClearFlags( CANDIDATE );
1958
1959 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
1960 {
1961 sch_item->RunOnChildren(
1962 [&]( SCH_ITEM* aChild )
1963 {
1964 // Filter pins by unit
1965 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aChild ) )
1966 {
1967 int unit = pin->GetLibPin()->GetUnit();
1968
1969 if( unit && unit != pin->GetParentSymbol()->GetUnit() )
1970 return;
1971 }
1972
1973 nearbyChildren.push_back( aChild );
1974 } );
1975 }
1976 }
1977 }
1978 }
1979
1980 BOX2I selectionRect( area.GetOrigin(), VECTOR2I( width, height ) );
1981 selectionRect.Normalize();
1982
1983 bool anyAdded = false;
1984 bool anySubtracted = false;
1985
1986 auto selectItem =
1987 [&]( EDA_ITEM* aItem, EDA_ITEM_FLAGS flags )
1988 {
1989 if( m_subtractive || ( m_exclusive_or && aItem->IsSelected() ) )
1990 {
1991 if ( m_exclusive_or )
1992 aItem->XorFlags( flags );
1993 else
1994 aItem->ClearFlags( flags );
1995
1996 if( !aItem->HasFlag( STARTPOINT ) && !aItem->HasFlag( ENDPOINT ) )
1997 {
1998 unselect( aItem );
1999 anySubtracted = true;
2000 }
2001
2002 // We changed one line endpoint on a selected line,
2003 // update the view at least.
2004 if( flags && !anySubtracted )
2005 getView()->Update( aItem );
2006 }
2007 else
2008 {
2009 aItem->SetFlags( flags );
2010 select( aItem );
2011 anyAdded = true;
2012 }
2013 };
2014
2015 for( EDA_ITEM* item : nearbyItems )
2016 {
2017 bool selected = false;
2018 EDA_ITEM_FLAGS flags = 0;
2019
2021 item->SetFlags( SHOW_ELEC_TYPE );
2022
2023 if( Selectable( item ) && itemPassesFilter( item ) )
2024 {
2025 if( item->Type() == SCH_LINE_T )
2026 {
2027 SCH_LINE* line = static_cast<SCH_LINE*>( item );
2028
2029 if( ( isGreedy && line->HitTest( selectionRect, false ) )
2030 || ( selectionRect.Contains( line->GetEndPoint() )
2031 && selectionRect.Contains( line->GetStartPoint() ) ) )
2032 {
2033 selected = true;
2034 flags |= STARTPOINT | ENDPOINT;
2035 }
2036 else if( !isGreedy )
2037 {
2038 if( selectionRect.Contains( line->GetStartPoint() )
2039 && line->IsStartDangling() )
2040 {
2041 selected = true;
2042 flags |= STARTPOINT;
2043 }
2044
2045 if( selectionRect.Contains( line->GetEndPoint() )
2046 && line->IsEndDangling() )
2047 {
2048 selected = true;
2049 flags |= ENDPOINT;
2050 }
2051 }
2052 }
2053 else
2054 {
2055 selected = item->HitTest( selectionRect, !isGreedy );
2056 }
2057 }
2058
2059 if( selected )
2060 {
2061 item->SetFlags( CANDIDATE );
2062 flaggedItems.push_back( item );
2063 selectItem( item, flags );
2064 }
2065
2066 item->ClearFlags( SHOW_ELEC_TYPE );
2067 }
2068
2069 for( EDA_ITEM* item : nearbyChildren )
2070 {
2072 item->SetFlags( SHOW_ELEC_TYPE );
2073
2074 if( Selectable( item )
2075 && itemPassesFilter( item )
2076 && !item->GetParent()->HasFlag( CANDIDATE )
2077 && item->HitTest( selectionRect, !isGreedy ) )
2078 {
2079 selectItem( item, 0 );
2080 }
2081
2082 item->ClearFlags( SHOW_ELEC_TYPE );
2083 }
2084
2085 for( EDA_ITEM* item : flaggedItems )
2086 item->ClearFlags( CANDIDATE );
2087
2088 m_selection.SetIsHover( false );
2089
2090 // Inform other potentially interested tools
2091 if( anyAdded )
2093
2094 if( anySubtracted )
2096
2097 break; // Stop waiting for events
2098 }
2099
2100 // Allow some actions for navigation
2101 for( int i = 0; allowedActions[i]; ++i )
2102 {
2103 if( evt->IsAction( allowedActions[i] ) )
2104 {
2105 evt->SetPassEvent();
2106 break;
2107 }
2108 }
2109 }
2110
2111 getViewControls()->SetAutoPan( false );
2112
2113 // Stop drawing the selection box
2114 view->Remove( &area );
2115 m_multiple = false; // Multiple selection mode is inactive
2116
2117 if( !cancelled )
2119
2120 return cancelled;
2121}
2122
2123
2125{
2126 bool cancelled = false; // Was the tool canceled while it was running?
2127 m_multiple = true; // Multiple selection mode is active
2128
2129 for( SCH_TABLECELL* cell : aTable->GetCells() )
2130 {
2131 if( cell->IsSelected() )
2132 cell->SetFlags( CANDIDATE );
2133 else
2134 cell->ClearFlags( CANDIDATE );
2135 }
2136
2137 auto wasSelected =
2138 []( EDA_ITEM* aItem )
2139 {
2140 return ( aItem->GetFlags() & CANDIDATE ) > 0;
2141 };
2142
2143 while( TOOL_EVENT* evt = Wait() )
2144 {
2145 if( evt->IsCancelInteractive() || evt->IsActivate() )
2146 {
2147 cancelled = true;
2148 break;
2149 }
2150 else if( evt->IsDrag( BUT_LEFT ) )
2151 {
2152 getViewControls()->SetAutoPan( true );
2153
2154 BOX2I selectionRect( evt->DragOrigin(), evt->Position() - evt->DragOrigin() );
2155 selectionRect.Normalize();
2156
2157 for( SCH_TABLECELL* cell : aTable->GetCells() )
2158 {
2159 bool doSelect = false;
2160
2161 if( cell->HitTest( selectionRect, false ) )
2162 {
2163 if( m_subtractive )
2164 doSelect = false;
2165 else if( m_exclusive_or )
2166 doSelect = !wasSelected( cell );
2167 else
2168 doSelect = true;
2169 }
2170 else if( wasSelected( cell ) )
2171 {
2172 doSelect = m_additive || m_subtractive || m_exclusive_or;
2173 }
2174
2175 if( doSelect && !cell->IsSelected() )
2176 select( cell );
2177 else if( !doSelect && cell->IsSelected() )
2178 unselect( cell );
2179 }
2180 }
2181 else if( evt->IsMouseUp( BUT_LEFT ) )
2182 {
2183 m_selection.SetIsHover( false );
2184
2185 bool anyAdded = false;
2186 bool anySubtracted = false;
2187
2188 for( SCH_TABLECELL* cell : aTable->GetCells() )
2189 {
2190 if( cell->IsSelected() && !wasSelected( cell ) )
2191 anyAdded = true;
2192 else if( wasSelected( cell ) && !cell->IsSelected() )
2193 anySubtracted = true;
2194 }
2195
2196 // Inform other potentially interested tools
2197 if( anyAdded )
2199
2200 if( anySubtracted )
2202
2203 break; // Stop waiting for events
2204 }
2205 else
2206 {
2207 // Allow some actions for navigation
2208 for( int i = 0; allowedActions[i]; ++i )
2209 {
2210 if( evt->IsAction( allowedActions[i] ) )
2211 {
2212 evt->SetPassEvent();
2213 break;
2214 }
2215 }
2216 }
2217 }
2218
2219 getViewControls()->SetAutoPan( false );
2220
2221 m_multiple = false; // Multiple selection mode is inactive
2222
2223 if( !cancelled )
2225
2226 return cancelled;
2227}
2228
2229
2231{
2232 EE_COLLECTOR collector;
2233
2234 //TODO(snh): Reimplement after exposing KNN interface
2235 int pixelThreshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
2236 int gridThreshold = KiROUND( getView()->GetGAL()->GetGridSize().EuclideanNorm() );
2237 int thresholdMax = std::max( pixelThreshold, gridThreshold );
2238
2239 for( int threshold : { 0, thresholdMax/4, thresholdMax/2, thresholdMax } )
2240 {
2241 collector.m_Threshold = threshold;
2242 collector.Collect( m_frame->GetScreen(), connectedTypes, aPosition );
2243
2244 if( collector.GetCount() > 0 )
2245 break;
2246 }
2247
2248 return collector.GetCount() ? collector[ 0 ] : nullptr;
2249}
2250
2251
2253{
2254 VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
2255
2256 SelectPoint( cursorPos, connectedTypes );
2257 return 0;
2258}
2259
2260
2262{
2265
2266 if( m_selection.Empty() )
2267 return 0;
2268
2269 unsigned done = false;
2270
2272
2273 for( EDA_ITEM* selItem : m_selection.GetItems() )
2274 {
2275 if( selItem->Type() != SCH_LINE_T )
2276 continue;
2277
2278 SCH_LINE* line = static_cast<SCH_LINE*>( selItem );
2279
2280 std::set<SCH_ITEM*> conns = m_frame->GetScreen()->MarkConnections( line, false );
2281 for( SCH_ITEM* item : conns )
2282 {
2283 if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T,
2284 SCH_ITEM_LOCATE_GRAPHIC_LINE_T } )
2285 && !item->IsSelected() )
2286 {
2287 done = true;
2288 }
2289
2290 select( item );
2291 }
2292
2293 if( !done )
2294 {
2295 conns = m_frame->GetScreen()->MarkConnections( line, true );
2296
2297 for( SCH_ITEM* item : conns )
2298 select( item );
2299 }
2300 }
2301
2302 if( m_selection.GetSize() > 1 )
2304
2305 return 0;
2306}
2307
2308
2310{
2311 std::set<std::pair<SCH_TABLE*, int>> columns;
2312 bool added = false;
2313
2314 for( EDA_ITEM* item : m_selection )
2315 {
2316 if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
2317 {
2318 SCH_TABLE* table = static_cast<SCH_TABLE*>( cell->GetParent() );
2319 columns.insert( std::make_pair( table, cell->GetColumn() ) );
2320 }
2321 }
2322
2323 for( auto& [ table, col ] : columns )
2324 {
2325 for( int row = 0; row < table->GetRowCount(); ++row )
2326 {
2327 SCH_TABLECELL* cell = table->GetCell( row, col );
2328
2329 if( !cell->IsSelected() )
2330 {
2331 select( table->GetCell( row, col ) );
2332 added = true;
2333 }
2334 }
2335 }
2336
2337 if( added )
2339
2340 return 0;
2341}
2342
2343
2345{
2346 std::set<std::pair<SCH_TABLE*, int>> rows;
2347 bool added = false;
2348
2349 for( EDA_ITEM* item : m_selection )
2350 {
2351 if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
2352 {
2353 SCH_TABLE* table = static_cast<SCH_TABLE*>( cell->GetParent() );
2354 rows.insert( std::make_pair( table, cell->GetRow() ) );
2355 }
2356 }
2357
2358 for( auto& [ table, row ] : rows )
2359 {
2360 for( int col = 0; col < table->GetColCount(); ++col )
2361 {
2362 SCH_TABLECELL* cell = table->GetCell( row, col );
2363
2364 if( !cell->IsSelected() )
2365 {
2366 select( table->GetCell( row, col ) );
2367 added = true;
2368 }
2369 }
2370 }
2371
2372 if( added )
2374
2375 return 0;
2376}
2377
2378
2380{
2381 std::set<SCH_TABLE*> tables;
2382 bool added = false;
2383
2384 for( EDA_ITEM* item : m_selection )
2385 {
2386 if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( item ) )
2387 tables.insert( static_cast<SCH_TABLE*>( cell->GetParent() ) );
2388 }
2389
2391
2392 for( SCH_TABLE* table : tables )
2393 {
2394 if( !table->IsSelected() )
2395 {
2396 select( table );
2397 added = true;
2398 }
2399 }
2400
2401 if( added )
2403
2404 return 0;
2405}
2406
2407
2409{
2411 return 0;
2412}
2413
2414
2416{
2417 if( aBBox.GetWidth() == 0 )
2418 return;
2419
2420 BOX2I bbox = aBBox;
2421 bbox.Normalize();
2422
2423 VECTOR2I bbSize = bbox.Inflate( KiROUND( bbox.GetWidth() * 0.2f ) ).GetSize();
2424 VECTOR2D screenSize = getView()->GetViewport().GetSize();
2425
2426 // This code tries to come up with a zoom factor that doesn't simply zoom in to the cross
2427 // probed symbol, but instead shows a reasonable amount of the circuit around it to provide
2428 // context. This reduces the need to manually change the zoom because it's too close.
2429
2430 // Using the default text height as a constant to compare against, use the height of the
2431 // bounding box of visible items for a footprint to figure out if this is a big symbol (like
2432 // a processor) or a small symbol (like a resistor). This ratio is not useful by itself as a
2433 // scaling factor. It must be "bent" to provide good scaling at varying symbol sizes. Bigger
2434 // symbols need less scaling than small ones.
2435 double currTextHeight = schIUScale.MilsToIU( DEFAULT_TEXT_SIZE );
2436
2437 double compRatio = bbSize.y / currTextHeight; // Ratio of symbol to text height
2438 double compRatioBent = 1.0;
2439
2440 // LUT to scale zoom ratio to provide reasonable schematic context. Must work with symbols
2441 // of varying sizes (e.g. 0402 package and 200 pin BGA).
2442 // Each entry represents a compRatio (symbol height / default text height) and an amount to
2443 // scale by.
2444 std::vector<std::pair<double, double>> lut{ { 1.25, 16 },
2445 { 2.5, 12 },
2446 { 5, 8 },
2447 { 6, 6 },
2448 { 10, 4 },
2449 { 20, 2 },
2450 { 40, 1.5 },
2451 { 100, 1 } };
2452
2453 std::vector<std::pair<double, double>>::iterator it;
2454
2455 // Large symbol default is last LUT entry (1:1).
2456 compRatioBent = lut.back().second;
2457
2458 // Use LUT to do linear interpolation of "compRatio" within "first", then use that result to
2459 // linearly interpolate "second" which gives the scaling factor needed.
2460 if( compRatio >= lut.front().first )
2461 {
2462 for( it = lut.begin(); it < lut.end() - 1; ++it )
2463 {
2464 if( it->first <= compRatio && next( it )->first >= compRatio )
2465 {
2466 double diffx = compRatio - it->first;
2467 double diffn = next( it )->first - it->first;
2468
2469 compRatioBent = it->second + ( next( it )->second - it->second ) * diffx / diffn;
2470 break; // We have our interpolated value
2471 }
2472 }
2473 }
2474 else
2475 {
2476 compRatioBent = lut.front().second; // Small symbol default is first entry
2477 }
2478
2479 // This is similar to the original KiCad code that scaled the zoom to make sure symbols were
2480 // visible on screen. It's simply a ratio of screen size to symbol size, and its job is to
2481 // zoom in to make the component fullscreen. Earlier in the code the symbol BBox is given a
2482 // 20% margin to add some breathing room. We compare the height of this enlarged symbol bbox
2483 // to the default text height. If a symbol will end up with the sides clipped, we adjust
2484 // later to make sure it fits on screen.
2485 screenSize.x = std::max( 10.0, screenSize.x );
2486 screenSize.y = std::max( 10.0, screenSize.y );
2487 double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
2488
2489 // Original KiCad code for how much to scale the zoom
2490 double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
2491 fabs( bbSize.y / screenSize.y ) );
2492
2493 // If the width of the part we're probing is bigger than what the screen width will be after
2494 // the zoom, then punt and use the KiCad zoom algorithm since it guarantees the part's width
2495 // will be encompassed within the screen.
2496 if( bbSize.x > screenSize.x * ratio * compRatioBent )
2497 {
2498 // Use standard KiCad zoom for parts too wide to fit on screen/
2499 ratio = kicadRatio;
2500 compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
2501 wxLogTrace( "CROSS_PROBE_SCALE",
2502 "Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f", ratio );
2503 }
2504
2505 // Now that "compRatioBent" holds our final scaling factor we apply it to the original
2506 // fullscreen zoom ratio to arrive at the final ratio itself.
2507 ratio *= compRatioBent;
2508
2509 bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
2510
2511 // Try not to zoom on every cross-probe; it gets very noisy
2512 if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
2513 getView()->SetScale( getView()->GetScale() / ratio );
2514}
2515
2516
2517void EE_SELECTION_TOOL::SyncSelection( const std::optional<SCH_SHEET_PATH>& targetSheetPath,
2518 SCH_ITEM* focusItem, const std::vector<SCH_ITEM*>& items )
2519{
2520 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
2521
2522 if( !editFrame )
2523 return;
2524
2525 if( targetSheetPath && targetSheetPath != editFrame->Schematic().CurrentSheet() )
2526 {
2527 editFrame->Schematic().SetCurrentSheet( *targetSheetPath );
2528 editFrame->DisplayCurrentSheet();
2529 }
2530
2531 ClearSelection( items.size() > 0 ? true /*quiet mode*/ : false );
2532
2533 // Perform individual selection of each item before processing the event.
2534 for( SCH_ITEM* item : items )
2535 {
2536 SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( item->GetParent() );
2537
2538 // Make sure we only select items on the current screen
2539 if( m_frame->GetScreen()->CheckIfOnDrawList( item )
2540 || ( parent && m_frame->GetScreen()->CheckIfOnDrawList( parent ) ) )
2541 {
2542 select( item );
2543 }
2544 }
2545
2547
2548 if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
2549 {
2551 {
2553 ZoomFitCrossProbeBBox( bbox );
2554
2555 editFrame->FocusOnItem( focusItem );
2556
2557 if( !focusItem )
2558 editFrame->FocusOnLocation( bbox.Centre() );
2559 }
2560 }
2561
2562 if( m_selection.Size() > 0 )
2564}
2565
2566
2568{
2570
2571 if( m_isSymbolEditor )
2572 {
2573 LIB_SYMBOL* start = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
2574
2575 for( SCH_ITEM& item : start->GetDrawItems() )
2576 {
2577 if( item.IsSelected() )
2578 select( &item );
2579 }
2580 }
2581 else
2582 {
2583 for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
2584 {
2585 // If the field and symbol are selected, only use the symbol
2586 if( item->IsSelected() )
2587 {
2588 select( item );
2589 }
2590 else
2591 {
2592 item->RunOnChildren(
2593 [&]( SCH_ITEM* aChild )
2594 {
2595 if( aChild->IsSelected() )
2596 select( aChild );
2597 } );
2598 }
2599 }
2600 }
2601
2603
2604 // Inform other potentially interested tools
2606}
2607
2608
2609bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
2610 bool checkVisibilityOnly ) const
2611{
2612 // NOTE: in the future this is where Eeschema layer/itemtype visibility will be handled
2613
2614 SYMBOL_EDIT_FRAME* symEditFrame = dynamic_cast<SYMBOL_EDIT_FRAME*>( m_frame );
2615
2616 // Do not allow selection of anything except fields when the current symbol in the symbol
2617 // editor is a derived symbol.
2618 if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != SCH_FIELD_T )
2619 return false;
2620
2621 switch( aItem->Type() )
2622 {
2623 case SCH_PIN_T:
2624 {
2625 const SCH_PIN* pin = static_cast<const SCH_PIN*>( aItem );
2626
2627 if( symEditFrame )
2628 {
2629 if( pin->GetUnit() && pin->GetUnit() != symEditFrame->GetUnit() )
2630 return false;
2631
2632 if( pin->GetBodyStyle() && pin->GetBodyStyle() != symEditFrame->GetBodyStyle() )
2633 return false;
2634 }
2635
2636 if( !pin->IsVisible() && !m_frame->GetShowAllPins() )
2637 return false;
2638
2639 if( !m_filter.pins )
2640 {
2641 // Pin anchors have to be allowed for auto-starting wires.
2642 if( aPos )
2643 {
2645 GRID_HELPER_GRIDS pinGrid = grid.GetItemGrid( pin );
2646
2647 if( pin->IsPointClickableAnchor( grid.BestSnapAnchor( *aPos, pinGrid ) ) )
2648 return true;
2649 }
2650
2651 return false;
2652 }
2653
2654 break;
2655 }
2656
2659 return false;
2660
2661 break;
2662
2663 case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
2664 return false;
2665
2666 case SCH_FIELD_T: // SCH_FIELD objects are not unit/body-style-specific.
2667 {
2668 const SCH_FIELD* field = static_cast<const SCH_FIELD*>( aItem );
2669
2670 if( !field->IsVisible() && !( symEditFrame && symEditFrame->GetShowInvisibleFields() ) )
2671 return false;
2672
2673 break;
2674 }
2675
2676 case SCH_SHAPE_T:
2677 case SCH_TEXT_T:
2678 case SCH_TEXTBOX_T:
2679 if( symEditFrame )
2680 {
2681 const SCH_ITEM* sch_item = static_cast<const SCH_ITEM*>( aItem );
2682
2683 if( sch_item->GetUnit() && sch_item->GetUnit() != symEditFrame->GetUnit() )
2684 return false;
2685
2686 if( sch_item->GetBodyStyle() && sch_item->GetBodyStyle() != symEditFrame->GetBodyStyle() )
2687 return false;
2688 }
2689
2690 break;
2691
2692 case SCH_MARKER_T: // Always selectable
2693 return true;
2694
2695 case SCH_TABLECELL_T:
2696 {
2697 const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aItem );
2698
2699 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2700 return false;
2701
2702 break;
2703 }
2704
2705 default: // Suppress warnings
2706 break;
2707 }
2708
2709 return true;
2710}
2711
2712
2714{
2715 if( m_selection.Empty() )
2716 return;
2717
2718 while( m_selection.GetSize() )
2720
2721 getView()->Update( &m_selection );
2722
2723 m_selection.SetIsHover( false );
2725
2726 // Inform other potentially interested tools
2727 if( !aQuietMode )
2729}
2730
2731
2733{
2734 highlight( aItem, SELECTED, &m_selection );
2735}
2736
2737
2739{
2740 unhighlight( aItem, SELECTED, &m_selection );
2741}
2742
2743
2744void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
2745{
2746 if( aMode == SELECTED )
2747 aItem->SetSelected();
2748 else if( aMode == BRIGHTENED )
2749 aItem->SetBrightened();
2750
2751 if( aGroup )
2752 aGroup->Add( aItem );
2753
2754 // Highlight pins and fields. (All the other symbol children are currently only
2755 // represented in the LIB_SYMBOL and will inherit the settings of the parent symbol.)
2756 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
2757 {
2758 sch_item->RunOnChildren(
2759 [&]( SCH_ITEM* aChild )
2760 {
2761 if( aMode == SELECTED )
2762 {
2763 aChild->SetSelected();
2764 getView()->Hide( aChild, true );
2765 }
2766 else if( aMode == BRIGHTENED )
2767 {
2768 aChild->SetBrightened();
2769 }
2770 } );
2771 }
2772
2773 if( aGroup && aMode != BRIGHTENED )
2774 getView()->Hide( aItem, true );
2775
2776 if( aItem->GetParent() && aItem->GetParent()->Type() != SCHEMATIC_T )
2777 getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
2778
2779 getView()->Update( aItem, KIGFX::REPAINT );
2780}
2781
2782
2783void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
2784{
2785 if( aMode == SELECTED )
2786 {
2787 aItem->ClearSelected();
2788 // Lines need endpoints cleared here
2789 if( aItem->Type() == SCH_LINE_T )
2790 aItem->ClearFlags( STARTPOINT | ENDPOINT );
2791
2792 if( aMode != BRIGHTENED )
2793 getView()->Hide( aItem, false );
2794 }
2795 else if( aMode == BRIGHTENED )
2796 {
2797 aItem->ClearBrightened();
2798 }
2799
2800 if( aGroup )
2801 aGroup->Remove( aItem );
2802
2803 // Unhighlight pins and fields. (All the other symbol children are currently only
2804 // represented in the LIB_SYMBOL.)
2805 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
2806 {
2807 sch_item->RunOnChildren(
2808 [&]( SCH_ITEM* aChild )
2809 {
2810 if( aMode == SELECTED )
2811 {
2812 aChild->ClearSelected();
2813 getView()->Hide( aChild, false );
2814 }
2815 else if( aMode == BRIGHTENED )
2816 {
2817 aChild->ClearBrightened();
2818 }
2819
2820 if( aGroup )
2821 aGroup->Remove( aChild );
2822 } );
2823 }
2824
2825 if( aItem->GetParent() && aItem->GetParent()->Type() != SCHEMATIC_T )
2826 getView()->Update( aItem->GetParent(), KIGFX::REPAINT );
2827
2828 getView()->Update( aItem, KIGFX::REPAINT );
2829}
2830
2831
2833{
2834 const unsigned GRIP_MARGIN = 20;
2835 int margin = KiROUND( getView()->ToWorld( GRIP_MARGIN ) );
2836
2837 // Check if the point is located within any of the currently selected items bounding boxes
2838 for( EDA_ITEM* item : m_selection )
2839 {
2840 BOX2I itemBox = item->ViewBBox();
2841 itemBox.Inflate( margin ); // Give some margin for gripping an item
2842
2843 if( itemBox.Contains( aPoint ) )
2844 return true;
2845 }
2846
2847 return false;
2848}
2849
2850
2852{
2854
2861
2863
2869
2872
2874}
2875
2876
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static TOOL_ACTION unselectAll
Definition: actions.h:76
static TOOL_ACTION cursorLeft
Definition: actions.h:161
static TOOL_ACTION zoomOutCenter
Definition: actions.h:128
static TOOL_ACTION zoomIn
Definition: actions.h:125
static TOOL_ACTION cursorLeftFast
Definition: actions.h:166
static TOOL_ACTION selectColumns
Definition: actions.h:95
static TOOL_ACTION cursorDown
Definition: actions.h:160
static TOOL_ACTION zoomOut
Definition: actions.h:126
static TOOL_ACTION cursorRightFast
Definition: actions.h:167
static TOOL_ACTION zoomCenter
Definition: actions.h:133
static TOOL_ACTION panDown
Definition: actions.h:174
static TOOL_ACTION cursorDownFast
Definition: actions.h:165
static TOOL_ACTION selectRows
Definition: actions.h:94
static TOOL_ACTION cursorUpFast
Definition: actions.h:164
static TOOL_ACTION panLeft
Definition: actions.h:175
static TOOL_ACTION updateMenu
Definition: actions.h:220
static TOOL_ACTION zoomFitScreen
Definition: actions.h:134
static TOOL_ACTION increment
Definition: actions.h:87
static TOOL_ACTION panUp
Definition: actions.h:173
static TOOL_ACTION zoomFitObjects
Definition: actions.h:135
static TOOL_ACTION zoomInCenter
Definition: actions.h:127
static TOOL_ACTION panRight
Definition: actions.h:176
static TOOL_ACTION selectTable
Definition: actions.h:96
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition: actions.h:159
static TOOL_ACTION finishInteractive
Definition: actions.h:66
static TOOL_ACTION cursorRight
Definition: actions.h:162
static TOOL_ACTION selectAll
Definition: actions.h:75
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
CROSS_PROBING_SETTINGS m_CrossProbing
Definition: app_settings.h:176
constexpr const Vec & GetPosition() const
Definition: box2.h:211
constexpr void SetMaximum()
Definition: box2.h:80
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr Vec Centre() const
Definition: box2.h:97
constexpr const Vec GetCenter() const
Definition: box2.h:230
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
An abstract class that will find and hold all the objects according to an inspection done by the Insp...
Definition: collector.h:48
void Transfer(int aIndex)
Move the item at aIndex (first position is 0) to the backup list.
Definition: collector.h:151
bool m_MenuCancelled
Definition: collector.h:237
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
bool HasItem(const EDA_ITEM *aItem) const
Tests if aItem has already been collected.
Definition: collector.h:195
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:109
int m_Threshold
Definition: collector.h:234
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:99
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition: commit.h:86
bool Empty() const
Returns status of an item.
Definition: commit.h:144
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition: commit.h:80
bool IsHorizontal() const
Definition: eda_angle.h:138
bool IsType(FRAME_T aType) const
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
void ClearSelected()
Definition: eda_item.h:122
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
bool IsSelected() const
Definition: eda_item.h:110
void SetSelected()
Definition: eda_item.h:119
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:176
void ClearBrightened()
Definition: eda_item.h:123
void SetBrightened()
Definition: eda_item.h:120
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:216
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:131
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:128
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:130
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:326
bool IsFilled() const
Definition: eda_shape.h:98
SHAPE_T GetShape() const
Definition: eda_shape.h:132
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
virtual bool IsVisible() const
Definition: eda_text.h:174
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
Definition: eda_text.cpp:1110
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION properties
Definition: ee_actions.h:135
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:63
static TOOL_ACTION move
Definition: ee_actions.h:127
static TOOL_ACTION clearHighlight
Definition: ee_actions.h:309
static TOOL_ACTION selectConnection
If current selection is a wire or bus, expand to entire connection.
Definition: ee_actions.h:53
static TOOL_ACTION pinTable
Definition: ee_actions.h:162
static TOOL_ACTION navigateForward
Definition: ee_actions.h:235
static TOOL_ACTION slice
Definition: ee_actions.h:151
static TOOL_ACTION assignNetclass
Definition: ee_actions.h:168
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION drag
Definition: ee_actions.h:128
static TOOL_ACTION navigateBack
Definition: ee_actions.h:236
static TOOL_ACTION selectionMenu
Runs a selection menu to select from a list of items.
Definition: ee_actions.h:67
static TOOL_ACTION placeClassLabel
Definition: ee_actions.h:90
static TOOL_ACTION drawWire
Definition: ee_actions.h:83
static TOOL_ACTION removeItemsFromSel
Definition: ee_actions.h:64
static TOOL_ACTION drawBus
Definition: ee_actions.h:84
static TOOL_ACTION selectNode
Select the junction, wire or bus segment under the cursor.
Definition: ee_actions.h:49
static TOOL_ACTION breakWire
Definition: ee_actions.h:150
static TOOL_ACTION placeSheetPin
Definition: ee_actions.h:96
static TOOL_ACTION drawLines
Definition: ee_actions.h:109
static TOOL_ACTION syncSheetPins
Definition: ee_actions.h:99
static TOOL_ACTION selectOnPCB
Definition: ee_actions.h:261
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:233
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:91
static TOOL_ACTION removeItemFromSel
Definition: ee_actions.h:60
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:92
static TOOL_ACTION addItemToSel
Selects an item (specified as the event parameter).
Definition: ee_actions.h:59
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:161
static TOOL_ACTION editPageNumber
Definition: ee_actions.h:170
static TOOL_ACTION enterSheet
Definition: ee_actions.h:232
static TOOL_ACTION setUnitDisplayName
Definition: ee_actions.h:228
static TOOL_ACTION unfoldBus
Definition: ee_actions.h:85
static TOOL_ACTION placeLabel
Definition: ee_actions.h:89
static TOOL_ACTION placeJunction
Definition: ee_actions.h:87
bool m_ShowPinElectricalTypes
static const std::vector< KICAD_T > MovableItems
Definition: ee_collectors.h:43
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
static SELECTION_CONDITION SingleSymbol
static SELECTION_CONDITION AllPinsOrSheetPins
static SELECTION_CONDITION SingleMultiFunctionPin
static SELECTION_CONDITION SingleSymbolOrPower
static SELECTION_CONDITION SingleMultiUnitSymbol
static SELECTION_CONDITION SingleNonExcludedMarker
static SELECTION_CONDITION SingleDeMorganSymbol
static SELECTION_CONDITION AllPins
static SELECTION_CONDITION MultipleSymbolsOrPower
GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const override
Gets the coarsest grid that applies to an item.
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, GRID_HELPER_GRIDS aGrid, SCH_ITEM *aSkip)
Tool that displays edit points allowing to modify items by dragging the points.
bool HasPoint()
Indicate the cursor is over an edit point.
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
bool selectionContains(const VECTOR2I &aPoint) const
SCH_SELECTION_FILTER_OPTIONS m_filter
EE_SELECTION m_selection
void unselect(EDA_ITEM *aItem) override
Take necessary action to mark an item as unselected.
void unhighlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
int SelectColumns(const TOOL_EVENT &aEvent)
void SyncSelection(const std::optional< SCH_SHEET_PATH > &targetSheetPath, SCH_ITEM *focusItem, const std::vector< SCH_ITEM * > &items)
int SelectConnection(const TOOL_EVENT &aEvent)
If a connected item is selected then expand the selection to the entire connection,...
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Collect one or more items at a given point.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
bool selectPoint(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int SelectAll(const TOOL_EVENT &aEvent)
Unselect all visible items in sheet.
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
bool selectTableCells(SCH_TABLE *aTable)
Handle a table cell drag selection within a table.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
void ZoomFitCrossProbeBBox(const BOX2I &aBBox)
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int Main(const TOOL_EVENT &aEvent)
The main loop.
int UnselectAll(const TOOL_EVENT &aEvent)
int SelectTable(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
void highlight(EDA_ITEM *aItem, int aMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
int SelectNode(const TOOL_EVENT &aEvent)
Selects the connected item at the current cursor position.
bool Init() override
Init() is called once upon a registration of the tool.
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
OPT_TOOL_EVENT autostartEvent(TOOL_EVENT *aEvent, EE_GRID_HELPER &aGrid, SCH_ITEM *aItem)
bool itemPassesFilter(EDA_ITEM *aItem)
Return true if the given item passes the stateful selection filter.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
void OnIdle(wxIdleEvent &aEvent)
Zoom the screen to fit the bounding box for cross probing/selection sync.
SCH_BASE_FRAME * m_frame
void narrowSelection(EE_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked, bool aSelectedOnly=false)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void select(EDA_ITEM *aItem) override
Take necessary action to mark an item as selected.
int SelectRows(const TOOL_EVENT &aEvent)
EE_SELECTION & GetSelection()
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
BOX2I GetBoundingBox() const override
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
static const TOOL_EVENT DisambiguatePoint
Used for hotkey feedback.
Definition: actions.h:309
static const TOOL_EVENT ClearedEvent
Definition: actions.h:294
static const TOOL_EVENT SelectedEvent
Definition: actions.h:292
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:291
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:293
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
void SetSubtractive(bool aSubtractive)
void SetAdditive(bool aAdditive)
void SetOrigin(const VECTOR2I &aOrigin)
const BOX2I ViewBBox() const override
Set the origin of the rectangle (the fixed corner)
void SetExclusiveOr(bool aExclusiveOr)
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:522
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:562
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:299
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:334
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:412
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:1669
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:247
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:72
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1617
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:217
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1596
Definition: kiid.h:49
Define a library symbol object.
Definition: lib_symbol.h:78
bool IsMulti() const override
Definition: lib_symbol.h:554
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:499
Tree view item data for the net navigator.
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:156
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:166
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:161
SCH_SHEET & Root() const
Definition: schematic.h:125
SCH_RENDER_SETTINGS * GetRenderSettings()
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
virtual bool GetShowAllPins() const
Allow some frames to show/hide hidden pins.
Class for a wire to bus entry.
SCH_ITEM * m_connected_bus_item
Pointer to the bus item (usually a bus wire) connected to this bus-wire entry, if it is connected to ...
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:432
virtual void Revert() override
Definition: sch_commit.cpp:510
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void ConfigureFromLabel(const wxString &aLabel)
Configures the connection given a label.
bool IsBus() const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Handle actions specific to the schematic editor.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void FlipBodyStyle(SCH_SYMBOL *aSymbol)
Definition: picksymbol.cpp:176
void DisplayCurrentSheet()
Draw the current sheet on the display.
const wxString & GetHighlightedConnection() const
void FocusOnItem(SCH_ITEM *aItem)
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:617
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
int GetBodyStyle() const
Definition: sch_item.h:232
virtual bool IsPointClickableAnchor(const VECTOR2I &aPos) const
Definition: sch_item.h:455
int GetUnit() const
Definition: sch_item.h:229
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:816
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_label.h:178
LABEL_SHAPE GetLabelShape() const
Definition: sch_label.h:181
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Definition: sch_label.cpp:297
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_line.cpp:806
bool IsStartDangling() const
Definition: sch_line.h:261
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
SEG GetSeg() const
Get the geometric aspect of the wire as a SEG.
Definition: sch_line.h:147
bool IsEndDangling() const
Definition: sch_line.h:262
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:979
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:967
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:142
bool IsVisible() const
Definition: sch_pin.cpp:367
void ClearDrawingState()
Clear the state flags of all the items in the screen.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
std::set< SCH_ITEM * > MarkConnections(SCH_LINE *aSegment, bool aSecondPass)
Return all wires and junctions connected to aSegment which are not connected any symbol pin.
Definition: sch_screen.cpp:408
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:386
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
SHEET_SIDE GetSide() const
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
Schematic symbol object.
Definition: sch_symbol.h:104
int GetOrientation() const
Get the display symbol orientation.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:212
BOX2I GetBodyBoundingBox() const
Return a bounding box for the symbol body but not the pins or fields.
int GetColSpan() const
Definition: sch_tablecell.h:61
int GetRowSpan() const
Definition: sch_tablecell.h:64
std::vector< SCH_TABLECELL * > GetCells() const
Definition: sch_table.h:142
Definition: seg.h:42
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.cpp:388
static SELECTION_CONDITION HasTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if among the selected items there is at least one of a given types.
static bool Empty(const SELECTION &aSelection)
Test if there are no items selected.
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...
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
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...
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.
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
bool doSelectionMenu(COLLECTOR *aCollector)
wxTimer m_disambiguateTimer
int AddItemsToSel(const TOOL_EVENT &aEvent)
int AddItemToSel(const TOOL_EVENT &aEvent)
int UpdateMenu(const TOOL_EVENT &aEvent)
Update a menu's state based on the current selection.
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 ...
VECTOR2I m_originalCursor
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
bool hasModifier()
True if a selection modifier is enabled, false otherwise.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:42
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:75
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:121
void SetIsHover(bool aIsHover)
Definition: selection.h:79
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.cpp:60
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:100
EDA_ITEM * Front() const
Definition: selection.h:172
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:93
int Size() const
Returns the number of selected parts.
Definition: selection.h:116
void ClearReferencePoint()
Definition: selection.cpp:186
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:180
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
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:142
An abstract shape on 2D plane.
Definition: shape.h:126
The symbol library editor main window.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
int GetBodyStyle() const
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
Symbol library viewer main window.
MOUSE_DRAG_ACTION GetDragAction() const
Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) objects.
Definition: tools_holder.h:144
bool ToolStackIsEmpty()
Definition: tools_holder.h:125
Represent a single user action.
Definition: tool_action.h:269
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ REDRAW
Full drawing refresh.
Definition: tool_base.h:83
@ SHUTDOWN
Tool is being shut down.
Definition: tool_base.h:84
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
@ SUPERMODEL_RELOAD
For schematics, the entire schematic changed, not just the sheet.
Definition: tool_base.h:81
Generic, UI-independent tool event.
Definition: tool_event.h:167
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:285
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).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
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.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
VECTOR2D GetMousePosition() const
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
bool RunSynchronousAction(const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:197
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:557
MOUSE_DRAG_ACTION
KICURSOR
Definition: cursors.h:34
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:536
#define BRIGHTENED
item is drawn with a bright contour
#define IS_NEW
New item, just created.
#define SELECTED
Item was manually selected by the user.
#define ENDPOINT
ends. (Used to support dragging.)
std::uint32_t EDA_ITEM_FLAGS
#define CANDIDATE
flag indicating that the structure is connected
#define IS_ROLLOVER
Rollover active. Used for hyperlink highlighting.
#define IS_MOVING
Item being moved.
#define SHOW_ELEC_TYPE
Show pin electrical type. Shared with IS_ROLLOVER.
#define STARTPOINT
When a line is selected, these flags indicate which.
static std::vector< KICAD_T > connectedTypes
static std::vector< KICAD_T > tableCellTypes
#define HITTEST_THRESHOLD_PIXELS
static std::vector< KICAD_T > lineTypes
static std::vector< KICAD_T > sheetTypes
const TOOL_ACTION * allowedActions[]
static std::vector< KICAD_T > connectedLineTypes
static std::vector< KICAD_T > crossProbingTypes
@ ID_POPUP_SCH_PIN_TRICKS_START
Definition: eeschema_id.h:91
@ ID_POPUP_SCH_PIN_TRICKS_HIER_LABEL
Definition: eeschema_id.h:95
@ ID_POPUP_SCH_PIN_TRICKS_WIRE
Definition: eeschema_id.h:93
@ ID_POPUP_SCH_ALT_PIN_FUNCTION
Definition: eeschema_id.h:99
@ ID_POPUP_SCH_UNFOLD_BUS_END
Definition: eeschema_id.h:79
@ ID_POPUP_SCH_SELECT_UNIT
Definition: eeschema_id.h:82
@ ID_POPUP_SCH_SELECT_BASE
Definition: eeschema_id.h:88
@ ID_POPUP_SCH_SELECT_ALT
Definition: eeschema_id.h:89
@ ID_POPUP_SCH_PIN_TRICKS_NET_LABEL
Definition: eeschema_id.h:94
@ ID_POPUP_SCH_PIN_TRICKS_NO_CONNECT
Definition: eeschema_id.h:92
@ ID_POPUP_SCH_UNFOLD_BUS
Definition: eeschema_id.h:78
@ ID_POPUP_SCH_SELECT_UNIT_END
Definition: eeschema_id.h:86
@ ID_POPUP_SCH_ALT_PIN_FUNCTION_END
Definition: eeschema_id.h:100
@ ID_POPUP_SCH_PIN_TRICKS_GLOBAL_LABEL
Definition: eeschema_id.h:96
@ ID_POPUP_SCH_PIN_TRICKS_END
Definition: eeschema_id.h:97
GRID_HELPER_GRIDS
Definition: grid_helper.h:42
KIID niluuid(0)
@ LAYER_WIRE
Definition: layer_ids.h:356
@ LAYER_BUS
Definition: layer_ids.h:357
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
CITER next(CITER it)
Definition: ptree.cpp:126
@ LABEL_BIDI
Definition: sch_label.h:119
@ LABEL_INPUT
Definition: sch_label.h:117
@ LABEL_OUTPUT
Definition: sch_label.h:118
@ LABEL_PASSIVE
Definition: sch_label.h:121
@ LABEL_TRISTATE
Definition: sch_label.h:120
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
std::vector< FAB_LAYER_COLOR > dummy
bool zoom_to_fit
Zoom to fit items (ignored if center_on_items is off)
Definition: app_settings.h:35
bool center_on_items
Automatically pan to cross-probed items.
Definition: app_settings.h:34
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
bool symbols
Allow selecting symbols and sheet symbols.
bool labels
Net and bus labels.
bool pins
Symbol and sheet pins.
bool graphics
Graphic lines, shapes, polygons.
bool lockedItems
Allow selecting locked items.
bool images
Bitmap/vector images.
bool otherItems
Anything not fitting one of the above categories.
bool wires
Net and bus wires and junctions.
void RotateAndMirrorPin(SCH_PIN &aPin, int aOrientMirror)
Rotate and/or mirror a SCH_PIN according to aOrientMirror.
constexpr int delta
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:629
@ TA_CHOICE_MENU_CHOICE
Definition: tool_event.h:97
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:105
@ TA_MOUSE_WHEEL
Definition: tool_event.h:72
@ TC_COMMAND
Definition: tool_event.h:56
@ MD_ALT
Definition: tool_event.h:144
@ MD_CTRL
Definition: tool_event.h:143
@ MD_SHIFT
Definition: tool_event.h:142
@ BUT_AUX1
Definition: tool_event.h:134
@ BUT_MIDDLE
Definition: tool_event.h:133
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132
@ BUT_AUX2
Definition: tool_event.h:135
@ SCH_TABLE_T
Definition: typeinfo.h:165
@ SCH_LINE_T
Definition: typeinfo.h:163
@ LIB_SYMBOL_T
Definition: typeinfo.h:148
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_TABLECELL_T
Definition: typeinfo.h:166
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:185
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:171
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:198
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:186
@ SCH_MARKER_T
Definition: typeinfo.h:158
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:162
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:187
@ SCHEMATIC_T
Definition: typeinfo.h:203
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:173
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_SYMBOL_LOCATE_POWER_T
Definition: typeinfo.h:195
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:161
@ SCH_BITMAP_T
Definition: typeinfo.h:164
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
@ SCH_PIN_T
Definition: typeinfo.h:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691