2017-02-20 18:10:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2016 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
#include <bitmaps.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <tool/actions.h>
|
2018-10-03 16:26:33 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <draw_frame.h>
|
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <base_screen.h>
|
2018-02-25 18:30:59 +00:00
|
|
|
#include <hotkeys.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <tool/common_tools.h>
|
2019-05-25 19:39:42 +00:00
|
|
|
#include <id.h>
|
2019-06-02 23:17:27 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <dialog_configure_paths.h>
|
2017-03-18 20:03:24 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
void COMMON_TOOLS::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<EDA_DRAW_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-03 16:26:33 +00:00
|
|
|
// Cursor control
|
|
|
|
int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
long type = aEvent.Parameter<intptr_t>();
|
|
|
|
bool fastMove = type & ACTIONS::CURSOR_FAST_MOVE;
|
|
|
|
type &= ~ACTIONS::CURSOR_FAST_MOVE;
|
|
|
|
bool mirroredX = getView()->IsMirroredX();
|
|
|
|
|
2018-10-21 21:27:25 +00:00
|
|
|
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( false );
|
2018-10-03 16:26:33 +00:00
|
|
|
VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() );
|
|
|
|
|
|
|
|
if( fastMove )
|
|
|
|
gridSize = gridSize * 10;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_UP:
|
|
|
|
cursor -= VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_DOWN:
|
|
|
|
cursor += VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_LEFT:
|
|
|
|
cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_RIGHT:
|
|
|
|
cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_CLICK: // fall through
|
|
|
|
case ACTIONS::CURSOR_DBL_CLICK:
|
|
|
|
{
|
|
|
|
TOOL_ACTIONS action = TA_NONE;
|
|
|
|
int modifiers = 0;
|
|
|
|
|
|
|
|
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
|
|
|
|
|
|
|
|
if( type == ACTIONS::CURSOR_CLICK )
|
|
|
|
action = TA_MOUSE_CLICK;
|
|
|
|
else if( type == ACTIONS::CURSOR_DBL_CLICK )
|
|
|
|
action = TA_MOUSE_DBLCLICK;
|
|
|
|
else
|
|
|
|
wxFAIL;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers );
|
|
|
|
evt.SetMousePosition( getViewControls()->GetCursorPosition() );
|
|
|
|
m_toolMgr->ProcessEvent( evt );
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 17:57:40 +00:00
|
|
|
getViewControls()->SetCursorPosition( cursor, true, true );
|
2018-10-03 16:26:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::PanControl( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
long type = aEvent.Parameter<intptr_t>();
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
VECTOR2D center = view->GetCenter();
|
|
|
|
VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() ) * 10;
|
|
|
|
bool mirroredX = view->IsMirroredX();
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_UP:
|
|
|
|
center -= VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_DOWN:
|
|
|
|
center += VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_LEFT:
|
|
|
|
center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
case ACTIONS::CURSOR_RIGHT:
|
|
|
|
center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 );
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
break;
|
2018-10-03 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view->SetCenter( center );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-11 01:23:34 +00:00
|
|
|
int COMMON_TOOLS::ZoomRedraw( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->HardRedraw();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
int COMMON_TOOLS::ZoomInOut( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-05-25 11:59:57 +00:00
|
|
|
bool direction = aEvent.IsAction( &ACTIONS::zoomIn );
|
|
|
|
return doZoomInOut( direction, true );
|
|
|
|
}
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
int COMMON_TOOLS::ZoomInOutCenter( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
bool direction = aEvent.IsAction( &ACTIONS::zoomInCenter );
|
|
|
|
return doZoomInOut( direction, false );
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
|
2017-02-20 18:10:20 +00:00
|
|
|
{
|
2018-05-25 11:59:57 +00:00
|
|
|
double zoom = m_frame->GetGalCanvas()->GetLegacyZoom();
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
// Step must be AT LEAST 1.3
|
|
|
|
if( aDirection )
|
|
|
|
zoom /= 1.3;
|
|
|
|
else
|
|
|
|
zoom *= 1.3;
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
// Now look for the next closest menu step
|
|
|
|
std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList;
|
|
|
|
int idx;
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
if( aDirection )
|
|
|
|
{
|
|
|
|
for( idx = zoomList.size() - 1; idx >= 0; --idx )
|
|
|
|
{
|
|
|
|
if( zoomList[idx] <= zoom )
|
|
|
|
break;
|
|
|
|
}
|
2018-06-12 18:15:04 +00:00
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0; // if we ran off the end then peg to the end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-12 18:15:04 +00:00
|
|
|
for( idx = 0; idx < (int)zoomList.size(); ++idx )
|
2018-05-25 11:59:57 +00:00
|
|
|
{
|
|
|
|
if( zoomList[idx] >= zoom )
|
|
|
|
break;
|
|
|
|
}
|
2018-06-12 18:15:04 +00:00
|
|
|
|
|
|
|
if( idx >= (int)zoomList.size() )
|
2018-05-25 11:59:57 +00:00
|
|
|
idx = zoomList.size() - 1; // if we ran off the end then peg to the end
|
|
|
|
}
|
|
|
|
|
|
|
|
return doZoomToPreset( idx + 1, aCenterOnCursor );
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::ZoomCenter( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
|
|
|
|
2017-03-15 10:48:28 +00:00
|
|
|
ctls->CenterOnCursor();
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-23 04:31:26 +00:00
|
|
|
int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas();
|
2019-04-13 23:53:33 +00:00
|
|
|
EDA_DRAW_FRAME* frame = getEditFrame<EDA_DRAW_FRAME>();
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2019-04-13 23:53:33 +00:00
|
|
|
BOX2I bBox = frame->GetDocumentExtents();
|
2019-05-25 14:43:55 +00:00
|
|
|
BOX2I defaultBox = galCanvas->GetDefaultViewBBox();
|
2017-02-23 04:31:26 +00:00
|
|
|
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
|
|
|
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
|
|
|
|
|
|
|
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
|
2019-05-25 14:43:55 +00:00
|
|
|
bBox = defaultBox;
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2018-01-11 03:53:55 +00:00
|
|
|
VECTOR2D vsize = bBox.GetSize();
|
|
|
|
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
|
|
|
fabs( vsize.y / screenSize.y ) );
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2018-02-13 21:19:41 +00:00
|
|
|
// Reserve a 10% margin around component bounding box.
|
|
|
|
double margin_scale_factor = 1.1;
|
|
|
|
|
|
|
|
// Leave 20% for library editors & viewers
|
|
|
|
if( frame->IsType( FRAME_PCB_MODULE_VIEWER ) || frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL )
|
|
|
|
|| frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL )
|
|
|
|
|| frame->IsType( FRAME_SCH_LIB_EDITOR ) || frame->IsType( FRAME_PCB_MODULE_EDITOR ) )
|
|
|
|
{
|
|
|
|
margin_scale_factor = 1.2;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->SetScale( scale / margin_scale_factor );
|
2018-01-11 03:53:55 +00:00
|
|
|
view->SetCenter( bBox.Centre() );
|
2017-02-23 04:31:26 +00:00
|
|
|
|
|
|
|
// Take scrollbars into account
|
|
|
|
VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false );
|
|
|
|
view->SetCenter( view->GetCenter() + worldScrollbarSize / 2.0 );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-11 15:28:57 +00:00
|
|
|
int COMMON_TOOLS::CenterContents( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas();
|
|
|
|
BOX2I bBox = getModel<EDA_ITEM>()->ViewBBox();
|
|
|
|
|
|
|
|
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
|
|
|
|
bBox = galCanvas->GetDefaultViewBBox();
|
|
|
|
|
|
|
|
getView()->SetCenter( bBox.Centre() );
|
|
|
|
|
|
|
|
// Take scrollbars into account
|
|
|
|
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
|
|
|
VECTOR2D worldScrollbarSize = getView()->ToWorld( scrollbarSize, false );
|
|
|
|
getView()->SetCenter( getView()->GetCenter() + worldScrollbarSize / 2.0 );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-23 04:31:26 +00:00
|
|
|
int COMMON_TOOLS::ZoomPreset( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
unsigned int idx = aEvent.Parameter<intptr_t>();
|
2018-05-25 11:59:57 +00:00
|
|
|
return doZoomToPreset( idx, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
|
|
|
|
int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
|
|
|
|
{
|
2017-02-23 04:31:26 +00:00
|
|
|
std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList;
|
|
|
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
|
|
|
|
|
|
|
if( idx == 0 ) // Zoom Auto
|
|
|
|
{
|
2018-05-25 11:59:57 +00:00
|
|
|
TOOL_EVENT dummy;
|
|
|
|
return ZoomFitScreen( dummy );
|
2017-02-23 04:31:26 +00:00
|
|
|
}
|
2018-05-25 11:59:57 +00:00
|
|
|
else
|
2018-10-21 22:16:15 +00:00
|
|
|
{
|
2018-05-25 11:59:57 +00:00
|
|
|
idx--;
|
2018-10-21 22:16:15 +00:00
|
|
|
}
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2018-10-21 22:16:15 +00:00
|
|
|
double scale = m_frame->GetZoomLevelCoeff() / zoomList[idx];
|
2018-05-25 11:59:57 +00:00
|
|
|
|
|
|
|
if( aCenterOnCursor )
|
|
|
|
{
|
|
|
|
view->SetScale( scale, getViewControls()->GetCursorPosition() );
|
|
|
|
|
|
|
|
if( getViewControls()->IsCursorWarpingEnabled() )
|
|
|
|
getViewControls()->CenterOnCursor();
|
|
|
|
}
|
|
|
|
else
|
2018-10-21 22:16:15 +00:00
|
|
|
{
|
2018-05-25 11:59:57 +00:00
|
|
|
view->SetScale( scale );
|
2018-10-21 22:16:15 +00:00
|
|
|
}
|
2017-02-23 04:31:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-16 12:07:39 +00:00
|
|
|
/**
|
|
|
|
* Advance a BASE_SCREEN's grid forwards or backwards by the given offset and
|
|
|
|
* return the cmd ID of that grid (doesn't change the grid).
|
|
|
|
*
|
|
|
|
* This works even if the base screen's grid do not have consecutive command IDs.
|
|
|
|
*
|
|
|
|
* @param aScreen the base screen to use
|
|
|
|
* @param aOffset how many grids to advance by (negative to go backwards)
|
|
|
|
* @return the cmd ID of the requested grid, or empty if it can't be found
|
|
|
|
*/
|
|
|
|
static OPT<int> getNextPreviousGrid( const BASE_SCREEN& aScreen, int aOffset )
|
|
|
|
{
|
|
|
|
const GRIDS& grids = aScreen.GetGrids();
|
|
|
|
const GRID_TYPE& currGrid = aScreen.GetGrid();
|
|
|
|
|
|
|
|
auto iter = std::find_if( grids.begin(), grids.end(),
|
|
|
|
[&]( const GRID_TYPE& aCandidate ) { return aCandidate.m_CmdId == currGrid.m_CmdId; } );
|
|
|
|
|
|
|
|
wxCHECK_MSG( iter != grids.end(), {}, "Grid not found in screen's grid list" );
|
|
|
|
|
|
|
|
int index = std::distance( grids.begin(), iter ) + aOffset;
|
|
|
|
|
|
|
|
// If we go off the end, return invalid, but we could also wrap around if wanted.
|
|
|
|
if( index < 0 || static_cast<size_t>( index ) >= grids.size() )
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return grids[index].m_CmdId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Grid control
|
|
|
|
int COMMON_TOOLS::GridNext( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-16 12:07:39 +00:00
|
|
|
const OPT<int> next_grid_id = getNextPreviousGrid( *m_frame->GetScreen(), 1 );
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2019-05-16 12:07:39 +00:00
|
|
|
if( next_grid_id )
|
|
|
|
return doGridPreset( *next_grid_id - ID_POPUP_GRID_LEVEL_1000 );
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2019-05-16 12:07:39 +00:00
|
|
|
return 1;
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::GridPrev( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-16 12:07:39 +00:00
|
|
|
const OPT<int> next_grid_id = getNextPreviousGrid( *m_frame->GetScreen(), -1 );
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2019-05-16 12:07:39 +00:00
|
|
|
if( next_grid_id )
|
|
|
|
return doGridPreset( *next_grid_id - ID_POPUP_GRID_LEVEL_1000 );
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2019-05-16 12:07:39 +00:00
|
|
|
return 1;
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::GridPreset( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-04-13 17:41:11 +00:00
|
|
|
return doGridPreset( aEvent.Parameter<intptr_t>() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::doGridPreset( int idx )
|
|
|
|
{
|
|
|
|
BASE_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
|
|
|
|
if( !screen->GridExists( idx + ID_POPUP_GRID_LEVEL_1000 ) )
|
|
|
|
idx = 0;
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2019-04-13 17:41:11 +00:00
|
|
|
screen->SetGrid( idx + ID_POPUP_GRID_LEVEL_1000 );
|
|
|
|
|
|
|
|
// Be sure m_LastGridSizeId is up to date.
|
|
|
|
m_frame->SetLastGridSizeId( idx );
|
|
|
|
|
|
|
|
// Update the combobox (if any)
|
|
|
|
wxUpdateUIEvent dummy;
|
|
|
|
m_frame->OnUpdateSelectGrid( dummy );
|
|
|
|
|
|
|
|
// Update GAL canvas from screen
|
|
|
|
getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
|
|
|
|
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|
|
|
|
|
|
|
// Put cursor on new grid
|
|
|
|
m_frame->SetCrossHairPosition( m_frame->RefPos( true ) );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int COMMON_TOOLS::ToggleGrid( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->SetGridVisibility( !m_frame->IsGridVisible() );
|
|
|
|
|
|
|
|
m_frame->GetGalCanvas()->GetGAL()->SetGridVisibility( m_frame->IsGridVisible() );
|
|
|
|
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 21:49:05 +00:00
|
|
|
int COMMON_TOOLS::GridProperties( const TOOL_EVENT& aEvent )
|
2019-05-13 20:42:40 +00:00
|
|
|
{
|
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
|
|
|
|
2019-05-13 21:49:05 +00:00
|
|
|
cmd.SetId( ID_GRID_SETTINGS );
|
2019-05-13 20:42:40 +00:00
|
|
|
m_frame->ProcessEvent( cmd );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 21:49:05 +00:00
|
|
|
int COMMON_TOOLS::MetricUnits( const TOOL_EVENT& aEvent )
|
2019-05-13 20:42:40 +00:00
|
|
|
{
|
2019-05-13 21:49:05 +00:00
|
|
|
m_frame->ChangeUserUnits( MILLIMETRES );
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-13 20:42:40 +00:00
|
|
|
|
|
|
|
|
2019-05-13 21:49:05 +00:00
|
|
|
int COMMON_TOOLS::ImperialUnits( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->ChangeUserUnits( INCHES );
|
2019-05-13 20:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::ToggleUnits( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-13 21:49:05 +00:00
|
|
|
m_frame->ChangeUserUnits( m_frame->GetUserUnits() == INCHES ? MILLIMETRES : INCHES );
|
2019-05-13 20:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-17 11:52:38 +00:00
|
|
|
int COMMON_TOOLS::TogglePolarCoords( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->SetStatusText( wxEmptyString );
|
|
|
|
m_frame->SetShowPolarCoords( !m_frame->GetShowPolarCoords() );
|
|
|
|
m_frame->UpdateStatusBar();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-28 14:39:14 +00:00
|
|
|
int COMMON_TOOLS::ResetLocalCoords( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
auto vcSettings = m_toolMgr->GetCurrentToolVC();
|
|
|
|
|
|
|
|
// Use either the active tool forced cursor position or the general settings
|
|
|
|
VECTOR2I cursorPos = vcSettings.m_forceCursorPosition ? vcSettings.m_forcedPosition :
|
|
|
|
getViewControls()->GetCursorPosition();
|
|
|
|
|
|
|
|
m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
|
|
|
|
m_frame->UpdateStatusBar();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-18 20:03:24 +00:00
|
|
|
int COMMON_TOOLS::ToggleCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
auto& galOpts = m_frame->GetGalDisplayOptions();
|
|
|
|
|
|
|
|
galOpts.m_forceDisplayCursor = !galOpts.m_forceDisplayCursor;
|
|
|
|
galOpts.NotifyChanged();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int COMMON_TOOLS::ToggleCursorStyle( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS& galOpts = m_frame->GetGalDisplayOptions();
|
|
|
|
|
|
|
|
galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
|
|
|
|
galOpts.NotifyChanged();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-02 23:17:27 +00:00
|
|
|
int COMMON_TOOLS::ConfigurePaths( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB );
|
|
|
|
kiface->CreateWindow( m_frame, DIALOG_CONFIGUREPATHS, &m_frame->Kiway() );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::ShowLibraryTable( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsAction( &ACTIONS::showSymbolLibTable ) )
|
|
|
|
{
|
|
|
|
KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH );
|
|
|
|
kiface->CreateWindow( m_frame, DIALOG_SCH_LIBRARY_TABLE, &m_frame->Kiway() );
|
|
|
|
}
|
|
|
|
else if( aEvent.IsAction( &ACTIONS::showFootprintLibTable ) )
|
|
|
|
{
|
|
|
|
KIFACE* kiface = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB );
|
|
|
|
kiface->CreateWindow( m_frame, DIALOG_PCB_LIBRARY_TABLE, &m_frame->Kiway() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-28 13:51:47 +00:00
|
|
|
int COMMON_TOOLS::SwitchCanvas( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsAction( &ACTIONS::acceleratedGraphics ) )
|
|
|
|
m_frame->SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
|
|
|
|
else if( aEvent.IsAction( &ACTIONS::standardGraphics ) )
|
|
|
|
m_frame->SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Unknown canvas type" );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void COMMON_TOOLS::setTransitions()
|
2017-02-20 18:10:20 +00:00
|
|
|
{
|
2018-10-03 16:26:33 +00:00
|
|
|
// Cursor control
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorUp.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDown.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorLeft.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorRight.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorUpFast.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDownFast.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorLeftFast.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorRightFast.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorClick.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::cursorDblClick.MakeEvent() );
|
|
|
|
|
|
|
|
// Pan control
|
|
|
|
Go( &COMMON_TOOLS::PanControl, ACTIONS::panUp.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::PanControl, ACTIONS::panDown.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::PanControl, ACTIONS::panLeft.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::PanControl, ACTIONS::panRight.MakeEvent() );
|
|
|
|
|
|
|
|
// Zoom control
|
2019-04-11 01:23:34 +00:00
|
|
|
Go( &COMMON_TOOLS::ZoomRedraw, ACTIONS::zoomRedraw.MakeEvent() );
|
2017-02-20 18:10:20 +00:00
|
|
|
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomOutCenter.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomCenter, ACTIONS::zoomCenter.MakeEvent() );
|
2017-02-23 04:31:26 +00:00
|
|
|
Go( &COMMON_TOOLS::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomPreset, ACTIONS::zoomPreset.MakeEvent() );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2018-09-11 15:28:57 +00:00
|
|
|
Go( &COMMON_TOOLS::CenterContents, ACTIONS::centerContents.MakeEvent() );
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
Go( &COMMON_TOOLS::GridNext, ACTIONS::gridNext.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridPrev, ACTIONS::gridPrev.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridPreset, ACTIONS::gridPreset.MakeEvent() );
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &COMMON_TOOLS::ToggleGrid, ACTIONS::toggleGrid.MakeEvent() );
|
2019-05-13 21:49:05 +00:00
|
|
|
Go( &COMMON_TOOLS::GridProperties, ACTIONS::gridProperties.MakeEvent() );
|
2019-05-13 20:42:40 +00:00
|
|
|
|
|
|
|
Go( &COMMON_TOOLS::ImperialUnits, ACTIONS::imperialUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::MetricUnits, ACTIONS::metricUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleUnits, ACTIONS::toggleUnits.MakeEvent() );
|
2019-05-17 11:52:38 +00:00
|
|
|
Go( &COMMON_TOOLS::TogglePolarCoords, ACTIONS::togglePolarCoords.MakeEvent() );
|
2019-05-28 14:39:14 +00:00
|
|
|
Go( &COMMON_TOOLS::ResetLocalCoords, ACTIONS::resetLocalCoords.MakeEvent() );
|
2017-03-18 20:03:24 +00:00
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &COMMON_TOOLS::ToggleCursor, ACTIONS::toggleCursor.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleCursorStyle, ACTIONS::toggleCursorStyle.MakeEvent() );
|
2019-05-28 13:51:47 +00:00
|
|
|
|
2019-06-02 23:17:27 +00:00
|
|
|
Go( &COMMON_TOOLS::ConfigurePaths, ACTIONS::configurePaths.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ShowLibraryTable, ACTIONS::showSymbolLibTable.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ShowLibraryTable, ACTIONS::showFootprintLibTable.MakeEvent() );
|
2019-05-28 13:51:47 +00:00
|
|
|
Go( &COMMON_TOOLS::SwitchCanvas, ACTIONS::acceleratedGraphics.MakeEvent() );
|
2019-05-29 19:20:31 +00:00
|
|
|
Go( &COMMON_TOOLS::SwitchCanvas, ACTIONS::standardGraphics.MakeEvent() );
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|