Fix a crash. ref #984.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-11-07 18:07:07 +02:00
parent f1c95e9046
commit f8ca985ad7
12 changed files with 252 additions and 165 deletions

View File

@ -33,6 +33,10 @@
#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;
@ -43,7 +47,6 @@ class QLabel;
class QWidget;
class QColor;
class QLineEdit;
class VContainer;
class QListWidget;
class VPieceNode;
@ -85,4 +88,32 @@ 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

@ -260,12 +260,23 @@ void DialogAlongLine::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::SetCurrentLength()
{
VLengthLine *length = nullptr;
try
{
const QSharedPointer<VPointF> p1 = data->GeometricObject<VPointF>(GetFirstPointId());
const QSharedPointer<VPointF> p2 = data->GeometricObject<VPointF>(GetSecondPointId());
VLengthLine *length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(),
GetSecondPointId(), *data->GetPatternUnit());
length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), GetSecondPointId(), *data->GetPatternUnit());
}
catch (const VExceptionBadId &)
{
QScopedPointer<VPointF> p1(new VPointF());
QScopedPointer<VPointF> p2(new VPointF());
length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), GetSecondPointId(), *data->GetPatternUnit());
}
SCASSERT(length != nullptr)
length->SetName(currentLength);
VContainer *locData = const_cast<VContainer *> (data);

View File

@ -193,6 +193,8 @@ void DialogCubicBezier::PointNameChanged()
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
}
else
{
try
{
VCubicBezier spline(*GetP1(), *GetP2(), *GetP3(), *GetP4());
@ -203,6 +205,12 @@ void DialogCubicBezier::PointNameChanged()
}
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name()));
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
}
}
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelFirstPoint, color);

View File

@ -219,12 +219,15 @@ void DialogCubicBezierPath::PointChanged(int row)
void DialogCubicBezierPath::currentPointChanged(int index)
{
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
QColor color;
try
{
QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() );
const auto point = data->GeometricObject<VPointF>(id);
DataPoint(*point);
item->setData(Qt::UserRole, QVariant::fromValue(*point));
QColor color;
if (not IsPathValid())
{
flagError = false;
@ -258,6 +261,15 @@ void DialogCubicBezierPath::currentPointChanged(int index)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name()));
}
}
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id));
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelPoint, color);
CheckState();

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutarc.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -196,14 +195,7 @@ void DialogCutArc::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::ArcChanged()
{
vidtype arcId = getArcId();
const QSharedPointer<VAbstractCurve> arc = data->GeometricObject<VArc>(arcId);
VCurveLength *length = new VCurveLength(arcId, arcId, arc.data(), *data->GetPatternUnit());
length->SetName(currentLength);
VContainer *locData = const_cast<VContainer *> (data);
locData->AddVariable(currentLength, length);
CurrentCurveLength<VArc>(getArcId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutspline.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -203,14 +202,7 @@ void DialogCutSpline::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SplineChanged()
{
vidtype splId = getSplineId();
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splId);
VCurveLength *length = new VCurveLength(splId, splId, spl.data(), *data->GetPatternUnit());
length->SetName(currentLength);
VContainer *locData = const_cast<VContainer *> (data);
locData->AddVariable(currentLength, length);
CurrentCurveLength<VSpline>(getSplineId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutsplinepath.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -203,14 +202,7 @@ void DialogCutSplinePath::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SplinePathChanged()
{
vidtype splPathId = getSplinePathId();
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splPathId);
VCurveLength *length = new VCurveLength(splPathId, splPathId, splPath.data(), *data->GetPatternUnit());
length->SetName(currentLength);
VContainer *locData = const_cast<VContainer *> (data);
locData->AddVariable(currentLength, length);
CurrentCurveLength<VSplinePath>(getSplinePathId(), const_cast<VContainer *> (data));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -268,11 +268,14 @@ void DialogHeight::PointNameChanged()
set.insert(p1LineId);
set.insert(p2LineId);
QColor color;
try
{
const QPointF basePoint = static_cast<QPointF>(*data->GeometricObject<VPointF>(basePointId));
const QPointF p1Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p1LineId));
const QPointF p2Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p2LineId));
QColor color;
if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF())
{
flagError = false;
@ -283,6 +286,13 @@ void DialogHeight::PointNameChanged()
flagError = true;
color = OkColor(this);
}
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
}
ChangeColor(ui->labelBasePoint, color);
ChangeColor(ui->labelFirstLinePoint, color);
ChangeColor(ui->labelSecondLinePoint, color);

View File

@ -215,6 +215,10 @@ void DialogLineIntersect::PointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersect::PointNameChanged()
{
QColor color;
try
{
QSet<quint32> set;
const quint32 p1Line1Id = getCurrentObjectId(ui->comboBoxP1Line1);
@ -237,7 +241,7 @@ void DialogLineIntersect::PointNameChanged()
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
QColor color;
if (set.size() < 3 || intersect == QLineF::NoIntersection)
{
flagError = false;
@ -248,6 +252,13 @@ void DialogLineIntersect::PointNameChanged()
flagError = true;
color = OkColor(this);
}
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
}
ChangeColor(ui->labelP1Line1, color);
ChangeColor(ui->labelP2Line1, color);
ChangeColor(ui->labelP1Line2, color);
@ -267,6 +278,8 @@ void DialogLineIntersect::ShowVisualization()
* @return true - line have intersection, false = don't have
*/
bool DialogLineIntersect::CheckIntersecion()
{
try
{
const QSharedPointer<VPointF> p1L1 = data->GeometricObject<VPointF>(GetP1Line1());
const QSharedPointer<VPointF> p2L1 = data->GeometricObject<VPointF>(GetP2Line1());
@ -277,11 +290,9 @@ bool DialogLineIntersect::CheckIntersecion()
QLineF line2(static_cast<QPointF>(*p1L2), static_cast<QPointF>(*p2L2));
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
{
return true;
return intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection;
}
else
catch (const VExceptionBadId &)
{
return false;
}

View File

@ -217,6 +217,8 @@ void DialogRotation::ShowDialog(bool click)
/*We will ignore click if pointer is in point circle*/
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
try
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetOrigPointId());
const QLineF line = QLineF(static_cast<QPointF>(*point), scene->getScenePos());
@ -225,6 +227,11 @@ void DialogRotation::ShowDialog(bool click)
{
return;
}
}
catch (const VExceptionBadId &)
{
return;
}
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
SCASSERT(operation != nullptr)

View File

@ -487,9 +487,10 @@ void DialogSpline::PointNameChanged()
}
else
{
VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(), spl.GetKasm2(),
spl.GetKcurve());
try
{
VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(),
spl.GetKasm2(), spl.GetKcurve());
if (not data->IsUnique(spline.name()))
{
newDuplicate = static_cast<qint32>(DNumber(spline.name()));
@ -497,6 +498,12 @@ void DialogSpline::PointNameChanged()
}
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name()));
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
}
}
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelFirstPoint, color);

View File

@ -617,15 +617,20 @@ void DialogSplinePath::PointChanged(int row)
void DialogSplinePath::currentPointChanged(int index)
{
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
QColor color;
try
{
QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
const auto point = data->GeometricObject<VPointF>(id);
p.SetP(*point);
DataPoint(p);
item->setData(Qt::UserRole, QVariant::fromValue(p));
ShowPointIssue(p.P().name());
QColor color;
if (not IsPathValid())
{
flagError = false;
@ -659,6 +664,15 @@ void DialogSplinePath::currentPointChanged(int index)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name()));
}
}
}
catch (const VExceptionBadId &)
{
flagError = false;
color = errorColor;
ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id));
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelPoint, color);
CheckState();