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