From: Jérôme Date: Fri, 23 Oct 2020 14:30:41 +0000 (+0200) Subject: Documentation and refactoring X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ec032f6e801f92f67997a162604219e13aaf6ffa;p=modules%2Fshaper.git Documentation and refactoring --- diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index d1266f3f7..5ee608e61 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) + double theDeflectionRelative, + 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())); } diff --git a/src/ExchangeAPI/ExchangeAPI_Export.h b/src/ExchangeAPI/ExchangeAPI_Export.h index fb6784f57..fb2703da5 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.h +++ b/src/ExchangeAPI/ExchangeAPI_Export.h @@ -146,12 +146,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, + double theDeflectionRelative, + 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/exportSTL.py b/src/ExchangePlugin/doc/examples/exportSTL.py new file mode 100644 index 000000000..01c1aa842 --- /dev/null +++ b/src/ExchangePlugin/doc/examples/exportSTL.py @@ -0,0 +1,11 @@ +from salome.shaper import model + +model.begin() +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, "/dn48/newgeom/vsv/test.stl", + [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..be71349ab 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 selectedShape: An exporting object + :param relative: value of the relative deflection + :param absolute: value of the absolute deflection + :param isRelative: indicate if use deflection relative + :param isASCII: 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..855af8430 Binary files /dev/null and b/src/ExchangePlugin/doc/images/ExportSTL.png differ 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;