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 (C) 2019-2024 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
25#include <advanced_config.h>
26#include <kiway.h>
27#include <pgm_base.h>
28#include <sch_painter.h>
29#include <tool/tool_manager.h>
30#include <tools/ee_actions.h>
32#include <symbol_edit_frame.h>
34#include <symbol_viewer_frame.h>
38#include <confirm.h>
39#include <kidialog.h>
40#include <gestfich.h> // To open with a text editor
41#include <wx/filedlg.h>
42#include "wx/generic/textdlgg.h"
43#include "string_utils.h"
44
46{
47 m_frame = getEditFrame<SCH_BASE_FRAME>();
50
52 {
53 CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
54 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
55
56 wxCHECK( editFrame, false );
57
58 auto libSelectedCondition =
59 [ editFrame ]( const SELECTION& aSel )
60 {
61 LIB_ID sel = editFrame->GetTreeLIBID();
62 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
63 };
64 // The libInferredCondition allows you to do things like New Symbol and Paste with a
65 // symbol selected (in other words, when we know the library context even if the library
66 // itself isn't selected.
67 auto libInferredCondition =
68 [ editFrame ]( const SELECTION& aSel )
69 {
70 LIB_ID sel = editFrame->GetTreeLIBID();
71 return !sel.GetLibNickname().empty();
72 };
73 auto pinnedLibSelectedCondition =
74 [ editFrame ]( const SELECTION& aSel )
75 {
76 LIB_TREE_NODE* node = editFrame->GetCurrentTreeNode();
77 return node && node->m_Type == LIB_TREE_NODE::LIBRARY && node->m_Pinned;
78 };
79 auto unpinnedLibSelectedCondition =
80 [ editFrame ](const SELECTION& aSel )
81 {
82 LIB_TREE_NODE* node = editFrame->GetCurrentTreeNode();
83 return node && node->m_Type == LIB_TREE_NODE::LIBRARY && !node->m_Pinned;
84 };
85 auto symbolSelectedCondition =
86 [ editFrame ]( const SELECTION& aSel )
87 {
88 LIB_ID sel = editFrame->GetTargetLibId();
89 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
90 };
91 auto saveSymbolAsCondition =
92 [ editFrame ]( const SELECTION& aSel )
93 {
94 LIB_ID sel = editFrame->GetTargetLibId();
95 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
96 };
97 auto multiSelectedCondition =
98 [ editFrame ]( const SELECTION& aSel )
99 {
100 return editFrame->GetTreeSelectionCount() > 1;
101 };
102 auto canOpenWithTextEditor =
103 [ editFrame ]( const SELECTION& aSel )
104 {
105 // The option is shown if the lib has no current edits
106 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
107 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
108 bool ret = !libMgr.IsLibraryModified( libName );
109 return ret;
110 };
111
112 ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLibSelectedCondition );
113 ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition );
114
115 ctxMenu.AddSeparator();
116 ctxMenu.AddItem( EE_ACTIONS::newSymbol, libInferredCondition );
117 ctxMenu.AddItem( EE_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition );
118
119 ctxMenu.AddSeparator();
120 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition );
121 ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition );
122 ctxMenu.AddItem( EE_ACTIONS::saveSymbolCopyAs, saveSymbolAsCondition );
123 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition );
124
125 ctxMenu.AddSeparator();
126 ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition || multiSelectedCondition );
127 ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition || multiSelectedCondition );
128 ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition );
129 ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition );
130 ctxMenu.AddItem( EE_ACTIONS::renameSymbol, symbolSelectedCondition );
131 ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSelectedCondition );
132
133 ctxMenu.AddSeparator();
134 ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition );
135
136 // If we've got nothing else to show, at least show a hide tree option
137 ctxMenu.AddSeparator();
138 ctxMenu.AddItem( EE_ACTIONS::hideSymbolTree, !libInferredCondition );
139
141 {
142 ctxMenu.AddSeparator();
144 canOpenWithTextEditor
145 && ( symbolSelectedCondition || libSelectedCondition ) );
146 }
147 }
148
149 return true;
150}
151
152
154{
155 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
156
158 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
159
160 return 0;
161}
162
163
165{
166 wxString libFile = *aEvent.Parameter<wxString*>();
168 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
169
170 return 0;
171}
172
173
175{
177 {
178 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
179 int unit = 0;
180 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
181
182 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
183 }
184
185 return 0;
186}
187
188
190{
192 {
193 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
194
195 LIB_ID target = editFrame->GetTargetLibId();
196 const wxString& libName = target.GetLibNickname();
197 wxString msg;
198
199 if( libName.IsEmpty() )
200 {
201 msg.Printf( _( "No symbol library selected." ) );
203 return 0;
204 }
205
206 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
207 {
208 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
210 return 0;
211 }
212
213 if( aEvent.IsAction( &EE_ACTIONS::newSymbol ) )
214 {
215 editFrame->CreateNewSymbol();
216 }
218 {
219 editFrame->CreateNewSymbol( target.GetLibItemName() );
220 }
221 else if( aEvent.IsAction( &EE_ACTIONS::importSymbol ) )
222 {
223 editFrame->ImportSymbol();
224 }
225 }
226
227 return 0;
228}
229
230
232{
234 {
235 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
236
237 if( aEvt.IsAction( &EE_ACTIONS::save ) )
238 editFrame->Save();
239 else if( aEvt.IsAction( &EE_ACTIONS::saveLibraryAs ) )
240 editFrame->SaveLibraryAs();
241 else if( aEvt.IsAction( &EE_ACTIONS::saveSymbolCopyAs ) )
242 editFrame->SaveSymbolCopyAs();
243 else if( aEvt.IsAction( &EE_ACTIONS::saveAll ) )
244 editFrame->SaveAll();
245 }
246
247 return 0;
248}
249
250
252{
254 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
255
256 return 0;
257}
258
259
261{
263 {
264 wxString fullEditorName = Pgm().GetTextEditor();
265
266 if( fullEditorName.IsEmpty() )
267 {
268 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
269 return 0;
270 }
271
272 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
273
274 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
275
276 LIB_ID libId = editFrame->GetTreeLIBID();
277
278 wxString libName = libId.GetLibNickname();
279 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
280
281 if( !tempFName.IsEmpty() )
282 {
283 ExecuteFile( fullEditorName, tempFName, nullptr, false );
284 }
285 }
286 return 0;
287}
288
289
291{
293 {
294 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
295
297 editFrame->CopySymbolToClipboard();
298
300 {
301 bool hasWritableLibs = false;
302 wxString msg;
303
304 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
305 {
306 const wxString& libName = sel.GetLibNickname();
307
308 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
309 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
310 else
311 hasWritableLibs = true;
312 }
313
314 if( !msg.IsEmpty() )
316
317 if( !hasWritableLibs )
318 return 0;
319
320 editFrame->DeleteSymbolFromLibrary();
321 }
322 }
323
324 return 0;
325}
326
327
329{
331 {
332 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
333 LIB_ID sel = editFrame->GetTargetLibId();
334 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
335 // saved symbol in clipboard
336 bool isPasteAction = aEvent.IsAction( &EE_ACTIONS::pasteSymbol );
337 wxString msg;
338
339 if( !sel.IsValid() && !isPasteAction )
340 {
341 // When duplicating a symbol, a source symbol must exists.
342 msg.Printf( _( "No symbol selected" ) );
344 return 0;
345 }
346
347 const wxString& libName = sel.GetLibNickname();
348
349 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
350 {
351 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
353 return 0;
354 }
355
356 editFrame->DuplicateSymbol( isPasteAction );
357 }
358
359 return 0;
360}
361
362
363class RENAME_DIALOG : public wxTextEntryDialog
364{
365public:
366 RENAME_DIALOG( wxWindow* aParent, const wxString& aName,
367 std::function<bool( wxString newName )> aValidator ) :
368 wxTextEntryDialog( aParent, _( "New name:" ), _( "Change Symbol Name" ), aName ),
369 m_validator( std::move( aValidator ) )
370 { }
371
372 wxString GetSymbolName()
373 {
374 wxString name = EscapeString( m_textctrl->GetValue(), CTX_LIBID );
375 name.Trim( true ).Trim( false );
376 return name;
377 }
378
379protected:
381 {
382 return m_validator( GetSymbolName() );
383 }
384
385private:
386 std::function<bool( wxString newName )> m_validator;
387};
388
389
391{
393 {
394 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
395 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
396
397 LIB_ID libId = editFrame->GetTreeLIBID();
398 wxString libName = libId.GetLibNickname();
399 wxString symbolName = libId.GetLibItemName();
400 wxString msg;
401
402 if( !libMgr.LibraryExists( libName ) )
403 return 0;
404
405 RENAME_DIALOG dlg( m_frame, symbolName,
406 [&]( wxString newName )
407 {
408 if( newName.IsEmpty() )
409 {
410 wxMessageBox( _( "Symbol must have a name." ) );
411 return false;
412 }
413
414 if( libMgr.SymbolExists( newName, libName ) )
415 {
416 msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'." ),
417 newName, libName );
418
419 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
420 wxOK | wxCANCEL | wxICON_WARNING );
421 errorDlg.SetOKLabel( _( "Overwrite" ) );
422
423 return errorDlg.ShowModal() == wxID_OK;
424 }
425
426 return true;
427 } );
428
429 if( dlg.ShowModal() != wxID_OK )
430 return 0; // canceled by user
431
432 wxString newName = dlg.GetSymbolName();
433 wxString oldName = symbolName;
434 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
435 bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
436
437 if( !libSymbol )
438 return 0;
439
440 libSymbol->SetName( newName );
441
442 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
443 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
444
445 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
446 libMgr.SetSymbolModified( newName, libName );
447
448 if( isCurrentSymbol && editFrame->GetCurSymbol())
449 {
450 libSymbol = editFrame->GetCurSymbol();
451
452 libSymbol->SetName( newName );
453
454 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
455 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
456
457 editFrame->RebuildView();
458 editFrame->OnModify();
459 editFrame->UpdateTitle();
460
461 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
462 // invalidate the view pointers by rebuilting the field table
463 editFrame->UpdateMsgPanel();
464 }
465
466 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
467 editFrame->UpdateLibraryTree( treeItem, libSymbol );
468 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
469 }
470
471 return 0;
472}
473
474
476{
477 int bodyStyle = aEvent.IsAction( &EE_ACTIONS::showDeMorganStandard ) ? BODY_STYLE::BASE
478 : BODY_STYLE::DEMORGAN;
479
481 {
484
485 SYMBOL_EDIT_FRAME* symbolEditor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
486 symbolEditor->SetBodyStyle( bodyStyle );
487
489 symbolEditor->RebuildView();
490 }
491 else if( m_frame->IsType( FRAME_SCH_VIEWER ) )
492 {
493 SYMBOL_VIEWER_FRAME* symbolViewer = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
494 symbolViewer->SetUnitAndBodyStyle( symbolViewer->GetUnit(), bodyStyle );
495 }
496
497 return 0;
498}
499
500
502{
504 {
505 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
506 LIB_TREE_NODE* currentNode = editFrame->GetCurrentTreeNode();
507
508 if( currentNode && !currentNode->m_Pinned )
509 {
510 m_frame->Prj().PinLibrary( currentNode->m_LibId.GetLibNickname(), true );
511
512 currentNode->m_Pinned = true;
513 editFrame->RegenerateLibraryTree();
514 }
515 }
516
517 return 0;
518}
519
520
522{
524 {
525 SYMBOL_EDIT_FRAME* editFrame = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
526 LIB_TREE_NODE* currentNode = editFrame->GetCurrentTreeNode();
527
528 if( currentNode && currentNode->m_Pinned )
529 {
530 m_frame->Prj().UnpinLibrary( currentNode->m_LibId.GetLibNickname(), true );
531
532 currentNode->m_Pinned = false;
533 editFrame->RegenerateLibraryTree();
534 }
535 }
536
537 return 0;
538}
539
540
542{
544 {
545 wxCommandEvent dummy;
546 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->OnToggleSymbolTree( dummy );
547 }
548
549 return 0;
550}
551
552
554{
556 {
557 SYMBOL_EDIT_FRAME& sym_edit_frame = static_cast<SYMBOL_EDIT_FRAME&>( *m_frame );
558
559 if( !sym_edit_frame.IsSymbolTreeShown() )
560 {
561 wxCommandEvent dummy;
562 sym_edit_frame.OnToggleSymbolTree( dummy );
563 }
564 sym_edit_frame.FocusSearchTreeInput();
565 }
566
567 return 0;
568}
569
570
572{
574 getEditFrame<SYMBOL_EDIT_FRAME>()->ToggleProperties();
575
576 return 0;
577}
578
579
581{
582 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
583 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
584
585 // Update canvas
588
589 return 0;
590}
591
592
594{
595 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
596 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
597
598 // Update canvas
601
602 return 0;
603}
604
605
607{
608 if( !m_isSymbolEditor )
609 return 0;
610
611 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
612 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
613
614 return 0;
615}
616
617
619{
620 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
621 editFrame->GetRenderSettings()->m_ShowHiddenPins =
622 !editFrame->GetRenderSettings()->m_ShowHiddenPins;
623
625 editFrame->GetCanvas()->Refresh();
626
627 return 0;
628}
629
630
632{
633 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
636
638 editFrame->GetCanvas()->Refresh();
639
640 return 0;
641}
642
643
645{
646 if( !m_isSymbolEditor )
647 return 0;
648
649 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
650 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
651
652 if( !symbol )
653 {
654 wxMessageBox( _( "No symbol to export" ) );
655 return 0;
656 }
657
658 wxFileName fn( symbol->GetName() );
659 fn.SetExt( "png" );
660
661 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
662
663 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
664 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
665
666 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
667 {
668 // calling wxYield is mandatory under Linux, after closing the file selector dialog
669 // to refresh the screen before creating the PNG or JPEG image from screen
670 wxYield();
671
672 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
673 {
674 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
675 }
676 }
677
678 return 0;
679}
680
681
683{
684 if( !m_isSymbolEditor )
685 return 0;
686
687 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
688 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
689
690 if( !symbol )
691 {
692 wxMessageBox( _( "No symbol to export" ) );
693 return 0;
694 }
695
696 wxFileName fn( symbol->GetName() );
697 fn.SetExt( FILEEXT::SVGFileExtension );
698
699 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
700
701 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
703 wxFD_SAVE,
704 m_frame );
705
706 if( !fullFileName.IsEmpty() )
707 {
708 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
709 PAGE_INFO pageTemp = pageSave;
710
711 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
712 editFrame->GetBodyStyle(), false );
713
714 // Add a small margin (10% of size)to the plot bounding box
715 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
716
717 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
718 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
719
720 // Add an offet to plot the symbol centered on the page.
721 VECTOR2I plot_offset = symbolBBox.GetOrigin();
722
723 editFrame->GetScreen()->SetPageSettings( pageTemp );
724 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
725 editFrame->GetScreen()->SetPageSettings( pageSave );
726 }
727
728 return 0;
729}
730
731
733{
734 LIB_SYMBOL* libSymbol = nullptr;
735 LIB_ID libId;
736 int unit, bodyStyle;
737
738 if( m_isSymbolEditor )
739 {
740 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
741
742 libSymbol = editFrame->GetCurSymbol();
743 unit = editFrame->GetUnit();
744 bodyStyle = editFrame->GetBodyStyle();
745
746 if( libSymbol )
747 libId = libSymbol->GetLibId();
748 }
749 else
750 {
751 SYMBOL_VIEWER_FRAME* viewerFrame = getEditFrame<SYMBOL_VIEWER_FRAME>();
752
753 libSymbol = viewerFrame->GetSelectedSymbol();
754 unit = viewerFrame->GetUnit();
755 bodyStyle = viewerFrame->GetBodyStyle();
756
757 if( libSymbol )
758 libId = libSymbol->GetLibId();
759 }
760
761 if( libSymbol )
762 {
763 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
764
765 if( !schframe ) // happens when the schematic editor is not active (or closed)
766 {
767 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
768 return 0;
769 }
770
771 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
772
773 if( blocking_dialog )
774 {
775 blocking_dialog->Raise();
776 wxBell();
777 return 0;
778 }
779
780 wxCHECK( libSymbol->GetLibId().IsValid(), 0 );
781
782 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
783 unit, bodyStyle );
784
785 symbol->SetParent( schframe->GetScreen() );
786
787 if( schframe->eeconfig()->m_AutoplaceFields.enable )
788 symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
789
790 schframe->Raise();
791 schframe->GetToolManager()->PostAction( EE_ACTIONS::placeSymbol, symbol );
792 }
793
794 return 0;
795}
796
797
799{
806
808
814
825
828
837
841}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION addLibrary
Definition: actions.h:49
static TOOL_ACTION pinLibrary
Definition: actions.h:140
static TOOL_ACTION saveAll
Definition: actions.h:54
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION unpinLibrary
Definition: actions.h:141
static TOOL_ACTION showProperties
Definition: actions.h:201
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.
const Vec & GetOrigin() const
Definition: box2.h:200
const SizeVec & GetSize() const
Definition: box2.h:196
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
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:103
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:207
static TOOL_ACTION cutSymbol
Definition: ee_actions.h:208
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 openWithTextEditor
Definition: ee_actions.h:215
static TOOL_ACTION showHiddenFields
Definition: ee_actions.h:237
static TOOL_ACTION duplicateSymbol
Definition: ee_actions.h:205
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:136
static TOOL_ACTION newSymbol
Definition: ee_actions.h:202
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:135
static TOOL_ACTION editSymbol
Definition: ee_actions.h:204
static TOOL_ACTION saveLibraryAs
Definition: ee_actions.h:200
static TOOL_ACTION addSymbolToSchematic
Definition: ee_actions.h:181
static TOOL_ACTION showPinNumbers
Definition: ee_actions.h:251
static TOOL_ACTION exportSymbolAsSVG
Definition: ee_actions.h:258
static TOOL_ACTION importSymbol
Definition: ee_actions.h:211
static TOOL_ACTION saveSymbolCopyAs
Definition: ee_actions.h:201
static TOOL_ACTION symbolTreeSearch
Definition: ee_actions.h:254
static TOOL_ACTION hideSymbolTree
Definition: ee_actions.h:253
static TOOL_ACTION copySymbol
Definition: ee_actions.h:209
static TOOL_ACTION renameSymbol
Definition: ee_actions.h:206
static TOOL_ACTION toggleSyncedPinsMode
Definition: ee_actions.h:244
static TOOL_ACTION showSymbolTree
Definition: ee_actions.h:252
static TOOL_ACTION showHiddenPins
Definition: ee_actions.h:236
static TOOL_ACTION exportSymbolView
Definition: ee_actions.h:257
static TOOL_ACTION deriveFromExistingSymbol
Definition: ee_actions.h:203
static TOOL_ACTION pasteSymbol
Definition: ee_actions.h:210
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:250
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1513
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:669
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:77
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:142
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
SCH_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxString GetName() const override
Definition: lib_symbol.h:136
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:563
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...
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type
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 const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:195
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:129
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:192
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:171
std::function< bool(wxString newName)> m_validator
bool TransferDataFromWindow() override
RENAME_DIALOG(wxWindow *aParent, const wxString &aName, std::function< bool(wxString newName)> aValidator)
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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:1138
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:130
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:131
Schematic symbol object.
Definition: sch_symbol.h:105
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) 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 RenameSymbol(const TOOL_EVENT &newName)
int DuplicateSymbol(const TOOL_EVENT &aEvent)
int SymbolTreeSearch(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
int UnpinLibrary(const TOOL_EVENT &aEvent)
int AddLibrary(const TOOL_EVENT &aEvent)
int AddSymbol(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 ToggleSymbolTree(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 PinLibrary(const TOOL_EVENT &aEvent)
int CutCopyDelete(const TOOL_EVENT &aEvent)
The symbol library editor main window.
void SaveAll()
Save all modified symbols and libraries.
void DeleteSymbolFromLibrary()
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.
LIB_ID GetTargetLibId() const
Return either the symbol selected in the symbol tree (if context menu is active) or the symbol on the...
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 IsSymbolTreeShown() 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
void OnToggleSymbolTree(wxCommandEvent &event)
void SaveSymbolCopyAs()
Save the currently selected symbol to a new name and/or location.
void DuplicateSymbol(bool aFromClipboard)
Insert a duplicate symbol.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_TREE_NODE * GetCurrentTreeNode() const
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void SetBodyStyle(int aBodyStyle)
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 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.
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).
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:217
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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).
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.
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
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:186
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:139
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.
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
STL namespace.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
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.