26#include <unordered_set>
87bool allSegments(
const std::vector<BOARD_ITEM*>& aItems )
89 return std::ranges::all_of( aItems, isSegment );
94bool allRadial(
const std::vector<BOARD_ITEM*>& aItems )
96 return std::ranges::all_of( aItems, isCircleOrArc );
101bool allCentered(
const std::vector<BOARD_ITEM*>& aItems )
103 return std::ranges::all_of( aItems,
106 return isCircleOrArc( aItem ) || isEllipseKind( aItem );
119 SEG::ecoord best = ( aEnds[0] - bEnds[0] ).SquaredEuclideanNorm();
121 for(
int i = 0; i < 2; ++i )
123 for(
int j = 0; j < 2; ++j )
125 SEG::ecoord dist = ( aEnds[i] - bEnds[j] ).SquaredEuclideanNorm();
139 return SEG( aEnds[
vA], aEnds[1 -
vA] ).
Angle(
SEG( bEnds[vB], bEnds[1 - vB] ) );
145 const std::vector<BOARD_ITEM*>& aItems )
148 auto makeWhole = [&]()
150 std::unique_ptr<PCB_CONSTRAINT> c = std::make_unique<PCB_CONSTRAINT>( aParent, aType );
165 if( aItems.size() != 2 || !allSegments( aItems ) )
174 if( aItems.size() != 1 || !isSegment( aItems[0] ) )
182 if( aItems.size() != 1 || !isSegment( aItems[0] ) )
187 std::unique_ptr<PCB_CONSTRAINT> c = makeWhole();
188 c->SetValue( ( seg->
GetEnd() - seg->
GetStart() ).EuclideanNorm() );
194 if( aItems.size() != 2 || !allCentered( aItems ) )
202 if( aItems.size() != 2 || !allRadial( aItems ) )
210 if( aItems.size() != 2 || !allSegments( aItems ) )
221 std::unique_ptr<PCB_CONSTRAINT> c = makeWhole();
229 if( aItems.size() != 1 || !isCircleOrArc( aItems[0] ) )
232 std::unique_ptr<PCB_CONSTRAINT> c = makeWhole();
233 c->SetValue(
static_cast<const PCB_SHAPE*
>( aItems[0] )->GetRadius() );
239 if( aItems.size() != 1 || !isArc( aItems[0] ) )
242 std::unique_ptr<PCB_CONSTRAINT> c = makeWhole();
243 c->SetValue(
static_cast<const PCB_SHAPE*
>( aItems[0] )->GetArcAngle().AsDegrees() );
249 if( aItems.size() != 2 )
257 return isCircleOrArc( aItem ) || isEllipseKind( aItem );
260 bool lineCurve = ( isSegment( a ) && isCurve( b ) ) || ( isSegment( b ) && isCurve( a ) );
261 bool curveCurve = isCircleOrArc( a ) && isCircleOrArc( b );
263 if( !lineCurve && !curveCurve )
289 format =
_(
"%s needs two line segments. Click them to constrain." );
294 format =
_(
"%s needs two line segments of nonzero length. Click them to constrain." );
299 format =
_(
"%s needs one line segment, or two anchor points. Click them to constrain." );
303 format =
_(
"%s needs one line segment. Click it to constrain." );
308 format =
_(
"%s needs two arcs, circles or ellipses. Click them to constrain." );
312 format =
_(
"%s needs two arcs or circles. Click them to constrain." );
316 format =
_(
"%s needs one arc or circle. Click it to constrain." );
320 format =
_(
"%s needs one arc. Click it to constrain." );
325 format =
_(
"%s needs a line and a curve, or two arcs or circles. Click them to constrain." );
335 return wxEmptyString;
344 std::vector<CONSTRAINT_ANCHOR_POINT> anchors;
371 VECTOR2I tl( std::min( s.
x, e.
x ), std::min( s.
y, e.
y ) );
372 VECTOR2I br( std::max( s.
x, e.
x ), std::max( s.
y, e.
y ) );
388 for(
int i = 0; i < outline.
PointCount(); ++i )
389 anchors.push_back( { CONSTRAINT_ANCHOR::VERTEX, outline.CPoint( i ), i } );
418 if( !aShape || aIndex < 0 )
426 if( aIndex >= (
int) anchors.size() )
429 return anchors[aIndex];
434 const VECTOR2I& aPos,
double aMaxDist )
436 double best = aMaxDist;
437 std::optional<CONSTRAINT_MEMBER>
result;
443 double dist = ( a.pos - aPos ).EuclideanNorm();
459 std::vector<PCB_SHAPE*> shapes;
465 [&](
const auto& aContainer )
470 shape && aBoard->
IsLayerVisible( shape->GetLayer() ) && layerMatches( shape, aLayer ) )
472 shapes.push_back( shape );
480 collect( footprint->GraphicalItems() );
488 std::vector<BOARD_ITEM*> items;
494 [&](
const auto& aContainer )
499 && aBoard->
IsLayerVisible( item->GetLayer() ) && layerMatches( item, aLayer ) )
501 items.push_back( item );
510 collect( footprint->GraphicalItems() );
513 for(
PAD*
pad : footprint->Pads() )
515 bool visible = std::ranges::any_of(
pad->GetLayerSet().Seq(),
518 return aBoard->IsLayerVisible( aPadLayer );
521 if( visible && layerMatches(
pad, aLayer ) )
522 items.push_back(
pad );
531 const std::vector<CONSTRAINT_MEMBER>& aExclude,
534 double best = aMaxDist;
535 std::optional<CONSTRAINT_MEMBER>
result;
547 double dist = ( a.pos - aPos ).EuclideanNorm();
562 const std::optional<VECTOR2I>& aEnd,
double aMaxDist,
565 std::vector<ENDPOINT_BINDING> bindings;
572 using ANCHOR_PAIR = std::pair<CONSTRAINT_MEMBER, CONSTRAINT_MEMBER>;
574 auto bestPairOn = [&](
BOARD_ITEM* aCandidate ) -> std::optional<std::pair<ANCHOR_PAIR, double>>
580 const size_t none = anchors.size();
581 size_t bestEnd = none;
582 size_t secondEnd = none;
583 std::vector<double> dEnd( anchors.size(), 0.0 );
585 for(
size_t j = 0; j < anchors.size(); ++j )
587 dEnd[j] = ( anchors[j].pos - *aEnd ).EuclideanNorm();
589 if( dEnd[j] > aMaxDist )
592 if( bestEnd == none || dEnd[j] < dEnd[bestEnd] )
597 else if( secondEnd == none || dEnd[j] < dEnd[secondEnd] )
603 if( bestEnd == none )
606 std::optional<std::pair<ANCHOR_PAIR, double>> best;
608 for(
size_t i = 0; i < anchors.size(); ++i )
610 double dStart = ( anchors[i].pos - aStart ).EuclideanNorm();
612 if( dStart > aMaxDist )
615 size_t j = ( i == bestEnd ) ? secondEnd : bestEnd;
620 double sum = dStart + dEnd[j];
622 if( !best || sum < best->second )
624 best = std::make_pair(
625 ANCHOR_PAIR{
CONSTRAINT_MEMBER( aCandidate->m_Uuid, anchors[i].anchor, anchors[i].index ),
638 std::optional<ANCHOR_PAIR> bestPair;
639 double bestSum = 0.0;
643 if( item->m_Uuid == aItem )
646 auto pair = bestPairOn( item );
651 if( !bestPair || pair->second < bestSum )
653 bestSum = pair->second;
654 bestPair = pair->first;
673 exclude.push_back( *startTarget );
708 double best = aMaxDist;
709 std::optional<KIID>
result;
713 const SHAPE_T shapeType = shape->GetShape();
718 dist =
SEG( shape->GetStart(), shape->GetEnd() ).
Distance( aPos );
722 dist =
std::abs( ( aPos - shape->GetCenter() ).EuclideanNorm() - shape->GetRadius() );
728 double a = shape->GetEllipseMajorRadius();
729 double b = shape->GetEllipseMinorRadius();
730 double phi = shape->GetEllipseRotation().AsRadians();
732 double lx = d.
x * std::cos( phi ) + d.
y * std::sin( phi );
733 double ly = -d.
x * std::sin( phi ) + d.
y * std::cos( phi );
734 double r = std::hypot( lx, ly );
736 if( a <= 0 || b <= 0 )
739 double theta = std::atan2( ly, lx );
740 double re = a * b / std::hypot( b * std::cos( theta ), a * std::sin( theta ) );
770 std::vector<CONSTRAINT_ANCHOR_POINT> anchors;
775 switch( aItem->
Type() )
814 const std::map<PCB_CONSTRAINT_TYPE, double>& aRemembered )
816 auto it = aRemembered.find( aType );
818 return it != aRemembered.end() ? it->second : aMeasured;
823 const VECTOR2I& aPos,
int aMaxDist )
828 for(
const KIID&
id : aCandidates )
832 if( shape && shape->
HitTest( aPos, aMaxDist ) )
842 std::unordered_set<KIID> ids;
848 [&](
const auto& aContainer )
853 ids.insert( item->m_Uuid );
858 ids.insert( cell->m_Uuid );
867 collect( footprint->GraphicalItems() );
869 for(
PAD*
pad : footprint->Pads() )
870 ids.insert(
pad->m_Uuid );
879 std::vector<KIID> ids;
885 std::unordered_set<KIID> seen;
891 if( onBoard.contains( member.m_item ) && seen.insert( member.m_item ).second )
892 ids.push_back( member.m_item );
902 std::vector<PCB_CONSTRAINT*> constraints;
913 constraints.insert( constraints.end(), footprint->Constraints().begin(), footprint->Constraints().end() );
920 const VECTOR2I& aRim,
double aMaxDist )
925 std::optional<KIID> best;
926 double bestErr = 0.0;
930 if( shape->m_Uuid == aDimension || !isCircleOrArc( shape ) )
935 std::optional<VECTOR2I> centerPos;
946 double centerErr = ( *centerPos - aCenter ).EuclideanNorm();
948 if( centerErr > aMaxDist )
951 double rimErr =
std::abs( ( aRim - *centerPos ).EuclideanNorm() - shape->GetRadius() );
953 if( rimErr > aMaxDist )
961 double err = centerErr + rimErr;
963 if( !best || err < bestErr )
966 best = shape->m_Uuid;
976 if( !aBoard || !aDimension )
984 auto anyConstraint = [&](
const auto& aMatch )
986 return std::ranges::any_of( resolved, aMatch );
993 auto rimOnItem = [&](
const KIID& aItem )
995 return anyConstraint(
1003 const std::vector<CONSTRAINT_MEMBER>& members = aConstraint->
GetMembers();
1005 return members.size() == 2 && members[0] == endMember
1010 return anyConstraint(
1016 const std::vector<CONSTRAINT_MEMBER>& members = aConstraint->
GetMembers();
1018 if( members.size() != 2 )
1024 if( members[0] == startMember )
1025 target = &members[1];
1026 else if( members[1] == startMember )
1027 target = &members[0];
1034 return item && isCircleOrArc( item ) && rimOnItem( target->
m_item );
1042 return anyConstraint(
1048 const std::vector<CONSTRAINT_MEMBER>& members = aConstraint->
GetMembers();
1051 if( members.size() != 2 || members[0].m_item == members[1].m_item )
1054 if( members[0] == aMember )
1057 return members[1] == aMember
1062 return hasCoincident( startMember ) && hasCoincident( endMember );
1071 switch( aDimension->
Type() )
1086 if( !aBoard || !aDimension )
1097 const std::vector<CONSTRAINT_MEMBER>& members = aConstraint->GetMembers();
1099 return members.size() == 2
1100 && ( ( members[0] == startMember && members[1] == endMember )
1101 || ( members[0] == endMember && members[1] == startMember ) );
1105 auto it = std::ranges::find_if( resolved, matches );
1107 return it != resolved.end() ? *it :
nullptr;
1121 return existing && existing->
IsDriving();
1129 if( lengthConstraint && lengthConstraint->
IsDriving() )
1140 std::optional<int> aDrivingLengthIU,
1141 const std::optional<wxString>& aOverrideText,
1142 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify,
1143 const std::function<
void(
BOARD_ITEM* )>& aStageAdd,
1144 const std::function<
void(
BOARD_ITEM* )>& aBeforeRemove )
1155 if( !aDrivingLengthIU || *aDrivingLengthIU <= 0 || !
DimensionCanDrive( aBoard, aDimension ) )
1158 aBeforeModify( aDimension );
1164 aBeforeModify( existing );
1165 existing->
SetValue( *aDrivingLengthIU );
1179 constraint->SetValue( *aDrivingLengthIU );
1180 constraint->SetDriving(
true );
1183 aStageAdd( constraint.release() );
1187 aBeforeModify( aDimension );
1197 aBeforeRemove( existing );
1204 const std::function<
void(
BOARD_ITEM* )>& aBeforeModify,
1205 const std::function<
void(
BOARD_ITEM* )>& aBeforeRemove )
1207 if( !aBoard || aDelta == 0 )
1210 auto remapIn = [&](
const CONSTRAINTS& aConstraints )
1214 bool shifts =
false;
1215 bool doomed =
false;
1222 if( aDelta < 0 && member.m_index == aChangedIndex )
1224 else if( member.m_index >= aChangedIndex )
1233 aBeforeRemove( constraint );
1240 aBeforeModify( constraint );
1245 && member.m_index >= aChangedIndex )
1247 member.m_index += aDelta;
1256 remapIn( footprint->Constraints() );
1274constexpr double AUTO_BIND_TOL_MM = 0.01;
1275constexpr double AUTO_CORRIDOR_MM = 0.25;
1276constexpr double AUTO_TANGENT_TOL_DEG = 10.0;
1280std::optional<double> tangentDirAt(
const PCB_SHAPE* aShape,
const VECTOR2I& aPos )
1288 if( dir.EuclideanNorm() == 0 )
1289 return std::nullopt;
1291 return std::atan2( dir.y, dir.x );
1299 if( radial.EuclideanNorm() == 0 )
1300 return std::nullopt;
1302 return std::atan2( radial.y, radial.x ) +
M_PI / 2;
1305 default:
return std::nullopt;
1315 const double tangentTol = AUTO_TANGENT_TOL_DEG *
M_PI / 180.0;
1320 if( !curveInvolved )
1323 std::optional<double> myDir = tangentDirAt( aShape, aPos );
1324 std::optional<double> otherDir = tangentDirAt( aTarget, aPos );
1326 if( !myDir || !otherDir )
1329 double diff = std::fabs( std::fmod( *myDir - *otherDir,
M_PI ) );
1330 diff = std::min( diff,
M_PI - diff );
1332 if( diff > tangentTol )
1345void addUnlessDuplicate(
const BOARD* aBoard, std::vector<AUTO_CONSTRAINT>& aResult,
1346 std::unique_ptr<PCB_CONSTRAINT> aConstraint,
bool aNeedsSolve )
1351 if( std::ranges::any_of( aResult,
1360 aResult.push_back( { std::move( aConstraint ), aNeedsSolve } );
1366std::vector<AUTO_CONSTRAINT> selectCenterBindings(
const BOARD* aBoard,
const PCB_SHAPE* aShape,
BOARD_ITEM* aParent )
1368 std::vector<AUTO_CONSTRAINT>
result;
1370 const double tol =
pcbIUScale.mmToIU( AUTO_BIND_TOL_MM );
1375 if( std::optional<CONSTRAINT_MEMBER> target =
1378 std::unique_ptr<PCB_CONSTRAINT> constraint;
1390 constraint->AddMember( target->m_item, target->m_anchor, target->m_index );
1393 addUnlessDuplicate( aBoard,
result, std::move( constraint ),
false );
1397 if( *outline != aShape->
m_Uuid )
1403 addUnlessDuplicate( aBoard,
result, std::move( constraint ),
false );
1413 std::vector<AUTO_CONSTRAINT>& aResult, std::set<CONSTRAINT_ANCHOR>& aBound,
1414 std::vector<std::pair<VECTOR2I, KIID>>& aTouches )
1416 const double tol =
pcbIUScale.mmToIU( AUTO_BIND_TOL_MM );
1424 constraint->AddMember( aShape->
m_Uuid, binding.sourceAnchor );
1425 constraint->AddMember( binding.target.m_item, binding.target.m_anchor, binding.target.m_index );
1427 aBound.insert( binding.sourceAnchor );
1430 aTouches.emplace_back( pos, binding.target.m_item );
1432 addUnlessDuplicate( aBoard, aResult, std::move( constraint ),
false );
1440 std::vector<AUTO_CONSTRAINT>& aResult,
const std::set<CONSTRAINT_ANCHOR>& aBound,
1441 std::vector<std::pair<VECTOR2I, KIID>>& aTouches )
1443 const double tol =
pcbIUScale.mmToIU( AUTO_BIND_TOL_MM );
1447 if( aBound.contains(
anchor ) )
1453 if( !target || *target == aShape->
m_Uuid )
1463 if( ( pos - mid ).EuclideanNorm() <= tol )
1467 auto constraint = std::make_unique<PCB_CONSTRAINT>( aParent, type );
1471 aTouches.emplace_back( pos, *target );
1473 addUnlessDuplicate( aBoard, aResult, std::move( constraint ),
false );
1481 std::vector<AUTO_CONSTRAINT>& aResult )
1486 const double tol =
pcbIUScale.mmToIU( AUTO_BIND_TOL_MM );
1487 const double corridor =
pcbIUScale.mmToIU( AUTO_CORRIDOR_MM );
1490 std::vector<VECTOR2I> boundPos;
1499 if( span.Distance(
anchor.pos ) > corridor )
1503 if( (
anchor.pos - aShape->
GetStart() ).EuclideanNorm() <= corridor
1504 || (
anchor.pos - aShape->
GetEnd() ).EuclideanNorm() <= corridor )
1510 if( std::ranges::any_of( boundPos,
1513 return (
anchor.pos - aP ).EuclideanNorm() <= tol;
1519 boundPos.push_back(
anchor.pos );
1522 constraint->AddMember( item->m_Uuid,
anchor.anchor,
anchor.index );
1525 addUnlessDuplicate( aBoard, aResult, std::move( constraint ),
true );
1533 std::vector<AUTO_CONSTRAINT>& aResult,
const std::vector<std::pair<VECTOR2I, KIID>>& aTouches )
1535 for(
const auto& [pos,
id] : aTouches )
1539 if( target && target != aShape )
1541 if( std::unique_ptr<PCB_CONSTRAINT> tangent = makeTangent( aShape, target, pos, aParent ) )
1542 addUnlessDuplicate( aBoard, aResult, std::move( tangent ),
true );
1550 std::vector<AUTO_CONSTRAINT>& aResult )
1558 if( !horizontal && !vertical )
1565 addUnlessDuplicate( aBoard, aResult, std::move( constraint ),
false );
1573 std::vector<AUTO_CONSTRAINT>
result;
1575 if( !aBoard || !aShape )
1579 return selectCenterBindings( aBoard, aShape, aParent );
1581 std::set<CONSTRAINT_ANCHOR> bound;
1582 std::vector<std::pair<VECTOR2I, KIID>> touches;
1584 selectEndpointCoincidents( aBoard, aShape, aParent,
result, bound, touches );
1585 selectOutlineFallbacks( aBoard, aShape, aParent,
result, bound, touches );
1586 selectCorridorPins( aBoard, aShape, aParent,
result );
1587 selectTangents( aBoard, aShape, aParent,
result, touches );
1589 if( aAxisConstraint )
1590 selectAxisConstraint( aBoard, aShape, aParent,
result );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
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.
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
const DRAWINGS & Drawings() const
KICAD_T Type() const
Returns the type of object.
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
A geometric constraint between board items (issue #2329).
const std::vector< CONSTRAINT_MEMBER > & GetMembers() const
bool IsDriving() const
A driving constraint forces its value; a reference (non-driving) one only measures it.
PCB_CONSTRAINT_TYPE GetConstraintType() const
void SetValue(std::optional< double > aValue)
void SetDriving(bool aDriving)
void Update()
Update the dimension's cached text and geometry.
void SetOverrideTextEnabled(bool aOverride)
void SetOverrideText(const wxString &aValue)
bool GetOverrideTextEnabled() const
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
VECTOR2I::extended_type ecoord
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
EDA_ANGLE Angle(const SEG &aOther) const
Determine the smallest angle between two segments.
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.
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
bool IsConstrainableItem(const BOARD_ITEM *aItem)
True when aItem is one ResolveConstrainableItem() accepts: a PCB_SHAPE, a dimension or a pad.
std::vector< ENDPOINT_BINDING > SelectEndpointBindings(const BOARD *aBoard, const KIID &aItem, const VECTOR2I &aStart, const std::optional< VECTOR2I > &aEnd, double aMaxDist, PCB_LAYER_ID aLayer)
Choose the coincident bindings a freshly drawn item endpoints should take so it tracks the geometry i...
std::optional< KIID > NearestConstrainedShape(const BOARD *aBoard, const std::vector< KIID > &aCandidates, const VECTOR2I &aPos, int aMaxDist)
The candidate shape whose outline aPos hits within aMaxDist, or std::nullopt.
void RemapPolygonVertexMembers(BOARD *aBoard, const KIID &aPoly, int aChangedIndex, int aDelta, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::function< void(BOARD_ITEM *)> &aBeforeRemove)
Repoint persisted VERTEX constraint members after an outline edit of polygon aPoly inserts or removes...
std::vector< BOARD_ITEM * > CollectConstrainableItems(const BOARD *aBoard, PCB_LAYER_ID aLayer)
Every constrainable item on a visible layer – shapes, dimensions and pads – for board-wide anchor pic...
std::optional< KIID > NearestOutlineShape(const BOARD *aBoard, const VECTOR2I &aPos, double aMaxDist, bool aAllowCircle, PCB_LAYER_ID aLayer)
The shape whose outline is nearest aPos within aMaxDist.
std::vector< KIID > ConstrainedShapeIds(const BOARD *aBoard)
The member ids of every resolved constraint (see CollectResolvedConstraints()) that are on aBoard,...
double InitialConstraintValue(PCB_CONSTRAINT_TYPE aType, double aMeasured, const std::map< PCB_CONSTRAINT_TYPE, double > &aRemembered)
Value a freshly authored constraint dialog should open with.
EDA_ANGLE MeasureCornerAngle(const SEG &aA, const SEG &aB)
The corner angle between two segments, in the closed range [0, 180] degrees.
BOARD_ITEM * ResolveConstrainableItem(const BOARD *aBoard, const KIID &aId)
The board item a constraint may reference: a PCB_SHAPE, a dimension or a pad, or nullptr for anything...
bool DimensionHasValueMode(const PCB_DIMENSION_BASE *aDimension)
True for dimension types with a measured value aligned orthogonal or radial offering the Driven Drivi...
std::optional< CONSTRAINT_MEMBER > NearestConstraintAnchor(const BOARD *aBoard, const VECTOR2I &aPos, double aMaxDist, const std::vector< CONSTRAINT_MEMBER > &aExclude, PCB_LAYER_ID aLayer)
Find the constrainable-item anchor (a shape's segment/arc endpoint or centre, or a dimension's featur...
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintItemAnchors(const BOARD_ITEM *aItem)
The constraint anchors an item exposes.
std::optional< CONSTRAINT_ANCHOR_POINT > ConstraintShapeVertex(const PCB_SHAPE *aShape, int aIndex)
VERTEX anchor at ordinal aIndex of a rectangle or eligible polygon or std::nullopt if the shape has n...
wxString ConstraintSelectionHint(PCB_CONSTRAINT_TYPE aType)
A sentence naming what aType needs selected, for the moment a selection does not fit it and the tool ...
bool DimensionCanDrive(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
True when Driving mode may be offered for aDimension needs both endpoints bound via DimensionEndpoint...
std::vector< AUTO_CONSTRAINT > SelectShapeAutoConstraints(const BOARD *aBoard, const PCB_SHAPE *aShape, BOARD_ITEM *aParent, bool aAxisConstraint)
Choose the constraints a freshly drawn shape should get from what its features landed on.
bool ConstraintIsDuplicateOnBoard(const BOARD *aBoard, const PCB_CONSTRAINT *aConstraint)
True if a resolved constraint (see CollectResolvedConstraints()) already equals aConstraint.
std::unique_ptr< PCB_CONSTRAINT > BuildConstraintFromItems(BOARD_ITEM *aParent, PCB_CONSTRAINT_TYPE aType, const std::vector< BOARD_ITEM * > &aItems)
Build a constraint of aType from a set of selected board items, or nullptr if the selection does not ...
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::optional< KIID > SelectRadialDimensionTarget(const BOARD *aBoard, const KIID &aDimension, const VECTOR2I &aCenter, const VECTOR2I &aRim, double aMaxDist)
Single circle or arc a radial dimension binds to or std::nullopt.
DIM_VALUE_MODE DimensionValueMode(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
The value mode aDimension is in, derived from state: a self driving length means Driving,...
PCB_CONSTRAINT * FindDimensionLengthConstraint(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
Self FIXED_LENGTH constraint whose members are exactly aDimension START and END or nullptr the drivin...
std::vector< PCB_SHAPE * > CollectConstraintShapes(const BOARD *aBoard, PCB_LAYER_ID aLayer)
Every PCB_SHAPE on a visible layer (drawings plus footprint graphics) – the candidates constraints ca...
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< CONSTRAINT_MEMBER > NearestAnchorAmong(const std::vector< PCB_SHAPE * > &aShapes, const VECTOR2I &aPos, double aMaxDist)
The {shape, anchor} member nearest aPos within aMaxDist among aShapes, or std::nullopt.
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...
bool DimensionEndpointsBound(const BOARD *aBoard, const PCB_DIMENSION_BASE *aDimension)
True when both of aDimension measured endpoints are bound to anchors that still resolve a coincident ...
PCB_CONSTRAINT * SetDimensionValueMode(BOARD *aBoard, PCB_DIMENSION_BASE *aDimension, DIM_VALUE_MODE aMode, std::optional< int > aDrivingLengthIU, const std::optional< wxString > &aOverrideText, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::function< void(BOARD_ITEM *)> &aStageAdd, const std::function< void(BOARD_ITEM *)> &aBeforeRemove)
Apply a value mode transition to aDimension Driving creates or updates the driving length with aDrivi...
std::vector< PCB_CONSTRAINT * > CollectResolvedConstraints(const BOARD *aBoard)
The constraints the editor resolves on aBoard.
DIM_VALUE_MODE
Mode a value bearing dimension value is in Driven mirrors measured geometry Driving forces geometry t...
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
PCB_LAYER_ID
A quick note on layer IDs:
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
bool ConstraintsAreDuplicate(const PCB_CONSTRAINT &aA, const PCB_CONSTRAINT &aB)
True if two constraints express the same relation, meaning the same type and the same members compare...
wxString ConstraintTypeLabel(PCB_CONSTRAINT_TYPE aType)
Human-readable name of a constraint type (e.g. "Parallel"), for menus and lists.
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.
std::deque< PCB_CONSTRAINT * > CONSTRAINTS
One constraint chosen for a freshly drawn shape.
std::unique_ptr< PCB_CONSTRAINT > constraint
A selectable feature of a shape (a segment endpoint, arc centre, ...) and its location.
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.
One of a drawn item feature points bound coincident to an object anchor by draw time auto constrain s...
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ 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_PAD_T
class PAD, a pad in a footprint
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D