KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2023 CERN (www.cern.ch)
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include "kicad_manager_frame.h"
28#include <eda_base_frame.h>
29
30#include <advanced_config.h>
31#include <bitmaps.h>
32#include <bitmap_store.h>
33#include <dialog_shim.h>
39#include <eda_dde.h>
40#include <file_history.h>
41#include <id.h>
42#include <kiface_base.h>
43#include <hotkeys_basic.h>
45#include <paths.h>
46#include <confirm.h>
48#include <pgm_base.h>
53#include <tool/action_manager.h>
54#include <tool/action_menu.h>
55#include <tool/action_toolbar.h>
56#include <tool/actions.h>
57#include <tool/common_control.h>
58#include <tool/tool_manager.h>
61#include <trace_helpers.h>
64#include <widgets/wx_infobar.h>
66#include <widgets/wx_grid.h>
67#include <widgets/wx_treebook.h>
68#include <wx/app.h>
69#include <wx/config.h>
70#include <wx/display.h>
71#include <wx/stdpaths.h>
72#include <wx/string.h>
73#include <wx/msgdlg.h>
74#include <wx/wupdlock.h>
75#include <kiplatform/app.h>
76#include <kiplatform/io.h>
77#include <kiplatform/ui.h>
78
79#include <functional>
80#include <kiface_ids.h>
81
82#ifdef KICAD_IPC_API
83#include <api/api_server.h>
84#endif
85
86
87// Minimum window size
88static const wxSize minSizeLookup( FRAME_T aFrameType, wxWindow* aWindow )
89{
90 switch( aFrameType )
91 {
93 return wxWindow::FromDIP( wxSize( 406, 354 ), aWindow );
94
95 default:
96 return wxWindow::FromDIP( wxSize( 500, 400 ), aWindow );
97 }
98}
99
100
101static const wxSize defaultSize( FRAME_T aFrameType, wxWindow* aWindow )
102{
103 switch( aFrameType )
104 {
106 return wxWindow::FromDIP( wxSize( 850, 540 ), aWindow );
107
108 default:
109 return wxWindow::FromDIP( wxSize( 1280, 720 ), aWindow );
110 }
111}
112
113
114BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
115 // These event table entries are needed to handle events from the mac application menu
116 EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
117 EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
118
119 EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
120 EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
121 EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
122 EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
123 EVT_MOVE( EDA_BASE_FRAME::OnMove )
124 EVT_SIZE( EDA_BASE_FRAME::OnSize )
125 EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
126
127 EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
128 EVT_ICONIZE( EDA_BASE_FRAME::onIconize )
129END_EVENT_TABLE()
130
131
132void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
133{
134 m_ident = aFrameType;
135 m_maximizeByDefault = false;
136 m_infoBar = nullptr;
137 m_settingsManager = nullptr;
138 m_fileHistory = nullptr;
139 m_supportsAutoSave = false;
140 m_autoSavePending = false;
141 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
142 m_isClosing = false;
143 m_isNonUserClose = false;
144 m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
145 m_autoSaveRequired = false;
147 m_frameSize = defaultSize( aFrameType, this );
148 m_displayIndex = -1;
149
150 m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
151
152 m_settingsManager = &Pgm().GetSettingsManager();
153
154 // Set a reasonable minimal size for the frame
155 wxSize minSize = minSizeLookup( aFrameType, this );
156 SetSizeHints( minSize.x, minSize.y, -1, -1, -1, -1 );
157
158 // Store dimensions of the user area of the main window.
159 GetClientSize( &m_frameSize.x, &m_frameSize.y );
160
161 Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
162 wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
163
164 // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
165 // to be called before any other hook for wxCloseEvent, which is necessary.
166 Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
167
168 initExitKey();
169}
170
171
172EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
173 const wxPoint& aPos, const wxSize& aSize, long aStyle,
174 const wxString& aFrameName, KIWAY* aKiway,
175 const EDA_IU_SCALE& aIuScale ) :
176 wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
177 TOOLS_HOLDER(),
178 KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
179 UNITS_PROVIDER( aIuScale, EDA_UNITS::MM )
180{
181 m_tbTopMain = nullptr;
182 m_tbTopAux = nullptr;
183 m_tbRight = nullptr;
184 m_tbLeft = nullptr;
185
186 commonInit( aFrameType );
187}
188
189
190wxWindow* findQuasiModalDialog( wxWindow* aParent )
191{
192 for( wxWindow* child : aParent->GetChildren() )
193 {
194 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( child ) )
195 {
196 if( dlg->IsQuasiModal() )
197 return dlg;
198
199 if( wxWindow* nestedDlg = findQuasiModalDialog( child ) )
200 return nestedDlg;
201 }
202 }
203
204 return nullptr;
205}
206
207
209{
210 if( wxWindow* dlg = ::findQuasiModalDialog( this ) )
211 return dlg;
212
213 // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
214 // so we have to look for it separately.
215 if( m_ident == FRAME_SCH )
216 {
217 wxWindow* cvpcb = wxWindow::FindWindowByName( wxS( "CvpcbFrame" ) );
218
219 if( cvpcb )
220 return cvpcb;
221 }
222
223 return nullptr;
224}
225
226
227void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
228{
229 // Don't allow closing when a quasi-modal is open.
230 wxWindow* quasiModal = findQuasiModalDialog();
231
232 if( quasiModal )
233 {
234 // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
235 // when they have no idea what those are.
236 quasiModal->Raise();
237 wxBell();
238
239 if( event.CanVeto() )
240 event.Veto();
241
242 return;
243 }
244
245
246 if( event.GetId() == wxEVT_QUERY_END_SESSION
247 || event.GetId() == wxEVT_END_SESSION )
248 {
249 // End session means the OS is going to terminate us
250 m_isNonUserClose = true;
251 }
252
253 if( canCloseWindow( event ) )
254 {
255 m_isClosing = true;
256
257 if( m_infoBar )
259
260 APP_SETTINGS_BASE* cfg = config();
261
262 if( cfg )
263 SaveSettings( cfg ); // virtual, wxFrame specific
264
266
267 // Destroy (safe delete frame) this frame only in non modal mode.
268 // In modal mode, the caller will call Destroy().
269 if( !IsModal() )
270 Destroy();
271 }
272 else
273 {
274 if( event.CanVeto() )
275 event.Veto();
276 }
277}
278
279
281{
282 Disconnect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
283 wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
284 Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
285
286 delete m_autoSaveTimer;
287 delete m_fileHistory;
288
290
292
294}
295
296
297bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
298{
299#ifdef __WXMAC__
300 // Apple in its infinite wisdom will raise a disabled window before even passing
301 // us the event, so we have no way to stop it. Instead, we have to catch an
302 // improperly ordered disabled window and quasi-modal dialog here and reorder
303 // them.
304 if( !IsEnabled() && IsActive() )
305 {
306 wxWindow* dlg = findQuasiModalDialog();
307
308 if( dlg )
309 dlg->Raise();
310 }
311#endif
312
313 if( !wxFrame::ProcessEvent( aEvent ) )
314 return false;
315
316 if( Pgm().m_Quitting )
317 return true;
318
319 if( !m_isClosing && m_supportsAutoSave && IsShownOnScreen() && IsActive()
321 && GetAutoSaveInterval() > 0 )
322 {
323 if( !m_autoSavePending )
324 {
325 wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
326 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
327 m_autoSavePending = true;
328 }
329 else if( m_autoSaveTimer->IsRunning() )
330 {
331 wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
332 m_autoSaveTimer->Stop();
333 m_autoSavePending = false;
334 }
335 }
336
337 return true;
338}
339
340
342{
344}
345
346
347void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
348{
349 // Don't stomp on someone else's timer event.
350 if( aEvent.GetId() != ID_AUTO_SAVE_TIMER )
351 {
352 aEvent.Skip();
353 return;
354 }
355
356 if( !doAutoSave() )
357 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
358}
359
360
362{
363 wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
364}
365
366
367void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
368{
369 wxLogTrace( kicadTraceKeyEvent, wxS( "EDA_BASE_FRAME::OnCharHook %s" ), dump( aKeyEvent ) );
370
371 // Key events can be filtered here.
372 // Currently no filtering is made.
373 aKeyEvent.Skip();
374}
375
376
377void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
378{
379 if( !m_toolDispatcher )
380 aEvent.Skip();
381 else
383}
384
385
387{
389 std::placeholders::_1,
390 this,
391 aConditions );
392
393 m_uiUpdateMap[aID] = evtFunc;
394
395 Bind( wxEVT_UPDATE_UI, evtFunc, aID );
396}
397
398
400{
401 const auto it = m_uiUpdateMap.find( aID );
402
403 if( it == m_uiUpdateMap.end() )
404 return;
405
406 Unbind( wxEVT_UPDATE_UI, it->second, aID );
407}
408
409
410void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
411 ACTION_CONDITIONS aCond )
412{
413 bool checkRes = false;
414 bool enableRes = true;
415 bool showRes = true;
416 bool isCut = aEvent.GetId() == ACTIONS::cut.GetUIId();
417 bool isCopy = aEvent.GetId() == ACTIONS::copy.GetUIId();
418 bool isPaste = aEvent.GetId() == ACTIONS::paste.GetUIId();
419 SELECTION& selection = aFrame->GetCurrentSelection();
420
421 try
422 {
423 checkRes = aCond.checkCondition( selection );
424 enableRes = aCond.enableCondition( selection );
425 showRes = aCond.showCondition( selection );
426 }
427 catch( std::exception& )
428 {
429 // Something broke with the conditions, just skip the event.
430 aEvent.Skip();
431 return;
432 }
433
434 if( showRes && aEvent.GetId() == ACTIONS::undo.GetUIId() )
435 {
436 wxString msg = _( "Undo" );
437
438 if( enableRes )
439 msg += wxS( " " ) + aFrame->GetUndoActionDescription();
440
441 aEvent.SetText( msg );
442 }
443 else if( showRes && aEvent.GetId() == ACTIONS::redo.GetUIId() )
444 {
445 wxString msg = _( "Redo" );
446
447 if( enableRes )
448 msg += wxS( " " ) + aFrame->GetRedoActionDescription();
449
450 aEvent.SetText( msg );
451 }
452
453 if( isCut || isCopy || isPaste )
454 {
455 wxWindow* focus = wxWindow::FindFocus();
456 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
457
458 if( textEntry && isCut && textEntry->CanCut() )
459 enableRes = true;
460 else if( textEntry && isCopy && textEntry->CanCopy() )
461 enableRes = true;
462 else if( textEntry && isPaste && textEntry->CanPaste() )
463 enableRes = true;
464 else if( dynamic_cast<WX_GRID*>( focus ) )
465 enableRes = false; // Must disable menu in order to get command as CharHook event
466 }
467
468 aEvent.Enable( enableRes );
469 aEvent.Show( showRes );
470
471 if( aEvent.IsCheckable() )
472 aEvent.Check( checkRes );
473}
474
475
477{
478 // Setup the conditions to check a language menu item
479 auto isCurrentLang =
480 [] ( const SELECTION& aSel, int aLangIdentifier )
481 {
482 return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
483 };
484
485 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
486 {
488 cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
489 LanguagesList[ii].m_WX_Lang_Identifier ) );
490
491 RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
492 }
493}
494
495
497 const ACTION_TOOLBAR_CONTROL_FACTORY& aControlFactory )
498{
499 m_toolbarControlFactories.emplace( aControlDesc.GetName(), aControlFactory );
500}
501
502
504{
505 for( auto& control : m_toolbarControlFactories )
506 {
507 if( control.first == aName )
508 return &control.second;
509 }
510
511 return nullptr;
512}
513
514
516{
517}
518
519
521{
522 wxWindowUpdateLocker dummy( this );
523
524 wxASSERT( m_toolbarSettings );
525
526 std::optional<TOOLBAR_CONFIGURATION> tbConfig;
527
528 // Drawing tools (typically on right edge of window)
529 tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::RIGHT, config()->m_CustomToolbars );
530
531 if( tbConfig.has_value() )
532 {
533 if( !m_tbRight )
534 {
535 m_tbRight = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
536 KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
538 }
539
540 m_tbRight->ApplyConfiguration( tbConfig.value() );
541 }
542
543 // Options (typically on left edge of window)
544 tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::LEFT, config()->m_CustomToolbars );
545
546 if( tbConfig.has_value() )
547 {
548 if( !m_tbLeft )
549 {
550 m_tbLeft = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
551 KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
553 }
554
555 m_tbLeft->ApplyConfiguration( tbConfig.value() );
556 }
557
558 // Top main toolbar (the top one)
559 tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::TOP_MAIN, config()->m_CustomToolbars );
560
561 if( tbConfig.has_value() )
562 {
563 if( !m_tbTopMain )
564 {
565 m_tbTopMain = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
566 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
568 }
569
570 m_tbTopMain->ApplyConfiguration( tbConfig.value() );
571 }
572
573 // Top aux toolbar (the bottom one)
574 tbConfig = m_toolbarSettings->GetToolbarConfig( TOOLBAR_LOC::TOP_AUX, config()->m_CustomToolbars );
575
576 if( tbConfig.has_value() )
577 {
578 if( !m_tbTopAux )
579 {
580 m_tbTopAux = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
581 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
583 }
584
585 m_tbTopAux->ApplyConfiguration( tbConfig.value() );
586 }
587}
588
589
591{
592 if( m_tbTopMain )
594
595 if( m_tbRight )
597
598 if( m_tbLeft )
600
601 if( m_tbTopAux )
603
604}
605
606
608{
609 if( m_tbTopMain )
610 m_auimgr.GetPane( m_tbTopMain ).MaxSize( m_tbTopMain->GetSize() );
611
612 if( m_tbRight )
613 m_auimgr.GetPane( m_tbRight ).MaxSize( m_tbRight->GetSize() );
614
615 if( m_tbLeft )
616 m_auimgr.GetPane( m_tbLeft ).MaxSize( m_tbLeft->GetSize() );
617
618 if( m_tbTopAux )
619 m_auimgr.GetPane( m_tbTopAux ).MaxSize( m_tbTopAux->GetSize() );
620
621 m_auimgr.Update();
622}
623
624
626{
634 CallAfter( [this]()
635 {
636 if( !m_isClosing )
638 } );
639}
640
641
642void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
643{
645 ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
646
647 helpMenu->Add( ACTIONS::help );
648 helpMenu->Add( ACTIONS::gettingStarted );
649 helpMenu->Add( ACTIONS::listHotKeys );
650 helpMenu->Add( ACTIONS::getInvolved );
651 helpMenu->Add( ACTIONS::donate );
652 helpMenu->Add( ACTIONS::reportBug );
653
654 helpMenu->AppendSeparator();
655 helpMenu->Add( ACTIONS::about );
656
657 aMenuBar->Append( helpMenu, _( "&Help" ) );
658}
659
660
662{
664
665 if( GetMenuBar() )
666 {
668 GetMenuBar()->Refresh();
669 }
670}
671
672
674{
676
677 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
678
679#ifdef KICAD_IPC_API
680 bool running = Pgm().GetApiServer().Running();
681
682 if( running && !settings->m_Api.enable_server )
683 Pgm().GetApiServer().Stop();
684 else if( !running && settings->m_Api.enable_server )
685 Pgm().GetApiServer().Start();
686#endif
687
688 if( m_fileHistory )
689 {
690 int historySize = settings->m_System.file_history_size;
691 m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
692 }
693
695 ThemeChanged();
696
697 if( GetMenuBar() )
698 {
699 // For icons in menus, icon scaling & hotkeys
701 GetMenuBar()->Refresh();
702 }
703
704 // Update the toolbars
706}
707
708
710{
712
713 // Update all the toolbars to have new icons
714 wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
715
716 for( size_t i = 0; i < panes.GetCount(); ++i )
717 {
718 if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
719 toolbar->RefreshBitmaps();
720 }
721}
722
723
724void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
725{
726#ifdef __WXMAC__
727 int currentDisplay = wxDisplay::GetFromWindow( this );
728
729 if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
730 {
731 wxLogTrace( traceDisplayLocation, wxS( "OnSize: current display changed %d to %d" ),
732 m_displayIndex, currentDisplay );
733 m_displayIndex = currentDisplay;
735 }
736#endif
737
738 aEvent.Skip();
739}
740
741
742void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
743{
744 if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
745 return;
746
747 const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
748
749 if( state != nullptr )
750 {
751 LoadWindowState( state->window );
752 }
753}
754
755
757{
758 bool wasDefault = false;
759
760 m_framePos.x = aState.pos_x;
761 m_framePos.y = aState.pos_y;
762 m_frameSize.x = aState.size_x;
763 m_frameSize.y = aState.size_y;
764
765 wxLogTrace( traceDisplayLocation, wxS( "Config position (%d, %d) with size (%d, %d)" ),
767
768 // Ensure minimum size is set if the stored config was zero-initialized
769 wxSize minSize = minSizeLookup( m_ident, this );
770
771 if( m_frameSize.x < minSize.x || m_frameSize.y < minSize.y )
772 {
774 wasDefault = true;
775
776 wxLogTrace( traceDisplayLocation, wxS( "Using minimum size (%d, %d)" ),
778 }
779
780 wxLogTrace( traceDisplayLocation, wxS( "Number of displays: %d" ), wxDisplay::GetCount() );
781
782 if( aState.display >= wxDisplay::GetCount() )
783 {
784 wxLogTrace( traceDisplayLocation, wxS( "Previous display not found" ) );
785
786 // If it isn't attached, use the first display
787 // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
788 const unsigned int index = 0;
789 wxDisplay display( index );
790 wxRect clientSize = display.GetGeometry();
791
792 m_framePos = wxDefaultPosition;
793
794 // Ensure the window fits on the display, since the other one could have been larger
795 if( m_frameSize.x > clientSize.width )
796 m_frameSize.x = clientSize.width;
797
798 if( m_frameSize.y > clientSize.height )
799 m_frameSize.y = clientSize.height;
800 }
801 else
802 {
803 wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
804 wxPoint upperLeft( m_framePos.x, m_framePos.y );
805
806 wxDisplay display( aState.display );
807 wxRect clientSize = display.GetClientArea();
808
809 int yLimTop = clientSize.y;
810 int yLimBottom = clientSize.y + clientSize.height;
811 int xLimLeft = clientSize.x;
812 int xLimRight = clientSize.x + clientSize.width;
813
814 if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
815 upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
816 upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
817 upperLeft.y > yLimBottom )
818 {
819 m_framePos = wxDefaultPosition;
820 wxLogTrace( traceDisplayLocation, wxS( "Resetting to default position" ) );
821 }
822 }
823
824 wxLogTrace( traceDisplayLocation, wxS( "Final window position (%d, %d) with size (%d, %d)" ),
826
827 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
828
829 // Center the window if we reset to default
830 if( m_framePos.x == -1 )
831 {
832 wxLogTrace( traceDisplayLocation, wxS( "Centering window" ) );
833 Center();
834 m_framePos = GetPosition();
835 }
836
837 // Record the frame sizes in an un-maximized state
840
841 // Maximize if we were maximized before
842 if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
843 {
844 wxLogTrace( traceDisplayLocation, wxS( "Maximizing window" ) );
845 Maximize();
846 }
847
848 m_displayIndex = wxDisplay::GetFromWindow( this );
849}
850
851
853{
854 wxDisplay display( wxDisplay::GetFromWindow( this ) );
855 wxRect clientSize = display.GetClientArea();
856 wxPoint pos = GetPosition();
857 wxSize size = GetWindowSize();
858
859 wxLogTrace( traceDisplayLocation,
860 wxS( "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d" ),
861 clientSize.x, clientSize.y,
862 clientSize.width, clientSize.height );
863
864 if( pos.y < clientSize.y )
865 {
866 wxLogTrace( traceDisplayLocation,
867 wxS( "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d" ), pos.y,
868 clientSize.y );
869 pos.y = clientSize.y;
870 }
871
872 if( pos.x < clientSize.x )
873 {
874 wxLogTrace( traceDisplayLocation,
875 wxS( "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d" ),
876 pos.x, clientSize.x );
877 pos.x = clientSize.x;
878 }
879
880 if( pos.x + size.x - clientSize.x > clientSize.width )
881 {
882 int newWidth = clientSize.width - ( pos.x - clientSize.x );
883 wxLogTrace( traceDisplayLocation,
884 wxS( "ensureWindowIsOnScreen: effective width %d above available %d, setting "
885 "to %d" ), pos.x + size.x, clientSize.width, newWidth );
886 size.x = newWidth;
887 }
888
889 if( pos.y + size.y - clientSize.y > clientSize.height )
890 {
891 int newHeight = clientSize.height - ( pos.y - clientSize.y );
892 wxLogTrace( traceDisplayLocation,
893 wxS( "ensureWindowIsOnScreen: effective height %d above available %d, setting "
894 "to %d" ), pos.y + size.y, clientSize.height, newHeight );
895 size.y = newHeight;
896 }
897
898 wxLogTrace( traceDisplayLocation, wxS( "Updating window position (%d, %d) with size (%d, %d)" ),
899 pos.x, pos.y, size.x, size.y );
900
901 SetSize( pos.x, pos.y, size.x, size.y );
902}
903
904
906{
907 LoadWindowState( aCfg->state );
908
910 m_mruPath = aCfg->mru_path;
911
913}
914
915
917{
918 if( IsIconized() )
919 return;
920
921 // If the window is maximized, we use the saved window size from before it was maximized
922 if( IsMaximized() )
923 {
926 }
927 else
928 {
930 m_framePos = GetPosition();
931 }
932
933 aCfg->state.pos_x = m_framePos.x;
934 aCfg->state.pos_y = m_framePos.y;
935 aCfg->state.size_x = m_frameSize.x;
936 aCfg->state.size_y = m_frameSize.y;
937 aCfg->state.maximized = IsMaximized();
938 aCfg->state.display = wxDisplay::GetFromWindow( this );
939
940 wxLogTrace( traceDisplayLocation, wxS( "Saving window maximized: %s" ),
941 IsMaximized() ? wxS( "true" ) : wxS( "false" ) );
942 wxLogTrace( traceDisplayLocation, wxS( "Saving config position (%d, %d) with size (%d, %d)" ),
944
945 // Once this is fully implemented, wxAuiManager will be used to maintain
946 // the persistence of the main frame and all it's managed windows and
947 // all of the legacy frame persistence position code can be removed.
948 aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
949
950 aCfg->mru_path = m_mruPath;
951}
952
953
955{
957
958 // Get file history size from common settings
959 int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
960
961 // Load the recently used files into the history menu
962 m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 1, fileHistorySize ),
964 m_fileHistory->Load( *aCfg );
965}
966
967
969{
970 wxCHECK( config(), /* void */ );
971
973
974 bool fileOpen = m_isClosing && m_isNonUserClose;
975
976 wxString currentlyOpenedFile = GetCurrentFileName();
977
978 if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
979 {
980 wxFileName rfn( currentlyOpenedFile );
981 rfn.MakeRelativeTo( Prj().GetProjectPath() );
982 Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
983 }
984
985 // Save the recently used files list
986 if( m_fileHistory )
987 {
988 // Save the currently opened file in the file history
989 if( !currentlyOpenedFile.IsEmpty() )
990 UpdateFileHistory( currentlyOpenedFile );
991
992 m_fileHistory->Save( *aCfg );
993 }
994}
995
996
998{
999 return &aCfg->m_Window;
1000}
1001
1002
1004{
1005 // KICAD_MANAGER_FRAME overrides this
1006 return Kiface().KifaceSettings();
1007}
1008
1009
1011{
1012 return Kiface().KifaceSearch();
1013}
1014
1015
1017{
1018 return Kiface().GetHelpFileName();
1019}
1020
1021
1022void EDA_BASE_FRAME::PrintMsg( const wxString& text )
1023{
1024 SetStatusText( text );
1025}
1026
1027
1029{
1030#if defined( __WXOSX_MAC__ )
1032#else
1033 m_infoBar = new WX_INFOBAR( this, &m_auimgr );
1034
1035 m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) ).Top().Layer(1) );
1036#endif
1037}
1038
1039
1041{
1042#if defined( __WXOSX_MAC__ )
1043 m_auimgr.Update();
1044#else
1045 // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
1046 // hiding it.
1047 m_auimgr.Update();
1048
1049 // We don't want the infobar displayed right away
1050 m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
1051 m_auimgr.Update();
1052#endif
1053}
1054
1055
1056void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
1058{
1060
1061 if( aShowCloseButton )
1063
1064 GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
1065}
1066
1067
1068void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
1069 std::function<void(void)> aCallback )
1070{
1072
1073 if( aShowCloseButton )
1075
1076 if( aCallback )
1077 m_infoBar->SetCallback( aCallback );
1078
1079 GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
1080}
1081
1082
1083void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
1084{
1086
1087 if( aShowCloseButton )
1089
1090 GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
1091}
1092
1093
1094void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
1095{
1097
1098 if( aShowCloseButton )
1100
1101 GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
1102}
1103
1104
1105void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
1106{
1107 if( !aFileHistory )
1108 aFileHistory = m_fileHistory;
1109
1110 wxASSERT( aFileHistory );
1111
1112 aFileHistory->AddFileToHistory( FullFileName );
1113
1114 // Update the menubar to update the file history menu
1115 if( !m_isClosing && GetMenuBar() )
1116 {
1118 GetMenuBar()->Refresh();
1119 }
1120}
1121
1122
1123wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
1124 FILE_HISTORY* aFileHistory )
1125{
1126 if( !aFileHistory )
1127 aFileHistory = m_fileHistory;
1128
1129 wxASSERT( aFileHistory );
1130
1131 int baseId = aFileHistory->GetBaseId();
1132
1133 wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
1134
1135 unsigned i = cmdId - baseId;
1136
1137 if( i < aFileHistory->GetCount() )
1138 {
1139 wxString fn = aFileHistory->GetHistoryFile( i );
1140
1141 if( wxFileName::FileExists( fn ) )
1142 {
1143 return fn;
1144 }
1145 else
1146 {
1147 DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
1148 aFileHistory->RemoveFileFromHistory( i );
1149 }
1150 }
1151
1152 // Update the menubar to update the file history menu
1153 if( GetMenuBar() )
1154 {
1156 GetMenuBar()->Refresh();
1157 }
1158
1159 return wxEmptyString;
1160}
1161
1162
1164{
1165 if( !aFileHistory )
1166 aFileHistory = m_fileHistory;
1167
1168 wxASSERT( aFileHistory );
1169
1170 aFileHistory->ClearFileHistory();
1171
1172 // Update the menubar to update the file history menu
1173 if( GetMenuBar() )
1174 {
1176 GetMenuBar()->Refresh();
1177 }
1178}
1179
1180
1181void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
1182{
1183 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
1184 ShowAboutDialog( this );
1185}
1186
1187
1188void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
1189{
1190 ShowPreferences( wxEmptyString, wxEmptyString );
1191}
1192
1193
1194void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParentPage )
1195{
1196 PAGED_DIALOG dlg( this, _( "Preferences" ), true, true, wxEmptyString,
1197 wxWindow::FromDIP( wxSize( 980, 560 ), NULL ) );
1198
1199 dlg.SetEvtHandlerEnabled( false );
1200
1201 {
1202 WX_BUSY_INDICATOR busy_cursor;
1203
1204 WX_TREEBOOK* book = dlg.GetTreebook();
1205 PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
1206 KIFACE* kiface = nullptr;
1207 std::vector<int> expand;
1208
1209 wxWindow* kicadMgr_window = wxWindow::FindWindowByName( KICAD_MANAGER_FRAME_NAME );
1210
1211 if( KICAD_MANAGER_FRAME* kicadMgr = static_cast<KICAD_MANAGER_FRAME*>( kicadMgr_window ) )
1212 {
1213 ACTION_MANAGER* actionMgr = kicadMgr->GetToolManager()->GetActionManager();
1214
1215 for( const auto& [name, action] : actionMgr->GetActions() )
1216 hotkeysPanel->ActionsList().push_back( action );
1217 }
1218
1219 book->AddLazyPage(
1220 []( wxWindow* aParent ) -> wxWindow*
1221 {
1222 return new PANEL_COMMON_SETTINGS( aParent );
1223 },
1224 _( "Common" ) );
1225
1226 book->AddLazyPage(
1227 []( wxWindow* aParent ) -> wxWindow*
1228 {
1229 return new PANEL_MOUSE_SETTINGS( aParent );
1230 }, _( "Mouse and Touchpad" ) );
1231
1232 book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
1233
1234 book->AddLazyPage(
1235 []( wxWindow* aParent ) -> wxWindow*
1236 {
1237 return new PANEL_GIT_REPOS( aParent );
1238 }, _( "Version Control" ) );
1239
1240#ifdef KICAD_USE_SENTRY
1241 book->AddLazyPage(
1242 []( wxWindow* aParent ) -> wxWindow*
1243 {
1244 return new PANEL_DATA_COLLECTION( aParent );
1245 }, _( "Data Collection" ) );
1246#endif
1247
1248#define LAZY_CTOR( key ) \
1249 [this, kiface]( wxWindow* aParent ) \
1250 { \
1251 return kiface->CreateKiWindow( aParent, key, &Kiway() ); \
1252 }
1253
1254 // If a dll is not loaded, the loader will show an error message.
1255
1256 try
1257 {
1259
1260 if( !kiface )
1261 return;
1262
1263 kiface->GetActions( hotkeysPanel->ActionsList() );
1264
1266 expand.push_back( (int) book->GetPageCount() );
1267
1268 book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
1269 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
1270 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_GRIDS ), _( "Grids" ) );
1271 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
1272 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) );
1273
1274 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1275 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_TOOLBARS ), _( "Toolbars" ) );
1276
1277 if( GetFrameType() == FRAME_SCH )
1278 expand.push_back( (int) book->GetPageCount() );
1279
1280 book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
1281 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
1282 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_GRIDS ), _( "Grids" ) );
1283 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
1284 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) );
1285 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_COLORS ), _( "Colors" ) );
1286
1287 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1288 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_TOOLBARS ), _( "Toolbars" ) );
1289
1291 _( "Field Name Templates" ) );
1292 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_SIMULATOR ), _( "Simulator" ) );
1293 }
1294 catch( ... )
1295 {
1296 }
1297
1298 try
1299 {
1301
1302 if( !kiface )
1303 return;
1304
1305 kiface->GetActions( hotkeysPanel->ActionsList() );
1306
1308 expand.push_back( (int) book->GetPageCount() );
1309
1310 book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
1311 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
1312 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_GRIDS ), _( "Grids" ) );
1313 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_ORIGINS_AXES ), _( "Origins & Axes" ) );
1314 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
1315 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) );
1316
1317 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1318 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_TOOLBARS ), _( "Toolbars" ) );
1319
1320 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_FIELDS ), _( "Footprint Defaults" ) );
1322 _( "Graphics Defaults" ) );
1323
1325 expand.push_back( (int) book->GetPageCount() );
1326
1327 book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
1328 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTS ), _( "Display Options" ) );
1329 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_GRIDS ), _( "Grids" ) );
1330 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
1331 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
1332 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) );
1333
1334 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1335 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_TOOLBARS ), _( "Toolbars" ) );
1336
1337 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Plugins" ) );
1338
1340 expand.push_back( (int) book->GetPageCount() );
1341
1342 book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
1343 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
1344
1345 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1346 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_TOOLBARS ), _( "Toolbars" ) );
1347
1348 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
1349 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
1350 }
1351 catch( ... )
1352 {
1353 }
1354
1355 try
1356 {
1358
1359 if( !kiface )
1360 return;
1361
1362 kiface->GetActions( hotkeysPanel->ActionsList() );
1363
1364 if( GetFrameType() == FRAME_GERBER )
1365 expand.push_back( (int) book->GetPageCount() );
1366
1367 book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
1368 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
1369 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) );
1370
1371 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1372 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_TOOLBARS ), _( "Toolbars" ) );
1373
1374 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_GRIDS ), _( "Grids" ) );
1376 _( "Excellon Options" ) );
1377 }
1378 catch( ... )
1379 {
1380 }
1381
1382 try
1383 {
1385
1386 if( !kiface )
1387 return;
1388
1389 kiface->GetActions( hotkeysPanel->ActionsList() );
1390
1391 if( GetFrameType() == FRAME_PL_EDITOR )
1392 expand.push_back( (int) book->GetPageCount() );
1393
1394 book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
1395 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
1396 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_GRIDS ), _( "Grids" ) );
1397 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) );
1398
1399 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1400 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_TOOLBARS ), _( "Toolbars" ) );
1401
1402 book->AddLazyPage(
1403 []( wxWindow* aParent ) -> wxWindow*
1404 {
1405 return new PANEL_PACKAGES_AND_UPDATES( aParent );
1406 }, _( "Packages and Updates" ) );
1407 }
1408 catch( ... )
1409 {
1410 }
1411
1412#ifdef KICAD_IPC_API
1413 book->AddPage( new PANEL_PLUGIN_SETTINGS( book ), _( "Plugins" ) );
1414#endif
1415
1416 // Update all of the action hotkeys. The process of loading the actions through
1417 // the KiFACE will only get us the default hotkeys
1418 ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
1419
1420 for( size_t i = 0; i < book->GetPageCount(); ++i )
1421 book->GetPage( i )->Layout();
1422
1423 for( int page : expand )
1424 book->ExpandNode( page );
1425
1426 if( !aStartPage.IsEmpty() )
1427 dlg.SetInitialPage( aStartPage, aStartParentPage );
1428
1429 dlg.SetEvtHandlerEnabled( true );
1430#undef LAZY_CTOR
1431 }
1432
1433 if( dlg.ShowModal() == wxID_OK )
1434 {
1435 // Update our grids that are cached in the tool
1439 }
1440
1441}
1442
1443
1444void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
1445{
1446 wxString* files = aEvent.GetFiles();
1447
1448 for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
1449 {
1450 const wxFileName fn = wxFileName( files[nb] );
1451 wxString ext = fn.GetExt();
1452
1453 // Alias all gerber files as GerberFileExtension
1456
1457 if( m_acceptedExts.find( ext.ToStdString() ) != m_acceptedExts.end() )
1458 m_AcceptedFiles.emplace_back( fn );
1459 }
1460
1462 m_AcceptedFiles.clear();
1463}
1464
1465
1467{
1468 for( const wxFileName& file : m_AcceptedFiles )
1469 {
1470 wxString fn = file.GetFullPath();
1471 m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( file.GetExt() ), &fn );
1472 }
1473}
1474
1475
1476bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
1477{
1478 wxString msg;
1479 wxFileName fn = aFileName;
1480
1481 // Check for absence of a file path with a file name. Unfortunately KiCad
1482 // uses paths relative to the current project path without the ./ part which
1483 // confuses wxFileName. Making the file name path absolute may be less than
1484 // elegant but it solves the problem.
1485 if( fn.GetPath().IsEmpty() && fn.HasName() )
1486 fn.MakeAbsolute();
1487
1488 wxCHECK_MSG( fn.IsOk(), false,
1489 wxT( "File name object is invalid. Bad programmer!" ) );
1490 wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
1491 wxT( "File name object path <" ) + fn.GetFullPath() +
1492 wxT( "> is not set. Bad programmer!" ) );
1493
1494 if( fn.IsDir() && !fn.IsDirWritable() )
1495 {
1496 msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
1497 }
1498 else if( !fn.FileExists() && !fn.IsDirWritable() )
1499 {
1500 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1501 }
1502 else if( fn.FileExists() && !fn.IsFileWritable() )
1503 {
1504 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1505 }
1506
1507 if( !msg.IsEmpty() )
1508 {
1509 if( aVerbose )
1510 DisplayErrorMessage( this, msg );
1511
1512 return false;
1513 }
1514
1515 return true;
1516}
1517
1518
1519void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
1520{
1521 if( !Pgm().IsGUI() )
1522 return;
1523
1524 wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1525
1526 wxFileName autoSaveFileName = aFileName;
1527
1528 // Check for auto save file.
1529 autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
1530
1531 wxLogTrace( traceAutoSave,
1532 wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
1533
1534 if( !autoSaveFileName.FileExists() )
1535 return;
1536
1537 wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
1538 "It appears that the last time you were editing\n"
1539 "%s\n"
1540 "KiCad exited before saving.\n"
1541 "\n"
1542 "Do you wish to open the auto-saved file instead?" ),
1543 aFileName.GetFullName() );
1544
1545 int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1546 this );
1547
1548 // Make a backup of the current file, delete the file, and rename the auto save file to
1549 // the file name.
1550 if( response == wxYES )
1551 {
1552 // Preserve the permissions of the current file
1553 KIPLATFORM::IO::DuplicatePermissions( aFileName.GetFullPath(),
1554 autoSaveFileName.GetFullPath() );
1555
1556 if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
1557 {
1558 wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
1559 Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
1560 }
1561 }
1562 else
1563 {
1564 DeleteAutoSaveFile( aFileName );
1565 }
1566}
1567
1568
1569void EDA_BASE_FRAME::DeleteAutoSaveFile( const wxFileName& aFileName )
1570{
1571 if( !Pgm().IsGUI() )
1572 return;
1573
1574 wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1575
1576 wxFileName autoSaveFn = aFileName;
1577 autoSaveFn.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
1578
1579 if( autoSaveFn.FileExists() )
1580 {
1581 wxLogTrace( traceAutoSave, wxT( "Removing auto save file " ) + autoSaveFn.GetFullPath() );
1582 wxRemoveFile( autoSaveFn.GetFullPath() );
1583 }
1584}
1585
1586
1588{
1589 // This function should be overridden in child classes
1590 return false;
1591}
1592
1593
1595{
1596 wxAcceleratorEntry entries[1];
1597 entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
1598 wxAcceleratorTable accel( 1, entries );
1599 SetAcceleratorTable( accel );
1600}
1601
1602
1604{
1607}
1608
1609
1611{
1612 m_undoList.PushCommand( aNewitem );
1613
1614 // Delete the extra items, if count max reached
1615 if( m_undoRedoCountMax > 0 )
1616 {
1617 int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
1618
1619 if( extraitems > 0 )
1620 ClearUndoORRedoList( UNDO_LIST, extraitems );
1621 }
1622}
1623
1624
1626{
1627 m_redoList.PushCommand( aNewitem );
1628
1629 // Delete the extra items, if count max reached
1630 if( m_undoRedoCountMax > 0 )
1631 {
1632 int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
1633
1634 if( extraitems > 0 )
1635 ClearUndoORRedoList( REDO_LIST, extraitems );
1636 }
1637}
1638
1639
1641{
1642 return m_undoList.PopCommand();
1643}
1644
1645
1647{
1648 return m_redoList.PopCommand();
1649}
1650
1651
1653{
1654 if( GetUndoCommandCount() > 0 )
1655 return m_undoList.m_CommandsList.back()->GetDescription();
1656
1657 return wxEmptyString;
1658}
1659
1660
1662{
1663 if( GetRedoCommandCount() > 0 )
1664 return m_redoList.m_CommandsList.back()->GetDescription();
1665
1666 return wxEmptyString;
1667}
1668
1669
1671{
1672 m_autoSaveRequired = true;
1673}
1674
1675
1677{
1678 SetUserUnits( aUnits );
1680
1681 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
1682 e.SetInt( static_cast<int>( aUnits ) );
1683 e.SetClientData( this );
1684 ProcessEventLocally( e );
1685}
1686
1687
1688void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
1689{
1690 // When we maximize the window, we want to save the old information
1691 // so that we can add it to the settings on next window load.
1692 // Contrary to the documentation, this event seems to be generated
1693 // when the window is also being unmaximized on OSX, so we only
1694 // capture the size information when we maximize the window when on OSX.
1695#ifdef __WXOSX__
1696 if( !IsMaximized() )
1697#endif
1698 {
1700 m_normalFramePos = GetPosition();
1701 wxLogTrace( traceDisplayLocation,
1702 "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
1705 }
1706
1707 // Skip event to actually maximize the window
1708 aEvent.Skip();
1709}
1710
1711
1713{
1714#ifdef __WXGTK__
1715 wxSize winSize = GetSize();
1716
1717 // GTK includes the window decorations in the normal GetSize call,
1718 // so we have to use a GTK-specific sizing call that returns the
1719 // non-decorated window size.
1721 {
1722 int width = 0;
1723 int height = 0;
1724 GTKDoGetSize( &width, &height );
1725
1726 winSize.Set( width, height );
1727 }
1728#else
1729 wxSize winSize = GetSize();
1730#endif
1731
1732 return winSize;
1733}
1734
1735
1737{
1738 // Update the icon theme when the system theme changes and update the toolbars
1740 ThemeChanged();
1741
1742 // This isn't handled by ThemeChanged()
1743 if( GetMenuBar() )
1744 {
1745 // For icons in menus, icon scaling & hotkeys
1747 GetMenuBar()->Refresh();
1748 }
1749}
1750
1751
1752void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
1753{
1754 // Call the handler to update the colors used in the frame
1756
1757 // Skip the change event to ensure the rest of the window controls get it
1758 aEvent.Skip();
1759}
1760
1761
1762void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
1763{
1764 // Call the handler
1765 handleIconizeEvent( aEvent );
1766
1767 // Skip the event.
1768 aEvent.Skip();
1769}
1770
1771
1772#ifdef __WXMSW__
1773WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
1774{
1775 // This will help avoid the menu keeping focus when the alt key is released
1776 // You can still trigger accelerators as long as you hold down alt
1777 if( message == WM_SYSCOMMAND )
1778 {
1779 if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
1780 return 0;
1781 }
1782
1783 return wxFrame::MSWWindowProc( message, wParam, lParam );
1784}
1785#endif
1786
1787
1789{
1790 ACTION_MENU* langsMenu = new ACTION_MENU( false, aControlTool );
1791 langsMenu->SetTitle( _( "Set Language" ) );
1792 langsMenu->SetIcon( BITMAPS::language );
1793
1794 wxString tooltip;
1795
1796 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
1797 {
1798 wxString label;
1799
1800 if( LanguagesList[ii].m_DoNotTranslate )
1801 label = LanguagesList[ii].m_Lang_Label;
1802 else
1803 label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
1804
1805 wxMenuItem* item =
1806 new wxMenuItem( langsMenu,
1807 LanguagesList[ii].m_KI_Lang_Identifier, // wxMenuItem wxID
1808 label, tooltip, wxITEM_CHECK );
1809
1810 langsMenu->Append( item );
1811 }
1812
1813 // This must be done after the items are added
1814 aMasterMenu->Add( langsMenu );
1815}
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
const char * name
Definition: DXF_plotter.cpp:62
std::function< void(ACTION_TOOLBAR *)> ACTION_TOOLBAR_CONTROL_FACTORY
Type for the function signature that is used to add custom controls to the toolbar.
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:172
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:92
static TOOL_ACTION paste
Definition: actions.h:80
static TOOL_ACTION about
Definition: actions.h:283
static TOOL_ACTION reportBug
Definition: actions.h:287
static TOOL_ACTION copy
Definition: actions.h:78
static TOOL_ACTION donate
Definition: actions.h:285
static TOOL_ACTION listHotKeys
Definition: actions.h:284
static TOOL_ACTION getInvolved
Definition: actions.h:286
static TOOL_ACTION undo
Definition: actions.h:75
static TOOL_ACTION redo
Definition: actions.h:76
static TOOL_ACTION cut
Definition: actions.h:77
static TOOL_ACTION gettingStarted
Definition: actions.h:281
static TOOL_ACTION help
Definition: actions.h:282
Manage TOOL_ACTION objects.
const std::map< std::string, TOOL_ACTION * > & GetActions() const
Get a list of currently-registered actions mapped by their name.
Define the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:92
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:78
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
Class to hold basic information about controls that can be added to the toolbars.
const std::string & GetName() const
Define the structure of a toolbar with buttons that invoke ACTIONs.
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void UpdateControlWidths()
Update the width of all wxControl tools on thsi toolbar.
void ApplyConfiguration(const TOOLBAR_CONFIGURATION &aConfig)
Replace the contents of this toolbar with the configuration given in aConfig.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
WINDOW_SETTINGS m_Window
Definition: app_settings.h:232
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:52
int ShowModal() override
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
Return 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
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
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 OnToolbarSizeChanged()
Update toolbars if desired toolbar icon changed.
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()
bool m_isNonUserClose
Set by NonUserClose() to indicate that the user did not request the current close.
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 UpdateToolbarControlSizes()
Update the sizes of any controls in the toolbars of the frame.
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)
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars.
ACTION_TOOLBAR * m_tbRight
void ShowPreferences(wxString aStartPage, wxString aStartParentPage)
Display the preferences and settings of all opened editors paged dialog, starting with a particular p...
void initExitKey()
Set the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
void OnPreferences(wxCommandEvent &event)
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.
virtual wxString GetRedoActionDescription() const
TOOLBAR_SETTINGS * m_toolbarSettings
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 AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Create a menu list for language choice, and add it as submenu to MasterMenu.
void RegisterCustomToolbarControlFactory(const ACTION_TOOLBAR_CONTROL &aControlDesc, const ACTION_TOOLBAR_CONTROL_FACTORY &aControlFactory)
Register a creation factory for toolbar controls that are present in this frame.
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...
virtual void configureToolbars()
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.
virtual void RecreateToolbars()
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Remove all files from the file history.
std::map< int, UIUpdateHandler > m_uiUpdateMap
Map containing the UI update handlers registered with wx for each action.
std::map< std::string, ACTION_TOOLBAR_CONTROL_FACTORY > m_toolbarControlFactories
ACTION_TOOLBAR_CONTROL_FACTORY * GetCustomToolbarControlFactory(const std::string &aName)
UNDO_REDO_CONTAINER m_redoList
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
FILE_HISTORY * m_fileHistory
ACTION_TOOLBAR * m_tbLeft
virtual void DeleteAutoSaveFile(const wxFileName &aFileName)
virtual void OnSize(wxSizeEvent &aEvent)
virtual wxString GetUndoActionDescription() const
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)
Check if aFileName can be written.
wxPoint m_normalFramePos
void OnMaximize(wxMaximizeEvent &aEvent)
ACTION_TOOLBAR * m_tbTopAux
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
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)
Fetch the file name from the file history list.
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.
ACTION_TOOLBAR * m_tbTopMain
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 the close window event handler after frames are asked if they can close.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Add the standard KiCad help menu to the menubar.
wxString m_mruPath
void ReCreateMenuBar()
Recreate 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.
The main KiCad project manager frame.
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_base.h:116
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
void GetActions(std::vector< TOOL_ACTION * > &aActions) const override
Append this Kiface's registered actions to the given list.
Definition: kiface_base.h:118
const wxString & GetHelpFileName() const
Return just the basename portion of the current help file.
Definition: kiface_base.h:112
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
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:55
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:201
@ FACE_SCH
eeschema DSO
Definition: kiway.h:292
@ FACE_PL_EDITOR
Definition: kiway.h:296
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
@ FACE_GERBVIEW
Definition: kiway.h:295
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:617
WX_TREEBOOK * GetTreebook()
Definition: paged_dialog.h:39
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
std::vector< TOOL_ACTION * > & ActionsList()
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:143
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:687
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:229
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
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:209
Look for files in a number of paths.
Definition: search_stack.h:43
std::optional< TOOLBAR_CONFIGURATION > GetToolbarConfig(TOOLBAR_LOC aToolbar, bool aAllowCustom=true)
Get the tools to show on the specified canvas toolbar.
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
virtual void CommonSettingsChanged(int aFlags=0)
Notification event that some of the common (suite-wide) settings have changed.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
virtual void ShowChangedLanguage()
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:173
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:98
int GetUIId() const
Get the unique ID for this action in the user interface system.
Definition: tool_action.h:374
@ REDRAW
Full drawing refresh.
Definition: tool_base.h:83
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, 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 PushCommand(PICKED_ITEMS_LIST *aCommand)
PICKED_ITEMS_LIST * PopCommand()
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
void SetUserUnits(EDA_UNITS aUnits)
Simple wrapper around wxBusyCursor for used with the generic BUSY_INDICATOR interface.
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:76
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:353
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:140
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: wx_infobar.h:94
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:190
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:343
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:160
bool AddLazyPage(std::function< wxWindow *(wxWindow *aParent)> aLazyCtor, const wxString &text, bool bSelect=false, int imageId=NO_IMAGE)
Definition: wx_treebook.cpp:89
bool AddLazySubPage(std::function< wxWindow *(wxWindow *aParent)> aLazyCtor, const wxString &text, bool bSelect=false, int imageId=NO_IMAGE)
Definition: wx_treebook.cpp:96
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
This file is part of the common library.
const int minSize
Push and Shove router track width and via size dialog.
#define _(s)
static const wxSize minSizeLookup(FRAME_T aFrameType, wxWindow *aWindow)
#define LAZY_CTOR(key)
static const wxSize defaultSize(FRAME_T aFrameType, wxWindow *aWindow)
wxWindow * findQuasiModalDialog(wxWindow *aParent)
Base window classes and related definitions.
#define KICAD_MANAGER_FRAME_NAME
#define DEFAULT_MAX_UNDO_ITEMS
std::function< void(wxUpdateUIEvent &) > UIUpdateHandler
This is the handler functor for the update UI events.
void SocketCleanup()
Must be called to clean up the socket thread used by SendCommand.
Definition: eda_dde.cpp:319
DDE server & client.
EDA_UNITS
Definition: eda_units.h:48
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ PANEL_PCB_GRIDS
Definition: frame_type.h:97
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
@ PANEL_SYM_EDIT_GRIDS
Definition: frame_type.h:73
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ PANEL_3DV_TOOLBARS
Definition: frame_type.h:107
@ PANEL_SCH_FIELD_NAME_TEMPLATES
Definition: frame_type.h:84
@ PANEL_DS_TOOLBARS
Definition: frame_type.h:119
@ PANEL_SCH_TOOLBARS
Definition: frame_type.h:83
@ PANEL_GBR_DISPLAY_OPTIONS
Definition: frame_type.h:109
@ PANEL_3DV_OPENGL
Definition: frame_type.h:105
@ PANEL_FP_DEFAULT_GRAPHICS_VALUES
Definition: frame_type.h:93
@ PANEL_PCB_TOOLBARS
Definition: frame_type.h:100
@ PANEL_PCB_ORIGINS_AXES
Definition: frame_type.h:102
@ PANEL_PCB_EDIT_OPTIONS
Definition: frame_type.h:98
@ PANEL_SCH_DISP_OPTIONS
Definition: frame_type.h:78
@ PANEL_FP_DISPLAY_OPTIONS
Definition: frame_type.h:87
@ PANEL_SCH_SIMULATOR
Definition: frame_type.h:85
@ FRAME_SCH
Definition: frame_type.h:34
@ PANEL_DS_COLORS
Definition: frame_type.h:118
@ PANEL_PCB_COLORS
Definition: frame_type.h:99
@ PANEL_SYM_TOOLBARS
Definition: frame_type.h:76
@ PANEL_3DV_RAYTRACING
Definition: frame_type.h:106
@ PANEL_SYM_EDIT_OPTIONS
Definition: frame_type.h:74
@ PANEL_FP_GRIDS
Definition: frame_type.h:88
@ PANEL_SCH_EDIT_OPTIONS
Definition: frame_type.h:80
@ PANEL_FP_ORIGINS_AXES
Definition: frame_type.h:94
@ PANEL_SYM_DISP_OPTIONS
Definition: frame_type.h:72
@ PANEL_PCB_DISPLAY_OPTS
Definition: frame_type.h:96
@ PANEL_FP_COLORS
Definition: frame_type.h:90
@ PANEL_FP_DEFAULT_FIELDS
Definition: frame_type.h:92
@ PANEL_SYM_COLORS
Definition: frame_type.h:75
@ FRAME_PL_EDITOR
Definition: frame_type.h:59
@ PANEL_GBR_GRIDS
Definition: frame_type.h:112
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
@ FRAME_GERBER
Definition: frame_type.h:57
@ PANEL_DS_GRIDS
Definition: frame_type.h:117
@ FRAME_PCB_DISPLAY3D
Definition: frame_type.h:47
@ PANEL_GBR_TOOLBARS
Definition: frame_type.h:114
@ PANEL_FP_EDIT_OPTIONS
Definition: frame_type.h:89
@ PANEL_SCH_ANNO_OPTIONS
Definition: frame_type.h:81
@ PANEL_SCH_GRIDS
Definition: frame_type.h:79
@ PANEL_FP_TOOLBARS
Definition: frame_type.h:91
@ PANEL_PCB_ACTION_PLUGINS
Definition: frame_type.h:101
@ PANEL_3DV_DISPLAY_OPTIONS
Definition: frame_type.h:104
@ PANEL_DS_DISPLAY_OPTIONS
Definition: frame_type.h:116
@ PANEL_SCH_COLORS
Definition: frame_type.h:82
@ PANEL_GBR_COLORS
Definition: frame_type.h:113
@ PANEL_GBR_EXCELLON_OPTIONS
Definition: frame_type.h:111
@ KICAD_MAIN_FRAME_T
Definition: frame_type.h:68
static const std::string GerberFileExtension
static const std::string AutoSaveFilePrefix
static bool IsGerberFileExtension(const wxString &ext)
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
const wxChar *const traceDisplayLocation
Flag to enable debug output of display positioning logic.
void ReadHotKeyConfigIntoActions(const wxString &aFileName, std::vector< TOOL_ACTION * > &aActions)
Read a hotkey config file into a list of actions.
Common command IDs shared by more than one of the KiCad applications.
@ ID_FILE_LIST_CLEAR
Definition: id.h:84
@ ID_FILE1
Definition: id.h:81
@ ID_AUTO_SAVE_TIMER
Definition: id.h:76
void RemoveShutdownBlockReason(wxWindow *aWindow)
Removes any shutdown block reason set.
Definition: unix/app.cpp:85
bool DuplicatePermissions(const wxString &aSrc, const wxString &aDest)
Duplicates the file security data from one file to another ensuring that they are the same between bo...
Definition: unix/io.cpp:47
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1071
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:95
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
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:152
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:74
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:77
struct WINDOW_STATE window
Store the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:90
WINDOW_STATE state
Definition: app_settings.h:91
wxString mru_path
Definition: app_settings.h:92
wxString perspective
Definition: app_settings.h:93
Store the window positioning/state.
Definition: app_settings.h:77
unsigned int display
Definition: app_settings.h:83
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
#define HOTKEYS_CHANGED
Definition: tools_holder.h:154
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.