31 #define _USE_MATH_DEFINES 37 #include <BRepAlgoAPI_Cut.hxx> 38 #include <BRepBuilderAPI_Sewing.hxx> 39 #include <TopAbs_ShapeEnum.hxx> 40 #include <TopExp_Explorer.hxx> 41 #include <TopoDS_Compound.hxx> 42 #include <TopoDS_ListOfShape.hxx> 43 #include <TopoDS_Shape.hxx> 59 const std::array<double, 3> ¢er,
60 const std::array<double, 2> &rotation) {
61 auto angle = rotation[1] * M_PI / 180.;
62 return {center[0] + rotation[0] * std::cos(angle),
63 center[1] + rotation[0] * std::sin(angle), center[2]};
69 if (origCompound.IsNull()) {
70 keepGeo = std::move(removeGeo);
73 auto newCompound = removeGeo.buildCompound();
74 TopoDS_ListOfShape newShapes;
75 static constexpr std::array<TopAbs_ShapeEnum, 4> shapeTypes{
76 TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX};
78 for (TopExp_Explorer explorer{newCompound,
shapeType}; explorer.More();
80 auto &oldSubshape = explorer.Current();
81 if (
auto old_metadata = removeGeo.get(oldSubshape)) {
82 keepGeo.
insert(oldSubshape, std::move(*old_metadata));
86 if (!newCompound.IsNull()) {
87 keepGeo.
setDim(std::max(keepGeo.
getDim(), removeGeo.getDim()));
88 BRepAlgoAPI_Cut cutter{origCompound, newCompound};
89 if (cutter.HasDeleted() || cutter.HasModified() ||
90 cutter.HasGenerated()) {
91 auto deletedShapes = keepGeo.
modify(cutter, {TopAbs_EDGE, TopAbs_FACE});
94 BRepBuilderAPI_Sewing sewer{};
95 std::vector<TopoDS_Shape> sewedShapes;
97 for (TopExp_Explorer explorer{compound, TopAbs_FACE}; explorer.More();
99 sewer.Add(explorer.Current());
100 sewedShapes.emplace_back(explorer.Current());
104 keepGeo.
modify(sewer, sewedShapes, {TopAbs_EDGE, TopAbs_FACE});
std::pair< MapType::iterator, bool > insert(const TopoDS_Shape &shape, std::shared_ptr< ShapeData > shapeData)
Class to manage TopoDS_Shapes along with metadata.
void deleteShapes(const TopoDS_Shape &shape)
Remove a shape from the map.
int getDim() const
Get dimension of geometry.
std::array< double, 3 > center_
static constexpr auto shapeType
static std::array< double, 3 > getRotatedPoint(const std::array< double, 3 > ¢er, const std::array< double, 2 > &rotation)
const std::array< double, 3 > & getCenter() const
ShapeBase(const std::array< double, 3 > ¢er={0, 0, 0})
TopoDS_Compound buildCompound() const
Create a compound from shapes present in the map that have same dimension as the instance.
static void mergeGeo(NEM::GEO::GeoManager &keepGeo, NEM::GEO::GeoManager &&removeGeo)
Merge two 2d NEM::GEO::GeoManager objects by cutting shapes in removeGeo from shapes in keepGeo and s...
std::vector< TopoDS_Shape > modify(BRepBuilderAPI_MakeShape &op, const std::vector< TopoDS_Shape > &shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
Modify this geoMetadata after a BRepBuilderAPI_MakeShape operation.
void setCenter(const std::array< double, 3 > ¢er)
void setDim(int dim)
Set the dimension.