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 <file_history.h>
37#include <id.h>
38#include <kiface_base.h>
39#include <kiplatform/ui.h>
40#include <lockfile.h>
41#include <macros.h>
42#include <math/vector2wx.h>
43#include <page_info.h>
44#include <paths.h>
45#include <pgm_base.h>
46#include <render_settings.h>
51#include <title_block.h>
52#include <tool/actions.h>
53#include <tool/action_toolbar.h>
54#include <tool/common_tools.h>
55#include <tool/grid_helper.h>
56#include <tool/grid_menu.h>
59#include <tool/tool_manager.h>
60#include <tool/tool_menu.h>
61#include <tool/zoom_menu.h>
62#include <trace_helpers.h>
63#include <view/view.h>
65#include <view/view_controls.h>
66#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>
80
81#define FR_HISTORY_LIST_CNT 10
82
83
84BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
87
88 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
89END_EVENT_TABLE()
90
91
92bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
93
94
95EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
96 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
97 long aStyle, const wxString& aFrameName,
98 const EDA_IU_SCALE& aIuScale ) :
99 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
100 m_socketServer( nullptr ),
101 m_lastToolbarIconSize( 0 )
102{
103 m_mainToolBar = nullptr;
104 m_drawToolBar = nullptr;
105 m_optionsToolBar = nullptr;
106 m_auxiliaryToolBar = nullptr;
107 m_gridSelectBox = nullptr;
108 m_zoomSelectBox = nullptr;
109 m_searchPane = nullptr;
110 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
111
113 m_canvas = nullptr;
114 m_toolDispatcher = nullptr;
115 m_messagePanel = nullptr;
116 m_currentScreen = nullptr;
117 m_showBorderAndTitleBlock = false; // true to display reference sheet.
118 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
119 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
120 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
121 m_colorSettings = nullptr;
122 m_polarCoords = false;
123 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
124 m_hotkeyPopup = nullptr;
125 m_propertiesPanel = nullptr;
126 m_netInspectorPanel = nullptr;
127
128 SetUserUnits( EDA_UNITS::MILLIMETRES );
129
130 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
131
132 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
133 {
134 CreateStatusBar( 8 )->SetDoubleBuffered( true );
135
136 GetStatusBar()->SetFont( KIUI::GetStatusFont( this ) );
137
138 // set the size of the status bar subwindows:
139 updateStatusBarWidths();
140 }
141
142 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ), wxDefaultSize );
143 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
144 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
145
146 // Create child subwindows.
147 GetClientSize( &m_frameSize.x, &m_frameSize.y );
148 m_framePos.x = m_framePos.y = 0;
149 m_frameSize.y -= m_msgFrameHeight;
150
151 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
152
153 Bind( wxEVT_DPI_CHANGED,
154 [&]( wxDPIChangedEvent& )
155 {
156 if( ( GetWindowStyle() & wxFRAME_NO_TASKBAR ) == 0 )
157 updateStatusBarWidths();
158
159 wxMoveEvent dummy;
160 OnMove( dummy );
161
162 // we need to kludge the msg panel to the correct size again
163 // especially important even for first launches as the constructor of the window
164 // here usually doesn't have the correct dpi awareness yet
165 m_frameSize.y += m_msgFrameHeight;
166 m_msgFrameHeight = m_messagePanel->GetBestSize().y;
167 m_frameSize.y -= m_msgFrameHeight;
168
169 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
170 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
171
172 // Don't skip, otherwise the frame gets too big
173 } );
174}
175
176
178{
180
181 delete m_actions;
182 delete m_toolManager;
183 delete m_toolDispatcher;
184 delete m_canvas;
185
186 delete m_currentScreen;
187 m_currentScreen = nullptr;
188
189 m_auimgr.UnInit();
190
191 ReleaseFile();
192}
193
194
196{
197 if( m_file_checker.get() != nullptr )
198 m_file_checker->UnlockFile();
199}
200
201
202bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
203{
204 // We need to explicitly reset here to get the deletion before
205 // we create a new unique_ptr that may be for the same file
206 m_file_checker.reset();
207
208 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
209
210 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
211 {
212 // If we cannot acquire the lock but we appear to be the one who
213 // locked it, check to see if there is another KiCad instance running.
214 // If there is not, then we can override the lock. This could happen if
215 // KiCad crashed or was interrupted
216 if( !Pgm().SingleInstance()->IsAnotherRunning() )
217 m_file_checker->OverrideLock();
218 }
219 // If the file is valid, return true. This could mean that the file is
220 // locked or it could mean that the file is read-only
221 return m_file_checker->Valid();
222}
223
224
226{
227 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
228
229 wxRect rect = GetScreenRect();
230 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
231
232 if( !frame )
233 {
234 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
235
236 // If we received an error in the CTOR due to Python-ness, don't crash
237 if( !frame )
238 return;
239
240 if( !frame->IsVisible() )
241 frame->Show( true );
242
243 // On Windows, Raise() does not bring the window on screen, when iconized
244 if( frame->IsIconized() )
245 frame->Iconize( false );
246
247 frame->Raise();
248 frame->SetPosition( center - frame->GetSize() / 2 );
249
250 return;
251 }
252
253 frame->Show( !frame->IsVisible() );
254 frame->SetPosition( center - frame->GetSize() / 2 );
255}
256
257
259{
260 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
261 return frame && frame->IsVisible();
262}
263
264
266{
267 // Notify all tools the units have changed
268 if( m_toolManager )
270
274}
275
276
278{
280 {
282 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
283 }
284 else
285 {
286 SetUserUnits( GetUserUnits() == EDA_UNITS::INCHES ? EDA_UNITS::MILLIMETRES
287 : EDA_UNITS::INCHES );
289
290 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
291 ProcessEventLocally( e );
292 }
293}
294
295
296void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
297{
298 EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
299
300 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
302
303 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
304 {
305 if( GetAutoSaveInterval() > 0 )
306 {
307 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
308 }
309 else
310 {
311 m_autoSaveTimer->Stop();
312 m_autoSavePending = false;
313 }
314 }
315
316 viewControls->LoadSettings();
317
318 m_galDisplayOptions.ReadCommonConfig( *settings, this );
319
320 GetToolManager()->RunAction( ACTIONS::gridPreset, config()->m_Window.grid.last_size_idx );
322
323 if( m_lastToolbarIconSize == 0
325 {
328 }
329
330#ifndef __WXMAC__
332
333 if( m_canvasType != GetCanvas()->GetBackend() )
334 {
335 // Try to switch (will automatically fallback if necessary)
338 bool success = newGAL == m_canvasType;
339
340 if( !success )
341 {
342 m_canvasType = newGAL;
343 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
344 }
345 }
346#endif
347
348 // Notify all tools the preferences have changed
349 if( m_toolManager )
351}
352
353
355{
356 if( m_messagePanel )
358}
359
360
362{
365
366 if( m_gridSelectBox == nullptr )
367 return;
368
369 // Update grid values with the current units setting.
370 m_gridSelectBox->Clear();
371 wxArrayString gridsList;
372
373 wxCHECK( config(), /* void */ );
374
375 GRID_MENU::BuildChoiceList( &gridsList, config(), this );
376
377 for( const wxString& grid : gridsList )
378 m_gridSelectBox->Append( grid );
379
380 m_gridSelectBox->Append( wxT( "---" ) );
381 m_gridSelectBox->Append( _( "Edit Grids..." ) );
382
383 m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
384}
385
386
387void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
388{
389 // No need to update the grid select box if it doesn't exist or the grid setting change
390 // was made using the select box.
391 if( m_gridSelectBox == nullptr )
392 return;
393
394 wxCHECK( config(), /* void */ );
395
396 int idx = config()->m_Window.grid.last_size_idx;
397 idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
398
399 if( idx != m_gridSelectBox->GetSelection() )
400 m_gridSelectBox->SetSelection( idx );
401}
402
403
404
405void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
406{
407 // No need to update the grid select box if it doesn't exist or the grid setting change
408 // was made using the select box.
409 if( m_zoomSelectBox == nullptr )
410 return;
411
412 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
413
414 wxCHECK( config(), /* void */ );
415
416 const std::vector<double>& zoomList = config()->m_Window.zoom_factors;
417 int curr_selection = m_zoomSelectBox->GetSelection();
418 int new_selection = 0; // select zoom auto
419 double last_approx = 1e9; // large value to start calculation
420
421 // Search for the nearest available value to the current zoom setting, and select it
422 for( size_t jj = 0; jj < zoomList.size(); ++jj )
423 {
424 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
425
426 if( rel_error < last_approx )
427 {
428 last_approx = rel_error;
429
430 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
431 new_selection = jj + 1;
432 }
433 }
434
435 if( curr_selection != new_selection )
436 m_zoomSelectBox->SetSelection( new_selection );
437}
438
439
441{
442 DisplayErrorMessage( this, wxT( "EDA_DRAW_FRAME::PrintPage() error" ) );
443}
444
445
446void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
447{
448 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
449
450 int idx = m_gridSelectBox->GetCurrentSelection();
451
452 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
453 {
454 // wxWidgets will check the separator, which we don't want.
455 // Re-check the current grid.
456 wxUpdateUIEvent dummy;
458 }
459 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
460 {
461 // wxWidgets will check the Grid Settings... entry, which we don't want.
462 // Re-check the current grid.
463 wxUpdateUIEvent dummy;
465
466 // Give a time-slice to close the menu before opening the dialog.
467 // (Only matters on some versions of GTK.)
468 wxSafeYield();
469
471 }
472 else
473 {
475 }
476
478 m_canvas->Refresh();
479
480 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
481 // (Windows specific
483}
484
485
487{
488 wxCHECK( config(), true );
489
490 return config()->m_Window.grid.show;
491}
492
493
495{
496 wxCHECK( config(), /* void */ );
497
498 config()->m_Window.grid.show = aVisible;
499
500 // Update the display with the new grid
501 if( GetCanvas() )
502 {
503 // Check to ensure these exist, since this function could be called before
504 // the GAL and View have been created
505 if( GetCanvas()->GetGAL() )
506 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
507
508 if( GetCanvas()->GetView() )
510
511 GetCanvas()->Refresh();
512 }
513}
514
515
517{
518 wxCHECK( config(), false );
519
521}
522
523
525{
526 wxCHECK( config(), /* void */ );
527
528 config()->m_Window.grid.overrides_enabled = aOverride;
529}
530
531
532std::unique_ptr<GRID_HELPER> EDA_DRAW_FRAME::MakeGridHelper()
533{
534 return nullptr;
535}
536
537
539{
540 if( m_zoomSelectBox == nullptr )
541 return;
542
543 double zoom = m_canvas->GetGAL()->GetZoomFactor();
544
545 m_zoomSelectBox->Clear();
546 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
547 m_zoomSelectBox->SetSelection( 0 );
548
549 wxCHECK( config(), /* void */ );
550
551 for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
552 {
553 double current = config()->m_Window.zoom_factors[i];
554
555 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
556
557 if( zoom == current )
558 m_zoomSelectBox->SetSelection( i + 1 );
559 }
560}
561
562
563void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
564{
565 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
566
567 int id = m_zoomSelectBox->GetCurrentSelection();
568
569 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
570 return;
571
574 m_canvas->Refresh();
575
576 // Needed on Windows because clicking on m_zoomSelectBox remove the focus from m_canvas
577 // (Windows specific
579}
580
581
582void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
583{
584 // If the window is moved to a different display, the scaling factor may change
585 double oldFactor = m_galDisplayOptions.m_scaleFactor;
587
588 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
589 {
590 wxSize clientSize = GetClientSize();
591 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
593 }
594
595 aEvent.Skip();
596}
597
598
600{
602 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
603
604 aMenu.AddSeparator( 1000 );
605
606 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
607 zoomMenu->SetTool( commonTools );
608 aToolMenu.RegisterSubMenu( zoomMenu );
609
610 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
611 gridMenu->SetTool( commonTools );
612 aToolMenu.RegisterSubMenu( gridMenu );
613
614 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
615 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
616}
617
618
619void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
620{
621 SetStatusText( msg, 6 );
622}
623
624
625void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
626{
627 SetStatusText( msg, 7 );
628}
629
630
632{
633 wxString msg;
634
637
638 msg.Printf( _( "grid %s" ),
639 gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
640
641 SetStatusText( msg, 4 );
642}
643
644
646{
647 wxString msg;
648
649 switch( GetUserUnits() )
650 {
651 case EDA_UNITS::INCHES: msg = _( "inches" ); break;
652 case EDA_UNITS::MILS: msg = _( "mils" ); break;
653 case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
654 default: msg = _( "Units" ); break;
655 }
656
657 SetStatusText( msg, 5 );
658}
659
660
661void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
662{
663 EDA_BASE_FRAME::OnSize( SizeEv );
664
665 m_frameSize = GetClientSize( );
666
667 SizeEv.Skip();
668}
669
670
672{
673 wxWindow* stsbar = GetStatusBar();
674 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
675
676 int dims[] = {
677 // remainder of status bar on far left is set to a default or whatever is left over.
678 -1,
679
680 // When using GetTextSize() remember the width of character '1' is not the same
681 // as the width of '0' unless the font is fixed width, and it usually won't be.
682
683 // zoom:
684 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
685
686 // cursor coords
687 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
688
689 // delta distances
690 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
691
692 // grid size
693 KIUI::GetTextSize( wxT( "grid X 1234.1234 Y 1234.1234" ), stsbar ).x,
694
695 // units display, Inches is bigger than mm
696 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
697
698 // Size for the "Current Tool" panel; longest string from SetTool()
699 KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
700
701 // constraint mode
702 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
703 };
704
705 for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
706 dims[ii] += spacer;
707
708 SetStatusWidths( arrayDim( dims ), dims );
709}
710
711
713{
714 SetStatusText( GetZoomLevelIndicator(), 1 );
715
716 // Absolute and relative cursor positions are handled by overloading this function and
717 // handling the internal to user units conversion at the appropriate level.
718
719 // refresh units display
721}
722
723
725{
726 // returns a human readable value which can be displayed as zoom
727 // level indicator in dialogs.
728 double zoom = m_canvas->GetGAL()->GetZoomFactor();
729 return wxString::Format( wxT( "Z %.2f" ), zoom );
730}
731
732
734{
736
738 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
739
740 // Read units used in dialogs and toolbars
741 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
742
744
745 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
746
747 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
748 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
749 m_findReplaceData->matchMode =
750 static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
751 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
752 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
753
754 for( const wxString& s : aCfg->m_FindReplace.find_history )
756
757 for( const wxString& s : aCfg->m_FindReplace.replace_history )
759
761}
762
763
765{
767
768 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
769
770 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
772
774
775 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
776
777 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
778 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
779
780 aCfg->m_FindReplace.find_history.clear();
781 aCfg->m_FindReplace.replace_history.clear();
782
783 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
784 {
785 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
786 }
787
788 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
789 {
790 aCfg->m_FindReplace.replace_history.push_back(
791 m_replaceStringHistoryList[ i ].ToStdString() );
792 }
793
794 // Save the units used in this frame
795 if( m_toolManager )
796 {
798 {
800 static_cast<int>( cmnTool->GetLastImperialUnits() );
801 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
802 }
803 }
804}
805
806
807void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
808 int aPadding )
809{
811 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
812}
813
814
816{
819}
820
821
822void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
823{
825 {
827
828 for( const MSG_PANEL_ITEM& item : aList )
830 }
831}
832
833
834void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
835 int aPadding )
836{
838 {
840 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
841 }
842}
843
844
846{
847 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
848
849 std::vector<MSG_PANEL_ITEM> items;
850 aItem->GetMsgPanelInfo( this, items );
851 SetMsgPanel( items );
852}
853
854
856{
857}
858
859
861{
862 GetCanvas()->SetEvtHandlerEnabled( true );
864}
865
866
868{
869 GetCanvas()->SwitchBackend( aCanvasType );
871
873}
874
875
877{
878#ifdef __WXMAC__
879 // Cairo renderer doesn't handle Retina displays so there's really only one game
880 // in town for Mac
882#endif
883
885 APP_SETTINGS_BASE* cfg = aCfg ? aCfg : Kiface().KifaceSettings();
886
887 if( cfg )
888 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
889
890 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
891 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
892 {
893 wxASSERT( false );
895 }
896
897 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
898 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
900
901 return canvasType;
902}
903
904
906{
907 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
908 // have a fixed type, or do not have a option to set the canvas type (they inherit from
909 // a parent frame)
910 static std::vector<FRAME_T> s_allowedFrames =
911 {
916 };
917
918 if( !alg::contains( s_allowedFrames, m_ident ) )
919 return false;
920
921 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
922 || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
923 {
924 wxASSERT( false );
925 return false;
926 }
927
928 if( APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings() )
929 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
930
931 return false;
932}
933
934
936{
937 const VECTOR2I& gridOrigin = GetGridOrigin();
938 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
939
940 double xOffset = fmod( gridOrigin.x, gridSize.x );
941 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
942 double yOffset = fmod( gridOrigin.y, gridSize.y );
943 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
944
945 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
946}
947
948
950{
951 const VECTOR2I& gridOrigin = GetGridOrigin();
952 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
953
954 double xOffset = fmod( gridOrigin.x, gridSize.x );
955 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
956 double yOffset = fmod( gridOrigin.y, gridSize.y );
957 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
958
959 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
960}
961
962
963const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
964{
965 return BOX2I();
966}
967
968
970{
971 // To be implemented by subclasses.
972}
973
974
975void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
976{
978}
979
980
981std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
982{
983 std::vector<wxWindow*> dialogs;
984
985 for( wxWindow* window : GetChildren() )
986 {
987 if( dynamic_cast<DIALOG_SHIM*>( window ) )
988 dialogs.push_back( window );
989 }
990
991 return dialogs;
992}
993
994
996{
997 bool centerView = false;
999
1000 // Center if we're off the current view, or within 10% of its edge
1001 r.Inflate( - (int) r.GetWidth() / 10 );
1002
1003 if( !r.Contains( aPos ) )
1004 centerView = true;
1005
1006 std::vector<BOX2D> dialogScreenRects;
1007
1008 for( wxWindow* dialog : findDialogs() )
1009 {
1010 dialogScreenRects.emplace_back(
1011 ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
1012 ToVECTOR2D( dialog->GetSize() ) );
1013 }
1014
1015 // Center if we're behind an obscuring dialog, or within 10% of its edge
1016 for( BOX2D rect : dialogScreenRects )
1017 {
1018 rect.Inflate( rect.GetWidth() / 10 );
1019
1020 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
1021 centerView = true;
1022 }
1023
1024 if( centerView )
1025 {
1026 try
1027 {
1028 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1029 }
1030 catch( const Clipper2Lib::Clipper2Exception& e )
1031 {
1032 wxFAIL_MSG( wxString::Format( wxT( "Clipper2 exception occurred centering object: %s" ),
1033 e.what() ) );
1034 }
1035 }
1036
1038}
1039
1040
1041static const wxString productName = wxT( "KiCad E.D.A. " );
1042
1043
1044void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1045 const wxString& aSheetName, const wxString& aSheetPath,
1046 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1047 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1048 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1049 const wxString& aSheetLayer, bool aIsFirstPage )
1050{
1051 DS_DRAW_ITEM_LIST drawList( unityScale );
1052
1053 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1054 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1055 drawList.SetPageNumber( aPageNumber );
1056 drawList.SetSheetCount( aSheetCount );
1057 drawList.SetFileName( aFileName );
1058 drawList.SetSheetName( aSheetName );
1059 drawList.SetSheetPath( aSheetPath );
1060 drawList.SetSheetLayer( aSheetLayer );
1061 drawList.SetProject( aProject );
1062 drawList.SetIsFirstPage( aIsFirstPage );
1063 drawList.SetProperties( aProperties );
1064
1065 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1066
1067 // Draw item list
1068 drawList.Print( aSettings );
1069}
1070
1071
1073 const std::map<wxString, wxString>* aProperties,
1074 double aMils2Iu, const wxString &aFilename,
1075 const wxString &aSheetLayer )
1076{
1078 return;
1079
1080 wxDC* DC = aSettings->GetPrintDC();
1081 wxPoint origin = DC->GetDeviceOrigin();
1082
1083 if( origin.y > 0 )
1084 {
1085 DC->SetDeviceOrigin( 0, 0 );
1086 DC->SetAxisOrientation( true, false );
1087 }
1088
1090 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1091 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1092 aScreen->GetVirtualPageNumber() == 1 );
1093
1094 if( origin.y > 0 )
1095 {
1096 DC->SetDeviceOrigin( origin.x, origin.y );
1097 DC->SetAxisOrientation( true, true );
1098 }
1099}
1100
1101
1103{
1104 // Virtual function. Base class implementation returns an empty string.
1105 return wxEmptyString;
1106}
1107
1108
1110{
1111 // Virtual function. Base class implementation returns an empty string.
1112 return wxEmptyString;
1113}
1114
1115
1116bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
1117 const wxString& wildcard, const wxString& ext,
1118 bool isDirectory, bool aIsGlobal,
1119 const wxString& aGlobalPath )
1120{
1121 wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
1122 aFilename.SetExt( ext );
1123
1124 wxString projectDir = Prj().IsNullProject() ? aFilename.GetPath() : Prj().GetProjectPath();
1125 wxString defaultDir;
1126
1127 if( aIsGlobal )
1128 {
1129 if( !GetMruPath().IsEmpty() && !GetMruPath().StartsWith( projectDir ) )
1130 defaultDir = GetMruPath();
1131 else
1132 defaultDir = aGlobalPath;
1133 }
1134 else
1135 {
1136 if( !GetMruPath().IsEmpty() && GetMruPath().StartsWith( projectDir ) )
1137 defaultDir = GetMruPath();
1138 else
1139 defaultDir = projectDir;
1140 }
1141
1142 if( isDirectory && doOpen )
1143 {
1144 wxDirDialog dlg( this, prompt, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1145
1146 if( dlg.ShowModal() == wxID_CANCEL )
1147 return false;
1148
1149 aFilename = dlg.GetPath();
1150 aFilename.SetExt( ext );
1151 }
1152 else
1153 {
1154 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1155 if( aFilename.GetName().empty() )
1156 aFilename.SetName( wxS( "Library" ) );
1157
1158 wxFileDialog dlg( this, prompt, defaultDir, aFilename.GetFullName(),
1159 wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1160 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1161
1162 if( dlg.ShowModal() == wxID_CANCEL )
1163 return false;
1164
1165 aFilename = dlg.GetPath();
1166 aFilename.SetExt( ext );
1167 }
1168
1169 SetMruPath( aFilename.GetPath() );
1170
1171 return true;
1172}
1173
1174
1176{
1177 // Rebuild all toolbars, and update the checked state of check tools
1178 if( m_mainToolBar )
1180
1181 if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
1183
1184 if( m_optionsToolBar ) // Options (typically on left edge of window)
1186
1187 if( m_auxiliaryToolBar ) // Additional tools under main toolbar
1189
1190
1191}
1192
1193
1195{
1196 if( m_mainToolBar )
1197 m_auimgr.GetPane( m_mainToolBar ).MaxSize( m_mainToolBar->GetSize() );
1198
1199 if( m_drawToolBar )
1200 m_auimgr.GetPane( m_drawToolBar ).MaxSize( m_drawToolBar->GetSize() );
1201
1202 if( m_optionsToolBar )
1203 m_auimgr.GetPane( m_optionsToolBar ).MaxSize( m_optionsToolBar->GetSize() );
1204
1205 if( m_auxiliaryToolBar )
1206 m_auimgr.GetPane( m_auxiliaryToolBar ).MaxSize( m_auxiliaryToolBar->GetSize() );
1207
1208 m_auimgr.Update();
1209}
1210
1211
1213{
1215
1216 if( m_searchPane )
1217 {
1218 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1219 search_pane_info.Caption( _( "Search" ) );
1220 }
1221
1222 if( m_propertiesPanel )
1223 {
1224 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1225 properties_pane_info.Caption( _( "Properties" ) );
1226 }
1227
1229 {
1230 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1231 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1232 }
1233}
1234
1235
1237{
1238 if( !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1239 return;
1240
1242}
1243
1244
1246{
1247 m_hotkeyPopup = new HOTKEY_CYCLE_POPUP( this );
1248}
1249
1250
1252{
1253 if( !m_colorSettings || aForceRefresh )
1254 {
1256
1257 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1258 }
1259
1260 return m_colorSettings;
1261}
1262
1263
1265{
1267
1268 if( cmnTool )
1269 {
1270 // Tell the tool what the units used last session
1271 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1272 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1273 }
1274
1275 // Tell the tool what units the frame is currently using
1276 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1277 {
1278 default:
1279 case EDA_UNITS::MILLIMETRES: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1280 case EDA_UNITS::INCHES: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1281 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1282 }
1283}
1284
1285
1286void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1287{
1289
1290 aPrimaryUnit = GetUserUnits();
1291 aSecondaryUnits = EDA_UNITS::MILS;
1292
1293 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1294 {
1295 if( cmnTool )
1296 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1297 else
1298 aSecondaryUnits = EDA_UNITS::MILLIMETRES;
1299 }
1300 else
1301 {
1302 if( cmnTool )
1303 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1304 else
1305 aSecondaryUnits = EDA_UNITS::MILS;
1306 }
1307}
1308
1309
1311{
1313
1314 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1315 // user preference silently:
1316
1319}
1320
1321
1322void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1323{
1324 // Force a refresh of the message panel to ensure that the text is the right color
1325 // when the window activates
1326 if( !IsIconized() )
1327 m_messagePanel->Refresh();
1328}
1329
1330
1331void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1332{
1333 handleActivateEvent( aEvent );
1334
1335 aEvent.Skip();
1336}
1337
1338
1339bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName,
1340 BITMAP_TYPE aBitmapType )
1341{
1342 bool retv = true;
1343
1344 // Make a screen copy of the canvas:
1345 wxSize image_size = GetCanvas()->GetClientSize();
1346
1347 wxClientDC dc( GetCanvas() );
1348 wxBitmap bitmap( image_size.x, image_size.y );
1349 wxMemoryDC memdc;
1350
1351 memdc.SelectObject( bitmap );
1352 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1353 memdc.SelectObject( wxNullBitmap );
1354
1355 wxImage image = bitmap.ConvertToImage();
1356
1357 wxBitmapType type = wxBITMAP_TYPE_PNG;
1358 switch( aBitmapType )
1359 {
1360 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1361 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1362 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1363 }
1364
1365 if( !image.SaveFile( aFileName, type ) )
1366 retv = false;
1367
1368 image.Destroy();
1369 return retv;
1370}
1371
1372
1374 APP_SETTINGS_BASE* aCfg )
1375{
1376 wxCHECK( aCfg, aAction.show_button );
1377
1378 for( const auto& [identifier, visible] : aCfg->m_Plugins.actions )
1379 {
1380 if( identifier == aAction.identifier )
1381 return visible;
1382 }
1383
1384 return aAction.show_button;
1385}
1386
1387
1388std::vector<const PLUGIN_ACTION*> EDA_DRAW_FRAME::GetOrderedPluginActions(
1390{
1391 std::vector<const PLUGIN_ACTION*> actions;
1392 wxCHECK( aCfg, actions );
1393
1394#ifdef KICAD_IPC_API
1395
1396 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1397 std::vector<const PLUGIN_ACTION*> unsorted = mgr.GetActionsForScope( aScope );
1398 std::map<wxString, const PLUGIN_ACTION*> actionMap;
1399 std::set<const PLUGIN_ACTION*> handled;
1400
1401 for( const PLUGIN_ACTION* action : unsorted )
1402 actionMap[action->identifier] = action;
1403
1404 for( const auto& identifier : aCfg->m_Plugins.actions | std::views::keys )
1405 {
1406 if( actionMap.contains( identifier ) )
1407 {
1408 const PLUGIN_ACTION* action = actionMap[ identifier ];
1409 actions.emplace_back( action );
1410 handled.insert( action );
1411 }
1412 }
1413
1414 for( const auto& action : actionMap | std::views::values )
1415 {
1416 if( !handled.contains( action ) )
1417 actions.emplace_back( action );
1418 }
1419
1420#endif
1421
1422 return actions;
1423}
1424
1425
1427{
1428#ifdef KICAD_IPC_API
1429 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1430
1431 mgr.ButtonBindings().clear();
1432
1433 std::vector<const PLUGIN_ACTION*> actions =
1435
1436 for( const PLUGIN_ACTION* action : actions )
1437 {
1438 if( !IsPluginActionButtonVisible( *action, config() ) )
1439 continue;
1440
1441 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk()
1442 ? action->icon_dark
1443 : action->icon_light;
1444
1445 wxAuiToolBarItem* button = m_mainToolBar->AddTool( wxID_ANY, wxEmptyString, icon,
1446 action->name );
1447
1448 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1449 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1450
1451 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1452 }
1453#endif
1454}
1455
1456
1457void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1458{
1459#ifdef KICAD_IPC_API
1460 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1461
1462 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1463 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ) );
1464#endif
1465}
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:56
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:111
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
BITMAP_TYPE
Definition: bitmap_types.h:43
BOX2< VECTOR2I > BOX2I
Definition: box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static TOOL_ACTION gridProperties
Definition: actions.h:189
static TOOL_ACTION millimetersUnits
Definition: actions.h:195
static TOOL_ACTION updatePreferences
Definition: actions.h:223
static TOOL_ACTION gridPreset
Definition: actions.h:186
static TOOL_ACTION updateUnits
Definition: actions.h:196
static TOOL_ACTION milsUnits
Definition: actions.h:194
static TOOL_ACTION inchesUnits
Definition: actions.h:193
static TOOL_ACTION zoomFitScreen
Definition: actions.h:134
static TOOL_ACTION zoomPreset
Definition: actions.h:137
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
std::map< int, wxString > & ButtonBindings()
std::vector< const PLUGIN_ACTION * > GetActionsForScope(PLUGIN_ACTION_SCOPE aScope)
void InvokeAction(const wxString &aIdentifier)
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:196
FIND_REPLACE m_FindReplace
Definition: app_settings.h:180
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
Definition: base_screen.cpp:70
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.
Definition: common_tools.h:38
void SetLastUnits(EDA_UNITS aUnit)
EDA_UNITS GetLastImperialUnits()
Definition: common_tools.h:79
EDA_UNITS GetLastMetricUnits()
Definition: common_tools.h:78
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:88
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:401
void SetPlotterMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to plot units.
Definition: ds_draw_item.h:468
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.
Definition: ds_draw_item.h:455
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:445
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:462
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.
Definition: ds_draw_item.h:450
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:494
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:435
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:460
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:499
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:489
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:425
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
wxTimer * m_autoSaveTimer
wxAuiManager m_auimgr
int GetMaxUndoItems() const
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
wxString GetMruPath() const
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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.
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.
virtual void ReCreateVToolbar()
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
virtual void PrintPage(const RENDER_SETTINGS *aSettings)
Print the page pointed by current screen, set by the calling print function.
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.
void OnToolbarSizeChanged()
Update toolbars if desired toolbar icon changed.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
void ScriptingConsoleEnableDisable()
Toggle the scripting console visibility.
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
bool IsScriptingConsoleVisible()
Get the current visibility of the scripting console window.
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.
ACTION_TOOLBAR * m_optionsToolBar
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.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
bool IsGridOverridden() const
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.
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting(APP_SETTINGS_BASE *aCfg=nullptr)
Return the canvas type stored in the application settings.
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.
virtual void ReCreateAuxiliaryToolbar()
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual void ReCreateHToolbar()
void RecreateToolbars()
Rebuild all toolbars and update the checked state of check tools.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Store the canvas type in the application settings.
ACTION_TOOLBAR * m_mainToolBar
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
virtual void SetGridVisibility(bool aVisible)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
virtual void ReCreateOptToolbar()
virtual void OnApiPluginInvoke(wxCommandEvent &aEvent)
Handler for activating an API plugin (via toolbar or menu).
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
void ToggleUserUnits() override
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 updateStatusBarWidths()
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.
ACTION_TOOLBAR * m_drawToolBar
SEARCH_PANE * m_searchPane
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
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
bool IsGridVisible() const
std::vector< wxWindow * > findDialogs()
virtual void DisplayGridMsg()
Display current grid size in the status bar.
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 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
virtual void addApiPluginTools()
Append actions from API plugins to the main toolbar.
bool m_showBorderAndTitleBlock
VECTOR2I GetNearestHalfGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
HOTKEY_CYCLE_POPUP * m_hotkeyPopup
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid wxchoice.
ACTION_TOOLBAR * m_auxiliaryToolBar
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_NONE
GAL not used (the legacy wxDC engine is used)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetFocus() override
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:89
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:204
A panel to display various information messages.
Definition: msgpanel.h:101
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
Definition: msgpanel.cpp:114
void EraseMsgBox()
Definition: msgpanel.cpp:218
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.
void WriteConfig(WINDOW_SETTINGS &aCfg)
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *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...
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
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.
int GetDefaultPenWidth() const
wxDC * GetPrintDC() const
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:520
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:655
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:586
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:635
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
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:59
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:689
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
Container for project specific data.
Definition: project.h:64
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:146
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:164
virtual void UpdateData()=0
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieve a color settings object that applications can read colors from.
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
Definition: tools_holder.h:167
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:169
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
ACTIONS * m_actions
Definition: tools_holder.h:168
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:400
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
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
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.
static const wxString productName
EDA_SEARCH_MATCH_MODE
EDA_UNITS
Definition: eda_units.h:46
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) void GERBVIEW_FRAME
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
@ FRAME_PYTHON
Definition: frame_type.h:55
Common command IDs shared by more than one of the KiCad applications.
@ ID_ON_GRID_SELECT
Definition: id.h:143
@ ID_ON_ZOOM_SELECT
Definition: id.h:141
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:48
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:131
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:77
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.
Definition: pgm_base.cpp:1073
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
std::vector< wxString > replace_history
Definition: app_settings.h:99
std::vector< wxString > find_history
Definition: app_settings.h:97
std::vector< std::pair< wxString, bool > > actions
Ordered list of plugin actions mapped to whether or not they are shown in the toolbar.
Definition: app_settings.h:166
bool overrides_enabled
Definition: grid_settings.h:78
std::vector< GRID > grids
Definition: grid_settings.h:66
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
Definition: api_plugin.h:82
wxString identifier
Definition: api_plugin.h:87
bool show_button
Definition: api_plugin.h:90
Store the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:74
GRID_SETTINGS grid
Definition: app_settings.h:81
std::vector< double > zoom_factors
Definition: app_settings.h:78
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:695
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition: vector2wx.h:40