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 -2,
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 + spacer,
733
734 // cursor coords
735 KIUI::GetTextSize( wxT( "X 00000.0000 Y 00000.0000" ), stsbar ).x + spacer,
736
737 // delta distances
738 KIUI::GetTextSize( wxT( "dx 00000.0000 dy 00000.0000 dist 00000.0000" ), stsbar ).x + spacer,
739
740 // grid size
741 KIUI::GetTextSize( wxT( "grid 0000.0000 x 0000.0000" ), stsbar ).x + spacer,
742
743 // units display, Inches is bigger than mm
744 KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
745
746 // Size for the "Current Tool" panel
747 -1,
748
749 // constraint mode
750 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar).x + spacer
751 };
752
753 for( int idx = numLocalFields; idx < totalFields; ++idx )
754 dims.emplace_back( stsbar->GetStatusWidth( idx ) );
755
756 SetStatusWidths( dims.size(), dims.data() );
757}
758
759
760wxStatusBar* EDA_DRAW_FRAME::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
761{
762 return new KISTATUSBAR( number, this, id, KISTATUSBAR::STYLE_FLAGS::WARNING_ICON );
763}
764
765
767{
768 if( m_isClosing )
769 return;
770
771 SetStatusText( GetZoomLevelIndicator(), 1 );
772
773 // Absolute and relative cursor positions are handled by overloading this function and
774 // handling the internal to user units conversion at the appropriate level.
775
776 // refresh units display
778}
779
780
782{
783 // returns a human readable value which can be displayed as zoom
784 // level indicator in dialogs.
785 double zoom = m_canvas->GetGAL()->GetZoomFactor();
786 return wxString::Format( wxT( "Z %.2f" ), zoom );
787}
788
789
791{
793
795 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
796
797 // Read units used in dialogs and toolbars
798 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
799
801
802 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
803
804 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
805 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
806 m_findReplaceData->matchMode = static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
807 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
808 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
809
810 for( const wxString& s : aCfg->m_FindReplace.find_history )
812
813 for( const wxString& s : aCfg->m_FindReplace.replace_history )
815
817}
818
819
821{
823
824 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
825
826 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
828
829 m_galDisplayOptions.WriteConfig( *window );
830
831 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
832
833 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
834 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
835
836 aCfg->m_FindReplace.find_history.clear();
837 aCfg->m_FindReplace.replace_history.clear();
838
839 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
840 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
841
842 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
843 aCfg->m_FindReplace.replace_history.push_back( m_replaceStringHistoryList[ i ].ToStdString() );
844
845 // Save the units used in this frame
846 if( m_toolManager )
847 {
848 if( COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>() )
849 {
850 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
851 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
852 }
853 }
854}
855
856
857void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
858{
860 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
861}
862
863
865{
867 m_messagePanel->EraseMsgBox();
868}
869
870
871void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
872{
874 {
875 m_messagePanel->EraseMsgBox();
876
877 for( const MSG_PANEL_ITEM& item : aList )
878 m_messagePanel->AppendMessage( item );
879 }
880}
881
882
883void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding )
884{
886 {
887 m_messagePanel->EraseMsgBox();
888 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
889 }
890}
891
892
894{
895 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
896
897 std::vector<MSG_PANEL_ITEM> items;
898 aItem->GetMsgPanelInfo( this, items );
899 SetMsgPanel( items );
900}
901
902
906
907
909{
910 GetCanvas()->SetEvtHandlerEnabled( true );
912}
913
914
922
923
925{
926#ifdef __WXMAC__
927 // Cairo renderer doesn't handle Retina displays so there's really only one game
928 // in town for Mac
930#endif
931
934
935 if( cfg )
936 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
937
938 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
939 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
940 {
941 wxASSERT( false );
943 }
944
945 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
946 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
948
949 wxString envCanvasType;
950
951 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) )
952 {
953 if( envCanvasType.CmpNoCase( "1" ) == 0
954 || envCanvasType.CmpNoCase( "true" ) == 0
955 || envCanvasType.CmpNoCase( "yes" ) == 0 )
956 {
957 // Force software rendering if the environment variable is set
959 }
960 }
961
962 return canvasType;
963}
964
965
967{
968 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
969 // have a fixed type, or do not have a option to set the canvas type (they inherit from
970 // a parent frame)
971 static std::vector<FRAME_T> s_allowedFrames = { FRAME_SCH,
977
978 if( !alg::contains( s_allowedFrames, m_ident ) )
979 return false;
980
981 if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) )
982 {
983 // If the environment variable is set, don't save the canvas type.
984 return false;
985 }
986
987 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
988 {
989 wxASSERT( false );
990 return false;
991 }
992
993 if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
994 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
995
996 return false;
997}
998
999
1001{
1002 const VECTOR2I& gridOrigin = GetGridOrigin();
1003 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
1004
1005 double xOffset = fmod( gridOrigin.x, gridSize.x );
1006 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1007 double yOffset = fmod( gridOrigin.y, gridSize.y );
1008 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1009
1010 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1011}
1012
1013
1015{
1016 const VECTOR2I& gridOrigin = GetGridOrigin();
1017 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
1018
1019 double xOffset = fmod( gridOrigin.x, gridSize.x );
1020 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
1021 double yOffset = fmod( gridOrigin.y, gridSize.y );
1022 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
1023
1024 return KiROUND( x * gridSize.x + xOffset, y * gridSize.y + yOffset );
1025}
1026
1027
1028const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1029{
1030 return BOX2I();
1031}
1032
1033
1035{
1036 // To be implemented by subclasses.
1037}
1038
1039
1040void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
1041{
1043}
1044
1045
1046std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
1047{
1048 std::vector<wxWindow*> dialogs;
1049
1050 for( wxWindow* window : GetChildren() )
1051 {
1052 if( dynamic_cast<DIALOG_SHIM*>( window ) )
1053 dialogs.push_back( window );
1054 }
1055
1056 return dialogs;
1057}
1058
1059
1060void EDA_DRAW_FRAME::FocusOnLocation( const VECTOR2I& aPos, bool aAllowScroll )
1061{
1062 bool centerView = false;
1063 std::vector<BOX2D> dialogScreenRects;
1064
1065 if( aAllowScroll )
1066 {
1067 BOX2D r = GetCanvas()->GetView()->GetViewport();
1068
1069 // Center if we're off the current view, or within 10% of its edge
1070 r.Inflate( - r.GetWidth() / 10.0 );
1071
1072 if( !r.Contains( aPos ) )
1073 centerView = true;
1074
1075 for( wxWindow* dialog : findDialogs() )
1076 {
1077 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1078 ToVECTOR2D( dialog->GetSize() ) );
1079 }
1080
1081 // Center if we're behind an obscuring dialog, or within 10% of its edge
1082 for( BOX2D rect : dialogScreenRects )
1083 {
1084 rect.Inflate( rect.GetWidth() / 10 );
1085
1086 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1087 centerView = true;
1088 }
1089 }
1090
1091 if( centerView )
1092 {
1093 try
1094 {
1095 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1096 }
1097 catch( const Clipper2Lib::Clipper2Exception& e )
1098 {
1099 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ), e.what() ) );
1100 }
1101 }
1102
1104}
1105
1106
1107void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1108 const wxString& aSheetName, const wxString& aSheetPath,
1109 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1110 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1111 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1112 const wxString& aSheetLayer, bool aIsFirstPage )
1113{
1114 DS_DRAW_ITEM_LIST drawList( unityScale );
1115
1116 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1117 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1118 drawList.SetPageNumber( aPageNumber );
1119 drawList.SetSheetCount( aSheetCount );
1120 drawList.SetFileName( aFileName );
1121 drawList.SetSheetName( aSheetName );
1122 drawList.SetSheetPath( aSheetPath );
1123 drawList.SetSheetLayer( aSheetLayer );
1124 drawList.SetProject( aProject );
1125 drawList.SetIsFirstPage( aIsFirstPage );
1126 drawList.SetProperties( aProperties );
1127
1128 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1129
1130 // Draw item list
1131 drawList.Print( aSettings );
1132}
1133
1134
1136 const std::map<wxString, wxString>* aProperties,
1137 double aMils2Iu, const wxString &aFilename,
1138 const wxString &aSheetLayer )
1139{
1141 return;
1142
1143 wxDC* DC = aSettings->GetPrintDC();
1144 wxPoint origin = DC->GetDeviceOrigin();
1145
1146 if( origin.y > 0 )
1147 {
1148 DC->SetDeviceOrigin( 0, 0 );
1149 DC->SetAxisOrientation( true, false );
1150 }
1151
1153 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1154 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1155 aScreen->GetVirtualPageNumber() == 1 );
1156
1157 if( origin.y > 0 )
1158 {
1159 DC->SetDeviceOrigin( origin.x, origin.y );
1160 DC->SetAxisOrientation( true, true );
1161 }
1162}
1163
1164
1166{
1167 // Virtual function. Base class implementation returns an empty string.
1168 return wxEmptyString;
1169}
1170
1171
1173{
1174 // Virtual function. Base class implementation returns an empty string.
1175 return wxEmptyString;
1176}
1177
1178
1179bool EDA_DRAW_FRAME::LibraryFileBrowser( const wxString& aTitle, bool doOpen, wxFileName& aFilename,
1180 const wxString& wildcard, const wxString& ext,
1181 bool isDirectory, FILEDLG_HOOK_NEW_LIBRARY* aFileDlgHook )
1182{
1183 aFilename.SetExt( ext );
1184
1185 wxString defaultDir = aFilename.GetPath();
1186
1187 if( defaultDir.IsEmpty() )
1188 defaultDir = GetMruPath();
1189
1190 if( isDirectory && doOpen )
1191 {
1192 wxDirDialog dlg( this, aTitle, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1193
1194 if( dlg.ShowModal() == wxID_CANCEL )
1195 return false;
1196
1197 aFilename = dlg.GetPath();
1198 aFilename.SetExt( ext );
1199 }
1200 else
1201 {
1202 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1203 if( aFilename.GetName().empty() )
1204 aFilename.SetName( wxS( "Library" ) );
1205
1206 wxFileDialog dlg( this, aTitle, defaultDir, aFilename.GetFullName(), wildcard,
1207 doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1208 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1209
1210 if( aFileDlgHook )
1211 dlg.SetCustomizeHook( *aFileDlgHook );
1212
1214
1215 if( dlg.ShowModal() == wxID_CANCEL )
1216 return false;
1217
1218 aFilename = dlg.GetPath();
1219 aFilename.SetExt( ext );
1220 }
1221
1222 SetMruPath( aFilename.GetPath() );
1223
1224 return true;
1225}
1226
1227
1229{
1231
1232 if( m_searchPane )
1233 {
1234 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1235 search_pane_info.Caption( _( "Search" ) );
1236 }
1237
1238 if( m_propertiesPanel )
1239 {
1240 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1241 properties_pane_info.Caption( _( "Properties" ) );
1242 }
1243
1245 {
1246 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1247 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1248 }
1249}
1250
1251
1253{
1254 if( m_isClosing || !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1255 return;
1256
1257 m_propertiesPanel->UpdateData();
1258}
1259
1260
1265
1266
1268{
1269 if( !m_colorSettings || aForceRefresh )
1270 {
1272 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1273 }
1274
1275 return m_colorSettings;
1276}
1277
1278
1280{
1282
1283 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
1284 EDITOR_CONDITIONS cond( this );
1285
1286 wxASSERT( mgr );
1287
1291}
1292
1293
1295{
1296 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1297
1298 if( cmnTool )
1299 {
1300 // Tell the tool what the units used last session
1301 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1302 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1303 }
1304
1305 // Tell the tool what units the frame is currently using
1306 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1307 {
1308 default:
1309 case EDA_UNITS::MM: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1310 case EDA_UNITS::INCH: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1311 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1312 }
1313}
1314
1315
1316void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1317{
1318 COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
1319
1320 aPrimaryUnit = GetUserUnits();
1321 aSecondaryUnits = EDA_UNITS::MILS;
1322
1323 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1324 {
1325 if( cmnTool )
1326 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1327 else
1328 aSecondaryUnits = EDA_UNITS::MM;
1329 }
1330 else
1331 {
1332 if( cmnTool )
1333 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1334 else
1335 aSecondaryUnits = EDA_UNITS::MILS;
1336 }
1337}
1338
1339
1341{
1343
1344 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1345 // user preference silently:
1346
1349}
1350
1351
1352void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1353{
1354 // Force a refresh of the message panel to ensure that the text is the right color
1355 // when the window activates
1356 if( !IsIconized() )
1357 m_messagePanel->Refresh();
1358}
1359
1360
1361void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1362{
1363 handleActivateEvent( aEvent );
1364
1365 aEvent.Skip();
1366}
1367
1368
1369bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName, BITMAP_TYPE aBitmapType )
1370{
1371 wxImage image;
1372
1373
1374 if( !GetCanvas()->GetScreenshot( image ) )
1375 {
1376 wxSize image_size = GetCanvas()->GetClientSize();
1377 wxClientDC dc( GetCanvas() );
1378 wxBitmap bitmap( image_size.x, image_size.y );
1379 wxMemoryDC memdc;
1380
1381 memdc.SelectObject( bitmap );
1382 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1383 memdc.SelectObject( wxNullBitmap );
1384
1385 image = bitmap.ConvertToImage();
1386 }
1387
1388 wxBitmapType type = wxBITMAP_TYPE_PNG;
1389 switch( aBitmapType )
1390 {
1391 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1392 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1393 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1394 }
1395
1396 bool retv = image.SaveFile( aFileName, type );
1397
1398 image.Destroy();
1399 return retv;
1400}
1401
1402
1404{
1405 wxCHECK( aCfg, aAction.show_button );
1406
1407 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1408 {
1409 if( identifier == aAction.identifier )
1410 return visible;
1411 }
1412
1413 return aAction.show_button;
1414}
1415
1416
1417std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions( PLUGIN_ACTION_SCOPE aScope,
1418 APP_SETTINGS_BASE* aCfg )
1419{
1420 std::vector<const PLUGIN_ACTION*> actions;
1421 wxCHECK( aCfg, actions );
1422
1423#ifdef KICAD_IPC_API
1424
1425 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1426 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1427 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1428 std::set<const PLUGIN_ACTION*> handled;
1429
1430 for( const PLUGIN_ACTION* action : unsorted )
1431 actionMap[action->identifier] = action;
1432
1433 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1434 {
1435 if( actionMap.contains( identifier ) )
1436 {
1437 const PLUGIN_ACTION* action = actionMap[ identifier ];
1438 actions.emplace_back( action );
1439 handled.insert( action );
1440 }
1441 }
1442
1443 for( const auto& action : actionMap | std::views::values )
1444 {
1445 if( !handled.contains( action ) )
1446 actions.emplace_back( action );
1447 }
1448
1449#endif
1450
1451 return actions;
1452}
1453
1454
1456{
1457#ifdef KICAD_IPC_API
1458 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1459
1460 mgr.ButtonBindings().clear();
1461
1462 std::vector<const PLUGIN_ACTION*> actions = GetOrderedPluginActions( PluginActionScope(), config() );
1463
1464 for( const PLUGIN_ACTION* action : actions )
1465 {
1466 if( !IsPluginActionButtonVisible( *action, config() ) )
1467 continue;
1468
1469 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark
1470 : action->icon_light;
1471
1472 wxAuiToolBarItem* button = aToolbar->AddTool( wxID_ANY, wxEmptyString, icon, action->name );
1473
1474 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1475 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1476
1477 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1478 }
1479#endif
1480}
1481
1482
1483void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1484{
1485#ifdef KICAD_IPC_API
1486 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1487
1488 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1489 {
1490 std::shared_ptr<REPORTER> reporter;
1491
1492 if( KISTATUSBAR* statusBar = dynamic_cast<KISTATUSBAR*>( GetStatusBar() ) )
1493 reporter = std::make_shared<STATUSBAR_WARNING_REPORTER>( statusBar, wxS( "plugin" ) );
1494
1495 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ), reporter );
1496 }
1497#endif
1498}
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:69
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:234
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:601
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:681
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:667
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:661
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:50
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h: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
IbisParser parser & reporter
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
VECTOR2< double > VECTOR2D
Definition vector2d.h:686
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:40