Skip to content

Commit

Permalink
+ Implement persistence of GeomEllipse
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 5, 2013
1 parent fdff852 commit dc1cd7b
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 4 deletions.
130 changes: 126 additions & 4 deletions src/Mod/Part/App/Geometry.cpp
Expand Up @@ -77,6 +77,7 @@
# include <Geom_TrimmedCurve.hxx>
# include <GC_MakeArcOfCircle.hxx>
# include <GC_MakeCircle.hxx>
# include <GC_MakeEllipse.hxx>
# include <GC_MakeLine.hxx>
# include <GC_MakeSegment.hxx>
# include <Precision.hxx>
Expand Down Expand Up @@ -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()
<< "<Ellipse "
<< "CenterX=\"" << center.X() << "\" "
<< "CenterY=\"" << center.Y() << "\" "
<< "CenterZ=\"" << center.Z() << "\" "
<< "NormalX=\"" << normal.X() << "\" "
<< "NormalY=\"" << normal.Y() << "\" "
<< "NormalZ=\"" << normal.Z() << "\" "
<< "MajorRadius=\"" << this->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)
{
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Mod/Part/App/Geometry.h
Expand Up @@ -238,6 +238,13 @@ class PartExport GeomEllipse : public GeomCurve
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;
Expand Down

0 comments on commit dc1cd7b

Please sign in to comment.