Toponaming: Add a plane matching based heuristic to TNP mitigation (#16803)

* Add a plane matching based heuristic to TNP mitigation

* Improve comments, add test
This commit is contained in:
bgbsww
2024-12-09 12:06:02 -05:00
committed by GitHub
parent 575c20886b
commit 9566f06683
4 changed files with 167 additions and 3 deletions

View File

@@ -5820,4 +5820,36 @@ bool TopoShape::getRelatedElementsCached(const Data::MappedName& name,
return true;
}
Data::MappedElement TopoShape::chooseMatchingSubShapeByPlaneOrLine(const TopoShape& shapeToFind, const TopoShape& shapeToLookIn)
{
Data::MappedElement result;
// See if we have a Face. If so, try to match using a plane.
auto targetShape = shapeToFind.getSubTopoShape("Face", true);
if ( ! targetShape.isNull() ) {
int index = 0;
for ( const auto& searchFace : shapeToLookIn.getSubTopoShapes(TopAbs_FACE)) {
index++; // We have to generate the element index.
if ( targetShape.isCoplanar(searchFace) ) {
if ( ! result.name.empty() )
return {}; // Found more than one, invalidate our guess. Future: return all matches to the UI?
result = shapeToLookIn.getElementName(("Face"+std::to_string(index)).c_str());
}
}
}
// Alternatively, try to locate an Edge, and try to match. Currently by exact equivalence; later can improve.
targetShape = shapeToFind.getSubTopoShape("Edge", true);
if ( ! targetShape.isNull() ) { // Try to match edges
int index = 0;
for ( const auto& searchEdge : shapeToLookIn.getSubTopoShapes(TopAbs_EDGE)) {
index++;
if ( targetShape.isSame(searchEdge) ) { // TODO: Test for edges that are collinear as really what we want
if ( ! result.name.empty() )
return {}; // Found more than one
result = shapeToLookIn.getElementName(("Edge"+std::to_string(index)).c_str());
}
}
}
return result;
}
} // namespace Part