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 TopoDS_Compound aResultCompound;
42 aBuilder.MakeCompound(aResultCompound);
43 for(TopoDS_Iterator anIt(aResult); anIt.More(); anIt.Next()) {
44 const TopoDS_Shape aSubShape = anIt.Value();
45 if(aSubShape.ShapeType() == TopAbs_SHELL) {
46 aBuilder.Add(aResultCompound, aSubShape);
47 } else if (aSubShape.ShapeType() == TopAbs_FACE) {
49 aBuilder.MakeShell(aShell);
50 aBuilder.Add(aShell, aSubShape);
51 aBuilder.Add(aResultCompound, aShell);
54 TopoDS_Iterator anIt(aResultCompound);
56 aResult = aResultCompound;
59 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
60 aShape->setImpl(new TopoDS_Shape(aResult));
61 this->setShape(aShape);
65 //==================================================================================================
66 void GeomAlgoAPI_Sewing::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
67 ListOfShape& theHistory)
69 static int anIndex = 0;
74 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
75 const BRepBuilderAPI_Sewing& aSewingBuilder = this->impl<BRepBuilderAPI_Sewing>();
77 TopoDS_Shape aModifiedShape = aSewingBuilder.Modified(aShape);
78 if(aModifiedShape.IsEqual(aShape)) {
79 aModifiedShape = aSewingBuilder.ModifiedSubShape(aShape);
82 for(TopExp_Explorer anExp(aModifiedShape, aShape.ShapeType()); anExp.More(); anExp.Next()) {
83 GeomShapePtr aGeomShape(new GeomAPI_Shape());
84 aGeomShape->setImpl(new TopoDS_Shape(anExp.Current()));
85 theHistory.push_back(aGeomShape);