KiCad PCB EDA Suite
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 (C) 2017 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, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef PREVIEW_POLYGON_GEOM_MANAGER__H_
25 #define PREVIEW_POLYGON_GEOM_MANAGER__H_
26 
27 #include <vector>
28 #include <math/vector2d.h>
29 
38 {
39 public:
40 
45  class CLIENT
46  {
47  public:
55  virtual bool OnFirstPoint() = 0;
56 
58  virtual void OnGeometryChange( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
59 
61  virtual void OnComplete( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
62  };
63 
67  enum class LEADER_MODE
68  {
69  DIRECT,
70  DEG45,
71  };
72 
76  POLYGON_GEOM_MANAGER( CLIENT& aClient );
77 
81  void AddPoint( const VECTOR2I& aPt );
82 
86  void SetFinished();
87 
91  void Reset();
92 
97  void SetLeaderMode( LEADER_MODE aMode );
98 
102  void SetCursorPosition( const VECTOR2I& aPos );
103 
108  bool IsPolygonInProgress() const;
109 
114  bool NewPointClosesOutline( const VECTOR2I& aPt ) const;
115 
119  void DeleteLastCorner();
120 
121  /* =================================================================
122  * Interfaces for users of the geometry
123  */
124 
128  const std::vector<VECTOR2I>& GetLockedInPoints() const;
129 
136  const std::vector<VECTOR2I>& GetLeaderLinePoints() const;
137 
138 private:
139 
144  void updateLeaderPoints( const VECTOR2I& aEndPoint );
145 
148 
151 
153  std::vector<VECTOR2I> m_lockedPoints;
154 
156  std::vector<VECTOR2I> m_leaderPts;
157 };
158 
159 #endif // PREVIEW_POLYGON_GEOM_MANAGER__H_
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Sent when the polygon geometry changes
LEADER_MODE
The kind of the leader line.
POLYGON_GEOM_MANAGER(CLIENT &aClient)
LEADER_MODE m_leaderMode
The current mode of the leader line
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
void updateLeaderPoints(const VECTOR2I &aEndPoint)
Update the leader line points based on a new endpoint (probably a cursor position) ...
const std::vector< VECTOR2I > & GetLeaderLinePoints() const
Get the points comprising the leader line (the line from the last locked-in point to the current curs...
void SetLeaderMode(LEADER_MODE aMode)
Set the leader mode to use when calculating the leader/returner lines.
const std::vector< VECTOR2I > & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.
Unconstrained point-to-point
"Listener" interface for a class that wants to be updated about polygon geometry changes ...
void AddPoint(const VECTOR2I &aPt)
Lock in a polygon point.
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
void DeleteLastCorner()
Remove the last-added point from the polygon.
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
bool NewPointClosesOutline(const VECTOR2I &aPt) const
void Reset()
Clear the manager state and start again.
virtual bool OnFirstPoint()=0
Called before the first point is added - clients can do initialisation here, and can veto the start o...
virtual void OnComplete(const POLYGON_GEOM_MANAGER &aMgr)=0
Called when the polygon is complete
void SetCursorPosition(const VECTOR2I &aPos)
Set the current cursor position.
void SetFinished()
Mark the polygon finished and update the client.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...