1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_MakeVolume.h"
23 #include <GeomAPI_ShapeExplorer.h>
25 #include <GeomAlgoAPI_ShapeTools.h>
27 #include <BOPAlgo_MakerVolume.hxx>
29 //=================================================================================================
30 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeVolume::make(const ListOfShape& theFaces)
32 GeomAlgoAPI_MakeVolume aMkVolAlgo(theFaces, false);
34 if(aMkVolAlgo.isDone() && !aMkVolAlgo.shape()->isNull() && aMkVolAlgo.isValid())
35 aResult = aMkVolAlgo.shape();
39 //=================================================================================================
40 GeomAlgoAPI_MakeVolume::GeomAlgoAPI_MakeVolume(
41 const ListOfShape& theFaces, const bool theAvoidInternal)
43 myAvoidInternal = theAvoidInternal;
47 static void convertToTopoDS(const ListOfShape& theShapes, TopTools_ListOfShape& theTopoDSShapes)
49 for (ListOfShape::const_iterator anIt = theShapes.begin(); anIt != theShapes.end(); ++anIt)
50 theTopoDSShapes.Append((*anIt)->impl<TopoDS_Shape>());
53 //=================================================================================================
54 void GeomAlgoAPI_MakeVolume::build(const ListOfShape& theFaces)
56 if (theFaces.empty()) {
60 // create make volume opration
61 BOPAlgo_MakerVolume* aVolumeMaker = new BOPAlgo_MakerVolume;
62 this->setImpl(aVolumeMaker);
63 this->setBuilderType(OCCT_BOPAlgo_Builder);
66 TopTools_ListOfShape anArgs;
67 convertToTopoDS(theFaces, anArgs);
69 // parameters of the volume maker
70 aVolumeMaker->SetArguments(anArgs);
71 aVolumeMaker->SetIntersect(true); // split edges and faces
72 aVolumeMaker->SetAvoidInternalShapes(myAvoidInternal);
73 aVolumeMaker->SetGlue(BOPAlgo_GlueOff);
75 // building and getting result
76 aVolumeMaker->Perform();
77 if (aVolumeMaker->HasErrors())
79 TopoDS_Shape aResult = aVolumeMaker->Shape();
81 if(aResult.ShapeType() == TopAbs_COMPOUND) {
82 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
83 aGeomShape->setImpl(new TopoDS_Shape(aResult));
84 aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aGeomShape)->impl<TopoDS_Shape>();
88 if(aResult.IsNull()) {
91 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
92 aShape->setImpl(new TopoDS_Shape(aResult));
93 this->setShape(aShape);
97 //=================================================================================================
98 void GeomAlgoAPI_MakeVolume::modified(const GeomShapePtr theOldShape,
99 ListOfShape& theNewShapes)
101 if (theOldShape->shapeType() == GeomAPI_Shape::SOLID) {
102 ListOfShape aNewShapes;
103 // collect faces and parent shapes, if it is not done yet
104 if (!isNewShapesCollected(theOldShape, GeomAPI_Shape::FACE))
105 collectNewShapes(theOldShape, GeomAPI_Shape::FACE);
107 for (GeomAPI_ShapeExplorer anIt(shape(), GeomAPI_Shape::SOLID); anIt.more(); anIt.next()) {
108 for (GeomAPI_ShapeExplorer anExp(anIt.current(), GeomAPI_Shape::FACE);
109 anExp.more(); anExp.next()) {
110 GeomShapePtr anOldShapesCompound =
111 oldShapesForNew(theOldShape, anExp.current(), GeomAPI_Shape::FACE);
112 if (!anOldShapesCompound->isNull()) {
113 aNewShapes.push_back(anIt.current());
119 if (!aNewShapes.empty())
120 theNewShapes = aNewShapes;
123 GeomAlgoAPI_MakeShape::modified(theOldShape, theNewShapes);