2019-05-08 18:56:03 +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
|
2021-01-26 15:23:37 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-08 18:56:03 +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-05-20 10:23:32 +00:00
|
|
|
#ifndef EE_POINT_EDITOR_H
|
|
|
|
#define EE_POINT_EDITOR_H
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
#include <tools/ee_tool_base.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
#include <tool/edit_points.h>
|
|
|
|
#include <tool/selection.h>
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
class EE_SELECTION_TOOL;
|
2019-05-08 18:56:03 +00:00
|
|
|
class SCH_BASE_FRAME;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tool that displays edit points allowing to modify items by dragging the points.
|
|
|
|
*/
|
2019-05-12 11:49:58 +00:00
|
|
|
class EE_POINT_EDITOR : public EE_TOOL_BASE<SCH_BASE_FRAME>
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_POINT_EDITOR();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
|
|
|
void Reset( RESET_REASON aReason ) override;
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
int Main( const TOOL_EVENT& aEvent );
|
|
|
|
|
2019-06-27 21:33:48 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Indicate the cursor is over an edit point. Used to coordinate cursor shapes with
|
2019-06-27 21:33:48 +00:00
|
|
|
* other tools.
|
|
|
|
*/
|
|
|
|
bool HasPoint() { return m_editedPoint != nullptr; }
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Set up handlers for various events.
|
2019-05-08 18:56:03 +00:00
|
|
|
void setTransitions() override;
|
|
|
|
|
|
|
|
private:
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Update item's points with edit points.
|
2020-10-30 15:15:20 +00:00
|
|
|
void updateParentItem() const;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Update edit points with item's points.
|
2019-05-08 18:56:03 +00:00
|
|
|
void updatePoints();
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Update which point is being edited.
|
2019-05-08 18:56:03 +00:00
|
|
|
void updateEditedPoint( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-10-06 17:20:07 +00:00
|
|
|
///< Clear references to the points
|
|
|
|
int clearEditedPoints( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Set the current point being edited. NULL means none.
|
2019-05-08 18:56:03 +00:00
|
|
|
void setEditedPoint( EDIT_POINT* aPoint );
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Return true if \a aPoint is the currently modified point.
|
2019-05-08 18:56:03 +00:00
|
|
|
inline bool isModified( const EDIT_POINT& aPoint ) const
|
|
|
|
{
|
|
|
|
return m_editedPoint == &aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getEditedPointIndex() const
|
|
|
|
{
|
2019-05-11 09:12:39 +00:00
|
|
|
for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( m_editedPoint == &m_editPoints->Point( i ) )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool addCornerCondition( const SELECTION& aSelection );
|
|
|
|
bool removeCornerCondition( const SELECTION& aSelection );
|
|
|
|
|
|
|
|
/// TOOL_ACTION handlers
|
|
|
|
int addCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int removeCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int modifiedSelection( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
void saveItemsToUndo();
|
|
|
|
void rollbackFromUndo();
|
|
|
|
|
|
|
|
private:
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Currently edited point, NULL if there is none.
|
2019-05-08 18:56:03 +00:00
|
|
|
EDIT_POINT* m_editedPoint;
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Currently available edit points.
|
2019-05-08 18:56:03 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> m_editPoints;
|
|
|
|
};
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
#endif // EE_POINT_EDITOR_H
|