-// 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<mailto:webmaster.salome@opencascade.com>
+//
#include "GeomAlgoAPI_ShapeAPI.h"
#include <GeomAlgoAPI_Box.h>
-#include <GeomAlgoAPI_Cylinder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_Cone.h>
#include <GeomAlgoAPI_ConeSegment.h>
+#include <GeomAlgoAPI_Cylinder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_Rotation.h>
#include <GeomAlgoAPI_Scale.h>
+#include <GeomAlgoAPI_Sphere.h>
#include <GeomAlgoAPI_Symmetry.h>
+#include <GeomAlgoAPI_Torus.h>
#include <GeomAlgoAPI_Translation.h>
#include <GeomAPI_Lin.h>
std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Ax2> anAxis;
anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
theEdge->line()->direction()));
std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Ax2> anAxis;
anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
theEdge->line()->direction()));
return aCylinderAlgo.shape();
}
+ //===============================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
+ std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
+ throw (GeomAlgoAPI_Exception)
+ {
+ std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
+ std::shared_ptr<GeomAPI_Pnt>(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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(
+ std::shared_ptr<GeomAPI_Pnt> theBasePoint,
+ std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Ax2> anAxis;
+ anAxis = std::shared_ptr<GeomAPI_Ax2>(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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(double theRadius,
+ double theRingRadius) throw (GeomAlgoAPI_Exception)
+ {
+ std::shared_ptr<GeomAPI_Pnt> aBasePoint =
+ std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+ std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
+ std::shared_ptr<GeomAPI_Ax2> anAxis;
+ anAxis = std::shared_ptr<GeomAPI_Ax2>(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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
+ std::shared_ptr<GeomAPI_Pnt> theBasePoint,
+ std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Ax2> anAxis;
+ anAxis = std::shared_ptr<GeomAPI_Ax2>(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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
+ double theBaseRadius, double theTopRadius,
+ double theHeight) throw (GeomAlgoAPI_Exception)
+ {
+ std::shared_ptr<GeomAPI_Pnt> aBasePoint =
+ std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+ std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
+ std::shared_ptr<GeomAPI_Ax2> anAxis;
+ anAxis = std::shared_ptr<GeomAPI_Ax2>(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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
std::shared_ptr<GeomAPI_Shape> theSourceShape,
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();
}
if(!aTranslationAlgo.isDone()) {
throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
}
- if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
- throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
- }
+
return aTranslationAlgo.shape();
}
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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+ std::shared_ptr<GeomAPI_Pnt> theStartPoint,
+ std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
std::shared_ptr<GeomAPI_Shape> theSourceShape,
if(!aSymmetryAlgo.isDone()) {
throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
}
- if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
- throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
- }
+
return aSymmetryAlgo.shape();
}
if(!aSymmetryAlgo.isDone()) {
throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
}
- if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
- throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
- }
+
return aSymmetryAlgo.shape();
}
if(!aSymmetryAlgo.isDone()) {
throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
}
- if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
- throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
- }
+
return aSymmetryAlgo.shape();
}
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();
}
if(!aScaleAlgo.isDone()) {
throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
}
- if (!aScaleAlgo.checkValid("Scale builder by dimensions")) {
- throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
- }
+
return aScaleAlgo.shape();
}
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; i<theNumber; i++) {
aListOfShape.
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.";
+ 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);
+ }
+
// Coord theFirstAxis
double x1 = theFirstAxis->dir()->x();
double y1 = theFirstAxis->dir()->y();
return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
}
+ //===============================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<theNumber; i++) {
+ aListOfShape.
+ push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*anAngle));
+ }
+ return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+ }
+
+ //===============================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<theNumber; i++) {
+ aListOfShape.
+ push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*theStep));
+ }
+ return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+ }
+
//===============================================================================================
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
const double theRMin1, const double theRMax1,