1 // Copyright (C) 2014 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 "XTPlugin_IOperations.hxx"
22 #include "XTPlugin_ImportDriver.hxx"
23 #include "XTPlugin_IImport.hxx"
26 #include <utilities.h>
29 #include <GEOM_PythonDump.hxx>
30 #include <GEOMImpl_Types.hxx>
32 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
34 //=============================================================================
38 //=============================================================================
39 XTPlugin_IOperations::XTPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
40 : GEOMImpl_IBaseIEOperations( theEngine, theDocID )
42 MESSAGE( "XTPlugin_IOperations::XTPlugin_IOperations" );
45 //=============================================================================
49 //=============================================================================
50 XTPlugin_IOperations::~XTPlugin_IOperations()
52 MESSAGE( "XTPlugin_IOperations::~XTPlugin_IOperations" );
55 //=============================================================================
58 * Import a shape from XT format
59 * \param theFileName The name of the file to import
60 * \return List of GEOM_Objects, containing the created shape and propagation groups.
62 //=============================================================================
63 Handle(TColStd_HSequenceOfTransient)
64 XTPlugin_IOperations::ImportXT( const TCollection_AsciiString& theFileName )
67 if( theFileName.IsEmpty() ) return NULL;
69 //Add a new result object
70 Handle(GEOM_Object) anImported = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT );
72 //Add an Import function
73 Handle(GEOM_Function) aFunction =
74 anImported->AddFunction( XTPlugin_ImportDriver::GetID(), IMPORT_SHAPE);
75 if (aFunction.IsNull()) return NULL;
77 //Check if the function is set correctly
78 if (aFunction->GetDriverGUID() != XTPlugin_ImportDriver::GetID()) return NULL;
81 XTPlugin_IImport aCI( aFunction );
82 aCI.SetFileName( theFileName );
85 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
89 if( !GetSolver()->ComputeFunction( aFunction ) ) {
90 SetErrorCode( "Import driver failed" );
93 aSeq->Append(anImported);
95 // Greate material groups.
96 //MakeMaterialGroups( anImported, aSeq );
98 catch( Standard_Failure ) {
99 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
100 SetErrorCode( aFail->GetMessageString() );
104 //Make a Python command
105 GEOM::TPythonDump pd (aFunction);
106 pd << aSeq << " = geompy.ImportXT(\"" << theFileName.ToCString() << "\" )";