KiCad PCB EDA Suite
KIGFX::PREVIEW::ARC_GEOM_MANAGER Class Reference

Manage the construction of a circular arc though sequential setting of critical points: center, arc start and arc end. More...

#include <arc_geom_manager.h>

Inheritance diagram for KIGFX::PREVIEW::ARC_GEOM_MANAGER:
KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER

Public Types

enum  ARC_STEPS { SET_ORIGIN = 0, SET_START, SET_ANGLE, COMPLETE }
 

Public Member Functions

 ARC_GEOM_MANAGER ()
 
int getMaxStep () const override
 The highest step this manager has - used to recognize completion and to clamp the step as it advances. More...
 
ARC_STEPS GetStep () const
 Get the current step the manager is on (useful when drawing something depends on the current state) More...
 
bool acceptPoint (const VECTOR2I &aPt) override
 The arc to be clockwise from start. More...
 
void SetClockwise (bool aCw)
 Reverse the current are direction. More...
 
void ToggleClockwise ()
 Set angle snapping (for the next point) More...
 
void SetAngleSnap (bool aSnap)
 
VECTOR2I GetOrigin () const
 < Get the center point of the arc (valid when state > SET_ORIGIN) More...
 
VECTOR2I GetStartRadiusEnd () const
 Get the coordinates of the arc end point. More...
 
VECTOR2I GetEndRadiusEnd () const
 Get the radius of the arc (valid if step >= SET_START) More...
 
double GetRadius () const
 Get the angle of the vector leading to the start point (valid if step >= SET_START) More...
 
double GetStartAngle () const
 Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE) More...
 
double GetSubtended () const
 
void AddPoint (const VECTOR2I &aPt, bool aLockIn)
 Add a point to the construction manager. More...
 
void RemoveLastPoint ()
 Undo the last point, and move the manager back to the previous step. More...
 
bool IsReset () const
 
void Reset ()
 Reset the manager to the initial state. More...
 
bool IsComplete () const
 
VECTOR2I GetLastPoint () const
 Get the last point added (locked in or not). More...
 
bool HasGeometryChanged () const
 
void ClearGeometryChanged ()
 Clear the geometry changed flag, call after the client code has updated everything as needed. More...
 

Protected Member Functions

void setGeometryChanged ()
 < Mark the geometry as changed for clients to notice More...
 
int getStep () const
 

Private Member Functions

bool setOrigin (const VECTOR2I &aOrigin)
 < Set the center point of the arc More...
 
bool setStart (const VECTOR2I &aEnd)
 Set a point of the second radius line (collinear with arc end) More...
 
bool setEnd (const VECTOR2I &aCursor)
 

Private Attributes

bool m_clockwise = true
 
VECTOR2I m_origin
 
double m_radius = 0.0
 
double m_startAngle = 0.0
 
double m_endAngle = 0.0
 
bool m_angleSnap = false
 
bool m_directionLocked = false
 

Detailed Description

Manage the construction of a circular arc though sequential setting of critical points: center, arc start and arc end.

The manager is driven by setting cursor points, which update the geometry, and optionally advance the manager state.

Interfaces are provided to return both arc geometry (can be used to set up real arcs on PCBs, for example) as well as important control points for informational overlays.

Definition at line 41 of file arc_geom_manager.h.

Member Enumeration Documentation

◆ ARC_STEPS

Enumerator
SET_ORIGIN 

Waiting to lock in origin point.

SET_START 

Waiting to lock in the arc start point.

SET_ANGLE 

Waiting to lock in the arc end point.

COMPLETE 

Definition at line 47 of file arc_geom_manager.h.

48  {
49  SET_ORIGIN = 0,
50  SET_START,
51  SET_ANGLE,
52  COMPLETE
53  };
Waiting to lock in the arc start point.
Waiting to lock in origin point.
Waiting to lock in the arc end point.

Constructor & Destructor Documentation

◆ ARC_GEOM_MANAGER()

KIGFX::PREVIEW::ARC_GEOM_MANAGER::ARC_GEOM_MANAGER ( )
inline

Definition at line 44 of file arc_geom_manager.h.

45  {}

Member Function Documentation

◆ acceptPoint()

bool ARC_GEOM_MANAGER::acceptPoint ( const VECTOR2I aPt)
overridevirtual

The arc to be clockwise from start.

Implements KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER.

Definition at line 38 of file arc_geom_manager.cpp.

39 {
40  switch( getStep() )
41  {
42  case SET_ORIGIN: return setOrigin( aPt );
43  case SET_START: return setStart( aPt );
44  case SET_ANGLE: return setEnd( aPt );
45  case COMPLETE: return false;
46  }
47 
48  return false;
49 }
bool setEnd(const VECTOR2I &aCursor)
Waiting to lock in the arc start point.
Waiting to lock in origin point.
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 setOrigin(const VECTOR2I &aOrigin)
< Set the center point of the arc

References COMPLETE, KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::getStep(), SET_ANGLE, SET_ORIGIN, SET_START, setEnd(), setOrigin(), and setStart().

◆ AddPoint()

void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::AddPoint ( const VECTOR2I aPt,
bool  aLockIn 
)
inlineinherited

Add a point to the construction manager.

Parameters
aPtthe new point
aLockInwhether to "lock in" the point, and move the geometry manager to the next (or previous) step. False to update geometry and not affect manager state.

Definition at line 60 of file multistep_geom_manager.h.

61  {
62  // hold onto the raw point separately to the managed geometry
63  m_lastPoint = aPt;
64 
65  // update the geometry
66  bool accepted = acceptPoint( aPt );
67 
68  // advance or regress the manager
69  if( aLockIn )
70  performStep( accepted );
71 
73  }
virtual bool acceptPoint(const VECTOR2I &aPt)=0
< Function that accepts a point for a stage, or rejects it to return to the previous stage
void setGeometryChanged()
< Mark the geometry as changed for clients to notice
void performStep(bool aForward)
Has the geometry changed such that a client should redraw?

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::acceptPoint(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_lastPoint, KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::performStep(), and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged().

Referenced by DRAWING_TOOL::drawArc().

◆ ClearGeometryChanged()

void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::ClearGeometryChanged ( )
inlineinherited

Clear the geometry changed flag, call after the client code has updated everything as needed.

Definition at line 136 of file multistep_geom_manager.h.

137  {
138  m_changed = false;
139  }
bool m_changed
The last (raw) point added, which is usually the cursor position.

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_changed.

◆ GetEndRadiusEnd()

VECTOR2I ARC_GEOM_MANAGER::GetEndRadiusEnd ( ) const

Get the radius of the arc (valid if step >= SET_START)

Definition at line 80 of file arc_geom_manager.cpp.

81 {
82  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_endAngle );
83 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371

References m_endAngle, m_origin, m_radius, and VECTOR2< T >::Rotate().

Referenced by updateArcFromConstructionMgr(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ GetLastPoint()

VECTOR2I KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::GetLastPoint ( ) const
inlineinherited

Get the last point added (locked in or not).

This can* be useful when drawing previews, as the point given isn't always what gets locked into the geometry, if that step doesn't have full degrees of freedom.

Definition at line 119 of file multistep_geom_manager.h.

120  {
121  return m_lastPoint;
122  }

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_lastPoint.

Referenced by KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ getMaxStep()

int KIGFX::PREVIEW::ARC_GEOM_MANAGER::getMaxStep ( ) const
inlineoverridevirtual

The highest step this manager has - used to recognize completion and to clamp the step as it advances.

Moves the manager forward or backward through the stages

Implements KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER.

Definition at line 55 of file arc_geom_manager.h.

References COMPLETE.

◆ GetOrigin()

VECTOR2I ARC_GEOM_MANAGER::GetOrigin ( ) const

< Get the center point of the arc (valid when state > SET_ORIGIN)

Get the coordinates of the arc start

Definition at line 68 of file arc_geom_manager.cpp.

69 {
70  return m_origin;
71 }

References m_origin.

Referenced by updateArcFromConstructionMgr(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ GetRadius()

double ARC_GEOM_MANAGER::GetRadius ( ) const

Get the angle of the vector leading to the start point (valid if step >= SET_START)

Definition at line 86 of file arc_geom_manager.cpp.

87 {
88  return m_radius;
89 }

References m_radius.

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ GetStartAngle()

double ARC_GEOM_MANAGER::GetStartAngle ( ) const

Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE)

Definition at line 92 of file arc_geom_manager.cpp.

93 {
94  double angle = m_startAngle;
95 
96  if( m_clockwise )
97  angle -= 2 * M_PI;
98 
99  return -angle;
100 }
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)

References PNS::angle(), m_clockwise, and m_startAngle.

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ GetStartRadiusEnd()

VECTOR2I ARC_GEOM_MANAGER::GetStartRadiusEnd ( ) const

Get the coordinates of the arc end point.

Definition at line 74 of file arc_geom_manager.cpp.

75 {
76  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_startAngle );
77 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371

References m_origin, m_radius, m_startAngle, and VECTOR2< T >::Rotate().

Referenced by updateArcFromConstructionMgr(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ GetStep()

ARC_STEPS KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetStep ( ) const
inline

Get the current step the manager is on (useful when drawing something depends on the current state)

Definition at line 64 of file arc_geom_manager.h.

65  {
66  return static_cast<ARC_STEPS>( getStep() );
67  }

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::getStep().

Referenced by DRAWING_TOOL::drawArc(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ getStep()

int KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::getStep ( ) const
inlineprotectedinherited

Definition at line 150 of file multistep_geom_manager.h.

151  {
152  return m_step;
153  }
int m_step
The current manager step, from 0 to some highest number that depends on the manager.

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_step.

Referenced by acceptPoint(), and GetStep().

◆ GetSubtended()

double ARC_GEOM_MANAGER::GetSubtended ( ) const

Definition at line 103 of file arc_geom_manager.cpp.

104 {
105  double angle = m_endAngle - m_startAngle;
106 
107  if( m_endAngle <= m_startAngle )
108  angle += 2 * M_PI;
109 
110  if( m_clockwise )
111  angle -= 2 * M_PI;
112 
113  return -angle;
114 }
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)

References PNS::angle(), m_clockwise, m_endAngle, and m_startAngle.

Referenced by setEnd(), updateArcFromConstructionMgr(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ HasGeometryChanged()

bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::HasGeometryChanged ( ) const
inlineinherited
Returns
true if the geometry has changed, eg such that a client should redraw.

Definition at line 127 of file multistep_geom_manager.h.

128  {
129  return m_changed;
130  }
bool m_changed
The last (raw) point added, which is usually the cursor position.

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_changed.

Referenced by DRAWING_TOOL::drawArc().

◆ IsComplete()

bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::IsComplete ( ) const
inlineinherited
Returns
true if the manager reached the final state.

Definition at line 108 of file multistep_geom_manager.h.

109  {
110  return m_step == getMaxStep();
111  }
virtual int getMaxStep() const =0
The highest step this manager has - used to recognize completion and to clamp the step as it advances...
int m_step
The current manager step, from 0 to some highest number that depends on the manager.

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::getMaxStep(), and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_step.

Referenced by DRAWING_TOOL::drawArc().

◆ IsReset()

bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::IsReset ( ) const
inlineinherited
Returns
true if the manager is in the initial state

Definition at line 91 of file multistep_geom_manager.h.

92  {
93  return m_step == 0;
94  }
int m_step
The current manager step, from 0 to some highest number that depends on the manager.

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_step.

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewBBox(), and KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ RemoveLastPoint()

void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint ( )
inlineinherited

Undo the last point, and move the manager back to the previous step.

Definition at line 78 of file multistep_geom_manager.h.

79  {
80  performStep( false );
81 
82  // process the last point again, but in the previous step mode it doesn't matter if
83  // accepted or not, as long as the geometry is regenerated if needed.
86  }
virtual bool acceptPoint(const VECTOR2I &aPt)=0
< Function that accepts a point for a stage, or rejects it to return to the previous stage
void setGeometryChanged()
< Mark the geometry as changed for clients to notice
VECTOR2I GetLastPoint() const
Get the last point added (locked in or not).
void performStep(bool aForward)
Has the geometry changed such that a client should redraw?

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::acceptPoint(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::GetLastPoint(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::performStep(), and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged().

Referenced by DRAWING_TOOL::drawArc().

◆ Reset()

void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::Reset ( )
inlineinherited

Reset the manager to the initial state.

Definition at line 99 of file multistep_geom_manager.h.

100  {
101  m_step = 0;
103  }
int m_step
The current manager step, from 0 to some highest number that depends on the manager.
void setGeometryChanged()
< Mark the geometry as changed for clients to notice

References KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_step, and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged().

◆ SetAngleSnap()

void KIGFX::PREVIEW::ARC_GEOM_MANAGER::SetAngleSnap ( bool  aSnap)
inline

Definition at line 78 of file arc_geom_manager.h.

79  {
80  m_angleSnap = aSnap;
81  }

References m_angleSnap.

Referenced by DRAWING_TOOL::drawArc().

◆ SetClockwise()

void ARC_GEOM_MANAGER::SetClockwise ( bool  aCw)

Reverse the current are direction.

Definition at line 52 of file arc_geom_manager.cpp.

53 {
54  m_clockwise = aCw;
55  m_directionLocked = true;
57 }
void setGeometryChanged()
< Mark the geometry as changed for clients to notice

References m_clockwise, m_directionLocked, and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged().

◆ setEnd()

bool ARC_GEOM_MANAGER::setEnd ( const VECTOR2I aCursor)
private

Definition at line 147 of file arc_geom_manager.cpp.

148 {
149  const VECTOR2I radVec = aCursor - m_origin;
150 
151  m_endAngle = radVec.Angle();
152 
153  if( m_angleSnap )
155 
156  // normalise into 0-2Pi
157  while( m_endAngle < 0 )
158  m_endAngle += M_PI * 2;
159 
160  if( !m_directionLocked )
161  {
162  double ccwAngle = m_endAngle - m_startAngle;
163 
164  if( m_endAngle <= m_startAngle )
165  ccwAngle += 2 * M_PI;
166 
167  double cwAngle = std::abs( ccwAngle - 2 * M_PI );
168 
169  if( std::min( ccwAngle, cwAngle ) >= M_PI_2 )
170  m_directionLocked = true;
171  else
172  m_clockwise = cwAngle < ccwAngle;
173  }
174  else if( std::abs( GetSubtended() ) < M_PI_2 )
175  {
176  m_directionLocked = false;
177  }
178 
179  // if the end is the same as the start, this is a bad point
180  return m_endAngle != m_startAngle;
181 }
#define M_PI_2
Definition: transline.cpp:40
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
static double snapAngle(double aAngle)
< Snap an angle to the nearest 45 degrees

References VECTOR2< T >::Angle(), GetSubtended(), m_angleSnap, m_clockwise, m_directionLocked, m_endAngle, m_origin, M_PI_2, m_startAngle, and snapAngle().

Referenced by acceptPoint().

◆ setGeometryChanged()

void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged ( )
inlineprotectedinherited

◆ setOrigin()

bool ARC_GEOM_MANAGER::setOrigin ( const VECTOR2I aOrigin)
private

< Set the center point of the arc

Set the end of the first radius line (arc start)

Definition at line 117 of file arc_geom_manager.cpp.

118 {
119  m_origin = aOrigin;
120  m_startAngle = 0.0;
121  m_endAngle = 0.0;
122 
123  return true;
124 }

References m_endAngle, m_origin, and m_startAngle.

Referenced by acceptPoint().

◆ setStart()

bool ARC_GEOM_MANAGER::setStart ( const VECTOR2I aEnd)
private

Set a point of the second radius line (collinear with arc end)

Definition at line 127 of file arc_geom_manager.cpp.

128 {
129  const VECTOR2I radVec = aEnd - m_origin;
130 
131  m_radius = radVec.EuclideanNorm();
132  m_startAngle = radVec.Angle();
133 
134  if( m_angleSnap )
136 
137  // normalise into 0-2Pi
138  while( m_startAngle < 0 )
139  m_startAngle += M_PI * 2;
140 
142 
143  return m_radius != 0.0;
144 }
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
static double snapAngle(double aAngle)
< Snap an angle to the nearest 45 degrees

References VECTOR2< T >::Angle(), VECTOR2< T >::EuclideanNorm(), m_angleSnap, m_endAngle, m_origin, m_radius, m_startAngle, and snapAngle().

Referenced by acceptPoint().

◆ ToggleClockwise()

void ARC_GEOM_MANAGER::ToggleClockwise ( )

Set angle snapping (for the next point)

Definition at line 60 of file arc_geom_manager.cpp.

61 {
63  m_directionLocked = true;
65 }
void setGeometryChanged()
< Mark the geometry as changed for clients to notice

References m_clockwise, m_directionLocked, and KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::setGeometryChanged().

Referenced by DRAWING_TOOL::drawArc().

Member Data Documentation

◆ m_angleSnap

bool KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_angleSnap = false
private

Definition at line 132 of file arc_geom_manager.h.

Referenced by SetAngleSnap(), setEnd(), and setStart().

◆ m_clockwise

bool KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_clockwise = true
private

◆ m_directionLocked

bool KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_directionLocked = false
private

Definition at line 133 of file arc_geom_manager.h.

Referenced by SetClockwise(), setEnd(), and ToggleClockwise().

◆ m_endAngle

double KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_endAngle = 0.0
private

Definition at line 127 of file arc_geom_manager.h.

Referenced by GetEndRadiusEnd(), GetSubtended(), setEnd(), setOrigin(), and setStart().

◆ m_origin

VECTOR2I KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_origin
private

◆ m_radius

double KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_radius = 0.0
private

Definition at line 125 of file arc_geom_manager.h.

Referenced by GetEndRadiusEnd(), GetRadius(), GetStartRadiusEnd(), and setStart().

◆ m_startAngle

double KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_startAngle = 0.0
private

The documentation for this class was generated from the following files: