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
21#include <sch_edit_frame.h>
25
26#include <advanced_config.h>
28#include <confirm.h>
30#include <gestfich.h> // To open with a text editor
31#include <kidialog.h>
32#include <kiway.h>
33#include <launch_ext.h> // To default when file manager setting is empty
36#include <pgm_base.h>
37#include <project_sch.h>
38#include <sch_painter.h>
39#include <string_utils.h>
40#include <symbol_edit_frame.h>
43#include <symbol_viewer_frame.h>
47#include <tool/tool_manager.h>
48#include <tools/sch_actions.h>
50
51#include <wx/filedlg.h>
52#include <kiplatform/ui.h>
53
58#include <lib_symbol.h>
59#include <symbol_edit_frame.h>
60
61#include <map>
62
63
65{
69
71 {
72 LIBRARY_EDITOR_CONTROL* libraryTreeTool = m_toolMgr->GetTool<LIBRARY_EDITOR_CONTROL>();
73 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
74
75 auto libSelectedCondition =
76 [this]( const SELECTION& aSel )
77 {
79 {
80 LIB_ID sel = editFrame->GetTreeLIBID();
81 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
82 }
83
84 return false;
85 };
86
87 // The libInferredCondition allows you to do things like New Symbol and Paste with a
88 // symbol selected (in other words, when we know the library context even if the library
89 // itself isn't selected.
90 auto libInferredCondition =
91 [this]( const SELECTION& aSel )
92 {
94 {
95 LIB_ID sel = editFrame->GetTreeLIBID();
96 return !sel.GetLibNickname().empty();
97 }
98
99 return false;
100 };
101
102 auto symbolSelectedCondition =
103 [this]( const SELECTION& aSel )
104 {
106 {
107 LIB_ID sel = editFrame->GetTargetLibId();
108 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
109 }
110
111 return false;
112 };
113
114 auto derivedSymbolSelectedCondition =
115 [this]( const SELECTION& aSel )
116 {
118 {
119 LIB_ID sel = editFrame->GetTargetLibId();
120
121 if( sel.GetLibNickname().empty() || sel.GetLibItemName().empty() )
122 return false;
123
124 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
125 const LIB_SYMBOL* sym = libMgr.GetSymbol( sel.GetLibItemName(), sel.GetLibNickname() );
126
127 return sym && sym->IsDerived();
128 }
129
130 return false;
131 };
132
133 auto relatedSymbolSelectedCondition =
134 [this]( const SELECTION& aSel )
135 {
137 {
138 LIB_ID sel = editFrame->GetTargetLibId();
139
140 if( sel.GetLibNickname().empty() || sel.GetLibItemName().empty() )
141 return false;
142
143 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
144 const LIB_SYMBOL* sym = libMgr.GetSymbol( sel.GetLibItemName(), sel.GetLibNickname() );
145
146 // This runs on every menu evaluation, so ask for the answer and not the list
147 return ( sym && sym->IsDerived() )
148 || libMgr.HasDerivedSymbols( sel.GetLibItemName(), sel.GetLibNickname() );
149 }
150
151 return false;
152 };
153
154 auto multiSymbolSelectedCondition =
155 [this]( const SELECTION& aSel )
156 {
158
159 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
160 {
161 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
162 {
163 if( !sel.IsValid() )
164 return false;
165 }
166
167 return true;
168 }
169
170 return false;
171 };
172/* not used, yet
173 auto multiLibrarySelectedCondition =
174 [this]( const SELECTION& aSel )
175 {
176 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
177
178 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
179 {
180 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
181 {
182 if( sel.IsValid() )
183 return false;
184 }
185
186 return true;
187 }
188
189 return false;
190 };
191*/
192 auto canOpenExternally =
193 [this]( const SELECTION& aSel )
194 {
195 // The option is shown if the lib has no current edits
197 {
198 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
199 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
200 return !libMgr.IsLibraryModified( libName );
201 }
202
203 return false;
204 };
205
206 auto isPackedLibraryCondition =
207 [this]( const SELECTION& aSel )
208 {
209 // The option is shown if the lib has no current edits
211 {
212 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
213 SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( &editFrame->Prj() );
214
215 if( !adapter )
216 return false;
217
218 std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( libName );
219
220 if( !row )
221 return false;
222
223 wxString uri = LIBRARY_MANAGER::ExpandURI( row.value()->URI(), editFrame->Prj() );
224
225 return wxFileName::FileExists( uri );
226 }
227
228 return false;
229 };
230
231 auto isUnpackedLibraryCondition =
232 [this]( const SELECTION& aSel )
233 {
234 // The option is shown if the lib has no current edits
236 {
237 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
238 SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( &editFrame->Prj() );
239
240 if( !adapter )
241 return false;
242
243 std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( libName );
244
245 if( !row )
246 return false;
247
248 wxString uri = LIBRARY_MANAGER::ExpandURI( row.value()->URI(), editFrame->Prj() );
249
250 return wxFileName::DirExists( uri );
251 }
252
253 return false;
254 };
255
256// clang-format off
257 ctxMenu.AddItem( SCH_ACTIONS::newSymbol, libInferredCondition, 10 );
258 ctxMenu.AddItem( SCH_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
259
260 ctxMenu.AddSeparator( 10 );
261 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
262 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
263 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAsPacked, isUnpackedLibraryCondition, 10 );
264 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAsUnpacked, isPackedLibraryCondition, 10 );
265 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolAs, symbolSelectedCondition, 10 );
266 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
267 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
268
269 ctxMenu.AddSeparator( 20 );
270 ctxMenu.AddItem( SCH_ACTIONS::importSymbol, libInferredCondition, 20 );
271 ctxMenu.AddItem( SCH_ACTIONS::exportSymbol, symbolSelectedCondition, 20 );
272
273 ctxMenu.AddSeparator( 100 );
274 ctxMenu.AddItem( SCH_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
275 ctxMenu.AddItem( SCH_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
276 ctxMenu.AddItem( SCH_ACTIONS::pasteSymbol, libInferredCondition, 100 );
277 ctxMenu.AddItem( SCH_ACTIONS::duplicateSymbol, symbolSelectedCondition, 100 );
278 ctxMenu.AddItem( SCH_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 100 );
279
280 ctxMenu.AddSeparator( 120 );
281 ctxMenu.AddItem( SCH_ACTIONS::renameSymbol, symbolSelectedCondition, 120 );
282 ctxMenu.AddItem( SCH_ACTIONS::symbolProperties, symbolSelectedCondition, 120 );
283 ctxMenu.AddItem( SCH_ACTIONS::flattenSymbol, derivedSymbolSelectedCondition, 120 );
284
285 if( ADVANCED_CFG::GetCfg().m_EnableLibWithText || ADVANCED_CFG::GetCfg().m_EnableLibDir )
286 ctxMenu.AddSeparator( 200 );
287
288 if( ADVANCED_CFG::GetCfg().m_EnableLibWithText )
289 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
290
291 if( ADVANCED_CFG::GetCfg().m_EnableLibDir )
292 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
293
294 ctxMenu.AddSeparator( 300 );
295 ctxMenu.AddItem( SCH_ACTIONS::showLibFieldsTable, libInferredCondition, 300 );
296 ctxMenu.AddItem( SCH_ACTIONS::showRelatedLibFieldsTable, relatedSymbolSelectedCondition, 300 );
297
298 libraryTreeTool->AddContextMenuItems( &ctxMenu );
299 }
300// clang-format on
301
302 return true;
303}
304
305
307{
308 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
309
310 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
311 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
312
313 return 0;
314}
315
316
318{
319 wxString libFile = *aEvent.Parameter<wxString*>();
320
321 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
322 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
323
324 return 0;
325}
326
327
329{
330 if( !m_isSymbolEditor )
331 return 0;
332
334 int unit = 0;
335 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
336
337 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
338 return 0;
339}
340
341
343{
345 const LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
346
347 if( !symbol || !editFrame->IsSymbolFromSchematic() )
348 {
349 wxBell();
350 return 0;
351 }
352
353 const LIB_ID& libId = symbol->GetLibId();
354
355 if( editFrame->LoadSymbol( libId, editFrame->GetUnit(), editFrame->GetBodyStyle() ) )
356 {
357 if( !editFrame->IsLibraryTreeShown() )
358 editFrame->ToggleLibraryTree();
359 }
360 else
361 {
362 const wxString libName = libId.GetLibNickname();
363 const wxString symbolName = libId.GetLibItemName();
364
365 DisplayError( editFrame,
366 wxString::Format( _( "Failed to load symbol %s from "
367 "library %s." ),
368 UnescapeString( symbolName ), UnescapeString( libName ) ) );
369 }
370 return 0;
371}
372
373
375{
376 if( !m_isSymbolEditor )
377 return 0;
378
380 LIB_ID target = editFrame->GetTargetLibId();
381 const wxString& libName = target.GetLibNickname();
382 wxString msg;
383
384 // Allow creating a new symbol before choosing a library
385 if( !aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
386 {
387 if( libName.IsEmpty() )
388 {
389 msg.Printf( _( "No symbol library selected." ) );
390 m_frame->ShowInfoBarError( msg );
391 return 0;
392 }
393
394 if( !editFrame->GetLibManager().LibraryExists( libName ) )
395 {
396 msg.Printf( _( "Symbol library '%s' not found." ), libName );
397 m_frame->ShowInfoBarError( msg );
398 return 0;
399 }
400
401 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
402 {
403 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
404 m_frame->ShowInfoBarError( msg );
405 return 0;
406 }
407 }
408
409 if( aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
410 editFrame->CreateNewSymbol();
412 editFrame->CreateNewSymbol( target.GetLibItemName() );
413 else if( aEvent.IsAction( &SCH_ACTIONS::importSymbol ) )
414 editFrame->ImportSymbol();
415
416 return 0;
417}
418
419
421{
422 if( !m_isSymbolEditor )
423 return 0;
424
426
427 if( aEvt.IsAction( &SCH_ACTIONS::save ) )
428 editFrame->Save();
429 else if( aEvt.IsAction( &SCH_ACTIONS::saveLibraryAs ) )
435 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolAs ) )
436 editFrame->SaveSymbolCopyAs( true );
437 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolCopyAs ) )
438 editFrame->SaveSymbolCopyAs( false );
439 else if( aEvt.IsAction( &SCH_ACTIONS::saveAll ) )
440 editFrame->SaveAll();
441
442 return 0;
443}
444
445
447{
448 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
449 {
450 LIB_ID libId = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetTargetLibId();
451 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert( libId );
452 }
453
454 return 0;
455}
456
457
459{
460 if( !m_isSymbolEditor )
461 return 0;
462
465
466 LIB_ID libId = editFrame->GetTreeLIBID();
467
468 wxString libName = libId.GetLibNickname();
469 std::optional<wxString> libItemName =
470 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
471
472 wxCHECK( libItemName, 0 );
473
474 wxFileName fileName( *libItemName );
475
476 wxString filePath = wxEmptyString;
477 wxString explorerCommand;
478
479 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
480 explorerCommand = cfg->m_System.file_explorer;
481
482 if( explorerCommand.IsEmpty() )
483 {
484 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
485
486 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
487 LaunchExternal( filePath );
488
489 return 0;
490 }
491
492 if( !explorerCommand.EndsWith( "%F" ) )
493 {
494 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
495 return 0;
496 }
497
498 filePath = fileName.GetFullPath();
499 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
500
501 wxString fileArg = '"' + filePath + '"';
502
503 explorerCommand.Replace( wxT( "%F" ), fileArg );
504
505 if( !explorerCommand.IsEmpty() )
506 wxExecute( explorerCommand );
507
508 return 0;
509}
510
511
513{
514 if( !m_isSymbolEditor )
515 return 0;
516
518 wxString textEditorName = Pgm().GetTextEditor();
519
520 if( textEditorName.IsEmpty() )
521 {
522 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
523 return 0;
524 }
525
527
528 LIB_ID libId = editFrame->GetTreeLIBID();
529 wxString libName = libId.GetLibNickname();
530
531 std::optional<wxString> optUri =
532 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
533
534 wxCHECK( optUri, 0 );
535
536 wxString tempFName = ( *optUri ).wc_str();
537
538 if( !tempFName.IsEmpty() )
539 ExecuteFile( textEditorName, tempFName, nullptr, false );
540
541 return 0;
542}
543
544
546{
547 if( !m_isSymbolEditor )
548 return 0;
549
551
553 editFrame->CopySymbolToClipboard();
554
556 {
557 bool hasWritableLibs = false;
558 wxString msg;
559
560 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
561 {
562 const wxString& libName = sel.GetLibNickname();
563
564 if( !editFrame->GetLibManager().LibraryExists( libName ) )
565 msg.Printf( _( "Symbol library '%s' not found." ), libName );
566 else if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
567 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
568 else
569 hasWritableLibs = true;
570 }
571
572 if( !msg.IsEmpty() )
573 m_frame->ShowInfoBarError( msg );
574
575 if( !hasWritableLibs )
576 return 0;
577
578 editFrame->DeleteSymbolFromLibrary();
579 }
580
581 return 0;
582}
583
584
586{
587 if( !m_isSymbolEditor )
588 return 0;
589
591 LIB_ID sel = editFrame->GetTargetLibId();
592 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
593 // saved symbol in clipboard
594 bool isPasteAction = aEvent.IsAction( &SCH_ACTIONS::pasteSymbol );
595 wxString msg;
596
597 if( !sel.IsValid() && !isPasteAction )
598 {
599 // When duplicating a symbol, a source symbol must exists.
600 msg.Printf( _( "No symbol selected" ) );
601 m_frame->ShowInfoBarError( msg );
602 return 0;
603 }
604
605 const wxString& libName = sel.GetLibNickname();
606
607 if( !editFrame->GetLibManager().LibraryExists( libName ) )
608 {
609 msg.Printf( _( "Symbol library '%s' not found." ), libName );
610 m_frame->ShowInfoBarError( msg );
611 return 0;
612 }
613
614 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
615 {
616 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
617 m_frame->ShowInfoBarError( msg );
618 return 0;
619 }
620
621 editFrame->DuplicateSymbol( isPasteAction );
622 return 0;
623}
624
625
627{
628 if( !m_isSymbolEditor )
629 return 0;
630
632 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
634
635 LIB_ID libId = editFrame->GetTreeLIBID();
636 wxString libName = libId.GetLibNickname();
637 wxString oldName = libId.GetLibItemName();
638 wxString newName;
639 wxString msg;
640
641 if( !libMgr.LibraryExists( libName ) )
642 return 0;
643
644 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
645 [&]( const wxString& aNewName )
646 {
647 newName = EscapeString( aNewName, CTX_LIBID );
648
649 if( newName.IsEmpty() )
650 {
651 wxMessageBox( _( "Symbol must have a name." ) );
652 return false;
653 }
654
655 // If no change, accept it without prompting
656 if( newName != oldName && libMgr.SymbolNameInUse( newName, libName ) )
657 {
658 msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
659 UnescapeString( newName ),
660 libName );
661
662 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
663 wxOK | wxCANCEL | wxICON_WARNING );
664
665 errorDlg.SetOKLabel( _( "Overwrite" ) );
666
667 return errorDlg.ShowModal() == wxID_OK;
668 }
669
670 return true;
671 } ) )
672 {
673 return 0; // cancelled by user
674 }
675
676 if( newName == oldName )
677 return 0;
678
679 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
680
681 if( !libSymbol )
682 return 0;
683
684 // Renaming the current symbol
685 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
686 bool overwritingCurrentSymbol = false;
687
688 if( libMgr.SymbolExists( newName, libName ) )
689 {
690 // Overwriting the current symbol also need to update the open symbol
691 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
692 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
693 libMgr.RemoveSymbol( newName, libName );
694 }
695
696 libSymbol->SetName( newName );
697
698 if( libSymbol->GetValueField().GetText() == oldName )
699 libSymbol->GetValueField().SetText( newName );
700
701 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
702 libMgr.SetSymbolModified( newName, libName );
703
704 if( overwritingCurrentSymbol )
705 {
706 // We overwrite the old current symbol with the renamed one, so show
707 // the renamed one now
708 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
709 }
710 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
711 {
712 // Renamed the current symbol - follow it
713 libSymbol = editFrame->GetCurSymbol();
714
715 libSymbol->SetName( newName );
716
717 if( libSymbol->GetValueField().GetText() == oldName )
718 libSymbol->GetValueField().SetText( newName );
719
720 editFrame->RebuildView();
721 editFrame->OnModify();
722
723 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
724 // invalidate the view pointers by rebuilting the field table
725 editFrame->UpdateMsgPanel();
726 }
727
728 editFrame->RenameSymbolTab( libId, LIB_ID( libName, newName ) );
729
730 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
731 editFrame->UpdateLibraryTree( treeItem, libSymbol );
732 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
733 return 0;
734}
735
736
744
745
747{
748 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
749 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
750
751 // Update canvas
752 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
753 m_frame->GetCanvas()->Refresh();
754
755 return 0;
756}
757
758
760{
761 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
762 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
763
764 // Update canvas
765 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
766 m_frame->GetCanvas()->Refresh();
767
768 return 0;
769}
770
771
773{
774 if( !m_isSymbolEditor )
775 return 0;
776
778
779 if( SYMBOL_EDITOR_SETTINGS* cfg = editFrame->GetSettings() )
780 cfg->m_SyncPinEdit = !cfg->m_SyncPinEdit;
781
782 return 0;
783}
784
785
787{
788 if( !m_isSymbolEditor )
789 return 0;
790
791 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
793
795 cfg->m_ShowHiddenPins;
796
798 m_frame->GetCanvas()->Refresh();
799 return 0;
800}
801
802
804{
805 if( !m_isSymbolEditor )
806 return 0;
807
808 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
810
812
814 m_frame->GetCanvas()->Refresh();
815 return 0;
816}
817
818
820{
821 if( !m_isSymbolEditor )
822 return 0;
823
824 SYMBOL_EDITOR_SETTINGS& cfg = *m_frame->libeditconfig();
826
827 m_frame->GetRenderSettings()->m_ShowPinAltIcons = cfg.m_ShowPinAltIcons;
828
830 m_frame->GetCanvas()->Refresh();
831 return 0;
832}
833
834
836{
837 if( !m_isSymbolEditor )
838 return 0;
839
841 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
842
843 if( !symbol )
844 {
845 wxMessageBox( _( "No symbol to export" ) );
846 return 0;
847 }
848
849 wxFileName fn( symbol->GetName() );
850 fn.SetExt( "png" );
851
852 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
853
854 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
855 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
856
858
859 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
860 {
861 // calling wxYield is mandatory under Linux, after closing the file selector dialog
862 // to refresh the screen before creating the PNG or JPEG image from screen
863 wxYield();
864
865 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
866 {
867 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
868 }
869 }
870
871 return 0;
872}
873
874
876{
877 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
878 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
879
880 return 0;
881}
882
883
885{
886 if( !m_isSymbolEditor )
887 return 0;
888
890 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
891
892 if( !symbol )
893 {
894 wxMessageBox( _( "No symbol to export" ) );
895 return 0;
896 }
897
898 wxFileName fn( symbol->GetName() );
899 fn.SetExt( FILEEXT::SVGFileExtension );
900
901 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
902
903 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
905 wxFD_SAVE,
906 m_frame );
907
908 if( !fullFileName.IsEmpty() )
909 {
910 // The symbol origin is kept at the SVG origin; the page/viewBox is sized to the symbol.
911 editFrame->SVGPlotSymbol( fullFileName );
912 }
913
914 return 0;
915}
916
917
919{
920 if( !m_isSymbolEditor )
921 return 0;
922
924 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
925 LIB_ID symId = editFrame->GetTargetLibId();
926
927 if( !symId.IsValid() )
928 {
929 wxMessageBox( _( "No symbol to flatten" ) );
930 return 0;
931 }
932
933 const LIB_SYMBOL* symbol = libMgr.GetBufferedSymbol( symId.GetLibItemName(), symId.GetLibNickname() );
934 std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->Flatten();
935 wxCHECK_MSG( flatSymbol, 0, _( "Failed to flatten symbol" ) );
936
937 if( !libMgr.UpdateSymbol( flatSymbol.get(), symId.GetLibNickname() ) )
938 {
939 wxMessageBox( _( "Failed to update library with flattened symbol" ) );
940 return 0;
941 }
942
943 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( symId );
944 editFrame->UpdateLibraryTree( treeItem, flatSymbol.get() );
945
946 return 0;
947}
948
949
951{
952 LIB_SYMBOL* libSymbol = nullptr;
953 LIB_ID libId;
954 int unit, bodyStyle;
955
956 if( m_isSymbolEditor )
957 {
959
960 libSymbol = editFrame->GetCurSymbol();
961 unit = editFrame->GetUnit();
962 bodyStyle = editFrame->GetBodyStyle();
963
964 if( libSymbol )
965 libId = libSymbol->GetLibId();
966 }
967 else
968 {
970
971 libSymbol = viewerFrame->GetSelectedSymbol();
972 unit = viewerFrame->GetUnit();
973 bodyStyle = viewerFrame->GetBodyStyle();
974
975 if( libSymbol )
976 libId = libSymbol->GetLibId();
977 }
978
979 if( libSymbol )
980 {
981 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
982
983 if( !schframe ) // happens when the schematic editor is not active (or closed)
984 {
985 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
986 return 0;
987 }
988
989 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
990
991 if( blocking_dialog )
992 {
993 blocking_dialog->Raise();
994 wxBell();
995 return 0;
996 }
997
998 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
999 unit, bodyStyle );
1000
1001 symbol->SetParent( schframe->GetScreen() );
1002
1003 if( schframe->eeconfig()->m_AutoplaceFields.enable )
1004 {
1005 // Not placed yet, so pass a nullptr screen reference
1006 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
1007 }
1008
1009 schframe->Raise();
1011 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
1012 }
1013
1014 return 0;
1015}
1016
1017
1019{
1020 if( !m_isSymbolEditor )
1021 return 0;
1022
1024 const int deltaUnit = aEvent.Parameter<int>();
1025
1026 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
1027 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
1028
1029 editFrame->SetUnit( newUnit );
1030
1031 return 0;
1032}
1033
1034
1036{
1037 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
1038 viewerFrame->SelectPreviousSymbol();
1039
1040 return 0;
1041}
1042
1043
1045{
1046 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
1047 viewerFrame->SelectNextSymbol();
1048
1049 return 0;
1050}
1051
1052
1054{
1056
1057 SCOPE scope = SCOPE::SCOPE_LIBRARY;
1058
1060 scope = SCOPE::SCOPE_RELATED_SYMBOLS;
1061
1063
1064 dlg.ShowModal();
1065 return 0;
1066}
1067
1068
1069static void showTabSwitcher( SYMBOL_EDIT_FRAME* aFrame, bool aForward )
1070{
1071 EDITOR_TABS_PANEL* panel = aFrame->GetTabsPanel();
1072
1073 if( !panel || panel->Model().Entries().size() < 2 )
1074 return;
1075
1076 if( !aFrame->GetHotkeyPopup() )
1077 aFrame->CreateHotkeyPopup();
1078
1079 HOTKEY_CYCLE_POPUP* popup = aFrame->GetHotkeyPopup();
1080
1081 if( !popup )
1082 return;
1083
1084 wxArrayString labels;
1085
1086 for( const EDITOR_TABS_MODEL::ENTRY& entry : panel->Model().Entries() )
1087 labels.Add( entry.key.AfterFirst( ':' ) );
1088
1089 const int count = static_cast<int>( labels.GetCount() );
1090 const int active = panel->GetActiveTab();
1091 const int next = aForward ? ( active + 1 ) % count : ( active - 1 + count ) % count;
1092
1093 popup->Popup( _( "Switch to Tab" ), labels, next );
1094}
1095
1096
1098{
1100
1101 if( editFrame && editFrame->GetTabsPanel() )
1102 {
1103 showTabSwitcher( editFrame, true );
1104 editFrame->GetTabsPanel()->AdvanceTab( true );
1105 }
1106
1107 return 0;
1108}
1109
1110
1112{
1114
1115 if( editFrame && editFrame->GetTabsPanel() )
1116 {
1117 showTabSwitcher( editFrame, false );
1118 editFrame->GetTabsPanel()->AdvanceTab( false );
1119 }
1120
1121 return 0;
1122}
1123
1124
1126{
1128
1129 if( editFrame && editFrame->GetTabsPanel() )
1130 editFrame->GetTabsPanel()->CloseTab( editFrame->GetTabsPanel()->GetActiveTab() );
1131
1132 return 0;
1133}
1134
1135
1137{
1139
1140 wxCHECK( editFrame, 0 );
1141
1142 const wxString currentLib = editFrame->GetTreeLIBID().GetLibNickname();
1143
1144 if( currentLib.IsEmpty() )
1145 {
1146 editFrame->ShowInfoBarError( _( "Select a library to compare against a file." ) );
1147 return 0;
1148 }
1149
1150 wxFileDialog dlg( editFrame, _( "Choose Library to Compare With" ), wxEmptyString,
1151 wxEmptyString, FILEEXT::KiCadSymbolLibFileWildcard(),
1152 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1153
1154 if( dlg.ShowModal() != wxID_OK )
1155 return 0;
1156
1157 wxFileName otherFn( dlg.GetPath() );
1158 otherFn.MakeAbsolute();
1159
1160 if( !otherFn.GetExt().IsSameAs( FILEEXT::KiCadSymbolLibFileExtension, false ) )
1161 {
1162 editFrame->ShowInfoBarError(
1163 _( "Select a KiCad symbol library file (.kicad_sym)." ) );
1164 return 0;
1165 }
1166
1167 const wxString otherPath = otherFn.GetFullPath();
1168
1169 // SYM_LIB_DIFFER::Diff() consumes these borrowed pointers synchronously;
1170 // DOCUMENT_DIFF does not retain them.
1171 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
1172 wxArrayString names;
1173 libMgr.GetSymbolNames( currentLib, names );
1174
1176
1177 for( const wxString& name : names )
1178 {
1179 if( LIB_SYMBOL* sym = libMgr.GetSymbol( name, currentLib ) )
1180 beforeMap.emplace( sym->GetName(), sym );
1181 }
1182
1183 std::vector<std::unique_ptr<LIB_SYMBOL>> afterStorage;
1185
1186 try
1187 {
1188 auto loaded = KICAD_DIFF::SYM_LIB_DIFFER::LoadLibrary( otherPath );
1189 afterStorage = std::move( loaded.first );
1190 afterMap = std::move( loaded.second );
1191 }
1192 catch( const IO_ERROR& ioe )
1193 {
1194 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1195 otherPath, ioe.What() ) );
1196 return 0;
1197 }
1198 catch( const std::exception& e )
1199 {
1200 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1201 otherPath,
1202 wxString::FromUTF8( e.what() ) ) );
1203 return 0;
1204 }
1205
1206 KICAD_DIFF::SYM_LIB_DIFFER differ( beforeMap, afterMap, otherPath );
1208
1209 auto cloneHolder = std::make_shared<std::vector<std::unique_ptr<LIB_SYMBOL>>>();
1210
1211 DIALOG_KICAD_DIFF dlgDiff( editFrame, currentLib, otherPath, result );
1212
1213 std::map<KIID_PATH, const KICAD_DIFF::ITEM_CHANGE*> changesById;
1214
1215 for( const KICAD_DIFF::ITEM_CHANGE& c : result.changes )
1216 changesById[c.id] = &c;
1217
1218 dlgDiff.SetChangeSelectedHandler(
1219 [&, cloneHolder]( const KIID_PATH& aId )
1220 {
1221 WIDGET_DIFF_CANVAS* canvas = dlgDiff.DiffCanvas();
1222
1223 if( !canvas )
1224 return;
1225
1226 auto it = changesById.find( aId );
1227
1228 if( it == changesById.end() || !it->second->refdes )
1229 {
1230 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, nullptr, nullptr );
1231 cloneHolder->clear();
1232 return;
1233 }
1234
1235 const wxString& name = *it->second->refdes;
1236 auto beforeIt = beforeMap.find( name );
1237 auto afterIt = afterMap.find( name );
1238
1239 std::unique_ptr<LIB_SYMBOL> beforeClone =
1240 beforeIt != beforeMap.end() ? beforeIt->second->Flatten() : nullptr;
1241 std::unique_ptr<LIB_SYMBOL> afterClone =
1242 afterIt != afterMap.end() ? afterIt->second->Flatten() : nullptr;
1243
1244 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, beforeClone.get(), afterClone.get() );
1245
1246 cloneHolder->clear();
1247
1248 if( beforeClone )
1249 cloneHolder->push_back( std::move( beforeClone ) );
1250
1251 if( afterClone )
1252 cloneHolder->push_back( std::move( afterClone ) );
1253 } );
1254
1255 dlgDiff.ShowModal();
1256
1257 return 0;
1258}
1259
1260
1262{
1270
1272
1281
1289
1291
1295
1298
1302
1306
1311
1314
1317
1320
1323}
const char * name
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.
File-compare dialog (Phase 7).
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:153
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:1743
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:680
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< 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.
static wxString ExpandURI(const wxString &aShortURI, const PROJECT &aProject)
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:114
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:190
bool IsDerived() const
Definition lib_symbol.h:241
wxString GetName() const override
Definition lib_symbol.h:183
SCH_FIELD & GetValueField()
Definition lib_symbol.h:447
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)
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition pgm_base.cpp:216
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:125
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static TOOL_ACTION editSymbol
static TOOL_ACTION importSymbol
static TOOL_ACTION newSymbol
static TOOL_ACTION saveLibraryAsPacked
static TOOL_ACTION saveLibraryAs
static TOOL_ACTION previousSymbol
static TOOL_ACTION showRelatedLibFieldsTable
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION saveLibraryAsUnpacked
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:72
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()
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:139
void SetText(const wxString &aText) override
Schematic symbol object.
Definition sch_symbol.h:73
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)
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
Return true if aLibId is an alias for the editor screen symbol.
void SVGPlotSymbol(const wxString &aFullFileName)
Create the SVG print file for the current edited symbol.
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.
void FocusOnLibId(const LIB_ID &aLibID)
void SaveLibraryAs(SAVE_LIBRARY_AS aSaveType=SAVE_LIBRARY_AS::NEW)
Save the currently selected library to a new file.
void Save()
Save the selected symbol or library.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
int GetTreeSelectionCount() const
bool IsSymbolFromSchematic() const
SYMBOL_EDITOR_SETTINGS * GetSettings() 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.
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 ToggleLibraryTree() override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
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)
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.
bool HasDerivedSymbols(const wxString &aSymbolName, const wxString &aLibraryName)
Check whether any symbol inherits from aSymbolName, without building the list of names.
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:484
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.
LIB_FIELDS_EDITOR_GRID_DATA_MODEL::SCOPE SCOPE
#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:166
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:533
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:75
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.
@ NEW
Save to a new library in the original symbol library format.
@ UNPACKED
Save a packed symbol library to the unpacked format.
@ PACKED
Save an unpacked symbol library to the packed format.
static void showTabSwitcher(SYMBOL_EDIT_FRAME *aFrame, bool aForward)
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.