From a284ac024e6bf864860e087afc05ac1ea3e0c01e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Nov 2016 14:08:23 +0200 Subject: [PATCH] VSAPoint class should keep data in pixels. Make testing a lot easier. --HG-- branch : feature --- src/libs/vlayout/vabstractpiece.cpp | 8 ++++---- src/libs/vpatterndb/vpiece.cpp | 27 ++++++++++++--------------- src/libs/vpatterndb/vpiecenode.cpp | 22 ++++++++++++++++++++++ src/libs/vpatterndb/vpiecenode.h | 2 ++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 8886879e9..c93c97e00 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -333,13 +333,13 @@ Q_DECL_CONSTEXPR qreal VAbstractPiece::PointPosition(const QPointF &p, const QLi //--------------------------------------------------------------------------------------------------------------------- qreal VAbstractPiece::MaxLocalSA(const VSAPoint &p, qreal width) { - qreal w1 = qApp->toPixel(p.GetSAAfter()); + qreal w1 = p.GetSAAfter(); if (w1 < 0) { w1 = width; } - qreal w2 = qApp->toPixel(p.GetSABefore()); + qreal w2 = p.GetSABefore(); if (w2 < 0) { w2 = width; @@ -493,13 +493,13 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin //--------------------------------------------------------------------------------------------------------------------- QLineF VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width) { - qreal w1 = qApp->toPixel(p1.GetSAAfter()); + qreal w1 = p1.GetSAAfter(); if (w1 < 0) { w1 = width; } - qreal w2 = qApp->toPixel(p2.GetSABefore()); + qreal w2 = p2.GetSABefore(); if (w2 < 0) { w2 = width; diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 7965fbcc5..a3515cdf3 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -221,8 +221,9 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const { const QSharedPointer point = data->GeometricObject(node.GetId()); VSAPoint p(point->toQPointF()); - p.SetSAAfter(node.GetSAAfter()); - p.SetSABefore(node.GetSABefore()); + + p.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + p.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); pointsEkv.append(p); } break; @@ -411,13 +412,11 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont { const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); - w1 = ToPixel(w1, *data->GetPatternUnit()); if (w1 < 0) { w1 = width; } - w2 = ToPixel(w2, *data->GetPatternUnit()); if (w2 < 0) { w2 = width; @@ -445,9 +444,7 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont else { length += QLineF(points.at(i-1), points.at(i)).length(); - - qreal localWidth = w1 + wDiff*(length/fullLength); - localWidth = FromPixel(localWidth, *data->GetPatternUnit()); + const qreal localWidth = w1 + wDiff*(length/fullLength); p.SetSAAfter(localWidth); p.SetSABefore(localWidth); @@ -486,8 +483,8 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const if (curve->IsPointOnCurve(p)) { begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter()); - begin.SetSABefore(node.GetSABefore()); + begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); } } } @@ -500,8 +497,8 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const if (curve->IsPointOnCurve(p)) { begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter()); - begin.SetSABefore(node.GetSABefore()); + begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); } } } @@ -537,8 +534,8 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const if (curve->IsPointOnCurve(p)) { end = VSAPoint(p); - end.SetSAAfter(node.GetSAAfter()); - end.SetSABefore(node.GetSABefore()); + end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); } } } @@ -551,8 +548,8 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const if (curve->IsPointOnCurve(p)) { end = VSAPoint(p); - end.SetSAAfter(node.GetSAAfter()); - end.SetSABefore(node.GetSABefore()); + end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); } } } diff --git a/src/libs/vpatterndb/vpiecenode.cpp b/src/libs/vpatterndb/vpiecenode.cpp index a98c155eb..32481a696 100644 --- a/src/libs/vpatterndb/vpiecenode.cpp +++ b/src/libs/vpatterndb/vpiecenode.cpp @@ -104,6 +104,17 @@ qreal VPieceNode::GetSABefore() const return d->m_saBefore; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPieceNode::GetSABefore(Unit unit) const +{ + qreal value = d->m_saBefore; + if (value >= 0) + { + value = ToPixel(value, unit); + } + return value; +} + //--------------------------------------------------------------------------------------------------------------------- void VPieceNode::SetSABefore(qreal value) { @@ -119,6 +130,17 @@ qreal VPieceNode::GetSAAfter() const return d->m_saAfter; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPieceNode::GetSAAfter(Unit unit) const +{ + qreal value = d->m_saAfter; + if (value >= 0) + { + value = ToPixel(value, unit); + } + return value; +} + //--------------------------------------------------------------------------------------------------------------------- void VPieceNode::SetSAAfter(qreal value) { diff --git a/src/libs/vpatterndb/vpiecenode.h b/src/libs/vpatterndb/vpiecenode.h index bc9751fcc..4b4da1a2f 100644 --- a/src/libs/vpatterndb/vpiecenode.h +++ b/src/libs/vpatterndb/vpiecenode.h @@ -59,9 +59,11 @@ public: void SetReverse(bool reverse); qreal GetSABefore() const; + qreal GetSABefore(Unit unit) const; void SetSABefore(qreal value); qreal GetSAAfter() const; + qreal GetSAAfter(Unit unit) const; void SetSAAfter(qreal value); private: QSharedDataPointer d;