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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <base_screen.h>
23#include <base_units.h>
24#include <gal/painter.h>
25#include <bitmaps.h>
29#include <eda_draw_frame.h>
31#include <id.h>
32#include <math/vector2wx.h>
33#include <core/kicad_algo.h>
34#include <kiface_base.h>
36#include <tool/actions.h>
37#include <tool/common_tools.h>
38#include <tool/tool_manager.h>
39#include <tool/selection_tool.h>
40#include <tool/grid_helper.h>
41#include <view/view.h>
42#include <view/view_controls.h>
43#include "macros.h"
44
45
47 TOOL_INTERACTIVE( "common.Control" ),
48 m_frame( nullptr ),
51{
52}
53
54
56{
58 m_grids.clear();
59
60 if( aReason == RESET_REASON::SHUTDOWN )
61 return;
62
63 GRID_SETTINGS& settings = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid;
64
65 // Protect against misconfigured settings with no grids
66 if( settings.grids.empty() )
67 settings.grids = m_frame->config()->DefaultGridSizeList();
68
69 EDA_IU_SCALE scale = m_frame->GetIuScale();
70
71 for( GRID& gridDef : settings.grids )
72 {
73 double gridSizeX = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MM, gridDef.x );
74 double gridSizeY = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MM, gridDef.y );
75
76 m_grids.emplace_back( KiROUND<double, int>( gridSizeX ), KiROUND<double, int>( gridSizeY ) );
77 }
78
79 OnGridChanged( false );
80}
81
82
84{
86 m_imperialUnit = aUnit;
87 else if( EDA_UNIT_UTILS::IsMetricUnit( aUnit ) )
88 m_metricUnit = aUnit;
89 else
90 wxASSERT_MSG( false, wxS( "Invalid unit" ) );
91}
92
93
95{
96 // Since selection tools are run permanently underneath the toolStack, this is really
97 // just a cancel of whatever other tools might be running.
98
99 m_toolMgr->ProcessEvent( TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL ) );
100 return 0;
101}
102
103
105{
107 std::unique_ptr<GRID_HELPER> grid = m_frame->MakeGridHelper();
108 VECTOR2D gridSize;
109
110 if( grid )
111 gridSize = grid->GetGridSize( grid->GetSelectionGrid( m_frame->GetCurrentSelection() ) );
112 else
113 gridSize = getView()->GetGAL()->GetGridSize();
114
115 bool mirroredX = getView()->IsMirroredX();
117
118 SELECTION& selection = m_frame->GetCurrentSelection();
119
120 if( !getViewControls()->GetSettings().m_lastKeyboardCursorPositionValid && selection.HasReferencePoint() )
121 {
122 cursor = selection.GetReferencePoint();
123 }
124
125 switch( type )
126 {
128 gridSize *= 10;
131 cursor -= VECTOR2D( 0, gridSize.y );
132 break;
133
135 gridSize *= 10;
138 cursor += VECTOR2D( 0, gridSize.y );
139 break;
140
142 gridSize *= 10;
145 cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
146 break;
147
149 gridSize *= 10;
152 cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
153 break;
154
155 case ACTIONS::CURSOR_CLICK: // fall through
158 {
161 int modifiers = 0;
162
163 modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
164 modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
165 modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
166
167 if( type == ACTIONS::CURSOR_DBL_CLICK )
168 action = TA_MOUSE_DBLCLICK;
169 else if( type == ACTIONS::CURSOR_RIGHT_CLICK )
170 button = BUT_RIGHT;
171
172 TOOL_EVENT evt( TC_MOUSE, action, static_cast<int>( button | modifiers ) );
173 evt.SetParameter( type );
174 evt.SetMousePosition( getViewControls()->GetMousePosition() );
175 m_toolMgr->ProcessEvent( evt );
176
177 return 0;
178 }
179 default:
180 wxFAIL_MSG( wxS( "CursorControl(): unexpected request" ) );
181 }
182
183 getViewControls()->SetCursorPosition( cursor, true, true, type );
184 m_toolMgr->PostAction( ACTIONS::refreshPreview );
185
186 return 0;
187}
188
189
191{
193 KIGFX::VIEW* view = getView();
194 VECTOR2D center = view->GetCenter();
195 VECTOR2D gridSize = getView()->GetGAL()->GetGridSize() * 10;
196 bool mirroredX = view->IsMirroredX();
197
198 switch( type )
199 {
201 center -= VECTOR2D( 0, gridSize.y );
202 break;
203
205 center += VECTOR2D( 0, gridSize.y );
206 break;
207
209 center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
210 break;
211
213 center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
214 break;
215
216 default:
217 wxFAIL;
218 break;
219 }
220
221 view->SetCenter( center );
222
223 return 0;
224}
225
226
228{
229 m_frame->HardRedraw();
230 return 0;
231}
232
233
235{
236 bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
237 return doZoomInOut( direction, true );
238}
239
240
242{
243 bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
244 return doZoomInOut( direction, false );
245}
246
247
248int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
249{
250 double zoom = getView()->GetGAL()->GetZoomFactor();
251
252 // Step must be AT LEAST 1.3
253 if( aDirection )
254 zoom *= 1.3;
255 else
256 zoom /= 1.3;
257
258 // Now look for the next closest menu step
259 std::vector<double>& zoomList = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->zoom_factors;
260 int idx;
261
262 if( aDirection )
263 {
264 for( idx = 0; idx < int( zoomList.size() ); ++idx )
265 {
266 if( zoomList[idx] >= zoom )
267 break;
268 }
269
270 if( idx >= int( zoomList.size() ) )
271 idx = (int) zoomList.size() - 1; // if we ran off the end then peg to the end
272 }
273 else
274 {
275 for( idx = int( zoomList.size() ) - 1; idx >= 0; --idx )
276 {
277 if( zoomList[idx] <= zoom )
278 break;
279 }
280
281 if( idx < 0 )
282 idx = 0; // if we ran off the end then peg to the end
283 }
284
285 // Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
286 return doZoomToPreset( idx + 1, aCenterOnCursor );
287}
288
289
291{
293
294 ctls->CenterOnCursor();
295
296 return 0;
297}
298
299
301{
302 return doZoomFit( ZOOM_FIT_ALL );
303}
304
305
307{
308 return doZoomFit( ZOOM_FIT_OBJECTS );
309}
310
311
313{
315}
316
317
319{
321 BOX2I bBox = frame->GetDocumentExtents();
322
323 // Currently "Zoom to Objects" is only supported in Eeschema & Pcbnew. Support for other
324 // programs in the suite can be added as needed.
325
326 if( aFitType == ZOOM_FIT_ALL )
327 {
328 if( frame->IsType( FRAME_PCB_EDITOR ) )
329 bBox = m_frame->GetDocumentExtents( false );
330 }
331
332 if( aFitType == ZOOM_FIT_OBJECTS )
333 {
334 if( frame->IsType( FRAME_SCH ) )
335 bBox = m_frame->GetDocumentExtents( false );
336 else
337 aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors
338 }
339
340 if( aFitType == ZOOM_FIT_SELECTION )
341 {
342 SELECTION& selection = m_frame->GetCurrentSelection();
343
344 if( selection.Empty() )
345 return 0;
346
347 bBox = selection.GetBoundingBox();
348 }
349
350 std::optional<double> marginScale;
351
352 if( aFitType == ZOOM_FIT_ALL )
353 {
354 // Leave a bigger margin for library editors & viewers
355
356 if( frame->IsType( FRAME_FOOTPRINT_VIEWER )
357 || frame->IsType( FRAME_SCH_VIEWER ) )
358 {
359 marginScale = 1.30;
360 }
361 else if( frame->IsType( FRAME_SCH_SYMBOL_EDITOR )
362 || frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
363 {
364 marginScale = 1.48;
365 }
366 }
367
368 return ZoomFitBox( bBox, marginScale );
369}
370
371
372int COMMON_TOOLS::ZoomFitBox( const BOX2I& aBox, std::optional<double> aMarginScale )
373{
374 KIGFX::VIEW* view = getView();
375 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
376 BOX2I bBox = aBox;
377
378 view->SetScale( 1.0 ); // The best scale will be determined later, but this initial
379 // value ensures all view parameters are up to date (especially
380 // at init time)
381 VECTOR2D screenSize = view->ToWorld( ToVECTOR2I( canvas->GetClientSize() ), false );
382
383 // A box with no extent (an empty screen or a lone point) has nothing to fit
384 if( bBox.GetWidth() == 0 && bBox.GetHeight() == 0 )
385 bBox = canvas->GetDefaultViewBBox();
386
387 VECTOR2D vsize = bBox.GetSize();
388 double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
389 fabs( vsize.y / screenSize.y ) );
390
391 // if the scale isn't finite (most likely due to an empty canvas)
392 // simply just make sure we are centered and quit out of trying to zoom to fit
393 if( !std::isfinite( scale ) )
394 {
395 view->SetCenter( VECTOR2D( 0, 0 ) );
396 canvas->Refresh();
397 return 0;
398 }
399
400 // Reserve enough margin to limit the amount of the view that might be obscured behind the
401 // infobar.
402 double margin_scale_factor = aMarginScale.value_or( canvas->GetClientSize().y < 768 ? 1.10 : 1.04 );
403
404 view->SetScale( scale / margin_scale_factor );
405 view->SetCenter( bBox.Centre() );
406 canvas->Refresh();
407
408 return 0;
409}
410
411
416
417
422
423
425{
426 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
427
428 BOX2I bBox;
429
430 if( aCenterType == CENTER_TYPE::CENTER_SELECTION )
431 {
432 SELECTION& selection = m_frame->GetCurrentSelection();
433
434 // No selection: do nothing
435 if( selection.Empty() )
436 return 0;
437
438 bBox = selection.GetBoundingBox().Centre();
439 }
440 else
441 {
442 bBox = getModel<EDA_ITEM>()->ViewBBox();
443
444 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
445 bBox = canvas->GetDefaultViewBBox();
446 }
447
448 getView()->SetCenter( bBox.Centre() );
449
450 // Take scrollbars into account
451 VECTOR2D scrollbarSize = VECTOR2D( ToVECTOR2D( canvas->GetSize() - canvas->GetClientSize() ) );
452 VECTOR2D worldScrollbarSize = getView()->ToWorld( scrollbarSize, false );
453 getView()->SetCenter( getView()->GetCenter() + worldScrollbarSize / 2.0 );
454 canvas->Refresh();
455
456 return 0;
457}
458
459
461{
462 int idx = aEvent.Parameter<int>();
463 return doZoomToPreset( idx, false );
464}
465
466
467// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
468int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
469{
470 std::vector<double>& zoomList = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->zoom_factors;
471
472 if( idx == 0 ) // Zoom Auto
473 {
475 return ZoomFitScreen( dummy );
476 }
477 else
478 {
479 idx--;
480 }
481
482 double scale = zoomList[idx];
483
484 if( aCenterOnCursor )
485 {
486 getView()->SetScale( scale, getViewControls()->GetCursorPosition() );
487
488 if( getViewControls()->IsCursorWarpingEnabled() )
490 }
491 else
492 {
493 getView()->SetScale( scale );
494 }
495
496 m_frame->GetCanvas()->Refresh();
497
498 return 0;
499}
500
501
503{
504 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
505
506 currentGrid++;
507
508 if( currentGrid >= int( m_grids.size() ) )
509 currentGrid = 0;
510
511 return OnGridChanged( true );
512}
513
514
516{
517 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
518
519 currentGrid--;
520
521 if( currentGrid < 0 )
522 currentGrid = (int) m_grids.size() - 1;
523
524 return OnGridChanged( true );
525}
526
527
529{
530 return GridPreset( aEvent.Parameter<int>(), false );
531}
532
533
534int COMMON_TOOLS::GridPreset( int idx, bool aFromHotkey )
535{
536 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
537
538 currentGrid = std::clamp( idx, 0, (int) m_grids.size() - 1 );
539
540 return OnGridChanged( aFromHotkey );
541}
542
543
544int COMMON_TOOLS::OnGridChanged( bool aFromHotkey )
545{
546 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
547
548 currentGrid = std::max( 0, std::min( currentGrid, static_cast<int>( m_grids.size() ) - 1 ) );
549
550 // Update the combobox (if any)
551 wxUpdateUIEvent dummy;
552 m_frame->OnUpdateSelectGrid( dummy );
553
554 // Update GAL canvas from screen
555 getView()->GetGAL()->SetGridSize( m_grids[ currentGrid ] );
556 getView()->GetGAL()->SetGridVisibility( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.show );
558
559 // Put cursor on new grid
560 VECTOR2D gridCursor = getViewControls()->GetCursorPosition( true );
561 getViewControls()->SetCrossHairCursorPosition( gridCursor, false );
562
563 // Show feedback
564 if( aFromHotkey )
566
567 return 0;
568}
569
570
572{
573 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1, true );
574}
575
576
578{
579 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_2, true );
580}
581
582
584{
585 if( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx
586 == m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1 )
587 {
588 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_2, true );
589 }
590
591 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1, true );
592}
593
594
596{
597 m_frame->SetGridVisibility( !m_frame->IsGridVisible() );
598 return 0;
599}
600
601
603{
604 m_frame->SetGridOverrides( !m_frame->IsGridOverridden() );
605 return 0;
606}
607
608
610{
611 auto showGridPrefs =
612 [this]( const wxString& aParentName )
613 {
614 m_frame->CallAfter(
615 [this, aParentName]()
616 {
617 m_frame->ShowPreferences( _( "Grids" ), aParentName );
618 } );
619 };
620
621 switch( m_frame->GetFrameType() )
622 {
623 case FRAME_SCH: showGridPrefs( _( "Schematic Editor" ) ); break;
624 case FRAME_SCH_SYMBOL_EDITOR: showGridPrefs( _( "Symbol Editor" ) ); break;
625 case FRAME_PCB_EDITOR: showGridPrefs( _( "PCB Editor" ) ); break;
626 case FRAME_FOOTPRINT_EDITOR: showGridPrefs( _( "Footprint Editor" ) ); break;
627 case FRAME_FOOTPRINT_VIEWER: showGridPrefs( _( "Footprint Browser" ) ); break;
628 case FRAME_PL_EDITOR: showGridPrefs( _( "Drawing Sheet Editor" ) ); break;
629 case FRAME_GERBER: showGridPrefs( _( "Gerber Viewer" ) ); break;
630 default: wxFAIL_MSG( "Unknown frame: " + GetName() ); break;
631 }
632
633 return 0;
634}
635
636
638{
639 VECTOR2I origin = m_frame->GetGridOrigin();
640 WX_PT_ENTRY_DIALOG dlg( m_frame, _( "Grid Origin" ), _( "X:" ), _( "Y:" ), origin, true );
641
642 if( dlg.ShowModal() == wxID_OK )
643 {
644 m_frame->SetGridOrigin( dlg.GetValue() );
645
646 m_toolMgr->ResetTools( TOOL_BASE::REDRAW );
647 m_toolMgr->RunAction( ACTIONS::gridSetOrigin, new VECTOR2D( m_frame->GetGridOrigin() ) );
648 m_frame->GetCanvas()->ForceRefresh();
649 }
650
651 return 0;
652}
653
654
656{
657 EDA_UNITS newUnit = aEvent.Parameter<EDA_UNITS>();
658
659 if( EDA_UNIT_UTILS::IsMetricUnit( newUnit ) )
660 m_metricUnit = newUnit;
661 else if( EDA_UNIT_UTILS::IsImperialUnit( newUnit ) )
662 m_imperialUnit = newUnit;
663 else
664 wxASSERT_MSG( false, wxS( "Invalid unit for the frame" ) );
665
666 m_frame->ChangeUserUnits( newUnit );
667 return 0;
668}
669
670
672{
673 m_frame->ChangeUserUnits( EDA_UNIT_UTILS::IsImperialUnit( m_frame->GetUserUnits() ) ?
676 return 0;
677}
678
679
681{
682 m_frame->SetStatusText( wxEmptyString );
683 m_frame->SetShowPolarCoords( !m_frame->GetShowPolarCoords() );
684 m_frame->UpdateStatusBar();
685
686 return 0;
687}
688
689
691{
692 if( !m_frame->GetScreen() ) // Can happen in footprint chooser frame
693 return 0;
694
695 const KIGFX::VC_SETTINGS& vcSettings = m_toolMgr->GetCurrentToolVC();
696
697 // Use either the active tool forced cursor position or the general settings
698 if( vcSettings.m_forceCursorPosition )
699 m_frame->GetScreen()->m_LocalOrigin = vcSettings.m_forcedPosition;
700 else
701 m_frame->GetScreen()->m_LocalOrigin = getViewControls()->GetCursorPosition();
702
703 m_frame->UpdateStatusBar();
704
705 return 0;
706}
707
708
710{
711 auto& galOpts = m_frame->GetGalDisplayOptions();
712
713 galOpts.m_forceDisplayCursor = !galOpts.m_forceDisplayCursor;
714 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
715 galOpts.NotifyChanged();
716
717 return 0;
718}
719
720
722{
723 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
724
726 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
727 galOpts.NotifyChanged();
728
729 return 0;
730}
731
732
734{
735 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
736
738 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
739 galOpts.NotifyChanged();
740
741 return 0;
742}
743
744
746{
747 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
748
750 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
751 galOpts.NotifyChanged();
752
753 return 0;
754}
755
756
758{
759 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
760
761 if( canvas )
762 {
764
766
767 canvas->GetView()->UpdateAllItems( KIGFX::ALL );
768 canvas->ForceRefresh();
769 }
770
771 return 0;
772}
773
774
776{
778
779 // Cursor control
788
792
793 // Pan control
798
799 // Zoom control
812
813 // Grid control
824
825 // Units and coordinates
832
833 // Misc
839}
BASE_SCREEN class implementation.
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:982
static TOOL_ACTION gridProperties
Definition actions.h:196
static TOOL_ACTION gridFastCycle
Definition actions.h:188
static TOOL_ACTION toggleGrid
Definition actions.h:194
static TOOL_ACTION zoomRedraw
Definition actions.h:128
static TOOL_ACTION millimetersUnits
Definition actions.h:202
static TOOL_ACTION gridFast1
Definition actions.h:186
static TOOL_ACTION gridPrev
Definition actions.h:190
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:148
static TOOL_ACTION cursorLeft
Definition actions.h:168
static TOOL_ACTION zoomOutCenter
Definition actions.h:132
static TOOL_ACTION togglePolarCoords
Definition actions.h:205
static TOOL_ACTION zoomIn
Definition actions.h:129
static TOOL_ACTION cursorLeftFast
Definition actions.h:173
static TOOL_ACTION gridPreset
Definition actions.h:193
static TOOL_ACTION zoomFitSelection
Definition actions.h:140
static TOOL_ACTION centerSelection
Definition actions.h:146
static TOOL_ACTION cursorDown
Definition actions.h:167
static TOOL_ACTION zoomOut
Definition actions.h:130
static TOOL_ACTION milsUnits
Definition actions.h:201
static TOOL_ACTION cursorRightFast
Definition actions.h:174
static TOOL_ACTION toggleBoundingBoxes
Definition actions.h:153
static TOOL_ACTION showContextMenu
Definition actions.h:70
static TOOL_ACTION toggleCursor
Definition actions.h:147
static TOOL_ACTION centerContents
Definition actions.h:145
static TOOL_ACTION zoomCenter
Definition actions.h:137
static TOOL_ACTION panDown
Definition actions.h:181
static TOOL_ACTION cursorDblClick
Definition actions.h:177
CURSOR_EVENT_TYPE
Cursor control event types.
Definition actions.h:303
@ CURSOR_DBL_CLICK
Definition actions.h:314
@ CURSOR_RIGHT
Definition actions.h:311
@ CURSOR_LEFT_FAST
Definition actions.h:310
@ CURSOR_LEFT
Definition actions.h:309
@ CURSOR_DOWN_FAST
Definition actions.h:308
@ CURSOR_CLICK
Definition actions.h:313
@ CURSOR_UP
Definition actions.h:305
@ CURSOR_RIGHT_FAST
Definition actions.h:312
@ CURSOR_DOWN
Definition actions.h:307
@ CURSOR_UP_FAST
Definition actions.h:306
@ CURSOR_RIGHT_CLICK
Definition actions.h:315
static TOOL_ACTION cursorDownFast
Definition actions.h:172
static TOOL_ACTION inchesUnits
Definition actions.h:200
static TOOL_ACTION cursorUpFast
Definition actions.h:171
static TOOL_ACTION gridOrigin
Definition actions.h:197
static TOOL_ACTION panLeft
Definition actions.h:182
static TOOL_ACTION selectionTool
Definition actions.h:247
static TOOL_ACTION cursorClick
Definition actions.h:176
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
static TOOL_ACTION zoomPreset
Definition actions.h:141
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:150
static TOOL_ACTION panUp
Definition actions.h:180
static TOOL_ACTION zoomFitObjects
Definition actions.h:139
static TOOL_ACTION toggleUnits
Definition actions.h:204
static TOOL_ACTION zoomInCenter
Definition actions.h:131
static TOOL_ACTION panRight
Definition actions.h:183
static TOOL_ACTION gridSetOrigin
Definition actions.h:191
static TOOL_ACTION gridFast2
Definition actions.h:187
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition actions.h:166
static TOOL_ACTION refreshPreview
Definition actions.h:155
static TOOL_ACTION toggleGridOverrides
Definition actions.h:195
static TOOL_ACTION gridNext
Definition actions.h:189
static TOOL_ACTION cursorRight
Definition actions.h:169
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:149
static TOOL_ACTION resetLocalCoords
Definition actions.h:206
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr Vec Centre() const
Definition box2.h:94
constexpr size_type GetHeight() const
Definition box2.h:212
constexpr const SizeVec & GetSize() const
Definition box2.h:203
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 GridOrigin(const TOOL_EVENT &aEvent)
int doZoomToPreset(int idx, bool aCenterOnCursor)
Note: idx == 0 is Auto; idx == 1 is first entry in zoomList.
int PanControl(const TOOL_EVENT &aEvent)
EDA_UNITS m_metricUnit
EDA_UNITS m_imperialUnit
int SwitchUnits(const TOOL_EVENT &aEvent)
int CursorSmallCrosshairs(const TOOL_EVENT &aEvent)
int ToggleGrid(const TOOL_EVENT &aEvent)
int GridFast1(const TOOL_EVENT &aEvent)
int Cursor45Crosshairs(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
Sets up handlers for various events.
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_BASE converted to internal units and with the user grid appended.
int ToggleCursor(const TOOL_EVENT &aEvent)
int CursorFullCrosshairs(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
Pointer to the currently used edit frame.
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.
@ ZOOM_FIT_SELECTION
Zoom to fit selected items in view.
@ ZOOM_FIT_ALL
Zoom to fall all items in view INCLUDING page and border.
@ ZOOM_FIT_OBJECTS
Zoom to fit all items in view EXCLUDING page and border.
int ZoomFitBox(const BOX2I &aBox, std::optional< double > aMarginScale=std::nullopt)
Zoom and center the view so that aBox fills it, keeping the same margin the "Zoom to Selection" actio...
int SelectionTool(const TOOL_EVENT &aEvent)
int GridPreset(const TOOL_EVENT &aEvent)
int ZoomInOut(const TOOL_EVENT &aEvent)
int doZoomInOut(bool aDirection, bool aCenterOnCursor)
int ShowModal() override
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Return bounding box of document with option to not include some items.
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 KIGFX::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
Used for hotkey feedback.
Definition actions.h:365
void WriteConfig(WINDOW_SETTINGS &aCfg)
void SetCursorMode(CROSS_HAIR_MODE aMode)
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 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:63
double GetScale() const
Definition view.h:283
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition view.cpp:651
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:209
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:548
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition view.h:257
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1743
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:227
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:677
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:661
VECTOR2I GetReferencePoint() const
bool Empty() const
Checks if there is anything selected.
Definition selection.h:114
bool HasReferencePoint() const
Definition selection.h:215
virtual BOX2I GetBoundingBox() const
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
const std::string & GetName() const
Return the name of the tool.
Definition tool_base.h:132
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ REDRAW
Full drawing refresh.
Definition tool_base.h:79
@ SHUTDOWN
Tool is being shut down.
Definition tool_base.h:80
Generic, UI-independent tool event.
Definition tool_event.h:167
void SetMousePosition(const VECTOR2D &aP)
Definition tool_event.h:549
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition tool_event.h:539
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
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).
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
VECTOR2I GetValue()
Return the value in internal units.
#define _(s)
EDA_UNITS
Definition eda_units.h:44
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:31
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_SCH_VIEWER
Definition frame_type.h:32
@ FRAME_SCH
Definition frame_type.h:30
@ FRAME_PL_EDITOR
Definition frame_type.h:55
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_GERBER
Definition frame_type.h:53
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:79
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
KICOMMON_API bool IsImperialUnit(EDA_UNITS aUnit)
Definition eda_units.cpp:43
KICOMMON_API bool IsMetricUnit(EDA_UNITS aUnit)
Definition eda_units.cpp:57
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
@ INCH
Definition rs274x.cpp:61
const int scale
std::vector< FAB_LAYER_COLOR > dummy
std::vector< GRID > grids
Common grid settings, available to every frame.
wxString y
wxString x
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates).
bool m_forceCursorPosition
Is the forced cursor position enabled.
static const long long MM
VECTOR2I center
TOOL_ACTIONS
Definition tool_event.h:60
@ TA_MOUSE_CLICK
Definition tool_event.h:63
@ TA_MOUSE_DBLCLICK
Definition tool_event.h:64
@ TA_CANCEL_TOOL
Tool cancel event.
Definition tool_event.h:86
@ MD_ALT
Definition tool_event.h:141
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ TC_COMMAND
Definition tool_event.h:53
@ TC_MOUSE
Definition tool_event.h:51
TOOL_MOUSE_BUTTONS
Definition tool_event.h:126
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition vector2wx.h:26
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:36