]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Debug and documentation for STL export
authorcg246364 <clarisse.genrault@cea.fr>
Wed, 9 Dec 2020 09:22:42 +0000 (10:22 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Wed, 9 Dec 2020 09:22:42 +0000 (10:22 +0100)
src/ExchangeAPI/ExchangeAPI_Export.cpp
src/ExchangeAPI/ExchangeAPI_Export.h
src/ExchangePlugin/doc/TUI_exportFeature.rst
src/ExchangePlugin/doc/examples/export.py
src/ExchangePlugin/doc/examples/exportSTL.py [new file with mode: 0644]
src/ExchangePlugin/doc/exportFeature.rst
src/ExchangePlugin/doc/images/ExportSTL.png [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp

index d1266f3f71c76ee2b79a87140b77bc1c9724fd2c..b0d9e094ce4f2010c64ab761a6fd9a220d4afc2d 100644 (file)
@@ -57,30 +57,30 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Document> & thePart,
 ExportPtr exportToSTL(const std::shared_ptr<ModelAPI_Document> & 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)
 {
index fb6784f57938ba3ff413813d88a993c5e404d350..0d5caa212c68aa51d282f948718f7d68cf18ee0e 100644 (file)
@@ -32,6 +32,7 @@
 #include <ExchangePlugin_ExportFeature.h>
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Selection;
+class ModelHighAPI_Double;
 //--------------------------------------------------------------------------------------
 
 
@@ -57,10 +58,10 @@ public:
     explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Document> & thePart,
  */
 EXCHANGEAPI_EXPORT
 ExportPtr exportToSTL(const std::shared_ptr<ModelAPI_Document> & 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.
index 49eecc5aadb406042af9c630970e8db52d7b3414..4ef25d686a06749ec653fc48cdbb1498739bdbda 100644 (file)
@@ -9,4 +9,16 @@ Export File
     :language: python
 
 :download:`Download this script <examples/export.py>` 
+
+  .. _tui_export_file_STL:
+
+Export STL File
+===============
+
+.. literalinclude:: examples/exportSTL.py
+    :linenos:
+    :language: python
+
+:download:`Download this script <examples/exportSTL.py>` 
    
+
index feb8372520bab434f1c222b8aa1bffa0f9c04648..1f9b7c2b5e125854519004e7cb67e49a3c5f198e 100644 (file)
@@ -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 (file)
index 0000000..a152c4a
--- /dev/null
@@ -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()
index e11ede6ada3a7b4d7603b69ef04584ee70161572..5867d1bf5081ca6d543f88349660022aa6c7fa82 100644 (file)
@@ -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 (file)
index 0000000..e69de29
index a11aa6565795f9bf2e52aec8eba559da10606d78..48477c36a18386ad1d897a8fdef042974cb6f23b 100644 (file)
@@ -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<TopoDS_Shape>(), 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<TopoDS_Shape>(), 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<TopoDS_Shape>(), 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;