]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Sewing.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Sewing.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Sewing.cpp
4 // Created:     25 April 2016
5 // Author:      Dmitry Bobylev
6
7
8 #include "GeomAlgoAPI_Sewing.h"
9
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>
16
17 //==================================================================================================
18 GeomAlgoAPI_Sewing::GeomAlgoAPI_Sewing(const ListOfShape& theShapes)
19 {
20   build(theShapes);
21 }
22
23 void GeomAlgoAPI_Sewing::build(const ListOfShape& theShapes)
24 {
25   if(theShapes.empty()) {
26     return;
27   }
28
29   BRepBuilderAPI_Sewing* aSewingBuilder = new BRepBuilderAPI_Sewing();
30   this->setImpl(aSewingBuilder);
31
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);
35   }
36
37   aSewingBuilder->Perform();
38
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) {
49         TopoDS_Shell aShell;
50         aBuilder.MakeShell(aShell);
51         aBuilder.Add(aShell, aSubShape);
52         aBuilder.Add(aResultCompound, aShell);
53       }
54     }
55     aResult = aResultCompound;
56   } else if(aResult.ShapeType() == TopAbs_FACE) {
57     TopoDS_Shell aShell;
58     aBuilder.MakeShell(aShell);
59     aBuilder.Add(aShell, aResult);
60     aResult = aShell;
61   }
62
63   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
64   aShape->setImpl(new TopoDS_Shape(aResult));
65   this->setShape(aShape);
66   this->setDone(true);
67 }
68
69 //==================================================================================================
70 void GeomAlgoAPI_Sewing::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
71                                   ListOfShape& theHistory)
72 {
73   static int anIndex = 0;
74   if(!theShape.get()) {
75     return;
76   }
77
78   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
79   const BRepBuilderAPI_Sewing& aSewingBuilder = this->impl<BRepBuilderAPI_Sewing>();
80
81   TopoDS_Shape aModifiedShape = aSewingBuilder.Modified(aShape);
82   if(aModifiedShape.IsEqual(aShape)) {
83     aModifiedShape = aSewingBuilder.ModifiedSubShape(aShape);
84   }
85
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);
90   }
91 }