1 // Copyright (C) 2014-2015 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 "DXFPlugin_IOperations.hxx"
22 #include "DXFPlugin_ExportDriver.hxx"
23 #include "DXFPlugin_ImportDriver.hxx"
24 #include "DXFPlugin_IExport.hxx"
25 #include "DXFPlugin_IImport.hxx"
28 #include <utilities.h>
31 #include <GEOM_PythonDump.hxx>
32 #include <GEOMImpl_Types.hxx>
34 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
36 //=============================================================================
40 //=============================================================================
41 DXFPlugin_IOperations::DXFPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
42 : GEOMImpl_IBaseIEOperations( theEngine, theDocID )
44 MESSAGE( "DXFPlugin_IOperations::DXFPlugin_IOperations" );
47 //=============================================================================
51 //=============================================================================
52 DXFPlugin_IOperations::~DXFPlugin_IOperations()
54 MESSAGE( "DXFPlugin_IOperations::~DXFPlugin_IOperations" );
57 //=============================================================================
60 * Export a shape to DXF format
61 * \param theOriginal The shape to export
62 * \param theFileName The name of the file to exported
64 //=============================================================================
65 void DXFPlugin_IOperations::ExportDXF( const Handle(GEOM_Object) theOriginal,
66 const TCollection_AsciiString& theFileName )
69 if( theOriginal.IsNull() ) return;
71 Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
72 if( aRefFunction.IsNull() ) return; //There is no function which creates an object to be exported
74 //Add a new result object
75 Handle(GEOM_Object) result = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT);
77 //Add an Export function
78 Handle(GEOM_Function) aFunction = result->AddFunction( DXFPlugin_ExportDriver::GetID(), EXPORT_SHAPE );
79 if( aFunction.IsNull() ) return;
81 //Check if the function is set correctly
82 if( aFunction->GetDriverGUID() != DXFPlugin_ExportDriver::GetID() ) return;
85 DXFPlugin_IExport aCI( aFunction );
86 aCI.SetOriginal( aRefFunction );
87 aCI.SetFileName( theFileName );
92 if( !GetSolver()->ComputeFunction( aFunction ) ) {
93 SetErrorCode( "Not enough space on disk, or you haven't permissions to write this directory" );
97 catch( Standard_Failure ) {
98 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
99 SetErrorCode( aFail->GetMessageString() );
103 //Make a Python command
104 GEOM::TPythonDump(aFunction) << "geompy.ExportDXF(" << theOriginal << ", \""
105 << theFileName.ToCString() << "\" )";
110 //=============================================================================
113 * Import a shape from DXF format
114 * \param theFileName The name of the file to import
115 * \return List of GEOM_Objects, containing the created shape and propagation groups.
117 //=============================================================================
118 Handle(TColStd_HSequenceOfTransient)
119 DXFPlugin_IOperations::ImportDXF( const TCollection_AsciiString& theFileName )
122 if( theFileName.IsEmpty() ) return NULL;
124 //Add a new result object
125 Handle(GEOM_Object) anImported = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT );
127 //Add an Import function
128 Handle(GEOM_Function) aFunction =
129 anImported->AddFunction( DXFPlugin_ImportDriver::GetID(), IMPORT_SHAPE);
130 if (aFunction.IsNull()) return NULL;
132 //Check if the function is set correctly
133 if (aFunction->GetDriverGUID() != DXFPlugin_ImportDriver::GetID()) return NULL;
136 DXFPlugin_IImport aCI( aFunction );
137 aCI.SetFileName( theFileName );
140 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
144 if( !GetSolver()->ComputeFunction( aFunction ) ) {
145 SetErrorCode( "Import driver failed" );
148 aSeq->Append(anImported);
150 // Greate material groups.
151 //MakeMaterialGroups( anImported, aSeq );
153 catch( Standard_Failure ) {
154 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
155 SetErrorCode( aFail->GetMessageString() );
159 //Make a Python command
160 GEOM::TPythonDump pd (aFunction);
161 pd << aSeq << " = geompy.ImportDXF(\"" << theFileName.ToCString() << "\" )";