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 <GeomAlgoAPI_ShapeTools.h>
25 #include <BOPAlgo_MakerVolume.hxx>
27 //=================================================================================================
28 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeVolume::make(const ListOfShape& theFaces)
30 GeomAlgoAPI_MakeVolume aMkVolAlgo(theFaces, false);
32 if(aMkVolAlgo.isDone() && !aMkVolAlgo.shape()->isNull() && aMkVolAlgo.isValid())
33 aResult = aMkVolAlgo.shape();
37 //=================================================================================================
38 GeomAlgoAPI_MakeVolume::GeomAlgoAPI_MakeVolume(
39 const ListOfShape& theFaces, const bool theAvoidInternal)
41 myAvoidInternal = theAvoidInternal;
45 static void convertToTopoDS(const ListOfShape& theShapes, TopTools_ListOfShape& theTopoDSShapes)
47 for (ListOfShape::const_iterator anIt = theShapes.begin(); anIt != theShapes.end(); ++anIt)
48 theTopoDSShapes.Append((*anIt)->impl<TopoDS_Shape>());
51 //=================================================================================================
52 void GeomAlgoAPI_MakeVolume::build(const ListOfShape& theFaces)
54 if (theFaces.empty()) {
58 // create make volume opration
59 BOPAlgo_MakerVolume* aVolumeMaker = new BOPAlgo_MakerVolume;
60 this->setImpl(aVolumeMaker);
61 this->setBuilderType(OCCT_BOPAlgo_Builder);
64 TopTools_ListOfShape anArgs;
65 convertToTopoDS(theFaces, anArgs);
67 // parameters of the volume maker
68 aVolumeMaker->SetArguments(anArgs);
69 aVolumeMaker->SetIntersect(true); // split edges and faces
70 aVolumeMaker->SetAvoidInternalShapes(myAvoidInternal);
71 aVolumeMaker->SetGlue(BOPAlgo_GlueOff);
73 // building and getting result
74 aVolumeMaker->Perform();
75 if (aVolumeMaker->HasErrors())
77 TopoDS_Shape aResult = aVolumeMaker->Shape();
79 if(aResult.ShapeType() == TopAbs_COMPOUND) {
80 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
81 aGeomShape->setImpl(new TopoDS_Shape(aResult));
82 aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aGeomShape)->impl<TopoDS_Shape>();
86 if(aResult.IsNull()) {
89 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
90 aShape->setImpl(new TopoDS_Shape(aResult));
91 this->setShape(aShape);