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
26#include <base_screen.h>
27#include <bitmaps.h>
28#include <confirm.h>
29#include <core/arraydim.h>
30#include <core/kicad_algo.h>
31#include <dialog_shim.h>
33#include <eda_draw_frame.h>
34#include <file_history.h>
36#include <id.h>
37#include <kiface_base.h>
38#include <lockfile.h>
39#include <macros.h>
40#include <math/vector2wx.h>
41#include <page_info.h>
42#include <paths.h>
43#include <pgm_base.h>
44#include <render_settings.h>
49#include <title_block.h>
50#include <tool/actions.h>
51#include <tool/action_toolbar.h>
52#include <tool/common_tools.h>
53#include <tool/grid_menu.h>
56#include <tool/tool_manager.h>
57#include <tool/tool_menu.h>
58#include <tool/zoom_menu.h>
59#include <trace_helpers.h>
60#include <view/view.h>
62#include <widgets/msgpanel.h>
64#include <wx/event.h>
65#include <wx/snglinst.h>
66#include <widgets/ui_common.h>
67#include <widgets/search_pane.h>
68#include <wx/dirdlg.h>
69#include <wx/filedlg.h>
70#include <wx/msgdlg.h>
71#include <wx/socket.h>
72
73#include <wx/snglinst.h>
74#include <wx/fdrepdlg.h>
75
76#define FR_HISTORY_LIST_CNT 10
77
78
79BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
82
83 EVT_ACTIVATE( EDA_DRAW_FRAME::onActivate )
84END_EVENT_TABLE()
85
86
87bool EDA_DRAW_FRAME::m_openGLFailureOccured = false;
88
89
90EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
91 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
92 long aStyle, const wxString& aFrameName,
93 const EDA_IU_SCALE& aIuScale ) :
94 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName, aIuScale ),
95 m_socketServer( nullptr ),
96 m_lastToolbarIconSize( 0 )
97{
98 m_mainToolBar = nullptr;
99 m_drawToolBar = nullptr;
100 m_optionsToolBar = nullptr;
101 m_auxiliaryToolBar = nullptr;
102 m_gridSelectBox = nullptr;
103 m_zoomSelectBox = nullptr;
104 m_searchPane = nullptr;
105 m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
106
108 m_canvas = nullptr;
109 m_toolDispatcher = nullptr;
110 m_messagePanel = nullptr;
111 m_currentScreen = nullptr;
112 m_showBorderAndTitleBlock = false; // true to display reference sheet.
113 m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
114 m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
115 // BLACK for Pcbnew, BLACK or WHITE for Eeschema
116 m_colorSettings = nullptr;
117 m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this );
118 m_polarCoords = false;
119 m_findReplaceData = std::make_unique<EDA_SEARCH_DATA>();
120 m_hotkeyPopup = nullptr;
121 m_propertiesPanel = nullptr;
122
123 SetUserUnits( EDA_UNITS::MILLIMETRES );
124
125 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
126
127 if( ( aStyle & wxFRAME_NO_TASKBAR ) == 0 )
128 {
129 CreateStatusBar( 8 )->SetDoubleBuffered( true );
130
131 // set the size of the status bar subwindows:
132
133 wxWindow* stsbar = GetStatusBar();
134 int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
135
136 int dims[] =
137 {
138 // remainder of status bar on far left is set to a default or whatever is left over.
139 -1,
140
141 // When using GetTextSize() remember the width of character '1' is not the same
142 // as the width of '0' unless the font is fixed width, and it usually won't be.
143
144 // zoom:
145 KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x,
146
147 // cursor coords
148 KIUI::GetTextSize( wxT( "X 1234.1234 Y 1234.1234" ), stsbar ).x,
149
150 // delta distances
151 KIUI::GetTextSize( wxT( "dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x,
152
153 // grid size
154 KIUI::GetTextSize( wxT( "grid X 1234.1234 Y 1234.1234" ), stsbar ).x,
155
156 // units display, Inches is bigger than mm
157 KIUI::GetTextSize( _( "Inches" ), stsbar ).x,
158
159 // Size for the "Current Tool" panel; longest string from SetTool()
160 KIUI::GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x,
161
162 // constraint mode
163 KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x
164 };
165
166 for( size_t ii = 1; ii < arrayDim( dims ); ii++ )
167 dims[ii] += spacer;
168
169 SetStatusWidths( arrayDim( dims ), dims );
170 stsbar->SetFont( KIUI::GetStatusFont( this ) );
171 }
172
173 // Create child subwindows.
174 GetClientSize( &m_frameSize.x, &m_frameSize.y );
175 m_framePos.x = m_framePos.y = 0;
176 m_frameSize.y -= m_msgFrameHeight;
177
178 m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_frameSize.y ),
179 wxSize( m_frameSize.x, m_msgFrameHeight ) );
180
181 m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
182
183 Bind( wxEVT_DPI_CHANGED,
184 [&]( wxDPIChangedEvent& )
185 {
186 wxMoveEvent dummy;
187 OnMove( dummy );
188
189 // we need to kludge the msg panel to the correct size again
190 // especially important even for first launches as the constructor of the window
191 // here usually doesn't have the correct dpi awareness yet
192 m_frameSize.y += m_msgFrameHeight;
193 m_msgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight( this );
194 m_frameSize.y -= m_msgFrameHeight;
195
196 m_messagePanel->SetPosition( wxPoint( 0, m_frameSize.y ) );
197 m_messagePanel->SetSize( m_frameSize.x, m_msgFrameHeight );
198 } );
199}
200
201
203{
205
206 delete m_actions;
207 delete m_toolManager;
208 delete m_toolDispatcher;
209 delete m_canvas;
210
211 delete m_currentScreen;
212 m_currentScreen = nullptr;
213
214 m_auimgr.UnInit();
215
216 ReleaseFile();
217}
218
219
221{
222 if( m_file_checker.get() != nullptr )
223 m_file_checker->UnlockFile();
224}
225
226
227bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
228{
229 // We need to explicitly reset here to get the deletion before
230 // we create a new unique_ptr that may be for the same file
231 m_file_checker.reset();
232
233 m_file_checker = std::make_unique<LOCKFILE>( aFileName );
234
235 if( !m_file_checker->Valid() && m_file_checker->IsLockedByMe() )
236 {
237 // If we cannot acquire the lock but we appear to be the one who
238 // locked it, check to see if there is another KiCad instance running.
239 // If there is not, then we can override the lock. This could happen if
240 // KiCad crashed or was interrupted
241 if( !Pgm().SingleInstance()->IsAnotherRunning() )
242 m_file_checker->OverrideLock();
243 }
244 // If the file is valid, return true. This could mean that the file is
245 // locked or it could mean that the file is read-only
246 return m_file_checker->Valid();
247}
248
249
251{
252 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
253
254 wxRect rect = GetScreenRect();
255 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
256
257 if( !frame )
258 {
259 frame = Kiway().Player( FRAME_PYTHON, true, Kiway().GetTop() );
260
261 // If we received an error in the CTOR due to Python-ness, don't crash
262 if( !frame )
263 return;
264
265 if( !frame->IsVisible() )
266 frame->Show( true );
267
268 // On Windows, Raise() does not bring the window on screen, when iconized
269 if( frame->IsIconized() )
270 frame->Iconize( false );
271
272 frame->Raise();
273 frame->SetPosition( center - frame->GetSize() / 2 );
274
275 return;
276 }
277
278 frame->Show( !frame->IsVisible() );
279 frame->SetPosition( center - frame->GetSize() / 2 );
280}
281
282
284{
285 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PYTHON, false );
286 return frame && frame->IsVisible();
287}
288
289
291{
292 // Notify all tools the units have changed
293 if( m_toolManager )
295
299}
300
301
303{
305 {
307 m_toolManager->GetTool<COMMON_TOOLS>()->ToggleUnits( dummy );
308 }
309 else
310 {
311 SetUserUnits( GetUserUnits() == EDA_UNITS::INCHES ? EDA_UNITS::MILLIMETRES
312 : EDA_UNITS::INCHES );
314
315 wxCommandEvent e( EDA_EVT_UNITS_CHANGED );
316 ProcessEventLocally( e );
317 }
318}
319
320
321void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
322{
323 EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
324
325 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
327
328 if( m_supportsAutoSave && m_autoSaveTimer->IsRunning() )
329 {
330 if( GetAutoSaveInterval() > 0 )
331 {
332 m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
333 }
334 else
335 {
336 m_autoSaveTimer->Stop();
337 m_autoSavePending = false;
338 }
339 }
340
341 viewControls->LoadSettings();
342
343 m_galDisplayOptions.ReadCommonConfig( *settings, this );
344
345 GetToolManager()->RunAction( ACTIONS::gridPreset, config()->m_Window.grid.last_size_idx );
347
348 if( m_lastToolbarIconSize == 0
350 {
353 }
354
355#ifndef __WXMAC__
357
358 if( m_canvasType != GetCanvas()->GetBackend() )
359 {
360 // Try to switch (will automatically fallback if necessary)
363 bool success = newGAL == m_canvasType;
364
365 if( !success )
366 {
367 m_canvasType = newGAL;
368 m_openGLFailureOccured = true; // Store failure for other EDA_DRAW_FRAMEs
369 }
370 }
371#endif
372
373 // Notify all tools the preferences have changed
374 if( m_toolManager )
376}
377
378
380{
381 if( m_messagePanel )
383}
384
385
387{
390
391 if( m_gridSelectBox == nullptr )
392 return;
393
394 // Update grid values with the current units setting.
395 m_gridSelectBox->Clear();
396 wxArrayString gridsList;
397
398 wxCHECK( config(), /* void */ );
399
400 GRID_MENU::BuildChoiceList( &gridsList, config(), this );
401
402 for( const wxString& grid : gridsList )
403 m_gridSelectBox->Append( grid );
404
405 m_gridSelectBox->Append( wxT( "---" ) );
406 m_gridSelectBox->Append( _( "Edit Grids..." ) );
407
408 m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx );
409}
410
411
412void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
413{
414 // No need to update the grid select box if it doesn't exist or the grid setting change
415 // was made using the select box.
416 if( m_gridSelectBox == nullptr )
417 return;
418
419 wxCHECK( config(), /* void */ );
420
421 int idx = config()->m_Window.grid.last_size_idx;
422 idx = alg::clamp( 0, idx, (int) m_gridSelectBox->GetCount() - 1 );
423
424 if( idx != m_gridSelectBox->GetSelection() )
425 m_gridSelectBox->SetSelection( idx );
426}
427
428
429
430void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
431{
432 // No need to update the grid select box if it doesn't exist or the grid setting change
433 // was made using the select box.
434 if( m_zoomSelectBox == nullptr )
435 return;
436
437 double zoom = GetCanvas()->GetGAL()->GetZoomFactor();
438
439 wxCHECK( config(), /* void */ );
440
441 const std::vector<double>& zoomList = config()->m_Window.zoom_factors;
442 int curr_selection = m_zoomSelectBox->GetSelection();
443 int new_selection = 0; // select zoom auto
444 double last_approx = 1e9; // large value to start calculation
445
446 // Search for the nearest available value to the current zoom setting, and select it
447 for( size_t jj = 0; jj < zoomList.size(); ++jj )
448 {
449 double rel_error = std::fabs( zoomList[jj] - zoom ) / zoom;
450
451 if( rel_error < last_approx )
452 {
453 last_approx = rel_error;
454 // zoom IDs in m_zoomSelectBox start with 1 (leaving 0 for auto-zoom choice)
455 new_selection = jj+1;
456 }
457 }
458
459 if( curr_selection != new_selection )
460 m_zoomSelectBox->SetSelection( new_selection );
461}
462
464{
465 DisplayErrorMessage( this, wxT("EDA_DRAW_FRAME::PrintPage() error") );
466}
467
468
469void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
470{
471 wxCHECK_RET( m_gridSelectBox, wxS( "m_gridSelectBox uninitialized" ) );
472
473 int idx = m_gridSelectBox->GetCurrentSelection();
474
475 if( idx == int( m_gridSelectBox->GetCount() ) - 2 )
476 {
477 // wxWidgets will check the separator, which we don't want.
478 // Re-check the current grid.
479 wxUpdateUIEvent dummy;
481 }
482 else if( idx == int( m_gridSelectBox->GetCount() ) - 1 )
483 {
484 // wxWidgets will check the Grid Settings... entry, which we don't want.
485 // Re-check the current grid.
486 wxUpdateUIEvent dummy;
488
489 // Give a time-slice to close the menu before opening the dialog.
490 // (Only matters on some versions of GTK.)
491 wxSafeYield();
492
494 }
495 else
496 {
498 }
499
501 m_canvas->Refresh();
502 // Needed on Windows because clicking on m_gridSelectBox remove the focus from m_canvas
503 // (Windows specific
505}
506
507
509{
510 wxCHECK( config(), true );
511
512 return config()->m_Window.grid.show;
513}
514
515
517{
518 wxCHECK( config(), /* void */ );
519
520 config()->m_Window.grid.show = aVisible;
521
522 // Update the display with the new grid
523 if( GetCanvas() )
524 {
525 // Check to ensure these exist, since this function could be called before
526 // the GAL and View have been created
527 if( GetCanvas()->GetGAL() )
528 GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
529
530 if( GetCanvas()->GetView() )
532
533 GetCanvas()->Refresh();
534 }
535}
536
537
539{
540 wxCHECK( config(), false );
541
543}
544
545
547{
548 wxCHECK( config(), /* void */ );
549
550 config()->m_Window.grid.overrides_enabled = aOverride;
551}
552
553
555{
556 if( m_zoomSelectBox == nullptr )
557 return;
558
559 double zoom = m_canvas->GetGAL()->GetZoomFactor();
560
561 m_zoomSelectBox->Clear();
562 m_zoomSelectBox->Append( _( "Zoom Auto" ) );
563 m_zoomSelectBox->SetSelection( 0 );
564
565 wxCHECK( config(), /* void */ );
566
567 for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
568 {
569 double current = config()->m_Window.zoom_factors[i];
570
571 m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
572
573 if( zoom == current )
574 m_zoomSelectBox->SetSelection( i + 1 );
575 }
576}
577
578
579void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
580{
581 wxCHECK_RET( m_zoomSelectBox, wxS( "m_zoomSelectBox uninitialized" ) );
582
583 int id = m_zoomSelectBox->GetCurrentSelection();
584
585 if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
586 return;
587
590 m_canvas->Refresh();
591 // Needed on Windows because clicking on m_zoomSelectBox remove the focus from m_canvas
592 // (Windows specific
594}
595
596
597void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
598{
599 // If the window is moved to a different display, the scaling factor may change
600 double oldFactor = m_galDisplayOptions.m_scaleFactor;
602
603 if( oldFactor != m_galDisplayOptions.m_scaleFactor && m_canvas )
604 {
605 wxSize clientSize = GetClientSize();
606 GetCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y );
608 }
609
610 aEvent.Skip();
611}
612
613
615{
617 CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
618
619 aMenu.AddSeparator( 1000 );
620
621 std::shared_ptr<ZOOM_MENU> zoomMenu = std::make_shared<ZOOM_MENU>( this );
622 zoomMenu->SetTool( commonTools );
623 aToolMenu.RegisterSubMenu( zoomMenu );
624
625 std::shared_ptr<GRID_MENU> gridMenu = std::make_shared<GRID_MENU>( this );
626 gridMenu->SetTool( commonTools );
627 aToolMenu.RegisterSubMenu( gridMenu );
628
629 aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
630 aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
631}
632
633
634void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
635{
636 SetStatusText( msg, 6 );
637}
638
639
640void EDA_DRAW_FRAME::DisplayConstraintsMsg( const wxString& msg )
641{
642 SetStatusText( msg, 7 );
643}
644
645
647{
648 wxString msg;
649
652
653 msg.Printf( _( "grid %s" ),
654 gridSettings.grids[currentIdx].UserUnitsMessageText( this, false ) );
655
656 SetStatusText( msg, 4 );
657}
658
659
661{
662 wxString msg;
663
664 switch( GetUserUnits() )
665 {
666 case EDA_UNITS::INCHES: msg = _( "inches" ); break;
667 case EDA_UNITS::MILS: msg = _( "mils" ); break;
668 case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
669 default: msg = _( "Units" ); break;
670 }
671
672 SetStatusText( msg, 5 );
673}
674
675
676void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
677{
678 EDA_BASE_FRAME::OnSize( SizeEv );
679
680 m_frameSize = GetClientSize( );
681
682 SizeEv.Skip();
683}
684
685
687{
688 SetStatusText( GetZoomLevelIndicator(), 1 );
689
690 // Absolute and relative cursor positions are handled by overloading this function and
691 // handling the internal to user units conversion at the appropriate level.
692
693 // refresh units display
695}
696
697
699{
700 // returns a human readable value which can be displayed as zoom
701 // level indicator in dialogs.
702 double zoom = m_canvas->GetGAL()->GetZoomFactor();
703 return wxString::Format( wxT( "Z %.2f" ), zoom );
704}
705
706
708{
710
711 COMMON_SETTINGS* cmnCfg = Pgm().GetCommonSettings();
712 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
713
714 // Read units used in dialogs and toolbars
715 SetUserUnits( static_cast<EDA_UNITS>( aCfg->m_System.units ) );
716
718
719 m_galDisplayOptions.ReadConfig( *cmnCfg, *window, this );
720
721 m_findReplaceData->findString = aCfg->m_FindReplace.find_string;
722 m_findReplaceData->replaceString = aCfg->m_FindReplace.replace_string;
723 m_findReplaceData->matchMode =
724 static_cast<EDA_SEARCH_MATCH_MODE>( aCfg->m_FindReplace.match_mode );
725 m_findReplaceData->matchCase = aCfg->m_FindReplace.match_case;
726 m_findReplaceData->searchAndReplace = aCfg->m_FindReplace.search_and_replace;
727
728 for( const wxString& s : aCfg->m_FindReplace.find_history )
730
731 for( const wxString& s : aCfg->m_FindReplace.replace_history )
733
735}
736
737
739{
741
742 WINDOW_SETTINGS* window = GetWindowSettings( aCfg );
743
744 aCfg->m_System.units = static_cast<int>( GetUserUnits() );
746
748
749 aCfg->m_FindReplace.search_and_replace = m_findReplaceData->searchAndReplace;
750
751 aCfg->m_FindReplace.find_string = m_findReplaceData->findString;
752 aCfg->m_FindReplace.replace_string = m_findReplaceData->replaceString;
753
754 aCfg->m_FindReplace.find_history.clear();
755 aCfg->m_FindReplace.replace_history.clear();
756
757 for( size_t i = 0; i < m_findStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
758 {
759 aCfg->m_FindReplace.find_history.push_back( m_findStringHistoryList[ i ].ToStdString() );
760 }
761
762 for( size_t i = 0; i < m_replaceStringHistoryList.GetCount() && i < FR_HISTORY_LIST_CNT; i++ )
763 {
764 aCfg->m_FindReplace.replace_history.push_back(
765 m_replaceStringHistoryList[ i ].ToStdString() );
766 }
767
768 // Save the units used in this frame
769 if( m_toolManager )
770 {
772 {
773 aCfg->m_System.last_imperial_units = static_cast<int>( cmnTool->GetLastImperialUnits() );
774 aCfg->m_System.last_metric_units = static_cast<int>( cmnTool->GetLastMetricUnits() );
775 }
776 }
777}
778
779
780void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
781 int aPadding )
782{
784 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
785}
786
787
789{
792}
793
794
795void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
796{
798 {
800
801 for( const MSG_PANEL_ITEM& item : aList )
803 }
804}
805
806
807void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
808 int aPadding )
809{
811 {
813 m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
814 }
815}
816
817
819{
820 wxCHECK_RET( aItem, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
821
822 std::vector<MSG_PANEL_ITEM> items;
823 aItem->GetMsgPanelInfo( this, items );
824 SetMsgPanel( items );
825}
826
827
829{
830}
831
832
834{
835 GetCanvas()->SetEvtHandlerEnabled( true );
837}
838
839
841{
842 GetCanvas()->SwitchBackend( aCanvasType );
844
846}
847
848
850{
851#ifdef __WXMAC__
852 // Cairo renderer doesn't handle Retina displays so there's really only one game
853 // in town for Mac
855#endif
856
858 APP_SETTINGS_BASE* cfg = aCfg ? aCfg : Kiface().KifaceSettings();
859
860 if( cfg )
861 canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
862
863 if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
864 || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
865 {
866 wxASSERT( false );
868 }
869
870 // Legacy canvas no longer supported. Switch to OpenGL, falls back to Cairo on failure
871 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
873
874 return canvasType;
875}
876
877
879{
880 // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
881 // have a fixed type, or do not have a option to set the canvas type (they inherit from
882 // a parent frame)
883 static std::vector<FRAME_T> s_allowedFrames =
884 {
889 };
890
891 if( !alg::contains( s_allowedFrames, m_ident ) )
892 return false;
893
894 if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
895 || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
896 {
897 wxASSERT( false );
898 return false;
899 }
900
901 if( APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings() )
902 cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
903
904 return false;
905}
906
907
909{
910 const VECTOR2I& gridOrigin = GetGridOrigin();
911 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
912
913 double xOffset = fmod( gridOrigin.x, gridSize.x );
914 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
915 double yOffset = fmod( gridOrigin.y, gridSize.y );
916 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
917
918 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
919}
920
921
923{
924 const VECTOR2I& gridOrigin = GetGridOrigin();
925 VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
926
927 double xOffset = fmod( gridOrigin.x, gridSize.x );
928 int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
929 double yOffset = fmod( gridOrigin.y, gridSize.y );
930 int y = KiROUND( (aPosition.y - yOffset) / gridSize.y );
931
932 return VECTOR2I( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) );
933}
934
935
936const BOX2I EDA_DRAW_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
937{
938 return BOX2I();
939}
940
941
943{
944 // To be implemented by subclasses.
945}
946
947
948void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
949{
951}
952
953
954// Find the first child dialog.
955std::vector<wxWindow*> EDA_DRAW_FRAME::findDialogs()
956{
957 std::vector<wxWindow*> dialogs;
958
959 for( wxWindow* window : GetChildren() )
960 {
961 if( dynamic_cast<DIALOG_SHIM*>( window ) )
962 dialogs.push_back( window );
963 }
964
965 return dialogs;
966}
967
968
970{
971 bool centerView = false;
973
974 // Center if we're off the current view, or within 10% of its edge
975 r.Inflate( - (int) r.GetWidth() / 10 );
976
977 if( !r.Contains( aPos ) )
978 centerView = true;
979
980 std::vector<BOX2D> dialogScreenRects;
981
982 for( wxWindow* dialog : findDialogs() )
983 {
984 dialogScreenRects.emplace_back( ToVECTOR2D( GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ) ),
985 ToVECTOR2D( dialog->GetSize() ) );
986 }
987
988 // Center if we're behind an obscuring dialog, or within 10% of its edge
989 for( BOX2D rect : dialogScreenRects )
990 {
991 rect.Inflate( rect.GetWidth() / 10 );
992
993 if( rect.Contains( GetCanvas()->GetView()->ToScreen( aPos ) ) )
994 centerView = true;
995 }
996
997 if( centerView )
998 {
999 try
1000 {
1001 GetCanvas()->GetView()->SetCenter( aPos, dialogScreenRects );
1002 }
1003 catch( const ClipperLib::clipperException& exc )
1004 {
1005 wxLogError( wxT( "Clipper library error '%s' occurred centering object." ),
1006 exc.what() );
1007 }
1008 }
1009
1011}
1012
1013
1014static const wxString productName = wxT( "KiCad E.D.A. " );
1015
1016
1017void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
1018 const wxString& aSheetName, const wxString& aSheetPath,
1019 const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
1020 const std::map<wxString, wxString>* aProperties, int aSheetCount,
1021 const wxString& aPageNumber, double aMils2Iu, const PROJECT* aProject,
1022 const wxString& aSheetLayer, bool aIsFirstPage )
1023{
1024 DS_DRAW_ITEM_LIST drawList( unityScale );
1025
1026 drawList.SetDefaultPenSize( aSettings->GetDefaultPenWidth() );
1027 drawList.SetPlotterMilsToIUfactor( aMils2Iu );
1028 drawList.SetPageNumber( aPageNumber );
1029 drawList.SetSheetCount( aSheetCount );
1030 drawList.SetFileName( aFileName );
1031 drawList.SetSheetName( aSheetName );
1032 drawList.SetSheetPath( aSheetPath );
1033 drawList.SetSheetLayer( aSheetLayer );
1034 drawList.SetProject( aProject );
1035 drawList.SetIsFirstPage( aIsFirstPage );
1036 drawList.SetProperties( aProperties );
1037
1038 drawList.BuildDrawItemsList( aPageInfo, aTitleBlock );
1039
1040 // Draw item list
1041 drawList.Print( aSettings );
1042}
1043
1044
1046 const std::map<wxString, wxString>* aProperties,
1047 double aMils2Iu, const wxString &aFilename,
1048 const wxString &aSheetLayer )
1049{
1051 return;
1052
1053 wxDC* DC = aSettings->GetPrintDC();
1054 wxPoint origin = DC->GetDeviceOrigin();
1055
1056 if( origin.y > 0 )
1057 {
1058 DC->SetDeviceOrigin( 0, 0 );
1059 DC->SetAxisOrientation( true, false );
1060 }
1061
1063 aFilename, GetTitleBlock(), aProperties, aScreen->GetPageCount(),
1064 aScreen->GetPageNumber(), aMils2Iu, &Prj(), aSheetLayer,
1065 aScreen->GetVirtualPageNumber() == 1 );
1066
1067 if( origin.y > 0 )
1068 {
1069 DC->SetDeviceOrigin( origin.x, origin.y );
1070 DC->SetAxisOrientation( true, true );
1071 }
1072}
1073
1074
1076{
1077 // Virtual function. Base class implementation returns an empty string.
1078 return wxEmptyString;
1079}
1080
1081
1083{
1084 // Virtual function. Base class implementation returns an empty string.
1085 return wxEmptyString;
1086}
1087
1088
1089bool EDA_DRAW_FRAME::LibraryFileBrowser( bool doOpen, wxFileName& aFilename,
1090 const wxString& wildcard, const wxString& ext,
1091 bool isDirectory, bool aIsGlobal,
1092 const wxString& aGlobalPath )
1093{
1094 wxString prompt = doOpen ? _( "Select Library" ) : _( "New Library" );
1095 aFilename.SetExt( ext );
1096
1097 wxString projectDir = Prj().IsNullProject() ? aFilename.GetPath() : Prj().GetProjectPath();
1098 wxString defaultDir;
1099
1100 if( aIsGlobal )
1101 {
1102 if( !GetMruPath().IsEmpty() && !GetMruPath().StartsWith( projectDir ) )
1103 defaultDir = GetMruPath();
1104 else
1105 defaultDir = aGlobalPath;
1106 }
1107 else
1108 {
1109 if( !GetMruPath().IsEmpty() && GetMruPath().StartsWith( projectDir ) )
1110 defaultDir = GetMruPath();
1111 else
1112 defaultDir = projectDir;
1113 }
1114
1115 if( isDirectory && doOpen )
1116 {
1117 wxDirDialog dlg( this, prompt, defaultDir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
1118
1119 if( dlg.ShowModal() == wxID_CANCEL )
1120 return false;
1121
1122 aFilename = dlg.GetPath();
1123 aFilename.SetExt( ext );
1124 }
1125 else
1126 {
1127 // Ensure the file has a dummy name, otherwise GTK will display the regex from the filter
1128 if( aFilename.GetName().empty() )
1129 aFilename.SetName( wxS( "Library" ) );
1130
1131 wxFileDialog dlg( this, prompt, defaultDir, aFilename.GetFullName(),
1132 wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1133 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1134
1135 if( dlg.ShowModal() == wxID_CANCEL )
1136 return false;
1137
1138 aFilename = dlg.GetPath();
1139 aFilename.SetExt( ext );
1140 }
1141
1142 SetMruPath( aFilename.GetPath() );
1143
1144 return true;
1145}
1146
1147
1149{
1150 // Rebuild all toolbars, and update the checked state of check tools
1151 if( m_mainToolBar )
1153
1154 if( m_drawToolBar ) // Drawing tools (typically on right edge of window)
1156
1157 if( m_optionsToolBar ) // Options (typically on left edge of window)
1159
1160 if( m_auxiliaryToolBar ) // Additional tools under main toolbar
1162
1163
1164}
1165
1166
1168{
1169 if( m_mainToolBar )
1170 m_auimgr.GetPane( m_mainToolBar ).MaxSize( m_mainToolBar->GetSize() );
1171
1172 if( m_drawToolBar )
1173 m_auimgr.GetPane( m_drawToolBar ).MaxSize( m_drawToolBar->GetSize() );
1174
1175 if( m_optionsToolBar )
1176 m_auimgr.GetPane( m_optionsToolBar ).MaxSize( m_optionsToolBar->GetSize() );
1177
1178 if( m_auxiliaryToolBar )
1179 m_auimgr.GetPane( m_auxiliaryToolBar ).MaxSize( m_auxiliaryToolBar->GetSize() );
1180
1181 m_auimgr.Update();
1182}
1183
1184
1186{
1188
1189 if( m_searchPane )
1190 {
1191 wxAuiPaneInfo& search_pane_info = m_auimgr.GetPane( m_searchPane );
1192 search_pane_info.Caption( _( "Search" ) );
1193 }
1194
1195 if( m_propertiesPanel )
1196 {
1197 wxAuiPaneInfo& properties_pane_info = m_auimgr.GetPane( m_propertiesPanel );
1198 properties_pane_info.Caption( _( "Properties" ) );
1199 }
1200}
1201
1202
1204{
1205 if( !m_propertiesPanel || !m_propertiesPanel->IsShownOnScreen() )
1206 return;
1207
1209}
1210
1211
1213{
1214 m_hotkeyPopup = new HOTKEY_CYCLE_POPUP( this );
1215}
1216
1217
1219{
1220 if( !m_colorSettings || aForceRefresh )
1221 {
1222 COLOR_SETTINGS* colorSettings = Pgm().GetSettingsManager().GetColorSettings();
1223
1224 const_cast<EDA_DRAW_FRAME*>( this )->m_colorSettings = colorSettings;
1225 }
1226
1227 return m_colorSettings;
1228}
1229
1230
1232{
1234
1235 if( cmnTool )
1236 {
1237 // Tell the tool what the units used last session
1238 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_imperial_units ) );
1239 cmnTool->SetLastUnits( static_cast<EDA_UNITS>( aCfg->m_System.last_metric_units ) );
1240 }
1241
1242 // Tell the tool what units the frame is currently using
1243 switch( static_cast<EDA_UNITS>( aCfg->m_System.units ) )
1244 {
1245 default:
1246 case EDA_UNITS::MILLIMETRES: m_toolManager->RunAction( ACTIONS::millimetersUnits ); break;
1247 case EDA_UNITS::INCHES: m_toolManager->RunAction( ACTIONS::inchesUnits ); break;
1248 case EDA_UNITS::MILS: m_toolManager->RunAction( ACTIONS::milsUnits ); break;
1249 }
1250}
1251
1252
1253void EDA_DRAW_FRAME::GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits )
1254{
1256
1257 aPrimaryUnit = GetUserUnits();
1258 aSecondaryUnits = EDA_UNITS::MILS;
1259
1260 if( EDA_UNIT_UTILS::IsImperialUnit( aPrimaryUnit ) )
1261 {
1262 if( cmnTool )
1263 aSecondaryUnits = cmnTool->GetLastMetricUnits();
1264 else
1265 aSecondaryUnits = EDA_UNITS::MILLIMETRES;
1266 }
1267 else
1268 {
1269 if( cmnTool )
1270 aSecondaryUnits = cmnTool->GetLastImperialUnits();
1271 else
1272 aSecondaryUnits = EDA_UNITS::MILS;
1273 }
1274}
1275
1276
1278{
1280
1281 // If we had an OpenGL failure this session, use the fallback GAL but don't update the
1282 // user preference silently:
1283
1286}
1287
1288
1289void EDA_DRAW_FRAME::handleActivateEvent( wxActivateEvent& aEvent )
1290{
1291 // Force a refresh of the message panel to ensure that the text is the right color
1292 // when the window activates
1293 if( !IsIconized() )
1294 m_messagePanel->Refresh();
1295}
1296
1297
1298void EDA_DRAW_FRAME::onActivate( wxActivateEvent& aEvent )
1299{
1300 handleActivateEvent( aEvent );
1301
1302 aEvent.Skip();
1303}
1304
1305
1306bool EDA_DRAW_FRAME::SaveCanvasImageToFile( const wxString& aFileName,
1307 BITMAP_TYPE aBitmapType )
1308{
1309 bool retv = true;
1310
1311 // Make a screen copy of the canvas:
1312 wxSize image_size = GetCanvas()->GetClientSize();
1313
1314 wxClientDC dc( GetCanvas() );
1315 wxBitmap bitmap( image_size.x, image_size.y );
1316 wxMemoryDC memdc;
1317
1318 memdc.SelectObject( bitmap );
1319 memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
1320 memdc.SelectObject( wxNullBitmap );
1321
1322 wxImage image = bitmap.ConvertToImage();
1323
1324 wxBitmapType type = wxBITMAP_TYPE_PNG;
1325 switch( aBitmapType )
1326 {
1327 case BITMAP_TYPE::PNG: type = wxBITMAP_TYPE_PNG; break;
1328 case BITMAP_TYPE::BMP: type = wxBITMAP_TYPE_BMP; break;
1329 case BITMAP_TYPE::JPG: type = wxBITMAP_TYPE_JPEG; break;
1330 }
1331
1332 if( !image.SaveFile( aFileName, type ) )
1333 retv = false;
1334
1335 image.Destroy();
1336 return retv;
1337}
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:112
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
BITMAP_TYPE
Definition: bitmap_types.h:41
BOX2< VECTOR2I > BOX2I
Definition: box2.h:853
static TOOL_ACTION gridProperties
Definition: actions.h:170
static TOOL_ACTION millimetersUnits
Definition: actions.h:176
static TOOL_ACTION updatePreferences
Definition: actions.h:203
static TOOL_ACTION gridPreset
Definition: actions.h:167
static TOOL_ACTION updateUnits
Definition: actions.h:177
static TOOL_ACTION milsUnits
Definition: actions.h:175
static TOOL_ACTION inchesUnits
Definition: actions.h:174
static TOOL_ACTION zoomFitScreen
Definition: actions.h:120
static TOOL_ACTION zoomPreset
Definition: actions.h:122
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
coord_type GetWidth() const
Definition: box2.h:188
bool Contains(const Vec &aPoint) const
Definition: box2.h:142
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
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:83
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.
virtual void SetGridVisibility(bool aVisible)
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
virtual void ReCreateOptToolbar()
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
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
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:85
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:199
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:53
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:432
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
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).
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:387
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:31
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:127
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
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition: vector2wx.h:40