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 (C) 2004-2023 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_menu.h>
58#include <tool/tool_manager.h>
59#include <tool/tool_menu.h>
60#include <tool/zoom_menu.h>
61#include <trace_helpers.h>
62#include <view/view.h>
64#include <widgets/msgpanel.h>
67#include <wx/event.h>
68#include <wx/snglinst.h>
69#include <widgets/ui_common.h>
70#include <widgets/search_pane.h>
71#include <wx/dirdlg.h>
72#include <wx/filedlg.h>
73#include <wx/msgdlg.h>
74#include <wx/socket.h>
75
76#include <wx/snglinst.h>
77#include <wx/fdrepdlg.h>
78
79#define FR_HISTORY_LIST_CNT 10
80
81
82BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
85
86 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
87END_EVENT_TABLE()
88
89
90bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
91
92
93EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
94 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
95 long aStyle, const wxString& aFrameName,
96 const EDA_IU_SCALE& aIuScale ) :
97 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
98 m_socketServer( nullptr ),
99 m_lastToolbarIconSize( 0 )
100{
101 m_mainToolBar = nullptr;
102 m_drawToolBar = nullptr;
103 m_optionsToolBar = nullptr;
104 m_auxiliaryToolBar = nullptr;
105 m_gridSelectBox = nullptr;
106 m_zoomSelectBox = nullptr;
107 m_searchPane = nullptr;
108 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
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_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this );
121 m_polarCoords = false;
122 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
123 m_hotkeyPopup = nullptr;
124 m_propertiesPanel = nullptr;
125 m_netInspectorPanel = nullptr;
126
127 SetUserUnits( EDA_UNITS::MILLIMETRES );
128
129 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
130
131 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
132 {
133 CreateStatusBar( 8 )->SetDoubleBuffered( true );
134
135 // set the size of the status bar subwindows:
136
137 wxWindow* stsbar = GetStatusBar();
138 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
139
140 int dims[] =
141 {
142 // remainder of status bar on far left is set to a default or whatever is left over.
143 -1,
144
145 // When using GetTextSize() remember the width of character '1' is not the same
146 // as the width of '0' unless the font is fixed width, and it usually won't be.
147
148 // zoom:
149 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
150
151 // cursor coords
152 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
153
154 // delta distances
155 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
156
157 // grid size
158 KIUI::GetTextSize( wxT( "grid X 1234.1234 Y 1234.1234" ), stsbar ).x,
159
160 // units display, Inches is bigger than mm
161 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
162
163 // Size for the "Current Tool" panel; longest string from SetTool()
164 KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
165
166 // constraint mode
167 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
168 };
169
170 for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
171 dims[ii] += spacer;
172
173 SetStatusWidths( arrayDim( dims ), dims );
174 stsbar->SetFont( KIUI::GetStatusFont( this ) );
175 }
176
177 // Create child subwindows.
178 GetClientSize( &m_frameSize.x, &m_frameSize.y );
179 m_framePos.x = m_framePos.y = 0;
180 m_frameSize.y -= m_msgFrameHeight;
181
182 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ),
183 wxSize( m_frameSize.x, m_msgFrameHeight ) );
184
185 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
186
187 Bind( wxEVT_DPI_CHANGED,
188 [&]( wxDPIChangedEvent& )
189 {
190 wxMoveEvent dummy;
191 OnMove( dummy );
192
193 // we need to kludge the msg panel to the correct size again
194 // especially important even for first launches as the constructor of the window
195 // here usually doesn't have the correct dpi awareness yet
196 m_frameSize.y += m_msgFrameHeight;
197 m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this );
198 m_frameSize.y -= m_msgFrameHeight;
199
200 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
201 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
202 } );
203}
204
205
207{
209
210 delete m_actions;
211 delete m_toolManager;
212 delete m_toolDispatcher;
213 delete m_canvas;
214
215 delete m_currentScreen;
216 m_currentScreen = nullptr;
217
218 m_auimgr.UnInit();
219
220 ReleaseFile();
221}
222
223
225{
226 if( m_file_checker.get() != nullptr )
227 m_file_checker->UnlockFile();
228}
229
230
231bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
232{
233 // We need to explicitly reset here to get the deletion before
234 // we create a new unique_ptr that may be for the same file
235 m_file_checker.reset();
236
237 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
238
239 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
240 {
241 // If we cannot acquire the lock but we appear to be the one who
242 // locked it, check to see if there is another KiCad instance running.
243 // If there is not, then we can override the lock. This could happen if
244 // KiCad crashed or was interrupted
245 if( !Pgm().SingleInstance()->IsAnotherRunning() )
246 m_file_checker->OverrideLock();
247 }
248 // If the file is valid, return true. This could mean that the file is
249 // locked or it could mean that the file is read-only
250 return m_file_checker->Valid();
251}
252
253
255{
256 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
257
258 wxRect rect = GetScreenRect();
259 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
260
261 if( !frame )
262 {
263 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
264
265 // If we received an error in the CTOR due to Python-ness, don't crash
266 if( !frame )
267 return;
268
269 if( !frame->IsVisible() )
270 frame->Show( true );
271
272 // On Windows, Raise() does not bring the window on screen, when iconized
273 if( frame->IsIconized() )
274 frame->Iconize( false );
275
276 frame->Raise();
277 frame->SetPosition( center - frame->GetSize() / 2 );
278
279 return;
280 }
281
282 frame->Show( !frame->IsVisible() );
283 frame->SetPosition( center - frame->GetSize() / 2 );
284}
285
286
288{
289 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
290 return frame && frame->IsVisible();
291}
292
293
295{
296 // Notify all tools the units have changed
297 if( m_toolManager )
299
303}
304
305
307{
309 {
311 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
312 }
313 else
314 {
315 SetUserUnits( GetUserUnits() == EDA_UNITS::INCHES ? EDA_UNITS::MILLIMETRES
316 : EDA_UNITS::INCHES );
318
319 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
320 ProcessEventLocally( e );
321 }
322}
323
324
325void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
326{
327 EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
328
329 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
331
332 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
333 {
334 if( GetAutoSaveInterval() > 0 )
335 {
336 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
337 }
338 else
339 {
340 m_autoSaveTimer->Stop();
341 m_autoSavePending = false;
342 }
343 }
344
345 viewControls->LoadSettings();
346
347 m_galDisplayOptions.ReadCommonConfig( *settings, this );
348
349 GetToolManager()->RunAction( ACTIONS::gridPreset, config()->m_Window.grid.last_size_idx );
351
352 if( m_lastToolbarIconSize == 0
354 {
357 }
358
359#ifndef __WXMAC__
361
362 if( m_canvasType != GetCanvas()->GetBackend() )
363 {
364 // Try to switch (will automatically fallback if necessary)
367 bool success = newGAL == m_canvasType;
368
369 if( !success )
370 {
371 m_canvasType = newGAL;
372 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
373 }
374 }
375#endif
376
377 // Notify all tools the preferences have changed
378 if( m_toolManager )
380}
381
382
384{
385 if( m_messagePanel )
387}
388
389
391{
394
395 if( m_gridSelectBox == nullptr )
396 return;
397
398 // Update grid values with the current units setting.
399 m_gridSelectBox->Clear();
400 wxArrayString gridsList;
401
402 wxCHECK( config(), /* void */ );
403
404 GRID_MENU::BuildChoiceList( &gridsList, config(), this );
405
406 for( const wxString& grid : gridsList )
407 m_gridSelectBox->Append( grid );
408
409 m_gridSelectBox->Append( wxT( "---" ) );
410 m_gridSelectBox->Append( _( "Edit Grids..." ) );
411
412 m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
413}
414
415
416void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
417{
418 // No need to update the grid select box if it doesn't exist or the grid setting change
419 // was made using the select box.
420 if( m_gridSelectBox == nullptr )
421 return;
422
423 wxCHECK( config(), /* void */ );
424
425 int idx = config()->m_Window.grid.last_size_idx;
426 idx = alg::clamp( 0, idx, (int) m_gridSelectBox->GetCount() - 1 );
427
428 if( idx != m_gridSelectBox->GetSelection() )
429 m_gridSelectBox->SetSelection( idx );
430}
431
432
433
434void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
435{
436 // No need to update the grid select box if it doesn't exist or the grid setting change
437 // was made using the select box.
438 if( m_zoomSelectBox == nullptr )
439 return;
440
441 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
442
443 wxCHECK( config(), /* void */ );
444
445 const std::vector<double>& zoomList = config()->m_Window.zoom_factors;
446 int curr_selection = m_zoomSelectBox->GetSelection();
447 int new_selection = 0; // select zoom auto
448 double last_approx = 1e9; // large value to start calculation
449
450 // Search for the nearest available value to the current zoom setting, and select it
451 for( size_t jj = 0; jj < zoomList.size(); ++jj )
452 {
453 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
454
455 if( rel_error < last_approx )
456 {
457 last_approx = rel_error;
458 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
459 new_selection = jj+1;
460 }
461 }
462
463 if( curr_selection != new_selection )
464 m_zoomSelectBox->SetSelection( new_selection );
465}
466
468{
469 DisplayErrorMessage( this, wxT("EDA_DRAW_FRAME::PrintPage() error") );
470}
471
472
473void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
474{
475 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
476
477 int idx = m_gridSelectBox->GetCurrentSelection();
478
479 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
480 {
481 // wxWidgets will check the separator, which we don't want.
482 // Re-check the current grid.
483 wxUpdateUIEvent dummy;
485 }
486 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
487 {
488 // wxWidgets will check the Grid Settings... entry, which we don't want.
489 // Re-check the current grid.
490 wxUpdateUIEvent dummy;
492
493 // Give a time-slice to close the menu before opening the dialog.
494 // (Only matters on some versions of GTK.)
495 wxSafeYield();
496
498 }
499 else
500 {
502 }
503
505 m_canvas->Refresh();
506 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
507 // (Windows specific
509}
510
511
513{
514 wxCHECK( config(), true );
515
516 return config()->m_Window.grid.show;
517}
518
519
521{
522 wxCHECK( config(), /* void */ );
523
524 config()->m_Window.grid.show = aVisible;
525
526 // Update the display with the new grid
527 if( GetCanvas() )
528 {
529 // Check to ensure these exist, since this function could be called before
530 // the GAL and View have been created
531 if( GetCanvas()->GetGAL() )
532 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
533
534 if( GetCanvas()->GetView() )
536
537 GetCanvas()->Refresh();
538 }
539}
540
541
543{
544 wxCHECK( config(), false );
545
547}
548
549
551{
552 wxCHECK( config(), /* void */ );
553
554 config()->m_Window.grid.overrides_enabled = aOverride;
555}
556
557
559{
560 if( m_zoomSelectBox == nullptr )
561 return;
562
563 double zoom = m_canvas->GetGAL()->GetZoomFactor();
564
565 m_zoomSelectBox->Clear();
566 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
567 m_zoomSelectBox->SetSelection( 0 );
568
569 wxCHECK( config(), /* void */ );
570
571 for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
572 {
573 double current = config()->m_Window.zoom_factors[i];
574
575 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
576
577 if( zoom == current )
578 m_zoomSelectBox->SetSelection( i + 1 );
579 }
580}
581
582
583void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
584{
585 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
586
587 int id = m_zoomSelectBox->GetCurrentSelection();
588
589 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
590 return;
591
594 m_canvas->Refresh();
595 // Needed on Windows because clicking on m_zoomSelectBox remove the focus from m_canvas
596 // (Windows specific
598}
599
600
601void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
602{
603 // If the window is moved to a different display, the scaling factor may change
604 double oldFactor = m_galDisplayOptions.m_scaleFactor;
606
607 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
608 {
609 wxSize clientSize = GetClientSize();
610 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
612 }
613
614 aEvent.Skip();
615}
616
617
619{
621 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
622
623 aMenu.AddSeparator( 1000 );
624
625 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
626 zoomMenu->SetTool( commonTools );
627 aToolMenu.RegisterSubMenu( zoomMenu );
628
629 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
630 gridMenu->SetTool( commonTools );
631 aToolMenu.RegisterSubMenu( gridMenu );
632
633 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
634 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
635}
636
637
638void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
639{
640 SetStatusText( msg, 6 );
641}
642
643
644void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
645{
646 SetStatusText( msg, 7 );
647}
648
649
651{
652 wxString msg;
653
656
657 msg.Printf( _( "grid %s" ),
658 gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
659
660 SetStatusText( msg, 4 );
661}
662
663
665{
666 wxString msg;
667
668 switch( GetUserUnits() )
669 {
670 case EDA_UNITS::INCHES: msg = _( "inches" ); break;
671 case EDA_UNITS::MILS: msg = _( "mils" ); break;
672 case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
673 default: msg = _( "Units" ); break;
674 }
675
676 SetStatusText( msg, 5 );
677}
678
679
680void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
681{
682 EDA_BASE_FRAME::OnSize( SizeEv );
683
684 m_frameSize = GetClientSize( );
685
686 SizeEv.Skip();
687}
688
689
691{
692 SetStatusText( GetZoomLevelIndicator(), 1 );
693
694 // Absolute and relative cursor positions are handled by overloading this function and
695 // handling the internal to user units conversion at the appropriate level.
696
697 // refresh units display
699}
700
701
703{
704 // returns a human readable value which can be displayed as zoom
705 // level indicator in dialogs.
706 double zoom = m_canvas->GetGAL()->GetZoomFactor();
707 return wxString::Format( wxT( "Z %.2f" ), zoom );
708}
709
710
712{
714
716 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
717
718 // Read units used in dialogs and toolbars
719 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
720
722
723 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
724
725 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
726 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
727 m_findReplaceData->matchMode =
728 static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
729 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
730 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
731
732 for( const wxString& s : aCfg->m_FindReplace.find_history )
734
735 for( const wxString& s : aCfg->m_FindReplace.replace_history )
737
739}
740
741
743{
745
746 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
747
748 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
750
752
753 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
754
755 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
756 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
757
758 aCfg->m_FindReplace.find_history.clear();
759 aCfg->m_FindReplace.replace_history.clear();
760
761 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
762 {
763 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
764 }
765
766 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
767 {
768 aCfg->m_FindReplace.replace_history.push_back(
769 m_replaceStringHistoryList[ i ].ToStdString() );
770 }
771
772 // Save the units used in this frame
773 if( m_toolManager )
774 {
776 {
777 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
778 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
779 }
780 }
781}
782
783
784void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
785 int aPadding )
786{
788 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
789}
790
791
793{
796}
797
798
799void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
800{
802 {
804
805 for( const MSG_PANEL_ITEM& item : aList )
807 }
808}
809
810
811void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
812 int aPadding )
813{
815 {
817 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
818 }
819}
820
821
823{
824 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
825
826 std::vector<MSG_PANEL_ITEM> items;
827 aItem->GetMsgPanelInfo( this, items );
828 SetMsgPanel( items );
829}
830
831
833{
834}
835
836
838{
839 GetCanvas()->SetEvtHandlerEnabled( true );
841}
842
843
845{
846 GetCanvas()->SwitchBackend( aCanvasType );
848
850}
851
852
854{
855#ifdef __WXMAC__
856 // Cairo renderer doesn't handle Retina displays so there's really only one game
857 // in town for Mac
859#endif
860
862 APP_SETTINGS_BASE* cfg = aCfg ? aCfg : Kiface().KifaceSettings();
863
864 if( cfg )
865 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
866
867 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
868 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
869 {
870 wxASSERT( false );
872 }
873
874 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
875 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
877
878 return canvasType;
879}
880
881
883{
884 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
885 // have a fixed type, or do not have a option to set the canvas type (they inherit from
886 // a parent frame)
887 static std::vector<FRAME_T> s_allowedFrames =
888 {
893 };
894
895 if( !alg::contains( s_allowedFrames, m_ident ) )
896 return false;
897
898 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
899 || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
900 {
901 wxASSERT( false );
902 return false;
903 }
904
905 if( APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings() )
906 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
907
908 return false;
909}
910
911
913{
914 const VECTOR2I& gridOrigin = GetGridOrigin();
915 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
916
917 double xOffset = fmod( gridOrigin.x, gridSize.x );
918 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
919 double yOffset = fmod( gridOrigin.y, gridSize.y );
920 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
921
922 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
923}
924
925
927{
928 const VECTOR2I& gridOrigin = GetGridOrigin();
929 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
930
931 double xOffset = fmod( gridOrigin.x, gridSize.x );
932 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
933 double yOffset = fmod( gridOrigin.y, gridSize.y );
934 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
935
936 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
937}
938
939
940const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
941{
942 return BOX2I();
943}
944
945
947{
948 // To be implemented by subclasses.
949}
950
951
952void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
953{
955}
956
957
958// Find the first child dialog.
959std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
960{
961 std::vector<wxWindow*> dialogs;
962
963 for( wxWindow* window : GetChildren() )
964 {
965 if( dynamic_cast<DIALOG_SHIM*>( window ) )
966 dialogs.push_back( window );
967 }
968
969 return dialogs;
970}
971
972
974{
975 bool centerView = false;
977
978 // Center if we're off the current view, or within 10% of its edge
979 r.Inflate( - (int) r.GetWidth() / 10 );
980
981 if( !r.Contains( aPos ) )
982 centerView = true;
983
984 std::vector<BOX2D> dialogScreenRects;
985
986 for( wxWindow* dialog : findDialogs() )
987 {
988 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
989 ToVECTOR2D( dialog->GetSize() ) );
990 }
991
992 // Center if we're behind an obscuring dialog, or within 10% of its edge
993 for( BOX2D rect : dialogScreenRects )
994 {
995 rect.Inflate( rect.GetWidth() / 10 );
996
997 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
998 centerView = true;
999 }
1000
1001 if( centerView )
1002 {
1003 try
1004 {
1005 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1006 }
1007 catch( const ClipperLib::clipperException& exc )
1008 {
1009 wxLogError( wxT( "Clipper library error '%s' occurred centering object." ),
1010 exc.what() );
1011 }
1012 }
1013
1015}
1016
1017
1018static const wxString productName = wxT( "KiCad E.D.A. " );
1019
1020
1021void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1022 const wxString& aSheetName, const wxString& aSheetPath,
1023 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1024 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1025 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1026 const wxString& aSheetLayer, bool aIsFirstPage )
1027{
1028 DS_DRAW_ITEM_LIST drawList( unityScale );
1029
1030 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1031 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1032 drawList.SetPageNumber( aPageNumber );
1033 drawList.SetSheetCount( aSheetCount );
1034 drawList.SetFileName( aFileName );
1035 drawList.SetSheetName( aSheetName );
1036 drawList.SetSheetPath( aSheetPath );
1037 drawList.SetSheetLayer( aSheetLayer );
1038 drawList.SetProject( aProject );
1039 drawList.SetIsFirstPage( aIsFirstPage );
1040 drawList.SetProperties( aProperties );
1041
1042 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1043
1044 // Draw item list
1045 drawList.Print( aSettings );
1046}
1047
1048
1050 const std::map<wxString, wxString>* aProperties,
1051 double aMils2Iu, const wxString &aFilename,
1052 const wxString &aSheetLayer )
1053{
1055 return;
1056
1057 wxDC* DC = aSettings->GetPrintDC();
1058 wxPoint origin = DC->GetDeviceOrigin();
1059
1060 if( origin.y > 0 )
1061 {
1062 DC->SetDeviceOrigin( 0, 0 );
1063 DC->SetAxisOrientation( true, false );
1064 }
1065
1067 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1068 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1069 aScreen->GetVirtualPageNumber() == 1 );
1070
1071 if( origin.y > 0 )
1072 {
1073 DC->SetDeviceOrigin( origin.x, origin.y );
1074 DC->SetAxisOrientation( true, true );
1075 }
1076}
1077
1078
1080{
1081 // Virtual function. Base class implementation returns an empty string.
1082 return wxEmptyString;
1083}
1084
1085
1087{
1088 // Virtual function. Base class implementation returns an empty string.
1089 return wxEmptyString;
1090}
1091
1092
1093bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
1094 const wxString& wildcard, const wxString& ext,
1095 bool isDirectory, bool aIsGlobal,
1096 const wxString& aGlobalPath )
1097{
1098 wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
1099 aFilename.SetExt( ext );
1100
1101 wxString projectDir = Prj().IsNullProject() ? aFilename.GetPath() : Prj().GetProjectPath();
1102 wxString defaultDir;
1103
1104 if( aIsGlobal )
1105 {
1106 if( !GetMruPath().IsEmpty() && !GetMruPath().StartsWith( projectDir ) )
1107 defaultDir = GetMruPath();
1108 else
1109 defaultDir = aGlobalPath;
1110 }
1111 else
1112 {
1113 if( !GetMruPath().IsEmpty() && GetMruPath().StartsWith( projectDir ) )
1114 defaultDir = GetMruPath();
1115 else
1116 defaultDir = projectDir;
1117 }
1118
1119 if( isDirectory && doOpen )
1120 {
1121 wxDirDialog dlg( this, prompt, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1122
1123 if( dlg.ShowModal() == wxID_CANCEL )
1124 return false;
1125
1126 aFilename = dlg.GetPath();
1127 aFilename.SetExt( ext );
1128 }
1129 else
1130 {
1131 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1132 if( aFilename.GetName().empty() )
1133 aFilename.SetName( wxS( "Library" ) );
1134
1135 wxFileDialog dlg( this, prompt, defaultDir, aFilename.GetFullName(),
1136 wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1137 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1138
1139 if( dlg.ShowModal() == wxID_CANCEL )
1140 return false;
1141
1142 aFilename = dlg.GetPath();
1143 aFilename.SetExt( ext );
1144 }
1145
1146 SetMruPath( aFilename.GetPath() );
1147
1148 return true;
1149}
1150
1151
1153{
1154 // Rebuild all toolbars, and update the checked state of check tools
1155 if( m_mainToolBar )
1157
1158 if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
1160
1161 if( m_optionsToolBar ) // Options (typically on left edge of window)
1163
1164 if( m_auxiliaryToolBar ) // Additional tools under main toolbar
1166
1167
1168}
1169
1170
1172{
1173 if( m_mainToolBar )
1174 m_auimgr.GetPane( m_mainToolBar ).MaxSize( m_mainToolBar->GetSize() );
1175
1176 if( m_drawToolBar )
1177 m_auimgr.GetPane( m_drawToolBar ).MaxSize( m_drawToolBar->GetSize() );
1178
1179 if( m_optionsToolBar )
1180 m_auimgr.GetPane( m_optionsToolBar ).MaxSize( m_optionsToolBar->GetSize() );
1181
1182 if( m_auxiliaryToolBar )
1183 m_auimgr.GetPane( m_auxiliaryToolBar ).MaxSize( m_auxiliaryToolBar->GetSize() );
1184
1185 m_auimgr.Update();
1186}
1187
1188
1190{
1192
1193 if( m_searchPane )
1194 {
1195 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1196 search_pane_info.Caption( _( "Search" ) );
1197 }
1198
1199 if( m_propertiesPanel )
1200 {
1201 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1202 properties_pane_info.Caption( _( "Properties" ) );
1203 }
1204
1206 {
1207 wxAuiPaneInfo& net_inspector_panel_info = m_auimgr.GetPane( m_netInspectorPanel );
1208 net_inspector_panel_info.Caption( _( "Net Inspector" ) );
1209 }
1210}
1211
1212
1214{
1215 if( !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1216 return;
1217
1219}
1220
1221
1223{
1224 m_hotkeyPopup = new HOTKEY_CYCLE_POPUP( this );
1225}
1226
1227
1229{
1230 if( !m_colorSettings || aForceRefresh )
1231 {
1233
1234 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1235 }
1236
1237 return m_colorSettings;
1238}
1239
1240
1242{
1244
1245 if( cmnTool )
1246 {
1247 // Tell the tool what the units used last session
1248 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1249 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1250 }
1251
1252 // Tell the tool what units the frame is currently using
1253 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1254 {
1255 default:
1256 case EDA_UNITS::MILLIMETRES: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1257 case EDA_UNITS::INCHES: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1258 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1259 }
1260}
1261
1262
1263void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1264{
1266
1267 aPrimaryUnit = GetUserUnits();
1268 aSecondaryUnits = EDA_UNITS::MILS;
1269
1270 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1271 {
1272 if( cmnTool )
1273 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1274 else
1275 aSecondaryUnits = EDA_UNITS::MILLIMETRES;
1276 }
1277 else
1278 {
1279 if( cmnTool )
1280 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1281 else
1282 aSecondaryUnits = EDA_UNITS::MILS;
1283 }
1284}
1285
1286
1288{
1290
1291 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1292 // user preference silently:
1293
1296}
1297
1298
1299void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1300{
1301 // Force a refresh of the message panel to ensure that the text is the right color
1302 // when the window activates
1303 if( !IsIconized() )
1304 m_messagePanel->Refresh();
1305}
1306
1307
1308void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1309{
1310 handleActivateEvent( aEvent );
1311
1312 aEvent.Skip();
1313}
1314
1315
1316bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName,
1317 BITMAP_TYPE aBitmapType )
1318{
1319 bool retv = true;
1320
1321 // Make a screen copy of the canvas:
1322 wxSize image_size = GetCanvas()->GetClientSize();
1323
1324 wxClientDC dc( GetCanvas() );
1325 wxBitmap bitmap( image_size.x, image_size.y );
1326 wxMemoryDC memdc;
1327
1328 memdc.SelectObject( bitmap );
1329 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1330 memdc.SelectObject( wxNullBitmap );
1331
1332 wxImage image = bitmap.ConvertToImage();
1333
1334 wxBitmapType type = wxBITMAP_TYPE_PNG;
1335 switch( aBitmapType )
1336 {
1337 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1338 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1339 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1340 }
1341
1342 if( !image.SaveFile( aFileName, type ) )
1343 retv = false;
1344
1345 image.Destroy();
1346 return retv;
1347}
1348
1349
1351{
1352#ifdef KICAD_IPC_API
1353 // TODO: Add user control over visibility and order
1354 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1355
1356 mgr.ButtonBindings().clear();
1357
1358 std::vector<const PLUGIN_ACTION*> actions = mgr.GetActionsForScope( PluginActionScope() );
1359
1360 for( auto& action : actions )
1361 {
1362 if( !action->show_button )
1363 continue;
1364
1365 const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk()
1366 ? action->icon_dark
1367 : action->icon_light;
1368
1369 wxAuiToolBarItem* button = m_mainToolBar->AddTool( wxID_ANY, wxEmptyString, icon,
1370 action->name );
1371
1372 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
1373 wxCommandEventHandler( EDA_DRAW_FRAME::OnApiPluginInvoke ) );
1374
1375 mgr.ButtonBindings().insert( { button->GetId(), action->identifier } );
1376 }
1377#endif
1378}
1379
1380
1381void EDA_DRAW_FRAME::OnApiPluginInvoke( wxCommandEvent& aEvent )
1382{
1383#ifdef KICAD_IPC_API
1384 API_PLUGIN_MANAGER& mgr = Pgm().GetPluginManager();
1385
1386 if( mgr.ButtonBindings().count( aEvent.GetId() ) )
1387 mgr.InvokeAction( mgr.ButtonBindings().at( aEvent.GetId() ) );
1388#endif
1389}
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:887
static TOOL_ACTION gridProperties
Definition: actions.h:174
static TOOL_ACTION millimetersUnits
Definition: actions.h:180
static TOOL_ACTION updatePreferences
Definition: actions.h:207
static TOOL_ACTION gridPreset
Definition: actions.h:171
static TOOL_ACTION updateUnits
Definition: actions.h:181
static TOOL_ACTION milsUnits
Definition: actions.h:179
static TOOL_ACTION inchesUnits
Definition: actions.h:178
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
static TOOL_ACTION zoomPreset
Definition: actions.h:126
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:170
FIND_REPLACE m_FindReplace
Definition: app_settings.h:158
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:71
size_type GetWidth() const
Definition: box2.h:204
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
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:77
EDA_UNITS GetLastMetricUnits()
Definition: common_tools.h:76
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:84
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:467
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:454
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
Definition: ds_draw_item.h:444
void SetDefaultPenSize(int aPenSize)
Definition: ds_draw_item.h:461
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:449
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
Definition: ds_draw_item.h:493
void SetProperties(const std::map< wxString, wxString > *aProps)
Set properties used for text variable resolution.
Definition: ds_draw_item.h:434
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:459
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:498
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:488
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:424
virtual APP_SETTINGS_BASE * config() const
Returns 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 NonUserClose() to indicate that the user did not request the current close.
The base class for create windows for drawing purpose.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Returns bbox of document with option to not include some items.
wxArrayString m_replaceStringHistoryList
virtual void ClearMsgPanel()
Clear all messages from the message panel.
virtual void ReCreateVToolbar()
EDA_DRAW_PANEL_GAL * m_canvas
This the frame's interface to setting GAL display options.
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
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
void ScriptingConsoleEnableDisable()
Toggles 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()
Gets 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)
Changes 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)
Returns 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()
Determines the Canvas type to load (with prompt if required) and initializes m_canvasType.
static bool m_openGLFailureOccured
Has any failure occured 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)
Stores 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 PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, const std::map< wxString, wxString > *aProperties, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints 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 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
The current canvas type.
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid wxchoice.
ACTION_TOOLBAR * m_auxiliaryToolBar
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:88
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:202
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:93
void EraseMsgBox()
Definition: msgpanel.cpp:197
static int GetRequiredHeight(wxWindow *aWindow)
Return the required height (in pixels) of a EDA_MSG_PANEL.
Definition: msgpanel.cpp:62
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()
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:512
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:643
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:578
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:619
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:67
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
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:678
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
Container for project specific data.
Definition: project.h:62
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:153
virtual void UpdateData()=0
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves 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:167
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:145
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:395
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:305
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
EVT_UPDATE_UI(ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
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
@ ID_ON_GRID_SELECT
Definition: id.h:145
@ ID_ON_ZOOM_SELECT
Definition: id.h:143
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:49
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:48
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:127
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:74
T clamp(T min, T value, T max)
Definition: kicad_algo.h:205
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:1059
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
bool overrides_enabled
Definition: grid_settings.h:78
std::vector< GRID > grids
Definition: grid_settings.h:66
Stores 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.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition: vector2wx.h:40