implement Ellipse2d and ArcOfEllipse2d
This commit is contained in:
parent
3374737c5a
commit
3067bd6a85
|
@ -14,7 +14,6 @@
|
|||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer[at]users.sourceforge.net" />
|
||||
<UserDocu>Describes a portion of an ellipse</UserDocu>
|
||||
</Documentation>
|
||||
<!--
|
||||
<Attribute Name="MajorRadius" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The major radius of the ellipse.</UserDocu>
|
||||
|
@ -33,6 +32,5 @@
|
|||
</Documentation>
|
||||
<Parameter Name="Ellipse" Type="Object"/>
|
||||
</Attribute>
|
||||
-->
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -23,21 +23,20 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <gp_Elips.hxx>
|
||||
# include <Geom_Ellipse.hxx>
|
||||
# include <GC_MakeArcOfEllipse.hxx>
|
||||
# include <GC_MakeEllipse.hxx>
|
||||
# include <Geom_TrimmedCurve.hxx>
|
||||
# include <gp_Elips2d.hxx>
|
||||
# include <Geom2d_Ellipse.hxx>
|
||||
# include <GCE2d_MakeArcOfEllipse.hxx>
|
||||
# include <GCE2d_MakeEllipse.hxx>
|
||||
# include <Geom2d_TrimmedCurve.hxx>
|
||||
#endif
|
||||
|
||||
#include <Mod/Part/App/Geometry2d.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.cpp>
|
||||
#include <Mod/Part/App/EllipsePy.h>
|
||||
#include <Mod/Part/App/Geom2d/Ellipse2dPy.h>
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
|
@ -46,41 +45,7 @@ extern const char* gce_ErrorStatusText(gce_ErrorType et);
|
|||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ArcOfEllipse2dPy::representation(void) const
|
||||
{
|
||||
#if 0
|
||||
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast
|
||||
(getGeomArcOfEllipsePtr()->handle());
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve());
|
||||
|
||||
gp_Ax1 axis = ellipse->Axis();
|
||||
gp_Dir dir = axis.Direction();
|
||||
gp_Pnt loc = axis.Location();
|
||||
Standard_Real fMajRad = ellipse->MajorRadius();
|
||||
Standard_Real fMinRad = ellipse->MinorRadius();
|
||||
Standard_Real u1 = trim->FirstParameter();
|
||||
Standard_Real u2 = trim->LastParameter();
|
||||
|
||||
gp_Dir normal = ellipse->Axis().Direction();
|
||||
gp_Dir xdir = ellipse->XAxis().Direction();
|
||||
|
||||
gp_Ax2 xdirref(loc, normal); // this is a reference XY for the ellipse
|
||||
|
||||
Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal);
|
||||
|
||||
|
||||
std::stringstream str;
|
||||
str << "ArcOfEllipse (";
|
||||
str << "MajorRadius : " << fMajRad << ", ";
|
||||
str << "MinorRadius : " << fMinRad << ", ";
|
||||
str << "AngleXU : " << fAngleXU << ", ";
|
||||
str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
|
||||
str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), ";
|
||||
str << "Parameter : (" << u1 << ", " << u2 << ")";
|
||||
str << ")";
|
||||
|
||||
return str.str();
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
return "<Arc of ellipse2d object>";
|
||||
}
|
||||
|
||||
PyObject *ArcOfEllipse2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
|
@ -92,23 +57,20 @@ PyObject *ArcOfEllipse2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
|
|||
// constructor method
|
||||
int ArcOfEllipse2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
|
||||
{
|
||||
#if 1
|
||||
return 0;
|
||||
#else
|
||||
PyObject* o;
|
||||
double u1, u2;
|
||||
PyObject *sense=Py_True;
|
||||
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::EllipsePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
|
||||
if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::Ellipse2dPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) {
|
||||
try {
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast
|
||||
(static_cast<EllipsePy*>(o)->getGeomEllipsePtr()->handle());
|
||||
GC_MakeArcOfEllipse arc(ellipse->Elips(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast
|
||||
(static_cast<Ellipse2dPy*>(o)->getGeom2dEllipsePtr()->handle());
|
||||
GCE2d_MakeArcOfEllipse arc(ellipse->Elips2d(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False);
|
||||
if (!arc.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
getGeomArcOfEllipsePtr()->setHandle(arc.Value());
|
||||
getGeom2dArcOfEllipsePtr()->setHandle(arc.Value());
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
|
@ -124,39 +86,37 @@ int ArcOfEllipse2dPy::PyInit(PyObject* args, PyObject* /*kwds*/)
|
|||
|
||||
// All checks failed
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"ArcOfEllipse constructor expects an ellipse curve and a parameter range");
|
||||
"ArcOfEllipse2d constructor expects an ellipse curve and a parameter range");
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
|
||||
Py::Float ArcOfEllipse2dPy::getMajorRadius(void) const
|
||||
{
|
||||
return Py::Float(getGeomArcOfEllipsePtr()->getMajorRadius());
|
||||
return Py::Float(getGeom2dArcOfEllipsePtr()->getMajorRadius());
|
||||
}
|
||||
|
||||
void ArcOfEllipse2dPy::setMajorRadius(Py::Float arg)
|
||||
{
|
||||
getGeomArcOfEllipsePtr()->setMajorRadius((double)arg);
|
||||
getGeom2dArcOfEllipsePtr()->setMajorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float ArcOfEllipse2dPy::getMinorRadius(void) const
|
||||
{
|
||||
return Py::Float(getGeomArcOfEllipsePtr()->getMinorRadius());
|
||||
return Py::Float(getGeom2dArcOfEllipsePtr()->getMinorRadius());
|
||||
}
|
||||
|
||||
void ArcOfEllipse2dPy::setMinorRadius(Py::Float arg)
|
||||
{
|
||||
getGeomArcOfEllipsePtr()->setMinorRadius((double)arg);
|
||||
getGeom2dArcOfEllipsePtr()->setMinorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Object ArcOfEllipse2dPy::getEllipse(void) const
|
||||
{
|
||||
Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast
|
||||
(getGeomArcOfEllipsePtr()->handle());
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve());
|
||||
return Py::Object(new EllipsePy(new GeomEllipse(ellipse)), true);
|
||||
Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(getGeom2dArcOfConicPtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(curve->BasisCurve());
|
||||
return Py::asObject(new Ellipse2dPy(new Geom2dEllipse(ellipse)));
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject *ArcOfEllipse2dPy::getCustomAttributes(const char* ) const
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -12,29 +12,26 @@
|
|||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>Describes an ellipse in 3D space
|
||||
<UserDocu>Describes an ellipse in 2D space
|
||||
To create an ellipse there are several ways:
|
||||
Part.Ellipse()
|
||||
Creates an ellipse with major radius 2 and minor radius 1 with the
|
||||
center in (0,0,0)
|
||||
center in (0,0)
|
||||
|
||||
Part.Ellipse(Ellipse)
|
||||
Create a copy of the given ellipse
|
||||
|
||||
Part.Ellipse(S1,S2,Center)
|
||||
Creates an ellipse centered on the point Center, where
|
||||
the plane of the ellipse is defined by Center, S1 and S2,
|
||||
Creates an ellipse centered on the point Center,
|
||||
its major axis is defined by Center and S1,
|
||||
its major radius is the distance between Center and S1, and
|
||||
its minor radius is the distance between S2 and the major axis.
|
||||
|
||||
Part.Ellipse(Center,MajorRadius,MinorRadius)
|
||||
Creates an ellipse with major and minor radii MajorRadius and
|
||||
MinorRadius, and located in the plane defined by Center and
|
||||
the normal (0,0,1)
|
||||
MinorRadius
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<!--
|
||||
<Attribute Name="MajorRadius" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>The major radius of the ellipse.</UserDocu>
|
||||
|
@ -70,6 +67,5 @@ the second focus is on the negative side.
|
|||
</Documentation>
|
||||
<Parameter Name="Focus2" Type="Object"/>
|
||||
</Attribute>
|
||||
-->
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -23,13 +23,12 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <gp_Elips.hxx>
|
||||
# include <Geom_Ellipse.hxx>
|
||||
# include <GC_MakeEllipse.hxx>
|
||||
# include <gp_Elips2d.hxx>
|
||||
# include <Geom2d_Ellipse.hxx>
|
||||
# include <GCE2d_MakeEllipse.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
#include <Mod/Part/App/Geometry2d.h>
|
||||
|
@ -55,11 +54,9 @@ PyObject *Ellipse2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) //
|
|||
// constructor method
|
||||
int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
return 0;
|
||||
#if 0
|
||||
char* keywords_n[] = {NULL};
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
ellipse->SetMajorRadius(2.0);
|
||||
ellipse->SetMinorRadius(1.0);
|
||||
return 0;
|
||||
|
@ -70,11 +67,11 @@ int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds)
|
|||
PyObject *pElips;
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Ellipse2dPy::Type), &pElips)) {
|
||||
Ellipse2dPy* pEllipse = static_cast<Ellipse2dPy*>(pElips);
|
||||
Handle_Geom_Ellipse Elips1 = Handle_Geom_Ellipse::DownCast
|
||||
(pEllipse->getGeomEllipsePtr()->handle());
|
||||
Handle_Geom_Ellipse Elips2 = Handle_Geom_Ellipse::DownCast
|
||||
(this->getGeomEllipsePtr()->handle());
|
||||
Elips2->SetElips(Elips1->Elips());
|
||||
Handle_Geom2d_Ellipse Elips1 = Handle_Geom2d_Ellipse::DownCast
|
||||
(pEllipse->getGeom2dEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse Elips2 = Handle_Geom2d_Ellipse::DownCast
|
||||
(this->getGeom2dEllipsePtr()->handle());
|
||||
Elips2->SetElips2d(Elips1->Elips2d());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -82,22 +79,22 @@ int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds)
|
|||
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 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_MakeEllipse me(gp_Pnt(v1.x,v1.y,v1.z),
|
||||
gp_Pnt(v2.x,v2.y,v2.z),
|
||||
gp_Pnt(v3.x,v3.y,v3.z));
|
||||
Base::Vector2dPy::type_object(), &pV1,
|
||||
Base::Vector2dPy::type_object(), &pV2,
|
||||
Base::Vector2dPy::type_object(), &pV3)) {
|
||||
Base::Vector2d v1 = Py::Vector2d(pV1).getCxxObject()->value();
|
||||
Base::Vector2d v2 = Py::Vector2d(pV2).getCxxObject()->value();
|
||||
Base::Vector2d v3 = Py::Vector2d(pV3).getCxxObject()->value();
|
||||
GCE2d_MakeEllipse me(gp_Pnt2d(v1.x,v1.y),
|
||||
gp_Pnt2d(v2.x,v2.y),
|
||||
gp_Pnt2d(v3.x,v3.y));
|
||||
if (!me.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
ellipse->SetElips(me.Value()->Elips());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
ellipse->SetElips2d(me.Value()->Elips2d());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,18 +103,18 @@ int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds)
|
|||
PyObject *pV;
|
||||
double major, minor;
|
||||
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm,
|
||||
&(Base::VectorPy::Type), &pV,
|
||||
Base::Vector2dPy::type_object(), &pV,
|
||||
&major, &minor)) {
|
||||
Base::Vector3d c = static_cast<Base::VectorPy*>(pV)->value();
|
||||
GC_MakeEllipse me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)),
|
||||
Base::Vector2d c = Py::Vector2d(pV).getCxxObject()->value();
|
||||
GCE2d_MakeEllipse me(gp_Ax2d(gp_Pnt2d(c.x,c.y), gp_Dir2d(0.0,1.0)),
|
||||
major, minor);
|
||||
if (!me.IsDone()) {
|
||||
PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
ellipse->SetElips(me.Value()->Elips());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
ellipse->SetElips2d(me.Value()->Elips2d());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -127,53 +124,64 @@ int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds)
|
|||
"-- Point, double, double\n"
|
||||
"-- Point, Point, Point");
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
|
||||
Py::Float Ellipse2dPy::getMajorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
return Py::Float(ellipse->MajorRadius());
|
||||
}
|
||||
|
||||
void Ellipse2dPy::setMajorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
ellipse->SetMajorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float Ellipse2dPy::getMinorRadius(void) const
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
return Py::Float(ellipse->MinorRadius());
|
||||
}
|
||||
|
||||
void Ellipse2dPy::setMinorRadius(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
ellipse->SetMinorRadius((double)arg);
|
||||
}
|
||||
|
||||
Py::Float Ellipse2dPy::getFocal(void) const
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
return Py::Float(ellipse->Focal());
|
||||
}
|
||||
|
||||
Py::Object Ellipse2dPy::getFocus1(void) const
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
gp_Pnt loc = ellipse->Focus1();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
gp_Pnt2d loc = ellipse->Focus1();
|
||||
|
||||
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::Object Ellipse2dPy::getFocus2(void) const
|
||||
{
|
||||
Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle());
|
||||
gp_Pnt loc = ellipse->Focus2();
|
||||
return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
|
||||
Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(getGeom2dEllipsePtr()->handle());
|
||||
gp_Pnt2d loc = ellipse->Focus2();
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject *Ellipse2dPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user