KiCad PCB EDA Suite
Loading...
Searching...
No Matches
arc_geom_manager.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
21#define PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
22
23#include <array>
24
27#include <geometry/eda_angle.h>
28#include <tool/arc_draw_mode.h>
29
30namespace KIGFX {
31namespace PREVIEW {
32
46{
47public:
50
59
60 int getMaxStep() const override
61 {
63 }
64
70 {
71 return IsComplete() ? COMPLETE : static_cast<ARC_STEPS>( getStep() );
72 }
73
79 void Reset() override;
80
87 void SetMode( ARC_DRAW_MODE aMode );
88
89 ARC_DRAW_MODE GetMode() const { return m_mode; }
90
100 void SetTangentSeed( const VECTOR2I& aStart, const VECTOR2D& aDirection, bool aDirectionIsAxis = false );
101
104
106 bool HasPreview() const { return !IsReset() || HasTangentSeed(); }
107
108
114 void ToggleClockwise();
115
117 void SetAngleSnap( bool aSnap )
118 {
119 m_angleSnap = aSnap;
120 }
121
122 /*
123 * Geometry query interface - used by clients of the manager
124 */
125
127 VECTOR2I GetOrigin() const;
128
131
134
136 double GetRadius() const;
137
139 EDA_ANGLE GetStartAngle() const;
140
142 EDA_ANGLE GetSubtended() const;
143
146
153 const KIGEOM::ARC_SOLUTION& GetSolution() const { return m_solution; }
154
156 int GetPointIndex() const { return getStep() + ( HasTangentSeed() ? 1 : 0 ); }
157
159 const VECTOR2I& GetPoint( int aIndex ) const { return m_pts[aIndex]; }
160
162 const VECTOR2D& GetTangentDirection() const { return m_dir; }
163
169
170protected:
171 bool acceptPoint( const VECTOR2I& aPt ) override;
172
173private:
175 bool rejectRegresses() const override { return m_mode == ARC_DRAW_MODE::CENTER_START_END; }
176
178 bool acceptExactPoint( const VECTOR2I& aPt );
179
181 void applySolution( const KIGEOM::ARC_SOLUTION& aSolution );
182
184 void clearSolution();
185
187 bool setDirection( const VECTOR2I& aPt );
188
189 /*
190 * Point acceptor functions
191 */
192
194 bool setOrigin( const VECTOR2I& aOrigin );
195
197 bool setStart( const VECTOR2I& aEnd );
198
200 bool setEnd( const VECTOR2I& aCursor );
201
202 /*
203 * Arc geometry
204 */
205 bool m_clockwise = true;
207 double m_radius = 0.0;
210
211 /*
212 * construction parameters
213 */
214 bool m_angleSnap = false;
215 bool m_directionLocked = false;
216
218
220 std::array<VECTOR2I, 3> m_pts;
222 bool m_hasSeed = false;
223 bool m_seedIsAxis = false;
224 bool m_axisFlipped = false;
226 bool m_major = false;
228};
229
230} // PREVIEW
231} // KIGFX
232
233#endif // PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
ARC_DRAW_MODE
Construction sequence used when interactively drawing a circular arc.
@ TANGENT
End only; start and departure direction come from a tangent seed.
@ START_DIR_END
Start, a point giving the departure direction, then the end.
@ CENTER_START_END
Center, then start (sets radius), then sweep to the end.
VECTOR2I GetOrigin() const
Get the center point of the arc (valid when state > FIRST_POINT in center mode)
bool acceptExactPoint(const VECTOR2I &aPt)
Point acceptor for every mode that keeps the clicked endpoints.
const KIGEOM::ARC_SOLUTION & GetSolution() const
The arc as start, mid and end (never used in center mode).
void Reset() override
Reset to the initial state, ready for the next arc.
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
ARC_STEPS GetStep() const
Get the current step the manager is on (useful when drawing something depends on the current state)
int getMaxStep() const override
The highest step this manager has - used to recognize completion and to clamp the step as it advances...
const VECTOR2D & GetTangentDirection() const
The departure direction of the arc (valid once the direction is set, or seeded)
bool HasTangentSeed() const
True when the TANGENT mode is running from a seed, so its first click already sets the end.
void ToggleClockwise()
Reverse the current arc direction in center mode, or switch between the minor and major arc in START_...
EDA_ANGLE GetStartAngle() const
Get the angle of the vector leading to the start point (valid if step >= SECOND_POINT in center mode)
bool setStart(const VECTOR2I &aEnd)
Set the end of the first radius line (arc start)
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc start.
bool HasPreview() const
True when there is something to preview, which a seeded tangent has before any click.
bool acceptPoint(const VECTOR2I &aPt) override
Function that accepts a point for a stage, or rejects it to return to the previous stage.
bool setDirection(const VECTOR2I &aPt)
Set the departure direction from the second click, snapped if requested.
void SetTangentSeed(const VECTOR2I &aStart, const VECTOR2D &aDirection, bool aDirectionIsAxis=false)
Preload the start point and departure direction for ARC_DRAW_MODE::TANGENT.
int GetPointIndex() const
Index of the point the next click sets, counting a tangent seed as point 0.
bool UsesDirectionClick() const
True when a direction is part of the construction, that is START_DIR_END or an unseeded TANGENT.
bool rejectRegresses() const override
Only the center mode returns to the previous step, so a refused click in the others is ignored.
VECTOR2I GetEndRadiusEnd() const
Get the coordinates of the arc end point.
const VECTOR2I & GetPoint(int aIndex) const
A point of the construction as set so far (index 0 to 2), including the one following the cursor.
bool UsesExactEndpoints() const
True when the committed endpoints are the clicked points, described by GetSolution()
void applySolution(const KIGEOM::ARC_SOLUTION &aSolution)
Take over a valid solution as the canonical arc state.
bool setEnd(const VECTOR2I &aCursor)
Set a point of the second radius line (collinear with arc end)
void clearSolution()
Forget the solution, leaving nothing drawable.
double GetRadius() const
Get the radius of the arc (valid if step >= SECOND_POINT in center mode)
EDA_ANGLE GetSubtended() const
Get the angle of the vector leading to the end point (valid if step >= THIRD_POINT in center mode)
std::array< VECTOR2I, 3 > m_pts
The points set so far for the modes that keep the clicked endpoints, the last following the cursor.
bool setOrigin(const VECTOR2I &aOrigin)
Set the center point of the arc.
void SetMode(ARC_DRAW_MODE aMode)
Select the construction sequence.
ARC_STEPS
The point each step waits for depends on the mode, for example the origin, the start,...
@ FIRST_POINT
Waiting to lock in the first point.
@ THIRD_POINT
Waiting to lock in the third point.
@ SECOND_POINT
Waiting to lock in the second point.
A geometry manager that works by accepting a sequence of points and advancing though stages of geomet...
int getStep() const
Get the current stage of the manager.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707