KiCad PCB EDA Suite
Loading...
Searching...
No Matches
polygon_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_POLYGON_GEOM_MANAGER__H_
21#define PREVIEW_POLYGON_GEOM_MANAGER__H_
22
25
33{
34public:
35
40 class CLIENT
41 {
42 public:
50 virtual bool OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) = 0;
51
53 virtual void OnGeometryChange( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
54
56 virtual void OnComplete( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
57
58 virtual ~CLIENT()
59 {
60 }
61 };
62
66 POLYGON_GEOM_MANAGER( CLIENT& aClient );
67
71 bool AddPoint( const VECTOR2I& aPt );
72
76 void SetFinished();
77
81 void Reset();
82
86 void SetLeaderMode( LEADER_MODE aMode );
87
89 {
90 return m_leaderMode;
91 }
92
98 void AllowIntersections( bool aEnabled )
99 {
101 }
102
109 {
111 }
112
119 bool IsSelfIntersecting( bool aIncludeLeaderPts ) const;
120
124 void SetCursorPosition( const VECTOR2I& aPos );
125
130 bool IsPolygonInProgress() const;
131
132 int PolygonPointCount() const;
133
137 bool NewPointClosesOutline( const VECTOR2I& aPt ) const;
138
142 std::optional<VECTOR2I> DeleteLastCorner();
143
144 /* =================================================================
145 * Interfaces for users of the geometry
146 */
147
152 {
153 return m_lockedPoints;
154 }
155
163 {
164 return m_leaderPts;
165 }
166
172 {
173 return m_loopPts;
174 }
175
176private:
177
182 void updateTemporaryLines( const VECTOR2I& aEndPoint,
183 LEADER_MODE aModifier = LEADER_MODE::DIRECT );
184
187
190
193
196
199
202};
203
204#endif // PREVIEW_POLYGON_GEOM_MANAGER__H_
"Listener" interface for a class that wants to be updated about polygon geometry changes
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Called when the polygon is complete.
virtual bool OnFirstPoint(POLYGON_GEOM_MANAGER &aMgr)=0
Called before the first point is added - clients can do initialization here, and can veto the start o...
virtual void OnComplete(const POLYGON_GEOM_MANAGER &aMgr)=0
bool AddPoint(const VECTOR2I &aPt)
Lock in a polygon point.
void updateTemporaryLines(const VECTOR2I &aEndPoint, LEADER_MODE aModifier=LEADER_MODE::DIRECT)
Update the leader and loop lines points based on a new endpoint (probably a cursor position)
CLIENT & m_client
The current mode of the leader line.
const SHAPE_LINE_CHAIN & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.
POLYGON_GEOM_MANAGER(CLIENT &aClient)
SHAPE_LINE_CHAIN m_leaderPts
Points between the cursor and start point.
void SetCursorPosition(const VECTOR2I &aPos)
Set the current cursor position.
bool IntersectionsAllowed() const
Check whether self-intersecting polygons are enabled.
LEADER_MODE GetLeaderMode() const
void AllowIntersections(bool aEnabled)
Enables/disables self-intersecting polygons.
bool IsSelfIntersecting(bool aIncludeLeaderPts) const
Check whether the locked points constitute a self-intersecting outline.
bool NewPointClosesOutline(const VECTOR2I &aPt) const
std::optional< VECTOR2I > DeleteLastCorner()
Remove the last-added point from the polygon.
void SetFinished()
Mark the polygon finished and update the client.
void SetLeaderMode(LEADER_MODE aMode)
Set the leader mode to use when calculating the leader/returner lines.
LEADER_MODE m_leaderMode
Flag enabling self-intersecting polygons.
const SHAPE_LINE_CHAIN & GetLoopLinePoints() const
Get the points from the current cursor position to the polygon start point.
const SHAPE_LINE_CHAIN & GetLeaderLinePoints() const
Get the points comprising the leader line (the line from the last locked-in point to the current curs...
void Reset()
Clear the manager state and start again.
SHAPE_LINE_CHAIN m_lockedPoints
Points in the temporary "leader" line(s)
bool m_intersectionsAllowed
Point that have been "locked in".
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
a few functions useful in geometry calculations.
LEADER_MODE
The kind of the leader line.
@ DIRECT
Unconstrained point-to-point.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683