From 8a8f63e88e26b40211956d47be20fc23b46ccd4c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 30 Jun 2016 16:02:59 +0300 Subject: [PATCH] Resolved issue #519. Error: Crash with Union tool. --HG-- branch : develop --- src/libs/vgeometry/vabstractcubicbezier.h | 2 + src/libs/vgeometry/vcubicbezier.h | 4 +- src/libs/vgeometry/vspline.cpp | 8 +-- src/libs/vgeometry/vspline.h | 4 +- src/libs/vtools/tools/vtooluniondetails.cpp | 54 ++++++++++++--------- src/test/ValentinaTest/tst_vspline.cpp | 4 +- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/libs/vgeometry/vabstractcubicbezier.h b/src/libs/vgeometry/vabstractcubicbezier.h index 2f2825b51..abf75dc1e 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.h +++ b/src/libs/vgeometry/vabstractcubicbezier.h @@ -42,6 +42,8 @@ public: virtual ~VAbstractCubicBezier(); virtual VPointF GetP1 () const =0; + virtual VPointF GetP2 () const =0; + virtual VPointF GetP3 () const =0; virtual VPointF GetP4 () const =0; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; diff --git a/src/libs/vgeometry/vcubicbezier.h b/src/libs/vgeometry/vcubicbezier.h index 64d0009cd..40a3ccfd4 100644 --- a/src/libs/vgeometry/vcubicbezier.h +++ b/src/libs/vgeometry/vcubicbezier.h @@ -48,10 +48,10 @@ public: virtual VPointF GetP1() const Q_DECL_OVERRIDE; void SetP1(const VPointF &p); - VPointF GetP2() const; + virtual VPointF GetP2() const Q_DECL_OVERRIDE; void SetP2(const VPointF &p); - VPointF GetP3() const; + virtual VPointF GetP3() const Q_DECL_OVERRIDE; void SetP3(const VPointF &p); virtual VPointF GetP4() const Q_DECL_OVERRIDE; diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 5cd4b8fc9..ca30af63d 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -222,11 +222,11 @@ void VSpline::SetP1(const VPointF &p) * @brief GetP2 return first control point. * @return first control point. */ -QPointF VSpline::GetP2() const +VPointF VSpline::GetP2() const { QLineF p1p2(d->p1.x(), d->p1.y(), d->p1.x() + d->c1Length, d->p1.y()); p1p2.setAngle(d->angle1); - return p1p2.p2(); + return VPointF(p1p2.p2()); } //--------------------------------------------------------------------------------------------------------------------- @@ -234,11 +234,11 @@ QPointF VSpline::GetP2() const * @brief GetP3 return second control point. * @return second control point. */ -QPointF VSpline::GetP3() const +VPointF VSpline::GetP3() const { QLineF p4p3(d->p4.x(), d->p4.y(), d->p4.x() + d->c2Length, d->p4.y()); p4p3.setAngle(d->angle2); - return p4p3.p2(); + return VPointF(p4p3.p2()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index 5b0de7ac7..3666f0c66 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -59,8 +59,8 @@ public: virtual VPointF GetP1 () const Q_DECL_OVERRIDE; void SetP1 (const VPointF &p); - QPointF GetP2 () const; - QPointF GetP3 () const; + virtual VPointF GetP2 () const Q_DECL_OVERRIDE; + virtual VPointF GetP3 () const Q_DECL_OVERRIDE; virtual VPointF GetP4 () const Q_DECL_OVERRIDE; void SetP4 (const VPointF &p); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 2b1840e90..11aaf9960 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -173,7 +173,8 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte } else { - const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); + const QSharedPointer spline = + data->GeometricObject(det.at(i).getId()); const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline->GetP1()); @@ -212,14 +213,11 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte { VSplinePath *path = new VSplinePath(); path->setMode(Draw::Modeling); - const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); + const QSharedPointer splinePath = + data->GeometricObject(det.at(i).getId()); for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) { - const VSplinePoint &point1 = splinePath->at(i-1); - const VSplinePoint &point2 = splinePath->at(i); - VSpline spline(point1.P(), point2.P(), point1.Angle2(), point1.Angle2Formula(), point2.Angle1(), - point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(), - point2.Length1Formula()); + const VSpline spline = splinePath->GetSpline(i); const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline.GetP1()); @@ -241,16 +239,22 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte const QString angle1F = QString().number(angle1); path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(), - point1.Length1(), point1.Length1Formula(), point1.Length2(), - point1.Length2Formula())); + 0, "0", spline.GetC1Length(), spline.GetC1LengthFormula())); } const qreal angle2 = spl.GetEndAngle()+180; const QString angle2F = QString().number(angle2); + qreal pL2 = 0; + QString pL2F("0"); + if (i+1 <= splinePath->CountSubSpl()) + { + const VSpline nextSpline = splinePath->GetSpline(i+1); + pL2 = nextSpline.GetC1Length(); + pL2F = nextSpline.GetC1LengthFormula(); + } path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F, - point2.Length1(), point2.Length1Formula(), point2.Length2(), - point2.Length2Formula())); + spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F)); delete p4; delete p1; @@ -332,7 +336,8 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) { - const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); + const QSharedPointer spline = + data->GeometricObject(det.at(i).getId()); const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline->GetP1()); @@ -360,16 +365,12 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { VSplinePath *path = new VSplinePath(); path->setMode(Draw::Modeling); - const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); + const QSharedPointer splinePath = + data->GeometricObject(det.at(i).getId()); SCASSERT(splinePath != nullptr); for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) { - const VSplinePoint &point1 = splinePath->at(i-1); - const VSplinePoint &point2 = splinePath->at(i); - - VSpline spline(point1.P(), point2.P(), point1.Angle2(), point1.Angle2Formula(), point2.Angle1(), - point2.Angle1Formula(), point1.Length2(), point1.Length2Formula(), point2.Length1(), - point2.Length1Formula()); + const VSpline spline = splinePath->GetSpline(i); const QPointF p = *data->GeometricObject(pRotate); VPointF *p1 = new VPointF(spline.GetP1()); @@ -391,16 +392,23 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const const QString angle1F = QString().number(angle1); path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(), - point1.Length1(), point1.Length1Formula(), point1.Length2(), - point1.Length2Formula())); + 0, "0", spline.GetC1Length(), spline.GetC1LengthFormula())); } const qreal angle2 = spl.GetEndAngle()+180; const QString angle2F = QString().number(angle2); + qreal pL2 = 0; + QString pL2F("0"); + if (i+1 <= splinePath->CountSubSpl()) + { + const VSpline nextSpline = splinePath->GetSpline(i+1); + pL2 = nextSpline.GetC1Length(); + pL2F = nextSpline.GetC1LengthFormula(); + } + path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F, - point2.Length1(), point2.Length1Formula(), point2.Length2(), - point2.Length2Formula())); + spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F)); delete p1; delete p4; diff --git a/src/test/ValentinaTest/tst_vspline.cpp b/src/test/ValentinaTest/tst_vspline.cpp index ae5b5c8ca..b5c0e206e 100644 --- a/src/test/ValentinaTest/tst_vspline.cpp +++ b/src/test/ValentinaTest/tst_vspline.cpp @@ -392,8 +392,8 @@ void TST_VSpline::TestLengthByPoint() void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const { QCOMPARE(spl1.GetP1().toQPointF().toPoint(), spl2.GetP1().toQPointF().toPoint()); - QCOMPARE(spl1.GetP2().toPoint(), spl2.GetP2().toPoint()); - QCOMPARE(spl1.GetP3().toPoint(), spl2.GetP3().toPoint()); + QCOMPARE(spl1.GetP2().toQPointF().toPoint(), spl2.GetP2().toQPointF().toPoint()); + QCOMPARE(spl1.GetP3().toQPointF().toPoint(), spl2.GetP3().toQPointF().toPoint()); QCOMPARE(spl1.GetP4().toQPointF().toPoint(), spl2.GetP4().toQPointF().toPoint()); QCOMPARE(spl1.GetStartAngle(), spl2.GetStartAngle());