]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add unitary tests and patch for importAPI
authorJérôme <jerome.lucas@cesgenslab.fr>
Thu, 24 Sep 2020 14:33:04 +0000 (16:33 +0200)
committerJérôme <jerome.lucas@cesgenslab.fr>
Thu, 24 Sep 2020 14:33:04 +0000 (16:33 +0200)
src/ConnectorAPI/Test/TestImportSTEP.py [new file with mode: 0644]
src/ExchangeAPI/ExchangeAPI_Import.cpp
src/ExchangeAPI/ExchangeAPI_Import.h

diff --git a/src/ConnectorAPI/Test/TestImportSTEP.py b/src/ConnectorAPI/Test/TestImportSTEP.py
new file mode 100644 (file)
index 0000000..f6094c1
--- /dev/null
@@ -0,0 +1,124 @@
+# 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
+#
+
+"""
+      TestImportStep.py
+      Unit test of ExchangePlugin_ImportFeature class for STEP 
+"""
+#=========================================================================
+# 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 GeomAPI import GeomAPI_Shape
+
+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 Import STEP 
+#=========================================================================
+def testImportSTEP():
+
+    model.begin()
+    partSet = model.moduleDocument()
+    Part_1 = model.addPart(partSet)
+    Part_1_doc = Part_1.document()
+    aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "black_and_white.step")
+    print("aShapePath=",aShapePath)
+    Import_1 = model.addImportStep(Part_1_doc,aShapePath, True, True, True)
+
+    model.do()
+
+    # Check results
+    Import_1_Feature = Import_1.feature()
+    assert Import_1_Feature.error() == ''
+    assert Import_1_Feature.name() == "black_and_white"
+    assert len(Import_1_Feature.results()) == 1
+    model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [2])
+
+    aCompositeFeature = featureToCompositeFeature(Import_1_Feature)
+    assert aCompositeFeature.numberOfSubs(False) == 2
+
+    aFeature1 = aCompositeFeature.subFeature(0, False)
+    assert aFeature1.getKind() == "Group"
+    assert aFeature1.name() == "Color_1"
+
+    aSelectionList = aFeature1.selectionList("group_list")
+    assert aSelectionList.size() == 1
+
+    aFeature1 = aCompositeFeature.subFeature(1, False)
+    assert aFeature1.getKind() == "Group"
+    assert aFeature1.name() == "Color_2"
+
+    aSelectionList = aFeature1.selectionList("group_list")
+    assert aSelectionList.size() == 1
+
+    aFeature1 = aCompositeFeature.subFeature(2, False)
+    assert aFeature1.getKind() == "Group"
+    assert aFeature1.name() == "Material_black"
+
+    aSelectionList = aFeature1.selectionList("group_list")
+    assert aSelectionList.size() == 1
+
+
+    aFeature1 = aCompositeFeature.subFeature(3, False)
+    assert aFeature1.getKind() == "Group"
+    assert aFeature1.name() == "Material_white"
+
+    aSelectionList = aFeature1.selectionList("group_list")
+    assert aSelectionList.size() == 1
+
+    model.end()
+
+if __name__ == '__main__':
+    with TemporaryDirectory() as tmp_dir:
+        #=========================================================================
+        # Export a shape into STL
+        #=========================================================================
+        testImportSTEP()
+        #=========================================================================
+        # End of test
+        #=========================================================================
index 981c92d9d7976e75385262b256ba42113648a278..d5d7ea2a98206757dbdcfb2793f0e2ede05d1c05 100644 (file)
@@ -58,7 +58,7 @@ ExchangeAPI_Import::ExchangeAPI_Import(
 : ModelHighAPI_Interface(theFeature)
 {
   if (initialize())
-    setParameters(theFeature,theFilePath,anScalInterUnits,anMaterials,anColor );
+    setParameters(theFilePath,anScalInterUnits,anMaterials,anColor);
 }
 
 ExchangeAPI_Import::~ExchangeAPI_Import()
@@ -67,16 +67,16 @@ ExchangeAPI_Import::~ExchangeAPI_Import()
 }
 
 //--------------------------------------------------------------------------------------
-void ExchangeAPI_Import::setParameters(const std::shared_ptr<ModelAPI_Feature> & theFeature,
-                                       const std::string & theFilePath, 
+void ExchangeAPI_Import::setParameters(const std::string & theFilePath, 
                                        const bool  anScalInterUnits,
                                        const bool  anMaterials,
                                        const bool  anColor)
 {
-  fillAttribute(theFilePath, myfilePath);
-  fillAttribute(anScalInterUnits, theFeature->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID()));
-  fillAttribute(anMaterials, theFeature->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID()));
-  fillAttribute(anColor, theFeature->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID()));
+  fillAttribute(theFilePath, mystepfilePath);
+  fillAttribute("STEP", feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()));
+  fillAttribute(anScalInterUnits, feature()->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID()));
+  fillAttribute(anMaterials, feature()->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID()));
+  fillAttribute(anColor, feature()->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID()));
   execute();
 }
 
@@ -84,7 +84,8 @@ void ExchangeAPI_Import::setParameters(const std::shared_ptr<ModelAPI_Feature> &
 void ExchangeAPI_Import::setFilePath(const std::string & theFilePath)
 {
   fillAttribute(theFilePath, myfilePath);
-
+  std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFilePath);
+  fillAttribute(anExtension, feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()));
   execute();
 }
 
index c477a0c986a07ab224669f929c502784f9c86ce9..d95a453895a69fab6d627c18f79e17493085cbc6 100644 (file)
@@ -59,9 +59,13 @@ public:
   EXCHANGEAPI_EXPORT
   virtual ~ExchangeAPI_Import();
 
-  INTERFACE_4(ExchangePlugin_ImportFeature::ID(),
+  INTERFACE_6(ExchangePlugin_ImportFeature::ID(),
               filePath, ExchangePlugin_ImportFeature::FILE_PATH_ID(),
               ModelAPI_AttributeString, /** File path */,
+              stepimporttype, ExchangePlugin_ImportFeature::IMPORT_TYPE_ID(),
+              ModelAPI_AttributeString, /**import type */,
+              stepfilePath, ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID(),
+              ModelAPI_AttributeString, /**step File path */,
               scalinterunits, ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID(),
               ModelAPI_AttributeBoolean, /** Scale internationals units */,
               materials, ExchangePlugin_ImportFeature::STEP_MATERIALS_ID(),
@@ -75,8 +79,7 @@ public:
   void setFilePath(const std::string & theFilePath);
   
   EXCHANGEAPI_EXPORT
-  void setParameters(const std::shared_ptr<ModelAPI_Feature> & theFeature,
-                     const std::string & theFilePath, 
+  void setParameters(const std::string & theFilePath, 
                      const bool  anScalInterUnits,
                      const bool  anMaterials,
                      const bool  anColor);