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/msgpanel.h>
70#include <wx/event.h>
71#include <wx/snglinst.h>
72#include <widgets/ui_common.h>
73#include <widgets/search_pane.h>
74#include <wx/dirdlg.h>
75#include <wx/filedlg.h>
76#include <wx/debug.h>
77#include <wx/socket.h>
78
79#include <wx/snglinst.h>
80#include <wx/fdrepdlg.h>
81
82#define FR_HISTORY_LIST_CNT 10
83
84
85BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
88
89 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
90END_EVENT_TABLE()
91
92
93bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
94
95
96EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
97 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
98 long aStyle, const wxString& aFrameName,
99 const EDA_IU_SCALE& aIuScale ) :
100 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName,
101 aIuScale ),
102 m_socketServer( nullptr ),
103 m_lastToolbarIconSize( 0 )
104{
105 m_gridSelectBox = nullptr;
106 m_zoomSelectBox = nullptr;
107 m_searchPane = nullptr;
108 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
109
111 m_canvas = nullptr;
112 m_toolDispatcher = nullptr;
113 m_messagePanel = nullptr;
114 m_currentScreen = nullptr;
115 m_showBorderAndTitleBlock = false; // true to display reference sheet.
116 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
117 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
118 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
119 m_colorSettings = nullptr;
120 m_polarCoords = false;
121 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
122 m_hotkeyPopup = nullptr;
123 m_propertiesPanel = nullptr;
124 m_netInspectorPanel = nullptr;
125
126 SetUserUnits( EDA_UNITS::MM );
127
128 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
129
130 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
131 {
132 CreateStatusBar( 8 )->SetDoubleBuffered( true );
133
134 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
135
136 // set the size of the status bar subwindows:
137 updateStatusBarWidths();
138 }
139
140 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
141 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
142 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
143
144 // Create child subwindows.
145 GetClientSize( &m_frameSize.x, &m_frameSize.y );
146 m_framePos.x = m_framePos.y = 0;
147 m_frameSize.y -= m_msgFrameHeight;
148
149 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
150
151 Bind( wxEVT_DPI_CHANGED,
152 [&]( wxDPIChangedEvent& )
153 {
154 if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
155 updateStatusBarWidths();
156
157 wxMoveEvent dummy;
158 OnMove( dummy );
159
160 // we need to kludge the msg panel to the correct size again
161 // especially important even for first launches as the constructor of the window
162 // here usually doesn't have the correct dpi awareness yet
163 m_frameSize.y += m_msgFrameHeight;
164 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
165 m_frameSize.y -= m_msgFrameHeight;
166
167 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
168 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
169
170 // Don't skip, otherwise the frame gets too big
171 } );
172}
173
174
176{
179
180 delete m_actions;
181 delete m_toolManager;
182 delete m_toolDispatcher;
183 delete m_canvas;
184
185 delete m_currentScreen;
186 m_currentScreen = nullptr;
187
188 m_auimgr.UnInit();
189
190 ReleaseFile();
191}
192
193
195{
197
198 // Grid selection
199 auto gridSelectorFactory =
200 [this]( ACTION_TOOLBAR* aToolbar )
201 {
202 if( !m_gridSelectBox )
203 {
204 m_gridSelectBox = new wxChoice( aToolbar, ID_ON_GRID_SELECT, wxDefaultPosition,
205 wxDefaultSize, 0, nullptr );
206 }
207
209
210 aToolbar->Add( m_gridSelectBox );
211 };
212
214
215 // Zoom selection
216 auto zoomSelectorFactory =
217 [this]( ACTION_TOOLBAR* aToolbar )
218 {
219 if( !m_zoomSelectBox )
220 {
221 m_zoomSelectBox = new wxChoice( aToolbar, ID_ON_ZOOM_SELECT, wxDefaultPosition,
222 wxDefaultSize, 0, nullptr );
223 }
224
226 aToolbar->Add( m_zoomSelectBox );
227 };
228
230}
231
232
234{
235 if( m_file_checker.get() != nullptr )
236 m_file_checker->UnlockFile();
237}
238
239
240bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
241{
242 // We need to explicitly reset here to get the deletion before
243 // we create a new unique_ptr that may be for the same file
244 m_file_checker.reset();
245
246 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
247
248 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
249 {
250 // If we cannot acquire the lock but we appear to be the one who
251 // locked it, check to see if there is another KiCad instance running.
252 // If there is not, then we can override the lock. This could happen if
253 // KiCad crashed or was interrupted
254 if( !Pgm().SingleInstance()->IsAnotherRunning() )
255 m_file_checker->OverrideLock();
256 }
257 // If the file is valid, return true. This could mean that the file is
258 // locked or it could mean that the file is read-only
259 return m_file_checker->Valid();
260}
261
262
264{
265 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
266
267 wxRect rect = GetScreenRect();
268 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
269
270 if( !frame )
271 {
272 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
273
274 // If we received an error in the CTOR due to Python-ness, don't crash
275 if( !frame )
276 return;
277
278 if( !frame->IsVisible() )
279 frame->Show( true );
280
281 // On Windows, Raise() does not bring the window on screen, when iconized
282 if( frame->IsIconized() )
283 frame->Iconize( false );
284
285 frame->Raise();
286 frame->SetPosition( center - frame->GetSize() / 2 );
287
288 return;
289 }
290
291 frame->Show( !frame->IsVisible() );
292 frame->SetPosition( center - frame->GetSize() / 2 );
293}
294
295
297{
298 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
299 return frame && frame->IsVisible();
300}
301
302
304{
305 // Notify all tools the units have changed
306 if( m_toolManager )
308
312}
313
314
316{
318 {
320 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
321 }
322 else
323 {
324 SetUserUnits( GetUserUnits() == EDA_UNITS::INCH ? EDA_UNITS::MM : EDA_UNITS::INCH );
326
327 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
328 ProcessEventLocally( e );
329 }
330}
331
332
334{
336
337 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
339
340 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
341 {
342 if( GetAutoSaveInterval() > 0 )
343 {
344 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
345 }
346 else
347 {
348 m_autoSaveTimer->Stop();
349 m_autoSavePending = false;
350 }
351 }
352
353 viewControls->LoadSettings();
354
355 m_galDisplayOptions.ReadCommonConfig( *settings, this );
356
357 GetToolManager()->RunAction( ACTIONS::gridPreset, config()->m_Window.grid.last_size_idx );
359
360 if( m_lastToolbarIconSize == 0
362 {
365 }
366
367#ifndef __WXMAC__
369
370 if( m_canvasType != GetCanvas()->GetBackend() )
371 {
372 // Try to switch (will automatically fallback if necessary)
375 bool success = newGAL == m_canvasType;
376
377 if( !success )
378 {
379 m_canvasType = newGAL;
380 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
381 }
382 }
383#endif
384
385 // Notify all tools the preferences have changed
386 if( m_toolManager )
388}
389
390
392{
393 if( m_messagePanel )
395}
396
397
399{
402
403 if( m_gridSelectBox == nullptr )
404 return;
405
406 // Update grid values with the current units setting.
407 m_gridSelectBox->Clear();
408 wxArrayString gridsList;
409
410 wxCHECK( config(), /* void */ );
411
412 GRID_MENU::BuildChoiceList( &gridsList, config(), this );
413
414 for( const wxString& grid : gridsList )
415 m_gridSelectBox->Append( grid );
416
417 m_gridSelectBox->Append( wxT( "---" ) );
418 m_gridSelectBox->Append( _( "Edit Grids..." ) );
419
420 m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
421}
422
423
424void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
425{
426 // No need to update the grid select box if it doesn't exist or the grid setting change
427 // was made using the select box.
428 if( m_gridSelectBox == nullptr )
429 return;
430
431 wxCHECK( config(), /* void */ );
432
433 int idx = config()->m_Window.grid.last_size_idx;
434 idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
435
436 if( idx != m_gridSelectBox->GetSelection() )
437 m_gridSelectBox->SetSelection( idx );
438}
439
440
441
442void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
443{
444 // No need to update the grid select box if it doesn't exist or the grid setting change
445 // was made using the select box.
446 if( m_zoomSelectBox == nullptr )
447 return;
448
449 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
450
451 wxCHECK( config(), /* void */ );
452
453 const std::vector<double>& zoomList = config()->m_Window.zoom_factors;
454 int curr_selection = m_zoomSelectBox->GetSelection();
455 int new_selection = 0; // select zoom auto
456 double last_approx = 1e9; // large value to start calculation
457
458 // Search for the nearest available value to the current zoom setting, and select it
459 for( size_t jj = 0; jj < zoomList.size(); ++jj )
460 {
461 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
462
463 if( rel_error < last_approx )
464 {
465 last_approx = rel_error;
466
467 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
468 new_selection = jj + 1;
469 }
470 }
471
472 if( curr_selection != new_selection )
473 m_zoomSelectBox->SetSelection( new_selection );
474}
475
476
477void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
478{
479 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
480
481 int idx = m_gridSelectBox->GetCurrentSelection();
482
483 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
484 {
485 // wxWidgets will check the separator, which we don't want.
486 // Re-check the current grid.
487 wxUpdateUIEvent dummy;
489 }
490 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
491 {
492 // wxWidgets will check the Grid Settings... entry, which we don't want.
493 // Re-check the current grid.
494 wxUpdateUIEvent dummy;
496
497 // Give a time-slice to close the menu before opening the dialog.
498 // (Only matters on some versions of GTK.)
499 wxSafeYield();
500
502 }
503 else
504 {
506 }
507
509 m_canvas->Refresh();
510
511 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
512 // (Windows specific
514}
515
516
518{
519 wxCHECK( config(), true );
520
521 return config()->m_Window.grid.show;
522}
523
524
526{
527 wxCHECK( config(), /* void */ );
528
529 config()->m_Window.grid.show = aVisible;
530
531 // Update the display with the new grid
532 if( GetCanvas() )
533 {
534 // Check to ensure these exist, since this function could be called before
535 // the GAL and View have been created
536 if( GetCanvas()->GetGAL() )
537 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
538
539 if( GetCanvas()->GetView() )
541
542 GetCanvas()->Refresh();
543 }
544}
545
546
548{
549 wxCHECK( config(), false );
550
552}
553
554
556{
557 wxCHECK( config(), /* void */ );
558
559 config()->m_Window.grid.overrides_enabled = aOverride;
560}
561
562
563std::unique_ptr<GRID_HELPER> EDA_DRAW_FRAME::MakeGridHelper()
564{
565 return nullptr;
566}
567
568
570{
571 if( m_zoomSelectBox == nullptr )
572 return;
573
574 double zoom = m_canvas->GetGAL()->GetZoomFactor();
575
576 m_zoomSelectBox->Clear();
577 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
578 m_zoomSelectBox->SetSelection( 0 );
579
580 wxCHECK( config(), /* void */ );
581
582 for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
583 {
584 double current = config()->m_Window.zoom_factors[i];
585
586 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
587
588 if( zoom == current )
589 m_zoomSelectBox->SetSelection( i + 1 );
590 }
591}
592
593
594void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
595{
596 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
597
598 int id = m_zoomSelectBox->GetCurrentSelection();
599
600 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
601 return;
602
605 m_canvas->Refresh();
606
607 // Needed on Windows because clicking on m_zoomSelectBox remove the focus from m_canvas
608 // (Windows specific
610}
611
612
613void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
614{
615 // If the window is moved to a different display, the scaling factor may change
616 double oldFactor = m_galDisplayOptions.m_scaleFactor;
618
619 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
620 {
621 wxSize clientSize = GetClientSize();
622 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
624 }
625
626 aEvent.Skip();
627}
628
629
631{
633 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
634
635 aMenu.AddSeparator( 1000 );
636
637 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
638 zoomMenu->SetTool( commonTools );
639 aToolMenu.RegisterSubMenu( zoomMenu );
640
641 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
642 gridMenu->SetTool( commonTools );
643 aToolMenu.RegisterSubMenu( gridMenu );
644
645 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
646 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
647}
648
649
650void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
651{
652 if( m_isClosing )
653 return;
654
655 SetStatusText( msg, 6 );
656}
657
658
659void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
660{
661 if( m_isClosing )
662 return;
663
664 SetStatusText( msg, 7 );
665}
666
667
669{
670 if( m_isClosing )
671 return;
672
673 wxString msg;
674
677
678 msg.Printf( _( "grid %s" ),
679 gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
680
681 SetStatusText( msg, 4 );
682}
683
684
686{
687 if( m_isClosing )
688 return;
689
690 wxString msg;
691
692 switch( GetUserUnits() )
693 {
694 case EDA_UNITS::INCH: msg = _( "inches" ); break;
695 case EDA_UNITS::MILS: msg = _( "mils" ); break;
696 case EDA_UNITS::MM: msg = _( "mm" ); break;
697 default: msg = _( "Units" ); break;
698 }
699
700 SetStatusText( msg, 5 );
701}
702
703
704void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
705{
706 EDA_BASE_FRAME::OnSize( SizeEv );
707
708 m_frameSize = GetClientSize( );
709
710 SizeEv.Skip();
711}
712
713
715{
716 wxWindow* stsbar = GetStatusBar();
717 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
718
719 int dims[] = {
720 // remainder of status bar on far left is set to a default or whatever is left over.
721 -1,
722
723 // When using GetTextSize() remember the width of character '1' is not the same
724 // as the width of '0' unless the font is fixed width, and it usually won't be.
725
726 // zoom:
727 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
728
729 // cursor coords
730 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
731
732 // delta distances
733 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
734
735 // grid size
736 KIUI::GetTextSize( wxT( "grid X 1234.1234 Y 1234.1234" ), stsbar ).x,
737
738 // units display, Inches is bigger than mm
739 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
740
741 // Size for the "Current Tool" panel; longest string from SetTool()
742 KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
743
744 // constraint mode
745 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
746 };
747
748 for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
749 dims[ii] += spacer;
750
751 SetStatusWidths( arrayDim( dims ), dims );
752}
753
754
756{
757 if( m_isClosing )
758 return;
759
760 SetStatusText( GetZoomLevelIndicator(), 1 );
761
762 // Absolute and relative cursor positions are handled by overloading this function and
763 // handling the internal to user units conversion at the appropriate level.
764
765 // refresh units display
767}
768
769
771{
772 // returns a human readable value which can be displayed as zoom
773 // level indicator in dialogs.
774 double zoom = m_canvas->GetGAL()->GetZoomFactor();
775 return wxString::Format( wxT( "Z %.2f" ), zoom );
776}
777
778
780{
782
784 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
785
786 // Read units used in dialogs and toolbars
787 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
788
790
791 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
792
793 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
794 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
795 m_findReplaceData->matchMode =
796 static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
797 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
798 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
799
800 for( const wxString& s : aCfg->m_FindReplace.find_history )
802
803 for( const wxString& s : aCfg->m_FindReplace.replace_history )
805
807}
808
809
811{
813
814 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
815
816 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
818
820
821 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
822
823 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
824 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
825
826 aCfg->m_FindReplace.find_history.clear();
827 aCfg->m_FindReplace.replace_history.clear();
828
829 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
830 {
831 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
832 }
833
834 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
835 {
836 aCfg->m_FindReplace.replace_history.push_back(
837 m_replaceStringHistoryList[ i ].ToStdString() );
838 }
839
840 // Save the units used in this frame
841 if( m_toolManager )
842 {
844 {
846 static_cast<int>( cmnTool->GetLastImperialUnits() );
847 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
848 }
849 }
850}
851
852
853void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
854 int aPadding )
855{
857 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
858}
859
860
862{
865}
866
867
868void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
869{
871 {
873
874 for( const MSG_PANEL_ITEM& item : aList )
876 }
877}
878
879
880void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
881 int aPadding )
882{
884 {
886 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
887 }
888}
889
890
892{
893 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
894
895 std::vector<MSG_PANEL_ITEM> items;
896 aItem->GetMsgPanelInfo( this, items );
897 SetMsgPanel( items );
898}
899
900
902{
903}
904
905
907{
908 GetCanvas()->SetEvtHandlerEnabled( true );
910}
911
912
914{
915 GetCanvas()->SwitchBackend( aCanvasType );
917
919}
920
921
923{
924#ifdef __WXMAC__
925 // Cairo renderer doesn't handle Retina displays so there's really only one game
926 // in town for Mac
928#endif
929
932
933 if( cfg )
934 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
935
936 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
937 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
938 {
939 wxASSERT( false );
941 }
942
943 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
944 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
946
947 wxString envCanvasType;
948
949 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) )
950 {
951 if( envCanvasType.CmpNoCase( "1" ) == 0
952 || envCanvasType.CmpNoCase( "true" ) == 0
953 || envCanvasType.CmpNoCase( "yes" ) == 0 )
954 {
955 // Force software rendering if the environment variable is set
957 }
958 }
959
960 return canvasType;
961}
962
963
965{
966 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
967 // have a fixed type, or do not have a option to set the canvas type (they inherit from
968 // a parent frame)
969 static std::vector<FRAME_T> s_allowedFrames =
970 {
975 };
976
977 if( !alg::contains( s_allowedFrames, m_ident ) )
978 return false;
979
980 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) )
981 {
982 // If the environment variable is set, don't save the canvas type.
983 return false;
984 }
985
986 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
987 || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
988 {
989 wxASSERT( false );
990 return false;
991 }
992
993 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
994 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
995
996 return false;
997}
998
999
1001{
1002 const VECTOR2I& gridOrigin = GetGridOrigin();
1003 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
1004
1005 double xOffset = fmod( gridOrigin.x, gridSize.x );
1006 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1007 double yOffset = fmod( gridOrigin.y, gridSize.y );
1008 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1009
1010 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
1011}
1012
1013
1015{
1016 const VECTOR2I& gridOrigin = GetGridOrigin();
1017 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
1018
1019 double xOffset = fmod( gridOrigin.x, gridSize.x );
1020 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1021 double yOffset = fmod( gridOrigin.y, gridSize.y );
1022 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1023
1024 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
1025}
1026
1027
1028const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1029{
1030 return BOX2I();
1031}
1032
1033
1035{
1036 // To be implemented by subclasses.
1037}
1038
1039
1040void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1041{
1043}
1044
1045
1046std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
1047{
1048 std::vector<wxWindow*> dialogs;
1049
1050 for( wxWindow* window : GetChildren() )
1051 {
1052 if( dynamic_cast<DIALOG_SHIM*>( window ) )
1053 dialogs.push_back( window );
1054 }
1055
1056 return dialogs;
1057}
1058
1059
1061{
1062 bool centerView = false;
1063 BOX2D r = GetCanvas()->GetView()->GetViewport();
1064
1065 // Center if we're off the current view, or within 10% of its edge
1066 r.Inflate( - (int) r.GetWidth() / 10 );
1067
1068 if( !r.Contains( aPos ) )
1069 centerView = true;
1070
1071 std::vector<BOX2D> dialogScreenRects;
1072
1073 for( wxWindow* dialog : findDialogs() )
1074 {
1075 dialogScreenRects.emplace_back(
1076 ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1077 ToVECTOR2D( dialog->GetSize() ) );
1078 }
1079
1080 // Center if we're behind an obscuring dialog, or within 10% of its edge
1081 for( BOX2D rect : dialogScreenRects )
1082 {
1083 rect.Inflate( rect.GetWidth() / 10 );
1084
1085 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1086 centerView = true;
1087 }
1088
1089 if( centerView )
1090 {
1091 try
1092 {
1093 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1094 }
1095 catch( const Clipper2Lib::Clipper2Exception& e )
1096 {
1097 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ),
1098 e.what() ) );
1099 }
1100 }
1101
1103}
1104
1105
1106static const wxString productName = wxT( "KiCad E.D.A. " );
1107
1108
1109void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1110 const wxString& aSheetName, const wxString& aSheetPath,
1111 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1112 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1113 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1114 const wxString& aSheetLayer, bool aIsFirstPage )
1115{
1116 DS_DRAW_ITEM_LIST drawList( unityScale );
1117
1118 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1119 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1120 drawList.SetPageNumber( aPageNumber );
1121 drawList.SetSheetCount( aSheetCount );
1122 drawList.SetFileName( aFileName );
1123 drawList.SetSheetName( aSheetName );
1124 drawList.SetSheetPath( aSheetPath );
1125 drawList.SetSheetLayer( aSheetLayer );
1126 drawList.SetProject( aProject );
1127 drawList.SetIsFirstPage( aIsFirstPage );
1128 drawList.SetProperties( aProperties );
1129
1130 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1131
1132 // Draw item list
1133 drawList.Print( aSettings );
1134}
1135
1136
1138 const std::map<wxString, wxString>* aProperties,
1139 double aMils2Iu, const wxString &aFilename,
1140 const wxString &aSheetLayer )
1141{
1143 return;
1144
1145 wxDC* DC = aSettings->GetPrintDC();
1146 wxPoint origin = DC->GetDeviceOrigin();
1147
1148 if( origin.y > 0 )
1149 {
1150 DC->SetDeviceOrigin( 0, 0 );
1151 DC->SetAxisOrientation( true, false );
1152 }
1153
1155 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1156 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1157 aScreen->GetVirtualPageNumber() == 1 );
1158
1159 if( origin.y > 0 )
1160 {
1161 DC->SetDeviceOrigin( origin.x, origin.y );
1162 DC->SetAxisOrientation( true, true );
1163 }
1164}
1165
1166
1168{
1169 // Virtual function. Base class implementation returns an empty string.
1170 return wxEmptyString;
1171}
1172
1173
1175{
1176 // Virtual function. Base class implementation returns an empty string.
1177 return wxEmptyString;
1178}
1179
1180
1181bool EDA_DRAW_FRAME::LibraryFileBrowser( const wxString& aTitle, bool doOpen, wxFileName& aFilename,
1182 const wxString& wildcard, const wxString& ext,
1183 bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY* aFileDlgHook )
1184{
1185 aFilename.SetExt( ext );
1186
1187 wxString defaultDir = aFilename.GetPath();
1188
1189 if( defaultDir.IsEmpty() )
1190 defaultDir = GetMruPath();
1191
1192 if( isDirectory && doOpen )
1193 {
1194 wxDirDialog dlg( this, aTitle, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1195
1196 if( dlg.ShowModal() == wxID_CANCEL )
1197 return false;
1198
1199 aFilename = dlg.GetPath();
1200 aFilename.SetExt( ext );
1201 }
1202 else
1203 {
1204 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1205 if( aFilename.GetName().empty() )
1206 aFilename.SetName( wxS( "Library" ) );
1207
1208 wxFileDialog dlg( this, aTitle, defaultDir, aFilename.GetFullName(), wildcard,
1209 doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1210 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1211
1212 if( aFileDlgHook )
1213 dlg.SetCustomizeHook( *aFileDlgHook );
1214
1215 if( dlg.ShowModal() == wxID_CANCEL )
1216 return false;
1217
1218 aFilename = dlg.GetPath();
1219 aFilename.SetExt( ext );
1220 }
1221
1222 SetMruPath( aFilename.GetPath() );
1223
1224 return true;
1225}
1226
1227
1229{
1231
1232 if( m_searchPane )
1233 {
1234 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1235 search_pane_info.Caption( _( "Search" ) );
1236 }
1237
1238 if( m_propertiesPanel )
1239 {
1240 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1241 properties_pane_info.Caption( _( "Properties" ) );
1242 }
1243
1245 {
1246 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1247 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1248 }
1249}
1250
1251
1253{
1254 if( m_isClosing || !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1255 return;
1256
1258}
1259
1260
1262{
1263 m_hotkeyPopup = new HOTKEY_CYCLE_POPUP( this );
1264}
1265
1266
1268{
1269 if( !m_colorSettings || aForceRefresh )
1270 {
1272 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1273 }
1274
1275 return m_colorSettings;
1276}
1277
1278
1280{
1282
1283 if( cmnTool )
1284 {
1285 // Tell the tool what the units used last session
1286 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1287 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1288 }
1289
1290 // Tell the tool what units the frame is currently using
1291 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1292 {
1293 default:
1294 case EDA_UNITS::MM: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1295 case EDA_UNITS::INCH: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1296 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1297 }
1298}
1299
1300
1301void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1302{
1304
1305 aPrimaryUnit = GetUserUnits();
1306 aSecondaryUnits = EDA_UNITS::MILS;
1307
1308 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1309 {
1310 if( cmnTool )
1311 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1312 else
1313 aSecondaryUnits = EDA_UNITS::MM;
1314 }
1315 else
1316 {
1317 if( cmnTool )
1318 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1319 else
1320 aSecondaryUnits = EDA_UNITS::MILS;
1321 }
1322}
1323
1324
1326{
1328
1329 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1330 // user preference silently:
1331
1334}
1335
1336
1337void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1338{
1339 // Force a refresh of the message panel to ensure that the text is the right color
1340 // when the window activates
1341 if( !IsIconized() )
1342 m_messagePanel->Refresh();
1343}
1344
1345
1346void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1347{
1348 handleActivateEvent( aEvent );
1349
1350 aEvent.Skip();
1351}
1352
1353
1354bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName,
1355 BITMAP_TYPE aBitmapType )
1356{
1357 bool retv = true;
1358
1359 // Make a screen copy of the canvas:
1360 wxSize image_size = GetCanvas()->GetClientSize();
1361
1362 wxClientDC dc( GetCanvas() );
1363 wxBitmap bitmap( image_size.x, image_size.y );
1364 wxMemoryDC memdc;
1365
1366 memdc.SelectObject( bitmap );
1367 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1368 memdc.SelectObject( wxNullBitmap );
1369
1370 wxImage image = bitmap.ConvertToImage();
1371
1372 wxBitmapType type = wxBITMAP_TYPE_PNG;
1373 switch( aBitmapType )
1374 {
1375 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1376 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1377 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1378 }
1379
1380 if( !image.SaveFile( aFileName, type ) )
1381 retv = false;
1382
1383 image.Destroy();
1384 return retv;
1385}
1386
1387
1389 APP_SETTINGS_BASE* aCfg )
1390{
1391 wxCHECK( aCfg, aAction.show_button );
1392
1393 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1394 {
1395 if( identifier == aAction.identifier )
1396 return visible;
1397 }
1398
1399 return aAction.show_button;
1400}
1401
1402
1403std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions(
1405{
1406 std::vector<const PLUGIN_ACTION*> actions;
1407 wxCHECK( aCfg, actions );
1408
1409#ifdef KICAD_IPC_API
1410
1411 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1412 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1413 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1414 std::set<const PLUGIN_ACTION*> handled;
1415
1416 for( const PLUGIN_ACTION* action : unsorted )
1417 actionMap[action->identifier] = action;
1418
1419 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1420 {
1421 if( actionMap.contains( identifier ) )
1422 {
1423 const PLUGIN_ACTION* action = actionMap[ identifier ];
1424 actions.emplace_back( action );
1425 handled.insert( action );
1426 }
1427 }
1428
1429 for( const auto& action : actionMap | std::views::values )
1430 {
1431 if( !handled.contains( action ) )
1432 actions.emplace_back( action );
1433 }
1434
1435#endif
1436
1437 return actions;
1438}
1439
1440
1442{
1443#ifdef KICAD_IPC_API
1444 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1445
1446 mgr.ButtonBindings().clear();
1447
1448 std::vector<const PLUGIN_ACTION*> actions =
1450
1451 for( const PLUGIN_ACTION* action : actions )
1452 {
1453 if( !IsPluginActionButtonVisible( *action, config() ) )
1454 continue;
1455
1456 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk()
1457 ? action->icon_dark
1458 : action->icon_light;
1459
1460 wxAuiToolBarItem* button = aToolbar->AddTool( wxID_ANY, wxEmptyString, icon,
1461 action->name );
1462
1463 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1464 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1465
1466 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1467 }
1468#endif
1469}
1470
1471
1472void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1473{
1474#ifdef KICAD_IPC_API
1475 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1476
1477 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1478 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ) );
1479#endif
1480}
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:56
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:115
BITMAP_TYPE
Definition: bitmap_types.h:43
BOX2< VECTOR2I > BOX2I
Definition: box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static TOOL_ACTION gridProperties
Definition: actions.h:197
static TOOL_ACTION millimetersUnits
Definition: actions.h:203
static TOOL_ACTION updatePreferences
Definition: actions.h:273
static TOOL_ACTION gridPreset
Definition: actions.h:194
static TOOL_ACTION updateUnits
Definition: actions.h:204
static TOOL_ACTION milsUnits
Definition: actions.h:202
static TOOL_ACTION inchesUnits
Definition: actions.h:201
static TOOL_ACTION zoomFitScreen
Definition: actions.h:141
static TOOL_ACTION zoomPreset
Definition: actions.h:144
static ACTION_TOOLBAR_CONTROL gridSelect
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.
Definition: app_settings.h:108
WINDOW_SETTINGS m_Window
Definition: app_settings.h:233
FIND_REPLACE m_FindReplace
Definition: app_settings.h:215
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
Definition: base_screen.cpp:70
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.
Definition: common_tools.h:38
void SetLastUnits(EDA_UNITS aUnit)
EDA_UNITS GetLastImperialUnits()
Definition: common_tools.h:79
EDA_UNITS GetLastMetricUnits()
Definition: common_tools.h:78
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:61
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:401
void SetPlotterMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to plot units.
Definition: ds_draw_item.h:468
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.
Definition: ds_draw_item.h:455
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:445
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:462
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.
Definition: ds_draw_item.h:450
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:494
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:435
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:460
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:499
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:489
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:425
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.
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
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.
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.
bool IsGridOverridden() const
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.
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Store the canvas type in the application settings.
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.
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
void ToggleUserUnits() override
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 updateStatusBarWidths()
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.
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
bool IsGridVisible() const
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.
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.
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.
void SetFocus() override
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:220
A panel to display various information messages.
Definition: msgpanel.h:101
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:114
void EraseMsgBox()
Definition: msgpanel.cpp:218
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.
void WriteConfig(WINDOW_SETTINGS &aCfg)
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *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:104
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.
int GetDefaultPenWidth() const
wxDC * GetPrintDC() const
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:530
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:596
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:639
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:286
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:395
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:59
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:565
Container for project specific data.
Definition: project.h:65
virtual void UpdateData()=0
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
Definition: tools_holder.h:171
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:173
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
ACTIONS * m_actions
Definition: tools_holder.h:172
Generic, UI-independent tool event.
Definition: tool_event.h:168
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
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:404
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.
static const wxString productName
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:114
@ ID_ON_ZOOM_SELECT
Definition: id.h:112
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:48
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:132
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.
Definition: pgm_base.cpp:902
see class PGM_BASE
#define DEFAULT_THEME
std::vector< FAB_LAYER_COLOR > dummy
std::vector< wxString > replace_history
Definition: app_settings.h:115
std::vector< wxString > find_history
Definition: app_settings.h:113
std::vector< std::pair< wxString, bool > > actions
Ordered list of plugin actions mapped to whether or not they are shown in the toolbar.
Definition: app_settings.h:199
int canvas_type
EDA_DRAW_PANEL_GAL::GAL_TYPE_* value, see gal_options_panel.cpp.
bool overrides_enabled
Definition: grid_settings.h:78
std::vector< GRID > grids
Definition: grid_settings.h:66
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
bool show_button
Definition: api_plugin.h:90
Store the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:90
GRID_SETTINGS grid
Definition: app_settings.h:97
std::vector< double > zoom_factors
Definition: app_settings.h:94
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
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition: vector2wx.h:40