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 The 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 <kidialog.h>
37#include <kiface_base.h>
38#include <kiplatform/app.h>
39#include <kiway_express.h>
40#include <symbol_edit_frame.h>
43#include <paths.h>
44#include <pgm_base.h>
45#include <project_sch.h>
46#include <sch_painter.h>
47#include <sch_view.h>
49#include <symbol_lib_table.h>
51#include <tool/action_manager.h>
52#include <tool/action_toolbar.h>
53#include <tool/common_control.h>
54#include <tool/common_tools.h>
56#include <tool/embed_tool.h>
58#include <tool/picker_tool.h>
60#include <tool/selection.h>
62#include <tool/tool_manager.h>
63#include <tool/zoom_tool.h>
64#include <tools/sch_actions.h>
75#include <view/view_controls.h>
77#include <widgets/wx_infobar.h>
85#include <panel_sym_lib_table.h>
86#include <string_utils.h>
87#include <wx/msgdlg.h>
88#include <wx/combobox.h>
89#include <wx/log.h>
90
91
93
94
95BEGIN_EVENT_TABLE( SYMBOL_EDIT_FRAME, SCH_BASE_FRAME )
98
99 // menubar commands
100 EVT_MENU( wxID_EXIT, SYMBOL_EDIT_FRAME::OnExitKiCad )
101 EVT_MENU( wxID_CLOSE, SYMBOL_EDIT_FRAME::CloseWindow )
102
103 // Update user interface elements.
106
107 // Drop files event
108 EVT_DROP_FILES( SYMBOL_EDIT_FRAME::OnDropFiles )
109
110END_EVENT_TABLE()
111
112
113SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
114 SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_SYMBOL_EDITOR, _( "Library Editor" ),
115 wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
117 m_unitSelectBox( nullptr ),
118 m_bodyStyleSelectBox( nullptr ),
120{
121 m_SyncPinEdit = false;
122
123 m_symbol = nullptr;
124 m_treePane = nullptr;
125 m_libMgr = nullptr;
126 m_unit = 1;
127 m_bodyStyle = 1;
128 m_aboutTitle = _HKI( "KiCad Symbol Editor" );
129
130 wxIcon icon;
131 wxIconBundle icon_bundle;
132
133 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 48 ) );
134 icon_bundle.AddIcon( icon );
135 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 256 ) );
136 icon_bundle.AddIcon( icon );
137 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit, 128 ) );
138 icon_bundle.AddIcon( icon );
139 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit_32 ) );
140 icon_bundle.AddIcon( icon );
141 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_libedit_16 ) );
142 icon_bundle.AddIcon( icon );
143
144 SetIcons( icon_bundle );
145
148
150
151 m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr );
152 m_treePane->GetLibTree()->SetSortMode( (LIB_TREE_MODEL_ADAPTER::SORT_MODE) m_settings->m_LibrarySortMode );
153
156
157 // Ensure axis are always drawn
159 gal_opts.m_axesEnabled = true;
160
163 GetScreen()->m_Center = true;
164
165 GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
166
167 GetRenderSettings()->LoadColors( GetColorSettings() );
168 GetRenderSettings()->m_IsSymbolEditor = true;
169 GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) );
170
171 setupTools();
173
175
179
180 UpdateTitle();
183
184 m_propertiesPanel = new SCH_PROPERTIES_PANEL( this, this );
185 m_propertiesPanel->SetSplitterProportion( m_settings->m_AuiPanels.properties_splitter );
186
188
189 m_auimgr.SetManagedWindow( this );
190
192
193 // Rows; layers 4 - 6
194 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" )
195 .Top().Layer( 6 ) );
196
197 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
198 .Bottom().Layer( 6 ) );
199
200 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" )
201 .Left().Layer( 2 ) );
202
203 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( "RightToolbar" )
204 .Right().Layer( 2 ) );
205
206 // Center
207 m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" )
208 .CentrePane() );
209
210 // Columns; layers 1 - 3
211 m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "LibraryTree" )
212 .Left().Layer( 3 )
213 .TopDockable( false ).BottomDockable( false )
214 .Caption( _( "Libraries" ) )
215 .MinSize( FromDIP( 250 ), -1 ).BestSize( FromDIP( 250 ), -1 ) );
216
219
220 // Can be called only when all panes are created, because (at least on Windows) when items
221 // managed by m_auimgr are not the same as those existing when saved by Perspective()
222 // in config, broken settings can happen.
224
225 // Protect against broken saved Perspective() due to bugs in previous version
226 // This is currently a workaround.
227 m_auimgr.GetPane( "TopMainToolbar" ).Top().Layer( 6 ).Position(0);
228 m_auimgr.GetPane( "LeftToolbar" ).Position(0);
229
230 // Show or hide m_propertiesPanel depending on current settings:
231 wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
232 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
233 // The selection filter doesn't need to grow in the vertical direction when docked
234 selectionFilterPane.dock_proportion = 0;
235
236 propertiesPaneInfo.Show( m_settings->m_AuiPanels.show_properties );
238
240
241 // Can't put this in LoadSettings, because it has to be called before setupTools :/
243 selTool->GetFilter() = GetSettings()->m_SelectionFilter;
244 m_selectionFilterPanel->SetCheckboxesFromFilter( selTool->GetFilter() );
245
246 if( m_settings->m_LibWidth > 0 )
247 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "LibraryTree" ), m_settings->m_LibWidth, -1 );
248
249 Raise();
250 Show( true );
251
252 SyncView();
253 GetCanvas()->GetView()->UseDrawPriority( true );
254 GetCanvas()->GetGAL()->SetAxesEnabled( true );
255
257
258 // Set the working/draw area size to display a symbol to a reasonable value:
259 // A 600mm x 600mm with a origin at the area center looks like a large working area
260 double max_size_x = schIUScale.mmToIU( 600 );
261 double max_size_y = schIUScale.mmToIU( 600 );
262 BOX2D bbox;
263 bbox.SetOrigin( -max_size_x /2, -max_size_y/2 );
264 bbox.SetSize( max_size_x, max_size_y );
265 GetCanvas()->GetView()->SetBoundary( bbox );
266
268
270 DragAcceptFiles( true );
271
272 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Library changes are unsaved" ) );
273
274 // Catch unhandled accelerator command characters that were no handled by the library tree
275 // panel.
277 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
278
279 // Ensure the window is on top
280 Raise();
281
282 // Load libraries
283 bool loadingCancelled = false;
284
285 {
286 // Preload libraries before using SyncLibraries the first time, as the preload is
287 // multi-threaded
288 WX_PROGRESS_REPORTER reporter( this, _( "Load Symbol Libraries" ), m_libMgr->GetLibraryCount(),
289 PR_CAN_ABORT );
290 m_libMgr->Preload( reporter );
291
292 loadingCancelled = reporter.IsCancelled();
293 wxSafeYield();
294 }
295
296 // run SyncLibraries with progress reporter enabled. The progress reporter is useful
297 // in debug mode because the loading time of ecah library can be really noticeable
298 SyncLibraries( true, loadingCancelled );
299
300 if( loadingCancelled )
301 ShowInfoBarWarning( _( "Symbol library loading canceled by user." ) );
302}
303
304
306{
307 // Shutdown all running tools
308 if( m_toolManager )
309 m_toolManager->ShutdownAllTools();
310
311 setSymWatcher( nullptr );
312
314 {
315 delete m_symbol;
316 m_symbol = nullptr;
317
318 SCH_SCREEN* screen = GetScreen();
319 delete screen;
321 }
322
323 // current screen is destroyed in EDA_DRAW_FRAME
325
327 Pgm().GetSettingsManager().Save( cfg );
328
329 delete m_libMgr;
330}
331
332
334{
335 wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME::LoadSettings with null m_settings" );
336
338
339 GetRenderSettings()->m_ShowPinsElectricalType = m_settings->m_ShowPinElectricalType;
340 GetRenderSettings()->m_ShowHiddenPins = m_settings->m_ShowHiddenPins;
341 GetRenderSettings()->m_ShowHiddenFields = m_settings->m_ShowHiddenFields;
342 GetRenderSettings()->m_ShowPinAltIcons = m_settings->m_ShowPinAltIcons;
343 GetRenderSettings()->SetDefaultFont( wxEmptyString );
344}
345
346
348{
349 wxCHECK_RET( m_settings, "Call to SYMBOL_EDIT_FRAME:SaveSettings with null m_settings" );
350
352
354
355 m_settings->m_ShowPinElectricalType = GetRenderSettings()->m_ShowPinsElectricalType;
356 m_settings->m_ShowHiddenPins = GetRenderSettings()->m_ShowHiddenPins;
357 m_settings->m_ShowHiddenFields = GetRenderSettings()->m_ShowHiddenFields;
358 m_settings->m_ShowPinAltIcons = GetRenderSettings()->m_ShowPinAltIcons;
359
360 m_settings->m_LibWidth = m_treePane->GetSize().x;
361
362 m_settings->m_LibrarySortMode = GetLibTree()->GetSortMode();
363
364 m_settings->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
365 bool prop_shown = m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
366 m_settings->m_AuiPanels.show_properties = prop_shown;
367
369 m_settings->m_SelectionFilter = selTool->GetFilter();
370}
371
372
374{
375 return static_cast<APP_SETTINGS_BASE*>( GetSettings() );
376}
377
378
380{
382
383 if( cfg && static_cast<SYMBOL_EDITOR_SETTINGS*>( cfg )->m_UseEeschemaColorSettings )
384 cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
385
386 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
387}
388
389
391{
392 // Create the manager and dispatcher & route draw panel events to the dispatcher
394 m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(),
395 GetCanvas()->GetViewControls(), GetSettings(), this );
396 m_actions = new SCH_ACTIONS();
398
399 // Register tools
400 m_toolManager->RegisterTool( new COMMON_CONTROL );
401 m_toolManager->RegisterTool( new COMMON_TOOLS );
402 m_toolManager->RegisterTool( new ZOOM_TOOL );
403 m_toolManager->RegisterTool( new SCH_SELECTION_TOOL );
404 m_toolManager->RegisterTool( new PICKER_TOOL );
405 m_toolManager->RegisterTool( new SCH_INSPECTION_TOOL );
406 m_toolManager->RegisterTool( new SYMBOL_EDITOR_PIN_TOOL );
407 m_toolManager->RegisterTool( new SYMBOL_EDITOR_DRAWING_TOOLS );
408 m_toolManager->RegisterTool( new SCH_POINT_EDITOR );
409 m_toolManager->RegisterTool( new SCH_FIND_REPLACE_TOOL );
410 m_toolManager->RegisterTool( new SYMBOL_EDITOR_MOVE_TOOL );
411 m_toolManager->RegisterTool( new SYMBOL_EDITOR_EDIT_TOOL );
412 m_toolManager->RegisterTool( new LIBRARY_EDITOR_CONTROL );
413 m_toolManager->RegisterTool( new SYMBOL_EDITOR_CONTROL );
414 m_toolManager->RegisterTool( new PROPERTIES_TOOL );
415 m_toolManager->RegisterTool( new EMBED_TOOL );
416 m_toolManager->InitTools();
417
418 // Run the selection tool, it is supposed to be always active
419 m_toolManager->InvokeTool( "common.InteractiveSelection" );
420
422}
423
424
426{
428
429 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
430 EDITOR_CONDITIONS cond( this );
431
432 wxASSERT( mgr );
433
434#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
435#define CHECK( x ) ACTION_CONDITIONS().Check( x )
436
437 auto haveSymbolCond =
438 [this]( const SELECTION& )
439 {
440 return m_symbol;
441 };
442
443 auto isEditableCond =
444 [this]( const SELECTION& )
445 {
446 // Only root symbols from the new s-expression libraries or the schematic
447 // are editable.
448 return IsSymbolEditable() && !IsSymbolAlias();
449 };
450
451 auto isEditableInAliasCond =
452 [this]( const SELECTION& )
453 {
454 // Less restrictive than isEditableCond
455 // Symbols fields (root symbols and aliases) from the new s-expression libraries
456 // or in the schematic are editable.
457 return IsSymbolEditable();
458 };
459
460 auto symbolModifiedCondition =
461 [this]( const SELECTION& sel )
462 {
463 return m_libMgr && m_libMgr->IsSymbolModified( GetTargetLibId().GetLibItemName(),
464 GetTargetLibId().GetLibNickname() );
465 };
466
467 auto libSelectedCondition =
468 [this]( const SELECTION& sel )
469 {
470 return !GetTargetLibId().GetLibNickname().empty();
471 };
472
473 auto canEditProperties =
474 [this]( const SELECTION& sel )
475 {
477 };
478
479 auto saveSymbolAsCondition =
480 [this]( const SELECTION& aSel )
481 {
482 return getTargetSymbol() != nullptr;
483 };
484
485 const auto isSymbolFromSchematicCond =
486 [this]( const SELECTION& )
487 {
488 return IsSymbolFromSchematic();
489 };
490
491 // clang-format off
494 mgr->SetConditions( SCH_ACTIONS::saveLibraryAs, ENABLE( libSelectedCondition ) );
495 mgr->SetConditions( SCH_ACTIONS::saveSymbolAs, ENABLE( saveSymbolAsCondition ) );
496 mgr->SetConditions( SCH_ACTIONS::saveSymbolCopyAs, ENABLE( saveSymbolAsCondition ) );
499 mgr->SetConditions( SCH_ACTIONS::editLibSymbolWithLibEdit, ENABLE( isSymbolFromSchematicCond ) );
500
501 mgr->SetConditions( ACTIONS::undo, ENABLE( haveSymbolCond && cond.UndoAvailable() ) );
502 mgr->SetConditions( ACTIONS::redo, ENABLE( haveSymbolCond && cond.RedoAvailable() ) );
503 mgr->SetConditions( ACTIONS::revert, ENABLE( symbolModifiedCondition ) );
504
507
508 mgr->SetConditions( ACTIONS::cut, ENABLE( isEditableCond ) );
509 mgr->SetConditions( ACTIONS::copy, ENABLE( haveSymbolCond ) );
510 mgr->SetConditions( ACTIONS::copyAsText, ENABLE( haveSymbolCond ) );
511 mgr->SetConditions( ACTIONS::paste, ENABLE( isEditableCond &&
513 mgr->SetConditions( ACTIONS::doDelete, ENABLE( isEditableCond ) );
514 mgr->SetConditions( ACTIONS::duplicate, ENABLE( isEditableCond ) );
515 mgr->SetConditions( ACTIONS::selectAll, ENABLE( haveSymbolCond ) );
516 mgr->SetConditions( ACTIONS::unselectAll, ENABLE( haveSymbolCond ) );
517
518 // These actions in symbol editor when editing alias field rotations are allowed.
519 mgr->SetConditions( SCH_ACTIONS::rotateCW, ENABLE( isEditableInAliasCond ) );
520 mgr->SetConditions( SCH_ACTIONS::rotateCCW, ENABLE( isEditableInAliasCond ) );
521
522 mgr->SetConditions( SCH_ACTIONS::mirrorH, ENABLE( isEditableCond ) );
523 mgr->SetConditions( SCH_ACTIONS::mirrorV, ENABLE( isEditableCond ) );
524
527 // clang-format on
528
529 auto pinTypeCond =
530 [this]( const SELECTION& )
531 {
533 };
534
535 auto hiddenPinCond =
536 [this]( const SELECTION& )
537 {
539 };
540
541 auto hiddenFieldCond =
542 [this]( const SELECTION& )
543 {
545 };
546
547 auto showPinAltIconsCond =
548 [this]( const SELECTION& )
549 {
551 };
552
553 auto showLibraryTreeCond =
554 [this]( const SELECTION& )
555 {
556 return IsLibraryTreeShown();
557 };
558
559 auto propertiesCond =
560 [this] ( const SELECTION& )
561 {
562 return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
563 };
564
567 mgr->SetConditions( ACTIONS::showLibraryTree, CHECK( showLibraryTreeCond ) );
568 mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
569 mgr->SetConditions( SCH_ACTIONS::showHiddenPins, CHECK( hiddenPinCond ) );
570 mgr->SetConditions( SCH_ACTIONS::showHiddenFields, CHECK( hiddenFieldCond ) );
571 mgr->SetConditions( SCH_ACTIONS::togglePinAltIcons, CHECK( showPinAltIconsCond ) );
572
573 auto multiUnitModeCond =
574 [this]( const SELECTION& )
575 {
576 return m_symbol && m_symbol->IsMultiUnit() && !m_symbol->UnitsLocked();
577 };
578
579 auto multiBodyStyleModeCond =
580 [this]( const SELECTION& )
581 {
582 return m_symbol && m_symbol->IsMultiBodyStyle();
583 };
584
585 auto syncedPinsModeCond =
586 [this]( const SELECTION& )
587 {
588 return m_SyncPinEdit;
589 };
590
591 auto haveDatasheetCond =
592 [this]( const SELECTION& )
593 {
594 return m_symbol && !m_symbol->GetDatasheetField().GetText().IsEmpty();
595 };
596
597 mgr->SetConditions( ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
598 mgr->SetConditions( SCH_ACTIONS::symbolProperties, ENABLE( canEditProperties && haveSymbolCond ) );
599 mgr->SetConditions( SCH_ACTIONS::runERC, ENABLE( haveSymbolCond ) );
600 mgr->SetConditions( SCH_ACTIONS::pinTable, ENABLE( isEditableCond && haveSymbolCond ) );
601 mgr->SetConditions( SCH_ACTIONS::cycleBodyStyle, ENABLE( multiBodyStyleModeCond ) );
602
603 mgr->SetConditions( SCH_ACTIONS::toggleSyncedPinsMode, ACTION_CONDITIONS().Enable( multiUnitModeCond ).Check( syncedPinsModeCond ) );
604
605// Only enable a tool if the symbol is edtable
606#define EDIT_TOOL( tool ) ACTION_CONDITIONS().Enable( isEditableCond ).Check( cond.CurrentTool( tool ) )
607
620
621#undef CHECK
622#undef ENABLE
623#undef EDIT_TOOL
624}
625
626
628{
629 if( IsContentModified() )
630 {
631 SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
632 wxString msg = _( "Save changes to '%s' before closing?" );
633
634 switch( UnsavedChangesDialog( this, wxString::Format( msg, m_reference ), nullptr ) )
635 {
636 case wxID_YES:
637 if( schframe && GetCurSymbol() ) // Should be always the case
639
640 break;
641
642 case wxID_NO:
643 break;
644
645 default:
646 case wxID_CANCEL:
647 return false;
648 }
649 }
650
651 if( doClose )
652 {
653 SetCurSymbol( nullptr, false );
654 UpdateTitle();
655 }
656
657 return true;
658}
659
660
661bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
662{
663 // Shutdown blocks must be determined and vetoed as early as possible
665 && aEvent.GetId() == wxEVT_QUERY_END_SESSION
666 && IsContentModified() )
667 {
668 return false;
669 }
670
672 return false;
673
674 if( !saveAllLibraries( true ) )
675 return false;
676
677 // Save symbol tree column widths
678 m_libMgr->GetAdapter()->SaveSettings();
679
680 return true;
681}
682
683
685{
687
688 if( GetLibTree() )
690
691 delete m_toolManager;
692 m_toolManager = nullptr;
693
694 Destroy();
695}
696
697
699{
700 if( m_unitSelectBox )
701 {
702 if( m_unitSelectBox->GetCount() != 0 )
703 m_unitSelectBox->Clear();
704
705 if( !m_symbol || m_symbol->GetUnitCount() <= 1 )
706 {
707 m_unit = 1;
708 m_unitSelectBox->Append( wxEmptyString );
709 }
710 else
711 {
712 for( int i = 0; i < m_symbol->GetUnitCount(); i++ )
713 m_unitSelectBox->Append( m_symbol->GetUnitDisplayName( i + 1, true ) );
714 }
715
716 // Ensure the selected unit is compatible with the number of units of the current symbol:
717 if( m_symbol && m_symbol->GetUnitCount() < m_unit )
718 m_unit = 1;
719
720 m_unitSelectBox->SetSelection( ( m_unit > 0 ) ? m_unit - 1 : 0 );
721 }
722
724 {
725 if( m_bodyStyleSelectBox->GetCount() != 0 )
726 m_bodyStyleSelectBox->Clear();
727
728 if( !m_symbol || !m_symbol->IsMultiBodyStyle() )
729 {
730 m_bodyStyle = 1;
731 m_bodyStyleSelectBox->Append( wxEmptyString );
732 }
733 else if( m_symbol && m_symbol->HasDeMorganBodyStyles() )
734 {
735 m_bodyStyleSelectBox->Append( wxGetTranslation( DEMORGAN_STD ) );
736 m_bodyStyleSelectBox->Append( wxGetTranslation( DEMORGAN_ALT ) );
737 }
738 else
739 {
740 for( int i = 0; i < m_symbol->GetBodyStyleCount(); i++ )
741 m_bodyStyleSelectBox->Append( m_symbol->GetBodyStyleNames()[i] );
742 }
743
744 // Ensure the selected body style is compatible with the number of body styles of the current symbol:
745 if( m_symbol && m_symbol->GetBodyStyleCount() < m_bodyStyle )
746 m_bodyStyle = 1;
747
748 m_bodyStyleSelectBox->SetSelection( ( m_bodyStyle > 0 ) ? m_bodyStyle - 1 : 0 );
749 }
750}
751
752
754{
755 if( !m_propertiesPanel )
756 return;
757
758 bool show = !m_propertiesPanel->IsShownOnScreen();
759
760 wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
761 propertiesPaneInfo.Show( show );
763
764 if( show )
765 {
766 SetAuiPaneSize( m_auimgr, propertiesPaneInfo,
767 m_settings->m_AuiPanels.properties_panel_width, -1 );
768 }
769 else
770 {
771 m_settings->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
772 }
773
774 m_auimgr.Update();
775 Refresh();
776}
777
778
780{
781 wxAuiPaneInfo& treePane = m_auimgr.GetPane( m_treePane );
782 treePane.Show( !IsLibraryTreeShown() );
784 m_auimgr.Update();
785 Refresh();
786}
787
788
790{
791 return const_cast<wxAuiManager&>( m_auimgr ).GetPane( m_treePane ).IsShown();
792}
793
794
799
800
802{
803 m_treePane->Freeze();
804 m_libMgr->GetAdapter()->Freeze();
805}
806
807
809{
810 m_libMgr->GetAdapter()->Thaw();
811 m_treePane->Thaw();
812}
813
814
815void SYMBOL_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
816{
817 Kiway().OnKiCadExit();
818}
819
820
821void SYMBOL_EDIT_FRAME::OnUpdateUnitNumber( wxUpdateUIEvent& event )
822{
823 event.Enable( m_symbol && m_symbol->GetUnitCount() > 1 );
824}
825
826
827void SYMBOL_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event )
828{
829 if( event.GetSelection() == wxNOT_FOUND )
830 return;
831
832 SetUnit( event.GetSelection() + 1 );
833}
834
835
836void SYMBOL_EDIT_FRAME::OnUpdateBodyStyle( wxUpdateUIEvent& event )
837{
838 event.Enable( m_symbol && m_symbol->GetBodyStyleCount() > 1 );
839}
840
841
842void SYMBOL_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
843{
844 if( event.GetSelection() == wxNOT_FOUND )
845 return;
846
847 SetBodyStyle( event.GetSelection() + 1 );
848}
849
850
852{
853 if( m_symbol )
854 {
855 SYMBOL_LIB_TABLE_ROW* row = m_libMgr->GetLibrary( m_symbol->GetLibNickname() );
856
857 if( row && row->GetType() == SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) )
858 return true;
859 }
860
861 return false;
862}
863
864
866{
867 wxString libNickname = Prj().GetRString( PROJECT::SCH_LIBEDIT_CUR_LIB );
868
869 if( !libNickname.empty() )
870 {
871 if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( libNickname ) )
872 {
873 Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
874 libNickname = wxEmptyString;
875 }
876 }
877
878 return libNickname;
879}
880
881
882wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
883{
884 wxString old = GetCurLib();
885
886 if( aLibNickname.empty() || !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( aLibNickname ) )
887 Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
888 else
890
891 return old;
892}
893
894
895void SYMBOL_EDIT_FRAME::SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom )
896{
897 wxCHECK( m_toolManager, /* void */ );
898
900 GetCanvas()->GetView()->Clear();
901 delete m_symbol;
902
903 m_symbol = aSymbol;
904
905 // select the current symbol in the tree widget
907 GetLibTree()->SelectLibId( m_symbol->GetLibId() );
908 else
909 GetLibTree()->Unselect();
910
911 wxString symbolName;
912 wxString libName;
913
914 if( m_symbol )
915 {
916 symbolName = m_symbol->GetName();
917 libName = UnescapeString( m_symbol->GetLibId().GetLibNickname() );
918 }
919
920 // retain in case this wxFrame is re-opened later on the same PROJECT
922
923 // Ensure synchronized pin edit can be enabled only symbols with interchangeable units
924 m_SyncPinEdit = aSymbol && aSymbol->IsRoot() && aSymbol->IsMultiUnit() && !aSymbol->UnitsLocked();
925
927
935
936 if( aUpdateZoom )
938
939 GetCanvas()->Refresh();
940 m_propertiesPanel->UpdateData();
941
942 WX_INFOBAR& infobar = *GetInfoBar();
943 infobar.RemoveAllButtons();
944
945 wxArrayString msgs;
946 int infobarFlags = wxICON_INFORMATION;
947
949 {
950 msgs.push_back( wxString::Format( _( "Editing symbol %s from schematic. Saving will "
951 "update the schematic only." ),
952 m_reference ) );
953
954 wxString link = wxString::Format( _( "Open symbol from library %s" ), libName );
955 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( &infobar, wxID_ANY, link, wxEmptyString );
956
957 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
958 [this, symbolName, libName]( wxHyperlinkEvent& aEvent )
959 {
961 } ) );
962
963 infobar.AddButton( button );
964 }
965 else if( IsSymbolFromLegacyLibrary() )
966 {
967 msgs.push_back( _( "Symbols in legacy libraries are not editable. Use Manage Symbol "
968 "Libraries to migrate to current format." ) );
969
970 wxString link = _( "Manage symbol libraries" );
971 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( &infobar, wxID_ANY, link, wxEmptyString );
972
973 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
974 [this]( wxHyperlinkEvent& aEvent )
975 {
977 } ) );
978
979 infobar.AddButton( button );
980 }
981 else if( IsSymbolAlias() )
982 {
983 msgs.push_back( wxString::Format( _( "Symbol %s is a derived symbol. Symbol graphics will "
984 "not be editable." ),
985 UnescapeString( symbolName ) ) );
986
987 // Don't assume the parent symbol shared pointer is still valid.
988 if( std::shared_ptr<LIB_SYMBOL> rootSymbol = m_symbol->GetRootSymbol() )
989 {
990 int unit = GetUnit();
991 int bodyStyle = GetBodyStyle();
992 wxString rootSymbolName = rootSymbol->GetName();
993 wxString link = wxString::Format( _( "Open %s" ), UnescapeString( rootSymbolName ) );
994
995 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( &infobar, wxID_ANY, link,
996 wxEmptyString );
997
998 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
999 [this, rootSymbolName, unit, bodyStyle]( wxHyperlinkEvent& aEvent )
1000 {
1001 LoadSymbolFromCurrentLib( rootSymbolName, unit, bodyStyle );
1002 } ) );
1003
1004 infobar.AddButton( button );
1005 }
1006 }
1007
1008 if( m_symbol
1010 && m_libMgr->IsLibraryReadOnly( m_symbol->GetLibId().GetFullLibraryName() ) )
1011 {
1012 msgs.push_back( _( "Library is read-only. Changes cannot be saved to this library." ) );
1013
1014 wxString link = wxString::Format( _( "Create an editable copy" ) );
1015 wxHyperlinkCtrl* button = new wxHyperlinkCtrl( &infobar, wxID_ANY, link, wxEmptyString );
1016
1017 button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
1018 [this, symbolName, libName]( wxHyperlinkEvent& aEvent )
1019 {
1020 wxString msg = wxString::Format( _( "Create an editable copy of the symbol or "
1021 "the entire library (%s)?" ),
1022 libName );
1023
1024 KIDIALOG errorDlg( this, msg, _( "Select type of item to save" ),
1025 wxYES_NO | wxCANCEL | wxICON_QUESTION );
1026 // These buttons are in a weird order(?)
1027 errorDlg.SetYesNoCancelLabels( _( "Copy symbol" ), _( "Cancel" ),
1028 _( "Copy library" ) );
1029
1030 int choice = errorDlg.ShowModal();
1031
1032 switch( choice )
1033 {
1034 case wxID_YES:
1035 SaveSymbolCopyAs( true );
1036 break;
1037 case wxID_CANCEL:
1038 SaveLibraryAs();
1039 break;
1040 default:
1041 // Do nothing
1042 break;
1043 }
1044 } ) );
1045
1046 infobar.AddButton( button );
1047 }
1048
1049 if( msgs.empty() )
1050 {
1051 infobar.Dismiss();
1052 }
1053 else
1054 {
1055 wxString msg = wxJoin( msgs, '\n', '\0' );
1056 infobar.ShowMessage( msg, infobarFlags );
1057 }
1058}
1059
1060
1066
1067
1069{
1071
1073
1074 if( !IsSymbolFromSchematic() )
1076
1077 if( m_isClosing )
1078 return;
1079
1081
1082 if( !GetTitle().StartsWith( "*" ) )
1083 UpdateTitle();
1084}
1085
1086
1088{
1089 wxCHECK( aUnit > 0 && aUnit <= GetCurSymbol()->GetUnitCount(), /* void*/ );
1090
1091 if( m_unit == aUnit )
1092 return;
1093
1096
1097 m_unit = aUnit;
1098
1099 if( m_unitSelectBox->GetSelection() != ( m_unit - 1 ) )
1100 m_unitSelectBox->SetSelection( m_unit - 1 );
1101
1103 RebuildView();
1105}
1106
1107
1109{
1110 wxCHECK( aBodyStyle > 0 && aBodyStyle <= GetCurSymbol()->GetBodyStyleCount(), /* void */ );
1111
1112 if( m_bodyStyle == aBodyStyle )
1113 return;
1114
1117
1118 m_bodyStyle = aBodyStyle;
1119
1120 if( m_bodyStyleSelectBox->GetSelection() != ( m_bodyStyle - 1 ) )
1121 m_bodyStyleSelectBox->SetSelection( m_bodyStyle - 1 );
1122
1123
1125 RebuildView();
1127}
1128
1129
1131{
1132 return m_SyncPinEdit && m_symbol && m_symbol->IsMultiUnit() && !m_symbol->UnitsLocked();
1133}
1134
1135
1136wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
1137{
1138 wxFileName fn = m_libMgr->GetUniqueLibraryName();
1139 bool useGlobalTable = false;
1140 FILEDLG_HOOK_NEW_LIBRARY tableChooser( useGlobalTable );
1141
1142 if( !LibraryFileBrowser( aCreateNew ? _( "New Symbol Library" ) : _( "Add Symbol Library" ),
1143 !aCreateNew, fn, FILEEXT::KiCadSymbolLibFileWildcard(),
1144 FILEEXT::KiCadSymbolLibFileExtension, false, &tableChooser ) )
1145 {
1146 return wxEmptyString;
1147 }
1148
1149 wxString libName = fn.GetName();
1150
1151 if( libName.IsEmpty() )
1152 return wxEmptyString;
1153
1154 useGlobalTable = tableChooser.GetUseGlobalTable();
1155
1156 if( m_libMgr->LibraryExists( libName ) )
1157 {
1158 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
1159 return wxEmptyString;
1160 }
1161
1162 SYMBOL_LIB_TABLE* libTable = useGlobalTable ? &SYMBOL_LIB_TABLE::GetGlobalLibTable()
1164
1165 if( aCreateNew )
1166 {
1167 if( !m_libMgr->CreateLibrary( fn.GetFullPath(), *libTable ) )
1168 {
1169 DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
1170 "Make sure you have write permissions and "
1171 "try again." ),
1172 fn.GetFullPath() ) );
1173 return wxEmptyString;
1174 }
1175 }
1176 else
1177 {
1178 if( !m_libMgr->AddLibrary( fn.GetFullPath(), *libTable ) )
1179 {
1180 DisplayError( this, _( "Could not open the library file." ) );
1181 return wxEmptyString;
1182 }
1183 }
1184
1185 bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
1186 saveSymbolLibTables( globalTable, !globalTable );
1187
1188 std::string packet = fn.GetFullPath().ToStdString();
1190
1191 return fn.GetFullPath();
1192}
1193
1194
1195void SYMBOL_EDIT_FRAME::DdAddLibrary( wxString aLibFile )
1196{
1197 wxFileName fn = wxFileName( aLibFile );
1198 wxString libName = fn.GetName();
1199
1200 if( libName.IsEmpty() )
1201 return;
1202
1203 if( m_libMgr->LibraryExists( libName ) )
1204 {
1205 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
1206 return;
1207 }
1208
1209 if( !m_libMgr->AddLibrary( fn.GetFullPath(), *PROJECT_SCH::SchSymbolLibTable( &Prj() ) ) )
1210 {
1211 DisplayError( this, _( "Could not open the library file." ) );
1212 return;
1213 }
1214
1215 saveSymbolLibTables( false, true );
1216
1217 std::string packet = fn.GetFullPath().ToStdString();
1219}
1220
1221
1223{
1224 return GetLibTree()->GetSelectedLibId( aUnit );
1225}
1226
1227
1232
1233int SYMBOL_EDIT_FRAME::GetTreeLIBIDs( std::vector<LIB_ID>& aSelection ) const
1234{
1235 return GetLibTree()->GetSelectedLibIds( aSelection );
1236}
1237
1238
1240{
1241 if( IsLibraryTreeShown() )
1242 {
1243 LIB_ID libId = GetTreeLIBID();
1244
1245 if( libId.IsValid() )
1246 return m_libMgr->GetSymbol( libId.GetLibItemName(), libId.GetLibNickname() );
1247 }
1248
1249 return m_symbol;
1250}
1251
1252
1254{
1255 LIB_ID id;
1256
1257 if( IsLibraryTreeShown() )
1258 id = GetTreeLIBID();
1259
1260 if( id.GetLibNickname().empty() && m_symbol )
1261 id = m_symbol->GetLibId();
1262
1263 return id;
1264}
1265
1266
1267std::vector<LIB_ID> SYMBOL_EDIT_FRAME::GetSelectedLibIds() const
1268{
1269 std::vector<LIB_ID> ids;
1270 GetTreeLIBIDs( ids );
1271 return ids;
1272}
1273
1274
1276{
1277 return GetTargetLibId().GetLibNickname();
1278}
1279
1280
1281void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress, bool aPreloadCancelled,
1282 const wxString& aForceRefresh )
1283{
1284 LIB_ID selected;
1285
1286 if( m_treePane )
1287 selected = GetLibTree()->GetSelectedLibId();
1288
1289 if( aShowProgress )
1290 {
1291 APP_PROGRESS_DIALOG progressDlg( _( "Loading Symbol Libraries" ), wxEmptyString,
1292 m_libMgr->GetAdapter()->GetLibrariesCount(), this );
1293
1294 m_libMgr->Sync( aForceRefresh,
1295 [&]( int progress, int max, const wxString& libName )
1296 {
1297 progressDlg.Update( progress, wxString::Format( _( "Loading library '%s'..." ),
1298 libName ) );
1299 } );
1300 }
1301 else if( !aPreloadCancelled )
1302 {
1303 m_libMgr->Sync( aForceRefresh,
1304 [&]( int progress, int max, const wxString& libName )
1305 {
1306 } );
1307 }
1308
1309 if( m_treePane )
1310 {
1311 wxDataViewItem found;
1312
1313 if( selected.IsValid() )
1314 {
1315 // Check if the previously selected item is still valid,
1316 // if not - it has to be unselected to prevent crash
1317 found = m_libMgr->GetAdapter()->FindItem( selected );
1318
1319 if( !found )
1320 GetLibTree()->Unselect();
1321 }
1322
1323 GetLibTree()->Regenerate( true );
1324
1325 // Try to select the parent library, in case the symbol is not found
1326 if( !found && selected.IsValid() )
1327 {
1328 selected.SetLibItemName( "" );
1329 found = m_libMgr->GetAdapter()->FindItem( selected );
1330
1331 if( found )
1332 GetLibTree()->SelectLibId( selected );
1333 }
1334
1335 // If no selection, see if there's a current symbol to centre
1336 if( !selected.IsValid() && m_symbol )
1337 {
1338 LIB_ID current( GetCurLib(), m_symbol->GetName() );
1339 GetLibTree()->CenterLibId( current );
1340 }
1341 }
1342}
1343
1344
1349
1350
1352{
1353 GetLibTree()->SelectLibId( aLibID );
1354}
1355
1356
1357void SYMBOL_EDIT_FRAME::UpdateLibraryTree( const wxDataViewItem& aTreeItem, LIB_SYMBOL* aSymbol )
1358{
1359 if( aTreeItem.IsOk() ) // Can be not found in tree if the current footprint is imported
1360 // from file therefore not yet in tree.
1361 {
1362 static_cast<LIB_TREE_NODE_ITEM*>( aTreeItem.GetID() )->Update( aSymbol );
1364 }
1365}
1366
1367
1368bool SYMBOL_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
1369{
1370 if( aOriginalFile.FileExists() )
1371 {
1372 wxFileName backupFileName( aOriginalFile );
1373 backupFileName.SetExt( aBackupExt );
1374
1375 if( backupFileName.FileExists() )
1376 wxRemoveFile( backupFileName.GetFullPath() );
1377
1378 if( !wxCopyFile( aOriginalFile.GetFullPath(), backupFileName.GetFullPath() ) )
1379 {
1380 DisplayError( this, wxString::Format( _( "Failed to save backup to '%s'." ),
1381 backupFileName.GetFullPath() ) );
1382 return false;
1383 }
1384 }
1385
1386 return true;
1387}
1388
1389
1391{
1392 if( m_symbol && !GetCurLib().IsEmpty() && GetScreen()->IsContentModified() )
1393 m_libMgr->UpdateSymbol( m_symbol, GetCurLib() ); // UpdateSymbol() makes a copy
1394}
1395
1396
1398{
1399 // This will return the root symbol of any alias
1400 LIB_SYMBOL* symbol = m_libMgr->GetBufferedSymbol( aLibId.GetLibItemName(),
1401 aLibId.GetLibNickname() );
1402
1403 // Now we can compare the libId of the current symbol and the root symbol
1404 return ( symbol && m_symbol && symbol->GetLibId() == m_symbol->GetLibId() );
1405}
1406
1407
1409{
1410 GetLibTree()->Unselect();
1411 SetCurLib( wxEmptyString );
1412 SetCurSymbol( nullptr, false );
1416 Refresh();
1417}
1418
1419
1421{
1423
1425 {
1426 GetRenderSettings()->m_ShowPinsElectricalType = cfg->m_ShowPinElectricalType;
1427 GetRenderSettings()->m_ShowHiddenPins = cfg->m_ShowHiddenPins;
1428 GetRenderSettings()->m_ShowHiddenFields = cfg->m_ShowHiddenFields;
1429 GetRenderSettings()->m_ShowPinAltIcons = cfg->m_ShowPinAltIcons;
1430
1431 GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
1432 }
1433
1434 if( m_symbol )
1435 m_symbol->ClearCaches();
1436
1438
1440 GetCanvas()->Refresh();
1441
1443
1444 if( aFlags & ENVVARS_CHANGED )
1445 SyncLibraries( true );
1446
1447 Layout();
1448 SendSizeEvent();
1449}
1450
1451
1453{
1454 // call my base class
1456
1457 // tooltips in toolbars
1459
1460 // For some obscure reason, the AUI manager hides the first modified pane.
1461 // So force show panes
1462 wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
1463 bool tree_shown = tree_pane_info.IsShown();
1464 tree_pane_info.Caption( _( "Libraries" ) );
1465 tree_pane_info.Show( tree_shown );
1466 m_auimgr.Update();
1467
1469
1470 // status bar
1472
1473 if( GetRenderSettings()->m_ShowPinsElectricalType )
1474 {
1476 GetCanvas()->Refresh();
1477 }
1478
1479 UpdateTitle();
1480}
1481
1482
1484{
1485 SCH_BASE_FRAME::SetScreen( aScreen );
1486
1487 // Let tools add things to the view if necessary
1488 if( m_toolManager )
1490}
1491
1492
1510
1511
1513{
1514 SyncLibraries( true );
1515
1516 if( m_symbol )
1517 {
1518 SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
1519 SCH_SELECTION& selection = selectionTool->GetSelection();
1520
1521 for( SCH_ITEM& item : m_symbol->GetDrawItems() )
1522 {
1523 if( !alg::contains( selection, &item ) )
1524 item.ClearSelected();
1525 else
1526 item.SetSelected();
1527 }
1528
1529 m_symbol->ClearCaches();
1530 }
1531
1532 RebuildView();
1533}
1534
1535
1536const BOX2I SYMBOL_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1537{
1538 if( !m_symbol )
1539 {
1540 // Gives a reasonable drawing area size
1541 int width = schIUScale.mmToIU( 50 );
1542 int height = schIUScale.mmToIU( 30 );
1543
1544 return BOX2I( VECTOR2I( -width/2, -height/2 ), VECTOR2I( width, height ) );
1545 }
1546 else
1547 {
1548 return m_symbol->Flatten()->GetUnitBoundingBox( m_unit, m_bodyStyle );
1549 }
1550}
1551
1552
1553void SYMBOL_EDIT_FRAME::FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll )
1554{
1555 static KIID lastBrightenedItemID( niluuid );
1556
1557 SCH_ITEM* lastItem = nullptr;
1558
1559 // nullptr will clear the current focus
1560 if( aItem != nullptr && !aItem->IsSCH_ITEM() )
1561 return;
1562
1563 if( m_symbol )
1564 {
1565 for( SCH_PIN* pin : m_symbol->GetPins() )
1566 {
1567 if( pin->m_Uuid == lastBrightenedItemID )
1568 lastItem = pin;
1569 }
1570
1571 std::vector<SCH_FIELD*> fields;
1572 m_symbol->GetFields( fields );
1573
1574 for( SCH_FIELD* field : fields )
1575 {
1576 if( field->m_Uuid == lastBrightenedItemID )
1577 lastItem = field;
1578 }
1579 }
1580
1581 if( lastItem && lastItem != aItem )
1582 {
1583 lastItem->ClearBrightened();
1584
1585 UpdateItem( lastItem );
1586 lastBrightenedItemID = niluuid;
1587 }
1588
1589 if( aItem )
1590 {
1591 if( !aItem->IsBrightened() )
1592 {
1593 aItem->SetBrightened();
1594
1595 UpdateItem( aItem );
1596 lastBrightenedItemID = aItem->m_Uuid;
1597 }
1598
1599 FocusOnLocation( VECTOR2I( aItem->GetFocusPosition().x, -aItem->GetFocusPosition().y ), aAllowScroll );
1600 }
1601}
1602
1603
1605{
1606 const std::string& payload = mail.GetPayload();
1607
1608 switch( mail.Command() )
1609 {
1610 case MAIL_LIB_EDIT:
1611 if( !payload.empty() )
1612 {
1613 wxString libFileName( payload );
1614 wxString libNickname;
1615 wxString msg;
1616
1618 const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
1619
1620 if( !libTableRow )
1621 {
1622 msg.Printf( _( "The current configuration does not include the symbol library '%s'." ),
1623 libFileName );
1624 msg += wxS( "\n" ) + _( "Use Manage Symbol Libraries to edit the configuration." );
1625 DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
1626 break;
1627 }
1628
1629 libNickname = libTableRow->GetNickName();
1630
1631 if( !libTable->HasLibrary( libNickname, true ) )
1632 {
1633 msg.Printf( _( "The symbol library '%s' is not enabled in the current configuration." ),
1634 UnescapeString( libNickname ) );
1635 msg += wxS( "\n" ) + _( "Use Manage Symbol Libraries to edit the configuration." );
1636 DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
1637 break;
1638 }
1639
1640 SetCurLib( libNickname );
1641
1642 if( m_treePane )
1643 {
1644 LIB_ID id( libNickname, wxEmptyString );
1645 GetLibTree()->SelectLibId( id );
1646 GetLibTree()->ExpandLibId( id );
1647 GetLibTree()->CenterLibId( id );
1648 }
1649 }
1650
1651 break;
1652
1653 case MAIL_RELOAD_LIB:
1654 {
1655 wxString currentLib = GetCurLib();
1657
1659
1660 // Check if the currently selected symbol library been removed or disabled.
1661 if( !currentLib.empty() && libTable && !libTable->HasLibrary( currentLib, true ) )
1662 {
1663 SetCurLib( wxEmptyString );
1664 emptyScreen();
1665 }
1666
1667 SyncLibraries( true );
1670
1671 break;
1672 }
1673
1675 {
1677 LIB_SYMBOL* symbol = GetCurSymbol();
1678
1679 wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s", payload );
1680
1681 if( !tbl || !symbol )
1682 break;
1683
1684 wxString libName = symbol->GetLibId().GetLibNickname();
1685 const SYMBOL_LIB_TABLE_ROW* row = tbl->FindRow( libName );
1686
1687 if( !row )
1688 return;
1689
1690 wxFileName libfullname( row->GetFullURI( true ) );
1691
1692 wxFileName changedLib( mail.GetPayload() );
1693 wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s, current symbols is %s",
1694 changedLib.GetFullPath(), libfullname.GetFullPath() );
1695
1696 if( changedLib == libfullname )
1697 {
1698 wxLogTrace( "KICAD_LIB_WATCH", "Refreshing symbol %s", symbol->GetName() );
1699
1700 SetScreen( m_dummyScreen ); // UpdateLibraryBuffer will destroy the old screen
1701 m_libMgr->UpdateLibraryBuffer( libName );
1702
1703 if( LIB_SYMBOL* lib_symbol = m_libMgr->GetBufferedSymbol( symbol->GetName(), libName ) )
1704 {
1705 // The buffered screen for the symbol
1706 SCH_SCREEN* symbol_screen = m_libMgr->GetScreen( lib_symbol->GetName(), libName );
1707
1708 SetScreen( symbol_screen );
1709 SetCurSymbol( new LIB_SYMBOL( *lib_symbol ), false );
1711
1712 if( m_toolManager )
1714 }
1715 }
1716
1717 break;
1718 }
1719
1720 default:
1721 ;
1722 }
1723}
1724
1725
1726std::unique_ptr<GRID_HELPER> SYMBOL_EDIT_FRAME::MakeGridHelper()
1727{
1728 return std::make_unique<EE_GRID_HELPER>( m_toolManager );
1729}
1730
1731
1733{
1734 // switches currently used canvas ( Cairo / OpenGL):
1735 SCH_BASE_FRAME::SwitchCanvas( aCanvasType );
1736
1737 // Set options specific to symbol editor (axies are always enabled):
1738 GetCanvas()->GetGAL()->SetAxesEnabled( true );
1740}
1741
1742
1744{
1745 wxCHECK( m_libMgr, false );
1746
1747 return m_libMgr->HasModifications();
1748}
1749
1750
1752{
1753 wxCHECK( m_libMgr, false );
1754
1755 // Test if the currently edited symbol is modified
1757 return true;
1758
1759 // Test if any library has been modified
1760 for( const wxString& libName : m_libMgr->GetLibraryNames() )
1761 {
1762 if( m_libMgr->IsLibraryModified( libName ) && !m_libMgr->IsLibraryReadOnly( libName ) )
1763 return true;
1764 }
1765
1766 return false;
1767}
1768
1769
1771{
1772 if( aItemCount == 0 )
1773 return;
1774
1775 UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
1776
1777 if( aItemCount < 0 )
1778 {
1779 list.ClearCommandList();
1780 }
1781 else
1782 {
1783 for( int ii = 0; ii < aItemCount; ii++ )
1784 {
1785 if( list.m_CommandsList.size() == 0 )
1786 break;
1787
1788 PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
1789 list.m_CommandsList.erase( list.m_CommandsList.begin() );
1790
1791 curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
1792 {
1793 delete aItem;
1794 } );
1795 delete curr_cmd; // Delete command
1796 }
1797 }
1798}
1799
1800
1802{
1803 return m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
1804}
1805
1806
1808{
1809 std::unique_ptr<LIB_SYMBOL> symbol = aSymbol->GetLibSymbolRef()->Flatten();
1810 wxCHECK( symbol, /* void */ );
1811
1812 symbol->SetLibId( aSymbol->GetLibId() );
1813
1814 // Take in account the symbol orientation and mirroring. to calculate the field
1815 // positions in symbol editor (i.e. no rotation, no mirroring)
1816 int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
1817 int mirror = aSymbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y );
1818
1819 std::vector<SCH_FIELD> fullSetOfFields;
1820
1821 for( const SCH_FIELD& field : aSymbol->GetFields() )
1822 {
1823 VECTOR2I pos = field.GetPosition() - aSymbol->GetPosition();
1824 SCH_FIELD libField( symbol.get(), field.GetId() );
1825
1826 libField = field;
1827
1828 // The inverse transform is mirroring before, rotate after
1829 switch( mirror )
1830 {
1831 case SYM_MIRROR_X: pos.y = -pos.y; break;
1832 case SYM_MIRROR_Y: pos.x = -pos.x; break;
1833 default: break;
1834 }
1835
1836 switch( orientation )
1837 {
1838 case SYM_ORIENT_90:
1839 std::swap( pos.x, pos.y );
1840 pos.x = - pos.x;
1841 break;
1842 case SYM_ORIENT_270:
1843 std::swap( pos.x, pos.y );
1844 pos.y = - pos.y;
1845 break;
1846 case SYM_ORIENT_180:
1847 pos.x = - pos.x;
1848 pos.y = - pos.y;
1849 break;
1850 default:
1851 break;
1852 }
1853
1854 libField.SetPosition( pos );
1855
1856 fullSetOfFields.emplace_back( std::move( libField ) );
1857 }
1858
1859 symbol->SetFields( fullSetOfFields );
1860
1861 if( m_symbol )
1862 SetCurSymbol( nullptr, false );
1863
1865 m_schematicSymbolUUID = aSymbol->m_Uuid;
1866 m_reference = symbol->GetReferenceField().GetText();
1867 m_unit = std::max( 1, aSymbol->GetUnit() );
1868 m_bodyStyle = std::max( 1, aSymbol->GetBodyStyle() );
1869
1870 // Optimize default edit options for this symbol
1871 // Usually if units are locked, graphic items are specific to each unit
1872 // and if units are interchangeable, graphic items are common to units
1874 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
1875
1876 // The buffered screen for the symbol
1877 SCH_SCREEN* tmpScreen = new SCH_SCREEN();
1878
1879 SetScreen( tmpScreen );
1880 SetCurSymbol( symbol.release(), true );
1881 setSymWatcher( nullptr );
1882
1885
1886 if( IsLibraryTreeShown() )
1888
1889 UpdateTitle();
1892
1893 // Let tools add things to the view if necessary
1894 if( m_toolManager )
1896
1898 GetCanvas()->Refresh();
1899}
1900
1901
1902bool SYMBOL_EDIT_FRAME::addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE aScope )
1903{
1904 wxFileName fn = aLibFile;
1905 wxFileName libTableFileName( Prj().GetProjectPath(),
1907 wxString libNickname = fn.GetName();
1909 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1910
1911 if( libTable->HasLibrary( libNickname ) )
1912 {
1913 wxString tmp;
1914 int suffix = 1;
1915
1916 while( libTable->HasLibrary( libNickname ) )
1917 {
1918 tmp.Printf( "%s%d", fn.GetName(), suffix );
1919 libNickname = tmp;
1920 suffix += 1;
1921 }
1922 }
1923
1925 row->SetNickName( libNickname );
1926
1927 wxString normalizedPath = NormalizePath( aLibFile, &envVars, Prj().GetProjectPath() );
1928
1929 if( aScope == GLOBAL_LIB_TABLE )
1930 {
1932 libTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
1933
1934 // We cannot normalize against the current project path when saving to global table.
1935 normalizedPath = NormalizePath( aLibFile, &envVars, wxEmptyString );
1936 }
1937
1938 row->SetFullURI( normalizedPath );
1939
1940 wxCHECK( libTable->InsertRow( row ), false );
1941
1942 try
1943 {
1944 libTable->Save( libTableFileName.GetFullPath() );
1945 }
1946 catch( const IO_ERROR& ioe )
1947 {
1948 wxString msg = aScope == GLOBAL_LIB_TABLE ? _( "Error saving global library table." )
1949 : _( "Error saving project library table." );
1950
1951 wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1952 dlg.SetExtendedMessage( ioe.What() );
1953 dlg.ShowModal();
1954
1955 return false;
1956 }
1957
1958 return true;
1959}
1960
1961
1962bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname,
1963 const wxString& aLibFile )
1964{
1965 // Check the global library table first because checking the project library table
1966 // checks the global library table as well due to library chaining.
1967 bool isGlobalTable = true;
1968 wxFileName libTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();;
1969 const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
1971 SYMBOL_LIB_TABLE_ROW* row = libTable->FindRow( aLibNickname );
1972
1973 if( !row )
1974 {
1975 libTableFileName.SetPath( Prj().GetProjectPath() );
1976 libTableFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
1977 libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
1978 isGlobalTable = false;
1979 row = libTable->FindRow( aLibNickname );
1980 }
1981
1982 wxCHECK( row, false );
1983
1984 wxString projectPath;
1985
1986 if( !isGlobalTable )
1987 projectPath = Prj().GetProjectPath();
1988
1989 wxString normalizedPath = NormalizePath( aLibFile, &envVars, projectPath );
1990
1991 row->SetFullURI( normalizedPath );
1992 row->SetType( "KiCad" );
1993
1994 try
1995 {
1996 libTable->Save( libTableFileName.GetFullPath() );
1997 }
1998 catch( const IO_ERROR& ioe )
1999 {
2000 wxString msg = isGlobalTable ? _( "Error saving global library table." )
2001 : _( "Error saving project library table." );
2002
2003 wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
2004 dlg.SetExtendedMessage( ioe.What() );
2005 dlg.ShowModal();
2006
2007 return false;
2008 }
2009
2010 return true;
2011}
2012
2013
2015{
2016 return m_symbol && !m_symbol->IsRoot();
2017}
2018
2019
2024
2025
2026void SYMBOL_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
2027{
2028 SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
2029
2030 if( EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( aItem ) )
2031 {
2032 eda_text->ClearBoundingBoxCache();
2033 eda_text->ClearRenderCache();
2034 }
2035}
2036
2037
2039{
2040 wxAuiPaneInfo& treePane = m_auimgr.GetPane( m_treePane );
2041 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
2042 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
2043
2044 // Don't give the selection filter its own visibility controls; instead show it if
2045 // anything else is visible
2046 bool showFilter = ( treePane.IsShown() && treePane.IsDocked() )
2047 || ( propertiesPane.IsShown() && propertiesPane.IsDocked() );
2048
2049 selectionFilterPane.Show( showFilter );
2050}
2051
2052
2054{
2055 // Returns the current render option for invisible fields
2057}
2058
2059
2061{
2062 // Returns the current render option for invisible pins
2064}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
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_16
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
BOX2< VECTOR2D > BOX2D
Definition box2.h:923
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION cancelInteractive
Definition actions.h:72
static TOOL_ACTION unselectAll
Definition actions.h:83
static TOOL_ACTION revert
Definition actions.h:62
static TOOL_ACTION showLibraryTree
Definition actions.h:163
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION showDatasheet
Definition actions.h:266
static TOOL_ACTION toggleBoundingBoxes
Definition actions.h:156
static TOOL_ACTION saveAll
Definition actions.h:61
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION duplicate
Definition actions.h:84
static TOOL_ACTION doDelete
Definition actions.h:85
static TOOL_ACTION selectionTool
Definition actions.h:250
static TOOL_ACTION save
Definition actions.h:58
static TOOL_ACTION zoomFitScreen
Definition actions.h:141
static TOOL_ACTION redo
Definition actions.h:76
static TOOL_ACTION deleteTool
Definition actions.h:86
static TOOL_ACTION zoomTool
Definition actions.h:145
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
static TOOL_ACTION showProperties
Definition actions.h:265
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION ddAddLibrary
Definition actions.h:67
static TOOL_ACTION copyAsText
Definition actions.h:79
static TOOL_ACTION toggleGridOverrides
Definition actions.h:198
static TOOL_ACTION selectAll
Definition actions.h:82
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.
wxString m_ColorTheme
Active color theme name.
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
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:237
constexpr void SetSize(const SizeVec &size)
Definition box2.h:248
Color settings are a bit different than most of the settings objects in that there can be more than o...
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
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()
UNDO_REDO_LIST
Specify 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...
ACTION_TOOLBAR * m_tbRight
TOOLBAR_SETTINGS * m_toolbarSettings
wxAuiManager m_auimgr
void ShowInfoBarWarning(const wxString &aWarningMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and a warning icon on the left ...
virtual void RecreateToolbars()
UNDO_REDO_CONTAINER m_redoList
ACTION_TOOLBAR * m_tbLeft
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
ACTION_TOOLBAR * m_tbTopMain
wxString m_aboutTitle
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
void ReCreateMenuBar()
Recreate the menu bar.
WX_INFOBAR * GetInfoBar()
COLOR_SETTINGS * m_colorSettings
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
void setupUnits(APP_SETTINGS_BASE *aCfg)
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Change the current rendering backend.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void resolveCanvasType()
Determine the canvas type to load (with prompt if required) and initializes m_canvasType.
static const wxString PropertiesPaneName()
EDA_MSG_PANEL * m_messagePanel
virtual void SetScreen(BASE_SCREEN *aScreen)
bool LibraryFileBrowser(const wxString &aTitle, bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY *aFileDlgHook=nullptr)
void FocusOnLocation(const VECTOR2I &aPos, bool aAllowScroll=true)
Useful to focus on a particular location, in find functions.
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:98
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition eda_item.h:279
const KIID m_Uuid
Definition eda_item.h:516
void ClearBrightened()
Definition eda_item.h:138
void SetBrightened()
Definition eda_item.h:135
bool IsBrightened() const
Definition eda_item.h:129
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:80
Class that groups generic conditions for editor states.
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
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 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.
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.
virtual const wxString What() const
A composite of Problem() and Where()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:42
int ShowModal() override
Definition kidialog.cpp:93
bool m_axesEnabled
Crosshair drawing mode.
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:206
void ClearHiddenFlags()
Clear the hide flag of all items in the view.
Definition sch_view.cpp:194
bool IsSCH_ITEM() const
Definition view_item.h:101
void Clear()
Remove all items from the view.
Definition view.cpp:1143
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1561
Definition kiid.h:49
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
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:286
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:395
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition kiway.cpp:499
Module editor specific tools.
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:111
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.
Define a library symbol object.
Definition lib_symbol.h:87
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:156
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition lib_symbol.h:293
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition lib_symbol.h:207
wxString GetName() const override
Definition lib_symbol.h:150
bool IsMultiUnit() const override
Definition lib_symbol.h:748
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
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.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
Definition lib_tree.cpp:472
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition lib_tree.cpp:381
int GetSelectionCount() const
Definition lib_tree.h:91
void ShutdownPreviews()
Definition lib_tree.cpp:287
void ShowChangedLanguage()
Definition lib_tree.cpp:304
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition lib_tree.cpp:487
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition lib_tree.cpp:375
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition lib_tree.h:155
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieve a list of selections for trees that allow multi-selection.
Definition lib_tree.cpp:334
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition lib_tree.cpp:387
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:314
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition lib_tree.cpp:395
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition lib_tree.cpp:454
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition pgm_base.cpp:822
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:125
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:222
@ SCH_LIBEDIT_CUR_SYMBOL
Definition project.h:223
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:162
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:334
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:345
Action handler for the Properties panel.
Gather all the actions that are shared by tools.
Definition sch_actions.h:40
static TOOL_ACTION rotateCCW
static TOOL_ACTION importSymbol
static TOOL_ACTION newSymbol
static TOOL_ACTION saveLibraryAs
static TOOL_ACTION mirrorV
static TOOL_ACTION editLibSymbolWithLibEdit
static TOOL_ACTION drawArc
Definition sch_actions.h:97
static TOOL_ACTION pinTable
static TOOL_ACTION drawSymbolLines
static TOOL_ACTION placeSymbolPin
static TOOL_ACTION drawSymbolTextBox
static TOOL_ACTION drawRectangle
Definition sch_actions.h:95
static TOOL_ACTION drawCircle
Definition sch_actions.h:96
static TOOL_ACTION importGraphics
static TOOL_ACTION drawBezier
Definition sch_actions.h:98
static TOOL_ACTION saveSymbolCopyAs
static TOOL_ACTION rotateCW
static TOOL_ACTION showElectricalTypes
static TOOL_ACTION drawSymbolPolygon
static TOOL_ACTION showHiddenFields
static TOOL_ACTION placeSymbolAnchor
static TOOL_ACTION showHiddenPins
static TOOL_ACTION cycleBodyStyle
static TOOL_ACTION mirrorH
static TOOL_ACTION runERC
Inspection and Editing.
static TOOL_ACTION symbolProperties
static TOOL_ACTION placeSymbolText
static TOOL_ACTION toggleSyncedPinsMode
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION saveSymbolAs
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aWindowType, const wxString &aTitle, const wxPoint &aPosition, const wxSize &aSize, long aStyle, const wxString &aFrameName)
SCH_RENDER_SETTINGS * GetRenderSettings()
void doCloseWindow() override
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.
SYMBOL_EDITOR_SETTINGS * libeditconfig() const
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void SyncView()
Mark all items for refresh.
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Save Symbol Library Tables to disk.
PANEL_SCH_SELECTION_FILTER * m_selectionFilterPanel
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.
void SetPosition(const VECTOR2I &aPosition) override
Handle actions specific to the schematic editor.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
int GetBodyStyle() const
Definition sch_item.h:247
int GetUnit() const
Definition sch_item.h:238
Tool that displays edit points allowing to modify items by dragging the points.
SCH_SELECTION & GetSelection()
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
Schematic symbol object.
Definition sch_symbol.h:75
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:808
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:164
int GetOrientation() const override
Get the display symbol orientation.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:183
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).
Handle actions for the various symbol editor and viewers.
bool m_ShowPinAltIcons
When true, dragging an outline edge will drag pins rooted on it.
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.
std::unique_ptr< GRID_HELPER > MakeGridHelper() override
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
Return 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.
bool IsLibraryTreeShown() const override
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box 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.
void OnSelectBodyStyle(wxCommandEvent &event)
bool backupFile(const wxFileName &aOriginalFile, const wxString &aBackupExt)
Return currently edited symbol.
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...
void CommonSettingsChanged(int aFlags) override
Called after the preferences dialog is run.
void FocusLibraryTreeInput() override
wxComboBox * m_unitSelectBox
void RebuildSymbolUnitAndBodyStyleLists()
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.
void FocusOnLibId(const LIB_ID &aLibID)
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
void ToggleProperties() override
SYMBOL_EDITOR_SETTINGS * m_settings
void HardRedraw() override
Rebuild the GAL and redraw the screen.
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 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)
SYMBOL_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
std::vector< LIB_ID > GetSelectedLibIds() 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 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
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)
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.
LIB_TREE * GetLibTree() const override
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.
bool LoadSymbolFromCurrentLib(const wxString &aSymbolName, int aUnit=0, int aBodyStyle=0)
Load a symbol from the current active library, optionally setting the selected unit and convert.
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.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void OnUpdateBodyStyle(wxUpdateUIEvent &event)
void SaveSymbolCopyAs(bool aOpenCopy)
Save the currently selected symbol to a new name and/or location.
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 FocusOnItem(EDA_ITEM *aItem, bool aAllowScroll=true) override
Focus on a particular canvas item.
void configureToolbars() override
void CloseWindow(wxCommandEvent &event)
Trigger the wxCloseEvent, which is handled by the function given to EVT_CLOSE() macro:
wxComboBox * m_bodyStyleSelectBox
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 ShowChangedLanguage() override
Redraw the menus and what not in current language.
void SaveLibraryAs()
Save the currently selected library to a new file.
bool IsContentModified() const override
Get if any symbols or libraries have been modified but not saved.
void ToggleLibraryTree() override
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)
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.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
@ 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:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
A holder to handle a list of undo (or redo) commands.
bool empty() const
Definition utf8.h:110
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:194
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
Definition confirm.cpp:64
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:169
This file is part of the common library.
#define CHECK(x)
#define ENABLE(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:65
@ ID_LIBEDIT_SELECT_BODY_STYLE
Definition eeschema_id.h:66
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:73
Helper functions to substitute paths with environmental variables.
@ 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:612
KIID niluuid(0)
@ LAYER_SCHEMATIC_GRID_AXES
Definition layer_ids.h:487
@ MAIL_LIB_EDIT
Definition mail_type.h:55
@ MAIL_REFRESH_SYMBOL
Definition mail_type.h:59
@ MAIL_RELOAD_LIB
Definition mail_type.h:57
@ ALL
All except INITIAL_ADD.
Definition view_item.h:59
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition unix/app.cpp:90
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition unix/app.cpp:79
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
#define _HKI(x)
Definition page_info.cpp:44
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:913
see class PGM_BASE
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
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 ...
@ SYM_ORIENT_270
Definition symbol.h:42
@ SYM_MIRROR_Y
Definition symbol.h:44
@ SYM_ORIENT_180
Definition symbol.h:41
@ SYM_MIRROR_X
Definition symbol.h:43
@ SYM_ORIENT_90
Definition symbol.h:40
#define EDIT_TOOL(tool)
#define DEMORGAN_ALT
#define DEMORGAN_STD
Definition for symbol library class.
#define ENVVARS_CHANGED
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
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.
#define PR_CAN_ABORT