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>
31#include <tools/ee_actions.h>
34#include <symbol_viewer_frame.h>
38#include <confirm.h>
39#include <kidialog.h>
40#include <launch_ext.h> // To default when file manager setting is empty
41#include <gestfich.h> // To open with a text editor
42#include <wx/filedlg.h>
43#include "string_utils.h"
44
46{
47 m_frame = getEditFrame<SCH_BASE_FRAME>();
50
52 {
54 CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
55 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
56
57 wxCHECK( editFrame, false );
58
59 auto libSelectedCondition =
60 [ editFrame ]( const SELECTION& aSel )
61 {
62 LIB_ID sel = editFrame->GetTreeLIBID();
63 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
64 };
65
66 // The libInferredCondition allows you to do things like New Symbol and Paste with a
67 // symbol selected (in other words, when we know the library context even if the library
68 // itself isn't selected.
69 auto libInferredCondition =
70 [ editFrame ]( const SELECTION& aSel )
71 {
72 LIB_ID sel = editFrame->GetTreeLIBID();
73 return !sel.GetLibNickname().empty();
74 };
75
76 auto symbolSelectedCondition =
77 [ editFrame ]( const SELECTION& aSel )
78 {
79 LIB_ID sel = editFrame->GetTargetLibId();
80 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
81 };
82
83/* not used, but used to be used
84 auto multiSelectedCondition =
85 [ editFrame ]( const SELECTION& aSel )
86 {
87 return editFrame->GetTreeSelectionCount() > 1;
88 };
89*/
90 auto multiSymbolSelectedCondition =
91 [ editFrame ]( const SELECTION& aSel )
92 {
93 if( editFrame->GetTreeSelectionCount() > 1 )
94 {
95 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
96 {
97 if( !sel.IsValid() )
98 return false;
99 }
100 return true;
101 }
102 return false;
103 };
104/* not used, yet
105 auto multiLibrarySelectedCondition =
106 [ editFrame ]( const SELECTION& aSel )
107 {
108 if( editFrame->GetTreeSelectionCount() > 1 )
109 {
110 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
111 {
112 if( sel.IsValid() )
113 return false;
114 }
115 return true;
116 }
117 return false;
118 };
119*/
120 auto canOpenExternally =
121 [ editFrame ]( const SELECTION& aSel )
122 {
123 // The option is shown if the lib has no current edits
124 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
125 wxString libName = editFrame->GetTargetLibId().GetLibNickname();
126 bool ret = !libMgr.IsLibraryModified( libName );
127 return ret;
128 };
129
130// clang-format off
131 ctxMenu.AddItem( EE_ACTIONS::newSymbol, libInferredCondition, 10 );
132 ctxMenu.AddItem( EE_ACTIONS::deriveFromExistingSymbol, symbolSelectedCondition, 10 );
133
134 ctxMenu.AddSeparator( 10 );
135 ctxMenu.AddItem( ACTIONS::save, symbolSelectedCondition || libInferredCondition, 10 );
136 ctxMenu.AddItem( EE_ACTIONS::saveLibraryAs, libSelectedCondition, 10 );
137 ctxMenu.AddItem( EE_ACTIONS::saveSymbolCopyAs, symbolSelectedCondition, 10 );
138 ctxMenu.AddItem( ACTIONS::revert, symbolSelectedCondition || libInferredCondition, 10 );
139
140 ctxMenu.AddSeparator( 10 );
141 ctxMenu.AddItem( EE_ACTIONS::cutSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
142 ctxMenu.AddItem( EE_ACTIONS::copySymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
143 ctxMenu.AddItem( EE_ACTIONS::pasteSymbol, libInferredCondition, 10 );
144 ctxMenu.AddItem( EE_ACTIONS::duplicateSymbol, symbolSelectedCondition, 10 );
145 ctxMenu.AddItem( EE_ACTIONS::renameSymbol, symbolSelectedCondition, 10 );
146 ctxMenu.AddItem( EE_ACTIONS::deleteSymbol, symbolSelectedCondition || multiSymbolSelectedCondition, 10 );
147
148 ctxMenu.AddSeparator( 100 );
149 ctxMenu.AddItem( EE_ACTIONS::importSymbol, libInferredCondition, 100 );
150
152 {
153 ctxMenu.AddSeparator( 200 );
154 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
155 }
156
158 {
159 ctxMenu.AddSeparator( 200 );
160 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( symbolSelectedCondition || libSelectedCondition ), 200 );
161 }
162
163 libraryTreeTool->AddContextMenuItems( &ctxMenu );
164 }
165// clang-format on
166
167 return true;
168}
169
170
172{
173 bool createNew = aEvent.IsAction( &ACTIONS::newLibrary );
174
176 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->AddLibraryFile( createNew );
177
178 return 0;
179}
180
181
183{
184 wxString libFile = *aEvent.Parameter<wxString*>();
185
187 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->DdAddLibrary( libFile );
188
189 return 0;
190}
191
192
194{
195 if( !m_isSymbolEditor )
196 return 0;
197
198 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
199 int unit = 0;
200 LIB_ID partId = editFrame->GetTreeLIBID( &unit );
201
202 editFrame->LoadSymbol( partId.GetLibItemName(), partId.GetLibNickname(), unit );
203 return 0;
204}
205
206
208{
209 if( !m_isSymbolEditor )
210 return 0;
211
212 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
213 LIB_ID target = editFrame->GetTargetLibId();
214 const wxString& libName = target.GetLibNickname();
215 wxString msg;
216
217 if( libName.IsEmpty() )
218 {
219 msg.Printf( _( "No symbol library selected." ) );
221 return 0;
222 }
223
224 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
225 {
226 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
228 return 0;
229 }
230
231 if( aEvent.IsAction( &EE_ACTIONS::newSymbol ) )
232 editFrame->CreateNewSymbol();
234 editFrame->CreateNewSymbol( target.GetLibItemName() );
235 else if( aEvent.IsAction( &EE_ACTIONS::importSymbol ) )
236 editFrame->ImportSymbol();
237
238 return 0;
239}
240
241
243{
244 if( !m_isSymbolEditor )
245 return 0;
246
247 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
248
249 if( aEvt.IsAction( &EE_ACTIONS::save ) )
250 editFrame->Save();
251 else if( aEvt.IsAction( &EE_ACTIONS::saveLibraryAs ) )
252 editFrame->SaveLibraryAs();
253 else if( aEvt.IsAction( &EE_ACTIONS::saveSymbolCopyAs ) )
254 editFrame->SaveSymbolCopyAs();
255 else if( aEvt.IsAction( &EE_ACTIONS::saveAll ) )
256 editFrame->SaveAll();
257
258 return 0;
259}
260
261
263{
265 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->Revert();
266
267 return 0;
268}
269
270
272{
273 if( !m_isSymbolEditor )
274 return 0;
275
276 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
277 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
278
279 LIB_ID libId = editFrame->GetTreeLIBID();
280
281 wxString libName = libId.GetLibNickname();
282 wxString libItemName = libMgr.GetLibrary( libName )->GetFullURI( true );
283
284 wxFileName fileName( libItemName );
285
286 wxString filePath = wxEmptyString;
287
289
290 wxString explCommand = cfg->m_System.file_explorer;
291
292 if( explCommand.IsEmpty() )
293 {
294 filePath = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
295
296 if( !filePath.IsEmpty() && wxDirExists( filePath ) )
297 LaunchExternal( filePath );
298 return 0;
299 }
300
301 if( !explCommand.EndsWith( "%F" ) )
302 {
303 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
304 return 0;
305 }
306
307 filePath = fileName.GetFullPath();
308 filePath.Replace( wxS( "\"" ), wxS( "_" ) );
309
310 wxString fileArg = '"' + filePath + '"';
311
312 explCommand.Replace( wxT( "%F" ), fileArg );
313
314 if( !explCommand.IsEmpty() )
315 wxExecute( explCommand );
316
317 return 0;
318}
319
320
322{
323 if( !m_isSymbolEditor )
324 return 0;
325
326 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
327 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
328 wxString textEditorName = Pgm().GetTextEditor();
329
330 if( textEditorName.IsEmpty() )
331 {
332 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
333 return 0;
334 }
335
336 LIB_ID libId = editFrame->GetTreeLIBID();
337 wxString libName = libId.GetLibNickname();
338 wxString tempFName = libMgr.GetLibrary( libName )->GetFullURI( true ).wc_str();
339
340 if( !tempFName.IsEmpty() )
341 ExecuteFile( textEditorName, tempFName, nullptr, false );
342
343 return 0;
344}
345
346
348{
349 if( !m_isSymbolEditor )
350 return 0;
351
352 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
353
355 editFrame->CopySymbolToClipboard();
356
358 {
359 bool hasWritableLibs = false;
360 wxString msg;
361
362 for( LIB_ID& sel : editFrame->GetSelectedLibIds() )
363 {
364 const wxString& libName = sel.GetLibNickname();
365
366 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
367 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
368 else
369 hasWritableLibs = true;
370 }
371
372 if( !msg.IsEmpty() )
374
375 if( !hasWritableLibs )
376 return 0;
377
378 editFrame->DeleteSymbolFromLibrary();
379 }
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 LIB_ID sel = editFrame->GetTargetLibId();
392 // DuplicateSymbol() is called to duplicate a symbol, or to paste a previously
393 // saved symbol in clipboard
394 bool isPasteAction = aEvent.IsAction( &EE_ACTIONS::pasteSymbol );
395 wxString msg;
396
397 if( !sel.IsValid() && !isPasteAction )
398 {
399 // When duplicating a symbol, a source symbol must exists.
400 msg.Printf( _( "No symbol selected" ) );
402 return 0;
403 }
404
405 const wxString& libName = sel.GetLibNickname();
406
407 if( editFrame->GetLibManager().IsLibraryReadOnly( libName ) )
408 {
409 msg.Printf( _( "Symbol library '%s' is not writable." ), libName );
411 return 0;
412 }
413
414 editFrame->DuplicateSymbol( isPasteAction );
415 return 0;
416}
417
418
420{
421 if( !m_isSymbolEditor )
422 return 0;
423
424 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
425 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = editFrame->GetLibManager();
427
428 LIB_ID libId = editFrame->GetTreeLIBID();
429 wxString libName = libId.GetLibNickname();
430 wxString oldName = libId.GetLibItemName();
431 wxString newName;
432 wxString msg;
433
434 if( !libMgr.LibraryExists( libName ) )
435 return 0;
436
437 if( !libTool->RenameLibrary( _( "Change Symbol Name" ), oldName,
438 [&]( const wxString& aNewName )
439 {
440 newName = EscapeString( aNewName, CTX_LIBID );
441
442 if( newName.IsEmpty() )
443 {
444 wxMessageBox( _( "Symbol must have a name." ) );
445 return false;
446 }
447
448 if( libMgr.SymbolExists( newName, libName ) )
449 {
450 msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'." ),
451 newName, libName );
452
453 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
454 wxOK | wxCANCEL | wxICON_WARNING );
455 errorDlg.SetOKLabel( _( "Overwrite" ) );
456
457 return errorDlg.ShowModal() == wxID_OK;
458 }
459
460 return true;
461 } ) )
462 {
463 return 0; // cancelled by user
464 }
465
466 LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName );
467 bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId );
468
469 if( !libSymbol )
470 return 0;
471
472 libSymbol->SetName( newName );
473
474 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
475 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
476
477 libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName );
478 libMgr.SetSymbolModified( newName, libName );
479
480 if( isCurrentSymbol && editFrame->GetCurSymbol())
481 {
482 libSymbol = editFrame->GetCurSymbol();
483
484 libSymbol->SetName( newName );
485
486 if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName )
487 libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName );
488
489 editFrame->RebuildView();
490 editFrame->OnModify();
491 editFrame->UpdateTitle();
492
493 // N.B. The view needs to be rebuilt first as the Symbol Properties change may
494 // invalidate the view pointers by rebuilting the field table
495 editFrame->UpdateMsgPanel();
496 }
497
498 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId );
499 editFrame->UpdateLibraryTree( treeItem, libSymbol );
500 editFrame->FocusOnLibId( LIB_ID( libName, newName ) );
501 return 0;
502}
503
504
506{
507 int bodyStyle = aEvent.IsAction( &EE_ACTIONS::showDeMorganStandard ) ? BODY_STYLE::BASE
508 : BODY_STYLE::DEMORGAN;
509
511 {
514
515 SYMBOL_EDIT_FRAME* symbolEditor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
516 symbolEditor->SetBodyStyle( bodyStyle );
517
519 symbolEditor->RebuildView();
520 }
521 else if( m_frame->IsType( FRAME_SCH_VIEWER ) )
522 {
523 SYMBOL_VIEWER_FRAME* symbolViewer = static_cast<SYMBOL_VIEWER_FRAME*>( m_frame );
524 symbolViewer->SetUnitAndBodyStyle( symbolViewer->GetUnit(), bodyStyle );
525 }
526
527 return 0;
528}
529
530
532{
534 getEditFrame<SYMBOL_EDIT_FRAME>()->ToggleProperties();
535
536 return 0;
537}
538
539
541{
542 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
543 renderSettings->m_ShowPinsElectricalType = !renderSettings->m_ShowPinsElectricalType;
544
545 // Update canvas
548
549 return 0;
550}
551
552
554{
555 SCH_RENDER_SETTINGS* renderSettings = m_frame->GetRenderSettings();
556 renderSettings->m_ShowPinNumbers = !renderSettings->m_ShowPinNumbers;
557
558 // Update canvas
561
562 return 0;
563}
564
565
567{
568 if( !m_isSymbolEditor )
569 return 0;
570
571 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
572 editFrame->m_SyncPinEdit = !editFrame->m_SyncPinEdit;
573
574 return 0;
575}
576
577
579{
580 if( !m_isSymbolEditor )
581 return 0;
582
583 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
584 editFrame->GetRenderSettings()->m_ShowHiddenPins =
585 !editFrame->GetRenderSettings()->m_ShowHiddenPins;
586
588 editFrame->GetCanvas()->Refresh();
589 return 0;
590}
591
592
594{
595 if( !m_isSymbolEditor )
596 return 0;
597
598 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
601
603 editFrame->GetCanvas()->Refresh();
604 return 0;
605}
606
607
609{
610 if( !m_isSymbolEditor )
611 return 0;
612
613 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
614 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
615
616 if( !symbol )
617 {
618 wxMessageBox( _( "No symbol to export" ) );
619 return 0;
620 }
621
622 wxFileName fn( symbol->GetName() );
623 fn.SetExt( "png" );
624
625 wxString projectPath = wxPathOnly( m_frame->Prj().GetProjectFullName() );
626
627 wxFileDialog dlg( editFrame, _( "Export View as PNG" ), projectPath, fn.GetFullName(),
628 FILEEXT::PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
629
630 if( dlg.ShowModal() == wxID_OK && !dlg.GetPath().IsEmpty() )
631 {
632 // calling wxYield is mandatory under Linux, after closing the file selector dialog
633 // to refresh the screen before creating the PNG or JPEG image from screen
634 wxYield();
635
636 if( !editFrame->SaveCanvasImageToFile( dlg.GetPath(), BITMAP_TYPE::PNG ) )
637 {
638 wxMessageBox( wxString::Format( _( "Can't save file '%s'." ), dlg.GetPath() ) );
639 }
640 }
641
642 return 0;
643}
644
645
647{
648 if( !m_isSymbolEditor )
649 return 0;
650
651 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
652 LIB_SYMBOL* symbol = editFrame->GetCurSymbol();
653
654 if( !symbol )
655 {
656 wxMessageBox( _( "No symbol to export" ) );
657 return 0;
658 }
659
660 wxFileName fn( symbol->GetName() );
661 fn.SetExt( FILEEXT::SVGFileExtension );
662
663 wxString pro_dir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
664
665 wxString fullFileName = wxFileSelector( _( "SVG File Name" ), pro_dir, fn.GetFullName(),
667 wxFD_SAVE,
668 m_frame );
669
670 if( !fullFileName.IsEmpty() )
671 {
672 PAGE_INFO pageSave = editFrame->GetScreen()->GetPageSettings();
673 PAGE_INFO pageTemp = pageSave;
674
675 BOX2I symbolBBox = symbol->GetUnitBoundingBox( editFrame->GetUnit(),
676 editFrame->GetBodyStyle(), false );
677
678 // Add a small margin (10% of size)to the plot bounding box
679 symbolBBox.Inflate( symbolBBox.GetSize().x * 0.1, symbolBBox.GetSize().y * 0.1 );
680
681 pageTemp.SetWidthMils( schIUScale.IUToMils( symbolBBox.GetSize().x ) );
682 pageTemp.SetHeightMils( schIUScale.IUToMils( symbolBBox.GetSize().y ) );
683
684 // Add an offet to plot the symbol centered on the page.
685 VECTOR2I plot_offset = symbolBBox.GetOrigin();
686
687 editFrame->GetScreen()->SetPageSettings( pageTemp );
688 editFrame->SVGPlotSymbol( fullFileName, -plot_offset );
689 editFrame->GetScreen()->SetPageSettings( pageSave );
690 }
691
692 return 0;
693}
694
695
697{
698 LIB_SYMBOL* libSymbol = nullptr;
699 LIB_ID libId;
700 int unit, bodyStyle;
701
702 if( m_isSymbolEditor )
703 {
704 SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
705
706 libSymbol = editFrame->GetCurSymbol();
707 unit = editFrame->GetUnit();
708 bodyStyle = editFrame->GetBodyStyle();
709
710 if( libSymbol )
711 libId = libSymbol->GetLibId();
712 }
713 else
714 {
715 SYMBOL_VIEWER_FRAME* viewerFrame = getEditFrame<SYMBOL_VIEWER_FRAME>();
716
717 libSymbol = viewerFrame->GetSelectedSymbol();
718 unit = viewerFrame->GetUnit();
719 bodyStyle = viewerFrame->GetBodyStyle();
720
721 if( libSymbol )
722 libId = libSymbol->GetLibId();
723 }
724
725 if( libSymbol )
726 {
727 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH, false );
728
729 if( !schframe ) // happens when the schematic editor is not active (or closed)
730 {
731 DisplayErrorMessage( m_frame, _( "No schematic currently open." ) );
732 return 0;
733 }
734
735 wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
736
737 if( blocking_dialog )
738 {
739 blocking_dialog->Raise();
740 wxBell();
741 return 0;
742 }
743
744 wxCHECK( libSymbol->GetLibId().IsValid(), 0 );
745
746 SCH_SYMBOL* symbol = new SCH_SYMBOL( *libSymbol, libId, &schframe->GetCurrentSheet(),
747 unit, bodyStyle );
748
749 symbol->SetParent( schframe->GetScreen() );
750
751 if( schframe->eeconfig()->m_AutoplaceFields.enable )
752 symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
753
754 schframe->Raise();
755 schframe->GetToolManager()->PostAction( EE_ACTIONS::placeSymbol, symbol );
756 }
757
758 return 0;
759}
760
761
763{
770
772
778
785
788
792
795
799
803}
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:206
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 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:94
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 showHiddenFields
Definition: ee_actions.h:236
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:256
static TOOL_ACTION importSymbol
Definition: ee_actions.h:211
static TOOL_ACTION saveSymbolCopyAs
Definition: ee_actions.h:201
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 showHiddenPins
Definition: ee_actions.h:235
static TOOL_ACTION exportSymbolView
Definition: ee_actions.h:255
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
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:1563
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
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:78
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:143
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:930
SCH_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxString GetName() const override
Definition: lib_symbol.h:137
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:288
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:678
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
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:1189
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 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 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 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)
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.
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
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_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 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:218
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: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:139
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:57
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
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.