2014-02-27 17:29:08 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 09:04:11 +01:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-27 17:15:38 -05:00
|
|
|
*
|
2014-02-27 17:29:08 +01: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 17:29:08 +01:00
|
|
|
|
|
|
|
#include <tool/tool_interactive.h>
|
2019-05-08 19:56:03 +01:00
|
|
|
#include "tool/edit_points.h"
|
2022-12-05 21:27:00 +03:00
|
|
|
#include <pcbnew_settings.h>
|
2018-02-22 12:28:01 +01:00
|
|
|
#include <status_popup.h>
|
2014-02-27 17:29:08 +01:00
|
|
|
|
2016-06-29 11:09:55 -04:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
class PCB_SELECTION_TOOL;
|
2024-11-02 14:35:30 +08:00
|
|
|
class POINT_EDIT_BEHAVIOR;
|
2018-02-22 12:28:01 +01:00
|
|
|
class SHAPE_POLY_SET;
|
2014-02-27 17:29:08 +01: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 17:29:08 +01:00
|
|
|
{
|
|
|
|
public:
|
2021-01-16 23:17:32 +00:00
|
|
|
PCB_POINT_EDITOR();
|
2014-02-27 17:29:08 +01:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
2016-09-24 14:53:15 -04:00
|
|
|
void Reset( RESET_REASON aReason ) override;
|
2014-02-27 17:29:08 +01:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
2016-09-24 14:53:15 -04:00
|
|
|
bool Init() override;
|
2014-02-27 17:29:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change selection event handler.
|
|
|
|
*/
|
2015-02-14 21:28:47 +01:00
|
|
|
int OnSelectionChange( const TOOL_EVENT& aEvent );
|
2014-02-27 17:29:08 +01:00
|
|
|
|
2019-06-27 22:33:48 +01:00
|
|
|
/**
|
2021-01-27 17:15:38 -05:00
|
|
|
* Indicate the cursor is over an edit point.
|
|
|
|
*
|
|
|
|
* Used to coordinate cursor shapes with other tools.
|
2019-06-27 22:33:48 +01:00
|
|
|
*/
|
2023-08-05 16:43:10 +01:00
|
|
|
bool HasPoint() { return m_editedPoint != nullptr; }
|
|
|
|
bool HasMidpoint() { return HasPoint() && dynamic_cast<EDIT_LINE*>( m_editedPoint ); }
|
|
|
|
bool HasCorner() { return HasPoint() && !HasMidpoint(); }
|
2019-06-27 22:33:48 +01:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
private:
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Set up handlers for various events.
|
2017-07-31 14:30:51 +02:00
|
|
|
void setTransitions() override;
|
2015-04-30 10:46:03 +02:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
|
2018-02-22 12:28:01 +01:00
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Update item's points with edit points.
|
2024-11-03 00:04:50 +08:00
|
|
|
void updateItem( BOARD_COMMIT& aCommit );
|
2014-02-27 17:29:08 +01:00
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Update edit points with item's points.
|
2014-07-09 16:50:31 +02:00
|
|
|
void updatePoints();
|
2014-02-27 17:29:08 +01:00
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Update which point is being edited.
|
2015-08-12 10:15:45 +02:00
|
|
|
void updateEditedPoint( const TOOL_EVENT& aEvent );
|
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Set the current point being edited. NULL means none.
|
2015-06-19 17:32:33 +02:00
|
|
|
void setEditedPoint( EDIT_POINT* aPoint );
|
|
|
|
|
2020-08-19 23:26:36 +01: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 17:15:38 -05:00
|
|
|
///< Return true if aPoint is the currently modified point.
|
2014-03-10 16:25:40 +01:00
|
|
|
inline bool isModified( const EDIT_POINT& aPoint ) const
|
|
|
|
{
|
2015-06-19 17:32:33 +02:00
|
|
|
return m_editedPoint == &aPoint;
|
2014-03-10 16:25:40 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Set up an alternative constraint (typically enabled upon a modifier key being pressed).
|
2014-03-14 15:37:55 +01:00
|
|
|
void setAltConstraint( bool aEnabled );
|
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Return a point that should be used as a constrainer for 45 degrees mode.
|
2014-03-06 17:34:04 +01:00
|
|
|
EDIT_POINT get45DegConstrainer() const;
|
|
|
|
|
2021-01-27 17:15:38 -05:00
|
|
|
///< Condition to display "Remove corner" context menu entry.
|
2015-06-19 17:32:33 +02:00
|
|
|
bool removeCornerCondition( const SELECTION& aSelection );
|
2017-01-18 09:04:11 +01:00
|
|
|
|
|
|
|
/// TOOL_ACTION handlers
|
2023-08-05 16:43:10 +01:00
|
|
|
int movePoint( const TOOL_EVENT& aEvent );
|
2017-01-18 09:04:11 +01:00
|
|
|
int addCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int removeCorner( const TOOL_EVENT& aEvent );
|
2024-10-12 22:32:49 +08:00
|
|
|
int chamferCorner( const TOOL_EVENT& aEvent );
|
2017-01-18 09:04:11 +01:00
|
|
|
int modifiedSelection( const TOOL_EVENT& aEvent );
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-12-05 21:27:00 +03:00
|
|
|
///< Change the edit method for arcs.
|
|
|
|
int changeArcEditMode( const TOOL_EVENT& aEvent );
|
2020-12-19 15:16:14 +00:00
|
|
|
|
2023-10-10 11:55:57 +01:00
|
|
|
private:
|
2024-11-06 20:38:01 -05:00
|
|
|
PCB_BASE_FRAME* m_frame;
|
2023-10-17 13:03:38 +01:00
|
|
|
PCB_SELECTION_TOOL* m_selectionTool;
|
|
|
|
std::shared_ptr<EDIT_POINTS> m_editPoints;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
2023-10-17 13:03:38 +01:00
|
|
|
EDIT_POINT* m_editedPoint;
|
|
|
|
EDIT_POINT* m_hoveredPoint;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
2023-10-17 13:03:38 +01:00
|
|
|
EDIT_POINT m_original; ///< Original pos for the current drag point.
|
2022-12-05 21:27:00 +03:00
|
|
|
|
2023-10-17 13:03:38 +01:00
|
|
|
ARC_EDIT_MODE m_arcEditMode;
|
2023-10-10 12:58:12 +01:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
PCB_SELECTION m_preview;
|
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-12 02:57:51 +03:00
|
|
|
|
2023-10-17 13:03:38 +01:00
|
|
|
bool m_inPointEditorTool; // Re-entrancy guard
|
2023-10-07 03:43:38 +03:00
|
|
|
|
2024-11-02 14:35:30 +08:00
|
|
|
// This handles the edit process for a specific tpye of item (not
|
|
|
|
// just C++ type, because PCB_SHAPE is one type that has many subtypes)
|
|
|
|
std::unique_ptr<POINT_EDIT_BEHAVIOR> m_editorBehavior;
|
|
|
|
|
2021-12-12 02:57:51 +03:00
|
|
|
static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
|
2014-02-27 17:29:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|