// Perform the export
std::string anError;
-
- TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
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;
}
// Perform the import
std::string anError;
- TopoDS_Shape aShape;
+ std::shared_ptr<GeomAPI_Shape> 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);
std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
data()->setName(anObjectName);
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
- std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
- aGeomShape->setImpl(new TopoDS_Shape(aShape));
//LoadNamingDS of the imported shape
loadNamingDS(aGeomShape, aResultBody);
#include "GeomAlgoAPI_Tools.h"
+#include <TopoDS_Shape.hxx>
+
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
//=============================================================================
bool BREPExport(const std::string& theFileName,
const std::string&,
- const TopoDS_Shape& theShape,
+ const std::shared_ptr<GeomAPI_Shape>& 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<TopoDS_Shape>(), theFileName.c_str())) {
theError = "BREP Export failed";
return false;
}
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape>& theShape,
std::string& theError);
#endif /* GEOMALGOAPI_BREPEXPORT_H_ */
#include <GeomAlgoAPI_BREPImport.h>
+#include <TopoDS_Shape.hxx>
+
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
*
*/
//=============================================================================
-TopoDS_Shape BREPImport(const std::string& theFileName,
- const std::string&,
- std::string& theError)
+std::shared_ptr<GeomAPI_Shape> BREPImport(const std::string& theFileName,
+ const std::string&,
+ std::string& theError)
{
#ifdef _DEBUG
std::cout << "Import BREP from file " << theFileName << std::endl;
if (aShape.IsNull()) {
theError = "BREP Import failed";
}
- return aShape;
+
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape(aShape));
+ return aGeomShape;
}
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape> BREPImport(const std::string& theFileName,
+ const std::string& theFormatName,
+ std::string& theError);
#endif /* GEOMALGOAPI_BREPIMPORT_H_ */
//=============================================================================
bool IGESExport(const std::string& theFileName,
const std::string& theFormatName,
- const TopoDS_Shape& theShape,
+ const std::shared_ptr<GeomAPI_Shape>& 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);
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<TopoDS_Shape>() );
if( aKind == -1 ) {
theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
return false;
Interface_Static::SetCVal( "write.precision.mode", "Max" );
// perform shape writing
- if( ICW.AddShape( theShape ) ) {
+ if( ICW.AddShape( theShape->impl<TopoDS_Shape>() ) ) {
ICW.ComputeModel();
return ICW.Write(theFileName.c_str());
}
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape>& theShape,
std::string& theError);
#endif /* GEOMALGOAPI_IGESEXPORT_H_ */
#include <GeomAlgoAPI_IGESImport.h>
+#include <TopoDS_Shape.hxx>
+
// OOCT includes
#include <IGESControl_Reader.hxx>
#include <IGESData_IGESModel.hxx>
*
*/
//=============================================================================
-TopoDS_Shape IGESImport(const std::string& theFileName,
- const std::string&,
- std::string& theError)
+std::shared_ptr<GeomAPI_Shape> 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() );
#ifdef _DEBUG
std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
#endif
- aResShape = aReader.OneShape();
+ aShape = aReader.OneShape();
}
else {
switch (status) {
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<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape(aShape));
+ return aGeomShape;
}
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape> IGESImport(const std::string& theFileName,
+ const std::string& theFormatName,
+ std::string& theError);
#endif /* GEOMALGOAPI_IGESIMPORT_H_ */
#include "GeomAlgoAPI_Tools.h"
+#include <TopoDS_Shape.hxx>
+
// OOCT includes
#include <IFSelect_ReturnStatus.hxx>
#include <STEPControl_Writer.hxx>
bool STEPExport(const std::string& theFileName,
const std::string& theFormatName,
- const TopoDS_Shape& theShape,
+ const std::shared_ptr<GeomAPI_Shape>& 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
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<TopoDS_Shape>(), 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 )
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape>& theShape,
std::string& theError);
#endif /* GEOMALGOAPI_STEPEXPORT_H_ */
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+
#include <TColStd_SequenceOfAsciiString.hxx>
return aValue;
}
-TopoDS_Shape STEPImport(const std::string& theFileName,
- const std::string& theFormatName,
- std::string& theError)
+std::shared_ptr<GeomAPI_Shape> STEPImport(const std::string& theFileName,
+ const std::string& theFormatName,
+ std::string& theError)
{
TopoDS_Shape aResShape;
Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
else {
theError = "The file contains not supported units.";
- return aResShape;
+ std::shared_ptr<GeomAPI_Shape> 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 == "")
if ( !TopExp_Explorer( aResShape, TopAbs_VERTEX ).More() )
{
theError = "No geometrical data in the imported file.";
- return TopoDS_Shape();
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape());
+ return aGeomShape;
}
} else {
theError = "Wrong format of the imported file. Can't import file.";
aResShape.Nullify();
}
// Return previous locale
- return aResShape;
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape(aResShape));
+ return aGeomShape;
}
#include <string>
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
/// 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<GeomAPI_Shape> STEPImport(const std::string& theFileName,
+ const std::string& theFormatName,
+ std::string& theError);
#endif /* GEOMALGOAPI_STEPIMPORT_H_ */