31#include <unordered_map>
32#include <unordered_set>
73 { return !aFootprint->Constraints().empty(); } );
79 std::vector<VECTOR2I> positions;
91 if( !aItems.contains( member.m_item ) )
96 if( pos && std::ranges::find( positions, *pos ) == positions.end() )
97 positions.push_back( *pos );
115 return parent && parent->
IsLocked();
138 if( aOnBoard && !aOnBoard->contains( aId ) )
149 std::unordered_map<KIID, std::vector<PCB_CONSTRAINT*>>
byMember;
162 std::vector<KIID>* aErrored =
nullptr,
const std::unordered_set<KIID>* aOnBoard =
nullptr )
165 std::unordered_map<KIID, std::vector<PCB_CONSTRAINT*>>& map = graph.
byMember;
169 bool errored = constraint->GetMembers().empty();
173 map[member.m_item].push_back( constraint );
181 if( errored && aErrored )
182 aErrored->push_back( constraint->m_Uuid );
192 std::vector<KIID> constrained;
196 if( map.contains( aChild->m_Uuid ) )
197 constrained.push_back( aChild->m_Uuid );
200 for(
const BOARD_ITEM* child : footprint->GraphicalItems() )
203 for(
const PAD*
pad : footprint->Pads() )
206 if( constrained.size() < 2 )
210 for(
size_t i = 1; i < constrained.size(); ++i )
212 graph.
rigidSiblings[constrained.front()].push_back( constrained[i] );
213 graph.
rigidSiblings[constrained[i]].push_back( constrained.front() );
225 std::unordered_set<KIID>& aClusterShapes, std::vector<PCB_CONSTRAINT*>& aClusterConstraints,
226 std::set<KIID>* aVisited =
nullptr )
229 std::vector<KIID> frontier{ aSeed };
230 aClusterShapes.insert( aSeed );
232 while( !frontier.empty() )
234 KIID shapeId = frontier.back();
238 aVisited->insert( shapeId );
242 for(
const KIID& sibling : siblings->second )
244 if( aClusterShapes.insert( sibling ).second )
245 frontier.push_back( sibling );
249 auto it = aGraph.
byMember.find( shapeId );
256 if( used.insert( constraint->
m_Uuid ).second )
257 aClusterConstraints.push_back( constraint );
261 if( aClusterShapes.insert( member.m_item ).second )
262 frontier.push_back( member.m_item );
274 const std::unordered_set<KIID>* aOnBoard )
276 std::vector<T*> items;
278 for(
const KIID&
id : aIds )
280 if(
T* item =
dynamic_cast<T*
>(
resolveMember( aBoard, aOnBoard,
id ) ) )
281 items.push_back( item );
289 const std::unordered_set<KIID>* aOnBoard =
nullptr )
296 const std::unordered_set<KIID>& aIds,
297 const std::unordered_set<KIID>* aOnBoard =
nullptr )
304 const std::unordered_set<KIID>* aOnBoard =
nullptr )
324 return std::hypot( *aLine.p2.x - *aLine.p1.x, *aLine.p2.y - *aLine.p1.y ) < 1e-9;
330 const double ax[2] = { *aL1.p1.x, *aL1.p2.x };
331 const double ay[2] = { *aL1.p1.y, *aL1.p2.y };
332 const double bx[2] = { *aL2.p1.x, *aL2.p2.x };
333 const double by[2] = { *aL2.p1.y, *aL2.p2.y };
336 double best = std::numeric_limits<double>::max();
338 for(
int i = 0; i < 2; ++i )
340 for(
int j = 0; j < 2; ++j )
342 double dist = std::hypot( ax[i] - bx[j], ay[i] - by[j] );
353 double d1x = ax[1] - ax[0], d1y = ay[1] - ay[0];
354 double d2x = bx[1] - bx[0], d2y = by[1] - by[0];
355 double theta = std::atan2( d1x * d2y - d1y * d2x, d1x * d2x + d1y * d2y );
359 double alpha =
std::abs( std::remainder( aCornerDeg *
M_PI / 180.0, 2.0 *
M_PI ) );
360 double shift = ( vB -
vA ) *
M_PI;
361 double c1 = alpha - shift;
362 double c2 = -alpha - shift;
364 double d1 =
std::abs( std::remainder( theta - c1, 2.0 *
M_PI ) );
365 double d2 =
std::abs( std::remainder( theta - c2, 2.0 *
M_PI ) );
367 return d1 <= d2 ? c1 : c2;
377static double arcSweepTarget(
double aStartAngle,
double aEndAngle,
double aSweepDeg )
379 double current = aEndAngle - aStartAngle;
382 return current - std::remainder( current - alpha, 2.0 *
M_PI );
400 return m_system.AddParameter( aValue );
423 if( aConstraint && !aConstraint->
IsDriving() )
435 const std::vector<CONSTRAINT_MEMBER>& members = constraint->GetMembers();
437 if( members.empty() )
440 auto it =
m_shapeVars.find( members.front().m_item );
445 const PCB_SHAPE* shape = it->second.shape;
446 std::optional<double> value;
451 switch( constraint->GetConstraintType() )
457 if( members.size() == 2 )
459 auto anchorPos = [&](
const CONSTRAINT_MEMBER& aMember ) -> std::optional<VECTOR2I>
470 std::optional<VECTOR2I> pa = anchorPos( members[0] );
471 std::optional<VECTOR2I> pb = anchorPos( members[1] );
484 value = ( *pb - *pa ).EuclideanNorm();
501 if( members.size() != 2 )
504 auto other =
m_shapeVars.find( members[1].m_item );
509 const PCB_SHAPE* shapeB = other->second.shape;
529 std::optional<double> current = constraint->GetValue();
531 if( current &&
std::abs( *value - *current ) <= tol )
535 aBeforeWrite( constraint );
537 constraint->SetValue( value );
576 case 0:
return { leftX, topY };
577 case 1:
return { rightX, topY };
578 case 2:
return { rightX, botY };
579 default:
return { leftX, botY };
617 if( aMembers.size() != 2 || aMembers[0].m_item != aMembers[1].m_item )
642 const std::vector<PCB_CONSTRAINT*>& aConstraints,
643 const std::set<KIID>* aFixedShapes,
644 const std::vector<PCB_DIMENSION_BASE*>& aDimensions,
645 const std::vector<PAD*>& aPads )
665 if( aShapes.empty() && aDimensions.empty() && aPads.empty() )
670 VECTOR2I origin = !aShapes.empty() ? aShapes.front()->GetStart()
671 : !aDimensions.empty() ? aDimensions.front()->GetStart()
672 : aPads.front()->GetPosition();
679 std::vector<std::pair<int, int>> lockedRanges;
682 std::vector<int> ellipseOffsetParams;
688 int firstParam =
static_cast<int>(
m_params.size() );
703 vars.
startIsLeft = shape->GetStart().x <= shape->GetEnd().x;
704 vars.
startIsTop = shape->GetStart().y <= shape->GetEnd().y;
724 for(
int i = 1; i < outline.
PointCount(); ++i )
779 m_gcs->addConstraintArcRules( arc );
786 double major = shape->GetEllipseMajorRadius();
787 double minor = shape->GetEllipseMinorRadius();
788 double phi = shape->GetEllipseRotation().AsRadians();
789 EDA_ANGLE startAngle = shape->GetEllipseStartAngle();
790 EDA_ANGLE endAngle = shape->GetEllipseEndAngle();
794 std::swap( major, minor );
801 double focal = std::sqrt( major * major - minor * minor );
815 ellipseOffsetParams.push_back( offX );
816 ellipseOffsetParams.push_back( offY );
833 GCS::ArcOfEllipse arc;
841 m_gcs->addConstraintArcOfEllipseRules( arc );
852 lockedRanges.emplace_back( firstParam,
static_cast<int>(
m_params.size() ) );
869 switch( dimension->Type() )
897 std::set<int> fixedParams;
901 std::set<int> groundedPositions;
903 for(
const auto& [first, last] : lockedRanges )
905 for(
int i = first; i < last; ++i )
906 fixedParams.insert( i );
909 for(
int i : ellipseOffsetParams )
910 fixedParams.insert( i );
912 std::set<FOOTPRINT*> rigidFootprints;
917 rigidFootprints.insert( footprint );
922 auto pointAt = [&](
int aXIndex ) -> GCS::Point
929 auto pointFor = [&](
const ANCHOR_PARAMS& aParams ) -> GCS::Point
944 aLine.p1 = pointAt( it->second.startX );
945 aLine.p2 = pointAt( it->second.endX );
951 auto circleFor = [&](
const CONSTRAINT_MEMBER& aMember, GCS::Circle& aCircle ) ->
bool
961 aCircle.center = pointAt( it->second.startX );
962 aCircle.rad = &
m_params[it->second.radius];
968 auto ellipseFor = [&](
const CONSTRAINT_MEMBER& aMember, GCS::Ellipse& aEllipse ) ->
bool
978 aEllipse.center = pointAt( it->second.startX );
979 aEllipse.focus1 = pointAt( it->second.focusX );
980 aEllipse.radmin = &
m_params[it->second.radius];
985 auto pushConstant = [&](
double aIU ) ->
int
988 fixedParams.insert( idx );
996 const std::vector<CONSTRAINT_MEMBER>& members = constraint->GetMembers();
999 switch( constraint->GetConstraintType() )
1005 if( members.size() == 2 && lineFor( members[0], l1 ) && lineFor( members[1], l2 ) )
1007 m_gcs->addConstraintParallel( l1, l2, tag );
1018 if( members.size() == 1 )
1022 if( lineFor( members[0], l ) )
1024 m_gcs->addConstraintHorizontal( l, tag );
1028 else if( members.size() == 2 )
1035 GCS::Point p1 = pointFor( a );
1036 GCS::Point p2 = pointFor( b );
1037 m_gcs->addConstraintHorizontal( p1, p2, tag );
1047 if( members.size() == 1 )
1051 if( lineFor( members[0], l ) )
1053 m_gcs->addConstraintVertical( l, tag );
1057 else if( members.size() == 2 )
1064 GCS::Point p1 = pointFor( a );
1065 GCS::Point p2 = pointFor( b );
1066 m_gcs->addConstraintVertical( p1, p2, tag );
1081 GCS::Point p1 = pointFor( a );
1082 GCS::Point p2 = pointFor( b );
1083 m_gcs->addConstraintP2PCoincident( p1, p2, tag );
1096 fixedParams.insert( a.
x );
1097 fixedParams.insert( a.
y );
1098 groundedPositions.insert( a.
x );
1099 groundedPositions.insert( a.
y );
1110 if( members.size() == 2 && lineFor( members[0], l1 ) && lineFor( members[1], l2 ) )
1112 m_gcs->addConstraintPerpendicular( l1, l2, tag );
1123 if( members.size() == 2 && lineFor( members[0], l1 ) && lineFor( members[1], l2 ) )
1125 m_gcs->addConstraintEqualLength( l1, l2, tag );
1139 if( p.
IsValid() && lineFor( members[1], l ) )
1141 GCS::Point point = pointFor( p );
1142 m_gcs->addConstraintPointOnLine( point, l, tag );
1145 else if( p.
IsValid() && circleFor( members[1], circ ) )
1148 GCS::Point point = pointFor( p );
1149 m_gcs->addConstraintPointOnCircle( point, circ, tag );
1152 else if( p.
IsValid() && ellipseFor( members[1], ell ) )
1154 GCS::Point point = pointFor( p );
1155 m_gcs->addConstraintPointOnEllipse( point, ell, tag );
1168 if( p.
IsValid() && lineFor( members[1], seg ) )
1170 GCS::Point mid = pointFor( p );
1171 m_gcs->addConstraintP2PSymmetric( seg.p1, seg.p2, mid, tag );
1183 if( members.size() == 2 && lineFor( members[0], l1 ) && lineFor( members[1], l2 ) )
1185 m_gcs->addConstraintPointOnLine( l2.p1, l1, tag );
1186 m_gcs->addConstraintPointOnLine( l2.p2, l1, tag );
1201 GCS::Point pa = pointFor( a );
1202 GCS::Point pb = pointFor( b );
1203 m_gcs->addConstraintP2PSymmetric( pa, pb, axis, tag );
1214 if( members.size() == 1 && constraint->HasValue() && lineFor( members[0], l ) )
1216 int len = pushConstant( *constraint->GetValue() );
1217 m_gcs->addConstraintP2PDistance( l.p1, l.p2, &
m_params[len], tag, constraint->IsDriving() );
1220 if( constraint->IsDriving() )
1223 it->second.fixedLengthParam = len;
1230 else if( members.size() == 2 && constraint->HasValue() )
1244 int aAxis = horiz ? a.
x : a.
y;
1245 int bAxis = horiz ? b.
x : b.
y;
1247 double sign = gap >= 0.0 ? 1.0 : -1.0;
1248 int len = pushConstant(
sign * *constraint->GetValue() );
1251 &
m_params[len], tag, constraint->IsDriving() );
1255 GCS::Point pa = pointFor( a );
1256 GCS::Point pb = pointFor( b );
1257 int len = pushConstant( *constraint->GetValue() );
1258 m_gcs->addConstraintP2PDistance( pa, pb, &
m_params[len], tag,
1259 constraint->IsDriving() );
1274 if( members.size() == 1 && constraint->HasValue() && circleFor( members[0], c ) )
1276 int rad = pushConstant( *constraint->GetValue() );
1277 m_gcs->addConstraintCircleRadius( c, &
m_params[rad], tag, constraint->IsDriving() );
1289 if( members.size() == 2 && circleFor( members[0], c1 ) && circleFor( members[1], c2 ) )
1291 m_gcs->addConstraintEqualRadius( c1, c2, tag );
1301 auto centerOf = [&](
const CONSTRAINT_MEMBER& aMember, GCS::Point& aOut ) ->
bool
1306 if( circleFor( aMember, c ) )
1312 if( ellipseFor( aMember, e ) )
1323 if( members.size() == 2 && centerOf( members[0], p1 ) && centerOf( members[1], p2 ) )
1325 m_gcs->addConstraintP2PCoincident( p1, p2, tag );
1336 if( members.size() == 2 && constraint->HasValue() && lineFor( members[0], l1 )
1340 fixedParams.insert( angle );
1341 m_gcs->addConstraintL2LAngle( l1, l2, &
m_params[angle], tag, constraint->IsDriving() );
1355 bool validSweep = constraint->HasValue() && *constraint->GetValue() > 0.0
1356 && *constraint->GetValue() < 360.0;
1362 *constraint->GetValue() );
1364 fixedParams.insert( tgt );
1366 &
m_params[tgt], tag, constraint->IsDriving() );
1376 if( members.size() != 2 )
1384 int lineIdx = lineFor( members[0], l ) ? 0 : ( lineFor( members[1], l ) ? 1 : -1 );
1390 if( circleFor( other, c1 ) )
1393 double dx = *l.p2.x - *l.p1.x;
1394 double dy = *l.p2.y - *l.p1.y;
1395 double cross = dx * ( *c1.center.y - *l.p1.y ) - dy * ( *c1.center.x - *l.p1.x );
1397 m_gcs->addConstraintTangent( l, c1, cross > 0.0, tag );
1400 else if( ellipseFor( other, ell ) )
1402 m_gcs->addConstraintTangent( l, ell, tag );
1406 else if( circleFor( members[0], c1 ) && circleFor( members[1], c2 ) )
1408 m_gcs->addConstraintTangent( c1, c2, tag );
1432 if( !constraint->IsDriving() )
1440 switch( constraint->GetConstraintType() )
1447 if( constraint->GetMembers().size() != 1 )
1478 std::set<int> referencedDimParams;
1482 if( unmappedConstraints.contains( constraint->m_Uuid ) )
1492 referencedDimParams.insert(
anchor.x );
1501 fixedParams.insert( vars.startX );
1502 fixedParams.insert( vars.startX + 1 );
1512 for(
int pointX : { vars.startX, vars.endX } )
1514 if( pointX >= 0 && (
locked || !referencedDimParams.contains( pointX ) ) )
1516 fixedParams.insert( pointX );
1517 fixedParams.insert( pointX + 1 );
1523 GCS::VEC_pD unknowns;
1525 for(
int i = 0; i < static_cast<int>(
m_params.size() ); ++i )
1527 if( !fixedParams.contains( i ) )
1528 unknowns.push_back( &
m_params[i] );
1533 m_gcs->declareUnknowns( unknowns );
1534 m_gcs->initSolution();
1560 const std::set<KIID>* aFixedShapes, std::set<int>& aFixed )
1562 for(
FOOTPRINT* footprint : aFootprints )
1564 std::set<KIID> children;
1565 bool frozen =
false;
1574 children.insert( kiid );
1584 aFixed.insert( hold.
radius );
1588 for(
int pointX : state.
points )
1590 aFixed.insert( pointX );
1591 aFixed.insert( pointX + 1 );
1603 for(
int pointX : state.
points )
1605 for(
int axis : { 0, 1 } )
1608 aFixed.insert( origin );
1637 m_gcs->initSolution();
1638 int ret =
m_gcs->solve();
1639 m_gcs->applySolution();
1643 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
1664 if( vars.radius < 0 )
1669 c.center = GCS::Point{ &
m_params[vars.startX], &
m_params[vars.startX + 1] };
1672 if( kiid == aResizedShape )
1680 m_gcs->addConstraintCoordinateX( c.center, &
m_params[cx], GCS::DefaultTemporaryConstraint );
1681 m_gcs->addConstraintCoordinateY( c.center, &
m_params[cy], GCS::DefaultTemporaryConstraint );
1686 m_gcs->addConstraintCircleRadius( c, &
m_params[target], GCS::DefaultTemporaryConstraint );
1698 m_gcs->initSolution();
1699 int ret =
m_gcs->solve();
1700 m_gcs->applySolution();
1704 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
1712 const std::set<KIID>& aEdited,
1713 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged,
1714 bool aHoldDraggedRigid )
1741 double len = std::hypot( dx, dy );
1753 && it->second.fixedLengthParam >= 0
1759 double dx = targetX -
m_params[farX];
1760 double dy = targetY -
m_params[farX + 1];
1761 double len = std::hypot( dx, dy );
1763 if( len > 1e-9 && segLen > 1e-9 )
1765 targetX =
m_params[farX] + dx * segLen / len;
1766 targetY =
m_params[farX + 1] + dy * segLen / len;
1790 coDragged = &aCoDragged->first;
1814 if( aHoldDraggedRigid )
1820 std::set<KIID> editedShapes = aEdited;
1821 editedShapes.insert( aDragged.
m_item );
1824 editedShapes.insert( coDragged->
m_item );
1830 std::set<KIID> heldPolygons = editedShapes;
1833 heldPolygons.erase( aDragged.
m_item );
1837 m_gcs->initSolution();
1838 int ret =
m_gcs->solve();
1839 m_gcs->applySolution();
1843 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
1850 const std::vector<SNAP_CANDIDATE>& aCandidates,
1854 bool addedRelation =
false;
1856 const auto addCoordinateX = [&](
double aCoordinate )
1859 m_gcs->addConstraintCoordinateX(
anchor, &
m_params[target], GCS::DefaultTemporaryConstraint );
1860 addedRelation =
true;
1862 const auto addCoordinateY = [&](
double aCoordinate )
1865 m_gcs->addConstraintCoordinateY(
anchor, &
m_params[target], GCS::DefaultTemporaryConstraint );
1866 addedRelation =
true;
1870 if( aCandidate.direction.SquaredEuclideanNorm() <= 1e-12 )
1873 VECTOR2D direction = aCandidate.direction * ( 1000000.0 / aCandidate.direction.EuclideanNorm() );
1882 m_gcs->addConstraintPointOnLine(
anchor, line, GCS::DefaultTemporaryConstraint );
1883 addedRelation =
true;
1888 switch( candidate.relation )
1893 addCoordinateX( candidate.origin.x );
1894 addCoordinateY( candidate.origin.y );
1905 if( candidate.direction.x != 0.0 )
1906 addCoordinateX( candidate.origin.x );
1907 else if( candidate.direction.y != 0.0 )
1908 addCoordinateY( candidate.origin.y );
1920 if( !candidate.manifold )
1926 if(
const CIRCLE*
circle = std::get_if<CIRCLE>( &*candidate.manifold ) )
1931 else if(
const SHAPE_ARC* arc = std::get_if<SHAPE_ARC>( &*candidate.manifold ) )
1933 center = arc->GetCenter();
1934 radius = arc->GetRadius();
1948 m_gcs->addConstraintPointOnCircle(
anchor,
circle, GCS::DefaultTemporaryConstraint );
1949 addedRelation =
true;
1955 return addedRelation;
1964 const auto addPoint = [&](
int aPointX )
1967 state.
points.insert( aPointX );
1970 for(
const KIID&
id : aEditedShapes )
1986 addPoint( vars.
endX );
2017 addPoint( vars.
startX + 2 * i );
2045 const std::vector<SNAP_CANDIDATE>& aCandidates,
2065 int xPin =
m_gcs->addConstraintCoordinateX(
anchor, &
m_params[cursorX], GCS::DefaultTemporaryConstraint );
2066 int yPin =
m_gcs->addConstraintCoordinateY(
anchor, &
m_params[cursorY], GCS::DefaultTemporaryConstraint );
2073 m_gcs->initSolution();
2074 int ret =
m_gcs->solve();
2075 m_gcs->applySolution();
2078 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
2086 [&](
const auto& aEntry )
2088 return aEditedShapes.contains( aEntry.first )
2098 if( !
m_built || aEditedShapes.empty() )
2103 if( state.
points.empty() )
2106 const bool movesGroundedPoint =
2107 std::ranges::any_of( state.
points,
2110 return m_fixedParams.contains( aPointX ) || m_fixedParams.contains( aPointX + 1 );
2114 if( movesGroundedPoint && aTranslation !=
VECTOR2I() )
2119 std::map<int, VECTOR2I> exactTargets;
2121 for(
int pointX : state.
points )
2135 for(
int pointX : state.
points )
2136 softPinPoint( pointX, GCS::DefaultTemporaryConstraint );
2141 m_gcs->initSolution();
2142 int ret =
m_gcs->solve();
2143 m_gcs->applySolution();
2146 for(
const auto& [pointX, target] : exactTargets )
2150 solved = solved && resolved == target;
2153 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
2160 const std::set<KIID>& aTranslatedShapes,
const VECTOR2I& aTranslation )
2168 std::map<int, int> targetsX;
2169 std::map<int, int> targetsY;
2176 const bool carriesGroundedPoint = std::ranges::any_of(
2180 return m_groundedPositionParams.contains( aPointX ) || m_groundedPositionParams.contains( aPointX + 1 );
2183 if( carriesGroundedPoint && aTranslation !=
VECTOR2I() )
2186 for(
int pointX : carried.
points )
2194 bool groundedAnchorPicked =
false;
2196 for(
const auto& [member, target] : aPinnedAnchors )
2207 groundedAnchorPicked =
true;
2209 targetsX[
anchor.x] = target.x;
2212 groundedAnchorPicked =
true;
2214 targetsY[
anchor.y] = target.y;
2218 if( targetsX.empty() && targetsY.empty() && !groundedAnchorPicked )
2223 std::set<int> commanded;
2225 for(
const auto& [param, target] : targetsX )
2228 commanded.insert( param );
2231 for(
const auto& [param, target] : targetsY )
2234 commanded.insert( param );
2241 for(
int param : commanded )
2246 m_gcs->initSolution();
2247 int ret =
m_gcs->solve();
2248 m_gcs->applySolution();
2252 for(
const auto& [param, target] : targetsX )
2255 for(
const auto& [param, target] : targetsY )
2258 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
2265 const std::vector<SNAP_CANDIDATE>& aCandidates,
2268 if( !
m_built || aEditedShapes.empty() )
2273 if( state.
points.empty() )
2277 const int anchorX = *state.
points.begin();
2280 const VECTOR2I cursorToAnchor = anchorAtBaseline - aReference;
2281 std::map<int, VECTOR2I> baselinePoints;
2283 for(
int pointX : state.
points )
2288 if( pointX == anchorX )
2294 GCS::DefaultTemporaryConstraint );
2296 GCS::DefaultTemporaryConstraint );
2299 bool addedRelation =
addSnapRelations( { anchorX, anchorX + 1 }, aCandidates, cursorToAnchor );
2305 int xPin =
m_gcs->addConstraintCoordinateX(
anchor, &
m_params[cursorX], GCS::DefaultTemporaryConstraint );
2306 int yPin =
m_gcs->addConstraintCoordinateY(
anchor, &
m_params[cursorY], GCS::DefaultTemporaryConstraint );
2310 m_gcs->initSolution();
2311 int ret =
m_gcs->solve();
2312 m_gcs->applySolution();
2313 bool solved =
solveSucceeded( ret ) && ( addedRelation || aCandidates.empty() );
2317 aResolvedCursor = resolvedAnchor - cursorToAnchor;
2318 VECTOR2I translation = aResolvedCursor - aReference;
2320 for(
const auto& [pointX, baseline] : baselinePoints )
2324 solved = solved && resolved == baseline + translation;
2327 m_gcs->clearByTag( GCS::DefaultTemporaryConstraint );
2343 if( !verified.
Accepted( candidate.id ) )
2347 return verified.
position == aResolvedCursor;
2356 return std::nullopt;
2365 if( ( aSolveResult == GCS::Success || aSolveResult == GCS::Converged ) &&
parametersFinite() )
2374 return std::ranges::all_of(
m_params,
2377 return std::isfinite( aParam );
2391 const double residualTol = 1e-3;
2395 double structuralErr =
m_gcs->calculateConstraintErrorByTag( 0 );
2397 if( std::isfinite( structuralErr ) &&
std::abs( structuralErr ) > residualTol )
2406 const double residualTol = 1e-3;
2407 std::vector<int> stale;
2415 double err =
m_gcs->calculateConstraintErrorByTag( tag );
2417 if( !std::isfinite( err ) ||
std::abs( err ) > residualTol )
2418 stale.push_back( tag );
2429 for(
int tag : stale )
2431 m_gcs->clearByTag( tag );
2437 if( !stale.empty() )
2438 m_gcs->initSolution();
2440 return (
int) stale.size();
2447 std::set<int> xParams;
2448 std::set<int> yParams;
2449 std::set<int> radiusParams;
2451 const auto addPoint =
2456 xParams.insert( aX );
2457 yParams.insert( aX + 1 );
2463 addPoint( vars.startX );
2464 addPoint( vars.endX );
2465 addPoint( vars.arcStartX );
2466 addPoint( vars.arcEndX );
2467 addPoint( vars.focusX );
2471 for(
int i = 0; i < vars.vertexCount; ++i )
2472 addPoint( vars.startX + 2 * i );
2475 if( vars.radius >= 0 )
2476 radiusParams.insert( vars.radius );
2479 for(
int index : xParams )
2482 for(
int index : yParams )
2485 for(
int index : radiusParams )
2497 wxASSERT( !aWeight || *aWeight > 0 );
2506 int cx =
m_gcs->addConstraintCoordinateX( point, &
m_params[pinX], aTag );
2507 int cy =
m_gcs->addConstraintCoordinateY( point, &
m_params[pinY], aTag );
2511 m_gcs->rescaleConstraint( cx, *aWeight );
2512 m_gcs->rescaleConstraint( cy, *aWeight );
2527 wxASSERT( !aWeight || *aWeight > 0 );
2536 m_gcs->rescaleConstraint(
id, *aWeight );
2549 bool commandedShape =
false;
2551 for(
int pointX : state.
points )
2552 commandedShape = commandedShape || aCommanded.contains( pointX ) || aCommanded.contains( pointX + 1 );
2556 for(
int pointX : state.
points )
2558 if( !aCommanded.contains( pointX ) )
2561 if( !aCommanded.contains( pointX + 1 ) )
2575 if( !commandedShape )
2623 ( aDragged.
m_index + 2 ) % 4 ) ),
2650 auto holdRadius = [&](
const SHAPE_VARS& aVars )
2662 if( aEdited.contains( kiid ) )
2701 for(
int i = 0; i < vars.vertexCount; ++i )
2721 if( !aShapes.contains( kiid ) )
2724 for(
int i = 0; i < vars.vertexCount; ++i )
2738 if( !aShapes.contains( kiid ) )
2746 m_gcs->addConstraintP2PDistance( p1, p2, &
m_params[len], aTag );
2771 if( !aShapes.contains( kiid ) )
2789 if( state.
points.empty() )
2793 const int anchorX = *state.
points.begin();
2795 for(
int pointX : state.
points )
2797 if( pointX == anchorX )
2814 std::vector<PCB_SHAPE*> changed;
2820 auto pointAt = [&](
int aX )
2831 VECTOR2I delta = body.buildPosition + translation - body.footprint->GetPosition();
2837 aBeforeWrite( body.footprint );
2839 body.footprint->Move(
delta );
2850 VECTOR2I start = pointAt( vars.startX );
2853 VECTOR2I end = vars.endX >= 0 ? pointAt( vars.endX ) : vars.dimension->GetEnd();
2855 if( start == vars.dimension->GetStart() &&
end == vars.dimension->GetEnd() )
2859 aBeforeWrite( vars.dimension );
2866 vars.dimension->SetStart( start );
2867 vars.dimension->SetEnd(
end );
2872 vars.dimension->Update();
2881 if(
center == vars.shape->GetCenter() &&
radius == vars.shape->GetRadius() )
2885 aBeforeWrite( vars.shape );
2887 vars.shape->SetCenter(
center );
2888 vars.shape->SetRadius(
radius );
2889 changed.push_back( vars.shape );
2901 VECTOR2I start = pointAt( vars.arcStartX );
2904 if( start == vars.shape->GetStart() &&
end == vars.shape->GetEnd()
2905 &&
center == vars.shape->GetCenter() )
2911 aBeforeWrite( vars.shape );
2916 double sa = std::atan2( start.
y -
center.y, start.
x -
center.x );
2919 if( vars.shape->IsClockwiseArc() )
2929 double midAngle = 0.5 * ( sa + ea );
2933 vars.shape->SetArcGeometry( start, mid,
end );
2934 changed.push_back( vars.shape );
2945 double focal = std::hypot( fx, fy );
2947 double major = std::sqrt( focal * focal + minor * minor );
2952 focal > 1.0 ?
EDA_ANGLE( std::atan2( fy, fx ),
RADIANS_T ) : vars.shape->GetEllipseRotation();
2954 EDA_ANGLE startAngle = vars.shape->GetEllipseStartAngle();
2955 EDA_ANGLE endAngle = vars.shape->GetEllipseEndAngle();
2965 return std::abs( ( aA - aB ).Normalize180().AsDegrees() ) < 1e-6;
2968 if(
center == vars.shape->GetEllipseCenter() &&
KiROUND( major ) == vars.shape->GetEllipseMajorRadius()
2969 &&
KiROUND( minor ) == vars.shape->GetEllipseMinorRadius()
2970 && sameAngle( rotation, vars.shape->GetEllipseRotation() )
2971 && sameAngle( startAngle, vars.shape->GetEllipseStartAngle() )
2972 && sameAngle( endAngle, vars.shape->GetEllipseEndAngle() ) )
2978 aBeforeWrite( vars.shape );
2980 vars.shape->SetEllipseCenter(
center );
2981 vars.shape->SetEllipseRotation( rotation );
2982 vars.shape->SetEllipseMajorRadius(
KiROUND( major ) );
2983 vars.shape->SetEllipseMinorRadius(
KiROUND( minor ) );
2987 vars.shape->SetEllipseStartAngle( startAngle );
2988 vars.shape->SetEllipseEndAngle( endAngle );
2991 changed.push_back( vars.shape );
2997 VECTOR2I start = pointAt( vars.startX );
3000 if( start == vars.shape->GetStart() &&
end == vars.shape->GetEnd() )
3004 aBeforeWrite( vars.shape );
3008 VECTOR2I startDelta = start - vars.shape->GetStart();
3011 vars.shape->SetBezierC1( vars.shape->GetBezierC1() + startDelta );
3012 vars.shape->SetBezierC2( vars.shape->GetBezierC2() + endDelta );
3013 vars.shape->SetStart( start );
3014 vars.shape->SetEnd(
end );
3015 vars.shape->RebuildBezierToSegmentsPointsList();
3016 changed.push_back( vars.shape );
3032 std::vector<VECTOR2I> points;
3033 points.reserve( vars.vertexCount );
3035 for(
int i = 0; i < vars.vertexCount; ++i )
3036 points.push_back( pointAt( vars.startX + 2 * i ) );
3041 for(
int i = 0; i < vars.vertexCount; ++i )
3043 if( points[i] != outline.
CPoint( i ) )
3054 aBeforeWrite( vars.shape );
3058 vars.shape->SetPolyPoints( points );
3059 changed.push_back( vars.shape );
3065 VECTOR2I start = pointAt( vars.startX );
3068 if( start == vars.shape->GetStart() &&
end == vars.shape->GetEnd() )
3073 const int collapseFloor = 1000;
3076 int curWidth =
std::abs( vars.shape->GetEnd().x - vars.shape->GetStart().x );
3077 int curHeight =
std::abs( vars.shape->GetEnd().y - vars.shape->GetStart().y );
3079 if( ( newWidth < collapseFloor && curWidth >= collapseFloor )
3080 || ( newHeight < collapseFloor && curHeight >= collapseFloor ) )
3086 aBeforeWrite( vars.shape );
3090 int cornerRadius = vars.shape->GetCornerRadius();
3092 vars.shape->SetStart( start );
3093 vars.shape->SetEnd(
end );
3095 if( cornerRadius > 0 )
3096 vars.shape->SetCornerRadius( cornerRadius );
3098 changed.push_back( vars.shape );
3102 VECTOR2I start = pointAt( vars.startX );
3105 if( start == vars.shape->GetStart() &&
end == vars.shape->GetEnd() )
3110 const double collapseFloor = 1000.0;
3111 double newLen = (
end - start ).EuclideanNorm();
3112 double curLen = ( vars.shape->GetEnd() - vars.shape->GetStart() ).EuclideanNorm();
3114 if( newLen < collapseFloor && curLen >= collapseFloor )
3118 aBeforeWrite( vars.shape );
3120 vars.shape->SetStart( start );
3121 vars.shape->SetEnd(
end );
3122 changed.push_back( vars.shape );
3139 GCS::VEC_I conflictingTags;
3140 GCS::VEC_I redundantTags;
3141 m_gcs->getConflicting( conflictingTags );
3142 m_gcs->getRedundant( redundantTags );
3144 auto tagsToKiids = [&](
const GCS::VEC_I& aTags, std::vector<KIID>& aOut )
3146 for(
int t : aTags )
3151 aOut.push_back( it->second );
3156 tagsToKiids( redundantTags, diag.
redundant );
3158 auto flagConflict = [&](
const KIID& aKiid )
3165 const double residualTol = 1e-3;
3174 double err =
m_gcs->calculateConstraintErrorByTag( tag );
3177 if( !std::isfinite( err ) ||
std::abs( err ) <= residualTol )
3180 flagConflict( kiid );
3185 const double normFloor = 1e-3;
3186 std::set<KIID> collapsedShapes;
3193 double solvedLen = std::hypot(
m_params[vars.endX] -
m_params[vars.startX],
3195 double origLen = ( vars.shape->GetEnd() - vars.shape->GetStart() ).EuclideanNorm() *
m_invScale;
3197 if( origLen > normFloor && solvedLen < normFloor )
3198 collapsedShapes.insert( k );
3201 if( !collapsedShapes.empty() )
3203 bool attributed =
false;
3216 bool incident = std::any_of( members->second.begin(), members->second.end(),
3217 [&](
const KIID& aMember )
3219 return collapsedShapes.contains( aMember );
3224 flagConflict( kiid );
3236 flagConflict( kiid );
3255 const std::unordered_set<KIID>& aClusterShapes,
3256 const std::vector<PCB_CONSTRAINT*>& aConstraints )
3265 if( ( shapes.empty() && dimensions.empty() && pads.empty() ) || aConstraints.empty() )
3268 auto adapter = std::make_unique<BOARD_CONSTRAINT_ADAPTER>();
3270 if( !adapter->Build( shapes, aConstraints,
nullptr, dimensions, pads ) )
3303 const std::vector<PCB_SHAPE*>& aEditedShapes,
3310 if( !aBoard || aEditedShapes.empty() )
3314 std::set<KIID> visited;
3315 std::unordered_set<KIID> sessionShapes;
3316 std::vector<PCB_CONSTRAINT*> sessionConstraints;
3322 if( !seed || visited.contains( seed->m_Uuid )
3323 || !shapeToConstraints.contains( seed->m_Uuid ) )
3328 std::unordered_set<KIID> clusterShapes;
3329 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3331 clusterConstraints, &visited );
3333 for(
PCB_SHAPE* edited : aEditedShapes )
3335 if( edited && clusterShapes.contains( edited->m_Uuid ) )
3339 sessionShapes.insert( clusterShapes.begin(), clusterShapes.end() );
3340 sessionConstraints.insert( sessionConstraints.end(), clusterConstraints.begin(),
3341 clusterConstraints.end() );
3347 return buildCluster( aBoard, sessionShapes, sessionConstraints );
3385 allAccepted = allAccepted && referenceResult.
Accepted( candidate.id );
3388 return referenceResult;
3415 result.position = projected;
3426 const VECTOR2I& aTarget, std::vector<PCB_SHAPE*>* aModified,
3427 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify )
3440 std::vector<PCB_SHAPE*> changed =
m_adapter->Apply( aBeforeModify );
3441 m_adapter->ApplyReferenceValues( aBeforeModify );
3444 aModified->insert( aModified->end(), changed.begin(), changed.end() );
3454 if( !aBoard || aBlockItems.empty() )
3458 std::set<KIID> visited;
3459 std::unordered_set<KIID> sessionShapes;
3460 std::vector<PCB_CONSTRAINT*> sessionConstraints;
3466 if( !seed || visited.contains( seed->m_Uuid ) || !shapeToConstraints.contains( seed->m_Uuid ) )
3469 std::unordered_set<KIID> clusterShapes;
3470 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3473 sessionShapes.insert( clusterShapes.begin(), clusterShapes.end() );
3474 sessionConstraints.insert( sessionConstraints.end(), clusterConstraints.begin(), clusterConstraints.end() );
3477 if( sessionShapes.empty() )
3480 if( !
buildCluster( aBoard, sessionShapes, sessionConstraints ) )
3495 const std::set<KIID>& aTranslatedShapes,
const VECTOR2I& aTranslation,
3496 std::vector<PCB_SHAPE*>* aModified,
3497 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify )
3514 std::vector<PCB_SHAPE*> changed =
m_adapter->Apply( aBeforeModify );
3515 m_adapter->ApplyReferenceValues( aBeforeModify );
3518 aModified->insert( aModified->end(), changed.begin(), changed.end() );
3535 std::unordered_set<KIID> clusterShapes;
3536 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3560 std::optional<VECTOR2I> resolved = solved ?
m_adapter->AnchorPosition(
m_dragged ) : std::nullopt;
3561 bool quantizedValid = resolved && *resolved == aTarget &&
m_adapter->QuantizedRelationsSatisfied();
3563 return quantizedValid;
3597 result.position = *resolved;
3599 const auto candidateResidual =
3604 switch( aCandidate.relation )
3609 return ( point - aCandidate.origin ).EuclideanNorm();
3613 return std::abs( point.
x - aCandidate.origin.x );
3617 return std::abs( point.
y - aCandidate.origin.y );
3621 if( aCandidate.direction.x != 0.0 )
3622 return std::abs( point.
x - aCandidate.origin.x );
3624 if( aCandidate.direction.y != 0.0 )
3625 return std::abs( point.
y - aCandidate.origin.y );
3627 return std::nullopt;
3634 double divisor = aCandidate.direction.SquaredEuclideanNorm();
3636 if( divisor <= 1e-12 )
3637 return std::nullopt;
3639 VECTOR2D offset = point - aCandidate.origin;
3640 double parameter = offset.
Dot( aCandidate.direction ) / divisor;
3643 return std::nullopt;
3646 && ( parameter < 0.0 || parameter > 1.0 ) )
3648 return std::nullopt;
3651 return std::abs( offset.
x * aCandidate.direction.y
3652 - offset.
y * aCandidate.direction.x )
3653 / std::sqrt( divisor );
3659 if( !aCandidate.manifold )
3660 return std::nullopt;
3662 if(
const CIRCLE*
circle = std::get_if<CIRCLE>( &*aCandidate.manifold ) )
3668 if(
const SHAPE_ARC* arc = std::get_if<SHAPE_ARC>( &*aCandidate.manifold ) )
3670 if( !arc->Collide(
result.position, 2 ) )
3671 return std::nullopt;
3674 - arc->GetRadius() );
3677 return std::nullopt;
3681 return std::nullopt;
3686 std::optional<double> residual = candidateResidual( candidate );
3697 if( !residual || ( discrete ? *residual != 0.0 : *residual > 2.0 ) )
3707 if( !
m_adapter->QuantizedRelationsSatisfied() )
3716 const VECTOR2I& aCursor, std::vector<PCB_SHAPE*>* aModified,
3717 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify,
bool aIncludeDragged,
3718 bool aStabilize,
const std::set<KIID>& aEdited,
3719 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged )
3726 const auto notifyModify = [&](
BOARD_ITEM* aItem )
3728 if( ( aIncludeDragged || aItem !=
m_draggedShape ) && aBeforeModify )
3729 aBeforeModify( aItem );
3745 std::vector<PCB_SHAPE*> changed =
m_adapter->Apply( notifyModify );
3747 m_adapter->ApplyReferenceValues( aBeforeModify );
3754 std::ranges::copy_if( changed, std::back_inserter( *aModified ),
3766 std::vector<PCB_SHAPE*>* aModified,
3767 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify,
bool aIncludeDragged,
3768 bool aStabilize,
const std::set<KIID>& aEdited,
3769 const std::optional<std::pair<CONSTRAINT_MEMBER, VECTOR2I>>& aCoDragged,
3770 const std::set<KIID>& aFixedShapes,
bool aHoldDraggedRigid )
3781 std::unordered_set<KIID> clusterShapes;
3782 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3789 if( ( shapes.empty() && dimensions.empty() && pads.empty() ) || clusterConstraints.empty() )
3794 if( !adapter.
Build( shapes, clusterConstraints, &aFixedShapes, dimensions, pads ) )
3797 bool solved = adapter.
Solve( aDragged, aCursor, aStabilize, aEdited, aCoDragged, aHoldDraggedRigid );
3806 std::vector<PCB_SHAPE*> changed = adapter.
Apply(
3809 if( ( aIncludeDragged || aItem != draggedShape ) && aBeforeModify )
3810 aBeforeModify( aItem );
3820 std::ranges::copy_if( changed, std::back_inserter( *aModified ),
3822 {
return aIncludeDragged || aShape != draggedShape; } );
3831 if( !aBoard || !aConstraint )
3839 const std::vector<CONSTRAINT_MEMBER>& members = aConstraint->
GetMembers();
3841 if( members.size() != 2 || members.front().m_item == members.back().m_item )
3858 && aOther->GetMembers().front() == members.front();
3864 return { members.back().m_item };
3869 std::vector<PCB_SHAPE*>* aModified,
3870 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify,
3871 const std::set<KIID>& aFixedShapes )
3873 if( !aBoard || !aConstraint || aConstraint->
GetMembers().empty() )
3890 if( anchors.empty() )
3893 pin.m_anchor = anchors.front().anchor;
3894 pin.m_index = anchors.front().index;
3904 return SolveCluster( aBoard,
pin, *pos, aModified, aBeforeModify,
true,
3905 true, {}, std::nullopt, aFixedShapes,
3906 !aFixedShapes.empty() );
3911 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify )
3919 std::set<KIID> visited;
3923 if( !shape || visited.contains( shape->m_Uuid ) || !shapeToConstraints.contains( shape->m_Uuid ) )
3926 std::unordered_set<KIID> clusterShapes;
3927 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3932 if( anchors.empty() )
3937 std::set<KIID> edited;
3941 if( other && clusterShapes.contains( other->m_Uuid ) )
3942 edited.insert( other->m_Uuid );
3945 SolveCluster( aBoard, { shape->m_Uuid, anchors.front().anchor, anchors.front().index }, anchors.front().pos,
3946 aModified, aBeforeModify,
3947 true,
false, edited );
3953 std::vector<PCB_SHAPE*>* aModified,
3954 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify )
3960 std::set<KIID> visited;
3961 std::vector<std::unique_ptr<BOARD_CONSTRAINT_ADAPTER>> solvedClusters;
3965 if( !seed || visited.contains( seed->m_Uuid ) || !shapeToConstraints.contains( seed->m_Uuid ) )
3968 std::unordered_set<KIID> clusterShapes;
3969 std::vector<PCB_CONSTRAINT*> clusterConstraints;
3976 if( shapes.empty() || clusterConstraints.empty() )
3981 std::set<KIID> fixed;
3983 for(
PCB_SHAPE* edited : aEditedShapes )
3985 if( edited && clusterShapes.contains( edited->m_Uuid ) )
3986 fixed.insert( edited->m_Uuid );
3989 auto adapter = std::make_unique<BOARD_CONSTRAINT_ADAPTER>();
3991 if( !adapter->Build( shapes, clusterConstraints, &fixed, dimensions, pads )
3992 || !adapter->Solve(
true ) || !adapter->CurrentRelationsSatisfied() )
3997 solvedClusters.push_back( std::move( adapter ) );
4000 for(
const std::unique_ptr<BOARD_CONSTRAINT_ADAPTER>& adapter : solvedClusters )
4002 std::vector<PCB_SHAPE*> changed = adapter->Apply( aBeforeModify );
4006 adapter->ApplyReferenceValues( aBeforeModify );
4009 aModified->insert( aModified->end(), changed.begin(), changed.end() );
4017 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify )
4019 if( !aBoard || !aShape )
4024 if( !shapeToConstraints.contains( aShape->
m_Uuid ) )
4027 std::unordered_set<KIID> clusterShapes;
4028 std::vector<PCB_CONSTRAINT*> clusterConstraints;
4035 if( shapes.empty() || clusterConstraints.empty() )
4040 if( !adapter.
Build( shapes, clusterConstraints,
nullptr, dimensions, pads )
4046 std::vector<PCB_SHAPE*> changed = adapter.
Apply(
4050 aBeforeModify( aChanged );
4056 aModified->insert( aModified->end(), changed.begin(), changed.end() );
4063 const std::unordered_set<KIID>& aClusterShapes,
4064 const std::vector<PCB_CONSTRAINT*>& aClusterConstraints,
4065 const std::unordered_set<KIID>& aOnBoard )
4075 if( ( shapes.empty() && dimensions.empty() && pads.empty() ) || aClusterConstraints.empty()
4076 || !adapter.
Build( shapes, aClusterConstraints,
nullptr, dimensions, pads ) )
4087 adapter.
Solve(
true );
4099 result.shapeIds.push_back( shape->m_Uuid );
4104 result.dimensionIds.push_back( dimension->m_Uuid );
4162 if( boardConstraints.empty() )
4170 std::set<KIID> visitedShapes;
4172 for(
const auto& [seedShape, seedConstraints] : shapeToConstraints.
byMember )
4174 if( visitedShapes.contains( seedShape ) )
4177 std::unordered_set<KIID> clusterShapes;
4178 std::vector<PCB_CONSTRAINT*> clusterConstraints;
4195 aSeed ^= aValue + 0x9e3779b97f4a7c15ULL + ( aSeed << 6 ) + ( aSeed >> 2 );
4199static void hashInt( std::size_t& aSeed,
long long aValue )
4201 hashCombine( aSeed,
static_cast<std::size_t
>( aValue ) );
4209 std::uint64_t bits = 0;
4210 static_assert(
sizeof( bits ) ==
sizeof( aValue ) );
4211 std::memcpy( &bits, &aValue,
sizeof( bits ) );
4212 hashCombine( aSeed,
static_cast<std::size_t
>( bits & 0xFFFFFFFFULL ) );
4213 hashCombine( aSeed,
static_cast<std::size_t
>( bits >> 32 ) );
4276 for(
int i = 0; i < outline.
PointCount(); ++i )
4318 hashInt( aSeed,
static_cast<int>( aDimension->
Type() ) );
4326 hashInt( aSeed,
static_cast<int>(
4345 hashInt( aSeed,
static_cast<int>( member.m_anchor ) );
4346 hashInt( aSeed, member.m_index );
4354 const std::vector<PCB_CONSTRAINT*>& aClusterConstraints,
4355 const std::unordered_set<KIID>& aOnBoard )
4357 std::size_t seed = 0;
4359 std::vector<KIID> ids( aClusterShapes.begin(), aClusterShapes.end() );
4360 std::sort( ids.begin(), ids.end() );
4362 for(
const KIID&
id : ids )
4370 else if(
PAD*
pad =
dynamic_cast<PAD*
>( item ) )
4377 std::vector<PCB_CONSTRAINT*> constraints = aClusterConstraints;
4378 std::sort( constraints.begin(), constraints.end(),
4380 { return aLhs->m_Uuid < aRhs->m_Uuid; } );
4407 if( boardConstraints.empty() )
4420 std::set<KIID> visitedShapes;
4421 std::set<std::vector<KIID>> seenKeys;
4423 for(
const auto& [seedShape, seedConstraints] : shapeToConstraints.
byMember )
4425 if( visitedShapes.contains( seedShape ) )
4428 std::unordered_set<KIID> clusterShapes;
4429 std::vector<PCB_CONSTRAINT*> clusterConstraints;
4435 std::vector<KIID> key;
4438 key.push_back( constraint->m_Uuid );
4440 std::sort( key.begin(), key.end() );
4442 std::size_t hash =
hashCluster( aBoard, clusterShapes, clusterConstraints, onBoard );
4443 auto it =
m_cache.find( key );
4445 if( it ==
m_cache.end() || it->second.hash != hash )
4450 it =
m_cache.insert_or_assign( key,
CACHE_ENTRY{ hash, std::move( cluster ) } ).first;
4454 seenKeys.insert( key );
4459 std::erase_if(
m_cache, [&seenKeys](
const auto& entry ) {
return !seenKeys.contains( entry.first ); } );
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 ...
static void hashCombine(std::size_t &aSeed, std::size_t aValue)
static void hashConstraint(std::size_t &aSeed, const PCB_CONSTRAINT *aConstraint)
static constexpr double STAY_PUT_WEIGHT
static void hashKiid(std::size_t &aSeed, const KIID &aId)
static void hashShape(std::size_t &aSeed, const PCB_SHAPE *aShape)
std::vector< VECTOR2I > ConstraintPinnedPositions(BOARD *aBoard, const std::set< KIID > &aItems)
The distinct board positions that fixed positions pin on aItems.
void ReSolveAfterShapeResize(BOARD *aBoard, PCB_SHAPE *aShape, std::vector< PCB_SHAPE * > *aModified, 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.
static std::size_t hashCluster(BOARD *aBoard, const std::unordered_set< KIID > &aClusterShapes, const std::vector< PCB_CONSTRAINT * > &aClusterConstraints, const std::unordered_set< KIID > &aOnBoard)
bool BoardHasConstraints(BOARD *aBoard)
True if aBoard resolves at least one geometric constraint (see CollectResolvedConstraints()).
static void assembleClusterInto(BOARD_CONSTRAINT_DIAGNOSTICS &aResult, const CLUSTER_DIAGNOSIS &aCluster)
static constexpr double IU_PER_NORM_UNIT
CONSTRAINT_DIAGNOSIS ApplyConstraintImmediately(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint, std::vector< PCB_SHAPE * > *aModified, 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),...
static std::vector< PAD * > resolveClusterPads(BOARD *aBoard, const std::unordered_set< KIID > &aIds, const std::unordered_set< KIID > *aOnBoard=nullptr)
static void hashPoint(std::size_t &aSeed, const VECTOR2I &aPoint)
CONSTRAINT_DIAGNOSIS SolveCluster(BOARD *aBoard, const CONSTRAINT_MEMBER &aDragged, 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, const std::set< KIID > &aFixedShapes, bool aHoldDraggedRigid)
Gather the cluster of shapes transitively constrained with the dragged shape, solve with the dragged ...
static std::vector< PCB_SHAPE * > resolveClusterShapes(BOARD *aBoard, const std::unordered_set< KIID > &aIds, const std::unordered_set< KIID > *aOnBoard=nullptr)
static void hashDimension(std::size_t &aSeed, const PCB_DIMENSION_BASE *aDimension)
static double arcSweepTarget(double aStartAngle, double aEndAngle, double aSweepDeg)
static CLUSTER_DIAGNOSIS diagnoseSingleCluster(BOARD *aBoard, const std::unordered_set< KIID > &aClusterShapes, const std::vector< PCB_CONSTRAINT * > &aClusterConstraints, const std::unordered_set< KIID > &aOnBoard)
static double directedAngleForCorner(const GCS::Line &aL1, const GCS::Line &aL2, double aCornerDeg)
static constexpr double CURSOR_WEIGHT
void ReSolveShapeClusters(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aShapes, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Re-solve the clusters of shapes edited outside the solver, e.g.
static void hashInt(std::size_t &aSeed, long long aValue)
bool ReSolveShapeClustersHoldingEdited(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aEditedShapes, std::vector< PCB_SHAPE * > *aModified, 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...
static CONSTRAINT_GRAPH buildShapeConstraintMap(BOARD *aBoard, const std::vector< PCB_CONSTRAINT * > &aConstraints, std::vector< KIID > *aErrored=nullptr, const std::unordered_set< KIID > *aOnBoard=nullptr)
static void dedupErrored(BOARD_CONSTRAINT_DIAGNOSTICS &aResult)
static void collectConstraintCluster(const CONSTRAINT_GRAPH &aGraph, const KIID &aSeed, std::unordered_set< KIID > &aClusterShapes, std::vector< PCB_CONSTRAINT * > &aClusterConstraints, std::set< KIID > *aVisited=nullptr)
static std::vector< PCB_DIMENSION_BASE * > resolveClusterDimensions(BOARD *aBoard, const std::unordered_set< KIID > &aIds, const std::unordered_set< KIID > *aOnBoard=nullptr)
BOARD_CONSTRAINT_DIAGNOSTICS DiagnoseBoardConstraints(BOARD *aBoard)
Diagnose every constraint cluster on the board (validate only – geometry is not changed) and return t...
static FOOTPRINT * boardFootprintOf(const BOARD_ITEM *aItem)
static constexpr int MAX_SOLVE_ITERATIONS
static BOARD_ITEM * resolveMember(BOARD *aBoard, const std::unordered_set< KIID > *aOnBoard, const KIID &aId)
static std::vector< T * > resolveClusterItems(BOARD *aBoard, const std::unordered_set< KIID > &aIds, const std::unordered_set< KIID > *aOnBoard)
static bool isDegenerateLine(const GCS::Line &aLine)
static void hashDouble(std::size_t &aSeed, double aValue)
@ 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).
bool ConstraintItemIsLocked(const BOARD_ITEM *aItem)
True when the solver must treat aItem as immovable, either locked itself or living inside a locked fo...
CONSTRAINT_BLOCK_RESULT
How a block edit solve turned out.
@ REFUSED
No arrangement fits the pinned points, and the geometry is untouched.
@ SOLVED
The constraints hold and every pinned point is exactly where it was put.
@ NOT_MODELED
Nothing the caller pinned belongs to this cluster.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Translates KiCad board geometry to and from the planegcs solver (issue #2329).
SNAPSHOT Snapshot() const
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...
double normalizeY(int aIU) const
std::set< int > m_droppedTags
Stale relations taken out of the system.
CONSTRAINT_SYSTEM_2D m_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.
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...
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...
double m_invScale
1 / m_scale.
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
std::deque< double > & m_params
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
std::vector< int > m_temporaryParams
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...
bool parametersFinite() const
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)
bool hardRelationsSatisfied() const
std::set< int > m_groundedPositionParams
The subset of those grounded by a FIXED_POSITION constraint rather than by a lock or a driving consta...
size_t m_nextTemporaryParam
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.
void beginTemporaryParameters()
int temporaryParam(double aValue)
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.
~BOARD_CONSTRAINT_ADAPTER()
@ 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 QuantizedRelationsSatisfied()
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).
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.
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
PCB_SHAPE * m_draggedShape
CONSTRAINT_MEMBER m_dragged
std::set< KIID > m_edited
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)
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
bool HasBaseConflict() const
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...
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
const FOOTPRINTS & Footprints() const
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Represent basic circle geometry with utility geometry functions.
KICAD_T Type() const
Returns the type of object.
EDA_ANGLE GetArcAngle() const
int GetEllipseMinorRadius() const
const VECTOR2I & GetBezierC2() const
const VECTOR2I & GetEllipseCenter() const
EDA_ANGLE GetEllipseEndAngle() const
int GetEllipseMajorRadius() const
SHAPE_POLY_SET & GetPolyShape()
EDA_ANGLE GetEllipseRotation() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
EDA_ANGLE GetEllipseStartAngle() const
const VECTOR2I & GetBezierC1() const
virtual void SetTextPos(const VECTOR2I &aPoint)
A geometric constraint between board items (issue #2329).
const std::vector< CONSTRAINT_MEMBER > & GetMembers() const
std::optional< double > GetValue() const
bool IsDriving() const
A driving constraint forces its value; a reference (non-driving) one only measures it.
PCB_CONSTRAINT_TYPE GetConstraintType() const
virtual VECTOR2I GetEnd() const
virtual VECTOR2I GetStart() const
The dimension's origin is the first feature point for the dimension.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
A radial dimension indicates either the radius or diameter of an arc or circle.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
VECTOR2I GetTextPos() const override
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
SNAP_RESULT Resolve(const SNAP_SOURCE_CONTEXT &aContext) const
void AddCandidate(SNAP_CANDIDATE aCandidate)
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
bool IsConstrainableItem(const BOARD_ITEM *aItem)
True when aItem is one ResolveConstrainableItem() accepts: a PCB_SHAPE, a dimension or a pad.
EDA_ANGLE MeasureCornerAngle(const SEG &aA, const SEG &aB)
The corner angle between two segments, in the closed range [0, 180] degrees.
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintShapeAnchors(const PCB_SHAPE *aShape)
Enumerate a shape constraint anchors with positions segment and arc endpoints arc centre circle centr...
std::unordered_set< KIID > CollectMemberCandidateIds(const BOARD *aBoard)
The ids of every item on aBoard a constraint member can resolve to (shapes, dimensions,...
bool ConstraintPolygonIsModelable(const PCB_SHAPE *aShape)
True when polygon has one non empty hole free arc free outline making it solver eligible Shared by ad...
std::optional< VECTOR2I > ConstraintAnchorPosition(const BOARD *aBoard, const CONSTRAINT_MEMBER &aMember)
Current location of a constraint member's anchor (its shape's START/END/CENTER, or a dimension's feat...
std::vector< PCB_CONSTRAINT * > CollectResolvedConstraints(const BOARD *aBoard)
The constraints the editor resolves on aBoard.
static constexpr EDA_ANGLE ANGLE_90
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
CONSTRAINT_ANCHOR
Which feature of a referenced board item participates in a constraint.
@ VERTEX
An indexed rectangle corner or polygon outline vertex; pairs with CONSTRAINT_MEMBER::m_index.
@ WHOLE
The item as a whole (a segment as a line, a circle).
@ START
First endpoint of a segment or arc.
@ END
Second endpoint of a segment or arc.
@ CENTER
Center of an arc or circle.
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
@ CONCENTRIC
Two arcs/circles share a center.
@ SYMMETRIC
Two points are mirror images about an axis.
@ FIXED_POSITION
A point is locked at its current location.
@ VERTICAL
A segment (or two points) is vertical.
@ TANGENT
A line and a curve, or two curves, touch tangentially.
@ COINCIDENT
Two points are made to coincide.
@ PERPENDICULAR
Two segments are perpendicular.
@ FIXED_RADIUS
An arc/circle has a driving radius value.
@ HORIZONTAL
A segment (or two points) is horizontal.
@ EQUAL_RADIUS
Two arcs/circles have equal radius.
@ MIDPOINT
A point is the midpoint of a segment.
@ POINT_ON_LINE
A point lies on a segment's supporting line.
@ FIXED_LENGTH
A segment has a driving length value.
@ ANGULAR_DIMENSION
An angle between members (driving or reference).
@ COLLINEAR
Two segments lie on the same line.
@ ARC_ANGLE
An arc has a driving or reference swept-angle value.
@ PARALLEL
Two segments are parallel.
@ EQUAL_LENGTH
Two segments have equal length.
Param indices of an anchor coordinates a rect corner aliases mixed start end params so y is not alway...
std::vector< RIGID_RADIUS_HOLD > radii
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).
PAD * pad
set instead of shape for a PAD_CENTER
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 > 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.
bool IsOverConstrained() 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).
std::unordered_map< KIID, std::vector< KIID > > rigidSiblings
std::unordered_map< KIID, std::vector< PCB_CONSTRAINT * > > byMember
bool contains(const KIID &aId) const
One participant in a constraint: a referenced board item plus the feature of that item that participa...
KIID m_item
Referenced board item, usually a PCB_SHAPE.
CONSTRAINT_ANCHOR m_anchor
Which feature of that item participates.
int m_index
Vertex ordinal; only meaningful for the VERTEX anchor.
std::vector< double > quantizedResiduals
bool Accepted(const SNAP_STABLE_ID &aId) const
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxString result
Test unit parsing edge cases and error handling.
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
constexpr int sign(T val)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D