KiCad PCB EDA Suite
KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER Class Referenceabstract

A geometry manager that works by accepting a sequence of points and advancing though stages of geometric construction with each point "locked in". More...

#include <multistep_geom_manager.h>

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

Public Member Functions

virtual ~MULTISTEP_GEOM_MANAGER ()
 
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

virtual bool acceptPoint (const VECTOR2I &aPt)=0
 

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

More...
 
virtual int getMaxStep () const =0
 The highest step this manager has - used to recognise completion and to clamp the step as it advances. More...
 
void performStep (bool aForward)
 

Moves the manager forward or backward through the stages

More...
 

Private Attributes

bool m_changed = false
 

Has the gemotry changed such that a client should redraw?

More...
 
VECTOR2I m_lastPoint
 

The last (raw) point added, which is usually the cursor position

More...
 
int m_step = 0
 The current manager step, from 0 to some highest number that depends on the manager. More...
 

Detailed Description

A geometry manager that works by accepting a sequence of points and advancing though stages of geometric construction with each point "locked in".

For example, constructing an arc might go:

  • Set origin
  • Set start point
  • Set end point

The exact steps and how the points translate to geometry depends on the subclass.

Definition at line 46 of file multistep_geom_manager.h.

Constructor & Destructor Documentation

virtual KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::~MULTISTEP_GEOM_MANAGER ( )
inlinevirtual

Definition at line 49 of file multistep_geom_manager.h.

50  {}

Member Function Documentation

virtual bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::acceptPoint ( const VECTOR2I aPt)
privatepure virtual

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

Implemented in KIGFX::PREVIEW::ARC_GEOM_MANAGER.

Referenced by AddPoint(), and RemoveLastPoint().

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

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 acceptPoint(), m_lastPoint, performStep(), and 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 ( )
inline

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

140  {
141  m_changed = false;
142  }
bool m_changed
Has the gemotry changed such that a client should redraw?
VECTOR2I KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::GetLastPoint ( ) const
inline

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

Referenced by 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
virtual int KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::getMaxStep ( ) const
privatepure virtual

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

Implemented in KIGFX::PREVIEW::ARC_GEOM_MANAGER.

Referenced by IsComplete(), and performStep().

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

Get the current stage of the manager

Definition at line 153 of file multistep_geom_manager.h.

References m_step.

Referenced by KIGFX::PREVIEW::ARC_GEOM_MANAGER::acceptPoint(), and KIGFX::PREVIEW::ARC_GEOM_MANAGER::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.
bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::HasGeometryChanged ( ) const
inline
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 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
inline
Returns
true if the manager reached the final state

Definition at line 110 of file multistep_geom_manager.h.

References getMaxStep(), and 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
inline
Returns
true if the manager is in the initial state

Definition at line 93 of file multistep_geom_manager.h.

References 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::performStep ( bool  aForward)
inlineprivate

Moves the manager forward or backward through the stages

Definition at line 171 of file multistep_geom_manager.h.

References getMaxStep(), m_step, max, and min.

Referenced by AddPoint(), and RemoveLastPoint().

172  {
173  m_step += aForward ? 1 : -1;
174 
175  // clamp to allowed values
176  m_step = std::min( std::max( m_step, 0 ), getMaxStep() );
177  }
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.
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
void KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::RemoveLastPoint ( )
inline

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

Definition at line 79 of file multistep_geom_manager.h.

References acceptPoint(), GetLastPoint(), performStep(), and 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 ( )
inline

Reset the manager to the initial state.

Definition at line 101 of file multistep_geom_manager.h.

References m_step, and 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::MULTISTEP_GEOM_MANAGER::setGeometryChanged ( )
inlineprotected

Mark the geometry as changed for clients to notice

Definition at line 147 of file multistep_geom_manager.h.

References m_changed.

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

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

Member Data Documentation

bool KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_changed = false
private

Has the gemotry changed such that a client should redraw?

Definition at line 180 of file multistep_geom_manager.h.

Referenced by ClearGeometryChanged(), HasGeometryChanged(), and setGeometryChanged().

VECTOR2I KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_lastPoint
private

The last (raw) point added, which is usually the cursor position

Definition at line 183 of file multistep_geom_manager.h.

Referenced by AddPoint(), and GetLastPoint().

int KIGFX::PREVIEW::MULTISTEP_GEOM_MANAGER::m_step = 0
private

The current manager step, from 0 to some highest number that depends on the manager.

Definition at line 189 of file multistep_geom_manager.h.

Referenced by getStep(), IsComplete(), IsReset(), performStep(), and Reset().


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