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>
28#include <kiway.h>
29#include <pgm_base.h>
30#include <sch_painter.h>
31#include <tool/tool_manager.h>
33#include <tools/sch_actions.h>
36#include <symbol_viewer_frame.h>
38#include <symbol_lib_table.h>
41#include <confirm.h>
42#include <kidialog.h>
43#include <launch_ext.h> // To default when file manager setting is empty
44#include <gestfich.h> // To open with a text editor
45#include <wx/filedlg.h>
46#include "string_utils.h"
47
49{
50 m_frame = getEditFrame<SCH_BASE_FRAME>();
53
55 {
57 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
58 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
59
60 wxCHECK( editFrame, false );
61
62 auto libSelectedCondition =
63 [ editFrame ]( const SELECTION& aSel )
64 {
65 LIB_ID sel = editFrame->GetTreeLIBID();
66 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
67 };
68
69 // The libInferredCondition allows you to do things like New Symbol and Paste with a
70 // symbol selected (in other words, when we know the library context even if the library
71 // itself isn't selected.
72 auto libInferredCondition =
73 [ editFrame ]( const SELECTION& aSel )
74 {
75 LIB_ID sel = editFrame->GetTreeLIBID();
76 return !sel.GetLibNickname().empty();
77 };
78
79 auto symbolSelectedCondition =
80 [ editFrame ]( const SELECTION& aSel )
81 {
82 LIB_ID sel = editFrame->GetTargetLibId();
83 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
84 };
85
86/* not used, but used to be used
87 auto multiSelectedCondition =
88 [ editFrame ]( const SELECTION& aSel )
89 {
90 return editFrame->GetTreeSelectionCount() > 1;
91 };
92*/
93 auto multiSymbolSelectedCondition =
94 [ editFrame ]( const SELECTION& aSel )
95 {
96 if( editFrame->GetTreeSelectionCount() > 1 )
97 {
98 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
99 {
100 if( !sel.IsValid() )
101 return false;
102 }
103 return true;
104 }
105 return false;
106 };
107/* not used, yet
108 auto multiLibrarySelectedCondition =
109 [ editFrame ]( const SELECTION& aSel )
110 {
111 if( editFrame->GetTreeSelectionCount() > 1 )
112 {
113 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
114 {
115 if( sel.IsValid() )
116 return false;
117 }
118 return true;
119 }
120 return false;
121 };
122*/
123 auto canOpenExternally =
124 [ editFrame ]( const SELECTION& aSel )
125 {
126 // The option is shown if the lib has no current edits
127 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
128 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
129 bool ret = !libMgr.IsLibraryModified( libName );
130 return ret;
131 };
132
133// clang-format off
134 ctxMenu.AddItem( SCH_ACTIONS::newSymbol, libInferredCondition, 10 );
135 ctxMenu.AddItem( SCH_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
136
137 ctxMenu.AddSeparator( 10 );
138 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
139 ctxMenu.AddItem( SCH_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
140 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolAs, symbolSelectedCondition, 10 );
141 ctxMenu.AddItem( SCH_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
142 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
143
144 ctxMenu.AddSeparator( 10 );
145 ctxMenu.AddItem( SCH_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
146 ctxMenu.AddItem( SCH_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
147 ctxMenu.AddItem( SCH_ACTIONS::pasteSymbol, libInferredCondition, 10 );
148 ctxMenu.AddItem( SCH_ACTIONS::duplicateSymbol, symbolSelectedCondition, 10 );
149 ctxMenu.AddItem( SCH_ACTIONS::renameSymbol, symbolSelectedCondition, 10 );
150 ctxMenu.AddItem( SCH_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
151
152 ctxMenu.AddSeparator( 100 );
153 ctxMenu.AddItem( SCH_ACTIONS::importSymbol, libInferredCondition, 100 );
154 ctxMenu.AddItem( SCH_ACTIONS::exportSymbol, symbolSelectedCondition );
155
157 {
158 ctxMenu.AddSeparator( 200 );
159 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
160 }
161
163 {
164 ctxMenu.AddSeparator( 200 );
165 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
166 }
167
168 libraryTreeTool->AddContextMenuItems( &ctxMenu );
169 }
170// clang-format on
171
172 return true;
173}
174
175
177{
178 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
179
181 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
182
183 return 0;
184}
185
186
188{
189 wxString libFile = *aEvent.Parameter<wxString*>();
190
192 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
193
194 return 0;
195}
196
197
199{
200 if( !m_isSymbolEditor )
201 return 0;
202
203 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
204 int unit = 0;
205 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
206
207 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
208 return 0;
209}
210
211
213{
214 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
215 const LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
216
217 if( !symbol || !editFrame->IsSymbolFromSchematic() )
218 {
219 wxBell();
220 return 0;
221 }
222
223 const LIB_ID& libId = symbol->GetLibId();
224
225 if( editFrame->LoadSymbol( libId, editFrame->GetUnit(), editFrame->GetBodyStyle() ) )
226 {
227 if( !editFrame->IsLibraryTreeShown() )
228 editFrame->ToggleLibraryTree();
229 }
230 else
231 {
232 const wxString libName = libId.GetLibNickname();
233 const wxString symbolName = libId.GetLibItemName();
234
235 DisplayError( editFrame,
236 wxString::Format( _( "Failed to load symbol %s from "
237 "library %s." ),
238 UnescapeString( symbolName ), UnescapeString( libName ) ) );
239 }
240 return 0;
241}
242
243
245{
246 if( !m_isSymbolEditor )
247 return 0;
248
249 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
250 LIB_ID target = editFrame->GetTargetLibId();
251 const wxString& libName = target.GetLibNickname();
252 wxString msg;
253
254 if( libName.IsEmpty() )
255 {
256 msg.Printf( _( "No symbol library selected." ) );
258 return 0;
259 }
260
261 if( !editFrame->GetLibManager().LibraryExists( libName ) )
262 {
263 msg.Printf( _( "Symbol library '%s' not found." ), libName );
265 return 0;
266 }
267
268 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
269 {
270 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
272 return 0;
273 }
274
275 if( aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
276 editFrame->CreateNewSymbol();
278 editFrame->CreateNewSymbol( target.GetLibItemName() );
279 else if( aEvent.IsAction( &SCH_ACTIONS::importSymbol ) )
280 editFrame->ImportSymbol();
281
282 return 0;
283}
284
285
287{
288 if( !m_isSymbolEditor )
289 return 0;
290
291 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
292
293 if( aEvt.IsAction( &SCH_ACTIONS::save ) )
294 editFrame->Save();
295 else if( aEvt.IsAction( &SCH_ACTIONS::saveLibraryAs ) )
296 editFrame->SaveLibraryAs();
297 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolAs ) )
298 editFrame->SaveSymbolCopyAs( true );
299 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolCopyAs ) )
300 editFrame->SaveSymbolCopyAs( false );
301 else if( aEvt.IsAction( &SCH_ACTIONS::saveAll ) )
302 editFrame->SaveAll();
303
304 return 0;
305}
306
307
309{
311 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
312
313 return 0;
314}
315
316
318{
319 if( !m_isSymbolEditor )
320 return 0;
321
322 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
323 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
324
325 LIB_ID libId = editFrame->GetTreeLIBID();
326
327 wxString libName = libId.GetLibNickname();
328 wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
329
330 wxFileName fileName( libItemName );
331
332 wxString filePath = wxEmptyString;
333
335
336 wxString explCommand = cfg->m_System.file_explorer;
337
338 if( explCommand.IsEmpty() )
339 {
340 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
341
342 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
343 LaunchExternal( filePath );
344 return 0;
345 }
346
347 if( !explCommand.EndsWith( "%F" ) )
348 {
349 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
350 return 0;
351 }
352
353 filePath = fileName.GetFullPath();
354 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
355
356 wxString fileArg = '"' + filePath + '"';
357
358 explCommand.Replace( wxT( "%F" ), fileArg );
359
360 if( !explCommand.IsEmpty() )
361 wxExecute( explCommand );
362
363 return 0;
364}
365
366
368{
369 if( !m_isSymbolEditor )
370 return 0;
371
372 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
373 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
374 wxString textEditorName = Pgm().GetTextEditor();
375
376 if( textEditorName.IsEmpty() )
377 {
378 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
379 return 0;
380 }
381
382 LIB_ID libId = editFrame->GetTreeLIBID();
383 wxString libName = libId.GetLibNickname();
384 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
385
386 if( !tempFName.IsEmpty() )
387 ExecuteFile( textEditorName, tempFName, nullptr, false );
388
389 return 0;
390}
391
392
394{
395 if( !m_isSymbolEditor )
396 return 0;
397
398 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
399
401 editFrame->CopySymbolToClipboard();
402
404 {
405 bool hasWritableLibs = false;
406 wxString msg;
407
408 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
409 {
410 const wxString& libName = sel.GetLibNickname();
411
412 if( !editFrame->GetLibManager().LibraryExists( libName ) )
413 msg.Printf( _( "Symbol library '%s' not found." ), libName );
414 else if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
415 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
416 else
417 hasWritableLibs = true;
418 }
419
420 if( !msg.IsEmpty() )
422
423 if( !hasWritableLibs )
424 return 0;
425
426 editFrame->DeleteSymbolFromLibrary();
427 }
428
429 return 0;
430}
431
432
434{
435 if( !m_isSymbolEditor )
436 return 0;
437
438 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
439 LIB_ID sel = editFrame->GetTargetLibId();
440 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
441 // saved symbol in clipboard
442 bool isPasteAction = aEvent.IsAction( &SCH_ACTIONS::pasteSymbol );
443 wxString msg;
444
445 if( !sel.IsValid() && !isPasteAction )
446 {
447 // When duplicating a symbol, a source symbol must exists.
448 msg.Printf( _( "No symbol selected" ) );
450 return 0;
451 }
452
453 const wxString& libName = sel.GetLibNickname();
454
455 if( !editFrame->GetLibManager().LibraryExists( libName ) )
456 {
457 msg.Printf( _( "Symbol library '%s' not found." ), libName );
459 return 0;
460 }
461
462 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
463 {
464 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
466 return 0;
467 }
468
469 editFrame->DuplicateSymbol( isPasteAction );
470 return 0;
471}
472
473
475{
476 if( !m_isSymbolEditor )
477 return 0;
478
479 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
480 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
482
483 LIB_ID libId = editFrame->GetTreeLIBID();
484 wxString libName = libId.GetLibNickname();
485 wxString oldName = libId.GetLibItemName();
486 wxString newName;
487 wxString msg;
488
489 if( !libMgr.LibraryExists( libName ) )
490 return 0;
491
492 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
493 [&]( const wxString& aNewName )
494 {
495 newName = EscapeString( aNewName, CTX_LIBID );
496
497 if( newName.IsEmpty() )
498 {
499 wxMessageBox( _( "Symbol must have a name." ) );
500 return false;
501 }
502
503 // If no change, accept it without prompting
504 if( newName != oldName && libMgr.SymbolNameInUse( newName, libName ) )
505 {
506 msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
507 UnescapeString( newName ),
508 libName );
509
510 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
511 wxOK | wxCANCEL | wxICON_WARNING );
512
513 errorDlg.SetOKLabel( _( "Overwrite" ) );
514
515 return errorDlg.ShowModal() == wxID_OK;
516 }
517
518 return true;
519 } ) )
520 {
521 return 0; // cancelled by user
522 }
523
524 if( newName == oldName )
525 return 0;
526
527 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
528
529 if( !libSymbol )
530 return 0;
531
532 // Renaming the current symbol
533 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
534 bool overwritingCurrentSymbol = false;
535
536 if( libMgr.SymbolExists( newName, libName ) )
537 {
538 // Overwriting the current symbol also need to update the open symbol
539 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
540 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
541 libMgr.RemoveSymbol( newName, libName );
542 }
543
544 libSymbol->SetName( newName );
545
546 if( libSymbol->GetValueField().GetText() == oldName )
547 libSymbol->GetValueField().SetText( newName );
548
549 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
550 libMgr.SetSymbolModified( newName, libName );
551
552 if( overwritingCurrentSymbol )
553 {
554 // We overwrite the old current symbol with the renamed one, so show
555 // the renamed one now
556 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
557 }
558 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
559 {
560 // Renamed the current symbol - follow it
561 libSymbol = editFrame->GetCurSymbol();
562
563 libSymbol->SetName( newName );
564
565 if( libSymbol->GetValueField().GetText() == oldName )
566 libSymbol->GetValueField().SetText( newName );
567
568 editFrame->RebuildView();
569 editFrame->OnModify();
570 editFrame->UpdateTitle();
571
572 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
573 // invalidate the view pointers by rebuilting the field table
574 editFrame->UpdateMsgPanel();
575 }
576
577 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
578 editFrame->UpdateLibraryTree( treeItem, libSymbol );
579 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
580 return 0;
581}
582
583
585{
586 int bodyStyle = aEvent.IsAction( &SCH_ACTIONS::showDeMorganStandard ) ? BODY_STYLE::BASE
587 : BODY_STYLE::DEMORGAN;
588
590 {
593
594 SYMBOL_EDIT_FRAME* symbolEditor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
595 symbolEditor->SetBodyStyle( bodyStyle );
596
598 symbolEditor->RebuildView();
599 }
600 else if( m_frame->IsType( FRAME_SCH_VIEWER ) )
601 {
602 SYMBOL_VIEWER_FRAME* symbolViewer = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
603 symbolViewer->SetUnitAndBodyStyle( symbolViewer->GetUnit(), bodyStyle );
604 }
605
606 return 0;
607}
608
609
611{
613 getEditFrame<SYMBOL_EDIT_FRAME>()->ToggleProperties();
614
615 return 0;
616}
617
618
620{
621 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
622 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
623
624 // Update canvas
627
628 return 0;
629}
630
631
633{
634 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
635 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
636
637 // Update canvas
640
641 return 0;
642}
643
644
646{
647 if( !m_isSymbolEditor )
648 return 0;
649
650 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
651 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
652
653 return 0;
654}
655
656
658{
659 if( !m_isSymbolEditor )
660 return 0;
661
664
665 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenPins =
666 cfg->m_ShowHiddenPins;
667
670 return 0;
671}
672
673
675{
676 if( !m_isSymbolEditor )
677 return 0;
678
681
682 // TODO: Why is this needed in symbol edit and not in schematic edit?
683 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenFields =
685
688 return 0;
689}
690
691
693{
694 if( !m_isSymbolEditor )
695 return 0;
696
699
701
704 return 0;
705}
706
707
709{
710 if( !m_isSymbolEditor )
711 return 0;
712
713 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
714 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
715
716 if( !symbol )
717 {
718 wxMessageBox( _( "No symbol to export" ) );
719 return 0;
720 }
721
722 wxFileName fn( symbol->GetName() );
723 fn.SetExt( "png" );
724
725 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
726
727 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
728 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
729
730 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
731 {
732 // calling wxYield is mandatory under Linux, after closing the file selector dialog
733 // to refresh the screen before creating the PNG or JPEG image from screen
734 wxYield();
735
736 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
737 {
738 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
739 }
740 }
741
742 return 0;
743}
744
745
747{
749 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
750
751 return 0;
752}
753
754
756{
757 if( !m_isSymbolEditor )
758 return 0;
759
760 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
761 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
762
763 if( !symbol )
764 {
765 wxMessageBox( _( "No symbol to export" ) );
766 return 0;
767 }
768
769 wxFileName fn( symbol->GetName() );
770 fn.SetExt( FILEEXT::SVGFileExtension );
771
772 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
773
774 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
776 wxFD_SAVE,
777 m_frame );
778
779 if( !fullFileName.IsEmpty() )
780 {
781 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
782 PAGE_INFO pageTemp = pageSave;
783
784 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
785 editFrame->GetBodyStyle(), false );
786
787 // Add a small margin (10% of size)to the plot bounding box
788 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
789
790 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
791 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
792
793 // Add an offet to plot the symbol centered on the page.
794 VECTOR2I plot_offset = symbolBBox.GetOrigin();
795
796 editFrame->GetScreen()->SetPageSettings( pageTemp );
797 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
798 editFrame->GetScreen()->SetPageSettings( pageSave );
799 }
800
801 return 0;
802}
803
804
806{
807 LIB_SYMBOL* libSymbol = nullptr;
808 LIB_ID libId;
809 int unit, bodyStyle;
810
811 if( m_isSymbolEditor )
812 {
813 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
814
815 libSymbol = editFrame->GetCurSymbol();
816 unit = editFrame->GetUnit();
817 bodyStyle = editFrame->GetBodyStyle();
818
819 if( libSymbol )
820 libId = libSymbol->GetLibId();
821 }
822 else
823 {
824 SYMBOL_VIEWER_FRAME* viewerFrame = getEditFrame<SYMBOL_VIEWER_FRAME>();
825
826 libSymbol = viewerFrame->GetSelectedSymbol();
827 unit = viewerFrame->GetUnit();
828 bodyStyle = viewerFrame->GetBodyStyle();
829
830 if( libSymbol )
831 libId = libSymbol->GetLibId();
832 }
833
834 if( libSymbol )
835 {
836 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
837
838 if( !schframe ) // happens when the schematic editor is not active (or closed)
839 {
840 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
841 return 0;
842 }
843
844 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
845
846 if( blocking_dialog )
847 {
848 blocking_dialog->Raise();
849 wxBell();
850 return 0;
851 }
852
853 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
854 unit, bodyStyle );
855
856 symbol->SetParent( schframe->GetScreen() );
857
858 if( schframe->eeconfig()->m_AutoplaceFields.enable )
859 {
860 // Not placed yet, so pass a nullptr screen reference
861 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
862 }
863
864 schframe->Raise();
866 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
867 }
868
869 return 0;
870}
871
872
874{
875 if( !m_isSymbolEditor )
876 return 0;
877
878 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
879 const int deltaUnit = aEvent.Parameter<int>();
880
881 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
882 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
883
884 editFrame->SetUnit( newUnit );
885
886 return 0;
887}
888
889
891{
892 // clang-format off
900
902
909
917
920
924
927
931
936
939 // clang-format on
940}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
static TOOL_ACTION cancelInteractive
Definition: actions.h:72
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 saveAll
Definition: actions.h:61
static TOOL_ACTION save
Definition: actions.h:58
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:221
static TOOL_ACTION showProperties
Definition: actions.h:263
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
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_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...
bool IsType(FRAME_T aType) const
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
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:50
int ShowModal() override
Definition: kidialog.cpp:95
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1561
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.
Definition: kiway_holder.h:55
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:395
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:637
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:155
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:917
wxString GetName() const override
Definition: lib_symbol.h:149
SCH_FIELD & GetValueField()
Return reference to the value field.
Definition: lib_symbol.h:334
int GetUnitCount() const override
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:328
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:59
void SetHeightMils(double aHeightInMils)
Definition: page_info.cpp:262
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:248
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:565
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:197
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:143
static TOOL_ACTION editSymbol
Definition: sch_actions.h:204
static TOOL_ACTION importSymbol
Definition: sch_actions.h:211
static TOOL_ACTION newSymbol
Definition: sch_actions.h:202
static TOOL_ACTION saveLibraryAs
Definition: sch_actions.h:199
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: sch_actions.h:173
static TOOL_ACTION showDeMorganAlternate
Definition: sch_actions.h:132
static TOOL_ACTION pasteSymbol
Definition: sch_actions.h:210
static TOOL_ACTION exportSymbolAsSVG
Definition: sch_actions.h:257
static TOOL_ACTION renameSymbol
Definition: sch_actions.h:206
static TOOL_ACTION duplicateSymbol
Definition: sch_actions.h:205
static TOOL_ACTION cutSymbol
Definition: sch_actions.h:208
static TOOL_ACTION saveSymbolCopyAs
Definition: sch_actions.h:201
static TOOL_ACTION nextUnit
Definition: sch_actions.h:261
static TOOL_ACTION showElectricalTypes
Definition: sch_actions.h:251
static TOOL_ACTION placeSymbol
Definition: sch_actions.h:66
static TOOL_ACTION showHiddenFields
Definition: sch_actions.h:236
static TOOL_ACTION showHiddenPins
Definition: sch_actions.h:235
static TOOL_ACTION showPinNumbers
Definition: sch_actions.h:252
static TOOL_ACTION exportSymbolView
Definition: sch_actions.h:256
static TOOL_ACTION copySymbol
Definition: sch_actions.h:209
static TOOL_ACTION toggleSyncedPinsMode
Definition: sch_actions.h:245
static TOOL_ACTION deleteSymbol
Definition: sch_actions.h:207
static TOOL_ACTION togglePinAltIcons
Definition: sch_actions.h:244
static TOOL_ACTION showDeMorganStandard
Definition: sch_actions.h:131
static TOOL_ACTION exportSymbol
Definition: sch_actions.h:212
static TOOL_ACTION previousUnit
Definition: sch_actions.h:260
static TOOL_ACTION deriveFromExistingSymbol
Definition: sch_actions.h:203
static TOOL_ACTION addSymbolToSchematic
Definition: sch_actions.h:180
static TOOL_ACTION saveSymbolAs
Definition: sch_actions.h:200
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
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
Definition: sch_field.cpp:1089
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 OnDeMorgan(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 OpenDirectory(const TOOL_EVENT &aEvent)
int RenameSymbol(const TOOL_EVENT &newName)
int DuplicateSymbol(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(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)
int GetBodyStyle() const
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 SetBodyStyle(int aBodyStyle)
void SetUnit(int aUnit)
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 DdAddLibrary(wxString aLibFile)
Add a library dropped file to the symbol library table.
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.
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.
Symbol library viewer main window.
void SetUnitAndBodyStyle(int aUnit, int aBodyStyle)
Set unit and convert, and set flag preventing them from automatically resetting to 1.
LIB_SYMBOL * GetSelectedSymbol() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:38
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:465
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
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_VIEWER
Definition: frame_type.h:36
@ 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
bool m_EnableLibDir
Enable option to open lib file directory.
bool m_EnableLibWithText
Enable option to load lib files with text editor.
static const std::string SVGFileExtension
static wxString PngFileWildcard()
static wxString SVGFileWildcard()
This file is part of the common library.
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
Definition: launch_ext.cpp:25
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:58
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:902
see class PGM_BASE
@ AUTOPLACE_AUTO
Definition: sch_item.h:71
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
Definition: string_utils.h:54
constexpr int IUToMils(int iu) const
Definition: base_units.h:103
Definition of file extensions used in Kicad.