From 689d2e42a9516fe116c6589a4c3f8a1bb8bd6172 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 21 Nov 2016 18:17:10 +0100 Subject: [PATCH] wrapper for Geom2d package --- src/Mod/Part/App/AppPart.cpp | 21 + src/Mod/Part/App/CMakeLists.txt | 2 + src/Mod/Part/App/Geometry.cpp | 8 +- src/Mod/Part/App/Geometry2d.cpp | 2543 +++++++++++++++++++++++++++++++ src/Mod/Part/App/Geometry2d.h | 556 +++++++ 5 files changed, 3126 insertions(+), 4 deletions(-) create mode 100644 src/Mod/Part/App/Geometry2d.cpp create mode 100644 src/Mod/Part/App/Geometry2d.h diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index cc614c9c1..4fe2bac01 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -55,6 +55,8 @@ #include "PrimitiveFeature.h" #include "Part2DObject.h" #include "CustomFeature.h" +#include "Geometry.h" +#include "Geometry2d.h" #include "TopoShapePy.h" #include "TopoShapeVertexPy.h" #include "TopoShapeFacePy.h" @@ -347,6 +349,25 @@ PyMODINIT_FUNC initPart() Part::GeomSurfaceOfExtrusion ::init(); Part::Datum ::init(); + // Geometry2d types + Part::Geometry2d ::init(); + Part::Geom2dPoint ::init(); + Part::Geom2dCurve ::init(); + Part::Geom2dBezierCurve ::init(); + Part::Geom2dBSplineCurve ::init(); + Part::Geom2dCircle ::init(); + Part::Geom2dArcOfCircle ::init(); + Part::Geom2dEllipse ::init(); + Part::Geom2dArcOfEllipse ::init(); + Part::Geom2dHyperbola ::init(); + Part::Geom2dArcOfHyperbola ::init(); + Part::Geom2dParabola ::init(); + Part::Geom2dArcOfParabola ::init(); + Part::Geom2dLine ::init(); + Part::Geom2dLineSegment ::init(); + Part::Geom2dOffsetCurve ::init(); + Part::Geom2dTrimmedCurve ::init(); + IGESControl_Controller::Init(); STEPControl_Controller::Init(); // set the user-defined settings diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index bee0cdcee..890f1d1fc 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -262,6 +262,8 @@ SET(Part_SRCS CrossSection.h Geometry.cpp Geometry.h + Geometry2d.cpp + Geometry2d.h ImportIges.cpp ImportIges.h ImportStep.cpp diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index e3c97c853..fa692e40c 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -2451,8 +2451,8 @@ Base::Vector3d GeomArcOfParabola::getEndPoint() const Base::Vector3d GeomArcOfParabola::getCenter(void) const { - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); - gp_Ax1 axis = h->Axis(); + Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); + gp_Ax1 axis = p->Axis(); const gp_Pnt& loc = axis.Location(); return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); } @@ -2460,10 +2460,10 @@ Base::Vector3d GeomArcOfParabola::getCenter(void) const void GeomArcOfParabola::setCenter(const Base::Vector3d& Center) { gp_Pnt p1(Center.x,Center.y,Center.z); - Handle_Geom_Hyperbola h = Handle_Geom_Hyperbola::DownCast(myCurve->BasisCurve()); + Handle_Geom_Parabola p = Handle_Geom_Parabola::DownCast(myCurve->BasisCurve()); try { - h->SetLocation(p1); + p->SetLocation(p1); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/Part/App/Geometry2d.cpp b/src/Mod/Part/App/Geometry2d.cpp new file mode 100644 index 000000000..b7b443394 --- /dev/null +++ b/src/Mod/Part/App/Geometry2d.cpp @@ -0,0 +1,2543 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include + +#include +#include +#include +#include + +#include "Geometry2d.h" + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + + +TYPESYSTEM_SOURCE_ABSTRACT(Part::Geometry2d, Base::Persistence) + +Geometry2d::Geometry2d() +{ +} + +Geometry2d::~Geometry2d() +{ +} + +unsigned int Geometry2d::getMemSize (void) const +{ + return sizeof(Geometry2d); +} + +void Geometry2d::Save(Base::Writer &writer) const +{ + throw Base::NotImplementedError("Save"); +} + +void Geometry2d::Restore(Base::XMLReader &reader) +{ + throw Base::NotImplementedError("Restore"); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dPoint, Part::Geometry2d) + +Geom2dPoint::Geom2dPoint() +{ + this->myPoint = new Geom2d_CartesianPoint(0,0); +} + +Geom2dPoint::Geom2dPoint(const Handle_Geom2d_CartesianPoint& p) +{ + this->myPoint = Handle_Geom2d_CartesianPoint::DownCast(p->Copy()); +} + +Geom2dPoint::Geom2dPoint(const Base::Vector2d& p) +{ + this->myPoint = new Geom2d_CartesianPoint(p.x,p.y); +} + +Geom2dPoint::~Geom2dPoint() +{ +} + +TopoDS_Shape Geom2dPoint::toShape(const Handle_Geom_Surface& hSurface) const +{ + Handle_Geom2d_CartesianPoint c = Handle_Geom2d_CartesianPoint::DownCast(handle()); + gp_Pnt2d xy = c->Pnt2d(); + gp_Pnt pnt = hSurface->Value(xy.X(), xy.Y()); + BRepBuilderAPI_MakeVertex mkBuilder(pnt); + return mkBuilder.Shape(); +} + +const Handle_Geom2d_Geometry& Geom2dPoint::handle() const +{ + return myPoint; +} + +Geometry2d *Geom2dPoint::clone(void) const +{ + Geom2dPoint *newPoint = new Geom2dPoint(myPoint); + return newPoint; +} + +Base::Vector2d Geom2dPoint::getPoint(void)const +{ + return Base::Vector2d(myPoint->X(),myPoint->Y()); +} + +void Geom2dPoint::setPoint(const Base::Vector2d& p) +{ + this->myPoint->SetCoord(p.x,p.y); +} + +unsigned int Geom2dPoint::getMemSize (void) const +{ + return sizeof(Geom2d_CartesianPoint); +} + +void Geom2dPoint::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geometry2d::Save(writer); + + Base::Vector2d Point = getPoint(); + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dPoint::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geometry2d::Restore(reader); + + double X,Y; + // read my Element + reader.readElement("Geom2dPoint"); + // get the value of my Attribute + X = reader.getAttributeAsFloat("X"); + Y = reader.getAttributeAsFloat("Y"); + + // set the read geometry + setPoint(Base::Vector2d(X,Y)); +} + +PyObject *Geom2dPoint::getPyObject(void) +{ + Handle_Geom2d_CartesianPoint c = Handle_Geom2d_CartesianPoint::DownCast(handle()); + gp_Pnt2d xy = c->Pnt2d(); + + Py::Tuple tuple(2); + tuple.setItem(0, Py::Float(xy.X())); + tuple.setItem(1, Py::Float(xy.Y())); + return Py::new_reference_to(tuple); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dCurve, Part::Geometry2d) + +Geom2dCurve::Geom2dCurve() +{ +} + +Geom2dCurve::~Geom2dCurve() +{ +} + +TopoDS_Shape Geom2dCurve::toShape(const Handle_Geom_Surface& hSurface) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + BRepBuilderAPI_MakeEdge mkBuilder(c, hSurface); + return mkBuilder.Shape(); +} + +bool Geom2dCurve::tangent(double u, gp_Dir2d& dir) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion()); + if (prop.IsTangentDefined()) { + prop.Tangent(dir); + return true; + } + + return false; +} + +Base::Vector2d Geom2dCurve::pointAtParameter(double u) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + Geom2dLProp_CLProps2d prop(c,u,0,Precision::Confusion()); + + const gp_Pnt2d &point=prop.Value(); + return Base::Vector2d(point.X(),point.Y()); +} + +Base::Vector2d Geom2dCurve::firstDerivativeAtParameter(double u) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + Geom2dLProp_CLProps2d prop(c,u,1,Precision::Confusion()); + + const gp_Vec2d &vec=prop.D1(); + return Base::Vector2d(vec.X(),vec.Y()); +} + +Base::Vector2d Geom2dCurve::secondDerivativeAtParameter(double u) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion()); + + const gp_Vec2d &vec=prop.D2(); + return Base::Vector2d(vec.X(),vec.Y()); +} + +bool Geom2dCurve::normal(double u, gp_Dir2d& dir) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + Geom2dLProp_CLProps2d prop(c,u,2,Precision::Confusion()); + if (prop.IsTangentDefined()) { + prop.Normal(dir); + return true; + } + + return false; +} + +bool Geom2dCurve::closestParameter(const Base::Vector2d& point, double &u) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + try { + if (!c.IsNull()) { + gp_Pnt2d pnt(point.x,point.y); + Geom2dAPI_ProjectPointOnCurve ppc(pnt, c); + u = ppc.LowerDistanceParameter(); + return true; + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + std::cout << e->GetMessageString() << std::endl; + return false; + } + + return false; +} + +bool Geom2dCurve::closestParameterToBasicCurve(const Base::Vector2d& point, double &u) const +{ + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(handle()); + + if (c->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))){ + Handle_Geom2d_TrimmedCurve tc = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + Handle_Geom2d_Curve bc = Handle_Geom2d_Curve::DownCast(tc->BasisCurve()); + try { + if (!bc.IsNull()) { + gp_Pnt2d pnt(point.x,point.y); + Geom2dAPI_ProjectPointOnCurve ppc(pnt, bc); + u = ppc.LowerDistanceParameter(); + return true; + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + std::cout << e->GetMessageString() << std::endl; + return false; + } + + return false; + + } + else { + return this->closestParameter(point, u); + } +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dBezierCurve, Part::Geom2dCurve) + +Geom2dBezierCurve::Geom2dBezierCurve() +{ + TColgp_Array1OfPnt2d poles(1,2); + poles(1) = gp_Pnt2d(0.0,0.0); + poles(2) = gp_Pnt2d(0.0,1.0); + Handle_Geom2d_BezierCurve b = new Geom2d_BezierCurve(poles); + this->myCurve = b; +} + +Geom2dBezierCurve::Geom2dBezierCurve(const Handle_Geom2d_BezierCurve& b) +{ + this->myCurve = Handle_Geom2d_BezierCurve::DownCast(b->Copy()); +} + +Geom2dBezierCurve::~Geom2dBezierCurve() +{ +} + +void Geom2dBezierCurve::setHandle(const Handle_Geom2d_BezierCurve& c) +{ + myCurve = Handle_Geom2d_BezierCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dBezierCurve::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dBezierCurve::clone(void) const +{ + Geom2dBezierCurve *newCurve = new Geom2dBezierCurve(myCurve); + return newCurve; +} + +unsigned int Geom2dBezierCurve::getMemSize (void) const +{ + throw Base::NotImplementedError("Geom2dBezierCurve::getMemSize"); +} + +void Geom2dBezierCurve::Save(Base::Writer &/*writer*/) const +{ + throw Base::NotImplementedError("Geom2dBezierCurve::Save"); +} + +void Geom2dBezierCurve::Restore(Base::XMLReader &/*reader*/) +{ + throw Base::NotImplementedError("Geom2dBezierCurve::Restore"); +} + +PyObject *Geom2dBezierCurve::getPyObject(void) +{ + return 0; + //return new BezierCurvePy((GeomBezierCurve*)this->clone()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dBSplineCurve, Part::Geom2dCurve) + +Geom2dBSplineCurve::Geom2dBSplineCurve() +{ + TColgp_Array1OfPnt2d poles(1,2); + poles(1) = gp_Pnt2d(0.0,0.0); + poles(2) = gp_Pnt2d(1.0,0.0); + + TColStd_Array1OfReal knots(1,2); + knots(1) = 0.0; + knots(2) = 1.0; + + TColStd_Array1OfInteger mults(1,2); + mults(1) = 2; + mults(2) = 2; + + this->myCurve = new Geom2d_BSplineCurve(poles, knots, mults, 1); +} + +Geom2dBSplineCurve::Geom2dBSplineCurve(const Handle_Geom2d_BSplineCurve& b) +{ + this->myCurve = Handle_Geom2d_BSplineCurve::DownCast(b->Copy()); +} + +Geom2dBSplineCurve::~Geom2dBSplineCurve() +{ +} + +void Geom2dBSplineCurve::setHandle(const Handle_Geom2d_BSplineCurve& c) +{ + myCurve = Handle_Geom2d_BSplineCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dBSplineCurve::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dBSplineCurve::clone(void) const +{ + Geom2dBSplineCurve *newCurve = new Geom2dBSplineCurve(myCurve); + return newCurve; +} + +int Geom2dBSplineCurve::countPoles() const +{ + return myCurve->NbPoles(); +} + +void Geom2dBSplineCurve::setPole(int index, const Base::Vector2d& pole, double weight) +{ + try { + gp_Pnt2d pnt(pole.x,pole.y); + if (weight < 0.0) + myCurve->SetPole(index+1,pnt); + else + myCurve->SetPole(index+1,pnt,weight); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + std::cout << e->GetMessageString() << std::endl; + } +} + +std::vector Geom2dBSplineCurve::getPoles() const +{ + std::vector poles; + poles.reserve(myCurve->NbPoles()); + TColgp_Array1OfPnt2d p(1,myCurve->NbPoles()); + myCurve->Poles(p); + + for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) { + const gp_Pnt2d& pnt = p(i); + poles.push_back(Base::Vector2d(pnt.X(), pnt.Y())); + } + return poles; +} + +bool Geom2dBSplineCurve::join(const Handle_Geom2d_BSplineCurve& spline) +{ + Geom2dConvert_CompCurveToBSplineCurve ccbc(this->myCurve); + if (!ccbc.Add(spline, Precision::Approximation())) + return false; + this->myCurve = ccbc.BSplineCurve(); + return true; +} + +void Geom2dBSplineCurve::interpolate(const std::vector& p, + const std::vector& t) +{ + if (p.size() < 2) + Standard_ConstructionError::Raise(); + if (p.size() != t.size()) + Standard_ConstructionError::Raise(); + + double tol3d = Precision::Approximation(); + Handle_TColgp_HArray1OfPnt2d pts = new TColgp_HArray1OfPnt2d(1, p.size()); + for (std::size_t i=0; iSetValue(i+1, p[i]); + } + + TColgp_Array1OfVec2d tgs(1, t.size()); + Handle_TColStd_HArray1OfBoolean fgs = new TColStd_HArray1OfBoolean(1, t.size()); + for (std::size_t i=0; iSetValue(i+1, Standard_True); + } + + Geom2dAPI_Interpolate interpolate(pts, Standard_False, tol3d); + interpolate.Load(tgs, fgs); + interpolate.Perform(); + this->myCurve = interpolate.Curve(); +} + +void Geom2dBSplineCurve::getCardinalSplineTangents(const std::vector& p, + const std::vector& c, + std::vector& t) const +{ + // https://de.wikipedia.org/wiki/Kubisch_Hermitescher_Spline#Cardinal_Spline + if (p.size() < 2) + Standard_ConstructionError::Raise(); + if (p.size() != c.size()) + Standard_ConstructionError::Raise(); + + t.resize(p.size()); + if (p.size() == 2) { + t[0] = gp_Vec2d(p[0], p[1]); + t[1] = gp_Vec2d(p[0], p[1]); + } + else { + std::size_t e = p.size() - 1; + + for (std::size_t i = 1; i < e; i++) { + gp_Vec2d v = gp_Vec2d(p[i-1], p[i+1]); + double f = 0.5 * (1-c[i]); + v.Scale(f); + t[i] = v; + } + + t[0] = t[1]; + t[t.size()-1] = t[t.size()-2]; + } +} + +void Geom2dBSplineCurve::getCardinalSplineTangents(const std::vector& p, double c, + std::vector& t) const +{ + // https://de.wikipedia.org/wiki/Kubisch_Hermitescher_Spline#Cardinal_Spline + if (p.size() < 2) + Standard_ConstructionError::Raise(); + + t.resize(p.size()); + if (p.size() == 2) { + t[0] = gp_Vec2d(p[0], p[1]); + t[1] = gp_Vec2d(p[0], p[1]); + } + else { + std::size_t e = p.size() - 1; + double f = 0.5 * (1-c); + + for (std::size_t i = 1; i < e; i++) { + gp_Vec2d v = gp_Vec2d(p[i-1], p[i+1]); + v.Scale(f); + t[i] = v; + } + + t[0] = t[1]; + t[t.size()-1] = t[t.size()-2]; + } +} + +void Geom2dBSplineCurve::makeC1Continuous(double tol) +{ + Geom2dConvert::C0BSplineToC1BSplineCurve(this->myCurve, tol); +} + +unsigned int Geom2dBSplineCurve::getMemSize(void) const +{ + throw Base::NotImplementedError("Geom2dBSplineCurve::getMemSize"); +} + +void Geom2dBSplineCurve::Save(Base::Writer &/*writer*/) const +{ + throw Base::NotImplementedError("Geom2dBSplineCurve::Save"); +} + +void Geom2dBSplineCurve::Restore(Base::XMLReader &/*reader*/) +{ + throw Base::NotImplementedError("Geom2dBSplineCurve::Restore"); +} + +PyObject *Geom2dBSplineCurve::getPyObject(void) +{ + return 0; + //return new BSplineCurvePy((GeomBSplineCurve*)this->clone()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dCircle, Part::Geom2dCurve) + +Geom2dCircle::Geom2dCircle() +{ + Handle_Geom2d_Circle c = new Geom2d_Circle(gp_Circ2d()); + this->myCurve = c; +} + +Geom2dCircle::Geom2dCircle(const Handle_Geom2d_Circle& c) +{ + this->myCurve = Handle_Geom2d_Circle::DownCast(c->Copy()); +} + +Geom2dCircle::~Geom2dCircle() +{ +} + +const Handle_Geom2d_Geometry& Geom2dCircle::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dCircle::clone(void) const +{ + Geom2dCircle *newCirc = new Geom2dCircle(myCurve); + return newCirc; +} + +Base::Vector2d Geom2dCircle::getCenter(void) const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + const gp_Pnt2d& loc = circle->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +double Geom2dCircle::getRadius(void) const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + return circle->Radius(); +} + +void Geom2dCircle::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + + try { + circle->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +void Geom2dCircle::setRadius(double Radius) +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + + try { + gp_Circ2d c = circle->Circ2d(); + c.SetRadius(Radius); + circle->SetCirc2d(c); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +bool Geom2dCircle::isReversed() const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + gp_Circ2d c = circle->Circ2d(); + gp_Ax22d loc = c.Axis(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; +} + +unsigned int Geom2dCircle::getMemSize (void) const +{ + return sizeof(Geom2d_Circle); +} + +void Geom2dCircle::Save(Base::Writer& writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + gp_Circ2d c = circle->Circ2d(); + gp_Ax22d loc = c.Axis(); + gp_Pnt2d center = loc.Location(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dCircle::Restore(Base::XMLReader& reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY,Radius; + // read my Element + reader.readElement("Geom2dCircle"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XdirX = reader.getAttributeAsFloat("XAxisX"); + XdirY = reader.getAttributeAsFloat("XAxisY"); + YdirX = reader.getAttributeAsFloat("YAxisX"); + YdirY = reader.getAttributeAsFloat("YAxisY"); + Radius = reader.getAttributeAsFloat("Radius"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XdirX,XdirY); + gp_Dir2d ydir(YdirX,YdirY); + try { + gp_Ax22d loc(p1, xdir, ydir); + GCE2d_MakeCircle mc(loc, Radius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dCircle::getPyObject(void) +{ + //return new CirclePy((GeomCircle*)this->clone()); + return 0; +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dArcOfCircle, Part::Geom2dCurve) + +Geom2dArcOfCircle::Geom2dArcOfCircle() +{ + Handle_Geom2d_Circle c = new Geom2d_Circle(gp_Circ2d()); + this->myCurve = new Geom2d_TrimmedCurve(c, c->FirstParameter(),c->LastParameter()); +} + +Geom2dArcOfCircle::Geom2dArcOfCircle(const Handle_Geom2d_Circle& c) +{ + this->myCurve = new Geom2d_TrimmedCurve(c, c->FirstParameter(),c->LastParameter()); +} + +Geom2dArcOfCircle::~Geom2dArcOfCircle() +{ +} + +void Geom2dArcOfCircle::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + Handle_Geom2d_Circle basis = Handle_Geom2d_Circle::DownCast(c->BasisCurve()); + if (basis.IsNull()) + Standard_Failure::Raise("Basis curve is not a circle"); + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dArcOfCircle::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dArcOfCircle::clone(void) const +{ + Geom2dArcOfCircle* copy = new Geom2dArcOfCircle(); + copy->setHandle(this->myCurve); + return copy; +} + +/*! + * \brief Geom2dArcOfCircle::getStartPoint + * \return XY of the arc's starting point. + */ +Base::Vector2d Geom2dArcOfCircle::getStartPoint() const +{ + gp_Pnt2d pnt = this->myCurve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +/*! + * \brief Geom2dArcOfCircle::getEndPoint + * \return XY of the arc's ending point. + */ +Base::Vector2d Geom2dArcOfCircle::getEndPoint() const +{ + gp_Pnt2d pnt = this->myCurve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfCircle::getCenter(void) const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); + const gp_Pnt2d& loc = circle->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +double Geom2dArcOfCircle::getRadius(void) const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); + return circle->Radius(); +} + +void Geom2dArcOfCircle::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); + + try { + circle->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +void Geom2dArcOfCircle::setRadius(double Radius) +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); + + try { + gp_Circ2d c = circle->Circ2d(); + c.SetRadius(Radius); + circle->SetCirc2d(c); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dArcOfCircle::getRange + * \param u [out] start angle of the arc, in radians. + * \param v [out] end angle of the arc, in radians. + */ +void Geom2dArcOfCircle::getRange(double& u, double& v) const +{ + u = myCurve->FirstParameter(); + v = myCurve->LastParameter(); +} + +/*! + * \brief Geom2dArcOfCircle::setRange + * \param u [in] start angle of the arc, in radians. + * \param v [in] end angle of the arc, in radians. + */ +void Geom2dArcOfCircle::setRange(double u, double v) +{ + + try { + myCurve->SetTrim(u, v); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dArcOfCircle::isReversedInXY + * \return tests if an arc that lies in XY plane is reversed (i.e. drawn from + * startpoint to endpoint in CW direction instead of CCW.). Returns True if the + * arc is CW and false if CCW. + */ +bool Geom2dArcOfCircle::isReversed() const +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); + assert(!circle.IsNull()); + gp_Circ2d c = circle->Circ2d(); + gp_Ax22d loc = c.Axis(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; +} + +unsigned int Geom2dArcOfCircle::getMemSize (void) const +{ + return sizeof(Geom2d_Circle) + 2 *sizeof(double); +} + +void Geom2dArcOfCircle::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(this->myCurve->BasisCurve()); + + gp_Circ2d c = circle->Circ2d(); + gp_Ax22d loc = c.Axis(); + gp_Pnt2d center = loc.Location(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + writer.Stream() + << writer.ind() + << "myCurve->FirstParameter() << "\" " + << "Last=\"" << this->myCurve->LastParameter() << "\" " + << "/>" << endl; +} + +void Geom2dArcOfCircle::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY,Radius,First,Last; + // read my Element + reader.readElement("Geom2dArcOfCircle"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XdirX = reader.getAttributeAsFloat("XAxisX"); + XdirY = reader.getAttributeAsFloat("XAxisY"); + YdirX = reader.getAttributeAsFloat("YAxisX"); + YdirY = reader.getAttributeAsFloat("YAxisY"); + Radius = reader.getAttributeAsFloat("Radius"); + First = reader.getAttributeAsFloat("First"); + Last = reader.getAttributeAsFloat("Last"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XdirX,XdirY); + gp_Dir2d ydir(YdirX,YdirY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeCircle mc(axis, Radius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + GCE2d_MakeArcOfCircle ma(mc.Value()->Circ2d(), First, Last); + if (!ma.IsDone()) + throw Base::Exception(gce_ErrorStatusText(ma.Status())); + + Handle_Geom2d_TrimmedCurve tmpcurve = ma.Value(); + Handle_Geom2d_Circle tmpcircle = Handle_Geom2d_Circle::DownCast(tmpcurve->BasisCurve()); + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(this->myCurve->BasisCurve()); + + circle->SetCirc2d(tmpcircle->Circ2d()); + this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dArcOfCircle::getPyObject(void) +{ + return 0; + //return new ArcOfCirclePy(static_cast(this->clone())); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dEllipse, Part::Geom2dCurve) + +Geom2dEllipse::Geom2dEllipse() +{ + Handle_Geom2d_Ellipse e = new Geom2d_Ellipse(gp_Elips2d()); + this->myCurve = e; +} + +Geom2dEllipse::Geom2dEllipse(const Handle_Geom2d_Ellipse& e) +{ + this->myCurve = Handle_Geom2d_Ellipse::DownCast(e->Copy()); +} + +Geom2dEllipse::~Geom2dEllipse() +{ +} + +const Handle_Geom2d_Geometry& Geom2dEllipse::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dEllipse::clone(void) const +{ + Geom2dEllipse *newEllipse = new Geom2dEllipse(myCurve); + return newEllipse; +} + +Base::Vector2d Geom2dEllipse::getCenter(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + const gp_Pnt2d& loc = ellipse->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dEllipse::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + + try { + ellipse->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dEllipse::getMajorRadius(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + return ellipse->MajorRadius(); +} + +void Geom2dEllipse::setMajorRadius(double Radius) +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + + try { + ellipse->SetMajorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dEllipse::getMinorRadius(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + return ellipse->MinorRadius(); +} + +void Geom2dEllipse::setMinorRadius(double Radius) +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + + try { + ellipse->SetMinorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dEllipse::getMajorAxisDir + * \return the direction vector (unit-length) of major axis of the ellipse. The + * direction also points to the first focus. + */ +Base::Vector2d Geom2dEllipse::getMajorAxisDir() const +{ + gp_Dir2d xdir = myCurve->XAxis().Direction(); + return Base::Vector2d(xdir.X(), xdir.Y()); +} + +/*! + * \brief Geom2dEllipse::setMajorAxisDir Rotates the ellipse in its plane, so + * that its major 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 ellipse will be preserved. If the vector is not small, + * but its projection onto plane of the ellipse is small, an exception will be + * thrown. + */ +void Geom2dEllipse::setMajorAxisDir(Base::Vector2d newdir) +{ + if (newdir.Length() < Precision::Confusion()) + return;//zero vector was passed. Keep the old orientation. + try { + gp_Elips2d e = myCurve->Elips2d(); + gp_Ax22d pos = e.Axis(); + pos.SetXDirection(gp_Dir2d(newdir.x, newdir.y)); + e.SetAxis(pos); + myCurve->SetElips2d(e); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dEllipse::isReversed tests if an ellipse is reversed + * (i.e. drawn from startpoint to endpoint in CW direction instead + * of CCW.) + * \return Returns True if the arc is CW and false if CCW. + */ +bool Geom2dEllipse::isReversed() const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); + gp_Elips2d e = ellipse->Elips2d(); + gp_Ax22d loc = e.Axis(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; +} + +unsigned int Geom2dEllipse::getMemSize (void) const +{ + return sizeof(Geom2d_Ellipse); +} + +void Geom2dEllipse::Save(Base::Writer& writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + gp_Elips2d e = this->myCurve->Elips2d(); + gp_Pnt2d center = e.Location(); + gp_Dir2d xdir = e.Axis().XDirection(); + gp_Dir2d ydir = e.Axis().YDirection(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dEllipse::Restore(Base::XMLReader& reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius; + // read my Element + reader.readElement("Geom2dEllipse"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + MajorRadius = reader.getAttributeAsFloat("MajorRadius"); + MinorRadius = reader.getAttributeAsFloat("MinorRadius"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dEllipse::getPyObject(void) +{ + return 0; + //return new EllipsePy((GeomEllipse*)this->clone()); +} + +void Geom2dEllipse::setHandle(const Handle_Geom2d_Ellipse &e) +{ + this->myCurve = Handle_Geom2d_Ellipse::DownCast(e->Copy()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dArcOfEllipse, Part::Geom2dCurve) + +Geom2dArcOfEllipse::Geom2dArcOfEllipse() +{ + Handle_Geom2d_Ellipse e = new Geom2d_Ellipse(gp_Elips2d()); + this->myCurve = new Geom2d_TrimmedCurve(e, e->FirstParameter(),e->LastParameter()); +} + +Geom2dArcOfEllipse::Geom2dArcOfEllipse(const Handle_Geom2d_Ellipse& e) +{ + this->myCurve = new Geom2d_TrimmedCurve(e, e->FirstParameter(),e->LastParameter()); +} + +Geom2dArcOfEllipse::~Geom2dArcOfEllipse() +{ +} + +void Geom2dArcOfEllipse::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + Handle_Geom2d_Ellipse basis = Handle_Geom2d_Ellipse::DownCast(c->BasisCurve()); + if (basis.IsNull()) + Standard_Failure::Raise("Basis curve is not an ellipse"); + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dArcOfEllipse::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dArcOfEllipse::clone(void) const +{ + Geom2dArcOfEllipse* copy = new Geom2dArcOfEllipse(); + copy->setHandle(this->myCurve); + return copy; +} + +Base::Vector2d Geom2dArcOfEllipse::getStartPoint() const +{ + gp_Pnt2d pnt = this->myCurve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfEllipse::getEndPoint() const +{ + gp_Pnt2d pnt = this->myCurve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfEllipse::getCenter(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + const gp_Pnt2d& loc = ellipse->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dArcOfEllipse::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + + try { + ellipse->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dArcOfEllipse::getMajorRadius(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + return ellipse->MajorRadius(); +} + +void Geom2dArcOfEllipse::setMajorRadius(double Radius) +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + + try { + ellipse->SetMajorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dArcOfEllipse::getMinorRadius(void) const +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + return ellipse->MinorRadius(); +} + +void Geom2dArcOfEllipse::setMinorRadius(double Radius) +{ + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + + try { + ellipse->SetMinorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dArcOfEllipse::getMajorAxisDir + * \return the direction vector (unit-length) of major axis of the ellipse. The + * direction also points to the first focus. + */ +Base::Vector2d Geom2dArcOfEllipse::getMajorAxisDir() const +{ + Handle_Geom2d_Ellipse c = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + assert(!c.IsNull()); + gp_Dir2d xdir = c->XAxis().Direction(); + return Base::Vector2d(xdir.X(), xdir.Y()); +} + +/*! + * \brief Geom2dArcOfEllipse::setMajorAxisDir Rotates the ellipse in its plane, so + * that its major 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 ellipse will be preserved. If the vector is not small, + * but its projection onto plane of the ellipse is small, an exception will be + * thrown. + */ +void Geom2dArcOfEllipse::setMajorAxisDir(Base::Vector2d newdir) +{ + Handle_Geom2d_Ellipse c = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + assert(!c.IsNull()); + if (newdir.Length() < Precision::Confusion()) + return;//zero vector was passed. Keep the old orientation. + try { + gp_Elips2d e = c->Elips2d(); + gp_Ax22d pos = e.Axis(); + pos.SetXDirection(gp_Dir2d(newdir.x, newdir.y)); + e.SetAxis(pos); + c->SetElips2d(e); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +/*! + * \brief Geom2dArcOfEllipse::isReversedInXY tests if an arc that lies in XY plane is reversed + * (i.e. drawn from startpoint to endpoint in CW direction instead of CCW.) + * \return Returns True if the arc is CW and false if CCW. + */ +bool Geom2dArcOfEllipse::isReversed() const +{ + Handle_Geom2d_Ellipse c = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); + assert(!c.IsNull()); + gp_Elips2d e = c->Elips2d(); + gp_Ax22d loc = e.Axis(); + gp_Dir2d xdir = loc.XDirection(); + gp_Dir2d ydir = loc.YDirection(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; +} + +/*! + * \brief Geom2dArcOfEllipse::getRange + * \param u [out] start angle of the arc, in radians. + * \param v [out] end angle of the arc, in radians. + */ +void Geom2dArcOfEllipse::getRange(double& u, double& v) const +{ + u = myCurve->FirstParameter(); + v = myCurve->LastParameter(); +} + +/*! + * \brief Geom2dArcOfEllipse::setRange + * \param u [in] start angle of the arc, in radians. + * \param v [in] end angle of the arc, in radians. + */ +void Geom2dArcOfEllipse::setRange(double u, double v) +{ + try { + myCurve->SetTrim(u, v); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dArcOfEllipse::getMemSize (void) const +{ + return sizeof(Geom2d_Ellipse) + 2 *sizeof(double); +} + +void Geom2dArcOfEllipse::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(this->myCurve->BasisCurve()); + + gp_Elips2d e = ellipse->Elips2d(); + gp_Pnt2d center = e.Location(); + gp_Dir2d xdir = e.Axis().XDirection(); + gp_Dir2d ydir = e.Axis().YDirection(); + + writer.Stream() + << writer.ind() + << "myCurve->FirstParameter() << "\" " + << "Last=\"" << this->myCurve->LastParameter() << "\" " + << "/>" << endl; +} + +void Geom2dArcOfEllipse::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius,First,Last; + // read my Element + reader.readElement("Geom2dArcOfEllipse"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + MajorRadius = reader.getAttributeAsFloat("MajorRadius"); + MinorRadius = reader.getAttributeAsFloat("MinorRadius"); + First = reader.getAttributeAsFloat("First"); + Last = reader.getAttributeAsFloat("Last"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + GCE2d_MakeArcOfEllipse ma(mc.Value()->Elips2d(), First, Last); + if (!ma.IsDone()) + throw Base::Exception(gce_ErrorStatusText(ma.Status())); + + Handle_Geom2d_TrimmedCurve tmpcurve = ma.Value(); + Handle_Geom2d_Ellipse tmpellipse = Handle_Geom2d_Ellipse::DownCast(tmpcurve->BasisCurve()); + Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(this->myCurve->BasisCurve()); + + ellipse->SetElips2d(tmpellipse->Elips2d()); + this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dArcOfEllipse::getPyObject(void) +{ + return 0; + //return new ArcOfEllipsePy(static_cast(this->clone())); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dHyperbola, Part::Geom2dCurve) + +Geom2dHyperbola::Geom2dHyperbola() +{ + Handle_Geom2d_Hyperbola h = new Geom2d_Hyperbola(gp_Hypr2d()); + this->myCurve = h; +} + +Geom2dHyperbola::Geom2dHyperbola(const Handle_Geom2d_Hyperbola& h) +{ + this->myCurve = Handle_Geom2d_Hyperbola::DownCast(h->Copy()); +} + +Geom2dHyperbola::~Geom2dHyperbola() +{ +} + +const Handle_Geom2d_Geometry& Geom2dHyperbola::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dHyperbola::clone(void) const +{ + Geom2dHyperbola *newHyp = new Geom2dHyperbola(myCurve); + return newHyp; +} + +Base::Vector2d Geom2dHyperbola::getCenter(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + const gp_Pnt2d& loc = h->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dHyperbola::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + + try { + h->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dHyperbola::getMajorRadius(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + return h->MajorRadius(); +} + +void Geom2dHyperbola::setMajorRadius(double Radius) +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + + try { + h->SetMajorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dHyperbola::getMinorRadius(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + return h->MinorRadius(); +} + +void Geom2dHyperbola::setMinorRadius(double Radius) +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); + + try { + h->SetMinorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dHyperbola::getMemSize (void) const +{ + return sizeof(Geom2d_Hyperbola); +} + +void Geom2dHyperbola::Save(Base::Writer& writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + gp_Hypr2d h = this->myCurve->Hypr2d(); + gp_Pnt2d center = h.Location(); + gp_Dir2d xdir = h.Axis().XDirection(); + gp_Dir2d ydir = h.Axis().YDirection(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dHyperbola::Restore(Base::XMLReader& reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius; + // read my Element + reader.readElement("Geom2dHyperbola"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + MajorRadius = reader.getAttributeAsFloat("MajorRadius"); + MinorRadius = reader.getAttributeAsFloat("MinorRadius"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dHyperbola::getPyObject(void) +{ + return 0; + //return new HyperbolaPy((GeomHyperbola*)this->clone()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dArcOfHyperbola, Part::Geom2dCurve) + +Geom2dArcOfHyperbola::Geom2dArcOfHyperbola() +{ + Handle_Geom2d_Hyperbola h = new Geom2d_Hyperbola(gp_Hypr2d()); + this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter()); +} + +Geom2dArcOfHyperbola::Geom2dArcOfHyperbola(const Handle_Geom2d_Hyperbola& h) +{ + this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter()); +} + +Geom2dArcOfHyperbola::~Geom2dArcOfHyperbola() +{ +} + +void Geom2dArcOfHyperbola::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + Handle_Geom2d_Hyperbola basis = Handle_Geom2d_Hyperbola::DownCast(c->BasisCurve()); + if (basis.IsNull()) + Standard_Failure::Raise("Basis curve is not an hyperbola"); + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dArcOfHyperbola::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dArcOfHyperbola::clone(void) const +{ + Geom2dArcOfHyperbola* copy = new Geom2dArcOfHyperbola(); + copy->setHandle(this->myCurve); + return copy; +} + +Base::Vector2d Geom2dArcOfHyperbola::getStartPoint() const +{ + gp_Pnt2d pnt = this->myCurve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfHyperbola::getEndPoint() const +{ + gp_Pnt2d pnt = this->myCurve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfHyperbola::getCenter(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + const gp_Pnt2d& loc = h->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dArcOfHyperbola::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + + try { + h->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dArcOfHyperbola::getMajorRadius(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + return h->MajorRadius(); +} + +void Geom2dArcOfHyperbola::setMajorRadius(double Radius) +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + + try { + h->SetMajorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dArcOfHyperbola::getMinorRadius(void) const +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + return h->MinorRadius(); +} + +void Geom2dArcOfHyperbola::setMinorRadius(double Radius) +{ + Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); + + try { + h->SetMinorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +void Geom2dArcOfHyperbola::getRange(double& u, double& v) const +{ + u = myCurve->FirstParameter(); + v = myCurve->LastParameter(); +} + +void Geom2dArcOfHyperbola::setRange(double u, double v) +{ + try { + myCurve->SetTrim(u, v); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dArcOfHyperbola::getMemSize (void) const +{ + return sizeof(Geom2d_Hyperbola) + 2 *sizeof(double); +} + +void Geom2dArcOfHyperbola::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Handle_Geom2d_Hyperbola hh = Handle_Geom2d_Hyperbola::DownCast(this->myCurve->BasisCurve()); + + gp_Hypr2d h = hh->Hypr2d(); + gp_Pnt2d center = h.Location(); + gp_Dir2d xdir = h.Axis().XDirection(); + gp_Dir2d ydir = h.Axis().YDirection(); + + writer.Stream() + << writer.ind() + << "myCurve->FirstParameter() << "\" " + << "Last=\"" << this->myCurve->LastParameter() << "\" " + << "/>" << endl; +} + +void Geom2dArcOfHyperbola::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius,First,Last; + // read my Element + reader.readElement("Geom2dHyperbola"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + MajorRadius = reader.getAttributeAsFloat("MajorRadius"); + MinorRadius = reader.getAttributeAsFloat("MinorRadius"); + First = reader.getAttributeAsFloat("First"); + Last = reader.getAttributeAsFloat("Last"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + GCE2d_MakeArcOfHyperbola ma(mc.Value()->Hypr2d(), First, Last); + if (!ma.IsDone()) + throw Base::Exception(gce_ErrorStatusText(ma.Status())); + + Handle_Geom2d_TrimmedCurve tmpcurve = ma.Value(); + Handle_Geom2d_Hyperbola tmphyperbola = Handle_Geom2d_Hyperbola::DownCast(tmpcurve->BasisCurve()); + Handle_Geom2d_Hyperbola hyperbola = Handle_Geom2d_Hyperbola::DownCast(this->myCurve->BasisCurve()); + + hyperbola->SetHypr2d(tmphyperbola->Hypr2d()); + this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dArcOfHyperbola::getPyObject(void) +{ + return 0; + //return new ArcOfHyperbolaPy(static_cast(this->clone())); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dParabola, Part::Geom2dCurve) + +Geom2dParabola::Geom2dParabola() +{ + Handle_Geom2d_Parabola p = new Geom2d_Parabola(gp_Parab2d()); + this->myCurve = p; +} + +Geom2dParabola::Geom2dParabola(const Handle_Geom2d_Parabola& p) +{ + this->myCurve = Handle_Geom2d_Parabola::DownCast(p->Copy()); +} + +Geom2dParabola::~Geom2dParabola() +{ +} + +const Handle_Geom2d_Geometry& Geom2dParabola::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dParabola::clone(void) const +{ + Geom2dParabola *newPar = new Geom2dParabola(myCurve); + return newPar; +} + +Base::Vector2d Geom2dParabola::getCenter(void) const +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); + const gp_Pnt2d& loc = p->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dParabola::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); + + try { + p->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dParabola::getFocal(void) const +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); + return p->Focal(); +} + +void Geom2dParabola::setFocal(double length) +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); + + try { + p->SetFocal(length); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dParabola::getMemSize (void) const +{ + return sizeof(Geom2d_Parabola); +} + +void Geom2dParabola::Save(Base::Writer& writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + gp_Parab2d p = this->myCurve->Parab2d(); + gp_Pnt2d center = p.Location(); + gp_Dir2d xdir = p.Axis().XDirection(); + gp_Dir2d ydir = p.Axis().YDirection(); + double focal = p.Focal(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dParabola::Restore(Base::XMLReader& reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,Focal; + // read my Element + reader.readElement("Geom2dParabola"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + Focal = reader.getAttributeAsFloat("Focal"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeParabola mc(axis, Focal); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dParabola::getPyObject(void) +{ + return 0; + //return new ParabolaPy((GeomParabola*)this->clone()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dArcOfParabola, Part::Geom2dCurve) + +Geom2dArcOfParabola::Geom2dArcOfParabola() +{ + Handle_Geom2d_Parabola p = new Geom2d_Parabola(gp_Parab2d()); + this->myCurve = new Geom2d_TrimmedCurve(p, p->FirstParameter(),p->LastParameter()); +} + +Geom2dArcOfParabola::Geom2dArcOfParabola(const Handle_Geom2d_Parabola& h) +{ + this->myCurve = new Geom2d_TrimmedCurve(h, h->FirstParameter(),h->LastParameter()); +} + +Geom2dArcOfParabola::~Geom2dArcOfParabola() +{ +} + +void Geom2dArcOfParabola::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + Handle_Geom2d_Parabola basis = Handle_Geom2d_Parabola::DownCast(c->BasisCurve()); + if (basis.IsNull()) + Standard_Failure::Raise("Basis curve is not a parabola"); + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dArcOfParabola::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dArcOfParabola::clone(void) const +{ + Geom2dArcOfParabola* copy = new Geom2dArcOfParabola(); + copy->setHandle(this->myCurve); + return copy; +} + +Base::Vector2d Geom2dArcOfParabola::getStartPoint() const +{ + gp_Pnt2d pnt = this->myCurve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfParabola::getEndPoint() const +{ + gp_Pnt2d pnt = this->myCurve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dArcOfParabola::getCenter(void) const +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); + const gp_Pnt2d& loc = p->Location(); + return Base::Vector2d(loc.X(),loc.Y()); +} + +void Geom2dArcOfParabola::setCenter(const Base::Vector2d& Center) +{ + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); + + try { + p->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double Geom2dArcOfParabola::getFocal(void) const +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); + return p->Focal(); +} + +void Geom2dArcOfParabola::setFocal(double length) +{ + Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); + + try { + p->SetFocal(length); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +void Geom2dArcOfParabola::getRange(double& u, double& v) const +{ + u = myCurve->FirstParameter(); + v = myCurve->LastParameter(); +} + +void Geom2dArcOfParabola::setRange(double u, double v) +{ + try { + myCurve->SetTrim(u, v); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dArcOfParabola::getMemSize (void) const +{ + return sizeof(Geom2d_Parabola) + 2 *sizeof(double); +} + +void Geom2dArcOfParabola::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Handle_Geom2d_Parabola hp = Handle_Geom2d_Parabola::DownCast(this->myCurve->BasisCurve()); + gp_Parab2d p = hp->Parab2d(); + gp_Pnt2d center = p.Location(); + gp_Dir2d xdir = p.Axis().XDirection(); + gp_Dir2d ydir = p.Axis().YDirection(); + double focal = p.Focal(); + + writer.Stream() + << writer.ind() + << "myCurve->FirstParameter() << "\" " + << "Last=\"" << this->myCurve->LastParameter() << "\" " + << "/>" << endl; +} + +void Geom2dArcOfParabola::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,Focal,First,Last; + // read my Element + reader.readElement("Geom2dParabola"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XAxisX = reader.getAttributeAsFloat("XAxisX"); + XAxisY = reader.getAttributeAsFloat("XAxisY"); + YAxisX = reader.getAttributeAsFloat("YAxisX"); + YAxisY = reader.getAttributeAsFloat("YAxisY"); + Focal = reader.getAttributeAsFloat("Focal"); + First = reader.getAttributeAsFloat("First"); + Last = reader.getAttributeAsFloat("Last"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XAxisX,XAxisY); + gp_Dir2d ydir(YAxisX,YAxisY); + gp_Ax22d axis(p1, xdir, ydir); + + try { + GCE2d_MakeParabola mc(axis, Focal); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + GCE2d_MakeArcOfParabola ma(mc.Value()->Parab2d(), First, Last); + if (!ma.IsDone()) + throw Base::Exception(gce_ErrorStatusText(ma.Status())); + + Handle_Geom2d_TrimmedCurve tmpcurve = ma.Value(); + Handle_Geom2d_Parabola tmpparabola = Handle_Geom2d_Parabola::DownCast(tmpcurve->BasisCurve()); + Handle_Geom2d_Parabola parabola = Handle_Geom2d_Parabola::DownCast(this->myCurve->BasisCurve()); + + parabola->SetParab2d(tmpparabola->Parab2d()); + this->myCurve->SetTrim(tmpcurve->FirstParameter(), tmpcurve->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dArcOfParabola::getPyObject(void) +{ + return 0; + //return new ArcOfParabolaPy(static_cast(this->clone())); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dLine, Part::Geom2dCurve) + +Geom2dLine::Geom2dLine() +{ + Handle_Geom2d_Line c = new Geom2d_Line(gp_Lin2d()); + this->myCurve = c; +} + +Geom2dLine::Geom2dLine(const Handle_Geom2d_Line& l) +{ + this->myCurve = Handle_Geom2d_Line::DownCast(l->Copy()); +} + +Geom2dLine::Geom2dLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir) +{ + this->myCurve = new Geom2d_Line(gp_Pnt2d(Pos.x,Pos.y),gp_Dir2d(Dir.x,Dir.y)); +} + +Geom2dLine::~Geom2dLine() +{ +} + +void Geom2dLine::setLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir) +{ + this->myCurve->SetLocation(gp_Pnt2d(Pos.x,Pos.y)); + this->myCurve->SetDirection(gp_Dir2d(Dir.x,Dir.y)); +} + +Base::Vector2d Geom2dLine::getPos(void) const +{ + gp_Pnt2d Pos = this->myCurve->Lin2d().Location(); + return Base::Vector2d(Pos.X(),Pos.Y()); +} + +Base::Vector2d Geom2dLine::getDir(void) const +{ + gp_Dir2d Dir = this->myCurve->Lin2d().Direction(); + return Base::Vector2d(Dir.X(),Dir.Y()); +} + +const Handle_Geom2d_Geometry& Geom2dLine::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dLine::clone(void) const +{ + Geom2dLine *newLine = new Geom2dLine(myCurve); + return newLine; +} + +unsigned int Geom2dLine::getMemSize (void) const +{ + return sizeof(Geom2d_Line); +} + +void Geom2dLine::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geometry2d::Save(writer); + + Base::Vector2d Pos = getPos(); + Base::Vector2d Dir = getDir(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dLine::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double PosX,PosY,DirX,DirY; + // read my Element + reader.readElement("Geom2dLine"); + // get the value of my Attribute + PosX = reader.getAttributeAsFloat("PosX"); + PosY = reader.getAttributeAsFloat("PosY"); + DirX = reader.getAttributeAsFloat("DirX"); + DirY = reader.getAttributeAsFloat("DirY"); + gp_Pnt2d pnt(PosX, PosY); + gp_Dir2d dir(DirX, DirY); + + try { + GCE2d_MakeLine mc(pnt, dir); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dLine::getPyObject(void) +{ + return 0; +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dLineSegment, Part::Geom2dCurve) + +Geom2dLineSegment::Geom2dLineSegment() +{ + gp_Lin2d line; + line.SetLocation(gp_Pnt2d(0.0,0.0)); + line.SetDirection(gp_Dir2d(0.0,1.0)); + Handle_Geom2d_Line c = new Geom2d_Line(line); + this->myCurve = new Geom2d_TrimmedCurve(c, 0.0,1.0); +} + +Geom2dLineSegment::~Geom2dLineSegment() +{ +} + +void Geom2dLineSegment::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + Handle_Geom2d_Line basis = Handle_Geom2d_Line::DownCast(c->BasisCurve()); + if (basis.IsNull()) + Standard_Failure::Raise("Basis curve is not a line"); + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dLineSegment::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dLineSegment::clone(void)const +{ + Geom2dLineSegment *tempCurve = new Geom2dLineSegment(); + tempCurve->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(myCurve->Copy()); + return tempCurve; +} + +Base::Vector2d Geom2dLineSegment::getStartPoint() const +{ + Handle_Geom2d_TrimmedCurve this_curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + gp_Pnt2d pnt = this_curve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +Base::Vector2d Geom2dLineSegment::getEndPoint() const +{ + Handle_Geom2d_TrimmedCurve this_curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + gp_Pnt2d pnt = this_curve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +void Geom2dLineSegment::setPoints(const Base::Vector2d& Start, const Base::Vector2d& End) +{ + gp_Pnt2d p1(Start.x,Start.y), p2(End.x,End.y); + Handle_Geom2d_TrimmedCurve this_curv = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + + try { + // Create line out of two points + if (p1.Distance(p2) < gp::Resolution()) + Standard_Failure::Raise("Both points are equal"); + GCE2d_MakeSegment ms(p1, p2); + if (!ms.IsDone()) { + throw Base::Exception(gce_ErrorStatusText(ms.Status())); + } + + // get Geom_Line of line segment + Handle_Geom2d_Line this_line = Handle_Geom2d_Line::DownCast + (this_curv->BasisCurve()); + Handle_Geom2d_TrimmedCurve that_curv = ms.Value(); + Handle_Geom2d_Line that_line = Handle_Geom2d_Line::DownCast(that_curv->BasisCurve()); + this_line->SetLin2d(that_line->Lin2d()); + this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +unsigned int Geom2dLineSegment::getMemSize (void) const +{ + return sizeof(Geom2d_TrimmedCurve) + sizeof(Geom2d_Line); +} + +void Geom2dLineSegment::Save(Base::Writer &writer) const +{ + // save the attributes of the father class + Geom2dCurve::Save(writer); + + Base::Vector2d End = getEndPoint(); + Base::Vector2d Start = getStartPoint(); + + writer.Stream() + << writer.ind() + << "" << endl; +} + +void Geom2dLineSegment::Restore(Base::XMLReader &reader) +{ + // read the attributes of the father class + Geom2dCurve::Restore(reader); + + double StartX,StartY,EndX,EndY; + // read my Element + reader.readElement("Geom2dLineSegment"); + // get the value of my Attribute + StartX = reader.getAttributeAsFloat("StartX"); + StartY = reader.getAttributeAsFloat("StartY"); + EndX = reader.getAttributeAsFloat("EndX"); + EndY = reader.getAttributeAsFloat("EndY"); + + gp_Pnt2d p1(StartX, StartY); + gp_Pnt2d p2(EndX, EndY); + + try { + GCE2d_MakeSegment mc(p1, p2); + if (!mc.IsDone()) + throw Base::Exception(gce_ErrorStatusText(mc.Status())); + + this->myCurve = mc.Value(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +PyObject *Geom2dLineSegment::getPyObject(void) +{ + return 0; + //return new LinePy((GeomLineSegment*)this->clone()); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dOffsetCurve, Part::Geom2dCurve) + +Geom2dOffsetCurve::Geom2dOffsetCurve() +{ +} + +Geom2dOffsetCurve::Geom2dOffsetCurve(const Handle_Geom2d_Curve& c, double offset) +{ + this->myCurve = new Geom2d_OffsetCurve(c, offset); +} + +Geom2dOffsetCurve::Geom2dOffsetCurve(const Handle_Geom2d_OffsetCurve& c) +{ + this->myCurve = Handle_Geom2d_OffsetCurve::DownCast(c->Copy()); +} + +Geom2dOffsetCurve::~Geom2dOffsetCurve() +{ +} + +Geometry2d *Geom2dOffsetCurve::clone(void) const +{ + Geom2dOffsetCurve *newCurve = new Geom2dOffsetCurve(myCurve); + return newCurve; +} + +void Geom2dOffsetCurve::setHandle(const Handle_Geom2d_OffsetCurve& c) +{ + this->myCurve = Handle_Geom2d_OffsetCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dOffsetCurve::handle() const +{ + return this->myCurve; +} + +unsigned int Geom2dOffsetCurve::getMemSize (void) const +{ + throw Base::NotImplementedError("Geom2dOffsetCurve::getMemSize"); +} + +void Geom2dOffsetCurve::Save(Base::Writer &/*writer*/) const +{ + throw Base::NotImplementedError("Geom2dOffsetCurve::Save"); +} + +void Geom2dOffsetCurve::Restore(Base::XMLReader &/*reader*/) +{ + throw Base::NotImplementedError("Geom2dOffsetCurve::Restore"); +} + +PyObject *Geom2dOffsetCurve::getPyObject(void) +{ + //return new OffsetCurvePy((GeomOffsetCurve*)this->clone()); + return 0; +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dTrimmedCurve, Part::Geom2dCurve) + +Geom2dTrimmedCurve::Geom2dTrimmedCurve() +{ +} + +Geom2dTrimmedCurve::Geom2dTrimmedCurve(const Handle_Geom2d_TrimmedCurve& c) +{ + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +Geom2dTrimmedCurve::~Geom2dTrimmedCurve() +{ +} + +void Geom2dTrimmedCurve::setHandle(const Handle_Geom2d_TrimmedCurve& c) +{ + this->myCurve = Handle_Geom2d_TrimmedCurve::DownCast(c->Copy()); +} + +const Handle_Geom2d_Geometry& Geom2dTrimmedCurve::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dTrimmedCurve::clone(void) const +{ + Geom2dTrimmedCurve *newCurve = new Geom2dTrimmedCurve(myCurve); + return newCurve; +} + +unsigned int Geom2dTrimmedCurve::getMemSize (void) const +{ + throw Base::NotImplementedError("Geom2dTrimmedCurve::getMemSize"); +} + +void Geom2dTrimmedCurve::Save(Base::Writer &/*writer*/) const +{ + throw Base::NotImplementedError("Geom2dTrimmedCurve::Save"); +} + +void Geom2dTrimmedCurve::Restore(Base::XMLReader &/*reader*/) +{ + throw Base::NotImplementedError("Geom2dTrimmedCurve::Restore"); +} + +PyObject *Geom2dTrimmedCurve::getPyObject(void) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geometry2d.h b/src/Mod/Part/App/Geometry2d.h new file mode 100644 index 000000000..1d431af8a --- /dev/null +++ b/src/Mod/Part/App/Geometry2d.h @@ -0,0 +1,556 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PART_GEOMETRY2D_H +#define PART_GEOMETRY2D_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Part { + +class PartExport Geometry2d : public Base::Persistence +{ + TYPESYSTEM_HEADER(); +public: + virtual ~Geometry2d(); + + virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const = 0; + virtual const Handle_Geom2d_Geometry& handle() const = 0; + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + /// returns a cloned object + virtual Geometry2d *clone(void) const = 0; + +protected: + Geometry2d(); + +private: + Geometry2d(const Geometry2d&); + Geometry2d& operator = (const Geometry2d&); +}; + +class PartExport Geom2dPoint : public Geometry2d +{ + TYPESYSTEM_HEADER(); +public: + Geom2dPoint(); + Geom2dPoint(const Handle_Geom2d_CartesianPoint&); + Geom2dPoint(const Base::Vector2d&); + virtual ~Geom2dPoint(); + virtual Geometry2d *clone(void) const; + virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + const Handle_Geom2d_Geometry& handle() const; + + Base::Vector2d getPoint(void)const; + void setPoint(const Base::Vector2d&); + +private: + Handle_Geom2d_CartesianPoint myPoint; +}; + +class PartExport Geom2dCurve : public Geometry2d +{ + TYPESYSTEM_HEADER(); +public: + Geom2dCurve(); + virtual ~Geom2dCurve(); + + virtual TopoDS_Shape toShape(const Handle_Geom_Surface&) const; + bool tangent(double u, gp_Dir2d&) const; + Base::Vector2d pointAtParameter(double u) const; + Base::Vector2d firstDerivativeAtParameter(double u) const; + Base::Vector2d secondDerivativeAtParameter(double u) const; + bool normal(double u, gp_Dir2d& dir) const; + bool closestParameter(const Base::Vector2d& point, double &u) const; + bool closestParameterToBasicCurve(const Base::Vector2d& point, double &u) const; +}; + +class PartExport Geom2dBezierCurve : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dBezierCurve(); + Geom2dBezierCurve(const Handle_Geom2d_BezierCurve&); + virtual ~Geom2dBezierCurve(); + virtual Geometry2d *clone(void) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize (void) const; + virtual void Save (Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_BezierCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_BezierCurve myCurve; +}; + +class PartExport Geom2dBSplineCurve : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dBSplineCurve(); + Geom2dBSplineCurve(const Handle_Geom2d_BSplineCurve&); + virtual ~Geom2dBSplineCurve(); + virtual Geometry2d *clone(void) const; + + /*! + * Set the poles and tangents for the cubic Hermite spline + */ + void interpolate(const std::vector&, const std::vector&); + /*! + * Compute the tangents for a Cardinal spline using the + * the cubic Hermite spline. It uses the method for Cardinal splines. + */ + void getCardinalSplineTangents(const std::vector&, + const std::vector&, + std::vector&) const; + /*! + * Compute the tangents for a Cardinal spline using the + * the cubic Hermite spline. It uses the method for Cardinal splines. + * It uses the same parameter for each tangent. + */ + void getCardinalSplineTangents(const std::vector&, double, + std::vector&) const; + + int countPoles() const; + void setPole(int index, const Base::Vector2d&, double weight=-1); + std::vector getPoles() const; + bool join(const Handle_Geom2d_BSplineCurve&); + void makeC1Continuous(double); + std::list toBiArcs(double tolerance) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_BSplineCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + void createArcs(double tolerance, std::list& new_spans, + const gp_Pnt2d &p_start, const gp_Vec2d &v_start, + double t_start, double t_end, gp_Pnt2d &p_end, gp_Vec2d &v_end) const; + bool calculateBiArcPoints(const gp_Pnt2d& p0, gp_Vec2d v_start, + const gp_Pnt2d& p4, gp_Vec2d v_end, + gp_Pnt2d& p1, gp_Pnt2d& p2, gp_Pnt2d& p3) const; +private: + Handle_Geom2d_BSplineCurve myCurve; +}; + +class PartExport Geom2dCircle : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dCircle(); + Geom2dCircle(const Handle_Geom2d_Circle&); + virtual ~Geom2dCircle(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getCenter(void) const; + double getRadius(void) const; + void setCenter(const Base::Vector2d& Center); + void setRadius(double Radius); + bool isReversed() const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_Circle myCurve; +}; + +class PartExport Geom2dArcOfCircle : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dArcOfCircle(); + Geom2dArcOfCircle(const Handle_Geom2d_Circle&); + virtual ~Geom2dArcOfCircle(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + Base::Vector2d getCenter(void) const; + double getRadius(void) const; + void setCenter(const Base::Vector2d& Center); + void setRadius(double Radius); + void getRange(double& u, double& v) const; + void setRange(double u, double v); + bool isReversed() const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +class PartExport Geom2dEllipse : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dEllipse(); + Geom2dEllipse(const Handle_Geom2d_Ellipse&); + virtual ~Geom2dEllipse(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getMajorRadius(void) const; + void setMajorRadius(double Radius); + double getMinorRadius(void) const; + void setMinorRadius(double Radius); + Base::Vector2d getMajorAxisDir() const; + void setMajorAxisDir(Base::Vector2d newdir); + bool isReversed() const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_Ellipse &e); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_Ellipse myCurve; +}; + +class PartExport Geom2dArcOfEllipse : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dArcOfEllipse(); + Geom2dArcOfEllipse(const Handle_Geom2d_Ellipse&); + virtual ~Geom2dArcOfEllipse(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getMajorRadius(void) const; + void setMajorRadius(double Radius); + double getMinorRadius(void) const; + void setMinorRadius(double Radius); + Base::Vector2d getMajorAxisDir() const; + void setMajorAxisDir(Base::Vector2d newdir); + bool isReversed() const; + + void getRange(double& u, double& v) const; + void setRange(double u, double v); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +class PartExport Geom2dHyperbola : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dHyperbola(); + Geom2dHyperbola(const Handle_Geom2d_Hyperbola&); + virtual ~Geom2dHyperbola(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getMajorRadius(void) const; + void setMajorRadius(double Radius); + double getMinorRadius(void) const; + void setMinorRadius(double Radius); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_Hyperbola myCurve; +}; + +class PartExport Geom2dArcOfHyperbola : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dArcOfHyperbola(); + Geom2dArcOfHyperbola(const Handle_Geom2d_Hyperbola&); + virtual ~Geom2dArcOfHyperbola(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getMajorRadius(void) const; + void setMajorRadius(double Radius); + double getMinorRadius(void) const; + void setMinorRadius(double Radius); + + void getRange(double& u, double& v) const; + void setRange(double u, double v); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +class PartExport Geom2dParabola : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dParabola(); + Geom2dParabola(const Handle_Geom2d_Parabola&); + virtual ~Geom2dParabola(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getFocal(void) const; + void setFocal(double length); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_Parabola myCurve; +}; + +class PartExport Geom2dArcOfParabola : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dArcOfParabola(); + Geom2dArcOfParabola(const Handle_Geom2d_Parabola&); + virtual ~Geom2dArcOfParabola(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + double getFocal(void) const; + void setFocal(double length); + + void getRange(double& u, double& v) const; + void setRange(double u, double v); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +class PartExport Geom2dLine : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dLine(); + Geom2dLine(const Handle_Geom2d_Line&); + Geom2dLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir); + virtual ~Geom2dLine(); + virtual Geometry2d *clone(void) const; + + void setLine(const Base::Vector2d& Pos, const Base::Vector2d& Dir); + Base::Vector2d getPos(void) const; + Base::Vector2d getDir(void) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_Line myCurve; +}; + +class PartExport Geom2dLineSegment : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dLineSegment(); + virtual ~Geom2dLineSegment(); + virtual Geometry2d *clone(void) const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + void setPoints(const Base::Vector2d& p1, + const Base::Vector2d& p2); + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +class PartExport Geom2dOffsetCurve : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dOffsetCurve(); + Geom2dOffsetCurve(const Handle_Geom2d_Curve&, double); + Geom2dOffsetCurve(const Handle_Geom2d_OffsetCurve&); + virtual ~Geom2dOffsetCurve(); + virtual Geometry2d *clone(void) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_OffsetCurve& c); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_OffsetCurve myCurve; +}; + +class PartExport Geom2dTrimmedCurve : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +public: + Geom2dTrimmedCurve(); + Geom2dTrimmedCurve(const Handle_Geom2d_TrimmedCurve&); + virtual ~Geom2dTrimmedCurve(); + virtual Geometry2d *clone(void) const; + + // Persistence implementer --------------------- + virtual unsigned int getMemSize(void) const; + virtual void Save(Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + // Base implementer ---------------------------- + virtual PyObject *getPyObject(void); + + void setHandle(const Handle_Geom2d_TrimmedCurve&); + const Handle_Geom2d_Geometry& handle() const; + +private: + Handle_Geom2d_TrimmedCurve myCurve; +}; + +} + +#endif // PART_GEOMETRY2D_H