KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_editor_control.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
23#include <advanced_config.h>
24#include <symbol_edit_frame.h>
26
27#include <algorithm>
28#include <unordered_set>
29
30#include <wx_filename.h>
31#include <wx/clipbrd.h>
32#include <wx/buffer.h>
33#include <wx/filedlg.h>
34#include <wx/filefn.h>
35#include <wx/imagpng.h>
36#include <wx/log.h>
37#include <wx/log.h>
38#include <wx/msgdlg.h>
39#include <wx/mstream.h>
40#include <wx/textdlg.h>
41#include <wx/treectrl.h>
42
44#include <core/base64.h>
45#include <clipboard.h>
46#include <confirm.h>
47#include <connection_graph.h>
51#include <design_block.h>
62#include <project_rescue.h>
63#include <erc/erc.h>
64#include <invoke_sch_dialog.h>
65#include <locale_io.h>
66#include <string_utils.h>
67#include <kiway.h>
68#include <kiplatform/ui.h>
70#include <paths.h>
71#include <pgm_base.h>
74#include <project_sch.h>
76#include <richio.h>
78#include <sch_edit_frame.h>
80#include <sch_bitmap.h>
81#include <sch_group.h>
82#include <sch_line.h>
83#include <sch_junction.h>
84#include <sch_bus_entry.h>
85#include <sch_shape.h>
86#include <sch_painter.h>
87#include <sch_sheet_pin.h>
88#include <sch_table.h>
89#include <sch_tablecell.h>
90#include <sch_label.h>
91#include <sch_commit.h>
92#include <sim/simulator_frame.h>
94#include <symbol_viewer_frame.h>
95#include <tool/picker_tool.h>
96#include <tool/tool_manager.h>
97#include <tools/sch_actions.h>
98#include <tools/sch_selection.h>
100#include <tools/sch_tool_utils.h>
104#include <view/view_controls.h>
105#include <widgets/wx_infobar.h>
111#include <view/view.h>
112#include <zoom_defines.h>
114#include <gal/gal_print.h>
116
122static const wxChar traceSchPaste[] = wxT( "KICAD_SCH_PASTE" );
123
124namespace
125{
126constexpr int clipboardMaxBitmapSize = 4096;
127constexpr double clipboardBboxInflation = 0.02; // Small padding around selection
128
129
130std::vector<SCH_ITEM*> collectSelectionItems( const SCH_SELECTION& aSelection )
131{
132 std::vector<SCH_ITEM*> items;
133 items.reserve( aSelection.GetSize() );
134
135 for( EDA_ITEM* item : aSelection.GetItems() )
136 {
137 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item );
138
139 if( schItem )
140 items.push_back( schItem );
141 }
142
143 return items;
144}
145
146
147BOX2I expandedSelectionBox( const SCH_SELECTION& aSelection )
148{
149 BOX2I bbox = aSelection.GetBoundingBox();
150
151 if( bbox.GetWidth() > 0 && bbox.GetHeight() > 0 )
152 bbox.Inflate( bbox.GetWidth() * clipboardBboxInflation,
153 bbox.GetHeight() * clipboardBboxInflation );
154
155 return bbox;
156}
157
158
159bool generateHtmlFromPngData( const wxMemoryBuffer& aPngData, wxMemoryBuffer& aHtmlBuffer )
160{
161 if( aPngData.GetDataLen() == 0 )
162 return false;
163
164 std::vector<uint8_t> pngVec( static_cast<const uint8_t*>( aPngData.GetData() ),
165 static_cast<const uint8_t*>( aPngData.GetData() ) + aPngData.GetDataLen() );
166
167 std::vector<uint8_t> base64Data;
168 base64::encode( pngVec, base64Data );
169
170 std::string html = "<img src=\"data:image/png;base64,";
171 html.append( reinterpret_cast<const char*>( base64Data.data() ), base64Data.size() );
172 html.append( "\" />" );
173
174 aHtmlBuffer.SetDataLen( 0 );
175 aHtmlBuffer.AppendData( html.data(), html.size() );
176
177 return true;
178}
179
180
181bool plotSelectionToSvg( SCH_EDIT_FRAME* aFrame, const SCH_SELECTION& aSelection, const BOX2I& aBBox,
182 wxMemoryBuffer& aBuffer )
183{
184 SCH_RENDER_SETTINGS renderSettings( *aFrame->GetRenderSettings() );
185 renderSettings.LoadColors( aFrame->GetColorSettings() );
186 renderSettings.SetDefaultFont( aFrame->eeconfig()->m_Appearance.default_font );
187 renderSettings.m_ShowHiddenPins = false;
188 renderSettings.m_ShowHiddenFields = false;
189
190 std::unique_ptr<SVG_PLOTTER> plotter = std::make_unique<SVG_PLOTTER>();
191 plotter->SetRenderSettings( &renderSettings );
192
193 PAGE_INFO pageInfo = aFrame->GetScreen()->GetPageSettings();
194 pageInfo.SetWidthMils( schIUScale.IUToMils( aBBox.GetWidth() ) );
195 pageInfo.SetHeightMils( schIUScale.IUToMils( aBBox.GetHeight() ) );
196
197 plotter->SetPageSettings( pageInfo );
198 plotter->SetColorMode( true );
199
200 VECTOR2I plot_offset = aBBox.GetOrigin();
201 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS / 10, 1.0, false );
202 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
203
204 wxFileName tempFile( wxFileName::CreateTempFileName( wxS( "kicad_svg" ) ) );
205
206 if( !plotter->OpenFile( tempFile.GetFullPath() ) )
207 {
208 wxRemoveFile( tempFile.GetFullPath() );
209 return false;
210 }
211
212 LOCALE_IO toggle;
213 SCH_PLOT_OPTS plotOpts;
214 plotOpts.m_plotHopOver = aFrame->Schematic().Settings().GetHopOverScale() > 0.0;
215
216 plotter->StartPlot( wxT( "1" ) );
217 aFrame->GetScreen()->Plot( plotter.get(), plotOpts, collectSelectionItems( aSelection ) );
218 plotter->EndPlot();
219 plotter.reset();
220
221 bool ok = LoadFileToMemory( tempFile.GetFullPath(), aBuffer );
222 wxRemoveFile( tempFile.GetFullPath() );
223 return ok;
224}
225
226
232wxImage renderSelectionToBitmap( SCH_EDIT_FRAME* aFrame, const SCH_SELECTION& aSelection, const BOX2I& aBBox,
233 int aWidth, int aHeight, bool aUseAlpha, bool aIncludeDrawingSheet )
234{
235 wxImage image( aWidth, aHeight, false );
236 image.SetAlpha();
237
238 double actualPPI_x = (double) aWidth / schIUScale.IUTomm( aBBox.GetWidth() ) * 25.4;
239 double actualPPI_y = (double) aHeight / schIUScale.IUTomm( aBBox.GetHeight() ) * 25.4;
240 double actualPPI = std::max( actualPPI_x, actualPPI_y );
241
242 VECTOR2D pageSizeIn( (double) aWidth / actualPPI, (double) aHeight / actualPPI );
243
244 {
247
248 std::unique_ptr<KIGFX::CAIRO_PRINT_GAL> gal = KIGFX::CAIRO_PRINT_GAL::Create( options, &image, actualPPI );
249
250 if( !gal )
251 return wxImage();
252
253 KIGFX::PRINT_CONTEXT* printCtx = gal->GetPrintCtx();
254 std::unique_ptr<KIGFX::SCH_PAINTER> painter = std::make_unique<KIGFX::SCH_PAINTER>( gal.get() );
255 std::unique_ptr<KIGFX::VIEW> view = std::make_unique<KIGFX::VIEW>();
256
257 painter->SetSchematic( &aFrame->Schematic() );
258 view->SetGAL( gal.get() );
259 view->SetPainter( painter.get() );
260 view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA, ZOOM_MIN_LIMIT_EESCHEMA );
261 view->SetScale( 1.0 );
262
263 gal->SetWorldUnitLength( SCH_WORLD_UNIT );
264 gal->SetSheetSize( pageSizeIn );
265 gal->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
266
267 // Clone items and add to view
268 std::vector<std::unique_ptr<SCH_ITEM>> clonedItems;
269 clonedItems.reserve( aSelection.GetSize() );
270
271 for( EDA_ITEM* item : aSelection.GetItems() )
272 {
273 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item );
274
275 if( !schItem )
276 continue;
277
278 SCH_ITEM* clone = static_cast<SCH_ITEM*>( schItem->Clone() );
279 clonedItems.emplace_back( clone );
280 view->Add( clone );
281 }
282
283 SCH_RENDER_SETTINGS* dstSettings = painter->GetSettings();
284 *dstSettings = *aFrame->GetRenderSettings();
285 dstSettings->m_ShowPinsElectricalType = false;
286 dstSettings->LoadColors( aFrame->GetColorSettings( false ) );
288 dstSettings->SetDefaultFont( aFrame->eeconfig()->m_Appearance.default_font );
289 dstSettings->SetIsPrinting( true );
290
291 if( aUseAlpha )
292 dstSettings->SetBackgroundColor( COLOR4D::CLEAR );
293
294 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
295 {
296 view->SetLayerVisible( i, true );
297 view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
298 }
299
300 view->SetLayerVisible( LAYER_DRAWINGSHEET, aIncludeDrawingSheet );
301
302 // Create and add drawing sheet proxy view item if requested
303 std::unique_ptr<DS_PROXY_VIEW_ITEM> drawingSheet;
304
305 if( aIncludeDrawingSheet )
306 {
307 SCH_SCREEN* screen = aFrame->GetScreen();
308
309 drawingSheet.reset( new DS_PROXY_VIEW_ITEM( schIUScale, &screen->GetPageSettings(),
310 &screen->Schematic()->Project(), &screen->GetTitleBlock(),
311 screen->Schematic()->GetProperties() ) );
312 drawingSheet->SetPageNumber( TO_UTF8( screen->GetPageNumber() ) );
313 drawingSheet->SetSheetCount( screen->GetPageCount() );
314 drawingSheet->SetFileName( TO_UTF8( screen->GetFileName() ) );
315 drawingSheet->SetColorLayer( LAYER_SCHEMATIC_DRAWINGSHEET );
316 drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
317 drawingSheet->SetIsFirstPage( screen->GetVirtualPageNumber() == 1 );
318 drawingSheet->SetSheetName( TO_UTF8( aFrame->GetScreenDesc() ) );
319 drawingSheet->SetSheetPath( TO_UTF8( aFrame->GetFullScreenDesc() ) );
320
321 wxString currentVariant = screen->Schematic()->GetCurrentVariant();
322 wxString variantDesc = screen->Schematic()->GetVariantDescription( currentVariant );
323 drawingSheet->SetVariantName( TO_UTF8( currentVariant ) );
324 drawingSheet->SetVariantDesc( TO_UTF8( variantDesc ) );
325
326 view->Add( drawingSheet.get() );
327 }
328
329 view->SetCenter( aBBox.Centre() );
330 view->UseDrawPriority( true );
331
332 gal->SetClearColor( dstSettings->GetBackgroundColor() );
333 gal->ClearScreen();
334
335 {
336 KIGFX::GAL_DRAWING_CONTEXT ctx( gal.get() );
337 view->Redraw();
338 }
339 }
340
341 return image;
342}
343
344
345wxImage renderSelectionToImageForClipboard( SCH_EDIT_FRAME* aFrame, const SCH_SELECTION& aSelection,
346 const BOX2I& aBBox, bool aUseAlpha, bool aIncludeDrawingSheet )
347{
348 const double c_targetPPI = 300;
349 const double c_targetPixelsPerMM = c_targetPPI / 25.4;
350
351 VECTOR2I size = aBBox.GetSize();
352
353 if( size.x <= 0 || size.y <= 0 )
354 return wxImage();
355
356 int bitmapWidth = KiROUND( schIUScale.IUTomm( size.x ) * c_targetPixelsPerMM );
357 int bitmapHeight = KiROUND( schIUScale.IUTomm( size.y ) * c_targetPixelsPerMM );
358
359 // Clamp to maximum size while preserving aspect ratio
360 if( bitmapWidth > clipboardMaxBitmapSize || bitmapHeight > clipboardMaxBitmapSize )
361 {
362 double scaleDown = (double) clipboardMaxBitmapSize / std::max( bitmapWidth, bitmapHeight );
363 bitmapWidth = KiROUND( bitmapWidth * scaleDown );
364 bitmapHeight = KiROUND( bitmapHeight * scaleDown );
365 }
366
367 if( bitmapWidth <= 0 || bitmapHeight <= 0 )
368 return wxImage();
369
370 wxImage result = renderSelectionToBitmap( aFrame, aSelection, aBBox, bitmapWidth, bitmapHeight, aUseAlpha,
371 aIncludeDrawingSheet );
372
373 return result;
374}
375} // namespace
376
377
379{
380 m_frame->NewProject();
381 return 0;
382}
383
384
386{
387 m_frame->LoadProject();
388 return 0;
389}
390
391
393{
394 m_frame->SaveProject();
395 return 0;
396}
397
398
400{
401 m_frame->SaveProject( true );
402 return 0;
403}
404
405
407{
408 SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
409 wxFileName curr_fn = curr_sheet->GetFileName();
410 wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(), curr_fn.GetFullName(),
411 FILEEXT::KiCadSchematicFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
412
414
415 if( dlg.ShowModal() == wxID_CANCEL )
416 return false;
417
418 wxString newFilename = EnsureFileExtension( dlg.GetPath(), FILEEXT::KiCadSchematicFileExtension );
419
420 m_frame->saveSchematicFile( curr_sheet, newFilename, true );
421 return 0;
422}
423
424
426{
427 wxString msg;
428 msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ), m_frame->Schematic().GetFileName() );
429
430 if( !IsOK( m_frame, msg ) )
431 return 0;
432
433 m_frame->ReloadFromDisk();
434
435 return 0;
436}
437
438
440{
441 m_frame->ShowSchematicSetupDialog();
442 return 0;
443}
444
445
447{
448 PICKED_ITEMS_LIST undoCmd;
450 ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
451
452 undoCmd.PushItem( wrapper );
453 undoCmd.SetDescription( _( "Page Settings" ) );
454 m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false );
455
456 DIALOG_EESCHEMA_PAGE_SETTINGS dlg( m_frame, m_frame->Schematic().GetEmbeddedFiles(),
459
460 if( dlg.ShowModal() == wxID_OK )
461 {
462 // Update text variables
463 m_frame->GetCanvas()->GetView()->MarkDirty();
464 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
465 m_frame->GetCanvas()->Refresh();
466
467 m_frame->OnModify();
468 }
469 else
470 {
471 m_frame->RollbackSchematicFromUndo();
472 }
473
474 return 0;
475}
476
477
479{
480 SCH_SCREENS schematic( m_frame->Schematic().Root() );
481
482 if( schematic.HasNoFullyDefinedLibIds() )
483 RescueLegacyProject( true );
484 else
486
487 return 0;
488}
489
490
491bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
492{
493 LEGACY_RESCUER rescuer( m_frame->Prj(), &m_frame->Schematic(), &m_frame->GetCurrentSheet(),
494 m_frame->GetCanvas()->GetBackend() );
495
496 return rescueProject( rescuer, aRunningOnDemand );
497}
498
499
501{
502 SYMBOL_LIB_TABLE_RESCUER rescuer( m_frame->Prj(), &m_frame->Schematic(), &m_frame->GetCurrentSheet(),
503 m_frame->GetCanvas()->GetBackend() );
504
505 return rescueProject( rescuer, aRunningOnDemand );
506}
507
508
509bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
510{
511 if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
512 return false;
513
514 if( aRescuer.GetCandidateCount() )
515 {
516 KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
517
518 if( viewer )
519 static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
520
521 if( aRunningOnDemand )
522 {
523 SCH_SCREENS schematic( m_frame->Schematic().Root() );
524
525 schematic.UpdateSymbolLinks();
526 m_frame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
527 }
528
529 m_frame->ClearUndoRedoList();
530 m_frame->SyncView();
531 m_frame->GetCanvas()->Refresh();
532 m_frame->OnModify();
533 }
534
535 return true;
536}
537
538
540{
541 DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
542
543 dlgRemap.ShowQuasiModal();
544
545 m_frame->GetCanvas()->Refresh( true );
546
547 return 0;
548}
549
550
552{
553 DIALOG_PRINT dlg( m_frame );
554
555 dlg.ShowModal();
556
557 return 0;
558}
559
560
562{
564
565 dlg.ShowModal();
566
567 return 0;
568}
569
570
572{
573 m_frame->Schematic().OnSchSelectionChanged();
574 doCrossProbeSchToPcb( aEvent, false );
575 return 0;
576}
577
578
580{
581 doCrossProbeSchToPcb( aEvent, true );
582 return 0;
583}
584
585
586void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
587{
588 // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
589 if( m_probingPcbToSch || m_frame->IsSyncingSelection() )
590 return;
591
592 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
593 SCH_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
594
595 m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
596}
597
598
600{
601 const wxString title = _( "Export for Older KiCad Version" );
602
603 // The export reads the files on disk, so they have to match what is on screen.
604 if( m_frame->IsContentModified() )
605 {
606 int answer = wxMessageBox( _( "You have unsaved changes. Save them before exporting?" ), title,
607 wxYES_NO | wxCANCEL | wxICON_WARNING, m_frame );
608
609 if( answer == wxCANCEL )
610 return 0;
611
612 if( answer == wxYES && !m_frame->SaveProject() )
613 {
614 wxMessageBox( _( "The schematic was not saved. Nothing was exported." ), title, wxOK | wxICON_ERROR,
615 m_frame );
616 return 0;
617 }
618 }
619
620 const wxString schematic = m_frame->Schematic().RootScreen()->GetFileName();
621
623 [&]( const DOWNGRADE_EXPORT_PASS& aPass, DOWNGRADE_EXPORT_RESULT& aResult ) -> bool
624 {
626 job.m_filename = schematic;
627 job.m_variant = aPass.m_variant;
628
629 if( !aPass.m_dryRun )
630 {
631 wxFileName out( aPass.m_folder, wxEmptyString );
632 out.AppendDir( wxFileName( schematic ).GetName() );
633 job.m_outputDir = out.GetPath();
634 }
635
636 if( !RunDowngradeJob( m_frame->Kiway(), KIWAY::FACE_SCH, job, aPass, aResult ) )
637 return false;
638
639 aResult.m_variantsFound = job.m_foundVariants;
640 return true;
641 } );
642
643 return 0;
644}
645
646
648{
649 bool savePowerSymbols = false;
650 bool map = false;
652 wxString targetLib;
653 wxString msg;
654
655 targetLib = m_frame->SelectLibrary( _( "Export Symbols" ), _( "Export symbols to library:" ),
656 { { _( "Include power symbols in export" ), &savePowerSymbols },
657 { _( "Update schematic symbols to link to exported symbols" ), &map }
658 } );
659
660 if( targetLib.empty() )
661 return 0;
662
663 SCH_SHEET_LIST sheets = m_frame->Schematic().BuildSheetListSortedByPageNumbers();
664 SCH_REFERENCE_LIST symbols;
665 sheets.GetSymbols( symbols, savePowerSymbols ? SYMBOL_FILTER_ALL : SYMBOL_FILTER_NON_POWER );
666
667 std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
668 std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
669
670 for( size_t i = 0; i < symbols.GetCount(); ++i )
671 {
672 SCH_SYMBOL* symbol = symbols[i].GetSymbol();
673 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
674 LIB_ID id = libSymbol->GetLibId();
675
676 if( libSymbols.count( id ) )
677 {
678 wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, ~SCH_ITEM::COMPARE_FLAGS::UUID ) == 0,
679 "Two symbols have the same LIB_ID but are different!" );
680 }
681 else
682 {
683 libSymbols[id] = libSymbol;
684 }
685
686 symbolMap[id].emplace_back( symbol );
687 }
688
689 bool append = false;
690 SCH_COMMIT commit( m_frame );
692
693 auto optRow = adapter->GetRow( targetLib );
694 wxCHECK( optRow, 0 );
695 const LIBRARY_TABLE_ROW* row = *optRow;
696
697 SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->Type() );
698 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( type ) );
699
700 wxFileName dest = LIBRARY_MANAGER::GetFullURI( row );
701 dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
702
703 for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
704 {
705 LIB_SYMBOL* origSym = it.second;
706 std::unique_ptr<LIB_SYMBOL> newSym = origSym->Flatten();
707 const wxString newSymName = newSym->GetName();
708
709 try
710 {
711 pi->SaveSymbol( dest.GetFullPath(), std::move( newSym ) );
712 }
713 catch( const IO_ERROR& ioe )
714 {
715 msg.Printf( _( "Error saving symbol %s to library '%s'." ), newSymName, row->Nickname() );
716 msg += wxS( "\n\n" ) + ioe.What();
717 wxLogWarning( msg );
718 return 0;
719 }
720
721 if( map )
722 {
723 LIB_ID id = it.first;
724 id.SetLibNickname( targetLib );
725
726 for( SCH_SYMBOL* symbol : symbolMap[it.first] )
727 {
728 SCH_SCREEN* parentScreen = static_cast<SCH_SCREEN*>( symbol->GetParent() );
729
730 wxCHECK2( parentScreen, continue );
731
732 commit.Modify( symbol, parentScreen, RECURSE_MODE::NO_RECURSE );
733 symbol->SetLibId( id );
734 append = true;
735 }
736 }
737 }
738
739 if( append )
740 {
741 std::set<SCH_SCREEN*> processedScreens;
742
743 for( SCH_SHEET_PATH& sheet : sheets )
744 {
745 SCH_SCREEN* screen = sheet.LastScreen();
746
747 if( processedScreens.find( ( screen ) ) == processedScreens.end() )
748 {
749 processedScreens.insert( screen );
750 screen->UpdateSymbolLinks();
751 }
752 }
753
754 commit.Push( wxS( "Update Library Identifiers" ) );
755 }
756
757 return 0;
758}
759
760
761#define HITTEST_THRESHOLD_PIXELS 5
762
764{
765 static const std::vector<KICAD_T> voltageProbeTypes = {
768 };
769
770 PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
771 KIWAY_PLAYER* sim_player = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
772 SIMULATOR_FRAME* sim_Frame = static_cast<SIMULATOR_FRAME*>( sim_player );
773
774 if( !sim_Frame ) // Defensive coding; shouldn't happen.
775 return 0;
776
777 if( wxWindow* blocking_win = sim_Frame->Kiway().GetBlockingDialog() )
778 blocking_win->Close( true );
779
780 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine && !m_frame->RecalculateConnections( nullptr, NO_CLEANUP ) )
781 return 0;
782
783 // Deactivate other tools; particularly important if another PICKER is currently running
784 Activate();
785
787 picker->SetSnapping( false );
788 picker->ClearHandlers();
789
790 picker->SetClickHandler(
791 [this]( const VECTOR2D& aPosition )
792 {
793 KIWAY_PLAYER* player = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
794 SIMULATOR_FRAME* simFrame = static_cast<SIMULATOR_FRAME*>( player );
795 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
796
797 // We do not really want to keep an item selected in schematic,
798 // so clear the current selection
799 selTool->ClearSelection();
800
801 EDA_ITEM* item = selTool->GetNode( aPosition );
802 SCH_SHEET_PATH& sheet = m_frame->GetCurrentSheet();
803 wxString variant = m_frame->Schematic().GetCurrentVariant();
804
805 if( !item )
806 return false;
807
808 if( item->Type() == SCH_PIN_T )
809 {
810 SCH_PIN* schPin = static_cast<SCH_PIN*>( item );
811 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( schPin->GetParentSymbol() );
812 SCH_PIN* libPin = schPin->GetLibPin();
813
814 if( !symbol || !libPin )
815 return false;
816
817 try
818 {
820 SIM_LIB_MGR mgr( &m_frame->Prj() );
821
822 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
823 embeddedFilesStack.push_back( m_frame->Schematic().GetEmbeddedFiles() );
824
825 if( symbol->GetLibSymbolRef() )
826 symbol->GetLibSymbolRef()->AppendParentEmbeddedFiles( embeddedFilesStack );
827
828 if( EMBEDDED_FILES* symbolEmbeddedFile = symbol->GetEmbeddedFiles() )
829 embeddedFilesStack.push_back( symbolEmbeddedFile );
830
831 mgr.SetFilesStack( std::move( embeddedFilesStack ) );
832
833 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, true, 0, variant, reporter ).model;
834
835 if( reporter.HasMessage() )
836 THROW_IO_ERROR( reporter.GetMessages() );
837
838 SPICE_ITEM spiceItem;
839 spiceItem.refName = symbol->GetRef( &sheet ).ToStdString();
840 std::vector<std::string> currentNames = model.SpiceGenerator().CurrentNames( spiceItem );
841
842 if( currentNames.size() == 0 )
843 {
844 return true;
845 }
846 else if( currentNames.size() == 1 )
847 {
848 if( simFrame )
849 simFrame->AddCurrentTrace( currentNames.at( 0 ) );
850
851 return true;
852 }
853
854 int modelPinIndex = model.FindModelPinIndex( libPin->GetNumber().ToStdString() );
855
856 if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
857 {
858 wxString name = currentNames.at( modelPinIndex );
859
860 if( simFrame )
861 simFrame->AddCurrentTrace( name );
862 }
863 }
864 catch( const IO_ERROR& e )
865 {
867 }
868 }
869 else if( item->IsType( voltageProbeTypes ) )
870 {
871 const SCH_ITEM* schItem = static_cast<const SCH_ITEM*>( item );
872
873 if( schItem->HasBusConnection( &sheet ) )
874 return true;
875
876 if( const auto name = schItem->GetConnectionName( &sheet );
877 name && !name->IsEmpty() )
878 {
879 wxString spiceNet = *name;
881
882 if( simFrame )
883 simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) );
884 }
885 }
886
887 return true;
888 } );
889
890 picker->SetMotionHandler(
891 [this]( const VECTOR2D& aPos )
892 {
893 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
894 EDA_ITEM* item = selectionTool->GetNode( aPos );
895 wxString connectionName;
896
897 if( item && item->IsType( voltageProbeTypes ) )
898 {
899 const SCH_ITEM* schItem = static_cast<const SCH_ITEM*>( item );
900 const SCH_SHEET_PATH& sheet = m_frame->GetCurrentSheet();
901 item = nullptr;
902
903 if( !schItem->HasBusConnection( &sheet ) )
904 connectionName = schItem->GetConnectionName( &sheet ).value_or( wxString() );
905 }
906 else if( item && item->Type() != SCH_PIN_T )
907 {
908 item = nullptr;
909 }
910
911 if( item && item->Type() == SCH_PIN_T )
912 m_toolMgr->GetTool<PICKER_TOOL>()->SetCursor( KICURSOR::CURRENT_PROBE );
913 else
914 m_toolMgr->GetTool<PICKER_TOOL>()->SetCursor( KICURSOR::VOLTAGE_PROBE );
915
916 if( m_pickerItem != item )
917 {
918 if( m_pickerItem )
919 selectionTool->UnbrightenItem( m_pickerItem );
920
921 m_pickerItem = item;
922
923 if( m_pickerItem )
924 selectionTool->BrightenItem( m_pickerItem );
925 }
926
927 if( m_frame->GetHighlightedConnection() != connectionName )
928 {
929 m_frame->SetHighlightedConnection( connectionName );
930
931 TOOL_EVENT dummyEvent;
932 UpdateNetHighlighting( dummyEvent );
933 }
934 } );
935
936 picker->SetFinalizeHandler(
937 [this]( const int& aFinalState )
938 {
939 if( m_pickerItem )
940 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
941
942 if( !m_frame->GetHighlightedConnection().IsEmpty() )
943 {
944 m_frame->SetHighlightedConnection( wxEmptyString );
945
946 TOOL_EVENT dummyEvent;
947 UpdateNetHighlighting( dummyEvent );
948 }
949
950 // Wake the selection tool after exiting to ensure the cursor gets updated
951 // and deselect previous selection from simulator to avoid any issue
952 // ( avoid crash in some cases when the SimProbe tool is deselected )
953 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
954 selectionTool->ClearSelection();
956 } );
957
958 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
959
960 return 0;
961}
962
963
965{
966 PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
967
968 // Deactivate other tools; particularly important if another PICKER is currently running
969 Activate();
970
971 picker->SetCursor( KICURSOR::TUNE );
972 picker->SetSnapping( false );
973 picker->ClearHandlers();
974
975 picker->SetClickHandler(
976 [this]( const VECTOR2D& aPosition )
977 {
978 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
979 EDA_ITEM* item = nullptr;
980 selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
981
982 if( !item )
983 return false;
984
985 if( item->Type() != SCH_SYMBOL_T )
986 {
987 item = item->GetParent();
988
989 if( item->Type() != SCH_SYMBOL_T )
990 return false;
991 }
992
993 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
994 SCH_SHEET_PATH sheetPath = symbol->Schematic()->CurrentSheet();
995 KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
996
997 if( simFrame )
998 {
999 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
1000 blocking_win->Close( true );
1001
1002 static_cast<SIMULATOR_FRAME*>( simFrame )->AddTuner( sheetPath, symbol );
1003 }
1004
1005 // We do not really want to keep a symbol selected in schematic,
1006 // so clear the current selection
1007 selTool->ClearSelection();
1008 return true;
1009 } );
1010
1011 picker->SetMotionHandler(
1012 [this]( const VECTOR2D& aPos )
1013 {
1014 SCH_COLLECTOR collector;
1015 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1016 collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos );
1017
1018 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1019 selectionTool->GuessSelectionCandidates( collector, aPos );
1020
1021 EDA_ITEM* item = collector.GetCount() == 1 ? collector[0] : nullptr;
1022
1023 if( item && item->Type() == SCH_FIELD_T )
1024 item = static_cast<SCH_FIELD*>( item )->GetParentSymbol();
1025
1026 if( m_pickerItem != item )
1027 {
1028 if( m_pickerItem )
1029 selectionTool->UnbrightenItem( m_pickerItem );
1030
1031 m_pickerItem = item;
1032
1033 if( m_pickerItem )
1034 selectionTool->BrightenItem( m_pickerItem );
1035 }
1036 } );
1037
1038 picker->SetFinalizeHandler(
1039 [this]( const int& aFinalState )
1040 {
1041 if( m_pickerItem )
1042 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
1043
1044 // Wake the selection tool after exiting to ensure the cursor gets updated
1045 // and deselect previous selection from simulator to avoid any issue
1046 // ( avoid crash in some cases when the SimTune tool is deselected )
1047 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1048 selectionTool->ClearSelection();
1050 } );
1051
1052 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
1053
1054 return 0;
1055}
1056
1057
1058// A singleton reference for clearing the highlight
1060
1061
1062static void recalculateIfStale( SCH_EDIT_FRAME* aFrame, SCH_ITEM* aItem )
1063{
1064 if( ( aItem && aItem->IsConnectivityDirty() ) || !aFrame->Schematic().NetChains().NetChainsBuilt() )
1065 aFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1066}
1067
1068
1069static bool setNetHighlight( SCH_ITEM* aItem, bool aHighlight )
1070{
1071 if( aItem->IsNetHighlighted() == aHighlight )
1072 return false;
1073
1074 aItem->SetNetHighlighted( aHighlight );
1075 return true;
1076}
1077
1078
1079static bool highlightNet( TOOL_MANAGER* aToolMgr, const SCH_SHEET_PATH& aSheetPath, const VECTOR2D& aPosition )
1080{
1081 wxLogTrace( "KICAD_SCH_HIGHLIGHT", "highlightNet: pos=(%f,%f) clear=%d", aPosition.x, aPosition.y,
1082 ( aPosition == CLEAR ) );
1083 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
1084 SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool<SCH_SELECTION_TOOL>();
1085 SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
1086 std::optional<wxString> connName;
1087 SCH_ITEM* item = nullptr;
1088 bool retVal = true;
1089
1090 if( aPosition != CLEAR )
1091 {
1092 ERC_TESTER erc( &editFrame->Schematic() );
1093
1094 if( erc.TestDuplicateSheetNames( false ) > 0 )
1095 {
1096 wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
1097 retVal = false;
1098 }
1099 else
1100 {
1101 item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
1102 wxLogTrace( "KICAD_SCH_HIGHLIGHT", "highlightNet: item=%p type=%d", (void*) item, item ? (int) item->Type()
1103 : -1 );
1104 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1105
1106 if( item )
1107 {
1108 recalculateIfStale( editFrame, item );
1109
1110 if( item->Type() == SCH_FIELD_T )
1111 symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
1112
1113 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1114 {
1115 std::vector<SCH_PIN*> pins = symbol->GetPins( &aSheetPath );
1116
1117 if( pins.size() == 1 )
1118 connName = pins[0]->GetConnectionName( &editFrame->GetCurrentSheet() );
1119 }
1120 else
1121 {
1122 connName = item->GetConnectionName( &editFrame->GetCurrentSheet() );
1123 }
1124 }
1125 }
1126 }
1127
1128 if( !connName || connName->IsEmpty() )
1129 {
1130 wxLogTrace( "KICAD_SCH_HIGHLIGHT", "highlightNet: no connection under cursor" );
1131 editFrame->SetStatusText( wxT( "" ) );
1132 editFrame->SendCrossProbeClearHighlight();
1133 editFrame->SetHighlightedConnection( wxEmptyString );
1134 // Also clear any highlighted net chain so ESC or clicking empty space clears both modes
1135 editFrame->SetHighlightedNetChain( wxEmptyString );
1136 editorControl->SetHighlightBusMembers( false );
1137 }
1138 else
1139 {
1140 NET_NAVIGATOR_ITEM_DATA itemData( editFrame->GetCurrentSheet(), item );
1141
1142 if( *connName != editFrame->GetHighlightedConnection() )
1143 {
1144 wxLogTrace( "KICAD_SCH_HIGHLIGHT", "highlightNet: setting highlighted connection to %s", *connName );
1145 editorControl->SetHighlightBusMembers( false );
1146 // Clear any previous chain highlight when switching to net highlight
1147 editFrame->SetHighlightedNetChain( wxEmptyString );
1148 editFrame->SetCrossProbeConnection( *connName );
1149 editFrame->SetHighlightedConnection( *connName, &itemData );
1150 }
1151 else
1152 {
1153 auto& chains = editFrame->Schematic().NetChains();
1154
1155 if( SCH_NETCHAIN* chain = chains.GetNetChainForNet( *connName ) )
1156 {
1157 editFrame->SetHighlightedConnection( wxEmptyString );
1158 editFrame->SetHighlightedNetChain( chain->GetName() );
1159 editorControl->SetHighlightBusMembers( false );
1160 }
1161 else
1162 {
1163 editorControl->SetHighlightBusMembers( !editorControl->GetHighlightBusMembers() );
1164
1165 if( item != editFrame->GetSelectedNetNavigatorItem() )
1166 editFrame->SelectNetNavigatorItem( &itemData );
1167 }
1168 }
1169 }
1170
1171 editFrame->UpdateNetHighlightStatus();
1172
1174 editorControl->UpdateNetHighlighting( dummy );
1175 wxLogTrace( "KICAD_SCH_HIGHLIGHT", "highlightNet: done" );
1176
1177 return retVal;
1178}
1179
1180
1182{
1184 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1185
1186 highlightNet( m_toolMgr, m_frame->GetCurrentSheet(), cursorPos );
1187
1188 return 0;
1189}
1190
1191
1193{
1195 const VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1196 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1197 SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( cursorPos ) );
1198 auto& chains = m_frame->Schematic().NetChains();
1199
1200 recalculateIfStale( m_frame, item );
1201
1202 const auto name = item ? item->GetConnectionName( &m_frame->GetCurrentSheet() ) : std::nullopt;
1203 wxString newChain;
1204 wxString newConnection;
1205
1206 if( name && !name->IsEmpty() )
1207 {
1208 if( SCH_NETCHAIN* chain = chains.GetNetChainForNet( *name ) )
1209 {
1210 newChain = chain->GetName();
1211
1212 if( !chain->GetNets().empty() )
1213 m_frame->SendCrossProbeNetName( *chain->GetNets().begin() );
1214 }
1215 else
1216 {
1217 newConnection = *name;
1218 m_frame->SetCrossProbeConnection( *name );
1219 }
1220 }
1221 else
1222 {
1223 m_frame->SendCrossProbeClearHighlight();
1224 }
1225
1226 SetHighlightBusMembers( false );
1227 m_frame->SetHighlightedNetChain( newChain );
1228 m_frame->SetHighlightedConnection( newConnection );
1229 m_frame->UpdateNetHighlightStatus();
1232 return 0;
1233}
1234
1236{
1237 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
1238 if( !editFrame )
1239 return 0;
1240
1241 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1243 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1244
1245 SCH_ITEM* target = nullptr;
1246
1247 // Prefer current selection; otherwise, use item under cursor
1248 if( selTool && selTool->GetSelection().GetSize() == 1 )
1249 target = static_cast<SCH_ITEM*>( selTool->GetSelection().Front() );
1250 else if( selTool )
1251 target = static_cast<SCH_ITEM*>( selTool->GetNode( cursorPos ) );
1252
1253 if( !target )
1254 return 0;
1255
1256 auto& chains = editFrame->Schematic().NetChains();
1257 const wxString net = SCH_CONNECTIVITY::NETCHAIN_MANAGER::NetKeyForItem( *target, editFrame->GetCurrentSheet() );
1258 const SCH_NETCHAIN* chain = chains.GetNetChainForNet( net );
1259
1260 if( !chain )
1261 return 0;
1262
1263 SCH_COMMIT commit( editFrame );
1264
1265 for( const auto& [symbol, screen] : chains.GetBridgeSymbols( *chain, net ) )
1266 {
1267 commit.Modify( symbol, screen );
1268 symbol->SetPassthroughMode( SCH_SYMBOL::PASSTHROUGH_MODE::BLOCK );
1269 }
1270
1271 commit.Push( _( "Remove from Net Chain" ) );
1272
1273 return 0;
1274}
1275
1276
1278{
1279 highlightNet( m_toolMgr, m_frame->GetCurrentSheet(), CLEAR );
1280
1281 // Also clear any highlighted chain explicitly
1282 if( m_frame )
1283 m_frame->SetHighlightedNetChain( wxEmptyString );
1284
1285 return 0;
1286}
1287
1288
1290{
1291 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1292 SCHEMATIC& schematic = m_frame->Schematic();
1293 const SCH_SHEET_PATH path = m_frame->GetCurrentSheet();
1294 SCH_SCREEN* screen = path.LastScreen();
1295 const bool usePublished = ADVANCED_CFG::GetCfg().m_ConnectivityEngine;
1296
1297 if( usePublished && !m_frame->RecalculateConnections( nullptr, NO_CLEANUP ) )
1298 return 0;
1299
1300 const auto getNetNamePattern =
1301 []( const auto& aConn ) -> std::optional<wxString>
1302 {
1303 wxString netName = aConn.Name();
1304
1305 if( aConn.IsBus() )
1306 {
1307 wxString prefix;
1308
1309 if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
1310 return prefix + wxT( "*" );
1311 else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
1312 return prefix + wxT( ".*" );
1313 }
1314 else if( !aConn.Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( aConn.Driver() )
1316 {
1317 return std::nullopt;
1318 }
1319
1320 return netName;
1321 };
1322
1323 std::set<wxString> netNames;
1324
1325 for( EDA_ITEM* item : selectionTool->GetSelection() )
1326 {
1327 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1328 std::optional<wxString> netNamePattern;
1329
1330 if( usePublished )
1331 {
1332 const auto connection = schematic.Connectivity().Connection( schItem->m_Uuid, path.PathRef() );
1333
1334 if( !connection )
1335 continue;
1336
1337 netNamePattern = getNetNamePattern( *connection );
1338 }
1339 else
1340 {
1341 const SCH_CONNECTION* connection = schItem->Connection( &path );
1342
1343 if( !connection )
1344 continue;
1345
1346 netNamePattern = getNetNamePattern( *connection );
1347 }
1348
1349 if( !netNamePattern )
1350 {
1351 // This is a choice, we can also allow some un-labeled nets as long as some are labeled.
1352 m_frame->ShowInfoBarError( _( "All selected nets must be labeled to assign a netclass." ) );
1353 return 0;
1354 }
1355
1356 netNames.insert( *netNamePattern );
1357 }
1358
1359 if( netNames.empty() )
1360 {
1361 m_frame->ShowInfoBarError( _( "No nets selected." ) );
1362 return 0;
1363 }
1364
1365 selectionTool->ClearSelection();
1366
1367 DIALOG_ASSIGN_NETCLASS dlg( m_frame, netNames, schematic.GetNetClassAssignmentCandidates(),
1368 [&]( const std::vector<wxString>& aNetNames )
1369 {
1370 std::unordered_set<SCH_ITEM*> highlighted;
1371 const SCH_CONNECTIVITY::NAVIGATION_QUERY query( schematic );
1372
1373 for( const wxString& name : aNetNames )
1374 query.CollectNetItems( name, path, highlighted );
1375
1376 for( SCH_ITEM* item : screen->Items() )
1377 {
1378 bool redraw = setNetHighlight( item, highlighted.contains( item ) );
1379
1380 item->RunOnChildren(
1381 [&]( SCH_ITEM* aChild )
1382 {
1383 redraw |= setNetHighlight( aChild, highlighted.contains( aChild ) );
1384 },
1385 RECURSE_MODE::NO_RECURSE );
1386
1387 if( redraw )
1388 getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
1389 }
1390
1391 m_frame->GetCanvas()->ForceRefresh();
1392 } );
1393
1394 if( dlg.ShowModal() )
1395 {
1396 getView()->UpdateAllItemsConditionally(
1397 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
1398 {
1399 int flags = 0;
1400
1401 auto invalidateTextVars =
1402 [&flags]( EDA_TEXT* text )
1403 {
1404 if( text->HasTextVars() )
1405 {
1406 text->ClearRenderCache();
1407 text->ClearBoundingBoxCache();
1409 }
1410 };
1411
1412 // Netclass coloured items
1413 //
1414 if( dynamic_cast<SCH_LINE*>( aItem ) )
1415 flags |= KIGFX::REPAINT;
1416 else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
1417 flags |= KIGFX::REPAINT;
1418 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
1419 flags |= KIGFX::REPAINT;
1420
1421 // Items that might reference an item's netclass name
1422 //
1423 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
1424 invalidateTextVars( text );
1425
1426 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
1427 {
1428 item->RunOnChildren(
1429 [&invalidateTextVars]( SCH_ITEM* aChild )
1430 {
1431 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
1432 invalidateTextVars( text );
1433 },
1435
1436 if( flags & KIGFX::GEOMETRY )
1437 m_frame->GetScreen()->UpdateDisplayBounds( item );
1438 }
1439
1440 return flags;
1441 } );
1442 }
1443
1444 highlightNet( m_toolMgr, m_frame->GetCurrentSheet(), CLEAR );
1445 return 0;
1446}
1447
1448
1450{
1451 SCH_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1452
1453 if( !selectionTool )
1454 return 0;
1455
1456 const SCH_SHEET_PATH path = m_frame->GetCurrentSheet();
1457 const bool usePublished = ADVANCED_CFG::GetCfg().m_ConnectivityEngine;
1458
1459 if( usePublished && !m_frame->RecalculateConnections( nullptr, NO_CLEANUP ) )
1460 return 0;
1461
1462 wxString netName;
1463
1464 for( EDA_ITEM* item : selectionTool->GetSelection() )
1465 {
1466 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
1467 {
1468 if( usePublished )
1469 {
1470 const auto connection = m_frame->Schematic().Connectivity().Connection(
1471 schItem->m_Uuid, path.PathRef() );
1472
1473 if( connection && !connection->IsUnconnected() )
1474 netName = connection->Name();
1475 }
1476 else if( const SCH_CONNECTION* connection = schItem->Connection( &path ) )
1477 {
1478 netName = connection->GetNetName();
1479 }
1480
1481 if( !netName.IsEmpty() )
1482 break;
1483 }
1484 }
1485
1486 if( netName.IsEmpty() )
1487 netName = m_frame->GetHighlightedConnection();
1488
1489 if( netName.IsEmpty() )
1490 {
1491 m_frame->ShowInfoBarError( _( "No connected net selected." ) );
1492 return 0;
1493 }
1494
1495 m_frame->FindNetInInspector( netName );
1496
1497 return 0;
1498}
1499
1500
1502{
1503 wxCHECK( m_frame, 0 );
1504
1505 const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
1506 SCH_SCREEN* screen = sheetPath.LastScreen();
1507 wxCHECK( screen, 0 );
1508
1509 const wxString selectedName = m_frame->GetHighlightedConnection();
1510 const wxString chainName = m_frame->GetHighlightedNetChain();
1511 SCH_NETCHAIN* chain = chainName.IsEmpty() ? nullptr
1512 : m_frame->Schematic().NetChains().GetNetChainByName( chainName );
1513 std::unordered_set<SCH_ITEM*> highlighted;
1514
1515 if( !selectedName.IsEmpty() || chain )
1516 {
1517 const SCH_CONNECTIVITY::NAVIGATION_QUERY query( m_frame->Schematic() );
1518
1519 if( !selectedName.IsEmpty() )
1520 query.CollectNetItems( selectedName, sheetPath, highlighted, true, m_highlightBusMembers );
1521
1522 if( chain )
1523 {
1524 for( const wxString& name : chain->GetNets() )
1525 query.CollectNetItems( name, sheetPath, highlighted );
1526 }
1527 }
1528
1529 bool changed = false;
1530
1531 for( SCH_ITEM* item : screen->Items() )
1532 {
1533 if( !item )
1534 continue;
1535
1536 bool redraw = setNetHighlight( item, highlighted.contains( item ) );
1537 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1538 bool powerHighlight = false;
1539
1540 if( symbol && symbol->IsPower() )
1541 {
1542 std::vector<SCH_PIN*> pins = symbol->GetPins( &sheetPath );
1543 powerHighlight = !pins.empty() && highlighted.contains( pins.front() );
1544 }
1545
1546 item->RunOnChildren(
1547 [&]( SCH_ITEM* child )
1548 {
1549 bool highlight = highlighted.contains( child );
1550
1551 if( powerHighlight && child->Type() == SCH_FIELD_T )
1552 {
1553 const auto* field = static_cast<SCH_FIELD*>( child );
1554 highlight = field->IsVisible() && ( field->GetId() == FIELD_T::REFERENCE
1555 || field->GetId() == FIELD_T::VALUE );
1556 }
1557
1558 redraw |= setNetHighlight( child, highlight );
1560
1561 if( redraw )
1562 {
1563 getView()->Update( item, KIGFX::REPAINT );
1564 changed = true;
1565 }
1566 }
1567
1568 if( changed )
1569 m_frame->GetCanvas()->Refresh();
1570
1571 return 0;
1572}
1573
1574
1576{
1577 PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
1578
1579 // Deactivate other tools; particularly important if another PICKER is currently running
1580 Activate();
1581
1582 picker->SetCursor( KICURSOR::BULLSEYE );
1583 picker->SetSnapping( false );
1584 picker->ClearHandlers();
1585
1586 picker->SetClickHandler(
1587 [this]( const VECTOR2D& aPos )
1588 {
1589 return highlightNet( m_toolMgr, m_frame->GetCurrentSheet(), aPos );
1590 } );
1591
1592 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
1593
1594 return 0;
1595}
1596
1597
1599{
1600 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
1602
1603 if( editFrame->Schematic().NetChains().ReplaceNetChainTerminalPin( change ) )
1604 {
1605 editFrame->OnModify();
1606 editFrame->GetCanvas()->Refresh();
1607 }
1608 else
1609 {
1610 DisplayError( editFrame, _( "Unable to replace the net chain terminal pin." ) );
1611 }
1612
1613 return 0;
1614}
1615
1616
1618{
1619 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1620 SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetSelection().Front() );
1621 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
1622
1623 if( !pin )
1624 return 0;
1625
1626 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
1627 auto& chains = editFrame->Schematic().NetChains();
1628 const auto netName = pin->GetConnectionName( &editFrame->GetCurrentSheet() );
1629
1630 if( !netName )
1631 return 0;
1632
1633 if( SCH_NETCHAIN* sig = chains.GetNetChainForNet( *netName ) )
1634 {
1635 const wxString oldName = sig->GetName();
1636 const wxString newName = wxGetTextFromUser( _( "Net chain name:" ), _( "Name Net Chain" ), oldName );
1637
1638 if( newName.IsEmpty() || newName == oldName )
1639 return 0;
1640
1641 if( !SCH_NETCHAIN::IsValidName( newName ) )
1642 {
1643 DisplayError( editFrame, _( "Chain name cannot contain spaces, quotes, or parentheses." ) );
1644 return 0;
1645 }
1646
1647 if( !chains.RenameCommittedNetChain( oldName, newName ) )
1648 {
1649 DisplayError( editFrame, wxString::Format( _( "Unable to rename net chain '%s' to '%s'." ),
1650 oldName, newName ) );
1651 return 0;
1652 }
1653
1654 editFrame->OnModify();
1655 editFrame->SetHighlightedNetChain( newName );
1658 editFrame->UpdateNetHighlightStatus();
1659 }
1660
1661 return 0;
1662}
1663
1665{
1666 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1667 auto& selection = selTool->GetSelection();
1668
1669 if( selection.GetSize() != 2 )
1670 return 0;
1671
1672 SCH_PIN* pinA = dynamic_cast<SCH_PIN*>( static_cast<SCH_ITEM*>( selection[0] ) );
1673 SCH_PIN* pinB = dynamic_cast<SCH_PIN*>( static_cast<SCH_ITEM*>( selection[1] ) );
1674
1675 if( !pinA || !pinB )
1676 return 0;
1677
1678 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
1679 auto& chains = editFrame->Schematic().NetChains();
1680 const SCH_SHEET_PATH& path = editFrame->GetCurrentSheet();
1681
1682 SCH_NETCHAIN* potential = chains.FindPotentialNetChainBetweenPins( pinA, path, pinB, path );
1683 if( !potential )
1684 {
1685 DisplayError( editFrame, _( "No potential net chain connects the selected pins." ) );
1686 return 0;
1687 }
1688
1689 // Potentials are rebuilt regardless of commitment and GetNetChainForNet() returns the first owner
1690 for( const wxString& net : potential->GetNets() )
1691 {
1692 if( SCH_NETCHAIN* owner = chains.GetNetChainForNet( net ) )
1693 {
1694 DisplayError( editFrame, wxString::Format( _( "The selected pins are already in net chain '%s'." ),
1695 owner->GetName() ) );
1696 return 0;
1697 }
1698 }
1699
1700 // Build default suggestion name
1701 wxString suggestion = wxString::Format( wxS( "%s_%s" ), pinA->GetParentSymbol()->GetRef( &editFrame->GetCurrentSheet() ), pinB->GetParentSymbol()->GetRef( &editFrame->GetCurrentSheet() ) );
1702
1703 // Compose display text for dialog
1704 wxString msg = wxString::Format( _( "Create Net Chain between %s:%s and %s:%s" ),
1705 pinA->GetParentSymbol()->GetRef( &editFrame->GetCurrentSheet() ), pinA->GetNumber(),
1706 pinB->GetParentSymbol()->GetRef( &editFrame->GetCurrentSheet() ), pinB->GetNumber() );
1707
1708 // Temporary highlight preview: highlight all nets in potential (reuse SetHighlightedNetChain with temp name)
1709 // We use the potential's current name as a temporary highlight identifier
1710 wxString prevHighlightedChain = editFrame->GetHighlightedNetChain();
1711 wxString prevHighlightedConn = editFrame->GetHighlightedConnection();
1712
1713 editFrame->SetHighlightedConnection( wxEmptyString );
1714 editFrame->SetHighlightedNetChain( potential->GetName() );
1717 editFrame->UpdateNetHighlightStatus();
1718
1719 // Zoom to bounding box of the two pins (union) expanded slightly
1720 BOX2I bbox = pinA->GetBoundingBox();
1721 bbox.Merge( pinB->GetBoundingBox() );
1722 // Expand by 25% for context
1723 int dx = bbox.GetWidth() / 4; if( dx < 100 ) dx = 100;
1724 int dy = bbox.GetHeight() / 4; if( dy < 100 ) dy = 100;
1725 bbox.Inflate( dx, dy );
1726 if( auto canvas = editFrame->GetCanvas() )
1727 {
1728 canvas->GetView()->SetCenter( bbox.GetCenter() );
1729 // Compute scale so bbox roughly fits viewport height
1730 auto view = canvas->GetView();
1731 if( view )
1732 {
1733 BOX2D viewBox = view->GetBoundary();
1734 double scaleX = (double) viewBox.GetWidth() / (double) bbox.GetWidth();
1735 double scaleY = (double) viewBox.GetHeight() / (double) bbox.GetHeight();
1736 double scale = std::min( scaleX, scaleY );
1737 if( scale > 0 )
1738 view->SetScale( scale );
1739 }
1740 }
1741
1742 const auto restoreHighlight =
1743 [&]()
1744 {
1745 editFrame->SetHighlightedNetChain( prevHighlightedChain );
1746 editFrame->SetHighlightedConnection( prevHighlightedConn );
1748 editFrame->UpdateNetHighlightStatus();
1749 };
1750
1751 wxString name = wxGetTextFromUser( msg, _( "Create Net Chain" ), suggestion, editFrame );
1752
1753 if( name.IsEmpty() )
1754 {
1755 restoreHighlight();
1756 return 0; // cancelled
1757 }
1758
1760 {
1761 restoreHighlight();
1762 DisplayError( editFrame, _( "Chain name cannot contain spaces, quotes, or parentheses." ) );
1763 return 0;
1764 }
1765
1766 if( chains.GetNetChainByName( name ) )
1767 {
1768 restoreHighlight();
1769 DisplayError( editFrame, wxString::Format( _( "A net chain named '%s' already exists." ), name ) );
1770 return 0;
1771 }
1772
1773 if( !chains.CreateNetChainFromPotential( potential, name ) )
1774 {
1775 restoreHighlight();
1776 DisplayError( editFrame, wxString::Format( _( "Unable to create net chain '%s'." ), name ) );
1777 return 0;
1778 }
1779
1780 editFrame->OnModify();
1781
1782 // Replace temporary highlight with new chain name
1783 editFrame->SetHighlightedNetChain( name );
1784 editFrame->SetHighlightedConnection( wxEmptyString );
1786 editFrame->UpdateNetHighlightStatus();
1787 editFrame->Refresh();
1788
1789 return 0;
1790}
1791
1792
1794{
1795 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( m_toolMgr->GetToolHolder() );
1796
1797 editFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1798
1800
1801 if( SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>() )
1802 {
1803 const SCH_SELECTION& sel = selTool->GetSelection();
1804
1805 std::vector<SCH_SYMBOL*> symbols;
1806
1807 for( EDA_ITEM* item : sel )
1808 {
1809 if( SCH_SYMBOL* sym = dynamic_cast<SCH_SYMBOL*>( static_cast<SCH_ITEM*>( item ) ) )
1810 symbols.push_back( sym );
1811 }
1812
1813 if( symbols.size() >= 1 )
1814 hint.fromRef = symbols[0]->GetRef( &editFrame->GetCurrentSheet() );
1815
1816 if( symbols.size() >= 2 )
1817 hint.toRef = symbols[1]->GetRef( &editFrame->GetCurrentSheet() );
1818
1819 // Single pin or single wire/bus → use its connection's net name as the focus hint.
1820 if( symbols.empty() && sel.GetSize() == 1 )
1821 {
1822 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( sel.Front() );
1823
1824 if( schItem && schItem->IsType( { SCH_PIN_T, SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) )
1825 {
1826 if( const auto name = schItem->GetConnectionName( &editFrame->GetCurrentSheet() ) )
1827 hint.netName = *name;
1828 }
1829 }
1830 }
1831
1832 DIALOG_CREATE_NET_CHAIN dlg( editFrame, hint );
1833 dlg.ShowModal();
1834
1835 return 0;
1836}
1837
1838
1840{
1841 wxCHECK( m_frame, 0 );
1842
1843 if( m_frame->GetUndoCommandCount() <= 0 )
1844 return 0;
1845
1846 // Inform tools that undo command was issued
1847 m_toolMgr->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
1848
1849 // Get the old list
1850 PICKED_ITEMS_LIST* undo_list = m_frame->PopCommandFromUndoList();
1851
1852 wxCHECK( undo_list, 0 );
1853
1854 m_frame->PutDataInPreviousState( undo_list );
1855
1856 // Now push the old command to the RedoList
1857 undo_list->ReversePickersListOrder();
1858 m_frame->PushCommandToRedoList( undo_list );
1859
1860 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->RebuildSelection();
1861
1862 m_frame->GetCanvas()->Refresh();
1863 m_frame->OnModify();
1864
1865 return 0;
1866}
1867
1868
1870{
1871 wxCHECK( m_frame, 0 );
1872
1873 if( m_frame->GetRedoCommandCount() == 0 )
1874 return 0;
1875
1876 // Inform tools that undo command was issued
1877 m_toolMgr->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
1878
1879 /* Get the old list */
1880 PICKED_ITEMS_LIST* list = m_frame->PopCommandFromRedoList();
1881
1882 wxCHECK( list, 0 );
1883
1884 /* Redo the command: */
1885 m_frame->PutDataInPreviousState( list );
1886
1887 /* Put the old list in UndoList */
1888 list->ReversePickersListOrder();
1889 m_frame->PushCommandToUndoList( list );
1890
1891 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->RebuildSelection();
1892
1893 m_frame->GetCanvas()->Refresh();
1894 m_frame->OnModify();
1895
1896 return 0;
1897}
1898
1899
1900bool SCH_EDITOR_CONTROL::doCopy( bool aUseDuplicateClipboard )
1901{
1902 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1903 SCH_SELECTION& selection = selTool->RequestSelection();
1904 SCHEMATIC& schematic = m_frame->Schematic();
1905
1906 if( selection.Empty() )
1907 return false;
1908
1909 if( aUseDuplicateClipboard )
1910 m_duplicateIsHoverSelection = selection.IsHover();
1911
1912 selection.SetScreen( m_frame->GetScreen() );
1914
1915 for( EDA_ITEM* item : selection.GetItems() )
1916 {
1917 if( item->Type() == SCH_SHEET_T )
1918 {
1919 SCH_SHEET* sheet = (SCH_SHEET*) item;
1920 m_supplementaryClipboard[sheet->GetFileName()] = sheet->GetScreen();
1921 }
1922 else if( item->Type() == SCH_FIELD_T && selection.IsHover() )
1923 {
1924 // Most of the time the user is trying to duplicate the parent symbol
1925 // and the field text is in it
1926 selection.Add( item->GetParent() );
1927 }
1928 else if( item->Type() == SCH_MARKER_T )
1929 {
1930 // Don't let the markers be copied
1931 selection.Remove( item );
1932 }
1933 else if( item->Type() == SCH_GROUP_T )
1934 {
1935 // Groups need to have all their items selected
1936 static_cast<SCH_ITEM*>( item )->RunOnChildren(
1937 [&]( EDA_ITEM* aChild )
1938 {
1939 selection.Add( aChild );
1940 },
1942 }
1943 }
1944
1945 bool result = true;
1946 STRING_FORMATTER formatter;
1947 SCH_IO_KICAD_SEXPR plugin;
1948 SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet();
1949
1950 plugin.Format( &selection, &selPath, schematic, &formatter, true );
1951
1952 std::string prettyData = formatter.GetString();
1953 KICAD_FORMAT::Prettify( prettyData, KICAD_FORMAT::FORMAT_MODE::COMPACT_TEXT_PROPERTIES );
1954
1955 if( !aUseDuplicateClipboard )
1956 {
1957 wxLogNull doNotLog; // disable logging of failed clipboard actions
1958
1959 result &= wxTheClipboard->Open();
1960
1961 if( result )
1962 {
1963 wxDataObjectComposite* data = new wxDataObjectComposite();
1964
1965 // Add KiCad data
1966 wxCustomDataObject* kicadObj = new wxCustomDataObject( wxDataFormat( "application/kicad" ) );
1967 kicadObj->SetData( prettyData.size(), prettyData.data() );
1968 data->Add( kicadObj );
1969
1970 BOX2I selectionBox = expandedSelectionBox( selection );
1971
1972 if( selectionBox.GetWidth() > 0 && selectionBox.GetHeight() > 0 )
1973 {
1974 // Add bitmap data (encoded once, used for both PNG clipboard and HTML)
1975 wxImage image = renderSelectionToImageForClipboard( m_frame, selection, selectionBox, true, false );
1976 wxMemoryBuffer pngBuffer;
1977
1978 if( image.IsOk() && EncodeImageToPng( image, pngBuffer ) )
1979 {
1980 AddPngToClipboardData( data, pngBuffer, &image );
1981
1982 // Add HTML with embedded base64 PNG for pasting into documents
1983 wxMemoryBuffer htmlBuffer;
1984
1985 if( generateHtmlFromPngData( pngBuffer, htmlBuffer ) )
1986 {
1987 wxCustomDataObject* htmlObj = new wxCustomDataObject( wxDF_HTML );
1988 htmlObj->SetData( htmlBuffer.GetDataLen(), htmlBuffer.GetData() );
1989 data->Add( htmlObj );
1990 }
1991 }
1992
1993 // Add SVG data
1994 wxMemoryBuffer svgBuffer;
1995
1996 if( plotSelectionToSvg( m_frame, selection, selectionBox, svgBuffer ) )
1997 {
1998 wxCustomDataObject* svgObj = new wxCustomDataObject( wxDataFormat( "image/svg+xml" ) );
1999 svgObj->SetData( svgBuffer.GetDataLen(), svgBuffer.GetData() );
2000 data->Add( svgObj );
2001 }
2002 }
2003
2004 // Finally add text data
2005 data->Add( new wxTextDataObject( wxString::FromUTF8( prettyData ) ) );
2006
2007 result &= wxTheClipboard->SetData( data );
2008 result &= wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
2009 wxTheClipboard->Close();
2010 }
2011 }
2012
2013 if( selection.IsHover() )
2014 m_toolMgr->RunAction( ACTIONS::selectionClear );
2015
2016 if( aUseDuplicateClipboard )
2017 {
2018 m_duplicateClipboard = prettyData;
2019 return true;
2020 }
2021
2022 return result;
2023}
2024
2025
2026bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename, SCH_SCREEN** aScreen )
2027{
2028 if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
2029 {
2030 *aScreen = m_supplementaryClipboard[aSheetFilename];
2031 return true;
2032 }
2033
2034 return false;
2035}
2036
2037
2039{
2040 doCopy( true ); // Use the local clipboard
2041 Paste( aEvent );
2042
2043 return 0;
2044}
2045
2046
2048{
2049 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
2050
2051 if( textEntry )
2052 {
2053 textEntry->Cut();
2054 return 0;
2055 }
2056
2057 if( doCopy() )
2058 m_toolMgr->RunAction( ACTIONS::doDelete );
2059
2060 return 0;
2061}
2062
2063
2065{
2066 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
2067
2068 if( textEntry )
2069 {
2070 textEntry->Copy();
2071 return 0;
2072 }
2073
2074 doCopy();
2075
2076 return 0;
2077}
2078
2079
2081{
2082 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
2083 SCH_SELECTION& selection = selTool->RequestSelection();
2084
2085 if( selection.Empty() )
2086 return false;
2087
2088 wxString itemsAsText = GetSelectedItemsAsText( selection );
2089
2090 if( selection.IsHover() )
2091 m_toolMgr->RunAction( ACTIONS::selectionClear );
2092
2093 return SaveClipboard( itemsAsText.ToStdString() );
2094}
2095
2096
2098 const KIID_PATH& aClipPath, bool aForceKeepAnnotations )
2099{
2100 wxCHECK( m_frame && aSymbol, /* void */ );
2101
2102 SCH_SYMBOL_INSTANCE newInstance;
2103 bool instanceFound = false;
2104 KIID_PATH pasteLookupPath = aClipPath;
2105
2106 m_pastedSymbols.insert( aSymbol );
2107
2108 for( const SCH_SYMBOL_INSTANCE& tmp : aSymbol->GetInstances() )
2109 {
2110 if( ( tmp.m_Path.empty() && aClipPath.empty() ) || ( !aClipPath.empty() && tmp.m_Path.EndsWith( aClipPath ) ) )
2111 {
2112 newInstance = tmp;
2113 instanceFound = true;
2114
2115 wxLogTrace( traceSchPaste, wxS( "Pasting found symbol instance with reference %s, unit %d:\n"
2116 "\tClipboard path: %s\n"
2117 "\tSymbol UUID: %s." ),
2118 tmp.m_Reference,
2119 tmp.m_Unit,
2120 aClipPath.AsString(),
2121 aSymbol->m_Uuid.AsString() );
2122
2123 break;
2124 }
2125 }
2126
2127 // The pasted symbol look up paths include the symbol UUID.
2128 pasteLookupPath.push_back( aSymbol->m_Uuid );
2129
2130 if( !instanceFound )
2131 {
2132 wxLogTrace( traceSchPaste, wxS( "Clipboard symbol instance **not** found:\n\tClipboard path: %s\n"
2133 "\tSymbol UUID: %s." ),
2134 aClipPath.AsString(),
2135 aSymbol->m_Uuid.AsString() );
2136
2137 // Some legacy versions saved value fields escaped. While we still do in the symbol
2138 // editor, we don't anymore in the schematic, so be sure to unescape them.
2139 SCH_FIELD* valueField = aSymbol->GetField( FIELD_T::VALUE );
2140 valueField->SetText( UnescapeString( valueField->GetText() ) );
2141
2142 // Pasted from notepad or an older instance of eeschema. Use the values in the fields
2143 // instead.
2144 newInstance.m_Reference = aSymbol->GetField( FIELD_T::REFERENCE )->GetText();
2145 newInstance.m_Unit = aSymbol->GetUnit();
2146 }
2147
2148 newInstance.m_Path = aPastePath.Path();
2149 newInstance.m_ProjectName = m_frame->Prj().GetProjectName();
2150
2151 aSymbol->AddHierarchicalReference( newInstance );
2152
2153 if( !aForceKeepAnnotations )
2154 aSymbol->ClearAnnotation( &aPastePath, false );
2155
2156 // We might clear annotations but always leave the original unit number from the paste.
2157 aSymbol->SetUnit( newInstance.m_Unit );
2158}
2159
2160
2162 const KIID_PATH& aClipPath, bool aForceKeepAnnotations,
2163 SCH_SHEET_LIST* aPastedSheets, std::map<SCH_SHEET_PATH,
2164 SCH_REFERENCE_LIST>& aPastedSymbols )
2165{
2166 wxCHECK( aSheet && aPastedSheets, aPastePath );
2167
2168 SCH_SHEET_PATH sheetPath = aPastePath;
2169 sheetPath.push_back( aSheet );
2170
2171 aPastedSheets->push_back( sheetPath );
2172
2173 if( aSheet->GetScreen() == nullptr )
2174 return sheetPath; // We can only really set the page number but not load any items
2175
2176 bool isSharedPath = sheetPath.IsSharedPath();
2177
2178 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
2179 {
2180 if( item->IsConnectable() )
2181 item->SetConnectivityDirty();
2182
2183 if( item->Type() == SCH_SYMBOL_T )
2184 {
2185 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2186
2187 wxCHECK2( symbol, continue );
2188
2189 // Only do this once if the symbol is shared across multiple sheets.
2190 if( !m_pastedSymbols.count( symbol ) )
2191 {
2192 if( !isSharedPath )
2193 const_cast<KIID&>( symbol->m_Uuid ) = KIID();
2194
2196 {
2197 // Only update the UUID if the symbol is not in a shared sheet.
2198 if( !isSharedPath )
2199 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2200
2201 pin->SetConnectivityDirty();
2202 }
2203 }
2204
2205 updatePastedSymbol( symbol, sheetPath, aClipPath, aForceKeepAnnotations );
2206 }
2207 else if( item->Type() == SCH_SHEET_T )
2208 {
2209 SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
2210
2211 wxCHECK2( subsheet, continue );
2212
2213 // Make sure pins get a new UUID and set the dirty connectivity flag.
2214 if( !aPastedSheets->ContainsSheet( subsheet ) )
2215 {
2216 if( !isSharedPath )
2217 const_cast<KIID&>( subsheet->m_Uuid ) = KIID();
2218
2219 for( SCH_SHEET_PIN* pin : subsheet->GetPins() )
2220 {
2221 if( !isSharedPath )
2222 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2223
2224 pin->SetConnectivityDirty();
2225 }
2226 }
2227
2228 KIID_PATH newClipPath = aClipPath;
2229 newClipPath.push_back( subsheet->m_Uuid );
2230
2231 updatePastedSheet( subsheet, sheetPath, newClipPath, aForceKeepAnnotations, aPastedSheets, aPastedSymbols );
2232 }
2233 }
2234
2235 sheetPath.GetSymbols( aPastedSymbols[aPastePath], SYMBOL_FILTER_ALL );
2236
2237 return sheetPath;
2238}
2239
2240
2242{
2243 wxCHECK( m_frame, /* void */ );
2244
2245 for( SCH_SYMBOL* symbol : m_pastedSymbols )
2246 {
2247 wxCHECK2( symbol, continue );
2248
2249 PrunePastedSymbolInstances( symbol, m_frame->Schematic() );
2250 }
2251}
2252
2253
2255 const SCH_SCREEN* aDestScreen,
2256 const wxString& aLibSymbolName )
2257{
2258 // The clipboard's cached library symbol is a matched pair with the pasted instance, so it
2259 // must win over the destination's same-named cache. Pasting from the destination cache would
2260 // silently remap the instance to a different definition and drop in-place edits such as
2261 // renumbered pins (issue 21401) or a changed power type (issue 22162). Fall back to the
2262 // destination cache only when the clipboard carries no copy.
2263 if( aClipboardScreen )
2264 {
2265 auto clipIt = aClipboardScreen->GetLibSymbols().find( aLibSymbolName );
2266
2267 if( clipIt != aClipboardScreen->GetLibSymbols().end() )
2268 return clipIt->second;
2269 }
2270
2271 if( aDestScreen )
2272 {
2273 auto destIt = aDestScreen->GetLibSymbols().find( aLibSymbolName );
2274
2275 if( destIt != aDestScreen->GetLibSymbols().end() )
2276 return destIt->second;
2277 }
2278
2279 return nullptr;
2280}
2281
2282
2284{
2285 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
2286
2287 if( textEntry )
2288 {
2289 textEntry->Paste();
2290 return 0;
2291 }
2292
2293 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
2294 std::string content;
2295 VECTOR2I eventPos;
2296
2297 SCH_SHEET tempSheet;
2298
2299 // Priority for paste:
2300 // 1. application/kicad format (handled by GetClipboardUTF8 which checks this first)
2301 // 2. Text data that can be parsed as KiCad S-expressions
2302 // 3. Bitmap/image data (fallback only if no valid text content)
2303 if( aEvent.IsAction( &ACTIONS::duplicate ) )
2304 content = m_duplicateClipboard;
2305 else
2306 content = GetClipboardUTF8();
2307
2308 // Only fall back to image data if there's no text content
2309 if( content.empty() )
2310 {
2311 std::unique_ptr<wxBitmap> clipImg = GetImageFromClipboard();
2312
2313 if( clipImg )
2314 {
2315 auto bitmap = std::make_unique<SCH_BITMAP>();
2316
2317 if( bitmap->GetReferenceImage().SetImage( clipImg->ConvertToImage() ) )
2318 return m_toolMgr->RunAction( SCH_ACTIONS::placeImage, bitmap.release() );
2319 }
2320
2321 return 0;
2322 }
2323
2324 if( aEvent.IsAction( &ACTIONS::duplicate ) )
2325 eventPos = getViewControls()->GetCursorPosition( false );
2326
2327 STRING_LINE_READER reader( content, "Clipboard" );
2328 SCH_IO_KICAD_SEXPR plugin;
2329
2330 // Screen object on heap is owned by the sheet.
2331 SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
2332 tempSheet.SetScreen( tempScreen );
2333
2334 try
2335 {
2336 plugin.LoadContent( reader, &tempSheet );
2337 }
2338 catch( IO_ERROR& )
2339 {
2340 // If it wasn't schematic content, paste as a text object
2341 {
2342 if( content.size() > static_cast<size_t>( ADVANCED_CFG::GetCfg().m_MaxPastedTextLength ) )
2343 {
2344 int result = IsOK( m_frame, _( "Pasting a long text text string may be very slow. "
2345 "Do you want to continue?" ) );
2346 if( !result )
2347 return 0;
2348 }
2349
2350 SCH_TEXT* text_item = new SCH_TEXT( VECTOR2I( 0, 0 ), content );
2351 tempScreen->Append( text_item );
2352 }
2353 }
2354
2355 SELECTION& currentSelection = selTool->GetSelection();
2356
2357 bool hasTableCells = false;
2358
2359 for( EDA_ITEM* item : currentSelection )
2360 {
2361 if( item->Type() == SCH_TABLECELL_T )
2362 {
2363 hasTableCells = true;
2364 break;
2365 }
2366 }
2367
2368 if( hasTableCells )
2369 {
2370 SCH_TABLE* clipboardTable = nullptr;
2371
2372 for( SCH_ITEM* item : tempScreen->Items() )
2373 {
2374 if( item->Type() == SCH_TABLE_T )
2375 {
2376 clipboardTable = static_cast<SCH_TABLE*>( item );
2377 break;
2378 }
2379 }
2380
2381 if( clipboardTable )
2382 {
2383 SCH_EDIT_TABLE_TOOL* tableEditTool = m_toolMgr->GetTool<SCH_EDIT_TABLE_TOOL>();
2384
2385 if( tableEditTool )
2386 {
2387 wxString errorMsg;
2388
2389 if( !tableEditTool->validatePasteIntoSelection( currentSelection, errorMsg ) )
2390 {
2391 DisplayError( m_frame, errorMsg );
2392 return 0;
2393 }
2394
2395 SCH_COMMIT commit( m_toolMgr );
2396
2397 if( tableEditTool->pasteCellsIntoSelection( currentSelection, clipboardTable, commit ) )
2398 {
2399 commit.Push( _( "Paste Cells" ) );
2400 return 0;
2401 }
2402 else
2403 {
2404 DisplayError( m_frame, _( "Failed to paste cells" ) );
2405 return 0;
2406 }
2407 }
2408 }
2409 }
2410
2411 m_pastedSymbols.clear();
2412
2413 tempScreen->MigrateSimModels();
2414
2415 bool annotateAutomatic = m_frame->eeconfig()->m_AnnotatePanel.automatic;
2416 SCHEMATIC_SETTINGS& schematicSettings = m_frame->Schematic().Settings();
2417 int annotateStartNum = schematicSettings.m_AnnotateStartNum;
2418
2420 bool forceRemoveAnnotations = false;
2421
2422 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
2423 {
2424 PASTE_MODE defaultPasteMode = pasteMode;
2425 DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
2426
2427 if( dlg.ShowModal() == wxID_CANCEL )
2428 return 0;
2429
2430 // We have to distinguish if removing was explicit
2431 forceRemoveAnnotations = pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS && pasteMode != defaultPasteMode;
2432 }
2433
2434 bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
2435
2436 // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
2437 // else. Pull them back out to start with.
2438 SCH_COMMIT commit( m_toolMgr );
2439 EDA_ITEMS loadedItems;
2440 std::vector<SCH_ITEM*> sortedLoadedItems;
2441 bool sheetsPasted = false;
2442 SCH_SHEET_LIST hierarchy = m_frame->Schematic().Hierarchy();
2443 SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
2444 wxFileName destFn = pasteRoot.Last()->GetFileName();
2445
2446 if( destFn.IsRelative() )
2447 destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
2448
2449 // List of paths in the hierarchy that refer to the destination sheet of the paste
2450 SCH_SHEET_LIST sheetPathsForScreen = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
2451 sheetPathsForScreen.SortByPageNumbers();
2452
2453 // Build a list of screens from the current design (to avoid loading sheets that already exist)
2454 std::map<wxString, SCH_SCREEN*> loadedScreens;
2455
2456 for( const SCH_SHEET_PATH& item : hierarchy )
2457 {
2458 if( item.LastScreen() )
2459 loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
2460 }
2461
2462 // Get set of sheet names in the current schematic to prevent duplicate sheet names on paste.
2463 std::set<wxString> existingSheetNames = pasteRoot.LastScreen()->GetSheetNames();
2464 std::set<wxString> existingSuffixes;
2465 std::set<wxString> composedSuffixes;
2466
2467 for( const SCH_SHEET_PATH& path : hierarchy )
2468 {
2469 const SCH_SHEET* sheet = path.Last();
2470
2471 composedSuffixes.insert( m_frame->Schematic().GetRefSuffix( path ) );
2472
2473 if( const SCH_FIELD* suffixField = sheet->GetField( FIELD_T::SHEET_REF_SUFFIX ) )
2474 {
2475 SCH_SHEET_PATH parentPath = path;
2476 parentPath.pop_back();
2477
2478 existingSuffixes.insert( suffixField->GetText() );
2479 existingSuffixes.insert( sheet->GetRefSuffix( parentPath ) );
2480 }
2481 }
2482
2483 // Build symbol list for reannotation of duplicates
2484 SCH_REFERENCE_LIST existingRefs;
2485 hierarchy.GetSymbols( existingRefs, SYMBOL_FILTER_ALL );
2486 existingRefs.SortByReferenceOnly();
2487
2488 std::set<wxString> existingRefsSet;
2489
2490 for( const SCH_REFERENCE& ref : existingRefs )
2491 existingRefsSet.insert( ref.GetRef() );
2492
2493 // Build UUID map for fetching last-resolved-properties
2494 std::unordered_map<KIID, EDA_ITEM*> itemMap;
2495 hierarchy.FillItemMap( itemMap );
2496
2497 // Keep track of pasted sheets and symbols for the different paths to the hierarchy.
2498 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
2499 std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
2500
2501 for( SCH_ITEM* item : tempScreen->Items() )
2502 {
2503 if( item->Type() == SCH_SHEET_T )
2504 sortedLoadedItems.push_back( item );
2505 else
2506 loadedItems.push_back( item );
2507 }
2508
2509 sort( sortedLoadedItems.begin(), sortedLoadedItems.end(),
2510 []( SCH_ITEM* firstItem, SCH_ITEM* secondItem )
2511 {
2512 SCH_SHEET* firstSheet = static_cast<SCH_SHEET*>( firstItem );
2513 SCH_SHEET* secondSheet = static_cast<SCH_SHEET*>( secondItem );
2514 return StrNumCmp( firstSheet->GetName(), secondSheet->GetName(), CMP_T::CASE_SENSITIVE ) < 0;
2515 } );
2516
2517
2518 for( SCH_ITEM* item : sortedLoadedItems )
2519 {
2520 loadedItems.push_back( item );
2521
2522 if( item->Type() == SCH_SHEET_T )
2523 {
2524 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
2525 wxFileName srcFn = sheet->GetFileName();
2526
2527 if( srcFn.IsRelative() )
2528 srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
2529
2530 SCH_SHEET_LIST sheetHierarchy( sheet );
2531
2532 if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
2533 {
2534 auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
2535 "was dropped because the destination already has "
2536 "the sheet or one of its subsheets as a parent." ),
2537 sheet->GetFileName() );
2538 DisplayError( m_frame, msg );
2539 loadedItems.pop_back();
2540 }
2541 }
2542 }
2543
2544 // Remove the references from our temporary screen to prevent freeing on the DTOR
2545 tempScreen->Clear( false );
2546
2547 for( EDA_ITEM* item : loadedItems )
2548 {
2549 KIID_PATH clipPath( wxT( "/" ) ); // clipboard is at root
2550
2551 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
2552
2553 wxCHECK2( schItem, continue );
2554
2555 if( schItem->IsConnectable() )
2556 schItem->SetConnectivityDirty();
2557
2558 // Clear lock state on paste to match PCB editor behavior
2559 schItem->SetLocked( false );
2560
2561 if( item->Type() == SCH_SYMBOL_T )
2562 {
2563 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2564
2565 SCH_SCREEN* currentScreen = m_frame->GetScreen();
2566
2567 wxCHECK2( currentScreen, continue );
2568
2569 const LIB_SYMBOL* source = ChoosePasteLibSymbol( tempScreen, currentScreen,
2570 symbol->GetSchSymbolLibraryName() );
2571
2572 if( source )
2573 symbol->SetLibSymbol( new LIB_SYMBOL( *source ) );
2574
2575 for( const LIB_ID& alternate : symbol->GetVariantSymbolOverrides() )
2576 {
2577 wxString key = alternate.Format().wx_str();
2578 auto it = tempScreen->GetLibSymbols().find( key );
2579
2580 if( it != tempScreen->GetLibSymbols().end() && it->second
2581 && !currentScreen->GetLibSymbols().contains( key ) )
2582 currentScreen->AddLibSymbol( key, it->second->Flatten() );
2583 }
2584
2585 // If the symbol is already in the schematic we have to always keep the annotations. The exception
2586 // is if the user has chosen to remove them.
2587 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
2588 {
2589 if( !existingRefsSet.contains( instance.m_Reference ) )
2590 {
2591 forceKeepAnnotations = !forceRemoveAnnotations;
2592 break;
2593 }
2594 }
2595
2596 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2597 updatePastedSymbol( symbol, sheetPath, clipPath, forceKeepAnnotations );
2598
2599 // Most modes will need new KIIDs for the symbol and its pins. However, if we are pasting
2600 // unique annotations, we need to check if the symbol is not already in the hierarchy. If we
2601 // don't already have a copy of the symbol, we just keep the existing KIID data as it is likely
2602 // the same symbol being moved around the schematic.
2603 bool needsNewKiid = ( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
2604
2605 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
2606 {
2607 if( existingRefsSet.contains( instance.m_Reference ) )
2608 {
2609 needsNewKiid = true;
2610 break;
2611 }
2612 }
2613
2614 if( needsNewKiid )
2615 {
2616 // Assign a new KIID
2617 const_cast<KIID&>( item->m_Uuid ) = KIID();
2618
2619 // Make sure pins get a new UUID
2621 {
2622 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2623 pin->SetConnectivityDirty();
2624 }
2625
2626 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2627 {
2628 // Ignore symbols from a non-existant library.
2629 if( source )
2630 {
2631 SCH_REFERENCE schReference( symbol, sheetPath );
2632 schReference.SetSheetNumber( sheetPath.GetPageNumberAsInt() );
2633 pastedSymbols[sheetPath].AddItem( schReference );
2634 }
2635 }
2636 }
2637 }
2638 else if( item->Type() == SCH_SHEET_T )
2639 {
2640 SCH_SHEET* sheet = (SCH_SHEET*) item;
2641 SCH_FIELD* nameField = sheet->GetField( FIELD_T::SHEET_NAME );
2642 wxString baseName = nameField->GetText();
2643 wxString candidateName = baseName;
2644 wxString number;
2645
2646 while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
2647 {
2648 number = baseName.Last() + number;
2649 baseName.RemoveLast();
2650 }
2651
2652 // Update hierarchy to include any other sheets we already added, avoiding
2653 // duplicate sheet names
2654 hierarchy = m_frame->Schematic().Hierarchy();
2655
2656 int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
2657
2658 while( existingSheetNames.count( candidateName ) )
2659 candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
2660
2661 nameField->SetText( candidateName );
2662 existingSheetNames.emplace( candidateName );
2663
2664 wxFileName fn = sheet->GetFileName();
2665 SCH_SCREEN* existingScreen = nullptr;
2666
2667 sheet->SetParent( pasteRoot.Last() );
2668 sheet->SetScreen( nullptr );
2669
2670 if( !fn.IsAbsolute() )
2671 {
2672 wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
2673 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS, currentSheetFileName.GetPath() );
2674 }
2675
2676 // Try to find the screen for the pasted sheet by several means
2677 if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ), &existingScreen ) )
2678 {
2679 if( loadedScreens.count( sheet->GetFileName() ) > 0 )
2680 existingScreen = loadedScreens.at( sheet->GetFileName() );
2681 else
2682 searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
2683 }
2684
2685 if( existingScreen )
2686 {
2687 sheet->SetScreen( existingScreen );
2688 }
2689 else
2690 {
2691 if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
2692 m_frame->InitSheet( sheet, sheet->GetFileName() );
2693 }
2694
2695 sheetsPasted = true;
2696
2697 // The non-const GetField would add a suffix field to every pasted sheet
2698 if( std::as_const( *sheet ).GetField( FIELD_T::SHEET_REF_SUFFIX ) )
2699 {
2700 SCH_FIELD* suffixField = sheet->GetField( FIELD_T::SHEET_REF_SUFFIX );
2701 wxString pastedSuffix = suffixField->GetText();
2702 SCH_SHEET_LIST subtree( sheet );
2703
2704 // Suffixes concatenate, so the sheet or any child below it can compose to one in use
2705 auto composedBelowPaste =
2706 [&]()
2707 {
2708 std::vector<wxString> composed;
2709
2710 for( const SCH_SHEET_PATH& parentPath : sheetPathsForScreen )
2711 {
2712 for( const SCH_SHEET_PATH& subPath : subtree )
2713 {
2714 SCH_SHEET_PATH fullPath = parentPath;
2715
2716 for( size_t ii = 0; ii < subPath.size(); ++ii )
2717 fullPath.push_back( subPath.at( ii ) );
2718
2719 composed.push_back( fullPath.ComposeRefSuffix() );
2720 }
2721 }
2722
2723 return composed;
2724 };
2725
2726 auto resolvesTaken =
2727 [&]( const wxString& aCandidate )
2728 {
2729 suffixField->SetText( aCandidate );
2730
2731 for( const SCH_SHEET_PATH& parentPath : sheetPathsForScreen )
2732 {
2733 if( existingSuffixes.contains( sheet->GetRefSuffix( parentPath ) ) )
2734 return true;
2735 }
2736
2737 for( const wxString& composed : composedBelowPaste() )
2738 {
2739 if( composedSuffixes.contains( composed ) )
2740 return true;
2741 }
2742
2743 return false;
2744 };
2745
2746 if( m_frame->Schematic().Settings().m_IncrementPastedSuffix )
2747 pastedSuffix = SCH_SHEET::NextRefSuffix( pastedSuffix, existingSuffixes, resolvesTaken );
2748
2749 suffixField->SetText( pastedSuffix );
2750 existingSuffixes.insert( pastedSuffix );
2751
2752 for( const SCH_SHEET_PATH& parentPath : sheetPathsForScreen )
2753 existingSuffixes.insert( sheet->GetRefSuffix( parentPath ) );
2754
2755 for( const wxString& composed : composedBelowPaste() )
2756 composedSuffixes.insert( composed );
2757 }
2758
2759 // Push it to the clipboard path while it still has its old KIID
2760 clipPath.push_back( sheet->m_Uuid );
2761
2762 // Assign a new KIID to the pasted sheet
2763 const_cast<KIID&>( sheet->m_Uuid ) = KIID();
2764
2765 // Make sure pins get a new UUID
2766 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
2767 {
2768 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2769 pin->SetConnectivityDirty();
2770 }
2771
2772 // Once we have our new KIID we can update all pasted instances. This will either
2773 // reset the annotations or copy "kept" annotations from the supplementary clipboard.
2774 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2775 {
2776 SCH_SHEET_PATH subPath = updatePastedSheet( sheet, sheetPath, clipPath,
2777 ( forceKeepAnnotations && annotateAutomatic ),
2778 &pastedSheets[sheetPath], pastedSymbols );
2779 }
2780 }
2781 else
2782 {
2783 SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[item->m_Uuid] );
2784 SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
2785
2786 // Everything gets a new KIID
2787 const_cast<KIID&>( item->m_Uuid ) = KIID();
2788
2789 if( srcItem && destItem )
2790 {
2791 destItem->SetConnectivityDirty( true );
2792 destItem->SetLastResolvedState( srcItem );
2793 }
2794
2795 // Pasted named groups need a unique name, the multichannel tool matches groups by name.
2796 if( item->Type() == SCH_GROUP_T )
2797 {
2798 SCH_GROUP* group = static_cast<SCH_GROUP*>( item );
2799
2800 if( !group->GetName().IsEmpty() )
2801 group->SetName( UniqueGroupName( m_frame->GetScreen(), group->GetName() ) );
2802 }
2803 }
2804
2805 // Lines need both ends selected for a move after paste so the whole line moves.
2806 if( item->Type() == SCH_LINE_T )
2807 item->SetFlags( STARTPOINT | ENDPOINT );
2808
2809 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
2810
2811 if( !m_frame->GetScreen()->CheckIfOnDrawList( (SCH_ITEM*) item ) ) // don't want a loop!
2812 m_frame->AddToScreen( item, m_frame->GetScreen() );
2813
2814 commit.Added( (SCH_ITEM*) item, m_frame->GetScreen() );
2815
2816 // Start out hidden so the pasted items aren't "ghosted" in their original location
2817 // before being moved to the current location.
2818 getView()->Hide( item, true );
2819 }
2820
2821 if( sheetsPasted )
2822 {
2823 // The full schematic hierarchy need to be update before assigning new annotation and page numbers.
2824 m_frame->Schematic().RefreshHierarchy();
2825
2826 // Update sheet instance page and virtual page numbers to ensure annotation works correctly.
2827 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2828 {
2829 for( SCH_SHEET_PATH& pastedSheet : pastedSheets[sheetPath] )
2830 {
2831 // Find next free string page number for the sheet instance.
2832 int page = 1;
2833 wxString pageNum = wxString::Format( "%d", page );
2834
2835 while( hierarchy.PageNumberExists( pageNum ) )
2836 pageNum = wxString::Format( "%d", ++page );
2837
2838 int virtualPageNumber = page;
2839
2840 // The virtual page and sheet instance page numbers do not necessarily track. Increment by one
2841 // to ensure the annotation sheet paths all have unique virtual page numbers.
2842 if( page == hierarchy.GetLastVirtualPageNumber() )
2843 virtualPageNumber = hierarchy.GetLastVirtualPageNumber() + 1;
2844
2845 pastedSheet.SetVirtualPageNumber( virtualPageNumber );
2846
2847 SCH_SHEET_INSTANCE sheetInstance;
2848
2849 sheetInstance.m_Path = pastedSheet.Path();
2850
2851 // Don't include the actual sheet in the instance path.
2852 sheetInstance.m_Path.pop_back();
2853 sheetInstance.m_PageNumber = pageNum;
2854 sheetInstance.m_ProjectName = m_frame->Prj().GetProjectName();
2855
2856 SCH_SHEET* sheet = pastedSheet.Last();
2857
2858 wxCHECK2( sheet, continue );
2859
2860 sheet->AddInstance( sheetInstance );
2861 hierarchy.push_back( pastedSheet );
2862
2863 // Remove all pasted sheet instance data that is not part of the current project.
2864 std::vector<KIID_PATH> instancesToRemove;
2865
2866 for( const SCH_SHEET_INSTANCE& instance : sheet->GetInstances() )
2867 {
2868 if( !hierarchy.HasPath( instance.m_Path ) )
2869 instancesToRemove.push_back( instance.m_Path );
2870 }
2871
2872 for( const KIID_PATH& instancePath : instancesToRemove )
2873 sheet->RemoveInstance( instancePath );
2874
2875 // The sheet paths for the annotation code where copied in updatePastedSheets() when the virtual
2876 // page number was still 1. Set the virtual page number in the copied sheet paths.
2877 for( auto&[path, refs] : pastedSymbols )
2878 {
2879 for( SCH_REFERENCE& ref : refs )
2880 {
2881 if( ref.GetSheetPath() == pastedSheet )
2882 {
2883 ref.GetSheetPath().SetVirtualPageNumber( virtualPageNumber );
2884 ref.SetSheetNumber( virtualPageNumber );
2885 }
2886 }
2887 }
2888 }
2889 }
2890
2891 m_frame->SetSheetNumberAndCount();
2892
2893 // Get a version with correct sheet numbers since we've pasted sheets,
2894 // we'll need this when annotating next
2895 hierarchy = m_frame->Schematic().Hierarchy();
2896 }
2897
2898 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> annotatedSymbols;
2899
2900 // Update the list of symbol instances that satisfy the annotation criteria.
2901 for( const SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2902 {
2903 for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
2904 {
2905 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pastedSymbols[sheetPath][i].AlwaysAnnotate() )
2906 annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
2907 }
2908
2909 for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[sheetPath] )
2910 {
2911 for( size_t i = 0; i < pastedSymbols[pastedSheetPath].GetCount(); i++ )
2912 {
2913 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pastedSymbols[pastedSheetPath][i].AlwaysAnnotate() )
2914 annotatedSymbols[pastedSheetPath].AddItem( pastedSymbols[pastedSheetPath][i] );
2915 }
2916 }
2917 }
2918
2919 if( !annotatedSymbols.empty() )
2920 {
2921 ANNOTATE_ORDER_T annotateOrder = static_cast<ANNOTATE_ORDER_T>( schematicSettings.m_AnnotateSortOrder );
2922 ANNOTATE_ALGO_T annotateAlgo = static_cast<ANNOTATE_ALGO_T>( schematicSettings.m_AnnotateMethod );
2923
2924 for( SCH_SHEET_PATH& path : sheetPathsForScreen )
2925 {
2926 annotatedSymbols[path].SortByReferenceOnly();
2927 annotatedSymbols[path].SetRefDesTracker( schematicSettings.m_refDesTracker );
2928
2929 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
2930 {
2931 annotatedSymbols[path].ReannotateDuplicates( existingRefs, annotateAlgo );
2932 }
2933 else
2934 {
2935 annotatedSymbols[path].ReannotateByOptions( annotateOrder, annotateAlgo, annotateStartNum,
2936 existingRefs, false, &hierarchy );
2937 }
2938
2939 annotatedSymbols[path].UpdateAnnotation();
2940
2941 // Update existing refs for next iteration
2942 for( size_t i = 0; i < annotatedSymbols[path].GetCount(); i++ )
2943 existingRefs.AddItem( annotatedSymbols[path][i] );
2944
2945 for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[path] )
2946 {
2947 annotatedSymbols[pastedSheetPath].SortByReferenceOnly();
2948 annotatedSymbols[pastedSheetPath].SetRefDesTracker( schematicSettings.m_refDesTracker );
2949
2950 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
2951 {
2952 annotatedSymbols[pastedSheetPath].ReannotateDuplicates( existingRefs, annotateAlgo );
2953 }
2954 else
2955 {
2956 annotatedSymbols[pastedSheetPath].ReannotateByOptions( annotateOrder, annotateAlgo,
2957 annotateStartNum, existingRefs,
2958 false, &hierarchy );
2959 }
2960
2961 annotatedSymbols[pastedSheetPath].UpdateAnnotation();
2962
2963 // Update existing refs for next iteration
2964 for( size_t i = 0; i < annotatedSymbols[pastedSheetPath].GetCount(); i++ )
2965 existingRefs.AddItem( annotatedSymbols[pastedSheetPath][i] );
2966 }
2967 }
2968 }
2969
2970 m_frame->GetCurrentSheet().UpdateAllScreenReferences();
2971
2972 // The copy operation creates instance paths that are not valid for the current project or
2973 // saved as part of another project. Prune them now so they do not accumulate in the saved
2974 // schematic file.
2976
2977 SCH_SHEET_LIST sheets = m_frame->Schematic().Hierarchy();
2978 SCH_SCREENS allScreens( m_frame->Schematic().Root() );
2979
2980 allScreens.PruneOrphanedSymbolInstances( m_frame->Prj().GetProjectName(), sheets );
2981 allScreens.PruneOrphanedSheetInstances( m_frame->Prj().GetProjectName(), sheets );
2982
2983 // Unique paste needs the full annotator to share reused-sheet bases while keeping composed refs whole.
2984 // Keep-existing paste must retain its references even when they duplicate existing symbols.
2985 // Annotation resets the tools, so run it before the move setup.
2986 if( schematicSettings.m_AnnotateReusedSheetSuffixes && pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
2987 && !loadedItems.empty() )
2988 {
2989 SCH_GROUP* enteredGroup = selTool->GetEnteredGroup();
2990
2991 m_toolMgr->RunAction( ACTIONS::selectionClear );
2992 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &loadedItems );
2993 m_frame->AnnotateSymbols( &commit, ANNOTATE_SELECTION,
2994 static_cast<ANNOTATE_ORDER_T>( schematicSettings.m_AnnotateSortOrder ),
2995 static_cast<ANNOTATE_ALGO_T>( schematicSettings.m_AnnotateMethod ), true,
2996 schematicSettings.m_AnnotateStartNum, false, false, false,
2998
2999 // The reset also leaves the entered group, which the pasted items must join
3000 if( enteredGroup && !selTool->GetEnteredGroup() )
3001 {
3002 selTool->ClearSelection();
3003 selTool->AddItemToSel( enteredGroup );
3004 selTool->EnterGroup();
3005 }
3006 }
3007
3008 // Now clear the previous selection, select the pasted items, and fire up the "move" tool.
3009 m_toolMgr->RunAction( ACTIONS::selectionClear );
3010
3011 // If the item has a parent group, it will be part of the loadedItems, and will handle
3012 // the move action. Iterate backwards to avoid invalidating the iterator.
3013 for( int i = loadedItems.size() - 1; i >= 0; i-- )
3014 {
3015 EDA_ITEM* item = loadedItems[i];
3016
3017 if( item->GetParentGroup() )
3018 {
3019 loadedItems.erase( loadedItems.begin() + i );
3020 // These were hidden before because they would be added to the move preview,
3021 // but now they need to be shown as a preview so they appear to move when
3022 // the group moves.
3023 getView()->SetVisible( item );
3024 getView()->AddToPreview( item, false );
3025 }
3026 }
3027
3028 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &loadedItems );
3029
3030 SCH_SELECTION& selection = selTool->GetSelection();
3031
3032 if( !selection.Empty() )
3033 {
3034 if( aEvent.IsAction( &ACTIONS::duplicate ) )
3035 {
3036 int closest_dist = INT_MAX;
3037
3038 auto processPt =
3039 [&]( const VECTOR2I& pt )
3040 {
3041 int dist = ( eventPos - pt ).EuclideanNorm();
3042
3043 if( dist < closest_dist )
3044 {
3045 selection.SetReferencePoint( pt );
3046 closest_dist = dist;
3047 }
3048 };
3049
3050 std::vector<SCH_ITEM*> anchorCandidates = FlattenGroups( selection.Items() );
3051
3052 // Prefer connection points (which should remain on grid)
3053 for( EDA_ITEM* item : anchorCandidates )
3054 {
3055 SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
3056 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
3057
3058 if( sch_item && sch_item->IsConnectable() )
3059 {
3060 for( const VECTOR2I& pt : sch_item->GetConnectionPoints() )
3061 processPt( pt );
3062 }
3063 else if( pin )
3064 {
3065 processPt( pin->GetPosition() );
3066 }
3067
3068 // Symbols need to have their center point added since often users are trying to
3069 // move parts from their center.
3070 if( dynamic_cast<SCH_SYMBOL*>( item ) )
3071 processPt( item->GetPosition() );
3072 }
3073
3074 // Only process other points if we didn't find any connection points
3075 if( closest_dist == INT_MAX )
3076 {
3077 for( EDA_ITEM* item : anchorCandidates )
3078 {
3079 switch( item->Type() )
3080 {
3081 // A group's position is its bounding box centre, which is off grid
3082 case SCH_GROUP_T: break;
3083
3084 case SCH_LINE_T:
3085 processPt( static_cast<SCH_LINE*>( item )->GetStartPoint() );
3086 processPt( static_cast<SCH_LINE*>( item )->GetEndPoint() );
3087 break;
3088
3089 case SCH_SHAPE_T:
3090 {
3091 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
3092
3093 switch( shape->GetShape() )
3094 {
3095 case SHAPE_T::RECTANGLE:
3096 for( const VECTOR2I& pt : shape->GetRectCorners() )
3097 processPt( pt );
3098
3099 break;
3100
3101 case SHAPE_T::CIRCLE:
3102 processPt( shape->GetCenter() );
3103 break;
3104
3105 case SHAPE_T::POLY:
3106 for( int ii = 0; ii < shape->GetPolyShape().TotalVertices(); ++ii )
3107 processPt( shape->GetPolyShape().CVertex( ii ) );
3108
3109 break;
3110
3111 default:
3112 processPt( shape->GetStart() );
3113 processPt( shape->GetEnd() );
3114 break;
3115 }
3116
3117 break;
3118 }
3119
3120 default:
3121 processPt( item->GetPosition() );
3122 break;
3123 }
3124 }
3125 }
3126
3127 selection.SetIsHover( m_duplicateIsHoverSelection );
3128 }
3129 // We want to the first non-group item in the selection to be the reference point.
3130 else if( selection.GetTopLeftItem()->Type() == SCH_GROUP_T )
3131 {
3132 SCH_GROUP* group = static_cast<SCH_GROUP*>( selection.GetTopLeftItem() );
3133
3134 bool found = false;
3135 SCH_ITEM* item = nullptr;
3136
3137 group->RunOnChildren(
3138 [&]( SCH_ITEM* schItem )
3139 {
3140 if( !found && schItem->Type() != SCH_GROUP_T )
3141 {
3142 item = schItem;
3143 found = true;
3144 }
3145 },
3147
3148 if( found )
3149 selection.SetReferencePoint( item->GetPosition() );
3150 else
3151 selection.SetReferencePoint( group->GetPosition() );
3152 }
3153 else
3154 {
3155 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetTopLeftItem() );
3156
3157 selection.SetReferencePoint( item->GetPosition() );
3158 }
3159
3160 if( m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit ) )
3161 {
3162 // Pushing the commit will update the connectivity.
3163 commit.Push( _( "Paste" ) );
3164
3165 if( !sheetsPasted && !ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
3166 m_frame->RefreshNetNavigator();
3167 }
3168 else
3169 {
3170 commit.Revert();
3171 }
3172
3173 getView()->ClearPreview();
3174 }
3175
3176 return 0;
3177}
3178
3179
3181{
3182 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
3183 SCH_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
3184 SCH_SYMBOL* symbol = nullptr;
3185 SYMBOL_EDIT_FRAME* symbolEditor;
3186
3187 if( selection.GetSize() >= 1 )
3188 symbol = (SCH_SYMBOL*) selection.Front();
3189
3190 if( selection.IsHover() )
3191 m_toolMgr->RunAction( ACTIONS::selectionClear );
3192
3193 if( !symbol )
3194 {
3195 // Giant hack: by default we assign Edit Table to the same hotkey, so give the table
3196 // tool a chance to handle it if we can't.
3197 if( SCH_EDIT_TABLE_TOOL* tableTool = m_toolMgr->GetTool<SCH_EDIT_TABLE_TOOL>() )
3198 tableTool->EditTable( aEvent );
3199
3200 return 0;
3201 }
3202
3203 if( symbol->GetEditFlags() != 0 )
3204 return 0;
3205
3206 if( symbol->IsMissingLibSymbol() )
3207 {
3208 m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot be edited." ) );
3209 return 0;
3210 }
3211
3213 symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
3214
3215 if( symbolEditor )
3216 {
3217 if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
3218 blocking_win->Close( true );
3219
3220 if( aEvent.IsAction( &SCH_ACTIONS::editWithLibEdit ) )
3221 {
3222 symbolEditor->LoadSymbolFromSchematic( symbol );
3223 }
3225 {
3226 symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() );
3227
3228 if( !symbolEditor->IsLibraryTreeShown() )
3229 symbolEditor->ToggleLibraryTree();
3230 }
3231 }
3232
3233 return 0;
3234}
3235
3236
3238{
3239 m_frame->OnAnnotate();
3240 return 0;
3241}
3242
3243
3245{
3247 dlg.m_FirstRefDes->SetValidator( wxTextValidator( wxFILTER_EMPTY ) );
3248
3249 dlg.SetInitialFocus( dlg.m_FirstRefDes );
3250
3251 if( dlg.ShowModal() == wxID_OK )
3252 {
3253 SCH_REFERENCE startRef;
3254 startRef.SetRef( dlg.m_FirstRefDes->GetValue() );
3255
3256 if( startRef.IsSplitNeeded() )
3257 startRef.Split();
3258 else
3259 return 0;
3260
3261 int startNum = atoi( startRef.GetRefNumber().utf8_string().c_str() );
3262
3263 SCH_COMMIT commit( m_frame );
3264 SCHEMATIC* schematic = m_frame->m_schematic;
3265 SCH_REFERENCE_LIST references;
3266
3267 if( dlg.m_AllSheets->GetValue() )
3268 schematic->Hierarchy().GetSymbols( references, SYMBOL_FILTER_ALL );
3269 else
3270 schematic->CurrentSheet().GetSymbols( references, SYMBOL_FILTER_ALL );
3271
3272 references.SplitReferences();
3273
3274 for( SCH_REFERENCE& ref : references )
3275 {
3276 if( ref.GetRef() == startRef.GetRef() )
3277 {
3278 int num = atoi( ref.GetRefNumber().utf8_string().c_str() );
3279
3280 if( num >= startNum )
3281 {
3282 const SCH_SHEET_PATH& sheet = ref.GetSheetPath();
3283 wxString fullRef = ref.GetRef();
3284
3285 num += dlg.m_Increment->GetValue();
3286 fullRef << num;
3287
3288 commit.Modify( ref.GetSymbol(), sheet.LastScreen(), RECURSE_MODE::NO_RECURSE );
3289 ref.GetSymbol()->SetUserRef( sheet, From_UTF8( fullRef.c_str() ) );
3290 }
3291 }
3292 }
3293
3294 if( !commit.Empty() )
3295 commit.Push( _( "Increment Annotations" ) );
3296 }
3297
3298 return 0;
3299}
3300
3301
3303{
3304 m_frame->OnOpenCvpcb();
3305 return 0;
3306}
3307
3308
3310{
3311 m_frame->OnImportProject();
3312 return 0;
3313}
3314
3315
3317{
3318 DIALOG_SYMBOL_FIELDS_TABLE* dlg = m_frame->GetSymbolFieldsTableDialog();
3319
3320 if( !dlg )
3321 return 0;
3322
3323 // Needed at least on Windows. Raise() is not enough
3324 dlg->Show( true );
3325
3326 // Bring it to the top if already open. Dual monitor users need this.
3327 dlg->Raise();
3328
3329 dlg->ShowEditTab();
3330
3331 return 0;
3332}
3333
3334
3336{
3337 if( !m_frame->Schematic().GetCurrentVariant().IsEmpty() )
3338 {
3340 _( "Bulk Edit Symbol Library Links is not available when a design variant is "
3341 "active. Switch to the default variant first." ) );
3342 return 0;
3343 }
3344
3346 m_frame->HardRedraw();
3347
3348 return 0;
3349}
3350
3351
3353{
3354 m_frame->OnOpenPcbnew();
3355 return 0;
3356}
3357
3358
3360{
3361 m_frame->OnUpdatePCB();
3362 return 0;
3363}
3364
3365
3367{
3369 dlg.ShowModal();
3370 return 0;
3371}
3372
3373
3375{
3377
3378 // If a plugin is removed or added, rebuild and reopen the new dialog
3379 while( result == NET_PLUGIN_CHANGE )
3381
3382 return 0;
3383}
3384
3385
3387{
3388 DIALOG_SYMBOL_FIELDS_TABLE* dlg = m_frame->GetSymbolFieldsTableDialog();
3389
3390 if( !dlg )
3391 return 0;
3392
3393 // Needed at least on Windows. Raise() is not enough
3394 dlg->Show( true );
3395
3396 // Bring it to the top if already open. Dual monitor users need this.
3397 dlg->Raise();
3398
3399 dlg->ShowExportTab();
3400
3401 return 0;
3402}
3403
3404
3406{
3408 return 0;
3409}
3410
3411
3413{
3414 m_frame->RecalculateConnections( nullptr, LOCAL_CLEANUP );
3415
3416 // Create a selection with all items from the current sheet
3417 SCH_SELECTION sheetSelection;
3418 SCH_SCREEN* screen = m_frame->GetScreen();
3419
3420 for( SCH_ITEM* item : screen->Items() )
3421 {
3422 sheetSelection.Add( item );
3423 }
3424
3425 // Get the full page bounding box for rendering the complete sheet
3426 BOX2I pageBBox( VECTOR2I( 0, 0 ), m_frame->GetPageSizeIU() );
3427
3428 // Render the full sheet selection including the worksheet
3429 wxImage image = renderSelectionToImageForClipboard( m_frame, sheetSelection, pageBBox, true, true );
3430
3431 if( image.IsOk() )
3432 {
3433 wxLogNull doNotLog; // disable logging of failed clipboard actions
3434
3435 if( wxTheClipboard->Open() )
3436 {
3437 wxDataObjectComposite* data = new wxDataObjectComposite();
3438
3440
3441 wxTheClipboard->SetData( data );
3442 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
3443 wxTheClipboard->Close();
3444 }
3445 }
3446 else
3447 {
3448 wxLogMessage( _( "Cannot create the schematic image" ) );
3449 }
3450
3451 return 0;
3452}
3453
3454
3456{
3458 return 0;
3459}
3460
3461
3467
3468
3474
3475
3481
3482
3488
3489
3495
3496
3502
3503
3505{
3506 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3508
3510 m_frame->GetCanvas()->Refresh();
3511
3512 return 0;
3513}
3514
3515
3517{
3518 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3520
3521 m_frame->GetRenderSettings()->m_ShowHiddenFields = cfg->m_Appearance.show_hidden_fields;
3522
3524 m_frame->GetCanvas()->Refresh();
3525
3526 return 0;
3527}
3528
3529
3531{
3532 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3534
3536 m_frame->GetCanvas()->Refresh();
3537
3538 return 0;
3539}
3540
3541
3543{
3544 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3546
3548 m_frame->GetCanvas()->Refresh();
3549
3550 return 0;
3551}
3552
3553
3555{
3556 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3558
3560 m_frame->GetCanvas()->Refresh();
3561
3562 return 0;
3563}
3564
3565
3567{
3568 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3570
3571 m_frame->GetCanvas()->Refresh();
3572
3573 return 0;
3574}
3575
3576
3578{
3579 SCH_SHEET_PATH* sheetPath = &m_frame->GetCurrentSheet();
3580 wxString variant = m_frame->Schematic().GetCurrentVariant();
3581 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3583
3584 m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally(
3585 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
3586 {
3587 int flags = 0;
3588
3589 auto invalidateTextVars =
3590 [&flags]( EDA_TEXT* text )
3591 {
3592 if( text->HasTextVars() )
3593 {
3594 text->ClearRenderCache();
3595 text->ClearBoundingBoxCache();
3597 }
3598 };
3599
3600 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
3601 {
3602 item->RunOnChildren(
3603 [&invalidateTextVars]( SCH_ITEM* aChild )
3604 {
3605 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
3606 invalidateTextVars( text );
3607 },
3609
3610 if( item->GetExcludedFromSim( sheetPath, variant ) )
3612 }
3613
3614 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
3615 invalidateTextVars( text );
3616
3617 return flags;
3618 } );
3619
3620 m_frame->GetCanvas()->Refresh();
3621
3622 return 0;
3623}
3624
3625
3627{
3628 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3630
3632 m_frame->RefreshOperatingPointDisplay();
3633 m_frame->GetCanvas()->Refresh();
3634
3635 return 0;
3636}
3637
3638
3640{
3641 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3643
3645 m_frame->RefreshOperatingPointDisplay();
3646 m_frame->GetCanvas()->Refresh();
3647
3648 return 0;
3649}
3650
3651
3653{
3654 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3656
3657 m_frame->GetRenderSettings()->m_ShowPinAltIcons = cfg->m_Appearance.show_pin_alt_icons;
3658
3660 m_frame->GetCanvas()->Refresh();
3661
3662 return 0;
3663}
3664
3665
3667{
3668 m_frame->eeconfig()->m_Drawing.line_mode = aEvent.Parameter<LINE_MODE>();
3669 m_toolMgr->PostAction( ACTIONS::refreshPreview );
3670 // Notify toolbar to update selection
3672 return 0;
3673}
3674
3675
3677{
3678 m_frame->eeconfig()->m_Drawing.line_mode++;
3679 m_frame->eeconfig()->m_Drawing.line_mode %= LINE_MODE::LINE_MODE_COUNT;
3680 m_toolMgr->PostAction( ACTIONS::refreshPreview );
3681 // Notify toolbar to update selection
3683 return 0;
3684}
3685
3686
3688{
3689 EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
3691 return 0;
3692}
3693
3694
3696{
3697 // Update the left toolbar Line modes group icon to match current mode
3698 switch( static_cast<LINE_MODE>( m_frame->eeconfig()->m_Drawing.line_mode ) )
3699 {
3700 case LINE_MODE::LINE_MODE_FREE: m_frame->SelectToolbarAction( SCH_ACTIONS::lineModeFree ); break;
3701 case LINE_MODE::LINE_MODE_90: m_frame->SelectToolbarAction( SCH_ACTIONS::lineMode90 ); break;
3702 default:
3703 case LINE_MODE::LINE_MODE_45: m_frame->SelectToolbarAction( SCH_ACTIONS::lineMode45 ); break;
3704 }
3705
3706 return 0;
3707}
3708
3709
3711{
3712 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
3713 return 0;
3714
3715 GRID_SETTINGS& gridSettings = m_toolMgr->GetSettings()->m_Window.grid;
3716 int currentIdx = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
3717
3718 wxArrayString gridsLabels;
3719
3720 for( const GRID& grid : gridSettings.grids )
3721 gridsLabels.Add( grid.UserUnitsMessageText( m_frame ) );
3722
3723 if( !m_frame->GetHotkeyPopup() )
3724 m_frame->CreateHotkeyPopup();
3725
3726 HOTKEY_CYCLE_POPUP* popup = m_frame->GetHotkeyPopup();
3727
3728 if( popup )
3729 popup->Popup( _( "Grid" ), gridsLabels, currentIdx );
3730
3731 return 0;
3732}
3733
3734
3736{
3737 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3738
3739 if( !editFrame )
3740 return 1;
3741
3742 // Need to have a group selected and it needs to have a linked design block
3743 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
3744 SCH_SELECTION selection = selTool->GetSelection();
3745
3746 if( selection.Size() != 1 || selection[0]->Type() != SCH_GROUP_T )
3747 return 1;
3748
3749 SCH_GROUP* group = static_cast<SCH_GROUP*>( selection[0] );
3750
3751 if( !group->HasDesignBlockLink() )
3752 return 1;
3753
3754 // Get the associated design block
3755 DESIGN_BLOCK_PANE* designBlockPane = editFrame->GetDesignBlockPane();
3756 std::unique_ptr<DESIGN_BLOCK> designBlock( designBlockPane->GetDesignBlock( group->GetDesignBlockLibId(),
3757 true, true ) );
3758
3759 if( !designBlock )
3760 return 1;
3761
3762 if( designBlock->GetSchematicFile().IsEmpty() )
3763 {
3764 wxString msg;
3765 msg.Printf( _( "Design block %s does not have a schematic file." ),
3766 group->GetDesignBlockLibId().GetUniStringLibId() );
3767 m_frame->GetInfoBar()->ShowMessageFor( msg, 5000, wxICON_WARNING );
3768 return 1;
3769 }
3770
3771 editFrame->GetDesignBlockPane()->SelectLibId( group->GetDesignBlockLibId() );
3772
3773 return m_toolMgr->RunAction( SCH_ACTIONS::placeDesignBlock, designBlock.release() );
3774}
3775
3776
3778{
3779 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3780
3781 if( !editFrame )
3782 return 1;
3783
3784 // Need to have a group selected and it needs to have a linked design block
3785 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
3786 SCH_SELECTION selection = selTool->GetSelection();
3787
3788 if( selection.Size() != 1 || selection[0]->Type() != SCH_GROUP_T )
3789 return 1;
3790
3791 SCH_GROUP* group = static_cast<SCH_GROUP*>( selection[0] );
3792
3793 if( !group->HasDesignBlockLink() )
3794 return 1;
3795
3796 // Get the associated design block
3797 DESIGN_BLOCK_PANE* designBlockPane = editFrame->GetDesignBlockPane();
3798 std::unique_ptr<DESIGN_BLOCK> designBlock( designBlockPane->GetDesignBlock( group->GetDesignBlockLibId(),
3799 true, true ) );
3800
3801 if( !designBlock )
3802 return 1;
3803
3804 editFrame->GetDesignBlockPane()->SelectLibId( group->GetDesignBlockLibId() );
3805
3806 return m_toolMgr->RunAction( SCH_ACTIONS::updateDesignBlockFromSelection ) ? 1 : 0;
3807}
3808
3809
3811{
3812 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3813
3814 if( !editFrame )
3815 return 1;
3816
3817 editFrame->AddVariant();
3818
3819 return 0;
3820}
3821
3822
3824{
3825 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3826
3827 if( !editFrame )
3828 return 1;
3829
3830 editFrame->RemoveVariant();
3831 return 0;
3832}
3833
3834
3836{
3837 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3838
3839 if( !editFrame )
3840 return 1;
3841
3842 editFrame->EditVariantDescription();
3843 return 0;
3844}
3845
3846
3848{
3849 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3850
3851 if( !editFrame )
3852 return 1;
3853
3854 editFrame->RenameVariant();
3855 return 0;
3856}
3857
3858
3860{
3861 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
3862
3863 if( !editFrame )
3864 return 1;
3865
3866 editFrame->CopyVariant();
3867 return 0;
3868}
3869
3870
3872{
3873 Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
3874 Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
3875 Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
3882 Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
3883
3886
3892
3895
3907
3910
3911 Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
3912 Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
3913 Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
3914 Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
3919
3921
3938
3947
3964
3967
3970
3976}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
static TOOL_ACTION updatePcbFromSchematic
Definition actions.h:261
static TOOL_ACTION paste
Definition actions.h:77
static TOOL_ACTION revert
Definition actions.h:58
static TOOL_ACTION saveAs
Definition actions.h:55
static TOOL_ACTION exportForOlderVersion
Definition actions.h:60
static TOOL_ACTION copy
Definition actions.h:75
static TOOL_ACTION pickerTool
Definition actions.h:250
static TOOL_ACTION showSymbolEditor
Definition actions.h:257
static TOOL_ACTION pasteSpecial
Definition actions.h:78
static TOOL_ACTION plot
Definition actions.h:62
static TOOL_ACTION open
Definition actions.h:53
static TOOL_ACTION pageSettings
Definition actions.h:59
static TOOL_ACTION showSearch
Definition actions.h:113
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition actions.h:211
static TOOL_ACTION duplicate
Definition actions.h:81
static TOOL_ACTION showGitCommitPane
Definition actions.h:264
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION save
Definition actions.h:54
static TOOL_ACTION redo
Definition actions.h:73
static TOOL_ACTION updateSchematicFromPcb
Definition actions.h:262
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION print
Definition actions.h:61
static TOOL_ACTION showProperties
Definition actions.h:263
static TOOL_ACTION doNew
Definition actions.h:50
static TOOL_ACTION cut
Definition actions.h:74
static TOOL_ACTION copyAsText
Definition actions.h:76
static TOOL_ACTION refreshPreview
Definition actions.h:156
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:229
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
int GetPageCount() const
Definition base_screen.h:68
int GetVirtualPageNumber() const
Definition base_screen.h:71
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition base_screen.h:81
const wxString & GetPageNumber() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr Vec Centre() const
Definition box2.h:100
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr const SizeVec & GetSize() const
Definition box2.h:209
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
int m_Threshold
Definition collector.h:234
static const COLOR4D CLEAR
Definition color4d.h:405
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:80
bool Empty() const
Definition commit.h:145
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
static PRIORITY GetDriverPriority(SCH_ITEM *aDriver)
Return the priority (higher is more important) of a candidate driver.
void SelectLibId(const LIB_ID &aLibId)
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg, wxString *aErrorMsg=nullptr)
Load design block from design block library table.
Class DIALOG_INCREMENT_ANNOTATIONS_BASE.
void SetWksFileName(const wxString &aFilename)
bool Show(bool show) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:95
int ShowModal() override
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:170
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:214
void SetNetHighlighted(bool aHighlighted)
Definition eda_item.cpp:131
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:288
bool IsNetHighlighted() const
Net highlighting must not clear brightening owned by find or picker tools.
Definition eda_item.cpp:125
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
SHAPE_POLY_SET & GetPolyShape()
SHAPE_T GetShape() const
Definition eda_shape.h:178
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
std::vector< VECTOR2I > GetRectCorners() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual bool IsVisible() const
Definition eda_text.h:226
bool validatePasteIntoSelection(const SELECTION &aSel, wxString &aErrorMsg)
Validate if paste-into-cells is possible for the given selection.
bool pasteCellsIntoSelection(const SELECTION &aSel, T_TABLE *aSourceTable, T_COMMIT &aCommit)
Paste text content from source table into selected cells.
PANEL_ANNOTATE m_AnnotatePanel
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
static const TOOL_EVENT ClearedEvent
Definition actions.h:349
static const TOOL_EVENT GridChangedByKeyEvent
Used for hotkey feedback.
Definition actions.h:367
static const TOOL_EVENT SelectedEvent
Definition actions.h:347
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:354
static const TOOL_EVENT PointSelectedEvent
Definition actions.h:346
static const TOOL_EVENT UnselectedEvent
Definition actions.h:348
Similar to EDA_VIEW_SWITCHER, this dialog is a popup that shows feedback when using a hotkey to cycle...
void Popup(const wxString &aTitle, const wxArrayString &aItems, int aSelection)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
std::vector< wxString > m_foundVariants
Variant names found in the schematic when the target drops variants.
wxString m_outputDir
Write downgraded sheets under this fresh folder.
wxString m_variant
Flatten this variant into the export. Empty means the base design.
wxString m_filename
Root schematic file (may be empty to downgrade only libraries)
static std::unique_ptr< CAIRO_PRINT_GAL > Create(GAL_DISPLAY_OPTIONS &aOptions, wxImage *aImage, double aDPI)
GAL_ANTIALIASING_MODE antialiasing_mode
virtual bool HasNativeLandscapeRotation() const =0
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
void SetDefaultFont(const wxString &aFont)
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetIsPrinting(bool isPrinting)
An interface for classes handling user events controlling the view behavior such as zooming,...
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:431
void ClearPreview()
Definition view.cpp:2718
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:899
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:2474
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:2575
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
Definition view.cpp:2740
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition view.cpp:2551
bool EndsWith(const KIID_PATH &aPath) const
Test if aPath from the last path towards the first path.
Definition kiid.cpp:402
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
wxString AsString() const
Definition kiid.cpp:264
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition kiway.cpp:705
@ FACE_SCH
eeschema DSO
Definition kiway.h:355
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const wxString & Type() const
const wxString & Nickname() const
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:113
Define a library symbol object.
Definition lib_symbol.h:114
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:190
bool IsPower() const override
void AppendParentEmbeddedFiles(std::vector< EMBEDDED_FILES * > &aStack) const
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
static void ConvertToSpiceMarkup(wxString *aNetName)
Convert an escaped schematic net name to SPICE, preserving literal slashes when mapping ground names.
Tree view item data for the net navigator.
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList, size_t *aPrefixEnd=nullptr)
Parse a bus group label into the name and a list of components.
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
static REPORTER & GetInstance()
Definition reporter.cpp:207
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition picker_tool.h:92
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition picker_tool.h:81
void SetSnapping(bool aSnap)
Definition picker_tool.h:65
void SetCursor(KICURSOR aCursor)
Definition picker_tool.h:63
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
size_t GetCandidateCount()
Return the number of rescue candidates found.
These are loaded from Eeschema settings but then overwritten by the project settings.
double GetHopOverScale()
Accessor that computes the current hop-over size.
std::shared_ptr< REFDES_TRACKER > m_refDesTracker
A list of previously used schematic reference designators.
Holds all the data relating to one schematic.
Definition schematic.h:155
SCH_CONNECTIVITY::NETCHAIN_MANAGER & NetChains() const
Definition schematic.h:412
wxString GetVariantDescription(const wxString &aVariantName) const
Return the description for a variant.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:177
wxString GetCurrentVariant() const
Return the current variant being edited.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:180
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
static TOOL_ACTION showPcbNew
static TOOL_ACTION createNetChain
static TOOL_ACTION assignFootprints
static TOOL_ACTION copyVariant
static TOOL_ACTION lineModeNext
static TOOL_ACTION toggleOPCurrents
static TOOL_ACTION saveToLinkedDesignBlock
Definition sch_actions.h:77
static TOOL_ACTION clearHighlight
static TOOL_ACTION removeVariant
static TOOL_ACTION editSymbolFields
static TOOL_ACTION importFPAssignments
static TOOL_ACTION toggleAnnotateAuto
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION toggleERCWarnings
static TOOL_ACTION editVariantDescription
static TOOL_ACTION schematicSetup
static TOOL_ACTION toggleDirectiveLabels
static TOOL_ACTION highlightNetTool
static TOOL_ACTION removeFromNetChain
static TOOL_ACTION findNetInInspector
static TOOL_ACTION toggleHiddenFields
static TOOL_ACTION saveCurrSheetCopyAs
Definition sch_actions.h:49
static TOOL_ACTION showRemoteSymbolPanel
static TOOL_ACTION remapSymbols
static TOOL_ACTION lineMode45
static TOOL_ACTION editSymbolLibraryLinks
static TOOL_ACTION simTune
static TOOL_ACTION generateBOM
static TOOL_ACTION showHierarchy
static TOOL_ACTION highlightNetChain
static TOOL_ACTION showNetNavigator
static TOOL_ACTION markSimExclusions
static TOOL_ACTION placeImage
static TOOL_ACTION editWithLibEdit
static TOOL_ACTION toggleERCErrors
static TOOL_ACTION incrementAnnotations
static TOOL_ACTION rescueSymbols
static TOOL_ACTION angleSnapModeChanged
static TOOL_ACTION placeLinkedDesignBlock
Definition sch_actions.h:76
static TOOL_ACTION generateBOMLegacy
static TOOL_ACTION placeDesignBlock
Definition sch_actions.h:75
static TOOL_ACTION toggleOPVoltages
static TOOL_ACTION simProbe
static TOOL_ACTION lineMode90
static TOOL_ACTION lineModeFree
static TOOL_ACTION highlightNet
static TOOL_ACTION assignNetclass
static TOOL_ACTION annotate
static TOOL_ACTION showDesignBlockPanel
static TOOL_ACTION updateDesignBlockFromSelection
static TOOL_ACTION replaceTerminalPin
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION toggleERCExclusions
static TOOL_ACTION updateNetHighlighting
static TOOL_ACTION renameVariant
static TOOL_ACTION createNetChainBetweenPins
static TOOL_ACTION exportNetlist
static TOOL_ACTION drawSheetOnClipboard
static TOOL_ACTION exportSymbolsToLibrary
static TOOL_ACTION toggleHiddenPins
static TOOL_ACTION selectOnPCB
static TOOL_ACTION addVariant
static TOOL_ACTION move
static TOOL_ACTION importNonKicadSchematic
static TOOL_ACTION nameNetChain
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Base class for a bus or wire entry.
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aBodyStyle=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
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).
One UI operation's hierarchy index.
void CollectNetItems(const wxString &aName, const SCH_SHEET_PATH &aSheet, std::unordered_set< SCH_ITEM * > &aItems, bool aIncludeBusParents=false, bool aIncludeBusMembers=false) const
bool ReplaceNetChainTerminalPin(const TERMINAL_CHANGE &aChange)
static wxString NetKeyForItem(const SCH_ITEM &aItem, const SCH_SHEET_PATH &aPath)
bool NetChainsBuilt() const
Returns true once RebuildNetChains() has completed at least once on this graph.
Handle actions specific to the schematic editor.
int PageSetup(const TOOL_EVENT &aEvent)
bool RescueLegacyProject(bool aRunningOnDemand)
int ToggleDirectiveLabels(const TOOL_EVENT &aEvent)
int SaveAs(const TOOL_EVENT &aEvent)
int MarkSimExclusions(const TOOL_EVENT &aEvent)
int Annotate(const TOOL_EVENT &aEvent)
int ShowSchematicSetup(const TOOL_EVENT &aEvent)
int HighlightNet(const TOOL_EVENT &aEvent)
Highlight net under the cursor.
int ClearHighlight(const TOOL_EVENT &aEvent)
Remove any net highlighting.
int FindNetInInspector(const TOOL_EVENT &aEvent)
int EditSymbolFields(const TOOL_EVENT &aEvent)
int GenerateBOMLegacy(const TOOL_EVENT &aEvent)
int RemoveFromNetChain(const TOOL_EVENT &aEvent)
int HighlightNetCursor(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
int CopyAsText(const TOOL_EVENT &aEvent)
int AddVariant(const TOOL_EVENT &aEvent)
int ImportFPAssignments(const TOOL_EVENT &aEvent)
int ChangeLineMode(const TOOL_EVENT &aEvent)
void doCrossProbeSchToPcb(const TOOL_EVENT &aEvent, bool aForce)
int ExportSymbolsToLibrary(const TOOL_EVENT &aEvent)
int SaveCurrSheetCopyAs(const TOOL_EVENT &aEvent)
Saves the currently-open schematic sheet to an other name.
bool rescueProject(RESCUER &aRescuer, bool aRunningOnDemand)
int CrossProbeToPcb(const TOOL_EVENT &aEvent)
Notifies pcbnew about the selected item.
void SetHighlightBusMembers(bool aHighlightBusMembers)
int CopyVariant(const TOOL_EVENT &aEvent)
int PlaceLinkedDesignBlock(const TOOL_EVENT &aEvent)
int ToggleRemoteSymbolPanel(const TOOL_EVENT &aEvent)
int RemapSymbols(const TOOL_EVENT &aEvent)
int DrawSheetOnClipboard(const TOOL_EVENT &aEvent)
SCH_SHEET_PATH updatePastedSheet(SCH_SHEET *aSheet, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations, SCH_SHEET_LIST *aPastedSheets, std::map< SCH_SHEET_PATH, SCH_REFERENCE_LIST > &aPastedSymbols)
int TogglePinAltIcons(const TOOL_EVENT &aEvent)
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
int AssignNetclass(const TOOL_EVENT &aEvent)
std::string m_duplicateClipboard
int ExportNetlist(const TOOL_EVENT &aEvent)
int Open(const TOOL_EVENT &aEvent)
int Paste(const TOOL_EVENT &aEvent)
int ToggleOPVoltages(const TOOL_EVENT &aEvent)
int Copy(const TOOL_EVENT &aEvent)
int SaveToLinkedDesignBlock(const TOOL_EVENT &aEvent)
int ToggleERCWarnings(const TOOL_EVENT &aEvent)
int NextLineMode(const TOOL_EVENT &aEvent)
int Redo(const TOOL_EVENT &aEvent)
int UpdatePCB(const TOOL_EVENT &aEvent)
int RemoveVariant(const TOOL_EVENT &aEvent)
int UpdateFromPCB(const TOOL_EVENT &aEvent)
int ToggleAnnotateAuto(const TOOL_EVENT &aEvent)
int EditVariantDescription(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
int Duplicate(const TOOL_EVENT &aEvent)
int IncrementAnnotations(const TOOL_EVENT &aEvent)
bool searchSupplementaryClipboard(const wxString &aSheetFilename, SCH_SCREEN **aScreen)
int GridFeedback(const TOOL_EVENT &aEvent)
int ShowSearch(const TOOL_EVENT &aEvent)
int EditWithSymbolEditor(const TOOL_EVENT &aEvent)
int ReplaceTerminalPin(const TOOL_EVENT &aEvent)
Replace one of a net chain's terminal pins.
int SimTune(const TOOL_EVENT &aEvent)
int EditSymbolLibraryLinks(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
int ImportNonKicadSchematic(const TOOL_EVENT &aEvent)
int ShowCreateNetChain(const TOOL_EVENT &aEvent)
std::map< wxString, SCH_SCREEN * > m_supplementaryClipboard
int ExplicitCrossProbeToPcb(const TOOL_EVENT &aEvent)
Equivalent to the above, but initiated by the user.
int ToggleOPCurrents(const TOOL_EVENT &aEvent)
int ShowPcbNew(const TOOL_EVENT &aEvent)
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Update net highlighting after an edit.
int ToggleERCErrors(const TOOL_EVENT &aEvent)
int ShowHierarchy(const TOOL_EVENT &aEvent)
int OnAngleSnapModeChanged(const TOOL_EVENT &aEvent)
void setTransitions() override
Set up handlers for various events.
static const LIB_SYMBOL * ChoosePasteLibSymbol(const SCH_SCREEN *aClipboardScreen, const SCH_SCREEN *aDestScreen, const wxString &aLibSymbolName)
Choose which cached library symbol a pasted instance should adopt.
int ExportForOlderVersion(const TOOL_EVENT &aEvent)
int ShowNetNavigator(const TOOL_EVENT &aEvent)
int NameNetChain(const TOOL_EVENT &aEvent)
int SimProbe(const TOOL_EVENT &aEvent)
void updatePastedSymbol(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
int ShowCvpcb(const TOOL_EVENT &aEvent)
int HighlightNetChain(const TOOL_EVENT &aEvent)
Highlight net chain under the cursor.
int ToggleLibraryTree(const TOOL_EVENT &aEvent)
int RenameVariant(const TOOL_EVENT &aEvent)
std::set< SCH_SYMBOL * > m_pastedSymbols
void prunePastedSymbolInstances()
Reconcile every pasted symbol's instances against the current project.
int Cut(const TOOL_EVENT &aEvent)
Clipboard support.
int ToggleProperties(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvent)
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
bool doCopy(bool aUseDuplicateClipboard=false)
copy selection to clipboard or to m_duplicateClipboard
int Undo(const TOOL_EVENT &aEvent)
int ToggleERCExclusions(const TOOL_EVENT &aEvent)
int ToggleGitCommitPane(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
int CreateNetChainBetweenPins(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int GenerateBOM(const TOOL_EVENT &aEvent)
int ToggleHiddenFields(const TOOL_EVENT &aEvent)
Schematic editor (Eeschema) main window.
void ToggleProperties() override
SCH_DESIGN_BLOCK_PANE * GetDesignBlockPane() const
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void ToggleLibraryTree() override
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
void SendCrossProbeClearHighlight()
Tell Pcbnew to clear the existing highlighted net, if one exists.
SCH_SHEET_PATH & GetCurrentSheet() const
const SCH_ITEM * GetSelectedNetNavigatorItem() const
SCHEMATIC & Schematic() const
void ToggleSearch()
Toggle the show/hide state of Search pane.
wxString GetFullScreenDesc() const override
const wxString & GetHighlightedNetChain() const
void ToggleSchematicHierarchy()
Toggle the show/hide state of the left side schematic navigation panel.
void SetHighlightedConnection(const wxString &aConnection, const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr, bool aForceNetNavigatorRefresh=false)
void SetHighlightedNetChain(const wxString &aNetChain)
void SetCrossProbeConnection(const wxString &aName)
Send a connection (net or bus) to Pcbnew for highlighting.
const wxString & GetHighlightedConnection() const
void UpdateNetHighlightStatus()
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
void SelectNetNavigatorItem(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
void SetText(const wxString &aText) override
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void Format(SCH_SHEET *aSheet)
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the file type from the corresponding plugin type name: "kicad", "legacy", etc.
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
void SetLocked(bool aLocked) override
Definition sch_item.h:262
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:350
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition sch_item.h:671
int GetBodyStyle() const
Definition sch_item.h:253
int GetUnit() const
Definition sch_item.h:243
void SetConnectivityDirty(bool aDirty=true)
Set the dirty flag.
Definition sch_item.cpp:314
bool IsConnectivityDirty() const
Definition sch_item.h:635
std::optional< wxString > GetConnectionName(const SCH_SHEET_PATH *aSheet=nullptr, bool aLocal=false, bool aIgnoreSheet=false) const
Return the active connection name; absent for missing or stale published rows.
Definition sch_item.cpp:629
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 HasBusConnection(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:720
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition sch_item.h:563
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
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
A net chain is a collection of nets that are connected together through passive components.
const std::set< wxString > & GetNets() const
const wxString & GetName() const
static bool IsValidName(const wxString &aName)
SCH_PIN * GetLibPin() const
Definition sch_pin.h:109
const wxString & GetNumber() const
Definition sch_pin.h:144
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_pin.h:280
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 SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetRef(const wxString &aReference)
void Split()
Attempt to split the reference designator into a name (U) and number (1).
wxString GetRef() const
bool IsSplitNeeded() const
Determine if this reference needs to be split or if it likely already has been.
void SetSheetNumber(int aSheetNumber)
wxString GetRefNumber() const
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
void LoadColors(const COLOR_SETTINGS *aSettings) override
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:826
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
void PruneOrphanedSheetInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
void PruneOrphanedSymbolInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:144
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void AddLibSymbol(LIB_SYMBOL *aLibSymbol)
Add aLibSymbol to the library symbol map.
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
std::set< wxString > GetSheetNames() const
const std::map< wxString, LIB_SYMBOL * > & GetLibSymbols() const
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition sch_screen.h:565
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
const wxString & GetFileName() const
Definition sch_screen.h:157
void UpdateSymbolLinks(REPORTER *aReporter=nullptr, LEGACY_SYMBOL_LIBS *aLegacyLibs=nullptr, SYMBOL_LIBRARY_ADAPTER *aLibraries=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in this schematic from the project LIBR...
SCHEMATIC * Schematic() const
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:168
void Plot(PLOTTER *aPlotter, const SCH_PLOT_OPTS &aPlotOpts) const
Plot all the schematic objects to aPlotter.
void MigrateSimModels()
Migrate any symbols having V6 simulation models to their V7 equivalents.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
void EnterGroup() override
Enter the group at the head of the current selection.
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void GuessSelectionCandidates(SCH_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
SCH_SELECTION & GetSelection()
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
SCH_GROUP * GetEnteredGroup()
BOX2I GetBoundingBox() const override
VECTOR2I GetCenter() const
Definition sch_shape.h:96
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.
int GetLastVirtualPageNumber() const
void FillItemMap(std::unordered_map< KIID, EDA_ITEM * > &aMap) const
Fill an item cache for temporary use when many items need to be fetched.
bool PageNumberExists(const wxString &aPageNumber) const
bool ContainsSheet(const SCH_SHEET *aSheet) const
bool HasPath(const KIID_PATH &aPath) 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.
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool IsSharedPath() const
Determine if this sheet path is shared in a complex hierarchy.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString ComposeRefSuffix() const
Compose the reference suffixes of every sheet in this path, from the root down.
void pop_back()
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
wxString GetRefSuffix(const SCH_SHEET_PATH &aParentPath) const
Return this sheet's own reference suffix with text variables resolved.
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition sch_sheet.h:428
void RemoveInstance(const KIID_PATH &aInstancePath)
static wxString NextRefSuffix(const wxString &aSuffix, const std::set< wxString > &aInUse, const std::function< bool(const wxString &)> &aIsTaken=nullptr)
Return the suffix a pasted copy of a sheet should take.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void AddInstance(const SCH_SHEET_INSTANCE &aInstance)
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:187
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:285
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition sch_sheet.h:563
Schematic symbol object.
Definition sch_symbol.h:76
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:136
std::vector< LIB_ID > GetVariantSymbolOverrides() const
wxString GetSchSymbolLibraryName() const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:166
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit, int aBodyStyle) const override
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool IsPower() const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void BrightenItem(EDA_ITEM *aItem)
int AddItemToSel(const TOOL_EVENT &aEvent)
void UnbrightenItem(EDA_ITEM *aItem)
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
Definition selection.cpp:38
const std::deque< EDA_ITEM * > GetItems() const
Definition selection.h:125
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:104
EDA_ITEM * Front() const
Definition selection.h:176
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
void AddCurrentTrace(const wxString &aDeviceName)
Add a current trace for a given device to the current plot.
void AddVoltageTrace(const wxString &aNetName)
Add a voltage trace for a given net to the current plot.
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:45
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
const std::string & GetString()
Definition richio.h:453
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:225
The symbol library editor main window.
bool IsLibraryTreeShown() const override
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
void ToggleLibraryTree() override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Class to handle modifications to the symbol libraries.
Symbol library viewer main window.
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
SCH_EDIT_FRAME * getEditFrame() const
Definition tool_base.h:182
const std::string & GetName() const
Definition tool_base.h:132
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 DisableGridSnapping() const
Definition tool_event.h:367
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 Go(int(SCH_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
TOOLS_HOLDER * GetToolHolder() const
A wrapper for reporting to a wxString object.
Definition reporter.h:242
std::unique_ptr< wxBitmap > GetImageFromClipboard()
Get image data from the clipboard, if there is any.
bool EncodeImageToPng(const wxImage &aImage, wxMemoryBuffer &aOutput)
Encode an image to PNG format with fast compression settings optimized for clipboard use.
bool AddTransparentImageToClipboardData(wxDataObjectComposite *aData, wxImage aImage)
Adds an image to clipboard data in a platform-specific way such that transparency is supported.
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition clipboard.cpp:32
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
bool AddPngToClipboardData(wxDataObjectComposite *aData, const wxMemoryBuffer &aPngData, const wxImage *aFallbackImage)
Adds pre-encoded PNG data to clipboard in a platform-specific way.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition common.cpp:880
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:245
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
@ VOLTAGE_PROBE
Definition cursors.h:57
@ CURRENT_PROBE
Definition cursors.h:59
@ BULLSEYE
Definition cursors.h:55
int InvokeDialogCreateBOM(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_BOM and return whatever DIALOG_BOM::ShowModal() returns.
bool InvokeDialogEditSymbolsLibId(SCH_EDIT_FRAME *aCaller)
Run a dialog to modify the LIB_ID of symbols for instance when a symbol has moved from a symbol libra...
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
void RunExportForOlderVersion(EDA_BASE_FRAME *aFrame, const DOWNGRADE_EXPORT_RUNNER &aRun)
bool RunDowngradeJob(KIWAY &aKiway, KIWAY::FACE_T aFace, JOB_T &aJob, const DOWNGRADE_EXPORT_PASS &aPass, DOWNGRADE_EXPORT_RESULT &aResult)
Fill in the parts of a downgrade job that every editor sets the same way, run it, and hand back its r...
#define _(s)
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_NEW
New item, just created.
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ LINE_MODE_90
@ LINE_MODE_45
@ LINE_MODE_FREE
@ LINE_MODE_COUNT
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:31
@ FRAME_SCH_VIEWER
Definition frame_type.h:32
@ FRAME_SIMULATOR
Definition frame_type.h:34
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
static const std::string KiCadSchematicFileExtension
static wxString KiCadSchematicFileWildcard()
static const wxChar traceSchPaste[]
Flag to enable schematic paste debugging output.
std::string source
#define NET_PLUGIN_CHANGE
Create and shows DIALOG_EXPORT_NETLIST and returns whatever DIALOG_EXPORT_NETLIST::ShowModal() return...
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
bool LoadFileToMemory(const wxString &aFileName, wxMemoryBuffer &aBuffer)
Load the contents of a file into a memory buffer.
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_ERC_WARN
Definition layer_ids.h:510
@ LAYER_ERC_ERR
Definition layer_ids.h:511
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:527
@ LAYER_OP_CURRENTS
Definition layer_ids.h:533
@ LAYER_SCHEMATIC_PAGE_LIMITS
Definition layer_ids.h:528
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:532
void Prettify(std::string &aSource, FORMAT_MODE aMode)
Pretty-prints s-expression text according to KiCad format rules.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
@ LAYERS
Layers have changed.
Definition view_item.h:52
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
void encode(const std::vector< uint8_t > &aInput, std::vector< uint8_t > &aOutput)
Definition base64.cpp:76
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition page_info.h:32
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Plotting engines similar to ps (PostScript, Gerber, svg)
static bool setNetHighlight(SCH_ITEM *aItem, bool aHighlight)
#define HITTEST_THRESHOLD_PIXELS
static void recalculateIfStale(SCH_EDIT_FRAME *aFrame, SCH_ITEM *aItem)
static VECTOR2D CLEAR
static bool highlightNet(TOOL_MANAGER *aToolMgr, const SCH_SHEET_PATH &aSheetPath, const VECTOR2D &aPosition)
Class to handle a set of SCH_ITEMs.
std::vector< EDA_ITEM * > EDA_ITEMS
ANNOTATE_ORDER_T
Schematic annotation order options.
@ ANNOTATE_SELECTION
Annotate the selection.
ANNOTATE_ALGO_T
Schematic annotation type options.
@ SYMBOL_FILTER_NON_POWER
@ 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...
wxString GetSelectedItemsAsText(const SELECTION &aSel)
void PrunePastedSymbolInstances(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic)
Discard the instance data a paste dragged in from somewhere else, keyed by path rather than project n...
std::vector< SCH_ITEM * > FlattenGroups(const EDA_ITEMS &aItems)
Return the given items with the members of any group added, recursively.
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
@ LOCAL_CLEANUP
Definition schematic.h:100
@ NO_CLEANUP
Definition schematic.h:99
@ GLOBAL_CLEANUP
Definition schematic.h:101
const int scale
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
wxString From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Optional context derived from the user selection that opened the dialog.
wxString toRef
Second selected symbol reference, if any.
wxString fromRef
Selected symbol reference (or first of two)
wxString netName
Net name from a selected pin or wire/bus.
What one pass of an export is asked to do.
wxString m_variant
Variant to flatten, empty for the base design.
bool m_dryRun
Classify only, write nothing.
wxString m_folder
Destination, empty on a dry run.
What the flow needs back from a pass.
std::vector< wxString > m_variantsFound
A dry run fills these so the picker can offer them.
std::vector< GRID > grids
Common grid settings, available to every frame.
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
static constexpr auto NOT_CONNECTED
Definition sim_model.h:71
std::string refName
#define ALL_UNITS
Definition symbol.h:150
#define ALL_BODY_STYLES
Definition symbol.h:151
@ SHEET_REF_SUFFIX
Optional sheet field appended to the references of the sheet's symbols.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
std::string path
IbisParser parser & reporter
KIBIS_MODEL * model
KIBIS_PIN * pin
KIBIS_PIN * pinA
const SHAPE_LINE_CHAIN chain
wxString result
Test unit parsing edge cases and error handling.
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition tool_action.h:45
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition tool_event.h:102
@ TC_MESSAGE
Definition tool_event.h:54
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_TABLE_T
Definition typeinfo.h:161
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_ITEM_LOCATE_WIRE_T
Definition typeinfo.h:182
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_MARKER_T
Definition typeinfo.h:154
@ SCH_SHAPE_T
Definition typeinfo.h:145
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ SCH_JUNCTION_T
Definition typeinfo.h:155
@ SCH_PIN_T
Definition typeinfo.h:149
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:35
#define ZOOM_MIN_LIMIT_EESCHEMA
#define ZOOM_MAX_LIMIT_EESCHEMA