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

Class 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
 

Detailed Description

Class 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

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

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

Definition at line 50 of file arc_geom_manager.h.

51  {}

Member Function Documentation

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.

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

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
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 geomtry and not affect manager state

Definition at line 60 of file multistep_geom_manager.h.

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

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

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

140  {
141  m_changed = false;
142  }
bool m_changed
Has the gemotry changed such that a client should redraw?
VECTOR2I ARC_GEOM_MANAGER::GetEndRadiusEnd ( ) const

Get the coordinates of the arc end point

Definition at line 82 of file arc_geom_manager.cpp.

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

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

83 {
84  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_endAngle );
85 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
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.

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

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

122  {
123  return m_lastPoint;
124  }
VECTOR2I m_lastPoint
The last (raw) point added, which is usually the cursor position
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 62 of file arc_geom_manager.h.

References COMPLETE.

63  {
64  return COMPLETE;
65  }
Waiting to lock in the arc end point
VECTOR2I ARC_GEOM_MANAGER::GetOrigin ( ) const

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

Definition at line 70 of file arc_geom_manager.cpp.

References m_origin.

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

71 {
72  return m_origin;
73 }
double ARC_GEOM_MANAGER::GetRadius ( ) const

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

Definition at line 88 of file arc_geom_manager.cpp.

References m_radius.

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

89 {
90  return m_radius;
91 }
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 94 of file arc_geom_manager.cpp.

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

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

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

Get the coordinates of the arc start

Definition at line 76 of file arc_geom_manager.cpp.

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

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

77 {
78  return m_origin + VECTOR2I( m_radius, 0 ).Rotate( m_startAngle );
79 }
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
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 71 of file arc_geom_manager.h.

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

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

72  {
73  return static_cast<ARC_STEPS>( getStep() );
74  }
int getStep() const
Get the current stage of the manager
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.

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

Referenced by acceptPoint(), and GetStep().

154  {
155  return m_step;
156  }
int m_step
The current manager step, from 0 to some highest number that depends on the manager.
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 105 of file arc_geom_manager.cpp.

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

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

106 {
107  double angle = m_endAngle - m_startAngle;
108 
109  if( m_endAngle <= m_startAngle )
110  angle += 2 * M_PI;
111 
112  if( m_clockwise )
113  angle -= 2 * M_PI;
114 
115  return -angle;
116 }
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
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.

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

Referenced by DRAWING_TOOL::drawArc().

131  {
132  return m_changed;
133  }
bool m_changed
Has the gemotry changed such that a client should redraw?
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.

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

Referenced by DRAWING_TOOL::drawArc().

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

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

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

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

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

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

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

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
void KIGFX::PREVIEW::ARC_GEOM_MANAGER::SetAngleSnap ( bool  aSnap)
inline

Set angle snapping (for the next point)

Definition at line 85 of file arc_geom_manager.h.

References m_angleSnap.

Referenced by DRAWING_TOOL::drawArc().

86  {
87  m_angleSnap = aSnap;
88  }
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.

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

57 {
58  m_clockwise = aCw;
60 }
void setGeometryChanged()
Mark the geometry as changed for clients to notice
bool ARC_GEOM_MANAGER::setEnd ( const VECTOR2I aCursor)
private

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

Definition at line 149 of file arc_geom_manager.cpp.

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

Referenced by acceptPoint().

150 {
151  const auto radVec = aCursor - m_origin;
152 
153  m_endAngle = radVec.Angle();
154 
155  if( m_angleSnap )
157 
158  // normalise into 0-2Pi
159  while( m_endAngle < 0 )
160  m_endAngle += M_PI * 2;
161 
162  // if the end is the same as the start, this is a bad point
163  return m_endAngle != m_startAngle;
164 }
static double snapAngle(double aAngle)
Snap an angle to the nearest 45 degrees
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.

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

148  {
149  m_changed = true;
150  }
bool m_changed
Has the gemotry changed such that a client should redraw?
bool ARC_GEOM_MANAGER::setOrigin ( const VECTOR2I aOrigin)
private

Set the centre point of the arc

Definition at line 119 of file arc_geom_manager.cpp.

References m_endAngle, m_origin, and m_startAngle.

Referenced by acceptPoint().

120 {
121  m_origin = aOrigin;
122  m_startAngle = 0.0;
123  m_endAngle = 0.0;
124 
125  return true;
126 }
bool ARC_GEOM_MANAGER::setStart ( const VECTOR2I aEnd)
private

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

Definition at line 129 of file arc_geom_manager.cpp.

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

Referenced by acceptPoint().

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

Reverse the current are direction

Definition at line 63 of file arc_geom_manager.cpp.

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

Referenced by DRAWING_TOOL::drawArc().

64 {
67 }
void setGeometryChanged()
Mark the geometry as changed for clients to notice

Member Data Documentation

bool KIGFX::PREVIEW::ARC_GEOM_MANAGER::m_angleSnap
private

Definition at line 139 of file arc_geom_manager.h.

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

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

Definition at line 130 of file arc_geom_manager.h.

Referenced by GetStartAngle(), GetSubtended(), SetClockwise(), and ToggleClockwise().

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

Definition at line 134 of file arc_geom_manager.h.

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

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

Definition at line 132 of file arc_geom_manager.h.

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

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

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