PICKER_TOOL - generic tool for picking a point.
This commit is contained in:
parent
ac10ca40f8
commit
057bd1b886
|
@ -284,6 +284,7 @@ set( PCBNEW_CLASS_SRCS
|
|||
tools/placement_tool.cpp
|
||||
tools/common_actions.cpp
|
||||
tools/grid_helper.cpp
|
||||
tools/picker_tool.cpp
|
||||
tools/tools_common.cpp
|
||||
|
||||
tools/grid_menu.cpp
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "tools/pcbnew_control.h"
|
||||
#include "tools/module_tools.h"
|
||||
#include "tools/placement_tool.h"
|
||||
#include "tools/picker_tool.h"
|
||||
#include "tools/common_actions.h"
|
||||
|
||||
|
||||
|
@ -946,6 +947,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
|
|||
m_toolManager->RegisterTool( new PCBNEW_CONTROL );
|
||||
m_toolManager->RegisterTool( new MODULE_TOOLS );
|
||||
m_toolManager->RegisterTool( new PLACEMENT_TOOL );
|
||||
m_toolManager->RegisterTool( new PICKER_TOOL );
|
||||
|
||||
m_toolManager->GetTool<SELECTION_TOOL>()->EditModules( true );
|
||||
m_toolManager->GetTool<EDIT_TOOL>()->EditModules( true );
|
||||
|
|
|
@ -419,6 +419,8 @@ TOOL_ACTION COMMON_ACTIONS::selectionTool( "pcbnew.Control.selectionTool",
|
|||
AS_GLOBAL, 0,
|
||||
"", "", NULL, AF_ACTIVATE );
|
||||
|
||||
TOOL_ACTION COMMON_ACTIONS::pickerTool( "pcbnew.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE );
|
||||
|
||||
TOOL_ACTION COMMON_ACTIONS::resetCoords( "pcbnew.Control.resetCoords",
|
||||
AS_GLOBAL, ' ',
|
||||
"", "" );
|
||||
|
|
|
@ -267,6 +267,7 @@ public:
|
|||
|
||||
// Miscellaneous
|
||||
static TOOL_ACTION selectionTool;
|
||||
static TOOL_ACTION pickerTool;
|
||||
static TOOL_ACTION resetCoords;
|
||||
static TOOL_ACTION switchCursor;
|
||||
static TOOL_ACTION switchUnits;
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*/
|
||||
|
||||
#include "picker_tool.h"
|
||||
#include "common_actions.h"
|
||||
|
||||
#include <wxPcbStruct.h>
|
||||
#include <view/view_controls.h>
|
||||
#include <tool/tool_manager.h>
|
||||
|
||||
PICKER_TOOL::PICKER_TOOL()
|
||||
: TOOL_INTERACTIVE( "pcbnew.Picker" )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
|
||||
assert( !m_picking );
|
||||
m_picking = true;
|
||||
m_picked = boost::optional<VECTOR2D>();
|
||||
|
||||
controls->ShowCursor( m_cursorVisible );
|
||||
controls->SetSnapping( m_cursorSnapping );
|
||||
controls->SetAutoPan( m_autoPanning );
|
||||
|
||||
while( OPT_TOOL_EVENT evt = Wait() )
|
||||
{
|
||||
if( evt->IsClick( BUT_LEFT ) )
|
||||
{
|
||||
bool getNext = false;
|
||||
m_picked = controls->GetCursorPosition();
|
||||
|
||||
if( m_clickHandler )
|
||||
getNext = (*m_clickHandler)( *m_picked );
|
||||
|
||||
if( !getNext )
|
||||
break;
|
||||
}
|
||||
|
||||
else if( evt->IsCancel() || evt->IsActivate() )
|
||||
break;
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
controls->SetAutoPan( false );
|
||||
controls->SetSnapping( false );
|
||||
controls->ShowCursor( false );
|
||||
getEditFrame<PCB_BASE_FRAME>()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void PICKER_TOOL::SetTransitions()
|
||||
{
|
||||
Go( &PICKER_TOOL::Main, COMMON_ACTIONS::pickerTool.MakeEvent() );
|
||||
}
|
||||
|
||||
|
||||
void PICKER_TOOL::reset()
|
||||
{
|
||||
m_cursorSnapping = true;
|
||||
m_cursorVisible = true;
|
||||
m_autoPanning = true;
|
||||
|
||||
m_picking = false;
|
||||
m_clickHandler = boost::optional<CLICK_HANDLER>();
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015 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
|
||||
*/
|
||||
|
||||
#ifndef PICKER_TOOL_H
|
||||
#define PICKER_TOOL_H
|
||||
|
||||
#include <tool/tool_interactive.h>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
/**
|
||||
* @brief Generic tool for picking a point.
|
||||
*/
|
||||
class PICKER_TOOL : public TOOL_INTERACTIVE
|
||||
{
|
||||
public:
|
||||
PICKER_TOOL();
|
||||
~PICKER_TOOL() {}
|
||||
|
||||
///> Mouse event click handler type.
|
||||
typedef boost::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
||||
|
||||
///> @copydoc TOOL_INTERACTIVE::Reset()
|
||||
void Reset( RESET_REASON aReason ) {}
|
||||
|
||||
///> Main event loop.
|
||||
int Main( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Function SetSnapping()
|
||||
* Sets cursor snapping to grid for the period when the tool is active.
|
||||
*/
|
||||
inline void SetSnapping( bool aEnable ) { m_cursorSnapping = aEnable; }
|
||||
|
||||
/**
|
||||
* Function SetCursorVisible()
|
||||
* Sets cursor visibility for the period when the tool is active.
|
||||
*/
|
||||
inline void SetCursorVisible( bool aEnable ) { m_cursorVisible = aEnable; }
|
||||
|
||||
/**
|
||||
* Function SetAutoPanning()
|
||||
* Sets autopanning mode for the period when the tool is active.
|
||||
*/
|
||||
inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; }
|
||||
|
||||
/**
|
||||
* Function GetPoint()
|
||||
* Returns picked point.
|
||||
*/
|
||||
inline boost::optional<VECTOR2D> GetPoint() const
|
||||
{
|
||||
assert( !m_picking );
|
||||
return m_picked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function IsPicking()
|
||||
* Returns information whether the tool is still active.
|
||||
*/
|
||||
bool IsPicking() const { return m_picking; }
|
||||
|
||||
/**
|
||||
* Function SetClickHandler()
|
||||
* Sets a handler for mouse click event. Handler may decide to receive further click by
|
||||
* returning true.
|
||||
*/
|
||||
inline void SetClickHandler( CLICK_HANDLER aHandler )
|
||||
{
|
||||
assert( !m_clickHandler );
|
||||
m_clickHandler = aHandler;
|
||||
}
|
||||
|
||||
///> @copydoc TOOL_INTERACTIVE::SetTransitions();
|
||||
void SetTransitions();
|
||||
|
||||
private:
|
||||
// Tool settings.
|
||||
bool m_cursorSnapping;
|
||||
bool m_cursorVisible;
|
||||
bool m_autoPanning;
|
||||
|
||||
///> Optional mouse click event handler.
|
||||
boost::optional<CLICK_HANDLER> m_clickHandler;
|
||||
|
||||
///> Picked point (if any).
|
||||
boost::optional<VECTOR2D> m_picked;
|
||||
|
||||
///> Activity status.
|
||||
bool m_picking;
|
||||
|
||||
///> Reinitializes tool to its initial state.
|
||||
void reset();
|
||||
};
|
||||
|
||||
#endif /* PICKER_TOOL_H */
|
|
@ -27,6 +27,7 @@
|
|||
#include <tool/tool_manager.h>
|
||||
|
||||
#include <tools/selection_tool.h>
|
||||
#include <tools/picker_tool.h>
|
||||
#include <tools/edit_tool.h>
|
||||
#include <tools/drawing_tool.h>
|
||||
#include <tools/point_editor.h>
|
||||
|
@ -41,6 +42,7 @@
|
|||
void registerAllTools( TOOL_MANAGER *aToolManager )
|
||||
{
|
||||
aToolManager->RegisterTool( new SELECTION_TOOL );
|
||||
aToolManager->RegisterTool( new PICKER_TOOL );
|
||||
aToolManager->RegisterTool( new ROUTER_TOOL );
|
||||
aToolManager->RegisterTool( new LENGTH_TUNER_TOOL );
|
||||
aToolManager->RegisterTool( new EDIT_TOOL );
|
||||
|
|
Loading…
Reference in New Issue