31 #include <unordered_set> 33 #include <BRepAlgoAPI_BooleanOperation.hxx> 34 #include <BRepBuilderAPI_Sewing.hxx> 35 #include <BRep_Builder.hxx> 36 #include <TopExp_Explorer.hxx> 37 #include <TopTools_ListOfShape.hxx> 38 #include <TopoDS_Compound.hxx> 39 #include <TopoDS_Shape.hxx> 48 dim_(
std::min(3,
std::max(1, dim))) {}
54 template <
typename Op,
typename T,
typename F>
56 Op &&op, T &&shapes,
const std::vector<TopAbs_ShapeEnum> &typesToTraverse,
58 std::vector<TopoDS_Shape> shapesToRemove;
59 for (
auto &shape : shapes) {
60 if (typesToTraverse.empty()) {
61 modifyFunc(shape, shapesToRemove);
64 for (TopExp_Explorer explorer{shape,
shapeType}; explorer.More();
66 modifyFunc(explorer.Current(), shapesToRemove);
71 return shapesToRemove;
75 BRepBuilderAPI_MakeShape &op,
const std::vector<TopoDS_Shape> &shapes,
76 const std::vector<TopAbs_ShapeEnum> &typesToTraverse) {
78 [
this, &op](
const TopoDS_Shape &shape,
79 std::vector<TopoDS_Shape> &shapesToRemove) {
86 const std::vector<TopAbs_ShapeEnum> &typesToTraverse) {
88 [
this, &op](
const TopoDS_Shape &shape,
89 std::vector<TopoDS_Shape> &shapesToRemove) {
95 BRepAlgoAPI_BooleanOperation &op,
96 const std::vector<TopAbs_ShapeEnum> &typesToTraverse) {
97 return {this->
modify(op, op.Arguments(), typesToTraverse),
98 this->
modify(op, op.Tools(), typesToTraverse)};
102 BRepBuilderAPI_Sewing &op,
const std::vector<TopoDS_Shape> &shapes,
103 const std::vector<TopAbs_ShapeEnum> &typesToTraverse) {
105 op, shapes, typesToTraverse,
106 [
this, &op](
const TopoDS_Shape &shape,
107 std::vector<TopoDS_Shape> &shapesToRemove) {
108 auto findIter =
map_.find(shape);
109 if (findIter !=
map_.end()) {
114 : op.ModifiedSubShape(shape);
115 if (!modified.IsSame(shape)) {
117 modShapes.Append(modified);
118 if (findIter->second) {
119 findIter->second->updateModified(shape, modShapes, *
this);
121 shapesToRemove.emplace_back(shape);
129 auto findIter =
map_.find(shape);
130 if (findIter !=
map_.end()) {
131 if (findIter->second) {
132 findIter->second->updateDeleted(shape, *
this);
134 map_.erase(findIter);
140 for (
auto &shape : shapes) {
146 BRep_Builder builder;
147 TopoDS_Compound compound;
149 bool addedShapes =
false;
150 for (
auto &shape :
map_) {
153 builder.MakeCompound(compound);
156 builder.Add(compound, shape.first);
163 auto findIter =
map_.find(shape);
164 if (findIter !=
map_.end()) {
165 return &findIter->second;
172 const TopoDS_Shape &shape)
const {
173 auto findIter =
map_.find(shape);
174 if (findIter !=
map_.end()) {
175 return &findIter->second;
182 const TopoDS_Shape &shape, std::shared_ptr<ShapeData> shapeData) {
183 return map_.emplace(shape, std::move(shapeData));
192 switch (shape.ShapeType()) {
193 case TopAbs_COMPSOLID:
194 case TopAbs_SOLID: shapeDim = 3;
break;
196 case TopAbs_FACE: shapeDim = 2;
break;
198 case TopAbs_EDGE: shapeDim = 1;
break;
199 case TopAbs_VERTEX: shapeDim = 0;
break;
200 case TopAbs_COMPOUND:
202 default:
return false;
204 return shapeDim <
dim_;
208 const TopoDS_Shape &shape,
209 std::vector<TopoDS_Shape> &shapesToRemove) {
210 if (op.IsDeleted(shape)) {
211 shapesToRemove.emplace_back(shape);
213 auto findIter =
map_.find(shape);
214 if (findIter !=
map_.end()) {
215 auto &generated = op.Generated(shape);
216 if (!generated.IsEmpty()) {
217 if (findIter->second) {
218 findIter->second->updateGenerated(shape, generated, *
this);
221 auto &modified = op.Modified(shape);
222 if (!modified.IsEmpty()) {
223 if (findIter->second) {
224 findIter->second->updateModified(shape, modified, *
this);
226 shapesToRemove.emplace_back(shape);
std::pair< MapType::iterator, bool > insert(const TopoDS_Shape &shape, std::shared_ptr< ShapeData > shapeData)
std::unordered_map< TopoDS_Shape, std::shared_ptr< ShapeData >, ShapeMapHasher_Hash, ShapeMapHasher_KeyEqual > MapType
std::shared_ptr< ShapeData > * get(const TopoDS_Shape &shape)
Get the data from the map.
void deleteShapes(const TopoDS_Shape &shape)
Remove a shape from the map.
int getDim() const
Get dimension of geometry.
std::vector< TopoDS_Shape > modifyTempl(Op &&op, T &&shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse, F &&modifyFunc)
static constexpr auto shapeType
bool isChild(const TopoDS_Shape &shape) const
void modifyImpl(BRepBuilderAPI_MakeShape &op, const TopoDS_Shape &shape, std::vector< TopoDS_Shape > &shapesToRemove)
TopoDS_Compound buildCompound() const
Create a compound from shapes present in the map that have same dimension as the instance.
GeoManager(int dim)
Create an empty geometry manager.
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 setDim(int dim)
Set the dimension.