implement Conic2d and Parabola2d
This commit is contained in:
parent
21dcfd442c
commit
94248e8da1
|
@ -12,37 +12,15 @@
|
|||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>Describes a circle in 3D space
|
||||
To create a circle there are several ways:
|
||||
Part.Circle()
|
||||
Creates a default circle with center (0,0,0) and radius 1
|
||||
|
||||
Part.Circle(Circle)
|
||||
Creates a copy of the given circle
|
||||
|
||||
Part.Circle(Circle, Distance)
|
||||
Creates a circle parallel to given circle at a certain distance
|
||||
|
||||
Part.Circle(Center,Normal,Radius)
|
||||
Creates a circle defined by center, normal direction and radius
|
||||
|
||||
Part.Circle(Point1,Point2,Point3)
|
||||
Creates a circle defined by three non-linear points
|
||||
<UserDocu>Describes an abstract conic in 2d space
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<!--
|
||||
<Attribute Name="Center" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Center of the circle.</UserDocu>
|
||||
<UserDocu>Center of the conic.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Center" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Axis" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The axis direction of the circle</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Axis" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="XAxis" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The X axis direction of the circle</UserDocu>
|
||||
|
@ -55,6 +33,5 @@ Part.Circle(Point1,Point2,Point3)
|
|||
</Documentation>
|
||||
<Parameter Name="YAxis" Type="Object"/>
|
||||
</Attribute>
|
||||
-->
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -23,9 +23,7 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <gp_Circ.hxx>
|
||||
# include <Geom_Circle.hxx>
|
||||
# include <GC_MakeCircle.hxx>
|
||||
# include <Geom2d_Conic.hxx>
|
||||
#endif
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
|
@ -33,277 +31,89 @@
|
|||
#include <Mod/Part/App/Geom2d/Conic2dPy.cpp>
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
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 Conic2dPy::representation(void) const
|
||||
{
|
||||
#if 0
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->Axis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
gp_Pnt loc = axis.Location();
|
||||
Standard_Real fRad = circle->Radius();
|
||||
|
||||
std::stringstream str;
|
||||
str << "Circle (";
|
||||
str << "Radius : " << fRad << ", ";
|
||||
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
|
||||
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << ")";
|
||||
str << ")";
|
||||
|
||||
return str.str();
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
return "<Conic2d object>";
|
||||
}
|
||||
|
||||
PyObject *Conic2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// never create such objects with the constructor
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"You cannot create an instance of the abstract class 'Conic2d'.");
|
||||
return 0;
|
||||
#if 0
|
||||
// create a new instance of Conic2dPy and the Twin object
|
||||
Handle_Geom_Circle circle = new Geom_Circle(gp_Circ());
|
||||
return new Conic2dPy(new GeomCircle(circle));
|
||||
#endif
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int Conic2dPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
return -1;
|
||||
#if 0
|
||||
// circle and distance for offset
|
||||
PyObject *pCirc;
|
||||
double dist;
|
||||
static char* keywords_cd[] = {"Circle","Distance",NULL};
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(Conic2dPy::Type), &pCirc, &dist)) {
|
||||
Conic2dPy* pcCircle = static_cast<Conic2dPy*>(pCirc);
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast
|
||||
(pcCircle->getGeomCirclePtr()->handle());
|
||||
GC_MakeCircle mc(circle->Circ(), dist);
|
||||
if (!mc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
circ->SetCirc(mc.Value()->Circ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// center, normal and radius
|
||||
PyObject *pV1, *pV2, *pV3;
|
||||
static char* keywords_cnr[] = {"Center","Normal","Radius",NULL};
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!d", keywords_cnr,
|
||||
&(Base::VectorPy::Type), &pV1,
|
||||
&(Base::VectorPy::Type), &pV2,
|
||||
&dist)) {
|
||||
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
|
||||
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
|
||||
GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Dir(v2.x,v2.y,v2.z),
|
||||
dist);
|
||||
if (!mc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
circle->SetCirc(mc.Value()->Circ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char* keywords_c[] = {"Circle",NULL};
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(Conic2dPy::Type), &pCirc)) {
|
||||
Conic2dPy* pcCircle = static_cast<Conic2dPy*>(pCirc);
|
||||
Handle_Geom_Circle circ1 = Handle_Geom_Circle::DownCast
|
||||
(pcCircle->getGeomCirclePtr()->handle());
|
||||
Handle_Geom_Circle circ2 = Handle_Geom_Circle::DownCast
|
||||
(this->getGeomCirclePtr()->handle());
|
||||
circ2->SetCirc(circ1->Circ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL};
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp,
|
||||
&(Base::VectorPy::Type), &pV1,
|
||||
&(Base::VectorPy::Type), &pV2,
|
||||
&(Base::VectorPy::Type), &pV3)) {
|
||||
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
|
||||
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
|
||||
Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
|
||||
GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Pnt(v2.x,v2.y,v2.z),
|
||||
gp_Pnt(v3.x,v3.y,v3.z));
|
||||
if (!mc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
circle->SetCirc(mc.Value()->Circ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// default circle
|
||||
static char* keywords_n[] = {NULL};
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
circle->SetRadius(1.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Circle constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- Circle\n"
|
||||
"-- Circle, Distance\n"
|
||||
"-- Center, Normal, Radius\n"
|
||||
"-- Point1, Point2, Point3");
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
|
||||
Py::Object Conic2dPy::getCenter(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Pnt loc = circle->Location();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
Base::Vector2d loc = getGeom2dConicPtr()->getCenter();
|
||||
|
||||
Py::Module module("__FreeCADBase__");
|
||||
Py::Callable method(module.getAttr("Vector2d"));
|
||||
Py::Tuple arg(2);
|
||||
arg.setItem(0, Py::Float(loc.x));
|
||||
arg.setItem(1, Py::Float(loc.y));
|
||||
return method.apply(arg);
|
||||
}
|
||||
|
||||
void Conic2dPy::setCenter(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
|
||||
getGeomCirclePtr()->setCenter(loc);
|
||||
}
|
||||
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
|
||||
Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
|
||||
getGeomCirclePtr()->setCenter(loc);
|
||||
} else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object Conic2dPy::getAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->Axis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void Conic2dPy::setAxis(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
Base::Vector3d val;
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
val = static_cast<Base::VectorPy*>(p)->value();
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
val = Base::getVectorFromTuple<double>(p);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax1 axis;
|
||||
axis.SetLocation(circle->Location());
|
||||
axis.SetDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetAxis(axis);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set axis");
|
||||
}
|
||||
Base::Vector2d loc = Py::Vector2d(arg.ptr()).getCxxObject()->value();
|
||||
getGeom2dConicPtr()->setCenter(loc);
|
||||
}
|
||||
|
||||
Py::Object Conic2dPy::getXAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->XAxis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(getGeom2dConicPtr()->handle());
|
||||
gp_Dir2d xdir = conic->XAxis().Direction();
|
||||
Py::Module module("__FreeCADBase__");
|
||||
Py::Callable method(module.getAttr("Vector2d"));
|
||||
Py::Tuple arg(2);
|
||||
arg.setItem(0, Py::Float(xdir.X()));
|
||||
arg.setItem(1, Py::Float(xdir.Y()));
|
||||
return method.apply(arg);
|
||||
}
|
||||
|
||||
void Conic2dPy::setXAxis(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
Base::Vector3d val;
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
val = static_cast<Base::VectorPy*>(p)->value();
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
val = Base::getVectorFromTuple<double>(p);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax2 pos;
|
||||
pos = circle->Position();
|
||||
pos.SetXDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetPosition(pos);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set X axis");
|
||||
}
|
||||
Base::Vector2d dir = Py::Vector2d(arg.ptr()).getCxxObject()->value();
|
||||
Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(getGeom2dConicPtr()->handle());
|
||||
gp_Ax2d xaxis = conic->XAxis();
|
||||
xaxis.SetDirection(gp_Dir2d(dir.x, dir.y));
|
||||
conic->SetXAxis(xaxis);
|
||||
}
|
||||
|
||||
Py::Object Conic2dPy::getYAxis(void) const
|
||||
{
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
gp_Ax1 axis = circle->YAxis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(getGeom2dConicPtr()->handle());
|
||||
gp_Dir2d ydir = conic->YAxis().Direction();
|
||||
Py::Module module("__FreeCADBase__");
|
||||
Py::Callable method(module.getAttr("Vector2d"));
|
||||
Py::Tuple arg(2);
|
||||
arg.setItem(0, Py::Float(ydir.X()));
|
||||
arg.setItem(1, Py::Float(ydir.Y()));
|
||||
return method.apply(arg);
|
||||
}
|
||||
|
||||
void Conic2dPy::setYAxis(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
Base::Vector3d val;
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
val = static_cast<Base::VectorPy*>(p)->value();
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
val = Base::getVectorFromTuple<double>(p);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
|
||||
try {
|
||||
gp_Ax2 pos;
|
||||
pos = circle->Position();
|
||||
pos.SetYDirection(gp_Dir(val.x, val.y, val.z));
|
||||
circle->SetPosition(pos);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set Y axis");
|
||||
}
|
||||
Base::Vector2d dir = Py::Vector2d(arg.ptr()).getCxxObject()->value();
|
||||
Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(getGeom2dConicPtr()->handle());
|
||||
gp_Ax2d yaxis = conic->YAxis();
|
||||
yaxis.SetDirection(gp_Dir2d(dir.x, dir.y));
|
||||
conic->SetYAxis(yaxis);
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject *Conic2dPy::getCustomAttributes(const char* ) const
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -85,7 +85,7 @@ PyObject *Curve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Py
|
|||
{
|
||||
// never create such objects with the constructor
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"You cannot create an instance of the abstract class 'GeometryCurve'.");
|
||||
"You cannot create an instance of the abstract class 'Curve2d'.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ PyObject* Geometry2dPy::mirror(PyObject *args)
|
|||
{
|
||||
PyObject* o;
|
||||
if (PyArg_ParseTuple(args, "O!", Base::Vector2dPy::type_object(),&o)) {
|
||||
Base::Vector2d vec = static_cast<Base::Vector2dPy*>(o)->value();
|
||||
Base::Vector2d vec = Py::Vector2d(o).getCxxObject()->value();
|
||||
gp_Pnt2d pnt(vec.x, vec.y);
|
||||
getGeometry2dPtr()->handle()->Mirror(pnt);
|
||||
Py_Return;
|
||||
|
@ -86,8 +86,8 @@ PyObject* Geometry2dPy::mirror(PyObject *args)
|
|||
PyObject* axis;
|
||||
if (PyArg_ParseTuple(args, "O!O!", Base::Vector2dPy::type_object(),&o,
|
||||
Base::Vector2dPy::type_object(),&axis)) {
|
||||
Base::Vector2d pnt = static_cast<Base::Vector2dPy*>(o)->value();
|
||||
Base::Vector2d dir = static_cast<Base::Vector2dPy*>(axis)->value();
|
||||
Base::Vector2d pnt = Py::Vector2d(o).getCxxObject()->value();
|
||||
Base::Vector2d dir = Py::Vector2d(axis).getCxxObject()->value();
|
||||
gp_Ax2d ax1(gp_Pnt2d(pnt.x,pnt.y), gp_Dir2d(dir.x,dir.y));
|
||||
getGeometry2dPtr()->handle()->Mirror(ax1);
|
||||
Py_Return;
|
||||
|
@ -103,7 +103,7 @@ PyObject* Geometry2dPy::rotate(PyObject *args)
|
|||
double angle;
|
||||
Base::Vector2d vec;
|
||||
if (PyArg_ParseTuple(args, "O!d", Base::Vector2dPy::type_object(), &o, &angle)) {
|
||||
vec = static_cast<Base::Vector2dPy*>(o)->value();
|
||||
vec = Py::Vector2d(o).getCxxObject()->value();
|
||||
gp_Pnt2d pnt(vec.x, vec.y);
|
||||
getGeometry2dPtr()->handle()->Rotate(pnt, angle);
|
||||
Py_Return;
|
||||
|
@ -119,7 +119,7 @@ PyObject* Geometry2dPy::scale(PyObject *args)
|
|||
double scale;
|
||||
Base::Vector2d vec;
|
||||
if (PyArg_ParseTuple(args, "O!d", Base::Vector2dPy::type_object(), &o, &scale)) {
|
||||
vec = static_cast<Base::Vector2dPy*>(o)->value();
|
||||
vec = Py::Vector2d(o).getCxxObject()->value();
|
||||
gp_Pnt2d pnt(vec.x, vec.y);
|
||||
getGeometry2dPtr()->handle()->Scale(pnt, scale);
|
||||
Py_Return;
|
||||
|
@ -161,7 +161,7 @@ PyObject* Geometry2dPy::translate(PyObject *args)
|
|||
PyObject* o;
|
||||
Base::Vector2d vec;
|
||||
if (PyArg_ParseTuple(args, "O!", Base::Vector2dPy::type_object(),&o)) {
|
||||
vec = static_cast<Base::Vector2dPy*>(o)->value();
|
||||
vec = Py::Vector2d(o).getCxxObject()->value();
|
||||
gp_Vec2d trl(vec.x, vec.y);
|
||||
getGeometry2dPtr()->handle()->Translate(trl);
|
||||
Py_Return;
|
||||
|
|
|
@ -12,31 +12,22 @@
|
|||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>Describes a parabola in 3D space</UserDocu>
|
||||
<UserDocu>Describes a parabola in 2D space</UserDocu>
|
||||
</Documentation>
|
||||
<!--
|
||||
<Methode Name="compute">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
compute(p1,p2,p3)
|
||||
The three points must lie on a plane parallel to xy plane and must not be collinear
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="Eccentricity" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Returns 1. (which is the eccentricity of any parabola).</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Eccentricity" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focal" ReadOnly="false">
|
||||
<Attribute Name="Focal" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The focal distance is the distance between
|
||||
the apex and the focus of the parabola.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Focal" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Focus" ReadOnly="true">
|
||||
<Attribute Name="Focus" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The focus is on the positive side of the
|
||||
'X Axis' of the local coordinate system of the parabola.</UserDocu>
|
||||
|
@ -52,18 +43,5 @@ and its directrix. This distance is twice the focal length.
|
|||
</Documentation>
|
||||
<Parameter Name="Parameter" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Location" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Location of the parabola</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Location" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Axis" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The axis direction of the parabola</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Axis" Type="Object"/>
|
||||
</Attribute>
|
||||
-->
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -60,161 +60,44 @@ int Parabola2dPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
|||
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
PyObject* Parabola2dPy::compute(PyObject *args)
|
||||
{
|
||||
PyObject *p1, *p2, *p3;
|
||||
if (!PyArg_ParseTuple(args, "O!O!O!",
|
||||
&Base::VectorPy::Type,&p1,
|
||||
&Base::VectorPy::Type,&p2,
|
||||
&Base::VectorPy::Type,&p3))
|
||||
return 0;
|
||||
Base::Vector3d v1 = Py::Vector(p1,false).toVector();
|
||||
Base::Vector3d v2 = Py::Vector(p2,false).toVector();
|
||||
Base::Vector3d v3 = Py::Vector(p3,false).toVector();
|
||||
Base::Vector3d c = (v1-v2) % (v3-v2);
|
||||
double zValue = v1.z;
|
||||
if (fabs(c.Length()) < 0.0001) {
|
||||
PyErr_SetString(PartExceptionOCCError, "Points are collinear");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Base::Matrix4D m;
|
||||
Base::Vector3d v;
|
||||
m[0][0] = v1.y * v1.y;
|
||||
m[0][1] = v1.y;
|
||||
m[0][2] = 1;
|
||||
m[1][0] = v2.y * v2.y;
|
||||
m[1][1] = v2.y;
|
||||
m[1][2] = 1;
|
||||
m[2][0] = v3.y * v3.y;
|
||||
m[2][1] = v3.y;
|
||||
m[2][2] = 1.0;
|
||||
v.x = v1.x;
|
||||
v.y = v2.x;
|
||||
v.z = v3.x;
|
||||
m.inverseGauss();
|
||||
v = m * v;
|
||||
double a22 = v.x;
|
||||
double a10 = -0.5;
|
||||
double a20 = v.y/2.0;
|
||||
double a00 = v.z;
|
||||
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
|
||||
curve->SetFocal(0.5*fabs(a10/a22));
|
||||
curve->SetLocation(gp_Pnt((a20*a20-a22*a00)/(2*a22*a10), -a20/a22, zValue));
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
Py::Float Parabola2dPy::getEccentricity(void) const
|
||||
{
|
||||
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom2d_Parabola curve = Handle_Geom2d_Parabola::DownCast(getGeometry2dPtr()->handle());
|
||||
return Py::Float(curve->Eccentricity());
|
||||
}
|
||||
|
||||
Py::Float Parabola2dPy::getFocal(void) const
|
||||
{
|
||||
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom2d_Parabola curve = Handle_Geom2d_Parabola::DownCast(getGeometry2dPtr()->handle());
|
||||
return Py::Float(curve->Focal());
|
||||
}
|
||||
|
||||
void Parabola2dPy::setFocal(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom2d_Parabola curve = Handle_Geom2d_Parabola::DownCast(getGeometry2dPtr()->handle());
|
||||
curve->SetFocal((double)arg);
|
||||
}
|
||||
|
||||
Py::Object Parabola2dPy::getFocus(void) const
|
||||
{
|
||||
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Pnt loc = c->Focus();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
Handle_Geom2d_Parabola curve = Handle_Geom2d_Parabola::DownCast(getGeometry2dPtr()->handle());
|
||||
gp_Pnt2d loc = curve->Focus();
|
||||
|
||||
Py::Module module("__FreeCADBase__");
|
||||
Py::Callable method(module.getAttr("Vector2d"));
|
||||
Py::Tuple arg(2);
|
||||
arg.setItem(0, Py::Float(loc.X()));
|
||||
arg.setItem(1, Py::Float(loc.Y()));
|
||||
return method.apply(arg);
|
||||
}
|
||||
|
||||
Py::Float Parabola2dPy::getParameter(void) const
|
||||
{
|
||||
Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle());
|
||||
return Py::Float(curve->Parameter());
|
||||
Handle_Geom2d_Parabola curve = Handle_Geom2d_Parabola::DownCast(getGeometry2dPtr()->handle());
|
||||
return Py::Float(curve->Parameter());
|
||||
}
|
||||
|
||||
Py::Object Parabola2dPy::getLocation(void) const
|
||||
{
|
||||
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Pnt loc = c->Location();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
}
|
||||
|
||||
void Parabola2dPy::setLocation(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
|
||||
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
Py::Tuple tuple(arg);
|
||||
gp_Pnt loc;
|
||||
loc.SetX((double)Py::Float(tuple.getItem(0)));
|
||||
loc.SetY((double)Py::Float(tuple.getItem(1)));
|
||||
loc.SetZ((double)Py::Float(tuple.getItem(2)));
|
||||
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
c->SetLocation(loc);
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object Parabola2dPy::getAxis(void) const
|
||||
{
|
||||
Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
gp_Dir dir = c->Axis().Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
|
||||
}
|
||||
|
||||
void Parabola2dPy::setAxis(Py::Object arg)
|
||||
{
|
||||
Standard_Real dir_x, dir_y, dir_z;
|
||||
PyObject *p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
|
||||
dir_x = v.x;
|
||||
dir_y = v.y;
|
||||
dir_z = v.z;
|
||||
}
|
||||
else if (PyTuple_Check(p)) {
|
||||
Py::Tuple tuple(arg);
|
||||
dir_x = (double)Py::Float(tuple.getItem(0));
|
||||
dir_y = (double)Py::Float(tuple.getItem(1));
|
||||
dir_z = (double)Py::Float(tuple.getItem(2));
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector' or tuple, not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
|
||||
try {
|
||||
Handle_Geom_Parabola this_curv = Handle_Geom_Parabola::DownCast
|
||||
(this->getGeometryPtr()->handle());
|
||||
gp_Ax1 axis;
|
||||
axis.SetLocation(this_curv->Location());
|
||||
axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
|
||||
this_curv->SetAxis(axis);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception("cannot set axis");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
PyObject *Parabola2dPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
|
@ -224,5 +107,3 @@ int Parabola2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user