23
#include "PreCompiled.h"
25
# include <Geom_Parabola.hxx>
26
# include <gce_MakeParab.hxx>
29
#include <Base/GeometryPyCXX.h>
30
#include <Base/PyWrapParseTupleAndKeywords.h>
31
#include <Base/VectorPy.h>
33
#include "ParabolaPy.h"
34
#include "ParabolaPy.cpp"
40
extern const char* gce_ErrorStatusText(gce_ErrorType et);
43
std::string ParabolaPy::representation() const
45
return "<Parabola object>";
48
PyObject *ParabolaPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
51
return new ParabolaPy(new GeomParabola);
55
int ParabolaPy::PyInit(PyObject* args, PyObject* kwds)
57
static const std::array<const char *, 1> keywords_n {nullptr};
58
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
59
Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(getGeomParabolaPtr()->handle());
60
parabola->SetFocal(1.0);
64
static const std::array<const char *, 2> keywords_e {"Parabola", nullptr};
67
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(ParabolaPy::Type), &pParab)) {
68
ParabolaPy* pParabola = static_cast<ParabolaPy*>(pParab);
69
Handle(Geom_Parabola) Parab1 = Handle(Geom_Parabola)::DownCast
70
(pParabola->getGeomParabolaPtr()->handle());
71
Handle(Geom_Parabola) Parab2 = Handle(Geom_Parabola)::DownCast
72
(this->getGeomParabolaPtr()->handle());
73
Parab2->SetParab(Parab1->Parab());
77
static const std::array<const char *, 4> keywords_ssc {"Focus","Center","Normal",nullptr};
79
PyObject *pV1, *pV2, *pV3;
80
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc,
81
&(Base::VectorPy::Type), &pV1,
82
&(Base::VectorPy::Type), &pV2,
83
&(Base::VectorPy::Type), &pV3)) {
84
Base::Vector3d focus = static_cast<Base::VectorPy*>(pV1)->value();
85
Base::Vector3d center = static_cast<Base::VectorPy*>(pV2)->value();
86
Base::Vector3d normal = static_cast<Base::VectorPy*>(pV3)->value();
88
Base::Vector3d xvect = focus-center;
91
gp_Pnt p1(center.x,center.y,center.z);
92
gp_Dir norm(normal.x,normal.y,normal.z);
93
gp_Dir xdiroce(xvect.x,xvect.y,xvect.z);
95
gp_Ax2 xdir(p1, norm, xdiroce);
97
gce_MakeParab mc(xdir, (Standard_Real) xvect.Length());
99
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
103
Handle(Geom_Parabola) parabola = Handle(Geom_Parabola)::DownCast(getGeomParabolaPtr()->handle());
104
parabola->SetParab(mc.Value());
108
PyErr_SetString(PyExc_TypeError, "Parabola constructor accepts:\n"
109
"-- empty parameter list\n"
111
"-- Point, Point, Point");
116
PyObject* ParabolaPy::compute(PyObject *args)
118
PyObject *p1, *p2, *p3;
119
if (!PyArg_ParseTuple(args, "O!O!O!",
120
&Base::VectorPy::Type,&p1,
121
&Base::VectorPy::Type,&p2,
122
&Base::VectorPy::Type,&p3))
124
Base::Vector3d v1 = Py::Vector(p1,false).toVector();
125
Base::Vector3d v2 = Py::Vector(p2,false).toVector();
126
Base::Vector3d v3 = Py::Vector(p3,false).toVector();
127
Base::Vector3d c = (v1-v2) % (v3-v2);
128
double zValue = v1.z;
129
if (fabs(c.Length()) < 0.0001) {
130
PyErr_SetString(PartExceptionOCCError, "Points are collinear");
136
m[0][0] = v1.y * v1.y;
139
m[1][0] = v2.y * v2.y;
142
m[2][0] = v3.y * v3.y;
152
double a20 = v.y/2.0;
154
Handle(Geom_Parabola) curve = Handle(Geom_Parabola)::DownCast(getGeometryPtr()->handle());
155
curve->SetFocal(0.5*fabs(a10/a22));
156
curve->SetLocation(gp_Pnt((a20*a20-a22*a00)/(2*a22*a10), -a20/a22, zValue));
161
Py::Float ParabolaPy::getFocal() const
163
Handle(Geom_Parabola) curve = Handle(Geom_Parabola)::DownCast(getGeometryPtr()->handle());
164
return Py::Float(curve->Focal());
167
void ParabolaPy::setFocal(Py::Float arg)
169
Handle(Geom_Parabola) curve = Handle(Geom_Parabola)::DownCast(getGeometryPtr()->handle());
170
curve->SetFocal((double)arg);
173
Py::Object ParabolaPy::getFocus() const
175
Handle(Geom_Parabola) c = Handle(Geom_Parabola)::DownCast
176
(getGeometryPtr()->handle());
177
gp_Pnt loc = c->Focus();
178
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
181
Py::Float ParabolaPy::getParameter() const
183
Handle(Geom_Parabola) curve = Handle(Geom_Parabola)::DownCast(getGeometryPtr()->handle());
184
return Py::Float(curve->Parameter());
187
PyObject *ParabolaPy::getCustomAttributes(const char* ) const
192
int ParabolaPy::setCustomAttributes(const char* , PyObject* )