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 "STEPPlugin_IOperations.hxx"
22 #include "STEPPlugin_ExportDriver.hxx"
23 #include "STEPPlugin_ImportDriver.hxx"
24 #include "STEPPlugin_IExport.hxx"
25 #include "STEPPlugin_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 STEPPlugin_IOperations::STEPPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
42 : GEOMImpl_IBaseIEOperations( theEngine, theDocID )
44 MESSAGE( "STEPPlugin_IOperations::STEPPlugin_IOperations" );
47 //=============================================================================
51 //=============================================================================
52 STEPPlugin_IOperations::~STEPPlugin_IOperations()
54 MESSAGE( "STEPPlugin_IOperations::~STEPPlugin_IOperations" );
57 //=============================================================================
60 * Export a shape to STEP format
61 * \param theOriginal The shape to export
62 * \param theFileName The name of the file to exported
63 * \param theIsASCII The format of the exported file (ASCII or Binary)
64 * \param theDeflection The deflection of the shape to exported
66 //=============================================================================
67 void STEPPlugin_IOperations::ExportSTEP( const Handle(GEOM_Object) theOriginal,
68 const TCollection_AsciiString& theFileName )
71 if( theOriginal.IsNull() ) return;
73 Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
74 if( aRefFunction.IsNull() ) return; //There is no function which creates an object to be exported
76 //Add a new result object
77 Handle(GEOM_Object) result = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT);
79 //Add an Export function
80 Handle(GEOM_Function) aFunction = result->AddFunction( STEPPlugin_ExportDriver::GetID(), EXPORT_SHAPE );
81 if( aFunction.IsNull() ) return;
83 //Check if the function is set correctly
84 if( aFunction->GetDriverGUID() != STEPPlugin_ExportDriver::GetID() ) return;
87 STEPPlugin_IExport aCI( aFunction );
88 aCI.SetOriginal( aRefFunction );
89 aCI.SetFileName( theFileName );
93 #if OCC_VERSION_LARGE > 0x06010000
96 if( !GetSolver()->ComputeFunction( aFunction ) ) {
97 SetErrorCode( "Not enough space on disk, or you haven't permissions to write this directory" );
101 catch( Standard_Failure ) {
102 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
103 SetErrorCode( aFail->GetMessageString() );
107 //Make a Python command
108 GEOM::TPythonDump(aFunction) << "geompy.ExportSTEP(" << theOriginal << ", \""
109 << theFileName.ToCString() << "\" )";
114 //=============================================================================
117 * Import a shape from STEP format
118 * \param theFileName The name of the file to import
119 * \return List of GEOM_Objects, containing the created shape and propagation groups.
121 //=============================================================================
122 Handle(TColStd_HSequenceOfTransient)
123 STEPPlugin_IOperations::ImportSTEP( const TCollection_AsciiString& theFileName,
124 const bool theIsIgnoreUnits )
127 if( theFileName.IsEmpty() ) return NULL;
129 //Add a new result object
130 Handle(GEOM_Object) anImported = GetEngine()->AddObject( GetDocID(), GEOM_IMPORT );
132 //Add an Import function
133 Handle(GEOM_Function) aFunction =
134 anImported->AddFunction( STEPPlugin_ImportDriver::GetID(), IMPORT_SHAPE);
135 if (aFunction.IsNull()) return NULL;
137 //Check if the function is set correctly
138 if (aFunction->GetDriverGUID() != STEPPlugin_ImportDriver::GetID()) return NULL;
141 STEPPlugin_IImport aCI( aFunction );
142 aCI.SetFileName( theFileName );
143 aCI.SetIsIgnoreUnits( theIsIgnoreUnits );
146 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
149 #if OCC_VERSION_LARGE > 0x06010000
152 if( !GetSolver()->ComputeFunction( aFunction ) ) {
153 SetErrorCode( "Import driver failed" );
156 aSeq->Append(anImported);
158 // Greate material groups.
159 MakeMaterialGroups( anImported, aSeq );
161 catch( Standard_Failure ) {
162 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
163 SetErrorCode( aFail->GetMessageString() );
167 //Make a Python command
168 GEOM::TPythonDump pd (aFunction);
169 if( theIsIgnoreUnits )
170 pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\", True)";
172 pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\")";
178 //=============================================================================
182 //=============================================================================
183 TCollection_AsciiString
184 STEPPlugin_IOperations::ReadValue( const TCollection_AsciiString& theFileName,
185 const TCollection_AsciiString& theParameterName )
189 TCollection_AsciiString aValue, anError;
191 if (theFileName.IsEmpty() || theParameterName.IsEmpty()) return aValue;
193 aValue = STEPPlugin_ImportDriver::GetValue( theFileName, theParameterName, anError );
195 if( aValue.IsEmpty() ) {
196 if( anError.IsEmpty() )
197 anError = theFileName + " doesn't contain requested parameter";
200 if (anError.IsEmpty())
203 SetErrorCode(anError.ToCString());