1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_Sewing.h"
22 #include <BRep_Builder.hxx>
23 #include <BRepBuilderAPI_MakeShell.hxx>
24 #include <BRepBuilderAPI_Sewing.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopoDS_Shape.hxx>
29 //==================================================================================================
30 GeomAlgoAPI_Sewing::GeomAlgoAPI_Sewing(const ListOfShape& theShapes)
35 GeomAlgoAPI_Sewing::GeomAlgoAPI_Sewing(const ListOfShape& theShapes, const bool theAllowNonManifold, const double theTolerance)
37 build(theShapes, theAllowNonManifold, theTolerance);
40 void GeomAlgoAPI_Sewing::build(const ListOfShape& theShapes, const bool theAllowNonManifold, const double theTolerance)
42 if(theShapes.empty()) {
46 BRepBuilderAPI_Sewing* aSewingBuilder = new BRepBuilderAPI_Sewing();
47 this->setImpl(aSewingBuilder);
49 aSewingBuilder->SetTolerance(theTolerance);
50 aSewingBuilder->SetFaceMode(Standard_True);
51 aSewingBuilder->SetFloatingEdgesMode(Standard_False);
52 aSewingBuilder->SetNonManifoldMode(theAllowNonManifold);
54 for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
55 const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
56 aSewingBuilder->Add(aShape);
59 aSewingBuilder->Perform();
61 TopoDS_Shape aResult = aSewingBuilder->SewedShape();
63 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
64 aShape->setImpl(new TopoDS_Shape(aResult));
65 this->setShape(aShape);
69 //==================================================================================================
70 #include <GeomAPI_ShapeIterator.h>
72 void GeomAlgoAPI_Sewing::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
73 ListOfShape& theHistory)
79 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
80 const BRepBuilderAPI_Sewing& aSewingBuilder = this->impl<BRepBuilderAPI_Sewing>();
82 TopoDS_Shape aModifiedShape = aSewingBuilder.Modified(aShape);
83 if(aModifiedShape.IsEqual(aShape)) {
84 aModifiedShape = aSewingBuilder.ModifiedSubShape(aShape);
87 for(TopExp_Explorer anExp(aModifiedShape, aShape.ShapeType()); anExp.More(); anExp.Next()) {
88 GeomShapePtr aGeomShape(new GeomAPI_Shape());
89 aGeomShape->setImpl(new TopoDS_Shape(anExp.Current()));
90 theHistory.push_back(aGeomShape);
93 if (theShape->shapeType() < GeomAPI_Shape::FACE) {
94 ListOfShape aNewShapes;
95 // collect faces and parent shapes, if it is not done yet
96 if (!isNewShapesCollected(theShape, GeomAPI_Shape::FACE))
97 collectNewShapes(theShape, GeomAPI_Shape::FACE);
99 for (GeomAPI_ShapeIterator anIt(shape()); anIt.more(); anIt.next()) {
100 GeomShapePtr anOldShapesCompound =
101 oldShapesForNew(theShape, anIt.current(), GeomAPI_Shape::FACE);
102 if (!anOldShapesCompound->isNull())
103 aNewShapes.push_back(anIt.current());
106 if (!aNewShapes.empty())
107 theHistory = aNewShapes;