From d72ea565cb9d61988efac3cd5469ca7b44914a86 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 8 Mar 2016 19:49:16 +0200 Subject: [PATCH] Fixed wrong handling with true darts points inside tool detail. (grafted from c84b1a66716faa7e171e5acb2824a7fb5702dd27) --HG-- branch : develop --- ChangeLog.txt | 3 + src/libs/vpatterndb/vdetail.cpp | 21 ++++-- src/libs/vpatterndb/vdetail.h | 2 +- .../vtools/tools/nodeDetails/vnodepoint.cpp | 51 +++++++++++++ .../vtools/tools/nodeDetails/vnodepoint.h | 3 + src/libs/vtools/tools/vtooluniondetails.cpp | 72 ++++++++++++++----- src/libs/vtools/tools/vtooluniondetails.h | 2 + src/libs/vtools/undocommands/adddet.cpp | 9 +-- src/libs/vtools/undocommands/deletedetail.cpp | 10 +-- .../vtools/undocommands/savedetailoptions.cpp | 19 +---- src/libs/vtools/undocommands/vundocommand.cpp | 56 +++++++++++++++ src/libs/vtools/undocommands/vundocommand.h | 4 ++ 12 files changed, 194 insertions(+), 58 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 329ba9eb5..1251243e3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,9 @@ - [#325] Check pattern for inverse compatibility. - [#385] Add 'Open Recent' option in Tape.exe, 'File' dropdown menu. +# Version 0.4.4 +- Fixed wrong handling with true darts points inside tool detail. + # Version 0.4.3 March 6, 2016 - [#456] Crash: broken formula + clicking on the f(x) symbol. - [#454] Crash: using CRTL+Z while using line tool diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 3c09862e0..1314d3d39 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -322,16 +322,16 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Missing find missing ids in detail. When we deleted object in detail and return this detail need + * @brief Missing find missing nodes in detail. When we deleted object in detail and return this detail need * understand, what nodes need make invisible. * @param det changed detail. - * @return list with missing detail. + * @return list with missing nodes. */ -QList VDetail::Missing(const VDetail &det) const +QVector VDetail::Missing(const VDetail &det) const { if (d->nodes.size() == det.CountNode()) //-V807 { - return QList(); + return QVector(); } QSet set1; @@ -346,9 +346,18 @@ QList VDetail::Missing(const VDetail &det) const set2.insert(det.at(j).getId()); } - QSet set3 = set1.subtract(set2); + const QList set3 = set1.subtract(set2).toList(); + QVector nodes; + for (qint32 i = 0; i < set3.size(); ++i) + { + const int index = indexOfNode(d->nodes, set3.at(i)); + if (index != -1) + { + nodes.append(d->nodes.at(index)); + } + } - return set3.toList(); + return nodes; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index ae72e2b94..fb57ab56e 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -76,7 +76,7 @@ public: void NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2)const; VDetail RemoveEdge(const quint32 &index) const; - QList Missing(const VDetail &det) const; + QVector Missing(const VDetail &det) const; QVector ContourPoints(const VContainer *data) const; QVector SeamAllowancePoints(const VContainer *data) const; diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 08bb62969..3b4cb520a 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -119,6 +119,57 @@ QString VNodePoint::getTagName() const return VNodePoint::TagName; } +//--------------------------------------------------------------------------------------------------------------------- +void VNodePoint::incrementReferens() +{ + ++_referens; + if (_referens == 1) + { + if (idTool != NULL_ID) + { + doc->IncrementReferens(idTool); + } + else + { + const QSharedPointer point = VAbstractTool::data.GeometricObject(idNode); + doc->IncrementReferens(point->getIdTool()); + } + ShowNode(); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VNodePoint::decrementReferens() +{ + if (_referens > 0) + { + --_referens; + } + if (_referens == 0) + { + if (idTool != NULL_ID) + { + doc->DecrementReferens(idTool); + } + else + { + const QSharedPointer point = VAbstractTool::data.GeometricObject(idNode); + doc->DecrementReferens(point->getIdTool()); + } + HideNode(); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::PointChoosed() { diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 2b97b59de..87a280b44 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -56,6 +56,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::NodePoint)}; virtual QString getTagName() const Q_DECL_OVERRIDE; + + virtual void incrementReferens() Q_DECL_OVERRIDE; + virtual void decrementReferens() Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; void NameChangePosition(const QPointF &pos); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 714bf7a7e..39d1a1b45 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -457,15 +457,8 @@ void VToolUnionDetails::incrementReferens() ++_referens; if (_referens == 1) { - for (int i = 0; i < d1.CountNode(); ++i) - { - doc->IncrementReferens(d1.at(i).getId()); - } - - for (int i = 0; i < d2.CountNode(); ++i) - { - doc->IncrementReferens(d2.at(i).getId()); - } + IncrementReferences(d1); + IncrementReferences(d2); QDomElement domElement = doc->elementById(id); if (domElement.isElement()) @@ -484,15 +477,8 @@ void VToolUnionDetails::decrementReferens() } if (_referens == 0) { - for (int i = 0; i < d1.CountNode(); ++i) - { - doc->DecrementReferens(d1.at(i).getId()); - } - - for (int i = 0; i < d2.CountNode(); ++i) - { - doc->DecrementReferens(d2.at(i).getId()); - } + DecrementReferences(d1); + DecrementReferences(d2); QDomElement domElement = doc->elementById(id); if (domElement.isElement()) @@ -900,6 +886,56 @@ void VToolUnionDetails::AddToModeling(const QDomElement &domElement) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::IncrementReferences(const VDetail &d) const +{ + for (int i = 0; i < d.CountNode(); ++i) + { + switch (d.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + const auto point = VAbstractTool::data.GeometricObject(d.at(i).getId()); + doc->IncrementReferens(point->getIdTool()); + break; + } + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + doc->IncrementReferens(d.at(i).getId()); + break; + default: + qDebug()<<"Get wrong tool type. Ignore."; + break; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::DecrementReferences(const VDetail &d) const +{ + for (int i = 0; i < d.CountNode(); ++i) + { + switch (d.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + const auto point = VAbstractTool::data.GeometricObject(d.at(i).getId()); + doc->DecrementReferens(point->getIdTool()); + break; + } + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + doc->DecrementReferens(d.at(i).getId()); + break; + default: + qDebug()<<"Get wrong tool type. Ignore."; + break; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolUnionDetails::SaveChildren(VAbstractPattern *doc, quint32 id, const QVector &children) { diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index ae2a5791b..5a4d20edd 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -113,6 +113,8 @@ private: void AddNode(QDomElement &domElement, const VNodeDetail &node); QDomNode UpdateDetail(const QDomNode &domNode, const VDetail &d); void AddToModeling(const QDomElement &domElement); + void IncrementReferences(const VDetail &d) const; + void DecrementReferences(const VDetail &d) const; static void SaveChildren(VAbstractPattern *doc, quint32 id, const QVector &children); static QVector AllChildren(VAbstractPattern *doc, quint32 id); diff --git a/src/libs/vtools/undocommands/adddet.cpp b/src/libs/vtools/undocommands/adddet.cpp index 8cd86b384..a73fb7e1a 100644 --- a/src/libs/vtools/undocommands/adddet.cpp +++ b/src/libs/vtools/undocommands/adddet.cpp @@ -59,14 +59,7 @@ void AddDet::undo() return; } - QVector nodes = detail.getNodes(); - if (nodes.size()>0) - { - for (qint32 i = 0; i < nodes.size(); ++i) - { - doc->DecrementReferens(nodes.at(i).getId()); - } - } + DecrementReferences(detail.getNodes()); } else { diff --git a/src/libs/vtools/undocommands/deletedetail.cpp b/src/libs/vtools/undocommands/deletedetail.cpp index dd4be5d6c..5ece463a6 100644 --- a/src/libs/vtools/undocommands/deletedetail.cpp +++ b/src/libs/vtools/undocommands/deletedetail.cpp @@ -89,15 +89,7 @@ void DeleteDetail::redo() SCASSERT(toolDet != nullptr); toolDet->hide(); - QVector nodes = detail.getNodes(); - if (nodes.size()>0) - { - for (qint32 i = 0; i < nodes.size(); ++i) - { - doc->DecrementReferens(nodes.at(i).getId()); - } - } - + DecrementReferences(detail.getNodes()); emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail. } else diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 7b3fddf30..656863a83 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -59,14 +59,7 @@ void SaveDetailOptions::undo() { VToolDetail::AddNode(doc, domElement, oldDet.at(i)); } - QVector nodes = oldDet.getNodes(); - if (nodes.size()>0) - { - for (qint32 i = 0; i < nodes.size(); ++i) - { - doc->IncrementReferens(nodes.at(i).getId()); - } - } + IncrementReferences(oldDet.getNodes()); emit NeedLiteParsing(Document::LiteParse); } else @@ -90,14 +83,8 @@ void SaveDetailOptions::redo() { VToolDetail::AddNode(doc, domElement, newDet.at(i)); } - QList list = oldDet.Missing(newDet); - if (list.size()>0) - { - for (qint32 i = 0; i < list.size(); ++i) - { - doc->DecrementReferens(list.at(i)); - } - } + + DecrementReferences(oldDet.Missing(newDet)); emit NeedLiteParsing(Document::LiteParse); } else diff --git a/src/libs/vtools/undocommands/vundocommand.cpp b/src/libs/vtools/undocommands/vundocommand.cpp index b7732829e..f12fcb9f6 100644 --- a/src/libs/vtools/undocommands/vundocommand.cpp +++ b/src/libs/vtools/undocommands/vundocommand.cpp @@ -28,6 +28,8 @@ #include "vundocommand.h" #include "../vmisc/def.h" +#include "../vgeometry/vpointf.h" +#include "../vtools/tools/vabstracttool.h" Q_LOGGING_CATEGORY(vUndo, "v.undo") @@ -65,3 +67,57 @@ void VUndoCommand::UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &s parentNode.insertAfter(xml, refElement); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::IncrementReferences(const QVector &nodes) const +{ + for (qint32 i = 0; i < nodes.size(); ++i) + { + switch (nodes.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + auto tool = qobject_cast(doc->getTool(nodeId)); + SCASSERT(tool != nullptr); + const auto point = tool->getData()->GeometricObject(nodes.at(i).getId()); + doc->IncrementReferens(point->getIdTool()); + break; + } + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + doc->IncrementReferens(nodes.at(i).getId()); + break; + default: + qDebug()<<"Get wrong tool type. Ignore."; + break; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::DecrementReferences(const QVector &nodes) const +{ + for (qint32 i = 0; i < nodes.size(); ++i) + { + switch (nodes.at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + auto tool = qobject_cast(doc->getTool(nodeId)); + SCASSERT(tool != nullptr); + const auto point = tool->getData()->GeometricObject(nodes.at(i).getId()); + doc->DecrementReferens(point->getIdTool()); + break; + } + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + doc->DecrementReferens(nodes.at(i).getId()); + break; + default: + qDebug()<<"Get wrong tool type. Ignore."; + break; + } + } +} diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index 4874c741d..b97134e6b 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -53,6 +53,7 @@ enum class UndoCommand: char { AddPatternPiece, }; class VPattern; +class VNodeDetail; class VUndoCommand : public QObject, public QUndoCommand { @@ -71,6 +72,9 @@ protected: bool redoFlag; virtual void RedoFullParsing(); void UndoDeleteAfterSibling(QDomNode &parentNode, const quint32 &siblingId) const; + + void IncrementReferences(const QVector &nodes) const; + void DecrementReferences(const QVector &nodes) const; private: Q_DISABLE_COPY(VUndoCommand) };