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