KiCad PCB EDA Suite
eda_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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2022 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 <bitmap_store.h>
28#include <dialog_shim.h>
32#include <eda_dde.h>
33#include <file_history.h>
34#include <id.h>
35#include <kiface_base.h>
36#include <menus_helpers.h>
37#include <hotkeys_basic.h>
39#include <paths.h>
40#include <confirm.h>
41#include <panel_pcm_settings.h>
42#include <pgm_base.h>
47#include <tool/action_manager.h>
48#include <tool/action_menu.h>
49#include <tool/action_toolbar.h>
50#include <tool/actions.h>
51#include <tool/common_control.h>
52#include <tool/tool_manager.h>
54#include <trace_helpers.h>
56#include <widgets/wx_infobar.h>
58#include <wx/app.h>
59#include <wx/config.h>
60#include <wx/display.h>
61#include <wx/stdpaths.h>
62#include <wx/string.h>
63#include <wx/treebook.h>
64#include <kiplatform/app.h>
65#include <kiplatform/ui.h>
66
67#include <functional>
68#include <kiface_ids.h>
69
70wxDEFINE_EVENT( UNITS_CHANGED, wxCommandEvent );
71
72
73// Minimum window size
74static const wxSize minSize( FRAME_T aFrameType )
75{
76 switch( aFrameType )
77 {
79 return wxSize( 406, 354 );
80
81 default:
82 return wxSize( 500, 400 );
83 }
84}
85
86
87static const wxSize defaultSize( FRAME_T aFrameType )
88{
89 switch( aFrameType )
90 {
92 return wxSize( 850, 540 );
93
94 default:
95 return wxSize( 1280, 720 );
96 }
97}
98
99
100BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
101 EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
102 EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
103
104 EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
105 EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
106 EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
107 EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
108 EVT_MOVE( EDA_BASE_FRAME::OnMove )
109 EVT_SIZE( EDA_BASE_FRAME::OnSize )
110 EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
111
112 EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
113 EVT_ICONIZE( EDA_BASE_FRAME::onIconize )
114END_EVENT_TABLE()
115
116
117void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
118{
119 m_ident = aFrameType;
120 m_maximizeByDefault = false;
121 m_infoBar = nullptr;
122 m_settingsManager = nullptr;
123 m_fileHistory = nullptr;
124 m_supportsAutoSave = false;
125 m_autoSavePending = false;
126 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
127 m_isClosing = false;
128 m_isNonUserClose = false;
129 m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
130 m_autoSaveRequired = false;
132 m_frameSize = defaultSize( aFrameType );
133 m_displayIndex = -1;
134
135 m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
136
137 m_settingsManager = &Pgm().GetSettingsManager();
138
139 // Set a reasonable minimal size for the frame
140 SetSizeHints( minSize( aFrameType ).x, minSize( aFrameType ).y, -1, -1, -1, -1 );
141
142 // Store dimensions of the user area of the main window.
143 GetClientSize( &m_frameSize.x, &m_frameSize.y );
144
145 Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
146 wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
147
148 // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
149 // to be called before any other hook for wxCloseEvent, which is necessary.
150 Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
151
152 initExitKey();
153}
154
155
156EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
157 const wxPoint& aPos, const wxSize& aSize, long aStyle,
158 const wxString& aFrameName, KIWAY* aKiway,
159 const EDA_IU_SCALE& aIuScale ) :
160 wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
161 TOOLS_HOLDER(),
162 KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
164{
165 commonInit( aFrameType );
166}
167
168
170{
171 for( wxWindow* iter : GetChildren() )
172 {
173 DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
174
175 if( dlg && dlg->IsQuasiModal() )
176 return dlg;
177 }
178
179 // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
180 // so we have to look for it separately.
181 if( m_ident == FRAME_SCH )
182 {
183 wxWindow* cvpcb = wxWindow::FindWindowByName( wxS( "CvpcbFrame" ) );
184
185 if( cvpcb )
186 return cvpcb;
187 }
188
189 return nullptr;
190}
191
192
193void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
194{
195 // Don't allow closing when a quasi-modal is open.
196 wxWindow* quasiModal = findQuasiModalDialog();
197
198 if( quasiModal )
199 {
200 // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
201 // when they have no idea what those are.
202 quasiModal->Raise();
203 wxBell();
204
205 if( event.CanVeto() )
206 event.Veto();
207
208 return;
209 }
210
211
212 if( event.GetId() == wxEVT_QUERY_END_SESSION
213 || event.GetId() == wxEVT_END_SESSION )
214 {
215 // End session means the OS is going to terminate us
216 m_isNonUserClose = true;
217 }
218
219 if( canCloseWindow( event ) )
220 {
221 m_isClosing = true;
222 APP_SETTINGS_BASE* cfg = config();
223
224 if( cfg )
225 SaveSettings( cfg ); // virtual, wxFrame specific
226
228
229 // Destroy (safe delete frame) this frame only in non modal mode.
230 // In modal mode, the caller will call Destroy().
231 if( !IsModal() )
232 Destroy();
233 }
234 else
235 {
236 if( event.CanVeto() )
237 event.Veto();
238 }
239}
240
241
243{
244 delete m_autoSaveTimer;
245 delete m_fileHistory;
246
248
250
252}
253
254
255bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
256{
257#ifdef __WXMAC__
258 // Apple in its infinite wisdom will raise a disabled window before even passing
259 // us the event, so we have no way to stop it. Instead, we have to catch an
260 // improperly ordered disabled window and quasi-modal dialog here and reorder
261 // them.
262 if( !IsEnabled() && IsActive() )
263 {
264 wxWindow* dlg = findQuasiModalDialog();
265 if( dlg )
266 dlg->Raise();
267 }
268#endif
269
270 if( !wxFrame::ProcessEvent( aEvent ) )
271 return false;
272
273 if( Pgm().m_Quitting )
274 return true;
275
276 if( !m_isClosing && m_supportsAutoSave && IsShown() && IsActive()
278 && GetAutoSaveInterval() > 0 )
279 {
280 if( !m_autoSavePending )
281 {
282 wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
283 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
284 m_autoSavePending = true;
285 }
286 else if( m_autoSaveTimer->IsRunning() )
287 {
288 wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
289 m_autoSaveTimer->Stop();
290 m_autoSavePending = false;
291 }
292 }
293
294 return true;
295}
296
297
299{
300 return Pgm().GetCommonSettings()->m_System.autosave_interval;
301}
302
303
304void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
305{
306 // Don't stomp on someone else's timer event.
307 if( aEvent.GetId() != ID_AUTO_SAVE_TIMER )
308 {
309 aEvent.Skip();
310 return;
311 }
312
313 if( !doAutoSave() )
314 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
315}
316
317
319{
320 wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
321}
322
323
324void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
325{
326 wxLogTrace( kicadTraceKeyEvent, wxS( "EDA_BASE_FRAME::OnCharHook %s" ), dump( aKeyEvent ) );
327
328 // Key events can be filtered here.
329 // Currently no filtering is made.
330 aKeyEvent.Skip();
331}
332
333
334void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
335{
336 if( !m_toolDispatcher )
337 aEvent.Skip();
338 else
340}
341
342
344{
346 std::placeholders::_1,
347 this,
348 aConditions );
349
350 m_uiUpdateMap[aID] = evtFunc;
351
352 Bind( wxEVT_UPDATE_UI, evtFunc, aID );
353}
354
355
357{
358 const auto it = m_uiUpdateMap.find( aID );
359
360 if( it == m_uiUpdateMap.end() )
361 return;
362
363 Unbind( wxEVT_UPDATE_UI, it->second, aID );
364}
365
366
367void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
368 ACTION_CONDITIONS aCond )
369{
370 bool checkRes = false;
371 bool enableRes = true;
372 bool showRes = true;
373 bool isCut = aEvent.GetId() == ACTIONS::cut.GetUIId();
374 bool isCopy = aEvent.GetId() == ACTIONS::copy.GetUIId();
375 bool isPaste = aEvent.GetId() == ACTIONS::paste.GetUIId();
376 SELECTION& selection = aFrame->GetCurrentSelection();
377
378 try
379 {
380 checkRes = aCond.checkCondition( selection );
381 enableRes = aCond.enableCondition( selection );
382 showRes = aCond.showCondition( selection );
383 }
384 catch( std::exception& )
385 {
386 // Something broke with the conditions, just skip the event.
387 aEvent.Skip();
388 return;
389 }
390
391 if( isCut || isCopy || isPaste )
392 {
393 wxWindow* focus = wxWindow::FindFocus();
394 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
395
396 if( textEntry && isCut && textEntry->CanCut() )
397 enableRes = true;
398 else if( textEntry && isCopy && textEntry->CanCopy() )
399 enableRes = true;
400 else if( textEntry && isPaste && textEntry->CanPaste() )
401 enableRes = true;
402 }
403
404 aEvent.Enable( enableRes );
405 aEvent.Show( showRes );
406
407 // wxWidgets 3.1.5+ includes a field in the event that says if the event supports being
408 // checked, since wxMenuItems don't want to be checked unless they actually are checkable
409#if wxCHECK_VERSION( 3, 1, 5 )
410 if( aEvent.IsCheckable() )
411 aEvent.Check( checkRes );
412#else
413 bool canCheck = true;
414
415 // wxMenuItems don't want to be checked unless they actually are checkable, so we have to
416 // check to see if they can be and can't just universally apply a check in this event.
417 if( wxMenu* menu = dynamic_cast<wxMenu*>( aEvent.GetEventObject() ) )
418 canCheck = menu->FindItem( aEvent.GetId() )->IsCheckable();
419
420 if( canCheck )
421 aEvent.Check( checkRes );
422#endif
423}
424
425
427{
428 // Setup the conditions to check a language menu item
429 auto isCurrentLang =
430 [] ( const SELECTION& aSel, int aLangIdentifier )
431 {
432 return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
433 };
434
435 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
436 {
438 cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
439 LanguagesList[ii].m_WX_Lang_Identifier ) );
440
441 RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
442 }
443}
444
445
447{
455 CallAfter( [=]()
456 {
458 } );
459}
460
461
462void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
463{
465 ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
466
467 helpMenu->Add( ACTIONS::help );
468 helpMenu->Add( ACTIONS::gettingStarted );
469 helpMenu->Add( ACTIONS::listHotKeys );
470 helpMenu->Add( ACTIONS::getInvolved );
471 helpMenu->Add( ACTIONS::donate );
472 helpMenu->Add( ACTIONS::reportBug );
473
474 helpMenu->AppendSeparator();
475 helpMenu->Add( _( "&About KiCad" ), "", wxID_ABOUT, BITMAPS::about );
476
477 // Trailing space keeps OSX from hijacking our menu (and disabling everything in it).
478 aMenuBar->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
479}
480
481
483{
485
486 if( GetMenuBar() )
487 {
489 GetMenuBar()->Refresh();
490 }
491}
492
493
494void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
495{
496 TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
497
498 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
499
500 if( m_fileHistory )
501 {
502 int historySize = settings->m_System.file_history_size;
503 m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
504 }
505
507 ThemeChanged();
508
509 if( GetMenuBar() )
510 {
511 // For icons in menus, icon scaling & hotkeys
513 GetMenuBar()->Refresh();
514 }
515}
516
517
519{
521
522 // Update all the toolbars to have new icons
523 wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
524
525 for( size_t i = 0; i < panes.GetCount(); ++i )
526 {
527 if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
528 toolbar->RefreshBitmaps();
529 }
530}
531
532
533void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
534{
535#ifdef __WXMAC__
536 int currentDisplay = wxDisplay::GetFromWindow( this );
537
538 if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
539 {
540 wxLogTrace( traceDisplayLocation, wxS( "OnSize: current display changed %d to %d" ),
541 m_displayIndex, currentDisplay );
542 m_displayIndex = currentDisplay;
544 }
545#endif
546
547 aEvent.Skip();
548}
549
550
551void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
552{
553 if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
554 return;
555
556 const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
557
558 if( state != nullptr )
559 {
560 LoadWindowState( state->window );
561 }
562}
563
564
566{
567 bool wasDefault = false;
568
569 m_framePos.x = aState.pos_x;
570 m_framePos.y = aState.pos_y;
571 m_frameSize.x = aState.size_x;
572 m_frameSize.y = aState.size_y;
573
574 wxLogTrace( traceDisplayLocation, wxS( "Config position (%d, %d) with size (%d, %d)" ),
576
577 // Ensure minimum size is set if the stored config was zero-initialized
578 if( m_frameSize.x < minSize( m_ident ).x || m_frameSize.y < minSize( m_ident ).y )
579 {
581 wasDefault = true;
582
583 wxLogTrace( traceDisplayLocation, wxS( "Using minimum size (%d, %d)" ),
585 }
586
587 wxLogTrace( traceDisplayLocation, wxS( "Number of displays: %d" ), wxDisplay::GetCount() );
588
589 if( aState.display >= wxDisplay::GetCount() )
590 {
591 wxLogTrace( traceDisplayLocation, wxS( "Previous display not found" ) );
592
593 // If it isn't attached, use the first display
594 // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
595 const unsigned int index = 0;
596 wxDisplay display( index );
597 wxRect clientSize = display.GetGeometry();
598
599 m_framePos = wxDefaultPosition;
600
601 // Ensure the window fits on the display, since the other one could have been larger
602 if( m_frameSize.x > clientSize.width )
603 m_frameSize.x = clientSize.width;
604
605 if( m_frameSize.y > clientSize.height )
606 m_frameSize.y = clientSize.height;
607 }
608 else
609 {
610 wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
611 wxPoint upperLeft( m_framePos.x, m_framePos.y );
612
613 wxDisplay display( aState.display );
614 wxRect clientSize = display.GetClientArea();
615
616 int yLimTop = clientSize.y;
617 int yLimBottom = clientSize.y + clientSize.height;
618 int xLimLeft = clientSize.x;
619 int xLimRight = clientSize.x + clientSize.width;
620
621 if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
622 upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
623 upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
624 upperLeft.y > yLimBottom )
625 {
626 m_framePos = wxDefaultPosition;
627 wxLogTrace( traceDisplayLocation, wxS( "Resetting to default position" ) );
628 }
629 }
630
631 wxLogTrace( traceDisplayLocation, wxS( "Final window position (%d, %d) with size (%d, %d)" ),
633
634 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
635
636 // Center the window if we reset to default
637 if( m_framePos.x == -1 )
638 {
639 wxLogTrace( traceDisplayLocation, wxS( "Centering window" ) );
640 Center();
641 m_framePos = GetPosition();
642 }
643
644 // Record the frame sizes in an un-maximized state
647
648 // Maximize if we were maximized before
649 if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
650 {
651 wxLogTrace( traceDisplayLocation, wxS( "Maximizing window" ) );
652 Maximize();
653 }
654
655 m_displayIndex = wxDisplay::GetFromWindow( this );
656}
657
658
660{
661 wxDisplay display( wxDisplay::GetFromWindow( this ) );
662 wxRect clientSize = display.GetClientArea();
663 wxPoint pos = GetPosition();
664 wxSize size = GetWindowSize();
665
666 wxLogTrace( traceDisplayLocation,
667 wxS( "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d" ), clientSize.x, clientSize.y,
668 clientSize.width, clientSize.height );
669
670 if( pos.y < clientSize.y )
671 {
672 wxLogTrace( traceDisplayLocation,
673 wxS( "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d" ), pos.y,
674 clientSize.y );
675 pos.y = clientSize.y;
676 }
677
678 if( pos.x < clientSize.x )
679 {
680 wxLogTrace( traceDisplayLocation,
681 wxS( "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d" ), pos.x,
682 clientSize.x );
683 pos.x = clientSize.x;
684 }
685
686 if( pos.x + size.x - clientSize.x > clientSize.width )
687 {
688 int newWidth = clientSize.width - ( pos.x - clientSize.x );
689 wxLogTrace( traceDisplayLocation,
690 wxS( "ensureWindowIsOnScreen: effective width %d above available %d, setting to %d" ),
691 pos.x + size.x, clientSize.width, newWidth );
692 size.x = newWidth;
693 }
694
695 if( pos.y + size.y - clientSize.y > clientSize.height )
696 {
697 int newHeight = clientSize.height - ( pos.y - clientSize.y );
698 wxLogTrace( traceDisplayLocation,
699 wxS( "ensureWindowIsOnScreen: effective height %d above available %d, setting to %d" ),
700 pos.y + size.y, clientSize.height, newHeight );
701 size.y = newHeight;
702 }
703
704 wxLogTrace( traceDisplayLocation, wxS( "Updating window position (%d, %d) with size (%d, %d)" ),
705 pos.x, pos.y, size.x, size.y );
706
707 SetSize( pos.x, pos.y, size.x, size.y );
708}
709
710
712{
713 LoadWindowState( aCfg->state );
714
716 m_mruPath = aCfg->mru_path;
717
719}
720
721
723{
724 if( IsIconized() )
725 return;
726
727 // If the window is maximized, we use the saved window size from before it was maximized
728 if( IsMaximized() )
729 {
732 }
733 else
734 {
736 m_framePos = GetPosition();
737 }
738
739 aCfg->state.pos_x = m_framePos.x;
740 aCfg->state.pos_y = m_framePos.y;
741 aCfg->state.size_x = m_frameSize.x;
742 aCfg->state.size_y = m_frameSize.y;
743 aCfg->state.maximized = IsMaximized();
744 aCfg->state.display = wxDisplay::GetFromWindow( this );
745
746 wxLogTrace( traceDisplayLocation, wxS( "Saving window maximized: %s" ),
747 IsMaximized() ? wxS( "true" ) : wxS( "false" ) );
748 wxLogTrace( traceDisplayLocation, wxS( "Saving config position (%d, %d) with size (%d, %d)" ),
750
751 // Once this is fully implemented, wxAuiManager will be used to maintain
752 // the persistence of the main frame and all it's managed windows and
753 // all of the legacy frame persistence position code can be removed.
754 aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
755
756 aCfg->mru_path = m_mruPath;
757}
758
759
761{
763
764 // Get file history size from common settings
765 int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
766
767 // Load the recently used files into the history menu
768 m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ),
770 m_fileHistory->Load( *aCfg );
771}
772
773
775{
776 wxCHECK( config(), /* void */ );
777
779
780 bool fileOpen = m_isClosing && m_isNonUserClose;
781
782 wxString currentlyOpenedFile = GetCurrentFileName();
783
784 if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
785 {
786 wxFileName rfn( currentlyOpenedFile );
787 rfn.MakeRelativeTo( Prj().GetProjectPath() );
788 Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
789 }
790
791 // Save the recently used files list
792 if( m_fileHistory )
793 {
794 // Save the currently opened file in the file history
795 if( !currentlyOpenedFile.IsEmpty() )
796 UpdateFileHistory( currentlyOpenedFile );
797
798 m_fileHistory->Save( *aCfg );
799 }
800}
801
802
804{
805 return &aCfg->m_Window;
806}
807
808
810{
811 // KICAD_MANAGER_FRAME overrides this
812 return Kiface().KifaceSettings();
813}
814
815
817{
818 return Kiface().KifaceSearch();
819}
820
821
823{
824 return Kiface().GetHelpFileName();
825}
826
827
828void EDA_BASE_FRAME::PrintMsg( const wxString& text )
829{
830 SetStatusText( text );
831}
832
833
835{
836#if defined( __WXOSX_MAC__ )
838#else
839 m_infoBar = new WX_INFOBAR( this, &m_auimgr );
840
841 m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) ).Top().Layer(1) );
842#endif
843}
844
845
847{
848#if defined( __WXOSX_MAC__ )
849 m_auimgr.Update();
850#else
851 // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
852 // hiding it.
853 m_auimgr.Update();
854
855 // We don't want the infobar displayed right away
856 m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
857 m_auimgr.Update();
858#endif
859}
860
861
862void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
864{
866
867 if( aShowCloseButton )
869
870 GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
871}
872
873
874void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
875 std::function<void(void)> aCallback )
876{
878
879 if( aShowCloseButton )
881
882 if( aCallback )
883 m_infoBar->SetCallback( aCallback );
884
885 GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
886}
887
888
889void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
890{
892
893 if( aShowCloseButton )
895
896 GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
897}
898
899
900void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
901{
903
904 if( aShowCloseButton )
906
907 GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
908}
909
910
911void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
912{
913 if( !aFileHistory )
914 aFileHistory = m_fileHistory;
915
916 wxASSERT( aFileHistory );
917
918 aFileHistory->AddFileToHistory( FullFileName );
919
920 // Update the menubar to update the file history menu
921 if( !m_isClosing && GetMenuBar() )
922 {
924 GetMenuBar()->Refresh();
925 }
926}
927
928
929wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
930 FILE_HISTORY* aFileHistory )
931{
932 if( !aFileHistory )
933 aFileHistory = m_fileHistory;
934
935 wxASSERT( aFileHistory );
936
937 int baseId = aFileHistory->GetBaseId();
938
939 wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
940
941 unsigned i = cmdId - baseId;
942
943 if( i < aFileHistory->GetCount() )
944 {
945 wxString fn = aFileHistory->GetHistoryFile( i );
946
947 if( wxFileName::FileExists( fn ) )
948 {
949 return fn;
950 }
951 else
952 {
953 DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
954 aFileHistory->RemoveFileFromHistory( i );
955 }
956 }
957
958 // Update the menubar to update the file history menu
959 if( GetMenuBar() )
960 {
962 GetMenuBar()->Refresh();
963 }
964
965 return wxEmptyString;
966}
967
968
970{
971 if( !aFileHistory )
972 aFileHistory = m_fileHistory;
973
974 wxASSERT( aFileHistory );
975
976 aFileHistory->ClearFileHistory();
977
978 // Update the menubar to update the file history menu
979 if( GetMenuBar() )
980 {
982 GetMenuBar()->Refresh();
983 }
984}
985
986
987void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
988{
989 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
990 ShowAboutDialog( this );
991}
992
993
994void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
995{
996 ShowPreferences( wxEmptyString, wxEmptyString );
997}
998
999
1000void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParentPage )
1001{
1002 wxBeginBusyCursor( wxHOURGLASS_CURSOR );
1003
1004 PAGED_DIALOG dlg( this, _( "Preferences" ), true );
1005
1006 dlg.SetEvtHandlerEnabled( false );
1007 wxTreebook* book = dlg.GetTreebook();
1008
1009 PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
1010 KIFACE* kiface = nullptr;
1011 std::vector<int> expand;
1012
1013 Kiway().GetActions( hotkeysPanel->ActionsList() );
1014
1015 book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) );
1016 book->AddPage( new PANEL_MOUSE_SETTINGS( &dlg, book ), _( "Mouse and Touchpad" ) );
1017 book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
1018
1019#ifdef KICAD_USE_SENTRY
1020 book->AddPage( new PANEL_DATA_COLLECTION( &dlg, book ), _( "Data Collection" ) );
1021#endif
1022
1023#define CREATE_PANEL( key ) kiface->CreateKiWindow( book, key, &Kiway() )
1024
1025 // If a dll is not loaded, the loader will show an error message.
1026
1027 try
1028 {
1030
1031 kiface->GetActions( hotkeysPanel->ActionsList() );
1032
1034 expand.push_back( book->GetPageCount() );
1035
1036 book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
1037 book->AddSubPage( CREATE_PANEL( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
1038 book->AddSubPage( CREATE_PANEL( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
1039 book->AddSubPage( CREATE_PANEL( PANEL_SYM_COLORS ), _( "Colors" ) );
1040
1041 if( GetFrameType() == FRAME_SCH )
1042 expand.push_back( book->GetPageCount() );
1043
1044 book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
1045 book->AddSubPage( CREATE_PANEL( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
1046 book->AddSubPage( CREATE_PANEL( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
1047 book->AddSubPage( CREATE_PANEL( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) );
1048 book->AddSubPage( CREATE_PANEL( PANEL_SCH_COLORS ), _( "Colors" ) );
1049 book->AddSubPage( CREATE_PANEL( PANEL_SCH_FIELD_NAME_TEMPLATES ),
1050 _( "Field Name Templates" ) );
1051 }
1052 catch( ... )
1053 {
1054 }
1055
1056 try
1057 {
1059
1060 kiface->GetActions( hotkeysPanel->ActionsList() );
1061
1063 expand.push_back( book->GetPageCount() );
1064
1065 book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
1066 book->AddSubPage( CREATE_PANEL( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
1067 book->AddSubPage( CREATE_PANEL( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
1068 book->AddSubPage( CREATE_PANEL( PANEL_FP_COLORS ), _( "Colors" ) );
1069 book->AddSubPage( CREATE_PANEL( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) );
1070
1072 expand.push_back( book->GetPageCount() );
1073
1074 book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
1075 book->AddSubPage( CREATE_PANEL( PANEL_PCB_DISPLAY_OPTIONS ), _( "Display Options" ) );
1076 book->AddSubPage( CREATE_PANEL( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
1077 book->AddSubPage( CREATE_PANEL( PANEL_PCB_COLORS ), _( "Colors" ) );
1078 book->AddSubPage( CREATE_PANEL( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) );
1079 book->AddSubPage( CREATE_PANEL( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
1080
1082 expand.push_back( book->GetPageCount() );
1083
1084 book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
1085 book->AddSubPage( CREATE_PANEL( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
1086 book->AddSubPage( CREATE_PANEL( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
1087 book->AddSubPage( CREATE_PANEL( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
1088 book->AddSubPage( CREATE_PANEL( PANEL_3DV_COLORS ), _( "Colors" ) );
1089 }
1090 catch( ... )
1091 {
1092 }
1093
1094 try
1095 {
1097
1098 kiface->GetActions( hotkeysPanel->ActionsList() );
1099
1100 if( GetFrameType() == FRAME_GERBER )
1101 expand.push_back( book->GetPageCount() );
1102
1103 book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
1104 book->AddSubPage( CREATE_PANEL( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
1105 book->AddSubPage( CREATE_PANEL( PANEL_GBR_COLORS ), _( "Colors" ) );
1106 book->AddSubPage( CREATE_PANEL( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) );
1107 }
1108 catch( ... )
1109 {
1110 }
1111
1112 try
1113 {
1115 kiface->GetActions( hotkeysPanel->ActionsList() );
1116
1117 if( GetFrameType() == FRAME_PL_EDITOR )
1118 expand.push_back( book->GetPageCount() );
1119
1120 book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
1121 book->AddSubPage( CREATE_PANEL( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
1122 book->AddSubPage( CREATE_PANEL( PANEL_DS_COLORS ), _( "Colors" ) );
1123
1124 book->AddPage( new PANEL_PCM_SETTINGS( book ), _( "Plugin and Content Manager" ) );
1125 }
1126 catch( ... )
1127 {
1128 }
1129
1130 // Update all of the action hotkeys. The process of loading the actions through
1131 // the KiFACE will only get us the default hotkeys
1132 ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
1133
1134 for( size_t i = 0; i < book->GetPageCount(); ++i )
1135 book->GetPage( i )->Layout();
1136
1137 for( int page : expand )
1138 book->ExpandNode( page );
1139
1140 if( !aStartPage.IsEmpty() )
1141 dlg.SetInitialPage( aStartPage, aStartParentPage );
1142
1143 dlg.SetEvtHandlerEnabled( true );
1144 wxEndBusyCursor();
1145
1146 if( dlg.ShowModal() == wxID_OK )
1147 {
1148 Pgm().GetSettingsManager().Save();
1149 dlg.Kiway().CommonSettingsChanged( false, false );
1150 }
1151
1152#undef CREATE_PANEL
1153}
1154
1155
1156void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
1157{
1158 wxString* files = aEvent.GetFiles();
1159
1160 for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
1161 {
1162 const wxFileName fn = wxFileName( files[nb] );
1163 wxString ext = fn.GetExt();
1164
1165 // Alias all gerber files as GerberFileExtension
1166 if( IsGerberFileExtension( ext ) )
1167 ext = GerberFileExtension;
1168
1169 if( m_acceptedExts.find( ext.ToStdString() ) != m_acceptedExts.end() )
1170 m_AcceptedFiles.emplace_back( fn );
1171 }
1172
1174 m_AcceptedFiles.clear();
1175}
1176
1177
1179{
1180 for( const wxFileName& file : m_AcceptedFiles )
1181 {
1182 wxString fn = file.GetFullPath();
1183 m_toolManager->RunAction( *m_acceptedExts.at( file.GetExt() ), true, &fn );
1184 }
1185}
1186
1187
1188bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
1189{
1190 wxString msg;
1191 wxFileName fn = aFileName;
1192
1193 // Check for absence of a file path with a file name. Unfortunately KiCad
1194 // uses paths relative to the current project path without the ./ part which
1195 // confuses wxFileName. Making the file name path absolute may be less than
1196 // elegant but it solves the problem.
1197 if( fn.GetPath().IsEmpty() && fn.HasName() )
1198 fn.MakeAbsolute();
1199
1200 wxCHECK_MSG( fn.IsOk(), false,
1201 wxT( "File name object is invalid. Bad programmer!" ) );
1202 wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
1203 wxT( "File name object path <" ) + fn.GetFullPath() +
1204 wxT( "> is not set. Bad programmer!" ) );
1205
1206 if( fn.IsDir() && !fn.IsDirWritable() )
1207 {
1208 msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
1209 }
1210 else if( !fn.FileExists() && !fn.IsDirWritable() )
1211 {
1212 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1213 }
1214 else if( fn.FileExists() && !fn.IsFileWritable() )
1215 {
1216 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1217 }
1218
1219 if( !msg.IsEmpty() )
1220 {
1221 if( aVerbose )
1222 DisplayErrorMessage( this, msg );
1223
1224 return false;
1225 }
1226
1227 return true;
1228}
1229
1230
1231void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
1232{
1233 if( !IsGUI() )
1234 return;
1235
1236 wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1237
1238 wxFileName autoSaveFileName = aFileName;
1239
1240 // Check for auto save file.
1241 autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() );
1242
1243 wxLogTrace( traceAutoSave,
1244 wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
1245
1246 if( !autoSaveFileName.FileExists() )
1247 return;
1248
1249 wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
1250 "It appears that the last time you were editing\n"
1251 "%s\n"
1252 "KiCad exited before saving.\n"
1253 "\n"
1254 "Do you wish to open the auto-saved file instead?" ),
1255 aFileName.GetFullName() );
1256
1257 int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1258 this );
1259
1260 // Make a backup of the current file, delete the file, and rename the auto save file to
1261 // the file name.
1262 if( response == wxYES )
1263 {
1264 if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
1265 {
1266 wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
1267 Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
1268 }
1269 }
1270 else
1271 {
1272 wxLogTrace( traceAutoSave,
1273 wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
1274
1275 // Remove the auto save file when using the previous file as is.
1276 wxRemoveFile( autoSaveFileName.GetFullPath() );
1277 }
1278}
1279
1280
1282{
1283 // This function should be overridden in child classes
1284 return false;
1285}
1286
1287
1289{
1290 wxAcceleratorEntry entries[1];
1291 entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
1292 wxAcceleratorTable accel( 1, entries );
1293 SetAcceleratorTable( accel );
1294}
1295
1296
1298{
1301}
1302
1303
1305{
1306 m_undoList.PushCommand( aNewitem );
1307
1308 // Delete the extra items, if count max reached
1309 if( m_undoRedoCountMax > 0 )
1310 {
1311 int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
1312
1313 if( extraitems > 0 )
1314 ClearUndoORRedoList( UNDO_LIST, extraitems );
1315 }
1316}
1317
1318
1320{
1321 m_redoList.PushCommand( aNewitem );
1322
1323 // Delete the extra items, if count max reached
1324 if( m_undoRedoCountMax > 0 )
1325 {
1326 int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
1327
1328 if( extraitems > 0 )
1329 ClearUndoORRedoList( REDO_LIST, extraitems );
1330 }
1331}
1332
1333
1335{
1336 return m_undoList.PopCommand();
1337}
1338
1339
1341{
1342 return m_redoList.PopCommand();
1343}
1344
1345
1347{
1348 m_autoSaveRequired = true;
1349}
1350
1351
1353{
1354 SetUserUnits( aUnits );
1356
1357 wxCommandEvent e( UNITS_CHANGED );
1358 e.SetClientData( this );
1359 ProcessEventLocally( e );
1360}
1361
1362
1363void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
1364{
1365 // When we maximize the window, we want to save the old information
1366 // so that we can add it to the settings on next window load.
1367 // Contrary to the documentation, this event seems to be generated
1368 // when the window is also being unmaximized on OSX, so we only
1369 // capture the size information when we maximize the window when on OSX.
1370#ifdef __WXOSX__
1371 if( !IsMaximized() )
1372#endif
1373 {
1375 m_normalFramePos = GetPosition();
1376 wxLogTrace( traceDisplayLocation,
1377 "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
1380 }
1381
1382 // Skip event to actually maximize the window
1383 aEvent.Skip();
1384}
1385
1386
1388{
1389#ifdef __WXGTK__
1390 wxSize winSize = GetSize();
1391
1392 // GTK includes the window decorations in the normal GetSize call,
1393 // so we have to use a GTK-specific sizing call that returns the
1394 // non-decorated window size.
1396 {
1397 int width = 0;
1398 int height = 0;
1399 GTKDoGetSize( &width, &height );
1400
1401 winSize.Set( width, height );
1402 }
1403#else
1404 wxSize winSize = GetSize();
1405#endif
1406
1407 return winSize;
1408}
1409
1410
1412{
1413 // Update the icon theme when the system theme changes and update the toolbars
1415 ThemeChanged();
1416
1417 // This isn't handled by ThemeChanged()
1418 if( GetMenuBar() )
1419 {
1420 // For icons in menus, icon scaling & hotkeys
1422 GetMenuBar()->Refresh();
1423 }
1424}
1425
1426
1427void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
1428{
1429 // Call the handler to update the colors used in the frame
1431
1432 // Skip the change event to ensure the rest of the window controls get it
1433 aEvent.Skip();
1434}
1435
1436
1437void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
1438{
1439 // Call the handler
1440 handleIconizeEvent( aEvent );
1441
1442 // Skip the event.
1443 aEvent.Skip();
1444}
1445
1446
1447#ifdef _WIN32
1448WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
1449{
1450 // This will help avoid the menu keeping focus when the alt key is released
1451 // You can still trigger accelerators as long as you hold down alt
1452 if( message == WM_SYSCOMMAND )
1453 {
1454 if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
1455 return 0;
1456 }
1457
1458 return wxFrame::MSWWindowProc( message, wParam, lParam );
1459}
1460#endif
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void ClearScaledBitmapCache()
Wipes out the scaled bitmap cache so that the icon theme can be changed.
Definition: bitmap.cpp:181
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:93
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION reportBug
Cursor control event types.
Definition: actions.h:187
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION donate
Definition: actions.h:185
static TOOL_ACTION listHotKeys
Definition: actions.h:184
static TOOL_ACTION getInvolved
Definition: actions.h:186
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION gettingStarted
Definition: actions.h:182
static TOOL_ACTION help
Definition: actions.h:183
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
Define the structure of a toolbar with buttons that invoke ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
WINDOW_SETTINGS m_Window
Definition: app_settings.h:187
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
Handle actions that are shared between different applications.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:83
bool IsQuasiModal() const
Definition: dialog_shim.h:106
The base frame for deriving all KiCad main window classes.
virtual wxString help_name()
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
void LoadWindowState(const wxString &aFileName)
FRAME_T GetFrameType() const
virtual void UnregisterUIUpdateHandler(int aID) override
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
virtual bool isAutoSaveRequired() const
Return the auto save status of the application.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
void windowClosing(wxCloseEvent &event)
(with its unexpected name so it does not collide with the real OnWindowClose() function provided in d...
virtual void OnCharHook(wxKeyEvent &aKeyEvent)
Capture the key event before it is sent to the GUI.
virtual int GetRedoCommandCount() const
UNDO_REDO_CONTAINER m_undoList
virtual void OnMove(wxMoveEvent &aEvent)
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
virtual void doCloseWindow()
void OnMenuEvent(wxMenuEvent &event)
The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu events aren't ...
virtual bool IsModal() const
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void HandleSystemColorChange()
Update the UI in response to a change in the system colors.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void ensureWindowIsOnScreen()
void LoadWindowSettings(const WINDOW_SETTINGS *aCfg)
Load window settings from the given settings object.
std::vector< wxFileName > m_AcceptedFiles
virtual void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
void OnKicadAbout(wxCommandEvent &event)
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
virtual void DoWithAcceptedFiles()
Execute action on accepted dropped file.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
wxWindow * findQuasiModalDialog()
static void HandleUpdateUIEvent(wxUpdateUIEvent &aEvent, EDA_BASE_FRAME *aFrame, ACTION_CONDITIONS aCond)
Handle events generated when the UI is trying to figure out the current state of the UI controls rela...
wxString m_perspective
virtual void ClearUndoORRedoList(UNDO_REDO_LIST aList, int aItemCount=-1)
Remove the aItemCount of old commands from aList and delete commands, pickers and picked items if nee...
virtual void ThemeChanged()
Process light/dark theme change.
wxSize m_normalFrameSize
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, KIWAY *aKiway, const EDA_IU_SCALE &aIuScale)
void ShowPreferences(wxString aStartPage, wxString aStartParentPage)
Displays the preferences and settings of all opened editors paged dialog, starting with a particular ...
void initExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
void OnPreferences(wxCommandEvent &event)
Displays the preferences and settings of all opened editors paged dialog.
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
WX_INFOBAR * m_infoBar
void onAutoSaveTimer(wxTimerEvent &aEvent)
Handle the auto save timer event.
void SaveWindowSettings(WINDOW_SETTINGS *aCfg)
Save window settings to the given settings object.
void FinishAUIInitialization()
virtual wxString GetCurrentFileName() const
Get the full filename + path of the currently opened file in the frame.
void ChangeUserUnits(EDA_UNITS aUnits)
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
wxTimer * m_autoSaveTimer
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxAuiManager m_auimgr
void PrintMsg(const wxString &text)
void commonInit(FRAME_T aFrameType)
Collect common initialization functions used in all CTORs.
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
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 PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
std::map< int, UIUpdateHandler > m_uiUpdateMap
< Map containing the UI update handlers registered with wx for each action.
UNDO_REDO_CONTAINER m_redoList
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
FILE_HISTORY * m_fileHistory
virtual void OnSize(wxSizeEvent &aEvent)
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual bool canCloseWindow(wxCloseEvent &aCloseEvent)
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Checks if aFileName can be written.
wxPoint m_normalFramePos
void OnMaximize(wxMaximizeEvent &aEvent)
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handles event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associates files extensions with action to execute.
void onIconize(wxIconizeEvent &aEvent)
virtual void unitsChangeRefresh()
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
static wxString GetAutoSaveFilePrefix()
wxSize GetWindowSize()
Get the undecorated window size that can be used for restoring the window size.
int GetAutoSaveInterval() const
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void onSystemColorChange(wxSysColourChangedEvent &aEvent)
virtual int GetUndoCommandCount() const
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
wxString m_mruPath
void ReCreateMenuBar()
Recreates the menu bar.
virtual void doReCreateMenuBar()
WX_INFOBAR * GetInfoBar()
Specialization of the wxAuiPaneInfo class for KiCad panels.
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
void ClearFileHistory()
Clear all entries from the file history.
void Save(APP_SETTINGS_BASE &aSettings)
Saves history into a JSON settings object.
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_base.h:114
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
const wxString & GetHelpFileName() const
Return just the basename portion of the current help file.
Definition: kiface_base.h:110
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:37
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:274
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:575
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:198
@ FACE_SCH
eeschema DSO
Definition: kiway.h:281
@ FACE_PL_EDITOR
Definition: kiway.h:285
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:282
@ FACE_GERBVIEW
Definition: kiway.h:284
virtual void GetActions(std::vector< TOOL_ACTION * > &aActions) const
Append all registered actions to the given list.
Definition: kiway.cpp:500
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
std::vector< TOOL_ACTION * > & ActionsList()
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:139
A holder to handle information on schematic or board items.
void SaveFileState(const wxString &aFileName, const WINDOW_SETTINGS *aWindowCfg, bool aOpen)
const PROJECT_FILE_STATE * GetFileState(const wxString &aFileName)
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:155
Look for files in a number of paths.
Definition: search_stack.h:42
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
virtual void ShowChangedLanguage()
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:172
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:101
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
int GetUIId() const
Definition: tool_action.h:130
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
void PushCommand(PICKED_ITEMS_LIST *aCommand)
PICKED_ITEMS_LIST * PopCommand()
void SetUserUnits(EDA_UNITS aUnits)
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:289
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:128
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: wx_infobar.h:93
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:279
void SetCallback(std::function< void(void)> aCallback)
Provide a callback to be called when the infobar is dismissed (either by user action or timer).
Definition: wx_infobar.h:157
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
bool IsGUI()
Determine if the application is running with a GUI.
Definition: confirm.cpp:40
This file is part of the common library.
return & kiface
Definition: cvpcb.cpp:112
#define _(s)
static const wxSize minSize(FRAME_T aFrameType)
wxDEFINE_EVENT(UNITS_CHANGED, wxCommandEvent)
static const wxSize defaultSize(FRAME_T aFrameType)
#define CREATE_PANEL(key)
#define DEFAULT_MAX_UNDO_ITEMS
std::function< void(wxUpdateUIEvent &) > UIUpdateHandler
This is the handler functor for the update UI events.
void SocketCleanup()
Definition: eda_dde.cpp:319
DDE server & client.
EDA_UNITS
Definition: eda_units.h:43
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ FRAME_PCB_EDITOR
Definition: frame_type.h:40
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ PANEL_SCH_FIELD_NAME_TEMPLATES
Definition: frame_type.h:76
@ PANEL_GBR_DISPLAY_OPTIONS
Definition: frame_type.h:94
@ PANEL_3DV_COLORS
Definition: frame_type.h:92
@ PANEL_3DV_OPENGL
Definition: frame_type.h:90
@ PANEL_PCB_ORIGINS_AXES
Definition: frame_type.h:87
@ PANEL_PCB_EDIT_OPTIONS
Definition: frame_type.h:84
@ PANEL_SCH_DISP_OPTIONS
Definition: frame_type.h:72
@ PANEL_FP_DISPLAY_OPTIONS
Definition: frame_type.h:78
@ FRAME_SCH
Definition: frame_type.h:34
@ PANEL_DS_COLORS
Definition: frame_type.h:100
@ PANEL_PCB_COLORS
Definition: frame_type.h:85
@ PANEL_3DV_RAYTRACING
Definition: frame_type.h:91
@ PANEL_SYM_EDIT_OPTIONS
Definition: frame_type.h:69
@ PANEL_SCH_EDIT_OPTIONS
Definition: frame_type.h:73
@ PANEL_SYM_DISP_OPTIONS
Definition: frame_type.h:68
@ PANEL_FP_COLORS
Definition: frame_type.h:80
@ PANEL_SYM_COLORS
Definition: frame_type.h:70
@ FRAME_PL_EDITOR
Definition: frame_type.h:55
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:41
@ FRAME_GERBER
Definition: frame_type.h:53
@ FRAME_PCB_DISPLAY3D
Definition: frame_type.h:45
@ PANEL_FP_EDIT_OPTIONS
Definition: frame_type.h:79
@ PANEL_SCH_ANNO_OPTIONS
Definition: frame_type.h:74
@ PANEL_PCB_ACTION_PLUGINS
Definition: frame_type.h:86
@ PANEL_FP_DEFAULT_VALUES
Definition: frame_type.h:81
@ PANEL_3DV_DISPLAY_OPTIONS
Definition: frame_type.h:89
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:99
@ PANEL_PCB_DISPLAY_OPTIONS
Definition: frame_type.h:83
@ PANEL_SCH_COLORS
Definition: frame_type.h:75
@ PANEL_GBR_COLORS
Definition: frame_type.h:97
@ PANEL_GBR_EXCELLON_OPTIONS
Definition: frame_type.h:96
@ KICAD_MAIN_FRAME_T
Definition: frame_type.h:64
bool IsGerberFileExtension(const wxString &ext)
const std::string GerberFileExtension
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
const wxChar *const traceDisplayLocation
Flag to enable debug output of display positioning logic.
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
void ReadHotKeyConfigIntoActions(const wxString &aFileName, std::vector< TOOL_ACTION * > &aActions)
Reads a hotkey config file into a list of actions.
@ ID_FILE_LIST_CLEAR
Definition: id.h:87
@ ID_FILE1
Definition: id.h:84
@ ID_AUTO_SAVE_TIMER
Definition: id.h:79
Macros and inline functions to create menus items in menubars or popup menus.
void RemoveShutdownBlockReason(wxWindow *aWindow)
Removes any shutdown block reason set.
Definition: gtk/app.cpp:78
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:85
see class PGM_BASE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
SELECTION_CONDITION enableCondition
Returns true if the UI control should be enabled.
SELECTION_CONDITION checkCondition
Returns true if the UI control should be checked.
SELECTION_CONDITION showCondition
Returns true if the UI control should be shown.
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:66
struct WINDOW_STATE window
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:92
WINDOW_STATE state
Definition: app_settings.h:93
wxString mru_path
Definition: app_settings.h:94
wxString perspective
Definition: app_settings.h:95
Stores the window positioning/state.
Definition: app_settings.h:79
unsigned int display
Definition: app_settings.h:85
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.