KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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().IsLibraryReadOnly( libName ) )
262 {
263 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
265 return 0;
266 }
267
268 if( aEvent.IsAction( &SCH_ACTIONS::newSymbol ) )
269 editFrame->CreateNewSymbol();
271 editFrame->CreateNewSymbol( target.GetLibItemName() );
272 else if( aEvent.IsAction( &SCH_ACTIONS::importSymbol ) )
273 editFrame->ImportSymbol();
274
275 return 0;
276}
277
278
280{
281 if( !m_isSymbolEditor )
282 return 0;
283
284 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
285
286 if( aEvt.IsAction( &SCH_ACTIONS::save ) )
287 editFrame->Save();
288 else if( aEvt.IsAction( &SCH_ACTIONS::saveLibraryAs ) )
289 editFrame->SaveLibraryAs();
290 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolAs ) )
291 editFrame->SaveSymbolCopyAs( true );
292 else if( aEvt.IsAction( &SCH_ACTIONS::saveSymbolCopyAs ) )
293 editFrame->SaveSymbolCopyAs( false );
294 else if( aEvt.IsAction( &SCH_ACTIONS::saveAll ) )
295 editFrame->SaveAll();
296
297 return 0;
298}
299
300
302{
304 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
305
306 return 0;
307}
308
309
311{
312 if( !m_isSymbolEditor )
313 return 0;
314
315 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
316 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
317
318 LIB_ID libId = editFrame->GetTreeLIBID();
319
320 wxString libName = libId.GetLibNickname();
321 wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
322
323 wxFileName fileName( libItemName );
324
325 wxString filePath = wxEmptyString;
326
328
329 wxString explCommand = cfg->m_System.file_explorer;
330
331 if( explCommand.IsEmpty() )
332 {
333 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
334
335 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
336 LaunchExternal( filePath );
337 return 0;
338 }
339
340 if( !explCommand.EndsWith( "%F" ) )
341 {
342 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
343 return 0;
344 }
345
346 filePath = fileName.GetFullPath();
347 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
348
349 wxString fileArg = '"' + filePath + '"';
350
351 explCommand.Replace( wxT( "%F" ), fileArg );
352
353 if( !explCommand.IsEmpty() )
354 wxExecute( explCommand );
355
356 return 0;
357}
358
359
361{
362 if( !m_isSymbolEditor )
363 return 0;
364
365 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
366 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
367 wxString textEditorName = Pgm().GetTextEditor();
368
369 if( textEditorName.IsEmpty() )
370 {
371 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
372 return 0;
373 }
374
375 LIB_ID libId = editFrame->GetTreeLIBID();
376 wxString libName = libId.GetLibNickname();
377 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
378
379 if( !tempFName.IsEmpty() )
380 ExecuteFile( textEditorName, tempFName, nullptr, false );
381
382 return 0;
383}
384
385
387{
388 if( !m_isSymbolEditor )
389 return 0;
390
391 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
392
394 editFrame->CopySymbolToClipboard();
395
397 {
398 bool hasWritableLibs = false;
399 wxString msg;
400
401 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
402 {
403 const wxString& libName = sel.GetLibNickname();
404
405 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
406 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
407 else
408 hasWritableLibs = true;
409 }
410
411 if( !msg.IsEmpty() )
413
414 if( !hasWritableLibs )
415 return 0;
416
417 editFrame->DeleteSymbolFromLibrary();
418 }
419
420 return 0;
421}
422
423
425{
426 if( !m_isSymbolEditor )
427 return 0;
428
429 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
430 LIB_ID sel = editFrame->GetTargetLibId();
431 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
432 // saved symbol in clipboard
433 bool isPasteAction = aEvent.IsAction( &SCH_ACTIONS::pasteSymbol );
434 wxString msg;
435
436 if( !sel.IsValid() && !isPasteAction )
437 {
438 // When duplicating a symbol, a source symbol must exists.
439 msg.Printf( _( "No symbol selected" ) );
441 return 0;
442 }
443
444 const wxString& libName = sel.GetLibNickname();
445
446 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
447 {
448 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
450 return 0;
451 }
452
453 editFrame->DuplicateSymbol( isPasteAction );
454 return 0;
455}
456
457
459{
460 if( !m_isSymbolEditor )
461 return 0;
462
463 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
464 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
466
467 LIB_ID libId = editFrame->GetTreeLIBID();
468 wxString libName = libId.GetLibNickname();
469 wxString oldName = libId.GetLibItemName();
470 wxString newName;
471 wxString msg;
472
473 if( !libMgr.LibraryExists( libName ) )
474 return 0;
475
476 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
477 [&]( const wxString& aNewName )
478 {
479 newName = EscapeString( aNewName, CTX_LIBID );
480
481 if( newName.IsEmpty() )
482 {
483 wxMessageBox( _( "Symbol must have a name." ) );
484 return false;
485 }
486
487 // If no change, accept it without prompting
488 if( newName != oldName && libMgr.SymbolNameInUse( newName, libName ) )
489 {
490 msg.Printf( _( "Symbol '%s' already exists in library '%s'." ),
491 UnescapeString( newName ),
492 libName );
493
494 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
495 wxOK | wxCANCEL | wxICON_WARNING );
496
497 errorDlg.SetOKLabel( _( "Overwrite" ) );
498
499 return errorDlg.ShowModal() == wxID_OK;
500 }
501
502 return true;
503 } ) )
504 {
505 return 0; // cancelled by user
506 }
507
508 if( newName == oldName )
509 return 0;
510
511 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
512
513 if( !libSymbol )
514 return 0;
515
516 // Renaming the current symbol
517 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
518 bool overwritingCurrentSymbol = false;
519
520 if( libMgr.SymbolExists( newName, libName ) )
521 {
522 // Overwriting the current symbol also need to update the open symbol
523 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
524 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
525 libMgr.RemoveSymbol( newName, libName );
526 }
527
528 libSymbol->SetName( newName );
529
530 if( libSymbol->GetValueField().GetText() == oldName )
531 libSymbol->GetValueField().SetText( newName );
532
533 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
534 libMgr.SetSymbolModified( newName, libName );
535
536 if( overwritingCurrentSymbol )
537 {
538 // We overwrite the old current symbol with the renamed one, so show
539 // the renamed one now
540 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
541 }
542 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
543 {
544 // Renamed the current symbol - follow it
545 libSymbol = editFrame->GetCurSymbol();
546
547 libSymbol->SetName( newName );
548
549 if( libSymbol->GetValueField().GetText() == oldName )
550 libSymbol->GetValueField().SetText( newName );
551
552 editFrame->RebuildView();
553 editFrame->OnModify();
554 editFrame->UpdateTitle();
555
556 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
557 // invalidate the view pointers by rebuilting the field table
558 editFrame->UpdateMsgPanel();
559 }
560
561 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
562 editFrame->UpdateLibraryTree( treeItem, libSymbol );
563 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
564 return 0;
565}
566
567
569{
570 int bodyStyle = aEvent.IsAction( &SCH_ACTIONS::showDeMorganStandard ) ? BODY_STYLE::BASE
571 : BODY_STYLE::DEMORGAN;
572
574 {
577
578 SYMBOL_EDIT_FRAME* symbolEditor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
579 symbolEditor->SetBodyStyle( bodyStyle );
580
582 symbolEditor->RebuildView();
583 }
584 else if( m_frame->IsType( FRAME_SCH_VIEWER ) )
585 {
586 SYMBOL_VIEWER_FRAME* symbolViewer = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
587 symbolViewer->SetUnitAndBodyStyle( symbolViewer->GetUnit(), bodyStyle );
588 }
589
590 return 0;
591}
592
593
595{
597 getEditFrame<SYMBOL_EDIT_FRAME>()->ToggleProperties();
598
599 return 0;
600}
601
602
604{
605 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
606 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
607
608 // Update canvas
611
612 return 0;
613}
614
615
617{
618 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
619 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
620
621 // Update canvas
624
625 return 0;
626}
627
628
630{
631 if( !m_isSymbolEditor )
632 return 0;
633
634 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
635 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
636
637 return 0;
638}
639
640
642{
643 if( !m_isSymbolEditor )
644 return 0;
645
648
649 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenPins =
650 cfg->m_ShowHiddenPins;
651
654 return 0;
655}
656
657
659{
660 if( !m_isSymbolEditor )
661 return 0;
662
665
666 // TODO: Why is this needed in symbol edit and not in schematic edit?
667 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenFields =
669
672 return 0;
673}
674
675
677{
678 if( !m_isSymbolEditor )
679 return 0;
680
683
685
688 return 0;
689}
690
691
693{
694 if( !m_isSymbolEditor )
695 return 0;
696
697 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
698 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
699
700 if( !symbol )
701 {
702 wxMessageBox( _( "No symbol to export" ) );
703 return 0;
704 }
705
706 wxFileName fn( symbol->GetName() );
707 fn.SetExt( "png" );
708
709 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
710
711 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
712 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
713
714 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
715 {
716 // calling wxYield is mandatory under Linux, after closing the file selector dialog
717 // to refresh the screen before creating the PNG or JPEG image from screen
718 wxYield();
719
720 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
721 {
722 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
723 }
724 }
725
726 return 0;
727}
728
729
731{
733 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->ExportSymbol();
734
735 return 0;
736}
737
738
740{
741 if( !m_isSymbolEditor )
742 return 0;
743
744 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
745 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
746
747 if( !symbol )
748 {
749 wxMessageBox( _( "No symbol to export" ) );
750 return 0;
751 }
752
753 wxFileName fn( symbol->GetName() );
754 fn.SetExt( FILEEXT::SVGFileExtension );
755
756 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
757
758 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
760 wxFD_SAVE,
761 m_frame );
762
763 if( !fullFileName.IsEmpty() )
764 {
765 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
766 PAGE_INFO pageTemp = pageSave;
767
768 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
769 editFrame->GetBodyStyle(), false );
770
771 // Add a small margin (10% of size)to the plot bounding box
772 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
773
774 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
775 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
776
777 // Add an offet to plot the symbol centered on the page.
778 VECTOR2I plot_offset = symbolBBox.GetOrigin();
779
780 editFrame->GetScreen()->SetPageSettings( pageTemp );
781 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
782 editFrame->GetScreen()->SetPageSettings( pageSave );
783 }
784
785 return 0;
786}
787
788
790{
791 LIB_SYMBOL* libSymbol = nullptr;
792 LIB_ID libId;
793 int unit, bodyStyle;
794
795 if( m_isSymbolEditor )
796 {
797 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
798
799 libSymbol = editFrame->GetCurSymbol();
800 unit = editFrame->GetUnit();
801 bodyStyle = editFrame->GetBodyStyle();
802
803 if( libSymbol )
804 libId = libSymbol->GetLibId();
805 }
806 else
807 {
808 SYMBOL_VIEWER_FRAME* viewerFrame = getEditFrame<SYMBOL_VIEWER_FRAME>();
809
810 libSymbol = viewerFrame->GetSelectedSymbol();
811 unit = viewerFrame->GetUnit();
812 bodyStyle = viewerFrame->GetBodyStyle();
813
814 if( libSymbol )
815 libId = libSymbol->GetLibId();
816 }
817
818 if( libSymbol )
819 {
820 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
821
822 if( !schframe ) // happens when the schematic editor is not active (or closed)
823 {
824 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
825 return 0;
826 }
827
828 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
829
830 if( blocking_dialog )
831 {
832 blocking_dialog->Raise();
833 wxBell();
834 return 0;
835 }
836
837 wxCHECK( libSymbol->GetLibId().IsValid(), 0 );
838
839 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
840 unit, bodyStyle );
841
842 symbol->SetParent( schframe->GetScreen() );
843
844 if( schframe->eeconfig()->m_AutoplaceFields.enable )
845 {
846 // Not placed yet, so pass a nullptr screen reference
847 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
848 }
849
850 schframe->Raise();
852 SCH_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
853 }
854
855 return 0;
856}
857
858
860{
861 if( !m_isSymbolEditor )
862 return 0;
863
864 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
865 const int deltaUnit = aEvent.Parameter<int>();
866
867 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
868 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
869
870 editFrame->SetUnit( newUnit );
871
872 return 0;
873}
874
875
877{
878 // clang-format off
886
888
895
903
906
910
913
917
922
925 // clang-format on
926}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
static TOOL_ACTION openWithTextEditor
Definition: actions.h:61
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION addLibrary
Definition: actions.h:49
static TOOL_ACTION openDirectory
Definition: actions.h:62
static TOOL_ACTION saveAll
Definition: actions.h:54
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION showProperties
Definition: actions.h:220
static TOOL_ACTION newLibrary
Definition: actions.h:48
static TOOL_ACTION ddAddLibrary
Definition: actions.h:60
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:110
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
AUTOPLACE_FIELDS m_AutoplaceFields
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:43
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:1549
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:406
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:670
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:915
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:326
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:261
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:247
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:687
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:196
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:140
static TOOL_ACTION editSymbol
Definition: sch_actions.h:217
static TOOL_ACTION importSymbol
Definition: sch_actions.h:224
static TOOL_ACTION newSymbol
Definition: sch_actions.h:215
static TOOL_ACTION saveLibraryAs
Definition: sch_actions.h:212
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: sch_actions.h:57
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: sch_actions.h:185
static TOOL_ACTION showDeMorganAlternate
Definition: sch_actions.h:144
static TOOL_ACTION pasteSymbol
Definition: sch_actions.h:223
static TOOL_ACTION exportSymbolAsSVG
Definition: sch_actions.h:270
static TOOL_ACTION renameSymbol
Definition: sch_actions.h:219
static TOOL_ACTION duplicateSymbol
Definition: sch_actions.h:218
static TOOL_ACTION cutSymbol
Definition: sch_actions.h:221
static TOOL_ACTION saveSymbolCopyAs
Definition: sch_actions.h:214
static TOOL_ACTION nextUnit
Definition: sch_actions.h:274
static TOOL_ACTION showElectricalTypes
Definition: sch_actions.h:264
static TOOL_ACTION placeSymbol
Definition: sch_actions.h:80
static TOOL_ACTION showHiddenFields
Definition: sch_actions.h:249
static TOOL_ACTION showHiddenPins
Definition: sch_actions.h:248
static TOOL_ACTION showPinNumbers
Definition: sch_actions.h:265
static TOOL_ACTION exportSymbolView
Definition: sch_actions.h:269
static TOOL_ACTION copySymbol
Definition: sch_actions.h:222
static TOOL_ACTION toggleSyncedPinsMode
Definition: sch_actions.h:258
static TOOL_ACTION deleteSymbol
Definition: sch_actions.h:220
static TOOL_ACTION togglePinAltIcons
Definition: sch_actions.h:257
static TOOL_ACTION showDeMorganStandard
Definition: sch_actions.h:143
static TOOL_ACTION exportSymbol
Definition: sch_actions.h:225
static TOOL_ACTION previousUnit
Definition: sch_actions.h:273
static TOOL_ACTION deriveFromExistingSymbol
Definition: sch_actions.h:216
static TOOL_ACTION addSymbolToSchematic
Definition: sch_actions.h:192
static TOOL_ACTION saveSymbolAs
Definition: sch_actions.h:213
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:1069
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:134
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:135
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:104
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:170
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:1071
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:99
Definition of file extensions used in Kicad.