From b8436388794858458c580bac2d2f890c5ebc3c14 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 17 Feb 2024 18:06:56 -0500 Subject: [PATCH 1/3] Toponaming/Part: transfer in and clean getSubShapes, getSubTopoShapes, getOrderedEdges --- src/Mod/Part/App/TopoShape.cpp | 8 -- src/Mod/Part/App/TopoShape.h | 34 +++++++- src/Mod/Part/App/TopoShapeExpansion.cpp | 104 +++++++++++++++++++++++- 3 files changed, 135 insertions(+), 11 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 431fb74645..b3b6ee6641 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -439,14 +439,6 @@ static inline std::vector _getSubShapes(const TopoDS_Shape &s, TopAbs_ShapeEn return shapes; } -std::vector TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type) const { - return _getSubShapes(_Shape,type); -} - -std::vector TopoShape::getSubShapes(TopAbs_ShapeEnum type) const { - return _getSubShapes(_Shape,type); -} - static std::array _ShapeNames; static void initShapeNameMap() { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 4bdd9243c3..a15c929dc5 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -188,6 +188,12 @@ enum class MakeSolid makeSolid }; +enum class MapElement +{ + noMap, + map +}; + /** The representation for a CAD Shape */ // NOLINTNEXTLINE cppcoreguidelines-special-member-functions @@ -330,8 +336,32 @@ public: * @return The shape, or a null TopoShape. */ TopoShape getSubTopoShape(TopAbs_ShapeEnum type, int idx, bool silent = false) const; - std::vector getSubTopoShapes(TopAbs_ShapeEnum type = TopAbs_SHAPE) const; - std::vector getSubShapes(TopAbs_ShapeEnum type = TopAbs_SHAPE) const; + /** + * Locate all of the sub TopoShapes of a given type, while avoiding a given type + * @param type The type to find + * @param avoid The type to avoid + * @return The sub TopoShapes. + */ + std::vector getSubTopoShapes(TopAbs_ShapeEnum type=TopAbs_SHAPE, TopAbs_ShapeEnum avoid=TopAbs_SHAPE) const; + /** + * Locate all of the sub TopoDS_Shapes of a given type, while avoiding a given type + * @param type The type to find + * @param avoid The type to avoid + * @return The sub TopoDS_Shapes. + */ + std::vector getSubShapes(TopAbs_ShapeEnum type=TopAbs_SHAPE, TopAbs_ShapeEnum avoid=TopAbs_SHAPE) const; + /** + * Locate all the Edges in the Wires of this shape + * @param mapElement If True, map the subelements ( Edges ) found + * @return Vector of the edges + */ + std::vector getOrderedEdges(MapElement mapElement=MapElement::map) const; + /** + * Locate all the Vertexes in the Wires of this shape + * @param mapElement If True, map the subelements ( Vertexes ) found + * @return Vector of the Vertexes + */ + std::vector getOrderedVertexes(MapElement mapElement=MapElement::map) const; unsigned long countSubShapes(const char* Type) const; unsigned long countSubShapes(TopAbs_ShapeEnum type) const; bool hasSubShape(const char* Type) const; diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 19c0472c90..a9771be3c7 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -691,7 +692,7 @@ void TopoShape::mapSubElementTypeForShape(const TopoShape& other, } char elementType {shapeName(type)[0]}; if (!elementMap()) { - FC_THROWM(NullShapeException, "No element map"); // NOLINT + resetElementMap(); // TODO: Should never happen, but does while code is in transit } std::ostringstream ss; elementMap()->encodeElementName(elementType, name, ss, &sids, Tag, op, other.Tag); @@ -820,6 +821,107 @@ void TopoShape::mapSubElement(const std::vector& shapes, const char* } } +std::vector TopoShape::getSubShapes(TopAbs_ShapeEnum type, TopAbs_ShapeEnum avoid) const { + std::vector ret; + if(isNull()) + return ret; + if (avoid != TopAbs_SHAPE) { + for (TopExp_Explorer exp(getShape(), type, avoid); exp.More(); exp.Next()) + ret.push_back(exp.Current()); + return ret; + } + initCache(); + auto &ancestry = _cache->getAncestry(type); + int count = ancestry.count(); + ret.reserve(count); + for(int i=1;i<=count;++i) + ret.push_back(ancestry.find(_Shape,i)); + return ret; +} + +std::vector TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type, TopAbs_ShapeEnum avoid) const { + if(isNull()) + return std::vector(); + initCache(); + + auto res = _cache->getAncestry(type).getTopoShapes(*this); + if (avoid != TopAbs_SHAPE && hasSubShape(avoid)) { + for (auto it = res.begin(); it != res.end(); ) { + if (_cache->findAncestor(_Shape, it->getShape(), avoid).IsNull()) + ++it; + else + it = res.erase(it); + } + } + return res; +} + +std::vector TopoShape::getOrderedEdges(MapElement mapElement) const +{ + if(isNull()) + return std::vector(); + + std::vector shapes; + if (shapeType() == TopAbs_WIRE) { + BRepTools_WireExplorer xp(TopoDS::Wire(getShape())); + while (xp.More()) { + shapes.push_back(TopoShape(xp.Current())); + xp.Next(); + } + } + else { +// INIT_SHAPE_CACHE(); + initCache(); + for (const auto &w : getSubShapes(TopAbs_WIRE)) { + BRepTools_WireExplorer xp(TopoDS::Wire(w)); + while (xp.More()) { + shapes.push_back(TopoShape(xp.Current())); + xp.Next(); + } + } + } + if (mapElement == MapElement::map) + mapSubElementsTo(shapes); + return shapes; +} + +std::vector TopoShape::getOrderedVertexes(MapElement mapElement) const +{ + if(isNull()) + return std::vector(); + + std::vector shapes; + + auto collect = [&](const TopoDS_Shape &s) { + auto wire = TopoDS::Wire(s); + BRepTools_WireExplorer xp(wire); + while (xp.More()) { + shapes.push_back(TopoShape(xp.CurrentVertex())); + xp.Next(); + } + // special treatment for open wires + TopoDS_Vertex Vfirst, Vlast; + TopExp::Vertices(wire, Vfirst, Vlast); + if (!Vfirst.IsNull() && !Vlast.IsNull()) { + if (!Vfirst.IsSame(Vlast)) { + shapes.push_back(TopoShape(Vlast)); + } + } + }; + + if (shapeType() == TopAbs_WIRE) + collect(getShape()); + else { +// INIT_SHAPE_CACHE(); + initCache(); + for (const auto &s : getSubShapes(TopAbs_WIRE)) + collect(s); + } + if (mapElement == MapElement::map) + mapSubElementsTo(shapes); + return shapes; +} + struct ShapeInfo { const TopoDS_Shape& shape; From fc1d0cc71c2e0d81ba1574fcc80d53ba4b00594a Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 17 Feb 2024 18:07:23 -0500 Subject: [PATCH 2/3] Toponaming/Part: tests addition and cleaning --- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 156 +++++++++++++----- 1 file changed, 114 insertions(+), 42 deletions(-) diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 64bf465140..c8562e29ab 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -182,7 +181,7 @@ TEST_F(TopoShapeExpansionTest, MapperMakerModified) // Creating a Face using the Wire created before auto faceMkr {BRepBuilderAPI_MakeFace(wire)}; - auto face = faceMkr.Face(); + const auto& face = faceMkr.Face(); // Creating an Edge to split the Face and the Wire auto edgeMkr {BRepBuilderAPI_MakeEdge(gp_Pnt(0.5, 1.0, 0.0), gp_Pnt(0.5, -1.0, 0.0))}; @@ -255,33 +254,55 @@ TEST_F(TopoShapeExpansionTest, MapperMakerGenerated) EXPECT_EQ(fuse2MprMkr.generated(edge3).size(), 1); // fuse2 has a new vertex generated by edge3 } -// ================================================================================================ -// The following test has been disabled to avoid the CI failing -// will be enabled again in following PRs -// ================================================================================================ +TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesAdjacent) +{ + // Arrange + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge(); + TopoShape topoShape {3L}; + std::vector shapes {TopoShape(edge1, 1L), TopoShape(edge2, 2L)}; + // std::vector shapes {edge1, edge2}; + // Act + topoShape.makeElementWires(shapes); + auto elementMap = topoShape.getElementMap(); + // Assert + EXPECT_EQ(0, elementMap.size()); // TODO: What is the correct value? +} -// TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesAdjacent) -// { -// // Arrange -// auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); -// auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge(); -// TopoShape topoShape; -// std::vector shapes {edge1, edge2}; - -// // Act -// topoShape.makeElementWires(shapes); - -// // Assert -// auto elementMap = topoShape.getElementMap(); -// EXPECT_EQ(6, elementMap.size()); -// } - -// ================================================================================================ +TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesWires) +{ + // Arrange + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge(); + auto edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(3.0, 0.0, 0.0), gp_Pnt(2.0, 1.0, 0.0)).Edge(); + auto edge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(2.0, 1.0, 0.0), gp_Pnt(2.0, 2.0, 0.0)).Edge(); + std::vector shapes {TopoShape(edge1, 1L), TopoShape(edge2, 2L)}; + std::vector shapes2 {TopoShape(edge3, 4L), TopoShape(edge4, 4L)}; + // std::vector shapes {edge1, edge2}; + // Act + auto& wire1 = (new TopoShape {})->makeElementWires(shapes); + auto& wire2 = (new TopoShape {})->makeElementWires(shapes2); + auto& topoShape = (new TopoShape {})->makeElementWires({wire1, wire2}); + auto elements = elementMap((topoShape)); + // Assert + EXPECT_EQ(elements.size(), 10); + EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Edge1;:H,E")); + EXPECT_EQ(elements[IndexedName("Edge", 2)], MappedName("Edge2;:H,E")); + EXPECT_EQ(elements[IndexedName("Edge", 3)], MappedName("Edge1;:C1;:H:4,E")); + EXPECT_EQ(elements[IndexedName("Edge", 4)], MappedName("Edge2;:C1;:H:4,E")); + EXPECT_EQ(elements[IndexedName("Vertex", 1)], MappedName("Vertex1;:H,V")); + EXPECT_EQ(elements[IndexedName("Vertex", 2)], MappedName("Vertex2;:H,V")); + EXPECT_EQ(elements[IndexedName("Vertex", 3)], MappedName("Vertex3;:H,V")); + EXPECT_EQ(elements[IndexedName("Vertex", 4)], MappedName("Vertex1;:C1;:H:4,V")); + EXPECT_EQ(elements[IndexedName("Vertex", 5)], MappedName("Vertex2;:C1;:H:4,V")); + EXPECT_EQ(elements[IndexedName("Vertex", 6)], MappedName("Vertex3;:C1;:H:4,V")); +} TEST_F(TopoShapeExpansionTest, makeElementFaceNull) { // Arrange - const double Len = 3, Wid = 2, Rad = 1; + const float Len = 3, Wid = 2, Rad = 1; auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad); TopoShape topoShape {face1}; double area = getArea(face1); @@ -431,7 +452,7 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceClosedWire) TEST_F(TopoShapeExpansionTest, setElementComboNameNothing) { // Arrange - TopoShape topoShape(1L); + TopoShape topoShape {1L}; // Act Data::MappedName result = topoShape.setElementComboName(Data::IndexedName(), {}); // ASSERT @@ -443,7 +464,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameSimple) { // Arrange auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); - TopoShape topoShape(edge1, 1L); + TopoShape topoShape {edge1, 1L}; topoShape.setElementMap({}); // Initialize the map to avoid a segfault. // Also, maybe the end of TopoShape::mapSubElementTypeForShape should enforce that elementMap() // isn't nullptr to eliminate the segfault. @@ -459,7 +480,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameSimple) TEST_F(TopoShapeExpansionTest, setElementComboName) { // Arrange - TopoShape topoShape(2L); + TopoShape topoShape {2L}; topoShape.setElementMap({}); Data::MappedName edgeName = topoShape.getMappedName(Data::IndexedName::fromConst("Edge", 1), true); @@ -484,7 +505,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameCompound) auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); auto wire1 = BRepBuilderAPI_MakeWire({edge1}).Wire(); auto wire2 = BRepBuilderAPI_MakeWire({edge1}).Wire(); - TopoShape topoShape(2L); + TopoShape topoShape {2L}; topoShape.makeElementCompound({wire1, wire2}); // Quality of shape doesn't matter Data::MappedName edgeName = topoShape.getMappedName(Data::IndexedName::fromConst("Edge", 1), true); @@ -530,12 +551,63 @@ TEST_F(TopoShapeExpansionTest, splitWires) // splitWires with all four reorientation values NoReorient, ReOrient, ReorientForward, // ReorientReversed +TEST_F(TopoShapeExpansionTest, getSubShapes) +{ + // Arrange + auto [cube1, cube2] = CreateTwoTopoShapeCubes(); + // Act + auto subShapes = cube1.getSubShapes(); + auto subShapes2 = cube1.getSubShapes(TopAbs_FACE); + auto subShapes3 = cube1.getSubShapes(TopAbs_SHAPE, TopAbs_EDGE); + // Assert + EXPECT_EQ(subShapes.size(), 6); + EXPECT_EQ(subShapes2.size(), 6); + EXPECT_EQ(subShapes3.size(), 0); // TODO: Why doesn't this match the next test? +} + +TEST_F(TopoShapeExpansionTest, getSubTopoShapes) +{ + // Arrange + auto [cube1, cube2] = CreateTwoTopoShapeCubes(); + // Act + auto subShapes = cube1.getSubTopoShapes(); + auto subShapes2 = cube1.getSubTopoShapes(TopAbs_FACE); + auto subShapes3 = cube1.getSubTopoShapes(TopAbs_SHAPE, TopAbs_EDGE); + // Assert + EXPECT_EQ(subShapes.size(), 6); + EXPECT_EQ(subShapes2.size(), 6); + EXPECT_EQ(subShapes3.size(), 6); +} + +TEST_F(TopoShapeExpansionTest, getOrderedEdges) +{ + // Arrange + auto [cube1, cube2] = CreateTwoTopoShapeCubes(); + // Act + auto subShapes = cube1.getOrderedEdges(MapElement::noMap); + // Assert + EXPECT_EQ(subShapes.size(), 24); + // EXPECT_THROW(cube1.getOrderedEdges(), NullShapeException); // No Map + EXPECT_EQ(subShapes.front().getElementMap().size(), 0); + // EXPECT_EQ(subShapes2.front().getElementMap().size(),2); +} + +TEST_F(TopoShapeExpansionTest, getOrderedVertexes) +{ + // Arrange + auto [cube1, cube2] = CreateTwoTopoShapeCubes(); + // Act + auto subShapes = cube1.getOrderedVertexes(MapElement::noMap); + // Assert + EXPECT_EQ(subShapes.size(), 24); + // EXPECT_THROW(cube1.getOrderedEdges(), NullShapeException); // No Map +} + TEST_F(TopoShapeExpansionTest, getSubTopoShapeByEnum) { // Arrange auto [cube1, cube2] = CreateTwoCubes(); - TopoShape cube1TS {cube1}; - cube1TS.Tag = 1L; + TopoShape cube1TS {cube1, 1L}; // Act auto subShape = cube1TS.getSubTopoShape(TopAbs_FACE, 1); @@ -554,8 +626,7 @@ TEST_F(TopoShapeExpansionTest, getSubTopoShapeByStringDefaults) { // Arrange auto [cube1, cube2] = CreateTwoCubes(); - Part::TopoShape cube1TS {cube1}; - cube1TS.Tag = 1L; + Part::TopoShape cube1TS {cube1, 1L}; const float Len = 3; const float Wid = 2; auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(Len, Wid); @@ -581,8 +652,7 @@ TEST_F(TopoShapeExpansionTest, getSubTopoShapeByStringNames) { // Arrange auto [cube1, cube2] = CreateTwoCubes(); - TopoShape cube1TS {cube1}; - cube1TS.Tag = 1; + TopoShape cube1TS {cube1, 1L}; // Act auto subShape = cube1TS.getSubTopoShape("Face1"); @@ -602,16 +672,17 @@ TEST_F(TopoShapeExpansionTest, mapSubElementInvalidParm) { // Arrange auto [cube1, cube2] = CreateTwoCubes(); - TopoShape cube1TS {cube1}; - cube1TS.Tag = 1; - + TopoShape cube1TS {cube1, 1L}; + TopoShape cube2TS {cube2, 2L}; // Act std::vector subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE); TopoShape face1 = subShapes.front(); - face1.Tag = 2; - + face1.Tag = 3; + cube1TS.mapSubElement(face1); + cube2TS.mapSubElement(face1); // Assert - EXPECT_THROW(cube1TS.mapSubElement(face1), NullShapeException); // No subshapes + EXPECT_EQ(cube1TS.getElementMap().size(), 9); // Valid, the face is in Cube1 + EXPECT_EQ(cube2TS.getElementMap().size(), 0); // Invalid, the face is not in Cube2 } TEST_F(TopoShapeExpansionTest, mapSubElementFindShapeByNames) @@ -1196,8 +1267,9 @@ TEST_F(TopoShapeExpansionTest, makeElementLoft) transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.0, 0.0, 10.0)); auto wire2 = wire1; // Shallow copy wire2.Move(TopLoc_Location(transform)); - TopoShape wire1ts {wire1, - 1L}; // One of these shapes should have a tag or we won't get an Element Map + TopoShape wire1ts { + wire1, + 1L}; // One of these shapes should have a tag or else we won't get an Element Map TopoShape wire2ts { wire2, 2L}; // If you change either tag or eliminate one it changes the resulting name. From 1653ad01d809de728016064cc3a92db90504bd27 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 17 Feb 2024 19:37:29 -0600 Subject: [PATCH 3/3] Toponaming/Part: clang-format pass --- src/Mod/Part/App/TopoShapeExpansion.cpp | 97 +++++++++++++++---------- 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index a9771be3c7..b1f739be01 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -29,10 +29,10 @@ #include #include -# if OCC_VERSION_HEX < 0x070600 -# include -# include -# endif +#if OCC_VERSION_HEX < 0x070600 +#include +#include +#endif #include #include @@ -240,10 +240,10 @@ TopoDS_Shape TopoShape::findShape(TopAbs_ShapeEnum type, int idx) const } std::vector TopoShape::findSubShapesWithSharedVertex(const TopoShape& subshape, - std::vector* names, - CheckGeometry checkGeometry, - double tol, - double atol) const + std::vector* names, + CheckGeometry checkGeometry, + double tol, + double atol) const { std::vector res; if (subshape.isNull() || this->isNull()) { @@ -347,8 +347,9 @@ std::vector TopoShape::findSubShapesWithSharedVertex(const TopoShape& // * Compare each vertex of the ancestor shape and the input shape // * Perform geometry comparison of the ancestor and input shape. // * For face, perform addition geometry comparison of each edge. - std::unordered_set shapeSet; - for (auto& vert : findSubShapesWithSharedVertex(vertices[0], nullptr, checkGeometry, tol, atol)) { + std::unordered_set shapeSet; + for (auto& vert : + findSubShapesWithSharedVertex(vertices[0], nullptr, checkGeometry, tol, atol)) { for (auto idx : findAncestors(vert.getShape(), shapeType)) { auto shape = getSubTopoShape(shapeType, idx); if (!shapeSet.insert(shape).second) { @@ -370,7 +371,8 @@ std::vector TopoShape::findSubShapesWithSharedVertex(const TopoShape& if (otherVertices.size() != vertices.size()) { continue; } - if (checkGeometry == CheckGeometry::checkGeometry && !compareGeometry(shape, false)) { + if (checkGeometry == CheckGeometry::checkGeometry + && !compareGeometry(shape, false)) { continue; } unsigned ind = 0; @@ -821,36 +823,46 @@ void TopoShape::mapSubElement(const std::vector& shapes, const char* } } -std::vector TopoShape::getSubShapes(TopAbs_ShapeEnum type, TopAbs_ShapeEnum avoid) const { +std::vector TopoShape::getSubShapes(TopAbs_ShapeEnum type, + TopAbs_ShapeEnum avoid) const +{ std::vector ret; - if(isNull()) + if (isNull()) { return ret; + } if (avoid != TopAbs_SHAPE) { - for (TopExp_Explorer exp(getShape(), type, avoid); exp.More(); exp.Next()) + for (TopExp_Explorer exp(getShape(), type, avoid); exp.More(); exp.Next()) { ret.push_back(exp.Current()); + } return ret; } initCache(); - auto &ancestry = _cache->getAncestry(type); + auto& ancestry = _cache->getAncestry(type); int count = ancestry.count(); ret.reserve(count); - for(int i=1;i<=count;++i) - ret.push_back(ancestry.find(_Shape,i)); + for (int i = 1; i <= count; ++i) { + ret.push_back(ancestry.find(_Shape, i)); + } return ret; } -std::vector TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type, TopAbs_ShapeEnum avoid) const { - if(isNull()) +std::vector TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type, + TopAbs_ShapeEnum avoid) const +{ + if (isNull()) { return std::vector(); + } initCache(); auto res = _cache->getAncestry(type).getTopoShapes(*this); if (avoid != TopAbs_SHAPE && hasSubShape(avoid)) { - for (auto it = res.begin(); it != res.end(); ) { - if (_cache->findAncestor(_Shape, it->getShape(), avoid).IsNull()) + for (auto it = res.begin(); it != res.end();) { + if (_cache->findAncestor(_Shape, it->getShape(), avoid).IsNull()) { ++it; - else + } + else { it = res.erase(it); + } } } return res; @@ -858,8 +870,9 @@ std::vector TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type, TopAbs std::vector TopoShape::getOrderedEdges(MapElement mapElement) const { - if(isNull()) + if (isNull()) { return std::vector(); + } std::vector shapes; if (shapeType() == TopAbs_WIRE) { @@ -870,9 +883,9 @@ std::vector TopoShape::getOrderedEdges(MapElement mapElement) const } } else { -// INIT_SHAPE_CACHE(); + // INIT_SHAPE_CACHE(); initCache(); - for (const auto &w : getSubShapes(TopAbs_WIRE)) { + for (const auto& w : getSubShapes(TopAbs_WIRE)) { BRepTools_WireExplorer xp(TopoDS::Wire(w)); while (xp.More()) { shapes.push_back(TopoShape(xp.Current())); @@ -880,19 +893,21 @@ std::vector TopoShape::getOrderedEdges(MapElement mapElement) const } } } - if (mapElement == MapElement::map) + if (mapElement == MapElement::map) { mapSubElementsTo(shapes); + } return shapes; } std::vector TopoShape::getOrderedVertexes(MapElement mapElement) const { - if(isNull()) + if (isNull()) { return std::vector(); + } std::vector shapes; - auto collect = [&](const TopoDS_Shape &s) { + auto collect = [&](const TopoDS_Shape& s) { auto wire = TopoDS::Wire(s); BRepTools_WireExplorer xp(wire); while (xp.More()) { @@ -909,16 +924,19 @@ std::vector TopoShape::getOrderedVertexes(MapElement mapElement) cons } }; - if (shapeType() == TopAbs_WIRE) + if (shapeType() == TopAbs_WIRE) { collect(getShape()); - else { -// INIT_SHAPE_CACHE(); - initCache(); - for (const auto &s : getSubShapes(TopAbs_WIRE)) - collect(s); } - if (mapElement == MapElement::map) + else { + // INIT_SHAPE_CACHE(); + initCache(); + for (const auto& s : getSubShapes(TopAbs_WIRE)) { + collect(s); + } + } + if (mapElement == MapElement::map) { mapSubElementsTo(shapes); + } return shapes; } @@ -1913,7 +1931,8 @@ TopoShape& TopoShape::makeElementRuledSurface(const std::vector& shap } } } - // Use empty mapper and let makeShapeWithElementMap name the created surface with lower elements. + // Use empty mapper and let makeShapeWithElementMap name the created surface with lower + // elements. return makeShapeWithElementMap(res.getShape(), Mapper(), edges, op); } @@ -2521,8 +2540,10 @@ TopoShape& TopoShape::makeElementShape(BRepPrimAPI_MakeHalfSpace& mkShape, return makeShapeWithElementMap(mkShape.Solid(), MapperMaker(mkShape), {source}, op); } -TopoShape &TopoShape::makeElementShape(BRepOffsetAPI_MakePipeShell &mkShape, - const std::vector &source, const char *op) { +TopoShape& TopoShape::makeElementShape(BRepOffsetAPI_MakePipeShell& mkShape, + const std::vector& source, + const char* op) +{ if (!op) { op = Part::OpCodes::PipeShell; }