19 changed files with 1176 additions and 139 deletions
-
4cvpcb/CMakeLists.txt
-
3cvpcb/cvpcb_id.h
-
2cvpcb/cvpcb_mainframe.cpp
-
37cvpcb/dialogs/dialog_display_options.cpp
-
9cvpcb/dialogs/dialog_display_options.h
-
28cvpcb/dialogs/dialog_display_options_base.cpp
-
79cvpcb/dialogs/dialog_display_options_base.fbp
-
12cvpcb/dialogs/dialog_display_options_base.h
-
161cvpcb/display_footprints_frame.cpp
-
28cvpcb/display_footprints_frame.h
-
65cvpcb/tools/cvpcb_actions.cpp
-
86cvpcb/tools/cvpcb_actions.h
-
288cvpcb/tools/cvpcb_control.cpp
-
78cvpcb/tools/cvpcb_control.h
-
290cvpcb/tools/cvpcb_selection_tool.cpp
-
99cvpcb/tools/cvpcb_selection_tool.h
-
33pcbnew/pcb_base_frame.cpp
-
10pcbnew/pcb_painter.cpp
-
3pcbnew/pcb_painter.h
@ -0,0 +1,65 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2013-2016 CERN |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tool/common_tools.h>
|
|||
#include <tool/zoom_tool.h>
|
|||
|
|||
#include "cvpcb_actions.h"
|
|||
#include "cvpcb_control.h"
|
|||
#include "cvpcb_selection_tool.h"
|
|||
#include <cvpcb_id.h>
|
|||
|
|||
|
|||
void CVPCB_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager ) |
|||
{ |
|||
aToolManager->RegisterTool( new COMMON_TOOLS ); |
|||
aToolManager->RegisterTool( new ZOOM_TOOL ); |
|||
aToolManager->RegisterTool( new CVPCB_SELECTION_TOOL ); |
|||
aToolManager->RegisterTool( new CVPCB_CONTROL ); |
|||
} |
|||
|
|||
OPT<TOOL_EVENT> CVPCB_ACTIONS::TranslateLegacyId( int aId ) |
|||
{ |
|||
switch( aId ) |
|||
{ |
|||
case ID_ZOOM_IN: // toolbar button "Zoom In"
|
|||
case ID_VIEWER_ZOOM_IN: |
|||
return ACTIONS::zoomInCenter.MakeEvent(); |
|||
|
|||
case ID_ZOOM_OUT: // toolbar button "Zoom In"
|
|||
case ID_VIEWER_ZOOM_OUT: |
|||
return ACTIONS::zoomOutCenter.MakeEvent(); |
|||
|
|||
case ID_ZOOM_PAGE: // toolbar button "Fit on Screen"
|
|||
case ID_VIEWER_ZOOM_PAGE: |
|||
return ACTIONS::zoomFitScreen.MakeEvent(); |
|||
|
|||
case ID_ZOOM_SELECTION: |
|||
return ACTIONS::zoomTool.MakeEvent(); |
|||
|
|||
} |
|||
|
|||
return OPT<TOOL_EVENT>(); |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2013-2016 CERN |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* @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 |
|||
*/ |
|||
|
|||
#ifndef CVPCB_ACTIONS_H |
|||
#define CVPCB_ACTIONS_H |
|||
|
|||
#include <tool/tool_action.h> |
|||
#include <tool/actions.h> |
|||
#include <core/optional.h> |
|||
|
|||
class TOOL_EVENT; |
|||
class TOOL_MANAGER; |
|||
|
|||
/** |
|||
* Class CVPCB_ACTIONS |
|||
* |
|||
* Gathers all the actions that are shared by tools. The instance of CVPCB_ACTIONS is created |
|||
* inside of ACTION_MANAGER object that registers the actions. |
|||
*/ |
|||
class CVPCB_ACTIONS : public ACTIONS |
|||
{ |
|||
public: |
|||
// Selection Tool |
|||
/// Activation of the selection tool |
|||
static TOOL_ACTION selectionActivate; |
|||
|
|||
static TOOL_ACTION measureTool; |
|||
|
|||
/// Cursor control with keyboard |
|||
static TOOL_ACTION cursorUp; |
|||
static TOOL_ACTION cursorDown; |
|||
static TOOL_ACTION cursorLeft; |
|||
static TOOL_ACTION cursorRight; |
|||
|
|||
static TOOL_ACTION cursorUpFast; |
|||
static TOOL_ACTION cursorDownFast; |
|||
static TOOL_ACTION cursorLeftFast; |
|||
static TOOL_ACTION cursorRightFast; |
|||
|
|||
static TOOL_ACTION cursorClick; |
|||
|
|||
// Panning with keyboard |
|||
static TOOL_ACTION panUp; |
|||
static TOOL_ACTION panDown; |
|||
static TOOL_ACTION panLeft; |
|||
static TOOL_ACTION panRight; |
|||
|
|||
// Miscellaneous |
|||
static TOOL_ACTION zoomTool; |
|||
static TOOL_ACTION resetCoords; |
|||
static TOOL_ACTION switchCursor; |
|||
static TOOL_ACTION switchUnits; |
|||
static TOOL_ACTION showHelp; |
|||
static TOOL_ACTION toBeDone; |
|||
|
|||
|
|||
///> @copydoc COMMON_ACTIONS::TranslateLegacyId() |
|||
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override; |
|||
|
|||
///> @copydoc COMMON_ACTIONS::RegisterAllTools() |
|||
virtual void RegisterAllTools( TOOL_MANAGER* aToolManager ) override; |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,288 @@ |
|||
/*
|
|||
* 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> |
|||
* Copyright (C) 2007-2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
#include <cstdint>
|
|||
|
|||
#include <view/view.h>
|
|||
#include "cvpcb_actions.h"
|
|||
#include "cvpcb_control.h"
|
|||
|
|||
#include <class_board.h>
|
|||
|
|||
#include <hotkeys.h>
|
|||
#include <properties.h>
|
|||
|
|||
#include <cvpcb_id.h>
|
|||
#include <tool/tool_manager.h>
|
|||
//#include <gal/graphics_abstraction_layer.h>
|
|||
#include <view/view_controls.h>
|
|||
//#include <pcb_painter.h>
|
|||
#include <tools/grid_helper.h> // from pcbnew
|
|||
|
|||
#include <functional>
|
|||
using namespace std::placeholders; |
|||
|
|||
// Cursor control
|
|||
TOOL_ACTION CVPCB_ACTIONS::cursorUp( "cvpcb.Control.cursorUp", |
|||
AS_GLOBAL, WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorDown( "cvpcb.Control.cursorDown", |
|||
AS_GLOBAL, WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorLeft( "cvpcb.Control.cursorLeft", |
|||
AS_GLOBAL, WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorRight( "cvpcb.Control.cursorRight", |
|||
AS_GLOBAL, WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT ); |
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::cursorUpFast( "cvpcb.Control.cursorUpFast", |
|||
AS_GLOBAL, MD_CTRL + WXK_UP, "", "", NULL, AF_NONE, (void*) ( CURSOR_UP | CURSOR_FAST_MOVE ) ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorDownFast( "cvpcb.Control.cursorDownFast", |
|||
AS_GLOBAL, MD_CTRL + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) ( CURSOR_DOWN | CURSOR_FAST_MOVE ) ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorLeftFast( "cvpcb.Control.cursorLeftFast", |
|||
AS_GLOBAL, MD_CTRL + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_LEFT | CURSOR_FAST_MOVE ) ); |
|||
TOOL_ACTION CVPCB_ACTIONS::cursorRightFast( "cvpcb.Control.cursorRightFast", |
|||
AS_GLOBAL, MD_CTRL + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) ( CURSOR_RIGHT | CURSOR_FAST_MOVE ) ); |
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::cursorClick( "cvpcb.Control.cursorClick", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LEFT_CLICK ), |
|||
"", "", NULL, AF_NONE, (void*) CURSOR_CLICK ); |
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::panUp( "cvpcb.Control.panUp", |
|||
AS_GLOBAL, MD_SHIFT + WXK_UP, "", "", NULL, AF_NONE, (void*) CURSOR_UP ); |
|||
TOOL_ACTION CVPCB_ACTIONS::panDown( "cvpcb.Control.panDown", |
|||
AS_GLOBAL, MD_SHIFT + WXK_DOWN, "", "" , NULL, AF_NONE, (void*) CURSOR_DOWN ); |
|||
TOOL_ACTION CVPCB_ACTIONS::panLeft( "cvpcb.Control.panLeft", |
|||
AS_GLOBAL, MD_SHIFT + WXK_LEFT, "", "" , NULL, AF_NONE, (void*) CURSOR_LEFT ); |
|||
TOOL_ACTION CVPCB_ACTIONS::panRight( "cvpcb.Control.panRight", |
|||
AS_GLOBAL, MD_SHIFT + WXK_RIGHT, "", "" , NULL, AF_NONE, (void*) CURSOR_RIGHT ); |
|||
|
|||
// Miscellaneous
|
|||
TOOL_ACTION CVPCB_ACTIONS::resetCoords( "cvpcb.Control.resetCoords", |
|||
AS_GLOBAL, ' ',//TOOL_ACTION::LegacyHotKey( HK_RESET_LOCAL_COORD ),
|
|||
"", "" ); |
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::switchCursor( "cvpcb.Control.switchCursor", |
|||
AS_GLOBAL, 0, |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::switchUnits( "cvpcb.Control.switchUnits", |
|||
AS_GLOBAL, 'U',//TOOL_ACTION::LegacyHotKey( HK_SWITCH_UNITS ),
|
|||
"", "" ); |
|||
|
|||
CVPCB_CONTROL::CVPCB_CONTROL() : |
|||
TOOL_INTERACTIVE( "cvpcb.Control" ), m_frame( NULL ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
CVPCB_CONTROL::~CVPCB_CONTROL() |
|||
{ |
|||
} |
|||
|
|||
|
|||
void CVPCB_CONTROL::Reset( RESET_REASON aReason ) |
|||
{ |
|||
m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>(); |
|||
} |
|||
|
|||
|
|||
// Cursor control
|
|||
int CVPCB_CONTROL::CursorControl( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
long type = aEvent.Parameter<intptr_t>(); |
|||
bool fastMove = type & CVPCB_ACTIONS::CURSOR_FAST_MOVE; |
|||
type &= ~CVPCB_ACTIONS::CURSOR_FAST_MOVE; |
|||
bool mirroredX = getView()->IsMirroredX(); |
|||
|
|||
GRID_HELPER gridHelper( m_frame ); |
|||
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( true ); |
|||
VECTOR2I gridSize = gridHelper.GetGrid(); |
|||
|
|||
if( fastMove ) |
|||
gridSize = gridSize * 10; |
|||
|
|||
switch( type ) |
|||
{ |
|||
case CVPCB_ACTIONS::CURSOR_UP: |
|||
cursor -= VECTOR2D( 0, gridSize.y ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_DOWN: |
|||
cursor += VECTOR2D( 0, gridSize.y ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_LEFT: |
|||
cursor -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_RIGHT: |
|||
cursor += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_CLICK: // fall through
|
|||
case CVPCB_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 == CVPCB_ACTIONS::CURSOR_CLICK ) |
|||
action = TA_MOUSE_CLICK; |
|||
else if( type == CVPCB_ACTIONS::CURSOR_DBL_CLICK ) |
|||
action = TA_MOUSE_DBLCLICK; |
|||
else |
|||
wxFAIL; |
|||
|
|||
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers ); |
|||
evt.SetMousePosition( getViewControls()->GetCursorPosition() ); |
|||
m_toolMgr->ProcessEvent( evt ); |
|||
|
|||
return 0; |
|||
} |
|||
break; |
|||
} |
|||
|
|||
getViewControls()->SetCursorPosition( cursor ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int CVPCB_CONTROL::PanControl( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
long type = aEvent.Parameter<intptr_t>(); |
|||
KIGFX::VIEW* view = getView(); |
|||
GRID_HELPER gridHelper( m_frame ); |
|||
VECTOR2D center = view->GetCenter(); |
|||
VECTOR2I gridSize = gridHelper.GetGrid() * 10; |
|||
bool mirroredX = view->IsMirroredX(); |
|||
|
|||
switch( type ) |
|||
{ |
|||
case CVPCB_ACTIONS::CURSOR_UP: |
|||
center -= VECTOR2D( 0, gridSize.y ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_DOWN: |
|||
center += VECTOR2D( 0, gridSize.y ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_LEFT: |
|||
center -= VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 ); |
|||
break; |
|||
|
|||
case CVPCB_ACTIONS::CURSOR_RIGHT: |
|||
center += VECTOR2D( mirroredX ? -gridSize.x : gridSize.x, 0 ); |
|||
break; |
|||
|
|||
default: |
|||
wxFAIL; |
|||
break; |
|||
} |
|||
|
|||
view->SetCenter( center ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
// Miscellaneous
|
|||
int CVPCB_CONTROL::ResetCoords( 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; |
|||
} |
|||
|
|||
|
|||
int CVPCB_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
auto& galOpts = m_frame->GetGalDisplayOptions(); |
|||
|
|||
galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor; |
|||
galOpts.NotifyChanged(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int CVPCB_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
// TODO should not it be refactored to pcb_frame member function?
|
|||
wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); |
|||
|
|||
if( m_frame->GetUserUnits() == INCHES ) |
|||
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM ); |
|||
else |
|||
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH ); |
|||
|
|||
m_frame->ProcessEvent( evt ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void CVPCB_CONTROL::setTransitions() |
|||
{ |
|||
// Cursor control
|
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorUp.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorDown.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorLeft.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorRight.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorUpFast.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorDownFast.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorLeftFast.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorRightFast.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::CursorControl, CVPCB_ACTIONS::cursorClick.MakeEvent() ); |
|||
|
|||
// Pan control
|
|||
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panUp.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panDown.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panLeft.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::PanControl, CVPCB_ACTIONS::panRight.MakeEvent() ); |
|||
|
|||
// Miscellaneous
|
|||
Go( &CVPCB_CONTROL::ResetCoords, CVPCB_ACTIONS::resetCoords.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::SwitchCursor, CVPCB_ACTIONS::switchCursor.MakeEvent() ); |
|||
Go( &CVPCB_CONTROL::SwitchUnits, CVPCB_ACTIONS::switchUnits.MakeEvent() ); |
|||
} |
|||
|
|||
/*
|
|||
void CVPCB_CONTROL::updateGrid() |
|||
{ |
|||
BASE_SCREEN* screen = m_frame->GetScreen(); |
|||
//GRID_TYPE grid = screen->GetGrid( idx );
|
|||
getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); |
|||
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); |
|||
} |
|||
*/ |
|||
@ -0,0 +1,78 @@ |
|||
/* |
|||
* 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> |
|||
* Copyright (C) 2007-2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
#ifndef CVPCB_CONTROL_H |
|||
#define CVPCB_CONTROL_H |
|||
|
|||
#include <tool/tool_interactive.h> |
|||
#include <display_footprints_frame.h> |
|||
|
|||
namespace KIGFX { |
|||
class ORIGIN_VIEWITEM; |
|||
} |
|||
|
|||
/** |
|||
* Class CVPCB_CONTROL |
|||
* |
|||
* Handles actions in cvpcb display frame. |
|||
*/ |
|||
|
|||
class CVPCB_CONTROL : public TOOL_INTERACTIVE |
|||
{ |
|||
public: |
|||
CVPCB_CONTROL(); |
|||
~CVPCB_CONTROL(); |
|||
|
|||
/// @copydoc TOOL_INTERACTIVE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
int CursorControl( const TOOL_EVENT& aEvent ); |
|||
int PanControl( const TOOL_EVENT& aEvent ); |
|||
|
|||
// Miscellaneous |
|||
int ResetCoords( const TOOL_EVENT& aEvent ); |
|||
int SwitchCursor( const TOOL_EVENT& aEvent ); |
|||
int SwitchUnits( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Sets up handlers for various events. |
|||
void setTransitions() override; |
|||
|
|||
private: |
|||
///> Pointer to the currently used edit/draw frame. |
|||
DISPLAY_FOOTPRINTS_FRAME* m_frame; |
|||
|
|||
///> Grid origin marker. |
|||
std::unique_ptr<KIGFX::ORIGIN_VIEWITEM> m_gridOrigin; |
|||
|
|||
///> Applies the legacy canvas grid settings for GAL. |
|||
void updateGrid(); |
|||
|
|||
KIGFX::VIEW* view() |
|||
{ |
|||
return m_frame->GetGalCanvas()->GetView(); |
|||
} |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,290 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <limits>
|
|||
|
|||
#include <functional>
|
|||
using namespace std::placeholders; |
|||
|
|||
#include <class_draw_panel_gal.h>
|
|||
#include <view/view.h>
|
|||
#include <hotkeys.h>
|
|||
|
|||
#include <tool/tool_event.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <preview_items/ruler_item.h>
|
|||
|
|||
#include <cvpcb_id.h>
|
|||
|
|||
#include "cvpcb_selection_tool.h"
|
|||
#include "cvpcb_actions.h"
|
|||
|
|||
// Selection tool actions
|
|||
TOOL_ACTION CVPCB_ACTIONS::selectionActivate( "cvpcb.InteractiveSelection", |
|||
AS_GLOBAL, 0, |
|||
"", "", NULL, AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere
|
|||
|
|||
|
|||
TOOL_ACTION CVPCB_ACTIONS::measureTool( "cvpcb.InteractiveSelection.measureTool", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_MEASURE_TOOL ), |
|||
_( "Measure Tool" ), _( "Interactively measure distance between points" ), |
|||
nullptr, AF_ACTIVATE ); |
|||
|
|||
|
|||
CVPCB_SELECTION_TOOL::CVPCB_SELECTION_TOOL() : |
|||
TOOL_INTERACTIVE( "cvpcb.InteractiveSelection" ), |
|||
m_frame( NULL ), m_menu( *this ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
CVPCB_SELECTION_TOOL::~CVPCB_SELECTION_TOOL() |
|||
{ |
|||
getView()->Remove( &m_selection ); |
|||
} |
|||
|
|||
|
|||
bool CVPCB_SELECTION_TOOL::Init() |
|||
{ |
|||
m_menu.AddStandardSubMenus( *getEditFrame<DISPLAY_FOOTPRINTS_FRAME>() ); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
void CVPCB_SELECTION_TOOL::Reset( RESET_REASON aReason ) |
|||
{ |
|||
m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>(); |
|||
} |
|||
|
|||
|
|||
int CVPCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
// Main loop: keep receiving events
|
|||
while( OPT_TOOL_EVENT evt = Wait() ) |
|||
{ |
|||
// This is kind of hacky: activate RMB drag on any event.
|
|||
// There doesn't seem to be any other good way to tell when another tool
|
|||
// is canceled and control returns to the selection tool, except by the
|
|||
// fact that the selection tool starts to get events again.
|
|||
if( m_frame->GetToolId() == ID_NO_TOOL_SELECTED) |
|||
{ |
|||
getViewControls()->SetAdditionalPanButtons( false, true ); |
|||
} |
|||
|
|||
// Disable RMB pan for other tools; they can re-enable if desired
|
|||
if( evt->IsActivate() ) |
|||
{ |
|||
getViewControls()->SetAdditionalPanButtons( false, false ); |
|||
} |
|||
|
|||
// single click? Select single object
|
|||
if( evt->IsClick( BUT_LEFT ) ) |
|||
{ |
|||
clearSelection(); |
|||
} |
|||
|
|||
// right click? if there is any object - show the context menu
|
|||
else if( evt->IsClick( BUT_RIGHT ) ) |
|||
{ |
|||
m_menu.ShowContextMenu( m_selection ); |
|||
} |
|||
|
|||
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE ) |
|||
{ |
|||
clearSelection(); |
|||
} |
|||
|
|||
else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) |
|||
{ |
|||
m_menu.CloseContextMenu( evt ); |
|||
} |
|||
} |
|||
|
|||
// This tool is supposed to be active forever
|
|||
wxASSERT( false ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
SELECTION& CVPCB_SELECTION_TOOL::GetSelection() |
|||
{ |
|||
return m_selection; |
|||
} |
|||
|
|||
|
|||
void CVPCB_SELECTION_TOOL::setTransitions() |
|||
{ |
|||
Go( &CVPCB_SELECTION_TOOL::Main, CVPCB_ACTIONS::selectionActivate.MakeEvent() ); |
|||
Go( &CVPCB_SELECTION_TOOL::MeasureTool, CVPCB_ACTIONS::measureTool.MakeEvent() ); |
|||
} |
|||
|
|||
|
|||
void CVPCB_SELECTION_TOOL::zoomFitSelection( void ) |
|||
{ |
|||
//Should recalculate the view to zoom in on the selection
|
|||
auto selectionBox = m_selection.ViewBBox(); |
|||
auto canvas = m_frame->GetGalCanvas(); |
|||
auto view = getView(); |
|||
|
|||
VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false ); |
|||
|
|||
if( !( selectionBox.GetWidth() == 0 ) || !( selectionBox.GetHeight() == 0 ) ) |
|||
{ |
|||
VECTOR2D vsize = selectionBox.GetSize(); |
|||
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), |
|||
fabs( vsize.y / screenSize.y ) ); |
|||
view->SetScale( scale ); |
|||
view->SetCenter( selectionBox.Centre() ); |
|||
view->Add( &m_selection ); |
|||
} |
|||
|
|||
m_frame->GetGalCanvas()->ForceRefresh(); |
|||
} |
|||
|
|||
|
|||
int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
auto& view = *getView(); |
|||
auto& controls = *getViewControls(); |
|||
auto previous_settings = controls.GetSettings(); |
|||
|
|||
Activate(); |
|||
m_frame->SetToolID( ID_TB_MEASUREMENT_TOOL, wxCURSOR_PENCIL, |
|||
_( "Measure distance" ) ); |
|||
|
|||
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; |
|||
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() ); |
|||
|
|||
view.Add( &ruler ); |
|||
view.SetVisible( &ruler, false ); |
|||
|
|||
bool originSet = false; |
|||
|
|||
controls.ShowCursor( true ); |
|||
controls.SetSnapping( true ); |
|||
controls.SetAdditionalPanButtons( false, true ); |
|||
|
|||
while( auto evt = Wait() ) |
|||
{ |
|||
const VECTOR2I cursorPos = controls.GetCursorPosition(); |
|||
|
|||
if( evt->IsCancel() || evt->IsActivate() ) |
|||
{ |
|||
break; |
|||
} |
|||
|
|||
// click or drag starts
|
|||
else if( !originSet && |
|||
( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) |
|||
{ |
|||
if( !evt->IsDrag( BUT_LEFT ) ) |
|||
{ |
|||
twoPtMgr.SetOrigin( cursorPos ); |
|||
twoPtMgr.SetEnd( cursorPos ); |
|||
} |
|||
|
|||
controls.CaptureCursor( true ); |
|||
controls.SetAutoPan( true ); |
|||
|
|||
originSet = true; |
|||
} |
|||
|
|||
else if( !originSet && evt->IsMotion() ) |
|||
{ |
|||
// make sure the origin is set before a drag starts
|
|||
// otherwise you can miss a step
|
|||
twoPtMgr.SetOrigin( cursorPos ); |
|||
twoPtMgr.SetEnd( cursorPos ); |
|||
} |
|||
|
|||
// second click or mouse up after drag ends
|
|||
else if( originSet && |
|||
( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) |
|||
{ |
|||
originSet = false; |
|||
|
|||
controls.SetAutoPan( false ); |
|||
controls.CaptureCursor( false ); |
|||
|
|||
view.SetVisible( &ruler, false ); |
|||
} |
|||
|
|||
// move or drag when origin set updates rules
|
|||
else if( originSet && |
|||
( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) |
|||
{ |
|||
twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); |
|||
twoPtMgr.SetEnd( cursorPos ); |
|||
|
|||
view.SetVisible( &ruler, true ); |
|||
view.Update( &ruler, KIGFX::GEOMETRY ); |
|||
} |
|||
|
|||
else if( evt->IsClick( BUT_RIGHT ) ) |
|||
{ |
|||
m_menu.ShowContextMenu( m_selection ); |
|||
} |
|||
} |
|||
|
|||
view.SetVisible( &ruler, false ); |
|||
view.Remove( &ruler ); |
|||
|
|||
controls.ApplySettings( previous_settings ); |
|||
|
|||
m_frame->SetNoToolSelected(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
const BOX2I SELECTION::ViewBBox() const |
|||
{ |
|||
EDA_RECT eda_bbox; |
|||
|
|||
if( Size() == 1 ) |
|||
{ |
|||
eda_bbox = Front()->GetBoundingBox(); |
|||
} |
|||
else if( Size() > 1 ) |
|||
{ |
|||
eda_bbox = Front()->GetBoundingBox(); |
|||
auto i = m_items.begin(); |
|||
++i; |
|||
|
|||
for( ; i != m_items.end(); ++i ) |
|||
{ |
|||
eda_bbox.Merge( (*i)->GetBoundingBox() ); |
|||
} |
|||
} |
|||
|
|||
return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() ); |
|||
} |
|||
|
|||
|
|||
const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const |
|||
{ |
|||
std::vector<VIEW_ITEM*> items; |
|||
|
|||
for( auto item : m_items ) |
|||
items.push_back( item ); |
|||
|
|||
return items; |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 3 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, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef CVPCB_SELECTION_TOOL_H |
|||
#define CVPCB_SELECTION_TOOL_H |
|||
|
|||
|
|||
#include <tool/tool_interactive.h> |
|||
#include <tool/context_menu.h> |
|||
#include <tool/selection.h> |
|||
#include <tool/selection_conditions.h> |
|||
#include <tool/tool_menu.h> |
|||
|
|||
#include <display_footprints_frame.h> |
|||
|
|||
class SELECTION_AREA; |
|||
class GERBER_COLLECTOR; |
|||
|
|||
namespace KIGFX |
|||
{ |
|||
class GAL; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Class CVPCB_SELECTION_TOOL |
|||
* |
|||
* Selection tool for GerbView, based on the one in PcbNew |
|||
*/ |
|||
class CVPCB_SELECTION_TOOL : public TOOL_INTERACTIVE |
|||
{ |
|||
public: |
|||
CVPCB_SELECTION_TOOL(); |
|||
~CVPCB_SELECTION_TOOL(); |
|||
|
|||
/// @copydoc TOOL_BASE::Init() |
|||
bool Init() override; |
|||
|
|||
/// @copydoc TOOL_BASE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
/** |
|||
* Function Main() |
|||
* |
|||
* The main loop. |
|||
*/ |
|||
int Main( const TOOL_EVENT& aEvent ); |
|||
|
|||
/** Returns the set of currently selected items. |
|||
*/ |
|||
SELECTION& GetSelection(); |
|||
|
|||
inline TOOL_MENU& GetToolMenu() |
|||
{ |
|||
return m_menu; |
|||
} |
|||
|
|||
/** Clears the current selection. |
|||
*/ |
|||
void clearSelection() {}; |
|||
|
|||
///> Launches a tool to measure between points |
|||
int MeasureTool( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Sets up handlers for various events. |
|||
void setTransitions() override; |
|||
|
|||
///> Zooms the screen to center and fit the current selection. |
|||
void zoomFitSelection( void ); |
|||
|
|||
private: |
|||
|
|||
/// Pointer to the parent frame. |
|||
DISPLAY_FOOTPRINTS_FRAME* m_frame; |
|||
|
|||
/// Current state of selection (not really used: no selection in display footprints frame). |
|||
SELECTION m_selection; |
|||
|
|||
/// Menu model displayed by the tool. |
|||
TOOL_MENU m_menu; |
|||
}; |
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue