20#ifndef BOARD_CONSTRAINT_ADAPTER_H_
21#define BOARD_CONSTRAINT_ADAPTER_H_
125 bool Build(
const std::vector<PCB_SHAPE*>& aShapes,
const std::vector<PCB_CONSTRAINT*>& aConstraints,
126 const std::set<KIID>* aFixedShapes =
nullptr,
127 const std::vector<PCB_DIMENSION_BASE*>& aDimensions = {} );
149 const std::set<KIID>& aEdited = {},
150 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged = std::nullopt );
153 bool Solve(
bool aStabilize =
false );
168 std::vector<PCB_SHAPE*>
Apply(
const std::function<
void( BOARD_ITEM* )>& aBeforeWrite = {} );
260 void softPinPoint(
const ANCHOR_PARAMS& aPoint,
int aTag, std::optional<double> aWeight = std::nullopt );
263 void softPinPoint(
int aPointX,
int aTag, std::optional<double> aWeight = std::nullopt );
356 std::vector<PCB_SHAPE*>* aModified =
nullptr,
357 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify = {},
358 bool aIncludeDragged =
false,
bool aStabilize =
false,
359 const std::set<KIID>& aEdited = {},
360 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged =
375 std::vector<PCB_SHAPE*>* aModified =
nullptr,
376 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify = {} );
394 std::vector<PCB_SHAPE*>* aModified =
nullptr,
395 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify = {} );
401 std::vector<PCB_SHAPE*>* aModified =
nullptr,
402 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify = {} );
407 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify = {} );
CONSTRAINT_STATE
The constraint state of a shape, for the diagnostics overlay tint.
@ UNCONSTRAINED
Not referenced by any constraint.
@ OVER_CONSTRAINED
In a cluster the solver reports as conflicting.
@ UNDER_CONSTRAINED
In a cluster with remaining free degrees of freedom.
@ WELL_CONSTRAINED
In a fully-determined cluster (zero free DOF).
void ReSolveShapeClustersHoldingEdited(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aEditedShapes, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={})
Re-solve clusters whose new geometry is authoritative holding every edited shape fully fixed so only ...
bool BoardHasConstraints(BOARD *aBoard)
True if the board or any of its footprints carries at least one geometric constraint.
CONSTRAINT_DIAGNOSIS ApplyConstraintImmediately(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={})
Solve a just-created constraint's cluster so the geometry snaps to satisfy it (SolidWorks-style),...
CONSTRAINT_DIAGNOSIS SolveCluster(BOARD *aBoard, const CONSTRAINT_MEMBER &aDragged, const VECTOR2I &aCursor, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={}, bool aIncludeDragged=false, bool aStabilize=false, const std::set< KIID > &aEdited={}, const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aCoDragged=std::nullopt)
Gather the cluster of shapes transitively constrained with the dragged shape, solve with the dragged ...
bool ConstraintItemIsLocked(const BOARD_ITEM *aItem)
True when the solver must treat aItem as immovable, either locked itself or living inside a locked fo...
void ReSolveShapeClusters(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aShapes, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={})
Re-solve the clusters of shapes edited outside the solver, e.g.
BOARD_CONSTRAINT_DIAGNOSTICS DiagnoseBoardConstraints(BOARD *aBoard)
Diagnose every constraint cluster on the board (validate only – geometry is not changed) and return t...
void ReSolveAfterShapeResize(BOARD *aBoard, PCB_SHAPE *aShape, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={})
Re-solve after a resize, e.g. a circle radius edit. Holds aShape fixed so its neighbors adjust.
void recordReferenceValue(PCB_CONSTRAINT *aConstraint)
Note a non-driving valued constraint so its measured value can be read back after a solve.
BOARD_CONSTRAINT_ADAPTER(const BOARD_CONSTRAINT_ADAPTER &)=delete
double normalizeY(int aIU) const
BOARD_CONSTRAINT_ADAPTER & operator=(const BOARD_CONSTRAINT_ADAPTER &)=delete
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.
int m_coDragTargetY
Backing slot for the co-dragged pin y target.
PCB_DIM_ORTHOGONAL * orthogonalDimensionForMembers(const std::vector< CONSTRAINT_MEMBER > &aMembers) const
The orthogonal dimension a two-point length constraint drives or nullptr requires both members to be ...
std::vector< KIID > m_unmapped
Constraints Build() could not map (not enforced).
double denormalizeX(double aNorm) const
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 weig...
BOARD_CONSTRAINT_ADAPTER()
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-movemen...
double m_originX
IU offset subtracted from x before scaling (cluster anchor).
int m_dragTargetX
Stable backing slot for the drag pin's x target (-1 = unset).
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 me...
std::vector< PCB_CONSTRAINT * > m_referenceConstraints
Non-driving valued, read back after a solve.
bool solveSucceeded(int aSolveResult)
Decide whether a solve reached a usable result a raw Success or Converged always qualifies while a Fa...
double m_invScale
1 / m_scale.
const std::vector< KIID > & UnmappedConstraints() const
Constraints from the last Build() that could not be mapped onto a solver primitive (wrong member coun...
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 fo...
std::map< KIID, SHAPE_VARS > m_shapeVars
bool SolveAfterResize(const KIID &aResizedShape)
Solve after a resize.
int m_coDragTargetX
Backing slot for the co-dragged pin x target.
double denormalizeY(double aNorm) const
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...
std::map< int, std::vector< KIID > > m_tagMembers
Member items per tag, for collapse attribution.
int m_dragTargetY
Stable backing slot for the drag pin's y target.
double m_scale
IU per normalized unit.
std::map< int, KIID > m_tagToConstraint
std::set< KIID > m_angleConstrainedShapes
Shapes a direction or angle constraint could collapse to a point only these get a stabilize length or...
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...
std::deque< double > m_params
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.
void holdPolygonVertices(const std::set< KIID > &aShapes, int aTag)
Soft-pin every vertex of each POLYGON in aShapes tagged aTag for edited shapes pinUneditedShapes excl...
std::vector< PCB_SHAPE * > Apply(const std::function< void(BOARD_ITEM *)> &aBeforeWrite={})
Write the solved coordinates back into the shapes, de-normalized to IU.
std::unique_ptr< GCS::System > m_gcs
int pushParam(double aValue)
Append a normalized coordinate to the backing store, returning its stable index.
CONSTRAINT_DIAGNOSIS Diagnose()
Report degrees of freedom and conflicting/redundant constraints.
double m_originY
IU offset subtracted from y before scaling.
std::set< int > m_nonDrivingTags
Measurement-only; excluded from conflict residuals.
double normalizeX(int aIU) const
IU <-> normalized (millimetre, cluster-centred) frame, per axis.
~BOARD_CONSTRAINT_ADAPTER()
@ RECT
An axis-aligned rectangle whose four corners alias the two stored corners params so rectness holds by...
@ POINT_PAIR
A dimension's two feature points (start + end); no line/curve geometry.
@ POLYGON
A single hole-free outline with one free param pair per vertex since write-back rebuilds one outline ...
@ BEZIER
A cubic bezier only its start and end endpoints are exposed as free points.
void ApplyReferenceValues(const std::function< void(BOARD_ITEM *)> &aBeforeWrite={})
Propagate solved reference (non-driving) constraint values back into their m_value so a reference dim...
void holdArcRadius(const SHAPE_VARS &aVars, int aTag)
Hold aVars's arc at its current radius (tagged aTag).
An incremental DiagnoseBoardConstraints for the interactive edit path.
std::size_t SolveCount() const
Clusters actually re-solved across this diagnoser lifetime for testing cache isolation.
BOARD_CONSTRAINT_DIAGNOSTICS Diagnose(BOARD *aBoard)
Diagnose every cluster reusing cached per-cluster results whose solve inputs are unchanged.
std::map< std::vector< KIID >, CACHE_ENTRY > m_cache
void Clear()
Drop the cache call when the board or view reloads and item-identity assumptions break.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
A geometric constraint between board items (issue #2329).
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
Param indices of an anchor coordinates a rect corner aliases mixed start end params so y is not alway...
Per-shape indices into m_params.
int radius
radius scalar (circle, arc) / minor radius (ellipse).
bool startIsLeft
Rect corner roles frozen at Build so VERTEX 0 to 3 as TL TR BR BL bind the same physical corners what...
int arcStartX
arc start-point.x.
int fixedLengthParam
param index of a driving fixed-length target, or -1.
int focusX
first focus.x (ellipse kinds only).
int startX
start.x (segment) / center.x (circle, arc, ellipse).
int endAngle
arc end angle (radians).
int startAngle
arc start angle (radians).
int arcEndX
arc end-point.x.
int endX
end.x (segment only).
PCB_DIMENSION_BASE * dimension
set instead of shape for a POINT_PAIR
int vertexCount
Outline-0 vertex count of a POLYGON vertex i x param is startX plus 2 times i.
Board-wide diagnostics for the constraint overlay and info bar.
std::map< KIID, CONSTRAINT_STATE > shapeStates
std::vector< KIID > errored
Invalid constraints (member missing, deleted, or of a kind incompatible with the type).
std::vector< KIID > redundant
std::vector< KIID > conflicting
One cluster's diagnosis, the unit DiagnoseBoardConstraints assembles the board-wide result from and B...
int freeDof
Remaining free DOF folded into the board total.
std::vector< KIID > dimensionIds
Cluster dimensions.
std::vector< KIID > conflicting
std::vector< KIID > erroredUnmapped
Constraints Build could not map and so not enforced.
std::vector< KIID > shapeIds
Cluster shapes in the order the state is written.
std::vector< KIID > redundant
The outcome of a constraint solve, in plain data so callers need not know planegcs.
bool solved
Solver reached Success or Converged.
bool IsOverConstrained() const
bool IsWellConstrained() const
std::vector< KIID > conflicting
Constraints the solver reports as over-constraining.
bool IsUnderConstrained() const
std::vector< KIID > redundant
Constraints the solver reports as redundant.
int freeDof
Remaining degrees of freedom (-1 if not diagnosed).
One participant in a constraint: a referenced board item plus the feature of that item that participa...
VECTOR2< int32_t > VECTOR2I