1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Sewing.cpp
4 // Created: 25 April 2016
5 // Author: Dmitry Bobylev
8 #include "GeomAlgoAPI_Sewing.h"
10 #include <BRep_Builder.hxx>
11 #include <BRepBuilderAPI_MakeShell.hxx>
12 #include <BRepBuilderAPI_Sewing.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Iterator.hxx>
15 #include <TopoDS_Shape.hxx>
17 //==================================================================================================
18 GeomAlgoAPI_Sewing::GeomAlgoAPI_Sewing(const ListOfShape& theShapes)
23 void GeomAlgoAPI_Sewing::build(const ListOfShape& theShapes)
25 if(theShapes.empty()) {
29 BRepBuilderAPI_Sewing* aSewingBuilder = new BRepBuilderAPI_Sewing();
30 this->setImpl(aSewingBuilder);
32 for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
33 const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
34 aSewingBuilder->Add(aShape);
37 aSewingBuilder->Perform();
39 TopoDS_Shape aResult = aSewingBuilder->SewedShape();
40 BRep_Builder aBuilder;
41 if(aResult.ShapeType() == TopAbs_COMPOUND) {
42 TopoDS_Compound aResultCompound;
43 aBuilder.MakeCompound(aResultCompound);
44 for(TopoDS_Iterator anIt(aResult); anIt.More(); anIt.Next()) {
45 const TopoDS_Shape aSubShape = anIt.Value();
46 if(aSubShape.ShapeType() == TopAbs_SHELL) {
47 aBuilder.Add(aResultCompound, aSubShape);
48 } else if (aSubShape.ShapeType() == TopAbs_FACE) {
50 aBuilder.MakeShell(aShell);
51 aBuilder.Add(aShell, aSubShape);
52 aBuilder.Add(aResultCompound, aShell);
55 aResult = aResultCompound;
56 } else if(aResult.ShapeType() == TopAbs_FACE) {
58 aBuilder.MakeShell(aShell);
59 aBuilder.Add(aShell, aResult);
63 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
64 aShape->setImpl(new TopoDS_Shape(aResult));
65 this->setShape(aShape);
69 //==================================================================================================
70 void GeomAlgoAPI_Sewing::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
71 ListOfShape& theHistory)
73 static int anIndex = 0;
78 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
79 const BRepBuilderAPI_Sewing& aSewingBuilder = this->impl<BRepBuilderAPI_Sewing>();
81 TopoDS_Shape aModifiedShape = aSewingBuilder.Modified(aShape);
82 if(aModifiedShape.IsEqual(aShape)) {
83 aModifiedShape = aSewingBuilder.ModifiedSubShape(aShape);
86 for(TopExp_Explorer anExp(aModifiedShape, aShape.ShapeType()); anExp.More(); anExp.Next()) {
87 GeomShapePtr aGeomShape(new GeomAPI_Shape());
88 aGeomShape->setImpl(new TopoDS_Shape(anExp.Current()));
89 theHistory.push_back(aGeomShape);