From 49167c0c3c4109bda172eb0dee065d7045effca3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 25 Jan 2017 11:32:52 +0200 Subject: [PATCH] Fix conversion to new seam allowance. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 7 +- src/app/valentina/xml/vpattern.h | 2 +- src/libs/vpatterndb/vnodedetail.cpp | 172 +++++++++++----------------- src/libs/vpatterndb/vnodedetail.h | 3 - src/libs/vpatterndb/vpiecenode_p.h | 4 +- 5 files changed, 75 insertions(+), 113 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 117437147..1fa4b300a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -733,7 +733,8 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0), "Time to refactor the code."); const bool closed = GetParametrUInt(domElement, AttrClosed, "1"); - ParseDetailNodes(element, detail, closed); + const qreal width = GetParametrDouble(domElement, AttrWidth, "0.0"); + ParseDetailNodes(element, detail, width, closed); } else { @@ -777,7 +778,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const +void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, qreal width, bool closed) const { QVector oldNodes; const QDomNodeList nodeList = domElement.childNodes(); @@ -791,7 +792,7 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, b } } - detail.GetPath().SetNodes(VNodeDetail::Convert(data, oldNodes, detail.GetSAWidth(), closed)); + detail.GetPath().SetNodes(VNodeDetail::Convert(data, oldNodes, width, closed)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 20f0e8a3a..1c0fb2f3f 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -120,7 +120,7 @@ private: void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); void ParseDetailElement(QDomElement &domElement, const Document &parse); - void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const; + void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, qreal width, bool closed) const; void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const; void ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const; void ParsePieceGrainline(const QDomElement &domElement, VPiece &detail) const; diff --git a/src/libs/vpatterndb/vnodedetail.cpp b/src/libs/vpatterndb/vnodedetail.cpp index b7fcf60ba..489c2a257 100644 --- a/src/libs/vpatterndb/vnodedetail.cpp +++ b/src/libs/vpatterndb/vnodedetail.cpp @@ -36,6 +36,66 @@ #include #include +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +bool IsOX(const QLineF &line) +{ + return VFuzzyComparePossibleNulls(line.angle(), 0) + || VFuzzyComparePossibleNulls(line.angle(), 360) + || VFuzzyComparePossibleNulls(line.angle(), 180); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool IsOY(const QLineF &line) +{ + return VFuzzyComparePossibleNulls(line.angle(), 90) || VFuzzyComparePossibleNulls(line.angle(), 270); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString LocalWidth(const QLineF &line, const QLineF &movedLine) +{ + if (VFuzzyComparePossibleNulls(line.angle(), movedLine.angle())) + { + return QString().setNum(movedLine.length()); + } + else + {// different direction means value is negative + return QString("0"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void ConvertBefore(VPieceNode &node, const QLineF &line, qreal mX, qreal mY) +{ + if (not qFuzzyIsNull(mX) && IsOX(line)) + { + const QLineF movedLine(line.p1().x(), line.p1().y(), line.p2().x() + mX, line.p2().y()); + node.SetFormulaSABefore(LocalWidth(line, movedLine)); + } + else if (not qFuzzyIsNull(mY) && IsOY(line)) + { + const QLineF movedLine(line.p1().x(), line.p1().y(), line.p2().x(), line.p2().y() + mY); + node.SetFormulaSABefore(LocalWidth(line, movedLine)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void ConvertAfter(VPieceNode &node, const QLineF &line, qreal mX, qreal mY) +{ + if (not qFuzzyIsNull(mX) && IsOX(line)) + { + const QLineF movedLine(line.p1().x(), line.p1().y(), line.p2().x() + mX, line.p2().y()); + node.SetFormulaSAAfter(LocalWidth(line, movedLine)); + } + else if (not qFuzzyIsNull(mY) && IsOY(line)) + { + const QLineF movedLine(line.p1().x(), line.p1().y(), line.p2().x(), line.p2().y() + mY); + node.SetFormulaSAAfter(LocalWidth(line, movedLine)); + } +} +}//static functions + //--------------------------------------------------------------------------------------------------------------------- VNodeDetail::VNodeDetail() :d(new VNodeDetailData) @@ -170,16 +230,6 @@ QVector VNodeDetail::Convert(const VContainer *data, const QVector 2) { for (int i = 0; i < nodes.size(); ++i) @@ -194,35 +244,17 @@ QVector VNodeDetail::Convert(const VContainer *data, const QVectorGeometricObject(node.getId())->toQPointF(); - const QPointF xPoint(point.x()+node.getMx(), point.y()); - const QPointF yPoint(point.x(), point.y()+node.getMy()); + QLineF lineBefore(point, previosPoint); + lineBefore.setAngle(lineBefore.angle()-90); + lineBefore.setLength(width); - if (IsSABefore(QLineF(point, previosPoint), QLineF(point, xPoint))) - { - path[i].SetFormulaSABefore(QString().setNum(LocalWidth(node.getMx()))); + ConvertBefore(path[i], lineBefore, node.getMx(), node.getMy()); - if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, yPoint))) - { - path[i].SetFormulaSAAfter(QString().setNum(LocalWidth(node.getMy()))); - } - } - else if (IsSABefore(QLineF(point, previosPoint), QLineF(point, yPoint))) - { - path[i].SetFormulaSABefore(QString().setNum(LocalWidth(node.getMy()))); + QLineF lineAfter(point, nextPoint); + lineAfter.setAngle(lineAfter.angle()+90); + lineAfter.setLength(width); - if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, xPoint))) - { - path[i].SetFormulaSAAfter(QString().setNum(LocalWidth(node.getMx()))); - } - } - else if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, xPoint))) - { - path[i].SetFormulaSAAfter(QString().setNum(LocalWidth(node.getMx()))); - } - else if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, yPoint))) - { - path[i].SetFormulaSAAfter(QString().setNum(LocalWidth(node.getMy()))); - } + ConvertAfter(path[i], lineAfter, node.getMx(), node.getMy()); } } } @@ -236,71 +268,3 @@ QVector VNodeDetail::Convert(const VContainer *data, const QVector= 360) - { - saAngle = 0; - } - - int mTest1 = qRound(mLine.angle()); - if (mTest1 >= 360) - { - mTest1 = 0; - } - - QLineF mrLine = mLine; - mrLine.setAngle(mrLine.angle()+180); - int mTest2 = qRound(mrLine.angle()); - if (mTest2 >=360) - { - mTest2 = 0; - } - - return (saAngle == mTest1 || saAngle == mTest2); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VNodeDetail::IsSAAfter(const QLineF &saBaseLine, const QLineF &mLine) -{ - if (qFuzzyIsNull(mLine.length())) - { - return false; - } - - QLineF saLine = saBaseLine; - saLine.setAngle(saLine.angle() + 90); - - int saAngle = qRound(saLine.angle()); - if (saAngle >= 360) - { - saAngle = 0; - } - - int mTest1 = qRound(mLine.angle()); - if (mTest1 >= 360) - { - mTest1 = 0; - } - - QLineF mrLine = mLine; - mrLine.setAngle(mrLine.angle()+180); - int mTest2 = qRound(mrLine.angle()); - if (mTest2 >=360) - { - mTest2 = 0; - } - - return (saAngle == mTest1 || saAngle == mTest2); -} diff --git a/src/libs/vpatterndb/vnodedetail.h b/src/libs/vpatterndb/vnodedetail.h index ca6df9f04..a26056923 100644 --- a/src/libs/vpatterndb/vnodedetail.h +++ b/src/libs/vpatterndb/vnodedetail.h @@ -129,9 +129,6 @@ public: bool closed); private: QSharedDataPointer d; - - static bool IsSABefore(const QLineF &saBaseLine, const QLineF &mLine); - static bool IsSAAfter(const QLineF &saBaseLine, const QLineF &mLine); }; Q_DECLARE_METATYPE(VNodeDetail) diff --git a/src/libs/vpatterndb/vpiecenode_p.h b/src/libs/vpatterndb/vpiecenode_p.h index 98c6c6797..df6b2e844 100644 --- a/src/libs/vpatterndb/vpiecenode_p.h +++ b/src/libs/vpatterndb/vpiecenode_p.h @@ -45,8 +45,8 @@ public: m_reverse(false), m_saBefore(-1), m_saAfter(-1), - m_formulaWidthBefore("-1"), - m_formulaWidthAfter("-1"), + m_formulaWidthBefore(""), + m_formulaWidthAfter(""), m_angleType(PieceNodeAngle::ByLength) {}