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 <eda_search_data.h>
36#include <file_history.h>
38#include <id.h>
39#include <kiface_base.h>
40#include <kiplatform/ui.h>
41#include <lockfile.h>
42#include <macros.h>
43#include <math/vector2wx.h>
44#include <page_info.h>
45#include <paths.h>
46#include <pgm_base.h>
47#include <render_settings.h>
52#include <title_block.h>
53#include <tool/actions.h>
54#include <tool/action_toolbar.h>
55#include <tool/common_tools.h>
56#include <tool/grid_helper.h>
57#include <tool/grid_menu.h>
60#include <tool/tool_manager.h>
61#include <tool/tool_menu.h>
62#include <tool/zoom_menu.h>
63#include <trace_helpers.h>
64#include <view/view.h>
66#include <view/view_controls.h>
67#include <widgets/kistatusbar.h>
68#include <widgets/msgpanel.h>
72#include <wx/event.h>
73#include <wx/snglinst.h>
74#include <widgets/ui_common.h>
75#include <widgets/search_pane.h>
76#include <wx/dirdlg.h>
77#include <wx/filedlg.h>
78#include <wx/debug.h>
79#include <wx/socket.h>
80
81#include <wx/snglinst.h>
82#include <wx/fdrepdlg.h>
84
85#define FR_HISTORY_LIST_CNT 10
86
87
88BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
91
92 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
93END_EVENT_TABLE()
94
95
96bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
97
98
99EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
100 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
101 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale ) :
102 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
103 m_socketServer( nullptr ),
105{
106 m_gridSelectBox = nullptr;
107 m_zoomSelectBox = nullptr;
108 m_overrideLocksCb = nullptr;
109 m_searchPane = nullptr;
111
113 m_canvas = nullptr;
114 m_toolDispatcher = nullptr;
115 m_messagePanel = nullptr;
116 m_currentScreen = nullptr;
117 m_showBorderAndTitleBlock = false; // true to display reference sheet.
118 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
119 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
120 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
121 m_colorSettings = nullptr;
122 m_polarCoords = false;
123 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
124 m_hotkeyPopup = nullptr;
125 m_propertiesPanel = nullptr;
126 m_netInspectorPanel = nullptr;
127
129
130 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
131
132 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
133 {
134 CreateStatusBar( 8 )->SetDoubleBuffered( true );
135
136 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
137
138 // set the size of the status bar subwindows:
140 }
141
142 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
143 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
144 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
145
146 // Create child subwindows.
147 GetClientSize( &m_frameSize.x, &m_frameSize.y );
148 m_framePos.x = m_framePos.y = 0;
150
152
153 Bind( wxEVT_DPI_CHANGED,
154 [&]( wxDPIChangedEvent& aEvent )
155 {
156 if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
158
159 wxMoveEvent dummy;
160 OnMove( dummy );
161
162 // we need to kludge the msg panel to the correct size again
163 // especially important even for first launches as the constructor of the window
164 // here usually doesn't have the correct dpi awareness yet
166 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
168
169 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
171
172 aEvent.Skip();
173 } );
174}
175
176
178{
181
182 delete m_actions;
183 delete m_toolManager;
184 delete m_toolDispatcher;
185 delete m_canvas;
186
187 delete m_currentScreen;
188 m_currentScreen = nullptr;
189
190 m_auimgr.UnInit();
191
192 ReleaseFile();
193}
194
195
200
201
203{
205
206 // Grid selection
207 auto gridSelectorFactory =
208 [this]( ACTION_TOOLBAR* aToolbar )
209 {
210 if( !m_gridSelectBox )
211 m_gridSelectBox = new wxChoice( aToolbar, ID_ON_GRID_SELECT );
212
214
215 aToolbar->Add( m_gridSelectBox );
216 };
217
219
220 // Zoom selection
221 auto zoomSelectorFactory =
222 [this]( ACTION_TOOLBAR* aToolbar )
223 {
224 if( !m_zoomSelectBox )
225 m_zoomSelectBox = new wxChoice( aToolbar, ID_ON_ZOOM_SELECT );
226
228 aToolbar->Add( m_zoomSelectBox );
229 };
230
232
233 auto overrideLocksFactory =
234 [this]( ACTION_TOOLBAR* aToolbar )
235 {
236 if( !m_overrideLocksCb )
237 m_overrideLocksCb = new wxCheckBox( aToolbar, ID_ON_OVERRIDE_LOCKS, _( "Override locks" ) );
238
239 aToolbar->Add( m_overrideLocksCb );
240 };
241
243}
244
245
247{
248 switch( aId )
249 {
250 case ID_ON_GRID_SELECT: m_gridSelectBox = nullptr; break;
251 case ID_ON_ZOOM_SELECT: m_zoomSelectBox = nullptr; break;
252 case ID_ON_OVERRIDE_LOCKS: m_overrideLocksCb = nullptr; break;
253 }
254}
255
256
258{
259 if( m_file_checker )
260 m_file_checker->UnlockFile();
261}
262
263
264bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
265{
266 // We need to explicitly reset here to get the deletion before we create a new unique_ptr that
267 // may be for the same file.
268 m_file_checker.reset();
269
270 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
271
272 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
273 {
274 // If we cannot acquire the lock but we appear to be the one who locked it, check to see if
275 // there is another KiCad instance running. If there is not, then we can override the lock.
276 // This could happen if KiCad crashed or was interrupted.
277 if( !Pgm().SingleInstance()->IsAnotherRunning() )
278 m_file_checker->OverrideLock();
279 }
280
281 // If the file is valid, return true. This could mean that the file is locked or it could mean
282 // that the file is read-only.
283 return m_file_checker->Valid();
284}
285
286
288{
289 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
290
291 wxRect rect = GetScreenRect();
292 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
293
294 if( !frame )
295 {
296 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
297
298 // If we received an error in the CTOR due to Python-ness, don't crash
299 if( !frame )
300 return;
301
302 if( !frame->IsVisible() )
303 frame->Show( true );
304
305 // On Windows, Raise() does not bring the window on screen, when iconized
306 if( frame->IsIconized() )
307 frame->Iconize( false );
308
309 frame->Raise();
310 frame->SetPosition( center - frame->GetSize() / 2 );
311
312 return;
313 }
314
315 frame->Show( !frame->IsVisible() );
316 frame->SetPosition( center - frame->GetSize() / 2 );
317}
318
319
321{
322 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
323 return frame && frame->IsVisible();
324}
325
326
328{
329 // Notify all tools the units have changed
330 if( m_toolManager )
332
336
337 switch( GetUserUnits() )
338 {
339 default:
343 }
344}
345
346
348{
349 if( m_toolManager->GetTool<COMMON_TOOLS>() )
350 {
352 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
353 }
354 else
355 {
358
359 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
360 ProcessEventLocally( e );
361 }
362}
363
364
366{
368
369 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
371
372 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
373 {
374 if( GetAutoSaveInterval() > 0 )
375 {
376 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
377 }
378 else
379 {
380 m_autoSaveTimer->Stop();
381 m_autoSavePending = false;
382 }
383 }
384
385 viewControls->LoadSettings();
386
387 m_galDisplayOptions.ReadCommonConfig( *settings, this );
388
391
392 if( m_lastToolbarIconSize == 0
394 {
397 }
398
399#ifndef __WXMAC__
401
402 if( m_canvasType != GetCanvas()->GetBackend() )
403 {
404 // Try to switch (will automatically fallback if necessary)
407 bool success = newGAL == m_canvasType;
408
409 if( !success )
410 {
411 m_canvasType = newGAL;
412 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
413 }
414 }
415#endif
416
417 // Notify all tools the preferences have changed
418 if( m_toolManager )
420}
421
422
424{
425 if( m_messagePanel )
426 m_messagePanel->EraseMsgBox();
427}
428
429
431{
434
435 if( m_gridSelectBox == nullptr )
436 return;
437
438 // Update grid values with the current units setting.
439 m_gridSelectBox->Clear();
440 wxArrayString gridsList;
441
442 wxCHECK( config(), /* void */ );
443
444 GRID_MENU::BuildChoiceList( &gridsList, GetWindowSettings( config() ), this );
445
446 for( const wxString& grid : gridsList )
447 m_gridSelectBox->Append( grid );
448
449 m_gridSelectBox->Append( wxT( "---" ) );
450 m_gridSelectBox->Append( _( "Edit Grids..." ) );
451
452 m_gridSelectBox->SetSelection( GetWindowSettings( config() )->grid.last_size_idx );
453}
454
455
456void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
457{
458 // No need to update the grid select box if it doesn't exist or the grid setting change
459 // was made using the select box.
460 if( m_gridSelectBox == nullptr )
461 return;
462
463 wxCHECK( config(), /* void */ );
464
466 idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
467
468 if( idx != m_gridSelectBox->GetSelection() )
469 m_gridSelectBox->SetSelection( idx );
470}
471
472
473
474void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
475{
476 // No need to update the grid select box if it doesn't exist or the grid setting change
477 // was made using the select box.
478 if( m_zoomSelectBox == nullptr )
479 return;
480
481 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
482
483 wxCHECK( config(), /* void */ );
484
485 const std::vector<double>& zoomList = GetWindowSettings( config() )->zoom_factors;
486 int curr_selection = m_zoomSelectBox->GetSelection();
487 int new_selection = 0; // select zoom auto
488 double last_approx = 1e9; // large value to start calculation
489
490 // Search for the nearest available value to the current zoom setting, and select it
491 for( size_t jj = 0; jj < zoomList.size(); ++jj )
492 {
493 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
494
495 if( rel_error < last_approx )
496 {
497 last_approx = rel_error;
498
499 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
500 new_selection = (int) jj + 1;
501 }
502 }
503
504 if( curr_selection != new_selection )
505 m_zoomSelectBox->SetSelection( new_selection );
506}
507
508
509void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
510{
511 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
512
513 int idx = m_gridSelectBox->GetCurrentSelection();
514
515 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
516 {
517 // wxWidgets will check the separator, which we don't want.
518 // Re-check the current grid.
519 wxUpdateUIEvent dummy;
521 }
522 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
523 {
524 // wxWidgets will check the Grid Settings... entry, which we don't want.
525 // Re-check the current grid.
526 wxUpdateUIEvent dummy;
528
529 // Give a time-slice to close the menu before opening the dialog.
530 // (Only matters on some versions of GTK.)
531 wxSafeYield();
532
534 }
535 else
536 {
537 m_toolManager->RunAction( ACTIONS::gridPreset, idx );
538 }
539
541 m_canvas->Refresh();
542
543 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
544 // (Windows specific
545 m_canvas->SetFocus();
546}
547
548
550{
552 return m_overrideLocksCb->GetValue();
553
554 return false;
555}
556
557
559{
560 wxCHECK( config(), true );
561
562 return GetWindowSettings( config() )->grid.show;
563}
564
565
567{
568 wxCHECK( config(), /* void */ );
569
570 GetWindowSettings( config() )->grid.show = aVisible;
571
572 // Update the display with the new grid
573 if( GetCanvas() )
574 {
575 // Check to ensure these exist, since this function could be called before
576 // the GAL and View have been created
577 if( GetCanvas()->GetGAL() )
578 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
579
580 if( GetCanvas()->GetView() )
582
583 GetCanvas()->Refresh();
584 }
585}
586
587
589{
590 wxCHECK( config(), false );
591
593}
594
595
597{
598 wxCHECK( config(), /* void */ );
599
601}
602
603
604std::unique_ptr<GRID_HELPER> EDA_DRAW_FRAME::MakeGridHelper()
605{
606 return nullptr;
607}
608
609
611{
612 if( m_zoomSelectBox == nullptr )
613 return;
614
615 double zoom = m_canvas->GetGAL()->GetZoomFactor();
616
617 m_zoomSelectBox->Clear();
618 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
619 m_zoomSelectBox->SetSelection( 0 );
620
621 wxCHECK( config(), /* void */ );
622
623 for( unsigned ii = 0; ii < GetWindowSettings( config() )->zoom_factors.size(); ++ii )
624 {
625 double current = GetWindowSettings( config() )->zoom_factors[ii];
626
627 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
628
629 if( zoom == current )
630 m_zoomSelectBox->SetSelection( (int) ii + 1 );
631 }
632}
633
634
635void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
636{
637 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
638
639 int id = m_zoomSelectBox->GetCurrentSelection();
640
641 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
642 return;
643
644 m_toolManager->RunAction( ACTIONS::zoomPreset, id );
646 m_canvas->Refresh();
647
648 // Needed on Windows (only) because clicking on m_zoomSelectBox removes the focus from m_canvas
649 m_canvas->SetFocus();
650}
651
652
653void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
654{
655 // If the window is moved to a different display, the scaling factor may change
656 double oldFactor = m_galDisplayOptions.m_scaleFactor;
657 m_galDisplayOptions.UpdateScaleFactor();
658
659 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
660 {
661 wxSize clientSize = GetClientSize();
662 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
664 }
665
666 aEvent.Skip();
667}
668
669
671{
672 COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
673 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
674
675 aMenu.AddSeparator( 1000 );
676
677 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
678 zoomMenu->SetTool( commonTools );
679 aToolMenu.RegisterSubMenu( zoomMenu );
680
681 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
682 gridMenu->SetTool( commonTools );
683 aToolMenu.RegisterSubMenu( gridMenu );
684
685 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
686 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
687}
688
689
690void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
691{
692 if( m_isClosing )
693 return;
694
695 SetStatusText( msg, 6 );
696}
697
698
699void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
700{
701 if( m_isClosing )
702 return;
703
704 SetStatusText( msg, 7 );
705}
706
707
709{
710 if( m_isClosing )
711 return;
712
713 wxString msg;
714
715 GRID_SETTINGS& gridSettings = m_toolManager->GetSettings()->m_Window.grid;
716 int currentIdx = m_toolManager->GetSettings()->m_Window.grid.last_size_idx;
717
718 msg.Printf( _( "grid %s" ), gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
719
720 SetStatusText( msg, 4 );
721}
722
723
725{
726 if( m_isClosing )
727 return;
728
729 wxString msg;
730
731 switch( GetUserUnits() )
732 {
733 case EDA_UNITS::INCH: msg = _( "inches" ); break;
734 case EDA_UNITS::MILS: msg = _( "mils" ); break;
735 case EDA_UNITS::MM: msg = _( "mm" ); break;
736 default: msg = _( "Units" ); break;
737 }
738
739 SetStatusText( msg, 5 );
740}
741
742
743void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
744{
745 EDA_BASE_FRAME::OnSize( SizeEv );
746
747 m_frameSize = GetClientSize( );
748
749 SizeEv.Skip();
750}
751
752
754{
755 constexpr int numLocalFields = 8;
756
757 wxStatusBar* stsbar = GetStatusBar();
758 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x;
759
760 // Note this is a KISTATUSBAR and there are fields to the right of the ones we know about
761 int totalFields = stsbar->GetFieldsCount();
762
763 std::vector<int> dims = {
764 // remainder of status bar on far left is set to a default or whatever is left over.
765 -3,
766
767 // When using GetTextSize() remember the width of character '1' is not the same
768 // as the width of '0' unless the font is fixed width, and it usually won't be.
769
770 // zoom:
771 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
772
773 // cursor coords
774 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
775
776 // delta distances
777 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
778
779 // grid size
780 KIUI::GetTextSize( wxT( "grid 1234.1234 x 1234.1234" ), stsbar ).x,
781
782 // units display, Inches is bigger than mm
783 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
784
785 // Size for the "Current Tool" panel
786 -2,
787
788 // constraint mode
789 -2
790 };
791
792 for( int& dim : dims )
793 {
794 if( dim >= 0 )
795 dim += spacer;
796 }
797
798 for( int idx = numLocalFields; idx < totalFields; ++idx )
799 dims.emplace_back( stsbar->GetStatusWidth( idx ) );
800
801 SetStatusWidths( dims.size(), dims.data() );
802}
803
804
805wxStatusBar* EDA_DRAW_FRAME::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
806{
807 return new KISTATUSBAR( number, this, id, KISTATUSBAR::STYLE_FLAGS::WARNING_ICON );
808}
809
810
812{
813 if( m_isClosing )
814 return;
815
816 SetStatusText( GetZoomLevelIndicator(), 1 );
817
818 // Absolute and relative cursor positions are handled by overloading this function and
819 // handling the internal to user units conversion at the appropriate level.
820
821 // refresh units display
823}
824
825
827{
828 // returns a human readable value which can be displayed as zoom
829 // level indicator in dialogs.
830 double zoom = m_canvas->GetGAL()->GetZoomFactor();
831 return wxString::Format( wxT( "Z %.2f" ), zoom );
832}
833
834
836{
838
840 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
841
842 // Read units used in dialogs and toolbars
843 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
844
846
847 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
848
849 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
850 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
851 m_findReplaceData->matchMode = static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
852 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
853 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
854
855 for( const wxString& s : aCfg->m_FindReplace.find_history )
857
858 for( const wxString& s : aCfg->m_FindReplace.replace_history )
860
862}
863
864
866{
868
869 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
870
871 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
873
874 m_galDisplayOptions.WriteConfig( *window );
875
876 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
877
878 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
879 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
880
881 aCfg->m_FindReplace.find_history.clear();
882 aCfg->m_FindReplace.replace_history.clear();
883
884 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
885 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
886
887 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
888 aCfg->m_FindReplace.replace_history.push_back( m_replaceStringHistoryList[ i ].ToStdString() );
889
890 // Save the units used in this frame
891 if( m_toolManager )
892 {
893 if( COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>() )
894 {
895 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
896 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
897 }
898 }
899}
900
901
902void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
903{
905 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
906}
907
908
910{
912 m_messagePanel->EraseMsgBox();
913}
914
915
916void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
917{
919 {
920 m_messagePanel->EraseMsgBox();
921
922 for( const MSG_PANEL_ITEM& item : aList )
923 m_messagePanel->AppendMessage( item );
924 }
925}
926
927
928void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
929{
931 {
932 m_messagePanel->EraseMsgBox();
933 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
934 }
935}
936
937
939{
940 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
941
942 std::vector<MSG_PANEL_ITEM> items;
943 aItem->GetMsgPanelInfo( this, items );
944 SetMsgPanel( items );
945}
946
947
951
952
954{
955 GetCanvas()->SetEvtHandlerEnabled( true );
957}
958
959
967
968
970{
971#ifdef __WXMAC__
972 // Cairo renderer doesn't handle Retina displays so there's really only one game
973 // in town for Mac
975#endif
976
979
980 if( cfg )
981 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
982
983 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
984 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
985 {
986 wxASSERT( false );
988 }
989
990 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
991 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
993
994 wxString envCanvasType;
995
996 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) )
997 {
998 if( envCanvasType.CmpNoCase( "1" ) == 0
999 || envCanvasType.CmpNoCase( "true" ) == 0
1000 || envCanvasType.CmpNoCase( "yes" ) == 0 )
1001 {
1002 // Force software rendering if the environment variable is set
1004 }
1005 }
1006
1007 return canvasType;
1008}
1009
1010
1012{
1013 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
1014 // have a fixed type, or do not have a option to set the canvas type (they inherit from
1015 // a parent frame)
1016 static std::vector<FRAME_T> s_allowedFrames = { FRAME_SCH,
1022
1023 if( !alg::contains( s_allowedFrames, m_ident ) )
1024 return false;
1025
1026 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) )
1027 {
1028 // If the environment variable is set, don't save the canvas type.
1029 return false;
1030 }
1031
1032 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1033 {
1034 wxASSERT( false );
1035 return false;
1036 }
1037
1038 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
1039 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
1040
1041 return false;
1042}
1043
1044
1046{
1047 const VECTOR2I& gridOrigin = GetGridOrigin();
1048 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
1049
1050 double xOffset = fmod( gridOrigin.x, gridSize.x );
1051 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1052 double yOffset = fmod( gridOrigin.y, gridSize.y );
1053 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1054
1055 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1056}
1057
1058
1060{
1061 const VECTOR2I& gridOrigin = GetGridOrigin();
1062 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
1063
1064 double xOffset = fmod( gridOrigin.x, gridSize.x );
1065 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1066 double yOffset = fmod( gridOrigin.y, gridSize.y );
1067 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1068
1069 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1070}
1071
1072
1073const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1074{
1075 return BOX2I();
1076}
1077
1078
1080{
1081 // To be implemented by subclasses.
1082}
1083
1084
1085void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1086{
1088}
1089
1090
1091std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
1092{
1093 std::vector<wxWindow*> dialogs;
1094
1095 for( wxWindow* window : GetChildren() )
1096 {
1097 if( dynamic_cast<DIALOG_SHIM*>( window ) )
1098 dialogs.push_back( window );
1099 }
1100
1101 return dialogs;
1102}
1103
1104
1105void EDA_DRAW_FRAME::FocusOnLocation( const VECTOR2I& aPos, bool aAllowScroll )
1106{
1107 bool centerView = false;
1108 std::vector<BOX2D> dialogScreenRects;
1109
1110 if( aAllowScroll )
1111 {
1112 BOX2D r = GetCanvas()->GetView()->GetViewport();
1113
1114 // Center if we're off the current view, or within 10% of its edge
1115 r.Inflate( - r.GetWidth() / 10.0 );
1116
1117 if( !r.Contains( aPos ) )
1118 centerView = true;
1119
1120 for( wxWindow* dialog : findDialogs() )
1121 {
1122 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1123 ToVECTOR2D( dialog->GetSize() ) );
1124 }
1125
1126 // Center if we're behind an obscuring dialog, or within 10% of its edge
1127 for( BOX2D rect : dialogScreenRects )
1128 {
1129 rect.Inflate( rect.GetWidth() / 10 );
1130
1131 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1132 centerView = true;
1133 }
1134 }
1135
1136 if( centerView )
1137 {
1138 try
1139 {
1140 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1141 }
1142 catch( const Clipper2Lib::Clipper2Exception& e )
1143 {
1144 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ), e.what() ) );
1145 }
1146 }
1147
1149}
1150
1151
1152void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1153 const wxString& aSheetName, const wxString& aSheetPath,
1154 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1155 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1156 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1157 const wxString& aSheetLayer, bool aIsFirstPage )
1158{
1159 DS_DRAW_ITEM_LIST drawList( unityScale );
1160
1161 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1162 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1163 drawList.SetPageNumber( aPageNumber );
1164 drawList.SetSheetCount( aSheetCount );
1165 drawList.SetFileName( aFileName );
1166 drawList.SetSheetName( aSheetName );
1167 drawList.SetSheetPath( aSheetPath );
1168 drawList.SetSheetLayer( aSheetLayer );
1169 drawList.SetProject( aProject );
1170 drawList.SetIsFirstPage( aIsFirstPage );
1171 drawList.SetProperties( aProperties );
1172
1173 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1174
1175 // Draw item list
1176 drawList.Print( aSettings );
1177}
1178
1179
1181 const std::map<wxString, wxString>* aProperties,
1182 double aMils2Iu, const wxString &aFilename,
1183 const wxString &aSheetLayer )
1184{
1186 return;
1187
1188 wxDC* DC = aSettings->GetPrintDC();
1189 wxPoint origin = DC->GetDeviceOrigin();
1190
1191 if( origin.y > 0 )
1192 {
1193 DC->SetDeviceOrigin( 0, 0 );
1194 DC->SetAxisOrientation( true, false );
1195 }
1196
1198 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1199 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1200 aScreen->GetVirtualPageNumber() == 1 );
1201
1202 if( origin.y > 0 )
1203 {
1204 DC->SetDeviceOrigin( origin.x, origin.y );
1205 DC->SetAxisOrientation( true, true );
1206 }
1207}
1208
1209
1211{
1212 // Virtual function. Base class implementation returns an empty string.
1213 return wxEmptyString;
1214}
1215
1216
1218{
1219 // Virtual function. Base class implementation returns an empty string.
1220 return wxEmptyString;
1221}
1222
1223
1224bool EDA_DRAW_FRAME::LibraryFileBrowser( const wxString& aTitle, bool doOpen, wxFileName& aFilename,
1225 const wxString& wildcard, const wxString& ext,
1226 bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY* aFileDlgHook )
1227{
1228 aFilename.SetExt( ext );
1229
1230 wxString defaultDir = aFilename.GetPath();
1231
1232 if( defaultDir.IsEmpty() )
1233 defaultDir = GetMruPath();
1234
1235 if( isDirectory && doOpen )
1236 {
1237 wxDirDialog dlg( this, aTitle, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1238
1239 if( dlg.ShowModal() == wxID_CANCEL )
1240 return false;
1241
1242 aFilename = dlg.GetPath();
1243 aFilename.SetExt( ext );
1244 }
1245 else
1246 {
1247 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1248 if( aFilename.GetName().empty() )
1249 aFilename.SetName( wxS( "Library" ) );
1250
1251 wxFileDialog dlg( this, aTitle, defaultDir, aFilename.GetFullName(), wildcard,
1252 doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1253 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1254
1255 if( aFileDlgHook )
1256 dlg.SetCustomizeHook( *aFileDlgHook );
1257
1259
1260 if( dlg.ShowModal() == wxID_CANCEL )
1261 return false;
1262
1263 aFilename = dlg.GetPath();
1264 aFilename.SetExt( ext );
1265 }
1266
1267 SetMruPath( aFilename.GetPath() );
1268
1269 return true;
1270}
1271
1272
1274{
1276
1277 if( m_searchPane )
1278 {
1279 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1280 search_pane_info.Caption( _( "Search" ) );
1281 }
1282
1283 if( m_propertiesPanel )
1284 {
1285 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1286 properties_pane_info.Caption( _( "Properties" ) );
1287 }
1288
1290 {
1291 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1292 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1293 }
1294}
1295
1296
1298{
1299 if( m_isClosing || !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1300 return;
1301
1302 m_propertiesPanel->UpdateData();
1303}
1304
1305
1310
1311
1313{
1314 if( !m_colorSettings || aForceRefresh )
1315 {
1317 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1318 }
1319
1320 return m_colorSettings;
1321}
1322
1323
1325{
1327
1328 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
1329 EDITOR_CONDITIONS cond( this );
1330
1331 wxASSERT( mgr );
1332
1336}
1337
1338
1340{
1341 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1342
1343 if( cmnTool )
1344 {
1345 // Tell the tool what the units used last session
1346 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1347 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1348 }
1349
1350 // Tell the tool what units the frame is currently using
1351 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1352 {
1353 default:
1354 case EDA_UNITS::MM: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1355 case EDA_UNITS::INCH: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1356 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1357 }
1358}
1359
1360
1361void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1362{
1363 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1364
1365 aPrimaryUnit = GetUserUnits();
1366 aSecondaryUnits = EDA_UNITS::MILS;
1367
1368 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1369 {
1370 if( cmnTool )
1371 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1372 else
1373 aSecondaryUnits = EDA_UNITS::MM;
1374 }
1375 else
1376 {
1377 if( cmnTool )
1378 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1379 else
1380 aSecondaryUnits = EDA_UNITS::MILS;
1381 }
1382}
1383
1384
1386{
1388
1389 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1390 // user preference silently:
1391
1394}
1395
1396
1397void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1398{
1399 // Force a refresh of the message panel to ensure that the text is the right color
1400 // when the window activates
1401 if( !IsIconized() )
1402 m_messagePanel->Refresh();
1403}
1404
1405
1406void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1407{
1408 handleActivateEvent( aEvent );
1409
1410 aEvent.Skip();
1411}
1412
1413
1414bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName, BITMAP_TYPE aBitmapType )
1415{
1416 bool retv = true;
1417
1418 // Make a screen copy of the canvas:
1419 wxSize image_size = GetCanvas()->GetClientSize();
1420
1421 wxClientDC dc( GetCanvas() );
1422 wxBitmap bitmap( image_size.x, image_size.y );
1423 wxMemoryDC memdc;
1424
1425 memdc.SelectObject( bitmap );
1426 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1427 memdc.SelectObject( wxNullBitmap );
1428
1429 wxImage image = bitmap.ConvertToImage();
1430
1431 wxBitmapType type = wxBITMAP_TYPE_PNG;
1432 switch( aBitmapType )
1433 {
1434 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1435 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1436 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1437 }
1438
1439 if( !image.SaveFile( aFileName, type ) )
1440 retv = false;
1441
1442 image.Destroy();
1443 return retv;
1444}
1445
1446
1448{
1449 wxCHECK( aCfg, aAction.show_button );
1450
1451 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1452 {
1453 if( identifier == aAction.identifier )
1454 return visible;
1455 }
1456
1457 return aAction.show_button;
1458}
1459
1460
1461std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions( PLUGIN_ACTION_SCOPE aScope,
1462 APP_SETTINGS_BASE* aCfg )
1463{
1464 std::vector<const PLUGIN_ACTION*> actions;
1465 wxCHECK( aCfg, actions );
1466
1467#ifdef KICAD_IPC_API
1468
1469 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1470 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1471 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1472 std::set<const PLUGIN_ACTION*> handled;
1473
1474 for( const PLUGIN_ACTION* action : unsorted )
1475 actionMap[action->identifier] = action;
1476
1477 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1478 {
1479 if( actionMap.contains( identifier ) )
1480 {
1481 const PLUGIN_ACTION* action = actionMap[ identifier ];
1482 actions.emplace_back( action );
1483 handled.insert( action );
1484 }
1485 }
1486
1487 for( const auto& action : actionMap | std::views::values )
1488 {
1489 if( !handled.contains( action ) )
1490 actions.emplace_back( action );
1491 }
1492
1493#endif
1494
1495 return actions;
1496}
1497
1498
1500{
1501#ifdef KICAD_IPC_API
1502 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1503
1504 mgr.ButtonBindings().clear();
1505
1506 std::vector<const PLUGIN_ACTION*> actions = GetOrderedPluginActions( PluginActionScope(), config() );
1507
1508 for( const PLUGIN_ACTION* action : actions )
1509 {
1510 if( !IsPluginActionButtonVisible( *action, config() ) )
1511 continue;
1512
1513 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
1514 : action->icon_light;
1515
1516 wxAuiToolBarItem* button = aToolbar->AddTool( wxID_ANY, wxEmptyString, icon, action->name );
1517
1518 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1519 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1520
1521 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1522 }
1523#endif
1524}
1525
1526
1527void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1528{
1529#ifdef KICAD_IPC_API
1530 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1531
1532 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1533 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ) );
1534#endif
1535}
const char * name
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
EDA_SEARCH_DATA & GetFindReplaceData()
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:99
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:226
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:535
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:660
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:601
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:640
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:295
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:407
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:541
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:435
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
PLUGIN_ACTION_SCOPE
#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:72
wxString identifier
Definition api_plugin.h:77
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