1 // Copyright (C) 2014-2019 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 "VTKPlugin_IOperations.hxx"
22 #include "VTKPlugin_ExportDriver.hxx"
23 #include "VTKPlugin_IExport.hxx"
26 #include <Basics_DirUtils.hxx>
27 #include <utilities.h>
30 #include "GEOM_PythonDump.hxx"
31 #include "GEOMImpl_Types.hxx"
33 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
35 //=============================================================================
39 //=============================================================================
40 VTKPlugin_IOperations::VTKPlugin_IOperations( GEOM_Engine* theEngine )
41 : GEOMImpl_IBaseIEOperations( theEngine )
43 MESSAGE( "VTKPlugin_IOperations::VTKPlugin_IOperations" );
46 //=============================================================================
50 //=============================================================================
51 VTKPlugin_IOperations::~VTKPlugin_IOperations()
53 MESSAGE( "VTKPlugin_IOperations::~VTKPlugin_IOperations" );
56 //=============================================================================
59 * Export a shape to VTK format
60 * \param theOriginal The shape to export
61 * \param theFileName The name of the file to exported
62 * \param theDeflection The deflection of the shape to exported
64 //=============================================================================
65 void VTKPlugin_IOperations::ExportVTK( const Handle(GEOM_Object) theOriginal,
66 const TCollection_AsciiString& theFileName,
67 const double theDeflection )
70 if( theOriginal.IsNull() ) return;
72 Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
73 if( aRefFunction.IsNull() ) return; //There is no function which creates an object to be exported
75 //Add a new result object
76 Handle(GEOM_Object) result = GetEngine()->AddObject( GEOM_IMPORT);
78 //Add an Export function
79 Handle(GEOM_Function) aFunction = result->AddFunction( VTKPlugin_ExportDriver::GetID(), EXPORT_SHAPE );
80 if( aFunction.IsNull() ) return;
82 //Check if the function is set correctly
83 if( aFunction->GetDriverGUID() != VTKPlugin_ExportDriver::GetID() ) return;
86 VTKPlugin_IExport aCI( aFunction );
87 aCI.SetOriginal( aRefFunction );
88 aCI.SetFileName( theFileName );
89 aCI.SetDeflection( theDeflection );
94 if( !GetSolver()->ComputeFunction( aFunction ) ) {
95 SetErrorCode( "Not enough space on disk, or you haven't permissions to write this directory" );
99 catch( Standard_Failure& aFail ) {
100 SetErrorCode( aFail.GetMessageString() );
104 //Make a Python command
105 std::string convFileName = Kernel_Utils::BackSlashToSlash(theFileName.ToCString());
106 GEOM::TPythonDump(aFunction) << "geompy.ExportVTK(" << theOriginal << ", \""
107 << convFileName.c_str() << "\", " << theDeflection << ")";