Fix conversion to new seam allowance.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-25 11:32:52 +02:00
parent 7817936d3e
commit 49167c0c3c
5 changed files with 75 additions and 113 deletions

View File

@ -733,7 +733,8 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
"Time to refactor the code."); "Time to refactor the code.");
const bool closed = GetParametrUInt(domElement, AttrClosed, "1"); 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 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<VNodeDetail> oldNodes; QVector<VNodeDetail> oldNodes;
const QDomNodeList nodeList = domElement.childNodes(); 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));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -120,7 +120,7 @@ private:
void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawElement(const QDomNode& node, const Document &parse);
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode);
void ParseDetailElement(QDomElement &domElement, const Document &parse); 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 ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const;
void ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const; void ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const;
void ParsePieceGrainline(const QDomElement &domElement, VPiece &detail) const; void ParsePieceGrainline(const QDomElement &domElement, VPiece &detail) const;

View File

@ -36,6 +36,66 @@
#include <QLineF> #include <QLineF>
#include <QVector> #include <QVector>
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() VNodeDetail::VNodeDetail()
:d(new VNodeDetailData) :d(new VNodeDetailData)
@ -170,16 +230,6 @@ QVector<VPieceNode> VNodeDetail::Convert(const VContainer *data, const QVector<V
path.Append(VPieceNode(node.getId(), node.getTypeTool(), node.getReverse())); path.Append(VPieceNode(node.getId(), node.getTypeTool(), node.getReverse()));
} }
auto LocalWidth = [width](qreal move) noexcept
{
qreal value = width + move;
if (value < 0)
{
value = 0;
}
return value;
};
if (path.PathPoints(data).size() > 2) if (path.PathPoints(data).size() > 2)
{ {
for (int i = 0; i < nodes.size(); ++i) for (int i = 0; i < nodes.size(); ++i)
@ -194,35 +244,17 @@ QVector<VPieceNode> VNodeDetail::Convert(const VContainer *data, const QVector<V
const QPointF point = data->GeometricObject<VPointF>(node.getId())->toQPointF(); const QPointF point = data->GeometricObject<VPointF>(node.getId())->toQPointF();
const QPointF xPoint(point.x()+node.getMx(), point.y()); QLineF lineBefore(point, previosPoint);
const QPointF yPoint(point.x(), point.y()+node.getMy()); lineBefore.setAngle(lineBefore.angle()-90);
lineBefore.setLength(width);
if (IsSABefore(QLineF(point, previosPoint), QLineF(point, xPoint))) ConvertBefore(path[i], lineBefore, node.getMx(), node.getMy());
{
path[i].SetFormulaSABefore(QString().setNum(LocalWidth(node.getMx())));
if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, yPoint))) QLineF lineAfter(point, nextPoint);
{ lineAfter.setAngle(lineAfter.angle()+90);
path[i].SetFormulaSAAfter(QString().setNum(LocalWidth(node.getMy()))); lineAfter.setLength(width);
}
}
else if (IsSABefore(QLineF(point, previosPoint), QLineF(point, yPoint)))
{
path[i].SetFormulaSABefore(QString().setNum(LocalWidth(node.getMy())));
if (IsSAAfter(QLineF(point, nextPoint), QLineF(point, xPoint))) ConvertAfter(path[i], lineAfter, node.getMx(), node.getMy());
{
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())));
}
} }
} }
} }
@ -236,71 +268,3 @@ QVector<VPieceNode> VNodeDetail::Convert(const VContainer *data, const QVector<V
return path.GetNodes(); return path.GetNodes();
} }
//---------------------------------------------------------------------------------------------------------------------
bool VNodeDetail::IsSABefore(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);
}
//---------------------------------------------------------------------------------------------------------------------
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);
}

View File

@ -129,9 +129,6 @@ public:
bool closed); bool closed);
private: private:
QSharedDataPointer<VNodeDetailData> d; QSharedDataPointer<VNodeDetailData> d;
static bool IsSABefore(const QLineF &saBaseLine, const QLineF &mLine);
static bool IsSAAfter(const QLineF &saBaseLine, const QLineF &mLine);
}; };
Q_DECLARE_METATYPE(VNodeDetail) Q_DECLARE_METATYPE(VNodeDetail)

View File

@ -45,8 +45,8 @@ public:
m_reverse(false), m_reverse(false),
m_saBefore(-1), m_saBefore(-1),
m_saAfter(-1), m_saAfter(-1),
m_formulaWidthBefore("-1"), m_formulaWidthBefore(""),
m_formulaWidthAfter("-1"), m_formulaWidthAfter(""),
m_angleType(PieceNodeAngle::ByLength) m_angleType(PieceNodeAngle::ByLength)
{} {}