KiCad PCB EDA Suite
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 (C) 2017-2021 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_ITEMS_ARC_GEOMETRY_MANAGER_H
25 #define PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
26 
28 
29 namespace KIGFX {
30 namespace PREVIEW {
31 
32 
42 {
43 public:
45  {}
46 
47  enum ARC_STEPS
48  {
49  SET_ORIGIN = 0,
53  };
54 
55  int getMaxStep() const override
56  {
57  return COMPLETE;
58  }
59 
65  {
66  return static_cast<ARC_STEPS>( getStep() );
67  }
68 
69  bool acceptPoint( const VECTOR2I& aPt ) override;
70 
72  void SetClockwise( bool aCw );
73 
75  void ToggleClockwise();
76 
78  void SetAngleSnap( bool aSnap )
79  {
80  m_angleSnap = aSnap;
81  }
82 
83  /*
84  * Geometry query interface - used by clients of the manager
85  */
86 
88  VECTOR2I GetOrigin() const;
89 
92 
94  VECTOR2I GetEndRadiusEnd() const;
95 
97  double GetRadius() const;
98 
100  double GetStartAngle() const;
101 
103  double GetSubtended() const;
104 
105 private:
106 
107  /*
108  * Point acceptor functions
109  */
110 
112  bool setOrigin( const VECTOR2I& aOrigin );
113 
115  bool setStart( const VECTOR2I& aEnd );
116 
118  bool setEnd( const VECTOR2I& aCursor );
119 
120  /*
121  * Arc geometry
122  */
123  bool m_clockwise = true;
125  double m_radius = 0.0;
126  double m_startAngle = 0.0;
127  double m_endAngle = 0.0;
128 
129  /*
130  * construction parameters
131  */
132  bool m_angleSnap = false;
133  bool m_directionLocked = false;
134 };
135 } // PREVIEW
136 } // KIGFX
137 
138 #endif // PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
Manage the construction of a circular arc though sequential setting of critical points: center,...
VECTOR2I GetEndRadiusEnd() const
Get the radius of the arc (valid if step >= SET_START)
bool setEnd(const VECTOR2I &aCursor)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:191
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc end point.
double GetStartAngle() const
Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE)
A geometry manager that works by accepting a sequence of points and advancing though stages of geomet...
Waiting to lock in the arc start point.
VECTOR2I GetOrigin() const
< Get the center point of the arc (valid when state > SET_ORIGIN)
Waiting to lock in origin point.
double GetRadius() const
Get the angle of the vector leading to the start point (valid if step >= SET_START)
bool setStart(const VECTOR2I &aEnd)
Set a point of the second radius line (collinear with arc end)
Waiting to lock in the arc end point.
bool acceptPoint(const VECTOR2I &aPt) override
The arc to be clockwise from start.
void ToggleClockwise()
Set angle snapping (for the next point)
void SetClockwise(bool aCw)
Reverse the current are direction.
ARC_STEPS GetStep() const
Get the current step the manager is on (useful when drawing something depends on the current state)
bool setOrigin(const VECTOR2I &aOrigin)
< Set the center point of the arc
int getMaxStep() const override
The highest step this manager has - used to recognize completion and to clamp the step as it advances...