diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index c2c9ddf2b..9d2b643ab 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -661,10 +661,11 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); - const QStringList tags = QStringList() << VAbstractPattern::TagNodes + const QStringList tags = QStringList() << TagNodes << TagData << TagPatternInfo - << TagGrainline; + << TagGrainline + << VToolSeamAllowance::TagCSA; const QDomNodeList nodeList = domElement.childNodes(); for (qint32 i = 0; i < nodeList.size(); ++i) @@ -674,7 +675,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document { switch (tags.indexOf(element.tagName())) { - case 0:// VAbstractPattern::TagNodes + case 0:// TagNodes ParseDetailNodes(element, detail); break; case 1:// TagData @@ -683,6 +684,9 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document break; case 3:// TagGrainline break; + case 4:// VToolSeamAllowance::TagCSA + ParseDetailCSARecords(element, detail); + break; default: break; } @@ -819,6 +823,28 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail) c } } } + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParseDetailCSARecords(const QDomElement &domElement, VPiece &detail) const +{ + QVector records; + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagRecord) + { + CustomSARecord record; + record.startPoint = GetParametrUInt(element, VToolSeamAllowance::AttrStart, NULL_ID_STR); + record.path = GetParametrUInt(element, VToolSeamAllowance::AttrPath, NULL_ID_STR); + record.endPoint = GetParametrUInt(element, VToolSeamAllowance::AttrEnd, NULL_ID_STR); + record.reverse = GetParametrBool(element, VAbstractPattern::AttrNodeReverse, falseStr); + records.append(record); + } + } + detail.SetCustomSARecords(records); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseDetails parse details tag. diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index e96387b05..0ab54d4f0 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -118,6 +118,7 @@ private: void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); void ParseDetailElement(const QDomElement &domElement, const Document &parse); void ParseDetailNodes(const QDomElement &domElement, VPiece &detail) const; + void ParseDetailCSARecords(const QDomElement &domElement, VPiece &detail) const; void ParseDetails(const QDomElement &domElement, const Document &parse); void ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement, diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 170b7eed0..e16eb5add 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -677,6 +677,26 @@ static inline bool VFuzzyComparePossibleNulls(double p1, double p2) } } +/** + * @brief The CustomSA struct contains record about custom seam allowanse (SA). + */ +struct CustomSARecord +{ + CustomSARecord() + : startPoint(0), + path(0), + endPoint(0), + reverse(false) + {} + + quint32 startPoint; + quint32 path; + quint32 endPoint; + bool reverse; +}; + +Q_DECLARE_TYPEINFO(CustomSARecord, Q_MOVABLE_TYPE); + /**************************************************************************** ** This file is derived from code bearing the following notice: ** The sole author of this file, Adam Higerd, has explicitly disclaimed all diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index dd3560597..a6f067437 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -231,6 +231,18 @@ void VPiece::SetUnited(bool united) d->m_united = united; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::GetCustomSARecords() const +{ + return d->m_customSARecords; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetCustomSARecords(const QVector &records) +{ + d->m_customSARecords = records; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Missing find missing nodes in detail. When we deleted object in detail and return this detail need diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 1c17e3f2d..bbc9a93db 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -75,6 +75,9 @@ public: bool IsUnited() const; void SetUnited(bool united); + QVector GetCustomSARecords() const; + void SetCustomSARecords(const QVector &records); + QVector Missing(const VPiece &det) const; int indexOfNode(const quint32 &id) const; diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index 3ec5cf61e..c8c42ad1a 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -33,6 +33,7 @@ #include #include "../vmisc/diagnostic.h" +#include "../vmisc/def.h" #include "vpiecenode.h" #include "vpiecepath.h" @@ -47,7 +48,8 @@ public: m_mx(0), m_my(0), m_inLayout(true), - m_united(false) + m_united(false), + m_customSARecords() {} VPieceData(const VPieceData &detail) @@ -56,7 +58,8 @@ public: m_mx(detail.m_mx), m_my(detail.m_my), m_inLayout(detail.m_inLayout), - m_united(detail.m_united) + m_united(detail.m_united), + m_customSARecords(detail.m_customSARecords) {} ~VPieceData(); @@ -70,6 +73,8 @@ public: bool m_inLayout; bool m_united; + QVector m_customSARecords; + private: VPieceData &operator=(const VPieceData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index f3274f560..7527af36c 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -201,7 +201,12 @@ void VToolPiecePath::AddToFile() } else if (path.GetType() == PiecePathType::CustomSeamAllowance) { + CustomSARecord record; + record.path = m_pieceId; + QVector records = newDet.GetCustomSARecords(); + records.append(record); + newDet.SetCustomSARecords(records); } SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index c3f06b6cf..37ac7e0c8 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -57,6 +57,9 @@ // Current version of seam allowance tag nned for backward compatibility const quint8 VToolSeamAllowance::pieceVersion = 2; +const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa"); +const QString VToolSeamAllowance::TagRecord = QStringLiteral("record"); + const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version"); const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping"); const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance"); @@ -64,6 +67,9 @@ const QString VToolSeamAllowance::AttrWidth = QStringLiteral("width"); const QString VToolSeamAllowance::AttrSABefore = QStringLiteral("before"); const QString VToolSeamAllowance::AttrSAAfter = QStringLiteral("after"); const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); +const QString VToolSeamAllowance::AttrStart = QStringLiteral("start"); +const QString VToolSeamAllowance::AttrPath = QStringLiteral("path"); +const QString VToolSeamAllowance::AttrEnd = QStringLiteral("end"); //--------------------------------------------------------------------------------------------------------------------- VToolSeamAllowance::~VToolSeamAllowance() @@ -273,6 +279,34 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl doc->SetAttribute(domElement, AttrUnited, piece.IsUnited()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record) +{ + QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord); + + doc->SetAttribute(recordNode, AttrStart, record.startPoint); + doc->SetAttribute(recordNode, AttrPath, record.path); + doc->SetAttribute(recordNode, AttrEnd, record.endPoint); + doc->SetAttribute(recordNode, VAbstractPattern::AttrNodeReverse, record.reverse); + + domElement.appendChild(recordNode); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, + const QVector &records) +{ + if (records.size() > 0) + { + QDomElement csaRecordsElement = doc->createElement(VToolSeamAllowance::TagCSA); + for (int i = 0; i < records.size(); ++i) + { + AddCSARecord(doc, csaRecordsElement, records.at(i)); + } + domElement.appendChild(csaRecordsElement); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) { @@ -370,6 +404,8 @@ void VToolSeamAllowance::AddToFile() // nodes AddNodes(doc, domElement, piece); + //custom seam allowance + AddCSARecords(doc, domElement, piece.GetCustomSARecords()); AddPiece *addDet = new AddPiece(domElement, doc, piece, m_drawName); connect(addDet, &AddPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index a12de91d3..50037c4ae 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -54,6 +54,9 @@ public: static const quint8 pieceVersion; + static const QString TagCSA; + static const QString TagRecord; + static const QString AttrVersion; static const QString AttrForbidFlipping; static const QString AttrSeamAllowance; @@ -61,12 +64,17 @@ public: static const QString AttrSABefore; static const QString AttrSAAfter; static const QString AttrUnited; + static const QString AttrStart; + static const QString AttrPath; + static const QString AttrEnd; void Remove(bool ask); static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node); static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece); + static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record); + static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector &records); static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); diff --git a/src/libs/vtools/undocommands/savepieceoptions.cpp b/src/libs/vtools/undocommands/savepieceoptions.cpp index d03657474..25771c5b9 100644 --- a/src/libs/vtools/undocommands/savepieceoptions.cpp +++ b/src/libs/vtools/undocommands/savepieceoptions.cpp @@ -75,6 +75,7 @@ void SavePieceOptions::undo() VToolSeamAllowance::AddPatternInfo(doc, domElement, m_oldDet); VToolSeamAllowance::AddGrainline(doc, domElement, m_oldDet); VToolSeamAllowance::AddNodes(doc, domElement, m_oldDet); + VToolSeamAllowance::AddCSARecords(doc, domElement, m_oldDet.GetCustomSARecords()); IncrementReferences(m_oldDet.Missing(m_newDet)); emit NeedLiteParsing(Document::LiteParse); @@ -100,6 +101,7 @@ void SavePieceOptions::redo() VToolSeamAllowance::AddPatternInfo(doc, domElement, m_newDet); VToolSeamAllowance::AddGrainline(doc, domElement, m_newDet); VToolSeamAllowance::AddNodes(doc, domElement, m_newDet); + VToolSeamAllowance::AddCSARecords(doc, domElement, m_newDet.GetCustomSARecords()); DecrementReferences(m_oldDet.Missing(m_newDet)); emit NeedLiteParsing(Document::LiteParse);