KiCad PCB EDA Suite
POLYGON_GEOM_MANAGER Class Reference

Class that handles the drawing of a polygon, including management of last corner deletion and drawing of leader lines with various constraints (eg 45 deg only). More...

#include <polygon_geom_manager.h>

Classes

class  CLIENT
 "Listener" interface for a class that wants to be updated about polygon geometry changes More...
 

Public Types

enum  LEADER_MODE { LEADER_MODE::DIRECT, LEADER_MODE::DEG45 }
 The kind of the leader line. More...
 

Public Member Functions

 POLYGON_GEOM_MANAGER (CLIENT &aClient)
 
void AddPoint (const VECTOR2I &aPt)
 Lock in a polygon point. More...
 
void SetFinished ()
 Mark the polygon finished and update the client. More...
 
void Reset ()
 Clear the manager state and start again. More...
 
void SetLeaderMode (LEADER_MODE aMode)
 Set the leader mode to use when calculating the leader/returner lines. More...
 
void SetCursorPosition (const VECTOR2I &aPos)
 Set the current cursor position. More...
 
bool IsPolygonInProgress () const
 
bool NewPointClosesOutline (const VECTOR2I &aPt) const
 
void DeleteLastCorner ()
 Remove the last-added point from the polygon. More...
 
const std::vector< VECTOR2I > & GetLockedInPoints () const
 Get the "locked-in" points that describe the polygon itself. More...
 
const std::vector< VECTOR2I > & GetLeaderLinePoints () const
 Get the points comprising the leader line (the line from the last locked-in point to the current cursor position. More...
 

Private Member Functions

void updateLeaderPoints (const VECTOR2I &aEndPoint)
 Update the leader line points based on a new endpoint (probably a cursor position) More...
 

Private Attributes

CLIENTm_client
 

The "user" of the polygon data that is informed when the geometry changes

More...
 
LEADER_MODE m_leaderMode
 

The current mode of the leader line

More...
 
std::vector< VECTOR2Im_lockedPoints
 

Point that have been "locked in"

More...
 
std::vector< VECTOR2Im_leaderPts
 

Points in the temporary "leader" line(s)

More...
 

Detailed Description

Class that handles the drawing of a polygon, including management of last corner deletion and drawing of leader lines with various constraints (eg 45 deg only).

This class handles only the geometry of the process.

Definition at line 37 of file polygon_geom_manager.h.

Member Enumeration Documentation

The kind of the leader line.

Enumerator
DIRECT 
DEG45 

Unconstrained point-to-point

Definition at line 67 of file polygon_geom_manager.h.

68  {
69  DIRECT,
70  DEG45,
71  };

Constructor & Destructor Documentation

POLYGON_GEOM_MANAGER::POLYGON_GEOM_MANAGER ( CLIENT aClient)
Parameters
aClientis the client to pass the results onto

Definition at line 29 of file polygon_geom_manager.cpp.

29  :
30  m_client( aClient ),
32 {}
LEADER_MODE m_leaderMode
The current mode of the leader line
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes

Member Function Documentation

void POLYGON_GEOM_MANAGER::AddPoint ( const VECTOR2I aPt)

Lock in a polygon point.

Definition at line 35 of file polygon_geom_manager.cpp.

References IsPolygonInProgress(), m_client, m_leaderPts, m_lockedPoints, POLYGON_GEOM_MANAGER::CLIENT::OnFirstPoint(), and POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange().

Referenced by DRAWING_TOOL::runPolygonEventLoop().

36 {
37  // if this is the first point, make sure the client is happy
38  // for us to continue
40  return;
41 
42  if( m_leaderPts.size() > 1 )
43  {
44  // there are enough leader points - the next
45  // locked-in point is the end of the first leader
46  // segment
47  m_lockedPoints.push_back( m_leaderPts[1] );
48  }
49  else
50  {
51  // no leader lines, directly add the cursor
52  m_lockedPoints.push_back( aPt );
53  }
54 
55  m_client.OnGeometryChange( *this );
56 }
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Sent when the polygon geometry changes
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
virtual bool OnFirstPoint()=0
Called before the first point is added - clients can do initialisation here, and can veto the start o...
void POLYGON_GEOM_MANAGER::DeleteLastCorner ( )

Remove the last-added point from the polygon.

Definition at line 89 of file polygon_geom_manager.cpp.

References m_client, m_leaderPts, m_lockedPoints, POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange(), and updateLeaderPoints().

Referenced by DRAWING_TOOL::runPolygonEventLoop().

90 {
91  if( m_lockedPoints.size() > 0 )
92  {
93  m_lockedPoints.pop_back();
94  }
95 
96  // update the new last segment (was previously
97  // locked in), reusing last constraints
98  if( m_lockedPoints.size() > 0 )
99  {
101  }
102 
103  m_client.OnGeometryChange( *this );
104 }
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Sent when the polygon geometry changes
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
void updateLeaderPoints(const VECTOR2I &aEndPoint)
Update the leader line points based on a new endpoint (probably a cursor position) ...
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
const std::vector< VECTOR2I > & POLYGON_GEOM_MANAGER::GetLeaderLinePoints ( ) const

Get the points comprising the leader line (the line from the last locked-in point to the current cursor position.

How this is drawn will depend on the LEADER_MODE

Definition at line 155 of file polygon_geom_manager.cpp.

References m_leaderPts.

Referenced by ZONE_CREATE_HELPER::OnGeometryChange().

156 {
157  return m_leaderPts;
158 }
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
const std::vector< VECTOR2I > & POLYGON_GEOM_MANAGER::GetLockedInPoints ( ) const

Get the "locked-in" points that describe the polygon itself.

Definition at line 149 of file polygon_geom_manager.cpp.

References m_lockedPoints.

Referenced by ZONE_CREATE_HELPER::OnComplete(), and ZONE_CREATE_HELPER::OnGeometryChange().

150 {
151  return m_lockedPoints;
152 }
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
bool POLYGON_GEOM_MANAGER::IsPolygonInProgress ( ) const
Returns
true if the polygon in "in progress", i.e. it has at least one locked-in point

Definition at line 77 of file polygon_geom_manager.cpp.

References m_lockedPoints.

Referenced by AddPoint(), and DRAWING_TOOL::runPolygonEventLoop().

78 {
79  return m_lockedPoints.size() > 0;
80 }
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
bool POLYGON_GEOM_MANAGER::NewPointClosesOutline ( const VECTOR2I aPt) const
Returns
true if locking in the given point would close the current polygon

Definition at line 83 of file polygon_geom_manager.cpp.

References m_lockedPoints.

Referenced by DRAWING_TOOL::runPolygonEventLoop().

84 {
85  return m_lockedPoints.size() && m_lockedPoints[0] == aPt;
86 }
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
void POLYGON_GEOM_MANAGER::Reset ( )

Clear the manager state and start again.

Definition at line 107 of file polygon_geom_manager.cpp.

References m_client, m_leaderPts, m_lockedPoints, and POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange().

Referenced by DRAWING_TOOL::runPolygonEventLoop().

108 {
109  m_lockedPoints.clear();
110  m_leaderPts.clear();
111 
112  m_client.OnGeometryChange( *this );
113 }
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Sent when the polygon geometry changes
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
void POLYGON_GEOM_MANAGER::SetCursorPosition ( const VECTOR2I aPos)

Set the current cursor position.

Definition at line 71 of file polygon_geom_manager.cpp.

References updateLeaderPoints().

Referenced by DRAWING_TOOL::runPolygonEventLoop().

72 {
73  updateLeaderPoints( aPos );
74 }
void updateLeaderPoints(const VECTOR2I &aEndPoint)
Update the leader line points based on a new endpoint (probably a cursor position) ...
void POLYGON_GEOM_MANAGER::SetFinished ( )

Mark the polygon finished and update the client.

Definition at line 59 of file polygon_geom_manager.cpp.

References m_client, and POLYGON_GEOM_MANAGER::CLIENT::OnComplete().

Referenced by DRAWING_TOOL::runPolygonEventLoop().

60 {
61  m_client.OnComplete( *this );
62 }
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
virtual void OnComplete(const POLYGON_GEOM_MANAGER &aMgr)=0
Called when the polygon is complete
void POLYGON_GEOM_MANAGER::SetLeaderMode ( LEADER_MODE  aMode)

Set the leader mode to use when calculating the leader/returner lines.

Definition at line 65 of file polygon_geom_manager.cpp.

References m_leaderMode.

Referenced by DRAWING_TOOL::runPolygonEventLoop().

66 {
67  m_leaderMode = aMode;
68 }
LEADER_MODE m_leaderMode
The current mode of the leader line
void POLYGON_GEOM_MANAGER::updateLeaderPoints ( const VECTOR2I aEndPoint)
private

Update the leader line points based on a new endpoint (probably a cursor position)

Definition at line 116 of file polygon_geom_manager.cpp.

References DEG45, m_client, m_leaderMode, m_leaderPts, m_lockedPoints, POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange(), SHAPE_LINE_CHAIN::Point(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by DeleteLastCorner(), and SetCursorPosition().

117 {
118  SHAPE_LINE_CHAIN newChain;
119 
121  {
122  // get a restricted 45/H/V line from the last fixed point to the cursor
123  DIRECTION_45 direction( m_lockedPoints.back() - aEndPoint );
124  newChain = direction.BuildInitialTrace( m_lockedPoints.back(), aEndPoint );
125 
126  // Can also add chain back to start, but this rearely produces
127  // usable result
128  //DIRECTION_45 directionToStart( aEndPoint - m_lockedPoints.front() );
129  //newChain.Append( directionToStart.BuildInitialTrace( aEndPoint, m_lockedPoints.front() ) );
130  }
131  else
132  {
133  // direct segment
134  newChain = SHAPE_LINE_CHAIN( m_lockedPoints.back(), aEndPoint );
135  }
136 
137  // rebuild leader point list from the chain
138  m_leaderPts.clear();
139 
140  for( int i = 0; i < newChain.PointCount(); ++i )
141  {
142  m_leaderPts.push_back( newChain.Point( i ) );
143  }
144 
145  m_client.OnGeometryChange( *this );
146 }
virtual void OnGeometryChange(const POLYGON_GEOM_MANAGER &aMgr)=0
Sent when the polygon geometry changes
LEADER_MODE m_leaderMode
The current mode of the leader line
CLIENT & m_client
The "user" of the polygon data that is informed when the geometry changes
Unconstrained point-to-point
Class DIRECTION_45.
Definition: direction45.h:33
std::vector< VECTOR2I > m_lockedPoints
Point that have been "locked in"
std::vector< VECTOR2I > m_leaderPts
Points in the temporary "leader" line(s)
Class SHAPE_LINE_CHAIN.

Member Data Documentation

CLIENT& POLYGON_GEOM_MANAGER::m_client
private

The "user" of the polygon data that is informed when the geometry changes

Definition at line 147 of file polygon_geom_manager.h.

Referenced by AddPoint(), DeleteLastCorner(), Reset(), SetFinished(), and updateLeaderPoints().

LEADER_MODE POLYGON_GEOM_MANAGER::m_leaderMode
private

The current mode of the leader line

Definition at line 150 of file polygon_geom_manager.h.

Referenced by SetLeaderMode(), and updateLeaderPoints().

std::vector<VECTOR2I> POLYGON_GEOM_MANAGER::m_leaderPts
private

Points in the temporary "leader" line(s)

Definition at line 156 of file polygon_geom_manager.h.

Referenced by AddPoint(), DeleteLastCorner(), GetLeaderLinePoints(), Reset(), and updateLeaderPoints().

std::vector<VECTOR2I> POLYGON_GEOM_MANAGER::m_lockedPoints
private

Point that have been "locked in"

Definition at line 153 of file polygon_geom_manager.h.

Referenced by AddPoint(), DeleteLastCorner(), GetLockedInPoints(), IsPolygonInProgress(), NewPointClosesOutline(), Reset(), and updateLeaderPoints().


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