From bb33252ddc3c0792f81b7f9139a8395f4ffcc1c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Fri, 9 Oct 2020 14:12:38 +0200 Subject: [PATCH] Fix bugs --- src/ExchangeAPI/CMakeLists.txt | 2 + src/ExchangeAPI/ExchangeAPI_Export.cpp | 28 ++++++----- src/ExchangeAPI/ExchangeAPI_Export.h | 48 ++++++++++--------- src/ExchangePlugin/CMakeLists.txt | 1 + .../ExchangePlugin_ExportFeature.cpp | 2 +- src/ExchangePlugin/export_widget.xml | 2 +- src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp | 6 ++- src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h | 2 +- 8 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/ExchangeAPI/CMakeLists.txt b/src/ExchangeAPI/CMakeLists.txt index bdf5bcb34..b61f22ce9 100644 --- a/src/ExchangeAPI/CMakeLists.txt +++ b/src/ExchangeAPI/CMakeLists.txt @@ -33,12 +33,14 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES ModelAPI ModelHighAPI + GeomAlgoAPI ) INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/ModelHighAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ) # Plugin headers dependency diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index ba11e3920..d1266f3f7 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Export.cpp @@ -59,38 +59,39 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& const ModelHighAPI_Selection& theSelectedShape, double aDeflectionRelative, double aDeflectionAbsolute, - const bool anIsRelative, + const bool anIsRelative, const bool anIsASCII) : ModelHighAPI_Interface(theFeature) { initialize(); fillAttribute("STL", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())); fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())); - + if (anIsRelative) { - fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(), + fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(), theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) ); - fillAttribute(aDeflectionRelative, - theFeature->real(ExchangePlugin_ExportFeature::STL_RELATIVE()) ); + fillAttribute(aDeflectionRelative, + theFeature->real(ExchangePlugin_ExportFeature::STL_RELATIVE()) ); } else { - fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(), + fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(), theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) ); - fillAttribute(aDeflectionAbsolute, + fillAttribute(aDeflectionAbsolute, theFeature->real(ExchangePlugin_ExportFeature::STL_ABSOLUTE()) ); } if(anIsASCII){ - fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_ASCII(), + fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_ASCII(), theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_TYPE())); } else { - fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_BINARY(), + fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_BINARY(), theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_TYPE())); } - - fillAttribute(theSelectedShape,theFeature->selection(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED())); + + fillAttribute(theSelectedShape, + theFeature->selection(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED())); fillAttribute("STL", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())); execute(); apply(); // finish operation to make sure the export is done on the current state of the history @@ -202,7 +203,8 @@ void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const theDumper <<","<< stlabsolute() <<","<< stlrelative(); - if (stldeflectionType()->value() == ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE()) { + if (stldeflectionType()->value() + == ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE()){ theDumper <<","<< "True"; } else { @@ -270,7 +272,7 @@ ExportPtr exportToSTL(const std::shared_ptr & thePart, theDeflectionRelative, theDeflectionAbsolute, theIsRelative, - theIsASCII)); + theIsASCII)); } ExportPtr exportToXAO(const std::shared_ptr & thePart, diff --git a/src/ExchangeAPI/ExchangeAPI_Export.h b/src/ExchangeAPI/ExchangeAPI_Export.h index 89f360a07..fb6784f57 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.h +++ b/src/ExchangeAPI/ExchangeAPI_Export.h @@ -51,24 +51,24 @@ public: const std::string & theFilePath, const std::string & theAuthor = std::string(), const std::string & theGeometryName = std::string()); - + /// Constructor with values for STL of selected result export. EXCHANGEAPI_EXPORT explicit ExchangeAPI_Export(const std::shared_ptr& theFeature, const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape, - double theDeflectionRelative , - double theDeflectionAbsolute, - const bool theIsRelative, - const bool theIsASCII); + double aDeflectionRelative , + double aDeflectionAbsolute, + const bool anIsRelative, + const bool anIsASCII); /// Constructor with values for XAO of selected result export. EXCHANGEAPI_EXPORT explicit ExchangeAPI_Export(const std::shared_ptr& theFeature, - const std::string & theFilePath, - const ModelHighAPI_Selection& theResult, - const std::string & theAuthor, - const std::string & theGeometryName = std::string()); + const std::string & theFilePath, + const ModelHighAPI_Selection& theResult, + const std::string & theAuthor, + const std::string & theGeometryName = std::string()); /// Constructor with values for export in other formats than XAO. EXCHANGEAPI_EXPORT @@ -108,9 +108,11 @@ public: ModelAPI_AttributeDouble, /** Absolute */, stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(), ModelAPI_AttributeString, /** Type of the stl file*/, - stldeflectionTypeabsolute, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(), + stldeflectionTypeabsolute, + ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(), ModelAPI_AttributeString, /** Type of the defelection */, - stldeflectionTyperelative, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(), + stldeflectionTyperelative, + ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(), ModelAPI_AttributeString, /** Type of the defelection */) /// Dump wrapped feature @@ -126,30 +128,30 @@ typedef std::shared_ptr ExportPtr; */ EXCHANGEAPI_EXPORT ExportPtr exportToFile(const std::shared_ptr & thePart, - const std::string & theFilePath, - const std::list & theSelectionList, - const std::string & theFileFormat = std::string()); + const std::string & theFilePath, + const std::list & theSelectionList, + const std::string & theFileFormat = std::string()); /**\ingroup CPPHighAPI * \brief Exports to XAO file all results of the current document */ EXCHANGEAPI_EXPORT ExportPtr exportToXAO(const std::shared_ptr & thePart, - const std::string & theFilePath, - const std::string & theAuthor = std::string(), - const std::string & theGeometryName = std::string()); + const std::string & theFilePath, + const std::string & theAuthor = std::string(), + const std::string & theGeometryName = std::string()); /**\ingroup CPPHighAPI * \brief Exports to STL file the result of the current document */ EXCHANGEAPI_EXPORT ExportPtr exportToSTL(const std::shared_ptr & thePart, - const std::string & theFilePath, - const ModelHighAPI_Selection& theSelectedShape, - double theDeflectionRelative, - double theDeflectionAbsolute, - const bool theIsRelative, - const bool theIsASCII); + const std::string & theFilePath, + const ModelHighAPI_Selection& theSelectedShape, + double aDeflectionRelative, + double aDeflectionAbsolute, + const bool anIsRelative, + const bool anIsASCII); /**\ingroup CPPHighAPI * \brief Exports to XAO file the selected result with groups parts related to it only. diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 67880c8e6..3df98bece 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -31,6 +31,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/XAO ${PROJECT_SOURCE_DIR}/src/ConstructionPlugin ${PROJECT_SOURCE_DIR}/src/PartSetPlugin + ${OpenCASCADE_INCLUDE_DIR} ) SET(PROJECT_HEADERS diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 0205960b1..e81ae860d 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -109,7 +109,7 @@ void ExchangePlugin_ExportFeature::initAttributes() ModelAPI_AttributeString::typeId()); data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(), ModelAPI_AttributeDouble::typeId()); - + double defelection = Config_PropManager::real("Visualization", "body_deflection"); real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection); diff --git a/src/ExchangePlugin/export_widget.xml b/src/ExchangePlugin/export_widget.xml index d0fcd3967..83b9aba4d 100644 --- a/src/ExchangePlugin/export_widget.xml +++ b/src/ExchangePlugin/export_widget.xml @@ -52,7 +52,7 @@ tooltip="Calculate by size of shape"> diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp index bf30792b2..a11aa6565 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp @@ -72,8 +72,10 @@ bool STLExport(const std::string& theFileName, } //Compute triangulation BRepMesh_IncrementalMesh aMesh( aCopyShape, lDeflection ); - aWriter.Write( aCopyShape, theFileName.c_str() ); - + if (!aWriter.Write( aCopyShape, theFileName.c_str())) { + theError = "STL Export failed"; + return false; + } return true; } catch( Standard_Failure ) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h index a08549e06..7c36584b1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h @@ -31,7 +31,7 @@ GEOMALGOAPI_EXPORT bool STLExport(const std::string& theFileName, const std::shared_ptr& theShape, const double theDeflection, - const bool theIsRelative, + const bool theIsRelative, const bool theIsASCII, std::string& theError); -- 2.39.2