2015-06-18 15:51:51 +00:00
|
|
|
/*
|
|
|
|
* 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 <boost/optional/optional.hpp>
|
2019-05-12 11:49:58 +00:00
|
|
|
#include <tools/pcb_tool_base.h>
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Generic tool for picking a point.
|
|
|
|
*/
|
2019-05-20 10:23:32 +00:00
|
|
|
class PCBNEW_PICKER_TOOL : public PCB_TOOL_BASE
|
2015-06-18 15:51:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-05-20 10:23:32 +00:00
|
|
|
PCBNEW_PICKER_TOOL();
|
2019-07-15 23:44:01 +00:00
|
|
|
~PCBNEW_PICKER_TOOL() override { }
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
///> Event handler types.
|
2017-09-22 15:17:38 +00:00
|
|
|
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
2019-06-25 13:01:22 +00:00
|
|
|
typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
|
2018-08-22 18:05:40 +00:00
|
|
|
typedef std::function<void(void)> CANCEL_HANDLER;
|
2018-11-21 04:10:46 +00:00
|
|
|
typedef std::function<void(const int&)> FINALIZE_HANDLER;
|
|
|
|
|
|
|
|
enum pickerEndState
|
|
|
|
{
|
|
|
|
WAIT_CANCEL,
|
|
|
|
CLICK_CANCEL,
|
2019-01-09 01:17:49 +00:00
|
|
|
END_ACTIVATE,
|
2018-11-21 04:10:46 +00:00
|
|
|
EVT_CANCEL,
|
|
|
|
EXCEPTION_CANCEL
|
|
|
|
};
|
2018-02-11 01:15:16 +00:00
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
///> @copydoc TOOL_INTERACTIVE::Reset()
|
2016-09-25 17:06:49 +00:00
|
|
|
void Reset( RESET_REASON aReason ) override {}
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
///> Main event loop.
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
2018-10-04 05:10:50 +00:00
|
|
|
/**
|
|
|
|
* Function SetLayerSet()
|
|
|
|
* Sets the tool's snap layer set
|
|
|
|
*/
|
|
|
|
inline void SetLayerSet( LSET aLayerSet ) { m_layerMask = aLayerSet; }
|
|
|
|
|
2020-10-08 11:39:51 +00:00
|
|
|
inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; }
|
2019-07-15 23:44:01 +00:00
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
/**
|
|
|
|
* 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 )
|
|
|
|
{
|
2019-07-19 16:15:23 +00:00
|
|
|
wxASSERT( !m_clickHandler );
|
2015-06-18 15:51:51 +00:00
|
|
|
m_clickHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2019-06-25 13:01:22 +00:00
|
|
|
/**
|
|
|
|
* Function SetMotionHandler()
|
|
|
|
* Sets a handler for mouse motion. Used for roll-over highlighting.
|
|
|
|
*/
|
|
|
|
inline void SetMotionHandler( MOTION_HANDLER aHandler )
|
|
|
|
{
|
|
|
|
wxASSERT( !m_motionHandler );
|
|
|
|
m_motionHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
/**
|
|
|
|
* Function SetCancelHandler()
|
|
|
|
* Sets a handler for cancel events (ESC or context-menu Cancel).
|
|
|
|
*/
|
|
|
|
inline void SetCancelHandler( CANCEL_HANDLER aHandler )
|
|
|
|
{
|
2019-07-19 16:15:23 +00:00
|
|
|
wxASSERT( !m_cancelHandler );
|
2018-08-22 18:05:40 +00:00
|
|
|
m_cancelHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2018-11-21 04:10:46 +00:00
|
|
|
/**
|
|
|
|
* Function SetFinalizeHandler()
|
|
|
|
* Sets a handler for the finalize event. Takes the state of the exit from the Main loop
|
|
|
|
*/
|
|
|
|
inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
|
|
|
|
{
|
2019-07-19 16:15:23 +00:00
|
|
|
wxASSERT( !m_finalizeHandler );
|
2018-11-21 04:10:46 +00:00
|
|
|
m_finalizeHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
private:
|
2017-07-31 12:30:51 +00:00
|
|
|
///> @copydoc TOOL_INTERACTIVE::setTransitions();
|
|
|
|
void setTransitions() override;
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
///> Reinitializes tool to its initial state.
|
|
|
|
void reset();
|
2015-07-24 08:58:47 +00:00
|
|
|
|
|
|
|
///> Applies the requested VIEW_CONTROLS settings.
|
|
|
|
void setControls();
|
2019-07-15 23:44:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///> The layer set to use for optional snapping
|
|
|
|
LSET m_layerMask;
|
2020-10-08 11:39:51 +00:00
|
|
|
KICURSOR m_cursor;
|
2019-07-15 23:44:01 +00:00
|
|
|
|
|
|
|
OPT<CLICK_HANDLER> m_clickHandler;
|
|
|
|
OPT<MOTION_HANDLER> m_motionHandler;
|
|
|
|
OPT<CANCEL_HANDLER> m_cancelHandler;
|
|
|
|
OPT<FINALIZE_HANDLER> m_finalizeHandler;
|
|
|
|
|
|
|
|
OPT<VECTOR2D> m_picked;
|
2015-06-18 15:51:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PICKER_TOOL_H */
|