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::LAYERS | KIGFX::GEOMETRY | 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::LAYERS | KIGFX::GEOMETRY | 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
797 m_frame->GetCanvas()->Refresh();
798 return 0;
799}
800
801
803{
804 if( !m_isSymbolEditor )
805 return 0;
806
807 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
809
811
813 m_frame->GetCanvas()->Refresh();
814 return 0;
815}
816
817
819{
820 if( !m_isSymbolEditor )
821 return 0;
822
823 SYMBOL_EDITOR_SETTINGS& cfg = *m_frame->libeditconfig();
825
826 m_frame->GetRenderSettings()->m_ShowPinAltIcons = cfg.m_ShowPinAltIcons;
827
829 m_frame->GetCanvas()->Refresh();
830 return 0;
831}
832
833
835{
836 if( !m_isSymbolEditor )
837 return 0;
838
840 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
841
842 if( !symbol )
843 {
844 wxMessageBox( _( "No symbol to export" ) );
845 return 0;
846 }
847
848 wxFileName fn( symbol->GetName() );
849 fn.SetExt( "png" );
850
851 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
852
853 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
854 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
855
857
858 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
859 {
860 // calling wxYield is mandatory under Linux, after closing the file selector dialog
861 // to refresh the screen before creating the PNG or JPEG image from screen
862 wxYield();
863
864 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
865 {
866 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
867 }
868 }
869
870 return 0;
871}
872
873
875{
876 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
877 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
878
879 return 0;
880}
881
882
884{
885 if( !m_isSymbolEditor )
886 return 0;
887
889 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
890
891 if( !symbol )
892 {
893 wxMessageBox( _( "No symbol to export" ) );
894 return 0;
895 }
896
897 wxFileName fn( symbol->GetName() );
898 fn.SetExt( FILEEXT::SVGFileExtension );
899
900 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
901
902 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
904 wxFD_SAVE,
905 m_frame );
906
907 if( !fullFileName.IsEmpty() )
908 {
909 // The symbol origin is kept at the SVG origin; the page/viewBox is sized to the symbol.
910 editFrame->SVGPlotSymbol( fullFileName );
911 }
912
913 return 0;
914}
915
916
918{
919 if( !m_isSymbolEditor )
920 return 0;
921
923 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
924 LIB_ID symId = editFrame->GetTargetLibId();
925
926 if( !symId.IsValid() )
927 {
928 wxMessageBox( _( "No symbol to flatten" ) );
929 return 0;
930 }
931
932 const LIB_SYMBOL* symbol = libMgr.GetBufferedSymbol( symId.GetLibItemName(), symId.GetLibNickname() );
933 std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->Flatten();
934 wxCHECK_MSG( flatSymbol, 0, _( "Failed to flatten symbol" ) );
935
936 if( !libMgr.UpdateSymbol( flatSymbol.get(), symId.GetLibNickname() ) )
937 {
938 wxMessageBox( _( "Failed to update library with flattened symbol" ) );
939 return 0;
940 }
941
942 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( symId );
943 editFrame->UpdateLibraryTree( treeItem, flatSymbol.get() );
944
945 return 0;
946}
947
948
950{
951 LIB_SYMBOL* libSymbol = nullptr;
952 LIB_ID libId;
953 int unit, bodyStyle;
954
955 if( m_isSymbolEditor )
956 {
958
959 libSymbol = editFrame->GetCurSymbol();
960 unit = editFrame->GetUnit();
961 bodyStyle = editFrame->GetBodyStyle();
962
963 if( libSymbol )
964 libId = libSymbol->GetLibId();
965 }
966 else
967 {
969
970 libSymbol = viewerFrame->GetSelectedSymbol();
971 unit = viewerFrame->GetUnit();
972 bodyStyle = viewerFrame->GetBodyStyle();
973
974 if( libSymbol )
975 libId = libSymbol->GetLibId();
976 }
977
978 if( libSymbol )
979 {
980 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
981
982 if( !schframe ) // happens when the schematic editor is not active (or closed)
983 {
984 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
985 return 0;
986 }
987
988 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
989
990 if( blocking_dialog )
991 {
992 blocking_dialog->Raise();
993 wxBell();
994 return 0;
995 }
996
997 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
998 unit, bodyStyle );
999
1000 symbol->SetParent( schframe->GetScreen() );
1001
1002 if( schframe->eeconfig()->m_AutoplaceFields.enable )
1003 {
1004 // Not placed yet, so pass a nullptr screen reference
1005 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
1006 }
1007
1008 schframe->Raise();
1010 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
1011 }
1012
1013 return 0;
1014}
1015
1016
1018{
1019 if( !m_isSymbolEditor )
1020 return 0;
1021
1023 const int deltaUnit = aEvent.Parameter<int>();
1024
1025 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
1026 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
1027
1028 editFrame->SetUnit( newUnit );
1029
1030 return 0;
1031}
1032
1033
1035{
1036 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
1037 viewerFrame->SelectPreviousSymbol();
1038
1039 return 0;
1040}
1041
1042
1044{
1045 if( SYMBOL_VIEWER_FRAME* viewerFrame = static_cast<SYMBOL_VIEWER_FRAME*>( m_toolMgr->GetToolHolder() ) )
1046 viewerFrame->SelectNextSymbol();
1047
1048 return 0;
1049}
1050
1051
1053{
1055
1056 SCOPE scope = SCOPE::SCOPE_LIBRARY;
1057
1059 scope = SCOPE::SCOPE_RELATED_SYMBOLS;
1060
1062
1063 dlg.ShowModal();
1064 return 0;
1065}
1066
1067
1068static void showTabSwitcher( SYMBOL_EDIT_FRAME* aFrame, bool aForward )
1069{
1070 EDITOR_TABS_PANEL* panel = aFrame->GetTabsPanel();
1071
1072 if( !panel || panel->Model().Entries().size() < 2 )
1073 return;
1074
1075 if( !aFrame->GetHotkeyPopup() )
1076 aFrame->CreateHotkeyPopup();
1077
1078 HOTKEY_CYCLE_POPUP* popup = aFrame->GetHotkeyPopup();
1079
1080 if( !popup )
1081 return;
1082
1083 wxArrayString labels;
1084
1085 for( const EDITOR_TABS_MODEL::ENTRY& entry : panel->Model().Entries() )
1086 labels.Add( entry.key.AfterFirst( ':' ) );
1087
1088 const int count = static_cast<int>( labels.GetCount() );
1089 const int active = panel->GetActiveTab();
1090 const int next = aForward ? ( active + 1 ) % count : ( active - 1 + count ) % count;
1091
1092 popup->Popup( _( "Switch to Tab" ), labels, next );
1093}
1094
1095
1097{
1099
1100 if( editFrame && editFrame->GetTabsPanel() )
1101 {
1102 showTabSwitcher( editFrame, true );
1103 editFrame->GetTabsPanel()->AdvanceTab( true );
1104 }
1105
1106 return 0;
1107}
1108
1109
1111{
1113
1114 if( editFrame && editFrame->GetTabsPanel() )
1115 {
1116 showTabSwitcher( editFrame, false );
1117 editFrame->GetTabsPanel()->AdvanceTab( false );
1118 }
1119
1120 return 0;
1121}
1122
1123
1125{
1127
1128 if( editFrame && editFrame->GetTabsPanel() )
1129 editFrame->GetTabsPanel()->CloseTab( editFrame->GetTabsPanel()->GetActiveTab() );
1130
1131 return 0;
1132}
1133
1134
1136{
1138
1139 wxCHECK( editFrame, 0 );
1140
1141 const wxString currentLib = editFrame->GetTreeLIBID().GetLibNickname();
1142
1143 if( currentLib.IsEmpty() )
1144 {
1145 editFrame->ShowInfoBarError( _( "Select a library to compare against a file." ) );
1146 return 0;
1147 }
1148
1149 wxFileDialog dlg( editFrame, _( "Choose Library to Compare With" ), wxEmptyString,
1150 wxEmptyString, FILEEXT::KiCadSymbolLibFileWildcard(),
1151 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1152
1153 if( dlg.ShowModal() != wxID_OK )
1154 return 0;
1155
1156 wxFileName otherFn( dlg.GetPath() );
1157 otherFn.MakeAbsolute();
1158
1159 if( !otherFn.GetExt().IsSameAs( FILEEXT::KiCadSymbolLibFileExtension, false ) )
1160 {
1161 editFrame->ShowInfoBarError(
1162 _( "Select a KiCad symbol library file (.kicad_sym)." ) );
1163 return 0;
1164 }
1165
1166 const wxString otherPath = otherFn.GetFullPath();
1167
1168 // SYM_LIB_DIFFER::Diff() consumes these borrowed pointers synchronously;
1169 // DOCUMENT_DIFF does not retain them.
1170 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
1171 wxArrayString names;
1172 libMgr.GetSymbolNames( currentLib, names );
1173
1175
1176 for( const wxString& name : names )
1177 {
1178 if( LIB_SYMBOL* sym = libMgr.GetSymbol( name, currentLib ) )
1179 beforeMap.emplace( sym->GetName(), sym );
1180 }
1181
1182 std::vector<std::unique_ptr<LIB_SYMBOL>> afterStorage;
1184
1185 try
1186 {
1187 auto loaded = KICAD_DIFF::SYM_LIB_DIFFER::LoadLibrary( otherPath );
1188 afterStorage = std::move( loaded.first );
1189 afterMap = std::move( loaded.second );
1190 }
1191 catch( const IO_ERROR& ioe )
1192 {
1193 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1194 otherPath, ioe.What() ) );
1195 return 0;
1196 }
1197 catch( const std::exception& e )
1198 {
1199 editFrame->ShowInfoBarError( wxString::Format( _( "Failed to load %s: %s" ),
1200 otherPath,
1201 wxString::FromUTF8( e.what() ) ) );
1202 return 0;
1203 }
1204
1205 KICAD_DIFF::SYM_LIB_DIFFER differ( beforeMap, afterMap, otherPath );
1207
1208 auto cloneHolder = std::make_shared<std::vector<std::unique_ptr<LIB_SYMBOL>>>();
1209
1210 DIALOG_KICAD_DIFF dlgDiff( editFrame, currentLib, otherPath, result );
1211
1212 std::map<KIID_PATH, const KICAD_DIFF::ITEM_CHANGE*> changesById;
1213
1214 for( const KICAD_DIFF::ITEM_CHANGE& c : result.changes )
1215 changesById[c.id] = &c;
1216
1217 dlgDiff.SetChangeSelectedHandler(
1218 [&, cloneHolder]( const KIID_PATH& aId )
1219 {
1220 WIDGET_DIFF_CANVAS* canvas = dlgDiff.DiffCanvas();
1221
1222 if( !canvas )
1223 return;
1224
1225 auto it = changesById.find( aId );
1226
1227 if( it == changesById.end() || !it->second->refdes )
1228 {
1229 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, nullptr, nullptr );
1230 cloneHolder->clear();
1231 return;
1232 }
1233
1234 const wxString& name = *it->second->refdes;
1235 auto beforeIt = beforeMap.find( name );
1236 auto afterIt = afterMap.find( name );
1237
1238 std::unique_ptr<LIB_SYMBOL> beforeClone =
1239 beforeIt != beforeMap.end() ? beforeIt->second->Flatten() : nullptr;
1240 std::unique_ptr<LIB_SYMBOL> afterClone =
1241 afterIt != afterMap.end() ? afterIt->second->Flatten() : nullptr;
1242
1243 KICAD_DIFF::ConfigureSymDiffCanvasContext( *canvas, beforeClone.get(), afterClone.get() );
1244
1245 cloneHolder->clear();
1246
1247 if( beforeClone )
1248 cloneHolder->push_back( std::move( beforeClone ) );
1249
1250 if( afterClone )
1251 cloneHolder->push_back( std::move( afterClone ) );
1252 } );
1253
1254 dlgDiff.ShowModal();
1255
1256 return 0;
1257}
1258
1259
1261{
1269
1271
1280
1288
1290
1294
1297
1301
1305
1310
1313
1316
1319
1322}
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:2475
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:693
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:233
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:75
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
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
@ LAYERS
Layers have changed.
Definition view_item.h:52
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:640
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.