KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_point_editor.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef PCB_POINT_EDITOR_H
28#define PCB_POINT_EDITOR_H
29
31#include "tool/edit_points.h"
32#include <pcbnew_settings.h>
33#include <status_popup.h>
34
35#include <memory>
36
37
39class SHAPE_POLY_SET;
40
45{
46public:
48
50 void Reset( RESET_REASON aReason ) override;
51
53 bool Init() override;
54
58 int OnSelectionChange( const TOOL_EVENT& aEvent );
59
65 bool HasPoint() { return m_editedPoint != nullptr; }
66 bool HasMidpoint() { return HasPoint() && dynamic_cast<EDIT_LINE*>( m_editedPoint ); }
67 bool HasCorner() { return HasPoint() && !HasMidpoint(); }
68
69private:
71 void setTransitions() override;
72
73 void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, const SHAPE_POLY_SET* aOutline );
74
75 std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
76
78 void updateItem( BOARD_COMMIT* aCommit );
79
81 void updatePoints();
82
84 void updateEditedPoint( const TOOL_EVENT& aEvent );
85
87 void setEditedPoint( EDIT_POINT* aPoint );
88
89 inline int getEditedPointIndex() const
90 {
91 for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
92 {
93 if( m_editedPoint == &m_editPoints->Point( i ) )
94 return i;
95 }
96
97 return wxNOT_FOUND;
98 }
99
101 inline bool isModified( const EDIT_POINT& aPoint ) const
102 {
103 return m_editedPoint == &aPoint;
104 }
105
106 void pinEditedCorner( VECTOR2I& aTopLeft, VECTOR2I& aTopRight, VECTOR2I& aBotLeft,
107 VECTOR2I& aBotRight, const VECTOR2I& aHole = { 0, 0 },
108 const VECTOR2I& aHoleSize = { 0, 0 } ) const;
109
111 void setAltConstraint( bool aEnabled );
112
115
117 static bool addCornerCondition( const SELECTION& aSelection );
118
120 static bool canAddCorner( const EDA_ITEM& aItem );
121
123 bool removeCornerCondition( const SELECTION& aSelection );
124
126 int movePoint( const TOOL_EVENT& aEvent );
127 int addCorner( const TOOL_EVENT& aEvent );
128 int removeCorner( const TOOL_EVENT& aEvent );
129 int modifiedSelection( const TOOL_EVENT& aEvent );
130
134 void editArcEndpointKeepTangent( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
135 const VECTOR2I& aStart, const VECTOR2I& aMid,
136 const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
137
141 void editArcEndpointKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
142 const VECTOR2I& aStart, const VECTOR2I& aMid,
143 const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
144
148 void editArcCenterKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
149 const VECTOR2I& aStart, const VECTOR2I& aMid,
150 const VECTOR2I& aEnd ) const;
151
155 void editArcMidKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aStart, const VECTOR2I& aEnd,
156 const VECTOR2I& aCursor ) const;
157
161 void editArcMidKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
162 const VECTOR2I& aMid, const VECTOR2I& aEnd,
163 const VECTOR2I& aCursor ) const;
164
166 int changeArcEditMode( const TOOL_EVENT& aEvent );
167
168private:
170 std::shared_ptr<EDIT_POINTS> m_editPoints;
171
174
176
178
180
181 // Alternative constraint, enabled while a modifier key is held
182 std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_altConstraint;
184
185 bool m_inPointEditorTool; // Re-entrancy guard
186
187 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
188};
189
190#endif
ARC_EDIT_MODE
Settings for arc editing.
Definition: app_settings.h:52
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
Represent a line connecting two EDIT_POINTs.
Definition: edit_points.h:223
Represent a single point that can be used for modifying items.
Definition: edit_points.h:48
Tool that displays edit points allowing to modify items by dragging the points.
int changeArcEditMode(const TOOL_EVENT &aEvent)
void pinEditedCorner(VECTOR2I &aTopLeft, VECTOR2I &aTopRight, VECTOR2I &aBotLeft, VECTOR2I &aBotRight, const VECTOR2I &aHole={ 0, 0 }, const VECTOR2I &aHoleSize={ 0, 0 }) const
Set up an alternative constraint (typically enabled upon a modifier key being pressed).
void editArcMidKeepEndpoints(PCB_SHAPE *aArc, const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move the mid point of the arc, while keeping the two endpoints.
int OnSelectionChange(const TOOL_EVENT &aEvent)
Change selection event handler.
void setAltConstraint(bool aEnabled)
Return a point that should be used as a constrainer for 45 degrees mode.
static const unsigned int COORDS_PADDING
bool removeCornerCondition(const SELECTION &aSelection)
EDIT_POINT * m_hoveredPoint
void editArcMidKeepCenter(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move the mid point of the arc, while keeping the angle.
int addCorner(const TOOL_EVENT &aEvent)
void updateItem(BOARD_COMMIT *aCommit)
Update edit points with item's points.
bool HasPoint()
Indicate the cursor is over an edit point.
EDIT_POINT m_original
Original pos for the current drag point.
EDIT_POINT get45DegConstrainer() const
Condition to display "Create corner" context menu entry.
int modifiedSelection(const TOOL_EVENT &aEvent)
void editArcEndpointKeepTangent(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move an end point of the arc, while keeping the tangent at the other endpoint.
int removeCorner(const TOOL_EVENT &aEvent)
static bool canAddCorner(const EDA_ITEM &aItem)
Condition to display "Remove corner" context menu entry.
bool Init() override
Init() is called once upon a registration of the tool.
PCB_SELECTION m_preview
int movePoint(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
void setEditedPoint(EDIT_POINT *aPoint)
void buildForPolyOutline(std::shared_ptr< EDIT_POINTS > points, const SHAPE_POLY_SET *aOutline)
EDIT_POINT m_altConstrainer
bool isModified(const EDIT_POINT &aPoint) const
ARC_EDIT_MODE m_arcEditMode
EDIT_POINT * m_editedPoint
void updateEditedPoint(const TOOL_EVENT &aEvent)
Set the current point being edited. NULL means none.
std::shared_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_altConstraint
int getEditedPointIndex() const
Return true if aPoint is the currently modified point.
void updatePoints()
Update which point is being edited.
void editArcCenterKeepEndpoints(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) const
Move the arc center but keep endpoint locations.
static bool addCornerCondition(const SELECTION &aSelection)
Determine if the tool can currently add a corner to the given item.
void setTransitions() override
< Set up handlers for various events.
std::shared_ptr< EDIT_POINTS > m_editPoints
std::shared_ptr< EDIT_POINTS > makePoints(EDA_ITEM *aItem)
Update item's points with edit points.
void editArcEndpointKeepCenter(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move an end point of the arc around the circumference.
PCB_SELECTION_TOOL * m_selectionTool
The selection tool: currently supports:
Represent a set of closed polygons.
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
void Reset() override