From f8ca985ad7eac2c93ef2af539829ba981adc0f47 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 7 Nov 2019 18:07:07 +0200 Subject: [PATCH] Fix a crash. ref #984. --HG-- branch : develop --- src/libs/vtools/dialogs/dialogtoolbox.h | 33 ++++++- .../vtools/dialogs/tools/dialogalongline.cpp | 19 +++- .../dialogs/tools/dialogcubicbezier.cpp | 20 +++-- .../dialogs/tools/dialogcubicbezierpath.cpp | 76 +++++++++------- .../vtools/dialogs/tools/dialogcutarc.cpp | 10 +-- .../vtools/dialogs/tools/dialogcutspline.cpp | 10 +-- .../dialogs/tools/dialogcutsplinepath.cpp | 10 +-- .../vtools/dialogs/tools/dialogheight.cpp | 30 ++++--- .../dialogs/tools/dialoglineintersect.cpp | 89 +++++++++++-------- .../vtools/dialogs/tools/dialogrotation.cpp | 15 +++- .../vtools/dialogs/tools/dialogspline.cpp | 21 +++-- .../vtools/dialogs/tools/dialogsplinepath.cpp | 84 +++++++++-------- 12 files changed, 252 insertions(+), 165 deletions(-) diff --git a/src/libs/vtools/dialogs/dialogtoolbox.h b/src/libs/vtools/dialogs/dialogtoolbox.h index 38ce98a22..257be42f1 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.h +++ b/src/libs/vtools/dialogs/dialogtoolbox.h @@ -33,6 +33,10 @@ #include #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 +void CurrentCurveLength(vidtype curveId, VContainer *data); + + +//--------------------------------------------------------------------------------------------------------------------- +template +void CurrentCurveLength(vidtype curveId, VContainer *data) +{ + SCASSERT(data != nullptr) + VCurveLength *length = nullptr; + try + { + const QSharedPointer curve = data->GeometricObject(curveId); + + length = new VCurveLength(curveId, curveId, curve.data(), *data->GetPatternUnit()); + } + catch (const VExceptionBadId &) + { + QScopedPointer 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 diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index bf1f0c57a..56c2c9228 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -261,11 +261,22 @@ void DialogAlongLine::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogAlongLine::SetCurrentLength() { - const QSharedPointer p1 = data->GeometricObject(GetFirstPointId()); - const QSharedPointer p2 = data->GeometricObject(GetSecondPointId()); + VLengthLine *length = nullptr; + try + { + const QSharedPointer p1 = data->GeometricObject(GetFirstPointId()); + const QSharedPointer p2 = data->GeometricObject(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 p1(new VPointF()); + QScopedPointer p2(new VPointF()); + length = new VLengthLine(p1.data(), GetFirstPointId(), p2.data(), GetSecondPointId(), *data->GetPatternUnit()); + } + + SCASSERT(length != nullptr) length->SetName(currentLength); VContainer *locData = const_cast (data); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index 213fbcdcf..008d6e99b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -194,14 +194,22 @@ void DialogCubicBezier::PointNameChanged() } else { - VCubicBezier spline(*GetP1(), *GetP2(), *GetP3(), *GetP4()); - - if (not data->IsUnique(spline.name())) + try { - newDuplicate = static_cast(DNumber(spline.name())); - spline.SetDuplicate(static_cast(newDuplicate)); + VCubicBezier spline(*GetP1(), *GetP2(), *GetP3(), *GetP4()); + + if (not data->IsUnique(spline.name())) + { + newDuplicate = static_cast(DNumber(spline.name())); + spline.SetDuplicate(static_cast(newDuplicate)); + } + ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name())); + } + catch (const VExceptionBadId &) + { + flagError = false; + color = errorColor; } - ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name())); } } ChangeColor(ui->labelName, color); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index 4e9b3834a..91b1096e2 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -219,45 +219,57 @@ void DialogCubicBezierPath::PointChanged(int row) void DialogCubicBezierPath::currentPointChanged(int index) { const quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); - QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); - const auto point = data->GeometricObject(id); - DataPoint(*point); - item->setData(Qt::UserRole, QVariant::fromValue(*point)); - QColor color; - if (not IsPathValid()) + + try + { + QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); + const auto point = data->GeometricObject(id); + DataPoint(*point); + item->setData(Qt::UserRole, QVariant::fromValue(*point)); + + if (not IsPathValid()) + { + flagError = false; + color = errorColor; + + ui->lineEditSplPathName->setText(tr("Invalid spline path")); + } + else + { + flagError = true; + color = OkColor(this); + + auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); + + if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id()) + { + newDuplicate = -1; + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); + } + else + { + VCubicBezierPath newPath = ExtractPath(); + + if (not data->IsUnique(newPath.name())) + { + newDuplicate = static_cast(DNumber(newPath.name())); + newPath.SetDuplicate(static_cast(newDuplicate)); + } + + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); + } + } + } + catch (const VExceptionBadId &) { flagError = false; color = errorColor; - ui->lineEditSplPathName->setText(tr("Invalid spline path")); + ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id)); } - else - { - flagError = true; - color = OkColor(this); - auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); - auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); - - if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id()) - { - newDuplicate = -1; - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); - } - else - { - VCubicBezierPath newPath = ExtractPath(); - - if (not data->IsUnique(newPath.name())) - { - newDuplicate = static_cast(DNumber(newPath.name())); - newPath.SetDuplicate(static_cast(newDuplicate)); - } - - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); - } - } ChangeColor(ui->labelName, color); ChangeColor(ui->labelPoint, color); CheckState(); diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index be86891d3..adf15987c 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -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 arc = data->GeometricObject(arcId); - - VCurveLength *length = new VCurveLength(arcId, arcId, arc.data(), *data->GetPatternUnit()); - length->SetName(currentLength); - - VContainer *locData = const_cast (data); - locData->AddVariable(currentLength, length); + CurrentCurveLength(getArcId(), const_cast (data)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 023a30b80..866f419b9 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -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 spl = data->GeometricObject(splId); - - VCurveLength *length = new VCurveLength(splId, splId, spl.data(), *data->GetPatternUnit()); - length->SetName(currentLength); - - VContainer *locData = const_cast (data); - locData->AddVariable(currentLength, length); + CurrentCurveLength(getSplineId(), const_cast (data)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index c21b626a7..b9b3ae26c 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -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 splPath = data->GeometricObject(splPathId); - - VCurveLength *length = new VCurveLength(splPathId, splPathId, splPath.data(), *data->GetPatternUnit()); - length->SetName(currentLength); - - VContainer *locData = const_cast (data); - locData->AddVariable(currentLength, length); + CurrentCurveLength(getSplinePathId(), const_cast (data)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogheight.cpp b/src/libs/vtools/dialogs/tools/dialogheight.cpp index 12534c597..1fce3ef50 100644 --- a/src/libs/vtools/dialogs/tools/dialogheight.cpp +++ b/src/libs/vtools/dialogs/tools/dialogheight.cpp @@ -268,21 +268,31 @@ void DialogHeight::PointNameChanged() set.insert(p1LineId); set.insert(p2LineId); - const QPointF basePoint = static_cast(*data->GeometricObject(basePointId)); - const QPointF p1Line = static_cast(*data->GeometricObject(p1LineId)); - const QPointF p2Line = static_cast(*data->GeometricObject(p2LineId)); - QColor color; - if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF()) + + try + { + const QPointF basePoint = static_cast(*data->GeometricObject(basePointId)); + const QPointF p1Line = static_cast(*data->GeometricObject(p1LineId)); + const QPointF p2Line = static_cast(*data->GeometricObject(p2LineId)); + + if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF()) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = OkColor(this); + } + } + catch (const VExceptionBadId &) { flagError = false; color = errorColor; } - else - { - flagError = true; - color = OkColor(this); - } + ChangeColor(ui->labelBasePoint, color); ChangeColor(ui->labelFirstLinePoint, color); ChangeColor(ui->labelSecondLinePoint, color); diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp index 369d28f3c..c92789aa2 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp @@ -216,38 +216,49 @@ void DialogLineIntersect::PointChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogLineIntersect::PointNameChanged() { - QSet set; - const quint32 p1Line1Id = getCurrentObjectId(ui->comboBoxP1Line1); - const quint32 p2Line1Id = getCurrentObjectId(ui->comboBoxP2Line1); - const quint32 p1Line2Id = getCurrentObjectId(ui->comboBoxP1Line2); - const quint32 p2Line2Id = getCurrentObjectId(ui->comboBoxP2Line2); - - set.insert(p1Line1Id); - set.insert(p2Line1Id); - set.insert(p1Line2Id); - set.insert(p2Line2Id); - - const QSharedPointer p1Line1 = data->GeometricObject(p1Line1Id); - const QSharedPointer p2Line1 = data->GeometricObject(p2Line1Id); - const QSharedPointer p1Line2 = data->GeometricObject(p1Line2Id); - const QSharedPointer p2Line2 = data->GeometricObject(p2Line2Id); - - QLineF line1(static_cast(*p1Line1), static_cast(*p2Line1)); - QLineF line2(static_cast(*p1Line2), static_cast(*p2Line2)); - QPointF fPoint; - QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); - QColor color; - if (set.size() < 3 || intersect == QLineF::NoIntersection) + + try + { + QSet set; + const quint32 p1Line1Id = getCurrentObjectId(ui->comboBoxP1Line1); + const quint32 p2Line1Id = getCurrentObjectId(ui->comboBoxP2Line1); + const quint32 p1Line2Id = getCurrentObjectId(ui->comboBoxP1Line2); + const quint32 p2Line2Id = getCurrentObjectId(ui->comboBoxP2Line2); + + set.insert(p1Line1Id); + set.insert(p2Line1Id); + set.insert(p1Line2Id); + set.insert(p2Line2Id); + + const QSharedPointer p1Line1 = data->GeometricObject(p1Line1Id); + const QSharedPointer p2Line1 = data->GeometricObject(p2Line1Id); + const QSharedPointer p1Line2 = data->GeometricObject(p1Line2Id); + const QSharedPointer p2Line2 = data->GeometricObject(p2Line2Id); + + QLineF line1(static_cast(*p1Line1), static_cast(*p2Line1)); + QLineF line2(static_cast(*p1Line2), static_cast(*p2Line2)); + QPointF fPoint; + QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); + + + if (set.size() < 3 || intersect == QLineF::NoIntersection) + { + flagError = false; + color = errorColor; + } + else + { + flagError = true; + color = OkColor(this); + } + } + catch (const VExceptionBadId &) { flagError = false; color = errorColor; } - else - { - flagError = true; - color = OkColor(this); - } + ChangeColor(ui->labelP1Line1, color); ChangeColor(ui->labelP2Line1, color); ChangeColor(ui->labelP1Line2, color); @@ -268,20 +279,20 @@ void DialogLineIntersect::ShowVisualization() */ bool DialogLineIntersect::CheckIntersecion() { - const QSharedPointer p1L1 = data->GeometricObject(GetP1Line1()); - const QSharedPointer p2L1 = data->GeometricObject(GetP2Line1()); - const QSharedPointer p1L2 = data->GeometricObject(GetP1Line2()); - const QSharedPointer p2L2 = data->GeometricObject(GetP2Line2()); - - QLineF line1(static_cast(*p1L1), static_cast(*p2L1)); - QLineF line2(static_cast(*p1L2), static_cast(*p2L2)); - QPointF fPoint; - QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); - if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) + try { - return true; + const QSharedPointer p1L1 = data->GeometricObject(GetP1Line1()); + const QSharedPointer p2L1 = data->GeometricObject(GetP2Line1()); + const QSharedPointer p1L2 = data->GeometricObject(GetP1Line2()); + const QSharedPointer p2L2 = data->GeometricObject(GetP2Line2()); + + QLineF line1(static_cast(*p1L1), static_cast(*p2L1)); + QLineF line2(static_cast(*p1L2), static_cast(*p2L2)); + QPointF fPoint; + QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); + return intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection; } - else + catch (const VExceptionBadId &) { return false; } diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index c624537c7..a1f73e0a9 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -217,11 +217,18 @@ void DialogRotation::ShowDialog(bool click) /*We will ignore click if pointer is in point circle*/ VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr) - const QSharedPointer point = data->GeometricObject(GetOrigPointId()); - const QLineF line = QLineF(static_cast(*point), scene->getScenePos()); + try + { + const QSharedPointer point = data->GeometricObject(GetOrigPointId()); + const QLineF line = QLineF(static_cast(*point), scene->getScenePos()); - //Radius of point circle, but little bigger. Need handle with hover sizes. - if (line.length() <= ScaledRadius(SceneScale(qApp->getCurrentScene()))*1.5) + //Radius of point circle, but little bigger. Need handle with hover sizes. + if (line.length() <= ScaledRadius(SceneScale(qApp->getCurrentScene()))*1.5) + { + return; + } + } + catch (const VExceptionBadId &) { return; } diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 3bda245ad..599c157a3 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -487,15 +487,22 @@ void DialogSpline::PointNameChanged() } else { - VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(), spl.GetKasm2(), - spl.GetKcurve()); - - if (not data->IsUnique(spline.name())) + try { - newDuplicate = static_cast(DNumber(spline.name())); - spline.SetDuplicate(static_cast(newDuplicate)); + VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(), + spl.GetKasm2(), spl.GetKcurve()); + if (not data->IsUnique(spline.name())) + { + newDuplicate = static_cast(DNumber(spline.name())); + spline.SetDuplicate(static_cast(newDuplicate)); + } + ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name())); + } + catch (const VExceptionBadId &) + { + flagError = false; + color = errorColor; } - ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name())); } } ChangeColor(ui->labelName, color); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 583554e9e..d0e300051 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -617,48 +617,62 @@ void DialogSplinePath::PointChanged(int row) void DialogSplinePath::currentPointChanged(int index) { const quint32 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); - QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); - VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); - const auto point = data->GeometricObject(id); - p.SetP(*point); - DataPoint(p); - item->setData(Qt::UserRole, QVariant::fromValue(p)); - ShowPointIssue(p.P().name()); - QColor color; - if (not IsPathValid()) + + try + { + QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() ); + VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); + + const auto point = data->GeometricObject(id); + p.SetP(*point); + + DataPoint(p); + item->setData(Qt::UserRole, QVariant::fromValue(p)); + ShowPointIssue(p.P().name()); + + if (not IsPathValid()) + { + flagError = false; + color = errorColor; + + ui->lineEditSplPathName->setText(tr("Invalid spline path")); + } + else + { + flagError = true; + color = OkColor(this); + + auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); + auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); + + if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoints()-1).P().id()) + { + newDuplicate = -1; + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); + } + else + { + VSplinePath newPath = ExtractPath(); + + if (not data->IsUnique(newPath.name())) + { + newDuplicate = static_cast(DNumber(newPath.name())); + newPath.SetDuplicate(static_cast(newDuplicate)); + } + + ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); + } + } + } + catch (const VExceptionBadId &) { flagError = false; color = errorColor; - ui->lineEditSplPathName->setText(tr("Invalid spline path")); + ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id)); } - else - { - flagError = true; - color = OkColor(this); - auto first = qvariant_cast(ui->listWidget->item(0)->data(Qt::UserRole)); - auto last = qvariant_cast(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole)); - - if (first.P().id() == path.at(0).P().id() && last.P().id() == path.at(path.CountPoints()-1).P().id()) - { - newDuplicate = -1; - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); - } - else - { - VSplinePath newPath = ExtractPath(); - - if (not data->IsUnique(newPath.name())) - { - newDuplicate = static_cast(DNumber(newPath.name())); - newPath.SetDuplicate(static_cast(newDuplicate)); - } - - ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name())); - } - } ChangeColor(ui->labelName, color); ChangeColor(ui->labelPoint, color); CheckState();