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