Salome HOME
Merge remote-tracking branch 'remotes/origin/CEA_2020_Lot1'
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 12 Oct 2020 19:24:41 +0000 (22:24 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 12 Oct 2020 19:24:41 +0000 (22:24 +0300)
14 files changed:
src/ConnectorAPI/Test/TestExportSTL.py [new file with mode: 0644]
src/ConnectorAPI/Test/tests.set
src/ExchangeAPI/CMakeLists.txt
src/ExchangeAPI/ExchangeAPI_Export.cpp
src/ExchangeAPI/ExchangeAPI_Export.h
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/ExchangePlugin_msg_fr.ts
src/ExchangePlugin/export_widget.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Macro.h
src/PythonAPI/model/exchange/__init__.py

diff --git a/src/ConnectorAPI/Test/TestExportSTL.py b/src/ConnectorAPI/Test/TestExportSTL.py
new file mode 100644 (file)
index 0000000..edc7eaf
--- /dev/null
@@ -0,0 +1,159 @@
+# Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+"""
+      TestExport.py
+      Unit test of ExchangePlugin_TestExport class
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+import salome
+
+import os
+import math
+from tempfile import TemporaryDirectory
+
+import GEOM
+
+from ModelAPI import *
+
+from salome.shaper import model
+
+from salome.geom import geomBuilder
+
+from GeomAlgoAPI import *
+
+__updated__ = "2015-05-22"
+
+salome.salome_init(1)
+geompy = geomBuilder.New()
+
+#=========================================================================
+# Help functions
+#=========================================================================
+def removeFile(theFileName):
+    try: os.remove(theFileName)
+    except OSError: pass
+    assert not os.path.exists(theFileName), \
+            "Can not remove file {0}".format(theFileName)
+
+#=========================================================================
+# test Export STL 
+#=========================================================================
+def testExportSTL(theFile, theDelta, theErrorExpected = False):
+
+    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)
+    Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
+    model.do()
+
+    # First export to GEOM
+    model.exportToGEOM(Part_1_doc)
+    model.end()
+
+    theSurface = 600
+
+    print("theFile=",theFile)
+
+    # deflection relative 0.0001 et Ascii 
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID","Box_1_1"),0.0001, 0.5, True,False)
+
+ #==   assert os.path.exists(theFile)
+        
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+    
+    removeFile(theFile)
+
+    theSurface =  600
+    # deflection relative 0.0001 et binaire
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, True,True)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+    
+    removeFile(theFile)
+
+    theSurface =  600
+    # deflection absolue et AScii
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False, False)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+
+    theSurface =  600
+    # deflection absolue et binaire
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False,True)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+
+    model.end()
+
+if __name__ == '__main__':
+    with TemporaryDirectory() as tmp_dir:
+        aRealSurface = 0.00192878
+        #=========================================================================
+        # Export a shape into STL
+        #=========================================================================
+        testExportSTL(os.path.join(tmp_dir, "export.stl"), 10 ** -5, True)
+        #=========================================================================
+        # End of test
+        #=========================================================================
index 60e932add571e24e5de7d9144d53f9fbd74c781d..31e182ca71e9349eb41828a1f98279c27f0cc16e 100644 (file)
@@ -27,4 +27,5 @@ SET(TEST_NAMES
   Test17917
   Test18887
   Test3195
+  TestExportSTL
 )
index bdf5bcb345ffd454bd8bde502f7e3765f6bacb81..b61f22ce9a20a675cce9f89aa4cca82e82da9b13 100644 (file)
@@ -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
index 000e178abdc874dff99814310bae3a905abbb4c6..d1266f3f71c76ee2b79a87140b77bc1c9724fd2c 100644 (file)
@@ -53,6 +53,52 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
   apply(); // finish operation to make sure the export is done on the current state of the history
 }
 
+// Constructor with values for STL of selected result export.
+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)
+  : 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(),
+      theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) );
+    fillAttribute(aDeflectionRelative,
+      theFeature->real(ExchangePlugin_ExportFeature::STL_RELATIVE()) );
+  }
+  else {
+    fillAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(),
+      theFeature->string(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE()) );
+    fillAttribute(aDeflectionAbsolute,
+      theFeature->real(ExchangePlugin_ExportFeature::STL_ABSOLUTE()) );
+  }
+
+  if(anIsASCII){
+    fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_ASCII(),
+      theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_TYPE()));
+  }
+  else
+  {
+    fillAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE_BINARY(),
+      theFeature->string(ExchangePlugin_ExportFeature::STL_FILE_TYPE()));
+  }
+
+  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
+}
+
+
+
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::string & theFilePath, const ModelHighAPI_Selection& theResult,
   const std::string & theAuthor, const std::string & theGeometryName)
@@ -74,6 +120,7 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
 }
 
 
+
 /// Constructor with values for export in other formats than XAO.
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                               const std::string & theFilePath,
@@ -144,6 +191,34 @@ void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const
       theDumper << ", '" << theGeometryName << "'";
     theDumper << ")" << std::endl;
   }
+  else if (exportType == "STL") {
+    std::string aTmpSTLFile =
+                aBase->string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value();
+    correctSeparators(aTmpSTLFile);
+    theDumper << "exportToSTL(" << aDocName << ", '" << aTmpSTLFile << "'" ;
+    AttributeSelectionPtr aShapeSelected =
+      aBase->selection(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED());
+
+    theDumper<<","<< aShapeSelected;
+
+    theDumper <<","<<  stlabsolute() <<","<< stlrelative();
+
+    if (stldeflectionType()->value()
+         == ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE()){
+      theDumper <<","<< "True";
+    }
+    else {
+      theDumper <<","<< "False";
+    }
+
+    if (stlfileType()->value() == ExchangePlugin_ExportFeature::STL_FILE_TYPE_BINARY()) {
+      theDumper << "False";
+    }
+    else {
+      theDumper <<  "True";
+    }
+    theDumper << ")" << std::endl;
+  }
   else {
     std::string aFilePath = aBase->string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->value();
     correctSeparators(aFilePath);
@@ -179,6 +254,27 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
 }
 
+ExportPtr exportToSTL(const std::shared_ptr<ModelAPI_Document> & thePart,
+      const std::string & theFilePath,
+      const ModelHighAPI_Selection& theSelectedShape,
+      double  theDeflectionRelative,
+      double  theDeflectionAbsolute,
+      const bool theIsRelative,
+      const bool theIsASCII)
+{
+  apply(); // finish previous operation to make sure all previous operations are done
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    thePart->addFeature(ExchangePlugin_ExportFeature::ID());
+
+  return ExportPtr(new ExchangeAPI_Export(aFeature,
+                                          theFilePath,
+                                          theSelectedShape,
+                                          theDeflectionRelative,
+                                          theDeflectionAbsolute,
+                                          theIsRelative,
+                                          theIsASCII));
+}
+
 ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
   const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape,
   const std::string & /*theAuthor*/, const std::string & /*theGeometryName*/)
index 24211c9fa7d154b784ed2cc7fe2ca4541d8f1510..fb6784f57938ba3ff413813d88a993c5e404d350 100644 (file)
@@ -52,6 +52,16 @@ public:
                               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<ModelAPI_Feature>& theFeature,
+                                const std::string & theFilePath,
+                                const ModelHighAPI_Selection& theSelectedShape,
+                                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<ModelAPI_Feature>& theFeature,
@@ -71,7 +81,7 @@ public:
   EXCHANGEAPI_EXPORT
   virtual ~ExchangeAPI_Export();
 
-  INTERFACE_7(ExchangePlugin_ExportFeature::ID(),
+  INTERFACE_15(ExchangePlugin_ExportFeature::ID(),
              exportType, ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
              ModelAPI_AttributeString, /** ExportType */,
              filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(),
@@ -85,7 +95,25 @@ public:
              xaoAuthor, ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
              ModelAPI_AttributeString, /** xao author */,
              xaoGeometryName, ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
-             ModelAPI_AttributeString, /** xao geometry name */)
+             ModelAPI_AttributeString, /** xao geometry name */,
+             stlFilePath, ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
+             ModelAPI_AttributeString, /** stl_file_path */,
+             stlobjectselected, ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
+             ModelAPI_AttributeSelection, /** Object selected to export in stl file*/,
+             stldeflectionType, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
+             ModelAPI_AttributeString, /** Type of the defelection */,
+             stlrelative, ExchangePlugin_ExportFeature::STL_RELATIVE(),
+             ModelAPI_AttributeDouble, /** Relative*/,
+             stlabsolute, ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
+             ModelAPI_AttributeDouble, /** Absolute */,
+             stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
+             ModelAPI_AttributeString, /** Type of the stl file*/,
+             stldeflectionTypeabsolute,
+                      ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(),
+             ModelAPI_AttributeString, /** Type of the defelection */,
+             stldeflectionTyperelative,
+                      ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(),
+             ModelAPI_AttributeString, /** Type of the defelection */)
 
   /// Dump wrapped feature
   EXCHANGEAPI_EXPORT
@@ -113,6 +141,18 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
                  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<ModelAPI_Document> & thePart,
+      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.
 */
index d898a08e5dd8895c829986908eed8143629eae56..e81ae860df0abb368483973b515c6d042e66be8b 100644 (file)
@@ -27,6 +27,7 @@
 #include <ostream>
 #endif
 
+
 #include <Config_Common.h>
 #include <Config_PropManager.h>
 
@@ -34,6 +35,7 @@
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_IGESExport.h>
 #include <GeomAlgoAPI_STEPExport.h>
+#include <GeomAlgoAPI_STLExport.h>
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_XAOExport.h>
 
@@ -48,6 +50,7 @@
 #include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeTables.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
@@ -98,9 +101,27 @@ void ExchangePlugin_ExportFeature::initAttributes()
     ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
     ModelAPI_AttributeSelectionList::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
+    ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
+    ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
+   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);
+
+  data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
+    ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
+   ModelAPI_AttributeString::typeId());
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+    ExchangePlugin_ExportFeature::STL_FILE_PATH_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
     ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
@@ -128,6 +149,11 @@ void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
   }
+  else if (theID == STL_FILE_PATH_ID()) {
+    string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
+      string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value());
+  }
+
 }
 
 /*
@@ -170,6 +196,9 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   if (aFormatName == "XAO") {
     exportXAO(theFileName);
     return;
+  }else if (aFormatName == "STL") {
+    exportSTL(theFileName);
+    return;
   }
 
   // make shape for export from selected shapes
@@ -316,6 +345,48 @@ static bool isInResults(AttributeSelectionListPtr theSelection,
   return false;
 }
 
+void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName)
+{
+  // Get shape.
+  AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED());
+  GeomShapePtr aShape = aSelection->value();
+  if (!aShape.get()) {
+    aShape = aSelection->context()->shape();
+  }
+
+  // Get relative value and percent flag.
+  double aValue;
+  bool anIsRelative = false;
+  bool anIsASCII = false;
+
+  if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) {
+    aValue = real(STL_RELATIVE())->value();
+    anIsRelative = true;
+  } else {
+    aValue = real(STL_ABSOLUTE())->value();
+  }
+
+  if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
+    anIsASCII = true;
+  }
+  // Perform the export
+  std::string anError;
+  bool aResult = false;
+
+  aResult = STLExport(theFileName,
+                      aShape,
+                      aValue,
+                      anIsRelative,
+                      anIsASCII,
+                      anError);
+
+  if (!aResult || !anError.empty()) {
+    setError("An error occurred while exporting " + theFileName + ": " + anError);
+    return;
+  }
+}
+
+
 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 {
   try {
index 1067d99af198ae4e40eb110cb456af766e0fa68c..bc975ea5b7de9c76f8e22458a706fb66301e7bbc 100644 (file)
@@ -60,6 +60,66 @@ public:
     static const std::string MY_XAO_FILE_PATH_ID("xao_file_path");
     return MY_XAO_FILE_PATH_ID;
   }
+  /// attribute name of stl file path
+  inline static const std::string& STL_FILE_PATH_ID()
+  {
+    static const std::string MY_STL_FILE_PATH_ID("stl_file_path");
+    return MY_STL_FILE_PATH_ID;
+  }
+  /// Attribute name for selected object to export in stl file path.
+  inline static const std::string& STL_OBJECT_SELECTED()
+  {
+    static const std::string ATTR_ID("stl_object_selected");
+    return ATTR_ID;
+  }
+  /// Attribute name for deflection type.
+  inline static const std::string& STL_DEFLECTION_TYPE()
+  {
+    static const std::string ATTR_ID("stl_deflection_type");
+    return ATTR_ID;
+  }
+  /// Attribute name for deflection type relative.
+  inline static const std::string& STL_DEFLECTION_TYPE_RELATIVE()
+  {
+    static const std::string ATTR_ID("stl_deflection_type_relative");
+    return ATTR_ID;
+  }
+  /// Attribute name for deflection type absolute.
+  inline static const std::string& STL_DEFLECTION_TYPE_ABSOLUTE()
+  {
+    static const std::string ATTR_ID("stl_deflection_type_absolute");
+    return ATTR_ID;
+  }
+  /// Attribute name for relative.
+  inline static const std::string& STL_RELATIVE()
+  {
+    static const std::string ATTR_ID("stl_relative");
+    return ATTR_ID;
+  }
+  /// Attribute name for absolute.
+  inline static const std::string& STL_ABSOLUTE()
+  {
+    static const std::string ATTR_ID("stl_absolute");
+    return ATTR_ID;
+  }
+  /// Attribute name for stl file type.
+  inline static const std::string& STL_FILE_TYPE()
+  {
+    static const std::string ATTR_ID("stl_file_type");
+    return ATTR_ID;
+  }
+  /// Attribute name for stl file type ascii.
+  inline static const std::string& STL_FILE_TYPE_ASCII()
+  {
+    static const std::string ATTR_ID("stl_file_type_acii");
+    return ATTR_ID;
+  }
+  /// Attribute name for stl file type binary.
+  inline static const std::string& STL_FILE_TYPE_BINARY()
+  {
+    static const std::string ATTR_ID("stl_file_type_binary");
+    return ATTR_ID;
+  }
   /// attribute name of file format
   inline static const std::string& FILE_FORMAT_ID()
   {
@@ -129,6 +189,9 @@ protected:
 
   /// Performs export to XAO file
   EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName);
+
+  /// Performs export to STL file
+  EXCHANGEPLUGIN_EXPORT void exportSTL(const std::string& theFileName);
 };
 
 #endif /* EXPORT_EXPORTFEATURE_H_ */
index 3e4061b1efb7e0646c9def66f02abfd314d487a9..110053a1d346ca8ad671f596bbdff6134f0b117b 100644 (file)
       <source>XAO</source>
       <translation>XAO</translation>
     </message>
+    <message>
+      <source>STL</source>
+      <translation>STL</translation>
+    </message>
   </context>
   <context>
     <name>Export:file_path</name>
       <translation>Veuillez saisir le nom de la géométrie</translation>
     </message>
   </context>
+  <context>
+    <name>Export:stl_file_path</name>
+    <message>
+      <source>Export file</source>
+      <translation>Fichier d&apos;export</translation>
+    </message>
+  </context>
+  <context>
+    <name>Export:stl_file_path:ExchangePlugin_ExportFormat</name>
+    <message>
+      <source>%1 is not initialized.</source>
+      <translation>%1 n&apos;est pas initialisé.</translation>
+    </message>
+    <message>
+      <source>File name is empty.</source>
+      <translation>Le nom du fichier est vide.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Export:stl_object_selected</name>
+    <message>
+      <source>Object</source>
+      <translation>Objet</translation>
+    </message>
+    <message>
+      <source>Object to export.</source>
+      <translation>Objet à exporter.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Export:stl_file_type</name> 
+    <message>
+      <source>File type</source>
+      <translation>type du fichier</translation>
+    </message>
+    <message>
+      <source>Binary</source>
+      <translation>Binaire</translation>
+    </message>
+    <message>
+      <source>ASCII</source>
+      <translation>ASCII</translation>
+    </message>
+  </context>
+  <context>
+    <name>Export:Deflection</name>
+    <message>
+      <source>Deflection</source>
+      <translation>Déflection</translation>
+    </message>
+    <message>
+      <source>Relative</source>
+      <translation>Relative</translation>
+    </message>
+    <message>
+      <source>Relative value.</source>
+      <translation>Valeur relative</translation>
+    </message>
+    <message>
+      <source>Calculate by size of shape</source>
+      <translation>Calcul par rapport à la taille de la shape</translation>
+    </message>
+    <message>
+      <source>Absolute</source>
+      <translation>Absolue</translation>
+    </message>
+    <message>
+      <source>Value indicate by user</source>
+      <translation>Valeur indiquée par l&apos;utilisateur</translation>
+    </message>
+    <message>
+      <source>Absolute value.</source>
+      <translation>Valeur absolue.</translation>
+    </message>
+  </context>
 
   <!-- Import -->
   <context>
index 9e134b805c32601d268fc1ce6e73a25e165e2a50..83b9aba4d627ce67e2b655512c2131e9fb49763e 100644 (file)
                    placeholder="Please input the geometry name">
       </stringvalue>
     </case>
+    <case id="STL" title="STL">
+      <export_file_selector id="stl_file_path"
+                            type="save"
+                            title="Export file"
+                            path="">
+        <validator id="ExchangePlugin_ExportFormat"
+                   parameters="stl:STL" />
+      </export_file_selector>
+      <shape_selector id="stl_object_selected"
+                          label="Object"
+                          tooltip="Object to export."
+                          shape_types="faces shells solids compsolids compounds">
+            <validator id="GeomValidators_Finite"/>
+      </shape_selector>
+      <groupbox title="Deflection">
+        <radiobox id="stl_deflection_type">
+          <radio id="stl_deflection_type_relative"
+              title="Relative"
+              tooltip="Calculate by size of shape">
+            <doublevalue id="stl_relative"
+              tooltip="Relative value."
+              min="1e-12"
+              step="0.001"
+              default="0.001">
+            </doublevalue>
+          </radio>
+          <radio id="stl_deflection_type_absolute"
+              title="Absolute"
+              tooltip="Value indicate by user">
+            <doublevalue id="stl_absolute"
+              tooltip="Absolute value."
+              min="1e-12"
+              step="0.1"
+              default="0.5">
+            </doublevalue>
+          </radio>
+        </radiobox>
+      </groupbox >
+      <groupbox title="File type">
+        <radiobox id="stl_file_type">
+          <radio id="stl_file_type_binary"
+              title="Binary">
+          </radio>
+          <radio id="stl_file_type_acii"
+              title="ASCII">
+          </radio>
+        </radiobox>
+      </groupbox >
+    </case>
   </switch>
 </source>
index 95e749c10d2d5263ee845b513f73b2659f70365e..2d3df2aee8e4b497a927457e359d2df367c950e1 100644 (file)
@@ -48,6 +48,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_IGESImport.h
     GeomAlgoAPI_BREPExport.h
     GeomAlgoAPI_STEPExport.h
+    GeomAlgoAPI_STLExport.h
     GeomAlgoAPI_IGESExport.h
     GeomAlgoAPI_Transform.h
     GeomAlgoAPI_ShapeTools.h
@@ -113,6 +114,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_IGESImport.cpp
     GeomAlgoAPI_BREPExport.cpp
     GeomAlgoAPI_STEPExport.cpp
+    GeomAlgoAPI_STLExport.cpp
     GeomAlgoAPI_IGESExport.cpp
     GeomAlgoAPI_Transform.cpp
     GeomAlgoAPI_ShapeTools.cpp
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp
new file mode 100644 (file)
index 0000000..a11aa65
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "GeomAlgoAPI_STLExport.h"
+
+#include "GeomAlgoAPI_Tools.h"
+
+#include <TopoDS_Shape.hxx>
+
+// OOCT includes
+#include <BRepBuilderAPI_Copy.hxx>
+#include <StlAPI_Writer.hxx>
+#include <TopoDS_Shape.hxx>
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepTools.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+
+
+
+#define MAX2(X, Y)      ( Abs(X) > Abs(Y) ? Abs(X) : Abs(Y) )
+#define MAX3(X, Y, Z)   ( MAX2 ( MAX2(X, Y) , Z ) )
+
+bool STLExport(const std::string& theFileName,
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               const double theDeflection,
+               const bool theIsRelative,
+               const bool theIsASCII,
+               std::string& theError)
+{
+  #ifdef _DEBUG
+  std::cout << "Export STl into file " << theFileName << std::endl;
+  #endif
+
+  if (!theShape.get()) {
+    theError = "STl Export failed: An invalid argument";
+    return false;
+  }
+
+  try
+  {
+
+    double lDeflection = theDeflection;
+    StlAPI_Writer aWriter;
+    // copy source shape
+    BRepBuilderAPI_Copy aCopy( theShape->impl<TopoDS_Shape>(), Standard_False );
+    TopoDS_Shape aCopyShape = aCopy.Shape();
+    // ASCII mode
+    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;
+    }
+    //Compute triangulation
+    BRepMesh_IncrementalMesh aMesh( aCopyShape, lDeflection );
+    if (!aWriter.Write( aCopyShape, theFileName.c_str())) {
+      theError = "STL Export failed";
+      return false;
+    }
+    return true;
+  }
+  catch( Standard_Failure )
+  {
+    theError = "Exception catched in STlExport";
+  }
+  return false;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STLExport.h
new file mode 100644 (file)
index 0000000..7c36584
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GEOMALGOAPI_STLEXPORT_H_
+#define GEOMALGOAPI_STLEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <string>
+
+#include <GeomAPI_Shape.h>
+
+/// Implementation of the export STL files algorithms
+GEOMALGOAPI_EXPORT
+bool STLExport(const std::string& theFileName,
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               const double theDeflection,
+               const bool theIsRelative,
+               const bool theIsASCII,
+               std::string& theError);
+
+#endif /* GEOMALGOAPI_STLEXPORT_H_ */
index 333de514e0347ea08358160a39ab93727b500db7..a372090fe334c4dcdc7f2008b240b7f196a98040 100644 (file)
       SET_ATTRIBUTE(N_13, T_13, AN_13) \
     END_INIT() \
   public:
+//--------------------------------------------------------------------------------------
+#define INTERFACE_15(KIND, \
+                     N_0, AN_0, T_0, C_0, \
+                     N_1, AN_1, T_1, C_1, \
+                     N_2, AN_2, T_2, C_2, \
+                     N_3, AN_3, T_3, C_3, \
+                     N_4, AN_4, T_4, C_4, \
+                     N_5, AN_5, T_5, C_5, \
+                     N_6, AN_6, T_6, C_6, \
+                     N_7, AN_7, T_7, C_7, \
+                     N_8, AN_8, T_8, C_8, \
+                     N_9, AN_9, T_9, C_9, \
+                     N_10, AN_10, T_10, C_10, \
+                     N_11, AN_11, T_11, C_11, \
+                     N_12, AN_12, T_12, C_12, \
+                     N_13, AN_13, T_13, C_13, \
+                     N_14, AN_14, T_14, C_14) \
+  public: \
+    INTERFACE_COMMON(KIND) \
+    DEFINE_ATTRIBUTE(N_0, T_0, C_0) \
+    DEFINE_ATTRIBUTE(N_1, T_1, C_1) \
+    DEFINE_ATTRIBUTE(N_2, T_2, C_2) \
+    DEFINE_ATTRIBUTE(N_3, T_3, C_3) \
+    DEFINE_ATTRIBUTE(N_4, T_4, C_4) \
+    DEFINE_ATTRIBUTE(N_5, T_5, C_5) \
+    DEFINE_ATTRIBUTE(N_6, T_6, C_6) \
+    DEFINE_ATTRIBUTE(N_7, T_7, C_7) \
+    DEFINE_ATTRIBUTE(N_8, T_8, C_8) \
+    DEFINE_ATTRIBUTE(N_9, T_9, C_9) \
+    DEFINE_ATTRIBUTE(N_10, T_10, C_10) \
+    DEFINE_ATTRIBUTE(N_11, T_11, C_11) \
+    DEFINE_ATTRIBUTE(N_12, T_12, C_12) \
+    DEFINE_ATTRIBUTE(N_13, T_13, C_13) \
+    DEFINE_ATTRIBUTE(N_14, T_14, C_14) \
+  protected: \
+    START_INIT() \
+      SET_ATTRIBUTE(N_0, T_0, AN_0) \
+      SET_ATTRIBUTE(N_1, T_1, AN_1) \
+      SET_ATTRIBUTE(N_2, T_2, AN_2) \
+      SET_ATTRIBUTE(N_3, T_3, AN_3) \
+      SET_ATTRIBUTE(N_4, T_4, AN_4) \
+      SET_ATTRIBUTE(N_5, T_5, AN_5) \
+      SET_ATTRIBUTE(N_6, T_6, AN_6) \
+      SET_ATTRIBUTE(N_7, T_7, AN_7) \
+      SET_ATTRIBUTE(N_8, T_8, AN_8) \
+      SET_ATTRIBUTE(N_9, T_9, AN_9) \
+      SET_ATTRIBUTE(N_10, T_10, AN_10) \
+      SET_ATTRIBUTE(N_11, T_11, AN_11) \
+      SET_ATTRIBUTE(N_12, T_12, AN_12) \
+      SET_ATTRIBUTE(N_13, T_13, AN_13) \
+      SET_ATTRIBUTE(N_14, T_14, AN_14) \
+    END_INIT() \
+  public:
 
 //--------------------------------------------------------------------------------------
 #define INTERFACE_16(KIND, \
index a37fdd6784b19b40d9b4e267ac4d8aef19eb874d..0e71bf0808242dcd3a314b972fc69228e6343c00 100644 (file)
@@ -19,7 +19,7 @@
 """Package for Exchange plugin for the Parametric Geometry API of the Modeler.
 """
 
-from ExchangeAPI import addImport, exportToFile, exportToXAO
+from ExchangeAPI import addImport, exportToFile, exportToXAO, exportToSTL
 from ExchangeAPI import exportPart, importPart
 
 from .tools import *