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 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 #include <common.h>
30 
31 namespace KIGFX {
32 namespace PREVIEW {
33 
34 
48 {
49 public:
51  {}
52 
53  enum ARC_STEPS
54  {
55  SET_ORIGIN = 0,
59  };
60 
61 
62  int getMaxStep() const override
63  {
64  return COMPLETE;
65  }
66 
72  {
73  return static_cast<ARC_STEPS>( getStep() );
74  }
75 
76  bool acceptPoint( const VECTOR2I& aPt ) override;
77 
79  void SetClockwise( bool aCw );
80 
82  void ToggleClockwise();
83 
85  void SetAngleSnap( bool aSnap )
86  {
87  m_angleSnap = aSnap;
88  }
89 
90  /*
91  * Geometry query interface - used by clients of the manager
92  */
93 
95  VECTOR2I GetOrigin() const;
96 
99 
101  VECTOR2I GetEndRadiusEnd() const;
102 
104  double GetRadius() const;
105 
107  double GetStartAngle() const;
108 
110  double GetSubtended() const;
111 
112 private:
113 
114  /*
115  * Point acceptor functions
116  */
117 
119  bool setOrigin( const VECTOR2I& aOrigin );
120 
122  bool setStart( const VECTOR2I& aEnd );
123 
125  bool setEnd( const VECTOR2I& aCursor );
126 
127  /*
128  * Arc geometry
129  */
130  bool m_clockwise = true;
132  double m_radius = 0.0;
133  double m_startAngle = 0.0;
134  double m_endAngle = 0.0;
135 
136  /*
137  * construction parameters
138  */
140 };
141 } // PREVIEW
142 } // KIGFX
143 
144 #endif // PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
Waiting to lock in the arc end point
Class ARC_GEOM_MANAGER.
bool setEnd(const VECTOR2I &aCursor)
Set a point of the second radius line (collinear with arc end)
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
double GetRadius() const
Get the radius of the arc (valid if step >= SET_START)
A geometry manager that works by accepting a sequence of points and advancing though stages of geomet...
VECTOR2I GetEndRadiusEnd() const
Get the coordinates of the arc end point
Waiting to lock in origin point
int getStep() const
Get the current stage of the manager
double GetSubtended() const
Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE) ...
bool setStart(const VECTOR2I &aEnd)
Set the end of the first radius line (arc start)
Waiting to lock in the arc start point
bool acceptPoint(const VECTOR2I &aPt) override
Function that accepts a point for a stage, or rejects it to return to the previous stage ...
void ToggleClockwise()
Reverse the current are direction
void SetClockwise(bool aCw)
The the arc to be clockwise from start
The common library.
bool setOrigin(const VECTOR2I &aOrigin)
Set the centre point of the arc
double GetStartAngle() const
Get the angle of the vector leading to the start point (valid if step >= SET_START) ...
void SetAngleSnap(bool aSnap)
Set angle snapping (for the next point)
VECTOR2I GetOrigin() const
Get the centre point of the arc (valid when state > SET_ORIGIN)
ARC_STEPS GetStep() const
Get the current step the mananger is on (useful when drawing something depends on the current state) ...
int getMaxStep() const override
The highest step this manager has - used to recognise completion and to clamp the step as it advances...
VECTOR2I GetStartRadiusEnd() const
Get the coordinates of the arc start