Custom Path will work in two modes. The first extend automatic seam allowance,

the second show custom deam allowance. In this case a path must have options
for controling seam allowance.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-28 11:58:44 +02:00
parent 530203966e
commit f56ea24810
10 changed files with 117 additions and 148 deletions

View file

@ -520,6 +520,49 @@ void VPattern::customEvent(QEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
VPieceNode VPattern::ParseSANode(const QDomElement &domElement) const
{
const quint32 id = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
const bool reverse = GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0");
const qreal saBefore = GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1");
const qreal saAfter = GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1");
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(GetParametrUInt(domElement, AttrAngle, "0"));
const QString t = GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint);
Tool tool;
const QStringList types = QStringList() << VAbstractPattern::NodePoint
<< VAbstractPattern::NodeArc
<< VAbstractPattern::NodeSpline
<< VAbstractPattern::NodeSplinePath;
switch (types.indexOf(t))
{
case 0: // VAbstractPattern::NodePoint
tool = Tool::NodePoint;
break;
case 1: // VAbstractPattern::NodeArc
tool = Tool::NodeArc;
break;
case 2: // VAbstractPattern::NodeSpline
tool = Tool::NodeSpline;
break;
case 3: // VAbstractPattern::NodeSplinePath
tool = Tool::NodeSplinePath;
break;
default:
VException e(tr("Wrong tag name '%1'.").arg(t));
throw e;
}
VPieceNode node(id, tool, reverse);
node.SetSABefore(saBefore);
node.SetSAAfter(saAfter);
node.SetAngleType(angle);
return node;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ParseDrawElement parse draw tag.
@ -777,49 +820,13 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail) const
{
const QStringList types = QStringList() << VAbstractPattern::NodePoint
<< VAbstractPattern::NodeArc
<< VAbstractPattern::NodeSpline
<< VAbstractPattern::NodeSplinePath;
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() == VAbstractPattern::TagNode)
{
const quint32 id = GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
const bool reverse = GetParametrUInt(element, VAbstractPattern::AttrNodeReverse, "0");
const qreal saBefore = GetParametrDouble(element, VToolSeamAllowance::AttrSABefore, "-1");
const qreal saAfter = GetParametrDouble(element, VToolSeamAllowance::AttrSAAfter, "-1");
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(GetParametrUInt(element, AttrAngle, "0"));
const QString t = GetParametrString(element, AttrType, VAbstractPattern::NodePoint);
Tool tool;
switch (types.indexOf(t))
{
case 0: // VToolSeamAllowance::NodePoint
tool = Tool::NodePoint;
break;
case 1: // VToolSeamAllowance::NodeArc
tool = Tool::NodeArc;
break;
case 2: // VToolSeamAllowance::NodeSpline
tool = Tool::NodeSpline;
break;
case 3: // VToolSeamAllowance::NodeSplinePath
tool = Tool::NodeSplinePath;
break;
default:
VException e(tr("Wrong tag name '%1'.").arg(t));
throw e;
}
VPieceNode node(id, tool, reverse);
node.SetSABefore(saBefore);
node.SetSAAfter(saAfter);
node.SetAngleType(angle);
detail.GetPath().Append(node);
detail.GetPath().Append(ParseSANode(element));
}
}
}
@ -3078,42 +3085,13 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParsePathNodes(const QDomElement &domElement, VPiecePath &path) const
{
const QStringList types = QStringList() << VAbstractPattern::NodePoint
<< VAbstractPattern::NodeArc
<< VAbstractPattern::NodeSpline
<< VAbstractPattern::NodeSplinePath;
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() == VAbstractPattern::TagNode)
{
const quint32 id = GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
const bool reverse = GetParametrUInt(element, VAbstractPattern::AttrNodeReverse, "0");
const QString t = GetParametrString(element, AttrType, VAbstractPattern::NodePoint);
Tool tool;
switch (types.indexOf(t))
{
case 0: // VAbstractPattern::NodePoint
tool = Tool::NodePoint;
break;
case 1: // VAbstractPattern::NodeArc
tool = Tool::NodeArc;
break;
case 2: // VAbstractPattern::NodeSpline
tool = Tool::NodeSpline;
break;
case 3: // VAbstractPattern::NodeSplinePath
tool = Tool::NodeSplinePath;
break;
default:
VException e(tr("Wrong tag name '%1'.").arg(t));
throw e;
}
path.Append(VPieceNode(id, tool, reverse));
path.Append(ParseSANode(element));
}
}
}

View file

@ -114,6 +114,8 @@ private:
VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail;
VPieceNode ParseSANode(const QDomElement &domElement) const;
void ParseDrawElement(const QDomNode& node, const Document &parse);
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode);
void ParseDetailElement(const QDomElement &domElement, const Document &parse);

View file

@ -315,6 +315,9 @@
<xs:attribute name="type" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="before" type="xs:double"></xs:attribute>
<xs:attribute name="after" type="xs:double"></xs:attribute>
<xs:attribute name="angle" type="nodeAngle"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>

View file

@ -105,6 +105,8 @@ const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"
const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement");
const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows");
const QString VAbstractPattern::AttrNodeReverse = QStringLiteral("reverse");
const QString VAbstractPattern::AttrSABefore = QStringLiteral("before");
const QString VAbstractPattern::AttrSAAfter = QStringLiteral("after");
const QString VAbstractPattern::AttrAll = QStringLiteral("all");

View file

@ -209,6 +209,8 @@ public:
static const QString AttrPlacement;
static const QString AttrArrows;
static const QString AttrNodeReverse;
static const QString AttrSABefore;
static const QString AttrSAAfter;
static const QString AttrAll;

View file

@ -105,36 +105,7 @@ QString VToolPiecePath::getTagName() const
//---------------------------------------------------------------------------------------------------------------------
void VToolPiecePath::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node)
{
QDomElement nod = doc->createElement(VAbstractPattern::TagNode);
doc->SetAttribute(nod, AttrIdObject, node.GetId());
const Tool type = node.GetTypeTool();
if (type != Tool::NodePoint)
{
doc->SetAttribute(nod, VAbstractPattern::AttrNodeReverse, static_cast<quint8>(node.GetReverse()));
}
switch (type)
{
case (Tool::NodeArc):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeArc);
break;
case (Tool::NodePoint):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodePoint);
break;
case (Tool::NodeSpline):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSpline);
break;
case (Tool::NodeSplinePath):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSplinePath);
break;
default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break;
}
domElement.appendChild(nod);
domElement.appendChild(AddSANode(doc, VAbstractPattern::TagNode, node));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -65,6 +65,7 @@
#include "../vmisc/vcommonsettings.h"
#include "../vmisc/logging.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vwidgets/vgraphicssimpletextitem.h"
#include "vdatatool.h"
@ -431,3 +432,59 @@ void VAbstractTool::RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleText
lineName->setVisible(false);
}
}
//---------------------------------------------------------------------------------------------------------------------
QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node)
{
QDomElement nod = doc->createElement(tagName);
doc->SetAttribute(nod, AttrIdObject, node.GetId());
const Tool type = node.GetTypeTool();
if (type != Tool::NodePoint)
{
doc->SetAttribute(nod, VAbstractPattern::AttrNodeReverse, static_cast<quint8>(node.GetReverse()));
}
else
{
const qreal w1 = node.GetSABefore();
if (w1 >= 0)
{
doc->SetAttribute(nod, VAbstractPattern::AttrSABefore, w1);
}
const qreal w2 = node.GetSAAfter();
if (w2 >= 0)
{
doc->SetAttribute(nod, VAbstractPattern::AttrSAAfter, w2);
}
}
switch (type)
{
case (Tool::NodeArc):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeArc);
break;
case (Tool::NodePoint):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodePoint);
break;
case (Tool::NodeSpline):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSpline);
break;
case (Tool::NodeSplinePath):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSplinePath);
break;
default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break;
}
const unsigned char angleType = static_cast<unsigned char>(node.GetAngleType());
if (angleType > 0)
{
doc->SetAttribute(nod, AttrAngle, angleType);
}
return nod;
}

View file

@ -146,8 +146,10 @@ protected:
virtual void SetVisualization()=0;
void ToolCreation(const Source &typeCreation);
static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, QGraphicsLineItem *lineName,
const qreal radius);
static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint,
QGraphicsLineItem *lineName, const qreal radius);
static QDomElement AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node);
private:
Q_DISABLE_COPY(VAbstractTool)
};

View file

@ -64,8 +64,6 @@ const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version")
const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping");
const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance");
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");
@ -201,51 +199,7 @@ void VToolSeamAllowance::Remove(bool ask)
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node)
{
QDomElement nod = doc->createElement(VAbstractPattern::TagNode);
doc->SetAttribute(nod, AttrIdObject, node.GetId());
const Tool type = node.GetTypeTool();
if (type != Tool::NodePoint)
{
doc->SetAttribute(nod, VAbstractPattern::AttrNodeReverse, static_cast<quint8>(node.GetReverse()));
}
else
{
const qreal w1 = node.GetSABefore();
w1 < 0 ? domElement.removeAttribute(AttrSABefore) : doc->SetAttribute(nod, AttrSABefore, w1);
const qreal w2 = node.GetSAAfter();
w2 < 0 ? domElement.removeAttribute(AttrSAAfter) : doc->SetAttribute(nod, AttrSAAfter, w2);
}
switch (type)
{
case (Tool::NodeArc):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeArc);
break;
case (Tool::NodePoint):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodePoint);
break;
case (Tool::NodeSpline):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSpline);
break;
case (Tool::NodeSplinePath):
doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSplinePath);
break;
default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break;
}
const unsigned char angleType = static_cast<unsigned char>(node.GetAngleType());
if (angleType > 0)
{
doc->SetAttribute(nod, AttrAngle, angleType);
}
domElement.appendChild(nod);
domElement.appendChild(AddSANode(doc, VAbstractPattern::TagNode, node));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -61,8 +61,6 @@ public:
static const QString AttrForbidFlipping;
static const QString AttrSeamAllowance;
static const QString AttrWidth;
static const QString AttrSABefore;
static const QString AttrSAAfter;
static const QString AttrUnited;
static const QString AttrStart;
static const QString AttrPath;