KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_constraint_adapter.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef BOARD_CONSTRAINT_ADAPTER_H_
21#define BOARD_CONSTRAINT_ADAPTER_H_
22
23#include <deque>
24#include <functional>
25#include <map>
26#include <memory>
27#include <optional>
28#include <set>
29#include <unordered_set>
30#include <vector>
31
33#include <kiid.h>
34#include <math/vector2d.h>
35#include <snap/snap_resolver.h>
36
38
39class BOARD;
40class BOARD_ITEM;
41class FOOTPRINT;
42class PAD;
45class PCB_SHAPE;
46
47// planegcs is an Eigen-heavy implementation detail; keep its header out of this one (PIMPL).
48namespace GCS
49{
50class System;
51}
52
53
58{
59 bool solved = false;
60 int freeDof = -1;
61 std::vector<KIID> conflicting;
62 std::vector<KIID> redundant;
63
64 bool IsWellConstrained() const { return solved && freeDof == 0; }
65 bool IsUnderConstrained() const { return freeDof > 0; }
66 bool IsOverConstrained() const { return !conflicting.empty(); }
67};
68
69
78
79
88
89
95{
96 int totalFreeDof = 0;
97 std::map<KIID, CONSTRAINT_STATE> shapeStates;
98 std::vector<KIID> conflicting;
99 std::vector<KIID> redundant;
100 std::vector<KIID> errored;
102};
103
104
119{
120public:
123
126
143 bool Build( const std::vector<PCB_SHAPE*>& aShapes, const std::vector<PCB_CONSTRAINT*>& aConstraints,
144 const std::set<KIID>* aFixedShapes = nullptr,
145 const std::vector<PCB_DIMENSION_BASE*>& aDimensions = {},
146 const std::vector<PAD*>& aPads = {} );
147
151 const std::vector<KIID>& UnmappedConstraints() const { return m_unmapped; }
152
169 bool Solve( const CONSTRAINT_MEMBER& aDragged, const VECTOR2I& aCursor, bool aStabilize = false,
170 const std::set<KIID>& aEdited = {},
171 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged = std::nullopt,
172 bool aHoldDraggedRigid = false );
173 bool SolveSnapRelations( const CONSTRAINT_MEMBER& aDragged,
174 const std::vector<SNAP_CANDIDATE>& aCandidates,
175 const VECTOR2I& aCursor );
176 bool SolveRigidTranslation( const std::set<KIID>& aEditedShapes,
177 const VECTOR2I& aTranslation );
178
203 SolveBlockEdit( const std::vector<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aPinnedAnchors,
204 const std::set<KIID>& aTranslatedShapes, const VECTOR2I& aTranslation );
205
207 bool TravelsWhole( const std::set<KIID>& aEditedShapes ) const;
208 bool SolveRigidSnapRelations( const std::set<KIID>& aEditedShapes,
209 const VECTOR2I& aReference,
210 const std::vector<SNAP_CANDIDATE>& aCandidates,
211 const VECTOR2I& aCursor, VECTOR2I& aResolvedCursor );
212
214 bool Solve( bool aStabilize = false );
215
218 bool SolveAfterResize( const KIID& aResizedShape );
219
230 std::vector<PCB_SHAPE*> Apply( const std::function<void( BOARD_ITEM* )>& aBeforeWrite = {} );
231
240 void ApplyReferenceValues( const std::function<void( BOARD_ITEM* )>& aBeforeWrite = {} );
241
245 CONSTRAINT_DIAGNOSIS Diagnose();
246
248
249 SNAPSHOT Snapshot() const { return m_system.Snapshot(); }
250 bool Restore( const SNAPSHOT& aSnapshot ) { return m_system.RestorePrefix( aSnapshot ); }
251 std::optional<VECTOR2I> AnchorPosition( const CONSTRAINT_MEMBER& aMember ) const;
254
262 int DropStaleRelations();
263
264private:
280
287 {
288 PCB_SHAPE* shape = nullptr;
290 PAD* pad = nullptr;
292 int startX = -1;
293 int endX = -1;
294 int radius = -1;
295 int focusX = -1;
296 int arcStartX = -1;
297 int arcEndX = -1;
298 int startAngle = -1;
299 int endAngle = -1;
301
303 int vertexCount = 0;
304
307 bool startIsLeft = true;
308 bool startIsTop = true;
309 };
310
314 {
315 int x = -1;
316 int y = -1;
317
318 bool IsValid() const { return x >= 0 && y >= 0; }
319 };
320
322 {
325 };
326
328 {
329 std::set<int> points;
330 std::vector<RIGID_RADIUS_HOLD> radii;
331 };
332
341
342 static BOARD_ITEM* itemOf( const SHAPE_VARS& aVars );
343
346 void coupleRigidFootprints( const std::set<FOOTPRINT*>& aFootprints, const std::set<KIID>* aFixedShapes,
347 std::set<int>& aFixed );
348
350 int pushParam( double aValue );
351 int temporaryParam( double aValue );
353 bool addSnapRelations( const ANCHOR_PARAMS& aAnchor,
354 const std::vector<SNAP_CANDIDATE>& aCandidates,
355 const VECTOR2I& aOffset );
356 RIGID_STATE collectRigidState( const std::set<KIID>& aEditedShapes ) const;
357 void holdRigidRadii( const std::vector<RIGID_RADIUS_HOLD>& aRadii, int aTag );
358
361 void recordReferenceValue( PCB_CONSTRAINT* aConstraint );
362
365 void holdFreeSegmentLengths( int aTag, const std::set<KIID>& aShapes );
366
369 void holdFreeArcRadii( int aTag, const std::set<KIID>& aShapes );
370
373 void holdShapesRigid( int aTag, const std::set<KIID>& aShapes );
374
376 void holdArcRadius( const SHAPE_VARS& aVars, int aTag );
377
380 void softPinPoint( const ANCHOR_PARAMS& aPoint, int aTag, std::optional<double> aWeight = std::nullopt );
381
383 void softPinPoint( int aPointX, int aTag, std::optional<double> aWeight = std::nullopt );
384
388 void softPinCoordinate( int aParam, int aTag, std::optional<double> aWeight = std::nullopt );
389
393 void pinUncommandedCoordinates( const std::set<int>& aCommanded, int aTag );
394
397 void holdPolygonVertices( const std::set<KIID>& aShapes, int aTag );
398
401 void pinDraggedShapeRest( const CONSTRAINT_MEMBER& aDragged, int aTag,
402 const CONSTRAINT_MEMBER* aCoDragged = nullptr );
403
406 void pinUneditedShapes( const std::set<KIID>& aEdited, int aTag );
407
411 bool solveSucceeded( int aSolveResult );
412 bool hardRelationsSatisfied() const;
413 bool parametersFinite() const;
414
416 std::vector<int> staleRelationTags() const;
417
420 ANCHOR_PARAMS anchorParams( const CONSTRAINT_MEMBER& aMember ) const;
421
424 PCB_DIM_ORTHOGONAL* orthogonalDimensionForMembers( const std::vector<CONSTRAINT_MEMBER>& aMembers ) const;
425
427 double normalizeX( int aIU ) const { return m_system.NormalizeX( aIU ); }
428 double normalizeY( int aIU ) const { return m_system.NormalizeY( aIU ); }
429 double denormalizeX( double aNorm ) const { return m_system.DenormalizeX( aNorm ); }
430 double denormalizeY( double aNorm ) const { return m_system.DenormalizeY( aNorm ); }
431
433 GCS::System* m_gcs;
434
435 // Compatibility alias while board geometry mapping remains in this adapter.
436 std::deque<double>& m_params;
437
438 std::map<KIID, SHAPE_VARS> m_shapeVars;
439
441 std::set<int> m_fixedParams;
442
446 std::map<int, KIID> m_tagToConstraint;
447 std::set<int> m_droppedTags;
448 std::set<int> m_nonDrivingTags;
449 std::map<int, std::vector<KIID>> m_tagMembers;
450 std::vector<PCB_CONSTRAINT*> m_referenceConstraints;
451 std::vector<KIID> m_unmapped;
452 std::vector<RIGID_FOOTPRINT> m_rigidFootprints;
453 std::set<KIID> m_rigidMembers;
454
458
459 double m_scale = 1.0;
460 double m_invScale = 1.0;
461
462 int m_dragTargetX = -1;
463 int m_dragTargetY = -1;
466 std::vector<int> m_temporaryParams;
468
469 // Hold tags reserved by Build() just past the mapped constraints' tags, so a hold can never
470 // collide with (and clear) a real constraint on a large cluster.
473
474 bool m_built = false;
475};
476
477
487{
488public:
489 bool HasBaseConflict() const { return m_baseConflict; }
490
491protected:
498 bool buildCluster( BOARD* aBoard, const std::unordered_set<KIID>& aClusterShapes,
499 const std::vector<PCB_CONSTRAINT*>& aConstraints );
500
502 void reset();
503
504 bool usable() const { return m_adapter && !m_baseConflict; }
505
507 bool rewind() { return m_adapter && m_adapter->Restore( m_baseline ); }
508
510 SNAP_RESULT startResult( const SNAP_SOURCE_CONTEXT& aContext ) const;
511
519 static void accept( SNAP_RESULT& aResult, const SNAP_CANDIDATE& aCandidate, double aResidual );
520
521 BOARD* m_board = nullptr;
522 std::unique_ptr<BOARD_CONSTRAINT_ADAPTER> m_adapter;
524 bool m_baseConflict = false;
525};
526
527
529{
530public:
531 bool Build( BOARD* aBoard, const CONSTRAINT_MEMBER& aDragged );
532 bool Matches( const CONSTRAINT_MEMBER& aDragged ) const;
533 bool IsExactFeasible( const VECTOR2I& aTarget );
535 const std::vector<SNAP_CANDIDATE>& aCandidates );
536
538 Solve( const VECTOR2I& aCursor, std::vector<PCB_SHAPE*>* aModified,
539 const std::function<void( BOARD_ITEM* )>& aBeforeModify, bool aIncludeDragged,
540 bool aStabilize, const std::set<KIID>& aEdited = {},
541 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged = std::nullopt );
542
543private:
546};
547
548
550{
551public:
552 bool Build( BOARD* aBoard, const std::vector<PCB_SHAPE*>& aEditedShapes,
553 const VECTOR2I& aReference );
555 const std::vector<SNAP_CANDIDATE>& aCandidates );
556 bool Solve( const VECTOR2I& aTarget, std::vector<PCB_SHAPE*>* aModified,
557 const std::function<void( BOARD_ITEM* )>& aBeforeModify );
558
559private:
560 bool feasibleAt( const VECTOR2I& aTarget );
561
563 std::set<KIID> m_edited;
564};
565
566
577{
578public:
581 bool Build( BOARD* aBoard, const std::vector<BOARD_ITEM*>& aBlockItems );
582
596 Solve( const std::vector<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aPinnedAnchors,
597 const std::set<KIID>& aTranslatedShapes, const VECTOR2I& aTranslation, std::vector<PCB_SHAPE*>* aModified,
598 const std::function<void( BOARD_ITEM* )>& aBeforeModify );
599};
600
601
631SolveCluster( BOARD* aBoard, const CONSTRAINT_MEMBER& aDragged, const VECTOR2I& aCursor,
632 std::vector<PCB_SHAPE*>* aModified = nullptr,
633 const std::function<void( BOARD_ITEM* )>& aBeforeModify = {}, bool aIncludeDragged = false,
634 bool aStabilize = false, const std::set<KIID>& aEdited = {},
635 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged = std::nullopt,
636 const std::set<KIID>& aFixedShapes = {}, bool aHoldDraggedRigid = false );
637
638
652std::set<KIID> ConstraintReferenceShapes( BOARD* aBoard, const PCB_CONSTRAINT* aConstraint );
653
654
669 std::vector<PCB_SHAPE*>* aModified = nullptr,
670 const std::function<void( BOARD_ITEM* )>& aBeforeModify = {},
671 const std::set<KIID>& aFixedShapes = {} );
672
673
676bool BoardHasConstraints( BOARD* aBoard );
677
678
681std::vector<VECTOR2I> ConstraintPinnedPositions( BOARD* aBoard, const std::set<KIID>& aItems );
682
683
688bool ConstraintItemIsLocked( const BOARD_ITEM* aItem );
689
690
693void ReSolveShapeClusters( BOARD* aBoard, const std::vector<PCB_SHAPE*>& aShapes,
694 std::vector<PCB_SHAPE*>* aModified = nullptr,
695 const std::function<void( BOARD_ITEM* )>& aBeforeModify = {} );
696
697
700bool ReSolveShapeClustersHoldingEdited( BOARD* aBoard, const std::vector<PCB_SHAPE*>& aEditedShapes,
701 std::vector<PCB_SHAPE*>* aModified = nullptr,
702 const std::function<void( BOARD_ITEM* )>& aBeforeModify = {} );
703
704
706void ReSolveAfterShapeResize( BOARD* aBoard, PCB_SHAPE* aShape, std::vector<PCB_SHAPE*>* aModified = nullptr,
707 const std::function<void( BOARD_ITEM* )>& aBeforeModify = {} );
708
709
716
717
723{
725 std::vector<KIID> shapeIds;
726 std::vector<KIID> dimensionIds;
727 std::vector<KIID> padIds;
728 int freeDof = 0;
729 std::vector<KIID> conflicting;
730 std::vector<KIID> redundant;
731 std::vector<KIID> erroredUnmapped;
732};
733
734
742{
743public:
746
748 void Clear();
749
751 std::size_t SolveCount() const { return m_solveCount; }
752
753private:
755 {
756 std::size_t hash = 0;
758 };
759
760 // Keyed by the cluster sorted constraint-id set which is stable across a geometry or value
761 // edit and changes only when a constraint is added to or removed from the cluster
762 std::map<std::vector<KIID>, CACHE_ENTRY> m_cache;
763 std::size_t m_solveCount = 0;
764};
765
766#endif // BOARD_CONSTRAINT_ADAPTER_H_
std::set< KIID > ConstraintReferenceShapes(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint)
The shapes a just-authored constraint should treat as an immovable reference, for the caller to pass ...
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).
std::vector< VECTOR2I > ConstraintPinnedPositions(BOARD *aBoard, const std::set< KIID > &aItems)
The distinct board positions that fixed positions pin on aItems.
bool BoardHasConstraints(BOARD *aBoard)
True if aBoard resolves at least one geometric constraint (see CollectResolvedConstraints()).
bool 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 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...
CONSTRAINT_DIAGNOSIS ApplyConstraintImmediately(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint, std::vector< PCB_SHAPE * > *aModified=nullptr, const std::function< void(BOARD_ITEM *)> &aBeforeModify={}, const std::set< KIID > &aFixedShapes={})
Solve a just-created constraint's cluster so the geometry snaps to satisfy it (SolidWorks-style),...
CONSTRAINT_BLOCK_RESULT
How a block edit solve turned out.
@ SOLVED
The constraints hold and every pinned point is exactly where it was put.
@ NOT_MODELED
Nothing the caller pinned belongs to this cluster.
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.
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, const std::set< KIID > &aFixedShapes={}, bool aHoldDraggedRigid=false)
Gather the cluster of shapes transitively constrained with the dragged shape, solve with the dragged ...
void recordReferenceValue(PCB_CONSTRAINT *aConstraint)
Note a non-driving valued constraint so its measured value can be read back after a solve.
void holdShapesRigid(int aTag, const std::set< KIID > &aShapes)
Hold the shapes in aShapes rigid, tagged aTag, so a shape the solve moves translates instead of stret...
BOARD_CONSTRAINT_ADAPTER(const BOARD_CONSTRAINT_ADAPTER &)=delete
BOARD_CONSTRAINT_ADAPTER & operator=(const BOARD_CONSTRAINT_ADAPTER &)=delete
std::set< int > m_droppedTags
Stale relations taken out of the system.
int m_coDragTargetY
Backing slot for the co-dragged pin y target.
std::vector< int > staleRelationTags() const
Driving constraint tags whose residual is already out of tolerance, ignoring dropped ones.
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 ...
void coupleRigidFootprints(const std::set< FOOTPRINT * > &aFootprints, const std::set< KIID > *aFixedShapes, std::set< int > &aFixed)
Tie every mapped child of each footprint in aFootprints to one shared translation,...
std::vector< KIID > m_unmapped
Constraints Build() could not map (not enforced).
double denormalizeX(double aNorm) const
std::set< int > m_fixedParams
Parameter indices the solver may not move, so a rigid translation may not either.
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...
bool addSnapRelations(const ANCHOR_PARAMS &aAnchor, const std::vector< SNAP_CANDIDATE > &aCandidates, const VECTOR2I &aOffset)
std::set< KIID > m_rigidMembers
Mapped items that move only with their footprint.
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...
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, bool aHoldDraggedRigid=false)
Solve the system, pinning a dragged anchor to a cursor position.
void softPinCoordinate(int aParam, int aTag, std::optional< double > aWeight=std::nullopt)
Hold the one coordinate at aParam where it sits, tagged aTag, with aWeight scaling the tier.
RIGID_STATE collectRigidState(const std::set< KIID > &aEditedShapes) const
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 qualifies while a Failed co...
void holdRigidRadii(const std::vector< RIGID_RADIUS_HOLD > &aRadii, int aTag)
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
std::vector< RIGID_FOOTPRINT > m_rigidFootprints
bool SolveAfterResize(const KIID &aResizedShape)
Solve after a resize.
int m_coDragTargetX
Backing slot for the co-dragged pin x target.
CONSTRAINT_SYSTEM_2D::SNAPSHOT SNAPSHOT
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::optional< VECTOR2I > AnchorPosition(const CONSTRAINT_MEMBER &aMember) const
bool Restore(const SNAPSHOT &aSnapshot)
bool SolveRigidTranslation(const std::set< KIID > &aEditedShapes, const VECTOR2I &aTranslation)
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...
bool SolveRigidSnapRelations(const std::set< KIID > &aEditedShapes, const VECTOR2I &aReference, const std::vector< SNAP_CANDIDATE > &aCandidates, const VECTOR2I &aCursor, VECTOR2I &aResolvedCursor)
std::set< int > m_groundedPositionParams
The subset of those grounded by a FIXED_POSITION constraint rather than by a lock or a driving consta...
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.
void pinUncommandedCoordinates(const std::set< int > &aCommanded, int aTag)
Weakly hold every cluster coordinate outside aCommanded where it sits, tagged aTag,...
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={}, const std::vector< PAD * > &aPads={})
Translate a cluster into a planegcs system.
bool TravelsWhole(const std::set< KIID > &aEditedShapes) const
True when every shape in the cluster is in aEditedShapes and free to travel with it.
int pushParam(double aValue)
Append a normalized coordinate to the backing store, returning its stable index.
static BOARD_ITEM * itemOf(const SHAPE_VARS &aVars)
CONSTRAINT_DIAGNOSIS Diagnose()
Report degrees of freedom and conflicting/redundant constraints.
CONSTRAINT_BLOCK_RESULT SolveBlockEdit(const std::vector< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aPinnedAnchors, const std::set< KIID > &aTranslatedShapes, const VECTOR2I &aTranslation)
Solve a block edit whose geometry the caller has already written.
int DropStaleRelations()
Remove the constraints the current geometry already fails to satisfy.
std::set< int > m_nonDrivingTags
Measurement-only; excluded from conflict residuals.
double normalizeX(int aIU) const
IU <-> normalized (millimetre, cluster-centred) frame, per axis.
@ PAD_CENTER
A pad's centre point, which only ever moves with its footprint.
@ RECTANGLE
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.
bool SolveSnapRelations(const CONSTRAINT_MEMBER &aDragged, const std::vector< SNAP_CANDIDATE > &aCandidates, const VECTOR2I &aCursor)
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).
One block edit session, holding several anchors and one travel offset at once.
bool Build(BOARD *aBoard, const std::vector< BOARD_ITEM * > &aBlockItems)
Build one adapter over the clusters holding aBlockItems.
CONSTRAINT_BLOCK_RESULT Solve(const std::vector< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aPinnedAnchors, const std::set< KIID > &aTranslatedShapes, const VECTOR2I &aTranslation, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Solve one frame of the block edit and apply it.
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.
bool IsExactFeasible(const VECTOR2I &aTarget)
bool Build(BOARD *aBoard, const CONSTRAINT_MEMBER &aDragged)
CONSTRAINT_DIAGNOSIS Solve(const VECTOR2I &aCursor, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify, bool aIncludeDragged, bool aStabilize, const std::set< KIID > &aEdited={}, const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aCoDragged=std::nullopt)
SNAP_RESULT ResolveCandidates(const SNAP_SOURCE_CONTEXT &aContext, const std::vector< SNAP_CANDIDATE > &aCandidates)
bool Matches(const CONSTRAINT_MEMBER &aDragged) const
bool feasibleAt(const VECTOR2I &aTarget)
bool Solve(const VECTOR2I &aTarget, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
bool Build(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aEditedShapes, const VECTOR2I &aReference)
SNAP_RESULT ResolveCandidates(const SNAP_SOURCE_CONTEXT &aContext, const std::vector< SNAP_CANDIDATE > &aCandidates)
One editing session over a constraint cluster.
BOARD_CONSTRAINT_ADAPTER::SNAPSHOT m_baseline
bool rewind()
Rewind to the state the next speculative solve starts from.
SNAP_RESULT startResult(const SNAP_SOURCE_CONTEXT &aContext) const
Seed a snap result at the cursor, rejecting a cluster that was already broken.
void reset()
Drop the built cluster, leaving the session unusable until the next successful build.
bool buildCluster(BOARD *aBoard, const std::unordered_set< KIID > &aClusterShapes, const std::vector< PCB_CONSTRAINT * > &aConstraints)
Assemble the adapter for one cluster and record its baseline.
std::unique_ptr< BOARD_CONSTRAINT_ADAPTER > m_adapter
static void accept(SNAP_RESULT &aResult, const SNAP_CANDIDATE &aCandidate, double aResidual)
Record one candidate the session honoured.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
std::vector< double > SNAPSHOT
Definition pad.h:61
A geometric constraint between board items (issue #2329).
Abstract dimension API.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
@ REFUSED
The target cannot represent this file.
Param indices of an anchor coordinates a rect corner aliases mixed start end params so y is not alway...
A footprint moving as one body with its translation from buildPosition held in the params at translat...
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 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).
PAD * pad
set instead of shape for a PAD_CENTER
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.
CLUSTER_DIAGNOSIS result
std::size_t hash
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).
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 > padIds
Cluster pads.
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.
std::vector< KIID > conflicting
Constraints the solver reports as over-constraining.
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
Definition vector2d.h:708