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

ARC_GEOM_MANAGER. 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 recognise completion and to clamp the step as it advances. More...
 
ARC_STEPS GetStep () const
 Get the current step the mananger is on (useful when drawing something depends on the current state) More...
 
bool acceptPoint (const VECTOR2I &aPt) override
 

Function that accepts a point for a stage, or rejects it to return to the previous stage

More...
 
void SetClockwise (bool aCw)
 

The the arc to be clockwise from start

More...
 
void ToggleClockwise ()
 

Reverse the current are direction

More...
 
void SetAngleSnap (bool aSnap)
 

Set angle snapping (for the next point)

More...
 
VECTOR2I GetOrigin () const
 

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

More...
 
VECTOR2I GetStartRadiusEnd () const
 

Get the coordinates of the arc start

More...
 
VECTOR2I GetEndRadiusEnd () const
 

Get the coordinates of the arc end point

More...
 
double GetRadius () const
 

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

More...
 
double GetStartAngle () const
 

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

More...
 
double GetSubtended () const
 

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

More...
 
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
 Gets 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
 

Get the current stage of the manager

More...
 

Private Member Functions

bool setOrigin (const VECTOR2I &aOrigin)
 

Set the centre point of the arc

More...
 
bool setStart (const VECTOR2I &aEnd)
 

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

More...
 
bool setEnd (const VECTOR2I &aCursor)
 

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

More...
 

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

ARC_GEOM_MANAGER.

A class to manage the construction of a circular arc though sequential setting of critical points: centre, 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 47 of file arc_geom_manager.h.

Member Enumeration Documentation

◆ ARC_STEPS

Enumerator
SET_ORIGIN 
SET_START 

Waiting to lock in origin point

SET_ANGLE 

Waiting to lock in the arc start point

COMPLETE 

Waiting to lock in the arc end point

Definition at line 53 of file arc_geom_manager.h.

54  {
55  SET_ORIGIN = 0,
56  SET_START,
57  SET_ANGLE,
58  COMPLETE
59  };
Waiting to lock in the arc end point
Waiting to lock in origin point
Waiting to lock in the arc start point

Constructor & Destructor Documentation

◆ ARC_GEOM_MANAGER()

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

Definition at line 50 of file arc_geom_manager.h.

51  {}

Member Function Documentation

◆ acceptPoint()

bool ARC_GEOM_MANAGER::acceptPoint ( const VECTOR2I aPt)
overridevirtual

Function that accepts a point for a stage, or rejects it to return to the previous stage

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:
43  return setOrigin( aPt );
44  case SET_START:
45  return setStart( aPt );
46  case SET_ANGLE:
47  return setEnd( aPt );
48  case COMPLETE:
49  break;
50  }
51 
52  return false;
53 }
Waiting to lock in the arc end point
bool setEnd(const VECTOR2I &aCursor)
Set a point of the second radius line (collinear with arc end)
Waiting to lock in origin point
int getStep() const
Get the current stage of the manager
bool setStart(const VECTOR2I &aEnd)
Set the end of the first radius line (arc start)
Waiting to lock in the arc start point
bool setOrigin(const VECTOR2I &aOrigin)
Set the centre 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)
Moves the manager forward or backward through the stages
VECTOR2I m_lastPoint
The last (raw) point added, which is usually the cursor position

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().

◆ 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 139 of file multistep_geom_manager.h.

140  {
141  m_changed = false;
142  }
bool m_changed
Has the gemotry changed such that a client should redraw?

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

◆ GetEndRadiusEnd()

VECTOR2I ARC_GEOM_MANAGER::GetEndRadiusEnd ( ) const

Get the coordinates of the arc end point

Definition at line 84 of file arc_geom_manager.cpp.

85 {
86  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_endAngle );
87 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377

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

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

◆ GetLastPoint()

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

Gets 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 121 of file multistep_geom_manager.h.

122  {
123  return m_lastPoint;
124  }
VECTOR2I m_lastPoint
The last (raw) point added, which is usually the cursor position

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 recognise completion and to clamp the step as it advances.

Implements KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER.

Definition at line 61 of file arc_geom_manager.h.

62  {
63  return COMPLETE;
64  }
Waiting to lock in the arc end point

References COMPLETE.

◆ GetOrigin()

VECTOR2I ARC_GEOM_MANAGER::GetOrigin ( ) const

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

Definition at line 72 of file arc_geom_manager.cpp.

73 {
74  return m_origin;
75 }

References m_origin.

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

◆ GetRadius()

double ARC_GEOM_MANAGER::GetRadius ( ) const

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

Definition at line 90 of file arc_geom_manager.cpp.

91 {
92  return m_radius;
93 }

References m_radius.

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

◆ GetStartAngle()

double ARC_GEOM_MANAGER::GetStartAngle ( ) const

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

Definition at line 96 of file arc_geom_manager.cpp.

97 {
98  double angle = m_startAngle;
99 
100  if( m_clockwise )
101  angle -= 2 * M_PI;
102 
103  return -angle;
104 }
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 start

Definition at line 78 of file arc_geom_manager.cpp.

79 {
80  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_startAngle );
81 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:377

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 mananger is on (useful when drawing something depends on the current state)

Definition at line 70 of file arc_geom_manager.h.

71  {
72  return static_cast<ARC_STEPS>( getStep() );
73  }
int getStep() const
Get the current stage of the manager

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

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

◆ getStep()

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

Get the current stage of the manager

Definition at line 153 of file multistep_geom_manager.h.

154  {
155  return m_step;
156  }
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

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

Definition at line 107 of file arc_geom_manager.cpp.

108 {
109  double angle = m_endAngle - m_startAngle;
110 
111  if( m_endAngle <= m_startAngle )
112  angle += 2 * M_PI;
113 
114  if( m_clockwise )
115  angle -= 2 * M_PI;
116 
117  return -angle;
118 }
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 geoemtry has changed, eg such that a client should redraw

Definition at line 130 of file multistep_geom_manager.h.

131  {
132  return m_changed;
133  }
bool m_changed
Has the gemotry changed such that a client should redraw?

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

◆ IsComplete()

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

Definition at line 110 of file multistep_geom_manager.h.

111  {
112  return m_step == getMaxStep();
113  }
virtual int getMaxStep() const =0
The highest step this manager has - used to recognise 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.

◆ IsReset()

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

Definition at line 93 of file multistep_geom_manager.h.

94  {
95  return m_step == 0;
96  }
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 79 of file multistep_geom_manager.h.

80  {
81  performStep( false );
82 
83  // process the last point again, but in the previous step mode
84  // it doesn't matter if accepted or not, as long as the geometry
85  // is regenerated if needed
88  }
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
Gets the last point added (locked in or not).
void performStep(bool aForward)
Moves the manager forward or backward through the stages

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().

◆ Reset()

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

Reset the manager to the initial state.

Definition at line 101 of file multistep_geom_manager.h.

102  {
103  m_step = 0;
105  }
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

Set angle snapping (for the next point)

Definition at line 84 of file arc_geom_manager.h.

85  {
86  m_angleSnap = aSnap;
87  }

References m_angleSnap.

◆ SetClockwise()

void ARC_GEOM_MANAGER::SetClockwise ( bool  aCw)

The the arc to be clockwise from start

Definition at line 56 of file arc_geom_manager.cpp.

57 {
58  m_clockwise = aCw;
59  m_directionLocked = true;
61 }
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

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

Definition at line 151 of file arc_geom_manager.cpp.

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

References 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

Mark the geometry as changed for clients to notice

Definition at line 147 of file multistep_geom_manager.h.

148  {
149  m_changed = true;
150  }
bool m_changed
Has the gemotry changed such that a client should redraw?

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

Referenced by KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::AddPoint(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint(), KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::Reset(), SetClockwise(), and ToggleClockwise().

◆ setOrigin()

bool ARC_GEOM_MANAGER::setOrigin ( const VECTOR2I aOrigin)
private

Set the centre point of the arc

Definition at line 121 of file arc_geom_manager.cpp.

122 {
123  m_origin = aOrigin;
124  m_startAngle = 0.0;
125  m_endAngle = 0.0;
126 
127  return true;
128 }

References m_endAngle, m_origin, and m_startAngle.

Referenced by acceptPoint().

◆ setStart()

bool ARC_GEOM_MANAGER::setStart ( const VECTOR2I aEnd)
private

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

Definition at line 131 of file arc_geom_manager.cpp.

132 {
133  const auto radVec = aEnd - m_origin;
134 
135  m_radius = radVec.EuclideanNorm();
136  m_startAngle = radVec.Angle();
137 
138  if( m_angleSnap )
140 
141  // normalise into 0-2Pi
142  while( m_startAngle < 0 )
143  m_startAngle += M_PI * 2;
144 
146 
147  return m_radius != 0.0;
148 }
static double snapAngle(double aAngle)
Snap an angle to the nearest 45 degrees

References m_angleSnap, m_endAngle, m_origin, m_radius, m_startAngle, and snapAngle().

Referenced by acceptPoint().

◆ ToggleClockwise()

void ARC_GEOM_MANAGER::ToggleClockwise ( )

Reverse the current are direction

Definition at line 64 of file arc_geom_manager.cpp.

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

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

Member Data Documentation

◆ m_angleSnap

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

Definition at line 138 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 139 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 133 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 131 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: