KiCad PCB EDA Suite
|
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< VECTOR2I > | DeleteLastCorner () |
Remove the last-added point from the polygon. | |
const SHAPE_LINE_CHAIN & | GetLockedInPoints () const |
Get the "locked-in" points that describe the polygon itself. | |
const SHAPE_LINE_CHAIN & | GetLeaderLinePoints () const |
Get the points comprising the leader line (the line from the last locked-in point to the current cursor position. | |
const SHAPE_LINE_CHAIN & | GetLoopLinePoints () 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 | |
CLIENT & | m_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 |
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.
|
strong |
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.
POLYGON_GEOM_MANAGER::POLYGON_GEOM_MANAGER | ( | CLIENT & | aClient | ) |
aClient | is the client to pass the results onto |
Definition at line 32 of file polygon_geom_manager.cpp.
bool POLYGON_GEOM_MANAGER::AddPoint | ( | const VECTOR2I & | aPt | ) |
Lock in a polygon point.
Definition at line 39 of file polygon_geom_manager.cpp.
References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CPoint(), IsPolygonInProgress(), IsSelfIntersecting(), m_client, m_intersectionsAllowed, m_leaderPts, m_lockedPoints, POLYGON_GEOM_MANAGER::CLIENT::OnFirstPoint(), POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange(), SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::Remove(), and updateTemporaryLines().
Referenced by SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
|
inline |
Enables/disables self-intersecting polygons.
aEnabled | true if self-intersecting polygons are enabled. |
Definition at line 110 of file polygon_geom_manager.h.
References m_intersectionsAllowed.
std::optional< VECTOR2I > POLYGON_GEOM_MANAGER::DeleteLastCorner | ( | ) |
Remove the last-added point from the polygon.
Definition at line 132 of file polygon_geom_manager.cpp.
References SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::GetPoint(), m_client, m_leaderPts, m_lockedPoints, POLYGON_GEOM_MANAGER::CLIENT::OnGeometryChange(), SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::Remove(), and updateTemporaryLines().
Referenced by SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
|
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 RULE_AREA_CREATE_HELPER::OnComplete(), ZONE_CREATE_HELPER::OnComplete(), RULE_AREA_CREATE_HELPER::OnGeometryChange(), and ZONE_CREATE_HELPER::OnGeometryChange().
|
inline |
Definition at line 100 of file polygon_geom_manager.h.
References m_leaderMode.
Referenced by RULE_AREA_CREATE_HELPER::OnComplete(), and ZONE_CREATE_HELPER::OnComplete().
|
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 RULE_AREA_CREATE_HELPER::OnComplete(), ZONE_CREATE_HELPER::OnComplete(), RULE_AREA_CREATE_HELPER::OnGeometryChange(), and ZONE_CREATE_HELPER::OnGeometryChange().
|
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 RULE_AREA_CREATE_HELPER::OnComplete(), ZONE_CREATE_HELPER::OnComplete(), RULE_AREA_CREATE_HELPER::OnGeometryChange(), and ZONE_CREATE_HELPER::OnGeometryChange().
|
inline |
Check whether self-intersecting polygons are enabled.
Definition at line 120 of file polygon_geom_manager.h.
References m_intersectionsAllowed.
bool POLYGON_GEOM_MANAGER::IsPolygonInProgress | ( | ) | const |
Definition at line 114 of file polygon_geom_manager.cpp.
References m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().
Referenced by AddPoint(), RULE_AREA_CREATE_HELPER::OnGeometryChange(), and ZONE_CREATE_HELPER::OnGeometryChange().
bool POLYGON_GEOM_MANAGER::IsSelfIntersecting | ( | bool | aIncludeLeaderPts | ) | const |
Check whether the locked points constitute a self-intersecting outline.
aIncludeLeaderPts | when true, also the leading points (not placed ones) will be tested. |
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().
bool POLYGON_GEOM_MANAGER::NewPointClosesOutline | ( | const VECTOR2I & | aPt | ) | const |
Definition at line 126 of file polygon_geom_manager.cpp.
References SHAPE_LINE_CHAIN::CPoint(), m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().
Referenced by SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
int POLYGON_GEOM_MANAGER::PolygonPointCount | ( | ) | const |
Definition at line 120 of file polygon_geom_manager.cpp.
References m_lockedPoints, and SHAPE_LINE_CHAIN::PointCount().
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 SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
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 SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
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 SCH_DRAWING_TOOLS::DrawRuleArea(), and DRAWING_TOOL::DrawZone().
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 SCH_DRAWING_TOOLS::DrawRuleArea(), DRAWING_TOOL::DrawZone(), RULE_AREA_CREATE_HELPER::OnFirstPoint(), and ZONE_CREATE_HELPER::OnFirstPoint().
|
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().
|
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().
|
private |
Point that have been "locked in".
Definition at line 204 of file polygon_geom_manager.h.
Referenced by AddPoint(), AllowIntersections(), and IntersectionsAllowed().
|
private |
Flag enabling self-intersecting polygons.
Definition at line 201 of file polygon_geom_manager.h.
Referenced by GetLeaderMode(), SetLeaderMode(), and updateTemporaryLines().
|
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().
|
private |
Points in the temporary "leader" line(s)
Definition at line 207 of file polygon_geom_manager.h.
Referenced by AddPoint(), DeleteLastCorner(), GetLockedInPoints(), IsPolygonInProgress(), IsSelfIntersecting(), NewPointClosesOutline(), PolygonPointCount(), Reset(), and updateTemporaryLines().
|
private |
Definition at line 213 of file polygon_geom_manager.h.
Referenced by GetLoopLinePoints(), Reset(), and updateTemporaryLines().