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>
27#include <kiway.h>
29#include <pgm_base.h>
30#include <eda_list_dialog.h>
33#include <eeschema_settings.h>
37#include <sch_draw_panel.h>
38#include <sch_group.h>
39#include <sch_view.h>
40#include <sch_painter.h>
41#include <sch_shape.h>
43#include <confirm.h>
45#include <project_sch.h>
46#include <symbol_library.h>
47#include <symbol_lib_table.h>
48#include <sch_base_frame.h>
50#include <design_block.h>
52#include <tool/actions.h>
53#include <tool/action_toolbar.h>
54#include <tool/tool_manager.h>
57#include <view/view_controls.h>
58#include <wx/choicdlg.h>
59#include <wx/fswatcher.h>
60#include <wx/log.h>
61#include <wx/msgdlg.h>
62
64#include <wx/fdrepdlg.h>
65
66
68 SYMBOL_LIB* aCacheLib, wxWindow* aParent, bool aShowErrorMsg )
69{
70 wxCHECK_MSG( aLibTable, nullptr, wxS( "Invalid symbol library table." ) );
71
72 LIB_SYMBOL* symbol = nullptr;
73
74 try
75 {
76 symbol = aLibTable->LoadSymbol( aLibId );
77
78 if( !symbol && aCacheLib )
79 {
80 wxCHECK_MSG( aCacheLib->IsCache(), nullptr, wxS( "Invalid cache library." ) );
81
82 wxString cacheName = aLibId.GetLibNickname().wx_str();
83 cacheName << "_" << aLibId.GetLibItemName();
84 symbol = aCacheLib->FindSymbol( cacheName );
85 }
86 }
87 catch( const IO_ERROR& ioe )
88 {
89 if( aShowErrorMsg )
90 {
91 wxString msg = wxString::Format( _( "Error loading symbol %s from library '%s'." ),
92 aLibId.GetLibItemName().wx_str(),
93 aLibId.GetLibNickname().wx_str() );
94 DisplayErrorMessage( aParent, msg, ioe.What() );
95 }
96 }
97
98 return symbol;
99}
100
101
102SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindowType,
103 const wxString& aTitle, const wxPoint& aPosition,
104 const wxSize& aSize, long aStyle, const wxString& aFrameName ) :
105 EDA_DRAW_FRAME( aKiway, aParent, aWindowType, aTitle, aPosition, aSize, aStyle,
106 aFrameName, schIUScale ),
107 m_selectionFilterPanel( nullptr ),
108 m_findReplaceDialog( nullptr ),
109 m_base_frame_defaults( nullptr, "base_Frame_defaults" ),
110 m_inSymChangeTimerEvent( false )
111{
112 m_findReplaceData = std::make_unique<SCH_SEARCH_DATA>();
113
114 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
115 createCanvas();
116
117 Bind( wxEVT_IDLE,
118 [this]( wxIdleEvent& aEvent )
119 {
120 // Handle cursor adjustments. While we can get motion and key events through
121 // wxWidgets, we can't get modifier-key-up events.
122 if( m_toolManager )
123 {
125
126 if( selTool )
127 selTool->OnIdle( aEvent );
128 }
129 } );
130
132}
133
134
137{}
138
139
141{
142 GetCanvas()->SetEvtHandlerEnabled( false );
144
145 // Shutdown all running tools
146 if( m_toolManager )
148
149 // Close the find dialog and preserve its setting if it is displayed.
151 {
154
155 m_findReplaceDialog->Destroy();
156 m_findReplaceDialog = nullptr;
157 }
158
159 // This class is pure virtual. Derived class will finish shutdown and Destroy().
160}
161
162
164{
166}
167
168
170{
171 return dynamic_cast<EESCHEMA_SETTINGS*>( config() );
172}
173
174
176{
177 return dynamic_cast<SYMBOL_EDITOR_SETTINGS*>( config() );
178}
179
180
182{
183 switch( GetFrameType() )
184 {
185 case FRAME_SCH:
186 default:
187 return GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
188
190 case FRAME_SCH_VIEWER:
192 return GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" );
193 }
194}
195
196
197void SCH_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
198{
199 GetScreen()->SetPageSettings( aPageSettings );
200}
201
202
204{
205 return GetScreen()->GetPageSettings();
206}
207
208
210{
211 // GetSizeIU is compile time dependent:
213}
214
215
217{
218 wxASSERT( GetScreen() );
219 return GetScreen()->GetTitleBlock();
220}
221
222
224{
225 wxASSERT( GetScreen() );
226 GetScreen()->SetTitleBlock( aTitleBlock );
227}
228
229
231{
232 wxString line;
233 BASE_SCREEN* screen = GetScreen();
234
235 if( !screen )
236 return;
237
239
240 // Display absolute and relative coordinates
242 VECTOR2D d = cursorPos - screen->m_LocalOrigin;
243
244 line.Printf( wxS( "X %s Y %s" ),
245 MessageTextFromValue( cursorPos.x, false ),
246 MessageTextFromValue( cursorPos.y, false ) );
247 SetStatusText( line, 2 );
248
249 line.Printf( wxS( "dx %s dy %s dist %s" ),
250 MessageTextFromValue( d.x, false ),
251 MessageTextFromValue( d.y, false ),
252 MessageTextFromValue( hypot( d.x, d.y ), false ) );
253 SetStatusText( line, 3 );
254
257}
258
259
260LIB_SYMBOL* SCH_BASE_FRAME::GetLibSymbol( const LIB_ID& aLibId, bool aUseCacheLib,
261 bool aShowErrorMsg )
262{
263 SYMBOL_LIB* cache =
264 ( aUseCacheLib ) ? PROJECT_SCH::SchLibs( &Prj() )->GetCacheLibrary() : nullptr;
265
266 return SchGetLibSymbol( aLibId, PROJECT_SCH::SchSymbolLibTable( &Prj() ), cache, this,
267 aShowErrorMsg );
268}
269
270
271bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject )
272{
273 wxString msg;
274 bool success = true;
275
276 if( aGlobal )
277 {
278 try
279 {
281 }
282 catch( const IO_ERROR& ioe )
283 {
284 success = false;
285 msg.Printf( _( "Error saving global symbol library table:\n%s" ), ioe.What() );
286 DisplayErrorMessage( this, msg );
287 }
288 }
289
290 if( aProject && !Prj().GetProjectName().IsEmpty() )
291 {
292 wxFileName fn( Prj().GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
293
294 try
295 {
296 PROJECT_SCH::SchSymbolLibTable( &Prj() )->Save( fn.GetFullPath() );
297 }
298 catch( const IO_ERROR& ioe )
299 {
300 success = false;
301 msg.Printf( _( "Error saving project-specific symbol library table:\n%s" ),
302 ioe.What() );
303 DisplayErrorMessage( this, msg );
304 }
305 }
306
307 return success;
308}
309
310
311void SCH_BASE_FRAME::RedrawScreen( const VECTOR2I& aCenterPoint, bool aWarpPointer )
312{
313 GetCanvas()->GetView()->SetCenter( aCenterPoint );
314
315 if( aWarpPointer )
317
318 GetCanvas()->Refresh();
319}
320
321
323{
324 if( GetCanvas() && GetCanvas()->GetView() )
325 {
328 }
329}
330
331
333{
334 return static_cast<SCH_DRAW_PANEL*>( EDA_DRAW_FRAME::GetCanvas() );
335}
336
337
339{
340 if( GetCanvas() && GetCanvas()->GetView() )
341 {
342 if( KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter() )
343 return static_cast<SCH_RENDER_SETTINGS*>( painter->GetSettings() );
344 }
345
346 return nullptr;
347}
348
349
351{
353
354 SetCanvas( new SCH_DRAW_PANEL( this, wxID_ANY, wxPoint( 0, 0 ), m_frameSize,
357}
358
359
361{
363
364 try
365 {
366 if( !m_spaceMouse )
367 m_spaceMouse = std::make_unique<NL_SCHEMATIC_PLUGIN>();
368
369 m_spaceMouse->SetCanvas( GetCanvas() );
370 }
371 catch( const std::system_error& e )
372 {
373 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
374 }
375}
376
377
378void SCH_BASE_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
379{
380 EDA_ITEM* parent = aItem->GetParent();
381
382 if( aItem->Type() == SCH_SHEET_PIN_T )
383 {
384 // Sheet pins aren't in the view. Refresh their parent.
385 if( parent )
386 GetCanvas()->GetView()->Update( parent );
387 }
388 else
389 {
390 if( aItem->Type() == SCH_SHAPE_T )
391 static_cast<SCH_SHAPE*>( aItem )->UpdateHatching();
392
393 if( !isAddOrDelete )
394 GetCanvas()->GetView()->Update( aItem );
395
396 // Some children are drawn from their parents. Mark them for re-paint.
397 if( parent && ( parent->Type() == SCH_SYMBOL_T
398 || parent->Type() == SCH_SHEET_T
399 || parent->Type() == SCH_LABEL_LOCATE_ANY_T
400 || parent->Type() == SCH_TABLE_T ) )
401 {
402 GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT );
403 }
404 }
405
406 /*
407 * Be careful when calling this. Update will invalidate RTree iterators, so you cannot
408 * call this while doing things like `for( SCH_ITEM* item : screen->Items() )`
409 */
410 if( aUpdateRtree && dynamic_cast<SCH_ITEM*>( aItem ) )
411 {
412 GetScreen()->Update( static_cast<SCH_ITEM*>( aItem ) );
413
414 /*
415 * If we are updating the group, we also need to update all the children otherwise
416 * their positions will remain stale in the RTree
417 */
418 if( SCH_GROUP* group = dynamic_cast<SCH_GROUP*>( aItem ) )
419 {
420 group->RunOnChildren(
421 [&]( SCH_ITEM* item )
422 {
423 GetScreen()->Update( item );
424 },
425 RECURSE_MODE::RECURSE );
426 }
427 }
428
429 // Calling Refresh() here introduces a bi-stable state: when doing operations on a
430 // large number of items if at some point the refresh timer times out and does a
431 // refresh it will take long enough that the next item will also time out, and the
432 // next, and the next, etc.
433 // GetCanvas()->Refresh();
434}
435
436
438{
439 // We currently have two zoom-dependent renderings: text, which is rendered as bitmap text
440 // when too small to see the difference, and selection shadows.
441 //
442 // Because non-selected text is cached by OpenGL, we only apply the bitmap performance hack
443 // to selected text items.
444 //
445 // Thus, as it currently stands, all zoom-dependent items can be found in the list of selected
446 // items.
447 if( m_toolManager )
448 {
450 SELECTION& selection = selectionTool->GetSelection();
451 KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
452
453 for( EDA_ITEM* item : selection )
454 {
455 if( item->RenderAsBitmap( view->GetGAL()->GetWorldScale() ) != item->IsShownAsBitmap()
457 {
458 view->Update( item, KIGFX::REPAINT );
459
460 EDA_ITEM* parent = item->GetParent();
461
462 // Symbol children are drawn from their parents. Mark them for re-paint.
463 if( parent && parent->Type() == SCH_SYMBOL_T )
464 GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT );
465 }
466 }
467 }
468}
469
470
472{
473 // Null pointers will cause boost::ptr_vector to raise a boost::bad_pointer exception which
474 // will be unhandled. There is no valid reason to pass an invalid EDA_ITEM pointer to the
475 // screen append function.
476 wxCHECK( aItem, /* void */ );
477
478 SCH_SCREEN* screen = aScreen;
479
480 if( aScreen == nullptr )
481 screen = GetScreen();
482
483 if( aItem->Type() != SCH_TABLECELL_T )
484 screen->Append( (SCH_ITEM*) aItem );
485
486 if( screen == GetScreen() )
487 {
488 GetCanvas()->GetView()->Add( aItem );
489 UpdateItem( aItem, true ); // handle any additional parent semantics
490 }
491}
492
493
495{
496 auto screen = aScreen;
497
498 if( aScreen == nullptr )
499 screen = GetScreen();
500
501 if( screen == GetScreen() )
502 GetCanvas()->GetView()->Remove( aItem );
503
504 if( aItem->Type() != SCH_TABLECELL_T )
505 screen->Remove( (SCH_ITEM*) aItem );
506
507 if( screen == GetScreen() )
508 UpdateItem( aItem, true ); // handle any additional parent semantics
509}
510
511
513{
514 // Let tools add things to the view if necessary
515 if( m_toolManager )
517
519}
520
521
523{
524 return GetColorSettings()->GetColor( aLayer );
525}
526
527
529{
530 wxString findString;
531
532 SCH_SELECTION& selection = m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
533
534 if( selection.Size() == 1 )
535 {
536 EDA_ITEM* front = selection.Front();
537
538 switch( front->Type() )
539 {
540 case SCH_SYMBOL_T:
541 {
542 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( front );
543 findString = UnescapeString( symbol->GetField( FIELD_T::VALUE )->GetText() );
544 break;
545 }
546
547 case SCH_FIELD_T:
548 findString = UnescapeString( static_cast<SCH_FIELD*>( front )->GetText() );
549 break;
550
551 case SCH_LABEL_T:
553 case SCH_HIER_LABEL_T:
554 case SCH_SHEET_PIN_T:
555 findString = UnescapeString( static_cast<SCH_LABEL_BASE*>( front )->GetText() );
556 break;
557
558 case SCH_TEXT_T:
559 findString = UnescapeString( static_cast<SCH_TEXT*>( front )->GetText() );
560
561 if( findString.Contains( wxT( "\n" ) ) )
562 findString = findString.Before( '\n' );
563
564 break;
565
566 default:
567 break;
568 }
569 }
570
572 m_findReplaceDialog->Destroy();
573
574 m_findReplaceDialog = new DIALOG_SCH_FIND( this, static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ),
575 wxDefaultPosition, wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
576
579 m_findReplaceDialog->Show( true );
580}
581
582
583void SCH_BASE_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
584{
585 // Prepare the infobar, since we don't know its state
588
589 m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
590}
591
592
594{
596}
597
598
600{
603
604 m_findReplaceDialog->Destroy();
605 m_findReplaceDialog = nullptr;
606
608}
609
610
612{
614
615 COLOR_SETTINGS* colorSettings = GetColorSettings( true );
616
617 GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colorSettings );
619
623}
624
625
627{
628 if( !m_colorSettings || aForceRefresh )
629 {
630 EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
631 wxString colorTheme = cfg ? cfg->m_ColorTheme : wxString( "" );
632
634 {
635 if( SYMBOL_EDITOR_SETTINGS* sym_edit_cfg = GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" ) )
636 {
637 if( !sym_edit_cfg->m_UseEeschemaColorSettings )
638 colorTheme = sym_edit_cfg->m_ColorTheme;
639 }
640 }
641
642 const_cast<SCH_BASE_FRAME*>( this )->m_colorSettings = ::GetColorSettings( colorTheme );
643 }
644
645 return m_colorSettings;
646}
647
648
650{
652}
653
654
655void SCH_BASE_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
656{
658
659 if( m_spaceMouse )
660 m_spaceMouse->SetFocus( aEvent.GetActive() );
661}
662
663
664void SCH_BASE_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
665{
667
668 if( m_spaceMouse )
669 m_spaceMouse->SetFocus( false );
670}
671
672
674 std::vector<wxArrayString>& aItemsToDisplay )
675{
679 std::vector<wxString> libNicknames = tbl->GetLogicalLibs();
680
681 aHeaders.Add( _( "Library" ) );
682 aHeaders.Add( _( "Description" ) );
683
684 for( const wxString& nickname : libNicknames )
685 {
686 if( alg::contains( project.m_PinnedSymbolLibs, nickname )
687 || alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
688 {
689 wxArrayString item;
690
691 item.Add( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
692 item.Add( tbl->GetDescription( nickname ) );
693 aItemsToDisplay.push_back( item );
694 }
695 }
696
697 for( const wxString& nickname : libNicknames )
698 {
699 if( !alg::contains( project.m_PinnedSymbolLibs, nickname )
700 && !alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) )
701 {
702 wxArrayString item;
703
704 item.Add( nickname );
705 item.Add( tbl->GetDescription( nickname ) );
706 aItemsToDisplay.push_back( item );
707 }
708 }
709}
710
711
712wxString SCH_BASE_FRAME::SelectLibrary( const wxString& aDialogTitle, const wxString& aListLabel,
713 const std::vector<std::pair<wxString, bool*>>& aExtraCheckboxes )
714{
715 static const int ID_MAKE_NEW_LIBRARY = wxID_HIGHEST;
716
717 // Keep asking the user for a new name until they give a valid one or cancel the operation
718 while( true )
719 {
720 wxArrayString headers;
721 std::vector<wxArrayString> itemsToDisplay;
722
723 GetLibraryItemsForListDialog( headers, itemsToDisplay );
724
725 wxString libraryName = Prj().GetRString( PROJECT::SCH_LIB_SELECT );
726
727 EDA_LIST_DIALOG dlg( this, aDialogTitle, headers, itemsToDisplay, libraryName, false, aExtraCheckboxes );
728 dlg.SetListLabel( aListLabel );
729
730 wxButton* newLibraryButton = new wxButton( &dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
731 dlg.m_ButtonsSizer->Prepend( 80, 20 );
732 dlg.m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
733
734 newLibraryButton->Bind( wxEVT_BUTTON,
735 [&dlg]( wxCommandEvent& )
736 {
737 dlg.EndModal( ID_MAKE_NEW_LIBRARY );
739
740 dlg.Layout();
741 dlg.GetSizer()->Fit( &dlg );
742
743 int ret = dlg.ShowModal();
744
745 switch( ret )
746 {
747 case wxID_CANCEL:
748 return wxEmptyString;
749
750 case wxID_OK:
751 libraryName = dlg.GetTextSelection();
752 Prj().SetRString( PROJECT::SCH_LIB_SELECT, libraryName );
754 return libraryName;
755
757 {
758 SYMBOL_LIBRARY_MANAGER mgr( *this );
759 wxFileName fn( Prj().GetRString( PROJECT::SCH_LIB_PATH ) );
760 bool useGlobalTable = false;
761 FILEDLG_HOOK_NEW_LIBRARY tableChooser( useGlobalTable );
762
763 if( !LibraryFileBrowser( _( "Create New Library" ), false, fn, FILEEXT::KiCadSymbolLibFileWildcard(),
764 FILEEXT::KiCadSymbolLibFileExtension, false, &tableChooser ) )
765 {
766 break;
767 }
768
769 libraryName = fn.GetName();
770 Prj().SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
771
772 useGlobalTable = tableChooser.GetUseGlobalTable();
773
774 SYMBOL_LIB_TABLE* libTable = useGlobalTable ? &SYMBOL_LIB_TABLE::GetGlobalLibTable()
776
777 if( libTable->HasLibrary( libraryName, false ) )
778 {
779 DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libraryName ) );
780 break;
781 }
782
783 if( !mgr.CreateLibrary( fn.GetFullPath(), *libTable ) )
784 DisplayError( this, wxString::Format( _( "Could not add library '%s'." ), libraryName ) );
785
786 break;
787 }
788
789 default:
790 break;
791 }
792 }
793}
794
795
797{
798 Unbind( wxEVT_FSWATCHER, &SCH_BASE_FRAME::OnSymChange, this );
799
800 if( m_watcher )
801 {
802 wxLogTrace( "KICAD_LIB_WATCH", "Remove watch" );
803 m_watcher->RemoveAll();
804 m_watcher->SetOwner( nullptr );
805 m_watcher.reset();
806 }
807
808 wxString libfullname;
810
811 if( !aID || !tbl )
812 return;
813
814 try
815 {
816 const SYMBOL_LIB_TABLE_ROW* row = tbl->FindRow( aID->GetLibNickname() );
817
818 if( !row )
819 return;
820
821 libfullname = row->GetFullURI( true );
822 }
823 catch( const std::exception& e )
824 {
825 DisplayInfoMessage( this, e.what() );
826 return;
827 }
828 catch( const IO_ERROR& error )
829 {
830 wxLogTrace( "KICAD_LIB_WATCH", "Error: %s", error.What() );
831 return;
832 }
833
834 wxLogTrace( "KICAD_LIB_WATCH", "Setting up watcher for %s", libfullname );
835 m_watcherFileName.Assign( libfullname );
836
837 if( !m_watcherFileName.FileExists() )
838 return;
839
840 wxLog::EnableLogging( false );
841 m_watcherLastModified = m_watcherFileName.GetModificationTime();
842 wxLog::EnableLogging( true );
843
844 Bind( wxEVT_FSWATCHER, &SCH_BASE_FRAME::OnSymChange, this );
845 m_watcher = std::make_unique<wxFileSystemWatcher>();
846 m_watcher->SetOwner( this );
847
848 wxFileName fn;
849 fn.AssignDir( m_watcherFileName.GetPath() );
850 fn.DontFollowLink();
851
852 {
853 // Silence OS errors that come from the watcher
854 wxLogNull silence;
855 m_watcher->Add( fn );
856 }
857}
858
859
860void SCH_BASE_FRAME::OnSymChange( wxFileSystemWatcherEvent& aEvent )
861{
863
864 wxLogTrace( "KICAD_LIB_WATCH", "OnSymChange: %s, watcher file: %s",
865 aEvent.GetPath().GetFullPath(), m_watcherFileName.GetFullPath() );
866
867 if( !libs || !m_watcher || !m_watcher.get() || m_watcherFileName.GetPath().IsEmpty() )
868 return;
869
870 if( aEvent.GetPath() != m_watcherFileName )
871 return;
872
873 // Start the debounce timer (set to 1 second)
874 if( !m_watcherDebounceTimer.StartOnce( 1000 ) )
875 {
876 wxLogTrace( "KICAD_LIB_WATCH", "Failed to start the debounce timer" );
877 return;
878 }
879}
880
881
883{
884 if( aEvent.GetId() != m_watcherDebounceTimer.GetId() )
885 {
886 aEvent.Skip();
887 return;
888 }
889
891 {
892 wxLogTrace( "KICAD_LIB_WATCH", "Restarting debounce timer" );
893 m_watcherDebounceTimer.StartOnce( 3000 );
894 }
895
896 wxLogTrace( "KICAD_LIB_WATCH", "OnSymChangeDebounceTimer" );
897
898 // Disable logging to avoid spurious messages and check if the file has changed
899 wxLog::EnableLogging( false );
900 wxDateTime lastModified = m_watcherFileName.GetModificationTime();
901 wxLog::EnableLogging( true );
902
903 if( lastModified == m_watcherLastModified || !lastModified.IsValid() )
904 return;
905
906 m_watcherLastModified = lastModified;
907
909
911 || IsOK( this, _( "The library containing the current symbol has changed.\n"
912 "Do you want to reload the library?" ) ) )
913 {
914 wxLogTrace( "KICAD_LIB_WATCH", "Sending refresh symbol mail" );
915 std::string libName = m_watcherFileName.GetFullPath().ToStdString();
918 }
919
921}
922
923
925{
926 if( m_toolManager )
928
929 return nullptr;
930}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
static TOOL_ACTION updateFind
Definition: actions.h:123
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:236
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
wxArrayString GetFindEntries() const
wxArrayString GetReplaceEntries() const
void SetReplaceEntries(const wxArrayString &aEntries)
void SetFindEntries(const wxArrayString &aEntries, const wxString &aFindString)
bool Show(bool show) override
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
The base class for create windows for drawing purpose.
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)
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:98
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
EDA_ITEM * GetParent() const
Definition: eda_item.h:112
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 GetExtraCheckboxValues()
Fills in the value pointers from the checkboxes after the dialog has run.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
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
Definition: sch_painter.h:147
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:298
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:341
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:202
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1451
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1561
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:220
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:596
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:639
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:286
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
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:85
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...
const wxString GetDescription(const wxString &aNickname)
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
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:59
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:171
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:565
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:68
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
static SYMBOL_LIBS * SchLibs(PROJECT *aProject)
These are all prefaced with "Sch".
Definition: project_sch.cpp:90
@ SCH_LIB_SELECT
Definition: project.h:221
@ SCH_LIB_PATH
Definition: project.h:220
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:204
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:321
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:332
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
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 HardRedraw() override
Rebuild the GAL and redraws the screen.
DIALOG_SCH_FIND * m_findReplaceDialog
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.
bool m_inSymChangeTimerEvent
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
bool saveSymbolLibTables(bool aGlobal, bool aProject)
Save Symbol Library Tables to disk.
void RefreshZoomDependentItems()
Mark selected items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock) override
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.
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:139
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:165
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:160
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:140
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:163
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:323
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:75
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:760
EDA_ITEM * Front() const
Definition: selection.h:177
int Size() const
Returns the number of selected parts.
Definition: selection.h:121
Class to handle modifications to the symbol libraries.
bool CreateLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE &aTable)
Create an empty library and adds it to the library table.
A collection of SYMBOL_LIB objects.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString GetSymbolLibTableFileName()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
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...
Object used to load, save, search, and otherwise manipulate symbol library files.
bool IsCache() const
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
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
Definition: tools_holder.h:171
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString wx_str() const
Definition: utf8.cpp:45
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:371
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
Definition: wx_infobar.cpp:142
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:192
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:361
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:251
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:222
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
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 _(s)
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()
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:439
@ LAYER_SCHEMATIC_GRID_AXES
Definition: layer_ids.h:477
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:478
@ 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.
Definition: pgm_base.cpp:902
see class PGM_BASE
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, SYMBOL_LIB *aCacheLib=nullptr, wxWindow *aParent=nullptr, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Class to handle a set of SCH_ITEMs.
KIWAY Kiway(KFCTL_STANDALONE)
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > pinned_symbol_libs
const double IU_PER_MILS
Definition: base_units.h:77
@ ID_MAKE_NEW_LIBRARY
Definition for symbol library class.
@ SCH_TABLE_T
Definition: typeinfo.h:166
@ SCH_SYMBOL_T
Definition: typeinfo.h:173
@ SCH_TABLECELL_T
Definition: typeinfo.h:167
@ SCH_FIELD_T
Definition: typeinfo.h:151
@ SCH_LABEL_T
Definition: typeinfo.h:168
@ SCH_SHEET_T
Definition: typeinfo.h:176
@ SCH_SHAPE_T
Definition: typeinfo.h:150
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:170
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:192
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:175
@ SCH_TEXT_T
Definition: typeinfo.h:152
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:169