KiCad PCB EDA Suite
Loading...
Searching...
No Matches
common_tools.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) 2014-2016 CERN
5 * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
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 <base_units.h>
28#include <gal/painter.h>
29#include <bitmaps.h>
33#include <eda_draw_frame.h>
35#include <id.h>
36#include <math/vector2wx.h>
37#include <core/kicad_algo.h>
38#include <kiface_base.h>
40#include <tool/actions.h>
41#include <tool/common_tools.h>
42#include <tool/tool_manager.h>
43#include <tool/selection_tool.h>
44#include <tool/grid_helper.h>
45#include <view/view.h>
46#include <view/view_controls.h>
47#include "macros.h"
48
49
51 TOOL_INTERACTIVE( "common.Control" ),
52 m_frame( nullptr ),
53 m_imperialUnit( EDA_UNITS::INCHES ),
54 m_metricUnit( EDA_UNITS::MILLIMETRES )
55{
56}
57
59{
60 m_frame = getEditFrame<EDA_DRAW_FRAME>();
61 m_grids.clear();
62
63 if( aReason == RESET_REASON::SHUTDOWN )
64 return;
65
68
69 for( GRID& gridDef : settings.grids )
70 {
71 double gridSizeX = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MILLIMETRES,
72 gridDef.x );
73 double gridSizeY = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MILLIMETRES,
74 gridDef.y );
75
76 m_grids.emplace_back( KiROUND<double, int>( gridSizeX ),
77 KiROUND<double, int>( gridSizeY ) );
78 }
79
80 OnGridChanged( false );
81}
82
83
85{
87 m_imperialUnit = aUnit;
88 else if( EDA_UNIT_UTILS::IsMetricUnit( aUnit ) )
89 m_metricUnit = aUnit;
90 else
91 wxASSERT_MSG( false, wxS( "Invalid unit" ) );
92}
93
94
96{
97 // Since selection tools are run permanently underneath the toolStack, this is really
98 // just a cancel of whatever other tools might be running.
99
101 return 0;
102}
103
104
105// Cursor control
107{
109 std::unique_ptr<GRID_HELPER> grid = m_frame->MakeGridHelper();
110 VECTOR2D gridSize;
111
112 if( grid )
113 gridSize = grid->GetGridSize( grid->GetSelectionGrid( m_frame->GetCurrentSelection() ) );
114 else
115 gridSize = getView()->GetGAL()->GetGridSize();
116
117 bool mirroredX = getView()->IsMirroredX();
119
120 switch( type )
121 {
123 gridSize *= 10;
126 cursor -= VECTOR2D( 0, gridSize.y );
127 break;
128
130 gridSize *= 10;
133 cursor += VECTOR2D( 0, gridSize.y );
134 break;
135
137 gridSize *= 10;
140 cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
141 break;
142
144 gridSize *= 10;
147 cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
148 break;
149
150 case ACTIONS::CURSOR_CLICK: // fall through
153 {
156 int modifiers = 0;
157
158 modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
159 modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
160 modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
161
162 if( type == ACTIONS::CURSOR_DBL_CLICK )
163 action = TA_MOUSE_DBLCLICK;
164 else if( type == ACTIONS::CURSOR_RIGHT_CLICK )
165 button = BUT_RIGHT;
166
167 TOOL_EVENT evt( TC_MOUSE, action, static_cast<int>( button | modifiers ) );
168 evt.SetParameter( type );
169 evt.SetMousePosition( getViewControls()->GetMousePosition() );
170 m_toolMgr->ProcessEvent( evt );
171
172 return 0;
173 }
174 default:
175 wxFAIL_MSG( wxS( "CursorControl(): unexpected request" ) );
176 }
177
178 getViewControls()->SetCursorPosition( cursor, true, true, type );
180
181 return 0;
182}
183
184
186{
188 KIGFX::VIEW* view = getView();
189 VECTOR2D center = view->GetCenter();
190 VECTOR2D gridSize = getView()->GetGAL()->GetGridSize() * 10;
191 bool mirroredX = view->IsMirroredX();
192
193 switch( type )
194 {
196 center -= VECTOR2D( 0, gridSize.y );
197 break;
198
200 center += VECTOR2D( 0, gridSize.y );
201 break;
202
204 center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
205 break;
206
208 center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
209 break;
210
211 default:
212 wxFAIL;
213 break;
214 }
215
216 view->SetCenter( center );
217
218 return 0;
219}
220
221
223{
225 return 0;
226}
227
228
230{
231 bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
232 return doZoomInOut( direction, true );
233}
234
235
237{
238 bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
239 return doZoomInOut( direction, false );
240}
241
242
243int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
244{
245 double zoom = getView()->GetGAL()->GetZoomFactor();
246
247 // Step must be AT LEAST 1.3
248 if( aDirection )
249 zoom *= 1.3;
250 else
251 zoom /= 1.3;
252
253 // Now look for the next closest menu step
254 std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
255 int idx;
256
257 if( aDirection )
258 {
259 for( idx = 0; idx < int( zoomList.size() ); ++idx )
260 {
261 if( zoomList[idx] >= zoom )
262 break;
263 }
264
265 if( idx >= int( zoomList.size() ) )
266 idx = (int) zoomList.size() - 1; // if we ran off the end then peg to the end
267 }
268 else
269 {
270 for( idx = int( zoomList.size() ) - 1; idx >= 0; --idx )
271 {
272 if( zoomList[idx] <= zoom )
273 break;
274 }
275
276 if( idx < 0 )
277 idx = 0; // if we ran off the end then peg to the end
278 }
279
280 // Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
281 return doZoomToPreset( idx + 1, aCenterOnCursor );
282}
283
284
286{
288
289 ctls->CenterOnCursor();
290
291 return 0;
292}
293
294
296{
297 return doZoomFit( ZOOM_FIT_ALL );
298}
299
300
302{
303 return doZoomFit( ZOOM_FIT_OBJECTS );
304}
305
306
308{
310}
311
312
314{
315 KIGFX::VIEW* view = getView();
317 EDA_DRAW_FRAME* frame = getEditFrame<EDA_DRAW_FRAME>();
318
319 BOX2I bBox = frame->GetDocumentExtents();
320 BOX2I defaultBox = canvas->GetDefaultViewBBox();
321
322 view->SetScale( 1.0 ); // The best scale will be determined later, but this initial
323 // value ensures all view parameters are up to date (especially
324 // at init time)
325 VECTOR2D screenSize = view->ToWorld( ToVECTOR2I( canvas->GetClientSize() ), false );
326
327 // Currently "Zoom to Objects" is only supported in Eeschema & Pcbnew. Support for other
328 // programs in the suite can be added as needed.
329
330 if( aFitType == ZOOM_FIT_ALL )
331 {
332 if( frame->IsType( FRAME_PCB_EDITOR ) )
333 bBox = m_frame->GetDocumentExtents( false );
334 }
335
336 if( aFitType == ZOOM_FIT_OBJECTS )
337 {
338 if( frame->IsType( FRAME_SCH ) )
339 bBox = m_frame->GetDocumentExtents( false );
340 else
341 aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors
342 }
343
344 if( aFitType == ZOOM_FIT_SELECTION )
345 {
346 SELECTION& selection = m_frame->GetCurrentSelection();
347
348 if( selection.Empty() )
349 return 0;
350
351 bBox = selection.GetBoundingBox();
352 }
353
354 // If the screen is empty then use the default view bbox
355
356 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
357 bBox = defaultBox;
358
359 VECTOR2D vsize = bBox.GetSize();
360 double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
361 fabs( vsize.y / screenSize.y ) );
362
363 // if the scale isn't finite (most likely due to an empty canvas)
364 // simply just make sure we are centered and quit out of trying to zoom to fit
365 if( !std::isfinite( scale ) )
366 {
367 view->SetCenter( VECTOR2D( 0, 0 ) );
368 canvas->Refresh();
369 return 0;
370 }
371
372 // Reserve enough margin to limit the amount of the view that might be obscured behind the
373 // infobar.
374 double margin_scale_factor = 1.04;
375
376 if( canvas->GetClientSize().y < 768 )
377 margin_scale_factor = 1.10;
378
379 if( aFitType == ZOOM_FIT_ALL )
380 {
381 // Leave a bigger margin for library editors & viewers
382
383 if( frame->IsType( FRAME_FOOTPRINT_VIEWER )
384 || frame->IsType( FRAME_SCH_VIEWER ) )
385 {
386 margin_scale_factor = 1.30;
387 }
388 else if( frame->IsType( FRAME_SCH_SYMBOL_EDITOR )
389 || frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
390 {
391 margin_scale_factor = 1.48;
392 }
393 }
394
395 view->SetScale( scale / margin_scale_factor );
396 view->SetCenter( bBox.Centre() );
397 canvas->Refresh();
398
399 return 0;
400}
401
402
404{
406}
407
409{
411}
412
413
415{
417
418 BOX2I bBox;
419
420 if( aCenterType == CENTER_TYPE::CENTER_SELECTION )
421 {
422 SELECTION& selection = m_frame->GetCurrentSelection();
423
424 // No selection: do nothing
425 if( selection.Empty() )
426 return 0;
427
428 bBox = selection.GetBoundingBox().Centre();
429 }
430 else
431 {
432 bBox = getModel<EDA_ITEM>()->ViewBBox();
433
434 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
435 bBox = canvas->GetDefaultViewBBox();
436 }
437
438 getView()->SetCenter( bBox.Centre() );
439
440 // Take scrollbars into account
441 VECTOR2D scrollbarSize = VECTOR2D( ToVECTOR2D( canvas->GetSize() - canvas->GetClientSize() ) );
442 VECTOR2D worldScrollbarSize = getView()->ToWorld( scrollbarSize, false );
443 getView()->SetCenter( getView()->GetCenter() + worldScrollbarSize / 2.0 );
444 canvas->Refresh();
445
446 return 0;
447}
448
449
451{
452 int idx = aEvent.Parameter<int>();
453 return doZoomToPreset( idx, false );
454}
455
456
457// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
458int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
459{
460 std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
461
462 if( idx == 0 ) // Zoom Auto
463 {
465 return ZoomFitScreen( dummy );
466 }
467 else
468 {
469 idx--;
470 }
471
472 double scale = zoomList[idx];
473
474 if( aCenterOnCursor )
475 {
476 getView()->SetScale( scale, getViewControls()->GetCursorPosition() );
477
478 if( getViewControls()->IsCursorWarpingEnabled() )
480 }
481 else
482 {
483 getView()->SetScale( scale );
484 }
485
487
488 return 0;
489}
490
491
492// Grid control
494{
495 int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
496
497 currentGrid++;
498
499 if( currentGrid >= int( m_grids.size() ) )
500 currentGrid = 0;
501
502 return OnGridChanged( true );
503}
504
505
507{
508 int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
509
510 currentGrid--;
511
512 if( currentGrid < 0 )
513 currentGrid = (int) m_grids.size() - 1;
514
515 return OnGridChanged( true );
516}
517
518
520{
521 return GridPreset( aEvent.Parameter<int>(), false );
522}
523
524
525int COMMON_TOOLS::GridPreset( int idx, bool aFromHotkey )
526{
527 int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
528
529 currentGrid = std::clamp( idx, 0, (int) m_grids.size() - 1 );
530
531 return OnGridChanged( aFromHotkey );
532}
533
534
535int COMMON_TOOLS::OnGridChanged( bool aFromHotkey )
536{
537 int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
538
539 currentGrid = std::max( 0, std::min( currentGrid, static_cast<int>( m_grids.size() ) - 1 ) );
540
541 // Update the combobox (if any)
542 wxUpdateUIEvent dummy;
544
545 // Update GAL canvas from screen
546 getView()->GetGAL()->SetGridSize( m_grids[ currentGrid ] );
549
550 // Put cursor on new grid
551 VECTOR2D gridCursor = getViewControls()->GetCursorPosition( true );
552 getViewControls()->SetCrossHairCursorPosition( gridCursor, false );
553
554 // Show feedback
555 if( aFromHotkey )
557
558 return 0;
559}
560
561
563{
564 return GridPreset( m_frame->config()->m_Window.grid.fast_grid_1, true );
565}
566
567
569{
570 return GridPreset( m_frame->config()->m_Window.grid.fast_grid_2, true );
571}
572
573
575{
578 {
579 return GridPreset( m_frame->config()->m_Window.grid.fast_grid_2, true );
580 }
581
582 return GridPreset( m_frame->config()->m_Window.grid.fast_grid_1, true );
583}
584
585
587{
589 return 0;
590}
591
592
594{
596 return 0;
597}
598
599
601{
602 auto showGridPrefs =
603 [this]( const wxString& aParentName )
604 {
605 m_frame->CallAfter(
606 [this, aParentName]()
607 {
608 m_frame->ShowPreferences( _( "Grids" ), aParentName );
609 } );
610 };
611
612 switch( m_frame->GetFrameType() )
613 {
614 case FRAME_SCH: showGridPrefs( _( "Schematic Editor" ) ); break;
615 case FRAME_SCH_SYMBOL_EDITOR: showGridPrefs( _( "Symbol Editor" ) ); break;
616 case FRAME_PCB_EDITOR: showGridPrefs( _( "PCB Editor" ) ); break;
617 case FRAME_FOOTPRINT_EDITOR: showGridPrefs( _( "Footprint Editor" ) ); break;
618 case FRAME_PL_EDITOR: showGridPrefs( _( "Drawing Sheet Editor" ) ); break;
619 case FRAME_GERBER: showGridPrefs( _( "Gerber Viewer" ) ); break;
620 default: wxFAIL_MSG( "Unknown frame: " + GetName() ); break;
621 }
622
623 return 0;
624}
625
626
628{
629 VECTOR2I origin = m_frame->GetGridOrigin();
630 WX_PT_ENTRY_DIALOG dlg( m_frame, _( "Grid Origin" ), _( "X:" ), _( "Y:" ), origin );
631
632 if( dlg.ShowModal() == wxID_OK )
633 {
635
639 }
640
641 return 0;
642}
643
644
646{
647 EDA_UNITS newUnit = aEvent.Parameter<EDA_UNITS>();
648
649 if( EDA_UNIT_UTILS::IsMetricUnit( newUnit ) )
650 m_metricUnit = newUnit;
651 else if( EDA_UNIT_UTILS::IsImperialUnit( newUnit ) )
652 m_imperialUnit = newUnit;
653 else
654 wxASSERT_MSG( false, wxS( "Invalid unit for the frame" ) );
655
656 m_frame->ChangeUserUnits( newUnit );
657 return 0;
658}
659
660
662{
666 return 0;
667}
668
669
671{
672 m_frame->SetStatusText( wxEmptyString );
675
676 return 0;
677}
678
679
681{
682 const KIGFX::VC_SETTINGS& vcSettings = m_toolMgr->GetCurrentToolVC();
683
684 // Use either the active tool forced cursor position or the general settings
685 if( vcSettings.m_forceCursorPosition )
687 else
689
691
692 return 0;
693}
694
695
697{
698 auto& galOpts = m_frame->GetGalDisplayOptions();
699
700 galOpts.m_forceDisplayCursor = !galOpts.m_forceDisplayCursor;
701 galOpts.WriteConfig( m_toolMgr->GetSettings()->m_Window );
702 galOpts.NotifyChanged();
703
704 return 0;
705}
706
707
709{
711
712 galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
714 galOpts.NotifyChanged();
715
716 return 0;
717}
718
719
721{
723
724 if( canvas )
725 {
727
729
730 canvas->GetView()->UpdateAllItems( KIGFX::ALL );
731 canvas->ForceRefresh();
732 }
733
734 return 0;
735}
736
737
739{
741
742 // Cursor control
751
755
756 // Pan control
761
762 // Zoom control
775
776 // Grid control
787
788 // Units and coordinates
795
796 // Misc
800}
801
802
BASE_SCREEN class implementation.
static TOOL_ACTION gridProperties
Definition: actions.h:189
static TOOL_ACTION gridFastCycle
Definition: actions.h:181
static TOOL_ACTION toggleGrid
Definition: actions.h:187
static TOOL_ACTION zoomRedraw
Definition: actions.h:124
static TOOL_ACTION millimetersUnits
Definition: actions.h:195
static TOOL_ACTION gridFast1
Definition: actions.h:179
static TOOL_ACTION gridPrev
Definition: actions.h:183
static TOOL_ACTION cursorLeft
Definition: actions.h:161
static TOOL_ACTION zoomOutCenter
Definition: actions.h:128
static TOOL_ACTION togglePolarCoords
Definition: actions.h:198
static TOOL_ACTION zoomIn
Definition: actions.h:125
static TOOL_ACTION cursorLeftFast
Definition: actions.h:166
static TOOL_ACTION gridPreset
Definition: actions.h:186
static TOOL_ACTION zoomFitSelection
Definition: actions.h:136
static TOOL_ACTION centerSelection
Definition: actions.h:142
static TOOL_ACTION cursorDown
Definition: actions.h:160
static TOOL_ACTION zoomOut
Definition: actions.h:126
static TOOL_ACTION milsUnits
Definition: actions.h:194
static TOOL_ACTION cursorRightFast
Definition: actions.h:167
static TOOL_ACTION toggleBoundingBoxes
Definition: actions.h:147
static TOOL_ACTION showContextMenu
Definition: actions.h:67
static TOOL_ACTION toggleCursor
Definition: actions.h:143
static TOOL_ACTION centerContents
Definition: actions.h:141
static TOOL_ACTION zoomCenter
Definition: actions.h:133
static TOOL_ACTION panDown
Definition: actions.h:174
static TOOL_ACTION cursorDblClick
Definition: actions.h:170
CURSOR_EVENT_TYPE
Definition: actions.h:250
@ CURSOR_DBL_CLICK
Definition: actions.h:261
@ CURSOR_RIGHT
Definition: actions.h:258
@ CURSOR_LEFT_FAST
Definition: actions.h:257
@ CURSOR_LEFT
Definition: actions.h:256
@ CURSOR_DOWN_FAST
Definition: actions.h:255
@ CURSOR_CLICK
Definition: actions.h:260
@ CURSOR_UP
Definition: actions.h:252
@ CURSOR_RIGHT_FAST
Definition: actions.h:259
@ CURSOR_DOWN
Definition: actions.h:254
@ CURSOR_UP_FAST
Definition: actions.h:253
@ CURSOR_RIGHT_CLICK
Definition: actions.h:262
static TOOL_ACTION cursorDownFast
Definition: actions.h:165
static TOOL_ACTION inchesUnits
Definition: actions.h:193
static TOOL_ACTION cursorUpFast
Definition: actions.h:164
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:144
static TOOL_ACTION gridOrigin
Definition: actions.h:190
static TOOL_ACTION panLeft
Definition: actions.h:175
static TOOL_ACTION selectionTool
Definition: actions.h:202
static TOOL_ACTION cursorClick
Definition: actions.h:169
static TOOL_ACTION zoomFitScreen
Definition: actions.h:134
static TOOL_ACTION zoomPreset
Definition: actions.h:137
static TOOL_ACTION panUp
Definition: actions.h:173
static TOOL_ACTION zoomFitObjects
Definition: actions.h:135
static TOOL_ACTION toggleUnits
Definition: actions.h:197
static TOOL_ACTION zoomInCenter
Definition: actions.h:127
static TOOL_ACTION panRight
Definition: actions.h:176
static TOOL_ACTION gridSetOrigin
Definition: actions.h:184
static TOOL_ACTION gridFast2
Definition: actions.h:180
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition: actions.h:159
static TOOL_ACTION refreshPreview
Definition: actions.h:149
static TOOL_ACTION toggleGridOverrides
Definition: actions.h:188
static TOOL_ACTION gridNext
Definition: actions.h:182
static TOOL_ACTION cursorRight
Definition: actions.h:162
static TOOL_ACTION resetLocalCoords
Definition: actions.h:199
WINDOW_SETTINGS m_Window
Definition: app_settings.h:194
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:90
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr Vec Centre() const
Definition: box2.h:97
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
int ZoomFitSelection(const TOOL_EVENT &aEvent)
int ZoomCenter(const TOOL_EVENT &aEvent)
int doCenter(CENTER_TYPE aCenterType)
int GridProperties(const TOOL_EVENT &aEvent)
int GridFastCycle(const TOOL_EVENT &aEvent)
int ToggleCursorStyle(const TOOL_EVENT &aEvent)
int GridOrigin(const TOOL_EVENT &aEvent)
int doZoomToPreset(int idx, bool aCenterOnCursor)
int PanControl(const TOOL_EVENT &aEvent)
EDA_UNITS m_metricUnit
Definition: common_tools.h:134
EDA_UNITS m_imperialUnit
Definition: common_tools.h:133
int SwitchUnits(const TOOL_EVENT &aEvent)
int ToggleGrid(const TOOL_EVENT &aEvent)
int GridFast1(const TOOL_EVENT &aEvent)
void SetLastUnits(EDA_UNITS aUnit)
int ToggleUnits(const TOOL_EVENT &aEvent)
int GridFast2(const TOOL_EVENT &aEvent)
int GridNext(const TOOL_EVENT &aEvent)
int OnGridChanged(bool aFromHotkey)
void setTransitions() override
Pointer to the currently used edit frame.
int CenterSelection(const TOOL_EVENT &aEvent)
int ZoomPreset(const TOOL_EVENT &aEvent)
int ZoomFitScreen(const TOOL_EVENT &aEvent)
int ToggleBoundingBoxes(const TOOL_EVENT &aEvent)
int ToggleGridOverrides(const TOOL_EVENT &aEvent)
std::vector< VECTOR2I > m_grids
Grids from #APP_SETTINGS converted to internal units and with the user grid appended.
Definition: common_tools.h:129
int ToggleCursor(const TOOL_EVENT &aEvent)
int ZoomFitObjects(const TOOL_EVENT &aEvent)
int CenterContents(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int TogglePolarCoords(const TOOL_EVENT &aEvent)
int GridPrev(const TOOL_EVENT &aEvent)
int ZoomInOutCenter(const TOOL_EVENT &aEvent)
int ZoomRedraw(const TOOL_EVENT &aEvent)
int ResetLocalCoords(const TOOL_EVENT &aEvent)
EDA_DRAW_FRAME * m_frame
Definition: common_tools.h:118
int doZoomFit(ZOOM_FIT_TYPE_T aFitType)
int CursorControl(const TOOL_EVENT &aEvent)
ZOOM_FIT_TYPE_T
The set of "Zoom to Fit" types that can be performed.
Definition: common_tools.h:102
@ ZOOM_FIT_SELECTION
Zoom to fit selected items in view.
Definition: common_tools.h:105
@ ZOOM_FIT_ALL
Zoom to fall all items in view INCLUDING page and border.
Definition: common_tools.h:103
@ ZOOM_FIT_OBJECTS
Zoom to fit all items in view EXCLUDING page and border.
Definition: common_tools.h:104
int SelectionTool(const TOOL_EVENT &aEvent)
int GridPreset(const TOOL_EVENT &aEvent)
int ZoomInOut(const TOOL_EVENT &aEvent)
int doZoomInOut(bool aDirection, bool aCenterOnCursor)
Note: idx == 0 is Auto; idx == 1 is first entry in zoomList.
int ShowModal() override
FRAME_T GetFrameType() const
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void ShowPreferences(wxString aStartPage, wxString aStartParentPage)
Displays the preferences and settings of all opened editors paged dialog, starting with a particular ...
void ChangeUserUnits(EDA_UNITS aUnits)
bool IsType(FRAME_T aType) const
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.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
virtual void SetGridOrigin(const VECTOR2I &aPosition)=0
bool IsGridOverridden() const
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual const VECTOR2I & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
void SetShowPolarCoords(bool aShow)
virtual void SetGridVisibility(bool aVisible)
void UpdateStatusBar() override
Update the status bar information.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
bool IsGridVisible() const
virtual std::unique_ptr< GRID_HELPER > MakeGridHelper()
virtual void SetGridOverrides(bool aOverride)
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid wxchoice.
bool GetShowPolarCoords() const
For those frames that support polar coordinates.
virtual BOX2I GetDefaultViewBBox() const
Return the bounding box of the view that should be used if model is not valid.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
static const TOOL_EVENT GridChangedByKeyEvent
Definition: actions.h:312
void WriteConfig(WINDOW_SETTINGS &aCfg)
bool m_forceDisplayCursor
The pixel scale factor (>1 for hi-DPI scaled displays)
bool m_fullscreenCursor
Force cursor display.
double GetZoomFactor() const
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
const VECTOR2D & GetGridSize() const
Return the grid size.
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDrawBoundingBoxes(bool aEnabled)
bool GetDrawBoundingBoxes() const
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const =0
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
virtual void CenterOnCursor()=0
Set the viewport center to the current cursor position and warps the cursor to the screen center.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
double GetScale() const
Definition: view.h:273
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:562
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:199
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:459
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:247
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1545
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:217
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:588
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition: view.h:636
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
virtual BOX2I GetBoundingBox() const
Definition: selection.cpp:134
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:98
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:136
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ REDRAW
Full drawing refresh.
Definition: tool_base.h:83
@ SHUTDOWN
Tool is being shut down.
Definition: tool_base.h:84
Generic, UI-independent tool event.
Definition: tool_event.h:167
void SetMousePosition(const VECTOR2D &aP)
Definition: tool_event.h:525
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition: tool_event.h:515
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
const KIGFX::VC_SETTINGS & GetCurrentToolVC() const
Return the view controls settings for the current tool or the general settings if there is no active ...
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:400
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
const EDA_IU_SCALE & GetIuScale() const
EDA_UNITS GetUserUnits() const
VECTOR2I GetValue()
Returns the value in internal units.
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_FOOTPRINT_VIEWER
Definition: frame_type.h:45
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ 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
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
Definition: eda_units.cpp:576
KICOMMON_API bool IsImperialUnit(EDA_UNITS aUnit)
Definition: eda_units.cpp:47
KICOMMON_API bool IsMetricUnit(EDA_UNITS aUnit)
Definition: eda_units.cpp:61
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:58
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:38
const int scale
std::vector< FAB_LAYER_COLOR > dummy
std::vector< GRID > grids
Definition: grid_settings.h:66
Common grid settings, available to every frame.
Definition: grid_settings.h:34
wxString y
Definition: grid_settings.h:53
wxString x
Definition: grid_settings.h:52
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:43
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:56
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:59
GRID_SETTINGS grid
Definition: app_settings.h:81
std::vector< double > zoom_factors
Definition: app_settings.h:78
TOOL_ACTIONS
Definition: tool_event.h:63
@ TA_MOUSE_CLICK
Definition: tool_event.h:66
@ TA_MOUSE_DBLCLICK
Definition: tool_event.h:67
@ TA_CANCEL_TOOL
Definition: tool_event.h:89
@ TC_COMMAND
Definition: tool_event.h:56
@ TC_MOUSE
Definition: tool_event.h:54
@ MD_ALT
Definition: tool_event.h:144
@ MD_CTRL
Definition: tool_event.h:143
@ MD_SHIFT
Definition: tool_event.h:142
TOOL_MOUSE_BUTTONS
Definition: tool_event.h:129
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition: vector2wx.h:30
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition: vector2wx.h:40