KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_drawing_tools.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-2023 CERN
5 * Copyright The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <eda_shape.h>
22#include <tool/tool_manager.h>
23#include "sch_sheet_path.h"
24#include <limits>
25#include <memory>
26#include <set>
27#include <unordered_set>
28
29#include <advanced_config.h>
31#include <kiplatform/ui.h>
32#include <optional>
33#include <project_sch.h>
41#include <sch_actions.h>
42#include <sch_tool_utils.h>
43#include <sch_edit_frame.h>
44#include <widgets/wx_infobar.h>
45#include <pgm_base.h>
46#include <design_block.h>
48#include <eeschema_id.h>
49#include <confirm.h>
50#include <view/view_controls.h>
51#include <view/view.h>
52#include <sch_symbol.h>
53#include <sch_no_connect.h>
54#include <sch_group.h>
55#include <sch_line.h>
56#include <sch_junction.h>
57#include <sch_bus_entry.h>
58#include <sch_table.h>
59#include <sch_tablecell.h>
60#include <sch_sheet.h>
61#include <sch_sheet_pin.h>
62#include <sch_label.h>
63#include <sch_bitmap.h>
64#include <schematic.h>
65#include <sch_commit.h>
66#include <scoped_set_reset.h>
68#include <eeschema_settings.h>
75#include <string_utils.h>
77#include <wx/filedlg.h>
78#include <wx/msgdlg.h>
79
80
82
83
101
102
104{
106
107 auto belowRootSheetCondition =
108 [this]( const SELECTION& aSel )
109 {
110 return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
111 };
112
113 // some interactive drawing tools can undo the last point
114 auto canUndoPoint =
115 [this]( const SELECTION& aSel )
116 {
117 return ( m_mode == MODE::RULE_AREA );
118 };
119
120 auto inDrawingRuleArea =
121 [this]( const SELECTION& aSel )
122 {
123 return m_mode == MODE::RULE_AREA;
124 };
125
126 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
127
128 // clang-format off
129 ctxMenu.AddItem( SCH_ACTIONS::leaveSheet, belowRootSheetCondition, 150 );
130 ctxMenu.AddItem( SCH_ACTIONS::closeOutline, inDrawingRuleArea, 200 );
131 ctxMenu.AddItem( ACTIONS::deleteLastPoint, canUndoPoint, 200 );
132 // clang-format on
133
134 return true;
135}
136
137
139{
141
142 SCH_SYMBOL* symbol = toolParams.m_Symbol;
143
144 // If we get a parameterised symbol, we probably just want to place that and get out of the placement tool,
145 // rather than popping up the chooser afterwards. A multi-unit symbol may still request that its remaining
146 // units be placed before the tool exits.
147 bool placeOneOnly = symbol != nullptr;
148
150 std::vector<PICKED_SYMBOL>* historyList = nullptr;
151 bool ignorePrimePosition = false;
152 COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
153 SCHEMATIC_SETTINGS& schSettings = m_frame->Schematic().Settings();
154 SCH_SCREEN* screen = m_frame->GetScreen();
155 bool keepSymbol = false;
156 bool placeAllUnits = toolParams.m_PlaceAllUnits;
157
158 if( m_inDrawingTool )
159 return 0;
160
162
165 VECTOR2I cursorPos;
166
167 // First we need to get all instances of this sheet so we can annotate whatever symbols we place on all copies
168 SCH_SHEET_LIST hierarchy = m_frame->Schematic().Hierarchy();
169 SCH_SHEET_LIST newInstances = hierarchy.FindAllSheetsForScreen( m_frame->GetCurrentSheet().LastScreen() );
170 newInstances.SortByPageNumbers();
171
172 // Get a list of all references in the schematic to avoid duplicates wherever they're placed
173 SCH_REFERENCE_LIST existingRefs;
174 hierarchy.GetSymbols( existingRefs, SYMBOL_FILTER_ALL );
175 existingRefs.SortByReferenceOnly();
176
177 if( aEvent.IsAction( &SCH_ACTIONS::placeSymbol ) )
178 {
179 historyList = &m_symbolHistoryList;
180 }
181 else if (aEvent.IsAction( &SCH_ACTIONS::placePower ) )
182 {
183 historyList = &m_powerHistoryList;
184 filter.FilterPowerSymbols( true );
185 }
186 else
187 {
188 wxFAIL_MSG( "PlaceSymbol(): unexpected request" );
189 }
190
191 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
192 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
193
194 auto addSymbol =
195 [this]( SCH_SYMBOL* aSymbol )
196 {
198 m_selectionTool->AddItemToSel( aSymbol );
199
200 aSymbol->SetFlags( IS_NEW | IS_MOVING );
201
202 m_view->ClearPreview();
203 m_view->AddToPreview( aSymbol, false ); // Add, but not give ownership
204
205 // Set IS_MOVING again, as AddItemToCommitAndScreen() will have cleared it.
206 aSymbol->SetFlags( IS_MOVING );
207 m_toolMgr->PostAction( ACTIONS::refreshPreview );
208 };
209
210 auto setCursor =
211 [&]()
212 {
213 m_frame->GetCanvas()->SetCurrentCursor( symbol ? KICURSOR::MOVING : KICURSOR::COMPONENT );
214 };
215
216 auto cleanup =
217 [&]()
218 {
220 m_view->ClearPreview();
221 delete symbol;
222 symbol = nullptr;
223
224 existingRefs.Clear();
225 hierarchy.GetSymbols( existingRefs, SYMBOL_FILTER_ALL );
226 existingRefs.SortByReferenceOnly();
227 };
228
229 auto annotate =
230 [&]()
231 {
232 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
233
234 // Then we need to annotate all instances by sheet
235 if( !newInstances.empty()
236 && ( cfg->m_AnnotatePanel.automatic
237 || SCH_REFERENCE( symbol, newInstances[0] ).AlwaysAnnotate() ) )
238 {
239 AnnotateNewSymbol( symbol, newInstances, existingRefs, schSettings, &hierarchy );
240 }
241
242 m_frame->GetCurrentSheet().UpdateAllScreenReferences();
243 };
244
245 Activate();
246
247 // Must be done after Activate() so that it gets set into the correct context
248 getViewControls()->ShowCursor( true );
249
250 // Set initial cursor
251 setCursor();
252
253 // Prime the pump
254 if( symbol )
255 {
256 addSymbol( symbol );
257
258 if( toolParams.m_Reannotate )
259 annotate();
260
261 // Seed the placed-reference list so multi-unit stepping sees this symbol's first unit
262 // as taken. The chooser path seeds it when it builds the symbol; this path bypasses
263 // that branch.
264 SCH_REFERENCE placedSymbolReference( symbol, m_frame->GetCurrentSheet() );
265 existingRefs.AddItem( placedSymbolReference );
266 existingRefs.SortByReferenceOnly();
267
268 getViewControls()->WarpMouseCursor( getViewControls()->GetMousePosition( false ) );
269 }
270 else if( aEvent.HasPosition() )
271 {
272 m_toolMgr->PrimeTool( aEvent.Position() );
273 }
274 else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
275 {
276 m_toolMgr->PrimeTool( { 0, 0 } );
277 ignorePrimePosition = true;
278 }
279
280 // Main loop: keep receiving events
281 while( TOOL_EVENT* evt = Wait() )
282 {
283 setCursor();
284 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
285 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
286
287 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
288 controls->ForceCursorPosition( true, cursorPos );
289
290 // The tool hotkey is interpreted as a click when drawing
291 bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
292
293 if( evt->IsCancelInteractive() || ( symbol && evt->IsAction( &ACTIONS::undo ) ) )
294 {
295 m_frame->GetInfoBar()->Dismiss();
296
297 if( symbol )
298 {
299 cleanup();
300
301 if( keepSymbol )
302 {
303 // Re-enter symbol chooser
304 m_toolMgr->PostAction( ACTIONS::cursorClick );
305 }
306 }
307 else
308 {
309 break;
310 }
311 }
312 else if( evt->IsActivate() && !isSyntheticClick )
313 {
314 if( symbol && evt->IsMoveTool() )
315 {
316 // we're already moving our own item; ignore the move tool
317 evt->SetPassEvent( false );
318 continue;
319 }
320
321 if( symbol )
322 {
323 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel symbol creation." ) );
324 evt->SetPassEvent( false );
325 continue;
326 }
327
328 if( evt->IsMoveTool() )
329 {
330 // Make sure we come back after the move tool runs
331 frame()->PushTool( originalEvent );
332 }
333
334 break;
335 }
336 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
337 || isSyntheticClick
338 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
339 {
340 if( !symbol )
341 {
343
346
347 std::set<UTF8> unique_libid;
348 std::vector<PICKED_SYMBOL> alreadyPlaced;
349
350 for( SCH_SHEET_PATH& sheet : hierarchy )
351 {
352 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
353 {
354 SCH_SYMBOL* s = static_cast<SCH_SYMBOL*>( item );
355
356 if( !unique_libid.insert( s->GetLibId().Format() ).second )
357 continue;
358
359 LIB_SYMBOL* libSymbol = SchGetLibSymbol( s->GetLibId(), libs, cache );
360
361 if( libSymbol )
362 {
363 if( libSymbol->IsPower() != filter.GetFilterPowerSymbols() )
364 continue;
365
366 PICKED_SYMBOL pickedSymbol;
367 pickedSymbol.LibId = libSymbol->GetLibId();
368 alreadyPlaced.push_back( pickedSymbol );
369 }
370 }
371 }
372
373 // Pick the symbol to be placed
374 bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
375 PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary( &filter, *historyList, alreadyPlaced,
376 footprintPreviews );
377
378 keepSymbol = sel.KeepSymbol;
379 placeAllUnits = sel.PlaceAllUnits;
380
381 LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? m_frame->GetLibSymbol( sel.LibId ) : nullptr;
382
383 if( !libSymbol )
384 continue;
385
386 // If we started with a hotkey which has a position then warp back to that.
387 // Otherwise update to the current mouse position pinned inside the autoscroll
388 // boundaries.
389 if( evt->IsPrime() && !ignorePrimePosition )
390 {
391 cursorPos = grid.Align( evt->Position(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
392 getViewControls()->WarpMouseCursor( cursorPos, true );
393 }
394 else
395 {
397 cursorPos = grid.Align( getViewControls()->GetMousePosition(),
399 }
400
401 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
402
403 // Only convert between power symbol types. Regular (non-power) symbols must
404 // never be promoted to power symbols just because the default is set to
405 // Global or Local. The preference's Default option means "follow the symbol
406 // definition" and any conversion only applies to symbols that are already
407 // power symbols.
408 if( libSymbol->IsPower()
409 && !libSymbol->IsLocalPower()
411 {
412 libSymbol->SetLocalPower();
413 wxString keywords = libSymbol->GetKeyWords();
414
415 // Adjust the KiCad library default fields to match the new power symbol type
416 if( keywords.Contains( wxT( "global power" ) ) )
417 {
418 keywords.Replace( wxT( "global power" ), wxT( "local power" ) );
419 libSymbol->SetKeyWords( keywords );
420 }
421
422 wxString desc = libSymbol->GetDescription();
423
424 if( desc.Contains( wxT( "global label" ) ) )
425 {
426 desc.Replace( wxT( "global label" ), wxT( "local label" ) );
427 libSymbol->SetDescription( desc );
428 }
429 }
430 else if( libSymbol->IsPower()
431 && !libSymbol->IsGlobalPower()
433 {
434 // We do not currently have local power symbols in the KiCad library, so
435 // don't update any fields
436 libSymbol->SetGlobalPower();
437 }
438
439 symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos,
440 &m_frame->Schematic() );
441 addSymbol( symbol );
442 annotate();
443
444 // Update the list of references for the next symbol placement.
445 SCH_REFERENCE placedSymbolReference( symbol, m_frame->GetCurrentSheet() );
446 existingRefs.AddItem( placedSymbolReference );
447 existingRefs.SortByReferenceOnly();
448
449 if( m_frame->eeconfig()->m_AutoplaceFields.enable )
450 {
451 // Not placed yet, so pass a nullptr screen reference
452 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
453 }
454
455 // Update cursor now that we have a symbol
456 setCursor();
457 }
458 else
459 {
460 m_view->ClearPreview();
461 m_frame->AddToScreen( symbol, screen );
462
463 if( m_frame->eeconfig()->m_AutoplaceFields.enable )
464 symbol->AutoplaceFields( screen, AUTOPLACE_AUTO );
465
466 m_frame->SaveCopyForRepeatItem( symbol );
467
468 SCH_COMMIT commit( m_toolMgr );
469 commit.Added( symbol, screen );
470
472 lwbTool->TrimOverLappingWires( &commit, &m_selectionTool->GetSelection() );
473 lwbTool->AddJunctionsIfNeeded( &commit, &m_selectionTool->GetSelection() );
474
475 commit.Push( _( "Place Symbol" ) );
476
477 // A preselected single-unit symbol exits here rather than re-opening the
478 // chooser. Multi-unit placement must fall through to the unit continuation
479 // below, which exits once the units are exhausted.
480 if( placeOneOnly && !placeAllUnits )
481 break;
482
483 SCH_SYMBOL* nextSymbol = nullptr;
484
485 if( keepSymbol || placeAllUnits )
486 {
487 SCH_REFERENCE currentReference( symbol, m_frame->GetCurrentSheet() );
488 SCHEMATIC& schematic = m_frame->Schematic();
489
490 if( placeAllUnits )
491 {
492 // For unannotated references all U?-prefix symbols share the same ref
493 // string regardless of the library symbol they originate from. Only
494 // consider units already used by THIS library symbol when stepping
495 // through units, so different multi-unit parts that share a reference
496 // prefix do not collide pre-annotation.
497 const wxString currentRefStr = currentReference.GetRef();
498 const bool isUnannotated = !currentRefStr.IsEmpty() && currentRefStr.Last() == '?';
499 const LIB_ID symLibId = symbol->GetLibId();
500
501 auto unitOccupied =
502 [&]( int aUnit ) -> bool
503 {
504 // The next unit copies every instance, so each must be free once composed
505 if( !isUnannotated )
506 {
507 for( const SCH_SHEET_PATH& instance : newInstances )
508 {
509 SCH_REFERENCE candidate( symbol, instance );
510 candidate.SetUnit( aUnit );
511
512 if( schematic.Contains( candidate ) )
513 return true;
514 }
515
516 return false;
517 }
518
519 return IsUnannotatedUnitOccupied( existingRefs, currentRefStr, symLibId, aUnit );
520 };
521
522 while( currentReference.GetUnit() <= symbol->GetUnitCount()
523 && unitOccupied( currentReference.GetUnit() ) )
524 {
525 currentReference.SetUnit( currentReference.GetUnit() + 1 );
526 }
527
528 if( currentReference.GetUnit() > symbol->GetUnitCount() )
529 {
530 currentReference.SetUnit( 1 );
531 }
532 }
533
534 // We are either stepping to the next unit or next symbol
535 if( keepSymbol || currentReference.GetUnit() > 1 )
536 {
537 nextSymbol = static_cast<SCH_SYMBOL*>( symbol->Duplicate( IGNORE_PARENT_GROUP ) );
538 nextSymbol->SetUnit( currentReference.GetUnit() );
539 nextSymbol->SetUnitSelection( currentReference.GetUnit() );
540
541 addSymbol( nextSymbol );
542 symbol = nextSymbol;
543
544 if( currentReference.GetUnit() == 1 )
545 annotate();
546
547 // Update the list of references for the next symbol placement.
548 SCH_REFERENCE placedSymbolReference( symbol, m_frame->GetCurrentSheet() );
549 existingRefs.AddItem( placedSymbolReference );
550 existingRefs.SortByReferenceOnly();
551 }
552 }
553
554 symbol = nextSymbol;
555
556 // A preselected multi-unit symbol leaves the tool once its last unit is placed.
557 if( placeOneOnly && !symbol )
558 break;
559 }
560 }
561 else if( evt->IsClick( BUT_RIGHT ) )
562 {
563 // Warp after context menu only if dragging...
564 if( !symbol )
565 m_toolMgr->VetoContextMenuMouseWarp();
566
567 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
568 }
569 else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
570 {
571 if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT
572 && *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_UNIT_END )
573 {
574 int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
575
576 if( symbol )
577 {
578 m_frame->SelectUnit( symbol, unit );
579 m_toolMgr->PostAction( ACTIONS::refreshPreview );
580 }
581 }
582 else if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_BODY_STYLE
583 && *evt->GetCommandId() <= ID_POPUP_SCH_SELECT_BODY_STYLE_END )
584 {
585 int bodyStyle = ( *evt->GetCommandId() - ID_POPUP_SCH_SELECT_BODY_STYLE ) + 1;
586
587 if( symbol && symbol->GetBodyStyle() != bodyStyle )
588 {
589 m_frame->SelectBodyStyle( symbol, bodyStyle );
590 m_toolMgr->PostAction( ACTIONS::refreshPreview );
591 }
592 }
593 }
594 else if( evt->IsAction( &ACTIONS::duplicate )
595 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
596 || evt->IsAction( &ACTIONS::paste ) )
597 {
598 if( symbol )
599 {
600 wxBell();
601 continue;
602 }
603
604 // Exit. The duplicate/repeat/paste will run in its own loop.
605 evt->SetPassEvent();
606 break;
607 }
608 else if( symbol && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
609 {
610 symbol->SetPosition( cursorPos );
611 m_view->ClearPreview();
612 m_view->AddToPreview( symbol, false ); // Add, but not give ownership
613 m_frame->SetMsgPanel( symbol );
614 }
615 else if( symbol && evt->IsAction( &ACTIONS::doDelete ) )
616 {
617 cleanup();
618 }
619 else if( symbol && ( evt->IsAction( &ACTIONS::redo )
620 || evt->IsAction( &SCH_ACTIONS::editWithLibEdit )
621 || evt->IsAction( &SCH_ACTIONS::changeSymbol ) ) )
622 {
623 wxBell();
624 }
625 else if( symbol
626 && ( evt->IsAction( &SCH_ACTIONS::properties ) || evt->IsAction( &SCH_ACTIONS::editReference )
627 || evt->IsAction( &SCH_ACTIONS::editValue ) || evt->IsAction( &SCH_ACTIONS::editFootprint )
628 || evt->IsAction( &SCH_ACTIONS::autoplaceFields ) || evt->IsAction( &SCH_ACTIONS::cycleBodyStyle )
629 || evt->IsAction( &SCH_ACTIONS::setExcludeFromBOM )
630 || evt->IsAction( &SCH_ACTIONS::setExcludeFromBoard )
631 || evt->IsAction( &SCH_ACTIONS::setExcludeFromSim )
632 || evt->IsAction( &SCH_ACTIONS::setExcludeFromPosFiles ) || evt->IsAction( &SCH_ACTIONS::setDNP )
633 || evt->IsAction( &SCH_ACTIONS::rotateCW ) || evt->IsAction( &SCH_ACTIONS::rotateCCW )
634 || evt->IsAction( &SCH_ACTIONS::mirrorV ) || evt->IsAction( &SCH_ACTIONS::mirrorH ) ) )
635 {
636 m_toolMgr->PostAction( ACTIONS::refreshPreview );
637 evt->SetPassEvent();
638 }
639 else
640 {
641 evt->SetPassEvent();
642 }
643
644 // Enable autopanning and cursor capture only when there is a symbol to be placed
645 getViewControls()->SetAutoPan( symbol != nullptr );
646 getViewControls()->CaptureCursor( symbol != nullptr );
647 }
648
649 getViewControls()->SetAutoPan( false );
650 getViewControls()->CaptureCursor( false );
651 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
652
653 return 0;
654}
655
656
658{
660 SCH_SYMBOL* symbol = params.m_Symbol;
661 int requestedUnit = params.m_Unit;
662
663 // TODO: get from selection
664 if( !symbol )
665 {
666 static const std::vector<KICAD_T> symbolTypes = { SCH_SYMBOL_T };
667 SCH_SELECTION& selection = m_selectionTool->RequestSelection( symbolTypes );
668
669 if( selection.Size() != 1 )
670 {
671 m_frame->ShowInfoBarMsg( _( "Select a single symbol to place the next unit." ) );
672 return 0;
673 }
674
675 wxCHECK( selection.Front()->Type() == SCH_SYMBOL_T, 0 );
676 symbol = static_cast<SCH_SYMBOL*>( selection.Front() );
677 }
678
679 if( !symbol )
680 return 0;
681
682 if( !symbol->IsMultiUnit() )
683 {
684 m_frame->ShowInfoBarMsg( _( "This symbol has only one unit." ) );
685 return 0;
686 }
687
688 const std::set<int> missingUnits = GetUnplacedUnitsForSymbol( *symbol );
689
690 if( missingUnits.empty() )
691 {
692 m_frame->ShowInfoBarMsg( _( "All units of this symbol are already placed." ) );
693 return 0;
694 }
695
696 int nextMissing;
697
698 if( requestedUnit > 0 )
699 {
700 if( missingUnits.count( requestedUnit ) == 0 )
701 {
702 m_frame->ShowInfoBarMsg( _( "Requested unit already placed." ) );
703 return 0;
704 }
705
706 nextMissing = requestedUnit;
707 }
708 else
709 {
710 // Find the lowest unit number that is missing
711 nextMissing = *std::min_element( missingUnits.begin(), missingUnits.end() );
712 }
713
714 std::unique_ptr<SCH_SYMBOL> newSymbol = std::make_unique<SCH_SYMBOL>( *symbol );
715 const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
716
717 // Use SetUnitSelection(int) to update ALL instance references at once.
718 // This is important for shared sheets where the same screen is used by multiple
719 // sheet instances - we want the new symbol unit to appear correctly on all instances.
720 newSymbol->SetUnitSelection( nextMissing );
721 newSymbol->SetUnit( nextMissing );
722 newSymbol->SetRefProp( symbol->GetBaseRef( &sheetPath ) );
723
724 // Post the new symbol - don't reannotate it - we set the reference ourselves
725 m_toolMgr->PostAction( SCH_ACTIONS::placeSymbol, SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ newSymbol.release(), false } );
726 return 0;
727}
728
729
737static std::optional<VECTOR2I> designBlockAnchor( const std::vector<SCH_ITEM*>& aItems )
738{
739 std::optional<VECTOR2I> connectionAnchor;
740 std::optional<VECTOR2I> positionAnchor;
741
742 auto keepTopLeft =
743 []( std::optional<VECTOR2I>& aBest, const VECTOR2I& aCandidate )
744 {
745 if( !aBest || aCandidate.y < aBest->y || ( aCandidate.y == aBest->y && aCandidate.x < aBest->x ) )
746 aBest = aCandidate;
747 };
748
749 for( SCH_ITEM* item : aItems )
750 {
751 if( item->Type() == SCH_GROUP_T )
752 continue;
753
754 for( const VECTOR2I& pt : item->GetConnectionPoints() )
755 keepTopLeft( connectionAnchor, pt );
756
757 keepTopLeft( positionAnchor, item->GetPosition() );
758 }
759
760 return connectionAnchor ? connectionAnchor : positionAnchor;
761}
762
763
765{
766 if( m_inDrawingTool )
767 return 0;
768
770
771 COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
772 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
773 SCHEMATIC_SETTINGS& schSettings = m_frame->Schematic().Settings();
774 SCH_SCREEN* screen = m_frame->GetScreen();
775 SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
776
779 VECTOR2I cursorPos;
780
781 // Guard to reset forced cursor positioning on exit, regardless of error path
782 struct RESET_FORCED_CURSOR_GUARD
783 {
784 KIGFX::VIEW_CONTROLS* m_controls;
785
786 ~RESET_FORCED_CURSOR_GUARD()
787 {
788 m_controls->ForceCursorPosition( false );
789 }
790 };
791
792 RESET_FORCED_CURSOR_GUARD forcedCursorGuard{ controls };
793
794 if( !cfg || !common_settings )
795 return 0;
796
797 bool placingDesignBlock = aEvent.IsAction( &SCH_ACTIONS::placeDesignBlock );
798
799 std::unique_ptr<DESIGN_BLOCK> designBlock;
800 wxString sheetFileName = wxEmptyString;
801
802 if( placingDesignBlock )
803 {
804 SCH_DESIGN_BLOCK_PANE* designBlockPane = m_frame->GetDesignBlockPane();
805
806 if( designBlockPane->GetSelectedLibId().IsValid() )
807 {
808 designBlock.reset( designBlockPane->GetDesignBlock( designBlockPane->GetSelectedLibId(), true, true ) );
809
810 if( !designBlock )
811 return 0;
812
813 sheetFileName = designBlock->GetSchematicFile();
814
815 if( sheetFileName.IsEmpty() || !wxFileExists( sheetFileName ) )
816 {
817 m_frame->ShowInfoBarError( _( "Design block has no schematic to place." ), true );
818 return 0;
819 }
820 }
821 }
822 else
823 {
824 wxString* importSourceFile = aEvent.Parameter<wxString*>();
825
826 if( importSourceFile != nullptr )
827 sheetFileName = *importSourceFile;
828 }
829
830 auto setCursor =
831 [&]()
832 {
833 m_frame->GetCanvas()->SetCurrentCursor( designBlock ? KICURSOR::MOVING
835 };
836
837 auto placeSheetContents =
838 [&]()
839 {
840 SCH_COMMIT commit( m_toolMgr );
841 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
842
843 EDA_ITEMS newItems;
844 bool keepAnnotations = cfg->m_DesignBlockChooserPanel.keep_annotations;
845 bool placeAsGroup = cfg->m_DesignBlockChooserPanel.place_as_group;
846 bool screenWasModified = screen->IsContentModified();
847
848 selectionTool->ClearSelection();
849
850 // Remember existing items so we only select and commit imported items.
851 std::unordered_set<EDA_ITEM*> existingItems;
852
853 for( EDA_ITEM* item : screen->Items() )
854 existingItems.insert( item );
855
856 if( !m_frame->LoadSheetFromFile( sheetPath.Last(), &sheetPath, sheetFileName, true,
857 placingDesignBlock ) )
858 {
859 return false;
860 }
861
862 m_frame->SetSheetNumberAndCount();
863
864 m_frame->SyncView();
865 m_frame->OnModify();
866 m_frame->HardRedraw(); // Full reinit of the current screen and the display.
867
868 SCH_GROUP* group = nullptr;
869
870 if( placeAsGroup )
871 {
872 group = new SCH_GROUP( screen );
873
874 wxString baseName;
875
876 if( designBlock )
877 {
878 baseName = designBlock->GetLibId().GetLibItemName().wx_str();
879 group->SetDesignBlockLibId( designBlock->GetLibId() );
880 }
881 else
882 {
883 baseName = wxFileName( sheetFileName ).GetName();
884 }
885
886 group->SetName( UniqueGroupName( screen, baseName ) );
887 }
888
889 bool autoAnnotate = !keepAnnotations && cfg->m_AnnotatePanel.automatic;
890
891 // Select all new items
892 for( EDA_ITEM* item : screen->Items() )
893 {
894 if( !existingItems.contains( item ) )
895 {
896 // When auto-annotating, preserve original refs so that
897 // AnnotateSymbols can build correct locked groups for
898 // multi-unit symbols before assigning new references.
899 // Clearing first would leave locked groups empty, causing
900 // units from different same-value arrays to get mixed.
901 if( item->Type() == SCH_SYMBOL_T && !keepAnnotations && !autoAnnotate )
902 static_cast<SCH_SYMBOL*>( item )->ClearAnnotation( &sheetPath, false );
903
904 if( item->Type() == SCH_LINE_T )
905 item->SetFlags( STARTPOINT | ENDPOINT );
906
907 if( !item->GetParentGroup() )
908 {
909 if( placeAsGroup )
910 group->AddItem( item );
911
912 newItems.emplace_back( item );
913 }
914
915 commit.Added( item, screen );
916 }
917 }
918
919 if( placeAsGroup )
920 {
921 commit.Add( group, screen );
922 selectionTool->AddItemToSel( group );
923 }
924 else
925 {
926 selectionTool->AddItemsToSel( &newItems, true );
927 }
928
929 cursorPos = grid.Align( controls->GetMousePosition(),
930 grid.GetSelectionGrid( selectionTool->GetSelection() ) );
931 controls->ForceCursorPosition( true, cursorPos );
932
933 std::vector<SCH_ITEM*> blockItems = FlattenGroups( newItems );
934 std::optional<VECTOR2I> anchorPos = designBlockAnchor( blockItems );
935 VECTOR2I delta = anchorPos ? cursorPos - *anchorPos : VECTOR2I( 0, 0 );
936
937 // Will all be SCH_ITEMs as these were pulled from the screen->Items()
938 for( EDA_ITEM* item : newItems )
939 static_cast<SCH_ITEM*>( item )->Move( delta );
940
941 if( !keepAnnotations || placingDesignBlock )
942 {
943 if( autoAnnotate )
944 {
946 m_frame->AnnotateSymbols( &commit, ANNOTATE_SELECTION,
948 (ANNOTATE_ALGO_T) schSettings.m_AnnotateMethod,
949 true /* recursive */,
950 schSettings.m_AnnotateStartNum,
951 true /* aResetAnnotation */,
952 false, false, reporter );
953 }
954
955 // Annotation will clear selection, so we need to restore it
956 for( EDA_ITEM* item : newItems )
957 {
958 if( item->Type() == SCH_LINE_T )
959 item->SetFlags( STARTPOINT | ENDPOINT );
960 }
961
962 if( placeAsGroup )
963 selectionTool->AddItemToSel( group );
964 else
965 selectionTool->AddItemsToSel( &newItems, true );
966 }
967
968 // IS_NEW is what makes the move tool use the reference point set below, and
969 // IS_MOVING stops the selection tool replacing it on the way there.
970 for( SCH_ITEM* item : blockItems )
971 item->SetFlags( IS_NEW | IS_MOVING );
972
973 if( group )
974 group->SetFlags( IS_NEW | IS_MOVING );
975
976 selectionTool->GetSelection().SetReferencePoint( cursorPos );
977
978 // Start moving selection, cancel undoes the insertion
979 bool placed = m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit );
980
981 // Update our cursor position to the new location in case we're placing repeated copies
982 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
983
984 if( placed )
985 {
986 commit.Push( placingDesignBlock ? _( "Add Design Block" )
987 : _( "Import Schematic Sheet Content" ) );
988 }
989 else
990 {
991 commit.Revert();
992 m_frame->SetContentModified( screenWasModified );
993 }
994
995 selectionTool->RebuildSelection();
996 m_frame->UpdateHierarchyNavigator();
997
998 return placed;
999 };
1000
1001 // Whether we are placing the sheet as a sheet, or as its contents, we need to get a filename
1002 // if we weren't provided one
1003 if( sheetFileName.IsEmpty() )
1004 {
1005 wxString path;
1006 wxString file;
1007
1008 if (!placingDesignBlock)
1009 {
1010 if( sheetFileName.IsEmpty() )
1011 {
1012 path = wxPathOnly( m_frame->Prj().GetProjectFullName() );
1013 file = wxEmptyString;
1014 }
1015 else
1016 {
1017 path = wxPathOnly( sheetFileName );
1018 file = wxFileName( sheetFileName ).GetFullName();
1019 }
1020
1021 // Open file chooser dialog even if we have been provided a file so the user
1022 // can select the options they want
1023 wxFileDialog dlg( m_frame, _( "Choose Schematic" ), path, file,
1024 FILEEXT::KiCadSchematicFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1025
1026 FILEDLG_IMPORT_SHEET_CONTENTS dlgHook( cfg );
1027 dlg.SetCustomizeHook( dlgHook );
1028
1030
1031 if( dlg.ShowModal() == wxID_CANCEL )
1032 return 0;
1033
1034 sheetFileName = dlg.GetPath();
1035
1036 m_frame->GetDesignBlockPane()->UpdateCheckboxes();
1037 }
1038
1039 if( sheetFileName.IsEmpty() )
1040 return 0;
1041 }
1042
1043 // If we're placing sheet contents, we don't even want to run our tool loop, just add the items
1044 // to the canvas and run the move tool
1046 {
1047 while( placeSheetContents() && cfg->m_DesignBlockChooserPanel.repeated_placement )
1048 {}
1049
1050 m_toolMgr->RunAction( ACTIONS::selectionClear );
1051 m_view->ClearPreview();
1052 return 0;
1053 }
1054
1055 // We're placing a sheet as a sheet, we need to run a small tool loop to get the starting
1056 // coordinate of the sheet drawing
1057 SCOPED_TOOL_PUSHER raii( m_frame, aEvent );
1058
1059 Activate();
1060
1061 // Must be done after Activate() so that it gets set into the correct context
1062 getViewControls()->ShowCursor( true );
1063
1064 // Set initial cursor
1065 setCursor();
1066
1067 if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
1068 m_toolMgr->PrimeTool( { 0, 0 } );
1069
1070 // Main loop: keep receiving events
1071 while( TOOL_EVENT* evt = Wait() )
1072 {
1073 setCursor();
1074 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1075 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1076
1077 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
1078 controls->ForceCursorPosition( true, cursorPos );
1079
1080 // The tool hotkey is interpreted as a click when drawing
1081 bool isSyntheticClick = designBlock && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
1082
1083 if( evt->IsCancelInteractive() || ( designBlock && evt->IsAction( &ACTIONS::undo ) ) )
1084 {
1085 m_frame->GetInfoBar()->Dismiss();
1086 break;
1087 }
1088 else if( evt->IsActivate() && !isSyntheticClick )
1089 {
1090 m_frame->GetInfoBar()->Dismiss();
1091 break;
1092 }
1093 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
1094 || isSyntheticClick
1095 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
1096 {
1097 if( placingDesignBlock )
1098 {
1099 // drawSheet must delete designBlock
1100 m_toolMgr->PostAction( SCH_ACTIONS::drawSheetFromDesignBlock, designBlock.release() );
1101 }
1102 else
1103 {
1104 // drawSheet must delete sheetFileName
1105 m_toolMgr->PostAction( SCH_ACTIONS::drawSheetFromFile, new wxString( sheetFileName ) );
1106 }
1107
1108 break;
1109 }
1110 else if( evt->IsClick( BUT_RIGHT ) )
1111 {
1112 // Warp after context menu only if dragging...
1113 if( !designBlock )
1114 m_toolMgr->VetoContextMenuMouseWarp();
1115
1116 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
1117 }
1118 else if( evt->IsAction( &ACTIONS::duplicate )
1119 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem ) )
1120 {
1121 wxBell();
1122 }
1123 else
1124 {
1125 evt->SetPassEvent();
1126 }
1127 }
1128
1129 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1130 return 0;
1131}
1132
1133
1135{
1136 SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
1137 bool immediateMode = image != nullptr;
1138 bool ignorePrimePosition = false;
1139 COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
1140
1141 if( m_inDrawingTool )
1142 return 0;
1143
1145
1148 VECTOR2I cursorPos;
1149
1150 m_toolMgr->RunAction( ACTIONS::selectionClear );
1151
1152 // Add all the drawable symbols to preview
1153 if( image )
1154 {
1155 image->SetPosition( getViewControls()->GetCursorPosition() );
1156 m_view->ClearPreview();
1157 m_view->AddToPreview( image, false ); // Add, but not give ownership
1158 }
1159
1160 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
1161 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
1162
1163 auto setCursor =
1164 [&]()
1165 {
1166 if( image )
1167 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
1168 else
1169 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1170 };
1171
1172 auto cleanup =
1173 [&]()
1174 {
1175 m_toolMgr->RunAction( ACTIONS::selectionClear );
1176 m_view->ClearPreview();
1177 m_view->RecacheAllItems();
1178 delete image;
1179 image = nullptr;
1180 };
1181
1182 Activate();
1183
1184 // Must be done after Activate() so that it gets set into the correct context
1185 getViewControls()->ShowCursor( true );
1186
1187 // Set initial cursor
1188 setCursor();
1189
1190 // Prime the pump
1191 if( image )
1192 {
1193 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1194 }
1195 else if( aEvent.HasPosition() )
1196 {
1197 m_toolMgr->PrimeTool( aEvent.Position() );
1198 }
1199 else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
1200 {
1201 m_toolMgr->PrimeTool( { 0, 0 } );
1202 ignorePrimePosition = true;
1203 }
1204
1205 // Main loop: keep receiving events
1206 while( TOOL_EVENT* evt = Wait() )
1207 {
1208 setCursor();
1209 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1210 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1211
1212 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
1213 controls->ForceCursorPosition( true, cursorPos );
1214
1215 // The tool hotkey is interpreted as a click when drawing
1216 bool isSyntheticClick = image && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
1217
1218 if( evt->IsCancelInteractive() || ( image && evt->IsAction( &ACTIONS::undo ) ) )
1219 {
1220 m_frame->GetInfoBar()->Dismiss();
1221
1222 if( image )
1223 cleanup();
1224 else
1225 break;
1226
1227 if( immediateMode )
1228 break;
1229 }
1230 else if( evt->IsActivate() && !isSyntheticClick )
1231 {
1232 if( image && evt->IsMoveTool() )
1233 {
1234 // we're already moving our own item; ignore the move tool
1235 evt->SetPassEvent( false );
1236 continue;
1237 }
1238
1239 if( image )
1240 {
1241 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel image creation." ) );
1242 evt->SetPassEvent( false );
1243 continue;
1244 }
1245
1246 if( evt->IsMoveTool() )
1247 {
1248 // Make sure we come back after the move tool is done
1249 m_frame->PushTool( originalEvent );
1250 }
1251
1252 break;
1253 }
1254 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
1255 || isSyntheticClick
1256 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
1257 {
1258 if( !image )
1259 {
1260 m_toolMgr->RunAction( ACTIONS::selectionClear );
1261
1262 wxFileDialog dlg( m_frame, _( "Choose Image" ), m_mruPath, wxEmptyString, FILEEXT::ImageFileWildcard(),
1263 wxFD_OPEN );
1264
1266
1267 bool cancelled = false;
1268
1270 [&]()
1271 {
1272 cancelled = dlg.ShowModal() != wxID_OK;
1273 } );
1274
1275 if( cancelled )
1276 continue;
1277
1278 // If we started with a hotkey which has a position then warp back to that.
1279 // Otherwise update to the current mouse position pinned inside the autoscroll
1280 // boundaries.
1281 if( evt->IsPrime() && !ignorePrimePosition )
1282 {
1283 cursorPos = grid.Align( evt->Position() );
1284 getViewControls()->WarpMouseCursor( cursorPos, true );
1285 }
1286 else
1287 {
1289 cursorPos = getViewControls()->GetMousePosition();
1290 }
1291
1292 wxString fullFilename = dlg.GetPath();
1293 m_mruPath = wxPathOnly( fullFilename );
1294
1295 if( wxFileExists( fullFilename ) )
1296 image = new SCH_BITMAP( cursorPos );
1297
1298 if( !image || !image->GetReferenceImage().ReadImageFile( fullFilename ) )
1299 {
1300 wxMessageBox( wxString::Format( _( "Could not load image from '%s'." ), fullFilename ) );
1301 delete image;
1302 image = nullptr;
1303 continue;
1304 }
1305
1306 image->SetFlags( IS_NEW | IS_MOVING );
1307
1308 m_frame->SaveCopyForRepeatItem( image );
1309
1310 m_view->ClearPreview();
1311 m_view->AddToPreview( image, false ); // Add, but not give ownership
1312 m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
1313
1314 m_selectionTool->AddItemToSel( image );
1315
1316 getViewControls()->SetCursorPosition( cursorPos, false );
1317 setCursor();
1318 }
1319 else
1320 {
1321 SCH_COMMIT commit( m_toolMgr );
1322 commit.Add( image, m_frame->GetScreen() );
1323 commit.Push( _( "Place Image" ) );
1324
1325 image = nullptr;
1327
1328 m_view->ClearPreview();
1329
1330 if( immediateMode )
1331 break;
1332 }
1333 }
1334 else if( evt->IsClick( BUT_RIGHT ) )
1335 {
1336 // Warp after context menu only if dragging...
1337 if( !image )
1338 m_toolMgr->VetoContextMenuMouseWarp();
1339
1340 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
1341 }
1342 else if( evt->IsAction( &ACTIONS::duplicate )
1343 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
1344 || evt->IsAction( &ACTIONS::paste ) )
1345 {
1346 if( image )
1347 {
1348 // This doesn't really make sense; we'll just end up dragging a stack of
1349 // objects so we ignore the duplicate and just carry on.
1350 wxBell();
1351 continue;
1352 }
1353
1354 // Exit. The duplicate/repeat/paste will run in its own loop.
1355 evt->SetPassEvent();
1356 break;
1357 }
1358 else if( image && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
1359 {
1360 image->SetPosition( cursorPos );
1361 m_view->ClearPreview();
1362 m_view->AddToPreview( image, false ); // Add, but not give ownership
1363 m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
1364 m_frame->SetMsgPanel( image );
1365 }
1366 else if( image && evt->IsAction( &ACTIONS::doDelete ) )
1367 {
1368 cleanup();
1369 }
1370 else if( image && evt->IsAction( &ACTIONS::redo ) )
1371 {
1372 wxBell();
1373 }
1374 else
1375 {
1376 evt->SetPassEvent();
1377 }
1378
1379 // Enable autopanning and cursor capture only when there is an image to be placed
1380 getViewControls()->SetAutoPan( image != nullptr );
1381 getViewControls()->CaptureCursor( image != nullptr );
1382 }
1383
1384 getViewControls()->SetAutoPan( false );
1385 getViewControls()->CaptureCursor( false );
1386 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1387
1388 return 0;
1389}
1390
1391
1393{
1394 VECTOR2I cursorPos;
1395 KICAD_T type = aEvent.Parameter<KICAD_T>();
1398 SCH_ITEM* previewItem;
1399 bool loggedInfoBarError = false;
1400 wxString description;
1401 SCH_SCREEN* screen = m_frame->GetScreen();
1402 bool allowRepeat = false; // Set to true to allow new item repetition
1403
1404 if( m_inDrawingTool )
1405 return 0;
1406
1408
1409 if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
1410 {
1411 SCH_SELECTION& selection = m_selectionTool->GetSelection();
1412 SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
1413
1414 if( wire )
1415 {
1416 SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
1417 VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() );
1418 getViewControls()->SetCrossHairCursorPosition( nearest, false );
1419 getViewControls()->WarpMouseCursor( getViewControls()->GetCursorPosition(), true );
1420 }
1421 }
1422
1423 switch( type )
1424 {
1425 case SCH_NO_CONNECT_T:
1426 previewItem = new SCH_NO_CONNECT( cursorPos );
1427 previewItem->SetParent( screen );
1428 description = _( "Add No Connect Flag" );
1429 allowRepeat = true;
1430 break;
1431
1432 case SCH_JUNCTION_T:
1433 previewItem = new SCH_JUNCTION( cursorPos );
1434 previewItem->SetParent( screen );
1435 description = _( "Add Junction" );
1436 break;
1437
1439 previewItem = new SCH_BUS_WIRE_ENTRY( cursorPos );
1440 previewItem->SetParent( screen );
1441 description = _( "Add Wire to Bus Entry" );
1442 allowRepeat = true;
1443 break;
1444
1445 default:
1446 wxASSERT_MSG( false, "Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
1447 return 0;
1448 }
1449
1450 m_toolMgr->RunAction( ACTIONS::selectionClear );
1451
1452 cursorPos = aEvent.HasPosition() ? aEvent.Position() : controls->GetMousePosition();
1453
1454 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
1455 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
1456
1457 auto setCursor =
1458 [&]()
1459 {
1460 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
1461 };
1462
1463 Activate();
1464
1465 // Must be done after Activate() so that it gets set into the correct context
1466 getViewControls()->ShowCursor( true );
1467
1468 // Set initial cursor
1469 setCursor();
1470
1471 m_view->ClearPreview();
1472 m_view->AddToPreview( previewItem->Clone() );
1473
1474 // Prime the pump
1475 if( aEvent.HasPosition() && type != SCH_SHEET_PIN_T )
1476 m_toolMgr->PrimeTool( aEvent.Position() );
1477 else
1478 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1479
1480 // Main loop: keep receiving events
1481 while( TOOL_EVENT* evt = Wait() )
1482 {
1483 setCursor();
1484 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1485 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1486
1487 cursorPos = evt->IsPrime() ? evt->Position() : controls->GetMousePosition();
1488 cursorPos = grid.ResolveSnap( cursorPos, grid.GetItemGrid( previewItem ), nullptr ).position;
1489 controls->ForceCursorPosition( true, cursorPos );
1490
1491 if( evt->IsCancelInteractive() )
1492 {
1493 break;
1494 }
1495 else if( evt->IsActivate() )
1496 {
1497 if( evt->IsMoveTool() )
1498 {
1499 // Make sure we come back after the move tool runs
1500 frame()->PushTool( originalEvent );
1501 }
1502
1503 break;
1504 }
1505 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
1506 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
1507 {
1508 if( SCH_ITEM* existingItem = screen->GetItem( cursorPos, 0, type ) )
1509 {
1510 // No connects can be "toggled"/removed by clicking on them again
1511 // It helps with not having to fight pin selection ambiguity
1512 if( type == SCH_NO_CONNECT_T )
1513 {
1514 SCH_COMMIT commit( m_toolMgr );
1515 commit.Removed( existingItem, screen );
1516 m_frame->RemoveFromScreen( existingItem, screen );
1517 commit.Push( _( "Remove No Connect Flag" ) );
1518 }
1519 }
1520 else
1521 {
1522 if( type == SCH_JUNCTION_T )
1523 {
1524 if( !screen->IsExplicitJunctionAllowed( cursorPos ) )
1525 {
1526 m_frame->ShowInfoBarError( _( "Junction location contains no joinable wires and/or pins." ) );
1527 loggedInfoBarError = true;
1528 continue;
1529 }
1530 else if( loggedInfoBarError )
1531 {
1532 m_frame->GetInfoBar()->Dismiss();
1533 }
1534 }
1535
1536 if( type == SCH_JUNCTION_T )
1537 {
1538 SCH_COMMIT commit( m_toolMgr );
1540 lwbTool->AddJunction( &commit, screen, cursorPos );
1541
1542 m_frame->Schematic().CleanUp( &commit );
1543
1544 commit.Push( description );
1545 }
1546 else
1547 {
1548 SCH_ITEM* newItem = static_cast<SCH_ITEM*>( previewItem->Clone() );
1549 const_cast<KIID&>( newItem->m_Uuid ) = KIID();
1550 newItem->SetPosition( cursorPos );
1551 newItem->SetFlags( IS_NEW );
1552 m_frame->AddToScreen( newItem, screen );
1553
1554 if( allowRepeat )
1555 m_frame->SaveCopyForRepeatItem( newItem );
1556
1557 SCH_COMMIT commit( m_toolMgr );
1558 commit.Added( newItem, screen );
1559
1560 m_frame->Schematic().CleanUp( &commit );
1561
1562 commit.Push( description );
1563 }
1564 }
1565
1566 if( evt->IsDblClick( BUT_LEFT )
1567 || evt->IsAction( &ACTIONS::cursorDblClick )
1568 || type == SCH_SHEET_PIN_T ) // Finish tool.
1569 {
1570 break;
1571 }
1572 }
1573 else if( evt->IsClick( BUT_RIGHT ) )
1574 {
1575 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
1576 }
1577 else if( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() )
1578 {
1579 previewItem->SetPosition( cursorPos );
1580 m_view->ClearPreview();
1581 m_view->AddToPreview( previewItem->Clone() );
1582 m_frame->SetMsgPanel( previewItem );
1583 }
1584 else if( evt->Category() == TC_COMMAND )
1585 {
1586 if( ( type == SCH_BUS_WIRE_ENTRY_T ) && ( evt->IsAction( &SCH_ACTIONS::rotateCW )
1587 || evt->IsAction( &SCH_ACTIONS::rotateCCW )
1588 || evt->IsAction( &SCH_ACTIONS::mirrorV )
1589 || evt->IsAction( &SCH_ACTIONS::mirrorH ) ) )
1590 {
1591 SCH_BUS_ENTRY_BASE* busItem = static_cast<SCH_BUS_ENTRY_BASE*>( previewItem );
1592
1593 if( evt->IsAction( &SCH_ACTIONS::rotateCW ) )
1594 {
1595 busItem->Rotate( busItem->GetPosition(), false );
1596 }
1597 else if( evt->IsAction( &SCH_ACTIONS::rotateCCW ) )
1598 {
1599 busItem->Rotate( busItem->GetPosition(), true );
1600 }
1601 else if( evt->IsAction( &SCH_ACTIONS::mirrorV ) )
1602 {
1603 busItem->MirrorVertically( busItem->GetPosition().y );
1604 }
1605 else if( evt->IsAction( &SCH_ACTIONS::mirrorH ) )
1606 {
1607 busItem->MirrorHorizontally( busItem->GetPosition().x );
1608 }
1609
1610 m_view->ClearPreview();
1611 m_view->AddToPreview( previewItem->Clone() );
1612 }
1613 else if( evt->IsAction( &SCH_ACTIONS::properties ) )
1614 {
1615 switch( type )
1616 {
1618 {
1619 std::deque<SCH_ITEM*> strokeItems;
1620 strokeItems.push_back( previewItem );
1621
1622 DIALOG_WIRE_BUS_PROPERTIES dlg( m_frame, strokeItems );
1623
1625 [&]()
1626 {
1627 dlg.ShowModal();
1628 } );
1629
1630 break;
1631 }
1632
1633 case SCH_JUNCTION_T:
1634 {
1635 std::deque<SCH_JUNCTION*> junctions;
1636 junctions.push_back( static_cast<SCH_JUNCTION*>( previewItem ) );
1637
1638 DIALOG_JUNCTION_PROPS dlg( m_frame, junctions );
1639
1641 [&]()
1642 {
1643 dlg.ShowModal();
1644 } );
1645
1646 break;
1647 }
1648
1649 default:
1650 // Do nothing
1651 break;
1652 }
1653
1654 m_view->ClearPreview();
1655 m_view->AddToPreview( previewItem->Clone() );
1656 }
1657 else
1658 {
1659 evt->SetPassEvent();
1660 }
1661 }
1662 else
1663 {
1664 evt->SetPassEvent();
1665 }
1666 }
1667
1668 delete previewItem;
1669 m_view->ClearPreview();
1670
1671 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1672 controls->ForceCursorPosition( false );
1673
1674 return 0;
1675}
1676
1677
1679{
1680 for( SCH_ITEM* item : m_frame->GetScreen()->Items().Overlapping( SCH_LINE_T, aPosition ) )
1681 {
1682 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1683
1684 if( line->GetEditFlags() & STRUCT_DELETED )
1685 continue;
1686
1687 if( line->IsWire() )
1688 return line;
1689 }
1690
1691 return nullptr;
1692}
1693
1694
1696{
1697 wxASSERT( aWire->IsWire() );
1698
1699 SCH_SHEET_PATH sheetPath = m_frame->GetCurrentSheet();
1700
1701 const auto labelDriverName = []( const auto& aConnection ) -> wxString
1702 {
1703 SCH_ITEM* driver = aConnection.Driver();
1704
1705 if( driver && driver->IsType( { SCH_LABEL_T, SCH_GLOBAL_LABEL_T } ) )
1706 return aConnection.LocalName();
1707
1708 return wxEmptyString;
1709 };
1710
1711 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1712 {
1713 const auto connection = m_frame->Schematic().Connectivity().Connection( aWire->m_Uuid, sheetPath.PathRef() );
1714 return connection ? labelDriverName( *connection ) : wxString();
1715 }
1716
1717 const SCH_CONNECTION* wireConnection = aWire->Connection( &sheetPath );
1718 return wireConnection ? labelDriverName( *wireConnection ) : wxString();
1719}
1720
1721
1722bool SCH_DRAWING_TOOLS::createNewLabel( const VECTOR2I& aPosition, int aType,
1723 std::list<std::unique_ptr<SCH_LABEL_BASE>>& aLabelList )
1724{
1725 SCHEMATIC* schematic = getModel<SCHEMATIC>();
1726 SCHEMATIC_SETTINGS& settings = schematic->Settings();
1727 SCH_LABEL_BASE* labelItem = nullptr;
1728 SCH_GLOBALLABEL* globalLabel = nullptr;
1729 wxString netName;
1730
1731 switch( aType )
1732 {
1733 case LAYER_LOCLABEL:
1734 labelItem = new SCH_LABEL( aPosition );
1735
1736 if( SCH_LINE* wire = findWire( aPosition ) )
1737 netName = findWireLabelDriverName( wire );
1738
1739 break;
1740
1742 labelItem = new SCH_DIRECTIVE_LABEL( aPosition );
1743 labelItem->SetShape( m_lastNetClassFlagShape );
1744 labelItem->GetFields().emplace_back( labelItem, FIELD_T::USER, wxT( "Netclass" ) );
1745 labelItem->GetFields().emplace_back( labelItem, FIELD_T::USER, wxT( "Component Class" ) );
1746 labelItem->GetFields().back().SetItalic( true );
1747 labelItem->GetFields().back().SetVisible( true );
1748 break;
1749
1750 case LAYER_HIERLABEL:
1751 labelItem = new SCH_HIERLABEL( aPosition );
1752 labelItem->SetShape( m_lastGlobalLabelShape );
1754 break;
1755
1756 case LAYER_GLOBLABEL:
1757 globalLabel = new SCH_GLOBALLABEL( aPosition );
1758 globalLabel->SetShape( m_lastGlobalLabelShape );
1761 labelItem = globalLabel;
1762
1763 if( SCH_LINE* wire = findWire( aPosition ) )
1764 netName = findWireLabelDriverName( wire );
1765
1766 break;
1767
1768 default:
1769 wxFAIL_MSG( "SCH_DRAWING_TOOLS::createNewLabel() unknown label type" );
1770 return false;
1771 }
1772
1773 // The normal parent is the current screen for these labels, set by SCH_SCREEN::Append()
1774 // but it is also used during placement for SCH_HIERLABEL before beeing appended
1775 labelItem->SetParent( m_frame->GetScreen() );
1776
1777 labelItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
1778
1779 if( aType != LAYER_NETCLASS_REFS )
1780 {
1781 // Must be after SetTextSize()
1782 labelItem->SetBold( m_lastTextBold );
1783 labelItem->SetItalic( m_lastTextItalic );
1784 }
1785
1786 labelItem->SetSpinStyle( m_lastTextOrientation );
1787 labelItem->SetFlags( IS_NEW | IS_MOVING );
1788
1789 if( !netName.IsEmpty() )
1790 {
1791 // Auto-create from attached wire
1792 labelItem->SetText( netName );
1793 }
1794 else
1795 {
1796 DIALOG_LABEL_PROPERTIES dlg( m_frame, labelItem, true );
1797
1798 dlg.SetLabelList( &aLabelList );
1799
1800 // QuasiModal required for syntax help and Scintilla auto-complete
1801 if( dlg.ShowQuasiModal() != wxID_OK )
1802 {
1804 delete labelItem;
1805 return false;
1806 }
1807 }
1808
1809 if( aType != LAYER_NETCLASS_REFS )
1810 {
1811 m_lastTextBold = labelItem->IsBold();
1812 m_lastTextItalic = labelItem->IsItalic();
1813 }
1814
1815 m_lastTextOrientation = labelItem->GetSpinStyle();
1816
1817 if( aType == LAYER_GLOBLABEL || aType == LAYER_HIERLABEL )
1818 {
1819 m_lastGlobalLabelShape = labelItem->GetShape();
1821 }
1822 else if( aType == LAYER_NETCLASS_REFS )
1823 {
1824 m_lastNetClassFlagShape = labelItem->GetShape();
1825 }
1826
1827 if( aLabelList.empty() )
1828 aLabelList.push_back( std::unique_ptr<SCH_LABEL_BASE>( labelItem ) );
1829 else // DIALOG_LABEL_PROPERTIES already filled in aLabelList; labelItem is extraneous to needs
1830 delete labelItem;
1831
1832 return true;
1833}
1834
1835
1837{
1838 SCHEMATIC* schematic = getModel<SCHEMATIC>();
1839 SCHEMATIC_SETTINGS& settings = schematic->Settings();
1840 SCH_TEXT* textItem = nullptr;
1841
1842 textItem = new SCH_TEXT( aPosition );
1843 textItem->SetParent( schematic );
1844 textItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
1845 // Must be after SetTextSize()
1846 textItem->SetBold( m_lastTextBold );
1847 textItem->SetItalic( m_lastTextItalic );
1850 textItem->SetTextAngle( m_lastTextAngle );
1851 textItem->SetFlags( IS_NEW | IS_MOVING );
1852
1853 DIALOG_TEXT_PROPERTIES dlg( m_frame, textItem );
1854
1855 // QuasiModal required for syntax help and Scintilla auto-complete
1856 if( dlg.ShowQuasiModal() != wxID_OK )
1857 {
1858 delete textItem;
1859 return nullptr;
1860 }
1861
1862 m_lastTextBold = textItem->IsBold();
1863 m_lastTextItalic = textItem->IsItalic();
1864 m_lastTextHJustify = textItem->GetHorizJustify();
1865 m_lastTextVJustify = textItem->GetVertJustify();
1866 m_lastTextAngle = textItem->GetTextAngle();
1867 return textItem;
1868}
1869
1870
1872{
1873 SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
1874 SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( aSheet );
1875
1876 pin->SetFlags( IS_NEW | IS_MOVING );
1877 pin->SetText( std::to_string( aSheet->GetPins().size() + 1 ) );
1878 pin->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
1879 pin->SetPosition( aPosition );
1880 pin->ClearSelected();
1881
1882 m_lastSheetPinType = pin->GetShape();
1883
1884 return pin;
1885}
1886
1887
1889 const VECTOR2I& aPosition,
1890 SCH_HIERLABEL* aLabel )
1891{
1892 auto pin = createNewSheetPin( aSheet, aPosition );
1893 pin->SetText( aLabel->GetText() );
1894 pin->SetShape( aLabel->GetShape() );
1895 return pin;
1896}
1897
1898
1900{
1901 SCH_ITEM* item = nullptr;
1904 bool ignorePrimePosition = false;
1905 COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
1906 SCH_SHEET* sheet = nullptr;
1907 wxString description;
1908
1909 std::list<std::unique_ptr<SCH_LABEL_BASE>> itemsToPlace;
1910
1911 if( m_inDrawingTool )
1912 return 0;
1913
1915
1916 bool isText = aEvent.IsAction( &SCH_ACTIONS::placeSchematicText );
1917 bool isGlobalLabel = aEvent.IsAction( &SCH_ACTIONS::placeGlobalLabel );
1918 bool isHierLabel = aEvent.IsAction( &SCH_ACTIONS::placeHierLabel );
1919 bool isClassLabel = aEvent.IsAction( &SCH_ACTIONS::placeClassLabel );
1920 bool isNetLabel = aEvent.IsAction( &SCH_ACTIONS::placeLabel );
1921 bool isSheetPin = aEvent.IsAction( &SCH_ACTIONS::placeSheetPin );
1922
1923 GRID_HELPER_GRIDS snapGrid = isText ? GRID_TEXT : GRID_CONNECTABLE;
1924
1925 // If we have a selected sheet use it, otherwise try to get one under the cursor
1926 if( isSheetPin )
1927 sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
1928
1929 m_toolMgr->RunAction( ACTIONS::selectionClear );
1930
1931 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
1932 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
1933
1934 auto setCursor =
1935 [&]()
1936 {
1937 if( item )
1938 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
1939 else if( isText )
1940 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
1941 else if( isGlobalLabel )
1942 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_GLOBAL );
1943 else if( isNetLabel || isClassLabel )
1944 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_NET );
1945 else if( isHierLabel )
1946 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LABEL_HIER );
1947 else
1948 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
1949 };
1950
1951 auto updatePreview =
1952 [&]()
1953 {
1954 m_view->ClearPreview();
1955 m_view->AddToPreview( item, false );
1956 item->RunOnChildren( [&]( SCH_ITEM* aChild )
1957 {
1958 m_view->AddToPreview( aChild, false );
1959 },
1961 m_frame->SetMsgPanel( item );
1962 };
1963
1964 auto cleanup =
1965 [&]()
1966 {
1967 m_toolMgr->RunAction( ACTIONS::selectionClear );
1968 m_view->ClearPreview();
1969 delete item;
1970 item = nullptr;
1971
1972 while( !itemsToPlace.empty() )
1973 itemsToPlace.erase( itemsToPlace.begin() );
1974 };
1975
1976 auto prepItemForPlacement =
1977 [&]( SCH_ITEM* aItem, const VECTOR2I& cursorPos )
1978 {
1979 item->SetPosition( cursorPos );
1980
1981 item->SetFlags( IS_NEW | IS_MOVING );
1982
1983 // Not placed yet, so pass a nullptr screen reference
1984 item->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
1985
1986 updatePreview();
1987 m_selectionTool->ClearSelection( true );
1988 m_selectionTool->AddItemToSel( item );
1989 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1990
1991 // update the cursor so it looks correct before another event
1992 setCursor();
1993 };
1994
1995 Activate();
1996
1997 // Must be done after Activate() so that it gets set into the correct context
1998 controls->ShowCursor( true );
1999
2000 // Set initial cursor
2001 setCursor();
2002
2003 if( aEvent.HasPosition() )
2004 {
2005 m_toolMgr->PrimeTool( aEvent.Position() );
2006 }
2007 else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate()
2008 && ( isText || isGlobalLabel || isHierLabel || isClassLabel || isNetLabel ) )
2009 {
2010 m_toolMgr->PrimeTool( { 0, 0 } );
2011 ignorePrimePosition = true;
2012 }
2013
2014 SCH_COMMIT commit( m_toolMgr );
2015
2016 // Main loop: keep receiving events
2017 while( TOOL_EVENT* evt = Wait() )
2018 {
2019 setCursor();
2020 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2021 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2022
2023 VECTOR2I cursorPos = controls->GetMousePosition();
2024 cursorPos = grid.ResolveSnap( cursorPos, snapGrid, item ).position;
2025 controls->ForceCursorPosition( true, cursorPos );
2026
2027 // The tool hotkey is interpreted as a click when drawing
2028 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
2029
2030 if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
2031 {
2032 m_frame->GetInfoBar()->Dismiss();
2033
2034 if( item )
2035 cleanup();
2036 else
2037 break;
2038 }
2039 else if( evt->IsActivate() && !isSyntheticClick )
2040 {
2041 if( item && evt->IsMoveTool() )
2042 {
2043 // we're already moving our own item; ignore the move tool
2044 evt->SetPassEvent( false );
2045 continue;
2046 }
2047
2048 if( item )
2049 {
2050 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel item creation." ) );
2051 evt->SetPassEvent( false );
2052 continue;
2053 }
2054
2055 if( evt->IsPointEditor() )
2056 {
2057 // don't exit (the point editor runs in the background)
2058 continue;
2059 }
2060
2061 if( evt->IsMoveTool() )
2062 {
2063 // Make sure we come back after the move tool runs
2064 frame()->PushTool( originalEvent );
2065 }
2066
2067 break;
2068 }
2069 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
2070 || isSyntheticClick
2071 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
2072 {
2073 PLACE_NEXT:
2074 // First click creates...
2075 if( !item )
2076 {
2077 m_toolMgr->RunAction( ACTIONS::selectionClear );
2078
2079 if( isText )
2080 {
2081 item = createNewText( cursorPos );
2082 description = _( "Add Text" );
2083 }
2084 else if( isHierLabel )
2085 {
2086 if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
2087 {
2088 auto pin = static_cast<SCH_HIERLABEL*>( m_dialogSyncSheetPin->GetPlacementTemplate() );
2089 SCH_HIERLABEL* label = new SCH_HIERLABEL( cursorPos );
2090 SCHEMATIC* schematic = getModel<SCHEMATIC>();
2091 label->SetText( pin->GetText() );
2092 label->SetShape( pin->GetShape() );
2094 label->SetParent( schematic );
2095 label->SetBold( m_lastTextBold );
2096 label->SetItalic( m_lastTextItalic );
2098 label->SetTextSize( VECTOR2I( schematic->Settings().m_DefaultTextSize,
2099 schematic->Settings().m_DefaultTextSize ) );
2100 label->SetFlags( IS_NEW | IS_MOVING );
2101 itemsToPlace.push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
2102 }
2103 else
2104 {
2105 createNewLabel( cursorPos, LAYER_HIERLABEL, itemsToPlace );
2106 }
2107
2108 description = _( "Add Hierarchical Label" );
2109 }
2110 else if( isNetLabel )
2111 {
2112 createNewLabel( cursorPos, LAYER_LOCLABEL, itemsToPlace );
2113 description = _( "Add Label" );
2114 }
2115 else if( isGlobalLabel )
2116 {
2117 createNewLabel( cursorPos, LAYER_GLOBLABEL, itemsToPlace );
2118 description = _( "Add Label" );
2119 }
2120 else if( isClassLabel )
2121 {
2122 createNewLabel( cursorPos, LAYER_NETCLASS_REFS, itemsToPlace );
2123 description = _( "Add Label" );
2124 }
2125 else if( isSheetPin )
2126 {
2127 EDA_ITEM* i = nullptr;
2128
2129 // If we didn't have a sheet selected, try to find one under the cursor
2130 if( !sheet && m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) )
2131 sheet = dynamic_cast<SCH_SHEET*>( i );
2132
2133 if( !sheet )
2134 {
2135 m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
2136 m_statusPopup->SetText( _( "Click over a sheet." ) );
2137 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
2138 m_statusPopup->PopupFor( 2000 );
2139 item = nullptr;
2140 }
2141 else
2142 {
2143 // User is using the 'Sync Sheet Pins' tool
2144 if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
2145 {
2146 item = createNewSheetPinFromLabel( sheet, cursorPos,
2147 m_dialogSyncSheetPin->GetPlacementTemplate() );
2148 }
2149 else
2150 {
2151 // User is using the 'Place Sheet Pins' tool
2152 SCH_HIERLABEL* label = importHierLabel( sheet );
2153
2154 if( !label )
2155 {
2156 m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
2157 m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
2158 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
2159 m_statusPopup->PopupFor( 2000 );
2160 item = nullptr;
2161 break;
2162 }
2163
2164 item = createNewSheetPinFromLabel( sheet, cursorPos, label );
2165 }
2166 }
2167
2168 description = _( "Add Sheet Pin" );
2169 }
2170
2171 // If we started with a hotkey which has a position then warp back to that.
2172 // Otherwise update to the current mouse position pinned inside the autoscroll
2173 // boundaries.
2174 if( evt->IsPrime() && !ignorePrimePosition )
2175 {
2176 cursorPos = grid.Align( evt->Position() );
2177 getViewControls()->WarpMouseCursor( cursorPos, true );
2178 }
2179 else
2180 {
2182 cursorPos = getViewControls()->GetMousePosition();
2183 cursorPos = grid.ResolveSnap( cursorPos, snapGrid, item ).position;
2184 }
2185
2186 if( !itemsToPlace.empty() )
2187 {
2188 item = itemsToPlace.front().release();
2189 itemsToPlace.pop_front();
2190 }
2191
2192 if( item )
2193 prepItemForPlacement( item, cursorPos );
2194
2195 if( m_frame->GetMoveWarpsCursor() )
2196 controls->SetCursorPosition( cursorPos, false );
2197
2198 m_toolMgr->PostAction( ACTIONS::refreshPreview );
2199 }
2200 else // ... and second click places:
2201 {
2202 item->ClearFlags( IS_MOVING );
2203
2204 if( item->IsConnectable() )
2205 m_frame->AutoRotateItem( m_frame->GetScreen(), item );
2206
2207 if( isSheetPin && sheet )
2208 {
2209 // Sheet pins are owned by their parent sheet.
2210 commit.Modify( sheet, m_frame->GetScreen() );
2211 sheet->AddPin( (SCH_SHEET_PIN*) item );
2212 }
2213 else
2214 {
2215 m_frame->SaveCopyForRepeatItem( item );
2216 m_frame->AddToScreen( item, m_frame->GetScreen() );
2217 commit.Added( item, m_frame->GetScreen() );
2218 }
2219
2220 item->AutoplaceFields( m_frame->GetScreen(), AUTOPLACE_AUTO );
2221
2222 commit.Push( description );
2223
2224 m_view->ClearPreview();
2225
2226 if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
2227 {
2228 m_dialogSyncSheetPin->EndPlaceItem( item );
2229
2230 if( m_dialogSyncSheetPin->CanPlaceMore() )
2231 {
2232 item = nullptr;
2233 goto PLACE_NEXT;
2234 }
2235
2236 m_toolMgr->RunAction( ACTIONS::selectionClear );
2237 m_dialogSyncSheetPin->Show( true );
2238 break;
2239 }
2240
2241 item = nullptr;
2242
2243 if( isSheetPin && sheet )
2244 {
2245 SCH_HIERLABEL* label = importHierLabel( sheet );
2246
2247 if( !label )
2248 {
2249 m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
2250 m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
2251 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
2252 m_statusPopup->PopupFor( 2000 );
2253 break;
2254 }
2255
2256 item = createNewSheetPinFromLabel( sheet, cursorPos, label );
2257 }
2258 else if( !itemsToPlace.empty() )
2259 {
2260 item = itemsToPlace.front().release();
2261 itemsToPlace.pop_front();
2262 prepItemForPlacement( item, cursorPos );
2263 }
2264 }
2265 }
2266 else if( evt->IsClick( BUT_RIGHT ) )
2267 {
2268 // Warp after context menu only if dragging...
2269 if( !item )
2270 m_toolMgr->VetoContextMenuMouseWarp();
2271
2272 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
2273 }
2274 else if( item && evt->IsSelectionEvent() )
2275 {
2276 // This happens if our text was replaced out from under us by ConvertTextType()
2277 SCH_SELECTION& selection = m_selectionTool->GetSelection();
2278
2279 if( selection.GetSize() == 1 )
2280 {
2281 item = (SCH_ITEM*) selection.Front();
2282 updatePreview();
2283 }
2284 else
2285 {
2286 item = nullptr;
2287 }
2288 }
2289 else if( evt->IsAction( &ACTIONS::increment ) )
2290 {
2291 if( evt->HasParameter() )
2292 m_toolMgr->RunSynchronousAction( ACTIONS::increment, &commit, evt->Parameter<ACTIONS::INCREMENT>() );
2293 else
2294 m_toolMgr->RunSynchronousAction( ACTIONS::increment, &commit, ACTIONS::INCREMENT { 1, 0 } );
2295 }
2296 else if( evt->IsAction( &ACTIONS::duplicate )
2297 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
2298 || evt->IsAction( &ACTIONS::paste ) )
2299 {
2300 if( item )
2301 {
2302 wxBell();
2303 continue;
2304 }
2305
2306 // Exit. The duplicate/repeat/paste will run in its own loop.
2307 evt->SetPassEvent();
2308 break;
2309 }
2310 else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
2311 {
2312 item->CalcEdit( cursorPos );
2313 m_view->ClearPreview();
2314 m_view->AddToPreview( item->Clone() );
2315 m_frame->SetMsgPanel( item );
2316 }
2317 else if( item && evt->IsAction( &ACTIONS::doDelete ) )
2318 {
2319 cleanup();
2320 }
2321 else if( evt->IsAction( &ACTIONS::redo ) )
2322 {
2323 wxBell();
2324 }
2325 else if( item && ( evt->IsAction( &SCH_ACTIONS::toDLabel )
2326 || evt->IsAction( &SCH_ACTIONS::toGLabel )
2327 || evt->IsAction( &SCH_ACTIONS::toHLabel )
2328 || evt->IsAction( &SCH_ACTIONS::toLabel )
2329 || evt->IsAction( &SCH_ACTIONS::toText )
2330 || evt->IsAction( &SCH_ACTIONS::toTextBox ) ) )
2331 {
2332 wxBell();
2333 }
2334 else if( item && ( evt->IsAction( &SCH_ACTIONS::properties )
2335 || evt->IsAction( &SCH_ACTIONS::autoplaceFields )
2336 || evt->IsAction( &SCH_ACTIONS::rotateCW )
2337 || evt->IsAction( &SCH_ACTIONS::rotateCCW )
2338 || evt->IsAction( &SCH_ACTIONS::mirrorV )
2339 || evt->IsAction( &SCH_ACTIONS::mirrorH ) ) )
2340 {
2341 m_toolMgr->PostAction( ACTIONS::refreshPreview );
2342 evt->SetPassEvent();
2343 }
2344 else
2345 {
2346 evt->SetPassEvent();
2347 }
2348
2349 // Enable autopanning and cursor capture only when there is an item to be placed
2350 controls->SetAutoPan( item != nullptr );
2351 controls->CaptureCursor( item != nullptr );
2352 }
2353
2354 controls->SetAutoPan( false );
2355 controls->CaptureCursor( false );
2356 controls->ForceCursorPosition( false );
2357 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
2358
2359 if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->CanPlaceMore() )
2360 {
2361 m_dialogSyncSheetPin->EndPlacement();
2362 m_dialogSyncSheetPin->Show( true );
2363 }
2364
2365 return 0;
2366}
2367
2368
2370{
2371 if( m_inDrawingTool )
2372 return 0;
2373
2375 SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::RULE_AREA );
2376
2379 VECTOR2I cursorPos;
2380
2381 RULE_AREA_CREATE_HELPER ruleAreaTool( *getView(), m_frame, m_toolMgr );
2382 POLYGON_GEOM_MANAGER polyGeomMgr( ruleAreaTool );
2383 bool started = false;
2384
2385 // We might be running as the same shape in another co-routine. Make sure that one
2386 // gets whacked.
2387 m_toolMgr->DeactivateTool();
2388
2389 m_toolMgr->RunAction( ACTIONS::selectionClear );
2390
2391 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
2392 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
2393
2394 auto setCursor =
2395 [&]()
2396 {
2397 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
2398 };
2399
2400 auto cleanup =
2401 [&]()
2402 {
2403 polyGeomMgr.Reset();
2404 started = false;
2405 getViewControls()->SetAutoPan( false );
2406 getViewControls()->CaptureCursor( false );
2407 m_toolMgr->RunAction( ACTIONS::selectionClear );
2408 };
2409
2410 Activate();
2411
2412 // Must be done after Activate() so that it gets set into the correct context
2413 getViewControls()->ShowCursor( true );
2414 //m_controls->ForceCursorPosition( false );
2415
2416 // Set initial cursor
2417 setCursor();
2418
2419 if( aEvent.HasPosition() )
2420 m_toolMgr->PrimeTool( aEvent.Position() );
2421
2422 // Main loop: keep receiving events
2423 while( TOOL_EVENT* evt = Wait() )
2424 {
2425 setCursor();
2426
2427 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2428 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2429
2430 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_CONNECTABLE );
2431 controls->ForceCursorPosition( true, cursorPos );
2432
2433 polyGeomMgr.SetLeaderMode( m_frame->eeconfig()->m_Drawing.line_mode == LINE_MODE_FREE ? LEADER_MODE::DIRECT
2435
2436 if( evt->IsCancelInteractive() )
2437 {
2438 if( started )
2439 {
2440 cleanup();
2441 }
2442 else
2443 {
2444 // We've handled the cancel event. Don't cancel other tools
2445 evt->SetPassEvent( false );
2446 break;
2447 }
2448 }
2449 else if( evt->IsActivate() )
2450 {
2451 if( started )
2452 cleanup();
2453
2454 if( evt->IsPointEditor() )
2455 {
2456 // don't exit (the point editor runs in the background)
2457 continue;
2458 }
2459
2460 if( evt->IsMoveTool() )
2461 {
2462 // Make sure we come back after the move tool runs
2463 frame()->PushTool( originalEvent );
2464 }
2465
2466 break;
2467 }
2468 else if( evt->IsClick( BUT_RIGHT ) )
2469 {
2470 if( !started )
2471 m_toolMgr->VetoContextMenuMouseWarp();
2472
2473 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
2474 }
2475 // events that lock in nodes
2476 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
2477 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick )
2478 || evt->IsAction( &SCH_ACTIONS::closeOutline ) )
2479 {
2480 // Check if it is double click / closing line (so we have to finish the zone)
2481 const bool endPolygon = evt->IsDblClick( BUT_LEFT )
2482 || evt->IsAction( &ACTIONS::cursorDblClick )
2483 || evt->IsAction( &SCH_ACTIONS::closeOutline )
2484 || polyGeomMgr.NewPointClosesOutline( cursorPos );
2485
2486 if( endPolygon )
2487 {
2488 polyGeomMgr.SetFinished();
2489 polyGeomMgr.Reset();
2490
2491 started = false;
2492 getViewControls()->SetAutoPan( false );
2493 getViewControls()->CaptureCursor( false );
2494 }
2495 // adding a corner
2496 else if( polyGeomMgr.AddPoint( cursorPos ) )
2497 {
2498 if( !started )
2499 {
2500 started = true;
2501
2502 getViewControls()->SetAutoPan( true );
2503 getViewControls()->CaptureCursor( true );
2504 }
2505 }
2506 }
2507 else if( started && ( evt->IsAction( &ACTIONS::deleteLastPoint )
2508 || evt->IsAction( &ACTIONS::doDelete )
2509 || evt->IsAction( &ACTIONS::undo ) ) )
2510 {
2511 if( std::optional<VECTOR2I> last = polyGeomMgr.DeleteLastCorner() )
2512 {
2513 cursorPos = last.value();
2514 getViewControls()->WarpMouseCursor( cursorPos, true );
2515 getViewControls()->ForceCursorPosition( true, cursorPos );
2516 polyGeomMgr.SetCursorPosition( cursorPos );
2517 }
2518 else
2519 {
2520 cleanup();
2521 }
2522 }
2523 else if( started && ( evt->IsMotion()
2524 || evt->IsAction( &ACTIONS::refreshPreview )
2525 || evt->IsDrag( BUT_LEFT ) ) )
2526 {
2527 polyGeomMgr.SetCursorPosition( cursorPos );
2528 }
2529 else if( evt->IsAction( &ACTIONS::duplicate )
2530 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
2531 || evt->IsAction( &ACTIONS::paste ) )
2532 {
2533 if( started )
2534 {
2535 wxBell();
2536 continue;
2537 }
2538
2539 // Exit. The duplicate/repeat/paste will run in its own loop.
2540 evt->SetPassEvent();
2541 break;
2542 }
2543 else
2544 {
2545 evt->SetPassEvent();
2546 }
2547
2548 } // end while
2549
2550 getViewControls()->SetAutoPan( false );
2551 getViewControls()->CaptureCursor( false );
2552 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
2553 return 0;
2554}
2555
2556
2558{
2559 SCHEMATIC* schematic = getModel<SCHEMATIC>();
2560 SCH_TABLE* table = nullptr;
2561
2562 if( m_inDrawingTool )
2563 return 0;
2564
2566
2569 VECTOR2I cursorPos;
2570
2571 // We might be running as the same shape in another co-routine. Make sure that one
2572 // gets whacked.
2573 m_toolMgr->DeactivateTool();
2574
2575 m_toolMgr->RunAction( ACTIONS::selectionClear );
2576
2577 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
2578 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
2579
2580 auto setCursor =
2581 [&]()
2582 {
2583 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
2584 };
2585
2586 auto cleanup =
2587 [&] ()
2588 {
2589 m_toolMgr->RunAction( ACTIONS::selectionClear );
2590 m_view->ClearPreview();
2591 delete table;
2592 table = nullptr;
2593 };
2594
2595 Activate();
2596
2597 // Must be done after Activate() so that it gets set into the correct context
2598 getViewControls()->ShowCursor( true );
2599
2600 // Set initial cursor
2601 setCursor();
2602
2603 if( aEvent.HasPosition() )
2604 m_toolMgr->PrimeTool( aEvent.Position() );
2605
2606 // Main loop: keep receiving events
2607 while( TOOL_EVENT* evt = Wait() )
2608 {
2609 setCursor();
2610 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2611 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2612
2613 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
2614 controls->ForceCursorPosition( true, cursorPos );
2615
2616 // The tool hotkey is interpreted as a click when drawing
2617 bool isSyntheticClick = table && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
2618
2619 if( evt->IsCancelInteractive() || ( table && evt->IsAction( &ACTIONS::undo ) ) )
2620 {
2621 if( table )
2622 cleanup();
2623 else
2624 break;
2625 }
2626 else if( evt->IsActivate() && !isSyntheticClick )
2627 {
2628 if( table && evt->IsMoveTool() )
2629 {
2630 // we're already drawing our own item; ignore the move tool
2631 evt->SetPassEvent( false );
2632 continue;
2633 }
2634
2635 if( table )
2636 cleanup();
2637
2638 if( evt->IsPointEditor() )
2639 {
2640 // don't exit (the point editor runs in the background)
2641 continue;
2642 }
2643
2644 if( evt->IsMoveTool() )
2645 {
2646 // Make sure we come back after the move tool runs
2647 frame()->PushTool( originalEvent );
2648 }
2649
2650 break;
2651 }
2652 else if( !table && ( evt->IsClick( BUT_LEFT )
2653 || evt->IsAction( &ACTIONS::cursorClick ) ) )
2654 {
2655 m_toolMgr->RunAction( ACTIONS::selectionClear );
2656
2657 table = new SCH_TABLE( 0 );
2658 table->SetColCount( 1 );
2659
2660 SCH_TABLECELL* tableCell = new SCH_TABLECELL();
2661 int defaultTextSize = schematic->Settings().m_DefaultTextSize;
2662
2663 tableCell->SetTextSize( VECTOR2I( defaultTextSize, defaultTextSize ) );
2664 table->AddCell( tableCell );
2665
2666 table->SetParent( schematic );
2667 table->SetFlags( IS_NEW );
2668 table->SetPosition( cursorPos );
2669
2670 m_view->ClearPreview();
2671 m_view->AddToPreview( table->Clone() );
2672 }
2673 else if( table && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
2674 || isSyntheticClick
2675 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick )
2676 || evt->IsAction( &SCH_ACTIONS::finishInteractive ) ) )
2677 {
2678 table->ClearEditFlags();
2679 table->SetFlags( IS_NEW );
2680 table->Normalize();
2681
2683
2684 // QuasiModal required for Scintilla auto-complete
2685 if( dlg.ShowQuasiModal() == wxID_OK )
2686 {
2687 SCH_COMMIT commit( m_toolMgr );
2688 commit.Add( table, m_frame->GetScreen() );
2689 commit.Push( _( "Draw Table" ) );
2690
2691 m_selectionTool->AddItemToSel( table );
2693 }
2694 else
2695 {
2696 delete table;
2697 }
2698
2699 table = nullptr;
2700 m_view->ClearPreview();
2701 }
2702 else if( table && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
2703 {
2704 VECTOR2I gridSize = grid.GetGridSize( grid.GetItemGrid( table ) );
2705 int fontSize = schematic->Settings().m_DefaultTextSize;
2706 VECTOR2I origin( table->GetPosition() );
2707 VECTOR2I requestedSize( cursorPos - origin );
2708
2709 int colCount = std::max( 1, requestedSize.x / ( fontSize * 15 ) );
2710 int rowCount = std::max( 1, requestedSize.y / ( fontSize * 2 ) );
2711
2712 VECTOR2I cellSize( std::max( gridSize.x * 5, requestedSize.x / colCount ),
2713 std::max( gridSize.y * 2, requestedSize.y / rowCount ) );
2714
2715 cellSize.x = KiROUND( (double) cellSize.x / gridSize.x ) * gridSize.x;
2716 cellSize.y = KiROUND( (double) cellSize.y / gridSize.y ) * gridSize.y;
2717
2718 table->ClearCells();
2719 table->SetColCount( colCount );
2720
2721 for( int col = 0; col < colCount; ++col )
2722 table->SetColWidth( col, cellSize.x );
2723
2724 for( int row = 0; row < rowCount; ++row )
2725 {
2726 table->SetRowHeight( row, cellSize.y );
2727
2728 for( int col = 0; col < colCount; ++col )
2729 {
2730 SCH_TABLECELL* cell = new SCH_TABLECELL();
2731 int defaultTextSize = schematic->Settings().m_DefaultTextSize;
2732
2733 cell->SetTextSize( VECTOR2I( defaultTextSize, defaultTextSize ) );
2734 cell->SetPosition( origin + VECTOR2I( col * cellSize.x, row * cellSize.y ) );
2735 cell->SetEnd( cell->GetPosition() + cellSize );
2736 table->AddCell( cell );
2737 }
2738 }
2739
2740 m_view->ClearPreview();
2741 m_view->AddToPreview( table->Clone() );
2742 m_frame->SetMsgPanel( table );
2743 }
2744 else if( !table && ( evt->IsDblClick( BUT_LEFT )
2745 || evt->IsAction( &ACTIONS::cursorDblClick ) ) )
2746 {
2747 m_toolMgr->RunAction( SCH_ACTIONS::properties );
2748 }
2749 else if( evt->IsClick( BUT_RIGHT ) )
2750 {
2751 // Warp after context menu only if dragging...
2752 if( !table )
2753 m_toolMgr->VetoContextMenuMouseWarp();
2754
2755 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
2756 }
2757 else if( evt->IsAction( &ACTIONS::duplicate )
2758 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
2759 || evt->IsAction( &ACTIONS::paste ) )
2760 {
2761 if( table )
2762 {
2763 wxBell();
2764 continue;
2765 }
2766
2767 // Exit. The duplicate/repeat/paste will run in its own loop.
2768 evt->SetPassEvent();
2769 break;
2770 }
2771 else if( table && evt->IsAction( &ACTIONS::redo ) )
2772 {
2773 wxBell();
2774 }
2775 else
2776 {
2777 evt->SetPassEvent();
2778 }
2779
2780 // Enable autopanning and cursor capture only when there is a shape being drawn
2781 getViewControls()->SetAutoPan( table != nullptr );
2782 getViewControls()->CaptureCursor( table != nullptr );
2783 }
2784
2785 getViewControls()->SetAutoPan( false );
2786 getViewControls()->CaptureCursor( false );
2787 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
2788 return 0;
2789}
2790
2791
2793{
2794 bool isDrawSheetCopy = aEvent.IsAction( &SCH_ACTIONS::drawSheetFromFile );
2795 bool isDrawSheetFromDesignBlock = aEvent.IsAction( &SCH_ACTIONS::drawSheetFromDesignBlock );
2796
2797 std::unique_ptr<DESIGN_BLOCK> designBlock;
2798
2799 SCH_SHEET* sheet = nullptr;
2800 wxString filename;
2801 SCH_GROUP* sheetGroup = nullptr;
2802
2803 if( isDrawSheetCopy )
2804 {
2805 wxString* ptr = aEvent.Parameter<wxString*>();
2806 wxCHECK( ptr, 0 );
2807
2808 // We own the string if we're importing a sheet
2809 filename = *ptr;
2810 delete ptr;
2811 }
2812 else if( isDrawSheetFromDesignBlock )
2813 {
2814 designBlock.reset( aEvent.Parameter<DESIGN_BLOCK*>() );
2815 wxCHECK( designBlock, 0 );
2816 filename = designBlock->GetSchematicFile();
2817 }
2818
2819 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock ) && !wxFileExists( filename ) )
2820 {
2821 wxMessageBox( wxString::Format( _( "File '%s' does not exist." ), filename ) );
2822 return 0;
2823 }
2824
2825 if( m_inDrawingTool )
2826 return 0;
2827
2829
2830 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
2831 SCHEMATIC_SETTINGS& schSettings = m_frame->Schematic().Settings();
2834 VECTOR2I cursorPos;
2835 bool startedWithDrag = false; // Track if initial sheet placement started with a drag
2836
2837 m_toolMgr->RunAction( ACTIONS::selectionClear );
2838
2839 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
2840 SCOPED_TOOL_PUSHER raii( m_frame, originalEvent );
2841
2842 auto setCursor =
2843 [&]()
2844 {
2845 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
2846 };
2847
2848 auto cleanup =
2849 [&] ()
2850 {
2851 m_toolMgr->RunAction( ACTIONS::selectionClear );
2852 m_view->ClearPreview();
2853 delete sheet;
2854 sheet = nullptr;
2855 };
2856
2857 Activate();
2858
2859 // Must be done after Activate() so that it gets set into the correct context
2860 getViewControls()->ShowCursor( true );
2861
2862 // Set initial cursor
2863 setCursor();
2864
2865 if( aEvent.HasPosition() && !( isDrawSheetCopy || isDrawSheetFromDesignBlock ) )
2866 m_toolMgr->PrimeTool( aEvent.Position() );
2867
2868 // Main loop: keep receiving events
2869 while( TOOL_EVENT* evt = Wait() )
2870 {
2871 setCursor();
2872 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
2873 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2874
2875 cursorPos = grid.Align( controls->GetMousePosition(), GRID_HELPER_GRIDS::GRID_GRAPHICS );
2876 controls->ForceCursorPosition( true, cursorPos );
2877
2878 // The tool hotkey is interpreted as a click when drawing
2879 bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()
2880 && evt->Matches( aEvent );
2881
2882 if( evt->IsCancelInteractive() || ( sheet && evt->IsAction( &ACTIONS::undo ) ) )
2883 {
2884 m_frame->GetInfoBar()->Dismiss();
2885
2886 if( sheet )
2887 cleanup();
2888 else
2889 break;
2890 }
2891 else if( evt->IsActivate() && !isSyntheticClick )
2892 {
2893 if( sheet && evt->IsMoveTool() )
2894 {
2895 // we're already drawing our own item; ignore the move tool
2896 evt->SetPassEvent( false );
2897 continue;
2898 }
2899
2900 if( sheet )
2901 {
2902 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel sheet creation." ) );
2903 evt->SetPassEvent( false );
2904 continue;
2905 }
2906
2907 if( evt->IsPointEditor() )
2908 {
2909 // don't exit (the point editor runs in the background)
2910 continue;
2911 }
2912
2913 if( evt->IsMoveTool() )
2914 {
2915 // Make sure we come back after the move tool runs
2916 frame()->PushTool( originalEvent );
2917 }
2918
2919 break;
2920 }
2921 else if( !sheet && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
2922 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick )
2923 || evt->IsDrag( BUT_LEFT ) ) )
2924 {
2925 SCH_SELECTION& selection = m_selectionTool->GetSelection();
2926
2927 if( selection.Size() == 1
2928 && selection.Front()->Type() == SCH_SHEET_T
2929 && selection.Front()->GetBoundingBox().Contains( cursorPos ) )
2930 {
2931 if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorClick ) )
2932 {
2933 // sheet already selected
2934 continue;
2935 }
2936 else if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
2937 {
2938 m_toolMgr->PostAction( SCH_ACTIONS::enterSheet );
2939 break;
2940 }
2941 }
2942
2943 m_toolMgr->RunAction( ACTIONS::selectionClear );
2944
2945 VECTOR2I sheetPos = evt->IsDrag( BUT_LEFT )
2946 ? grid.Align( evt->DragOrigin(), GRID_HELPER_GRIDS::GRID_GRAPHICS )
2947 : cursorPos;
2948
2949 // Remember whether this sheet was initiated with a drag so we can treat mouse-up as
2950 // the terminating (second) click.
2951 startedWithDrag = evt->IsDrag( BUT_LEFT );
2952
2953 sheet = new SCH_SHEET( m_frame->GetCurrentSheet().Last(), sheetPos );
2954 sheet->SetScreen( nullptr );
2955
2956 wxString ext = wxString( "." ) + FILEEXT::KiCadSchematicFileExtension;
2957
2958 if( isDrawSheetCopy )
2959 {
2960 wxFileName fn( filename );
2961
2962 sheet->GetField( FIELD_T::SHEET_NAME )->SetText( fn.GetName() );
2963 sheet->GetField( FIELD_T::SHEET_FILENAME )->SetText( fn.GetName() + ext );
2964 }
2965 else if( isDrawSheetFromDesignBlock )
2966 {
2967 wxString sn = UniqueSheetName( m_frame->GetScreen(), designBlock->GetLibId().GetLibItemName() );
2968 wxFileName fn( filename );
2969
2970 sheet->GetField( FIELD_T::SHEET_NAME )->SetText( sn );
2971 sheet->GetField( FIELD_T::SHEET_FILENAME )->SetText( fn.GetName() + ext );
2972
2973 std::vector<SCH_FIELD>& sheetFields = sheet->GetFields();
2974
2975 // Copy default fields into the sheet
2976 for( const auto& [fieldName, fieldValue] : designBlock->GetFields() )
2977 {
2978 sheetFields.emplace_back( sheet, FIELD_T::USER, fieldName );
2979 sheetFields.back().SetText( fieldValue );
2980 sheetFields.back().SetTextPos( sheet->GetPosition() );
2981 sheetFields.back().SetVisible( false );
2982 }
2983 }
2984 else
2985 {
2986 sheet->GetField( FIELD_T::SHEET_NAME )->SetText( wxT( "Untitled Sheet" ) );
2987 sheet->GetField( FIELD_T::SHEET_FILENAME )->SetText( wxT( "untitled" ) + ext );
2988 }
2989
2990 sheet->SetFlags( IS_NEW | IS_MOVING );
2991 sheet->SetBorderWidth( schIUScale.MilsToIU( cfg->m_Drawing.default_line_thickness ) );
2994 sizeSheet( sheet, cursorPos );
2995
2996 SCH_SHEET_LIST hierarchy = m_frame->Schematic().Hierarchy();
2997 SCH_SHEET_PATH instance = m_frame->GetCurrentSheet();
2998 instance.push_back( sheet );
2999 wxString pageNumber = hierarchy.GetNextPageNumber();
3000 instance.SetPageNumber( pageNumber );
3001
3002 m_view->ClearPreview();
3003 m_view->AddToPreview( sheet->Clone() );
3004 }
3005 else if( sheet && ( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
3006 || isSyntheticClick
3007 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick )
3008 || evt->IsAction( &ACTIONS::finishInteractive )
3009 || ( startedWithDrag && evt->IsMouseUp( BUT_LEFT ) ) ) )
3010 {
3011 getViewControls()->SetAutoPan( false );
3012 getViewControls()->CaptureCursor( false );
3013
3014 if( m_frame->EditSheetProperties( sheet, &m_frame->GetCurrentSheet(), nullptr, nullptr, nullptr,
3015 &filename ) )
3016 {
3017 m_view->ClearPreview();
3018
3019 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock ) && cfg->m_Drawing.auto_place_sheet_pins )
3021
3022 sheet->AutoplaceFields( m_frame->GetScreen(), AUTOPLACE_AUTO );
3023
3024 // Use the commit we were provided or make our own
3025 SCH_COMMIT tempCommit = SCH_COMMIT( m_toolMgr );
3026 SCH_COMMIT& c = evt->Commit() ? *( (SCH_COMMIT*) evt->Commit() ) : tempCommit;
3027
3028 // We need to manually add the sheet to the screen otherwise annotation will not be able to find
3029 // the sheet and its symbols to annotate.
3030 m_frame->AddToScreen( sheet );
3031 c.Added( sheet, m_frame->GetScreen() );
3032
3033 // Refresh the hierarchy so the new sheet and its symbols are found during annotation.
3034 // The cached hierarchy was built before this sheet was added.
3035 m_frame->Schematic().RefreshHierarchy();
3036
3037 if( cfg->m_AnnotatePanel.automatic && !( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3039 {
3040 // Annotation will remove this from selection, but we add it back later
3041 m_selectionTool->AddItemToSel( sheet );
3042
3044
3045 m_frame->AnnotateSymbols( &c, ANNOTATE_SELECTION,
3047 (ANNOTATE_ALGO_T) schSettings.m_AnnotateMethod, true, /* recursive */
3048 schSettings.m_AnnotateStartNum, true, /* reset */
3049 false, /* regroup */
3050 false, /* repair */
3051 reporter );
3052 }
3053
3054 if( isDrawSheetFromDesignBlock && cfg->m_DesignBlockChooserPanel.place_as_group )
3055 {
3056 SCH_SCREEN* screen = m_frame->GetScreen();
3057
3058 sheetGroup = new SCH_GROUP( screen );
3059 sheetGroup->SetName( UniqueGroupName( screen, designBlock->GetLibId().GetLibItemName() ) );
3060 sheetGroup->SetDesignBlockLibId( designBlock->GetLibId() );
3061 c.Add( sheetGroup, screen );
3062 c.Modify( sheet, screen, RECURSE_MODE::NO_RECURSE );
3063 sheetGroup->AddItem( sheet );
3064 }
3065
3066 c.Push( isDrawSheetCopy ? "Import Sheet Copy" : "Draw Sheet" );
3067
3068 if( sheetGroup )
3069 m_selectionTool->AddItemToSel( sheetGroup );
3070 else
3071 m_selectionTool->AddItemToSel( sheet );
3072
3073 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3075 {
3076 break;
3077 }
3078 }
3079 else
3080 {
3081 m_view->ClearPreview();
3082 delete sheet;
3083 }
3084
3085 sheet = nullptr;
3086 }
3087 else if( evt->IsAction( &ACTIONS::duplicate )
3088 || evt->IsAction( &SCH_ACTIONS::repeatDrawItem )
3089 || evt->IsAction( &ACTIONS::paste ) )
3090 {
3091 if( sheet )
3092 {
3093 wxBell();
3094 continue;
3095 }
3096
3097 // Exit. The duplicate/repeat/paste will run in its own loop.
3098 evt->SetPassEvent();
3099 break;
3100 }
3101 else if( sheet && ( evt->IsAction( &ACTIONS::refreshPreview )
3102 || evt->IsMotion()
3103 || evt->IsDrag( BUT_LEFT ) ) )
3104 {
3105 sizeSheet( sheet, cursorPos );
3106 m_view->ClearPreview();
3107 m_view->AddToPreview( sheet->Clone() );
3108 m_frame->SetMsgPanel( sheet );
3109 }
3110 else if( evt->IsClick( BUT_RIGHT ) )
3111 {
3112 // Warp after context menu only if dragging...
3113 if( !sheet )
3114 m_toolMgr->VetoContextMenuMouseWarp();
3115
3116 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
3117 }
3118 else if( sheet && evt->IsAction( &ACTIONS::redo ) )
3119 {
3120 wxBell();
3121 }
3122 else
3123 {
3124 evt->SetPassEvent();
3125 }
3126
3127 // Enable autopanning and cursor capture only when there is a sheet to be placed
3128 getViewControls()->SetAutoPan( sheet != nullptr );
3129 getViewControls()->CaptureCursor( sheet != nullptr );
3130 }
3131
3132 getViewControls()->SetAutoPan( false );
3133 getViewControls()->CaptureCursor( false );
3134 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
3135
3136 return 0;
3137}
3138
3139
3141{
3142 VECTOR2I pos = aSheet->GetPosition();
3143 VECTOR2I size = aPos - pos;
3145
3146 size.x = std::max( size.x, minSize.x );
3147 size.y = std::max( size.y, minSize.y );
3148
3149 VECTOR2I grid = m_frame->GetNearestGridPosition( pos + size );
3150 VECTOR2I gridSize = getView()->GetGAL()->GetGridSize();
3151
3152 // Keep the corner on-grid without letting inward rounding violate the minimum size.
3153 if( grid.x - pos.x < minSize.x )
3154 grid.x += gridSize.x;
3155
3156 if( grid.y - pos.y < minSize.y )
3157 grid.y += gridSize.y;
3158
3159 aSheet->Resize( VECTOR2I( grid.x - pos.x, grid.y - pos.y ) );
3160}
3161
3162
3163int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths, SCH_SHEET* aInitialSheet )
3164{
3165 if( !sheetPaths.size() )
3166 return 0;
3167
3168 m_dialogSyncSheetPin = std::make_unique<DIALOG_SYNC_SHEET_PINS>(
3169 m_frame, std::move( sheetPaths ),
3170 std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
3171 [&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath,
3173 {
3174 SCH_COMMIT commit( m_toolMgr );
3175
3176 if( auto pin = dynamic_cast<SCH_SHEET_PIN*>( aItem ) )
3177 {
3178 commit.Modify( pin->GetParent(), aPath.LastScreen() );
3179 aModify();
3180 commit.Push( _( "Modify Sheet Pin" ) );
3181 }
3182 else
3183 {
3184 commit.Modify( aItem, aPath.LastScreen() );
3185 aModify();
3186 commit.Push( _( "Modify Schematic Item" ) );
3187 }
3188
3189 // The push already updated the R-tree and republished connectivity
3190 updateItem( aItem, false );
3191 m_frame->OnModify();
3192 },
3193 [&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath )
3194 {
3195 m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
3196 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
3197 selectionTool->UnbrightenItem( aItem );
3198 selectionTool->AddItemToSel( aItem, true );
3199 m_toolMgr->RunAction( ACTIONS::doDelete );
3200 },
3201 [&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath,
3203 std::set<EDA_ITEM*> aTemplates )
3204 {
3205 switch( aOp )
3206 {
3208 {
3209 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
3210 m_dialogSyncSheetPin->Hide();
3211 m_dialogSyncSheetPin->PreparePlacementTemplate(
3213 m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
3215 break;
3216 }
3218 {
3219 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
3220 m_dialogSyncSheetPin->Hide();
3221 m_dialogSyncSheetPin->PreparePlacementTemplate(
3223 m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>( SCH_ACTIONS::changeSheet, &aPath );
3224 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->SyncSelection( {}, nullptr, { sheet } );
3226 break;
3227 }
3228 }
3229 },
3230 m_toolMgr, m_frame ),
3231 aInitialSheet );
3232 m_dialogSyncSheetPin->Show( true );
3233 return 0;
3234}
3235
3236
3238{
3239 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
3240
3241 if( !sheet )
3242 {
3243 VECTOR2I cursorPos = getViewControls()->GetMousePosition();
3244
3245 if( EDA_ITEM* i = nullptr; static_cast<void>(m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) ) , i != nullptr )
3246 {
3247 sheet = dynamic_cast<SCH_SHEET*>( i );
3248 }
3249 }
3250
3251 if ( sheet )
3252 {
3253 SCH_SHEET_PATH current = m_frame->GetCurrentSheet();
3254 current.push_back( sheet );
3255 return doSyncSheetsPins( { current } );
3256 }
3257
3258 return 0;
3259}
3260
3261
3263{
3264 if( m_inDrawingTool )
3265 return 0;
3266
3268
3269 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
3270
3271 if( !sheet )
3272 return 0;
3273
3274 std::vector<SCH_HIERLABEL*> labels = GetUnplacedSheetPinLabels( *sheet );
3275
3276 if( labels.empty() )
3277 {
3278 SCOPED_TOOL_PUSHER raii( m_frame, aEvent );
3279
3280 m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
3281 m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
3282 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
3283 m_statusPopup->PopupFor( 2000 );
3284 m_toolMgr->RunAction( ACTIONS::selectionClear );
3285 m_view->ClearPreview();
3286 return 0;
3287 }
3288
3289 m_toolMgr->RunAction( ACTIONS::selectionClear );
3290
3291 SCH_COMMIT commit( m_toolMgr );
3292 commit.Modify( sheet, m_frame->GetScreen() );
3293
3294 AutoPlaceSheetPins( sheet, labels );
3295
3296 commit.Push( _( "Auto-place Sheet Pins" ) );
3297 return 0;
3298}
3299
3300
3302{
3303 static const std::function<void( std::list<SCH_SHEET_PATH>&, SCH_SCREEN*, std::set<SCH_SCREEN*>&,
3304 SCH_SHEET_PATH const& )> getSheetChildren =
3305 []( std::list<SCH_SHEET_PATH>& aPaths, SCH_SCREEN* aScene, std::set<SCH_SCREEN*>& aVisited,
3306 SCH_SHEET_PATH const& aCurPath )
3307 {
3308 if( ! aScene || aVisited.find(aScene) != aVisited.end() )
3309 return ;
3310
3311 std::vector<SCH_ITEM*> sheetChildren;
3312 aScene->GetSheets( &sheetChildren );
3313 aVisited.insert( aScene );
3314
3315 for( SCH_ITEM* child : sheetChildren )
3316 {
3317 SCH_SHEET_PATH cp = aCurPath;
3318 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( child );
3319 cp.push_back( sheet );
3320 aPaths.push_back( cp );
3321 getSheetChildren( aPaths, sheet->GetScreen(), aVisited, cp );
3322 }
3323 };
3324
3325 std::list<SCH_SHEET_PATH> sheetPaths;
3326 std::set<SCH_SCREEN*> visited;
3327
3328 // Build sheet paths for each top-level sheet (don't include virtual root in paths)
3329 std::vector<SCH_SHEET*> topLevelSheets = m_frame->Schematic().GetTopLevelSheets();
3330
3331 for( SCH_SHEET* topSheet : topLevelSheets )
3332 {
3333 if( topSheet && topSheet->GetScreen() )
3334 {
3335 SCH_SHEET_PATH current;
3336 current.push_back( topSheet );
3337 getSheetChildren( sheetPaths, topSheet->GetScreen(), visited, current );
3338 }
3339 }
3340
3341 if( sheetPaths.size() == 0 )
3342 {
3343 m_frame->ShowInfoBarMsg( _( "No sub schematic found in the current project" ) );
3344 return 0;
3345 }
3346
3347 // If a sheet is currently selected, pre-select its tab in the dialog
3348 SCH_SHEET* selectedSheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
3349
3350 return doSyncSheetsPins( std::move( sheetPaths ), selectedSheet );
3351}
3352
3354{
3355 if( !aSheet->GetScreen() )
3356 return nullptr;
3357
3358 std::vector<SCH_HIERLABEL*> labels;
3359
3360 for( EDA_ITEM* item : aSheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
3361 {
3362 SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
3363 labels.push_back( label );
3364 }
3365
3366 std::sort( labels.begin(), labels.end(),
3367 []( const SCH_HIERLABEL* label1, const SCH_HIERLABEL* label2 )
3368 {
3369 return StrNumCmp( label1->GetText(), label2->GetText(), CMP_T::IGNORE_CASE ) < 0;
3370 } );
3371
3372 for( SCH_HIERLABEL* label : labels )
3373 {
3374 if( !aSheet->HasPin( label->GetText() ) )
3375 return label;
3376 }
3377
3378 return nullptr;
3379}
3380
3381
3383{
3384 // clang-format off
3408 // clang-format on
3409}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static TOOL_ACTION paste
Definition actions.h:77
static TOOL_ACTION deleteLastPoint
Definition actions.h:272
static TOOL_ACTION cursorDblClick
Definition actions.h:178
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION duplicate
Definition actions.h:81
static TOOL_ACTION activatePointEditor
Definition actions.h:269
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION cursorClick
Definition actions.h:177
static TOOL_ACTION redo
Definition actions.h:73
static TOOL_ACTION increment
Definition actions.h:91
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION refreshPreview
Definition actions.h:156
static TOOL_ACTION finishInteractive
Definition actions.h:70
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
bool IsContentModified() const
Definition base_screen.h:56
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:80
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
Definition commit.h:92
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg, wxString *aErrorMsg=nullptr)
Load design block from design block library table.
void SetLabelList(std::list< std::unique_ptr< SCH_LABEL_BASE > > *aLabelList)
FIELDS_GRID_TABLE * GetFieldsGridTable()
int ShowModal() override
void SetDesignBlockLibId(const LIB_ID &aLibId)
Definition eda_group.h:101
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
void SetName(const wxString &aName)
Definition eda_group.h:76
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:280
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:170
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:484
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:288
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:338
bool IsItalic() const
Definition eda_text.h:200
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:513
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition eda_text.cpp:311
bool IsBold() const
Definition eda_text.h:215
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:291
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
PANEL_ANNOTATE m_AnnotatePanel
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
const VECTOR2D & GetGridSize() const
Return the grid size.
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 ShowCursor(bool aEnabled)
Enable or disables display of cursor.
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.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
virtual void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor)=0
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
Definition kiid.h:46
LEGACY_SYMBOL_LIB * GetCacheLibrary()
Object used to load, save, search, and otherwise manipulate symbol library files.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
UTF8 Format() const
Definition lib_id.cpp:132
Define a library symbol object.
Definition lib_symbol.h:114
wxString GetDescription() const override
Get the Description field text value *‍/.
Definition lib_symbol.h:202
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:190
wxString GetKeyWords() const override
Definition lib_symbol.h:220
void SetGlobalPower()
bool IsPower() const override
void SetDescription(const wxString &aDescription)
Set the Description field text value.
void SetKeyWords(const wxString &aKeyWords)
bool IsLocalPower() const override
void SetLocalPower()
bool IsGlobalPower() const override
A singleton reporter that reports to nowhere.
Definition reporter.h:267
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:600
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
bool AddPoint(const VECTOR2I &aPt)
Lock in a polygon point.
void SetCursorPosition(const VECTOR2I &aPos)
Set the current cursor position.
bool NewPointClosesOutline(const VECTOR2I &aPt) const
std::optional< VECTOR2I > DeleteLastCorner()
Remove the last-added point from the polygon.
void SetFinished()
Mark the polygon finished and update the client.
void SetLeaderMode(LEADER_MODE aMode)
Set the leader mode to use when calculating the leader/returner lines.
void Reset()
Clear the manager state and start again.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
An adjunct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from ...
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:155
SCHEMATIC_SETTINGS & Settings() const
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
static TOOL_ACTION rotateCCW
static TOOL_ACTION placeClassLabel
Definition sch_actions.h:85
static TOOL_ACTION placeSheetPin
Definition sch_actions.h:91
static TOOL_ACTION placeNextSymbolUnit
Definition sch_actions.h:73
static TOOL_ACTION editValue
static TOOL_ACTION setExcludeFromBOM
static TOOL_ACTION mirrorV
static TOOL_ACTION drawSheetFromFile
Definition sch_actions.h:89
static TOOL_ACTION placeGlobalLabel
Definition sch_actions.h:86
static TOOL_ACTION autoplaceFields
static TOOL_ACTION changeSymbol
static TOOL_ACTION syncAllSheetsPins
Definition sch_actions.h:97
static TOOL_ACTION closeOutline
static TOOL_ACTION drawSheet
Definition sch_actions.h:88
static TOOL_ACTION properties
static TOOL_ACTION editReference
static TOOL_ACTION leaveSheet
static TOOL_ACTION autoplaceAllSheetPins
Definition sch_actions.h:92
static TOOL_ACTION placeHierLabel
Definition sch_actions.h:87
static TOOL_ACTION placeLabel
Definition sch_actions.h:84
static TOOL_ACTION toText
static TOOL_ACTION placeBusWireEntry
Definition sch_actions.h:83
static TOOL_ACTION toHLabel
static TOOL_ACTION rotateCW
static TOOL_ACTION importSheet
Definition sch_actions.h:93
static TOOL_ACTION setExcludeFromSim
static TOOL_ACTION toLabel
static TOOL_ACTION placeJunction
Definition sch_actions.h:82
static TOOL_ACTION setDNP
static TOOL_ACTION drawRuleArea
static TOOL_ACTION placeSymbol
Definition sch_actions.h:72
static TOOL_ACTION placeImage
static TOOL_ACTION editWithLibEdit
static TOOL_ACTION toDLabel
static TOOL_ACTION setExcludeFromPosFiles
static TOOL_ACTION cycleBodyStyle
static TOOL_ACTION drawSheetFromDesignBlock
Definition sch_actions.h:90
static TOOL_ACTION mirrorH
static TOOL_ACTION placeDesignBlock
Definition sch_actions.h:75
static TOOL_ACTION drawTable
static TOOL_ACTION placeSchematicText
Definition sch_actions.h:98
static TOOL_ACTION toTextBox
static TOOL_ACTION changeSheet
static TOOL_ACTION enterSheet
static TOOL_ACTION editFootprint
static TOOL_ACTION repeatDrawItem
static TOOL_ACTION placeNoConnect
Definition sch_actions.h:81
static TOOL_ACTION toGLabel
static TOOL_ACTION setExcludeFromBoard
static TOOL_ACTION move
static TOOL_ACTION syncSheetPins
Definition sch_actions.h:95
static TOOL_ACTION placePower
Definition sch_actions.h:74
Object to handle a bitmap image that can be inserted in a schematic.
Definition sch_bitmap.h:36
Base class for a bus or wire entry.
VECTOR2I GetPosition() const override
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Class for a wire to bus entry.
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
void Revert() override
Revert the commit by restoring the modified items state.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
int ImportSheet(const TOOL_EVENT &aEvent)
int doSyncSheetsPins(std::list< SCH_SHEET_PATH > aSheets, SCH_SHEET *aInitialSheet=nullptr)
SCH_TEXT * createNewText(const VECTOR2I &aPosition)
int PlaceNextSymbolUnit(const TOOL_EVENT &aEvent)
int DrawSheet(const TOOL_EVENT &aEvent)
bool createNewLabel(const VECTOR2I &aPosition, int aType, std::list< std::unique_ptr< SCH_LABEL_BASE > > &aLabelList)
SPIN_STYLE m_lastTextOrientation
int SyncSheetsPins(const TOOL_EVENT &aEvent)
std::vector< PICKED_SYMBOL > m_powerHistoryList
int SingleClickPlace(const TOOL_EVENT &aEvent)
SCH_LINE * findWire(const VECTOR2I &aPosition)
void sizeSheet(SCH_SHEET *aSheet, const VECTOR2I &aPos)
LABEL_FLAG_SHAPE m_lastGlobalLabelShape
LABEL_FLAG_SHAPE m_lastNetClassFlagShape
GR_TEXT_H_ALIGN_T m_lastTextHJustify
int DrawRuleArea(const TOOL_EVENT &aEvent)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
int AutoPlaceAllSheetPins(const TOOL_EVENT &aEvent)
int TwoClickPlace(const TOOL_EVENT &aEvent)
SCH_SHEET_PIN * createNewSheetPin(SCH_SHEET *aSheet, const VECTOR2I &aPosition)
SCH_SHEET_PIN * createNewSheetPinFromLabel(SCH_SHEET *aSheet, const VECTOR2I &aPosition, SCH_HIERLABEL *aLabel)
int SyncAllSheetsPins(const TOOL_EVENT &aEvent)
wxString findWireLabelDriverName(SCH_LINE *aWire)
Gets the (global) label name driving this wire, if it is driven by a label.
int DrawTable(const TOOL_EVENT &aEvent)
GR_TEXT_V_ALIGN_T m_lastTextVJustify
LABEL_FLAG_SHAPE m_lastSheetPinType
MODE
The possible drawing modes of SCH_DRAWING_TOOLS.
std::unique_ptr< DIALOG_SYNC_SHEET_PINS > m_dialogSyncSheetPin
bool Init() override
Init() is called once upon a registration of the tool.
void setTransitions() override
Set up handlers for various events.
int PlaceSymbol(const TOOL_EVENT &aEvent)
int PlaceImage(const TOOL_EVENT &aEvent)
std::vector< PICKED_SYMBOL > m_symbolHistoryList
SCH_HIERLABEL * importHierLabel(SCH_SHEET *aSheet)
Try finding any hierlabel that does not have a sheet pin associated with it.
Schematic editor (Eeschema) main window.
void SetText(const wxString &aText) override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this label.
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
void SetSpinStyle(SPIN_STYLE aSpinStyle) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
virtual bool IsConnectable() const
Definition sch_item.h:550
virtual void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo)
Definition sch_item.h:681
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:683
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
virtual void CalcEdit(const VECTOR2I &aPosition)
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_item.h:490
virtual void SetUnit(int aUnit)
Definition sch_item.h:242
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:580
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition sch_item.h:185
bool AutoRotateOnPlacement() const
autoRotateOnPlacement
SPIN_STYLE GetSpinStyle() const
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition sch_label.h:179
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:178
void SetAutoRotateOnPlacement(bool autoRotate=true)
std::vector< SCH_FIELD > & GetFields()
Definition sch_label.h:210
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
int AddJunctionsIfNeeded(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Handle the addition of junctions to a selection of objects.
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
int TrimOverLappingWires(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
Definition sch_line.h:145
VECTOR2I GetStartPoint() const
Definition sch_line.h:136
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByReferenceOnly()
Sort the list of references by reference.
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetUnit(int aUnit)
wxString GetRef() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
SCH_ITEM * GetItem(const VECTOR2I &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
bool IsExplicitJunctionAllowed(const VECTOR2I &aPosition) const
Indicate that a junction dot may be placed at the given location.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
SCH_SELECTION & GetSelection()
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:89
VECTOR2I GetPosition() const override
Definition sch_shape.h:88
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
wxString GetNextPageNumber() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
const KIID_PATH & PathRef() const
Borrow the cached path until this sheet path is modified or destroyed.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition sch_sheet.h:196
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:93
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition sch_sheet.h:199
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:187
VECTOR2I GetPosition() const override
Definition sch_sheet.h:548
bool HasPin(const wxString &aName) const
Check if the sheet already has a sheet pin named aName.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetBorderWidth(int aWidth)
Definition sch_sheet.h:193
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
void Resize(const VECTOR2I &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:285
Schematic symbol object.
Definition sch_symbol.h:76
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:166
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
bool Init() override
Init() is called once upon a registration of the tool.
SCH_TOOL_BASE(const std::string &aName)
SCH_SELECTION_TOOL * m_selectionTool
RAII class that sets an value at construction and resets it to the original value at destruction.
Definition seg.h:38
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition seg.cpp:599
int AddItemsToSel(const TOOL_EVENT &aEvent)
int AddItemToSel(const TOOL_EVENT &aEvent)
void UnbrightenItem(EDA_ITEM *aItem)
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:104
EDA_ITEM * Front() const
Definition selection.h:176
int Size() const
Returns the number of selected parts.
Definition selection.h:120
void SetReferencePoint(const VECTOR2I &aP)
Spin style for labels of all kinds on schematics.
Definition sch_label.h:38
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Helper object to filter a list of libraries.
SCH_EDIT_FRAME * getModel() const
Definition tool_base.h:195
KIGFX::VIEW_CONTROLS * getViewControls() const
Definition tool_base.cpp:40
KIGFX::VIEW * getView() const
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition tool_event.h:256
const VECTOR2D Position() const
Return mouse cursor position in world coordinates.
Definition tool_event.h:289
bool IsReactivate() const
Control whether the tool is first being pushed to the stack or being reactivated after a pause.
Definition tool_event.h:269
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
void RunMainStack(std::function< void()> aFunc)
void Go(int(SCH_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
std::unique_ptr< TOOL_MENU > m_menu
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
This file is part of the common library.
@ COMPONENT
Definition cursors.h:81
@ PLACE
Definition cursors.h:95
@ LABEL_GLOBAL
Definition cursors.h:79
@ MOVING
Definition cursors.h:45
@ LABEL_NET
Definition cursors.h:77
@ ARROW
Definition cursors.h:43
@ LABEL_HIER
Definition cursors.h:93
@ PENCIL
Definition cursors.h:49
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ NO_RECURSE
Definition eda_item.h:52
#define IGNORE_PARENT_GROUP
Definition eda_item.h:55
#define IS_NEW
New item, just created.
#define STRUCT_DELETED
flag indication structures to be erased
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
SCOPED_SET_RESET< EE_GRAPHIC_TOOL::MODE > SCOPED_DRAW_MODE
@ ID_POPUP_SCH_SELECT_UNIT
Definition eeschema_id.h:81
@ ID_POPUP_SCH_SELECT_BODY_STYLE
Definition eeschema_id.h:91
@ ID_POPUP_SCH_SELECT_BODY_STYLE_END
Definition eeschema_id.h:93
@ ID_POPUP_SCH_SELECT_UNIT_END
Definition eeschema_id.h:85
@ LINE_MODE_FREE
@ DEG45
45 Degree only
@ DIRECT
Unconstrained point-to-point.
GRID_HELPER_GRIDS
Definition grid_helper.h:55
@ GRID_TEXT
Definition grid_helper.h:62
@ GRID_GRAPHICS
Definition grid_helper.h:63
@ GRID_CONNECTABLE
Definition grid_helper.h:59
static const std::string KiCadSchematicFileExtension
static wxString ImageFileWildcard()
static wxString KiCadSchematicFileWildcard()
@ LAYER_HIERLABEL
Definition layer_ids.h:488
@ LAYER_GLOBLABEL
Definition layer_ids.h:487
@ LAYER_LOCLABEL
Definition layer_ids.h:486
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:495
Definition for symbol library class.
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIBRARY_ADAPTER *aLibMgr, LEGACY_SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
static std::optional< VECTOR2I > designBlockAnchor(const std::vector< SCH_ITEM * > &aItems)
Pick the point a placed design block hangs from.
Class to handle a set of SCH_ITEMs.
@ AUTOPLACE_AUTO
Definition sch_item.h:75
std::vector< EDA_ITEM * > EDA_ITEMS
LABEL_FLAG_SHAPE
Label and flag shapes used with text objects.
Definition sch_label.h:97
@ F_ROUND
Definition sch_label.h:106
@ L_INPUT
Definition sch_label.h:98
void AnnotateNewSymbol(SCH_SYMBOL *aSymbol, const std::vector< SCH_SHEET_PATH > &aPaths, SCH_REFERENCE_LIST &aExistingRefs, const SCHEMATIC_SETTINGS &aSettings, SCH_SHEET_LIST *aHierarchy)
Annotate a newly placed symbol on each of aPaths in turn, avoiding aExistingRefs and adding the resul...
ANNOTATE_ORDER_T
Schematic annotation order options.
@ ANNOTATE_SELECTION
Annotate the selection.
ANNOTATE_ALGO_T
Schematic annotation type options.
#define MIN_SHEET_HEIGHT
Definition sch_sheet.h:43
#define MIN_SHEET_WIDTH
Definition sch_sheet.h:42
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_ALL
wxString UniqueGroupName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a group with that name already exists on aS...
bool IsUnannotatedUnitOccupied(const SCH_REFERENCE_LIST &aRefs, const wxString &aRef, const LIB_ID &aLibId, int aUnit)
Decide whether aUnit of an unannotated multi-unit symbol is already placed.
std::set< int > GetUnplacedUnitsForSymbol(const SCH_SYMBOL &aSym)
Get a list of unplaced (i.e.
void AutoPlaceSheetPins(SCH_SHEET *aSheet, const std::vector< SCH_HIERLABEL * > &aLabels)
Import and auto-place sheet pins for the given labels, growing the sheet as needed.
std::vector< SCH_ITEM * > FlattenGroups(const EDA_ITEMS &aItems)
Return the given items with the members of any group added, recursively.
std::vector< SCH_HIERLABEL * > GetUnplacedSheetPinLabels(const SCH_SHEET &aSheet)
Return one sheet hierarchical label per name that does not already have a sheet pin.
wxString UniqueSheetName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a sheet with that name already exists on aS...
Increment event parameters.
Definition actions.h:330
bool PlaceAllUnits
Definition sch_screen.h:89
bool m_Reannotate
If a symbol is provide, reannotate it?
bool m_PlaceAllUnits
For a preselected multi-unit symbol, keep placing remaining units instead of exiting.
SCH_SYMBOL * m_Symbol
Provide a symbol to place.
int m_Unit
Unit number to place; 0 means next available unit.
SCH_SYMBOL * m_Symbol
Symbol used as reference for unit placement.
@ USER
The field ID hasn't been set yet; field is invalid.
@ INTERSHEET_REFS
Global label cross-reference page numbers.
const std::string table
std::string path
IbisParser parser & reporter
KIBIS_PIN * pin
int delta
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_CENTER
@ TA_CHOICE_MENU_CHOICE
Context menu choice.
Definition tool_event.h:94
@ MD_SHIFT
Definition tool_event.h:139
@ TC_COMMAND
Definition tool_event.h:53
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:157
@ SCH_JUNCTION_T
Definition typeinfo.h:155
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
Definition of file extensions used in Kicad.