Resolved issue #519. Error: Crash with Union tool.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-06-30 16:02:59 +03:00
parent 750fe98ea4
commit 8a8f63e88e
6 changed files with 43 additions and 33 deletions

View File

@ -42,6 +42,8 @@ public:
virtual ~VAbstractCubicBezier(); virtual ~VAbstractCubicBezier();
virtual VPointF GetP1 () const =0; virtual VPointF GetP1 () const =0;
virtual VPointF GetP2 () const =0;
virtual VPointF GetP3 () const =0;
virtual VPointF GetP4 () const =0; virtual VPointF GetP4 () const =0;
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;

View File

@ -48,10 +48,10 @@ public:
virtual VPointF GetP1() const Q_DECL_OVERRIDE; virtual VPointF GetP1() const Q_DECL_OVERRIDE;
void SetP1(const VPointF &p); void SetP1(const VPointF &p);
VPointF GetP2() const; virtual VPointF GetP2() const Q_DECL_OVERRIDE;
void SetP2(const VPointF &p); void SetP2(const VPointF &p);
VPointF GetP3() const; virtual VPointF GetP3() const Q_DECL_OVERRIDE;
void SetP3(const VPointF &p); void SetP3(const VPointF &p);
virtual VPointF GetP4() const Q_DECL_OVERRIDE; virtual VPointF GetP4() const Q_DECL_OVERRIDE;

View File

@ -222,11 +222,11 @@ void VSpline::SetP1(const VPointF &p)
* @brief GetP2 return first control point. * @brief GetP2 return first control point.
* @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()); QLineF p1p2(d->p1.x(), d->p1.y(), d->p1.x() + d->c1Length, d->p1.y());
p1p2.setAngle(d->angle1); 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. * @brief GetP3 return second control point.
* @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()); QLineF p4p3(d->p4.x(), d->p4.y(), d->p4.x() + d->c2Length, d->p4.y());
p4p3.setAngle(d->angle2); p4p3.setAngle(d->angle2);
return p4p3.p2(); return VPointF(p4p3.p2());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -59,8 +59,8 @@ public:
virtual VPointF GetP1 () const Q_DECL_OVERRIDE; virtual VPointF GetP1 () const Q_DECL_OVERRIDE;
void SetP1 (const VPointF &p); void SetP1 (const VPointF &p);
QPointF GetP2 () const; virtual VPointF GetP2 () const Q_DECL_OVERRIDE;
QPointF GetP3 () const; virtual VPointF GetP3 () const Q_DECL_OVERRIDE;
virtual VPointF GetP4 () const Q_DECL_OVERRIDE; virtual VPointF GetP4 () const Q_DECL_OVERRIDE;
void SetP4 (const VPointF &p); void SetP4 (const VPointF &p);

View File

@ -173,7 +173,8 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte
} }
else else
{ {
const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId()); const QSharedPointer<VAbstractCubicBezier> spline =
data->GeometricObject<VAbstractCubicBezier>(det.at(i).getId());
const QPointF p = *data->GeometricObject<VPointF>(pRotate); const QPointF p = *data->GeometricObject<VPointF>(pRotate);
VPointF *p1 = new VPointF(spline->GetP1()); VPointF *p1 = new VPointF(spline->GetP1());
@ -212,14 +213,11 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte
{ {
VSplinePath *path = new VSplinePath(); VSplinePath *path = new VSplinePath();
path->setMode(Draw::Modeling); path->setMode(Draw::Modeling);
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId()); const QSharedPointer<VAbstractCubicBezierPath> splinePath =
data->GeometricObject<VAbstractCubicBezierPath>(det.at(i).getId());
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
{ {
const VSplinePoint &point1 = splinePath->at(i-1); const VSpline spline = splinePath->GetSpline(i);
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 QPointF p = *data->GeometricObject<VPointF>(pRotate); const QPointF p = *data->GeometricObject<VPointF>(pRotate);
VPointF *p1 = new VPointF(spline.GetP1()); VPointF *p1 = new VPointF(spline.GetP1());
@ -241,16 +239,22 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte
const QString angle1F = QString().number(angle1); const QString angle1F = QString().number(angle1);
path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(), path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(),
point1.Length1(), point1.Length1Formula(), point1.Length2(), 0, "0", spline.GetC1Length(), spline.GetC1LengthFormula()));
point1.Length2Formula()));
} }
const qreal angle2 = spl.GetEndAngle()+180; const qreal angle2 = spl.GetEndAngle()+180;
const QString angle2F = QString().number(angle2); 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, path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F,
point2.Length1(), point2.Length1Formula(), point2.Length2(), spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F));
point2.Length2Formula()));
delete p4; delete p4;
delete p1; delete p1;
@ -332,7 +336,8 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const
{ {
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0) if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != 0)
{ {
const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(det.at(i).getId()); const QSharedPointer<VAbstractCubicBezier> spline =
data->GeometricObject<VAbstractCubicBezier>(det.at(i).getId());
const QPointF p = *data->GeometricObject<VPointF>(pRotate); const QPointF p = *data->GeometricObject<VPointF>(pRotate);
VPointF *p1 = new VPointF(spline->GetP1()); VPointF *p1 = new VPointF(spline->GetP1());
@ -360,16 +365,12 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const
{ {
VSplinePath *path = new VSplinePath(); VSplinePath *path = new VSplinePath();
path->setMode(Draw::Modeling); path->setMode(Draw::Modeling);
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId()); const QSharedPointer<VAbstractCubicBezierPath> splinePath =
data->GeometricObject<VAbstractCubicBezierPath>(det.at(i).getId());
SCASSERT(splinePath != nullptr); SCASSERT(splinePath != nullptr);
for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i) for (qint32 i = 1; i <= splinePath->CountSubSpl(); ++i)
{ {
const VSplinePoint &point1 = splinePath->at(i-1); const VSpline spline = splinePath->GetSpline(i);
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 QPointF p = *data->GeometricObject<VPointF>(pRotate); const QPointF p = *data->GeometricObject<VPointF>(pRotate);
VPointF *p1 = new VPointF(spline.GetP1()); 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); const QString angle1F = QString().number(angle1);
path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(), path->append(VSplinePoint(*p1, angle1, angle1F, spl.GetStartAngle(), spl.GetStartAngleFormula(),
point1.Length1(), point1.Length1Formula(), point1.Length2(), 0, "0", spline.GetC1Length(), spline.GetC1LengthFormula()));
point1.Length2Formula()));
} }
const qreal angle2 = spl.GetEndAngle()+180; const qreal angle2 = spl.GetEndAngle()+180;
const QString angle2F = QString().number(angle2); 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, path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F,
point2.Length1(), point2.Length1Formula(), point2.Length2(), spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F));
point2.Length2Formula()));
delete p1; delete p1;
delete p4; delete p4;

View File

@ -392,8 +392,8 @@ void TST_VSpline::TestLengthByPoint()
void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const void TST_VSpline::CompareSplines(const VSpline &spl1, const VSpline &spl2) const
{ {
QCOMPARE(spl1.GetP1().toQPointF().toPoint(), spl2.GetP1().toQPointF().toPoint()); QCOMPARE(spl1.GetP1().toQPointF().toPoint(), spl2.GetP1().toQPointF().toPoint());
QCOMPARE(spl1.GetP2().toPoint(), spl2.GetP2().toPoint()); QCOMPARE(spl1.GetP2().toQPointF().toPoint(), spl2.GetP2().toQPointF().toPoint());
QCOMPARE(spl1.GetP3().toPoint(), spl2.GetP3().toPoint()); QCOMPARE(spl1.GetP3().toQPointF().toPoint(), spl2.GetP3().toQPointF().toPoint());
QCOMPARE(spl1.GetP4().toQPointF().toPoint(), spl2.GetP4().toQPointF().toPoint()); QCOMPARE(spl1.GetP4().toQPointF().toPoint(), spl2.GetP4().toQPointF().toPoint());
QCOMPARE(spl1.GetStartAngle(), spl2.GetStartAngle()); QCOMPARE(spl1.GetStartAngle(), spl2.GetStartAngle());