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
|
2020-06-13 18:55:59 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-02-20 18:10:20 +00:00
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2020-09-25 07:31:56 +00:00
|
|
|
#include <base_screen.h>
|
|
|
|
#include <base_units.h>
|
2022-01-17 11:55:55 +00:00
|
|
|
#include <painter.h>
|
2019-05-14 19:21:10 +00:00
|
|
|
#include <bitmaps.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2020-10-25 13:36:19 +00:00
|
|
|
#include <dialogs/dialog_configure_paths.h>
|
2020-09-25 07:31:56 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2019-05-25 19:39:42 +00:00
|
|
|
#include <id.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-09-25 07:31:56 +00:00
|
|
|
#include <settings/app_settings.h>
|
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <tool/common_tools.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
2020-06-12 10:58:56 +00:00
|
|
|
|
2017-03-18 20:03:24 +00:00
|
|
|
|
2020-10-05 19:26:33 +00:00
|
|
|
COMMON_TOOLS::COMMON_TOOLS() :
|
|
|
|
TOOL_INTERACTIVE( "common.Control" ),
|
|
|
|
m_frame( nullptr ),
|
|
|
|
m_imperialUnit( EDA_UNITS::INCHES ),
|
|
|
|
m_metricUnit( EDA_UNITS::MILLIMETRES )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
void COMMON_TOOLS::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2020-10-05 19:26:33 +00:00
|
|
|
m_frame = getEditFrame<EDA_DRAW_FRAME>();
|
2020-06-12 10:58:56 +00:00
|
|
|
|
2020-06-23 10:16:34 +00:00
|
|
|
GRID_SETTINGS& settings = m_toolMgr->GetSettings()->m_Window.grid;
|
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
m_grids.clear();
|
|
|
|
|
2020-06-23 10:16:34 +00:00
|
|
|
for( const wxString& gridDef : settings.sizes )
|
2020-06-12 10:58:56 +00:00
|
|
|
{
|
2020-10-02 20:51:24 +00:00
|
|
|
int gridSize = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridDef );
|
2020-06-12 10:58:56 +00:00
|
|
|
m_grids.emplace_back( gridSize, gridSize );
|
|
|
|
}
|
|
|
|
|
2020-10-02 20:51:24 +00:00
|
|
|
m_grids.emplace_back( ValueFromString( EDA_UNITS::MILLIMETRES, settings.user_grid_x ),
|
|
|
|
ValueFromString( EDA_UNITS::MILLIMETRES, settings.user_grid_y ) );
|
2020-06-23 10:16:34 +00:00
|
|
|
|
2020-06-13 21:11:32 +00:00
|
|
|
OnGridChanged();
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 19:26:33 +00:00
|
|
|
void COMMON_TOOLS::SetLastUnits( EDA_UNITS aUnit )
|
|
|
|
{
|
2020-10-24 14:45:37 +00:00
|
|
|
if( EDA_UNIT_UTILS::IsImperialUnit( aUnit ) )
|
2020-10-05 19:26:33 +00:00
|
|
|
m_imperialUnit = aUnit;
|
2020-10-24 14:45:37 +00:00
|
|
|
else if( EDA_UNIT_UTILS::IsMetricUnit( aUnit ) )
|
2020-10-05 19:26:33 +00:00
|
|
|
m_metricUnit = aUnit;
|
|
|
|
else
|
|
|
|
wxASSERT_MSG( false, "Invalid unit" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-27 11:47:24 +00:00
|
|
|
int COMMON_TOOLS::SelectionTool( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
// Since selection tools are run permanently underneath the toolStack, this is really
|
|
|
|
// just a cancel of whatever other tools might be running.
|
|
|
|
|
2022-07-10 23:14:29 +00:00
|
|
|
m_toolMgr->ProcessEvent( TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL, ID_SEL_TOOL ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
2020-06-12 10:58:56 +00:00
|
|
|
VECTOR2D gridSize = getView()->GetGAL()->GetGridSize();
|
2018-10-03 16:26:33 +00:00
|
|
|
|
|
|
|
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:
|
2019-06-21 09:49:27 +00:00
|
|
|
case ACTIONS::CURSOR_RIGHT_CLICK:
|
2019-04-11 01:23:34 +00:00
|
|
|
{
|
2019-06-21 09:49:27 +00:00
|
|
|
TOOL_ACTIONS action = TA_MOUSE_CLICK;
|
|
|
|
TOOL_MOUSE_BUTTONS button = BUT_LEFT;
|
2019-04-11 01:23:34 +00:00
|
|
|
int modifiers = 0;
|
|
|
|
|
|
|
|
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
|
|
|
|
|
2019-06-21 09:49:27 +00:00
|
|
|
if( type == ACTIONS::CURSOR_DBL_CLICK )
|
2019-04-11 01:23:34 +00:00
|
|
|
action = TA_MOUSE_DBLCLICK;
|
2018-10-03 16:26:33 +00:00
|
|
|
|
2019-06-21 09:49:27 +00:00
|
|
|
if( type == ACTIONS::CURSOR_RIGHT_CLICK )
|
|
|
|
button = BUT_RIGHT;
|
|
|
|
|
|
|
|
TOOL_EVENT evt( TC_MOUSE, action, button | modifiers );
|
2021-11-22 00:43:45 +00:00
|
|
|
evt.SetParameter( static_cast<intptr_t>( type ) );
|
2019-04-11 01:23:34 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-06-21 09:49:27 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "CursorControl(): unexpected request" );
|
2018-10-03 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
2019-12-15 14:29:22 +00:00
|
|
|
getViewControls()->SetCursorPosition( cursor, true, true, type );
|
2019-07-04 20:56:21 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::refreshPreview );
|
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();
|
2020-06-12 10:58:56 +00:00
|
|
|
VECTOR2D gridSize = getView()->GetGAL()->GetGridSize() * 10;
|
2018-10-03 16:26:33 +00:00
|
|
|
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
|
|
|
{
|
2020-12-02 17:33:59 +00:00
|
|
|
double zoom = getView()->GetGAL()->GetZoomFactor();
|
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;
|
2020-06-13 21:09:02 +00:00
|
|
|
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
|
2020-06-13 21:09:02 +00:00
|
|
|
std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
|
2018-05-25 11:59:57 +00:00
|
|
|
int idx;
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2018-05-25 11:59:57 +00:00
|
|
|
if( aDirection )
|
|
|
|
{
|
2020-06-15 15:59:09 +00:00
|
|
|
for( idx = 0; idx < int( zoomList.size() ); ++idx )
|
2018-05-25 11:59:57 +00:00
|
|
|
{
|
2020-06-13 21:09:02 +00:00
|
|
|
if( zoomList[idx] >= zoom )
|
2018-05-25 11:59:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-12 18:15:04 +00:00
|
|
|
|
2020-06-15 15:59:09 +00:00
|
|
|
if( idx >= int( zoomList.size() ) )
|
2020-06-13 21:09:02 +00:00
|
|
|
idx = (int) zoomList.size() - 1; // if we ran off the end then peg to the end
|
2018-05-25 11:59:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-15 15:59:09 +00:00
|
|
|
for( idx = int( zoomList.size() ) - 1; idx >= 0; --idx )
|
2018-05-25 11:59:57 +00:00
|
|
|
{
|
2020-06-13 21:09:02 +00:00
|
|
|
if( zoomList[idx] <= zoom )
|
2018-05-25 11:59:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-12 18:15:04 +00:00
|
|
|
|
2020-06-13 21:09:02 +00:00
|
|
|
if( idx < 0 )
|
|
|
|
idx = 0; // if we ran off the end then peg to the end
|
2018-05-25 11:59:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:33:59 +00:00
|
|
|
// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
|
2018-05-25 11:59:57 +00:00
|
|
|
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 )
|
|
|
|
{
|
2020-09-11 07:51:00 +00:00
|
|
|
return doZoomFit( ZOOM_FIT_ALL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::ZoomFitObjects( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return doZoomFit( ZOOM_FIT_OBJECTS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::doZoomFit( ZOOM_FIT_TYPE_T aFitType )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW* view = getView();
|
2019-06-13 17:28:55 +00:00
|
|
|
EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
|
2020-09-20 01:20:41 +00:00
|
|
|
EDA_DRAW_FRAME* frame = getEditFrame<EDA_DRAW_FRAME>();
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
BOX2I bBox = frame->GetDocumentExtents();
|
|
|
|
BOX2I defaultBox = canvas->GetDefaultViewBBox();
|
2019-07-20 09:53:53 +00:00
|
|
|
|
2020-09-11 07:51:00 +00:00
|
|
|
view->SetScale( 1.0 ); // The best scale will be determined later, but this initial
|
|
|
|
// value ensures all view parameters are up to date (especially
|
|
|
|
// at init time)
|
2019-06-13 17:28:55 +00:00
|
|
|
VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false );
|
2017-02-23 04:31:26 +00:00
|
|
|
|
2020-09-25 07:31:56 +00:00
|
|
|
// Currently "Zoom to Objects" is only supported in Eeschema & Pcbnew. Support for other
|
2020-09-11 07:51:00 +00:00
|
|
|
// programs in the suite can be added as needed.
|
2020-09-25 07:31:56 +00:00
|
|
|
|
2020-09-11 07:51:00 +00:00
|
|
|
if( aFitType == ZOOM_FIT_OBJECTS )
|
|
|
|
{
|
2020-09-25 07:31:56 +00:00
|
|
|
if( frame->IsType( FRAME_SCH ) || frame->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
bBox = m_frame->GetDocumentExtents( false );
|
2020-09-11 07:51:00 +00:00
|
|
|
else
|
|
|
|
aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the screen is empty then use the default view bbox
|
2020-09-25 07:31:56 +00:00
|
|
|
|
2017-02-23 04:31:26 +00:00
|
|
|
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
|
|
|
|
2020-10-19 22:51:32 +00:00
|
|
|
// if the scale isn't finite (most likely due to an empty canvas)
|
|
|
|
// simply just make sure we are centered and quit out of trying to zoom to fit
|
|
|
|
if( !std::isfinite( scale ) )
|
|
|
|
{
|
|
|
|
view->SetCenter( VECTOR2D( 0, 0 ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-19 21:16:17 +00:00
|
|
|
// Reserve enough margin to limit the amount of the view that might be obscured behind the
|
|
|
|
// infobar.
|
|
|
|
double margin_scale_factor = 1.04;
|
2018-02-13 21:19:41 +00:00
|
|
|
|
2021-06-19 21:16:17 +00:00
|
|
|
if( canvas->GetClientSize().y < 768 )
|
|
|
|
margin_scale_factor = 1.10;
|
|
|
|
|
|
|
|
if( aFitType == ZOOM_FIT_ALL )
|
2018-02-13 21:19:41 +00:00
|
|
|
{
|
2020-09-11 07:51:00 +00:00
|
|
|
// Leave a bigger margin for library editors & viewers
|
2020-09-25 07:31:56 +00:00
|
|
|
|
2020-09-11 07:51:00 +00:00
|
|
|
if( frame->IsType( FRAME_FOOTPRINT_VIEWER ) || frame->IsType( FRAME_FOOTPRINT_VIEWER_MODAL )
|
|
|
|
|| frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL ) )
|
|
|
|
{
|
2021-06-19 21:16:17 +00:00
|
|
|
margin_scale_factor = 1.30;
|
2020-09-11 07:51:00 +00:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
else if( frame->IsType( FRAME_SCH_SYMBOL_EDITOR )
|
|
|
|
|| frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
|
2020-09-11 07:51:00 +00:00
|
|
|
{
|
2021-06-19 21:16:17 +00:00
|
|
|
margin_scale_factor = 1.48;
|
2020-09-11 07:51:00 +00:00
|
|
|
}
|
2018-02-13 21:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-11 15:28:57 +00:00
|
|
|
int COMMON_TOOLS::CenterContents( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-13 17:28:55 +00:00
|
|
|
EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
|
2018-09-11 15:28:57 +00:00
|
|
|
BOX2I bBox = getModel<EDA_ITEM>()->ViewBBox();
|
|
|
|
|
|
|
|
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
|
2019-06-13 17:28:55 +00:00
|
|
|
bBox = canvas->GetDefaultViewBBox();
|
2018-09-11 15:28:57 +00:00
|
|
|
|
|
|
|
getView()->SetCenter( bBox.Centre() );
|
|
|
|
|
|
|
|
// Take scrollbars into account
|
2019-06-13 17:28:55 +00:00
|
|
|
VECTOR2D scrollbarSize = VECTOR2D( canvas->GetSize() - canvas->GetClientSize() );
|
2018-09-11 15:28:57 +00:00
|
|
|
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>();
|
2020-06-13 21:09:02 +00:00
|
|
|
return doZoomToPreset( (int) idx, false );
|
2018-05-25 11:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
|
|
|
|
int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
|
|
|
|
{
|
2020-06-13 21:09:02 +00:00
|
|
|
std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
|
2017-02-23 04:31:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-12-02 17:33:59 +00:00
|
|
|
double scale = zoomList[idx];
|
2018-05-25 11:59:57 +00:00
|
|
|
|
|
|
|
if( aCenterOnCursor )
|
|
|
|
{
|
2020-06-13 21:09:02 +00:00
|
|
|
getView()->SetScale( scale, getViewControls()->GetCursorPosition() );
|
2018-05-25 11:59:57 +00:00
|
|
|
|
|
|
|
if( getViewControls()->IsCursorWarpingEnabled() )
|
|
|
|
getViewControls()->CenterOnCursor();
|
|
|
|
}
|
|
|
|
else
|
2018-10-21 22:16:15 +00:00
|
|
|
{
|
2020-06-13 21:09:02 +00:00
|
|
|
getView()->SetScale( scale );
|
2018-10-21 22:16:15 +00:00
|
|
|
}
|
2017-02-23 04:31:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Grid control
|
|
|
|
int COMMON_TOOLS::GridNext( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-13 18:55:59 +00:00
|
|
|
if( currentGrid + 1 < int( m_grids.size() ) )
|
2020-06-12 10:58:56 +00:00
|
|
|
currentGrid++;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
return OnGridChanged();
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::GridPrev( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
if( currentGrid > 0 )
|
|
|
|
currentGrid--;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
return OnGridChanged();
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::GridPreset( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-19 17:34:02 +00:00
|
|
|
return GridPreset( aEvent.Parameter<intptr_t>() );
|
2019-04-13 17:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 17:34:02 +00:00
|
|
|
int COMMON_TOOLS::GridPreset( int idx )
|
2019-04-13 17:41:11 +00:00
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
currentGrid = std::max( 0, std::min( idx, (int) m_grids.size() - 1 ) );
|
|
|
|
|
|
|
|
return OnGridChanged();
|
|
|
|
}
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
int COMMON_TOOLS::OnGridChanged()
|
|
|
|
{
|
|
|
|
int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
2019-04-13 17:41:11 +00:00
|
|
|
|
2020-06-16 23:59:00 +00:00
|
|
|
currentGrid = std::max( 0, std::min( currentGrid, static_cast<int>( m_grids.size() ) - 1 ) );
|
|
|
|
|
2019-04-13 17:41:11 +00:00
|
|
|
// Update the combobox (if any)
|
|
|
|
wxUpdateUIEvent dummy;
|
|
|
|
m_frame->OnUpdateSelectGrid( dummy );
|
|
|
|
|
|
|
|
// Update GAL canvas from screen
|
2020-06-12 10:58:56 +00:00
|
|
|
getView()->GetGAL()->SetGridSize( m_grids[ currentGrid ] );
|
|
|
|
getView()->GetGAL()->SetGridVisibility( m_toolMgr->GetSettings()->m_Window.grid.show );
|
2019-04-13 17:41:11 +00:00
|
|
|
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|
|
|
|
|
|
|
// Put cursor on new grid
|
2019-06-13 13:34:38 +00:00
|
|
|
VECTOR2D gridCursor = getViewControls()->GetCursorPosition( true );
|
|
|
|
getViewControls()->SetCrossHairCursorPosition( gridCursor, false );
|
2020-06-12 10:58:56 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-14 15:08:47 +00:00
|
|
|
int COMMON_TOOLS::GridFast1( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return GridPreset( m_frame->config()->m_Window.grid.fast_grid_1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::GridFast2( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return GridPreset( m_frame->config()->m_Window.grid.fast_grid_2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int COMMON_TOOLS::ToggleGrid( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->SetGridVisibility( !m_frame->IsGridVisible() );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-03 23:34:23 +00:00
|
|
|
int COMMON_TOOLS::SwitchUnits( const TOOL_EVENT& aEvent )
|
2019-05-13 20:42:40 +00:00
|
|
|
{
|
2020-10-03 23:34:23 +00:00
|
|
|
EDA_UNITS newUnit = aEvent.Parameter<EDA_UNITS>();
|
2019-05-13 20:42:40 +00:00
|
|
|
|
2020-10-24 14:45:37 +00:00
|
|
|
if( EDA_UNIT_UTILS::IsMetricUnit( newUnit ) )
|
2020-10-03 23:34:23 +00:00
|
|
|
m_metricUnit = newUnit;
|
2020-10-24 14:45:37 +00:00
|
|
|
else if( EDA_UNIT_UTILS::IsImperialUnit( newUnit ) )
|
2020-10-03 23:34:23 +00:00
|
|
|
m_imperialUnit = newUnit;
|
|
|
|
else
|
|
|
|
wxASSERT_MSG( false, "Invalid unit for the frame" );
|
2019-05-13 20:42:40 +00:00
|
|
|
|
2020-10-03 23:34:23 +00:00
|
|
|
m_frame->ChangeUserUnits( newUnit );
|
2019-05-13 20:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int COMMON_TOOLS::ToggleUnits( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-10-24 14:45:37 +00:00
|
|
|
m_frame->ChangeUserUnits( EDA_UNIT_UTILS::IsImperialUnit( m_frame->GetUserUnits() ) ?
|
2020-10-03 23:34:23 +00:00
|
|
|
m_metricUnit :
|
|
|
|
m_imperialUnit );
|
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
|
2019-06-13 13:34:38 +00:00
|
|
|
if( vcSettings.m_forceCursorPosition )
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = vcSettings.m_forcedPosition;
|
|
|
|
else
|
|
|
|
m_frame->GetScreen()->m_LocalOrigin = getViewControls()->GetCursorPosition();
|
2019-05-28 14:39:14 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-17 11:55:55 +00:00
|
|
|
int COMMON_TOOLS::ToggleBoundingBoxes( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
|
|
|
|
|
|
|
|
if( canvas )
|
|
|
|
{
|
|
|
|
KIGFX::RENDER_SETTINGS* rs = canvas->GetView()->GetPainter()->GetSettings();
|
|
|
|
|
|
|
|
rs->SetDrawBoundingBoxes( !rs->GetDrawBoundingBoxes() );
|
|
|
|
|
|
|
|
canvas->GetView()->UpdateAllItems( KIGFX::ALL );
|
|
|
|
canvas->ForceRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void COMMON_TOOLS::setTransitions()
|
2017-02-20 18:10:20 +00:00
|
|
|
{
|
2022-01-17 11:55:55 +00:00
|
|
|
Go( &COMMON_TOOLS::SelectionTool, ACTIONS::selectionTool.MakeEvent() );
|
2019-06-27 11:47:24 +00:00
|
|
|
|
2018-10-03 16:26:33 +00:00
|
|
|
// Cursor control
|
2022-01-17 11:55:55 +00:00
|
|
|
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() );
|
|
|
|
Go( &COMMON_TOOLS::CursorControl, ACTIONS::showContextMenu.MakeEvent() );
|
2018-10-03 16:26:33 +00:00
|
|
|
|
|
|
|
// Pan control
|
2022-01-17 11:55:55 +00:00
|
|
|
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() );
|
2018-10-03 16:26:33 +00:00
|
|
|
|
|
|
|
// Zoom control
|
2022-01-17 11:55:55 +00:00
|
|
|
Go( &COMMON_TOOLS::ZoomRedraw, ACTIONS::zoomRedraw.MakeEvent() );
|
|
|
|
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() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomFitObjects, ACTIONS::zoomFitObjects.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ZoomPreset, ACTIONS::zoomPreset.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::CenterContents, ACTIONS::centerContents.MakeEvent() );
|
2018-09-11 15:28:57 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
// Grid control
|
2022-01-17 11:55:55 +00:00
|
|
|
Go( &COMMON_TOOLS::GridNext, ACTIONS::gridNext.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridPrev, ACTIONS::gridPrev.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridPreset, ACTIONS::gridPreset.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridFast1, ACTIONS::gridFast1.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridFast2, ACTIONS::gridFast2.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleGrid, ACTIONS::toggleGrid.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::GridProperties, ACTIONS::gridProperties.MakeEvent() );
|
2019-05-13 20:42:40 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
// Units and coordinates
|
2022-01-17 11:55:55 +00:00
|
|
|
Go( &COMMON_TOOLS::SwitchUnits, ACTIONS::inchesUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::SwitchUnits, ACTIONS::milsUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::SwitchUnits, ACTIONS::millimetersUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleUnits, ACTIONS::toggleUnits.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::TogglePolarCoords, ACTIONS::togglePolarCoords.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ResetLocalCoords, ACTIONS::resetLocalCoords.MakeEvent() );
|
2017-03-18 20:03:24 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
// Misc
|
2022-01-17 11:55:55 +00:00
|
|
|
Go( &COMMON_TOOLS::ToggleCursor, ACTIONS::toggleCursor.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleCursorStyle, ACTIONS::toggleCursorStyle.MakeEvent() );
|
|
|
|
Go( &COMMON_TOOLS::ToggleBoundingBoxes, ACTIONS::toggleBoundingBoxes.MakeEvent() );
|
2017-02-20 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|