1 // Copyright (C) 2014-2024 CEA, EDF
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_STLImport.h>
22 #include "GeomAlgoAPI_Tools.h"
24 #include <Basics_OCCTVersion.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <BRepBuilderAPI_MakeSolid.hxx>
30 #include <BRepBuilderAPI_Sewing.hxx>
31 #include <StlAPI_Reader.hxx>
33 std::shared_ptr<GeomAPI_Shape> STLImport(const std::string& theFileName,
34 std::string& theError)
36 TopoDS_Shape aResShape;
37 StlAPI_Reader aReader;
41 if(!aReader.Read(aResShape, theFileName.c_str()))
43 theError = "Can't import file.";
46 #if OCC_VERSION_LARGE >= 0x07070000
47 BRepBuilderAPI_Sewing aSewingTool;
48 aSewingTool.Init(1.0e-06, Standard_True);
49 aSewingTool.Load(aResShape);
50 aSewingTool.Perform();
51 TopoDS_Shape aSewedShape = aSewingTool.SewedShape();
52 if (!aSewedShape.IsNull())
53 aResShape = aSewedShape;
55 if(aResShape.ShapeType() == TopAbs_SHELL)
57 BRepBuilderAPI_MakeSolid soliMaker(TopoDS::Shell(aResShape));
59 if(soliMaker.IsDone())
60 aResShape = soliMaker.Shape();
63 catch (Standard_Failure const& anException) {
64 theError = anException.GetMessageString();
67 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
68 aGeomShape->setImpl(new TopoDS_Shape(aResShape));