From: spo Date: Tue, 30 Jun 2015 08:48:49 +0000 (+0300) Subject: Issue #608: Usage of OCCT in interface -- Remove OCCT from *Export/Import interfaces... X-Git-Tag: V_1.3.0~153 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=caa4d861f0489d16238a3229795dd8216f08069e;p=modules%2Fshaper.git Issue #608: Usage of OCCT in interface -- Remove OCCT from *Export/Import interfaces -- Eliminate TopoDS_Shape from interfaces --- diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index f4e87b76e..882a14a00 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -116,15 +116,13 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName, // Perform the export std::string anError; - - TopoDS_Shape aShape(theShape->impl()); bool aResult = false; if (aFormatName == "BREP") { - aResult = BREPExport(theFileName, aFormatName, aShape, anError); + aResult = BREPExport(theFileName, aFormatName, theShape, anError); } else if (aFormatName == "STEP") { - aResult = STEPExport(theFileName, aFormatName, aShape, anError); + aResult = STEPExport(theFileName, aFormatName, theShape, anError); } else if (aFormatName.substr(0, 4) == "IGES") { - aResult = IGESExport(theFileName, aFormatName, aShape, anError); + aResult = IGESExport(theFileName, aFormatName, theShape, anError); } else { anError = "Unsupported format " + aFormatName; } diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index adc678657..bcf06561e 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -79,16 +79,16 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) // Perform the import std::string anError; - TopoDS_Shape aShape; + std::shared_ptr aGeomShape; if (anExtension == "BREP" || anExtension == "BRP") { - aShape = BREPImport(theFileName, anExtension, anError); + aGeomShape = BREPImport(theFileName, anExtension, anError); } else if (anExtension == "STEP" || anExtension == "STP") { - aShape = STEPImport(theFileName, anExtension, anError); + aGeomShape = STEPImport(theFileName, anExtension, anError); } else if (anExtension == "IGES" || anExtension == "IGS") { - aShape = IGESImport(theFileName, anExtension, anError); + aGeomShape = IGESImport(theFileName, anExtension, anError); } // Check if shape is valid - if ( aShape.IsNull() ) { + if ( aGeomShape->isNull() ) { const static std::string aShapeError = "An error occurred while importing " + theFileName + ": " + anError; setError(aShapeError); @@ -99,8 +99,6 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); data()->setName(anObjectName); std::shared_ptr aResultBody = document()->createBody(data()); - std::shared_ptr aGeomShape(new GeomAPI_Shape); - aGeomShape->setImpl(new TopoDS_Shape(aShape)); //LoadNamingDS of the imported shape loadNamingDS(aGeomShape, aResultBody); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp index d85ae6b4f..a9c4fffd2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp @@ -8,6 +8,8 @@ #include "GeomAlgoAPI_Tools.h" +#include + #include #include @@ -18,17 +20,22 @@ //============================================================================= bool BREPExport(const std::string& theFileName, const std::string&, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError) { #ifdef _DEBUG std::cout << "Export BREP into file " << theFileName << std::endl; #endif + if (!theShape.get()) { + theError = "BREP Export failed: An invalid argument"; + return false; + } + // Set "C" numeric locale to save numbers correctly GeomAlgoAPI_Tools::Localizer loc; - if (!BRepTools::Write(theShape, theFileName.c_str())) { + if (!BRepTools::Write(theShape->impl(), theFileName.c_str())) { theError = "BREP Export failed"; return false; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h index de545479e..79f3d99b6 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h @@ -11,13 +11,13 @@ #include -#include +#include /// Implementation of the export BREP files algorithms GEOMALGOAPI_EXPORT bool BREPExport(const std::string& theFileName, const std::string& theFormatName, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError); #endif /* GEOMALGOAPI_BREPEXPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp index 4dc8769bd..e067acc9e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp @@ -6,6 +6,8 @@ #include +#include + #include #include @@ -14,9 +16,9 @@ * */ //============================================================================= -TopoDS_Shape BREPImport(const std::string& theFileName, - const std::string&, - std::string& theError) +std::shared_ptr BREPImport(const std::string& theFileName, + const std::string&, + std::string& theError) { #ifdef _DEBUG std::cout << "Import BREP from file " << theFileName << std::endl; @@ -27,5 +29,8 @@ TopoDS_Shape BREPImport(const std::string& theFileName, if (aShape.IsNull()) { theError = "BREP Import failed"; } - return aShape; + + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); + return aGeomShape; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h index 18ac9ffd7..a8a5c582f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h @@ -11,12 +11,12 @@ #include -#include +#include /// Implementation of the import BREP files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape BREPImport(const std::string& theFileName, - const std::string& theFormatName, - std::string& theError); +std::shared_ptr BREPImport(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); #endif /* GEOMALGOAPI_BREPIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp index 0479b0a4f..b91780545 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp @@ -80,9 +80,18 @@ int KindOfBRep (const TopoDS_Shape& theShape) //============================================================================= bool IGESExport(const std::string& theFileName, const std::string& theFormatName, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError) { + #ifdef _DEBUG + std::cout << "Export IGES into file " << theFileName << std::endl; + #endif + + if (!theShape.get()) { + theError = "IGES Export failed: An invalid argument"; + return false; + } + // theFormatName expected "IGES-5.1", "IGES-5.3"... TCollection_AsciiString aFormatName(theFormatName.c_str()); TCollection_AsciiString aVersion = aFormatName.Token("-", 2); @@ -97,14 +106,10 @@ bool IGESExport(const std::string& theFileName, if( aVersion.IsEqual( "5.3" ) ) aBrepMode = 1; - #ifdef _DEBUG - std::cout << "Export IGES into file " << theFileName << std::endl; - #endif - // Mantis issue 0021350: check being exported shape, as some stand-alone // entities (edges, wires and vertices) cannot be saved in BRepMode if( aBrepMode == 1 ) { - int aKind = KindOfBRep( theShape ); + int aKind = KindOfBRep( theShape->impl() ); if( aKind == -1 ) { theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND"; return false; @@ -127,7 +132,7 @@ bool IGESExport(const std::string& theFileName, Interface_Static::SetCVal( "write.precision.mode", "Max" ); // perform shape writing - if( ICW.AddShape( theShape ) ) { + if( ICW.AddShape( theShape->impl() ) ) { ICW.ComputeModel(); return ICW.Write(theFileName.c_str()); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h index f70172342..62781d9ea 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h @@ -11,13 +11,13 @@ #include -#include +#include /// Implementation of the export IGES files algorithms GEOMALGOAPI_EXPORT bool IGESExport(const std::string& theFileName, const std::string& theFormatName, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError); #endif /* GEOMALGOAPI_IGESEXPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp index 910be52e8..79830e43f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp @@ -6,6 +6,8 @@ #include +#include + // OOCT includes #include #include @@ -15,14 +17,14 @@ * */ //============================================================================= -TopoDS_Shape IGESImport(const std::string& theFileName, - const std::string&, - std::string& theError) +std::shared_ptr IGESImport(const std::string& theFileName, + const std::string&, + std::string& theError) { #ifdef _DEBUG std::cout << "Import IGES from file " << theFileName << std::endl; #endif - TopoDS_Shape aResShape; + TopoDS_Shape aShape; IGESControl_Reader aReader; try { IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.c_str() ); @@ -37,7 +39,7 @@ TopoDS_Shape IGESImport(const std::string& theFileName, #ifdef _DEBUG std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl; #endif - aResShape = aReader.OneShape(); + aShape = aReader.OneShape(); } else { switch (status) { @@ -57,14 +59,16 @@ TopoDS_Shape IGESImport(const std::string& theFileName, theError = "Wrong format of the imported file. Can't import file."; break; } - aResShape.Nullify(); + aShape.Nullify(); } } catch( Standard_Failure ) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); theError = aFail->GetMessageString(); - aResShape.Nullify(); + aShape.Nullify(); } - return aResShape; + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); + return aGeomShape; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h index b7a63865d..37ab90aa7 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h @@ -11,12 +11,12 @@ #include -#include +#include /// Implementation of the import IGES files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape IGESImport(const std::string& theFileName, - const std::string& theFormatName, - std::string& theError); +std::shared_ptr IGESImport(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); #endif /* GEOMALGOAPI_IGESIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp index fbf7f718b..c9e9830c1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp @@ -8,6 +8,8 @@ #include "GeomAlgoAPI_Tools.h" +#include + // OOCT includes #include #include @@ -15,13 +17,18 @@ bool STEPExport(const std::string& theFileName, const std::string& theFormatName, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError) { #ifdef _DEBUG std::cout << "Export STEP into file " << theFileName << std::endl; #endif + if (!theShape.get()) { + theError = "STEP Export failed: An invalid argument"; + return false; + } + try { // Set "C" numeric locale to save numbers correctly @@ -33,10 +40,10 @@ bool STEPExport(const std::string& theFileName, Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetCVal("write.step.unit", "M"); Interface_Static::SetIVal("write.step.nonmanifold", 1); - status = aWriter.Transfer( theShape, STEPControl_AsIs ); + status = aWriter.Transfer(theShape->impl(), STEPControl_AsIs); //VRV: OCC 4.0 migration if( status == IFSelect_RetDone ) - status = aWriter.Write( theFileName.c_str() ); + status = aWriter.Write(theFileName.c_str()); // Return previous locale if( status == IFSelect_RetDone ) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h index 2011617af..5376a050b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h @@ -11,13 +11,13 @@ #include -#include +#include /// Implementation of the export STEP files algorithms GEOMALGOAPI_EXPORT bool STEPExport(const std::string& theFileName, const std::string& theFormatName, - const TopoDS_Shape& theShape, + const std::shared_ptr& theShape, std::string& theError); #endif /* GEOMALGOAPI_STEPEXPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 432cd1d59..6c251b429 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -41,6 +41,8 @@ #include #include #include +#include + #include @@ -367,9 +369,9 @@ Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFil return aValue; } -TopoDS_Shape STEPImport(const std::string& theFileName, - const std::string& theFormatName, - std::string& theError) +std::shared_ptr STEPImport(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError) { TopoDS_Shape aResShape; @@ -413,7 +415,9 @@ TopoDS_Shape STEPImport(const std::string& theFileName, Interface_Static::SetCVal("xstep.cascade.unit", "INCH"); else { theError = "The file contains not supported units."; - return aResShape; + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aResShape)); + return aGeomShape; } // TODO (for other units than mm, cm, m or inch) //else if (aLenUnits == "") @@ -482,7 +486,9 @@ TopoDS_Shape STEPImport(const std::string& theFileName, if ( !TopExp_Explorer( aResShape, TopAbs_VERTEX ).More() ) { theError = "No geometrical data in the imported file."; - return TopoDS_Shape(); + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape()); + return aGeomShape; } } else { theError = "Wrong format of the imported file. Can't import file."; @@ -495,5 +501,7 @@ TopoDS_Shape STEPImport(const std::string& theFileName, aResShape.Nullify(); } // Return previous locale - return aResShape; + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aResShape)); + return aGeomShape; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h index 0a5060798..b206962cb 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h @@ -12,12 +12,12 @@ #include -#include +#include /// Implementation of the import STEP files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape STEPImport(const std::string& theFileName, - const std::string& theFormatName, - std::string& theError); +std::shared_ptr STEPImport(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); #endif /* GEOMALGOAPI_STEPIMPORT_H_ */