KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_base_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) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <advanced_config.h>
26#include <base_units.h>
28#include <kiway.h>
30#include <pgm_base.h>
31#include <eda_list_dialog.h>
34#include <eeschema_settings.h>
38#include <sch_draw_panel.h>
40#include <sch_group.h>
41#include <sch_view.h>
42#include <sch_painter.h>
43#include <sch_shape.h>
46#include <widgets/wx_infobar.h>
47#include <confirm.h>
49#include <project_sch.h>
52#include <sch_base_frame.h>
54#include <design_block.h>
55#include <thread_pool.h>
56#include <tool/actions.h>
57#include <tool/action_toolbar.h>
58#include <tool/tool_manager.h>
61#include <trace_helpers.h>
62#include <view/view_controls.h>
63#include <widgets/kistatusbar.h>
64#include <wx/choicdlg.h>
65#include <wx/evtloop.h>
66#include <wx/fswatcher.h>
67#include <wx/log.h>
68#include <wx/msgdlg.h>
69#include <trace_helpers.h>
70
71#if defined(__linux__) || defined(__FreeBSD__)
73#else
75#include <wx/fdrepdlg.h>
76#endif
77
78
80 LEGACY_SYMBOL_LIB* aCacheLib, wxWindow* aParent, bool aShowErrorMsg )
81{
82 wxCHECK_MSG( aLibMgr, nullptr, wxS( "Invalid symbol library manager adapter." ) );
83
84 LIB_SYMBOL* symbol = nullptr;
85
86 try
87 {
88 symbol = aLibMgr->LoadSymbol( aLibId );
89
90 if( !symbol && aCacheLib )
91 {
92 wxCHECK_MSG( aCacheLib->IsCache(), nullptr, wxS( "Invalid cache library." ) );
93
94 wxString cacheName = aLibId.GetLibNickname().wx_str();
95 cacheName << "_" << aLibId.GetLibItemName();
96 symbol = aCacheLib->FindSymbol( cacheName );
97 }
98 }
99 catch( const IO_ERROR& ioe )
100 {
101 if( aShowErrorMsg )
102 {
103 wxString msg = wxString::Format( _( "Error loading symbol %s from library '%s'." ),
104 aLibId.GetLibItemName().wx_str(),
105 aLibId.GetLibNickname().wx_str() );
106 DisplayErrorMessage( aParent, msg, ioe.What() );
107 }
108 }
109
110 return symbol;
111}
112
113
114SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindowType,
115 const wxString& aTitle, const wxPoint& aPosition,
116 const wxSize& aSize, long aStyle, const wxString& aFrameName ) :
117 EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition, aSize, aStyle,
118 aFrameName, schIUScale ),
119 m_selectionFilterPanel( nullptr ),
120 m_findReplaceDialog( nullptr ),
121 m_base_frame_defaults( nullptr, "base_Frame_defaults" ),
123{
124 m_findReplaceData = std::make_unique<SCH_SEARCH_DATA>();
125
126 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
127 createCanvas();
128
129 Bind( wxEVT_IDLE,
130 [this]( wxIdleEvent& aEvent )
131 {
132 // Handle cursor adjustments. While we can get motion and key events through
133 // wxWidgets, we can't get modifier-key-up events.
134 if( m_toolManager )
135 {
137
138 if( selTool )
139 selTool->OnIdle( aEvent );
140 }
141 } );
142
143 Pgm().GetBackgroundJobMonitor().RegisterStatusBar( static_cast<KISTATUSBAR*>( GetStatusBar() ) );
144
146}
147
148
151{
152 Pgm().GetBackgroundJobMonitor().UnregisterStatusBar( static_cast<KISTATUSBAR*>( GetStatusBar() ) );
153}
154
155
157{
158 GetCanvas()->SetEvtHandlerEnabled( false );
160
161 // Shutdown all running tools
162 if( m_toolManager )
163 m_toolManager->ShutdownAllTools();
164
165 // Close the find dialog and preserve its setting if it is displayed.
167 {
169 m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
170
171 m_findReplaceDialog->Destroy();
172 m_findReplaceDialog = nullptr;
173 }
174
175 // This class is pure virtual. Derived class will finish shutdown and Destroy().
176}
177
178
183
184
186{
187 return dynamic_cast<EESCHEMA_SETTINGS*>( config() );
188}
189
190
195
196
198{
199 switch( GetFrameType() )
200 {
201 case FRAME_SCH:
202 default:
203 return GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
204
206 case FRAME_SCH_VIEWER:
208 return GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" );
209 }
210}
211
212
213void SCH_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
214{
215 GetScreen()->SetPageSettings( aPageSettings );
216}
217
218
220{
221 return GetScreen()->GetPageSettings();
222}
223
224
226{
227 // GetSizeIU is compile time dependent:
228 return GetScreen()->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS );
229}
230
231
233{
234 wxASSERT( GetScreen() );
235 return GetScreen()->GetTitleBlock();
236}
237
238
240{
241 wxASSERT( GetScreen() );
242 GetScreen()->SetTitleBlock( aTitleBlock );
243}
244
245
247{
248 wxString line;
249 BASE_SCREEN* screen = GetScreen();
250
251 if( !screen )
252 return;
253
255
256 // Display absolute and relative coordinates
258 VECTOR2D d = cursorPos - screen->m_LocalOrigin;
259
260 line.Printf( wxS( "X %s Y %s" ),
261 MessageTextFromValue( cursorPos.x, false ),
262 MessageTextFromValue( cursorPos.y, false ) );
263 SetStatusText( line, 2 );
264
265 line.Printf( wxS( "dx %s dy %s dist %s" ),
266 MessageTextFromValue( d.x, false ),
267 MessageTextFromValue( d.y, false ),
268 MessageTextFromValue( hypot( d.x, d.y ), false ) );
269 SetStatusText( line, 3 );
270
273}
274
275
276LIB_SYMBOL* SCH_BASE_FRAME::GetLibSymbol( const LIB_ID& aLibId, bool aUseCacheLib,
277 bool aShowErrorMsg )
278{
279 LEGACY_SYMBOL_LIB* cache =
280 ( aUseCacheLib ) ? PROJECT_SCH::LegacySchLibs( &Prj() )->GetCacheLibrary() : nullptr;
281
282 return SchGetLibSymbol( aLibId, PROJECT_SCH::SymbolLibAdapter( &Prj() ), cache, this,
283 aShowErrorMsg );
284}
285
286
287void SCH_BASE_FRAME::RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer )
288{
289 GetCanvas()->GetView()->SetCenter( aCenterPoint );
290
291 if( aWarpPointer )
293
294 GetCanvas()->Refresh();
295}
296
297
299{
300 if( GetCanvas() && GetCanvas()->GetView() )
301 {
304 }
305}
306
307
312
313
315{
316 if( GetCanvas() && GetCanvas()->GetView() )
317 {
318 if( KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter() )
319 return static_cast<SCH_RENDER_SETTINGS*>( painter->GetSettings() );
320 }
321
322 return nullptr;
323}
324
325
327{
329
330 SetCanvas( new SCH_DRAW_PANEL( this, wxID_ANY, wxPoint( 0, 0 ), m_frameSize,
333}
334
335
337{
339
340 try
341 {
342 if( !m_spaceMouse )
343 {
344#if defined(__linux__) || defined(__FreeBSD__)
345 m_spaceMouse = std::make_unique<SPNAV_2D_PLUGIN>( GetCanvas() );
346 m_spaceMouse->SetScale( schIUScale.IU_PER_MILS / pcbIUScale.IU_PER_MILS );
347#else
348 m_spaceMouse = std::make_unique<NL_SCHEMATIC_PLUGIN>();
349#endif
350 }
351
352 m_spaceMouse->SetCanvas( GetCanvas() );
353 }
354 catch( const std::system_error& e )
355 {
356 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
357 }
358}
359
360
361void SCH_BASE_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
362{
363 EDA_ITEM* parent = aItem->GetParent();
364
365 if( aItem->Type() == SCH_SHEET_PIN_T )
366 {
367 // Sheet pins aren't in the view. Refresh their parent.
368 if( parent )
369 GetCanvas()->GetView()->Update( parent );
370 }
371 else
372 {
373 if( aItem->Type() == SCH_SHAPE_T )
374 static_cast<SCH_SHAPE*>( aItem )->UpdateHatching();
375
376 if( !isAddOrDelete )
377 GetCanvas()->GetView()->Update( aItem );
378
379 // Some children are drawn from their parents. Mark them for re-paint.
380 if( parent && ( parent->Type() == SCH_SYMBOL_T
381 || parent->Type() == SCH_SHEET_T
382 || parent->Type() == SCH_LABEL_LOCATE_ANY_T
383 || parent->Type() == SCH_TABLE_T ) )
384 {
385 GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT );
386 }
387 }
388
389 /*
390 * Be careful when calling this. Update will invalidate RTree iterators, so you cannot
391 * call this while doing things like `for( SCH_ITEM* item : screen->Items() )`
392 */
393 if( aUpdateRtree && dynamic_cast<SCH_ITEM*>( aItem ) )
394 {
395 GetScreen()->Update( static_cast<SCH_ITEM*>( aItem ) );
396
397 /*
398 * If we are updating the group, we also need to update all the children otherwise
399 * their positions will remain stale in the RTree
400 */
401 if( SCH_GROUP* group = dynamic_cast<SCH_GROUP*>( aItem ) )
402 {
403 group->RunOnChildren(
404 [&]( SCH_ITEM* item )
405 {
406 GetScreen()->Update( item );
407 },
409 }
410 }
411
412 // Calling Refresh() here introduces a bi-stable state: when doing operations on a
413 // large number of items if at some point the refresh timer times out and does a
414 // refresh it will take long enough that the next item will also time out, and the
415 // next, and the next, etc.
416 // GetCanvas()->Refresh();
417}
418
419
421{
422 // We currently have two zoom-dependent renderings: text, which is rendered as bitmap text
423 // when too small to see the difference, and selection shadows.
424 //
425 // Because non-selected text is cached by OpenGL, we only apply the bitmap performance hack
426 // to selected text items.
427 //
428 // Thus, as it currently stands, all zoom-dependent items can be found in the list of selected
429 // items.
430 if( m_toolManager )
431 {
432 SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
433 SELECTION& selection = selectionTool->GetSelection();
434 KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
435
436 for( EDA_ITEM* item : selection )
437 {
438 if( item->RenderAsBitmap( view->GetGAL()->GetWorldScale() ) != item->IsShownAsBitmap()
440 {
441 view->Update( item, KIGFX::REPAINT );
442
443 EDA_ITEM* parent = item->GetParent();
444
445 // Symbol children are drawn from their parents. Mark them for re-paint.
446 if( parent && parent->Type() == SCH_SYMBOL_T )
447 GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT );
448 }
449 }
450 }
451}
452
453
455{
456 // Null pointers will cause boost::ptr_vector to raise a boost::bad_pointer exception which
457 // will be unhandled. There is no valid reason to pass an invalid EDA_ITEM pointer to the
458 // screen append function.
459 wxCHECK( aItem, /* void */ );
460
461 SCH_SCREEN* screen = aScreen;
462
463 if( aScreen == nullptr )
464 screen = GetScreen();
465
466 if( aItem->Type() != SCH_TABLECELL_T )
467 screen->Append( (SCH_ITEM*) aItem );
468
469 if( screen == GetScreen() )
470 {
471 GetCanvas()->GetView()->Add( aItem );
472 UpdateItem( aItem, true ); // handle any additional parent semantics
473 }
474}
475
476
478{
479 auto screen = aScreen;
480
481 if( aScreen == nullptr )
482 screen = GetScreen();
483
484 if( screen == GetScreen() )
485 GetCanvas()->GetView()->Remove( aItem );
486
487 if( aItem->Type() != SCH_TABLECELL_T )
488 screen->Remove( (SCH_ITEM*) aItem );
489
490 if( screen == GetScreen() )
491 UpdateItem( aItem, true ); // handle any additional parent semantics
492}
493
494
496{
497 // Let tools add things to the view if necessary
498 if( m_toolManager )
500
502}
503
504
509
510
512{
513 wxString findString;
514
515 SCH_SELECTION& selection = m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
516
517 if( selection.Size() == 1 )
518 {
519 EDA_ITEM* front = selection.Front();
520
521 switch( front->Type() )
522 {
523 case SCH_SYMBOL_T:
524 {
525 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( front );
526 findString = UnescapeString( symbol->GetField( FIELD_T::VALUE )->GetText() );
527 break;
528 }
529
530 case SCH_FIELD_T:
531 findString = UnescapeString( static_cast<SCH_FIELD*>( front )->GetText() );
532 break;
533
534 case SCH_LABEL_T:
536 case SCH_HIER_LABEL_T:
537 case SCH_SHEET_PIN_T:
538 findString = UnescapeString( static_cast<SCH_LABEL_BASE*>( front )->GetText() );
539 break;
540
541 case SCH_TEXT_T:
542 findString = UnescapeString( static_cast<SCH_TEXT*>( front )->GetText() );
543
544 if( findString.Contains( wxT( "\n" ) ) )
545 findString = findString.Before( '\n' );
546
547 break;
548
549 default:
550 break;
551 }
552 }
553
555 m_findReplaceDialog->Destroy();
556
557 m_findReplaceDialog = new DIALOG_SCH_FIND( this, static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ),
558 wxDefaultPosition, wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
559
560 m_findReplaceDialog->SetFindEntries( m_findStringHistoryList, findString );
562 m_findReplaceDialog->Show( true );
563}
564
565
566void SCH_BASE_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
567{
568 // Prepare the infobar, since we don't know its state
569 m_infoBar->RemoveAllButtons();
570 m_infoBar->AddCloseButton();
571
572 m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
573}
574
575
577{
578 m_infoBar->Dismiss();
579}
580
581
583{
585 m_replaceStringHistoryList = m_findReplaceDialog->GetReplaceEntries();
586
587 m_findReplaceDialog->Destroy();
588 m_findReplaceDialog = nullptr;
589
591}
592
593
607
608
610{
611 if( !m_colorSettings || aForceRefresh )
612 {
614 wxString colorTheme = cfg ? cfg->m_ColorTheme : wxString( "" );
615
617 {
618 if( SYMBOL_EDITOR_SETTINGS* sym_edit_cfg = GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" ) )
619 {
620 if( !sym_edit_cfg->m_UseEeschemaColorSettings )
621 colorTheme = sym_edit_cfg->m_ColorTheme;
622 }
623 }
624
625 const_cast<SCH_BASE_FRAME*>( this )->m_colorSettings = ::GetColorSettings( colorTheme );
626 }
627
628 return m_colorSettings;
629}
630
631
636
637
638void SCH_BASE_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
639{
641
642 if( m_spaceMouse )
643 m_spaceMouse->SetFocus( aEvent.GetActive() );
644}
645
646
647void SCH_BASE_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
648{
650
651 if( m_spaceMouse )
652 m_spaceMouse->SetFocus( false );
653}
654
655
657 std::vector<wxArrayString>& aItemsToDisplay )
658{
659 aHeaders.Add( _( "Library" ) );
660 aHeaders.Add( _( "Description" ) );
661
665 std::vector<wxString> libNicknames = adapter->GetLibraryNames();
666 std::vector<wxArrayString> unpinned;
667
668 for( const wxString& nickname : libNicknames )
669 {
670 wxArrayString item;
671 wxString description = adapter->GetLibraryDescription( nickname ).value_or( wxEmptyString );
672
673 if( alg::contains( project.m_PinnedSymbolLibs, nickname )
674 || alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
675 {
676 item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
677 item.Add( description );
678 aItemsToDisplay.push_back( item );
679 }
680 else
681 {
682 item.Add( nickname );
683 item.Add( description );
684 unpinned.push_back( item );
685 }
686 }
687
688 std::ranges::copy( unpinned, std::back_inserter( aItemsToDisplay ) );
689}
690
691
692wxString SCH_BASE_FRAME::SelectLibrary( const wxString& aDialogTitle, const wxString& aListLabel,
693 const std::vector<std::pair<wxString, bool*>>& aExtraCheckboxes )
694{
695 static const int ID_MAKE_NEW_LIBRARY = wxID_HIGHEST;
696
697 // Keep asking the user for a new name until they give a valid one or cancel the operation
698 while( true )
699 {
700 wxArrayString headers;
701 std::vector<wxArrayString> itemsToDisplay;
702
703 GetLibraryItemsForListDialog( headers, itemsToDisplay );
704
705 wxString libraryName = Prj().GetRString( PROJECT::SCH_LIB_SELECT );
706
707 EDA_LIST_DIALOG dlg( this, aDialogTitle, headers, itemsToDisplay, libraryName, false );
708 dlg.SetListLabel( aListLabel );
709
710 for( const auto& [label, val] : aExtraCheckboxes )
711 dlg.AddExtraCheckbox( label, val );
712
713 wxButton* newLibraryButton = new wxButton( &dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
714 dlg.m_ButtonsSizer->Prepend( 80, 20 );
715 dlg.m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
716
717 newLibraryButton->Bind( wxEVT_BUTTON,
718 [&dlg]( wxCommandEvent& )
719 {
720 dlg.EndModal( ID_MAKE_NEW_LIBRARY );
722
723 dlg.Layout();
724 dlg.GetSizer()->Fit( &dlg );
725
726 int ret = dlg.ShowModal();
727
728 switch( ret )
729 {
730 case wxID_CANCEL:
731 return wxEmptyString;
732
733 case wxID_OK:
734 libraryName = dlg.GetTextSelection();
735 Prj().SetRString( PROJECT::SCH_LIB_SELECT, libraryName );
737 return libraryName;
738
740 {
741 SYMBOL_LIBRARY_MANAGER mgr( *this );
742 wxFileName fn( Prj().GetRString( PROJECT::SCH_LIB_PATH ) );
743 bool useGlobalTable = false;
744 FILEDLG_HOOK_NEW_LIBRARY tableChooser( useGlobalTable );
745
746 if( !LibraryFileBrowser( _( "Create New Library" ), false, fn, FILEEXT::KiCadSymbolLibFileWildcard(),
747 FILEEXT::KiCadSymbolLibFileExtension, false, &tableChooser ) )
748 {
749 break;
750 }
751
752 libraryName = fn.GetName();
753 Prj().SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
754
758
759 if( adapter->HasLibrary( libraryName, false ) )
760 {
761 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libraryName ) );
762 break;
763 }
764
765 if( !mgr.CreateLibrary( fn.GetFullPath(), scope ) )
766 DisplayError( this, wxString::Format( _( "Could not add library '%s'." ), libraryName ) );
767
768 break;
769 }
770
771 default:
772 break;
773 }
774 }
775}
776
777
779{
780 Unbind( wxEVT_FSWATCHER, &SCH_BASE_FRAME::OnSymChange, this );
781
782 if( m_watcher )
783 {
784 wxLogTrace( traceLibWatch, "Remove watch" );
785 m_watcher->RemoveAll();
786 m_watcher->SetOwner( nullptr );
787 m_watcher.reset();
788 }
789
790 if( !aID )
791 return;
792
794 std::optional<wxString> uri = manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL,
795 aID->GetLibNickname() );
796
797 if( !uri )
798 {
799 wxLogTrace( traceLibWatch, "Could not get URI for library %s",
800 wxString( aID->GetLibNickname().c_str() ) );
801 return;
802 }
803
804 wxString tmp = ExpandEnvVarSubstitutions( *uri, &Prj() );
805
806 wxLogTrace( traceLibWatch, "Setting up watcher for %s", tmp );
807 m_watcherFileName.Assign( tmp );
808
809 if( !m_watcherFileName.FileExists() )
810 return;
811
812 wxLog::EnableLogging( false );
813 m_watcherLastModified = m_watcherFileName.GetModificationTime();
814 wxLog::EnableLogging( true );
815
816 // File system watcher requires an active event loop. If we're being called during
817 // library enumeration before the main event loop is running, skip watcher creation.
818 if( !wxEventLoopBase::GetActive() )
819 return;
820
821 Bind( wxEVT_FSWATCHER, &SCH_BASE_FRAME::OnSymChange, this );
822 m_watcher = std::make_unique<wxFileSystemWatcher>();
823 m_watcher->SetOwner( this );
824
825 wxFileName fn;
826 fn.AssignDir( m_watcherFileName.GetPath() );
827 fn.DontFollowLink();
828
829 {
830 // Silence OS errors that come from the watcher
831 wxLogNull silence;
832 m_watcher->Add( fn );
833 }
834}
835
836
837void SCH_BASE_FRAME::OnSymChange( wxFileSystemWatcherEvent& aEvent )
838{
840
841 wxLogTrace( traceLibWatch, "OnSymChange: %s, watcher file: %s",
842 aEvent.GetPath().GetFullPath(), m_watcherFileName.GetFullPath() );
843
844 if( !libs || !m_watcher || !m_watcher.get() || m_watcherFileName.GetPath().IsEmpty() )
845 return;
846
847 if( aEvent.GetPath() != m_watcherFileName )
848 return;
849
850 // Start the debounce timer (set to 1 second)
851 if( !m_watcherDebounceTimer.StartOnce( 1000 ) )
852 {
853 wxLogTrace( traceLibWatch, "Failed to start the debounce timer" );
854 return;
855 }
856}
857
858
860{
861 if( aEvent.GetId() != m_watcherDebounceTimer.GetId() )
862 {
863 aEvent.Skip();
864 return;
865 }
866
868 {
869 wxLogTrace( traceLibWatch, "Restarting debounce timer" );
870 m_watcherDebounceTimer.StartOnce( 3000 );
871 }
872
873 wxLogTrace( traceLibWatch, "OnSymChangeDebounceTimer" );
874
875 // Disable logging to avoid spurious messages and check if the file has changed
876 wxLog::EnableLogging( false );
877 wxDateTime lastModified = m_watcherFileName.GetModificationTime();
878 wxLog::EnableLogging( true );
879
880 if( lastModified == m_watcherLastModified || !lastModified.IsValid() )
881 return;
882
883 m_watcherLastModified = lastModified;
884
886
888 || IsOK( this, _( "The library containing the current symbol has changed.\n"
889 "Do you want to reload the library?" ) ) )
890 {
891 wxLogTrace( traceLibWatch, "Sending refresh symbol mail" );
892 std::string libName = m_watcherFileName.GetFullPath().ToStdString();
895 }
896
898}
899
900
902{
903 if( m_toolManager )
904 return m_toolManager->GetTool<SCH_SELECTION_TOOL>();
905
906 return nullptr;
907}
908
909
911{
912 SCH_SELECTION_FILTER_EVENT evt( aOptions );
913 wxPostEvent( this, evt );
914}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
static TOOL_ACTION updateFind
Definition actions.h:124
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
wxString m_ColorTheme
Active color theme name.
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:41
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition base_screen.h:90
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
int ShowModal() override
FRAME_T GetFrameType() const
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
WX_INFOBAR * m_infoBar
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
bool IsType(FRAME_T aType) const
wxArrayString m_replaceStringHistoryList
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
COLOR_SETTINGS * m_colorSettings
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
void DisplayUnitsMsg()
Display current unit pane in the status bar.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
bool LibraryFileBrowser(const wxString &aTitle, bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY *aFileDlgHook=nullptr)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
void UpdateStatusBar() override
Update the status bar information.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void DisplayGridMsg()
Display current grid size in the status bar.
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting()
Return the canvas type stored in the application settings.
wxArrayString m_findStringHistoryList
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
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.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:99
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
EDA_ITEM * GetParent() const
Definition eda_item.h:113
A dialog which shows:
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
void AddExtraCheckbox(const wxString &aLabel, bool *aValuePtr)
Add a checkbox value to the dialog.
void GetExtraCheckboxValues()
Fills in the value pointers from the checkboxes after the dialog has run.
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()
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
double GetWorldScale() const
Get the world scale.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition painter.h:59
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
static std::vector< KICAD_T > g_ScaledSelectionTypes
void Update(const KIGFX::VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition sch_view.cpp:60
virtual void CenterOnCursor()=0
Set the viewport center to the current cursor position and warps the cursor to the screen center.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:299
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition view.cpp:342
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:203
void RecacheAllItems()
Rebuild GAL display lists.
Definition view.cpp:1466
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1576
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:221
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:601
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:640
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:295
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
Definition kiway.cpp:505
A collection of #SYMBOL_LIB objects.
Object used to load, save, search, and otherwise manipulate symbol library files.
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
std::optional< wxString > GetLibraryDescription(const wxString &aNickname) const
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
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
Define a library symbol object.
Definition lib_symbol.h:83
static const wxString GetPinningSymbol()
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:177
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:137
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:133
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
@ SCH_LIB_SELECT
Definition project.h:220
@ SCH_LIB_PATH
Definition project.h:219
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:203
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:349
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:360
virtual void RedrawScreen(const VECTOR2I &aCenterPoint, bool aWarpPointer)
SCH_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aWindowType, const wxString &aTitle, const wxPoint &aPosition, const wxSize &aSize, long aStyle, const wxString &aFrameName)
void UpdateStatusBar() override
Update the status bar information.
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen) override
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
SCH_RENDER_SETTINGS * GetRenderSettings()
void doCloseWindow() override
void ActivateGalCanvas() override
Use to start up the GAL drawing canvas.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void SetPageSettings(const PAGE_INFO &aPageSettings) override
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
void OnSymChange(wxFileSystemWatcherEvent &aEvent)
Handler for Symbol change events.
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.
APP_SETTINGS_BASE * GetViewerSettingsBase() const
void HighlightSelectionFilter(const SCH_SELECTION_FILTER_OPTIONS &aOptions)
void HardRedraw() override
Rebuild the GAL and redraws the screen.
DIALOG_SCH_FIND * m_findReplaceDialog
SCHEMATIC_SETTINGS m_base_frame_defaults
Only used by symbol_editor. Eeschema should be using the one inside the SCHEMATIC.
wxTimer m_watcherDebounceTimer
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void ShowFindReplaceDialog(bool aReplace)
Run the Find or Find & Replace dialog.
SCH_SELECTION_TOOL * GetSelectionTool() override
void SyncView()
Mark all items for refresh.
std::unique_ptr< NL_SCHEMATIC_PLUGIN > m_spaceMouse
void GetLibraryItemsForListDialog(wxArrayString &aHeaders, std::vector< wxArrayString > &aItemsToDisplay)
wxDateTime m_watcherLastModified
std::unique_ptr< wxFileSystemWatcher > m_watcher
These are file watchers for the symbol library tables.
wxString SelectLibrary(const wxString &aDialogTitle, const wxString &aListLabel, const std::vector< std::pair< wxString, bool * > > &aExtraCheckboxes={})
Display a list of loaded libraries and allows the user to select a library.
virtual ~SCH_BASE_FRAME()
Needs to be in the cpp file to encode the sizeof() for std::unique_ptr.
const TITLE_BLOCK & GetTitleBlock() const override
void RefreshZoomDependentItems()
Mark selected items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
PANEL_SCH_SELECTION_FILTER * m_selectionFilterPanel
LIB_SYMBOL * GetLibSymbol(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
virtual void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
void handleActivateEvent(wxActivateEvent &aEvent) override
Handle a window activation event.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
void OnFindDialogClose()
Notification that the Find dialog has closed.
wxFileName m_watcherFileName
void setSymWatcher(const LIB_ID *aSymbol)
Creates (or removes) a watcher on the specified symbol library.
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr) override
Add an item to the screen (and view) aScreen is the screen the item is located on,...
const PAGE_INFO & GetPageSettings() const override
void ShowFindReplaceStatus(const wxString &aMsg, int aStatusTime)
COLOR4D GetDrawBgColor() const override
void OnSymChangeDebounceTimer(wxTimerEvent &aEvent)
Handler for the filesystem watcher debounce timer.
void ClearFindReplaceStatus()
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper to retrieve a layer color from the global color settings.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:116
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:141
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition sch_screen.h:167
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition sch_screen.h:142
const TITLE_BLOCK & GetTitleBlock() const
Definition sch_screen.h:165
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
SCH_SELECTION & GetSelection()
void OnIdle(wxIdleEvent &aEvent)
Zoom the screen to fit the bounding box for cross probing/selection sync.
Schematic symbol object.
Definition sch_symbol.h:76
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
EDA_ITEM * Front() const
Definition selection.h:177
int Size() const
Returns the number of selected parts.
Definition selection.h:121
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
Class to handle modifications to the symbol libraries.
bool CreateLibrary(const wxString &aFilePath, LIBRARY_TABLE_SCOPE aScope)
Create an empty library and adds it to the library table.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:41
TOOL_MANAGER * m_toolManager
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:80
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
const char * c_str() const
Definition utf8.h:108
wxString wx_str() const
Definition utf8.cpp:45
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:558
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:259
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
#define _(s)
@ RECURSE
Definition eda_item.h:52
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:33
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:35
@ FRAME_SCH_VIEWER
Definition frame_type.h:36
@ FRAME_SCH
Definition frame_type.h:34
@ FRAME_SYMBOL_CHOOSER
Definition frame_type.h:37
static const std::string KiCadSymbolLibFileExtension
static wxString KiCadSymbolLibFileWildcard()
const wxChar *const traceLibWatch
Flag to enable debug output for library file watch refreshes.
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ LAYER_SCHEMATIC_GRID_AXES
Definition layer_ids.h:487
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
LIBRARY_TABLE_SCOPE
@ MAIL_REFRESH_SYMBOL
Definition mail_type.h:59
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
@ ALL
All except INITIAL_ADD.
Definition view_item.h:59
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:38
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
Declaration of the NL_SCHEMATIC_PLUGIN class.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIBRARY_ADAPTER *aLibMgr, LEGACY_SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIBRARY_ADAPTER *aLibMgr, LEGACY_SYMBOL_LIB *aCacheLib=nullptr, wxWindow *aParent=nullptr, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Class to handle a set of SCH_ITEMs.
T * GetAppSettings(const char *aFilename)
KIWAY Kiway(KFCTL_STANDALONE)
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > pinned_symbol_libs
@ ID_MAKE_NEW_LIBRARY
@ VALUE
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.
@ SCH_TABLE_T
Definition typeinfo.h:169
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_TABLECELL_T
Definition typeinfo.h:170
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_SHAPE_T
Definition typeinfo.h:153
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:195
@ SCH_SHEET_PIN_T
Definition typeinfo.h:178
@ SCH_TEXT_T
Definition typeinfo.h:155
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694