From 5ae4adba8e5c3406f5dc88c87a63e5cbb0c334f8 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 18 Dec 2018 17:15:09 +0300 Subject: [PATCH] [Code coverage GeomAlgoAPI]: Improve coverage of Prism and Revolution algorithms. Remove unused code. --- src/FeaturesPlugin/CMakeLists.txt | 3 ++ .../FeaturesPlugin_CompositeSketch.cpp | 1 - .../Test/TestExtrusionOfCompound.py | 46 ++++++++++++++++ .../Test/TestRevolutionOfEdge.py | 54 +++++++++++++++++++ .../Test/TestRevolutionOfPoint.py | 51 ++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 29 ---------- src/GeomAlgoAPI/GeomAlgoAPI_Prism.h | 33 ------------ src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 9 ---- src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h | 10 ---- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 25 +-------- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h | 6 +-- 11 files changed, 158 insertions(+), 109 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestExtrusionOfCompound.py create mode 100644 src/FeaturesPlugin/Test/TestRevolutionOfEdge.py create mode 100644 src/FeaturesPlugin/Test/TestRevolutionOfPoint.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 7460a5b38..532e40e00 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -169,6 +169,7 @@ INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Featu INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) ADD_UNIT_TESTS(TestExtrusion.py + TestExtrusionOfCompound.py TestExtrusionCut.py TestExtrusionCut_BySize.py TestExtrusionCut_ByPlanesAndOffsets.py @@ -179,6 +180,8 @@ ADD_UNIT_TESTS(TestExtrusion.py TestExtrusion_ZeroOffsetError.py TestRevolution.py TestRevolution_ByAngle.py + TestRevolutionOfPoint.py + TestRevolutionOfEdge.py TestRevolutionCut.py TestRevolutionCut_ByAngle.py TestRevolutionCut_ByPlanesAndOffsets.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index e3d5803ba..1c16b04fc 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/src/FeaturesPlugin/Test/TestExtrusionOfCompound.py b/src/FeaturesPlugin/Test/TestExtrusionOfCompound.py new file mode 100644 index 000000000..27c1a74ed --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusionOfCompound.py @@ -0,0 +1,46 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(15, -20, 8) +SketchCircle_2 = Sketch_1.addCircle(35, -5, 15) +model.do() +Compound_1 = model.addCompound(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_2_2f")]) +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Compound_1_1")], model.selection(), model.selection(), 0, model.selection("FACE", "PartSet/XOY"), 10) +model.do() +model.end() + +from GeomAPI import GeomAPI_Shape + +model.testNbResults(Extrusion_1, 1) +model.testNbSubResults(Extrusion_1, [2]) +model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2]) +model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6]) +model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12]) +model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24]) +model.testResultsVolumes(Extrusion_1, [9079.2027688745]) + +assert(model.checkPythonDump()) \ No newline at end of file diff --git a/src/FeaturesPlugin/Test/TestRevolutionOfEdge.py b/src/FeaturesPlugin/Test/TestRevolutionOfEdge.py new file mode 100644 index 000000000..9e434db5f --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionOfEdge.py @@ -0,0 +1,54 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model +from GeomAPI import GeomAPI_Shape + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Point_2 = model.addPoint(Part_1_doc, 10, 0, 0) +Point_3 = model.addPoint(Part_1_doc, 20, 0, 10) +Polyline_1 = model.addPolyline3D(Part_1_doc, [model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2")], False) + +Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("EDGE", "Polyline_1_1/Generated_Edge&Point_1/Point_1")], model.selection("EDGE", "PartSet/OZ"), model.selection(), 0, model.selection("FACE", "PartSet/XOZ"), 0) + +model.testNbResults(Revolution_1, 1) +model.testNbSubResults(Revolution_1, [0]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Revolution_1, [666.43244]) + +Revolution_1.setPlanesAndOffsets(model.selection("FACE", "PartSet/YOZ"), 0, model.selection("FACE", "PartSet/XOZ"), 0) + +model.testNbResults(Revolution_1, 1) +model.testNbSubResults(Revolution_1, [0]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.EDGE, [4]) +model.testNbSubShapes(Revolution_1, GeomAPI_Shape.VERTEX, [8]) +model.testResultsVolumes(Revolution_1, [333.21622]) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRevolutionOfPoint.py b/src/FeaturesPlugin/Test/TestRevolutionOfPoint.py new file mode 100644 index 000000000..0ec5d3dc4 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRevolutionOfPoint.py @@ -0,0 +1,51 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model +from GeomAPI import * + +import math + +def checkMiddlePoint(shape, x, y, z, tolerance = 1.e-7): + assert(shape is not None) + assert(shape.isEdge()) + middlePoint = shape.middlePoint() + assert(math.fabs(middlePoint.x() - x) < tolerance), "{} != {}".format(middlePoint.x(), x) + assert(math.fabs(middlePoint.y() - y) < tolerance), "{} != {}".format(middlePoint.y(), y) + assert(math.fabs(middlePoint.z() - z) < tolerance), "{} != {}".format(middlePoint.z(), z) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Point_2 = model.addPoint(Part_1_doc, 10, 0, 0) +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Point_1")]) + +Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("VERTEX", "Vertex_1_1")], model.selection("EDGE", "PartSet/OZ"), model.selection(), 0, model.selection("FACE", "PartSet/XOZ"), 0) +Shape = Revolution_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 0, -10, 0) + +Revolution_1.setPlanesAndOffsets(model.selection("FACE", "PartSet/YOZ"), 0, model.selection("FACE", "PartSet/XOZ"), 0) +Shape = Revolution_1.results()[0].resultSubShapePair()[0].shape() +checkMiddlePoint(Shape, 7.071067811865474, -7.071067811865474, 0) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 3a0e7eee8..3e46fe132 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -66,35 +66,6 @@ static void storeGenerationHistory(GeomAlgoAPI_Prism* thePrismAlgo, const TopoDS_Face& theFromFace); -//================================================================================================== -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const double theToSize, - const double theFromSize) -{ - build(theBaseShape, std::shared_ptr(), GeomShapePtr(), - theToSize, GeomShapePtr(), theFromSize); -} - -//================================================================================================== -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const std::shared_ptr theDirection, - const double theToSize, - const double theFromSize) -{ - build(theBaseShape, theDirection, GeomShapePtr(), theToSize, GeomShapePtr(), theFromSize); -} - -//================================================================================================== -GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const GeomShapePtr theToShape, - const double theToSize, - const GeomShapePtr theFromShape, - const double theFromSize) -{ - build(theBaseShape, std::shared_ptr(), theToShape, - theToSize, theFromShape, theFromSize); -} - //================================================================================================== GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, const std::shared_ptr theDirection, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index 0309004ed..46d77259c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -38,39 +38,6 @@ class GeomAlgoAPI_Prism : public GeomAlgoAPI_MakeSweep { public: - /// \brief Creates extrusion for the given shape along the normal for this shape. - /// \param[in] theBaseShape planar face or wire to be extruded. - /// \param[in] theToSize offset for "to" plane. - /// \param[in] theFromSize offset for "from" plane. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const double theToSize, - const double theFromSize); - - /// \brief Creates extrusion for the given shape along the normal for this shape. - /// \param[in] theBaseShape vertex, edge, wire, face or shell. - /// \param[in] theDirection direction of extrusion. - /// Can be empty if theBaseShape is planar wire or face. - /// \param[in] theToSize offset for "to" plane. - /// \param[in] theFromSize offset for "from" plane. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const std::shared_ptr theDirection, - const double theToSize, - const double theFromSize); - - /// \brief Creates extrusion for the given shape along the normal for this shape. - /// \param[in] theBaseShape planar face or wire to be extruded. - /// \param[in] theToShape top bounding shape. Can be empty. - /// In this case offset will be applied to the basis. - /// \param[in] theToSize offset for "to" plane. - /// \param[in] theFromShape bottom bounding shape. Can be empty. - /// In this case offset will be applied to the basis. - /// \param[in] theFromSize offset for "from" plane. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const GeomShapePtr theBaseShape, - const GeomShapePtr theToShape, - const double theToSize, - const GeomShapePtr theFromShape, - const double theFromSize); - /// \brief Creates extrusion for the given shape along the normal for this shape. /// \param[in] theBaseShape planar face or wire to be extruded. /// \param[in] theDirection direction of extrusion. diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index 8c2f62448..e7a035cc1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -89,15 +89,6 @@ static void storeGenerationHistory(GeomAlgoAPI_Revolution* theRevolutionAlgo, const TopoDS_Shape& theModifiedBaseShape, const bool theIsFromFaceSet); -//================================================================================================== -GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, - const std::shared_ptr theAxis, - const double theToAngle, - const double theFromAngle) -{ - build(theBaseShape, theAxis, GeomShapePtr(), theToAngle, GeomShapePtr(), theFromAngle); -} - //================================================================================================== GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, const std::shared_ptr theAxis, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h index b951c9867..f388e03bd 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.h @@ -40,16 +40,6 @@ class GeomAlgoAPI_Revolution : public GeomAlgoAPI_MakeSweep { public: - /// \brief Creates revolution for the given shape. - /// \param[in] theBaseShape face for revolution. - /// \param[in] theAxis axis for revolution. - /// \param[in] theToAngle to angle. - /// \param[in] theFromAngle from angle. - GEOMALGOAPI_EXPORT GeomAlgoAPI_Revolution(const GeomShapePtr theBaseShape, - const std::shared_ptr theAxis, - const double theToAngle, - const double theFromAngle); - /// \brief Creates revolution for the given shape. /// \param[in] theBaseShape face for revolution. /// \param[in] theAxis axis for revolution. diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index a9390272b..598053313 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -554,29 +554,6 @@ std::list > return aResultPoints; } -//================================================================================================== -std::shared_ptr - GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr theFace) -{ - if (!theFace.get()) - return std::shared_ptr(); - - TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl()); - if (aPlaneFace.IsNull()) - return std::shared_ptr(); - - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace)); - if (aPlane.IsNull()) - return std::shared_ptr(); - - // make an infinity face on the plane - TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape(); - - std::shared_ptr aResult(new GeomAPI_Shape); - aResult->setImpl(new TopoDS_Shape(anInfiniteFace)); - return aResult; -} - //================================================================================================== std::shared_ptr GeomAlgoAPI_ShapeTools::fitPlaneToBox( const std::shared_ptr thePlane, @@ -997,6 +974,7 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::findShape( } //================================================================================================== +#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS std::shared_ptr GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape( const std::shared_ptr theBaseShape, const std::shared_ptr theAxis) @@ -1012,6 +990,7 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape( aCentreOfMassPoint.Z()-aPoint.Z())); return aDir; } +#endif //================================================================================================== static TopoDS_Wire fixParametricGaps(const TopoDS_Wire& theWire) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index af2a81f5c..4c80a6e7c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -92,10 +92,6 @@ public: std::list > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0); - /// \return infinite plane received from theFace plane. - GEOMALGOAPI_EXPORT static std::shared_ptr - faceToInfinitePlane(const std::shared_ptr theFace); - /// \brief Enlarges or reduces plane to fit bounding box. /// \return plane that fits to bounding box. /// \param[in] thePlane base plane. @@ -176,6 +172,7 @@ public: const std::list >& thePoints, const std::set >& theShapes); +#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS /// \brief Returns a dir from a shape and an axis. /// \param[in] theBaseShape shape whose center of mass serves as the starting point of the dir. /// \param[in] theAxis axis that serves as a direction for the dir @@ -183,6 +180,7 @@ public: GEOMALGOAPI_EXPORT static std::shared_ptr buildDirFromAxisAndShape( const std::shared_ptr theBaseShape, const std::shared_ptr theAxis); +#endif /// \brief Reapproximate a wire to build a single edge GEOMALGOAPI_EXPORT static std::shared_ptr wireToEdge( -- 2.39.2