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