#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_Rotation.h>
#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_Tools.h>
#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
// Getting angle.
double anAngle = real(ANGLE())->value();
- GeomAlgoAPI_Rotation aRotationAlgo(aFace, anAxis, anAngle);
- if (!aRotationAlgo.check()) {
- setError(aRotationAlgo.getError());
- return GeomShapePtr();
- }
- aRotationAlgo.build();
- if (!aRotationAlgo.isDone()) {
+ std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(
+ new GeomAlgoAPI_Rotation(aFace, anAxis, anAngle));
+ // Checking that the algorithm worked properly.
+ std::string anError;
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
setError("Error: Failed to rotate plane");
return GeomShapePtr();
}
- std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face(aRotationAlgo.shape()));
+ std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face(aRotationAlgo->shape()));
return aRes;
}
std::shared_ptr<GeomAlgoAPI_Rotation> aRotationnAlgo(
new GeomAlgoAPI_Rotation(aBaseShape, anAxis, i*anAngle));
- if (!aRotationnAlgo->check()) {
- setError(aRotationnAlgo->getError());
- break;
- }
-
- aRotationnAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep));
- if (!aTranslationAlgo->check()) {
- setError(aTranslationAlgo->getError());
- break;
- }
-
- aTranslationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(
aTranslationAlgo, getKind(), anError)) {
std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz));
- if (!aTranslationAlgo->check()) {
- setError(aTranslationAlgo->getError());
- break;
- }
-
- aTranslationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(
aTranslationAlgo, getKind(), anError)) {
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_Tools.h>
+#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_ShapeIterator.h>
std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(new GeomAlgoAPI_Rotation(aBaseShape,
anAxis,
anAngle));
-
- if (!aRotationAlgo->check()) {
- setError(aRotationAlgo->getError());
- return;
- }
-
- aRotationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
setError(anError);
aCenterPoint,
aStartPoint,
anEndPoint));
-
- if (!aRotationAlgo->check()) {
- setError(aRotationAlgo->getError());
- return;
- }
-
- aRotationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Scale> aScaleAlgo(
new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, aScaleFactor));
- if (!aScaleAlgo->check()) {
- setError(aScaleAlgo->getError());
- return;
- }
-
- aScaleAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) {
setError(anError);
aScaleFactorY,
aScaleFactorZ));
- if (!aScaleAlgo->check()) {
- setError(aScaleAlgo->getError());
- return;
- }
-
- aScaleAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) {
setError(anError);
#include <GeomAlgoAPI_MakeShapeList.h>
#include <GeomAlgoAPI_Tools.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Ax2.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Face.h>
#include <GeomAPI_Lin.h>
std::shared_ptr<GeomAlgoAPI_Symmetry> aSymmetryAlgo(
new GeomAlgoAPI_Symmetry(aBaseShape, aPoint));
- if (!aSymmetryAlgo->check()) {
- setError(aSymmetryAlgo->getError());
- return;
- }
-
- aSymmetryAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Symmetry> aSymmetryAlgo(
new GeomAlgoAPI_Symmetry(aBaseShape, anAxis));
- if (!aSymmetryAlgo->check()) {
- setError(aSymmetryAlgo->getError());
- return;
- }
-
- aSymmetryAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Symmetry> aSymmetryAlgo(
new GeomAlgoAPI_Symmetry(aBaseShape, aPlane));
- if (!aSymmetryAlgo->check()) {
- setError(aSymmetryAlgo->getError());
- return;
- }
-
- aSymmetryAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, getKind(), anError)) {
setError(anError);
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
+#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_ShapeIterator.h>
} else {
std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
new GeomAlgoAPI_Translation(aBaseShape, anAxis, aDistance));
-
- if (!aTranslationAlgo->check()) {
- setError(aTranslationAlgo->getError());
- return;
- }
-
- aTranslationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
new GeomAlgoAPI_Translation(aBaseShape, aDX, aDY, aDZ));
- if (!aTranslationAlgo->check()) {
- setError(aTranslationAlgo->getError());
- return;
- }
-
- aTranslationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
setError(anError);
std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
new GeomAlgoAPI_Translation(aBaseShape, aFirstPoint, aSecondPoint));
- if (!aTranslationAlgo->check()) {
- setError(aTranslationAlgo->getError());
- return;
- }
-
- aTranslationAlgo->build();
-
// Checking that the algorithm worked properly.
if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
setError(anError);
{
MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());
}
+
+//=================================================================================================
+void GeomAPI_Trsf::setScale(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
+ const double theScale)
+{
+ MY_TRSF->SetScale(theCenter->impl<gp_Pnt>(), theScale);
+}
* \param[in] thePlane symmetry plane.
*/
GEOMAPI_EXPORT void setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane);
+
+ /** \brief Sets the scaling transformation.
+ * \param[in] theCenter scaling origin.
+ * \param[in] theScale scaling factor.
+ */
+ GEOMAPI_EXPORT void setScale(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
+ const double theScale);
};
//! Pointer on the object
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "GeomAlgoAPI_Rotation.h"
+#include <GeomAlgoAPI_Rotation.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Pnt.h>
#include <GeomAPI_XYZ.h>
-#include <BRepBuilderAPI_Transform.hxx>
-
-#include <gp_Ax1.hxx>
-#include <gp_Dir.hxx>
-#include <gp_Vec.hxx>
-
#include <Precision.hxx>
+// Verify points are applicable to build the rotation transformation
+static bool checkPoints(GeomPointPtr theCenterPoint,
+ GeomPointPtr theStartPoint,
+ GeomPointPtr theEndPoint,
+ std::string& theError);
+
//=================================================================================================
GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theAngle)
{
- myMethodType = BY_ANGLE;
- mySourceShape = theSourceShape;
- myAxis = theAxis;
- myAngle = theAngle;
+ if (!theAxis) {
+ myError = "Rotation builder :: axis is not valid.";
+ return;
+ }
+
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setRotation(theAxis, theAngle / 180.0 * M_PI);
+
+ build(theSourceShape, aTrsf);
}
std::shared_ptr<GeomAPI_Pnt> theStartPoint,
std::shared_ptr<GeomAPI_Pnt> theEndPoint)
{
- myMethodType = BY_POINTS;
- mySourceShape = theSourceShape;
- myCenterPoint = theCenterPoint;
- myStartPoint = theStartPoint;
- myEndPoint = theEndPoint;
-}
+ if (!checkPoints(theCenterPoint, theStartPoint, theEndPoint, myError))
+ return;
-//=================================================================================================
-bool GeomAlgoAPI_Rotation::check()
-{
- switch (myMethodType) {
- case BY_ANGLE: {
- if (!myAxis) {
- myError = "Rotation builder :: axis is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Rotation builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- case BY_POINTS: {
- if (!myCenterPoint) {
- myError = "Rotation builder :: center point is not valid.";
- return false;
- }
- if (!myStartPoint) {
- myError = "Rotation builder :: start point is not valid.";
- return false;
- }
- if (!myEndPoint) {
- myError = "Rotation builder :: end point is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Rotation builder :: source shape is not valid.";
- return false;
- }
- if(myCenterPoint->distance(myStartPoint) < Precision::Confusion()) {
- myError = "Rotation builder :: center point and start point coincide.";
- return false;
- }
- if(myCenterPoint->distance(myEndPoint) < Precision::Confusion()) {
- myError = "Rotation builder :: center point and end point coincide.";
- return false;
- }
- if(myStartPoint->distance(myEndPoint) < Precision::Confusion()) {
- myError = "Rotation builder :: start point and end point coincide.";
- return false;
- }
- std::shared_ptr<GeomAPI_XYZ> aCenterPointXYZ = myCenterPoint->xyz();
- std::shared_ptr<GeomAPI_XYZ> aStartPointXYZ = myStartPoint->xyz();
- std::shared_ptr<GeomAPI_XYZ> aEndPointXYZ = myEndPoint->xyz();
- std::shared_ptr<GeomAPI_XYZ> vectCenterPointStartPoint =
- aStartPointXYZ->decreased(aCenterPointXYZ);
- std::shared_ptr<GeomAPI_XYZ> vectCenterPointEndPoint =
- aEndPointXYZ->decreased(aCenterPointXYZ);
- std::shared_ptr<GeomAPI_XYZ> crossProduct =
- vectCenterPointStartPoint->cross(vectCenterPointEndPoint);
- std::shared_ptr<GeomAPI_Pnt> aOriginPnt =
- std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
- std::shared_ptr<GeomAPI_XYZ> aOriginXYZ = aOriginPnt->xyz();
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setRotation(theCenterPoint, theStartPoint, theEndPoint);
- if (crossProduct->distance(aOriginXYZ) < Precision::Confusion()) {
- myError = "Rotation builder :: center point, start point and end point are on a line.";
- return false;
- }
- return true;
- }
- default: {
- myError = "Rotation builder :: method not implemented.";
- return false;
- }
- }
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
-void GeomAlgoAPI_Rotation::build()
+bool checkPoints(GeomPointPtr theCenterPoint,
+ GeomPointPtr theStartPoint,
+ GeomPointPtr theEndPoint,
+ std::string& theError)
{
- gp_Trsf* aTrsf = new gp_Trsf();
-
- switch (myMethodType) {
- case BY_ANGLE: {
- const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
- aTrsf->SetRotation(anAxis, myAngle/180.0*M_PI);
- break;
- }
- case BY_POINTS: {
- const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
- const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
- const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
- gp_Vec aVec1(aCenterPoint, aStartPoint);
- gp_Vec aVec2(aCenterPoint, aEndPoint);
- gp_Dir aDir(aVec1^aVec2);
- gp_Ax1 anAxis(aCenterPoint, aDir);
- double anAngle = aVec1.Angle(aVec2);
- if (fabs(anAngle) < Precision::Angular()) anAngle += 2.*M_PI;
- aTrsf->SetRotation(anAxis, anAngle);
- break;
- }
- default: {
- myError = "Rotation builder :: method not supported";
- return;
- }
+ if (!theCenterPoint) {
+ theError = "Rotation builder :: center point is not valid.";
+ return false;
}
-
- const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
-
- if(aSourceShape.IsNull()) {
- myError = "Rotation builder :: source shape does not contain any actual shape.";
- return;
+ if (!theStartPoint) {
+ theError = "Rotation builder :: start point is not valid.";
+ return false;
}
-
- // Transform the shape while copying it.
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
- if(!aBuilder) {
- myError = "Rotation builder :: transform initialization failed.";
- return;
+ if (!theEndPoint) {
+ theError = "Rotation builder :: end point is not valid.";
+ return false;
}
-
- setImpl(aBuilder);
- setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- if(!aBuilder->IsDone()) {
- myError = "Rotation builder :: algorithm failed.";
- return;
+ if (theCenterPoint->distance(theStartPoint) < Precision::Confusion()) {
+ theError = "Rotation builder :: center point and start point coincide.";
+ return false;
}
-
- TopoDS_Shape aResult = aBuilder->Shape();
-
- std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aResult));
- setShape(aShape);
- setDone(true);
+ if (theCenterPoint->distance(theEndPoint) < Precision::Confusion()) {
+ theError = "Rotation builder :: center point and end point coincide.";
+ return false;
+ }
+ if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
+ theError = "Rotation builder :: start point and end point coincide.";
+ return false;
+ }
+ std::shared_ptr<GeomAPI_XYZ> aCenterPointXYZ = theCenterPoint->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aStartPointXYZ = theStartPoint->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aEndPointXYZ = theEndPoint->xyz();
+ std::shared_ptr<GeomAPI_XYZ> vectCenterPointStartPoint =
+ aStartPointXYZ->decreased(aCenterPointXYZ);
+ std::shared_ptr<GeomAPI_XYZ> vectCenterPointEndPoint =
+ aEndPointXYZ->decreased(aCenterPointXYZ);
+ std::shared_ptr<GeomAPI_XYZ> crossProduct =
+ vectCenterPointStartPoint->cross(vectCenterPointEndPoint);
+
+ if (crossProduct->squareModulus() < Precision::SquareConfusion()) {
+ theError = "Rotation builder :: center point, start point and end point are on a line.";
+ return false;
+ }
+ return true;
}
#define GeomAlgoAPI_Rotation_H_
#include <GeomAlgoAPI.h>
-#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_Transform.h>
-#include <GeomAPI_Ax1.h>
-#include <GeomAPI_Shape.h>
+class GeomAPI_Ax1;
+class GeomAPI_Pnt;
/// \class GeomAlgoAPI_Rotation
/// \ingroup DataAlgo
/// \brief Creates a copy of the object by rotating it around the axis.
-class GeomAlgoAPI_Rotation : public GeomAlgoAPI_MakeShape
+class GeomAlgoAPI_Rotation : public GeomAlgoAPI_Transform
{
public:
- /// Type of rotation operation
- enum MethodType {
- BY_ANGLE, ///< Rotation by axis and an angle
- BY_POINTS ///< Rotation by a center and two points
- };
-
/// \brief Creates an object which is obtained from current object by rotating it around the axis
/// with the angle.
/// \param[in] theSourceShape a shape to be rotated.
std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
std::shared_ptr<GeomAPI_Pnt> theStartPoint,
std::shared_ptr<GeomAPI_Pnt> theEndPoint);
-
- /// Checks if data for the translation execution is OK.
- GEOMALGOAPI_EXPORT bool check();
-
- /// Execute the translation.
- GEOMALGOAPI_EXPORT void build();
-
-private:
- MethodType myMethodType; /// Type of method used.
- std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be rotated.
- std::shared_ptr<GeomAPI_Ax1> myAxis; /// Rotation axis.
- double myAngle; /// Rotation angle.
- std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Rotation center point.
- std::shared_ptr<GeomAPI_Pnt> myStartPoint; /// Rotation start point.
- std::shared_ptr<GeomAPI_Pnt> myEndPoint; /// Rotation end point.
};
#endif
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "GeomAlgoAPI_Scale.h"
+#include <GeomAlgoAPI_Scale.h>
+
+#include <GeomAPI_Pnt.h>
-#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
//=================================================================================================
std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
double theScaleFactor)
{
- myMethodType = BY_FACTOR;
- mySourceShape = theSourceShape;
- myCenterPoint = theCenterPoint;
- myScaleFactor = theScaleFactor;
+ if (fabs(theScaleFactor) < Precision::Confusion()) {
+ myError = "Scale builder :: the scale factor is null.";
+ return;
+ }
+
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setScale(theCenterPoint, theScaleFactor);
+
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
double theScaleFactorY,
double theScaleFactorZ)
{
- myMethodType = BY_DIMENSIONS;
- mySourceShape = theSourceShape;
- myCenterPoint = theCenterPoint;
- myScaleFactorX = theScaleFactorX;
- myScaleFactorY = theScaleFactorY;
- myScaleFactorZ = theScaleFactorZ;
-}
-
-//=================================================================================================
-bool GeomAlgoAPI_Scale::check()
-{
- if (!mySourceShape) {
- myError = "Scale builder :: source shape is not valid.";
- return false;
- }
- if (!myCenterPoint) {
- myError = "Scale builder :: center point is not valid.";
- return false;
- }
- switch (myMethodType) {
- case BY_FACTOR: {
- if (fabs(myScaleFactor) < Precision::Confusion()) {
- myError = "Scale builder :: the scale factor is null.";
- return false;
- }
- return true;
- }
- case BY_DIMENSIONS: {
- if (fabs(myScaleFactorX) < Precision::Confusion()) {
- myError = "Scale builder :: the scale factor in X is null.";
- return false;
- }
- if (fabs(myScaleFactorY) < Precision::Confusion()) {
- myError = "Scale builder :: the scale factor in Y is null.";
- return false;
- }
- if (fabs(myScaleFactorZ) < Precision::Confusion()) {
- myError = "Scale builder :: the scale factor in Z is null.";
- return false;
- }
- return true;
- }
- default: {
- myError = "Scale builder :: method not implemented.";
- return false;
- }
- }
-}
-
-//=================================================================================================
-void GeomAlgoAPI_Scale::build()
-{
- switch (myMethodType) {
- case BY_FACTOR : {
- buildByFactor();
- break;
- }
- case BY_DIMENSIONS : {
- buildByDimensions();
- break;
- }
- default : {
- myError = "Scale builder :: method not yet implemented";
- return;
- }
- }
-}
-
-//=================================================================================================
-void GeomAlgoAPI_Scale::buildByFactor()
-{
- const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
- gp_Trsf* aTrsf = new gp_Trsf();
- aTrsf->SetScale(aCenterPoint, myScaleFactor);
-
- const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
-
- if(aSourceShape.IsNull()) {
- myError = "Scale builder :: source shape does not contain any actual shape.";
+ if (fabs(theScaleFactorX) < Precision::Confusion()) {
+ myError = "Scale builder :: the scale factor in X is null.";
return;
}
-
- // Transform the shape while copying it.
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
- if(!aBuilder) {
- myError = "Scale builder :: transform initialization failed.";
+ if (fabs(theScaleFactorY) < Precision::Confusion()) {
+ myError = "Scale builder :: the scale factor in Y is null.";
return;
}
-
- setImpl(aBuilder);
- setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- if(!aBuilder->IsDone()) {
- myError = "Scale builder :: algorithm failed.";
+ if (fabs(theScaleFactorZ) < Precision::Confusion()) {
+ myError = "Scale builder :: the scale factor in Z is null.";
return;
}
- TopoDS_Shape aResult = aBuilder->Shape();
-
- std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aResult));
- setShape(aShape);
- setDone(true);
+ buildByDimensions(theSourceShape, theCenterPoint,
+ theScaleFactorX, theScaleFactorY, theScaleFactorZ);
}
//=================================================================================================
-void GeomAlgoAPI_Scale::buildByDimensions()
+void GeomAlgoAPI_Scale::buildByDimensions(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+ double theScaleFactorX,
+ double theScaleFactorY,
+ double theScaleFactorZ)
{
- const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
+ const gp_Pnt& aCenterPoint = theCenterPoint->impl<gp_Pnt>();
// Perform the rotation matrix
- gp_Mat aMatRot(myScaleFactorX, 0., 0.,
- 0., myScaleFactorY, 0.,
- 0., 0., myScaleFactorZ);
+ gp_Mat aMatRot(theScaleFactorX, 0., 0.,
+ 0., theScaleFactorY, 0.,
+ 0., 0., theScaleFactorZ);
// Perform the tranformation
- gp_Pnt anOriginPnt(0., 0., 0.);
gp_GTrsf aGTrsf;
gp_GTrsf aGTrsfP0;
gp_GTrsf aGTrsf0P;
- aGTrsfP0.SetTranslationPart(anOriginPnt.XYZ() - aCenterPoint.XYZ());
+ aGTrsfP0.SetTranslationPart(gp::Origin().XYZ() - aCenterPoint.XYZ());
aGTrsf0P.SetTranslationPart(aCenterPoint.XYZ());
aGTrsf.SetVectorialPart(aMatRot);
aGTrsf = aGTrsf0P.Multiplied(aGTrsf);
aGTrsf = aGTrsf.Multiplied(aGTrsfP0);
- const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
if(aSourceShape.IsNull()) {
myError = "Scale builder :: source shape does not contain any actual shape.";
#ifndef GEOMALGOAPI_SCALE_H_
#define GEOMALGOAPI_SCALE_H_
-#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI.h>
+#include <GeomAlgoAPI_Transform.h>
-#include <GeomAPI_Pnt.h>
+class GeomAPI_Pnt;
/// \class GeomAlgoAPI_Scale
/// \ingroup DataAlgo
/// \brief Creates a copy of the object by performing a scale operation by a factor or
/// by dimensions.
-class GeomAlgoAPI_Scale : public GeomAlgoAPI_MakeShape
+class GeomAlgoAPI_Scale : public GeomAlgoAPI_Transform
{
public:
- /// Type of scale operation
- enum MethodType {
- BY_FACTOR, ///< Scale by factor.
- BY_DIMENSIONS, ///< Scale by dimensions.
- };
-
/// \brief Creates an object which is obtained from current object by performing
/// a scale operation by a factor.
/// \param[in] theSourceShape the shape to be moved.
double theScaleFactorY,
double theScaleFactorZ);
- /// Checks if data for the scale transform is OK.
- GEOMALGOAPI_EXPORT bool check();
-
- /// Execute the scale transform.
- GEOMALGOAPI_EXPORT void build();
-
private:
- MethodType myMethodType; /// Type of method used.
- std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be moved.
- std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Center point.
- double myScaleFactor; /// Scale factor.
- double myScaleFactorX; /// Scale factor in X.
- double myScaleFactorY; /// Scale factor in Y.
- double myScaleFactorZ; /// Scale factor in Z.
-
- void buildByFactor();
- void buildByDimensions();
+ void buildByDimensions(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+ double theScaleFactorX,
+ double theScaleFactorY,
+ double theScaleFactorZ);
};
#endif // GEOMALGOAPI_SCALE_H_
\ No newline at end of file
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "GeomAlgoAPI_Symmetry.h"
+#include <GeomAlgoAPI_Symmetry.h>
-#include <BRepBuilderAPI_Transform.hxx>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Ax2.h>
//=================================================================================================
GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Pnt> thePoint)
{
- myMethodType = BY_POINT;
- mySourceShape = theSourceShape;
- myPoint = thePoint;
+ if (!thePoint) {
+ myError = "Symmetry builder :: point is not valid.";
+ return;
+ }
+
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setSymmetry(thePoint);
+
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis)
{
- myMethodType = BY_AXIS;
- mySourceShape = theSourceShape;
- myAxis = theAxis;
-}
+ if (!theAxis) {
+ myError = "Symmetry builder :: axis is not valid.";
+ return;
+ }
-//=================================================================================================
-GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax2> thePlane)
-{
- myMethodType = BY_PLANE;
- mySourceShape = theSourceShape;
- myPlane = thePlane;
-}
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setSymmetry(theAxis);
-//=================================================================================================
-bool GeomAlgoAPI_Symmetry::check()
-{
- switch (myMethodType) {
- case BY_POINT: {
- if (!myPoint) {
- myError = "Symmetry builder :: point is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Symmetry builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- case BY_AXIS: {
- if (!myAxis) {
- myError = "Symmetry builder :: axis is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Symmetry builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- case BY_PLANE: {
- if (!myPlane) {
- myError = "Symmetry builder :: plane is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Symmetry builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- default: {
- myError = "Symmetry builder :: method not implemented.";
- return false;
- }
- }
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
-void GeomAlgoAPI_Symmetry::build()
+GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax2> thePlane)
{
- gp_Trsf* aTrsf = new gp_Trsf();
-
- switch (myMethodType) {
- case BY_POINT: {
- const gp_Pnt& aPoint = myPoint->impl<gp_Pnt>();
- aTrsf->SetMirror(aPoint);
- break;
- }
- case BY_AXIS: {
- const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
- aTrsf->SetMirror(anAxis);
- break;
- }
- case BY_PLANE: {
- const gp_Ax2& aPlane = myPlane->impl<gp_Ax2>();
- aTrsf->SetMirror(aPlane);
- break;
- }
- default: {
- myError = "Symmetry builder :: method not supported";
- return;
- }
- }
-
- const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
-
- if(aSourceShape.IsNull()) {
- myError = "Symmetry builder :: source shape does not contain any actual shape.";
- return;
- }
-
- // Transform the shape while copying it.
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
- if(!aBuilder) {
- myError = "Symmetry builder :: transform initialization failed.";
- return;
- }
-
- setImpl(aBuilder);
- setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- if(!aBuilder->IsDone()) {
- myError = "Symmetry builder :: algorithm failed.";
+ if (!thePlane) {
+ myError = "Symmetry builder :: plane is not valid.";
return;
}
- TopoDS_Shape aResult = aBuilder->Shape();
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setSymmetry(thePlane);
- std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aResult));
- setShape(aShape);
- setDone(true);
+ build(theSourceShape, aTrsf);
}
#define GEOMALGOAPI_SYMMETRY_H_
#include <GeomAlgoAPI.h>
-#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_Transform.h>
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Ax1.h>
-#include <GeomAPI_Ax2.h>
+class GeomAPI_Ax1;
+class GeomAPI_Ax2;
+class GeomAPI_Pnt;
/// \class GeomAlgoAPI_Symmetry
/// \ingroup DataAlgo
/// \brief Creates a copy of the object by performing a symmetry operation by a point,
/// by an axis or by a plane.
-class GeomAlgoAPI_Symmetry : public GeomAlgoAPI_MakeShape
+class GeomAlgoAPI_Symmetry : public GeomAlgoAPI_Transform
{
public:
- /// Type of symmetry operation
- enum MethodType {
- BY_POINT, ///< Symmetry by point.
- BY_AXIS, ///< Symmetry by axis.
- BY_PLANE ///< Symmetry by plane.
- };
-
/// \brief Creates an object which is obtained from current object by performing
/// a symmetry operation by a point.
/// \param[in] theSourceShape the shape to be moved.
/// \param[in] thePlane the symmetry plane.
GEOMALGOAPI_EXPORT GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax2> thePlane);
-
- /// Checks if data for the symmetry execution is OK.
- GEOMALGOAPI_EXPORT bool check();
-
- /// Execute the symmetry.
- GEOMALGOAPI_EXPORT void build();
-
-private:
- MethodType myMethodType; /// Type of method used.
- std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be moved.
- std::shared_ptr<GeomAPI_Pnt> myPoint; /// Reflection point.
- std::shared_ptr<GeomAPI_Ax1> myAxis; /// Reflection axis.
- std::shared_ptr<GeomAPI_Ax2> myPlane; /// Reflection plane.
};
#endif // GEOMALGOAPI_SYMMETRY_H_
//=================================================================================================
GeomAlgoAPI_Transform::GeomAlgoAPI_Transform(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Trsf> theTrsf)
-: myTrsf(theTrsf)
{
build(theSourceShape, theTrsf);
}
void GeomAlgoAPI_Transform::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Trsf> theTrsf)
{
- if(!theSourceShape || !theTrsf) {
+ if (!theSourceShape || !theTrsf) {
+ myError = "Transformation :: incorrect input data";
return;
}
const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
const gp_Trsf& aTrsf = theTrsf->impl<gp_Trsf>();
- if(aSourceShape.IsNull()) {
+ if (aSourceShape.IsNull()) {
+ myError = "Transformation :: source shape does not contain any actual shape.";
return;
}
BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
- if(!aBuilder) {
+ if (!aBuilder)
return;
- }
- this->setImpl(aBuilder);
- this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
- if(aBuilder->IsDone() != Standard_True) {
+ setImpl(aBuilder);
+ setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
+
+ if (aBuilder->IsDone() != Standard_True)
return;
- }
+
TopoDS_Shape aResult = aBuilder->Shape();
std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(aResult));
- this->setShape(aShape);
- this->setDone(true);
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Transform::transformation() const
-{
- return myTrsf;
+ setShape(aShape);
+ setDone(true);
}
GEOMALGOAPI_EXPORT GeomAlgoAPI_Transform(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Trsf> theTrsf);
- /// \return the transformation.
- GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Trsf> transformation() const;
+protected:
+ /// \brief Default constructor (to be used in the derived classes)
+ GeomAlgoAPI_Transform() {}
-private:
/// Builds resulting shape.
void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Trsf> theTrsf);
-
-private:
- std::shared_ptr<GeomAPI_Trsf> myTrsf;
};
#endif
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "GeomAlgoAPI_Translation.h"
+#include <GeomAlgoAPI_Translation.h>
+
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Shape.h>
-#include <BRepBuilderAPI_Transform.hxx>
#include <Precision.hxx>
-#include <gp_Ax1.hxx>
//=================================================================================================
GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance)
{
- myMethodType = BY_DISTANCE;
- mySourceShape = theSourceShape;
- myAxis = theAxis;
- myDistance = theDistance;
+ if (!theAxis) {
+ myError = "Translation builder :: axis is not valid.";
+ return;
+ }
+
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theAxis, theDistance);
+
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
double theDy,
double theDz)
{
- myMethodType = BY_DIM;
- mySourceShape = theSourceShape;
- myDx = theDx;
- myDy = theDy;
- myDz = theDz;
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theDx, theDy, theDz);
+
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
std::shared_ptr<GeomAPI_Pnt> theStartPoint,
std::shared_ptr<GeomAPI_Pnt> theEndPoint)
{
- myMethodType = BY_POINTS;
- mySourceShape = theSourceShape;
- myStartPoint = theStartPoint;
- myEndPoint = theEndPoint;
-}
-
-//=================================================================================================
-bool GeomAlgoAPI_Translation::check()
-{
- switch (myMethodType) {
- case BY_DISTANCE: {
- if (!myAxis) {
- myError = "Translation builder :: axis is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Translation builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- case BY_DIM: {
- if (!mySourceShape) {
- myError = "Translation builder :: source shape is not valid.";
- return false;
- }
- return true;
- }
- case BY_POINTS: {
- if (!myStartPoint) {
- myError = "Translation builder :: start point is not valid.";
- return false;
- }
- if (!myEndPoint) {
- myError = "Translation builder :: end point is not valid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Translation builder :: source shape is invalid.";
- return false;
- }
- if(myStartPoint->distance(myEndPoint) < Precision::Confusion()) {
- myError = "Translation builder :: start point and end point coincide.";
- return false;
- }
- return true;
- }
- default: {
- myError = "Translation builder :: method not implemented.";
- return false;
- }
- }
-}
-
-//=================================================================================================
-void GeomAlgoAPI_Translation::build()
-{
- gp_Trsf* aTrsf = new gp_Trsf();
-
- switch (myMethodType) {
- case BY_DISTANCE: {
- const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
- aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
- break;
- }
- case BY_DIM: {
- aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
- break;
- }
- case BY_POINTS: {
- const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
- const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
- aTrsf->SetTranslation(aStartPoint, aEndPoint);
- break;
- }
- default: {
- myError = "Translation builder :: method not supported";
- return;
- }
- }
-
- const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
-
- if(aSourceShape.IsNull()) {
- myError = "Translation builder :: source shape does not contain any actual shape.";
+ if (!theStartPoint) {
+ myError = "Translation builder :: start point is not valid.";
return;
}
-
- // Transform the shape while copying it.
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
- if(!aBuilder) {
- myError = "Translation builder :: transform initialization failed.";
+ if (!theEndPoint) {
+ myError = "Translation builder :: end point is not valid.";
return;
}
-
- setImpl(aBuilder);
- setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- if(!aBuilder->IsDone()) {
- myError = "Translation builder :: algorithm failed.";
+ if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
+ myError = "Translation builder :: start point and end point coincide.";
return;
}
- TopoDS_Shape aResult = aBuilder->Shape();
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theStartPoint, theEndPoint);
- std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aResult));
- setShape(aShape);
- setDone(true);
+ build(theSourceShape, aTrsf);
}
#define GeomAlgoAPI_Translation_H_
#include <GeomAlgoAPI.h>
-#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_Transform.h>
-#include <GeomAPI_Ax1.h>
-#include <GeomAPI_Shape.h>
+class GeomAPI_Ax1;
+class GeomAPI_Pnt;
/// \class GeomAlgoAPI_Translation
/// \ingroup DataAlgo
/// \brief Creates a copy of the object by moving it along the axis.
-class GeomAlgoAPI_Translation : public GeomAlgoAPI_MakeShape
+class GeomAlgoAPI_Translation : public GeomAlgoAPI_Transform
{
public:
- /// Type of translation operation
- enum MethodType {
- BY_DISTANCE, ///< Translation by axis and distance
- BY_DIM, ///< Translation by dimensions in X, Y and Z
- BY_POINTS ///< Translation by two points
- };
-
/// \brief Creates an object which is obtained from current object by moving it along the axis.
/// \param[in] theSourceShape a shape to be moved.
/// \param[in] theAxis movement axis.
GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Pnt> theStartPoint,
std::shared_ptr<GeomAPI_Pnt> theEndPoint);
-
- /// Checks if data for the translation execution is OK.
- GEOMALGOAPI_EXPORT bool check();
-
- /// Execute the translation.
- GEOMALGOAPI_EXPORT void build();
-
-private:
- MethodType myMethodType; /// Type of method used.
- std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be moved.
- std::shared_ptr<GeomAPI_Ax1> myAxis; /// Movement axis.
- double myDistance; /// Movement distance.
- double myDx; /// Movement dimension on X.
- double myDy; /// Movement dimension on Y.
- double myDz; /// Movement dimension on Z.
- std::shared_ptr<GeomAPI_Pnt> myStartPoint; /// Movement start point.
- std::shared_ptr<GeomAPI_Pnt> myEndPoint; /// Movement end point.
};
#endif