From de2679d59f7b45a05a08573abab5c98ac38f0054 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Tue, 17 Nov 2020 19:24:09 +0100 Subject: [PATCH] Add unit test --- .../FeaturesAPI_PointCoordinates.cpp | 4 +- .../FeaturesAPI_PointCoordinates.h | 6 +- src/FeaturesPlugin/CMakeLists.txt | 1 + .../Test/TestPointCoordinates.py | 73 +++++++++++++++++++ src/PythonAPI/model/features/__init__.py | 2 +- 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestPointCoordinates.py diff --git a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp index d8fdb6930..f4805ac22 100644 --- a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp +++ b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp @@ -24,8 +24,8 @@ #include #include -std::list pointCoordinates(const std::shared_ptr& thePart, - const ModelHighAPI_Selection& thePoint) +std::list getPointCoordinates(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint) { FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_PointCoordinates::ID()); diff --git a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h index 2c1abfa76..b6d502d38 100644 --- a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h +++ b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h @@ -29,9 +29,9 @@ class ModelAPI_Document; class ModelHighAPI_Selection; /// \ingroup CPPHighAPI -/// \brief ??? +/// \brief Get the point coordinates. FEATURESAPI_EXPORT -std::list pointCoordinates(const std::shared_ptr& thePart, - const ModelHighAPI_Selection& thePoint); +std::list getPointCoordinates(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint); #endif // FeaturesAPI_PointCoordinates_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index d6fb6ae6c..ada07caa6 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -701,4 +701,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet1D_Wire_3.py TestFillet1D_Wire_4.py TestFillet1D_Wire_5.py + TestPointCoordinates.py ) diff --git a/src/FeaturesPlugin/Test/TestPointCoordinates.py b/src/FeaturesPlugin/Test/TestPointCoordinates.py new file mode 100644 index 000000000..8b5c5b954 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestPointCoordinates.py @@ -0,0 +1,73 @@ +# 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 +# + +""" + Unit test of ... +""" +#========================================================================= +# Initialization of the test +#========================================================================= + +import os +import math + +from salome.shaper import model + +__updated__ = "2020-11-12" + +#========================================================================= +# test get point coordinates +#========================================================================= +def test_point_coordinates(): + + model.begin() + file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep") + partSet = model.moduleDocument() + Part_1 = model.addPart(partSet) + Part_1_doc = Part_1.document() + Import_1 = model.addImport(Part_1_doc,file_path) + model.do() + + myDelta = 1e-6 + coordinates = model.getPointCoordinates(Part_1_doc,model.selection("VERTEX", "[box1_1/Shape_2][box1_1/Shape_3][box1_1/Shape_6]")) + + print(" x: ", coordinates[0]) + print(" y: ", coordinates[1]) + print(" z: ", coordinates[2]) + + aRef = 200 + aRes = coordinates[0] + assert (math.fabs(aRes - aRef) < myDelta), "The coordinate X is wrong: expected = {0}, real = {1}".format(aRef, aRes) + + aRef = 0 + aRes= coordinates[1] + assert (math.fabs(aRes - aRef) < myDelta), "The coordinate Y is wrong: expected = {0}, real = {1}".format(aRef, aRes) + + aRef = 200 + aRes = coordinates[2] + assert (math.fabs(aRes - aRef) < myDelta), "The coordinate Z is wrong: expected = {0}, real = {1}".format(aRef, aRes) + + +if __name__ == '__main__': + + test_point_coordinates() + + #========================================================================= + # End of test + #========================================================================= diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index d0dbeb2c6..41f3e1e8e 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -30,7 +30,7 @@ from FeaturesAPI import addRecover from FeaturesAPI import addFillet, addChamfer from FeaturesAPI import addFusionFaces from FeaturesAPI import measureLength, measureDistance, measureRadius, measureAngle -from FeaturesAPI import pointCoordinates +from FeaturesAPI import getPointCoordinates from FeaturesAPI import addRemoveResults from FeaturesAPI import addCopy, addImportResult from FeaturesAPI import addDefeaturing -- 2.39.2