diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index a15642ffa..4298a9ddc 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -260,7 +260,7 @@ void MainWindow::AddPP(const QString &PPName) comboBoxDraws->blockSignals(true); comboBoxDraws->addItem(PPName); - pattern->ClearGObjects(); + pattern->ClearCalculationGObjects(); //Create single point ui->view->itemClicked(nullptr);//hide options previous tool const QString label = doc->GenerateLabel(LabelType::NewPatternPiece); diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 10caece95..1e2820220 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -103,10 +103,7 @@ VContainer::VContainer(const VContainer &data) //--------------------------------------------------------------------------------------------------------------------- VContainer::~VContainer() -{ - ClearGObjects(); - ClearVariables(); -} +{} //--------------------------------------------------------------------------------------------------------------------- /** @@ -115,9 +112,20 @@ VContainer::~VContainer() * @return point */ // cppcheck-suppress unusedFunction -const QSharedPointer VContainer::GetGObject(quint32 id)const +const QSharedPointer VContainer::GetGObject(quint32 id) const { - return GetObject(d->gObjects, id); + if (d->calculationObjects.contains(id)) + { + return d->calculationObjects.value(id); + } + else if (d->modelingObjects->contains(id)) + { + return d->modelingObjects->value(id); + } + else + { + throw VExceptionBadId(tr("Can't find object"), id); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -129,26 +137,6 @@ const QSharedPointer VContainer::GetFakeGObject(quint32 id) return pointer; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetObject return object from container - * @param obj container - * @param id id of object - * @return Object - */ -template -const val VContainer::GetObject(const QHash &obj, key id) const -{ - if (obj.contains(id)) - { - return obj.value(id); - } - else - { - throw VExceptionBadId(tr("Can't find object"), id); - } -} - //--------------------------------------------------------------------------------------------------------------------- VPiece VContainer::GetPiece(quint32 id) const { @@ -192,8 +180,27 @@ quint32 VContainer::AddGObject(VGObject *obj) quint32 VContainer::AddGObject(const QSharedPointer &obj) { SCASSERT(not obj.isNull()) + + if (obj->getMode() == Draw::Layout) + { + qWarning("Can't add an object with mode 'Layout'"); + return NULL_ID; + } + uniqueNames.insert(obj->name()); - return AddObject(d->gObjects, obj); + const quint32 id = getNextId(); + obj->setId(id); + + if (obj->getMode() == Draw::Calculation) + { + d->calculationObjects.insert(id, obj); + } + else if (obj->getMode() == Draw::Modeling) + { + d->modelingObjects->insert(id, obj); + } + + return id; } //--------------------------------------------------------------------------------------------------------------------- @@ -290,33 +297,14 @@ void VContainer::ClearForFullParse() */ void VContainer::ClearGObjects() { - d->gObjects.clear(); + d->calculationObjects.clear(); + d->modelingObjects->clear(); } //--------------------------------------------------------------------------------------------------------------------- void VContainer::ClearCalculationGObjects() { - if (not d->gObjects.isEmpty()) //-V807 - { - QVector keys; - QHash >::iterator i; - for (i = d->gObjects.begin(); i != d->gObjects.end(); ++i) - { - if (i.value()->getMode() == Draw::Calculation) - { - i.value().clear(); - keys.append(i.key()); - } - } - // We can't delete objects in previous loop it will destroy the iterator. - if (not keys.isEmpty()) - { - for (int i = 0; i < keys.size(); ++i) - { - d->gObjects.remove(keys.at(i)); - } - } - } + d->calculationObjects.clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -464,23 +452,6 @@ void VContainer::RemovePiece(quint32 id) d->pieces->remove(id); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddObject add object to container - * @param obj container - * @param value object - * @return id of object in container - */ -template -quint32 VContainer::AddObject(QHash &obj, val value) -{ - SCASSERT(value != nullptr) - const quint32 id = getNextId(); - value->setId(id); - obj[id] = value; - return id; -} - //--------------------------------------------------------------------------------------------------------------------- void VContainer::UpdatePiece(quint32 id, const VPiece &detail) { @@ -678,9 +649,9 @@ qreal *VContainer::rheight() * @brief data container with datagObjects return container of gObjects * @return pointer on container of gObjects */ -const QHash > *VContainer::DataGObjects() const +const QHash > *VContainer::CalculationGObjects() const { - return &d->gObjects; + return &d->calculationObjects; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 2837bbddd..65999883d 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -69,7 +69,8 @@ class VContainerData : public QSharedData //-V690 public: VContainerData(const VTranslateVars *trVars, const Unit *patternUnit) - : gObjects(QHash >()), + : calculationObjects(QHash >()), + modelingObjects(QSharedPointer>>::create()), variables(QHash > ()), pieces(QSharedPointer>::create()), piecePaths(QSharedPointer>::create()), @@ -79,7 +80,8 @@ public: VContainerData(const VContainerData &data) : QSharedData(data), - gObjects(data.gObjects), + calculationObjects(data.calculationObjects), + modelingObjects(data.modelingObjects), variables(data.variables), pieces(data.pieces), piecePaths(data.piecePaths), @@ -89,10 +91,8 @@ public: virtual ~VContainerData(); - /** - * @brief gObjects graphicals objects of pattern. - */ - QHash > gObjects; + QHash > calculationObjects; + QSharedPointer>> modelingObjects; /** * @brief variables container for measurements, increments, lines lengths, lines angles, arcs lengths, curve lengths @@ -184,7 +184,7 @@ public: void RemoveIncrement(const QString& name); - const QHash > *DataGObjects() const; + const QHash > *CalculationGObjects() const; const QHash *DataPieces() const; const QHash> *DataVariables() const; @@ -219,16 +219,9 @@ private: template uint qHash( const QSharedPointer &p ); - template - // cppcheck-suppress functionStatic - const val GetObject(const QHash &obj, key id) const; - template void UpdateObject(const quint32 &id, const QSharedPointer &point); - template - static quint32 AddObject(QHash &obj, val value); - template const QMap > DataVar(const VarType &type) const; }; @@ -248,25 +241,23 @@ const QSharedPointer VContainer::GeometricObject(const quint32 &id) const throw VExceptionBadId(tr("Can't find object"), id); } - QSharedPointer gObj = QSharedPointer(); - if (d->gObjects.contains(id)) + QSharedPointer gObj; + if (d->calculationObjects.contains(id)) { - gObj = d->gObjects.value(id); + gObj = d->calculationObjects.value(id); + } + else if (d->modelingObjects->contains(id)) + { + gObj = d->modelingObjects->value(id); } else { throw VExceptionBadId(tr("Can't find object"), id); } - try - { - QSharedPointer obj = qSharedPointerDynamicCast(gObj); - SCASSERT(obj.isNull() == false) - return obj; - } - catch (const std::bad_alloc &) - { - throw VExceptionBadId(tr("Can't cast object"), id); - } + + QSharedPointer obj = qSharedPointerDynamicCast(gObj); + SCASSERT(obj.isNull() == false) + return obj; } @@ -375,19 +366,39 @@ void VContainer::UpdateObject(const quint32 &id, const QSharedPointer &point) Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712 SCASSERT(point.isNull() == false) point->setId(id); - if (d->gObjects.contains(id)) + + if (d->calculationObjects.contains(id) && point->getMode() == Draw::Calculation) { - QSharedPointer obj = qSharedPointerDynamicCast(d->gObjects.value(id)); + QSharedPointer obj = qSharedPointerDynamicCast(d->calculationObjects.value(id)); if (obj.isNull()) { throw VExceptionBadId(tr("Can't cast object"), id); } *obj = *point; } + else if (d->modelingObjects->contains(id) && point->getMode() == Draw::Modeling) + { + QSharedPointer obj = qSharedPointerDynamicCast(d->modelingObjects->value(id)); + if (obj.isNull()) + { + throw VExceptionBadId(tr("Can't cast object"), id); + } + *obj = *point; + } + else if (point->getMode() == Draw::Calculation) + { + d->calculationObjects.insert(id, point); + } + else if (point->getMode() == Draw::Modeling) + { + d->modelingObjects->insert(id, point); + } else { - d->gObjects.insert(id, point); + qWarning("Can't update an object with mode 'Layout'"); + return; } + UpdateId(id); } #endif // VCONTAINER_H diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 513e6709f..53f13eccc 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -215,7 +215,7 @@ void DialogTool::FillComboBoxSplines(QComboBox *box) const SCASSERT(box != nullptr) box->blockSignals(true); - const auto objs = data->DataGObjects(); + const auto objs = data->CalculationGObjects(); QHash >::const_iterator i; QMap list; for (i = objs->constBegin(); i != objs->constEnd(); ++i) @@ -239,7 +239,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box) const SCASSERT(box != nullptr) box->blockSignals(true); - const auto objs = data->DataGObjects(); + const auto objs = data->CalculationGObjects(); QHash >::const_iterator i; QMap list; for (i = objs->constBegin(); i != objs->constEnd(); ++i) @@ -261,7 +261,7 @@ void DialogTool::FillComboBoxSplinesPath(QComboBox *box) const void DialogTool::FillComboBoxCurves(QComboBox *box) const { SCASSERT(box != nullptr) - const auto objs = data->DataGObjects(); + const auto objs = data->CalculationGObjects(); QMap list; QHash >::const_iterator i; for (i = objs->constBegin(); i != objs->constEnd(); ++i) @@ -269,12 +269,12 @@ void DialogTool::FillComboBoxCurves(QComboBox *box) const if (i.key() != toolId) { QSharedPointer obj = i.value(); - if ((obj->getType() == GOType::Arc - || obj->getType() == GOType::EllipticalArc - || obj->getType() == GOType::Spline - || obj->getType() == GOType::SplinePath - || obj->getType() == GOType::CubicBezier - || obj->getType() == GOType::CubicBezierPath) && obj->getMode() == Draw::Calculation) + if (obj->getType() == GOType::Arc + || obj->getType() == GOType::EllipticalArc + || obj->getType() == GOType::Spline + || obj->getType() == GOType::SplinePath + || obj->getType() == GOType::CubicBezier + || obj->getType() == GOType::CubicBezierPath) { PrepareList(list, i.key()); } @@ -683,8 +683,7 @@ void DialogTool::InitNodeAngles(QComboBox *box) //--------------------------------------------------------------------------------------------------------------------- bool DialogTool::IsSplinePath(const QSharedPointer &obj) const { - return (obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezierPath) && - obj->getMode() == Draw::Calculation; + return obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezierPath; } //--------------------------------------------------------------------------------------------------------------------- @@ -1010,8 +1009,7 @@ void DialogTool::PrepareList(QMap &list, quint32 id) const //--------------------------------------------------------------------------------------------------------------------- bool DialogTool::IsSpline(const QSharedPointer &obj) const { - return (obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier) && - obj->getMode() == Draw::Calculation; + return obj->getType() == GOType::Spline || obj->getType() == GOType::CubicBezier; } //--------------------------------------------------------------------------------------------------------------------- @@ -1290,7 +1288,7 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, cons SCASSERT(box != nullptr) box->blockSignals(true); - const QHash > *objs = data->DataGObjects(); + const QHash > *objs = data->CalculationGObjects(); QHash >::const_iterator i; QMap list; for (i = objs->constBegin(); i != objs->constEnd(); ++i) @@ -1300,7 +1298,7 @@ void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule, cons if (i.key() != toolId && i.key() != ch1 && i.key() != ch2) { QSharedPointer obj = i.value(); - if (obj->getType() == gType && obj->getMode() == Draw::Calculation) + if (obj->getType() == gType) { PrepareList(list, i.key()); } diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 07d94fffe..75d99cfa7 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -83,35 +83,6 @@ template class QSharedPointer; const QString VAbstractTool::AttrInUse = QStringLiteral("inUse"); -namespace -{ -//--------------------------------------------------------------------------------------------------------------------- -quint32 CreateNodeSpline(VContainer *data, quint32 id) -{ - if (data->GetGObject(id)->getType() == GOType::Spline) - { - return VAbstractTool::CreateNode(data, id); - } - else - { - return VAbstractTool::CreateNode(data, id); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -quint32 CreateNodeSplinePath(VContainer *data, quint32 id) -{ - if (data->GetGObject(id)->getType() == GOType::SplinePath) - { - return VAbstractTool::CreateNode(data, id); - } - else - { - return VAbstractTool::CreateNode(data, id); - } -} -}//static functions - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VAbstractTool container. @@ -379,7 +350,7 @@ QMap VAbstractTool::ColorsList() // cppcheck-suppress unusedFunction QMap VAbstractTool::PointsList() const { - const QHash > *objs = data.DataGObjects(); + const QHash > *objs = data.CalculationGObjects(); QMap list; QHash >::const_iterator i; for (i = objs->constBegin(); i != objs->constEnd(); ++i) @@ -387,7 +358,7 @@ QMap VAbstractTool::PointsList() const if (i.key() != m_id) { QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Point && obj->getMode() == Draw::Calculation) + if (obj->getType() == GOType::Point) { const QSharedPointer point = data.GeometricObject(i.key()); list[point->name()] = i.key(); @@ -694,3 +665,29 @@ quint32 VAbstractTool::PrepareNode(const VPieceNode &node, VMainGraphicsScene *s } return initData.id; } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VAbstractTool::CreateNodeSpline(VContainer *data, quint32 id) +{ + if (data->GetGObject(id)->getType() == GOType::Spline) + { + return VAbstractTool::CreateNode(data, id); + } + else + { + return VAbstractTool::CreateNode(data, id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VAbstractTool::CreateNodeSplinePath(VContainer *data, quint32 id) +{ + if (data->GetGObject(id)->getType() == GOType::SplinePath) + { + return VAbstractTool::CreateNode(data, id); + } + else + { + return VAbstractTool::CreateNode(data, id); + } +}