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/ee_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( EE_ACTIONS::newSymbol, libInferredCondition, 10 );
135 ctxMenu.AddItem( EE_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
136
137 ctxMenu.AddSeparator( 10 );
138 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
139 ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
140 ctxMenu.AddItem( EE_ACTIONS::saveSymbolAs, symbolSelectedCondition, 10 );
141 ctxMenu.AddItem( EE_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
142 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
143
144 ctxMenu.AddSeparator( 10 );
145 ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
146 ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
147 ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition, 10 );
148 ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition, 10 );
149 ctxMenu.AddItem( EE_ACTIONS::renameSymbol, symbolSelectedCondition, 10 );
150 ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
151
152 ctxMenu.AddSeparator( 100 );
153 ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition, 100 );
154
156 {
157 ctxMenu.AddSeparator( 200 );
158 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
159 }
160
162 {
163 ctxMenu.AddSeparator( 200 );
164 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
165 }
166
167 libraryTreeTool->AddContextMenuItems( &ctxMenu );
168 }
169// clang-format on
170
171 return true;
172}
173
174
176{
177 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
178
180 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
181
182 return 0;
183}
184
185
187{
188 wxString libFile = *aEvent.Parameter<wxString*>();
189
191 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
192
193 return 0;
194}
195
196
198{
199 if( !m_isSymbolEditor )
200 return 0;
201
202 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
203 int unit = 0;
204 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
205
206 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
207 return 0;
208}
209
210
212{
213 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
214 const LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
215
216 if( !symbol || !editFrame->IsSymbolFromSchematic() )
217 {
218 wxBell();
219 return 0;
220 }
221
222 const LIB_ID& libId = symbol->GetLibId();
223
224 if( editFrame->LoadSymbol( libId, editFrame->GetUnit(), editFrame->GetBodyStyle() ) )
225 {
226 if( !editFrame->IsLibraryTreeShown() )
227 editFrame->ToggleLibraryTree();
228 }
229 else
230 {
231 const wxString libName = libId.GetLibNickname();
232 const wxString symbolName = libId.GetLibItemName();
233
234 DisplayError( editFrame,
235 wxString::Format( _( "Failed to load symbol %s from "
236 "library %s." ),
237 UnescapeString( symbolName ), UnescapeString( libName ) ) );
238 }
239 return 0;
240}
241
242
244{
245 if( !m_isSymbolEditor )
246 return 0;
247
248 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
249 LIB_ID target = editFrame->GetTargetLibId();
250 const wxString& libName = target.GetLibNickname();
251 wxString msg;
252
253 if( libName.IsEmpty() )
254 {
255 msg.Printf( _( "No symbol library selected." ) );
257 return 0;
258 }
259
260 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
261 {
262 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
264 return 0;
265 }
266
267 if( aEvent.IsAction( &EE_ACTIONS::newSymbol ) )
268 editFrame->CreateNewSymbol();
270 editFrame->CreateNewSymbol( target.GetLibItemName() );
271 else if( aEvent.IsAction( &EE_ACTIONS::importSymbol ) )
272 editFrame->ImportSymbol();
273
274 return 0;
275}
276
277
279{
280 if( !m_isSymbolEditor )
281 return 0;
282
283 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
284
285 if( aEvt.IsAction( &EE_ACTIONS::save ) )
286 editFrame->Save();
287 else if( aEvt.IsAction( &EE_ACTIONS::saveLibraryAs ) )
288 editFrame->SaveLibraryAs();
289 else if( aEvt.IsAction( &EE_ACTIONS::saveSymbolAs ) )
290 editFrame->SaveSymbolCopyAs( true );
291 else if( aEvt.IsAction( &EE_ACTIONS::saveSymbolCopyAs ) )
292 editFrame->SaveSymbolCopyAs( false );
293 else if( aEvt.IsAction( &EE_ACTIONS::saveAll ) )
294 editFrame->SaveAll();
295
296 return 0;
297}
298
299
301{
303 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
304
305 return 0;
306}
307
308
310{
311 if( !m_isSymbolEditor )
312 return 0;
313
314 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
315 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
316
317 LIB_ID libId = editFrame->GetTreeLIBID();
318
319 wxString libName = libId.GetLibNickname();
320 wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
321
322 wxFileName fileName( libItemName );
323
324 wxString filePath = wxEmptyString;
325
327
328 wxString explCommand = cfg->m_System.file_explorer;
329
330 if( explCommand.IsEmpty() )
331 {
332 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
333
334 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
335 LaunchExternal( filePath );
336 return 0;
337 }
338
339 if( !explCommand.EndsWith( "%F" ) )
340 {
341 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
342 return 0;
343 }
344
345 filePath = fileName.GetFullPath();
346 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
347
348 wxString fileArg = '"' + filePath + '"';
349
350 explCommand.Replace( wxT( "%F" ), fileArg );
351
352 if( !explCommand.IsEmpty() )
353 wxExecute( explCommand );
354
355 return 0;
356}
357
358
360{
361 if( !m_isSymbolEditor )
362 return 0;
363
364 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
365 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
366 wxString textEditorName = Pgm().GetTextEditor();
367
368 if( textEditorName.IsEmpty() )
369 {
370 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
371 return 0;
372 }
373
374 LIB_ID libId = editFrame->GetTreeLIBID();
375 wxString libName = libId.GetLibNickname();
376 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
377
378 if( !tempFName.IsEmpty() )
379 ExecuteFile( textEditorName, tempFName, nullptr, false );
380
381 return 0;
382}
383
384
386{
387 if( !m_isSymbolEditor )
388 return 0;
389
390 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
391
393 editFrame->CopySymbolToClipboard();
394
396 {
397 bool hasWritableLibs = false;
398 wxString msg;
399
400 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
401 {
402 const wxString& libName = sel.GetLibNickname();
403
404 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
405 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
406 else
407 hasWritableLibs = true;
408 }
409
410 if( !msg.IsEmpty() )
412
413 if( !hasWritableLibs )
414 return 0;
415
416 editFrame->DeleteSymbolFromLibrary();
417 }
418
419 return 0;
420}
421
422
424{
425 if( !m_isSymbolEditor )
426 return 0;
427
428 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
429 LIB_ID sel = editFrame->GetTargetLibId();
430 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
431 // saved symbol in clipboard
432 bool isPasteAction = aEvent.IsAction( &EE_ACTIONS::pasteSymbol );
433 wxString msg;
434
435 if( !sel.IsValid() && !isPasteAction )
436 {
437 // When duplicating a symbol, a source symbol must exists.
438 msg.Printf( _( "No symbol selected" ) );
440 return 0;
441 }
442
443 const wxString& libName = sel.GetLibNickname();
444
445 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
446 {
447 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
449 return 0;
450 }
451
452 editFrame->DuplicateSymbol( isPasteAction );
453 return 0;
454}
455
456
458{
459 if( !m_isSymbolEditor )
460 return 0;
461
462 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
463 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
465
466 LIB_ID libId = editFrame->GetTreeLIBID();
467 wxString libName = libId.GetLibNickname();
468 wxString oldName = libId.GetLibItemName();
469 wxString newName;
470 wxString msg;
471
472 if( !libMgr.LibraryExists( libName ) )
473 return 0;
474
475 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
476 [&]( const wxString& aNewName )
477 {
478 newName = EscapeString( aNewName, CTX_LIBID );
479
480 if( newName.IsEmpty() )
481 {
482 wxMessageBox( _( "Symbol must have a name." ) );
483 return false;
484 }
485
486 // If no change, accept it without prompting
487 if( newName != oldName && libMgr.SymbolExists( newName, libName ) )
488 {
489 msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'." ),
490 newName, libName );
491
492 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
493 wxOK | wxCANCEL | wxICON_WARNING );
494 errorDlg.SetOKLabel( _( "Overwrite" ) );
495
496 return errorDlg.ShowModal() == wxID_OK;
497 }
498
499 return true;
500 } ) )
501 {
502 return 0; // cancelled by user
503 }
504
505 if( newName == oldName )
506 return 0;
507
508 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
509
510 if( !libSymbol )
511 return 0;
512
513 // Renaming the current symbol
514 const bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
515 bool overwritingCurrentSymbol = false;
516
517 if( libMgr.SymbolExists( newName, libName ) )
518 {
519 // Overwriting the current symbol also need to update the open symbol
520 LIB_SYMBOL* const overwrittenSymbol = libMgr.GetBufferedSymbol( newName, libName );
521 overwritingCurrentSymbol = editFrame->IsCurrentSymbol( overwrittenSymbol->GetLibId() );
522 libMgr.RemoveSymbol( newName, libName );
523 }
524
525 libSymbol->SetName( newName );
526
527 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
528 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
529
530 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
531 libMgr.SetSymbolModified( newName, libName );
532
533 if( overwritingCurrentSymbol )
534 {
535 // We overwrite the old current symbol with the renamed one, so show
536 // the renamed one now
537 editFrame->SetCurSymbol( new LIB_SYMBOL( *libSymbol ), false );
538 }
539 else if( isCurrentSymbol && editFrame->GetCurSymbol() )
540 {
541 // Renamed the current symbol - follow it
542 libSymbol = editFrame->GetCurSymbol();
543
544 libSymbol->SetName( newName );
545
546 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
547 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
548
549 editFrame->RebuildView();
550 editFrame->OnModify();
551 editFrame->UpdateTitle();
552
553 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
554 // invalidate the view pointers by rebuilting the field table
555 editFrame->UpdateMsgPanel();
556 }
557
558 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
559 editFrame->UpdateLibraryTree( treeItem, libSymbol );
560 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
561 return 0;
562}
563
564
566{
567 int bodyStyle = aEvent.IsAction( &EE_ACTIONS::showDeMorganStandard ) ? BODY_STYLE::BASE
568 : BODY_STYLE::DEMORGAN;
569
571 {
574
575 SYMBOL_EDIT_FRAME* symbolEditor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
576 symbolEditor->SetBodyStyle( bodyStyle );
577
579 symbolEditor->RebuildView();
580 }
581 else if( m_frame->IsType( FRAME_SCH_VIEWER ) )
582 {
583 SYMBOL_VIEWER_FRAME* symbolViewer = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
584 symbolViewer->SetUnitAndBodyStyle( symbolViewer->GetUnit(), bodyStyle );
585 }
586
587 return 0;
588}
589
590
592{
594 getEditFrame<SYMBOL_EDIT_FRAME>()->ToggleProperties();
595
596 return 0;
597}
598
599
601{
602 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
603 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
604
605 // Update canvas
608
609 return 0;
610}
611
612
614{
615 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
616 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
617
618 // Update canvas
621
622 return 0;
623}
624
625
627{
628 if( !m_isSymbolEditor )
629 return 0;
630
631 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
632 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
633
634 return 0;
635}
636
637
639{
640 if( !m_isSymbolEditor )
641 return 0;
642
645
646 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenPins =
647 cfg->m_ShowHiddenPins;
648
651 return 0;
652}
653
654
656{
657 if( !m_isSymbolEditor )
658 return 0;
659
662
663 // TODO: Why is this needed in symbol edit and not in schematic edit?
664 getEditFrame<SYMBOL_EDIT_FRAME>()->GetRenderSettings()->m_ShowHiddenFields =
666
669 return 0;
670}
671
672
674{
675 if( !m_isSymbolEditor )
676 return 0;
677
680
682
685 return 0;
686}
687
688
690{
691 if( !m_isSymbolEditor )
692 return 0;
693
694 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
695 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
696
697 if( !symbol )
698 {
699 wxMessageBox( _( "No symbol to export" ) );
700 return 0;
701 }
702
703 wxFileName fn( symbol->GetName() );
704 fn.SetExt( "png" );
705
706 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
707
708 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
709 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
710
711 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
712 {
713 // calling wxYield is mandatory under Linux, after closing the file selector dialog
714 // to refresh the screen before creating the PNG or JPEG image from screen
715 wxYield();
716
717 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
718 {
719 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
720 }
721 }
722
723 return 0;
724}
725
726
728{
729 if( !m_isSymbolEditor )
730 return 0;
731
732 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
733 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
734
735 if( !symbol )
736 {
737 wxMessageBox( _( "No symbol to export" ) );
738 return 0;
739 }
740
741 wxFileName fn( symbol->GetName() );
742 fn.SetExt( FILEEXT::SVGFileExtension );
743
744 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
745
746 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
748 wxFD_SAVE,
749 m_frame );
750
751 if( !fullFileName.IsEmpty() )
752 {
753 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
754 PAGE_INFO pageTemp = pageSave;
755
756 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
757 editFrame->GetBodyStyle(), false );
758
759 // Add a small margin (10% of size)to the plot bounding box
760 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
761
762 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
763 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
764
765 // Add an offet to plot the symbol centered on the page.
766 VECTOR2I plot_offset = symbolBBox.GetOrigin();
767
768 editFrame->GetScreen()->SetPageSettings( pageTemp );
769 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
770 editFrame->GetScreen()->SetPageSettings( pageSave );
771 }
772
773 return 0;
774}
775
776
778{
779 LIB_SYMBOL* libSymbol = nullptr;
780 LIB_ID libId;
781 int unit, bodyStyle;
782
783 if( m_isSymbolEditor )
784 {
785 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
786
787 libSymbol = editFrame->GetCurSymbol();
788 unit = editFrame->GetUnit();
789 bodyStyle = editFrame->GetBodyStyle();
790
791 if( libSymbol )
792 libId = libSymbol->GetLibId();
793 }
794 else
795 {
796 SYMBOL_VIEWER_FRAME* viewerFrame = getEditFrame<SYMBOL_VIEWER_FRAME>();
797
798 libSymbol = viewerFrame->GetSelectedSymbol();
799 unit = viewerFrame->GetUnit();
800 bodyStyle = viewerFrame->GetBodyStyle();
801
802 if( libSymbol )
803 libId = libSymbol->GetLibId();
804 }
805
806 if( libSymbol )
807 {
808 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
809
810 if( !schframe ) // happens when the schematic editor is not active (or closed)
811 {
812 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
813 return 0;
814 }
815
816 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
817
818 if( blocking_dialog )
819 {
820 blocking_dialog->Raise();
821 wxBell();
822 return 0;
823 }
824
825 wxCHECK( libSymbol->GetLibId().IsValid(), 0 );
826
827 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
828 unit, bodyStyle );
829
830 symbol->SetParent( schframe->GetScreen() );
831
832 if( schframe->eeconfig()->m_AutoplaceFields.enable )
833 {
834 // Not placed yet, so pass a nullptr screen reference
835 symbol->AutoplaceFields( nullptr, AUTOPLACE_AUTO );
836 }
837
838 schframe->Raise();
840 EE_ACTIONS::PLACE_SYMBOL_PARAMS{ symbol, true } );
841 }
842
843 return 0;
844}
845
846
848{
849 if( !m_isSymbolEditor )
850 return 0;
851
852 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
853 const int deltaUnit = aEvent.Parameter<int>();
854
855 const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
856 const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
857
858 editFrame->SetUnit( newUnit );
859
860 return 0;
861}
862
863
865{
866 // clang-format off
874
876
883
890
893
897
900
904
909
912 // clang-format on
913}
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:216
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:104
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
AUTOPLACE_FIELDS m_AutoplaceFields
static TOOL_ACTION deleteSymbol
Definition: ee_actions.h:213
static TOOL_ACTION cutSymbol
Definition: ee_actions.h:214
static TOOL_ACTION saveSymbolAs
Definition: ee_actions.h:206
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:79
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION showHiddenFields
Definition: ee_actions.h:242
static TOOL_ACTION duplicateSymbol
Definition: ee_actions.h:211
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:142
static TOOL_ACTION newSymbol
Definition: ee_actions.h:208
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:141
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: ee_actions.h:180
static TOOL_ACTION editSymbol
Definition: ee_actions.h:210
static TOOL_ACTION saveLibraryAs
Definition: ee_actions.h:205
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:187
static TOOL_ACTION showPinNumbers
Definition: ee_actions.h:258
static TOOL_ACTION togglePinAltIcons
Definition: ee_actions.h:250
static TOOL_ACTION exportSymbolAsSVG
Definition: ee_actions.h:263
static TOOL_ACTION importSymbol
Definition: ee_actions.h:217
static TOOL_ACTION saveSymbolCopyAs
Definition: ee_actions.h:207
static TOOL_ACTION copySymbol
Definition: ee_actions.h:215
static TOOL_ACTION renameSymbol
Definition: ee_actions.h:212
static TOOL_ACTION previousUnit
Definition: ee_actions.h:266
static TOOL_ACTION toggleSyncedPinsMode
Definition: ee_actions.h:251
static TOOL_ACTION nextUnit
Definition: ee_actions.h:267
static TOOL_ACTION showHiddenPins
Definition: ee_actions.h:241
static TOOL_ACTION exportSymbolView
Definition: ee_actions.h:262
static TOOL_ACTION deriveFromExistingSymbol
Definition: ee_actions.h:209
static TOOL_ACTION pasteSymbol
Definition: ee_actions.h:216
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:257
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
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:84
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:154
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:975
SCH_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxString GetName() const override
Definition: lib_symbol.h:148
int GetUnitCount() const override
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:322
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:689
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
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:1214
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:132
Schematic symbol object.
Definition: sch_symbol.h:77
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
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)
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
LIB_SYMBOL * GetBufferedSymbol(const wxString &aAlias, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &oldAlias, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
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.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
void SetSymbolModified(const wxString &aAlias, const wxString &aLibrary)
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
bool RemoveSymbol(const wxString &aName, const wxString &aLibrary)
Remove the symbol from the symbol buffer.
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 DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
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:1073
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
Definition: string_utils.h:54
constexpr int IUToMils(int iu) const
Definition: base_units.h:99
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
Definition of file extensions used in Kicad.