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 <QSharedPointer>
#include "../vpatterndb/variables/vinternalvariable.h" #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 QPlainTextEdit;
class QPushButton; class QPushButton;
@ -43,7 +47,6 @@ class QLabel;
class QWidget; class QWidget;
class QColor; class QColor;
class QLineEdit; class QLineEdit;
class VContainer;
class QListWidget; class QListWidget;
class VPieceNode; class VPieceNode;
@ -85,4 +88,32 @@ bool EachPointLabelIsUnique(QListWidget *listWidget);
QString DialogWarningIcon(); QString DialogWarningIcon();
QFont NodeFont(QFont font, bool nodeExcluded = false); 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 #endif // DIALOGTOOLBOX_H

View File

@ -260,12 +260,23 @@ void DialogAlongLine::closeEvent(QCloseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::SetCurrentLength() void DialogAlongLine::SetCurrentLength()
{
VLengthLine *length = nullptr;
try
{ {
const QSharedPointer<VPointF> p1 = data->GeometricObject<VPointF>(GetFirstPointId()); const QSharedPointer<VPointF> p1 = data->GeometricObject<VPointF>(GetFirstPointId());
const QSharedPointer<VPointF> p2 = data->GeometricObject<VPointF>(GetSecondPointId()); const QSharedPointer<VPointF> p2 = data->GeometricObject<VPointF>(GetSecondPointId());
VLengthLine *length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), GetSecondPointId(), *data->GetPatternUnit());
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); length->SetName(currentLength);
VContainer *locData = const_cast<VContainer *> (data); VContainer *locData = const_cast<VContainer *> (data);

View File

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

View File

@ -219,12 +219,15 @@ void DialogCubicBezierPath::PointChanged(int row)
void DialogCubicBezierPath::currentPointChanged(int index) void DialogCubicBezierPath::currentPointChanged(int index)
{ {
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index)); const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
QColor color;
try
{
QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() );
const auto point = data->GeometricObject<VPointF>(id); const auto point = data->GeometricObject<VPointF>(id);
DataPoint(*point); DataPoint(*point);
item->setData(Qt::UserRole, QVariant::fromValue(*point)); item->setData(Qt::UserRole, QVariant::fromValue(*point));
QColor color;
if (not IsPathValid()) if (not IsPathValid())
{ {
flagError = false; flagError = false;
@ -258,6 +261,15 @@ void DialogCubicBezierPath::currentPointChanged(int index)
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); 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->labelName, color);
ChangeColor(ui->labelPoint, color); ChangeColor(ui->labelPoint, color);
CheckState(); CheckState();

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutarc.h" #include "../../visualization/path/vistoolcutarc.h"
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
@ -196,14 +195,7 @@ void DialogCutArc::closeEvent(QCloseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::ArcChanged() void DialogCutArc::ArcChanged()
{ {
vidtype arcId = getArcId(); CurrentCurveLength<VArc>(getArcId(), const_cast<VContainer *> (data));
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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutspline.h" #include "../../visualization/path/vistoolcutspline.h"
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
@ -203,14 +202,7 @@ void DialogCutSpline::closeEvent(QCloseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::SplineChanged() void DialogCutSpline::SplineChanged()
{ {
vidtype splId = getSplineId(); CurrentCurveLength<VSpline>(getSplineId(), const_cast<VContainer *> (data));
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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -38,7 +38,6 @@
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/variables/vcurvelength.h"
#include "../../visualization/path/vistoolcutsplinepath.h" #include "../../visualization/path/vistoolcutsplinepath.h"
#include "../../visualization/visualization.h" #include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
@ -203,14 +202,7 @@ void DialogCutSplinePath::closeEvent(QCloseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::SplinePathChanged() void DialogCutSplinePath::SplinePathChanged()
{ {
vidtype splPathId = getSplinePathId(); CurrentCurveLength<VSplinePath>(getSplinePathId(), const_cast<VContainer *> (data));
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);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

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

View File

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

View File

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

View File

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

View File

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