X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeAPI.cpp;h=55567c40a1fc167652428327c24c95d0cf57bac8;hb=7a56425e50582b34ad233c2865e7da87a2e23406;hp=b0dabccc9cb1f3866c7ea8ae3773f29b8dc069d9;hpb=43587947e4b5094a910389d02ea56c40f842790c;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index b0dabccc9..55567c40a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -1,24 +1,68 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_ShapeAPI.cpp -// Created: 17 Mar 2016 -// Author: Clarisse Genrault (CEA) +// Copyright (C) 2014-2019 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_ShapeAPI.h" #include -#include #include +#include #include +#include #include +#include #include +#include #include +#include #include #include #include +static GeomShapePtr runAlgo(GeomAlgoAPI_MakeShape& theAlgo) throw (GeomAlgoAPI_Exception) +{ + if (!theAlgo.check()) + throw GeomAlgoAPI_Exception(theAlgo.getError()); + + theAlgo.build(); + + if (!theAlgo.isDone()) + throw GeomAlgoAPI_Exception(theAlgo.getError()); + + return theAlgo.shape(); +} + +static GeomShapePtr runAlgoAndCheckShape(GeomAlgoAPI_MakeShape& theAlgo, const std::string& theMsg) +throw (GeomAlgoAPI_Exception) +{ + if (!theAlgo.check()) + throw GeomAlgoAPI_Exception(theAlgo.getError()); + + theAlgo.build(); + + if (!theAlgo.isDone() || !theAlgo.checkValid(theMsg)) + throw GeomAlgoAPI_Exception(theAlgo.getError()); + + return theAlgo.shape(); +} + namespace GeomAlgoAPI_ShapeAPI { //=============================================================================================== @@ -26,21 +70,9 @@ namespace GeomAlgoAPI_ShapeAPI const double theDx, const double theDy, const double theDz) throw (GeomAlgoAPI_Exception) { + static const std::string aMsg("Box builder with dimensions"); GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz); - - if (!aBoxAlgo.check()) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - - aBoxAlgo.build(); - - if(!aBoxAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - if (!aBoxAlgo.checkValid("Box builder with dimensions")) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - return aBoxAlgo.shape(); + return runAlgoAndCheckShape(aBoxAlgo, aMsg); } //=============================================================================================== @@ -48,21 +80,9 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr theFirstPoint, std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception) { + static const std::string aMsg("Box builder with two points"); GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint); - - if (!aBoxAlgo.check()) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - - aBoxAlgo.build(); - - if(!aBoxAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - if (!aBoxAlgo.checkValid("Box builder with two points")) { - throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); - } - return aBoxAlgo.shape(); + return runAlgoAndCheckShape(aBoxAlgo, aMsg); } //=============================================================================================== @@ -85,19 +105,8 @@ namespace GeomAlgoAPI_ShapeAPI GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight); - if (!aCylinderAlgo.check()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - - aCylinderAlgo.build(); - - if(!aCylinderAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - if (!aCylinderAlgo.checkValid("Cylinder builder")) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - return aCylinderAlgo.shape(); + static const std::string aMsg("Cylinder builder"); + return runAlgoAndCheckShape(aCylinderAlgo, aMsg); } //=============================================================================================== @@ -120,19 +129,8 @@ namespace GeomAlgoAPI_ShapeAPI GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle); - if (!aCylinderAlgo.check()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - - aCylinderAlgo.build(); - - if(!aCylinderAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - if (!aCylinderAlgo.checkValid("Cylinder portion builder")) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - return aCylinderAlgo.shape(); + static const std::string aMsg("Cylinder portion builder"); + return runAlgoAndCheckShape(aCylinderAlgo, aMsg); } //=============================================================================================== @@ -148,19 +146,8 @@ namespace GeomAlgoAPI_ShapeAPI GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight); - if (!aCylinderAlgo.check()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - - aCylinderAlgo.build(); - - if(!aCylinderAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - if (!aCylinderAlgo.checkValid("Cylinder builder")) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); - } - return aCylinderAlgo.shape(); + static const std::string aMsg("Cylinder builder"); + return runAlgoAndCheckShape(aCylinderAlgo, aMsg); } //=============================================================================================== @@ -176,19 +163,116 @@ namespace GeomAlgoAPI_ShapeAPI GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle); - if (!aCylinderAlgo.check()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + static const std::string aMsg("Cylinder portion builder"); + return runAlgoAndCheckShape(aCylinderAlgo, aMsg); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSphere( + std::shared_ptr theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception) + { + static const std::string aMsg("Sphere builder"); + GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius); + return runAlgoAndCheckShape(aSphereAlgo, aMsg); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius) + throw (GeomAlgoAPI_Exception) + { + std::shared_ptr aCenterPoint = + std::shared_ptr(new GeomAPI_Pnt(0.,0.,0.)); + + GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius); + + static const std::string aMsg("Sphere builder"); + return runAlgoAndCheckShape(aSphereAlgo, aMsg); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTorus( + std::shared_ptr theBasePoint, + std::shared_ptr theEdge,double theRadius, double theRingRadius) + throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid."); } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius); + + static const std::string aMsg("Torus builder"); + return runAlgoAndCheckShape(aTorusAlgo, aMsg); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTorus(double theRadius, + double theRingRadius) throw (GeomAlgoAPI_Exception) + { + std::shared_ptr aBasePoint = + std::shared_ptr(new GeomAPI_Pnt(0.,0.,0.)); + std::shared_ptr aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.); + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + aEdge->line()->direction())); + + GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius); - aCylinderAlgo.build(); + static const std::string aMsg("Torus builder"); + return runAlgoAndCheckShape(aTorusAlgo, aMsg); + } - if(!aCylinderAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCone( + std::shared_ptr theBasePoint, + std::shared_ptr theEdge, + double theBaseRadius, double theTopRadius, + double theHeight) throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid."); } - if (!aCylinderAlgo.checkValid("Cylinder portion builder")) { - throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid."); } - return aCylinderAlgo.shape(); + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight); + + static const std::string aMsg("Cone builder"); + return runAlgoAndCheckShape(aConeAlgo, aMsg); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCone( + double theBaseRadius, double theTopRadius, + double theHeight) throw (GeomAlgoAPI_Exception) + { + std::shared_ptr aBasePoint = + std::shared_ptr(new GeomAPI_Pnt(0.,0.,0.)); + std::shared_ptr aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.); + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + aEdge->line()->direction())); + + GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight); + + static const std::string aMsg("Cone builder"); + return runAlgoAndCheckShape(aConeAlgo, aMsg); } //=============================================================================================== @@ -198,20 +282,7 @@ namespace GeomAlgoAPI_ShapeAPI const double theDistance) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance); - - if (!aTranslationAlgo.check()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - - aTranslationAlgo.build(); - - if(!aTranslationAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - return aTranslationAlgo.shape(); + return runAlgo(aTranslationAlgo); } //=============================================================================================== @@ -222,20 +293,7 @@ namespace GeomAlgoAPI_ShapeAPI const double theDz) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz); - - if (!aTranslationAlgo.check()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - - aTranslationAlgo.build(); - - if(!aTranslationAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - return aTranslationAlgo.shape(); + return runAlgo(aTranslationAlgo); } //=============================================================================================== @@ -245,20 +303,28 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr theEndPoint) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint); + return runAlgo(aTranslationAlgo); + } - if (!aTranslationAlgo.check()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - - aTranslationAlgo.build(); + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeRotation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const double theAngle) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle); + return runAlgo(aRotationAlgo); + } - if(!aTranslationAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - if (!aTranslationAlgo.checkValid("Translation builder with two points")) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } - return aTranslationAlgo.shape(); + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeRotation( + std::shared_ptr theSourceShape, + std::shared_ptr theCenterPoint, + std::shared_ptr theStartPoint, + std::shared_ptr theEndPoint) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theCenterPoint, theStartPoint, theEndPoint); + return runAlgo(aRotationAlgo); } //=============================================================================================== @@ -267,20 +333,7 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr thePoint) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint); - - if (!aSymmetryAlgo.check()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - - aSymmetryAlgo.build(); - - if(!aSymmetryAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - return aSymmetryAlgo.shape(); + return runAlgo(aSymmetryAlgo); } //=============================================================================================== @@ -289,20 +342,7 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr theAxis) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis); - - if (!aSymmetryAlgo.check()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - - aSymmetryAlgo.build(); - - if(!aSymmetryAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - return aSymmetryAlgo.shape(); + return runAlgo(aSymmetryAlgo); } //=============================================================================================== @@ -311,20 +351,7 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr thePlane) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane); - - if (!aSymmetryAlgo.check()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - - aSymmetryAlgo.build(); - - if(!aSymmetryAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) { - throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError()); - } - return aSymmetryAlgo.shape(); + return runAlgo(aSymmetryAlgo); } //=============================================================================================== @@ -334,20 +361,7 @@ namespace GeomAlgoAPI_ShapeAPI const double theScaleFactor) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor); - - if (!aScaleAlgo.check()) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - - aScaleAlgo.build(); - - if(!aScaleAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - if (!aScaleAlgo.checkValid("Scale builder by a scale factor")) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - return aScaleAlgo.shape(); + return runAlgo(aScaleAlgo); } //=============================================================================================== @@ -360,20 +374,7 @@ namespace GeomAlgoAPI_ShapeAPI { GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactorX, theScaleFactorY, theScaleFactorZ); - - if (!aScaleAlgo.check()) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - - aScaleAlgo.build(); - - if(!aScaleAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - if (!aScaleAlgo.checkValid("Scale builder by dimensions")) { - throw GeomAlgoAPI_Exception(aScaleAlgo.getError()); - } - return aScaleAlgo.shape(); + return runAlgo(aScaleAlgo); } //=============================================================================================== @@ -383,6 +384,18 @@ namespace GeomAlgoAPI_ShapeAPI const double theStep, const int theNumber) throw (GeomAlgoAPI_Exception) { + if (!theAxis) { + std::string aError = "Multitranslation builder "; + aError+=":: the first axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + + if (theNumber <=0) { + std::string aError = "Multitranslation builder "; + aError+=":: the number of copies for the first direction is null or negative."; + throw GeomAlgoAPI_Exception(aError); + } + ListOfShape aListOfShape; for (int i=0; idir()->x(); double y1 = theFirstAxis->dir()->y(); @@ -425,6 +462,61 @@ namespace GeomAlgoAPI_ShapeAPI return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); } + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeMultiRotation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const int theNumber) throw (GeomAlgoAPI_Exception) + { + if (!theAxis) { + std::string aError = "Multirotation builder "; + aError+=":: the axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + + if (theNumber <=0) { + std::string aError = "Multirotation builder "; + aError+=":: the number of copies is null or negative."; + throw GeomAlgoAPI_Exception(aError); + } + + double anAngle = 360./theNumber; + + ListOfShape aListOfShape; + for (int i=0; i GeomAlgoAPI_ShapeAPI::makeMultiRotation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const double theStep, + const int theNumber) throw (GeomAlgoAPI_Exception) + { + if (!theAxis) { + std::string aError = "Multirotation builder "; + aError+=":: the axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + + if (theNumber <=0) { + std::string aError = "Multirotation builder "; + aError+=":: the number of copies is null or negative."; + throw GeomAlgoAPI_Exception(aError); + } + + ListOfShape aListOfShape; + for (int i=0; i GeomAlgoAPI_ShapeAPI::makeConeSegment( const double theRMin1, const double theRMax1, @@ -435,18 +527,7 @@ namespace GeomAlgoAPI_ShapeAPI GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2, theZ, theStartPhi, theDeltaPhi); - if (!aConeSegmentAlgo.check()) { - throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError()); - } - - aConeSegmentAlgo.build(); - - if(!aConeSegmentAlgo.isDone()) { - throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError()); - } - if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) { - throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError()); - } - return aConeSegmentAlgo.shape(); + static const std::string aMsg("Cone Segment builder"); + return runAlgoAndCheckShape(aConeSegmentAlgo, aMsg); } }