KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 class  LEADER_MODE { DIRECT , DEG45 }
 The kind of the leader line. More...
 

Public Member Functions

 POLYGON_GEOM_MANAGER (CLIENT &aClient)
 
bool AddPoint (const VECTOR2I &aPt)
 Lock in a polygon point.
 
void SetFinished ()
 Mark the polygon finished and update the client.
 
void Reset ()
 Clear the manager state and start again.
 
void SetLeaderMode (LEADER_MODE aMode)
 Set the leader mode to use when calculating the leader/returner lines.
 
LEADER_MODE GetLeaderMode () const
 
void AllowIntersections (bool aEnabled)
 Enables/disables self-intersecting polygons.
 
bool IntersectionsAllowed () const
 Check whether self-intersecting polygons are enabled.
 
bool IsSelfIntersecting (bool aIncludeLeaderPts) const
 Check whether the locked points constitute a self-intersecting outline.
 
void SetCursorPosition (const VECTOR2I &aPos)
 Set the current cursor position.
 
bool IsPolygonInProgress () const
 
int PolygonPointCount () const
 
bool NewPointClosesOutline (const VECTOR2I &aPt) const
 
std::optional< VECTOR2IDeleteLastCorner ()
 Remove the last-added point from the polygon.
 
const SHAPE_LINE_CHAINGetLockedInPoints () const
 Get the "locked-in" points that describe the polygon itself.
 
const SHAPE_LINE_CHAINGetLeaderLinePoints () const
 Get the points comprising the leader line (the line from the last locked-in point to the current cursor position.
 
const SHAPE_LINE_CHAINGetLoopLinePoints () const
 Get the points from the current cursor position to the polygon start point.
 

Private Member Functions

void updateTemporaryLines (const VECTOR2I &aEndPoint, LEADER_MODE aModifier=LEADER_MODE::DIRECT)
 Update the leader and loop lines points based on a new endpoint (probably a cursor position)
 

Private Attributes

CLIENTm_client
 The current mode of the leader line.
 
LEADER_MODE m_leaderMode
 Flag enabling self-intersecting polygons.
 
bool m_intersectionsAllowed
 Point that have been "locked in".
 
SHAPE_LINE_CHAIN m_lockedPoints
 Points in the temporary "leader" line(s)
 
SHAPE_LINE_CHAIN m_leaderPts
 Points between the cursor and start point.
 
SHAPE_LINE_CHAIN m_loopPts
 

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 35 of file polygon_geom_manager.h.

Member Enumeration Documentation

◆ LEADER_MODE

The kind of the leader line.

Enumerator
DIRECT 

Unconstrained point-to-point.

DEG45 

45 Degree only

Definition at line 69 of file polygon_geom_manager.h.

Constructor & Destructor Documentation

◆ POLYGON_GEOM_MANAGER()

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

Definition at line 32 of file polygon_geom_manager.cpp.

Member Function Documentation

◆ AddPoint()

◆ AllowIntersections()

void POLYGON_GEOM_MANAGER::AllowIntersections ( bool  aEnabled)
inline

Enables/disables self-intersecting polygons.

Parameters
aEnabledtrue if self-intersecting polygons are enabled.

Definition at line 110 of file polygon_geom_manager.h.

References m_intersectionsAllowed.

◆ DeleteLastCorner()

std::optional< VECTOR2I > POLYGON_GEOM_MANAGER::DeleteLastCorner ( )

◆ GetLeaderLinePoints()

const SHAPE_LINE_CHAIN & POLYGON_GEOM_MANAGER::GetLeaderLinePoints ( ) const
inline

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 174 of file polygon_geom_manager.h.

References m_leaderPts.

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

◆ GetLeaderMode()

LEADER_MODE POLYGON_GEOM_MANAGER::GetLeaderMode ( ) const
inline

Definition at line 100 of file polygon_geom_manager.h.

References m_leaderMode.

Referenced by ZONE_CREATE_HELPER::OnComplete().

◆ GetLockedInPoints()

const SHAPE_LINE_CHAIN & POLYGON_GEOM_MANAGER::GetLockedInPoints ( ) const
inline

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

Definition at line 163 of file polygon_geom_manager.h.

References m_lockedPoints.

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

◆ GetLoopLinePoints()

const SHAPE_LINE_CHAIN & POLYGON_GEOM_MANAGER::GetLoopLinePoints ( ) const
inline

Get the points from the current cursor position to the polygon start point.

Definition at line 183 of file polygon_geom_manager.h.

References m_loopPts.

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

◆ IntersectionsAllowed()

bool POLYGON_GEOM_MANAGER::IntersectionsAllowed ( ) const
inline

Check whether self-intersecting polygons are enabled.

Returns
true if self-intersecting polygons are enabled.

Definition at line 120 of file polygon_geom_manager.h.

References m_intersectionsAllowed.

◆ IsPolygonInProgress()

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 114 of file polygon_geom_manager.cpp.

References m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().

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

◆ IsSelfIntersecting()

bool POLYGON_GEOM_MANAGER::IsSelfIntersecting ( bool  aIncludeLeaderPts) const

Check whether the locked points constitute a self-intersecting outline.

Parameters
aIncludeLeaderPtswhen true, also the leading points (not placed ones) will be tested.
Returns
True when the outline is self-intersecting.

Definition at line 88 of file polygon_geom_manager.cpp.

References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CPoint(), m_leaderPts, m_lockedPoints, SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::SelfIntersecting(), and SHAPE_LINE_CHAIN::SetClosed().

Referenced by AddPoint().

◆ NewPointClosesOutline()

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 126 of file polygon_geom_manager.cpp.

References SHAPE_LINE_CHAIN::CPoint(), m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().

Referenced by DRAWING_TOOL::DrawZone().

◆ PolygonPointCount()

int POLYGON_GEOM_MANAGER::PolygonPointCount ( ) const

Definition at line 120 of file polygon_geom_manager.cpp.

References m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().

◆ Reset()

void POLYGON_GEOM_MANAGER::Reset ( )

Clear the manager state and start again.

Definition at line 152 of file polygon_geom_manager.cpp.

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

Referenced by DRAWING_TOOL::DrawZone().

◆ SetCursorPosition()

void POLYGON_GEOM_MANAGER::SetCursorPosition ( const VECTOR2I aPos)

Set the current cursor position.

Definition at line 108 of file polygon_geom_manager.cpp.

References updateTemporaryLines().

Referenced by DRAWING_TOOL::DrawZone().

◆ SetFinished()

void POLYGON_GEOM_MANAGER::SetFinished ( )

Mark the polygon finished and update the client.

Definition at line 75 of file polygon_geom_manager.cpp.

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

Referenced by DRAWING_TOOL::DrawZone().

◆ SetLeaderMode()

void POLYGON_GEOM_MANAGER::SetLeaderMode ( LEADER_MODE  aMode)

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

Definition at line 82 of file polygon_geom_manager.cpp.

References m_leaderMode.

Referenced by DRAWING_TOOL::DrawZone(), and ZONE_CREATE_HELPER::OnFirstPoint().

◆ updateTemporaryLines()

void POLYGON_GEOM_MANAGER::updateTemporaryLines ( const VECTOR2I aEndPoint,
LEADER_MODE  aModifier = LEADER_MODE::DIRECT 
)
private

Update the leader and loop lines points based on a new endpoint (probably a cursor position)

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

Definition at line 231 of file polygon_geom_manager.cpp.

References build45DegLeader(), SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::Clear(), DEG45, m_client, m_leaderMode, m_leaderPts, m_lockedPoints, m_loopPts, POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange(), SHAPE_LINE_CHAIN::PointCount(), and SHAPE_LINE_CHAIN::Reverse().

Referenced by AddPoint(), DeleteLastCorner(), and SetCursorPosition().

Member Data Documentation

◆ m_client

CLIENT& POLYGON_GEOM_MANAGER::m_client
private

The current mode of the leader line.

Definition at line 198 of file polygon_geom_manager.h.

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

◆ m_intersectionsAllowed

bool POLYGON_GEOM_MANAGER::m_intersectionsAllowed
private

Point that have been "locked in".

Definition at line 204 of file polygon_geom_manager.h.

Referenced by AddPoint(), AllowIntersections(), and IntersectionsAllowed().

◆ m_leaderMode

LEADER_MODE POLYGON_GEOM_MANAGER::m_leaderMode
private

Flag enabling self-intersecting polygons.

Definition at line 201 of file polygon_geom_manager.h.

Referenced by GetLeaderMode(), SetLeaderMode(), and updateTemporaryLines().

◆ m_leaderPts

SHAPE_LINE_CHAIN POLYGON_GEOM_MANAGER::m_leaderPts
private

Points between the cursor and start point.

Definition at line 210 of file polygon_geom_manager.h.

Referenced by AddPoint(), DeleteLastCorner(), GetLeaderLinePoints(), IsSelfIntersecting(), Reset(), and updateTemporaryLines().

◆ m_lockedPoints

SHAPE_LINE_CHAIN POLYGON_GEOM_MANAGER::m_lockedPoints
private

◆ m_loopPts

SHAPE_LINE_CHAIN POLYGON_GEOM_MANAGER::m_loopPts
private

Definition at line 213 of file polygon_geom_manager.h.

Referenced by GetLoopLinePoints(), Reset(), and updateTemporaryLines().


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