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 <widgets/ui_common.h>
71#include <widgets/search_pane.h>
72#include <wx/dirdlg.h>
73#include <wx/filedlg.h>
74#include <wx/debug.h>
75#include <wx/socket.h>
76
77#include <wx/fdrepdlg.h>
79
80#define FR_HISTORY_LIST_CNT 10
81
82
83BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
86
87 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
88END_EVENT_TABLE()
89
90
91bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
92
93
94EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
95 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
96 long aStyle, const wxString& aFrameName, const EDA_IU_SCALE& aIuScale ) :
97 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
98 m_socketServer( nullptr ),
100{
101 m_gridSelectBox = nullptr;
102 m_zoomSelectBox = nullptr;
103 m_zoomCustomEntry = wxNOT_FOUND;
104 m_overrideLocksCb = nullptr;
105 m_searchPane = nullptr;
107
109 m_canvas = nullptr;
110 m_toolDispatcher = nullptr;
111 m_messagePanel = nullptr;
112 m_currentScreen = nullptr;
113 m_showBorderAndTitleBlock = false; // true to display reference sheet.
114 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
115 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
116 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
117 m_colorSettings = nullptr;
118 m_polarCoords = false;
119 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
120 m_hotkeyPopup = nullptr;
121 m_propertiesPanel = nullptr;
122 m_netInspectorPanel = nullptr;
123
125
126 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
127
128 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
129 {
130 CreateStatusBar( 8 )->SetDoubleBuffered( true );
131
132 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
133
134 // set the size of the status bar subwindows:
136 }
137
138 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
139 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
140 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
141
142 // Create child subwindows.
143 GetClientSize( &m_frameSize.x, &m_frameSize.y );
144 m_framePos.x = m_framePos.y = 0;
146
148
149 Bind( wxEVT_DPI_CHANGED,
150 [&]( wxDPIChangedEvent& aEvent )
151 {
152 if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
154
155 wxMoveEvent dummy;
156 OnMove( dummy );
157
158 // we need to kludge the msg panel to the correct size again
159 // especially important even for first launches as the constructor of the window
160 // here usually doesn't have the correct dpi awareness yet
162 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
164
165 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
167
168 aEvent.Skip();
169 } );
170}
171
172
174{
177
178 delete m_actions;
179 delete m_toolManager;
180 delete m_toolDispatcher;
181 delete m_canvas;
182
183 delete m_currentScreen;
184 m_currentScreen = nullptr;
185
186 m_auimgr.UnInit();
187
188 ReleaseFile();
189}
190
191
196
197
199{
201
202 // Grid selection
203 auto gridSelectorFactory =
204 [this]( ACTION_TOOLBAR* aToolbar )
205 {
206 if( !m_gridSelectBox )
207 m_gridSelectBox = new wxChoice( aToolbar, ID_ON_GRID_SELECT );
208
210
211 aToolbar->Add( m_gridSelectBox );
212 };
213
215
216 // Zoom selection
217 auto zoomSelectorFactory =
218 [this]( ACTION_TOOLBAR* aToolbar )
219 {
220 if( !m_zoomSelectBox )
221 m_zoomSelectBox = new wxChoice( aToolbar, ID_ON_ZOOM_SELECT );
222
224 aToolbar->Add( m_zoomSelectBox );
225 };
226
228
229 auto overrideLocksFactory =
230 [this]( ACTION_TOOLBAR* aToolbar )
231 {
232 if( !m_overrideLocksCb )
233 {
234 m_overrideLocksCb = new wxCheckBox( aToolbar, ID_ON_OVERRIDE_LOCKS, _( "Override locks" ) );
235
236 // Clicking the checkbox takes focus off the canvas, so return it
237 m_overrideLocksCb->Bind( wxEVT_CHECKBOX,
238 [this]( wxCommandEvent& aEvent )
239 {
240 if( m_toolManager )
242
243 if( m_canvas )
244 m_canvas->SetFocus();
245
246 aEvent.Skip();
247 } );
248 }
249
250 aToolbar->Add( m_overrideLocksCb );
251 };
252
254}
255
256
258{
259 switch( aId )
260 {
261 case ID_ON_GRID_SELECT: m_gridSelectBox = nullptr; break;
262 case ID_ON_ZOOM_SELECT: m_zoomSelectBox = nullptr; break;
263 case ID_ON_OVERRIDE_LOCKS: m_overrideLocksCb = nullptr; break;
264 }
265}
266
267
269{
270 if( m_file_checker )
271 m_file_checker->UnlockFile();
272}
273
274
275bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
276{
277 // We need to explicitly reset here to get the deletion before we create a new unique_ptr that
278 // may be for the same file.
279 m_file_checker.reset();
280
281 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
282
283 // If the file is valid, return true. This could mean that the file is locked or it could mean
284 // that the file is read-only.
285 return m_file_checker->Valid();
286}
287
288
290{
291 // Notify all tools the units have changed
292 if( m_toolManager )
294
298
299 switch( GetUserUnits() )
300 {
301 default:
305 }
306}
307
308
310{
311 if( m_toolManager->GetTool<COMMON_TOOLS>() )
312 {
314 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
315 }
316 else
317 {
320
321 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
322 ProcessEventLocally( e );
323 }
324}
325
326
328{
330
331 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
333
334 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
335 {
336 if( GetAutoSaveInterval() > 0 )
337 {
338 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
339 }
340 else
341 {
342 m_autoSaveTimer->Stop();
343 m_autoSavePending = false;
344 }
345 }
346
347 viewControls->LoadSettings();
349
350 m_galDisplayOptions.ReadCommonConfig( *settings, this );
351
354
355 if( m_lastToolbarIconSize == 0
357 {
360 }
361
362#ifndef __WXMAC__
364#endif
365
366 // Notify all tools the preferences have changed
367 if( m_toolManager )
369}
370
371
373{
374 if( m_messagePanel )
375 m_messagePanel->EraseMsgBox();
376}
377
378
380{
383
384 if( m_gridSelectBox == nullptr )
385 return;
386
387 // Update grid values with the current units setting.
388 m_gridSelectBox->Clear();
389 wxArrayString gridsList;
390
391 wxCHECK( config(), /* void */ );
392
393 GRID_MENU::BuildChoiceList( &gridsList, GetWindowSettings( config() ), this );
394
395 for( const wxString& grid : gridsList )
396 m_gridSelectBox->Append( grid );
397
398 m_gridSelectBox->Append( wxT( "---" ) );
399 m_gridSelectBox->Append( _( "Edit Grids..." ) );
400
401 m_gridSelectBox->SetSelection( GetWindowSettings( config() )->grid.last_size_idx );
402}
403
404
405void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
406{
407 // No need to update the grid select box if it doesn't exist or the grid setting change
408 // was made using the select box.
409 if( m_gridSelectBox == nullptr )
410 return;
411
412 wxCHECK( config(), /* void */ );
413
415 idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
416
417 if( idx != m_gridSelectBox->GetSelection() )
418 m_gridSelectBox->SetSelection( idx );
419}
420
421
422
423void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
424{
425 if( m_zoomSelectBox == nullptr )
426 return;
427
428 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
429
430 wxCHECK( config(), /* void */ );
431
432 const std::vector<double>& zoomList = GetWindowSettings( config() )->zoom_factors;
433 int preset = wxNOT_FOUND;
434
435 for( size_t jj = 0; jj < zoomList.size(); ++jj )
436 {
437 if( zoomList[jj] == zoom )
438 {
439 preset = (int) jj + 1; // index 0 is Zoom Auto
440 break;
441 }
442 }
443
444 if( preset != wxNOT_FOUND )
445 {
446 // Zoom is on a preset, so drop the custom entry and select the preset.
447 if( m_zoomCustomEntry != wxNOT_FOUND )
448 {
450 m_zoomCustomEntry = wxNOT_FOUND;
451 }
452
453 if( m_zoomSelectBox->GetSelection() != preset )
454 m_zoomSelectBox->SetSelection( preset );
455 }
456 else
457 {
458 // Off-preset zoom, show the exact value in its own entry just below Zoom Auto.
459 wxString text = wxString::Format( _( "Zoom %.2f" ), zoom );
460
461 if( m_zoomCustomEntry == wxNOT_FOUND )
462 m_zoomCustomEntry = m_zoomSelectBox->Insert( text, 1 );
463 else if( m_zoomSelectBox->GetString( m_zoomCustomEntry ) != text )
465
466 if( m_zoomSelectBox->GetSelection() != m_zoomCustomEntry )
467 m_zoomSelectBox->SetSelection( m_zoomCustomEntry );
468 }
469}
470
471
472void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
473{
474 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
475
476 int idx = m_gridSelectBox->GetCurrentSelection();
477
478 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
479 {
480 // wxWidgets will check the separator, which we don't want.
481 // Re-check the current grid.
482 wxUpdateUIEvent dummy;
484 }
485 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
486 {
487 // wxWidgets will check the Grid Settings... entry, which we don't want.
488 // Re-check the current grid.
489 wxUpdateUIEvent dummy;
491
492 // Give a time-slice to close the menu before opening the dialog.
493 // (Only matters on some versions of GTK.)
494 wxSafeYield();
495
497 }
498 else
499 {
500 m_toolManager->RunAction( ACTIONS::gridPreset, idx );
501 }
502
504 m_canvas->Refresh();
505
506 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
507 // (Windows specific
508 m_canvas->SetFocus();
509}
510
511
513{
515 return m_overrideLocksCb->GetValue();
516
517 return false;
518}
519
520
522{
523 wxCHECK( config(), true );
524
525 return GetWindowSettings( config() )->grid.show;
526}
527
528
530{
531 wxCHECK( config(), /* void */ );
532
533 GetWindowSettings( config() )->grid.show = aVisible;
534
535 // Update the display with the new grid
536 if( GetCanvas() )
537 {
538 // Check to ensure these exist, since this function could be called before
539 // the GAL and View have been created
540 if( GetCanvas()->GetGAL() )
541 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
542
543 if( GetCanvas()->GetView() )
545
546 GetCanvas()->Refresh();
547 }
548}
549
550
552{
553 wxCHECK( config(), false );
554
556}
557
558
560{
561 wxCHECK( config(), /* void */ );
562
564}
565
566
567std::unique_ptr<GRID_HELPER> EDA_DRAW_FRAME::MakeGridHelper()
568{
569 return nullptr;
570}
571
572
574{
575 if( m_zoomSelectBox == nullptr )
576 return;
577
578 double zoom = m_canvas->GetGAL()->GetZoomFactor();
579
580 m_zoomSelectBox->Clear();
581 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
582 m_zoomSelectBox->SetSelection( 0 );
583 m_zoomCustomEntry = wxNOT_FOUND;
584
585 wxCHECK( config(), /* void */ );
586
587 for( unsigned ii = 0; ii < GetWindowSettings( config() )->zoom_factors.size(); ++ii )
588 {
589 double current = GetWindowSettings( config() )->zoom_factors[ii];
590
591 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
592
593 if( zoom == current )
594 m_zoomSelectBox->SetSelection( (int) ii + 1 );
595 }
596}
597
598
599void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
600{
601 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
602
603 int id = m_zoomSelectBox->GetCurrentSelection();
604
605 if( id < 0 || id >= (int) m_zoomSelectBox->GetCount() )
606 return;
607
608 // Picking the custom entry means keep the current zoom, so nothing to do.
609 if( id == m_zoomCustomEntry )
610 return;
611
612 // The custom entry pushes the presets down by one, so shift back to the real preset id.
613 int preset = id;
614
615 if( m_zoomCustomEntry != wxNOT_FOUND && id > m_zoomCustomEntry )
616 preset = id - 1;
617
618 m_toolManager->RunAction( ACTIONS::zoomPreset, preset );
620 m_canvas->Refresh();
621
622 // Needed on Windows (only) because clicking on m_zoomSelectBox removes the focus from m_canvas
623 m_canvas->SetFocus();
624}
625
626
627void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
628{
629 // If the window is moved to a different display, the scaling factor may change
630 double oldFactor = m_galDisplayOptions.m_scaleFactor;
631 m_galDisplayOptions.UpdateScaleFactor();
632
633 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
634 {
635 // wx has not laid the frame out for the new DPI yet, so defer until the canvas has
636 // reached its final size
637 EDA_DRAW_PANEL_GAL* canvas = GetCanvas();
638
639 canvas->CallAfter( [canvas]() { canvas->ResizeGal( true ); } );
640 }
641
642 aEvent.Skip();
643}
644
645
647{
648 COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
649 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
650
651 aMenu.AddSeparator( 1000 );
652
653 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
654 zoomMenu->SetTool( commonTools );
655 aToolMenu.RegisterSubMenu( zoomMenu );
656
657 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
658 gridMenu->SetTool( commonTools );
659 aToolMenu.RegisterSubMenu( gridMenu );
660
661 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
662 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
663}
664
665
666void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
667{
668 if( m_isClosing )
669 return;
670
671 SetStatusText( msg, 6 );
672}
673
674
675void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
676{
677 if( m_isClosing )
678 return;
679
680 SetStatusText( msg, 7 );
681}
682
683
685{
686 if( m_isClosing )
687 return;
688
689 wxString msg;
690
691 GRID_SETTINGS& gridSettings = GetWindowSettings( config() )->grid;
692 int currentIdx = gridSettings.last_size_idx;
693
694 msg.Printf( _( "grid %s" ), gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
695
696 SetStatusText( msg, 4 );
697}
698
699
701{
702 if( m_isClosing )
703 return;
704
705 wxString msg;
706
707 switch( GetUserUnits() )
708 {
709 case EDA_UNITS::INCH: msg = _( "inches" ); break;
710 case EDA_UNITS::MILS: msg = _( "mils" ); break;
711 case EDA_UNITS::MM: msg = _( "mm" ); break;
712 default: msg = _( "Units" ); break;
713 }
714
715 SetStatusText( msg, 5 );
716}
717
718
719void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
720{
721 EDA_BASE_FRAME::OnSize( SizeEv );
722
723 m_frameSize = GetClientSize( );
724
725 SizeEv.Skip();
726}
727
728
730{
731 constexpr int numLocalFields = 8;
732
733 wxStatusBar* stsbar = GetStatusBar();
734 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x;
735
736 // Note this is a KISTATUSBAR and there are fields to the right of the ones we know about
737 int totalFields = stsbar->GetFieldsCount();
738
739 std::vector<int> dims = {
740 // remainder of status bar on far left is set to a default or whatever is left over.
741 -2,
742
743 // When using GetTextSize() remember the width of character '1' is not the same
744 // as the width of '0' unless the font is fixed width, and it usually won't be.
745
746 // zoom:
747 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + spacer,
748
749 // cursor coords
750 KIUI::GetTextSize( wxT( "X 00000.0000 Y 00000.0000" ), stsbar ).x + spacer,
751
752 // delta distances
753 KIUI::GetTextSize( wxT( "dx 00000.0000 dy 00000.0000 dist 00000.0000" ), stsbar ).x + spacer,
754
755 // grid size
756 KIUI::GetTextSize( wxT( "grid 0000.0000 x 0000.0000" ), stsbar ).x + spacer,
757
758 // units display, Inches is bigger than mm
759 KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
760
761 // Size for the "Current Tool" panel
762 -1,
763
764 // constraint mode
765 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar).x + spacer
766 };
767
768 for( int idx = numLocalFields; idx < totalFields; ++idx )
769 dims.emplace_back( stsbar->GetStatusWidth( idx ) );
770
771 SetStatusWidths( dims.size(), dims.data() );
772}
773
774
775wxStatusBar* EDA_DRAW_FRAME::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
776{
777 return new KISTATUSBAR( number, this, id, KISTATUSBAR::STYLE_FLAGS::WARNING_ICON );
778}
779
780
782{
783 if( m_isClosing )
784 return;
785
786 SetStatusText( GetZoomLevelIndicator(), 1 );
787
788 // Absolute and relative cursor positions are handled by overloading this function and
789 // handling the internal to user units conversion at the appropriate level.
790
791 // refresh units display
793}
794
795
797{
798 // returns a human readable value which can be displayed as zoom
799 // level indicator in dialogs.
800 double zoom = m_canvas->GetGAL()->GetZoomFactor();
801 return wxString::Format( wxT( "Z %.2f" ), zoom );
802}
803
804
806{
808
810 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
811
812 // Read units used in dialogs and toolbars
813 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
814
816
817 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
818
819 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
820 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
821 m_findReplaceData->matchMode = static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
822 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
823 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
824
825 for( const wxString& s : aCfg->m_FindReplace.find_history )
827
828 for( const wxString& s : aCfg->m_FindReplace.replace_history )
830
832}
833
834
836{
838
839 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
840
841 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
843
844 m_galDisplayOptions.WriteConfig( *window );
845
846 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
847
848 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
849 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
850
851 aCfg->m_FindReplace.find_history.clear();
852 aCfg->m_FindReplace.replace_history.clear();
853
854 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
855 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
856
857 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
858 aCfg->m_FindReplace.replace_history.push_back( m_replaceStringHistoryList[ i ].ToStdString() );
859
860 // Save the units used in this frame
861 if( m_toolManager )
862 {
863 if( COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>() )
864 {
865 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
866 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
867 }
868 }
869}
870
871
872void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
873{
875 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
876}
877
878
880{
882 m_messagePanel->EraseMsgBox();
883}
884
885
886void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
887{
889 {
890 m_messagePanel->EraseMsgBox();
891
892 for( const MSG_PANEL_ITEM& item : aList )
893 m_messagePanel->AppendMessage( item );
894 }
895}
896
897
898void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
899{
901 {
902 m_messagePanel->EraseMsgBox();
903 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
904 }
905}
906
907
909{
910 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
911
912 std::vector<MSG_PANEL_ITEM> items;
913 aItem->GetMsgPanelInfo( this, items );
914 SetMsgPanel( items );
915}
916
917
921
922
924{
925 GetCanvas()->SetEvtHandlerEnabled( true );
927}
928
929
937
938
940{
941#ifdef __WXMAC__
942 // Cairo renderer doesn't handle Retina displays so there's really only one game
943 // in town for Mac
945#endif
946
949
950 if( cfg )
951 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
952
953 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
954 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
955 {
956 wxASSERT( false );
958 }
959
960 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
961 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
963
964 wxString envCanvasType;
965
966 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) )
967 {
968 if( envCanvasType.CmpNoCase( "1" ) == 0
969 || envCanvasType.CmpNoCase( "true" ) == 0
970 || envCanvasType.CmpNoCase( "yes" ) == 0 )
971 {
972 // Force software rendering if the environment variable is set
974 }
975 }
976
977 return canvasType;
978}
979
980
982{
983 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
984 // have a fixed type, or do not have a option to set the canvas type (they inherit from
985 // a parent frame)
986 static std::vector<FRAME_T> s_allowedFrames = { FRAME_SCH,
992
993 if( !alg::contains( s_allowedFrames, m_ident ) )
994 return false;
995
996 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) )
997 {
998 // If the environment variable is set, don't save the canvas type.
999 return false;
1000 }
1001
1002 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
1003 {
1004 wxASSERT( false );
1005 return false;
1006 }
1007
1008 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
1009 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
1010
1011 return false;
1012}
1013
1014
1016{
1017 const VECTOR2I& gridOrigin = GetGridOrigin();
1018 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
1019
1020 double xOffset = fmod( gridOrigin.x, gridSize.x );
1021 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1022 double yOffset = fmod( gridOrigin.y, gridSize.y );
1023 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1024
1025 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1026}
1027
1028
1030{
1031 const VECTOR2I& gridOrigin = GetGridOrigin();
1032 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
1033
1034 double xOffset = fmod( gridOrigin.x, gridSize.x );
1035 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1036 double yOffset = fmod( gridOrigin.y, gridSize.y );
1037 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1038
1039 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1040}
1041
1042
1043const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1044{
1045 return BOX2I();
1046}
1047
1048
1050{
1051 // To be implemented by subclasses.
1052}
1053
1054
1055void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1056{
1058}
1059
1060
1061std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
1062{
1063 std::vector<wxWindow*> dialogs;
1064
1065 for( wxWindow* window : GetChildren() )
1066 {
1067 if( dynamic_cast<DIALOG_SHIM*>( window ) )
1068 dialogs.push_back( window );
1069 }
1070
1071 return dialogs;
1072}
1073
1074
1075void EDA_DRAW_FRAME::FocusOnLocation( const VECTOR2I& aPos, bool aAllowScroll )
1076{
1077 bool centerView = false;
1078 std::vector<BOX2D> dialogScreenRects;
1079
1080 if( aAllowScroll )
1081 {
1082 BOX2D r = GetCanvas()->GetView()->GetViewport();
1083
1084 // Center if we're off the current view, or within 10% of its edge
1085 r.Inflate( - r.GetWidth() / 10.0 );
1086
1087 if( !r.Contains( aPos ) )
1088 centerView = true;
1089
1090 for( wxWindow* dialog : findDialogs() )
1091 {
1092 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1093 ToVECTOR2D( dialog->GetSize() ) );
1094 }
1095
1096 // Center if we're behind an obscuring dialog, or within 10% of its edge
1097 for( BOX2D rect : dialogScreenRects )
1098 {
1099 rect.Inflate( rect.GetWidth() / 10 );
1100
1101 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1102 centerView = true;
1103 }
1104 }
1105
1106 if( centerView )
1107 {
1108 try
1109 {
1110 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1111 }
1112 catch( const Clipper2Lib::Clipper2Exception& e )
1113 {
1114 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ), e.what() ) );
1115 }
1116 }
1117
1119}
1120
1121
1122void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1123 const wxString& aSheetName, const wxString& aSheetPath,
1124 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1125 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1126 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1127 const wxString& aSheetLayer, bool aIsFirstPage )
1128{
1129 DS_DRAW_ITEM_LIST drawList( unityScale );
1130
1131 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1132 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1133 drawList.SetPageNumber( aPageNumber );
1134 drawList.SetSheetCount( aSheetCount );
1135 drawList.SetFileName( aFileName );
1136 drawList.SetSheetName( aSheetName );
1137 drawList.SetSheetPath( aSheetPath );
1138 drawList.SetSheetLayer( aSheetLayer );
1139 drawList.SetProject( aProject );
1140 drawList.SetIsFirstPage( aIsFirstPage );
1141 drawList.SetProperties( aProperties );
1142
1143 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1144
1145 // Draw item list
1146 drawList.Print( aSettings );
1147}
1148
1149
1151 const std::map<wxString, wxString>* aProperties,
1152 double aMils2Iu, const wxString &aFilename,
1153 const wxString &aSheetLayer )
1154{
1156 return;
1157
1158 wxDC* DC = aSettings->GetPrintDC();
1159 wxPoint origin = DC->GetDeviceOrigin();
1160
1161 if( origin.y > 0 )
1162 {
1163 DC->SetDeviceOrigin( 0, 0 );
1164 DC->SetAxisOrientation( true, false );
1165 }
1166
1168 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1169 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1170 aScreen->GetVirtualPageNumber() == 1 );
1171
1172 if( origin.y > 0 )
1173 {
1174 DC->SetDeviceOrigin( origin.x, origin.y );
1175 DC->SetAxisOrientation( true, true );
1176 }
1177}
1178
1179
1181{
1182 // Virtual function. Base class implementation returns an empty string.
1183 return wxEmptyString;
1184}
1185
1186
1188{
1189 // Virtual function. Base class implementation returns an empty string.
1190 return wxEmptyString;
1191}
1192
1193
1194bool EDA_DRAW_FRAME::LibraryFileBrowser( const wxString& aTitle, bool doOpen, wxFileName& aFilename,
1195 const wxString& wildcard, const wxString& ext,
1196 bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY* aFileDlgHook )
1197{
1198 aFilename.SetExt( ext );
1199
1200 wxString defaultDir = aFilename.GetPath();
1201
1202 if( defaultDir.IsEmpty() )
1203 defaultDir = GetMruPath();
1204
1205 if( isDirectory && doOpen )
1206 {
1207 wxDirDialog dlg( this, aTitle, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1208
1209 if( dlg.ShowModal() == wxID_CANCEL )
1210 return false;
1211
1212 aFilename = dlg.GetPath();
1213 aFilename.SetExt( ext );
1214 }
1215 else
1216 {
1217 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1218 if( aFilename.GetName().empty() )
1219 aFilename.SetName( wxS( "Library" ) );
1220
1221 wxFileDialog dlg( this, aTitle, defaultDir, aFilename.GetFullName(), wildcard,
1222 doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1223 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1224
1225 if( aFileDlgHook )
1226 dlg.SetCustomizeHook( *aFileDlgHook );
1227
1229
1230 if( dlg.ShowModal() == wxID_CANCEL )
1231 return false;
1232
1233 aFilename = dlg.GetPath();
1234 aFilename.SetExt( ext );
1235 }
1236
1237 SetMruPath( aFilename.GetPath() );
1238
1239 return true;
1240}
1241
1242
1244{
1246
1247 if( m_searchPane )
1248 {
1249 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1250 search_pane_info.Caption( _( "Search" ) );
1251 }
1252
1253 if( m_propertiesPanel )
1254 {
1255 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1256 properties_pane_info.Caption( _( "Properties" ) );
1257 }
1258
1260 {
1261 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1262 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1263 }
1264}
1265
1266
1268{
1269 if( m_isClosing || !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1270 return;
1271
1272 m_propertiesPanel->UpdateData();
1273}
1274
1275
1280
1281
1283{
1284 if( !m_colorSettings || aForceRefresh )
1285 {
1287 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1288 }
1289
1290 return m_colorSettings;
1291}
1292
1293
1295{
1297
1298 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
1299 EDITOR_CONDITIONS cond( this );
1300
1301 wxASSERT( mgr );
1302
1306}
1307
1308
1310{
1311 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1312
1313 if( cmnTool )
1314 {
1315 // Tell the tool what the units used last session
1316 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1317 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1318 }
1319
1320 // Tell the tool what units the frame is currently using
1321 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1322 {
1323 default:
1324 case EDA_UNITS::MM: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1325 case EDA_UNITS::INCH: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1326 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1327 }
1328}
1329
1330
1331void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1332{
1333 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1334
1335 aPrimaryUnit = GetUserUnits();
1336 aSecondaryUnits = EDA_UNITS::MILS;
1337
1338 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1339 {
1340 if( cmnTool )
1341 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1342 else
1343 aSecondaryUnits = EDA_UNITS::MM;
1344 }
1345 else
1346 {
1347 if( cmnTool )
1348 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1349 else
1350 aSecondaryUnits = EDA_UNITS::MILS;
1351 }
1352}
1353
1354
1356{
1358
1359 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1360 // user preference silently:
1361
1364
1365 if( m_canvasType != GetCanvas()->GetBackend() )
1366 {
1367 // Try to switch (will automatically fallback if necessary)
1369
1370 if( GetCanvas()->GetBackend() != m_canvasType )
1371 {
1373 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
1374 }
1375 }
1376}
1377
1378
1379void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1380{
1381 // Force a refresh of the message panel to ensure that the text is the right color
1382 // when the window activates
1383 if( !IsIconized() )
1384 m_messagePanel->Refresh();
1385}
1386
1387
1388void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1389{
1390 handleActivateEvent( aEvent );
1391
1392 aEvent.Skip();
1393}
1394
1395
1396bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName, BITMAP_TYPE aBitmapType )
1397{
1398 wxImage image;
1399
1400
1401 if( !GetCanvas()->GetScreenshot( image ) )
1402 {
1403 wxSize image_size = GetCanvas()->GetClientSize();
1404 wxClientDC dc( GetCanvas() );
1405 wxBitmap bitmap( image_size.x, image_size.y );
1406 wxMemoryDC memdc;
1407
1408 memdc.SelectObject( bitmap );
1409 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1410 memdc.SelectObject( wxNullBitmap );
1411
1412 image = bitmap.ConvertToImage();
1413 }
1414
1415 wxBitmapType type = wxBITMAP_TYPE_PNG;
1416 switch( aBitmapType )
1417 {
1418 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1419 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1420 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1421 }
1422
1423 bool retv = image.SaveFile( aFileName, type );
1424
1425 image.Destroy();
1426 return retv;
1427}
1428
1429
1431{
1432 wxCHECK( aCfg, aAction.show_button );
1433
1434 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1435 {
1436 if( identifier == aAction.identifier )
1437 return visible;
1438 }
1439
1440 return aAction.show_button;
1441}
1442
1443
1444std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions( PLUGIN_ACTION_SCOPE aScope,
1445 APP_SETTINGS_BASE* aCfg )
1446{
1447 std::vector<const PLUGIN_ACTION*> actions;
1448 wxCHECK( aCfg, actions );
1449
1451 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1452 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1453 std::set<const PLUGIN_ACTION*> handled;
1454
1455 for( const PLUGIN_ACTION* action : unsorted )
1456 actionMap[action->identifier] = action;
1457
1458 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1459 {
1460 if( actionMap.contains( identifier ) )
1461 {
1462 const PLUGIN_ACTION* action = actionMap[ identifier ];
1463 actions.emplace_back( action );
1464 handled.insert( action );
1465 }
1466 }
1467
1468 for( const auto& action : actionMap | std::views::values )
1469 {
1470 if( !handled.contains( action ) )
1471 actions.emplace_back( action );
1472 }
1473
1474 return actions;
1475}
1476
1477
1479{
1481
1482 mgr.ButtonBindings().clear();
1483
1484 std::vector<const PLUGIN_ACTION*> actions = GetOrderedPluginActions( PluginActionScope(), config() );
1485
1486 for( const PLUGIN_ACTION* action : actions )
1487 {
1488 if( !IsPluginActionButtonVisible( *action, config() ) )
1489 continue;
1490
1491 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
1492 : action->icon_light;
1493
1494 wxAuiToolBarItem* button = aToolbar->AddTool( wxID_ANY, wxEmptyString, icon, action->name );
1495
1496 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1497 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1498
1499 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1500 }
1501}
1502
1503
1504void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1505{
1507
1508 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1509 {
1510 std::shared_ptr<REPORTER> reporter;
1511
1512 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
1513 reporter = std::make_shared<STATUSBAR_WARNING_REPORTER>( statusBar, wxS( "plugin" ) );
1514
1515 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ), reporter );
1516 }
1517}
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:927
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
BOX2< VECTOR2D > BOX2D
Definition box2.h:928
static TOOL_ACTION gridProperties
Definition actions.h:196
static TOOL_ACTION millimetersUnits
Definition actions.h:202
static TOOL_ACTION updatePreferences
Definition actions.h:274
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:553
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:165
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:80
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)
void SelectToolbarAction(const TOOL_ACTION &aAction) override
Select the given action in the toolbar group which contains it, if any.
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
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.
void ResizeGal(bool aForce=false)
Resize the GAL to the current client size of this panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
@ GAL_TYPE_LAST
Sentinel, do not use as a parameter.
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_CAIRO
Cairo implementation.
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void UpdateTouchpadGestureHandler()
Apply the current native touchpad gesture preference to the active backend window.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void StartDrawing()
Begin drawing if it was stopped previously.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition eda_item.h:296
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 const TOOL_EVENT SelectedEvent
Definition actions.h:343
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
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:615
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:681
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:659
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50
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:340
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:546
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:139
Container for project specific data.
Definition project.h:63
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:38
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: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: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:51
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
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