X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_ShapeAPI.cpp;h=44ec71043ac65f1993fa99a8413b91ea7f4e4a96;hb=be7adf6a7a775f269c00f994af50035035844fee;hp=37ecc1296c4bebf7dcaafa8a500ec9eb11a6ac7e;hpb=eed4f101a32c24d5a9be0830f9a7ead06ca159d1;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index 37ecc1296..44ec71043 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -5,18 +5,27 @@ // Author: Clarisse Genrault (CEA) #include "GeomAlgoAPI_ShapeAPI.h" + #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include +#include -#include +#include namespace GeomAlgoAPI_ShapeAPI { - //======================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox( const double theDx, const double theDy, const double theDz) throw (GeomAlgoAPI_Exception) @@ -38,7 +47,7 @@ namespace GeomAlgoAPI_ShapeAPI return aBoxAlgo.shape(); } - //====================================================================================== + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox( std::shared_ptr theFirstPoint, std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception) @@ -60,7 +69,314 @@ namespace GeomAlgoAPI_ShapeAPI return aBoxAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + std::shared_ptr theBasePoint, std::shared_ptr theEdge, + double theRadius, double theHeight) throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid."); + } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + 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(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + std::shared_ptr theBasePoint, std::shared_ptr theEdge, + double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid."); + } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + 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(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + double theRadius, 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_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(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + double theRadius, double theHeight, double theAngle) 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_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(); + } + + //=============================================================================================== + 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, std::shared_ptr theAxis, @@ -77,13 +393,11 @@ namespace GeomAlgoAPI_ShapeAPI 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(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, const double theDx, @@ -101,13 +415,11 @@ namespace GeomAlgoAPI_ShapeAPI if(!aTranslationAlgo.isDone()) { throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); } - if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) { - throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); - } + return aTranslationAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, std::shared_ptr theStartPoint, @@ -124,9 +436,265 @@ namespace GeomAlgoAPI_ShapeAPI 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 theAxis, + const double theAngle) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle); + + if (!aRotationAlgo.check()) { + throw GeomAlgoAPI_Exception(aRotationAlgo.getError()); + } + + aRotationAlgo.build(); + + if(!aRotationAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aRotationAlgo.getError()); + } + + return aRotationAlgo.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); + + if (!aRotationAlgo.check()) { + throw GeomAlgoAPI_Exception(aRotationAlgo.getError()); + } + + aRotationAlgo.build(); + + if(!aRotationAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aRotationAlgo.getError()); + } + + return aRotationAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( + std::shared_ptr theSourceShape, + 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()); + } + + return aSymmetryAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( + std::shared_ptr theSourceShape, + 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()); + } + + return aSymmetryAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( + std::shared_ptr theSourceShape, + 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()); + } + + return aSymmetryAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeScale( + std::shared_ptr theSourceShape, + std::shared_ptr theCenterPoint, + 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()); + } + + return aScaleAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeScale( + std::shared_ptr theSourceShape, + std::shared_ptr theCenterPoint, + const double theScaleFactorX, + const double theScaleFactorY, + const double theScaleFactorZ) throw (GeomAlgoAPI_Exception) + { + 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()); + } + + return aScaleAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeMultiTranslation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const double theStep, + const int theNumber) throw (GeomAlgoAPI_Exception) + { + 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); + } + + if (!theAxis) { + std::string aError = "Multitranslation builder "; + aError+=":: the first axis is not valid"; + throw GeomAlgoAPI_Exception(aError); + } + + ListOfShape aListOfShape; + for (int i=0; i GeomAlgoAPI_ShapeAPI::makeMultiTranslation( + std::shared_ptr theSourceShape, + std::shared_ptr theFirstAxis, + const double theFirstStep, + const int theFirstNumber, + std::shared_ptr theSecondAxis, + const double theSecondStep, + const int theSecondNumber) throw (GeomAlgoAPI_Exception) + { + if (theFirstNumber <=0) { + 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."; + throw GeomAlgoAPI_Exception(aError); + } + + 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); + } + + // Coord theFirstAxis + double x1 = theFirstAxis->dir()->x(); + double y1 = theFirstAxis->dir()->y(); + double z1 = theFirstAxis->dir()->z(); + double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1); + + // Coord theSecondAxis + double x2 = theSecondAxis->dir()->x(); + double y2 = theSecondAxis->dir()->y(); + double z2 = theSecondAxis->dir()->z(); + double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2); + + ListOfShape aListOfShape; + for (int j=0; j GeomAlgoAPI_ShapeAPI::makeConeSegment( + const double theRMin1, const double theRMax1, + const double theRMin2, const double theRMax2, + const double theZ, + const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception) + { + 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(); + } }