2015-06-18 15:51:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2019-05-20 10:23:32 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-06-18 15:51:51 +00:00
|
|
|
*
|
|
|
|
* 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-07-15 23:44:01 +00:00
|
|
|
#ifndef PICKER_TOOL_H
|
|
|
|
#define PICKER_TOOL_H
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
#include <boost/optional/optional.hpp>
|
2019-07-15 23:44:01 +00:00
|
|
|
#include <math/vector2d.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <tool/tool_interactive.h>
|
2020-10-08 00:50:28 +00:00
|
|
|
#include <cursors.h>
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
class EDA_DRAW_FRAME;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
class PICKER_TOOL : public TOOL_INTERACTIVE
|
2015-06-18 15:51:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-07-15 23:44:01 +00:00
|
|
|
PICKER_TOOL();
|
|
|
|
~PICKER_TOOL() {}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
2019-07-15 23:44:01 +00:00
|
|
|
void Reset( RESET_REASON aReason ) 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 14:12:40 +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
|
|
|
///> Main event loop.
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
2020-10-08 00:50:28 +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-15 23:44:01 +00:00
|
|
|
wxASSERT( !m_clickHandler );
|
2015-06-18 15:51:51 +00:00
|
|
|
m_clickHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2019-06-25 14:12:40 +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-15 23:44:01 +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-15 23:44:01 +00:00
|
|
|
wxASSERT( !m_finalizeHandler );
|
2018-11-21 04:10:46 +00:00
|
|
|
m_finalizeHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
private:
|
|
|
|
///> Reinitializes tool to its initial state.
|
|
|
|
void resetPicker();
|
|
|
|
|
|
|
|
///> Applies the requested VIEW_CONTROLS settings.
|
|
|
|
void setControls();
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
///> @copydoc TOOL_INTERACTIVE::setTransitions();
|
|
|
|
void setTransitions() override;
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-08 00:50:28 +00:00
|
|
|
EDA_DRAW_FRAME* m_frame;
|
|
|
|
KICURSOR m_cursor;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
OPT<CLICK_HANDLER> m_clickHandler;
|
|
|
|
OPT<MOTION_HANDLER> m_motionHandler;
|
|
|
|
OPT<CANCEL_HANDLER> m_cancelHandler;
|
2019-04-14 00:44:05 +00:00
|
|
|
OPT<FINALIZE_HANDLER> m_finalizeHandler;
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
OPT<VECTOR2D> m_picked;
|
2015-06-18 15:51:51 +00:00
|
|
|
};
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
#endif /* PICKER_TOOL_H */
|