KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_draw_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) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include <base_screen.h>
28#include <bitmaps.h>
29#include <confirm.h>
30#include <core/arraydim.h>
31#include <core/kicad_algo.h>
32#include <dialog_shim.h>
34#include <eda_draw_frame.h>
35#include <file_history.h>
37#include <id.h>
38#include <kiface_base.h>
39#include <kiplatform/ui.h>
40#include <lockfile.h>
41#include <macros.h>
42#include <math/vector2wx.h>
43#include <page_info.h>
44#include <paths.h>
45#include <pgm_base.h>
46#include <render_settings.h>
51#include <title_block.h>
52#include <tool/actions.h>
53#include <tool/action_toolbar.h>
54#include <tool/common_tools.h>
55#include <tool/grid_helper.h>
56#include <tool/grid_menu.h>
59#include <tool/tool_manager.h>
60#include <tool/tool_menu.h>
61#include <tool/zoom_menu.h>
62#include <trace_helpers.h>
63#include <view/view.h>
65#include <view/view_controls.h>
66#include <widgets/kistatusbar.h>
67#include <widgets/msgpanel.h>
71#include <wx/event.h>
72#include <wx/snglinst.h>
73#include <widgets/ui_common.h>
74#include <widgets/search_pane.h>
75#include <wx/dirdlg.h>
76#include <wx/filedlg.h>
77#include <wx/debug.h>
78#include <wx/socket.h>
79
80#include <wx/snglinst.h>
81#include <wx/fdrepdlg.h>
83
84#define FR_HISTORY_LIST_CNT 10
85
86
87BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
90
91 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
92END_EVENT_TABLE()
93
94
95bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
96
97
98EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
99 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
100 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale ) :
101 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
102 m_socketServer( nullptr ),
104{
105 m_gridSelectBox = nullptr;
106 m_zoomSelectBox = nullptr;
107 m_overrideLocksCb = nullptr;
108 m_searchPane = nullptr;
110
112 m_canvas = nullptr;
113 m_toolDispatcher = nullptr;
114 m_messagePanel = nullptr;
115 m_currentScreen = nullptr;
116 m_showBorderAndTitleBlock = false; // true to display reference sheet.
117 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
118 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
119 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
120 m_colorSettings = nullptr;
121 m_polarCoords = false;
122 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
123 m_hotkeyPopup = nullptr;
124 m_propertiesPanel = nullptr;
125 m_netInspectorPanel = nullptr;
126
128
129 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
130
131 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
132 {
133 CreateStatusBar( 8 )->SetDoubleBuffered( true );
134
135 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
136
137 // set the size of the status bar subwindows:
139 }
140
141 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
142 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
143 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
144
145 // Create child subwindows.
146 GetClientSize( &m_frameSize.x, &m_frameSize.y );
147 m_framePos.x = m_framePos.y = 0;
149
151
152 Bind( wxEVT_DPI_CHANGED,
153 [&]( wxDPIChangedEvent& aEvent )
154 {
155 if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
157
158 wxMoveEvent dummy;
159 OnMove( dummy );
160
161 // we need to kludge the msg panel to the correct size again
162 // especially important even for first launches as the constructor of the window
163 // here usually doesn't have the correct dpi awareness yet
165 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
167
168 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
170
171 aEvent.Skip();
172 } );
173}
174
175
177{
180
181 delete m_actions;
182 delete m_toolManager;
183 delete m_toolDispatcher;
184 delete m_canvas;
185
186 delete m_currentScreen;
187 m_currentScreen = nullptr;
188
189 m_auimgr.UnInit();
190
191 ReleaseFile();
192}
193
194
196{
198
199 // Grid selection
200 auto gridSelectorFactory =
201 [this]( ACTION_TOOLBAR* aToolbar )
202 {
203 if( !m_gridSelectBox )
204 m_gridSelectBox = new wxChoice( aToolbar, ID_ON_GRID_SELECT );
205
207
208 aToolbar->Add( m_gridSelectBox );
209 };
210
212
213 // Zoom selection
214 auto zoomSelectorFactory =
215 [this]( ACTION_TOOLBAR* aToolbar )
216 {
217 if( !m_zoomSelectBox )
218 m_zoomSelectBox = new wxChoice( aToolbar, ID_ON_ZOOM_SELECT );
219
221 aToolbar->Add( m_zoomSelectBox );
222 };
223
225
226 auto overrideLocksFactory =
227 [this]( ACTION_TOOLBAR* aToolbar )
228 {
229 if( !m_overrideLocksCb )
230 m_overrideLocksCb = new wxCheckBox( aToolbar, ID_ON_OVERRIDE_LOCKS, _( "Override locks" ) );
231
232 aToolbar->Add( m_overrideLocksCb );
233 };
234
236}
237
238
240{
241 switch( aId )
242 {
243 case ID_ON_GRID_SELECT: m_gridSelectBox = nullptr; break;
244 case ID_ON_ZOOM_SELECT: m_zoomSelectBox = nullptr; break;
245 case ID_ON_OVERRIDE_LOCKS: m_overrideLocksCb = nullptr; break;
246 }
247}
248
249
251{
252 if( m_file_checker )
253 m_file_checker->UnlockFile();
254}
255
256
257bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
258{
259 // We need to explicitly reset here to get the deletion before we create a new unique_ptr that
260 // may be for the same file.
261 m_file_checker.reset();
262
263 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
264
265 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
266 {
267 // If we cannot acquire the lock but we appear to be the one who locked it, check to see if
268 // there is another KiCad instance running. If there is not, then we can override the lock.
269 // This could happen if KiCad crashed or was interrupted.
270 if( !Pgm().SingleInstance()->IsAnotherRunning() )
271 m_file_checker->OverrideLock();
272 }
273
274 // If the file is valid, return true. This could mean that the file is locked or it could mean
275 // that the file is read-only.
276 return m_file_checker->Valid();
277}
278
279
281{
282 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
283
284 wxRect rect = GetScreenRect();
285 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
286
287 if( !frame )
288 {
289 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
290
291 // If we received an error in the CTOR due to Python-ness, don't crash
292 if( !frame )
293 return;
294
295 if( !frame->IsVisible() )
296 frame->Show( true );
297
298 // On Windows, Raise() does not bring the window on screen, when iconized
299 if( frame->IsIconized() )
300 frame->Iconize( false );
301
302 frame->Raise();
303 frame->SetPosition( center - frame->GetSize() / 2 );
304
305 return;
306 }
307
308 frame->Show( !frame->IsVisible() );
309 frame->SetPosition( center - frame->GetSize() / 2 );
310}
311
312
314{
315 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
316 return frame && frame->IsVisible();
317}
318
319
321{
322 // Notify all tools the units have changed
323 if( m_toolManager )
325
329
330 switch( GetUserUnits() )
331 {
332 default:
336 }
337}
338
339
341{
342 if( m_toolManager->GetTool<COMMON_TOOLS>() )
343 {
345 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
346 }
347 else
348 {
351
352 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
353 ProcessEventLocally( e );
354 }
355}
356
357
359{
361
362 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
364
365 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
366 {
367 if( GetAutoSaveInterval() > 0 )
368 {
369 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
370 }
371 else
372 {
373 m_autoSaveTimer->Stop();
374 m_autoSavePending = false;
375 }
376 }
377
378 viewControls->LoadSettings();
379
380 m_galDisplayOptions.ReadCommonConfig( *settings, this );
381
384
385 if( m_lastToolbarIconSize == 0
387 {
390 }
391
392#ifndef __WXMAC__
394
395 if( m_canvasType != GetCanvas()->GetBackend() )
396 {
397 // Try to switch (will automatically fallback if necessary)
400 bool success = newGAL == m_canvasType;
401
402 if( !success )
403 {
404 m_canvasType = newGAL;
405 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
406 }
407 }
408#endif
409
410 // Notify all tools the preferences have changed
411 if( m_toolManager )
413}
414
415
417{
418 if( m_messagePanel )
419 m_messagePanel->EraseMsgBox();
420}
421
422
424{
427
428 if( m_gridSelectBox == nullptr )
429 return;
430
431 // Update grid values with the current units setting.
432 m_gridSelectBox->Clear();
433 wxArrayString gridsList;
434
435 wxCHECK( config(), /* void */ );
436
437 GRID_MENU::BuildChoiceList( &gridsList, GetWindowSettings( config() ), this );
438
439 for( const wxString& grid : gridsList )
440 m_gridSelectBox->Append( grid );
441
442 m_gridSelectBox->Append( wxT( "---" ) );
443 m_gridSelectBox->Append( _( "Edit Grids..." ) );
444
445 m_gridSelectBox->SetSelection( GetWindowSettings( config() )->grid.last_size_idx );
446}
447
448
449void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
450{
451 // No need to update the grid select box if it doesn't exist or the grid setting change
452 // was made using the select box.
453 if( m_gridSelectBox == nullptr )
454 return;
455
456 wxCHECK( config(), /* void */ );
457
459 idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
460
461 if( idx != m_gridSelectBox->GetSelection() )
462 m_gridSelectBox->SetSelection( idx );
463}
464
465
466
467void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
468{
469 // No need to update the grid select box if it doesn't exist or the grid setting change
470 // was made using the select box.
471 if( m_zoomSelectBox == nullptr )
472 return;
473
474 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
475
476 wxCHECK( config(), /* void */ );
477
478 const std::vector<double>& zoomList = GetWindowSettings( config() )->zoom_factors;
479 int curr_selection = m_zoomSelectBox->GetSelection();
480 int new_selection = 0; // select zoom auto
481 double last_approx = 1e9; // large value to start calculation
482
483 // Search for the nearest available value to the current zoom setting, and select it
484 for( size_t jj = 0; jj < zoomList.size(); ++jj )
485 {
486 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
487
488 if( rel_error < last_approx )
489 {
490 last_approx = rel_error;
491
492 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
493 new_selection = (int) jj + 1;
494 }
495 }
496
497 if( curr_selection != new_selection )
498 m_zoomSelectBox->SetSelection( new_selection );
499}
500
501
502void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
503{
504 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
505
506 int idx = m_gridSelectBox->GetCurrentSelection();
507
508 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
509 {
510 // wxWidgets will check the separator, which we don't want.
511 // Re-check the current grid.
512 wxUpdateUIEvent dummy;
514 }
515 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
516 {
517 // wxWidgets will check the Grid Settings... entry, which we don't want.
518 // Re-check the current grid.
519 wxUpdateUIEvent dummy;
521
522 // Give a time-slice to close the menu before opening the dialog.
523 // (Only matters on some versions of GTK.)
524 wxSafeYield();
525
527 }
528 else
529 {
530 m_toolManager->RunAction( ACTIONS::gridPreset, idx );
531 }
532
534 m_canvas->Refresh();
535
536 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
537 // (Windows specific
538 m_canvas->SetFocus();
539}
540
541
543{
545 return m_overrideLocksCb->GetValue();
546
547 return false;
548}
549
550
552{
553 wxCHECK( config(), true );
554
555 return GetWindowSettings( config() )->grid.show;
556}
557
558
560{
561 wxCHECK( config(), /* void */ );
562
563 GetWindowSettings( config() )->grid.show = aVisible;
564
565 // Update the display with the new grid
566 if( GetCanvas() )
567 {
568 // Check to ensure these exist, since this function could be called before
569 // the GAL and View have been created
570 if( GetCanvas()->GetGAL() )
571 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
572
573 if( GetCanvas()->GetView() )
575
576 GetCanvas()->Refresh();
577 }
578}
579
580
582{
583 wxCHECK( config(), false );
584
586}
587
588
590{
591 wxCHECK( config(), /* void */ );
592
594}
595
596
597std::unique_ptr<GRID_HELPER> EDA_DRAW_FRAME::MakeGridHelper()
598{
599 return nullptr;
600}
601
602
604{
605 if( m_zoomSelectBox == nullptr )
606 return;
607
608 double zoom = m_canvas->GetGAL()->GetZoomFactor();
609
610 m_zoomSelectBox->Clear();
611 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
612 m_zoomSelectBox->SetSelection( 0 );
613
614 wxCHECK( config(), /* void */ );
615
616 for( unsigned ii = 0; ii < GetWindowSettings( config() )->zoom_factors.size(); ++ii )
617 {
618 double current = GetWindowSettings( config() )->zoom_factors[ii];
619
620 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
621
622 if( zoom == current )
623 m_zoomSelectBox->SetSelection( (int) ii + 1 );
624 }
625}
626
627
628void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
629{
630 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
631
632 int id = m_zoomSelectBox->GetCurrentSelection();
633
634 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
635 return;
636
637 m_toolManager->RunAction( ACTIONS::zoomPreset, id );
639 m_canvas->Refresh();
640
641 // Needed on Windows (only) because clicking on m_zoomSelectBox removes the focus from m_canvas
642 m_canvas->SetFocus();
643}
644
645
646void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
647{
648 // If the window is moved to a different display, the scaling factor may change
649 double oldFactor = m_galDisplayOptions.m_scaleFactor;
650 m_galDisplayOptions.UpdateScaleFactor();
651
652 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
653 {
654 wxSize clientSize = GetClientSize();
655 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
657 }
658
659 aEvent.Skip();
660}
661
662
664{
665 COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
666 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
667
668 aMenu.AddSeparator( 1000 );
669
670 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
671 zoomMenu->SetTool( commonTools );
672 aToolMenu.RegisterSubMenu( zoomMenu );
673
674 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
675 gridMenu->SetTool( commonTools );
676 aToolMenu.RegisterSubMenu( gridMenu );
677
678 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
679 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
680}
681
682
683void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
684{
685 if( m_isClosing )
686 return;
687
688 SetStatusText( msg, 6 );
689}
690
691
692void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
693{
694 if( m_isClosing )
695 return;
696
697 SetStatusText( msg, 7 );
698}
699
700
702{
703 if( m_isClosing )
704 return;
705
706 wxString msg;
707
708 GRID_SETTINGS& gridSettings = m_toolManager->GetSettings()->m_Window.grid;
709 int currentIdx = m_toolManager->GetSettings()->m_Window.grid.last_size_idx;
710
711 msg.Printf( _( "grid %s" ), gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
712
713 SetStatusText( msg, 4 );
714}
715
716
718{
719 if( m_isClosing )
720 return;
721
722 wxString msg;
723
724 switch( GetUserUnits() )
725 {
726 case EDA_UNITS::INCH: msg = _( "inches" ); break;
727 case EDA_UNITS::MILS: msg = _( "mils" ); break;
728 case EDA_UNITS::MM: msg = _( "mm" ); break;
729 default: msg = _( "Units" ); break;
730 }
731
732 SetStatusText( msg, 5 );
733}
734
735
736void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
737{
738 EDA_BASE_FRAME::OnSize( SizeEv );
739
740 m_frameSize = GetClientSize( );
741
742 SizeEv.Skip();
743}
744
745
747{
748 constexpr int numLocalFields = 8;
749
750 wxStatusBar* stsbar = GetStatusBar();
751 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x;
752
753 // Note this is a KISTATUSBAR and there are fields to the right of the ones we know about
754 int totalFields = stsbar->GetFieldsCount();
755
756 std::vector<int> dims = {
757 // remainder of status bar on far left is set to a default or whatever is left over.
758 -3,
759
760 // When using GetTextSize() remember the width of character '1' is not the same
761 // as the width of '0' unless the font is fixed width, and it usually won't be.
762
763 // zoom:
764 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
765
766 // cursor coords
767 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
768
769 // delta distances
770 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
771
772 // grid size
773 KIUI::GetTextSize( wxT( "grid 1234.1234 x 1234.1234" ), stsbar ).x,
774
775 // units display, Inches is bigger than mm
776 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
777
778 // Size for the "Current Tool" panel
779 -2,
780
781 // constraint mode
782 -2
783 };
784
785 for( int& dim : dims )
786 {
787 if( dim >= 0 )
788 dim += spacer;
789 }
790
791 for( int idx = numLocalFields; idx < totalFields; ++idx )
792 dims.emplace_back( stsbar->GetStatusWidth( idx ) );
793
794 SetStatusWidths( dims.size(), dims.data() );
795}
796
797
798wxStatusBar* EDA_DRAW_FRAME::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
799{
800 return new KISTATUSBAR( number, this, id, KISTATUSBAR::STYLE_FLAGS::WARNING_ICON );
801}
802
803
805{
806 if( m_isClosing )
807 return;
808
809 SetStatusText( GetZoomLevelIndicator(), 1 );
810
811 // Absolute and relative cursor positions are handled by overloading this function and
812 // handling the internal to user units conversion at the appropriate level.
813
814 // refresh units display
816}
817
818
820{
821 // returns a human readable value which can be displayed as zoom
822 // level indicator in dialogs.
823 double zoom = m_canvas->GetGAL()->GetZoomFactor();
824 return wxString::Format( wxT( "Z %.2f" ), zoom );
825}
826
827
829{
831
833 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
834
835 // Read units used in dialogs and toolbars
836 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
837
839
840 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
841
842 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
843 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
844 m_findReplaceData->matchMode = static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
845 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
846 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
847
848 for( const wxString& s : aCfg->m_FindReplace.find_history )
850
851 for( const wxString& s : aCfg->m_FindReplace.replace_history )
853
855}
856
857
859{
861
862 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
863
864 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
866
867 m_galDisplayOptions.WriteConfig( *window );
868
869 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
870
871 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
872 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
873
874 aCfg->m_FindReplace.find_history.clear();
875 aCfg->m_FindReplace.replace_history.clear();
876
877 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
878 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
879
880 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
881 aCfg->m_FindReplace.replace_history.push_back( m_replaceStringHistoryList[ i ].ToStdString() );
882
883 // Save the units used in this frame
884 if( m_toolManager )
885 {
886 if( COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>() )
887 {
888 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
889 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
890 }
891 }
892}
893
894
895void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
896{
898 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
899}
900
901
903{
905 m_messagePanel->EraseMsgBox();
906}
907
908
909void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
910{
912 {
913 m_messagePanel->EraseMsgBox();
914
915 for( const MSG_PANEL_ITEM& item : aList )
916 m_messagePanel->AppendMessage( item );
917 }
918}
919
920
921void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
922{
924 {
925 m_messagePanel->EraseMsgBox();
926 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
927 }
928}
929
930
932{
933 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
934
935 std::vector<MSG_PANEL_ITEM> items;
936 aItem->GetMsgPanelInfo( this, items );
937 SetMsgPanel( items );
938}
939
940
944
945
947{
948 GetCanvas()->SetEvtHandlerEnabled( true );
950}
951
952
960
961
963{
964#ifdef __WXMAC__
965 // Cairo renderer doesn't handle Retina displays so there's really only one game
966 // in town for Mac
968#endif
969
972
973 if( cfg )
974 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
975
976 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
977 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
978 {
979 wxASSERT( false );
981 }
982
983 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
984 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
986
987 wxString envCanvasType;
988
989 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) )
990 {
991 if( envCanvasType.CmpNoCase( "1" ) == 0
992 || envCanvasType.CmpNoCase( "true" ) == 0
993 || envCanvasType.CmpNoCase( "yes" ) == 0 )
994 {
995 // Force software rendering if the environment variable is set
997 }
998 }
999
1000 return canvasType;
1001}
1002
1003
1005{
1006 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
1007 // have a fixed type, or do not have a option to set the canvas type (they inherit from
1008 // a parent frame)
1009 static std::vector<FRAME_T> s_allowedFrames = { FRAME_SCH,
1015
1016 if( !alg::contains( s_allowedFrames, m_ident ) )
1017 return false;
1018
1019 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) )
1020 {
1021 // If the environment variable is set, don't save the canvas type.
1022 return false;
1023 }
1024
1025 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1026 {
1027 wxASSERT( false );
1028 return false;
1029 }
1030
1031 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
1032 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
1033
1034 return false;
1035}
1036
1037
1039{
1040 const VECTOR2I& gridOrigin = GetGridOrigin();
1041 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
1042
1043 double xOffset = fmod( gridOrigin.x, gridSize.x );
1044 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1045 double yOffset = fmod( gridOrigin.y, gridSize.y );
1046 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1047
1048 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1049}
1050
1051
1053{
1054 const VECTOR2I& gridOrigin = GetGridOrigin();
1055 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
1056
1057 double xOffset = fmod( gridOrigin.x, gridSize.x );
1058 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1059 double yOffset = fmod( gridOrigin.y, gridSize.y );
1060 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1061
1062 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1063}
1064
1065
1066const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1067{
1068 return BOX2I();
1069}
1070
1071
1073{
1074 // To be implemented by subclasses.
1075}
1076
1077
1078void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1079{
1081}
1082
1083
1084std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
1085{
1086 std::vector<wxWindow*> dialogs;
1087
1088 for( wxWindow* window : GetChildren() )
1089 {
1090 if( dynamic_cast<DIALOG_SHIM*>( window ) )
1091 dialogs.push_back( window );
1092 }
1093
1094 return dialogs;
1095}
1096
1097
1098void EDA_DRAW_FRAME::FocusOnLocation( const VECTOR2I& aPos, bool aAllowScroll )
1099{
1100 bool centerView = false;
1101 std::vector<BOX2D> dialogScreenRects;
1102
1103 if( aAllowScroll )
1104 {
1105 BOX2D r = GetCanvas()->GetView()->GetViewport();
1106
1107 // Center if we're off the current view, or within 10% of its edge
1108 r.Inflate( - r.GetWidth() / 10.0 );
1109
1110 if( !r.Contains( aPos ) )
1111 centerView = true;
1112
1113 for( wxWindow* dialog : findDialogs() )
1114 {
1115 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1116 ToVECTOR2D( dialog->GetSize() ) );
1117 }
1118
1119 // Center if we're behind an obscuring dialog, or within 10% of its edge
1120 for( BOX2D rect : dialogScreenRects )
1121 {
1122 rect.Inflate( rect.GetWidth() / 10 );
1123
1124 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1125 centerView = true;
1126 }
1127 }
1128
1129 if( centerView )
1130 {
1131 try
1132 {
1133 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1134 }
1135 catch( const Clipper2Lib::Clipper2Exception& e )
1136 {
1137 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ), e.what() ) );
1138 }
1139 }
1140
1142}
1143
1144
1145void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1146 const wxString& aSheetName, const wxString& aSheetPath,
1147 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1148 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1149 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1150 const wxString& aSheetLayer, bool aIsFirstPage )
1151{
1152 DS_DRAW_ITEM_LIST drawList( unityScale );
1153
1154 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1155 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1156 drawList.SetPageNumber( aPageNumber );
1157 drawList.SetSheetCount( aSheetCount );
1158 drawList.SetFileName( aFileName );
1159 drawList.SetSheetName( aSheetName );
1160 drawList.SetSheetPath( aSheetPath );
1161 drawList.SetSheetLayer( aSheetLayer );
1162 drawList.SetProject( aProject );
1163 drawList.SetIsFirstPage( aIsFirstPage );
1164 drawList.SetProperties( aProperties );
1165
1166 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1167
1168 // Draw item list
1169 drawList.Print( aSettings );
1170}
1171
1172
1174 const std::map<wxString, wxString>* aProperties,
1175 double aMils2Iu, const wxString &aFilename,
1176 const wxString &aSheetLayer )
1177{
1179 return;
1180
1181 wxDC* DC = aSettings->GetPrintDC();
1182 wxPoint origin = DC->GetDeviceOrigin();
1183
1184 if( origin.y > 0 )
1185 {
1186 DC->SetDeviceOrigin( 0, 0 );
1187 DC->SetAxisOrientation( true, false );
1188 }
1189
1191 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1192 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1193 aScreen->GetVirtualPageNumber() == 1 );
1194
1195 if( origin.y > 0 )
1196 {
1197 DC->SetDeviceOrigin( origin.x, origin.y );
1198 DC->SetAxisOrientation( true, true );
1199 }
1200}
1201
1202
1204{
1205 // Virtual function. Base class implementation returns an empty string.
1206 return wxEmptyString;
1207}
1208
1209
1211{
1212 // Virtual function. Base class implementation returns an empty string.
1213 return wxEmptyString;
1214}
1215
1216
1217bool EDA_DRAW_FRAME::LibraryFileBrowser( const wxString& aTitle, bool doOpen, wxFileName& aFilename,
1218 const wxString& wildcard, const wxString& ext,
1219 bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY* aFileDlgHook )
1220{
1221 aFilename.SetExt( ext );
1222
1223 wxString defaultDir = aFilename.GetPath();
1224
1225 if( defaultDir.IsEmpty() )
1226 defaultDir = GetMruPath();
1227
1228 if( isDirectory && doOpen )
1229 {
1230 wxDirDialog dlg( this, aTitle, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1231
1232 if( dlg.ShowModal() == wxID_CANCEL )
1233 return false;
1234
1235 aFilename = dlg.GetPath();
1236 aFilename.SetExt( ext );
1237 }
1238 else
1239 {
1240 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1241 if( aFilename.GetName().empty() )
1242 aFilename.SetName( wxS( "Library" ) );
1243
1244 wxFileDialog dlg( this, aTitle, defaultDir, aFilename.GetFullName(), wildcard,
1245 doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1246 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1247
1248 if( aFileDlgHook )
1249 dlg.SetCustomizeHook( *aFileDlgHook );
1250
1252
1253 if( dlg.ShowModal() == wxID_CANCEL )
1254 return false;
1255
1256 aFilename = dlg.GetPath();
1257 aFilename.SetExt( ext );
1258 }
1259
1260 SetMruPath( aFilename.GetPath() );
1261
1262 return true;
1263}
1264
1265
1267{
1269
1270 if( m_searchPane )
1271 {
1272 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1273 search_pane_info.Caption( _( "Search" ) );
1274 }
1275
1276 if( m_propertiesPanel )
1277 {
1278 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1279 properties_pane_info.Caption( _( "Properties" ) );
1280 }
1281
1283 {
1284 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1285 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1286 }
1287}
1288
1289
1291{
1292 if( m_isClosing || !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1293 return;
1294
1295 m_propertiesPanel->UpdateData();
1296}
1297
1298
1303
1304
1306{
1307 if( !m_colorSettings || aForceRefresh )
1308 {
1310 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1311 }
1312
1313 return m_colorSettings;
1314}
1315
1316
1318{
1320
1321 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
1322 EDITOR_CONDITIONS cond( this );
1323
1324 wxASSERT( mgr );
1325
1329}
1330
1331
1333{
1334 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1335
1336 if( cmnTool )
1337 {
1338 // Tell the tool what the units used last session
1339 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1340 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1341 }
1342
1343 // Tell the tool what units the frame is currently using
1344 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1345 {
1346 default:
1347 case EDA_UNITS::MM: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1348 case EDA_UNITS::INCH: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1349 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1350 }
1351}
1352
1353
1354void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1355{
1356 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1357
1358 aPrimaryUnit = GetUserUnits();
1359 aSecondaryUnits = EDA_UNITS::MILS;
1360
1361 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1362 {
1363 if( cmnTool )
1364 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1365 else
1366 aSecondaryUnits = EDA_UNITS::MM;
1367 }
1368 else
1369 {
1370 if( cmnTool )
1371 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1372 else
1373 aSecondaryUnits = EDA_UNITS::MILS;
1374 }
1375}
1376
1377
1379{
1381
1382 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1383 // user preference silently:
1384
1387}
1388
1389
1390void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1391{
1392 // Force a refresh of the message panel to ensure that the text is the right color
1393 // when the window activates
1394 if( !IsIconized() )
1395 m_messagePanel->Refresh();
1396}
1397
1398
1399void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1400{
1401 handleActivateEvent( aEvent );
1402
1403 aEvent.Skip();
1404}
1405
1406
1407bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName, BITMAP_TYPE aBitmapType )
1408{
1409 bool retv = true;
1410
1411 // Make a screen copy of the canvas:
1412 wxSize image_size = GetCanvas()->GetClientSize();
1413
1414 wxClientDC dc( GetCanvas() );
1415 wxBitmap bitmap( image_size.x, image_size.y );
1416 wxMemoryDC memdc;
1417
1418 memdc.SelectObject( bitmap );
1419 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1420 memdc.SelectObject( wxNullBitmap );
1421
1422 wxImage image = bitmap.ConvertToImage();
1423
1424 wxBitmapType type = wxBITMAP_TYPE_PNG;
1425 switch( aBitmapType )
1426 {
1427 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1428 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1429 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1430 }
1431
1432 if( !image.SaveFile( aFileName, type ) )
1433 retv = false;
1434
1435 image.Destroy();
1436 return retv;
1437}
1438
1439
1441{
1442 wxCHECK( aCfg, aAction.show_button );
1443
1444 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1445 {
1446 if( identifier == aAction.identifier )
1447 return visible;
1448 }
1449
1450 return aAction.show_button;
1451}
1452
1453
1454std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions( PLUGIN_ACTION_SCOPE aScope,
1455 APP_SETTINGS_BASE* aCfg )
1456{
1457 std::vector<const PLUGIN_ACTION*> actions;
1458 wxCHECK( aCfg, actions );
1459
1460#ifdef KICAD_IPC_API
1461
1462 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1463 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1464 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1465 std::set<const PLUGIN_ACTION*> handled;
1466
1467 for( const PLUGIN_ACTION* action : unsorted )
1468 actionMap[action->identifier] = action;
1469
1470 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1471 {
1472 if( actionMap.contains( identifier ) )
1473 {
1474 const PLUGIN_ACTION* action = actionMap[ identifier ];
1475 actions.emplace_back( action );
1476 handled.insert( action );
1477 }
1478 }
1479
1480 for( const auto& action : actionMap | std::views::values )
1481 {
1482 if( !handled.contains( action ) )
1483 actions.emplace_back( action );
1484 }
1485
1486#endif
1487
1488 return actions;
1489}
1490
1491
1493{
1494#ifdef KICAD_IPC_API
1495 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1496
1497 mgr.ButtonBindings().clear();
1498
1499 std::vector<const PLUGIN_ACTION*> actions = GetOrderedPluginActions( PluginActionScope(), config() );
1500
1501 for( const PLUGIN_ACTION* action : actions )
1502 {
1503 if( !IsPluginActionButtonVisible( *action, config() ) )
1504 continue;
1505
1506 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
1507 : action->icon_light;
1508
1509 wxAuiToolBarItem* button = aToolbar->AddTool( wxID_ANY, wxEmptyString, icon, action->name );
1510
1511 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1512 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1513
1514 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1515 }
1516#endif
1517}
1518
1519
1520void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1521{
1522#ifdef KICAD_IPC_API
1523 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1524
1525 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1526 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ) );
1527#endif
1528}
const char * name
PLUGIN_ACTION_SCOPE
Definition api_plugin.h:56
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:115
BITMAP_TYPE
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
BOX2< VECTOR2D > BOX2D
Definition box2.h:923
static TOOL_ACTION gridProperties
Definition actions.h:200
static TOOL_ACTION millimetersUnits
Definition actions.h:206
static TOOL_ACTION updatePreferences
Definition actions.h:276
static TOOL_ACTION gridPreset
Definition actions.h:197
static TOOL_ACTION updateUnits
Definition actions.h:207
static TOOL_ACTION milsUnits
Definition actions.h:205
static TOOL_ACTION inchesUnits
Definition actions.h:204
static TOOL_ACTION zoomFitScreen
Definition actions.h:142
static TOOL_ACTION zoomPreset
Definition actions.h:145
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static ACTION_TOOLBAR_CONTROL gridSelect
static ACTION_TOOLBAR_CONTROL overrideLocks
static ACTION_TOOLBAR_CONTROL zoomSelect
Define the structure of a toolbar with buttons that invoke ACTIONs.
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
std::map< int, wxString > & ButtonBindings()
std::vector< const PLUGIN_ACTION * > GetActionsForScope(PLUGIN_ACTION_SCOPE aScope)
void InvokeAction(const wxString &aIdentifier)
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
FIND_REPLACE m_FindReplace
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:41
int GetPageCount() const
Definition base_screen.h:72
int GetVirtualPageNumber() const
Definition base_screen.h:75
const wxString & GetPageNumber() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr size_type GetWidth() const
Definition box2.h:214
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
Color settings are a bit different than most of the settings objects in that there can be more than o...
APPEARANCE m_Appearance
Handles action that are shared between different applications.
void SetLastUnits(EDA_UNITS aUnit)
EDA_UNITS GetLastImperialUnits()
EDA_UNITS GetLastMetricUnits()
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
void SetPlotterMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to plot units.
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetSheetPath(const wxString &aSheetPath)
Set the sheet path to draw/plot.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetDefaultPenSize(int aPenSize)
void Print(const RENDER_SETTINGS *aSettings)
Draws the item list created by BuildDrawItemsList.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
void SetProject(const PROJECT *aProject)
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
void OnToolbarSizeChanged()
Update toolbars if desired toolbar icon changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
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.
virtual void configureToolbars()
wxTimer * m_autoSaveTimer
wxAuiManager m_auimgr
void SelectToolbarAction(const TOOL_ACTION &aAction)
Select the given action in the toolbar group which contains it, if any.
int GetMaxUndoItems() const
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
wxString GetMruPath() const
virtual void OnSize(wxSizeEvent &aEvent)
int GetAutoSaveInterval() const
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void SetMruPath(const wxString &aPath)
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
The base class for create windows for drawing purpose.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Return bounding box of document with option to not include some items.
wxCheckBox * m_overrideLocksCb
wxArrayString m_replaceStringHistoryList
virtual void ClearMsgPanel()
Clear all messages from the message panel.
static std::vector< const PLUGIN_ACTION * > GetOrderedPluginActions(PLUGIN_ACTION_SCOPE aScope, APP_SETTINGS_BASE *aCfg)
Return ordered list of plugin actions for display in the toolbar.
void configureToolbars() override
EDA_DRAW_PANEL_GAL * m_canvas
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
GAL_DISPLAY_OPTIONS_IMPL m_galDisplayOptions
This the frame's interface to setting GAL display options.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
void onActivate(wxActivateEvent &aEvent)
COLOR_SETTINGS * m_colorSettings
wxChoice * m_gridSelectBox
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
void ReleaseFile()
Release the current file marked in use.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
void ScriptingConsoleEnableDisable()
Toggle the scripting console visibility.
virtual wxString GetFullScreenDesc() const
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void DisplayToolMsg(const wxString &msg) override
std::unique_ptr< LOCKFILE > m_file_checker
bool IsScriptingConsoleVisible()
Get the current visibility of the scripting console window.
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
Update the checked item in the zoom wxchoice.
virtual const PAGE_INFO & GetPageSettings() const =0
void DisplayUnitsMsg()
Display current unit pane in the status bar.
void setupUnits(APP_SETTINGS_BASE *aCfg)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
bool SaveCanvasImageToFile(const wxString &aFileName, BITMAP_TYPE aBitmapType)
Save the current view as an image file.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Change the current rendering backend.
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
virtual void resolveCanvasType()
Determine the canvas type to load (with prompt if required) and initializes m_canvasType.
static bool m_openGLFailureOccured
Has any failure occurred when switching to OpenGL in any EDA_DRAW_FRAME?
BASE_SCREEN * m_currentScreen
current used SCREEN
virtual wxString GetScreenDesc() const
VECTOR2I GetNearestGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize location to aPosition.
EDA_MSG_PANEL * m_messagePanel
virtual const VECTOR2I & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Store the canvas type in the application settings.
EDA_DRAW_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
NET_INSPECTOR_PANEL * m_netInspectorPanel
bool LibraryFileBrowser(const wxString &aTitle, bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY *aFileDlgHook=nullptr)
virtual void SetGridVisibility(bool aVisible)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
virtual void AddApiPluginTools(ACTION_TOOLBAR *aToolbar)
Append actions from API plugins to the given toolbar.
virtual void OnApiPluginInvoke(wxCommandEvent &aEvent)
Handler for activating an API plugin (via toolbar or menu).
virtual void UpdateMsgPanel()
Redraw the message panel.
wxStatusBar * OnCreateStatusBar(int number, long style, wxWindowID id, const wxString &name) override
Create the status line (like a wxStatusBar).
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
void ToggleUserUnits() override
void FocusOnLocation(const VECTOR2I &aPos, bool aAllowScroll=true)
Useful to focus on a particular location, in find functions.
virtual void CreateHotkeyPopup()
void UpdateStatusBar() override
Update the status bar information.
void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits) override
Get the pair or units in current use.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, const std::map< wxString, wxString > *aProperties, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Print the drawing-sheet (frame and title block).
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
wxSocketServer * m_socketServer
Prevents opening same file multiple times.
SEARCH_PANE * m_searchPane
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void OnMove(wxMoveEvent &aEvent) override
std::vector< wxWindow * > findDialogs()
virtual void DisplayGridMsg()
Display current grid size in the status bar.
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting()
Return the canvas type stored in the application settings.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
wxArrayString m_findStringHistoryList
wxChoice * m_zoomSelectBox
virtual std::unique_ptr< GRID_HELPER > MakeGridHelper()
virtual PLUGIN_ACTION_SCOPE PluginActionScope() const
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void DisplayConstraintsMsg(const wxString &msg)
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
virtual void SetGridOverrides(bool aOverride)
PROPERTIES_PANEL * m_propertiesPanel
bool m_showBorderAndTitleBlock
VECTOR2I GetNearestHalfGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
void ClearToolbarControl(int aId) override
bool GetOverrideLocks() const
HOTKEY_CYCLE_POPUP * m_hotkeyPopup
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid wxchoice.
static bool IsPluginActionButtonVisible(const PLUGIN_ACTION &aAction, APP_SETTINGS_BASE *aCfg)
static constexpr GAL_TYPE GAL_FALLBACK
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
@ GAL_TYPE_LAST
Sentinel, do not use as a parameter.
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_CAIRO
Cairo implementation.
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void StartDrawing()
Begin drawing if it was stopped previously.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition eda_item.h:225
A panel to display various information messages.
Definition msgpanel.h:101
Class that groups generic conditions for editor states.
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
static void BuildChoiceList(wxArrayString *aGridsList, WINDOW_SETTINGS *aCfg, EDA_DRAW_FRAME *aParent)
Definition grid_menu.cpp:83
Similar to EDA_VIEW_SWITCHER, this dialog is a popup that shows feedback when using a hotkey to cycle...
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
virtual void ResizeScreen(int aWidth, int aHeight)
Resize the canvas.
double GetZoomFactor() const
const VECTOR2D & GetGridSize() const
Return the grid size.
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void LoadSettings()
Load new settings from program common settings.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition view.cpp:531
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:659
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:597
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:639
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:294
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:403
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:54
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:535
Container for project specific data.
Definition project.h:65
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:41
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
Generic, UI-independent tool event.
Definition tool_event.h:171
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition tool_menu.h:43
CONDITIONAL_MENU & GetMenu()
Definition tool_menu.cpp:44
void RegisterSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Store a submenu of this menu model.
Definition tool_menu.cpp:50
EDA_UNITS GetUserUnits() const
void SetUserUnits(EDA_UNITS aUnits)
@ LIGHTGRAY
Definition color4d.h:47
@ DARKGRAY
Definition color4d.h:46
@ BLACK
Definition color4d.h:44
This file is part of the common library.
#define _(s)
#define DEFAULT_MAX_UNDO_ITEMS
#define FR_HISTORY_LIST_CNT
Maximum size of the find/replace history stacks.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, const std::map< wxString, wxString > *aProperties, int aSheetCount, const wxString &aPageNumber, double aMils2Iu, const PROJECT *aProject, const wxString &aSheetLayer, bool aIsFirstPage)
Print the border and title block.
EDA_SEARCH_MATCH_MODE
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
@ FRAME_PCB_EDITOR
Definition frame_type.h:42
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:35
@ FRAME_SCH
Definition frame_type.h:34
@ FRAME_PL_EDITOR
Definition frame_type.h:59
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:43
@ FRAME_GERBER
Definition frame_type.h:57
@ FRAME_PYTHON
Definition frame_type.h:55
@ ID_ON_GRID_SELECT
Definition id.h:113
@ ID_ON_ZOOM_SELECT
Definition id.h:112
@ ID_ON_OVERRIDE_LOCKS
Definition id.h:114
File locking utilities.
This file contains miscellaneous commonly used macros and functions.
Message panel definition file.
KICOMMON_API bool IsImperialUnit(EDA_UNITS aUnit)
Definition eda_units.cpp:47
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:38
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:49
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:717
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
#define DEFAULT_THEME
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 ...
std::vector< wxString > replace_history
std::vector< wxString > find_history
std::vector< std::pair< wxString, bool > > actions
Ordered list of plugin actions mapped to whether or not they are shown in the toolbar.
int canvas_type
EDA_DRAW_PANEL_GAL::GAL_TYPE_* value, see gal_options_panel.cpp.
std::vector< GRID > grids
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
Definition api_plugin.h:82
wxString identifier
Definition api_plugin.h:87
Store the common settings that are saved and loaded for each window / frame.
GRID_SETTINGS grid
std::vector< double > zoom_factors
VECTOR2I center
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:40