From 8e9b01a93a93f0ee88db72788918ed1139d0af81 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 25 Nov 2016 16:12:33 +0200 Subject: [PATCH] Decrement/increment custom seam allowance in tool seam allowance undocommands. --HG-- branch : feature --- src/libs/vpatterndb/vpiece.cpp | 39 +++++++++++-- src/libs/vpatterndb/vpiece.h | 3 +- src/libs/vtools/undocommands/addpiece.cpp | 1 + src/libs/vtools/undocommands/deletepiece.cpp | 1 + .../vtools/undocommands/savepieceoptions.cpp | 3 + src/libs/vtools/undocommands/vundocommand.cpp | 58 ++++++++++++++++++- src/libs/vtools/undocommands/vundocommand.h | 7 +++ 7 files changed, 104 insertions(+), 8 deletions(-) diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index e4968d6ec..a77a15540 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -250,12 +250,12 @@ void VPiece::SetCustomSARecords(const QVector &records) * @param det changed detail. * @return list with missing nodes. */ -QVector VPiece::MissingNodes(const VPiece &det) const +QVector VPiece::MissingNodes(const VPiece &det) const { const QVector pNodes = d->m_path.GetNodes(); if (pNodes.size() == det.GetPath().CountNodes()) //-V807 { - return QVector(); + return QVector(); } QSet set1; @@ -271,19 +271,50 @@ QVector VPiece::MissingNodes(const VPiece &det) const } const QList set3 = set1.subtract(set2).toList(); - QVector nodes; + QVector nodes; for (qint32 i = 0; i < set3.size(); ++i) { const int index = indexOfNode(pNodes, set3.at(i)); if (index != -1) { - nodes.append(pNodes.at(index)); + nodes.append(pNodes.at(index).GetId()); } } return nodes; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::MissingCSAPath(const VPiece &det) const +{ + const QVector detRecords = det.GetCustomSARecords(); + if (d->m_customSARecords.size() == detRecords.size()) //-V807 + { + return QVector(); + } + + QSet set1; + for (qint32 i = 0; i < d->m_customSARecords.size(); ++i) + { + set1.insert(d->m_customSARecords.at(i).path); + } + + QSet set2; + for (qint32 j = 0; j < detRecords.size(); ++j) + { + set2.insert(detRecords.at(j).path); + } + + const QList set3 = set1.subtract(set2).toList(); + QVector r; + for (qint32 i = 0; i < set3.size(); ++i) + { + r.append(set3.at(i)); + } + + return r; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief indexOfNode return index in list node using id object. diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 5a7934e77..255beb9a4 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -78,7 +78,8 @@ public: QVector GetCustomSARecords() const; void SetCustomSARecords(const QVector &records); - QVector MissingNodes(const VPiece &det) const; + QVector MissingNodes(const VPiece &det) const; + QVector MissingCSAPath(const VPiece &det) const; int indexOfNode(const quint32 &id) const; diff --git a/src/libs/vtools/undocommands/addpiece.cpp b/src/libs/vtools/undocommands/addpiece.cpp index 185ac804f..c27b9e250 100644 --- a/src/libs/vtools/undocommands/addpiece.cpp +++ b/src/libs/vtools/undocommands/addpiece.cpp @@ -63,6 +63,7 @@ void AddPiece::undo() } DecrementReferences(m_detail.GetPath().GetNodes()); + DecrementReferences(m_detail.GetCustomSARecords()); } else { diff --git a/src/libs/vtools/undocommands/deletepiece.cpp b/src/libs/vtools/undocommands/deletepiece.cpp index 1aea7088c..6fb5fd5bf 100644 --- a/src/libs/vtools/undocommands/deletepiece.cpp +++ b/src/libs/vtools/undocommands/deletepiece.cpp @@ -107,6 +107,7 @@ void DeletePiece::redo() toolDet->hide(); DecrementReferences(m_detail.GetPath().GetNodes()); + DecrementReferences(m_detail.GetCustomSARecords()); emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail. } else diff --git a/src/libs/vtools/undocommands/savepieceoptions.cpp b/src/libs/vtools/undocommands/savepieceoptions.cpp index 3d8390087..ae7e28f3d 100644 --- a/src/libs/vtools/undocommands/savepieceoptions.cpp +++ b/src/libs/vtools/undocommands/savepieceoptions.cpp @@ -78,6 +78,7 @@ void SavePieceOptions::undo() VToolSeamAllowance::AddCSARecords(doc, domElement, m_oldDet.GetCustomSARecords()); IncrementReferences(m_oldDet.MissingNodes(m_newDet)); + IncrementReferences(m_oldDet.MissingCSAPath(m_newDet)); emit NeedLiteParsing(Document::LiteParse); } else @@ -104,6 +105,8 @@ void SavePieceOptions::redo() VToolSeamAllowance::AddCSARecords(doc, domElement, m_newDet.GetCustomSARecords()); DecrementReferences(m_oldDet.MissingNodes(m_newDet)); + DecrementReferences(m_oldDet.MissingCSAPath(m_newDet)); + emit NeedLiteParsing(Document::LiteParse); } else diff --git a/src/libs/vtools/undocommands/vundocommand.cpp b/src/libs/vtools/undocommands/vundocommand.cpp index fab10fab9..cd8351b65 100644 --- a/src/libs/vtools/undocommands/vundocommand.cpp +++ b/src/libs/vtools/undocommands/vundocommand.cpp @@ -95,19 +95,71 @@ void VUndoCommand::DecrementReferences(const QVector &nodes) const } //--------------------------------------------------------------------------------------------------------------------- -void VUndoCommand::IncrementReferences(const QVector &nodes) const +void VUndoCommand::IncrementReferences(const QVector &nodes) const { for (qint32 i = 0; i < nodes.size(); ++i) { - doc->IncrementReferens(nodes.at(i).GetId()); + doc->IncrementReferens(nodes.at(i)); } } +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::DecrementReferences(const QVector &nodes) const +{ + for (qint32 i = 0; i < nodes.size(); ++i) + { + doc->DecrementReferens(nodes.at(i)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::IncrementReferences(const QVector &nodes) const +{ + QVector n; + + for (qint32 i = 0; i < nodes.size(); ++i) + { + n.append(nodes.at(i).path); + } + + IncrementReferences(n); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::DecrementReferences(const QVector &nodes) const +{ + QVector n; + + for (qint32 i = 0; i < nodes.size(); ++i) + { + n.append(nodes.at(i).path); + } + + DecrementReferences(n); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VUndoCommand::IncrementReferences(const QVector &nodes) const +{ + QVector n; + + for (qint32 i = 0; i < nodes.size(); ++i) + { + n.append(nodes.at(i).GetId()); + } + + IncrementReferences(n); +} + //--------------------------------------------------------------------------------------------------------------------- void VUndoCommand::DecrementReferences(const QVector &nodes) const { + QVector n; + for (qint32 i = 0; i < nodes.size(); ++i) { - doc->DecrementReferens(nodes.at(i).GetId()); + n.append(nodes.at(i).GetId()); } + + DecrementReferences(n); } diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index d4fceb414..dea2b9ff8 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -89,6 +89,13 @@ protected: void IncrementReferences(const QVector &nodes) const; void DecrementReferences(const QVector &nodes) const; + + void IncrementReferences(const QVector &nodes) const; + void DecrementReferences(const QVector &nodes) const; + + void IncrementReferences(const QVector &nodes) const; + void DecrementReferences(const QVector &nodes) const; + void IncrementReferences(const QVector &nodes) const; void DecrementReferences(const QVector &nodes) const; private: