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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26
27#include <advanced_config.h>
29#include <confirm.h>
31#include <gestfich.h> // To open with a text editor
32#include <kidialog.h>
33#include <kiway.h>
34#include <launch_ext.h> // To default when file manager setting is empty
36#include <pgm_base.h>
37#include <sch_painter.h>
38#include <string_utils.h>
40#include <symbol_lib_table.h>
42#include <symbol_viewer_frame.h>
44#include <tool/tool_manager.h>
45#include <tools/sch_actions.h>
47
48#include <wx/filedlg.h>
49
50
52{
56
58 {
59 LIBRARY_EDITOR_CONTROL* libraryTreeTool = m_toolMgr->GetTool<LIBRARY_EDITOR_CONTROL>();
60 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
61
62 auto libSelectedCondition =
63 [this]( const SELECTION& aSel )
64 {
66 {
67 LIB_ID sel = editFrame->GetTreeLIBID();
68 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
69 }
70
71 return false;
72 };
73
74 // The libInferredCondition allows you to do things like New Symbol and Paste with a
75 // symbol selected (in other words, when we know the library context even if the library
76 // itself isn't selected.
77 auto libInferredCondition =
78 [this]( const SELECTION& aSel )
79 {
81 {
82 LIB_ID sel = editFrame->GetTreeLIBID();
83 return !sel.GetLibNickname().empty();
84 }
85
86 return false;
87 };
88
89 auto symbolSelectedCondition =
90 [this]( const SELECTION& aSel )
91 {
93 {
94 LIB_ID sel = editFrame->GetTargetLibId();
95 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
96 }
97
98 return false;
99 };
100
101 auto derivedSymbolSelectedCondition =
102 [this]( const SELECTION& aSel )
103 {
105 {
106 LIB_ID sel = editFrame->GetTargetLibId();
107
108 if( sel.GetLibNickname().empty() || sel.GetLibItemName().empty() )
109 return false;
110
111 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
112 const LIB_SYMBOL* sym = libMgr.GetSymbol( sel.GetLibItemName(), sel.GetLibNickname() );
113
114 return sym && sym->IsDerived();
115 }
116
117 return false;
118 };
119
120 auto multiSymbolSelectedCondition =
121 [this]( const SELECTION& aSel )
122 {
124
125 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
126 {
127 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
128 {
129 if( !sel.IsValid() )
130 return false;
131 }
132
133 return true;
134 }
135
136 return false;
137 };
138/* not used, yet
139 auto multiLibrarySelectedCondition =
140 [this]( const SELECTION& aSel )
141 {
142 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
143
144 if( editFrame && editFrame->GetTreeSelectionCount() > 1 )
145 {
146 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
147 {
148 if( sel.IsValid() )
149 return false;
150 }
151
152 return true;
153 }
154
155 return false;
156 };
157*/
158 auto canOpenExternally =
159 [this]( const SELECTION& aSel )
160 {
161 // The option is shown if the lib has no current edits
163 {
164 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
165 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
166 return !libMgr.IsLibraryModified( libName );
167 }
168
169 return false;
170 };
171
172
173// clang-format off
174 ctxMenu.AddItem( SCH_ACTIONS::newSymbol, libInferredCondition, 10 );
175 ctxMenu.AddItem( SCH_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
176
177 ctxMenu.AddSeparator( 10 );
178 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
179 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
180 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolAs, symbolSelectedCondition, 10 );
181 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
182 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
183
184 ctxMenu.AddSeparator( 10 );
185 ctxMenu.AddItem( SCH_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
186 ctxMenu.AddItem( SCH_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
187 ctxMenu.AddItem( SCH_ACTIONS::pasteSymbol, libInferredCondition, 10 );
188 ctxMenu.AddItem( SCH_ACTIONS::duplicateSymbol, symbolSelectedCondition, 10 );
189 ctxMenu.AddItem( SCH_ACTIONS::renameSymbol, symbolSelectedCondition, 10 );
190 ctxMenu.AddItem( SCH_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
191
192 ctxMenu.AddSeparator( 20 );
193 ctxMenu.AddItem( SCH_ACTIONS::flattenSymbol, derivedSymbolSelectedCondition, 20 );
194
195 ctxMenu.AddSeparator( 100 );
196 ctxMenu.AddItem( SCH_ACTIONS::importSymbol, libInferredCondition, 100 );
197 ctxMenu.AddItem( SCH_ACTIONS::exportSymbol, symbolSelectedCondition );
198
199
200 if( ADVANCED_CFG::GetCfg().m_EnableLibWithText )
201 {
202 ctxMenu.AddSeparator( 200 );
203 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
204 }
205
206 if( ADVANCED_CFG::GetCfg().m_EnableLibDir )
207 {
208 ctxMenu.AddSeparator( 200 );
209 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
210 }
211
212 ctxMenu.AddItem( ACTIONS::showLibraryFieldsTable, libInferredCondition, 300 );
213 ctxMenu.AddItem( ACTIONS::showRelatedLibraryFieldsTable, symbolSelectedCondition, 300 );
214
215 libraryTreeTool->AddContextMenuItems( &ctxMenu );
216 }
217// clang-format on
218
219 return true;
220}
221
222
224{
225 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
226
227 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
228 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
229
230 return 0;
231}
232
233
235{
236 wxString libFile = *aEvent.Parameter<wxString*>();
237
238 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
239 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
240
241 return 0;
242}
243
244
246{
247 if( !m_isSymbolEditor )
248 return 0;
249
251 int unit = 0;
252 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
253
254 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
255 return 0;
256}
257
258
260{
262 const LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
263
264 if( !symbol || !editFrame->IsSymbolFromSchematic() )
265 {
266 wxBell();
267 return 0;
268 }
269
270 const LIB_ID& libId = symbol->GetLibId();
271
272 if( editFrame->LoadSymbol( libId, editFrame->GetUnit(), editFrame->GetBodyStyle() ) )
273 {
274 if( !editFrame->IsLibraryTreeShown() )
275 editFrame->ToggleLibraryTree();
276 }
277 else
278 {
279 const wxString libName = libId.GetLibNickname();
280 const wxString symbolName = libId.GetLibItemName();
281
282 DisplayError( editFrame,
283 wxString::Format( _( "Failed to load symbol %s from "
284 "library %s." ),
285 UnescapeString( symbolName ), UnescapeString( libName ) ) );
286 }
287 return 0;
288}
289
290
292{
293 if( !m_isSymbolEditor )
294 return 0;
295
297 LIB_ID target = editFrame->GetTargetLibId();
298 const wxString& libName = target.GetLibNickname();
299 wxString msg;
300
301 if( libName.IsEmpty() )
302 {
303 msg.Printf( _( "No symbol library selected." ) );
304 m_frame->ShowInfoBarError( msg );
305 return 0;
306 }
307
308 if( !editFrame->GetLibManager().LibraryExists( libName ) )
309 {
310 msg.Printf( _( "Symbol library '%s' not found." ), libName );
311 m_frame->ShowInfoBarError( msg );
312 return 0;
313 }
314
315 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
316 {
317 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
318 m_frame->ShowInfoBarError( msg );
319 return 0;
320 }
321
322 if( aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
323 editFrame->CreateNewSymbol();
325 editFrame->CreateNewSymbol( target.GetLibItemName() );
326 else if( aEvent.IsAction( &SCH_ACTIONS::importSymbol ) )
327 editFrame->ImportSymbol();
328
329 return 0;
330}
331
332
334{
335 if( !m_isSymbolEditor )
336 return 0;
337
339
340 if( aEvt.IsAction( &SCH_ACTIONS::save ) )
341 editFrame->Save();
342 else if( aEvt.IsAction( &SCH_ACTIONS::saveLibraryAs ) )
343 editFrame->SaveLibraryAs();
344 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolAs ) )
345 editFrame->SaveSymbolCopyAs( true );
346 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolCopyAs ) )
347 editFrame->SaveSymbolCopyAs( false );
348 else if( aEvt.IsAction( &SCH_ACTIONS::saveAll ) )
349 editFrame->SaveAll();
350
351 return 0;
352}
353
354
356{
357 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
358 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
359
360 return 0;
361}
362
363
365{
366 if( !m_isSymbolEditor )
367 return 0;
368
370 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
371
372 LIB_ID libId = editFrame->GetTreeLIBID();
373
374 wxString libName = libId.GetLibNickname();
375 wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
376
377 wxFileName fileName( libItemName );
378
379 wxString filePath = wxEmptyString;
380 wxString explorerCommand;
381
382 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
383 explorerCommand = cfg->m_System.file_explorer;
384
385 if( explorerCommand.IsEmpty() )
386 {
387 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
388
389 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
390 LaunchExternal( filePath );
391
392 return 0;
393 }
394
395 if( !explorerCommand.EndsWith( "%F" ) )
396 {
397 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
398 return 0;
399 }
400
401 filePath = fileName.GetFullPath();
402 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
403
404 wxString fileArg = '"' + filePath + '"';
405
406 explorerCommand.Replace( wxT( "%F" ), fileArg );
407
408 if( !explorerCommand.IsEmpty() )
409 wxExecute( explorerCommand );
410
411 return 0;
412}
413
414
416{
417 if( !m_isSymbolEditor )
418 return 0;
419
421 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
422 wxString textEditorName = Pgm().GetTextEditor();
423
424 if( textEditorName.IsEmpty() )
425 {
426 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
427 return 0;
428 }
429
430 LIB_ID libId = editFrame->GetTreeLIBID();
431 wxString libName = libId.GetLibNickname();
432 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
433
434 if( !tempFName.IsEmpty() )
435 ExecuteFile( textEditorName, tempFName, nullptr, false );
436
437 return 0;
438}
439
440
442{
443 if( !m_isSymbolEditor )
444 return 0;
445
447
449 editFrame->CopySymbolToClipboard();
450
452 {
453 bool hasWritableLibs = false;
454 wxString msg;
455
456 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
457 {
458 const wxString& libName = sel.GetLibNickname();
459
460 if( !editFrame->GetLibManager().LibraryExists( libName ) )
461 msg.Printf( _( "Symbol library '%s' not found." ), libName );
462 else if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
463 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
464 else
465 hasWritableLibs = true;
466 }
467
468 if( !msg.IsEmpty() )
469 m_frame->ShowInfoBarError( msg );
470
471 if( !hasWritableLibs )
472 return 0;
473
474 editFrame->DeleteSymbolFromLibrary();
475 }
476
477 return 0;
478}
479
480
482{
483 if( !m_isSymbolEditor )
484 return 0;
485
487 LIB_ID sel = editFrame->GetTargetLibId();
488 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
489 // saved symbol in clipboard
490 bool isPasteAction = aEvent.IsAction( &SCH_ACTIONS::pasteSymbol );
491 wxString msg;
492
493 if( !sel.IsValid() && !isPasteAction )
494 {
495 // When duplicating a symbol, a source symbol must exists.
496 msg.Printf( _( "No symbol selected" ) );
497 m_frame->ShowInfoBarError( msg );
498 return 0;
499 }
500
501 const wxString& libName = sel.GetLibNickname();
502
503 if( !editFrame->GetLibManager().LibraryExists( libName ) )
504 {
505 msg.Printf( _( "Symbol library '%s' not found." ), libName );
506 m_frame->ShowInfoBarError( msg );
507 return 0;
508 }
509
510 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
511 {
512 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
513 m_frame->ShowInfoBarError( msg );
514 return 0;
515 }
516
517 editFrame->DuplicateSymbol( isPasteAction );
518 return 0;
519}
520
521
523{
524 if( !m_isSymbolEditor )
525 return 0;
526
528 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
530
531 LIB_ID libId = editFrame->GetTreeLIBID();
532 wxString libName = libId.GetLibNickname();
533 wxString oldName = libId.GetLibItemName();
534 wxString newName;
535 wxString msg;
536
537 if( !libMgr.LibraryExists( libName ) )
538 return 0;
539
540 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
541 [&]( const wxString& aNewName )
542 {
543 newName = EscapeString( aNewName, CTX_LIBID );
544
545 if( newName.IsEmpty() )
546 {
547 wxMessageBox( _( "Symbol must have a name." ) );
548 return false;
549 }
550
551 // If no change, accept it without prompting
552 if( newName != oldName && libMgr.SymbolNameInUse( newName, libName ) )
553 {
554 msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
555 UnescapeString( newName ),
556 libName );
557
558 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
559 wxOK | wxCANCEL | wxICON_WARNING );
560
561 errorDlg.SetOKLabel( _( "Overwrite" ) );
562
563 return errorDlg.ShowModal() == wxID_OK;
564 }
565
566 return true;
567 } ) )
568 {
569 return 0; // cancelled by user
570 }
571
572 if( newName == oldName )
573 return 0;
574
575 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
576
577 if( !libSymbol )
578 return 0;
579
580 // Renaming the current symbol
581 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
582 bool overwritingCurrentSymbol = false;
583
584 if( libMgr.SymbolExists( newName, libName ) )
585 {
586 // Overwriting the current symbol also need to update the open symbol
587 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
588 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
589 libMgr.RemoveSymbol( newName, libName );
590 }
591
592 libSymbol->SetName( newName );
593
594 if( libSymbol->GetValueField().GetText() == oldName )
595 libSymbol->GetValueField().SetText( newName );
596
597 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
598 libMgr.SetSymbolModified( newName, libName );
599
600 if( overwritingCurrentSymbol )
601 {
602 // We overwrite the old current symbol with the renamed one, so show
603 // the renamed one now
604 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
605 }
606 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
607 {
608 // Renamed the current symbol - follow it
609 libSymbol = editFrame->GetCurSymbol();
610
611 libSymbol->SetName( newName );
612
613 if( libSymbol->GetValueField().GetText() == oldName )
614 libSymbol->GetValueField().SetText( newName );
615
616 editFrame->RebuildView();
617 editFrame->OnModify();
618 editFrame->UpdateTitle();
619
620 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
621 // invalidate the view pointers by rebuilting the field table
622 editFrame->UpdateMsgPanel();
623 }
624
625 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
626 editFrame->UpdateLibraryTree( treeItem, libSymbol );
627 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
628 return 0;
629}
630
631
639
640
642{
643 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
644 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
645
646 // Update canvas
647 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
648 m_frame->GetCanvas()->Refresh();
649
650 return 0;
651}
652
653
655{
656 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
657 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
658
659 // Update canvas
660 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
661 m_frame->GetCanvas()->Refresh();
662
663 return 0;
664}
665
666
668{
669 if( !m_isSymbolEditor )
670 return 0;
671
673 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
674
675 return 0;
676}
677
678
680{
681 if( !m_isSymbolEditor )
682 return 0;
683
684 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
686
688 cfg->m_ShowHiddenPins;
689
691 m_frame->GetCanvas()->Refresh();
692 return 0;
693}
694
695
697{
698 if( !m_isSymbolEditor )
699 return 0;
700
701 SYMBOL_EDITOR_SETTINGS* cfg = m_frame->libeditconfig();
703
704 // TODO: Why is this needed in symbol edit and not in schematic edit?
707
709 m_frame->GetCanvas()->Refresh();
710 return 0;
711}
712
713
715{
716 if( !m_isSymbolEditor )
717 return 0;
718
719 SYMBOL_EDITOR_SETTINGS& cfg = *m_frame->libeditconfig();
721
722 m_frame->GetRenderSettings()->m_ShowPinAltIcons = cfg.m_ShowPinAltIcons;
723
725 m_frame->GetCanvas()->Refresh();
726 return 0;
727}
728
729
731{
732 if( !m_isSymbolEditor )
733 return 0;
734
736 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
737
738 if( !symbol )
739 {
740 wxMessageBox( _( "No symbol to export" ) );
741 return 0;
742 }
743
744 wxFileName fn( symbol->GetName() );
745 fn.SetExt( "png" );
746
747 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
748
749 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
750 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
751
752 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
753 {
754 // calling wxYield is mandatory under Linux, after closing the file selector dialog
755 // to refresh the screen before creating the PNG or JPEG image from screen
756 wxYield();
757
758 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
759 {
760 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
761 }
762 }
763
764 return 0;
765}
766
767
769{
770 if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
771 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
772
773 return 0;
774}
775
776
778{
779 if( !m_isSymbolEditor )
780 return 0;
781
783 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
784
785 if( !symbol )
786 {
787 wxMessageBox( _( "No symbol to export" ) );
788 return 0;
789 }
790
791 wxFileName fn( symbol->GetName() );
792 fn.SetExt( FILEEXT::SVGFileExtension );
793
794 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
795
796 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
798 wxFD_SAVE,
799 m_frame );
800
801 if( !fullFileName.IsEmpty() )
802 {
803 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
804 PAGE_INFO pageTemp = pageSave;
805
806 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
807 editFrame->GetBodyStyle(), false );
808
809 // Add a small margin (10% of size)to the plot bounding box
810 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
811
812 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
813 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
814
815 // Add an offet to plot the symbol centered on the page.
816 VECTOR2I plot_offset = symbolBBox.GetOrigin();
817
818 editFrame->GetScreen()->SetPageSettings( pageTemp );
819 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
820 editFrame->GetScreen()->SetPageSettings( pageSave );
821 }
822
823 return 0;
824}
825
826
828{
829 if( !m_isSymbolEditor )
830 return 0;
831
833 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
834 LIB_ID symId = editFrame->GetTargetLibId();
835
836 if( !symId.IsValid() )
837 {
838 wxMessageBox( _( "No symbol to flatten" ) );
839 return 0;
840 }
841
842 const LIB_SYMBOL* symbol = libMgr.GetBufferedSymbol( symId.GetLibItemName(), symId.GetLibNickname() );
843 std::unique_ptr<LIB_SYMBOL> flatSymbol = symbol->Flatten();
844 wxCHECK_MSG( flatSymbol, 0, _( "Failed to flatten symbol" ) );
845
846 if( !libMgr.UpdateSymbol( flatSymbol.get(), symId.GetLibNickname() ) )
847 {
848 wxMessageBox( _( "Failed to update library with flattened symbol" ) );
849 return 0;
850 }
851
852 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( symId );
853 editFrame->UpdateLibraryTree( treeItem, flatSymbol.get() );
854
855 return 0;
856}
857
858
860{
861 LIB_SYMBOL* libSymbol = nullptr;
862 LIB_ID libId;
863 int unit, bodyStyle;
864
865 if( m_isSymbolEditor )
866 {
868
869 libSymbol = editFrame->GetCurSymbol();
870 unit = editFrame->GetUnit();
871 bodyStyle = editFrame->GetBodyStyle();
872
873 if( libSymbol )
874 libId = libSymbol->GetLibId();
875 }
876 else
877 {
879
880 libSymbol = viewerFrame->GetSelectedSymbol();
881 unit = viewerFrame->GetUnit();
882 bodyStyle = viewerFrame->GetBodyStyle();
883
884 if( libSymbol )
885 libId = libSymbol->GetLibId();
886 }
887
888 if( libSymbol )
889 {
890 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
891
892 if( !schframe ) // happens when the schematic editor is not active (or closed)
893 {
894 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
895 return 0;
896 }
897
898 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
899
900 if( blocking_dialog )
901 {
902 blocking_dialog->Raise();
903 wxBell();
904 return 0;
905 }
906
907 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
908 unit, bodyStyle );
909
910 symbol->SetParent( schframe->GetScreen() );
911
912 if( schframe->eeconfig()->m_AutoplaceFields.enable )
913 {
914 // Not placed yet, so pass a nullptr screen reference
915 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
916 }
917
918 schframe->Raise();
920 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
921 }
922
923 return 0;
924}
925
926
928{
929 if( !m_isSymbolEditor )
930 return 0;
931
933 const int deltaUnit = aEvent.Parameter<int>();
934
935 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
936 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
937
938 editFrame->SetUnit( newUnit );
939
940 return 0;
941}
942
943
956
957
959{
960 // clang-format off
968
970
977
985
987
990
994
998
1003
1006
1009 // clang-format on
1010}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
static TOOL_ACTION showLibraryFieldsTable
Definition actions.h:267
static TOOL_ACTION openWithTextEditor
Definition actions.h:68
static TOOL_ACTION revert
Definition actions.h:62
static TOOL_ACTION addLibrary
Definition actions.h:56
static TOOL_ACTION openDirectory
Definition actions.h:69
static TOOL_ACTION showRelatedLibraryFieldsTable
Definition actions.h:268
static TOOL_ACTION saveAll
Definition actions.h:61
static TOOL_ACTION save
Definition actions.h:58
static TOOL_ACTION showProperties
Definition actions.h:265
static TOOL_ACTION newLibrary
Definition actions.h:55
static TOOL_ACTION ddAddLibrary
Definition actions.h:67
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr const Vec & GetOrigin() const
Definition box2.h:210
constexpr const SizeVec & GetSize() const
Definition box2.h:206
int ShowModal() override
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
virtual void ToggleProperties()
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.h:113
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:97
AUTOPLACE_FIELDS m_AutoplaceFields
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:42
int ShowModal() override
Definition kidialog.cpp:93
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1561
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:660
Module editor specific tools.
bool RenameLibrary(const wxString &aTitle, const wxString &aName, std::function< bool(const wxString &aNewName)> aValidator)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:172
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:87
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:85
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:154
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true, bool aIgnoreLabelsOnInvisiblePins=true) const
Get the bounding box for the symbol.
bool IsDerived() const
Definition lib_symbol.h:206
wxString GetName() const override
Definition lib_symbol.h:148
SCH_FIELD & GetValueField()
Return reference to the value field.
Definition lib_symbol.h:336
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)
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition pgm_base.cpp:204
static TOOL_ACTION editSymbol
static TOOL_ACTION importSymbol
static TOOL_ACTION newSymbol
static TOOL_ACTION saveLibraryAs
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION pasteSymbol
static TOOL_ACTION exportSymbolAsSVG
static TOOL_ACTION renameSymbol
static TOOL_ACTION duplicateSymbol
static TOOL_ACTION cutSymbol
static TOOL_ACTION saveSymbolCopyAs
static TOOL_ACTION nextUnit
static TOOL_ACTION showElectricalTypes
static TOOL_ACTION flattenSymbol
static TOOL_ACTION placeSymbol
Definition sch_actions.h:66
static TOOL_ACTION showHiddenFields
static TOOL_ACTION showHiddenPins
static TOOL_ACTION showPinNumbers
static TOOL_ACTION exportSymbolView
static TOOL_ACTION copySymbol
static TOOL_ACTION toggleSyncedPinsMode
static TOOL_ACTION deleteSymbol
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION exportSymbol
static TOOL_ACTION previousUnit
static TOOL_ACTION deriveFromExistingSymbol
static TOOL_ACTION addSymbolToSchematic
static TOOL_ACTION saveSymbolAs
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
EESCHEMA_SETTINGS * eeconfig() const
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
void SetText(const wxString &aText) override
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:139
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition sch_screen.h:140
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 ToggleSyncedPinsMode(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvt)
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 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)
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 ExportSymbolAsSVG(const TOOL_EVENT &aEvent)
int ShowPinNumbers(const TOOL_EVENT &aEvent)
int DdAddLibrary(const TOOL_EVENT &aEvent)
int AddSymbolToSchematic(const TOOL_EVENT &aEvent)
int CutCopyDelete(const TOOL_EVENT &aEvent)
bool m_ShowPinAltIcons
When true, dragging an outline edge will drag pins rooted on it.
The symbol library editor main window.
void SaveAll()
Save all modified symbols and libraries.
bool IsLibraryTreeShown() const override
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
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 SVGPlotSymbol(const wxString &aFullFileName, const VECTOR2I &aOffset)
Create the SVG print file for the current edited symbol.
void Save()
Save the selected symbol or library.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
int GetTreeSelectionCount() const
bool IsSymbolFromSchematic() const
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
LIB_ID GetTargetLibId() const override
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
void UpdateMsgPanel() override
Redraw the message panel.
void CreateNewSymbol(const wxString &newName=wxEmptyString)
Create a new symbol in the selected library.
void UpdateTitle()
Update the main window title bar with the current library name and read only status of the library.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
void UpdateLibraryTree(const wxDataViewItem &aTreeItem, LIB_SYMBOL *aSymbol)
Update a symbol node in the library tree.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
void SaveLibraryAs()
Save the currently selected library to a new file.
void ToggleLibraryTree() override
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
LIB_SYMBOL * GetBufferedSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
LIB_SYMBOL * GetSymbol(const wxString &aSymbolName, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
bool RemoveSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &aOldSymbolName, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
void SetSymbolModified(const wxString &aSymbolName, const wxString &aLibrary)
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).
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
Symbol library viewer main window.
LIB_SYMBOL * GetSelectedSymbol() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
SCH_BASE_FRAME * getEditFrame() const
Definition tool_base.h:186
KIGFX::VIEW * getView() const
Definition tool_base.cpp:38
Generic, UI-independent tool event.
Definition tool_event.h:171
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:473
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:110
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:194
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:169
This file is part of the common library.
#define _(s)
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:35
@ FRAME_SCH
Definition frame_type.h:34
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:143
static const std::string SVGFileExtension
static wxString PngFileWildcard()
static wxString SVGFileWildcard()
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
see class PGM_BASE
@ AUTOPLACE_AUTO
Definition sch_item.h:70
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
Definition of file extensions used in Kicad.