KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <stambaughw@gmail.com>
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::SetMenuBar( wxMenuBar* menu_bar )
643{
644 wxFrame::SetMenuBar( menu_bar );
645
646 // Move Help menu back to end of menubar
647
648 int pos = GetMenuBar()->FindMenu( _( "&Help" ) + wxS( " " ) );
649
650 if( pos != wxNOT_FOUND )
651 {
652 wxMenu* helpMenu = GetMenuBar()->Remove( pos );
653 GetMenuBar()->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
654 }
655}
656
657
658void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
659{
661 ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
662
663 helpMenu->Add( ACTIONS::help );
664 helpMenu->Add( ACTIONS::gettingStarted );
665 helpMenu->Add( ACTIONS::listHotKeys );
666 helpMenu->Add( ACTIONS::getInvolved );
667 helpMenu->Add( ACTIONS::donate );
668 helpMenu->Add( ACTIONS::reportBug );
669
670 helpMenu->AppendSeparator();
671 helpMenu->Add( ACTIONS::about );
672
673 // Trailing space keeps OSX from hijacking our menu (and disabling everything in it).
674 aMenuBar->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
675
676 // This change is only needed on macOS, and creates a bug on Windows
677 #ifdef __WXMAC__
678 helpMenu->wxMenu::SetTitle( _( "&Help" ) + wxS( " " ) );
679 #endif
680}
681
682
684{
686
687 if( GetMenuBar() )
688 {
690 GetMenuBar()->Refresh();
691 }
692}
693
694
696{
698
699 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
700
701#ifdef KICAD_IPC_API
702 bool running = Pgm().GetApiServer().Running();
703
704 if( running && !settings->m_Api.enable_server )
705 Pgm().GetApiServer().Stop();
706 else if( !running && settings->m_Api.enable_server )
707 Pgm().GetApiServer().Start();
708#endif
709
710 if( m_fileHistory )
711 {
712 int historySize = settings->m_System.file_history_size;
713 m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
714 }
715
717 ThemeChanged();
718
719 if( GetMenuBar() )
720 {
721 // For icons in menus, icon scaling & hotkeys
723 GetMenuBar()->Refresh();
724 }
725
726 // Update the toolbars
728}
729
730
732{
734
735 // Update all the toolbars to have new icons
736 wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
737
738 for( size_t i = 0; i < panes.GetCount(); ++i )
739 {
740 if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
741 toolbar->RefreshBitmaps();
742 }
743}
744
745
746void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
747{
748#ifdef __WXMAC__
749 int currentDisplay = wxDisplay::GetFromWindow( this );
750
751 if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
752 {
753 wxLogTrace( traceDisplayLocation, wxS( "OnSize: current display changed %d to %d" ),
754 m_displayIndex, currentDisplay );
755 m_displayIndex = currentDisplay;
757 }
758#endif
759
760 aEvent.Skip();
761}
762
763
764void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
765{
766 if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
767 return;
768
769 const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
770
771 if( state != nullptr )
772 {
773 LoadWindowState( state->window );
774 }
775}
776
777
779{
780 bool wasDefault = false;
781
782 m_framePos.x = aState.pos_x;
783 m_framePos.y = aState.pos_y;
784 m_frameSize.x = aState.size_x;
785 m_frameSize.y = aState.size_y;
786
787 wxLogTrace( traceDisplayLocation, wxS( "Config position (%d, %d) with size (%d, %d)" ),
789
790 // Ensure minimum size is set if the stored config was zero-initialized
791 wxSize minSize = minSizeLookup( m_ident, this );
792
793 if( m_frameSize.x < minSize.x || m_frameSize.y < minSize.y )
794 {
796 wasDefault = true;
797
798 wxLogTrace( traceDisplayLocation, wxS( "Using minimum size (%d, %d)" ),
800 }
801
802 wxLogTrace( traceDisplayLocation, wxS( "Number of displays: %d" ), wxDisplay::GetCount() );
803
804 if( aState.display >= wxDisplay::GetCount() )
805 {
806 wxLogTrace( traceDisplayLocation, wxS( "Previous display not found" ) );
807
808 // If it isn't attached, use the first display
809 // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
810 const unsigned int index = 0;
811 wxDisplay display( index );
812 wxRect clientSize = display.GetGeometry();
813
814 m_framePos = wxDefaultPosition;
815
816 // Ensure the window fits on the display, since the other one could have been larger
817 if( m_frameSize.x > clientSize.width )
818 m_frameSize.x = clientSize.width;
819
820 if( m_frameSize.y > clientSize.height )
821 m_frameSize.y = clientSize.height;
822 }
823 else
824 {
825 wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
826 wxPoint upperLeft( m_framePos.x, m_framePos.y );
827
828 wxDisplay display( aState.display );
829 wxRect clientSize = display.GetClientArea();
830
831 int yLimTop = clientSize.y;
832 int yLimBottom = clientSize.y + clientSize.height;
833 int xLimLeft = clientSize.x;
834 int xLimRight = clientSize.x + clientSize.width;
835
836 if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
837 upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
838 upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
839 upperLeft.y > yLimBottom )
840 {
841 m_framePos = wxDefaultPosition;
842 wxLogTrace( traceDisplayLocation, wxS( "Resetting to default position" ) );
843 }
844 }
845
846 wxLogTrace( traceDisplayLocation, wxS( "Final window position (%d, %d) with size (%d, %d)" ),
848
849 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
850
851 // Center the window if we reset to default
852 if( m_framePos.x == -1 )
853 {
854 wxLogTrace( traceDisplayLocation, wxS( "Centering window" ) );
855 Center();
856 m_framePos = GetPosition();
857 }
858
859 // Record the frame sizes in an un-maximized state
862
863 // Maximize if we were maximized before
864 if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
865 {
866 wxLogTrace( traceDisplayLocation, wxS( "Maximizing window" ) );
867 Maximize();
868 }
869
870 m_displayIndex = wxDisplay::GetFromWindow( this );
871}
872
873
875{
876 wxDisplay display( wxDisplay::GetFromWindow( this ) );
877 wxRect clientSize = display.GetClientArea();
878 wxPoint pos = GetPosition();
879 wxSize size = GetWindowSize();
880
881 wxLogTrace( traceDisplayLocation,
882 wxS( "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d" ),
883 clientSize.x, clientSize.y,
884 clientSize.width, clientSize.height );
885
886 if( pos.y < clientSize.y )
887 {
888 wxLogTrace( traceDisplayLocation,
889 wxS( "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d" ), pos.y,
890 clientSize.y );
891 pos.y = clientSize.y;
892 }
893
894 if( pos.x < clientSize.x )
895 {
896 wxLogTrace( traceDisplayLocation,
897 wxS( "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d" ),
898 pos.x, clientSize.x );
899 pos.x = clientSize.x;
900 }
901
902 if( pos.x + size.x - clientSize.x > clientSize.width )
903 {
904 int newWidth = clientSize.width - ( pos.x - clientSize.x );
905 wxLogTrace( traceDisplayLocation,
906 wxS( "ensureWindowIsOnScreen: effective width %d above available %d, setting "
907 "to %d" ), pos.x + size.x, clientSize.width, newWidth );
908 size.x = newWidth;
909 }
910
911 if( pos.y + size.y - clientSize.y > clientSize.height )
912 {
913 int newHeight = clientSize.height - ( pos.y - clientSize.y );
914 wxLogTrace( traceDisplayLocation,
915 wxS( "ensureWindowIsOnScreen: effective height %d above available %d, setting "
916 "to %d" ), pos.y + size.y, clientSize.height, newHeight );
917 size.y = newHeight;
918 }
919
920 wxLogTrace( traceDisplayLocation, wxS( "Updating window position (%d, %d) with size (%d, %d)" ),
921 pos.x, pos.y, size.x, size.y );
922
923 SetSize( pos.x, pos.y, size.x, size.y );
924}
925
926
928{
929 LoadWindowState( aCfg->state );
930
932 m_mruPath = aCfg->mru_path;
933
935}
936
937
939{
940 if( IsIconized() )
941 return;
942
943 // If the window is maximized, we use the saved window size from before it was maximized
944 if( IsMaximized() )
945 {
948 }
949 else
950 {
952 m_framePos = GetPosition();
953 }
954
955 aCfg->state.pos_x = m_framePos.x;
956 aCfg->state.pos_y = m_framePos.y;
957 aCfg->state.size_x = m_frameSize.x;
958 aCfg->state.size_y = m_frameSize.y;
959 aCfg->state.maximized = IsMaximized();
960 aCfg->state.display = wxDisplay::GetFromWindow( this );
961
962 wxLogTrace( traceDisplayLocation, wxS( "Saving window maximized: %s" ),
963 IsMaximized() ? wxS( "true" ) : wxS( "false" ) );
964 wxLogTrace( traceDisplayLocation, wxS( "Saving config position (%d, %d) with size (%d, %d)" ),
966
967 // Once this is fully implemented, wxAuiManager will be used to maintain
968 // the persistence of the main frame and all it's managed windows and
969 // all of the legacy frame persistence position code can be removed.
970 aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
971
972 aCfg->mru_path = m_mruPath;
973}
974
975
977{
979
980 // Get file history size from common settings
981 int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
982
983 // Load the recently used files into the history menu
984 m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 1, fileHistorySize ),
986 m_fileHistory->Load( *aCfg );
987}
988
989
991{
992 wxCHECK( config(), /* void */ );
993
995
996 bool fileOpen = m_isClosing && m_isNonUserClose;
997
998 wxString currentlyOpenedFile = GetCurrentFileName();
999
1000 if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
1001 {
1002 wxFileName rfn( currentlyOpenedFile );
1003 rfn.MakeRelativeTo( Prj().GetProjectPath() );
1004 Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
1005 }
1006
1007 // Save the recently used files list
1008 if( m_fileHistory )
1009 {
1010 // Save the currently opened file in the file history
1011 if( !currentlyOpenedFile.IsEmpty() )
1012 UpdateFileHistory( currentlyOpenedFile );
1013
1014 m_fileHistory->Save( *aCfg );
1015 }
1016}
1017
1018
1020{
1021 return &aCfg->m_Window;
1022}
1023
1024
1026{
1027 // KICAD_MANAGER_FRAME overrides this
1028 return Kiface().KifaceSettings();
1029}
1030
1031
1033{
1034 return Kiface().KifaceSearch();
1035}
1036
1037
1039{
1040 return Kiface().GetHelpFileName();
1041}
1042
1043
1044void EDA_BASE_FRAME::PrintMsg( const wxString& text )
1045{
1046 SetStatusText( text );
1047}
1048
1049
1051{
1052#if defined( __WXOSX_MAC__ )
1054#else
1055 m_infoBar = new WX_INFOBAR( this, &m_auimgr );
1056
1057 m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) ).Top().Layer(1) );
1058#endif
1059}
1060
1061
1063{
1064#if defined( __WXOSX_MAC__ )
1065 m_auimgr.Update();
1066#else
1067 // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
1068 // hiding it.
1069 m_auimgr.Update();
1070
1071 // We don't want the infobar displayed right away
1072 m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
1073 m_auimgr.Update();
1074#endif
1075}
1076
1077
1078void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
1080{
1082
1083 if( aShowCloseButton )
1085
1086 GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
1087}
1088
1089
1090void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
1091 std::function<void(void)> aCallback )
1092{
1094
1095 if( aShowCloseButton )
1097
1098 if( aCallback )
1099 m_infoBar->SetCallback( aCallback );
1100
1101 GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
1102}
1103
1104
1105void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
1106{
1108
1109 if( aShowCloseButton )
1111
1112 GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
1113}
1114
1115
1116void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
1117{
1119
1120 if( aShowCloseButton )
1122
1123 GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
1124}
1125
1126
1127void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
1128{
1129 if( !aFileHistory )
1130 aFileHistory = m_fileHistory;
1131
1132 wxASSERT( aFileHistory );
1133
1134 aFileHistory->AddFileToHistory( FullFileName );
1135
1136 // Update the menubar to update the file history menu
1137 if( !m_isClosing && GetMenuBar() )
1138 {
1140 GetMenuBar()->Refresh();
1141 }
1142}
1143
1144
1145wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
1146 FILE_HISTORY* aFileHistory )
1147{
1148 if( !aFileHistory )
1149 aFileHistory = m_fileHistory;
1150
1151 wxASSERT( aFileHistory );
1152
1153 int baseId = aFileHistory->GetBaseId();
1154
1155 wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
1156
1157 unsigned i = cmdId - baseId;
1158
1159 if( i < aFileHistory->GetCount() )
1160 {
1161 wxString fn = aFileHistory->GetHistoryFile( i );
1162
1163 if( wxFileName::FileExists( fn ) )
1164 {
1165 return fn;
1166 }
1167 else
1168 {
1169 DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
1170 aFileHistory->RemoveFileFromHistory( i );
1171 }
1172 }
1173
1174 // Update the menubar to update the file history menu
1175 if( GetMenuBar() )
1176 {
1178 GetMenuBar()->Refresh();
1179 }
1180
1181 return wxEmptyString;
1182}
1183
1184
1186{
1187 if( !aFileHistory )
1188 aFileHistory = m_fileHistory;
1189
1190 wxASSERT( aFileHistory );
1191
1192 aFileHistory->ClearFileHistory();
1193
1194 // Update the menubar to update the file history menu
1195 if( GetMenuBar() )
1196 {
1198 GetMenuBar()->Refresh();
1199 }
1200}
1201
1202
1203void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
1204{
1205 void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
1206 ShowAboutDialog( this );
1207}
1208
1209
1210void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
1211{
1212 ShowPreferences( wxEmptyString, wxEmptyString );
1213}
1214
1215
1216void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParentPage )
1217{
1218 PAGED_DIALOG dlg( this, _( "Preferences" ), true, true, wxEmptyString,
1219 wxWindow::FromDIP( wxSize( 980, 560 ), NULL ) );
1220
1221 dlg.SetEvtHandlerEnabled( false );
1222
1223 {
1224 WX_BUSY_INDICATOR busy_cursor;
1225
1226 WX_TREEBOOK* book = dlg.GetTreebook();
1227 PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
1228 KIFACE* kiface = nullptr;
1229 std::vector<int> expand;
1230
1231 wxWindow* kicadMgr_window = wxWindow::FindWindowByName( KICAD_MANAGER_FRAME_NAME );
1232
1233 if( KICAD_MANAGER_FRAME* kicadMgr = static_cast<KICAD_MANAGER_FRAME*>( kicadMgr_window ) )
1234 {
1235 ACTION_MANAGER* actionMgr = kicadMgr->GetToolManager()->GetActionManager();
1236
1237 for( const auto& [name, action] : actionMgr->GetActions() )
1238 hotkeysPanel->ActionsList().push_back( action );
1239 }
1240
1241 book->AddLazyPage(
1242 []( wxWindow* aParent ) -> wxWindow*
1243 {
1244 return new PANEL_COMMON_SETTINGS( aParent );
1245 },
1246 _( "Common" ) );
1247
1248 book->AddLazyPage(
1249 []( wxWindow* aParent ) -> wxWindow*
1250 {
1251 return new PANEL_MOUSE_SETTINGS( aParent );
1252 }, _( "Mouse and Touchpad" ) );
1253
1254 book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
1255
1256 book->AddLazyPage(
1257 []( wxWindow* aParent ) -> wxWindow*
1258 {
1259 return new PANEL_GIT_REPOS( aParent );
1260 }, _( "Version Control" ) );
1261
1262#ifdef KICAD_USE_SENTRY
1263 book->AddLazyPage(
1264 []( wxWindow* aParent ) -> wxWindow*
1265 {
1266 return new PANEL_DATA_COLLECTION( aParent );
1267 }, _( "Data Collection" ) );
1268#endif
1269
1270#define LAZY_CTOR( key ) \
1271 [this, kiface]( wxWindow* aParent ) \
1272 { \
1273 return kiface->CreateKiWindow( aParent, key, &Kiway() ); \
1274 }
1275
1276 // If a dll is not loaded, the loader will show an error message.
1277
1278 try
1279 {
1281
1282 if( !kiface )
1283 return;
1284
1285 kiface->GetActions( hotkeysPanel->ActionsList() );
1286
1288 expand.push_back( (int) book->GetPageCount() );
1289
1290 book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
1291 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
1292 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_GRIDS ), _( "Grids" ) );
1293 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
1294 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) );
1295
1296 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1297 book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_TOOLBARS ), _( "Toolbars" ) );
1298
1299 if( GetFrameType() == FRAME_SCH )
1300 expand.push_back( (int) book->GetPageCount() );
1301
1302 book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
1303 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
1304 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_GRIDS ), _( "Grids" ) );
1305 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
1306 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) );
1307 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_COLORS ), _( "Colors" ) );
1308
1309 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1310 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_TOOLBARS ), _( "Toolbars" ) );
1311
1313 _( "Field Name Templates" ) );
1314 book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_SIMULATOR ), _( "Simulator" ) );
1315 }
1316 catch( ... )
1317 {
1318 }
1319
1320 try
1321 {
1323
1324 if( !kiface )
1325 return;
1326
1327 kiface->GetActions( hotkeysPanel->ActionsList() );
1328
1330 expand.push_back( (int) book->GetPageCount() );
1331
1332 book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
1333 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
1334 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_GRIDS ), _( "Grids" ) );
1335 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_ORIGINS_AXES ), _( "Origins & Axes" ) );
1336 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
1337 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) );
1338
1339 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1340 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_TOOLBARS ), _( "Toolbars" ) );
1341
1342 book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_FIELDS ), _( "Footprint Defaults" ) );
1344 _( "Graphics Defaults" ) );
1345
1347 expand.push_back( (int) book->GetPageCount() );
1348
1349 book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
1350 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTS ), _( "Display Options" ) );
1351 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_GRIDS ), _( "Grids" ) );
1352 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
1353 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
1354 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) );
1355
1356 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1357 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_TOOLBARS ), _( "Toolbars" ) );
1358
1359 book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Plugins" ) );
1360
1362 expand.push_back( (int) book->GetPageCount() );
1363
1364 book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
1365 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
1366
1367 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1368 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_TOOLBARS ), _( "Toolbars" ) );
1369
1370 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
1371 book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
1372 }
1373 catch( ... )
1374 {
1375 }
1376
1377 try
1378 {
1380
1381 if( !kiface )
1382 return;
1383
1384 kiface->GetActions( hotkeysPanel->ActionsList() );
1385
1386 if( GetFrameType() == FRAME_GERBER )
1387 expand.push_back( (int) book->GetPageCount() );
1388
1389 book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
1390 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
1391 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) );
1392
1393 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1394 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_TOOLBARS ), _( "Toolbars" ) );
1395
1396 book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_GRIDS ), _( "Grids" ) );
1398 _( "Excellon Options" ) );
1399 }
1400 catch( ... )
1401 {
1402 }
1403
1404 try
1405 {
1407
1408 if( !kiface )
1409 return;
1410
1411 kiface->GetActions( hotkeysPanel->ActionsList() );
1412
1413 if( GetFrameType() == FRAME_PL_EDITOR )
1414 expand.push_back( (int) book->GetPageCount() );
1415
1416 book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
1417 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
1418 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_GRIDS ), _( "Grids" ) );
1419 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) );
1420
1421 if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
1422 book->AddLazySubPage( LAZY_CTOR( PANEL_DS_TOOLBARS ), _( "Toolbars" ) );
1423
1424 book->AddLazyPage(
1425 []( wxWindow* aParent ) -> wxWindow*
1426 {
1427 return new PANEL_PACKAGES_AND_UPDATES( aParent );
1428 }, _( "Packages and Updates" ) );
1429 }
1430 catch( ... )
1431 {
1432 }
1433
1434#ifdef KICAD_IPC_API
1435 book->AddPage( new PANEL_PLUGIN_SETTINGS( book ), _( "Plugins" ) );
1436#endif
1437
1438 // Update all of the action hotkeys. The process of loading the actions through
1439 // the KiFACE will only get us the default hotkeys
1440 ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
1441
1442 for( size_t i = 0; i < book->GetPageCount(); ++i )
1443 book->GetPage( i )->Layout();
1444
1445 for( int page : expand )
1446 book->ExpandNode( page );
1447
1448 if( !aStartPage.IsEmpty() )
1449 dlg.SetInitialPage( aStartPage, aStartParentPage );
1450
1451 dlg.SetEvtHandlerEnabled( true );
1452#undef LAZY_CTOR
1453 }
1454
1455 if( dlg.ShowModal() == wxID_OK )
1456 {
1457 // Update our grids that are cached in the tool
1461 }
1462
1463}
1464
1465
1466void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
1467{
1468 wxString* files = aEvent.GetFiles();
1469
1470 for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
1471 {
1472 const wxFileName fn = wxFileName( files[nb] );
1473 wxString ext = fn.GetExt();
1474
1475 // Alias all gerber files as GerberFileExtension
1478
1479 if( m_acceptedExts.find( ext.ToStdString() ) != m_acceptedExts.end() )
1480 m_AcceptedFiles.emplace_back( fn );
1481 }
1482
1484 m_AcceptedFiles.clear();
1485}
1486
1487
1489{
1490 for( const wxFileName& file : m_AcceptedFiles )
1491 {
1492 wxString fn = file.GetFullPath();
1493 m_toolManager->RunAction<wxString*>( *m_acceptedExts.at( file.GetExt() ), &fn );
1494 }
1495}
1496
1497
1498bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
1499{
1500 wxString msg;
1501 wxFileName fn = aFileName;
1502
1503 // Check for absence of a file path with a file name. Unfortunately KiCad
1504 // uses paths relative to the current project path without the ./ part which
1505 // confuses wxFileName. Making the file name path absolute may be less than
1506 // elegant but it solves the problem.
1507 if( fn.GetPath().IsEmpty() && fn.HasName() )
1508 fn.MakeAbsolute();
1509
1510 wxCHECK_MSG( fn.IsOk(), false,
1511 wxT( "File name object is invalid. Bad programmer!" ) );
1512 wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
1513 wxT( "File name object path <" ) + fn.GetFullPath() +
1514 wxT( "> is not set. Bad programmer!" ) );
1515
1516 if( fn.IsDir() && !fn.IsDirWritable() )
1517 {
1518 msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
1519 }
1520 else if( !fn.FileExists() && !fn.IsDirWritable() )
1521 {
1522 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1523 }
1524 else if( fn.FileExists() && !fn.IsFileWritable() )
1525 {
1526 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
1527 }
1528
1529 if( !msg.IsEmpty() )
1530 {
1531 if( aVerbose )
1532 DisplayErrorMessage( this, msg );
1533
1534 return false;
1535 }
1536
1537 return true;
1538}
1539
1540
1541void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
1542{
1543 if( !Pgm().IsGUI() )
1544 return;
1545
1546 wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1547
1548 wxFileName autoSaveFileName = aFileName;
1549
1550 // Check for auto save file.
1551 autoSaveFileName.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
1552
1553 wxLogTrace( traceAutoSave,
1554 wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
1555
1556 if( !autoSaveFileName.FileExists() )
1557 return;
1558
1559 wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
1560 "It appears that the last time you were editing\n"
1561 "%s\n"
1562 "KiCad exited before saving.\n"
1563 "\n"
1564 "Do you wish to open the auto-saved file instead?" ),
1565 aFileName.GetFullName() );
1566
1567 int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1568 this );
1569
1570 // Make a backup of the current file, delete the file, and rename the auto save file to
1571 // the file name.
1572 if( response == wxYES )
1573 {
1574 // Preserve the permissions of the current file
1575 KIPLATFORM::IO::DuplicatePermissions( aFileName.GetFullPath(),
1576 autoSaveFileName.GetFullPath() );
1577
1578 if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
1579 {
1580 wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
1581 Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
1582 }
1583 }
1584 else
1585 {
1586 DeleteAutoSaveFile( aFileName );
1587 }
1588}
1589
1590
1591void EDA_BASE_FRAME::DeleteAutoSaveFile( const wxFileName& aFileName )
1592{
1593 if( !Pgm().IsGUI() )
1594 return;
1595
1596 wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1597
1598 wxFileName autoSaveFn = aFileName;
1599 autoSaveFn.SetName( FILEEXT::AutoSaveFilePrefix + aFileName.GetName() );
1600
1601 if( autoSaveFn.FileExists() )
1602 {
1603 wxLogTrace( traceAutoSave, wxT( "Removing auto save file " ) + autoSaveFn.GetFullPath() );
1604 wxRemoveFile( autoSaveFn.GetFullPath() );
1605 }
1606}
1607
1608
1610{
1611 // This function should be overridden in child classes
1612 return false;
1613}
1614
1615
1617{
1618 wxAcceleratorEntry entries[1];
1619 entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
1620 wxAcceleratorTable accel( 1, entries );
1621 SetAcceleratorTable( accel );
1622}
1623
1624
1626{
1629}
1630
1631
1633{
1634 m_undoList.PushCommand( aNewitem );
1635
1636 // Delete the extra items, if count max reached
1637 if( m_undoRedoCountMax > 0 )
1638 {
1639 int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
1640
1641 if( extraitems > 0 )
1642 ClearUndoORRedoList( UNDO_LIST, extraitems );
1643 }
1644}
1645
1646
1648{
1649 m_redoList.PushCommand( aNewitem );
1650
1651 // Delete the extra items, if count max reached
1652 if( m_undoRedoCountMax > 0 )
1653 {
1654 int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
1655
1656 if( extraitems > 0 )
1657 ClearUndoORRedoList( REDO_LIST, extraitems );
1658 }
1659}
1660
1661
1663{
1664 return m_undoList.PopCommand();
1665}
1666
1667
1669{
1670 return m_redoList.PopCommand();
1671}
1672
1673
1675{
1676 if( GetUndoCommandCount() > 0 )
1677 return m_undoList.m_CommandsList.back()->GetDescription();
1678
1679 return wxEmptyString;
1680}
1681
1682
1684{
1685 if( GetRedoCommandCount() > 0 )
1686 return m_redoList.m_CommandsList.back()->GetDescription();
1687
1688 return wxEmptyString;
1689}
1690
1691
1693{
1694 m_autoSaveRequired = true;
1695}
1696
1697
1699{
1700 SetUserUnits( aUnits );
1702
1703 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
1704 e.SetInt( static_cast<int>( aUnits ) );
1705 e.SetClientData( this );
1706 ProcessEventLocally( e );
1707}
1708
1709
1710void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
1711{
1712 // When we maximize the window, we want to save the old information
1713 // so that we can add it to the settings on next window load.
1714 // Contrary to the documentation, this event seems to be generated
1715 // when the window is also being unmaximized on OSX, so we only
1716 // capture the size information when we maximize the window when on OSX.
1717#ifdef __WXOSX__
1718 if( !IsMaximized() )
1719#endif
1720 {
1722 m_normalFramePos = GetPosition();
1723 wxLogTrace( traceDisplayLocation,
1724 "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
1727 }
1728
1729 // Skip event to actually maximize the window
1730 aEvent.Skip();
1731}
1732
1733
1735{
1736#ifdef __WXGTK__
1737 wxSize winSize = GetSize();
1738
1739 // GTK includes the window decorations in the normal GetSize call,
1740 // so we have to use a GTK-specific sizing call that returns the
1741 // non-decorated window size.
1743 {
1744 int width = 0;
1745 int height = 0;
1746 GTKDoGetSize( &width, &height );
1747
1748 winSize.Set( width, height );
1749 }
1750#else
1751 wxSize winSize = GetSize();
1752#endif
1753
1754 return winSize;
1755}
1756
1757
1759{
1760 // Update the icon theme when the system theme changes and update the toolbars
1762 ThemeChanged();
1763
1764 // This isn't handled by ThemeChanged()
1765 if( GetMenuBar() )
1766 {
1767 // For icons in menus, icon scaling & hotkeys
1769 GetMenuBar()->Refresh();
1770 }
1771}
1772
1773
1774void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
1775{
1776 // Call the handler to update the colors used in the frame
1778
1779 // Skip the change event to ensure the rest of the window controls get it
1780 aEvent.Skip();
1781}
1782
1783
1784void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
1785{
1786 // Call the handler
1787 handleIconizeEvent( aEvent );
1788
1789 // Skip the event.
1790 aEvent.Skip();
1791}
1792
1793
1794#ifdef __WXMSW__
1795WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
1796{
1797 // This will help avoid the menu keeping focus when the alt key is released
1798 // You can still trigger accelerators as long as you hold down alt
1799 if( message == WM_SYSCOMMAND )
1800 {
1801 if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
1802 return 0;
1803 }
1804
1805 return wxFrame::MSWWindowProc( message, wParam, lParam );
1806}
1807#endif
1808
1809
1811{
1812 ACTION_MENU* langsMenu = new ACTION_MENU( false, aControlTool );
1813 langsMenu->SetTitle( _( "Set Language" ) );
1814 langsMenu->SetIcon( BITMAPS::language );
1815
1816 wxString tooltip;
1817
1818 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
1819 {
1820 wxString label;
1821
1822 if( LanguagesList[ii].m_DoNotTranslate )
1823 label = LanguagesList[ii].m_Lang_Label;
1824 else
1825 label = wxGetTranslation( LanguagesList[ii].m_Lang_Label );
1826
1827 wxMenuItem* item =
1828 new wxMenuItem( langsMenu,
1829 LanguagesList[ii].m_KI_Lang_Identifier, // wxMenuItem wxID
1830 label, tooltip, wxITEM_CHECK );
1831
1832 langsMenu->Append( item );
1833 }
1834
1835 // This must be done after the items are added
1836 aMasterMenu->Add( langsMenu );
1837}
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
const char * name
Definition: DXF_plotter.cpp:59
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:278
static TOOL_ACTION reportBug
Definition: actions.h:282
static TOOL_ACTION copy
Definition: actions.h:78
static TOOL_ACTION donate
Definition: actions.h:280
static TOOL_ACTION listHotKeys
Definition: actions.h:279
static TOOL_ACTION getInvolved
Definition: actions.h:281
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:276
static TOOL_ACTION help
Definition: actions.h:277
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:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:214
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 SetMenuBar(wxMenuBar *menu_bar) override
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:46
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:74
WINDOW_STATE state
Definition: app_settings.h:75
wxString mru_path
Definition: app_settings.h:76
wxString perspective
Definition: app_settings.h:77
Store the window positioning/state.
Definition: app_settings.h:61
unsigned int display
Definition: app_settings.h:67
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.