KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_edit_frame.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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <bitmaps.h>
27#include <wx/hyperlink.h>
28#include <base_screen.h>
29#include <symbol_library.h>
30#include <confirm.h>
31#include <core/kicad_algo.h>
32#include <eeschema_id.h>
33#include <eeschema_settings.h>
34#include <env_paths.h>
36#include <kiface_base.h>
37#include <kiplatform/app.h>
38#include <kiway_express.h>
39#include <symbol_edit_frame.h>
42#include <paths.h>
43#include <pgm_base.h>
44#include <project_sch.h>
45#include <sch_painter.h>
46#include <sch_view.h>
48#include <symbol_lib_table.h>
49#include <tool/action_manager.h>
50#include <tool/action_toolbar.h>
51#include <tool/common_control.h>
52#include <tool/common_tools.h>
54#include <tool/picker_tool.h>
56#include <tool/selection.h>
58#include <tool/tool_manager.h>
59#include <tool/zoom_tool.h>
60#include <tools/ee_actions.h>
69#include <view/view_controls.h>
71#include <widgets/wx_infobar.h>
72#include <widgets/lib_tree.h>
79#include <panel_sym_lib_table.h>
80#include <string_utils.h>
81#include <wx/msgdlg.h>
82
83
85
86
87BEGIN_EVENT_TABLE( SYMBOL_EDIT_FRAME, SCH_BASE_FRAME )
89
90 // menubar commands
91 EVT_MENU( wxID_EXIT, SYMBOL_EDIT_FRAME::OnExitKiCad )
92 EVT_MENU( wxID_CLOSE, SYMBOL_EDIT_FRAME::CloseWindow )
93
94 // Update user interface elements.
96
97 // Drop files event
98 EVT_DROP_FILES( SYMBOL_EDIT_FRAME::OnDropFiles )
99
100END_EVENT_TABLE()
101
102
103SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
104 SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_SYMBOL_EDITOR, _( "Library Editor" ),
105 wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
107 m_unitSelectBox( nullptr ),
108 m_isSymbolFromSchematic( false )
109{
110 SetShowDeMorgan( false );
111 m_SyncPinEdit = false;
112
113 m_symbol = nullptr;
114 m_treePane = nullptr;
115 m_libMgr = nullptr;
116 m_unit = 1;
117 m_bodyStyle = 1;
118 m_aboutTitle = _HKI( "KiCad Symbol Editor" );
119
120 wxIcon icon;
121 wxIconBundle icon_bundle;
122
123 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 48 ) );
124 icon_bundle.AddIcon( icon );
125 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 256 ) );
126 icon_bundle.AddIcon( icon );
127 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 128 ) );
128 icon_bundle.AddIcon( icon );
129 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit_32 ) );
130 icon_bundle.AddIcon( icon );
131 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit_16 ) );
132 icon_bundle.AddIcon( icon );
133
134 SetIcons( icon_bundle );
135
137 LoadSettings( m_settings );
138
139 m_libMgr = new LIB_SYMBOL_LIBRARY_MANAGER( *this );
140 bool loadingCancelled = false;
141
142 {
143 // Preload libraries before using SyncLibraries the first time, as the preload is
144 // multi-threaded
145 WX_PROGRESS_REPORTER reporter( this, _( "Loading Symbol Libraries" ),
146 m_libMgr->GetLibraryCount(), true );
147 m_libMgr->Preload( reporter );
148
149 loadingCancelled = reporter.IsCancelled();
150 wxSafeYield();
151 }
152
153 SyncLibraries( false, loadingCancelled );
154 m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
155 m_treePane->GetLibTree()->SetSortMode( (LIB_TREE_MODEL_ADAPTER::SORT_MODE) m_settings->m_LibrarySortMode );
156
157 resolveCanvasType();
158 SwitchCanvas( m_canvasType );
159
160 // Ensure axis are always drawn
161 KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions();
162 gal_opts.m_axesEnabled = true;
163
164 m_dummyScreen = new SCH_SCREEN();
165 SetScreen( m_dummyScreen );
166 GetScreen()->m_Center = true;
167
168 GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
169
170 GetRenderSettings()->LoadColors( GetColorSettings() );
171 GetRenderSettings()->m_IsSymbolEditor = true;
172 GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
173
174 setupTools();
175 setupUIConditions();
176
177 ReCreateMenuBar();
178 ReCreateHToolbar();
179 ReCreateVToolbar();
180 ReCreateOptToolbar();
181
182 UpdateTitle();
183 UpdateSymbolMsgPanelInfo();
184 RebuildSymbolUnitsList();
185
186 m_propertiesPanel = new SCH_PROPERTIES_PANEL( this, this );
187 m_propertiesPanel->SetSplitterProportion( m_settings->m_AuiPanels.properties_splitter );
188
189 m_selectionFilterPanel = new PANEL_SCH_SELECTION_FILTER( this );
190
191 m_auimgr.SetManagedWindow( this );
192
193 CreateInfoBar();
194
195 // Rows; layers 4 - 6
196 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
197 .Top().Layer( 6 ) );
198
199 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
200 .Bottom().Layer( 6 ) );
201
202 // Columns; layers 1 - 3
203 m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "SymbolTree" )
204 .Left().Layer( 3 )
205 .TopDockable( false ).BottomDockable( false )
206 .Caption( _( "Libraries" ) )
207 .MinSize( FromDIP( 250 ), -1 ).BestSize( FromDIP( 250 ), -1 ) );
208
209 m_auimgr.AddPane( m_propertiesPanel, defaultPropertiesPaneInfo( this ) );
210 // Show or hide m_propertiesPanel depending on current settings:
211 wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
212
213 m_auimgr.AddPane( m_selectionFilterPanel, defaultSchSelectionFilterPaneInfo( this ) );
214
215 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
216 // The selection filter doesn't need to grow in the vertical direction when docked
217 selectionFilterPane.dock_proportion = 0;
218
219 propertiesPaneInfo.Show( m_settings->m_AuiPanels.show_properties );
220 updateSelectionFilterVisbility();
221
222 m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
223 .Left().Layer( 2 ) );
224
225 m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
226 .Right().Layer( 2 ) );
227
228 // Center
229 m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" )
230 .CentrePane() );
231
232 FinishAUIInitialization();
233
234 // Can't put this in LoadSettings, because it has to be called before setupTools :/
235 EE_SELECTION_TOOL* selTool = GetToolManager()->GetTool<EE_SELECTION_TOOL>();
236 selTool->GetFilter() = GetSettings()->m_SelectionFilter;
237
238 if( m_settings->m_LibWidth > 0 )
239 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "SymbolTree" ), m_settings->m_LibWidth, -1 );
240
241 Raise();
242 Show( true );
243
244 SyncView();
245 GetCanvas()->GetView()->UseDrawPriority( true );
246 GetCanvas()->GetGAL()->SetAxesEnabled( true );
247
248 setupUnits( m_settings );
249
250 // Set the working/draw area size to display a symbol to a reasonable value:
251 // A 600mm x 600mm with a origin at the area center looks like a large working area
252 double max_size_x = schIUScale.mmToIU( 600 );
253 double max_size_y = schIUScale.mmToIU( 600 );
254 BOX2D bbox;
255 bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
256 bbox.SetSize( max_size_x, max_size_y );
257 GetCanvas()->GetView()->SetBoundary( bbox );
258
259 m_toolManager->RunAction( ACTIONS::zoomFitScreen );
260
262 DragAcceptFiles( true );
263
264 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Library changes are unsaved" ) );
265
266 // Catch unhandled accelerator command characters that were no handled by the library tree
267 // panel.
268 Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
269 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
270
271 // Ensure the window is on top
272 Raise();
273
274 if( loadingCancelled )
275 ShowInfoBarWarning( _( "Symbol library loading was cancelled by user." ) );
276}
277
278
280{
281 // Shutdown all running tools
282 if( m_toolManager )
284
285 setSymWatcher( nullptr );
286
288 {
289 delete m_symbol;
290 m_symbol = nullptr;
291
292 SCH_SCREEN* screen = GetScreen();
293 delete screen;
295 }
296
297 // current screen is destroyed in EDA_DRAW_FRAME
299
300 SYMBOL_EDITOR_SETTINGS* cfg = nullptr;
301
302 try
303 {
305 }
306 catch( const std::runtime_error& e )
307 {
308 wxFAIL_MSG( e.what() );
309 }
310
311 if( cfg )
312 {
313 Pgm().GetSettingsManager().Save( cfg );
314 }
315
316 delete m_libMgr;
317}
318
319
321{
322 wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_boardAdapter" );
323
325
329 GetRenderSettings()->SetDefaultFont( wxEmptyString );
330}
331
332
334{
335 wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_boardAdapter" );
336
338
340
344
345 m_settings->m_LibWidth = m_treePane->GetSize().x;
346
348
350 bool prop_shown = m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
352
355}
356
357
359{
360 return static_cast<APP_SETTINGS_BASE*>( GetSettings() );
361}
362
363
365{
367
368 if( GetSettings()->m_UseEeschemaColorSettings )
370 else
371 return mgr.GetColorSettings( GetSettings()->m_ColorTheme );
372}
373
374
376{
377 // Create the manager and dispatcher & route draw panel events to the dispatcher
380 GetCanvas()->GetViewControls(), GetSettings(), this );
381 m_actions = new EE_ACTIONS();
383
384 // Register tools
399
400 // Run the selection tool, it is supposed to be always active
401 m_toolManager->InvokeTool( "eeschema.InteractiveSelection" );
402
404}
405
406
408{
410
412 EDITOR_CONDITIONS cond( this );
413
414 wxASSERT( mgr );
415
416#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
417#define CHECK( x ) ACTION_CONDITIONS().Check( x )
418
419 auto haveSymbolCond =
420 [this]( const SELECTION& )
421 {
422 return m_symbol;
423 };
424
425 auto isEditableCond =
426 [this]( const SELECTION& )
427 {
428 // Only root symbols from the new s-expression libraries or the schematic
429 // are editable.
430 return IsSymbolEditable() && !IsSymbolAlias();
431 };
432
433 auto symbolModifiedCondition =
434 [this]( const SELECTION& sel )
435 {
438 };
439
440 auto libSelectedCondition =
441 [this]( const SELECTION& sel )
442 {
443 return !GetTargetLibId().GetLibNickname().empty();
444 };
445
446 auto canEditProperties =
447 [this]( const SELECTION& sel )
448 {
450 };
451
452 auto saveSymbolAsCondition =
453 [this]( const SELECTION& aSel )
454 {
455 return getTargetSymbol() != nullptr;
456 };
457
460 mgr->SetConditions( EE_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) );
461 mgr->SetConditions( EE_ACTIONS::saveSymbolCopyAs, ENABLE( saveSymbolAsCondition ) );
464
465 mgr->SetConditions( ACTIONS::undo, ENABLE( haveSymbolCond && cond.UndoAvailable() ) );
466 mgr->SetConditions( ACTIONS::redo, ENABLE( haveSymbolCond && cond.RedoAvailable() ) );
467 mgr->SetConditions( ACTIONS::revert, ENABLE( symbolModifiedCondition ) );
468
472 mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
473 mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
474 mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
475
476 mgr->SetConditions( ACTIONS::cut, ENABLE( isEditableCond ) );
477 mgr->SetConditions( ACTIONS::copy, ENABLE( haveSymbolCond ) );
479 mgr->SetConditions( ACTIONS::doDelete, ENABLE( isEditableCond ) );
480 mgr->SetConditions( ACTIONS::duplicate, ENABLE( isEditableCond ) );
481 mgr->SetConditions( ACTIONS::selectAll, ENABLE( haveSymbolCond ) );
482 mgr->SetConditions( ACTIONS::unselectAll, ENABLE( haveSymbolCond ) );
483
484 mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( isEditableCond ) );
485 mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( isEditableCond ) );
486 mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( isEditableCond ) );
487 mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( isEditableCond ) );
488
491
492 auto pinTypeCond =
493 [this]( const SELECTION& )
494 {
496 };
497
498 auto hiddenPinCond =
499 [this]( const SELECTION& )
500 {
502 };
503
504 auto hiddenFieldCond =
505 [this]( const SELECTION& )
506 {
508 };
509
510 auto showCompTreeCond =
511 [this]( const SELECTION& )
512 {
513 return IsSymbolTreeShown();
514 };
515
516 auto propertiesCond =
517 [this] ( const SELECTION& )
518 {
519 return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
520 };
521
524 mgr->SetConditions( EE_ACTIONS::showSymbolTree, CHECK( showCompTreeCond ) );
525 mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
526 mgr->SetConditions( EE_ACTIONS::showHiddenPins, CHECK( hiddenPinCond ) );
527 mgr->SetConditions( EE_ACTIONS::showHiddenFields, CHECK( hiddenFieldCond ) );
528
529 auto demorganCond =
530 [this]( const SELECTION& )
531 {
532 return GetShowDeMorgan();
533 };
534
535 auto demorganStandardCond =
536 [this]( const SELECTION& )
537 {
538 return m_bodyStyle == BODY_STYLE::BASE;
539 };
540
541 auto demorganAlternateCond =
542 [this]( const SELECTION& )
543 {
544 return m_bodyStyle == BODY_STYLE::DEMORGAN;
545 };
546
547 auto multiUnitModeCond =
548 [this]( const SELECTION& )
549 {
550 return m_symbol && m_symbol->IsMulti() && !m_symbol->UnitsLocked();
551 };
552
553 auto hasMultipleUnitsCond =
554 [this]( const SELECTION& )
555 {
556 return m_symbol && m_symbol->IsMulti();
557 };
558
559 auto syncedPinsModeCond =
560 [this]( const SELECTION& )
561 {
562 return m_SyncPinEdit;
563 };
564
565 auto haveDatasheetCond =
566 [this]( const SELECTION& )
567 {
568 return m_symbol && !m_symbol->GetDatasheetField().GetText().IsEmpty();
569 };
570
571 mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
572 mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( canEditProperties && haveSymbolCond ) );
573 mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( haveSymbolCond ) );
574 mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( isEditableCond && haveSymbolCond ) );
575
577 ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
579 ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganAlternateCond ) );
581 ACTION_CONDITIONS().Enable( multiUnitModeCond ).Check( syncedPinsModeCond ) );
583 ACTION_CONDITIONS().Enable( isEditableCond && hasMultipleUnitsCond ) );
584
585// Only enable a tool if the symbol is edtable
586#define EDIT_TOOL( tool ) ACTION_CONDITIONS().Enable( isEditableCond ).Check( cond.CurrentTool( tool ) )
587
599
600#undef CHECK
601#undef ENABLE
602#undef EDIT_TOOL
603}
604
605
607{
608 if( IsContentModified() )
609 {
610 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
611 wxString msg = _( "Save changes to '%s' before closing?" );
612
613 switch( UnsavedChangesDialog( this, wxString::Format( msg, m_reference ), nullptr ) )
614 {
615 case wxID_YES:
616 if( schframe && GetCurSymbol() ) // Should be always the case
618
619 break;
620
621 case wxID_NO:
622 break;
623
624 default:
625 case wxID_CANCEL:
626 return false;
627 }
628 }
629
630 if( doClose )
631 {
632 SetCurSymbol( nullptr, false );
633 UpdateTitle();
634 }
635
636 return true;
637}
638
639
640bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
641{
642 // Shutdown blocks must be determined and vetoed as early as possible
644 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
645 && IsContentModified() )
646 {
647 return false;
648 }
649
651 return false;
652
653 if( !saveAllLibraries( true ) )
654 return false;
655
656 // Save symbol tree column widths
657 m_libMgr->GetAdapter()->SaveSettings();
658
659 return true;
660}
661
662
664{
665 Destroy();
666}
667
668
670{
671 if( !m_unitSelectBox )
672 return;
673
674 if( m_unitSelectBox->GetCount() != 0 )
675 m_unitSelectBox->Clear();
676
677 if( !m_symbol || m_symbol->GetUnitCount() <= 1 )
678 {
679 m_unit = 1;
680 m_unitSelectBox->Append( wxEmptyString );
681 }
682 else
683 {
684 for( int i = 0; i < m_symbol->GetUnitCount(); i++ )
685 {
686 wxString unitDisplayName = m_symbol->GetUnitDisplayName( i + 1 );
687 m_unitSelectBox->Append( unitDisplayName );
688 }
689 }
690
691 // Ensure the selected unit is compatible with the number of units of the current symbol:
693 m_unit = 1;
694
695 m_unitSelectBox->SetSelection(( m_unit > 0 ) ? m_unit - 1 : 0 );
696}
697
698
699void SYMBOL_EDIT_FRAME::OnToggleSymbolTree( wxCommandEvent& event )
700{
701 wxAuiPaneInfo& treePane = m_auimgr.GetPane( m_treePane );
702 treePane.Show( !IsSymbolTreeShown() );
704 m_auimgr.Update();
705}
706
707
709{
710 return const_cast<wxAuiManager&>( m_auimgr ).GetPane( m_treePane ).IsShown();
711}
712
713
715{
716 m_treePane->Freeze();
717 m_libMgr->GetAdapter()->Freeze();
718}
719
720
722{
723 m_libMgr->GetAdapter()->Thaw();
724 m_treePane->Thaw();
725}
726
727
728void SYMBOL_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
729{
730 Kiway().OnKiCadExit();
731}
732
733
734void SYMBOL_EDIT_FRAME::OnUpdateUnitNumber( wxUpdateUIEvent& event )
735{
736 event.Enable( m_symbol && m_symbol->GetUnitCount() > 1 );
737}
738
739
740void SYMBOL_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event )
741{
742 int i = event.GetSelection();
743
744 if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
745 return;
746
749
750 m_unit = i + 1;
751
753 RebuildView();
755}
756
757
759{
760 if( m_symbol )
761 {
763
764 if( row && row->GetType() == SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) )
765 return true;
766 }
767
768 return false;
769}
770
771
773{
774 wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
775
776 if( !libNickname.empty() )
777 {
778 if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( libNickname ) )
779 {
780 Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
781 libNickname = wxEmptyString;
782 }
783 }
784
785 return libNickname;
786}
787
788
789wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
790{
791 wxString old = GetCurLib();
792
793 if( aLibNickname.empty() || !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( aLibNickname ) )
794 Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
795 else
797
798 return old;
799}
800
801
802void SYMBOL_EDIT_FRAME::SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom )
803{
804 wxCHECK( m_toolManager, /* void */ );
805
807 GetCanvas()->GetView()->Clear();
808 delete m_symbol;
809
810 m_symbol = aSymbol;
811
812 // select the current symbol in the tree widget
815 else
817
818 wxString symbolName = m_symbol ? m_symbol->GetName() : wxString();
819
820 // retain in case this wxFrame is re-opened later on the same PROJECT
822
823 // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
824 m_SyncPinEdit = aSymbol && aSymbol->IsRoot() && aSymbol->IsMulti() && !aSymbol->UnitsLocked();
825
827
835
836 if( aUpdateZoom )
838
839 GetCanvas()->Refresh();
840
841 WX_INFOBAR* infobar = GetInfoBar();
842
844 {
845 wxString msg;
846 msg.Printf( _( "Editing symbol %s from schematic. Saving will update the schematic "
847 "only." ), m_reference );
848
849 infobar->RemoveAllButtons();
850 infobar->ShowMessage( msg, wxICON_INFORMATION );
851 }
852 else if( IsSymbolFromLegacyLibrary() )
853 {
854 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY,
855 _( "Manage symbol libraries" ),
856 wxEmptyString );
857
858 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
859 [this]( wxHyperlinkEvent& aEvent )
860 {
862 } ) );
863
864 infobar->RemoveAllButtons();
865 infobar->AddButton( button );
866 infobar->ShowMessage( _( "Symbols in legacy libraries are not editable. Use Manage "
867 "Symbol Libraries to migrate to current format." ),
868 wxICON_INFORMATION );
869 }
870 else if( IsSymbolAlias() )
871 {
872 wxString rootSymbolName;
873
874 // Don't assume the parent symbol shared pointer is still valid.
875 if( std::shared_ptr<LIB_SYMBOL> rootSymbol = m_symbol->GetRootSymbol() )
876 rootSymbolName = rootSymbol->GetName();
877 else
878 {
879 wxCHECK( false, /* void */ );
880 }
881
882 int unit = GetUnit();
883 int bodyStyle = GetBodyStyle();
884 wxString msg;
885 wxString link;
886
887 msg.Printf( _( "Symbol %s is a derived symbol. Symbol graphics will not be editable." ),
888 UnescapeString( symbolName ) );
889
890 link.Printf( _( "Open %s" ), UnescapeString( rootSymbolName ) );
891
892 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, link, wxEmptyString );
893 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
894 [this, rootSymbolName, unit, bodyStyle]( wxHyperlinkEvent& aEvent )
895 {
896 LoadSymbolFromCurrentLib( rootSymbolName, unit, bodyStyle );
897 } ) );
898
899 infobar->RemoveAllButtons();
900 infobar->AddButton( button );
901 infobar->ShowMessage( msg, wxICON_INFORMATION );
902 }
903 else
904 {
905 infobar->Dismiss();
906 }
907}
908
909
911{
912 wxASSERT( m_libMgr );
913 return *m_libMgr;
914}
915
916
918{
920
922 m_autoSaveRequired = true;
923
924 if( !IsSymbolFromSchematic() )
926
928
929 if( !GetTitle().StartsWith( "*" ) )
930 UpdateTitle();
931}
932
933
935{
937}
938
939
940wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
941{
942 // Select the target library table (global/project)
944
945 if( !libTable )
946 return wxEmptyString;
947
948 wxFileName fn = m_libMgr->GetUniqueLibraryName();
949
952 ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
954 {
955 return wxEmptyString;
956 }
957
958 wxString libName = fn.GetName();
959
960 if( libName.IsEmpty() )
961 return wxEmptyString;
962
963 if( m_libMgr->LibraryExists( libName ) )
964 {
965 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
966 return wxEmptyString;
967 }
968
969 if( aCreateNew )
970 {
971 if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
972 {
973 DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
974 "Make sure you have write permissions and "
975 "try again." ),
976 fn.GetFullPath() ) );
977 return wxEmptyString;
978 }
979 }
980 else
981 {
982 if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
983 {
984 DisplayError( this, _( "Could not open the library file." ) );
985 return wxEmptyString;
986 }
987 }
988
989 bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
990 saveSymbolLibTables( globalTable, !globalTable );
991
992 std::string packet = fn.GetFullPath().ToStdString();
994
995 return fn.GetFullPath();
996}
997
998
999void SYMBOL_EDIT_FRAME::DdAddLibrary( wxString aLibFile )
1000{
1001 // Select the target library table (global/project)
1002 SYMBOL_LIB_TABLE* libTable = SelectSymLibTable();
1003
1004 if( !libTable )
1005 return;
1006
1007 wxFileName fn = wxFileName( aLibFile );
1008
1009 wxString libName = fn.GetName();
1010
1011 if( libName.IsEmpty() )
1012 return;
1013
1014 if( m_libMgr->LibraryExists( libName ) )
1015 {
1016 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
1017 return;
1018 }
1019
1020 if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
1021 {
1022 DisplayError( this, _( "Could not open the library file." ) );
1023 return;
1024 }
1025
1026 bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
1027 saveSymbolLibTables( globalTable, !globalTable );
1028
1029 std::string packet = fn.GetFullPath().ToStdString();
1031}
1032
1033
1035{
1036 return m_treePane->GetLibTree()->GetSelectedLibId( aUnit );
1037}
1038
1039
1041{
1043}
1044
1045int SYMBOL_EDIT_FRAME::GetTreeLIBIDs( std::vector<LIB_ID>& aSelection ) const
1046{
1047 return m_treePane->GetLibTree()->GetSelectedLibIds( aSelection );
1048}
1049
1050
1052{
1053 if( IsSymbolTreeShown() )
1054 {
1055 LIB_ID libId = GetTreeLIBID();
1056
1057 if( libId.IsValid() )
1058 return m_libMgr->GetAlias( libId.GetLibItemName(), libId.GetLibNickname() );
1059 }
1060
1061 return m_symbol;
1062}
1063
1064
1066{
1067 LIB_ID id;
1068
1069 if( IsSymbolTreeShown() )
1070 id = GetTreeLIBID();
1071
1072 if( id.GetLibNickname().empty() && m_symbol )
1073 id = m_symbol->GetLibId();
1074
1075 return id;
1076}
1077
1078
1079std::vector<LIB_ID> SYMBOL_EDIT_FRAME::GetSelectedLibIds() const
1080{
1081 std::vector<LIB_ID> ids;
1082 GetTreeLIBIDs( ids );
1083 return ids;
1084}
1085
1086
1088{
1090}
1091
1092
1094{
1095 return GetTargetLibId().GetLibNickname();
1096}
1097
1098
1099void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress, bool aPreloadCancelled,
1100 const wxString& aForceRefresh )
1101{
1102 LIB_ID selected;
1103
1104 if( m_treePane )
1105 selected = m_treePane->GetLibTree()->GetSelectedLibId();
1106
1107 if( aShowProgress )
1108 {
1109 APP_PROGRESS_DIALOG progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
1110 m_libMgr->GetAdapter()->GetLibrariesCount(), this );
1111
1112 m_libMgr->Sync( aForceRefresh,
1113 [&]( int progress, int max, const wxString& libName )
1114 {
1115 progressDlg.Update( progress, wxString::Format( _( "Loading library '%s'..." ),
1116 libName ) );
1117 } );
1118 }
1119 else if( !aPreloadCancelled )
1120 {
1121 m_libMgr->Sync( aForceRefresh,
1122 [&]( int progress, int max, const wxString& libName )
1123 {
1124 } );
1125 }
1126
1127 if( m_treePane )
1128 {
1129 wxDataViewItem found;
1130
1131 if( selected.IsValid() )
1132 {
1133 // Check if the previously selected item is still valid,
1134 // if not - it has to be unselected to prevent crash
1135 found = m_libMgr->GetAdapter()->FindItem( selected );
1136
1137 if( !found )
1139 }
1140
1141 m_treePane->GetLibTree()->Regenerate( true );
1142
1143 // Try to select the parent library, in case the symbol is not found
1144 if( !found && selected.IsValid() )
1145 {
1146 selected.SetLibItemName( "" );
1147 found = m_libMgr->GetAdapter()->FindItem( selected );
1148
1149 if( found )
1150 m_treePane->GetLibTree()->SelectLibId( selected );
1151 }
1152
1153 // If no selection, see if there's a current symbol to centre
1154 if( !selected.IsValid() && m_symbol )
1155 {
1156 LIB_ID current( GetCurLib(), m_symbol->GetName() );
1157 m_treePane->GetLibTree()->CenterLibId( current );
1158 }
1159 }
1160}
1161
1162
1164{
1165 LIB_ID target = GetTargetLibId();
1166
1167 m_treePane->GetLibTree()->Regenerate( true );
1168
1169 if( target.IsValid() )
1170 m_treePane->GetLibTree()->CenterLibId( target );
1171}
1172
1173
1175{
1177}
1178
1179
1181{
1182 m_treePane->GetLibTree()->SelectLibId( aLibID );
1183}
1184
1185
1186void SYMBOL_EDIT_FRAME::UpdateLibraryTree( const wxDataViewItem& aTreeItem, LIB_SYMBOL* aSymbol )
1187{
1188 if( aTreeItem.IsOk() ) // Can be not found in tree if the current footprint is imported
1189 // from file therefore not yet in tree.
1190 {
1191 static_cast<LIB_TREE_NODE_ITEM*>( aTreeItem.GetID() )->Update( aSymbol );
1193 }
1194}
1195
1196
1197bool SYMBOL_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
1198{
1199 if( aOriginalFile.FileExists() )
1200 {
1201 wxFileName backupFileName( aOriginalFile );
1202 backupFileName.SetExt( aBackupExt );
1203
1204 if( backupFileName.FileExists() )
1205 wxRemoveFile( backupFileName.GetFullPath() );
1206
1207 if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
1208 {
1209 DisplayError( this, wxString::Format( _( "Failed to save backup to '%s'." ),
1210 backupFileName.GetFullPath() ) );
1211 return false;
1212 }
1213 }
1214
1215 return true;
1216}
1217
1218
1220{
1221 if( m_symbol && !GetCurLib().IsEmpty() && GetScreen()->IsContentModified() )
1222 m_libMgr->UpdateSymbol( m_symbol, GetCurLib() ); // UpdateSymbol() makes a copy
1223}
1224
1225
1227{
1228 // This will return the root symbol of any alias
1230 aLibId.GetLibNickname() );
1231
1232 // Now we can compare the libId of the current symbol and the root symbol
1233 return ( symbol && m_symbol && symbol->GetLibId() == m_symbol->GetLibId() );
1234}
1235
1236
1238{
1240 SetCurLib( wxEmptyString );
1241 SetCurSymbol( nullptr, false );
1245 Refresh();
1246}
1247
1248
1249void SYMBOL_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1250{
1251 SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1252
1255
1259
1261
1262 if( m_symbol )
1264
1266
1268 GetCanvas()->Refresh();
1269
1271
1272 if( aEnvVarsChanged )
1273 SyncLibraries( true );
1274
1275 Layout();
1276 SendSizeEvent();
1277}
1278
1279
1281{
1282 // call my base class
1284
1285 // tooltips in toolbars
1287
1288 // For some obscure reason, the AUI manager hides the first modified pane.
1289 // So force show panes
1290 wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
1291 bool tree_shown = tree_pane_info.IsShown();
1292 tree_pane_info.Caption( _( "Libraries" ) );
1293 tree_pane_info.Show( tree_shown );
1294 m_auimgr.Update();
1295
1297
1298 // status bar
1300
1301 if( GetRenderSettings()->m_ShowPinsElectricalType )
1302 {
1304 GetCanvas()->Refresh();
1305 }
1306
1307 UpdateTitle();
1308}
1309
1310
1312{
1313 SCH_BASE_FRAME::SetScreen( aScreen );
1314
1315 // Let tools add things to the view if necessary
1316 if( m_toolManager )
1318}
1319
1320
1322{
1330
1331 // Let tools add things to the view if necessary
1332 if( m_toolManager )
1334
1336 GetCanvas()->Refresh();
1337}
1338
1339
1341{
1342 SyncLibraries( true );
1343
1344 if( m_symbol )
1345 {
1347 EE_SELECTION& selection = selectionTool->GetSelection();
1348
1349 for( SCH_ITEM& item : m_symbol->GetDrawItems() )
1350 {
1351 if( !alg::contains( selection, &item ) )
1352 item.ClearSelected();
1353 else
1354 item.SetSelected();
1355 }
1356
1358 }
1359
1360 RebuildView();
1361}
1362
1363
1364const BOX2I SYMBOL_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1365{
1366 if( !m_symbol )
1367 {
1368 // Gives a reasonable drawing area size
1369 int width = schIUScale.mmToIU( 50 );
1370 int height = schIUScale.mmToIU( 30 );
1371
1372 return BOX2I( VECTOR2I( -width/2, -height/2 ),
1373 VECTOR2I( width, height ) );
1374 }
1375 else
1376 {
1377 return m_symbol->Flatten()->GetUnitBoundingBox( m_unit, m_bodyStyle );
1378 }
1379}
1380
1381
1383{
1384 static KIID lastBrightenedItemID( niluuid );
1385
1386 SCH_ITEM* lastItem = nullptr;
1387
1388 if( m_symbol )
1389 {
1390 for( SCH_PIN* pin : m_symbol->GetAllLibPins() )
1391 {
1392 if( pin->m_Uuid == lastBrightenedItemID )
1393 lastItem = pin;
1394 }
1395
1396 std::vector<SCH_FIELD*> fields;
1397 m_symbol->GetFields( fields );
1398
1399 for( SCH_FIELD* field : fields )
1400 {
1401 if( field->m_Uuid == lastBrightenedItemID )
1402 lastItem = field;
1403 }
1404 }
1405
1406 if( lastItem && lastItem != aItem )
1407 {
1408 lastItem->ClearBrightened();
1409
1410 UpdateItem( lastItem );
1411 lastBrightenedItemID = niluuid;
1412 }
1413
1414 if( aItem )
1415 {
1416 if( !aItem->IsBrightened() )
1417 {
1418 aItem->SetBrightened();
1419
1420 UpdateItem( aItem );
1421 lastBrightenedItemID = aItem->m_Uuid;
1422 }
1423
1424 FocusOnLocation( VECTOR2I( aItem->GetFocusPosition().x, -aItem->GetFocusPosition().y ) );
1425 }
1426}
1427
1428
1430{
1431 const std::string& payload = mail.GetPayload();
1432
1433 switch( mail.Command() )
1434 {
1435 case MAIL_LIB_EDIT:
1436 if( !payload.empty() )
1437 {
1438 wxString libFileName( payload );
1439 wxString libNickname;
1440 wxString msg;
1441
1443 const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
1444
1445 if( !libTableRow )
1446 {
1447 msg.Printf( _( "The current configuration does not include the symbol library '%s'." ),
1448 libFileName );
1449 msg += wxS( "\n" ) + _( "Use Manage Symbol Libraries to edit the configuration." );
1450 DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
1451 break;
1452 }
1453
1454 libNickname = libTableRow->GetNickName();
1455
1456 if( !libTable->HasLibrary( libNickname, true ) )
1457 {
1458 msg.Printf( _( "The symbol library '%s' is not enabled in the current configuration." ),
1459 UnescapeString( libNickname ) );
1460 msg += wxS( "\n" ) + _( "Use Manage Symbol Libraries to edit the configuration." );
1461 DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
1462 break;
1463 }
1464
1465 SetCurLib( libNickname );
1466
1467 if( m_treePane )
1468 {
1469 LIB_ID id( libNickname, wxEmptyString );
1473 }
1474 }
1475
1476 break;
1477
1478 case MAIL_RELOAD_LIB:
1479 {
1480 wxString currentLib = GetCurLib();
1482
1484
1485 // Check if the currently selected symbol library been removed or disabled.
1486 if( !currentLib.empty() && libTable && !libTable->HasLibrary( currentLib, true ) )
1487 {
1488 SetCurLib( wxEmptyString );
1489 emptyScreen();
1490 }
1491
1492 SyncLibraries( true );
1495
1496 break;
1497 }
1498
1500 {
1502 LIB_SYMBOL* symbol = GetCurSymbol();
1503
1504 wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s",
1505 payload );
1506
1507 if( !tbl || !symbol )
1508 break;
1509
1510 wxString libName = symbol->GetLibId().GetLibNickname();
1511 const SYMBOL_LIB_TABLE_ROW* row = tbl->FindRow( libName );
1512
1513 if( !row )
1514 return;
1515
1516 wxFileName libfullname( row->GetFullURI( true ) );
1517
1518 wxFileName changedLib( mail.GetPayload() );
1519 wxLogTrace( "KICAD_LIB_WATCH",
1520 "Received refresh symbol request for %s, current symbols is %s",
1521 changedLib.GetFullPath(), libfullname.GetFullPath() );
1522
1523 if( changedLib == libfullname )
1524 {
1525 wxLogTrace( "KICAD_LIB_WATCH", "Refreshing symbol %s", symbol->GetName() );
1526
1527 SetScreen( m_dummyScreen ); // UpdateLibraryBuffer will destroy the old screen
1528 m_libMgr->UpdateLibraryBuffer( libName );
1529
1530 LIB_SYMBOL* lib_symbol = m_libMgr->GetBufferedSymbol( symbol->GetName(), libName );
1531 wxCHECK2_MSG( lib_symbol, break, wxString::Format( "Symbol %s not found in library %s",
1532 symbol->GetName(), libName ) );
1533
1534 // The buffered screen for the symbol
1535 SCH_SCREEN* symbol_screen = m_libMgr->GetScreen( lib_symbol->GetName(), libName );
1536
1537 SetScreen( symbol_screen );
1538 SetCurSymbol( new LIB_SYMBOL( *lib_symbol ), false );
1540 SetShowDeMorgan( GetCurSymbol()->HasAlternateBodyStyle() );
1541
1542 if( m_toolManager )
1544 }
1545
1546 break;
1547 }
1548
1549 default:
1550 ;
1551 }
1552}
1553
1554
1556{
1557 // switches currently used canvas ( Cairo / OpenGL):
1558 SCH_BASE_FRAME::SwitchCanvas( aCanvasType );
1559
1560 // Set options specific to symbol editor (axies are always enabled):
1561 GetCanvas()->GetGAL()->SetAxesEnabled( true );
1563}
1564
1565
1567{
1568 wxCHECK( m_libMgr, false );
1569
1570 return m_libMgr->HasModifications();
1571}
1572
1573
1575{
1576 wxCHECK( m_libMgr, false );
1577
1578 // Test if the currently edited symbol is modified
1580 return true;
1581
1582 // Test if any library has been modified
1583 for( const wxString& libName : m_libMgr->GetLibraryNames() )
1584 {
1585 if( m_libMgr->IsLibraryModified( libName ) && !m_libMgr->IsLibraryReadOnly( libName ) )
1586 return true;
1587 }
1588
1589 return false;
1590}
1591
1592
1594{
1595 if( aItemCount == 0 )
1596 return;
1597
1598 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
1599
1600 if( aItemCount < 0 )
1601 {
1602 list.ClearCommandList();
1603 }
1604 else
1605 {
1606 for( int ii = 0; ii < aItemCount; ii++ )
1607 {
1608 if( list.m_CommandsList.size() == 0 )
1609 break;
1610
1611 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
1612 list.m_CommandsList.erase( list.m_CommandsList.begin() );
1613
1614 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
1615 {
1616 delete aItem;
1617 } );
1618 delete curr_cmd; // Delete command
1619 }
1620 }
1621}
1622
1623
1625{
1626 return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
1627}
1628
1629
1631{
1632 std::unique_ptr<LIB_SYMBOL> symbol = aSymbol->GetLibSymbolRef()->Flatten();
1633 wxCHECK( symbol, /* void */ );
1634
1635 // Take in account the symbol orientation and mirroring. to calculate the field
1636 // positions in symbol editor (i.e. no rotation, no mirroring)
1637 int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
1638 int mirror = aSymbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y );
1639
1640 std::vector<SCH_FIELD> fullSetOfFields;
1641
1642 for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i )
1643 {
1644 const SCH_FIELD& field = aSymbol->GetFields()[i];
1645 VECTOR2I pos = field.GetPosition() - aSymbol->GetPosition();
1646 SCH_FIELD libField( symbol.get(), field.GetId() );
1647
1648 if( i >= MANDATORY_FIELDS && !field.GetName( false ).IsEmpty() )
1649 libField.SetName( field.GetName( false ) );
1650
1651 libField.SetText( field.GetText() );
1652 libField.SetAttributes( field );
1653
1654 // The inverse transform is mirroring before, rotate after
1655 switch( mirror )
1656 {
1657 default:; break;
1658 case SYM_MIRROR_X: pos.y = -pos.y; break;
1659 case SYM_MIRROR_Y: pos.x = -pos.x; break;
1660 }
1661
1662 switch( orientation )
1663 {
1664 default:
1665 case SYM_ORIENT_0: break;
1666 case SYM_ORIENT_90:
1667 std::swap( pos.x, pos.y );
1668 pos.x = - pos.x;
1669 break;
1670 case SYM_ORIENT_270:
1671 std::swap( pos.x, pos.y );
1672 pos.y = - pos.y;
1673 break;
1674 case SYM_ORIENT_180:
1675 pos.x = - pos.x;
1676 pos.y = - pos.y;
1677 break;
1678 }
1679
1680 libField.SetPosition( VECTOR2I( pos.x, -pos.y ) );
1681
1682 fullSetOfFields.emplace_back( std::move( libField ) );
1683 }
1684
1685 symbol->SetFields( fullSetOfFields );
1686
1687 if( m_symbol )
1688 SetCurSymbol( nullptr, false );
1689
1691 m_schematicSymbolUUID = aSymbol->m_Uuid;
1692 m_reference = symbol->GetFieldById( REFERENCE_FIELD )->GetText();
1693 m_unit = std::max( 1, aSymbol->GetUnit() );
1694 m_bodyStyle = std::max( 1, aSymbol->GetBodyStyle() );
1695
1696 // Optimize default edit options for this symbol
1697 // Usually if units are locked, graphic items are specific to each unit
1698 // and if units are interchangeable, graphic items are common to units
1700 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
1701
1702 // The buffered screen for the symbol
1703 SCH_SCREEN* tmpScreen = new SCH_SCREEN();
1704
1705 SetScreen( tmpScreen );
1706 SetCurSymbol( symbol.release(), true );
1707 setSymWatcher( nullptr );
1708
1711
1712 if( IsSymbolTreeShown() )
1713 {
1714 wxCommandEvent evt;
1715 OnToggleSymbolTree( evt );
1716 }
1717
1718 UpdateTitle();
1720 SetShowDeMorgan( GetCurSymbol()->HasAlternateBodyStyle() );
1722
1723 // Let tools add things to the view if necessary
1724 if( m_toolManager )
1726
1728 GetCanvas()->Refresh();
1729}
1730
1731
1732bool SYMBOL_EDIT_FRAME::addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE aScope )
1733{
1734 wxFileName fn = aLibFile;
1735 wxFileName libTableFileName( Prj().GetProjectPath(),
1737 wxString libNickname = fn.GetName();
1739 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1740
1741 if( libTable->HasLibrary( libNickname ) )
1742 {
1743 wxString tmp;
1744 int suffix = 1;
1745
1746 while( libTable->HasLibrary( libNickname ) )
1747 {
1748 tmp.Printf( "%s%d", fn.GetName(), suffix );
1749 libNickname = tmp;
1750 suffix += 1;
1751 }
1752 }
1753
1755 row->SetNickName( libNickname );
1756
1757 wxString normalizedPath = NormalizePath( aLibFile, &envVars, Prj().GetProjectPath() );
1758
1759 if( aScope == GLOBAL_LIB_TABLE )
1760 {
1762 libTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
1763
1764 // We cannot normalize against the current project path when saving to global table.
1765 normalizedPath = NormalizePath( aLibFile, &envVars, wxEmptyString );
1766 }
1767
1768 row->SetFullURI( normalizedPath );
1769
1770 wxCHECK( libTable->InsertRow( row ), false );
1771
1772 try
1773 {
1774 libTable->Save( libTableFileName.GetFullPath() );
1775 }
1776 catch( const IO_ERROR& ioe )
1777 {
1778 wxString msg = aScope == GLOBAL_LIB_TABLE ? _( "Error saving global library table." )
1779 : _( "Error saving project library table." );
1780
1781 wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1782 dlg.SetExtendedMessage( ioe.What() );
1783 dlg.ShowModal();
1784
1785 return false;
1786 }
1787
1788 return true;
1789}
1790
1791
1792bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname,
1793 const wxString& aLibFile )
1794{
1795 // Check the global library table first because checking the project library table
1796 // checks the global library table as well due to library chaining.
1797 bool isGlobalTable = true;
1798 wxFileName libTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();;
1799 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1801 SYMBOL_LIB_TABLE_ROW* row = libTable->FindRow( aLibNickname );
1802
1803 if( !row )
1804 {
1805 libTableFileName.SetPath( Prj().GetProjectPath() );
1806 libTableFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
1807 libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
1808 isGlobalTable = false;
1809 row = libTable->FindRow( aLibNickname );
1810 }
1811
1812 wxCHECK( row, false );
1813
1814 wxString projectPath;
1815
1816 if( !isGlobalTable )
1817 projectPath = Prj().GetProjectPath();
1818
1819 wxString normalizedPath = NormalizePath( aLibFile, &envVars, projectPath );
1820
1821 row->SetFullURI( normalizedPath );
1822 row->SetType( "KiCad" );
1823
1824 try
1825 {
1826 libTable->Save( libTableFileName.GetFullPath() );
1827 }
1828 catch( const IO_ERROR& ioe )
1829 {
1830 wxString msg = isGlobalTable ? _( "Error saving global library table." )
1831 : _( "Error saving project library table." );
1832
1833 wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1834 dlg.SetExtendedMessage( ioe.What() );
1835 dlg.ShowModal();
1836
1837 return false;
1838 }
1839
1840 return true;
1841}
1842
1843
1845{
1846 return m_symbol && !m_symbol->IsRoot();
1847}
1848
1849
1851{
1853}
1854
1855
1856void SYMBOL_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
1857{
1858 SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
1859
1860 if( EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( aItem ) )
1861 {
1862 eda_text->ClearBoundingBoxCache();
1863 eda_text->ClearRenderCache();
1864 }
1865}
1866
1867
1869{
1870 wxAuiPaneInfo& treePane = m_auimgr.GetPane( "SymbolTree" );
1871 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
1872 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
1873
1874 // Don't give the selection filter its own visibility controls; instead show it if
1875 // anything else is visible
1876 bool showFilter = ( treePane.IsShown() && treePane.IsDocked() )
1877 || ( propertiesPane.IsShown() && propertiesPane.IsDocked() );
1878
1879 selectionFilterPane.Show( showFilter );
1880}
1881
1882
1884{
1885 // Returns the current render option for invisible fields
1887}
1888
1889
1891{
1892 // Returns the current render option for invisible pins
1894}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
@ icon_libedit_32
@ icon_libedit
@ icon_libedit_16
BOX2< VECTOR2I > BOX2I
Definition: box2.h:877
static TOOL_ACTION toggleGrid
Definition: actions.h:172
static TOOL_ACTION paste
Definition: actions.h:70
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION millimetersUnits
Definition: actions.h:180
static TOOL_ACTION unselectAll
Definition: actions.h:73
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION copy
Definition: actions.h:69
static TOOL_ACTION milsUnits
Definition: actions.h:179
static TOOL_ACTION toggleBoundingBoxes
Definition: actions.h:135
static TOOL_ACTION saveAll
Definition: actions.h:54
static TOOL_ACTION undo
Definition: actions.h:66
static TOOL_ACTION duplicate
Definition: actions.h:74
static TOOL_ACTION inchesUnits
Definition: actions.h:178
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:132
static TOOL_ACTION doDelete
Definition: actions.h:75
static TOOL_ACTION selectionTool
Definition: actions.h:187
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
static TOOL_ACTION redo
Definition: actions.h:67
static TOOL_ACTION deleteTool
Definition: actions.h:76
static TOOL_ACTION zoomTool
Definition: actions.h:127
static TOOL_ACTION showProperties
Definition: actions.h:201
static TOOL_ACTION cut
Definition: actions.h:68
static TOOL_ACTION ddAddLibrary
Definition: actions.h:60
static TOOL_ACTION toggleGridOverrides
Definition: actions.h:173
static TOOL_ACTION selectAll
Definition: actions.h:72
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
wxProgressDialog with the option to also update the application progress on the taskbar
virtual bool Update(int aValue, const wxString &aNewMsg=wxEmptyString, bool *aSkip=nullptr) override
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:170
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:173
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
void SetOrigin(const Vec &pos)
Definition: box2.h:227
void SetSize(const SizeVec &size)
Definition: box2.h:238
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
Definition: common_tools.h:38
UNDO_REDO_CONTAINER m_undoList
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
SETTINGS_MANAGER * GetSettingsManager() const
UNDO_REDO_LIST
Specifies whether we are interacting with the undo or redo stacks.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
wxAuiManager m_auimgr
UNDO_REDO_CONTAINER m_redoList
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handles event fired when a file is dropped to the window.
void ReCreateMenuBar()
Recreates the menu bar.
WX_INFOBAR * GetInfoBar()
COLOR_SETTINGS * m_colorSettings
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
static const wxString PropertiesPaneName()
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual void SetScreen(BASE_SCREEN *aScreen)
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
PROPERTIES_PANEL * m_propertiesPanel
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:249
const KIID m_Uuid
Definition: eda_item.h:485
void ClearBrightened()
Definition: eda_item.h:122
void SetBrightened()
Definition: eda_item.h:119
bool IsBrightened() const
Definition: eda_item.h:111
Specialization of the wxAuiPaneInfo class for KiCad panels.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:290
Class that groups generic conditions for editor states.
SELECTION_CONDITION BoundingBoxes()
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
virtual SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION GridOverrides()
Create a functor testing if the grid overrides wires is enabled in a frame.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
Gather all the actions that are shared by tools.
Definition: ee_actions.h:39
static TOOL_ACTION mirrorV
Definition: ee_actions.h:126
static TOOL_ACTION runERC
Definition: ee_actions.h:151
static TOOL_ACTION pinTable
Definition: ee_actions.h:156
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION placeSymbolAnchor
Definition: ee_actions.h:117
static TOOL_ACTION showHiddenFields
Definition: ee_actions.h:237
static TOOL_ACTION drawSymbolPolygon
Definition: ee_actions.h:116
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:136
static TOOL_ACTION newSymbol
Definition: ee_actions.h:202
static TOOL_ACTION drawCircle
Definition: ee_actions.h:101
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:135
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:125
static TOOL_ACTION saveLibraryAs
Definition: ee_actions.h:200
static TOOL_ACTION placeSymbolText
Definition: ee_actions.h:113
static TOOL_ACTION mirrorH
Definition: ee_actions.h:127
static TOOL_ACTION rotateCW
Definition: ee_actions.h:124
static TOOL_ACTION importGraphics
Definition: ee_actions.h:255
static TOOL_ACTION importSymbol
Definition: ee_actions.h:211
static TOOL_ACTION showDatasheet
Inspection and Editing.
Definition: ee_actions.h:150
static TOOL_ACTION saveSymbolCopyAs
Definition: ee_actions.h:201
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:155
static TOOL_ACTION drawRectangle
Definition: ee_actions.h:100
static TOOL_ACTION setUnitDisplayName
Definition: ee_actions.h:214
static TOOL_ACTION drawSymbolTextBox
Definition: ee_actions.h:114
static TOOL_ACTION drawSymbolLines
Definition: ee_actions.h:115
static TOOL_ACTION drawArc
Definition: ee_actions.h:102
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 placeSymbolPin
Definition: ee_actions.h:112
static TOOL_ACTION showElectricalTypes
Definition: ee_actions.h:250
Tool that displays edit points allowing to modify items by dragging the points.
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
EE_SELECTION & GetSelection()
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool m_axesEnabled
Fullscreen crosshair or small cross.
void SetAxesEnabled(bool aAxesEnabled)
Enable drawing the axes.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
void SetDefaultFont(const wxString &aFont)
void HideDrawingSheet()
Definition: sch_view.cpp:186
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition: sch_view.cpp:179
void Clear()
Remove all items from the view.
Definition: view.cpp:1124
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1513
Definition: kiid.h:49
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:40
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
Definition: kiway_express.h:58
MAIL_T Command()
Returns the MAIL_T associated with this mail.
Definition: kiway_express.h:50
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
void OnKiCadExit()
Definition: kiway.cpp:717
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
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:527
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:110
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.
void Sync(const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
Updates the SYMBOL_LIBRARY_MANAGER data to synchronize with Symbol Library Table.
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
bool IsMulti() const override
Definition: lib_symbol.h:541
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:263
void GetFields(std::vector< SCH_FIELD * > &aList)
Return a list of fields within this symbol.
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:193
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:535
std::vector< SCH_PIN * > GetAllLibPins() const
Return a list of pin pointers for all units / converts.
SCH_FIELD & GetDatasheetField() const
Return reference to the datasheet field.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:486
wxString GetName() const override
Definition: lib_symbol.h:136
wxString GetLibNickname() const override
Sets the Description field text value.
Definition: lib_symbol.h:148
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:579
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:511
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
void SetNickName(const wxString &aNickName)
Change the logical name of this library, useful for an editor.
const wxString & GetNickName() const
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...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Node type: LIB_ID.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:438
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:332
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:349
int GetSelectionCount() const
Definition: lib_tree.h:91
void ShowChangedLanguage()
Definition: lib_tree.cpp:291
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:343
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition: lib_tree.h:141
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieves a list of selections for trees that allow multi-selection.
Definition: lib_tree.cpp:315
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:355
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:301
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:361
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:420
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:87
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:923
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
A holder to handle information on schematic or board items.
void ClearListAndDeleteItems(std::function< void(EDA_ITEM *)> aItemDeleter)
Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to th...
bool IsCancelled() const override
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
@ SCH_LIBEDIT_CUR_LIB
Definition: project.h:184
@ SCH_LIBEDIT_CUR_SYMBOL
Definition: project.h:185
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
Definition: project.cpp:269
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Definition: project.cpp:280
float SplitterProportion() const
Action handler for the Properties panel.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_RENDER_SETTINGS * GetRenderSettings()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
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.
SYMBOL_LIB_TABLE * SelectSymLibTable(bool aOptional=false)
Display a dialog asking the user to select a symbol library table.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Save Symbol Library Tables to disk.
virtual void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
void setSymWatcher(const LIB_ID *aSymbol)
Creates (or removes) a watcher on the specified symbol library.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplaySymbol(LIB_SYMBOL *aSymbol)
Schematic editor (Eeschema) main window.
void SaveSymbolToSchematic(const LIB_SYMBOL &aSymbol, const KIID &aSchematicSymbolUUID)
Update a schematic symbol from a LIB_SYMBOL.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1376
int GetId() const
Definition: sch_field.h:133
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1118
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1356
void SetName(const wxString &aName)
Definition: sch_field.cpp:1097
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1107
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:83
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
int GetBodyStyle() const
Definition: sch_item.h:240
int GetUnit() const
Definition: sch_item.h:237
virtual void ClearCaches()
Definition: sch_item.cpp:364
Schematic symbol object.
Definition: sch_symbol.h:105
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:779
int GetOrientation() const
Get the display symbol orientation.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:963
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:213
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
Handle actions for the various symbol editor and viewers.
SYMBOL_EDITOR_DRAWING_TOOLS.
SCH_SELECTION_FILTER_OPTIONS m_SelectionFilter
The symbol library editor main window.
void OnExitKiCad(wxCommandEvent &event)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
APP_SETTINGS_BASE * config() const override
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
bool addLibTableEntry(const wxString &aLibFile, TABLE_SCOPE aScope=GLOBAL_LIB_TABLE)
Add aLibFile to the symbol library table defined by aScope.
void storeCurrentSymbol()
Rename LIB_SYMBOL aliases to avoid conflicts before adding a symbol to a library.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
wxString getTargetLib() const
bool IsCurrentSymbol(const LIB_ID &aLibId) const
Restore the empty editor screen, without any symbol or library selected.
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Return currently edited symbol.
void FocusOnItem(SCH_ITEM *aItem)
void RefreshLibraryTree()
Redisplay the library tree.
void updateSelectionFilterVisbility() override
Selection filter panel doesn't have a dedicated visibility control, so show it if any other AUI panel...
wxComboBox * m_unitSelectBox
int GetTreeLIBIDs(std::vector< LIB_ID > &aSelection) const
LIB_ID GetTreeLIBID(int *aUnit=nullptr) const
Return the LIB_ID of the library or symbol selected in the symbol tree.
LIB_SYMBOL_LIBRARY_MANAGER * m_libMgr
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
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)
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
SYMBOL_EDITOR_SETTINGS * m_settings
int GetBodyStyle() const
void HardRedraw() override
Rebuild the GAL and redraw the screen.
bool GetShowDeMorgan() 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 SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool CanCloseSymbolFromSchematic(bool doClose)
bool IsSymbolFromLegacyLibrary() const
bool replaceLibTableEntry(const wxString &aLibNickname, const wxString &aLibFile)
Replace the file path of the symbol library table entry aLibNickname with aLibFile.
bool IsSymbolFromSchematic() const
void OnToggleSymbolTree(wxCommandEvent &event)
static bool m_showDeMorgan
void SetScreen(BASE_SCREEN *aScreen) override
SYMBOL_EDITOR_SETTINGS * GetSettings() const
SCH_SCREEN * m_dummyScreen
< Helper screen used when no symbol is loaded
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Receive KIWAY_EXPRESS messages from other players.
void SetCurSymbol(LIB_SYMBOL *aSymbol, bool aUpdateZoom)
Take ownership of aSymbol and notes that it is the one currently being edited.
KIID m_schematicSymbolUUID
RefDes of the symbol (only valid if symbol was loaded from schematic)
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
std::vector< LIB_ID > GetSelectedLibIds() const
LIB_TREE_NODE * GetCurrentTreeNode() const
void SyncLibraries(bool aShowProgress, bool aPreloadCancelled=false, const wxString &aForceRefresh=wxEmptyString)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
void OnSelectUnit(wxCommandEvent &event)
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
int m_bodyStyle
Flag if the symbol being edited was loaded directly from a schematic.
bool saveAllLibraries(bool aRequireConfirmation)
Save the current symbol.
void UpdateMsgPanel() override
Redraw the message panel.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Free the undo or redo list from aList element.
wxString SetCurLib(const wxString &aLibNickname)
Set the current library nickname and returns the old library nickname.
void UpdateTitle()
Update the main window title bar with the current library name and read only status of the library.
void ReCreateHToolbar() override
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
bool HasLibModifications() const
Check if any pending libraries have been modified.
SYMBOL_TREE_PANE * m_treePane
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
bool LoadSymbolFromCurrentLib(const wxString &aAliasName, int aUnit=0, int aBodyStyle=0)
Load a symbol from the current active library, optionally setting the selected unit and convert.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
Switch currently used canvas ( Cairo / OpenGL).
void doCloseWindow() override
void DdAddLibrary(wxString aLibFile)
Add a library dropped file to the symbol library table.
wxString AddLibraryFile(bool aCreateNew)
Create or add an existing library to the symbol library table.
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
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 SetShowDeMorgan(bool show)
void ShowChangedLanguage() override
bool IsContentModified() const override
Get if any symbols or libraries have been modified but not saved.
LIB_SYMBOL * getTargetSymbol() const
Return either the library selected in the symbol tree, if context menu is active or the library that ...
void OnUpdateUnitNumber(wxUpdateUIEvent &event)
LIB_SYMBOL * GetBufferedSymbol(const wxString &aAlias, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool IsLibraryReadOnly(const wxString &aLibrary) const
Return true if the library is stored in a read-only file.
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
LIB_SYMBOL * GetAlias(const wxString &aAlias, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
SCH_SCREEN * GetScreen(const wxString &aAlias, const wxString &aLibrary)
Return the screen used to edit a specific symbol.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
wxArrayString GetLibraryNames() const
Return the array of library names.
wxString GetUniqueLibraryName() const
Return a library name that is not currently in use.
bool AddLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Add an existing library.
bool CreateLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Create an empty library and adds it to the library table.
bool IsSymbolModified(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol has unsaved modifications.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
bool UpdateLibraryBuffer(const wxString &aLibrary)
Update the library buffer with a new version of the library.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
void SetType(const wxString &aType) override
Change the schematic plugin type represented by this row.
const wxString GetType() const override
Return the type of symbol library table represented by this row.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString & GetSymbolLibTableFileName()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Library Editor pane with symbol tree and symbol library table selector.
LIB_TREE * GetLibTree() const
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:169
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
ACTIONS * m_actions
Definition: tools_holder.h:168
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
Master controller class:
Definition: tool_manager.h:62
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 InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:302
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initializes all registered tools.
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
A holder to handle a list of undo (or redo) commands.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool empty() const
Definition: utf8.h:104
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:301
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: wx_infobar.cpp:260
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:187
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:161
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:186
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
Definition: confirm.cpp:58
This file is part of the common library.
#define CHECK(x)
#define ENABLE(x)
#define _HKI(x)
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define LIB_EDIT_FRAME_NAME
@ ID_LIBEDIT_SELECT_UNIT_NUMBER
Definition: eeschema_id.h:60
const wxAuiPaneInfo & defaultSchSelectionFilterPaneInfo(wxWindow *aWindow)
const wxAuiPaneInfo & defaultPropertiesPaneInfo(wxWindow *aWindow)
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Definition: env_paths.cpp:71
EVT_UPDATE_UI(ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH
Definition: frame_type.h:34
static const std::string KiCadSymbolLibFileExtension
static wxString KiCadSymbolLibFileWildcard()
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
PROJECT & Prj()
Definition: kicad.cpp:595
KIID niluuid(0)
@ LAYER_SCHEMATIC_GRID_AXES
Definition: layer_ids.h:389
@ MAIL_LIB_EDIT
Definition: mail_type.h:54
@ MAIL_REFRESH_SYMBOL
Definition: mail_type.h:58
@ MAIL_RELOAD_LIB
Definition: mail_type.h:56
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:58
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition: gtk/app.cpp:90
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: gtk/app.cpp:79
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
@ SYM_ORIENT_270
Definition: sch_symbol.h:84
@ SYM_MIRROR_Y
Definition: sch_symbol.h:86
@ SYM_ORIENT_180
Definition: sch_symbol.h:83
@ SYM_MIRROR_X
Definition: sch_symbol.h:85
@ SYM_ORIENT_90
Definition: sch_symbol.h:82
@ SYM_ORIENT_0
Definition: sch_symbol.h:81
KIWAY Kiway(KFCTL_STANDALONE)
wxString UnescapeString(const wxString &aSource)
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
#define EDIT_TOOL(tool)
Definition for symbol library class.
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.