Merge pull request #401 from abdullahtahiriyo/parabola_2017

Parabola 2017
This commit is contained in:
wwmayer
2016-12-28 13:48:13 +01:00
committed by GitHub
29 changed files with 4493 additions and 265 deletions

View File

@@ -2322,9 +2322,61 @@ void GeomArcOfParabola::setFocal(double length)
}
}
void GeomArcOfParabola::getRange(double& u, double& v, bool /*emulateCCWXY*/) const
/*!
* \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
{
#if 0
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());
gp_Pnt gp = p->Focus();
return Base::Vector3d(gp.X(),gp.Y(),gp.Z());
}
void GeomArcOfParabola::getRange(double& u, double& v, bool emulateCCWXY) const
{
//#if 0
try {
if (emulateCCWXY) {
if (isReversed()) {
@@ -2338,17 +2390,17 @@ void GeomArcOfParabola::getRange(double& u, double& v, bool /*emulateCCWXY*/) co
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::Exception(e->GetMessageString());
}
#endif
//#endif
u = myCurve->FirstParameter();
v = myCurve->LastParameter();
}
void GeomArcOfParabola::setRange(double u, double v, bool /*emulateCCWXY*/)
void GeomArcOfParabola::setRange(double u, double v, bool emulateCCWXY)
{
try {
myCurve->SetTrim(u, v);
#if 0
//#if 0
if (emulateCCWXY) {
if (isReversed()) {
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve());
@@ -2356,7 +2408,7 @@ void GeomArcOfParabola::setRange(double u, double v, bool /*emulateCCWXY*/)
c->Reverse();
}
}
#endif
//#endif
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
@@ -2408,7 +2460,7 @@ void GeomArcOfParabola::Restore(Base::XMLReader &reader)
double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,Focal,AngleXU,StartAngle,EndAngle;
// read my Element
reader.readElement("ArcOfHyperbola");
reader.readElement("ArcOfParabola");
// get the value of my Attribute
CenterX = reader.getAttributeAsFloat("CenterX");
CenterY = reader.getAttributeAsFloat("CenterY");

View File

@@ -497,6 +497,11 @@ 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;
virtual void setRange(double u, double v, bool emulateCCWXY);

View File

@@ -24,6 +24,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Geom_Parabola.hxx>
# include <gp_Parab.hxx>
#include <gce_MakeParab.hxx>
#endif
#include <Base/VectorPy.h>
@@ -36,6 +38,8 @@
using namespace Part;
extern const char* gce_ErrorStatusText(gce_ErrorType et);
// returns a string which represents the object e.g. when printed in python
std::string ParabolaPy::representation(void) const
{
@@ -49,15 +53,65 @@ PyObject *ParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // P
}
// constructor method
int ParabolaPy::PyInit(PyObject* args, PyObject* /*kwd*/)
int ParabolaPy::PyInit(PyObject* args, PyObject* kwds)
{
if (PyArg_ParseTuple(args, "")) {
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
(getGeometryPtr()->handle());
c->SetFocal(1.0);
char* keywords_n[] = {NULL};
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(getGeomParabolaPtr()->handle());
parabola->SetFocal(1.0);
return 0;
}
char* keywords_e[] = {"Parabola",NULL};
PyErr_Clear();
PyObject *pParab;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(ParabolaPy::Type), &pParab)) {
ParabolaPy* pParabola = static_cast<ParabolaPy*>(pParab);
Handle_Geom_Parabola Parab1 = Handle_Geom_Parabola::DownCast
(pParabola->getGeomParabolaPtr()->handle());
Handle_Geom_Parabola Parab2 = Handle_Geom_Parabola::DownCast
(this->getGeomParabolaPtr()->handle());
Parab2->SetParab(Parab1->Parab());
return 0;
}
char* keywords_ssc[] = {"Focus","Center","Normal",NULL};
PyErr_Clear();
PyObject *pV1, *pV2, *pV3;
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc,
&(Base::VectorPy::Type), &pV1,
&(Base::VectorPy::Type), &pV2,
&(Base::VectorPy::Type), &pV3)) {
Base::Vector3d focus = static_cast<Base::VectorPy*>(pV1)->value();
Base::Vector3d center = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d normal = static_cast<Base::VectorPy*>(pV3)->value();
Base::Vector3d xvect = focus-center;
// set the geometry
gp_Pnt p1(center.x,center.y,center.z);
gp_Dir norm(normal.x,normal.y,normal.z);
gp_Dir xdiroce(xvect.x,xvect.y,xvect.z);
gp_Ax2 xdir(p1, norm, xdiroce);
gce_MakeParab mc(xdir, (Standard_Real) xvect.Length());
if (!mc.IsDone()) {
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
return -1;
}
Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(getGeomParabolaPtr()->handle());
parabola->SetParab(mc.Value());
return 0;
}
PyErr_SetString(PyExc_TypeError, "Parabola constructor accepts:\n"
"-- empty parameter list\n"
"-- Parabola\n"
"-- Point, Point, Point");
return -1;
}