KiCad PCB EDA Suite
Loading...
Searching...
No Matches
BOARD_CONSTRAINT_ADAPTER Class Reference

Translates KiCad board geometry to and from the planegcs solver (issue #2329). More...

#include <board_constraint_adapter.h>

Classes

struct  ANCHOR_PARAMS
 Param indices of an anchor coordinates a rect corner aliases mixed start end params so y is not always x plus 1. More...
 
struct  SHAPE_VARS
 Per-shape indices into m_params. More...
 

Public Member Functions

 BOARD_CONSTRAINT_ADAPTER ()
 
 ~BOARD_CONSTRAINT_ADAPTER ()
 
 BOARD_CONSTRAINT_ADAPTER (const BOARD_CONSTRAINT_ADAPTER &)=delete
 
BOARD_CONSTRAINT_ADAPTERoperator= (const BOARD_CONSTRAINT_ADAPTER &)=delete
 
bool Build (const std::vector< PCB_SHAPE * > &aShapes, const std::vector< PCB_CONSTRAINT * > &aConstraints, const std::set< KIID > *aFixedShapes=nullptr, const std::vector< PCB_DIMENSION_BASE * > &aDimensions={})
 Translate a cluster into a planegcs system.
 
const std::vector< KIID > & UnmappedConstraints () const
 Constraints from the last Build() that could not be mapped onto a solver primitive (wrong member count/kind for their type, e.g.
 
bool Solve (const CONSTRAINT_MEMBER &aDragged, const VECTOR2I &aCursor, bool aStabilize=false, const std::set< KIID > &aEdited={}, const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aCoDragged=std::nullopt)
 Solve the system, pinning a dragged anchor to a cursor position.
 
bool Solve (bool aStabilize=false)
 Solve with no drag pin. aStabilize holds free segment lengths (see the dragged overload).
 
bool SolveAfterResize (const KIID &aResizedShape)
 Solve after a resize.
 
std::vector< PCB_SHAPE * > Apply (const std::function< void(BOARD_ITEM *)> &aBeforeWrite={})
 Write the solved coordinates back into the shapes, de-normalized to IU.
 
void ApplyReferenceValues (const std::function< void(BOARD_ITEM *)> &aBeforeWrite={})
 Propagate solved reference (non-driving) constraint values back into their m_value so a reference dimension tracks the geometry it measures.
 
CONSTRAINT_DIAGNOSIS Diagnose ()
 Report degrees of freedom and conflicting/redundant constraints.
 

Private Types

enum class  SHAPE_KIND {
  SEGMENT , BEZIER , CIRCLE , ARC ,
  ELLIPSE , ELLIPSE_ARC , POINT_PAIR , RECT ,
  POLYGON
}
 

Private Member Functions

int pushParam (double aValue)
 Append a normalized coordinate to the backing store, returning its stable index.
 
void recordReferenceValue (PCB_CONSTRAINT *aConstraint)
 Note a non-driving valued constraint so its measured value can be read back after a solve.
 
void holdFreeSegmentLengths (int aTag, const std::set< KIID > &aShapes)
 Length hold on the free segments in aShapes tagged aTag so only those shapes are protected while a merely dragged-along neighbour keeps its own stay-put pins instead.
 
void holdFreeArcRadii (int aTag, const std::set< KIID > &aShapes)
 Radius hold on the free arcs in aShapes tagged aTag so an angle change rotates an endpoint instead of collapsing the arc a real FIXED_RADIUS still wins.
 
void holdArcRadius (const SHAPE_VARS &aVars, int aTag)
 Hold aVars's arc at its current radius (tagged aTag).
 
void softPinPoint (const ANCHOR_PARAMS &aPoint, int aTag, std::optional< double > aWeight=std::nullopt)
 Pin the point at aPoint where it sits tagged aTag with aWeight rescaling the tier or the default weight overriding the stay-put tier when unset an invalid point is ignored.
 
void softPinPoint (int aPointX, int aTag, std::optional< double > aWeight=std::nullopt)
 As above for the point whose x param is aPointX and whose y param follows it.
 
void holdPolygonVertices (const std::set< KIID > &aShapes, int aTag)
 Soft-pin every vertex of each POLYGON in aShapes tagged aTag for edited shapes pinUneditedShapes excludes so unbound vertices keep their null-space minimal-movement pins.
 
void pinDraggedShapeRest (const CONSTRAINT_MEMBER &aDragged, int aTag, const CONSTRAINT_MEMBER *aCoDragged=nullptr)
 Hold the parts of the dragged shape meant to stay put tagged aTag a segment holds its far endpoint an arc holds centre radius and far endpoint or both endpoints on a centre drag.
 
void pinUneditedShapes (const std::set< KIID > &aEdited, int aTag)
 Soft-pin every cluster shape not in aEdited at its current geometry tagged aTag for a minimal-movement solve aEdited must list every edited shape or a neighbour gets held back.
 
bool solveSucceeded (int aSolveResult)
 Decide whether a solve reached a usable result a raw Success or Converged always qualifies while a Failed code is accepted only when every driving hard constraint is still satisfied.
 
ANCHOR_PARAMS anchorParams (const CONSTRAINT_MEMBER &aMember) const
 Indices into m_params of the coordinates an anchor maps to invalid if the shape has no such anchor for example a circle has no endpoints.
 
PCB_DIM_ORTHOGONALorthogonalDimensionForMembers (const std::vector< CONSTRAINT_MEMBER > &aMembers) const
 The orthogonal dimension a two-point length constraint drives or nullptr requires both members to be the same dimension START and END in either order.
 
double normalizeX (int aIU) const
 IU <-> normalized (millimetre, cluster-centred) frame, per axis.
 
double normalizeY (int aIU) const
 
double denormalizeX (double aNorm) const
 
double denormalizeY (double aNorm) const
 

Private Attributes

std::unique_ptr< GCS::System > m_gcs
 
std::deque< double > m_params
 
std::map< KIID, SHAPE_VARSm_shapeVars
 
std::map< int, KIIDm_tagToConstraint
 
std::set< int > m_nonDrivingTags
 Measurement-only; excluded from conflict residuals.
 
std::map< int, std::vector< KIID > > m_tagMembers
 Member items per tag, for collapse attribution.
 
std::vector< PCB_CONSTRAINT * > m_referenceConstraints
 Non-driving valued, read back after a solve.
 
std::vector< KIIDm_unmapped
 Constraints Build() could not map (not enforced).
 
std::set< KIIDm_angleConstrainedShapes
 Shapes a direction or angle constraint could collapse to a point only these get a stabilize length or radius hold.
 
double m_originX = 0.0
 IU offset subtracted from x before scaling (cluster anchor).
 
double m_originY = 0.0
 IU offset subtracted from y before scaling.
 
double m_scale = 1.0
 IU per normalized unit.
 
double m_invScale = 1.0
 1 / m_scale.
 
int m_dragTargetX = -1
 Stable backing slot for the drag pin's x target (-1 = unset).
 
int m_dragTargetY = -1
 Stable backing slot for the drag pin's y target.
 
int m_coDragTargetX = -1
 Backing slot for the co-dragged pin x target.
 
int m_coDragTargetY = -1
 Backing slot for the co-dragged pin y target.
 
int m_lengthHoldTag = -1
 
int m_resizeRadiusTag = -1
 
bool m_built = false
 

Detailed Description

Translates KiCad board geometry to and from the planegcs solver (issue #2329).

Build() translates a cluster of #PCB_SHAPEs and the #PCB_CONSTRAINTs among them into a planegcs system, scaled into a millimetre frame because raw IU (nanometres) squared in the residuals is badly conditioned. Solve() runs the solver (optionally pinning a dragged anchor to a cursor position), Apply() writes the solution back to the shapes in IU, and Diagnose() reports the constraint state.

The adapter owns a pointer-stable std::deque<double> backing store for every value the solver touches, both point coordinates and driving constants (lengths, pin targets). planegcs holds raw double* into this deque, so it must never reallocate, erase, or reorder while the GCS::System is alive. std::deque keeps element pointers stable across push_back, the only growth used.

Definition at line 105 of file board_constraint_adapter.h.

Member Enumeration Documentation

◆ SHAPE_KIND

enum class BOARD_CONSTRAINT_ADAPTER::SHAPE_KIND
strongprivate
Enumerator
SEGMENT 
BEZIER 

A cubic bezier only its start and end endpoints are exposed as free points.

CIRCLE 
ARC 
ELLIPSE 
ELLIPSE_ARC 
POINT_PAIR 

A dimension's two feature points (start + end); no line/curve geometry.

RECT 

An axis-aligned rectangle whose four corners alias the two stored corners params so rectness holds by construction with no extra DOF.

POLYGON 

A single hole-free outline with one free param pair per vertex since write-back rebuilds one outline only.

Definition at line 186 of file board_constraint_adapter.h.

Constructor & Destructor Documentation

◆ BOARD_CONSTRAINT_ADAPTER() [1/2]

BOARD_CONSTRAINT_ADAPTER::BOARD_CONSTRAINT_ADAPTER ( )

Definition at line 287 of file board_constraint_adapter.cpp.

References m_gcs.

Referenced by BOARD_CONSTRAINT_ADAPTER(), and operator=().

◆ ~BOARD_CONSTRAINT_ADAPTER()

BOARD_CONSTRAINT_ADAPTER::~BOARD_CONSTRAINT_ADAPTER ( )

Definition at line 293 of file board_constraint_adapter.cpp.

References m_gcs.

◆ BOARD_CONSTRAINT_ADAPTER() [2/2]

BOARD_CONSTRAINT_ADAPTER::BOARD_CONSTRAINT_ADAPTER ( const BOARD_CONSTRAINT_ADAPTER & )
delete

Member Function Documentation

◆ anchorParams()

◆ Apply()

std::vector< PCB_SHAPE * > BOARD_CONSTRAINT_ADAPTER::Apply ( const std::function< void(BOARD_ITEM *)> & aBeforeWrite = {})

◆ ApplyReferenceValues()

void BOARD_CONSTRAINT_ADAPTER::ApplyReferenceValues ( const std::function< void(BOARD_ITEM *)> & aBeforeWrite = {})

Propagate solved reference (non-driving) constraint values back into their m_value so a reference dimension tracks the geometry it measures.

Call after Apply(); the value is measured from the written shape geometry (not the raw solver param, which rounds separately), so a settled solve re-measures the same value and stages nothing. The value is always written when it changed; aBeforeWrite, if set, stages that constraint (BOARD_COMMIT::Modify) first so the write is undoable. Driving constraints are never touched.

Definition at line 316 of file board_constraint_adapter.cpp.

References std::abs(), anchor, anchorParams(), ANGULAR_DIMENSION, ARC_ANGLE, EDA_ANGLE::AsDegrees(), denormalizeX(), denormalizeY(), FIXED_LENGTH, FIXED_RADIUS, EDA_SHAPE::GetArcAngle(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetStart(), PCB_DIM_ORTHOGONAL::HORIZONTAL, KiROUND(), m_built, m_params, m_referenceConstraints, m_shapeVars, MeasureCornerAngle(), ortho, and orthogonalDimensionForMembers().

Referenced by ReSolveAfterShapeResize(), ReSolveShapeClustersHoldingEdited(), and SolveCluster().

◆ Build()

bool BOARD_CONSTRAINT_ADAPTER::Build ( const std::vector< PCB_SHAPE * > & aShapes,
const std::vector< PCB_CONSTRAINT * > & aConstraints,
const std::set< KIID > * aFixedShapes = nullptr,
const std::vector< PCB_DIMENSION_BASE * > & aDimensions = {} )

Translate a cluster into a planegcs system.

Parameters
aShapesthe shapes referenced by the constraints (resolved by the caller).
aConstraintsthe constraints relating those shapes.
aFixedShapesshapes to treat as immovable references (their whole span is frozen).
aDimensionsdimensions referenced by the constraints; each contributes its two feature points, so a coincident constraint can drag a dimension along with a shape.
Returns
true if the system was built; unmappable constraints are skipped rather than fatal, and are listed by UnmappedConstraints() so the caller can flag them.

Definition at line 531 of file board_constraint_adapter.cpp.

References anchor, anchorParams(), ANGULAR_DIMENSION, ARC, ARC, ARC_ANGLE, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::arcEndX, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::arcStartX, arcSweepTarget(), BEZIER, BEZIER, center, CIRCLE, CIRCLE, COINCIDENT, COLLINEAR, CONCENTRIC, ConstraintItemIsLocked(), ConstraintPolygonIsModelable(), SHAPE_LINE_CHAIN::CPoint(), BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::dimension, directedAngleForCorner(), ELLIPSE, ELLIPSE, ELLIPSE_ARC, ELLIPSE_ARC, end, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::endAngle, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::endX, EQUAL_LENGTH, EQUAL_RADIUS, FIXED_LENGTH, FIXED_POSITION, FIXED_RADIUS, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::focusX, HORIZONTAL, PCB_DIM_ORTHOGONAL::HORIZONTAL, isDegenerateLine(), BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::IsValid(), IU_PER_NORM_UNIT, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::kind, locked, CONSTRAINT_MEMBER::m_anchor, m_angleConstrainedShapes, m_built, m_gcs, m_invScale, CONSTRAINT_MEMBER::m_item, m_lengthHoldTag, m_nonDrivingTags, m_originX, m_originY, m_params, m_referenceConstraints, m_resizeRadiusTag, m_scale, m_shapeVars, m_tagMembers, m_tagToConstraint, m_unmapped, MAX_SOLVE_ITERATIONS, MIDPOINT, normalizeX(), normalizeY(), ortho, orthogonalDimensionForMembers(), PARALLEL, PCB_DIM_ALIGNED_T, PCB_DIM_ORTHOGONAL_T, PCB_DIM_RADIAL_T, PERPENDICULAR, POINT_ON_LINE, POINT_PAIR, SHAPE_LINE_CHAIN::PointCount(), POLY, POLYGON, pushParam(), BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::radius, recordReferenceValue(), RECT, RECTANGLE, SEGMENT, SEGMENT, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::shape, sign(), BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startAngle, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startIsLeft, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startIsTop, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startX, SYMMETRIC, TANGENT, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::vertexCount, VERTICAL, WHOLE, BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::x, VECTOR2< T >::x, BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::y, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), diagnoseSingleCluster(), ReSolveAfterShapeResize(), ReSolveShapeClustersHoldingEdited(), KI_TEST::solveAndApply(), and SolveCluster().

◆ denormalizeX()

double BOARD_CONSTRAINT_ADAPTER::denormalizeX ( double aNorm) const
inlineprivate

Definition at line 293 of file board_constraint_adapter.h.

References m_originX, and m_scale.

Referenced by Apply(), and ApplyReferenceValues().

◆ denormalizeY()

double BOARD_CONSTRAINT_ADAPTER::denormalizeY ( double aNorm) const
inlineprivate

Definition at line 294 of file board_constraint_adapter.h.

References m_originY, and m_scale.

Referenced by Apply(), and ApplyReferenceValues().

◆ Diagnose()

CONSTRAINT_DIAGNOSIS BOARD_CONSTRAINT_ADAPTER::Diagnose ( )

Report degrees of freedom and conflicting/redundant constraints.

The residual check reads the last solve's params; a contradictory cluster diverges under the stabilize holds, and the finite residuals it leaves behind are what flag the conflict.

Definition at line 2150 of file board_constraint_adapter.cpp.

References std::abs(), CONSTRAINT_DIAGNOSIS::conflicting, CONSTRAINT_DIAGNOSIS::freeDof, m_built, m_gcs, m_invScale, m_nonDrivingTags, m_params, m_shapeVars, m_tagMembers, m_tagToConstraint, CONSTRAINT_DIAGNOSIS::redundant, and SEGMENT.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), diagnoseSingleCluster(), and SolveCluster().

◆ holdArcRadius()

void BOARD_CONSTRAINT_ADAPTER::holdArcRadius ( const SHAPE_VARS & aVars,
int aTag )
private

Hold aVars's arc at its current radius (tagged aTag).

Definition at line 1835 of file board_constraint_adapter.cpp.

References circle(), m_gcs, m_params, pushParam(), BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::radius, and BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startX.

Referenced by holdFreeArcRadii(), and pinDraggedShapeRest().

◆ holdFreeArcRadii()

void BOARD_CONSTRAINT_ADAPTER::holdFreeArcRadii ( int aTag,
const std::set< KIID > & aShapes )
private

Radius hold on the free arcs in aShapes tagged aTag so an angle change rotates an endpoint instead of collapsing the arc a real FIXED_RADIUS still wins.

Definition at line 1846 of file board_constraint_adapter.cpp.

References ARC, ConstraintItemIsLocked(), holdArcRadius(), and m_shapeVars.

Referenced by Solve(), and Solve().

◆ holdFreeSegmentLengths()

void BOARD_CONSTRAINT_ADAPTER::holdFreeSegmentLengths ( int aTag,
const std::set< KIID > & aShapes )
private

Length hold on the free segments in aShapes tagged aTag so only those shapes are protected while a merely dragged-along neighbour keeps its own stay-put pins instead.

Definition at line 1814 of file board_constraint_adapter.cpp.

References ConstraintItemIsLocked(), m_gcs, m_params, m_shapeVars, pushParam(), and SEGMENT.

Referenced by Solve(), and Solve().

◆ holdPolygonVertices()

void BOARD_CONSTRAINT_ADAPTER::holdPolygonVertices ( const std::set< KIID > & aShapes,
int aTag )
private

Soft-pin every vertex of each POLYGON in aShapes tagged aTag for edited shapes pinUneditedShapes excludes so unbound vertices keep their null-space minimal-movement pins.

Definition at line 1798 of file board_constraint_adapter.cpp.

References ConstraintItemIsLocked(), m_shapeVars, POLYGON, softPinPoint(), and STAY_PUT_WEIGHT.

Referenced by Solve(), and SolveAfterResize().

◆ normalizeX()

double BOARD_CONSTRAINT_ADAPTER::normalizeX ( int aIU) const
inlineprivate

IU <-> normalized (millimetre, cluster-centred) frame, per axis.

Definition at line 291 of file board_constraint_adapter.h.

References m_invScale, and m_originX.

Referenced by Build(), and Solve().

◆ normalizeY()

double BOARD_CONSTRAINT_ADAPTER::normalizeY ( int aIU) const
inlineprivate

Definition at line 292 of file board_constraint_adapter.h.

References m_invScale, and m_originY.

Referenced by Build(), and Solve().

◆ operator=()

BOARD_CONSTRAINT_ADAPTER & BOARD_CONSTRAINT_ADAPTER::operator= ( const BOARD_CONSTRAINT_ADAPTER & )
delete

◆ orthogonalDimensionForMembers()

PCB_DIM_ORTHOGONAL * BOARD_CONSTRAINT_ADAPTER::orthogonalDimensionForMembers ( const std::vector< CONSTRAINT_MEMBER > & aMembers) const
private

The orthogonal dimension a two-point length constraint drives or nullptr requires both members to be the same dimension START and END in either order.

Definition at line 504 of file board_constraint_adapter.cpp.

References END, m_shapeVars, PCB_DIM_ORTHOGONAL_T, POINT_PAIR, and START.

Referenced by ApplyReferenceValues(), and Build().

◆ pinDraggedShapeRest()

void BOARD_CONSTRAINT_ADAPTER::pinDraggedShapeRest ( const CONSTRAINT_MEMBER & aDragged,
int aTag,
const CONSTRAINT_MEMBER * aCoDragged = nullptr )
private

◆ pinUneditedShapes()

void BOARD_CONSTRAINT_ADAPTER::pinUneditedShapes ( const std::set< KIID > & aEdited,
int aTag )
private

Soft-pin every cluster shape not in aEdited at its current geometry tagged aTag for a minimal-movement solve aEdited must list every edited shape or a neighbour gets held back.

Definition at line 1732 of file board_constraint_adapter.cpp.

References ARC, BEZIER, CIRCLE, circle(), ConstraintItemIsLocked(), ELLIPSE, ELLIPSE_ARC, m_gcs, m_params, m_shapeVars, POINT_PAIR, POLYGON, pushParam(), RECT, SEGMENT, softPinPoint(), and STAY_PUT_WEIGHT.

Referenced by Solve(), Solve(), and SolveAfterResize().

◆ pushParam()

int BOARD_CONSTRAINT_ADAPTER::pushParam ( double aValue)
private

Append a normalized coordinate to the backing store, returning its stable index.

Definition at line 300 of file board_constraint_adapter.cpp.

References m_params.

Referenced by Build(), holdArcRadius(), holdFreeSegmentLengths(), pinUneditedShapes(), softPinPoint(), Solve(), and SolveAfterResize().

◆ recordReferenceValue()

void BOARD_CONSTRAINT_ADAPTER::recordReferenceValue ( PCB_CONSTRAINT * aConstraint)
private

Note a non-driving valued constraint so its measured value can be read back after a solve.

A driving constraint is ignored here – its value is an input, never overwritten.

Definition at line 309 of file board_constraint_adapter.cpp.

References PCB_CONSTRAINT::IsDriving(), and m_referenceConstraints.

Referenced by Build().

◆ softPinPoint() [1/2]

void BOARD_CONSTRAINT_ADAPTER::softPinPoint ( const ANCHOR_PARAMS & aPoint,
int aTag,
std::optional< double > aWeight = std::nullopt )
private

Pin the point at aPoint where it sits tagged aTag with aWeight rescaling the tier or the default weight overriding the stay-put tier when unset an invalid point is ignored.

Definition at line 1640 of file board_constraint_adapter.cpp.

References BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::IsValid(), m_gcs, m_params, pushParam(), BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::x, and BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::y.

Referenced by holdPolygonVertices(), pinDraggedShapeRest(), pinUneditedShapes(), and softPinPoint().

◆ softPinPoint() [2/2]

void BOARD_CONSTRAINT_ADAPTER::softPinPoint ( int aPointX,
int aTag,
std::optional< double > aWeight = std::nullopt )
private

As above for the point whose x param is aPointX and whose y param follows it.

Definition at line 1663 of file board_constraint_adapter.cpp.

References softPinPoint().

◆ Solve() [1/2]

bool BOARD_CONSTRAINT_ADAPTER::Solve ( bool aStabilize = false)

Solve with no drag pin. aStabilize holds free segment lengths (see the dragged overload).

Definition at line 1375 of file board_constraint_adapter.cpp.

References holdFreeArcRadii(), holdFreeSegmentLengths(), m_angleConstrainedShapes, m_built, m_gcs, m_lengthHoldTag, pinUneditedShapes(), and solveSucceeded().

◆ Solve() [2/2]

bool BOARD_CONSTRAINT_ADAPTER::Solve ( const CONSTRAINT_MEMBER & aDragged,
const VECTOR2I & aCursor,
bool aStabilize = false,
const std::set< KIID > & aEdited = {},
const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > & aCoDragged = std::nullopt )

Solve the system, pinning a dragged anchor to a cursor position.

The pin is a temporary (negatively tagged) constraint, so it yields to the real ones and an over-constrained drag leaves the geometry where the rules allow.

Parameters
aDraggedthe anchor being dragged.
aCursorthe cursor target, in IU.
aEditedother shapes edited alongside the dragged one excluded from stay-put pins
aCoDraggedsecond anchor moved by the same handle with its own target pinned at the same weight since a polygon edge drag needs two independent points aStabilize holds free segment lengths so an angle constraint rotates a segment instead of collapsing it. Off for live dragging.

Definition at line 1463 of file board_constraint_adapter.cpp.

References anchor, anchorParams(), ARC, END, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::endX, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::fixedLengthParam, holdFreeArcRadii(), holdFreeSegmentLengths(), holdPolygonVertices(), BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::IsValid(), CONSTRAINT_MEMBER::m_anchor, m_angleConstrainedShapes, m_built, m_coDragTargetX, m_coDragTargetY, m_dragTargetX, m_dragTargetY, m_gcs, CONSTRAINT_MEMBER::m_item, m_params, m_shapeVars, normalizeX(), normalizeY(), pinDraggedShapeRest(), pinUneditedShapes(), pushParam(), BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::radius, radius, SEGMENT, solveSucceeded(), START, BOARD_CONSTRAINT_ADAPTER::SHAPE_VARS::startX, BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::x, VECTOR2< T >::x, BOARD_CONSTRAINT_ADAPTER::ANCHOR_PARAMS::y, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), diagnoseSingleCluster(), ReSolveShapeClustersHoldingEdited(), KI_TEST::solveAndApply(), and SolveCluster().

◆ SolveAfterResize()

bool BOARD_CONSTRAINT_ADAPTER::SolveAfterResize ( const KIID & aResizedShape)

Solve after a resize.

Holds the resized radius, pins its centre (yielding), and holds the other radii (yielding), so neighbours translate and the resized shape moves only if forced.

Definition at line 1406 of file board_constraint_adapter.cpp.

References holdPolygonVertices(), m_built, m_gcs, m_params, m_resizeRadiusTag, m_shapeVars, pinUneditedShapes(), pushParam(), and solveSucceeded().

Referenced by ReSolveAfterShapeResize().

◆ solveSucceeded()

bool BOARD_CONSTRAINT_ADAPTER::solveSucceeded ( int aSolveResult)
private

Decide whether a solve reached a usable result a raw Success or Converged always qualifies while a Failed code is accepted only when every driving hard constraint is still satisfied.

Definition at line 1607 of file board_constraint_adapter.cpp.

References std::abs(), m_gcs, m_nonDrivingTags, and m_tagToConstraint.

Referenced by Solve(), Solve(), and SolveAfterResize().

◆ UnmappedConstraints()

const std::vector< KIID > & BOARD_CONSTRAINT_ADAPTER::UnmappedConstraints ( ) const
inline

Constraints from the last Build() that could not be mapped onto a solver primitive (wrong member count/kind for their type, e.g.

a parallel whose shape was changed to a circle), so they are silently not enforced. Callers surface these as errored.

Definition at line 132 of file board_constraint_adapter.h.

References m_unmapped.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and diagnoseSingleCluster().

Member Data Documentation

◆ m_angleConstrainedShapes

std::set<KIID> BOARD_CONSTRAINT_ADAPTER::m_angleConstrainedShapes
private

Shapes a direction or angle constraint could collapse to a point only these get a stabilize length or radius hold.

Definition at line 310 of file board_constraint_adapter.h.

Referenced by Build(), Solve(), and Solve().

◆ m_built

bool BOARD_CONSTRAINT_ADAPTER::m_built = false
private

◆ m_coDragTargetX

int BOARD_CONSTRAINT_ADAPTER::m_coDragTargetX = -1
private

Backing slot for the co-dragged pin x target.

Definition at line 319 of file board_constraint_adapter.h.

Referenced by Solve().

◆ m_coDragTargetY

int BOARD_CONSTRAINT_ADAPTER::m_coDragTargetY = -1
private

Backing slot for the co-dragged pin y target.

Definition at line 320 of file board_constraint_adapter.h.

Referenced by Solve().

◆ m_dragTargetX

int BOARD_CONSTRAINT_ADAPTER::m_dragTargetX = -1
private

Stable backing slot for the drag pin's x target (-1 = unset).

Definition at line 317 of file board_constraint_adapter.h.

Referenced by Solve().

◆ m_dragTargetY

int BOARD_CONSTRAINT_ADAPTER::m_dragTargetY = -1
private

Stable backing slot for the drag pin's y target.

Definition at line 318 of file board_constraint_adapter.h.

Referenced by Solve().

◆ m_gcs

◆ m_invScale

double BOARD_CONSTRAINT_ADAPTER::m_invScale = 1.0
private

1 / m_scale.

Definition at line 315 of file board_constraint_adapter.h.

Referenced by Build(), Diagnose(), normalizeX(), and normalizeY().

◆ m_lengthHoldTag

int BOARD_CONSTRAINT_ADAPTER::m_lengthHoldTag = -1
private

Definition at line 324 of file board_constraint_adapter.h.

Referenced by Build(), and Solve().

◆ m_nonDrivingTags

std::set<int> BOARD_CONSTRAINT_ADAPTER::m_nonDrivingTags
private

Measurement-only; excluded from conflict residuals.

Definition at line 303 of file board_constraint_adapter.h.

Referenced by Build(), Diagnose(), and solveSucceeded().

◆ m_originX

double BOARD_CONSTRAINT_ADAPTER::m_originX = 0.0
private

IU offset subtracted from x before scaling (cluster anchor).

Definition at line 312 of file board_constraint_adapter.h.

Referenced by Build(), denormalizeX(), and normalizeX().

◆ m_originY

double BOARD_CONSTRAINT_ADAPTER::m_originY = 0.0
private

IU offset subtracted from y before scaling.

Definition at line 313 of file board_constraint_adapter.h.

Referenced by Build(), denormalizeY(), and normalizeY().

◆ m_params

std::deque<double> BOARD_CONSTRAINT_ADAPTER::m_params
private

◆ m_referenceConstraints

std::vector<PCB_CONSTRAINT*> BOARD_CONSTRAINT_ADAPTER::m_referenceConstraints
private

Non-driving valued, read back after a solve.

Definition at line 305 of file board_constraint_adapter.h.

Referenced by ApplyReferenceValues(), Build(), and recordReferenceValue().

◆ m_resizeRadiusTag

int BOARD_CONSTRAINT_ADAPTER::m_resizeRadiusTag = -1
private

Definition at line 325 of file board_constraint_adapter.h.

Referenced by Build(), and SolveAfterResize().

◆ m_scale

double BOARD_CONSTRAINT_ADAPTER::m_scale = 1.0
private

IU per normalized unit.

Definition at line 314 of file board_constraint_adapter.h.

Referenced by Apply(), Build(), denormalizeX(), and denormalizeY().

◆ m_shapeVars

◆ m_tagMembers

std::map<int, std::vector<KIID> > BOARD_CONSTRAINT_ADAPTER::m_tagMembers
private

Member items per tag, for collapse attribution.

Definition at line 304 of file board_constraint_adapter.h.

Referenced by Build(), and Diagnose().

◆ m_tagToConstraint

std::map<int, KIID> BOARD_CONSTRAINT_ADAPTER::m_tagToConstraint
private

Definition at line 302 of file board_constraint_adapter.h.

Referenced by Build(), Diagnose(), and solveSucceeded().

◆ m_unmapped

std::vector<KIID> BOARD_CONSTRAINT_ADAPTER::m_unmapped
private

Constraints Build() could not map (not enforced).

Definition at line 306 of file board_constraint_adapter.h.

Referenced by Build(), and UnmappedConstraints().


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