From ce72dd01645885d720b731795d676e2feeabc8d6 Mon Sep 17 00:00:00 2001 From: cg246364 Date: Wed, 9 Dec 2020 10:22:42 +0100 Subject: [PATCH] Debug and documentation for STL export --- src/ExchangeAPI/ExchangeAPI_Export.cpp | 20 +++---- src/ExchangeAPI/ExchangeAPI_Export.h | 21 +++---- src/ExchangePlugin/doc/TUI_exportFeature.rst | 12 ++++ src/ExchangePlugin/doc/examples/export.py | 4 +- src/ExchangePlugin/doc/examples/exportSTL.py | 13 +++++ src/ExchangePlugin/doc/exportFeature.rst | 61 +++++++++++++++++++- src/ExchangePlugin/doc/images/ExportSTL.png | 0 src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp | 14 +++-- 8 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 src/ExchangePlugin/doc/examples/exportSTL.py create mode 100644 src/ExchangePlugin/doc/images/ExportSTL.png diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index d1266f3f7..b0d9e094c 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Export.cpp @@ -57,30 +57,30 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr& theFeature, const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape, - double aDeflectionRelative, - double aDeflectionAbsolute, - const bool anIsRelative, - const bool anIsASCII) + const ModelHighAPI_Double& theDeflectionRelative, + const ModelHighAPI_Double& theDeflectionAbsolute, + const bool theIsRelative, + const bool theIsASCII) : 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) { + if (theIsRelative) { fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(), theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) ); - fillAttribute(aDeflectionRelative, + fillAttribute(theDeflectionRelative, theFeature->real(ExchangePlugin_ExportFeature::STL_RELATIVE()) ); } else { fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(), theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) ); - fillAttribute(aDeflectionAbsolute, + fillAttribute(theDeflectionAbsolute, theFeature->real(ExchangePlugin_ExportFeature::STL_ABSOLUTE()) ); } - if(anIsASCII){ + if(theIsASCII){ fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_ASCII(), theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_TYPE())); } @@ -257,8 +257,8 @@ ExportPtr exportToXAO(const std::shared_ptr & thePart, ExportPtr exportToSTL(const std::shared_ptr & thePart, const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape, - double theDeflectionRelative, - double theDeflectionAbsolute, + const ModelHighAPI_Double& theDeflectionRelative, + const ModelHighAPI_Double& theDeflectionAbsolute, const bool theIsRelative, const bool theIsASCII) { diff --git a/src/ExchangeAPI/ExchangeAPI_Export.h b/src/ExchangeAPI/ExchangeAPI_Export.h index fb6784f57..0d5caa212 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.h +++ b/src/ExchangeAPI/ExchangeAPI_Export.h @@ -32,6 +32,7 @@ #include //-------------------------------------------------------------------------------------- class ModelHighAPI_Selection; +class ModelHighAPI_Double; //-------------------------------------------------------------------------------------- @@ -57,10 +58,10 @@ public: explicit ExchangeAPI_Export(const std::shared_ptr& theFeature, const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape, - double aDeflectionRelative , - double aDeflectionAbsolute, - const bool anIsRelative, - const bool anIsASCII); + const ModelHighAPI_Double& theDeflectionRelative , + const ModelHighAPI_Double& theDeflectionAbsolute, + const bool theIsRelative, + const bool theIsASCII); /// Constructor with values for XAO of selected result export. EXCHANGEAPI_EXPORT @@ -146,12 +147,12 @@ ExportPtr exportToXAO(const std::shared_ptr & thePart, */ EXCHANGEAPI_EXPORT ExportPtr exportToSTL(const std::shared_ptr & thePart, - const std::string & theFilePath, - const ModelHighAPI_Selection& theSelectedShape, - double aDeflectionRelative, - double aDeflectionAbsolute, - const bool anIsRelative, - const bool anIsASCII); + const std::string & theFilePath, + const ModelHighAPI_Selection& theSelectedShape, + const ModelHighAPI_Double& theDeflectionRelative, + const ModelHighAPI_Double& theDeflectionAbsolute, + const bool theIsRelative, + const bool theIsASCII); /**\ingroup CPPHighAPI * \brief Exports to XAO file the selected result with groups parts related to it only. diff --git a/src/ExchangePlugin/doc/TUI_exportFeature.rst b/src/ExchangePlugin/doc/TUI_exportFeature.rst index 49eecc5aa..4ef25d686 100644 --- a/src/ExchangePlugin/doc/TUI_exportFeature.rst +++ b/src/ExchangePlugin/doc/TUI_exportFeature.rst @@ -9,4 +9,16 @@ Export File :language: python :download:`Download this script ` + + .. _tui_export_file_STL: + +Export STL File +=============== + +.. literalinclude:: examples/exportSTL.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/ExchangePlugin/doc/examples/export.py b/src/ExchangePlugin/doc/examples/export.py index feb837252..1f9b7c2b5 100644 --- a/src/ExchangePlugin/doc/examples/export.py +++ b/src/ExchangePlugin/doc/examples/export.py @@ -1,11 +1,13 @@ from salome.shaper import model +import os model.begin() +file_path = os.path.join(os.getenv("DATA_DIR"), "test.step") partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() Box_1 = model.addBox(Part_1_doc, 10, 10, 10) -Export_1 = model.exportToFile(Part_1_doc, "/dn48/newgeom/vsv/test.step", +Export_1 = model.exportToFile(Part_1_doc, file_path, [model.selection("SOLID", "Box_1_1")]) model.do() model.end() diff --git a/src/ExchangePlugin/doc/examples/exportSTL.py b/src/ExchangePlugin/doc/examples/exportSTL.py new file mode 100644 index 000000000..a152c4a2e --- /dev/null +++ b/src/ExchangePlugin/doc/examples/exportSTL.py @@ -0,0 +1,13 @@ +from salome.shaper import model +import os + +model.begin() +file_path = os.path.join(os.getenv("DATA_DIR"), "test.stl") +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Export_1 = model.exportToSTL(Part_1_doc, file_path, + model.selection("SOLID", "Box_1_1"),0.0001,0.5,True,False) +model.do() +model.end() diff --git a/src/ExchangePlugin/doc/exportFeature.rst b/src/ExchangePlugin/doc/exportFeature.rst index e11ede6ad..5867d1bf5 100644 --- a/src/ExchangePlugin/doc/exportFeature.rst +++ b/src/ExchangePlugin/doc/exportFeature.rst @@ -69,9 +69,10 @@ The Result of operation is an exported file. Export to CAD format -------------------- -It is possible to export objects to files in the following CAD-neutral formats: BREP, STEP, IGES, XAO. +It is possible to export objects to files in the following CAD-neutral formats: BREP, STEP, IGES, XAO, STL. To export objects to a file select in the Main Menu *File -> Export -> To CAD formats...* item. + The following property panel will be opened: .. figure:: images/Export_panel.png @@ -79,15 +80,22 @@ The following property panel will be opened: **Export property panel** -In this panel, it is necessary to select desirable format of export file. It can be **'BREP, STEP, IGES'** or **'XAO'**. In case of first choice the format of exported file will be defined according to file extension. The file name and path can be defined in **Export file** field by direct input or browsing with **'...'** button, which opens **Export file** dialog box: +In this panel, it is necessary to select desirable format of export file. It can be **'BREP, STEP, IGES'** , **'XAO'** or **'STL'** . + + +Export to BREP, STEP, IGES +"""""""""""""""""""""""""" + +In case of first choice the format of exported file will be defined according to file extension. The file name and path can be defined in **Export file** field by direct input or browsing with **'...'** button, which opens **Export file** dialog box: .. figure:: images/ExportFileDlg.png :align: center - **Dialog box tp export in CAD-neutral format** + **Dialog box to export in CAD-neutral format** Selection list in the property panel contains a list of exported objects which can be selected in a viewer or object browser. + **Apply** button exports the file. **Cancel** button cancels the operation. @@ -115,3 +123,50 @@ Result The Result of operation is an exported file. **See Also** a sample TUI Script of :ref:`tui_export_file` operation. + +Result +"""""" + +The Result of operation is an exported file. + +**See Also** a sample TUI Script of :ref:`tui_export_file` operation. + +Export to STL +""""""""""""" +In this case, the following property panel will be opened: + +.. figure:: images/ExportSTL.png + :align: center + + **Dialog box to export in STL format** + + +The file name and path can be defined in **Export file** field by direct input or browsing with ‘…’ button, which opens Export file dialog box. + +**Object** field contains an exported object which can be selected in a viewer or object browser. + +**Deflection** (**Relative** or **Absolute**) has to be chosen and defined in the corresponding field as well as the **File type** which can defined as **Binary** or as **ASCII**. + + +**Apply** button exports the file. + +**Cancel** button cancels the operation. + +**TUI Command**: + +.. py:function:: model.exportToSTL(Part_doc, FileNameString, selectedShape, relative, absolute, isRelative, isASCII) + + :param part: The current part object + :param string: The file name + :param object: An exporting object + :param real: value of the relative deflection + :param real: value of the absolute deflection + :param boolean: indicate if use deflection relative + :param boolean: indicate if the file is in ASCII type + +Result +"""""" + +The Result of operation is an exported STL file. + +**See Also** a sample TUI Script of :ref:`tui_export_file_STL` operation. diff --git a/src/ExchangePlugin/doc/images/ExportSTL.png b/src/ExchangePlugin/doc/images/ExportSTL.png new file mode 100644 index 000000000..e69de29bb diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp index a11aa6565..48477c36a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp @@ -56,7 +56,7 @@ bool STLExport(const std::string& theFileName, try { - double lDeflection = theDeflection; + double aDeflection = theDeflection; StlAPI_Writer aWriter; // copy source shape BRepBuilderAPI_Copy aCopy( theShape->impl(), Standard_False ); @@ -65,13 +65,15 @@ bool STLExport(const std::string& theFileName, aWriter.ASCIIMode() = theIsASCII; if ( theIsRelative ) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - Bnd_Box bndBox; - BRepBndLib::Add( theShape->impl(), bndBox ); - bndBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax ); - lDeflection = MAX3( aXmax-aXmin, aYmax-aYmin, aZmax-aZmin ) * theDeflection; + Bnd_Box aBndBox; + BRepBndLib::Add( theShape->impl(), aBndBox ); + aBndBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax ); + aDeflection = MAX3( aXmax-aXmin, aYmax-aYmin, aZmax-aZmin ) * theDeflection; } //Compute triangulation - BRepMesh_IncrementalMesh aMesh( aCopyShape, lDeflection ); + BRepTools::Clean( aCopyShape ); + BRepMesh_IncrementalMesh aMesh( aCopyShape, aDeflection ); + if (!aWriter.Write( aCopyShape, theFileName.c_str())) { theError = "STL Export failed"; return false; -- 2.39.2