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, 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 ),
55{
56}
57
58
60{
62 m_grids.clear();
63
64 if( aReason == RESET_REASON::SHUTDOWN )
65 return;
66
67 GRID_SETTINGS& settings = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid;
68
69 // Protect against misconfigured settings with no grids
70 if( settings.grids.empty() )
71 settings.grids = m_frame->config()->DefaultGridSizeList();
72
73 EDA_IU_SCALE scale = m_frame->GetIuScale();
74
75 for( GRID& gridDef : settings.grids )
76 {
77 double gridSizeX = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MM, gridDef.x );
78 double gridSizeY = EDA_UNIT_UTILS::UI::DoubleValueFromString( scale, EDA_UNITS::MM, gridDef.y );
79
80 m_grids.emplace_back( KiROUND<double, int>( gridSizeX ), KiROUND<double, int>( gridSizeY ) );
81 }
82
83 OnGridChanged( false );
84}
85
86
88{
90 m_imperialUnit = aUnit;
91 else if( EDA_UNIT_UTILS::IsMetricUnit( aUnit ) )
92 m_metricUnit = aUnit;
93 else
94 wxASSERT_MSG( false, wxS( "Invalid unit" ) );
95}
96
97
99{
100 // Since selection tools are run permanently underneath the toolStack, this is really
101 // just a cancel of whatever other tools might be running.
102
103 m_toolMgr->ProcessEvent( TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL ) );
104 return 0;
105}
106
107
109{
111 std::unique_ptr<GRID_HELPER> grid = m_frame->MakeGridHelper();
112 VECTOR2D gridSize;
113
114 if( grid )
115 gridSize = grid->GetGridSize( grid->GetSelectionGrid( m_frame->GetCurrentSelection() ) );
116 else
117 gridSize = getView()->GetGAL()->GetGridSize();
118
119 bool mirroredX = getView()->IsMirroredX();
121
122 switch( type )
123 {
125 gridSize *= 10;
128 cursor -= VECTOR2D( 0, gridSize.y );
129 break;
130
132 gridSize *= 10;
135 cursor += VECTOR2D( 0, gridSize.y );
136 break;
137
139 gridSize *= 10;
142 cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
143 break;
144
146 gridSize *= 10;
149 cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
150 break;
151
152 case ACTIONS::CURSOR_CLICK: // fall through
155 {
158 int modifiers = 0;
159
160 modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
161 modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
162 modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
163
164 if( type == ACTIONS::CURSOR_DBL_CLICK )
165 action = TA_MOUSE_DBLCLICK;
166 else if( type == ACTIONS::CURSOR_RIGHT_CLICK )
167 button = BUT_RIGHT;
168
169 TOOL_EVENT evt( TC_MOUSE, action, static_cast<int>( button | modifiers ) );
170 evt.SetParameter( type );
171 evt.SetMousePosition( getViewControls()->GetMousePosition() );
172 m_toolMgr->ProcessEvent( evt );
173
174 return 0;
175 }
176 default:
177 wxFAIL_MSG( wxS( "CursorControl(): unexpected request" ) );
178 }
179
180 getViewControls()->SetCursorPosition( cursor, true, true, type );
181 m_toolMgr->PostAction( ACTIONS::refreshPreview );
182
183 return 0;
184}
185
186
188{
190 KIGFX::VIEW* view = getView();
191 VECTOR2D center = view->GetCenter();
192 VECTOR2D gridSize = getView()->GetGAL()->GetGridSize() * 10;
193 bool mirroredX = view->IsMirroredX();
194
195 switch( type )
196 {
198 center -= VECTOR2D( 0, gridSize.y );
199 break;
200
202 center += VECTOR2D( 0, gridSize.y );
203 break;
204
206 center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
207 break;
208
210 center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
211 break;
212
213 default:
214 wxFAIL;
215 break;
216 }
217
218 view->SetCenter( center );
219
220 return 0;
221}
222
223
225{
226 m_frame->HardRedraw();
227 return 0;
228}
229
230
232{
233 bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
234 return doZoomInOut( direction, true );
235}
236
237
239{
240 bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
241 return doZoomInOut( direction, false );
242}
243
244
245int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
246{
247 double zoom = getView()->GetGAL()->GetZoomFactor();
248
249 // Step must be AT LEAST 1.3
250 if( aDirection )
251 zoom *= 1.3;
252 else
253 zoom /= 1.3;
254
255 // Now look for the next closest menu step
256 std::vector<double>& zoomList = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->zoom_factors;
257 int idx;
258
259 if( aDirection )
260 {
261 for( idx = 0; idx < int( zoomList.size() ); ++idx )
262 {
263 if( zoomList[idx] >= zoom )
264 break;
265 }
266
267 if( idx >= int( zoomList.size() ) )
268 idx = (int) zoomList.size() - 1; // if we ran off the end then peg to the end
269 }
270 else
271 {
272 for( idx = int( zoomList.size() ) - 1; idx >= 0; --idx )
273 {
274 if( zoomList[idx] <= zoom )
275 break;
276 }
277
278 if( idx < 0 )
279 idx = 0; // if we ran off the end then peg to the end
280 }
281
282 // Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
283 return doZoomToPreset( idx + 1, aCenterOnCursor );
284}
285
286
288{
290
291 ctls->CenterOnCursor();
292
293 return 0;
294}
295
296
298{
299 return doZoomFit( ZOOM_FIT_ALL );
300}
301
302
304{
305 return doZoomFit( ZOOM_FIT_OBJECTS );
306}
307
308
310{
312}
313
314
316{
317 KIGFX::VIEW* view = getView();
318 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
320
321 BOX2I bBox = frame->GetDocumentExtents();
322 BOX2I defaultBox = canvas->GetDefaultViewBBox();
323
324 view->SetScale( 1.0 ); // The best scale will be determined later, but this initial
325 // value ensures all view parameters are up to date (especially
326 // at init time)
327 VECTOR2D screenSize = view->ToWorld( ToVECTOR2I( canvas->GetClientSize() ), false );
328
329 // Currently "Zoom to Objects" is only supported in Eeschema & Pcbnew. Support for other
330 // programs in the suite can be added as needed.
331
332 if( aFitType == ZOOM_FIT_ALL )
333 {
334 if( frame->IsType( FRAME_PCB_EDITOR ) )
335 bBox = m_frame->GetDocumentExtents( false );
336 }
337
338 if( aFitType == ZOOM_FIT_OBJECTS )
339 {
340 if( frame->IsType( FRAME_SCH ) )
341 bBox = m_frame->GetDocumentExtents( false );
342 else
343 aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors
344 }
345
346 if( aFitType == ZOOM_FIT_SELECTION )
347 {
348 SELECTION& selection = m_frame->GetCurrentSelection();
349
350 if( selection.Empty() )
351 return 0;
352
353 bBox = selection.GetBoundingBox();
354 }
355
356 // If the screen is empty then use the default view bbox
357
358 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
359 bBox = defaultBox;
360
361 VECTOR2D vsize = bBox.GetSize();
362 double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
363 fabs( vsize.y / screenSize.y ) );
364
365 // if the scale isn't finite (most likely due to an empty canvas)
366 // simply just make sure we are centered and quit out of trying to zoom to fit
367 if( !std::isfinite( scale ) )
368 {
369 view->SetCenter( VECTOR2D( 0, 0 ) );
370 canvas->Refresh();
371 return 0;
372 }
373
374 // Reserve enough margin to limit the amount of the view that might be obscured behind the
375 // infobar.
376 double margin_scale_factor = 1.04;
377
378 if( canvas->GetClientSize().y < 768 )
379 margin_scale_factor = 1.10;
380
381 if( aFitType == ZOOM_FIT_ALL )
382 {
383 // Leave a bigger margin for library editors & viewers
384
385 if( frame->IsType( FRAME_FOOTPRINT_VIEWER )
386 || frame->IsType( FRAME_SCH_VIEWER ) )
387 {
388 margin_scale_factor = 1.30;
389 }
390 else if( frame->IsType( FRAME_SCH_SYMBOL_EDITOR )
391 || frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
392 {
393 margin_scale_factor = 1.48;
394 }
395 }
396
397 view->SetScale( scale / margin_scale_factor );
398 view->SetCenter( bBox.Centre() );
399 canvas->Refresh();
400
401 return 0;
402}
403
404
409
410
415
416
418{
419 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
420
421 BOX2I bBox;
422
423 if( aCenterType == CENTER_TYPE::CENTER_SELECTION )
424 {
425 SELECTION& selection = m_frame->GetCurrentSelection();
426
427 // No selection: do nothing
428 if( selection.Empty() )
429 return 0;
430
431 bBox = selection.GetBoundingBox().Centre();
432 }
433 else
434 {
435 bBox = getModel<EDA_ITEM>()->ViewBBox();
436
437 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
438 bBox = canvas->GetDefaultViewBBox();
439 }
440
441 getView()->SetCenter( bBox.Centre() );
442
443 // Take scrollbars into account
444 VECTOR2D scrollbarSize = VECTOR2D( ToVECTOR2D( canvas->GetSize() - canvas->GetClientSize() ) );
445 VECTOR2D worldScrollbarSize = getView()->ToWorld( scrollbarSize, false );
446 getView()->SetCenter( getView()->GetCenter() + worldScrollbarSize / 2.0 );
447 canvas->Refresh();
448
449 return 0;
450}
451
452
454{
455 int idx = aEvent.Parameter<int>();
456 return doZoomToPreset( idx, false );
457}
458
459
460// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
461int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
462{
463 std::vector<double>& zoomList = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->zoom_factors;
464
465 if( idx == 0 ) // Zoom Auto
466 {
468 return ZoomFitScreen( dummy );
469 }
470 else
471 {
472 idx--;
473 }
474
475 double scale = zoomList[idx];
476
477 if( aCenterOnCursor )
478 {
479 getView()->SetScale( scale, getViewControls()->GetCursorPosition() );
480
481 if( getViewControls()->IsCursorWarpingEnabled() )
483 }
484 else
485 {
486 getView()->SetScale( scale );
487 }
488
489 m_frame->GetCanvas()->Refresh();
490
491 return 0;
492}
493
494
496{
497 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
498
499 currentGrid++;
500
501 if( currentGrid >= int( m_grids.size() ) )
502 currentGrid = 0;
503
504 return OnGridChanged( true );
505}
506
507
509{
510 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
511
512 currentGrid--;
513
514 if( currentGrid < 0 )
515 currentGrid = (int) m_grids.size() - 1;
516
517 return OnGridChanged( true );
518}
519
520
522{
523 return GridPreset( aEvent.Parameter<int>(), false );
524}
525
526
527int COMMON_TOOLS::GridPreset( int idx, bool aFromHotkey )
528{
529 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
530
531 currentGrid = std::clamp( idx, 0, (int) m_grids.size() - 1 );
532
533 return OnGridChanged( aFromHotkey );
534}
535
536
537int COMMON_TOOLS::OnGridChanged( bool aFromHotkey )
538{
539 int& currentGrid = m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx;
540
541 currentGrid = std::max( 0, std::min( currentGrid, static_cast<int>( m_grids.size() ) - 1 ) );
542
543 // Update the combobox (if any)
544 wxUpdateUIEvent dummy;
545 m_frame->OnUpdateSelectGrid( dummy );
546
547 // Update GAL canvas from screen
548 getView()->GetGAL()->SetGridSize( m_grids[ currentGrid ] );
549 getView()->GetGAL()->SetGridVisibility( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.show );
551
552 // Put cursor on new grid
553 VECTOR2D gridCursor = getViewControls()->GetCursorPosition( true );
554 getViewControls()->SetCrossHairCursorPosition( gridCursor, false );
555
556 // Show feedback
557 if( aFromHotkey )
559
560 return 0;
561}
562
563
565{
566 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1, true );
567}
568
569
571{
572 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_2, true );
573}
574
575
577{
578 if( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.last_size_idx
579 == m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1 )
580 {
581 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_2, true );
582 }
583
584 return GridPreset( m_frame->GetWindowSettings( m_toolMgr->GetSettings() )->grid.fast_grid_1, true );
585}
586
587
589{
590 m_frame->SetGridVisibility( !m_frame->IsGridVisible() );
591 return 0;
592}
593
594
596{
597 m_frame->SetGridOverrides( !m_frame->IsGridOverridden() );
598 return 0;
599}
600
601
603{
604 auto showGridPrefs =
605 [this]( const wxString& aParentName )
606 {
607 m_frame->CallAfter(
608 [this, aParentName]()
609 {
610 m_frame->ShowPreferences( _( "Grids" ), aParentName );
611 } );
612 };
613
614 switch( m_frame->GetFrameType() )
615 {
616 case FRAME_SCH: showGridPrefs( _( "Schematic Editor" ) ); break;
617 case FRAME_SCH_SYMBOL_EDITOR: showGridPrefs( _( "Symbol Editor" ) ); break;
618 case FRAME_PCB_EDITOR: showGridPrefs( _( "PCB Editor" ) ); break;
619 case FRAME_FOOTPRINT_EDITOR: showGridPrefs( _( "Footprint Editor" ) ); break;
620 case FRAME_PL_EDITOR: showGridPrefs( _( "Drawing Sheet Editor" ) ); break;
621 case FRAME_GERBER: showGridPrefs( _( "Gerber Viewer" ) ); break;
622 default: wxFAIL_MSG( "Unknown frame: " + GetName() ); break;
623 }
624
625 return 0;
626}
627
628
630{
631 VECTOR2I origin = m_frame->GetGridOrigin();
632 WX_PT_ENTRY_DIALOG dlg( m_frame, _( "Grid Origin" ), _( "X:" ), _( "Y:" ), origin, true );
633
634 if( dlg.ShowModal() == wxID_OK )
635 {
636 m_frame->SetGridOrigin( dlg.GetValue() );
637
638 m_toolMgr->ResetTools( TOOL_BASE::REDRAW );
639 m_toolMgr->RunAction( ACTIONS::gridSetOrigin, new VECTOR2D( m_frame->GetGridOrigin() ) );
640 m_frame->GetCanvas()->ForceRefresh();
641 }
642
643 return 0;
644}
645
646
648{
649 EDA_UNITS newUnit = aEvent.Parameter<EDA_UNITS>();
650
651 if( EDA_UNIT_UTILS::IsMetricUnit( newUnit ) )
652 m_metricUnit = newUnit;
653 else if( EDA_UNIT_UTILS::IsImperialUnit( newUnit ) )
654 m_imperialUnit = newUnit;
655 else
656 wxASSERT_MSG( false, wxS( "Invalid unit for the frame" ) );
657
658 m_frame->ChangeUserUnits( newUnit );
659 return 0;
660}
661
662
664{
665 m_frame->ChangeUserUnits( EDA_UNIT_UTILS::IsImperialUnit( m_frame->GetUserUnits() ) ?
668 return 0;
669}
670
671
673{
674 m_frame->SetStatusText( wxEmptyString );
675 m_frame->SetShowPolarCoords( !m_frame->GetShowPolarCoords() );
676 m_frame->UpdateStatusBar();
677
678 return 0;
679}
680
681
683{
684 if( !m_frame->GetScreen() ) // Can happen in footprint chooser frame
685 return 0;
686
687 const KIGFX::VC_SETTINGS& vcSettings = m_toolMgr->GetCurrentToolVC();
688
689 // Use either the active tool forced cursor position or the general settings
690 if( vcSettings.m_forceCursorPosition )
691 m_frame->GetScreen()->m_LocalOrigin = vcSettings.m_forcedPosition;
692 else
693 m_frame->GetScreen()->m_LocalOrigin = getViewControls()->GetCursorPosition();
694
695 m_frame->UpdateStatusBar();
696
697 return 0;
698}
699
700
702{
703 auto& galOpts = m_frame->GetGalDisplayOptions();
704
705 galOpts.m_forceDisplayCursor = !galOpts.m_forceDisplayCursor;
706 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
707 galOpts.NotifyChanged();
708
709 return 0;
710}
711
712
714{
715 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
716
718 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
719 galOpts.NotifyChanged();
720
721 return 0;
722}
723
724
726{
727 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
728
730 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
731 galOpts.NotifyChanged();
732
733 return 0;
734}
735
736
738{
739 GAL_DISPLAY_OPTIONS_IMPL& galOpts = m_frame->GetGalDisplayOptions();
740
742 galOpts.WriteConfig( *m_frame->GetWindowSettings( m_toolMgr->GetSettings() ) );
743 galOpts.NotifyChanged();
744
745 return 0;
746}
747
748
750{
751 EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
752
753 if( canvas )
754 {
756
758
759 canvas->GetView()->UpdateAllItems( KIGFX::ALL );
760 canvas->ForceRefresh();
761 }
762
763 return 0;
764}
765
766
768{
770
771 // Cursor control
780
784
785 // Pan control
790
791 // Zoom control
804
805 // Grid control
816
817 // Units and coordinates
824
825 // Misc
831}
BASE_SCREEN class implementation.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
static TOOL_ACTION gridProperties
Definition actions.h:199
static TOOL_ACTION gridFastCycle
Definition actions.h:191
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION zoomRedraw
Definition actions.h:131
static TOOL_ACTION millimetersUnits
Definition actions.h:205
static TOOL_ACTION gridFast1
Definition actions.h:189
static TOOL_ACTION gridPrev
Definition actions.h:193
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:151
static TOOL_ACTION cursorLeft
Definition actions.h:171
static TOOL_ACTION zoomOutCenter
Definition actions.h:135
static TOOL_ACTION togglePolarCoords
Definition actions.h:208
static TOOL_ACTION zoomIn
Definition actions.h:132
static TOOL_ACTION cursorLeftFast
Definition actions.h:176
static TOOL_ACTION gridPreset
Definition actions.h:196
static TOOL_ACTION zoomFitSelection
Definition actions.h:143
static TOOL_ACTION centerSelection
Definition actions.h:149
static TOOL_ACTION cursorDown
Definition actions.h:170
static TOOL_ACTION zoomOut
Definition actions.h:133
static TOOL_ACTION milsUnits
Definition actions.h:204
static TOOL_ACTION cursorRightFast
Definition actions.h:177
static TOOL_ACTION toggleBoundingBoxes
Definition actions.h:156
static TOOL_ACTION showContextMenu
Definition actions.h:74
static TOOL_ACTION toggleCursor
Definition actions.h:150
static TOOL_ACTION centerContents
Definition actions.h:148
static TOOL_ACTION zoomCenter
Definition actions.h:140
static TOOL_ACTION panDown
Definition actions.h:184
static TOOL_ACTION cursorDblClick
Definition actions.h:180
CURSOR_EVENT_TYPE
Definition actions.h:304
@ CURSOR_DBL_CLICK
Definition actions.h:315
@ CURSOR_RIGHT
Definition actions.h:312
@ CURSOR_LEFT_FAST
Definition actions.h:311
@ CURSOR_LEFT
Definition actions.h:310
@ CURSOR_DOWN_FAST
Definition actions.h:309
@ CURSOR_CLICK
Definition actions.h:314
@ CURSOR_UP
Definition actions.h:306
@ CURSOR_RIGHT_FAST
Definition actions.h:313
@ CURSOR_DOWN
Definition actions.h:308
@ CURSOR_UP_FAST
Definition actions.h:307
@ CURSOR_RIGHT_CLICK
Definition actions.h:316
static TOOL_ACTION cursorDownFast
Definition actions.h:175
static TOOL_ACTION inchesUnits
Definition actions.h:203
static TOOL_ACTION cursorUpFast
Definition actions.h:174
static TOOL_ACTION gridOrigin
Definition actions.h:200
static TOOL_ACTION panLeft
Definition actions.h:185
static TOOL_ACTION selectionTool
Definition actions.h:250
static TOOL_ACTION cursorClick
Definition actions.h:179
static TOOL_ACTION zoomFitScreen
Definition actions.h:141
static TOOL_ACTION zoomPreset
Definition actions.h:144
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:153
static TOOL_ACTION panUp
Definition actions.h:183
static TOOL_ACTION zoomFitObjects
Definition actions.h:142
static TOOL_ACTION toggleUnits
Definition actions.h:207
static TOOL_ACTION zoomInCenter
Definition actions.h:134
static TOOL_ACTION panRight
Definition actions.h:186
static TOOL_ACTION gridSetOrigin
Definition actions.h:194
static TOOL_ACTION gridFast2
Definition actions.h:190
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition actions.h:169
static TOOL_ACTION refreshPreview
Definition actions.h:158
static TOOL_ACTION toggleGridOverrides
Definition actions.h:198
static TOOL_ACTION gridNext
Definition actions.h:192
static TOOL_ACTION cursorRight
Definition actions.h:172
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:152
static TOOL_ACTION resetLocalCoords
Definition actions.h:209
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 GridOrigin(const TOOL_EVENT &aEvent)
int doZoomToPreset(int idx, bool aCenterOnCursor)
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
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.
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
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 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
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 #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:366
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 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:66
double GetScale() const
Definition view.h:276
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition view.cpp:570
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:202
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:467
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition view.h:250
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:1561
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:220
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:596
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:639
bool Empty() const
Checks if there is anything selected.
Definition selection.h:115
virtual BOX2I GetBoundingBox() const
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:186
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:198
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:44
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:38
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:171
void SetMousePosition(const VECTOR2D &aP)
Definition tool_event.h:538
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition tool_event.h:528
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:473
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:48
@ 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)
Convert aTextValue to a double.
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:59
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:38
@ INCH
Definition rs274x.cpp:62
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.
VECTOR2I center
TOOL_ACTIONS
Definition tool_event.h:64
@ TA_MOUSE_CLICK
Definition tool_event.h:67
@ TA_MOUSE_DBLCLICK
Definition tool_event.h:68
@ TA_CANCEL_TOOL
Tool cancel event.
Definition tool_event.h:90
@ TC_COMMAND
Definition tool_event.h:57
@ TC_MOUSE
Definition tool_event.h:55
@ MD_ALT
Definition tool_event.h:145
@ MD_CTRL
Definition tool_event.h:144
@ MD_SHIFT
Definition tool_event.h:143
TOOL_MOUSE_BUTTONS
Definition tool_event.h:130
@ BUT_LEFT
Definition tool_event.h:132
@ BUT_RIGHT
Definition tool_event.h:133
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694
VECTOR2I ToVECTOR2I(const wxSize &aSize)
Definition vector2wx.h:30
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:40