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
|
2020-12-27 00:41:04 +00:00
|
|
|
* Copyright (C) 2019-2020 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
|
|
|
|
|
|
|
|
2021-01-31 14:50:19 +00:00
|
|
|
class PICKER_TOOL_BASE
|
2015-06-18 15:51:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-12-27 00:41:04 +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
|
|
|
|
2021-01-31 14:50:19 +00:00
|
|
|
PICKER_TOOL_BASE() :
|
|
|
|
m_frame( nullptr )
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; }
|
2019-07-15 23:44:01 +00:00
|
|
|
|
2021-01-31 14:50:19 +00:00
|
|
|
inline void SetSnapping( bool aSnap ) { m_snap = aSnap; }
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a handler for mouse click event.
|
|
|
|
*
|
|
|
|
* The handler may decide to receive further click by returning true.
|
2015-06-18 15:51:51 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a handler for mouse motion.
|
|
|
|
*
|
|
|
|
* This is used for roll-over highlighting.
|
2019-06-25 14:12:40 +00:00
|
|
|
*/
|
|
|
|
inline void SetMotionHandler( MOTION_HANDLER aHandler )
|
|
|
|
{
|
|
|
|
wxASSERT( !m_motionHandler );
|
|
|
|
m_motionHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
2018-08-22 18:05:40 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a handler for cancel events (ESC or context-menu Cancel).
|
2018-08-22 18:05:40 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a handler for the finalize event.
|
|
|
|
*
|
|
|
|
* Takes the state of the exit from the main loop.
|
2018-11-21 04:10:46 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-31 14:50:19 +00:00
|
|
|
protected:
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Reinitializes tool to its initial state.
|
2021-01-31 14:50:19 +00:00
|
|
|
virtual void reset();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
EDA_DRAW_FRAME* m_frame;
|
|
|
|
KICURSOR m_cursor;
|
2021-01-31 14:50:19 +00:00
|
|
|
bool m_snap;
|
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
|
|
|
};
|
|
|
|
|
2021-01-31 14:50:19 +00:00
|
|
|
|
|
|
|
class PICKER_TOOL : public TOOL_INTERACTIVE, public PICKER_TOOL_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PICKER_TOOL();
|
|
|
|
|
|
|
|
PICKER_TOOL( const std::string& aName );
|
|
|
|
|
|
|
|
virtual ~PICKER_TOOL() = default;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
|
|
|
void Reset( RESET_REASON aReason ) override { }
|
|
|
|
|
|
|
|
///< Main event loop.
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///< Applies the requested VIEW_CONTROLS settings.
|
|
|
|
void setControls();
|
|
|
|
|
|
|
|
///< @copydoc TOOL_INTERACTIVE::setTransitions();
|
|
|
|
void setTransitions() override;
|
|
|
|
};
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
#endif /* PICKER_TOOL_H */
|