2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 08:04:11 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2014-02-27 16:29:08 +00:00
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
#ifndef PCB_POINT_EDITOR_H
|
|
|
|
#define PCB_POINT_EDITOR_H
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
#include <tool/tool_interactive.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
#include "tool/edit_points.h"
|
2022-12-05 18:27:00 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2018-02-22 11:28:01 +00:00
|
|
|
#include <status_popup.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2016-06-29 15:09:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
class PCB_SELECTION_TOOL;
|
2018-02-22 11:28:01 +00:00
|
|
|
class SHAPE_POLY_SET;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tool that displays edit points allowing to modify items by dragging the points.
|
|
|
|
*/
|
2021-01-16 23:17:32 +00:00
|
|
|
class PCB_POINT_EDITOR : public PCB_TOOL_BASE
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-16 23:17:32 +00:00
|
|
|
PCB_POINT_EDITOR();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
2016-09-24 18:53:15 +00:00
|
|
|
void Reset( RESET_REASON aReason ) override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Init() override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change selection event handler.
|
|
|
|
*/
|
2015-02-14 20:28:47 +00:00
|
|
|
int OnSelectionChange( const TOOL_EVENT& aEvent );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2019-06-27 21:33:48 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Indicate the cursor is over an edit point.
|
|
|
|
*
|
|
|
|
* Used to coordinate cursor shapes with other tools.
|
2019-06-27 21:33:48 +00:00
|
|
|
*/
|
|
|
|
bool HasPoint() { return m_editedPoint != nullptr; }
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
private:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Set up handlers for various events.
|
2017-07-31 12:30:51 +00:00
|
|
|
void setTransitions() override;
|
2015-04-30 08:46:03 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, const SHAPE_POLY_SET* aOutline );
|
2018-04-03 20:26:01 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Update item's points with edit points.
|
2014-02-28 15:53:28 +00:00
|
|
|
void updateItem() const;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2018-02-22 11:28:01 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Validate a polygon and displays a popup warning if invalid.
|
|
|
|
*
|
2018-02-22 11:28:01 +00:00
|
|
|
* @param aModified is the polygon to be checked.
|
|
|
|
* @return True if polygon is valid.
|
|
|
|
*/
|
2019-07-14 12:46:59 +00:00
|
|
|
bool validatePolygon( SHAPE_POLY_SET& aModified ) const;
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Update edit points with item's points.
|
2014-07-09 14:50:31 +00:00
|
|
|
void updatePoints();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Update which point is being edited.
|
2015-08-12 08:15:45 +00:00
|
|
|
void updateEditedPoint( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Set the current point being edited. NULL means none.
|
2015-06-19 15:32:33 +00:00
|
|
|
void setEditedPoint( EDIT_POINT* aPoint );
|
|
|
|
|
2020-08-19 22:26:36 +00:00
|
|
|
inline int getEditedPointIndex() const
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
|
|
|
|
{
|
|
|
|
if( m_editedPoint == &m_editPoints->Point( i ) )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Return true if aPoint is the currently modified point.
|
2014-03-10 15:25:40 +00:00
|
|
|
inline bool isModified( const EDIT_POINT& aPoint ) const
|
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
return m_editedPoint == &aPoint;
|
2014-03-10 15:25:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 10:51:00 +00:00
|
|
|
void pinEditedCorner( VECTOR2I& aTopLeft, VECTOR2I& aTopRight, VECTOR2I& aBotLeft,
|
|
|
|
VECTOR2I& aBotRight, const VECTOR2I& aHole = { 0, 0 },
|
|
|
|
const VECTOR2I& aHoleSize = { 0, 0 } ) const;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Set up an alternative constraint (typically enabled upon a modifier key being pressed).
|
2014-03-14 14:37:55 +00:00
|
|
|
void setAltConstraint( bool aEnabled );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Return a point that should be used as a constrainer for 45 degrees mode.
|
2014-03-06 16:34:04 +00:00
|
|
|
EDIT_POINT get45DegConstrainer() const;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Condition to display "Create corner" context menu entry.
|
2015-06-19 15:32:33 +00:00
|
|
|
static bool addCornerCondition( const SELECTION& aSelection );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Determine if the tool can currently add a corner to the given item
|
2018-07-24 15:15:05 +00:00
|
|
|
static bool canAddCorner( const EDA_ITEM& aItem );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Condition to display "Remove corner" context menu entry.
|
2015-06-19 15:32:33 +00:00
|
|
|
bool removeCornerCondition( const SELECTION& aSelection );
|
2017-01-18 08:04:11 +00:00
|
|
|
|
|
|
|
/// TOOL_ACTION handlers
|
|
|
|
int addCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int removeCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int modifiedSelection( const TOOL_EVENT& aEvent );
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-01-18 22:31:48 +00:00
|
|
|
/**
|
|
|
|
* Move an end point of the arc, while keeping the tangent at the other endpoint.
|
2020-08-29 22:59:11 +00:00
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void editArcEndpointKeepTangent( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-01-18 22:31:48 +00:00
|
|
|
/**
|
|
|
|
* Move an end point of the arc around the circumference.
|
2020-08-29 22:59:11 +00:00
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void editArcEndpointKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-01-18 22:31:48 +00:00
|
|
|
/**
|
|
|
|
* Move the mid point of the arc, while keeping the two endpoints.
|
2020-08-29 22:59:11 +00:00
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void editArcMidKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCursor ) const;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-01-18 22:31:48 +00:00
|
|
|
/**
|
|
|
|
* Move the mid point of the arc, while keeping the angle.
|
2020-08-29 22:59:11 +00:00
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void editArcMidKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
|
|
|
|
const VECTOR2I& aMid, const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCursor ) const;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-12-05 18:27:00 +00:00
|
|
|
///< Change the edit method for arcs.
|
|
|
|
int changeArcEditMode( const TOOL_EVENT& aEvent );
|
2020-12-19 15:16:14 +00:00
|
|
|
|
2022-07-09 22:30:52 +00:00
|
|
|
PCB_SELECTION_TOOL* m_selectionTool;
|
|
|
|
mutable std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
|
|
|
|
std::shared_ptr<EDIT_POINTS> m_editPoints;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
EDIT_POINT* m_editedPoint;
|
|
|
|
EDIT_POINT* m_hoveredPoint;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
EDIT_POINT m_original; ///< Original position for the current drag point.
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
bool m_refill;
|
2022-12-05 18:27:00 +00:00
|
|
|
|
|
|
|
ARC_EDIT_MODE m_arcEditMode;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
// Alternative constraint, enabled while a modifier key is held
|
|
|
|
std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_altConstraint;
|
|
|
|
EDIT_POINT m_altConstrainer;
|
2021-12-11 23:57:51 +00:00
|
|
|
|
|
|
|
static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
|
2014-02-27 16:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|