Fix a crash. ref #984.

Cover cases with VCubicBezier and VCubicBezierPath.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-11-24 12:49:40 +02:00
parent 9e25e6de24
commit 2d63440549
5 changed files with 28 additions and 33 deletions

View file

@ -33,6 +33,9 @@
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vgeometry/vpointf.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../ifc/exception/vexceptionbadid.h"
#include "../vpatterndb/vcontainer.h"
#include <QDialog>
#include <QLabel>
@ -462,3 +465,24 @@ QFont NodeFont(QFont font, bool nodeExcluded)
font.setStrikeOut(nodeExcluded);
return font;
}
//---------------------------------------------------------------------------------------------------------------------
void CurrentCurveLength(vidtype curveId, VContainer *data)
{
SCASSERT(data != nullptr)
VCurveLength *length = nullptr;
try
{
const QSharedPointer<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(curveId);
length = new VCurveLength(curveId, curveId, curve.data(), *data->GetPatternUnit());
}
catch (const VExceptionBadId &)
{
length = new VCurveLength();
}
SCASSERT(length != nullptr)
length->SetName(currentLength);
data->AddVariable(currentLength, length);
}

View file

@ -33,10 +33,7 @@
#include <QSharedPointer>
#include "../vpatterndb/variables/vinternalvariable.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../vmisc/typedef.h"
#include "../ifc/exception/vexceptionbadid.h"
#include "../vpatterndb/vcontainer.h"
class QPlainTextEdit;
class QPushButton;
@ -47,6 +44,7 @@ class QLabel;
class QWidget;
class QColor;
class QLineEdit;
class VContainer;
class QListWidget;
class VPieceNode;
@ -87,33 +85,6 @@ bool DoubleCurves(QListWidget *listWidget);
bool EachPointLabelIsUnique(QListWidget *listWidget);
QString DialogWarningIcon();
QFont NodeFont(QFont font, bool nodeExcluded = false);
template <typename T>
void CurrentCurveLength(vidtype curveId, VContainer *data);
//---------------------------------------------------------------------------------------------------------------------
template<typename T>
void CurrentCurveLength(vidtype curveId, VContainer *data)
{
SCASSERT(data != nullptr)
VCurveLength *length = nullptr;
try
{
const QSharedPointer<T> curve = data->GeometricObject<T>(curveId);
length = new VCurveLength(curveId, curveId, curve.data(), *data->GetPatternUnit());
}
catch (const VExceptionBadId &)
{
QScopedPointer<T> curve(new T());
length = new VCurveLength(NULL_ID, NULL_ID, curve.data(), *data->GetPatternUnit());
}
SCASSERT(length != nullptr)
length->SetName(currentLength);
data->AddVariable(currentLength, length);
}
#endif // DIALOGTOOLBOX_H

View file

@ -195,7 +195,7 @@ void DialogCutArc::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::ArcChanged()
{
CurrentCurveLength<VArc>(getArcId(), const_cast<VContainer *> (data));
CurrentCurveLength(getArcId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -202,7 +202,7 @@ void DialogCutSpline::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SplineChanged()
{
CurrentCurveLength<VSpline>(getSplineId(), const_cast<VContainer *> (data));
CurrentCurveLength(getSplineId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -202,7 +202,7 @@ void DialogCutSplinePath::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SplinePathChanged()
{
CurrentCurveLength<VSplinePath>(getSplinePathId(), const_cast<VContainer *> (data));
CurrentCurveLength(getSplinePathId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------