From dc1cd7b45c5665134633bf6b95371b9524fa2a61 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 5 Nov 2013 12:52:20 +0100 Subject: [PATCH] + Implement persistence of GeomEllipse --- src/Mod/Part/App/Geometry.cpp | 130 ++++++++++++++++++++++++++++++++-- src/Mod/Part/App/Geometry.h | 7 ++ 2 files changed, 133 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 9e68d83f0..082122638 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -77,6 +77,7 @@ # include # include # include +# include # include # include # include @@ -826,10 +827,127 @@ Geometry *GeomEllipse::clone(void) const return newEllipse; } +Base::Vector3d GeomEllipse::getCenter(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + gp_Ax1 axis = ellipse->Axis(); + const gp_Pnt& loc = axis.Location(); + return Base::Vector3d(loc.X(),loc.Y(),loc.Z()); +} + +void GeomEllipse::setCenter(const Base::Vector3d& Center) +{ + gp_Pnt p1(Center.x,Center.y,Center.z); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + + try { + ellipse->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double GeomEllipse::getMajorRadius(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + return ellipse->MajorRadius(); +} + +void GeomEllipse::setMajorRadius(double Radius) +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + + try { + ellipse->SetMajorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + +double GeomEllipse::getMinorRadius(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + return ellipse->MinorRadius(); +} + +void GeomEllipse::setMinorRadius(double Radius) +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(handle()); + + try { + ellipse->SetMinorRadius(Radius); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } +} + // Persistence implementer -unsigned int GeomEllipse::getMemSize (void) const {assert(0); return 0;/* not implemented yet */} -void GeomEllipse::Save (Base::Writer &/*writer*/) const {assert(0); /* not implemented yet */} -void GeomEllipse::Restore (Base::XMLReader &/*reader*/) {assert(0); /* not implemented yet */} +unsigned int GeomEllipse::getMemSize (void) const +{ + return sizeof(Geom_Ellipse); +} + +void GeomEllipse::Save(Base::Writer& writer) const +{ + // save the attributes of the father class + GeomCurve::Save(writer); + + gp_Pnt center = this->myCurve->Axis().Location(); + gp_Dir normal = this->myCurve->Axis().Direction(); + + writer.Stream() + << writer.ind() + << "myCurve->MajorRadius() << "\" " + << "MinorRadius=\"" << this->myCurve->MinorRadius() << "\" " + << "/>" << endl; +} + +void GeomEllipse::Restore(Base::XMLReader& reader) +{ + // read the attributes of the father class + GeomCurve::Restore(reader); + + double CenterX,CenterY,CenterZ,NormalX,NormalY,NormalZ,MajorRadius,MinorRadius; + // read my Element + reader.readElement("Ellipse"); + // get the value of my Attribute + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + CenterZ = reader.getAttributeAsFloat("CenterZ"); + NormalX = reader.getAttributeAsFloat("NormalX"); + NormalY = reader.getAttributeAsFloat("NormalY"); + NormalZ = reader.getAttributeAsFloat("NormalZ"); + MajorRadius = reader.getAttributeAsFloat("MajorRadius"); + MinorRadius = reader.getAttributeAsFloat("MinorRadius"); + + // set the read geometry + gp_Pnt p1(CenterX,CenterY,CenterZ); + gp_Dir norm(NormalX,NormalY,NormalZ); + try { + GC_MakeEllipse mc(gp_Ax2(p1, norm), 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 *GeomEllipse::getPyObject(void) { @@ -1103,7 +1221,11 @@ void GeomLineSegment::setPoints(const Base::Vector3d& Start, const Base::Vector3 } // Persistence implementer -unsigned int GeomLineSegment::getMemSize (void) const {assert(0); return 0;/* not implemented yet */} +unsigned int GeomLineSegment::getMemSize (void) const +{ + return sizeof(Geom_TrimmedCurve) + sizeof(Geom_Line); +} + void GeomLineSegment::Save (Base::Writer &writer) const { // save the attributes of the father class diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index d04797083..b066cf9d5 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -238,6 +238,13 @@ public: virtual ~GeomEllipse(); virtual Geometry *clone(void) const; + Base::Vector3d getCenter(void) const; + void setCenter(const Base::Vector3d& 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;