1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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
21 #include "STLPlugin_ImportDriver.hxx"
22 #include "STLPlugin_IImport.hxx"
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
29 #include "GEOM_Function.hxx"
30 #include "GEOMImpl_Types.hxx"
33 #include <StlAPI_Reader.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <BRep_Tool.hxx>
37 #include <BRep_Builder.hxx>
39 #include <Precision.hxx>
40 #include <BRepClass3d_SolidClassifier.hxx>
42 //=======================================================================
45 //=======================================================================
46 const Standard_GUID& STLPlugin_ImportDriver::GetID()
48 static Standard_GUID aGUID("69e33dc7-9630-4a73-ac19-cc4da1f659b8");
52 //=======================================================================
53 //function : STLPlugin_ImportDriver
55 //=======================================================================
56 STLPlugin_ImportDriver::STLPlugin_ImportDriver()
60 //=======================================================================
63 //=======================================================================
64 Standard_Integer STLPlugin_ImportDriver::Execute(Handle(TFunction_Logbook)& log) const
66 if( Label().IsNull() ) return 0;
67 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
69 STLPlugin_IImport aData( aFunction );
71 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
73 MESSAGE( "Import STL to file " << aFileName );
75 // Set "C" numeric locale to save numbers correctly
76 Kernel_Utils::Localizer loc;
78 StlAPI_Reader aReader;
81 aReader.Read( aShape, aData.GetFileName().ToCString() );
83 if( aShape.IsNull() ) return 0;
85 // Fix the orientation of closed shell or solid.
86 if( BRep_Tool::IsClosed( aShape ) ) {
87 TopAbs_ShapeEnum aType = aShape.ShapeType();
88 if( aType == TopAbs_SHELL || aType == TopAbs_SOLID ) {
90 if( aType == TopAbs_SHELL ) {
92 BRep_Builder aBuilder;
93 aBuilder.MakeSolid( aSolid );
94 aBuilder.Add(aSolid, aShape );
97 aSolid = TopoDS::Solid( aShape );
99 // Classify infinite point against solid.
100 BRepClass3d_SolidClassifier aClassifier( aSolid );
101 aClassifier.PerformInfinitePoint(Precision::Confusion());
103 if( aClassifier.State() == TopAbs_IN ) {
104 // The shape is inverted. Reverse it.
110 aFunction->SetValue( aShape );
112 log->SetTouched(Label());
117 //================================================================================
119 * \brief Returns a name of creation operation and names and values of creation parameters
121 //================================================================================
123 bool STLPlugin_ImportDriver::
124 GetCreationInformation( std::string& theOperationName,
125 std::vector<GEOM_Param>& theParams )
127 if( Label().IsNull() ) return 0;
128 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
130 STLPlugin_IImport aCI( function );
131 Standard_Integer aType = function->GetType();
133 theOperationName = "ImportSTL";
137 AddParam( theParams, "File name", aCI.GetFileName() );
145 IMPLEMENT_STANDARD_RTTIEXT( STLPlugin_ImportDriver, GEOM_BaseDriver );