X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeAPI.cpp;h=550bf68f3f0b74d9d9e824b29c685f244d4e172e;hb=7074394f8f08413d885f63be01df6bd5007b868c;hp=c593215ecb75d55db018f35fe60e5c23ee4e370b;hpb=a39de1d3dfee7bf14d5d446575c969e13f1df257;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index c593215ec..550bf68f3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -1,19 +1,36 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_ShapeAPI.cpp -// Created: 17 Mar 2016 -// Author: Clarisse Genrault (CEA) +// Copyright (C) 2014-2017 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 @@ -192,6 +209,187 @@ namespace GeomAlgoAPI_ShapeAPI return aCylinderAlgo.shape(); } + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSphere( + std::shared_ptr theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius); + + if (!aSphereAlgo.check()) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + + aSphereAlgo.build(); + + if(!aSphereAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + + if (!aSphereAlgo.checkValid("Sphere builder")) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + return aSphereAlgo.shape(); + } + + //=============================================================================================== + 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); + + if (!aSphereAlgo.check()) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + + aSphereAlgo.build(); + + if(!aSphereAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + + if (!aSphereAlgo.checkValid("Sphere builder")) { + throw GeomAlgoAPI_Exception(aSphereAlgo.getError()); + } + return aSphereAlgo.shape(); + } + + //=============================================================================================== + 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); + + if (!aTorusAlgo.check()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + aTorusAlgo.build(); + + if(!aTorusAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + if (!aTorusAlgo.checkValid("Torus builder")) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + return aTorusAlgo.shape(); + } + + //=============================================================================================== + 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); + + if (!aTorusAlgo.check()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + aTorusAlgo.build(); + + if(!aTorusAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + if (!aTorusAlgo.checkValid("Torus builder")) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + return aTorusAlgo.shape(); + } + + //=============================================================================================== + 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."); + } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight); + + if (!aConeAlgo.check()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + aConeAlgo.build(); + + if(!aConeAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + if (!aConeAlgo.checkValid("Cone builder")) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + return aConeAlgo.shape(); + } + + //=============================================================================================== + 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); + + if (!aConeAlgo.check()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + aConeAlgo.build(); + + if(!aConeAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + if (!aConeAlgo.checkValid("Cone builder")) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + return aConeAlgo.shape(); + } + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, @@ -411,9 +609,15 @@ 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."; + std::string aError = "Multitranslation builder "; + aError+=":: the number of copies for the first direction is null or negative."; throw GeomAlgoAPI_Exception(aError); } @@ -435,15 +639,27 @@ namespace GeomAlgoAPI_ShapeAPI const double theSecondStep, const int theSecondNumber) throw (GeomAlgoAPI_Exception) { + if (!theFirstAxis) { + std::string aError = "Multitranslation builder "; + aError+=":: the first axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + + if (!theSecondAxis) { + std::string aError = "Multitranslation builder "; + aError+=":: the second axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + if (theFirstNumber <=0) { - std::string aError = "Multitranslation builder "; - aError+=":: the number of copies for the first direction is null or negative."; + std::string aError = "Multitranslation builder "; + aError+=":: the number of copies for the first direction is null or negative."; throw GeomAlgoAPI_Exception(aError); } if (theSecondNumber <=0) { - std::string aError = "Multitranslation builder "; - aError+=":: the number of copies for the second direction is null or negative."; + std::string aError = "Multitranslation builder "; + aError+=":: the number of copies for the second direction is null or negative."; throw GeomAlgoAPI_Exception(aError); } @@ -471,6 +687,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) + { + 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) + { + 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,