KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_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 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
22
23#include <advanced_config.h>
25#include <confirm.h>
27#include <gestfich.h> // To open with a text editor
28#include <kidialog.h>
29#include <kiway.h>
30#include <launch_ext.h> // To default when file manager setting is empty
33#include <pgm_base.h>
34#include <sch_painter.h>
35#include <string_utils.h>
36#include <symbol_edit_frame.h>
39#include <symbol_viewer_frame.h>
43#include <tool/tool_manager.h>
44#include <tools/sch_actions.h>
46
47#include <wx/filedlg.h>
48#include <kiplatform/ui.h>
49
54#include <lib_symbol.h>
55#include <symbol_edit_frame.h>
56
57#include <map>
58
59
61{
65
67 {
68 LIBRARY_EDITOR_CONTROL* libraryTreeTool = m_toolMgr->GetTool<LIBRARY_EDITOR_CONTROL>();
69 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
70
71 auto libSelectedCondition =
72 [this]( const SELECTION& aSel )
73 {
75 {
76 LIB_ID sel = editFrame->GetTreeLIBID();
77 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
78 }
79
80 return false;
81 };
82
83 // The libInferredCondition allows you to do things like New Symbol and Paste with a
84 // symbol selected (in other words, when we know the library context even if the library
85 // itself isn't selected.
86 auto libInferredCondition =
87 [this]( const SELECTION& aSel )
88 {
90 {
91 LIB_ID sel = editFrame->GetTreeLIBID();
92 return !sel.GetLibNickname().empty();
93 }
94
95 return false;
96 };
97
98 auto symbolSelectedCondition =
99 [this]( const SELECTION& aSel )
100 {
102 {
103 LIB_ID sel = editFrame->GetTargetLibId();
104 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
105 }
106
107 return false;
108 };
109
110 auto derivedSymbolSelectedCondition =
111 [this]( const SELECTION& aSel )
112 {
114 {
115 LIB_ID sel = editFrame->GetTargetLibId();
116
117 if( sel.GetLibNickname().empty() || sel.GetLibItemName().empty() )
118 return false;
119
120 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
121 const LIB_SYMBOL* sym = libMgr.GetSymbol( sel.GetLibItemName(), sel.GetLibNickname() );
122
123 return sym && sym->IsDerived();
124 }
125
126 return false;
127 };
128
129 auto relatedSymbolSelectedCondition =
130 [this]( const SELECTION& aSel )
131 {
133 {
134 LIB_ID sel = editFrame->GetTargetLibId();
135
136 if( sel.GetLibNickname().empty() || sel.GetLibItemName().empty() )
137 return false;
138
139 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
140 const LIB_SYMBOL* sym = libMgr.GetSymbol( sel.GetLibItemName(), sel.GetLibNickname() );
141 wxArrayString derived;
142
143 libMgr.GetDerivedSymbolNames( sel.GetLibItemName(), sel.GetLibNickname(), derived );
144
145 return ( sym && sym->IsDerived() ) || !derived.IsEmpty();
146 }
147
148 return false;
149 };
150
151 auto multiSymbolSelectedCondition =
152 [this]( const SELECTION& aSel )
153 {
155
156 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
157 {
158 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
159 {
160 if( !sel.IsValid() )
161 return false;
162 }
163
164 return true;
165 }
166
167 return false;
168 };
169/* not used, yet
170 auto multiLibrarySelectedCondition =
171 [this]( const SELECTION& aSel )
172 {
173 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
174
175 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
176 {
177 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
178 {
179 if( sel.IsValid() )
180 return false;
181 }
182
183 return true;
184 }
185
186 return false;
187 };
188*/
189 auto canOpenExternally =
190 [this]( const SELECTION& aSel )
191 {
192 // The option is shown if the lib has no current edits
194 {
195 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
196 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
197 return !libMgr.IsLibraryModified( libName );
198 }
199
200 return false;
201 };
202
203
204// clang-format off
205 ctxMenu.AddItem( SCH_ACTIONS::newSymbol, libInferredCondition, 10 );
206 ctxMenu.AddItem( SCH_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
207
208 ctxMenu.AddSeparator( 10 );
209 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
210 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
211 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolAs, symbolSelectedCondition, 10 );
212 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
213 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
214
215 ctxMenu.AddSeparator( 20 );
216 ctxMenu.AddItem( SCH_ACTIONS::importSymbol, libInferredCondition, 20 );
217 ctxMenu.AddItem( SCH_ACTIONS::exportSymbol, symbolSelectedCondition, 20 );
218
219 ctxMenu.AddSeparator( 100 );
220 ctxMenu.AddItem( SCH_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
221 ctxMenu.AddItem( SCH_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
222 ctxMenu.AddItem( SCH_ACTIONS::pasteSymbol, libInferredCondition, 100 );
223 ctxMenu.AddItem( SCH_ACTIONS::duplicateSymbol, symbolSelectedCondition, 100 );
224 ctxMenu.AddItem( SCH_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
225
226 ctxMenu.AddSeparator( 120 );
227 ctxMenu.AddItem( SCH_ACTIONS::renameSymbol, symbolSelectedCondition, 120 );
228 ctxMenu.AddItem( SCH_ACTIONS::symbolProperties, symbolSelectedCondition, 120 );
229 ctxMenu.AddItem( SCH_ACTIONS::flattenSymbol, derivedSymbolSelectedCondition, 120 );
230
231 if( ADVANCED_CFG::GetCfg().m_EnableLibWithText || ADVANCED_CFG::GetCfg().m_EnableLibDir )
232 ctxMenu.AddSeparator( 200 );
233
234 if( ADVANCED_CFG::GetCfg().m_EnableLibWithText )
235 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
236
237 if( ADVANCED_CFG::GetCfg().m_EnableLibDir )
238 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
239
240 ctxMenu.AddSeparator( 300 );
241 ctxMenu.AddItem( SCH_ACTIONS::showLibFieldsTable, libInferredCondition, 300 );
242 ctxMenu.AddItem( SCH_ACTIONS::showRelatedLibFieldsTable, relatedSymbolSelectedCondition, 300 );
243
244 libraryTreeTool->AddContextMenuItems( &ctxMenu );
245 }
246// clang-format on
247
248 return true;
249}
250
251
253{
254 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
255
256 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
257 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
258
259 return 0;
260}
261
262
264{
265 wxString libFile = *aEvent.Parameter<wxString*>();
266
267 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
268 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
269
270 return 0;
271}
272
273
275{
276 if( !m_isSymbolEditor )
277 return 0;
278
280 int unit = 0;
281 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
282
283 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
284 return 0;
285}
286
287
289{
291 const LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
292
293 if( !symbol || !editFrame->IsSymbolFromSchematic() )
294 {
295 wxBell();
296 return 0;
297 }
298
299 const LIB_ID& libId = symbol->GetLibId();
300
301 if( editFrame->LoadSymbol( libId, editFrame->GetUnit(), editFrame->GetBodyStyle() ) )
302 {
303 if( !editFrame->IsLibraryTreeShown() )
304 editFrame->ToggleLibraryTree();
305 }
306 else
307 {
308 const wxString libName = libId.GetLibNickname();
309 const wxString symbolName = libId.GetLibItemName();
310
311 DisplayError( editFrame,
312 wxString::Format( _( "Failed to load symbol %s from "
313 "library %s." ),
314 UnescapeString( symbolName ), UnescapeString( libName ) ) );
315 }
316 return 0;
317}
318
319
321{
322 if( !m_isSymbolEditor )
323 return 0;
324
326 LIB_ID target = editFrame->GetTargetLibId();
327 const wxString& libName = target.GetLibNickname();
328 wxString msg;
329
330 if( libName.IsEmpty() )
331 {
332 msg.Printf( _( "No symbol library selected." ) );
333 m_frame->ShowInfoBarError( msg );
334 return 0;
335 }
336
337 if( !editFrame->GetLibManager().LibraryExists( libName ) )
338 {
339 msg.Printf( _( "Symbol library '%s' not found." ), libName );
340 m_frame->ShowInfoBarError( msg );
341 return 0;
342 }
343
344 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
345 {
346 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
347 m_frame->ShowInfoBarError( msg );
348 return 0;
349 }
350
351 if( aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
352 editFrame->CreateNewSymbol();
354 editFrame->CreateNewSymbol( target.GetLibItemName() );
355 else if( aEvent.IsAction( &SCH_ACTIONS::importSymbol ) )
356 editFrame->ImportSymbol();
357
358 return 0;
359}
360
361
363{
364 if( !m_isSymbolEditor )
365 return 0;
366
368
369 if( aEvt.IsAction( &SCH_ACTIONS::save ) )
370 editFrame->Save();
371 else if( aEvt.IsAction( &SCH_ACTIONS::saveLibraryAs ) )
372 editFrame->SaveLibraryAs();
373 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolAs ) )
374 editFrame->SaveSymbolCopyAs( true );
375 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolCopyAs ) )
376 editFrame->SaveSymbolCopyAs( false );
377 else if( aEvt.IsAction( &SCH_ACTIONS::saveAll ) )
378 editFrame->SaveAll();
379
380 return 0;
381}
382
383
385{
386 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
387 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
388
389 return 0;
390}
391
392
394{
395 if( !m_isSymbolEditor )
396 return 0;
397
400
401 LIB_ID libId = editFrame->GetTreeLIBID();
402
403 wxString libName = libId.GetLibNickname();
404 std::optional<wxString> libItemName =
405 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
406
407 wxCHECK( libItemName, 0 );
408
409 wxFileName fileName( *libItemName );
410
411 wxString filePath = wxEmptyString;
412 wxString explorerCommand;
413
414 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
415 explorerCommand = cfg->m_System.file_explorer;
416
417 if( explorerCommand.IsEmpty() )
418 {
419 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
420
421 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
422 LaunchExternal( filePath );
423
424 return 0;
425 }
426
427 if( !explorerCommand.EndsWith( "%F" ) )
428 {
429 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
430 return 0;
431 }
432
433 filePath = fileName.GetFullPath();
434 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
435
436 wxString fileArg = '"' + filePath + '"';
437
438 explorerCommand.Replace( wxT( "%F" ), fileArg );
439
440 if( !explorerCommand.IsEmpty() )
441 wxExecute( explorerCommand );
442
443 return 0;
444}
445
446
448{
449 if( !m_isSymbolEditor )
450 return 0;
451
453 wxString textEditorName = Pgm().GetTextEditor();
454
455 if( textEditorName.IsEmpty() )
456 {
457 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
458 return 0;
459 }
460
462
463 LIB_ID libId = editFrame->GetTreeLIBID();
464 wxString libName = libId.GetLibNickname();
465
466 std::optional<wxString> optUri =
467 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
468
469 wxCHECK( optUri, 0 );
470
471 wxString tempFName = ( *optUri ).wc_str();
472
473 if( !tempFName.IsEmpty() )
474 ExecuteFile( textEditorName, tempFName, nullptr, false );
475
476 return 0;
477}
478
479
481{
482 if( !m_isSymbolEditor )
483 return 0;
484
486
488 editFrame->CopySymbolToClipboard();
489
491 {
492 bool hasWritableLibs = false;
493 wxString msg;
494
495 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
496 {
497 const wxString& libName = sel.GetLibNickname();
498
499 if( !editFrame->GetLibManager().LibraryExists( libName ) )
500 msg.Printf( _( "Symbol library '%s' not found." ), libName );
501 else if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
502 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
503 else
504 hasWritableLibs = true;
505 }
506
507 if( !msg.IsEmpty() )
508 m_frame->ShowInfoBarError( msg );
509
510 if( !hasWritableLibs )
511 return 0;
512
513 editFrame->DeleteSymbolFromLibrary();
514 }
515
516 return 0;
517}
518
519
521{
522 if( !m_isSymbolEditor )
523 return 0;
524
526 LIB_ID sel = editFrame->GetTargetLibId();
527 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
528 // saved symbol in clipboard
529 bool isPasteAction = aEvent.IsAction( &SCH_ACTIONS::pasteSymbol );
530 wxString msg;
531
532 if( !sel.IsValid() && !isPasteAction )
533 {
534 // When duplicating a symbol, a source symbol must exists.
535 msg.Printf( _( "No symbol selected" ) );
536 m_frame->ShowInfoBarError( msg );
537 return 0;
538 }
539
540 const wxString& libName = sel.GetLibNickname();
541
542 if( !editFrame->GetLibManager().LibraryExists( libName ) )
543 {
544 msg.Printf( _( "Symbol library '%s' not found." ), libName );
545 m_frame->ShowInfoBarError( msg );
546 return 0;
547 }
548
549 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
550 {
551 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
552 m_frame->ShowInfoBarError( msg );
553 return 0;
554 }
555
556 editFrame->DuplicateSymbol( isPasteAction );
557 return 0;
558}
559
560
562{
563 if( !m_isSymbolEditor )
564 return 0;
565
567 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
569
570 LIB_ID libId = editFrame->GetTreeLIBID();
571 wxString libName = libId.GetLibNickname();
572 wxString oldName = libId.GetLibItemName();
573 wxString newName;
574 wxString msg;
575
576 if( !libMgr.LibraryExists( libName ) )
577 return 0;
578
579 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
580 [&]( const wxString& aNewName )
581 {
582 newName = EscapeString( aNewName, CTX_LIBID );
583
584 if( newName.IsEmpty() )
585 {
586 wxMessageBox( _( "Symbol must have a name." ) );
587 return false;
588 }
589
590 // If no change, accept it without prompting
591 if( newName != oldName && libMgr.SymbolNameInUse( newName, libName ) )
592 {
593 msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
594 UnescapeString( newName ),
595 libName );
596
597 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
598 wxOK | wxCANCEL | wxICON_WARNING );
599
600 errorDlg.SetOKLabel( _( "Overwrite" ) );
601
602 return errorDlg.ShowModal() == wxID_OK;
603 }
604
605 return true;
606 } ) )
607 {
608 return 0; // cancelled by user
609 }
610
611 if( newName == oldName )
612 return 0;
613
614 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
615
616 if( !libSymbol )
617 return 0;
618
619 // Renaming the current symbol
620 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
621 bool overwritingCurrentSymbol = false;
622
623 if( libMgr.SymbolExists( newName, libName ) )
624 {
625 // Overwriting the current symbol also need to update the open symbol
626 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
627 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
628 libMgr.RemoveSymbol( newName, libName );
629 }
630
631 libSymbol->SetName( newName );
632
633 if( libSymbol->GetValueField().GetText() == oldName )
634 libSymbol->GetValueField().SetText( newName );
635
636 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
637 libMgr.SetSymbolModified( newName, libName );
638
639 if( overwritingCurrentSymbol )
640 {
641 // We overwrite the old current symbol with the renamed one, so show
642 // the renamed one now
643 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
644 }
645 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
646 {
647 // Renamed the current symbol - follow it
648 libSymbol = editFrame->GetCurSymbol();
649
650 libSymbol->SetName( newName );
651
652 if( libSymbol->GetValueField().GetText() == oldName )
653 libSymbol->GetValueField().SetText( newName );
654
655 editFrame->RebuildView();
656 editFrame->OnModify();
657 editFrame->UpdateTitle();
658
659 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
660 // invalidate the view pointers by rebuilting the field table
661 editFrame->UpdateMsgPanel();
662 }
663
664 editFrame->RenameSymbolTab( libId, LIB_ID( libName, newName ) );
665
666 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
667 editFrame->UpdateLibraryTree( treeItem, libSymbol );
668 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
669 return 0;
670}
671
672
680
681
683{
684 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
685 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
686
687 // Update canvas
688 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
689 m_frame->GetCanvas()->Refresh();
690
691 return 0;
692}
693
694
696{
697 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
698 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
699
700 // Update canvas
701 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
702 m_frame->GetCanvas()->Refresh();
703
704 return 0;
705}
706
707
709{
710 if( !m_isSymbolEditor )
711 return 0;
712
714 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
715
716 return 0;
717}
718
719
721{
722 if( !m_isSymbolEditor )
723 return 0;
724
725 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
727
729 cfg->m_ShowHiddenPins;
730
732 m_frame->GetCanvas()->Refresh();
733 return 0;
734}
735
736
738{
739 if( !m_isSymbolEditor )
740 return 0;
741
742 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
744
746
748 m_frame->GetCanvas()->Refresh();
749 return 0;
750}
751
752
754{
755 if( !m_isSymbolEditor )
756 return 0;
757
758 SYMBOL_EDITOR_SETTINGS& cfg = *m_frame->libeditconfig();
760
761 m_frame->GetRenderSettings()->m_ShowPinAltIcons = cfg.m_ShowPinAltIcons;
762
764 m_frame->GetCanvas()->Refresh();
765 return 0;
766}
767
768
770{
771 if( !m_isSymbolEditor )
772 return 0;
773
775 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
776
777 if( !symbol )
778 {
779 wxMessageBox( _( "No symbol to export" ) );
780 return 0;
781 }
782
783 wxFileName fn( symbol->GetName() );
784 fn.SetExt( "png" );
785
786 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
787
788 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
789 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
790
792
793 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
794 {
795 // calling wxYield is mandatory under Linux, after closing the file selector dialog
796 // to refresh the screen before creating the PNG or JPEG image from screen
797 wxYield();
798
799 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
800 {
801 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
802 }
803 }
804
805 return 0;
806}
807
808
810{
811 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
812 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
813
814 return 0;
815}
816
817
819{
820 if( !m_isSymbolEditor )
821 return 0;
822
824 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
825
826 if( !symbol )
827 {
828 wxMessageBox( _( "No symbol to export" ) );
829 return 0;
830 }
831
832 wxFileName fn( symbol->GetName() );
833 fn.SetExt( FILEEXT::SVGFileExtension );
834
835 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
836
837 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
839 wxFD_SAVE,
840 m_frame );
841
842 if( !fullFileName.IsEmpty() )
843 {
844 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
845 PAGE_INFO pageTemp = pageSave;
846
847 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
848 editFrame->GetBodyStyle(), false );
849
850 // Add a small margin (10% of size)to the plot bounding box
851 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
852
853 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
854 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
855
856 // Add an offet to plot the symbol centered on the page.
857 VECTOR2I plot_offset = symbolBBox.GetOrigin();
858
859 editFrame->GetScreen()->SetPageSettings( pageTemp );
860 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
861 editFrame->GetScreen()->SetPageSettings( pageSave );
862 }
863
864 return 0;
865}
866
867
869{
870 if( !m_isSymbolEditor )
871 return 0;
872
874 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
875 LIB_ID symId = editFrame->GetTargetLibId();
876
877 if( !symId.IsValid() )
878 {
879 wxMessageBox( _( "No symbol to flatten" ) );
880 return 0;
881 }
882
883 const LIB_SYMBOL* symbol = libMgr.GetBufferedSymbol( symId.GetLibItemName(), symId.GetLibNickname() );
884 std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->Flatten();
885 wxCHECK_MSG( flatSymbol, 0, _( "Failed to flatten symbol" ) );
886
887 if( !libMgr.UpdateSymbol( flatSymbol.get(), symId.GetLibNickname() ) )
888 {
889 wxMessageBox( _( "Failed to update library with flattened symbol" ) );
890 return 0;
891 }
892
893 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( symId );
894 editFrame->UpdateLibraryTree( treeItem, flatSymbol.get() );
895
896 return 0;
897}
898
899
901{
902 LIB_SYMBOL* libSymbol = nullptr;
903 LIB_ID libId;
904 int unit, bodyStyle;
905
906 if( m_isSymbolEditor )
907 {
909
910 libSymbol = editFrame->GetCurSymbol();
911 unit = editFrame->GetUnit();
912 bodyStyle = editFrame->GetBodyStyle();
913
914 if( libSymbol )
915 libId = libSymbol->GetLibId();
916 }
917 else
918 {
920
921 libSymbol = viewerFrame->GetSelectedSymbol();
922 unit = viewerFrame->GetUnit();
923 bodyStyle = viewerFrame->GetBodyStyle();
924
925 if( libSymbol )
926 libId = libSymbol->GetLibId();
927 }
928
929 if( libSymbol )
930 {
931 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
932
933 if( !schframe ) // happens when the schematic editor is not active (or closed)
934 {
935 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
936 return 0;
937 }
938
939 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
940
941 if( blocking_dialog )
942 {
943 blocking_dialog->Raise();
944 wxBell();
945 return 0;
946 }
947
948 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
949 unit, bodyStyle );
950
951 symbol->SetParent( schframe->GetScreen() );
952
953 if( schframe->eeconfig()->m_AutoplaceFields.enable )
954 {
955 // Not placed yet, so pass a nullptr screen reference
956 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
957 }
958
959 schframe->Raise();
961 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
962 }
963
964 return 0;
965}
966
967
969{
970 if( !m_isSymbolEditor )
971 return 0;
972
974 const int deltaUnit = aEvent.Parameter<int>();
975
976 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
977 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
978
979 editFrame->SetUnit( newUnit );
980
981 return 0;
982}
983
984
986{
987 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
988 viewerFrame->SelectPreviousSymbol();
989
990 return 0;
991}
992
993
995{
996 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
997 viewerFrame->SelectNextSymbol();
998
999 return 0;
1000}
1001
1002
1015
1016
1017static void showTabSwitcher( SYMBOL_EDIT_FRAME* aFrame, bool aForward )
1018{
1019 EDITOR_TABS_PANEL* panel = aFrame->GetTabsPanel();
1020
1021 if( !panel || panel->Model().Entries().size() < 2 )
1022 return;
1023
1024 if( !aFrame->GetHotkeyPopup() )
1025 aFrame->CreateHotkeyPopup();
1026
1027 HOTKEY_CYCLE_POPUP* popup = aFrame->GetHotkeyPopup();
1028
1029 if( !popup )
1030 return;
1031
1032 wxArrayString labels;
1033
1034 for( const EDITOR_TABS_MODEL::ENTRY& entry : panel->Model().Entries() )
1035 labels.Add( entry.key.AfterFirst( ':' ) );
1036
1037 const int count = static_cast<int>( labels.GetCount() );
1038 const int active = panel->GetActiveTab();
1039 const int next = aForward ? ( active + 1 ) % count : ( active - 1 + count ) % count;
1040
1041 popup->Popup( _( "Switch to Tab" ), labels, next );
1042}
1043
1044
1046{
1048
1049 if( editFrame && editFrame->GetTabsPanel() )
1050 {
1051 showTabSwitcher( editFrame, true );
1052 editFrame->GetTabsPanel()->AdvanceTab( true );
1053 }
1054
1055 return 0;
1056}
1057
1058
1060{
1062
1063 if( editFrame && editFrame->GetTabsPanel() )
1064 {
1065 showTabSwitcher( editFrame, false );
1066 editFrame->GetTabsPanel()->AdvanceTab( false );
1067 }
1068
1069 return 0;
1070}
1071
1072
1074{
1076
1077 if( editFrame && editFrame->GetTabsPanel() )
1078 editFrame->GetTabsPanel()->CloseTab( editFrame->GetTabsPanel()->GetActiveTab() );
1079
1080 return 0;
1081}
1082
1083
1085{
1087
1088 wxCHECK( editFrame, 0 );
1089
1090 const wxString currentLib = editFrame->GetCurLib();
1091
1092 if( currentLib.IsEmpty() )
1093 {
1094 editFrame->ShowInfoBarError( _( "Select a library to compare against a file." ) );
1095 return 0;
1096 }
1097
1098 wxFileDialog dlg( editFrame, _( "Choose Library to Compare With" ), wxEmptyString,
1099 wxEmptyString, FILEEXT::KiCadSymbolLibFileWildcard(),
1100 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1101
1102 if( dlg.ShowModal() != wxID_OK )
1103 return 0;
1104
1105 wxFileName otherFn( dlg.GetPath() );
1106 otherFn.MakeAbsolute();
1107
1108 if( !otherFn.GetExt().IsSameAs( FILEEXT::KiCadSymbolLibFileExtension, false ) )
1109 {
1110 editFrame->ShowInfoBarError(
1111 _( "Select a KiCad symbol library file (.kicad_sym)." ) );
1112 return 0;
1113 }
1114
1115 const wxString otherPath = otherFn.GetFullPath();
1116
1117 // SYM_LIB_DIFFER::Diff() consumes these borrowed pointers synchronously;
1118 // DOCUMENT_DIFF does not retain them.
1119 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
1120 wxArrayString names;
1121 libMgr.GetSymbolNames( currentLib, names );
1122
1124
1125 for( const wxString& name : names )
1126 {
1127 if( LIB_SYMBOL* sym = libMgr.GetSymbol( name, currentLib ) )
1128 beforeMap.emplace( sym->GetName(), sym );
1129 }
1130
1131 std::vector<std::unique_ptr<LIB_SYMBOL>> afterStorage;
1133
1134 try
1135 {
1136 auto loaded = KICAD_DIFF::SYM_LIB_DIFFER::LoadLibrary( otherPath );
1137 afterStorage = std::move( loaded.first );
1138 afterMap = std::move( loaded.second );
1139 }
1140 catch( const IO_ERROR& ioe )
1141 {
1142 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1143 otherPath, ioe.What() ) );
1144 return 0;
1145 }
1146 catch( const std::exception& e )
1147 {
1148 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1149 otherPath,
1150 wxString::FromUTF8( e.what() ) ) );
1151 return 0;
1152 }
1153
1154 KICAD_DIFF::SYM_LIB_DIFFER differ( beforeMap, afterMap, otherPath );
1156
1157 DIALOG_KICAD_DIFF dlgDiff( editFrame, currentLib, otherPath, result );
1158
1159 std::map<KIID_PATH, const KICAD_DIFF::ITEM_CHANGE*> changesById;
1160
1161 for( const KICAD_DIFF::ITEM_CHANGE& c : result.changes )
1162 changesById[c.id] = &c;
1163
1164 auto cloneHolder = std::make_shared<std::vector<std::unique_ptr<LIB_SYMBOL>>>();
1165
1167 [&, cloneHolder]( const KIID_PATH& aId )
1168 {
1169 WIDGET_DIFF_CANVAS* canvas = dlgDiff.DiffCanvas();
1170
1171 if( !canvas )
1172 return;
1173
1174 auto it = changesById.find( aId );
1175
1176 if( it == changesById.end() || !it->second->refdes )
1177 {
1178 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, nullptr, nullptr );
1179 cloneHolder->clear();
1180 return;
1181 }
1182
1183 const wxString& name = *it->second->refdes;
1184 auto beforeIt = beforeMap.find( name );
1185 auto afterIt = afterMap.find( name );
1186
1187 std::unique_ptr<LIB_SYMBOL> beforeClone =
1188 beforeIt != beforeMap.end() ? beforeIt->second->Flatten() : nullptr;
1189 std::unique_ptr<LIB_SYMBOL> afterClone =
1190 afterIt != afterMap.end() ? afterIt->second->Flatten() : nullptr;
1191
1192 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, beforeClone.get(), afterClone.get() );
1193
1194 cloneHolder->clear();
1195
1196 if( beforeClone )
1197 cloneHolder->push_back( std::move( beforeClone ) );
1198
1199 if( afterClone )
1200 cloneHolder->push_back( std::move( afterClone ) );
1201 } );
1202
1203 dlgDiff.ShowModal();
1204
1205 return 0;
1206}
1207
1208
1210{
1218
1220
1227
1235
1237
1241
1244
1248
1252
1257
1260
1263
1266
1269}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
static TOOL_ACTION openWithTextEditor
Definition actions.h:64
static TOOL_ACTION revert
Definition actions.h:58
static TOOL_ACTION addLibrary
Definition actions.h:52
static TOOL_ACTION openDirectory
Definition actions.h:65
static TOOL_ACTION saveAll
Definition actions.h:57
static TOOL_ACTION save
Definition actions.h:54
static TOOL_ACTION showProperties
Definition actions.h:262
static TOOL_ACTION newLibrary
Definition actions.h:51
static TOOL_ACTION ddAddLibrary
Definition actions.h:63
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:554
constexpr const Vec & GetOrigin() const
Definition box2.h:206
constexpr const SizeVec & GetSize() const
Definition box2.h:202
File-compare dialog (Phase 7).
void SetChangeSelectedHandler(CHANGE_SELECTED_FN aFn)
WIDGET_DIFF_CANVAS * DiffCanvas() const
int ShowModal() override
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
HOTKEY_CYCLE_POPUP * GetHotkeyPopup()
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
virtual void CreateHotkeyPopup()
virtual void ToggleProperties()
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
const std::vector< ENTRY > & Entries() const
The tab strip plus the single shared GAL canvas.
void AdvanceTab(bool aForward)
const EDITOR_TABS_MODEL & Model() const
AUTOPLACE_FIELDS m_AutoplaceFields
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()
Diff two .kicad_sym symbol libraries.
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
static std::pair< std::vector< std::unique_ptr< LIB_SYMBOL > >, SYMBOL_MAP > LoadLibrary(const wxString &aPath)
Convenience: load a .kicad_sym path into a SYMBOL_MAP using SCH_IO_KICAD_SEXPR::EnumerateSymbolLib.
std::map< wxString, const LIB_SYMBOL * > SYMBOL_MAP
Library content is a map of (canonical_name -> LIB_SYMBOL*).
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
int ShowModal() override
Definition kidialog.cpp:89
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1686
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition kiway.cpp:686
Module editor specific tools.
bool RenameLibrary(const wxString &aTitle, const wxString &aName, std::function< bool(const wxString &aNewName)> aValidator)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
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...
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Symbol library management helper that is specific to the symbol library editor frame.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetAdapter()
Return the adapter object that provides the stored data.
Define a library symbol object.
Definition lib_symbol.h:79
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:148
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true, bool aIgnoreLabelsOnInvisiblePins=true) const
Get the bounding box for the symbol.
bool IsDerived() const
Definition lib_symbol.h:196
wxString GetName() const override
Definition lib_symbol.h:141
SCH_FIELD & GetValueField()
Return reference to the value field.
Definition lib_symbol.h:329
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
virtual void SetName(const wxString &aName)
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)
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition pgm_base.cpp:218
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
static TOOL_ACTION editSymbol
static TOOL_ACTION importSymbol
static TOOL_ACTION newSymbol
static TOOL_ACTION saveLibraryAs
static TOOL_ACTION previousSymbol
static TOOL_ACTION showRelatedLibFieldsTable
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION pasteSymbol
static TOOL_ACTION exportSymbolAsSVG
static TOOL_ACTION renameSymbol
static TOOL_ACTION duplicateSymbol
static TOOL_ACTION closeSymbolTab
static TOOL_ACTION cutSymbol
static TOOL_ACTION compareLibraryWithFile
static TOOL_ACTION saveSymbolCopyAs
static TOOL_ACTION nextUnit
static TOOL_ACTION showElectricalTypes
static TOOL_ACTION flattenSymbol
static TOOL_ACTION placeSymbol
Definition sch_actions.h:62
static TOOL_ACTION showHiddenFields
static TOOL_ACTION nextSymbol
static TOOL_ACTION prevSymbolTab
static TOOL_ACTION showHiddenPins
static TOOL_ACTION showPinNumbers
static TOOL_ACTION exportSymbolView
static TOOL_ACTION showLibFieldsTable
static TOOL_ACTION copySymbol
static TOOL_ACTION symbolProperties
static TOOL_ACTION toggleSyncedPinsMode
static TOOL_ACTION deleteSymbol
static TOOL_ACTION nextSymbolTab
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION exportSymbol
static TOOL_ACTION previousUnit
static TOOL_ACTION deriveFromExistingSymbol
static TOOL_ACTION addSymbolToSchematic
static TOOL_ACTION saveSymbolAs
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
EESCHEMA_SETTINGS * eeconfig() const
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:128
void SetText(const wxString &aText) override
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:137
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition sch_screen.h:138
Schematic symbol object.
Definition sch_symbol.h:69
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
SCH_SELECTION_TOOL * m_selectionTool
int PreviousSymbol(const TOOL_EVENT &aEvent)
int ToggleSyncedPinsMode(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvt)
int PrevTab(const TOOL_EVENT &aEvent)
int EditSymbol(const TOOL_EVENT &aEvent)
int ExportView(const TOOL_EVENT &aEvent)
int ShowElectricalTypes(const TOOL_EVENT &aEvent)
int FlattenSymbol(const TOOL_EVENT &aEvent)
int OpenDirectory(const TOOL_EVENT &aEvent)
int RenameSymbol(const TOOL_EVENT &newName)
int DuplicateSymbol(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
int ShowLibraryTable(const TOOL_EVENT &aEvent)
int AddLibrary(const TOOL_EVENT &aEvent)
int AddSymbol(const TOOL_EVENT &aEvent)
int CloseTab(const TOOL_EVENT &aEvent)
int TogglePinAltIcons(const TOOL_EVENT &aEvent)
int ChangeUnit(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int ToggleHiddenFields(const TOOL_EVENT &aEvent)
int OpenWithTextEditor(const TOOL_EVENT &aEvent)
int ExportSymbol(const TOOL_EVENT &aEvent)
int NextTab(const TOOL_EVENT &aEvent)
int NextSymbol(const TOOL_EVENT &aEvent)
void setTransitions() override
< Set up handlers for various events.
int ToggleProperties(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
int EditLibrarySymbol(const TOOL_EVENT &aEvent)
int CompareLibraryWithFile(const TOOL_EVENT &aEvent)
Diff the currently-open symbol library against another .kicad_sym file.
int ExportSymbolAsSVG(const TOOL_EVENT &aEvent)
int ShowPinNumbers(const TOOL_EVENT &aEvent)
int DdAddLibrary(const TOOL_EVENT &aEvent)
int AddSymbolToSchematic(const TOOL_EVENT &aEvent)
int CutCopyDelete(const TOOL_EVENT &aEvent)
bool m_ShowPinAltIcons
When true, dragging an outline edge will drag pins rooted on it.
The symbol library editor main window.
void SaveAll()
Save all modified symbols and libraries.
bool IsLibraryTreeShown() const override
void RenameSymbolTab(const LIB_ID &aOldId, const LIB_ID &aNewId)
Update the open tab for aOldId, if any, to the renamed symbol aNewId so its label and key track the r...
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
EDITOR_TABS_PANEL * GetTabsPanel() const
The tab strip fronting the shared canvas, or nullptr before it is mounted.
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
void FocusOnLibId(const LIB_ID &aLibID)
void SVGPlotSymbol(const wxString &aFullFileName, const VECTOR2I &aOffset)
Create the SVG print file for the current edited symbol.
void Save()
Save the selected symbol or library.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
int GetTreeSelectionCount() const
bool IsSymbolFromSchematic() const
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
LIB_ID GetTargetLibId() const override
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
void UpdateMsgPanel() override
Redraw the message panel.
void CreateNewSymbol(const wxString &newName=wxEmptyString)
Create a new symbol in the selected library.
void UpdateTitle()
Update the main window title bar with the current library name and read only status of the library.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
void UpdateLibraryTree(const wxDataViewItem &aTreeItem, LIB_SYMBOL *aSymbol)
Update a symbol node in the library tree.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
void SaveLibraryAs()
Save the currently selected library to a new file.
void ToggleLibraryTree() override
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
LIB_SYMBOL * GetBufferedSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
LIB_SYMBOL * GetSymbol(const wxString &aSymbolName, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
bool RemoveSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &aOldSymbolName, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
void SetSymbolModified(const wxString &aSymbolName, const wxString &aLibrary)
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
size_t GetDerivedSymbolNames(const wxString &aSymbolName, const wxString &aLibraryName, wxArrayString &aList)
Fetch all of the symbols derived from a aSymbolName into aList.
bool SymbolExists(const wxString &aSymbolName, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
Symbol library viewer main window.
LIB_SYMBOL * GetSelectedSymbol() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
SCH_BASE_FRAME * getEditFrame() const
Definition tool_base.h:182
KIGFX::VIEW * getView() const
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
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:469
void Go(int(SCH_BASE_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
std::unique_ptr< TOOL_MENU > m_menu
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
bool empty() const
Definition utf8.h:105
GAL-backed canvas for visualizing a KICAD_DIFF::DIFF_SCENE.
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.
#define _(s)
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:31
@ FRAME_SCH
Definition frame_type.h:30
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:160
static const std::string KiCadSymbolLibFileExtension
static const std::string SVGFileExtension
static wxString PngFileWildcard()
static wxString SVGFileWildcard()
static wxString KiCadSymbolLibFileWildcard()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
void ConfigureSymDiffCanvasContext(WIDGET_DIFF_CANVAS &aCanvas, LIB_SYMBOL *aBefore, LIB_SYMBOL *aAfter)
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
CITER next(CITER it)
Definition ptree.cpp:120
@ AUTOPLACE_AUTO
Definition sch_item.h:67
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
The full set of changes between two parsed documents of one type.
One change record on a single item.
static void showTabSwitcher(SYMBOL_EDIT_FRAME *aFrame, bool aForward)
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
Definition of file extensions used in Kicad.