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