Read/write custom seam allowance record.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-25 14:19:44 +02:00
parent 6c04b2e7ca
commit 6424a92559
10 changed files with 123 additions and 5 deletions

View File

@ -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<CustomSARecord> 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.

View File

@ -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,

View File

@ -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

View File

@ -231,6 +231,18 @@ void VPiece::SetUnited(bool united)
d->m_united = united;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> VPiece::GetCustomSARecords() const
{
return d->m_customSARecords;
}
//---------------------------------------------------------------------------------------------------------------------
void VPiece::SetCustomSARecords(const QVector<CustomSARecord> &records)
{
d->m_customSARecords = records;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Missing find missing nodes in detail. When we deleted object in detail and return this detail need

View File

@ -75,6 +75,9 @@ public:
bool IsUnited() const;
void SetUnited(bool united);
QVector<CustomSARecord> GetCustomSARecords() const;
void SetCustomSARecords(const QVector<CustomSARecord> &records);
QVector<VPieceNode> Missing(const VPiece &det) const;
int indexOfNode(const quint32 &id) const;

View File

@ -33,6 +33,7 @@
#include <QVector>
#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<CustomSARecord> m_customSARecords;
private:
VPieceData &operator=(const VPieceData &) Q_DECL_EQ_DELETE;
};

View File

@ -201,7 +201,12 @@ void VToolPiecePath::AddToFile()
}
else if (path.GetType() == PiecePathType::CustomSeamAllowance)
{
CustomSARecord record;
record.path = m_pieceId;
QVector<CustomSARecord> records = newDet.GetCustomSARecords();
records.append(record);
newDet.SetCustomSARecords(records);
}
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId);

View File

@ -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<CustomSARecord> &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);

View File

@ -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<CustomSARecord> &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);

View File

@ -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);