From e7dacb9178dab1d5df2e3276b884d6ebf36987bd Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 10 Jan 2017 14:44:43 +0100 Subject: [PATCH] Part: Bezier serialization support extension to periodic ======================================================= Extension for periodic + suggestions by Werner. --- src/Mod/Part/App/Geometry.cpp | 91 ++++++++++++++++------------------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index ff5459493fd1..89ecd1adc6ce 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -813,10 +813,11 @@ void GeomBSplineCurve::Save(Base::Writer& writer) const GeomCurve::Save(writer); std::vector poles = this->getPoles(); - std::vector weights = this->getWeights(); - std::vector knots = this->getKnots(); - std::vector mults = this->getMultiplicities(); - int degree = this->getDegree(); + std::vector weights = this->getWeights(); + std::vector knots = this->getKnots(); + std::vector mults = this->getMultiplicities(); + int degree = this->getDegree(); + bool isperiodic = this->IsPeriodic(); writer.Stream() << writer.ind() @@ -824,39 +825,37 @@ void GeomBSplineCurve::Save(Base::Writer& writer) const << "PolesCount=\"" << poles.size() << "\" KnotsCount=\"" << knots.size() << "\" Degree=\"" << degree << + "\" IsPeriodic=\"" << (int) isperiodic << "\">" << endl; writer.incInd(); - for(std::vector::const_iterator it = poles.begin(); it != poles.end(); ++it){ + + std::vector::const_iterator itp; + std::vector::const_iterator itw; + + for(itp = poles.begin(), itw = weights.begin(); itp != poles.end() && itw != weights.end(); ++itp, ++itw){ writer.Stream() << writer.ind() << "" << endl; - } - for(std::vector::const_iterator it = weights.begin(); it != weights.end(); ++it){ - writer.Stream() - << writer.ind() - << "" << endl; } - for(std::vector::const_iterator it = knots.begin(); it != knots.end(); ++it){ + + std::vector::const_iterator itk; + std::vector::const_iterator itm; + + for(itk = knots.begin(), itm = mults.begin(); itk != knots.end() && itm != mults.end(); ++itk, ++itm){ writer.Stream() << writer.ind() << "" << endl; - } - for(std::vector::const_iterator it = mults.begin(); it != mults.end(); ++it){ - writer.Stream() - << writer.ind() - << "" << endl; } + writer.decInd(); writer.Stream() << writer.ind() << "" << endl ; } @@ -871,8 +870,8 @@ void GeomBSplineCurve::Restore(Base::XMLReader& reader) int polescount = reader.getAttributeAsInteger("PolesCount"); int knotscount = reader.getAttributeAsInteger("KnotsCount"); int degree = reader.getAttributeAsInteger("Degree"); - - // You are here!! + bool isperiodic = (bool) reader.getAttributeAsInteger("IsPeriodic"); + // Handle_Geom_BSplineCurve spline = new // Geom_BSplineCurve(occpoles,occweights,occknots,occmults,degree, // PyObject_IsTrue(periodic) ? Standard_True : Standard_False, @@ -882,39 +881,31 @@ void GeomBSplineCurve::Restore(Base::XMLReader& reader) TColStd_Array1OfReal w(1,polescount); TColStd_Array1OfReal k(1,knotscount); TColStd_Array1OfInteger m(1,knotscount); - + for (int i = 1; i <= polescount; i++) { reader.readElement("Pole"); - double X = reader.getAttributeAsFloat("X"); - double Y = reader.getAttributeAsFloat("Y"); - double Z = reader.getAttributeAsFloat("Z"); - p.SetValue(i, gp_Pnt(X,Y,Z)); - } - - for (int i = 1; i <= polescount; i++) { - reader.readElement("Weight"); - double val = reader.getAttributeAsFloat("value"); - w.SetValue(i, val); + double X = reader.getAttributeAsFloat("X"); + double Y = reader.getAttributeAsFloat("Y"); + double Z = reader.getAttributeAsFloat("Z"); + double W = reader.getAttributeAsFloat("Weight"); + p.SetValue(i, gp_Pnt(X,Y,Z)); + w.SetValue(i, W); } - + for (int i = 1; i <= knotscount; i++) { reader.readElement("Knot"); - double val = reader.getAttributeAsFloat("value"); - k.SetValue(i, val); + double val = reader.getAttributeAsFloat("Value"); + Standard_Integer mult = reader.getAttributeAsInteger("Mult"); + k.SetValue(i, val); + m.SetValue(i, mult); } - - for (int i = 1; i <= knotscount; i++) { - reader.readElement("Mult"); - double val = reader.getAttributeAsInteger("value"); - m.SetValue(i, val); - } - + reader.readEndElement("BSplineCurve"); // Geom_BSplineCurve(occpoles,occweights,occknots,occmults,degree,periodic,CheckRational - + try { - Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(p, w, k, m, degree, Standard_False, Standard_False); - + Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(p, w, k, m, degree, isperiodic==true?Standard_True:Standard_False, Standard_False); + if (!spline.IsNull()) this->myCurve = spline; else