From 579cbb280b71d038b1c5f63fcc836ab115bb2d30 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 17 Dec 2016 23:21:47 +0100 Subject: [PATCH] Part: ArcOfParabola extension to set the symmetry axis --- src/Mod/Part/App/Geometry.cpp | 43 +++++++++++++++++++++++++++++++++++ src/Mod/Part/App/Geometry.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 342c55785..fcdea9f0c 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -2322,6 +2322,49 @@ void GeomArcOfParabola::setFocal(double length) } } +/*! + * \brief GeomArcOfParabola::getXAxisDir + * \return the direction vector (unit-length) of symmetry axis of the parabola. The + * direction also points to the focus. + */ +Base::Vector3d GeomArcOfParabola::getXAxisDir() const +{ + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast( myCurve->BasisCurve() ); + assert(!c.IsNull()); + gp_Dir xdir = c->XAxis().Direction(); + return Base::Vector3d(xdir.X(), xdir.Y(), xdir.Z()); +} + +/*! + * \brief GeomArcOfParabola::setXAxisDir Rotates the parabola in its plane, so + * that its symmetry axis is as close as possible to the provided direction. + * \param newdir [in] is the new direction. If the vector is small, the + * orientation of the parabola will be preserved. If the vector is not small, + * but its projection onto plane of the parabola is small, an exception will be + * thrown. + */ +void GeomArcOfParabola::setXAxisDir(Base::Vector3d newdir) +{ + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast( myCurve->BasisCurve() ); + assert(!c.IsNull()); + #if OCC_VERSION_HEX >= 0x060504 + if (newdir.Sqr() < Precision::SquareConfusion()) + #else + if (newdir.Length() < Precision::Confusion()) + #endif + return;//zero vector was passed. Keep the old orientation. + + try { + gp_Ax2 pos = c->Position(); + pos.SetXDirection(gp_Dir(newdir.x, newdir.y, newdir.z));//OCC should keep the old main Direction (Z), and change YDirection to accomodate the new XDirection. + c->SetPosition(pos); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + Base::Vector3d GeomArcOfParabola::getFocus(void) const { Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 4c49aeba7..8f2e8a1d5 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -497,6 +497,9 @@ public: double getFocal(void) const; void setFocal(double length); + Base::Vector3d getXAxisDir() const; + void setXAxisDir(Base::Vector3d newdir); + Base::Vector3d getFocus(void) const; virtual void getRange(double& u, double& v, bool emulateCCWXY) const;