From 7aa7ba8e5728c56dcfc6ebf405691307671f95c9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Nov 2016 15:29:54 +0200 Subject: [PATCH] Handle firt default angle type. --HG-- branch : feature --- src/libs/vlayout/vabstractpiece.cpp | 82 +++++++++++++++++++---------- src/libs/vlayout/vabstractpiece.h | 32 +++++++++-- src/libs/vpatterndb/vpiece.cpp | 10 ++++ 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index c93c97e00..53d8e3903 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -395,36 +395,20 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin // Comparison bisector angles helps to find direction if (angle <= 90)// Go in a same direction {//Regular equdistant case - const qreal length = line.length(); - if (length > localWidth*2.4) - { // Cutting too long a cut angle - line.setLength(localWidth); - QLineF cutLine(line.p2(), CrosPoint); // Cut line is a perpendicular - cutLine.setLength(length); // Decided take this length - - // We do not check intersection type because intersection must alwayse exist - QPointF px; - cutLine.setAngle(cutLine.angle()+90); - QLineF::IntersectType type = bigLine1.intersect( cutLine, &px ); - if (type == QLineF::NoIntersection) - { - qDebug()<<"Couldn't find intersection with cut line."; - } - points.append(px); - - cutLine.setAngle(cutLine.angle()-180); - type = bigLine2.intersect( cutLine, &px ); - if (type == QLineF::NoIntersection) - { - qDebug()<<"Couldn't find intersection with cut line."; - } - points.append(px); - } - else - { // The point just fine - points.append(CrosPoint); - return points; +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch (p2Line1.GetAngleType()) + { + case PieceNodeAngle::ByLength: + return AngleByLength(p2Line1, bigLine1.p1(), CrosPoint, bigLine2.p2(), localWidth); + case PieceNodeAngle::ByPointsIntersection: + case PieceNodeAngle::ByFirstEdgeSymmetry: + case PieceNodeAngle::BySecondEdgeSymmetry: + case PieceNodeAngle::ByFirstEdgeRightAngle: + case PieceNodeAngle::BySecondEdgeRightAngle: + break; } +QT_WARNING_POP } else { // Different directions @@ -437,6 +421,7 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin if (result1 <=0 && result2 <= 0) {// Dart case. A bisector watch outside. In some cases a point still valid, but ignore if going // outside of an equdistant. + const QLineF bigEdge = ParallelLine(p1Line1, p1Line2, localWidth ); QPointF px; const QLineF::IntersectType type = bigEdge.intersect(line, &px); @@ -490,6 +475,45 @@ QVector VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin return points; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractPiece::AngleByLength(const QPointF &p2, const QPointF &sp1, const QPointF &sp2, + const QPointF &sp3, qreal width) +{ + QVector points; + + QLineF line(p2, sp2); + const qreal length = line.length(); + if (length > width*2.4) + { // Cutting too long a cut angle + line.setLength(width); + QLineF cutLine(line.p2(), sp2); // Cut line is a perpendicular + cutLine.setLength(length); // Decided take this length + + // We do not check intersection type because intersection must alwayse exist + QPointF px; + cutLine.setAngle(cutLine.angle()+90); + QLineF::IntersectType type = QLineF(sp1, sp2).intersect(cutLine, &px); + if (type == QLineF::NoIntersection) + { + qDebug()<<"Couldn't find intersection with cut line."; + } + points.append(px); + + cutLine.setAngle(cutLine.angle()-180); + type = QLineF(sp2, sp3).intersect(cutLine, &px); + if (type == QLineF::NoIntersection) + { + qDebug()<<"Couldn't find intersection with cut line."; + } + points.append(px); + } + else + { // The point just fine + points.append(sp2); + } + return points; +} + //--------------------------------------------------------------------------------------------------------------------- QLineF VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width) { diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 32101eb89..341d29eb7 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -35,6 +35,7 @@ #include #include "../vmisc/diagnostic.h" +#include "../vmisc/def.h" #include "../vgeometry/vgobject.h" template class QVector; @@ -61,9 +62,13 @@ public: Q_DECL_CONSTEXPR qreal GetSAAfter() const; void SetSAAfter(qreal value); + Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const; + void SetAngleType(PieceNodeAngle value); + private: - qreal m_before; - qreal m_after; + qreal m_before; + qreal m_after; + PieceNodeAngle m_angle; }; Q_DECLARE_METATYPE(VSAPoint) @@ -73,21 +78,24 @@ Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE); Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint() : QPointF(), m_before(-1), - m_after(-1) + m_after(-1), + m_angle(PieceNodeAngle::ByLength) {} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos) : QPointF(xpos, ypos), m_before(-1), - m_after(-1) + m_after(-1), + m_angle(PieceNodeAngle::ByLength) {} //--------------------------------------------------------------------------------------------------------------------- Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(const QPointF &p) : QPointF(p), m_before(-1), - m_after(-1) + m_after(-1), + m_angle(PieceNodeAngle::ByLength) {} //--------------------------------------------------------------------------------------------------------------------- @@ -114,6 +122,18 @@ inline void VSAPoint::SetSAAfter(qreal value) value < 0 ? m_after = -1 : m_after = value; } +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline PieceNodeAngle VSAPoint::GetAngleType() const +{ + return m_angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VSAPoint::SetAngleType(PieceNodeAngle value) +{ + m_angle = value; +} + QT_WARNING_POP class VAbstractPiece @@ -154,6 +174,8 @@ private: static qreal MaxLocalSA(const VSAPoint &p, qreal width); static QVector EkvPoint(const VSAPoint &p1Line1, const VSAPoint &p2Line1, const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width); + static QVector AngleByLength(const QPointF &p2, const QPointF &sp1, const QPointF &sp2, const QPointF &sp3, + qreal width); static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width); static QLineF ParallelLine(const QPointF &p1, const QPointF &p2, qreal width); static QPointF SingleParallelPoint(const QPointF &p1, const QPointF &p2, qreal angle, qreal width); diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 84effaede..bbc201647 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -224,6 +224,7 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const p.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); p.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + p.SetAngleType(node.GetAngleType()); pointsEkv.append(p); } break; @@ -399,11 +400,13 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont { // first point p.SetSAAfter(begin.GetSAAfter()); p.SetSABefore(begin.GetSABefore()); + p.SetAngleType(begin.GetAngleType()); } else if (i == points.size() - 1) { // last point p.SetSAAfter(end.GetSAAfter()); p.SetSABefore(end.GetSABefore()); + p.SetAngleType(end.GetAngleType()); } pointsEkv.append(p); } @@ -428,6 +431,7 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont VSAPoint p(points.at(0));//First point in the list p.SetSAAfter(begin.GetSAAfter()); p.SetSABefore(begin.GetSABefore()); + p.SetAngleType(begin.GetAngleType()); pointsEkv.append(p); qreal length = 0; // how much we handle @@ -440,6 +444,7 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont {// last point p.SetSAAfter(end.GetSAAfter()); p.SetSABefore(end.GetSABefore()); + p.SetAngleType(end.GetAngleType()); } else { @@ -448,6 +453,7 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont p.SetSAAfter(localWidth); p.SetSABefore(localWidth); + // curve points have angle type by default } pointsEkv.append(p); @@ -485,6 +491,7 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const begin = VSAPoint(p); begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + begin.SetAngleType(node.GetAngleType()); } } } @@ -499,6 +506,7 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const begin = VSAPoint(p); begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + begin.SetAngleType(node.GetAngleType()); } } } @@ -536,6 +544,7 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const end = VSAPoint(p); end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + end.SetAngleType(node.GetAngleType()); } } } @@ -550,6 +559,7 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const end = VSAPoint(p); end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + end.SetAngleType(node.GetAngleType()); } } }