implement OffsetCurve2d
This commit is contained in:
parent
c817c3334e
commit
de8bfaafc3
|
@ -55,7 +55,7 @@ using namespace Part;
|
|||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string BSplineCurve2dPy::representation(void) const
|
||||
{
|
||||
return "<BSplineCurve object>";
|
||||
return "<BSplineCurve2d object>";
|
||||
}
|
||||
|
||||
PyObject *BSplineCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
|
|
|
@ -42,7 +42,7 @@ using namespace Part;
|
|||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string BezierCurve2dPy::representation(void) const
|
||||
{
|
||||
return "<BezierCurve object>";
|
||||
return "<BezierCurve2d object>";
|
||||
}
|
||||
|
||||
PyObject *BezierCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu></UserDocu>
|
||||
</Documentation>
|
||||
<!--
|
||||
<Attribute Name="OffsetValue">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
@ -23,14 +22,6 @@
|
|||
</Documentation>
|
||||
<Parameter Name="OffsetValue" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="OffsetDirection">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Sets or gets the offset direction to offset the underlying curve.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="OffsetDirection" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="BasisCurve">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
@ -39,6 +30,5 @@
|
|||
</Documentation>
|
||||
<Parameter Name="BasisCurve" Type="Object"/>
|
||||
</Attribute>
|
||||
-->
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <Geom_OffsetCurve.hxx>
|
||||
# include <Geom2d_OffsetCurve.hxx>
|
||||
#endif
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
|
@ -32,8 +32,6 @@
|
|||
#include <Mod/Part/App/Geom2d/OffsetCurve2dPy.cpp>
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
|
@ -52,29 +50,24 @@ PyObject *OffsetCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
|
|||
// constructor method
|
||||
int OffsetCurve2dPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
{
|
||||
return 0;
|
||||
#if 0
|
||||
PyObject* pGeom;
|
||||
PyObject* pDir;
|
||||
double offset;
|
||||
if (!PyArg_ParseTuple(args, "O!dO!",
|
||||
&(GeometryPy::Type), &pGeom,
|
||||
&offset,
|
||||
&(Base::VectorPy::Type),&pDir))
|
||||
if (!PyArg_ParseTuple(args, "O!d",
|
||||
&(Curve2dPy::Type), &pGeom,
|
||||
&offset))
|
||||
return -1;
|
||||
|
||||
GeometryPy* pcGeo = static_cast<GeometryPy*>(pGeom);
|
||||
Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
|
||||
(pcGeo->getGeometryPtr()->handle());
|
||||
Curve2dPy* pcGeo = static_cast<Curve2dPy*>(pGeom);
|
||||
Handle_Geom2d_Curve curve = Handle_Geom2d_Curve::DownCast
|
||||
(pcGeo->getGeometry2dPtr()->handle());
|
||||
if (curve.IsNull()) {
|
||||
PyErr_SetString(PyExc_TypeError, "geometry is not a curve");
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
|
||||
Handle_Geom_OffsetCurve curve2 = new Geom_OffsetCurve(curve, offset, gp_Dir(dir.x,dir.y,dir.z));
|
||||
getGeomOffsetCurvePtr()->setHandle(curve2);
|
||||
Handle_Geom2d_OffsetCurve curve2 = new Geom2d_OffsetCurve(curve, offset);
|
||||
getGeom2dOffsetCurvePtr()->setHandle(curve2);
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
|
@ -82,69 +75,79 @@ int OffsetCurve2dPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
|||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
|
||||
Py::Float OffsetCurve2dPy::getOffsetValue(void) const
|
||||
{
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom2d_OffsetCurve curve = Handle_Geom2d_OffsetCurve::DownCast(getGeometry2dPtr()->handle());
|
||||
return Py::Float(curve->Offset());
|
||||
}
|
||||
|
||||
void OffsetCurve2dPy::setOffsetValue(Py::Float arg)
|
||||
{
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom2d_OffsetCurve curve = Handle_Geom2d_OffsetCurve::DownCast(getGeometry2dPtr()->handle());
|
||||
curve->SetOffsetValue((double)arg);
|
||||
}
|
||||
|
||||
Py::Object OffsetCurve2dPy::getOffsetDirection(void) const
|
||||
{
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
const gp_Dir& dir = curve->Direction();
|
||||
return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()));
|
||||
}
|
||||
|
||||
void OffsetCurve2dPy::setOffsetDirection(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(p)->value();
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
|
||||
}
|
||||
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
|
||||
Base::Vector3d dir = Base::getVectorFromTuple<double>(p);
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z));
|
||||
}
|
||||
else {
|
||||
std::string error = std::string("type must be 'Vector', not ");
|
||||
error += p->ob_type->tp_name;
|
||||
throw Py::TypeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object OffsetCurve2dPy::getBasisCurve(void) const
|
||||
{
|
||||
Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle());
|
||||
Handle_Geom_Curve basis = curve->BasisCurve();
|
||||
throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented");
|
||||
Handle_Geom2d_OffsetCurve curve = Handle_Geom2d_OffsetCurve::DownCast(getGeometry2dPtr()->handle());
|
||||
Handle_Geom2d_Curve basis = curve->BasisCurve();
|
||||
if (basis.IsNull())
|
||||
return Py::None();
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
|
||||
Geom2dParabola c(Handle_Geom2d_Parabola::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
|
||||
Geom2dHyperbola c(Handle_Geom2d_Hyperbola::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
|
||||
Geom2dEllipse c(Handle_Geom2d_Ellipse::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
|
||||
Geom2dCircle c(Handle_Geom2d_Circle::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Line))) {
|
||||
Geom2dLine c(Handle_Geom2d_Line::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
|
||||
Geom2dBSplineCurve c(Handle_Geom2d_BSplineCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
|
||||
Geom2dBezierCurve c(Handle_Geom2d_BezierCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_TrimmedCurve))) {
|
||||
Geom2dTrimmedCurve c(Handle_Geom2d_TrimmedCurve::DownCast(basis));
|
||||
return Py::asObject(c.getPyObject());
|
||||
}
|
||||
throw Py::RuntimeError("Unknown curve type");
|
||||
}
|
||||
|
||||
void OffsetCurve2dPy::setBasisCurve(Py::Object arg)
|
||||
{
|
||||
PyObject* p = arg.ptr();
|
||||
if (PyObject_TypeCheck(p, &(GeometryPy::Type))) {
|
||||
GeometryPy* pcGeo = static_cast<GeometryPy*>(p);
|
||||
Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast
|
||||
(pcGeo->getGeometryPtr()->handle());
|
||||
if (PyObject_TypeCheck(p, &(Curve2dPy::Type))) {
|
||||
Curve2dPy* pcGeo = static_cast<Curve2dPy*>(p);
|
||||
Handle_Geom2d_Curve curve = Handle_Geom2d_Curve::DownCast
|
||||
(pcGeo->getGeometry2dPtr()->handle());
|
||||
if (curve.IsNull()) {
|
||||
throw Py::TypeError("geometry is not a curve");
|
||||
}
|
||||
|
||||
Handle_Geom2d_OffsetCurve curve2 = Handle_Geom2d_OffsetCurve::DownCast
|
||||
(getGeometry2dPtr()->handle());
|
||||
if (curve == curve2) {
|
||||
throw Py::RuntimeError("cannot set this curve as basis");
|
||||
}
|
||||
|
||||
try {
|
||||
Handle_Geom_OffsetCurve curve2 = Handle_Geom_OffsetCurve::DownCast
|
||||
(getGeometryPtr()->handle());
|
||||
curve2->SetBasisCurve(curve);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
|
@ -153,7 +156,7 @@ void OffsetCurve2dPy::setBasisCurve(Py::Object arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject *OffsetCurve2dPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -68,7 +68,18 @@
|
|||
#include <Base/Tools.h>
|
||||
|
||||
#include "Geometry2d.h"
|
||||
#include <Mod/Part/App/Geom2d/Circle2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/Ellipse2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/Hyperbola2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/Parabola2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfCircle2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/ArcOfParabola2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/BezierCurve2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/BSplineCurve2dPy.h>
|
||||
#include <Mod/Part/App/Geom2d/Line2dSegmentPy.h>
|
||||
#include <Mod/Part/App/Geom2d/OffsetCurve2dPy.h>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
|
@ -373,8 +384,7 @@ void Geom2dBezierCurve::Restore(Base::XMLReader &/*reader*/)
|
|||
|
||||
PyObject *Geom2dBezierCurve::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new BezierCurvePy((GeomBezierCurve*)this->clone());
|
||||
return new BezierCurve2dPy(static_cast<Geom2dBezierCurve*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -572,8 +582,7 @@ void Geom2dBSplineCurve::Restore(Base::XMLReader &/*reader*/)
|
|||
|
||||
PyObject *Geom2dBSplineCurve::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new BSplineCurvePy((GeomBSplineCurve*)this->clone());
|
||||
return new BSplineCurve2dPy(static_cast<Geom2dBSplineCurve*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -892,8 +901,7 @@ void Geom2dCircle::Restore(Base::XMLReader& reader)
|
|||
|
||||
PyObject *Geom2dCircle::getPyObject(void)
|
||||
{
|
||||
//return new CirclePy((GeomCircle*)this->clone());
|
||||
return 0;
|
||||
return new Circle2dPy(static_cast<Geom2dCircle*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -1018,8 +1026,7 @@ void Geom2dArcOfCircle::Restore(Base::XMLReader &reader)
|
|||
|
||||
PyObject *Geom2dArcOfCircle::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new ArcOfCirclePy(static_cast<GeomArcOfCircle*>(this->clone()));
|
||||
return new ArcOfCircle2dPy(static_cast<Geom2dArcOfCircle*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -1178,8 +1185,7 @@ void Geom2dEllipse::Restore(Base::XMLReader& reader)
|
|||
|
||||
PyObject *Geom2dEllipse::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new EllipsePy((GeomEllipse*)this->clone());
|
||||
return new Ellipse2dPy(static_cast<Geom2dEllipse*>(this->clone()));
|
||||
}
|
||||
|
||||
void Geom2dEllipse::setHandle(const Handle_Geom2d_Ellipse &e)
|
||||
|
@ -1369,8 +1375,7 @@ void Geom2dArcOfEllipse::Restore(Base::XMLReader &reader)
|
|||
|
||||
PyObject *Geom2dArcOfEllipse::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new ArcOfEllipsePy(static_cast<GeomArcOfEllipse*>(this->clone()));
|
||||
return new ArcOfEllipse2dPy(static_cast<Geom2dArcOfEllipse*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -1493,8 +1498,7 @@ void Geom2dHyperbola::Restore(Base::XMLReader& reader)
|
|||
|
||||
PyObject *Geom2dHyperbola::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new HyperbolaPy((GeomHyperbola*)this->clone());
|
||||
return new Hyperbola2dPy(static_cast<Geom2dHyperbola*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -1639,8 +1643,7 @@ void Geom2dArcOfHyperbola::Restore(Base::XMLReader &reader)
|
|||
|
||||
PyObject *Geom2dArcOfHyperbola::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new ArcOfHyperbolaPy(static_cast<GeomArcOfHyperbola*>(this->clone()));
|
||||
return new ArcOfHyperbola2dPy(static_cast<Geom2dArcOfHyperbola*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -1867,8 +1870,7 @@ void Geom2dArcOfParabola::Restore(Base::XMLReader &reader)
|
|||
|
||||
PyObject *Geom2dArcOfParabola::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new ArcOfParabolaPy(static_cast<GeomArcOfParabola*>(this->clone()));
|
||||
return new ArcOfParabola2dPy(static_cast<Geom2dArcOfParabola*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -2115,8 +2117,7 @@ void Geom2dLineSegment::Restore(Base::XMLReader &reader)
|
|||
|
||||
PyObject *Geom2dLineSegment::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
//return new LinePy((GeomLineSegment*)this->clone());
|
||||
return new Line2dSegmentPy(static_cast<Geom2dLineSegment*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -2174,8 +2175,7 @@ void Geom2dOffsetCurve::Restore(Base::XMLReader &/*reader*/)
|
|||
|
||||
PyObject *Geom2dOffsetCurve::getPyObject(void)
|
||||
{
|
||||
//return new OffsetCurvePy((GeomOffsetCurve*)this->clone());
|
||||
return 0;
|
||||
return new OffsetCurve2dPy(static_cast<Geom2dOffsetCurve*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
@ -2228,5 +2228,45 @@ void Geom2dTrimmedCurve::Restore(Base::XMLReader &/*reader*/)
|
|||
|
||||
PyObject *Geom2dTrimmedCurve::getPyObject(void)
|
||||
{
|
||||
Handle_Geom2d_Curve basis = this->myCurve->BasisCurve();
|
||||
if (basis.IsNull())
|
||||
Py_Return;
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Parabola))) {
|
||||
Geom2dArcOfParabola c;
|
||||
c.setHandle(this->myCurve);
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) {
|
||||
Geom2dArcOfHyperbola c;
|
||||
c.setHandle(this->myCurve);
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) {
|
||||
Geom2dArcOfEllipse c;
|
||||
c.setHandle(this->myCurve);
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Circle))) {
|
||||
Geom2dArcOfCircle c;
|
||||
c.setHandle(this->myCurve);
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_Line))) {
|
||||
Geom2dLineSegment c;
|
||||
c.setHandle(this->myCurve);
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) {
|
||||
Geom2dBSplineCurve c;
|
||||
c.setHandle(Handle_Geom2d_BSplineCurve::DownCast(basis));
|
||||
return c.getPyObject();
|
||||
}
|
||||
if (basis->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) {
|
||||
Geom2dBezierCurve c;
|
||||
c.setHandle(Handle_Geom2d_BezierCurve::DownCast(basis));
|
||||
return c.getPyObject();
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_RuntimeError, "Unknown curve type");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user