From 06e945d8a3e406f65c2a0a2516a351c632d6ef35 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 3 Jan 2015 14:22:55 +0200 Subject: [PATCH] Detail must return contour points and seam allowence points yourself. --HG-- branch : feature --- src/app/geometry/vdetail.cpp | 150 +++++++++++++++++++++++++++++++++++ src/app/geometry/vdetail.h | 9 +++ 2 files changed, 159 insertions(+) diff --git a/src/app/geometry/vdetail.cpp b/src/app/geometry/vdetail.cpp index e9a0eb17e..edc286def 100644 --- a/src/app/geometry/vdetail.cpp +++ b/src/app/geometry/vdetail.cpp @@ -28,6 +28,9 @@ #include "vdetail.h" #include "vdetail_p.h" +#include "../container/vcontainer.h" +#include "vpointf.h" + #include #include @@ -353,6 +356,84 @@ QList VDetail::Missing(const VDetail &det) const return set3.toList(); } +//--------------------------------------------------------------------------------------------------------------------- +QVector VDetail::ContourPoints(const VContainer *data) const +{ + QVector points; + for (int i = 0; i< CountNode(); ++i) + { + switch (at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + const QSharedPointer point = data->GeometricObject(at(i).getId()); + points.append(point->toQPointF()); + } + break; + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + { + const QSharedPointer curve = data->GeometricObject(at(i).getId()); + + const QPointF begin = StartSegment(data, i); + const QPointF end = EndSegment(data, i); + + points << curve->GetSegmentPoints(begin, end, at(i).getReverse()); + } + break; + default: + qDebug()<<"Get wrong tool type. Ignore."<< static_cast(at(i).getTypeTool()); + break; + } + } + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VDetail::SeamAllowancePoints(const VContainer *data) const +{ + QVector pointsEkv; + for (int i = 0; i< CountNode(); ++i) + { + switch (at(i).getTypeTool()) + { + case (Tool::NodePoint): + { + const QSharedPointer point = data->GeometricObject(at(i).getId()); + if (getSeamAllowance() == true) + { + QPointF pEkv = point->toQPointF(); + pEkv.setX(pEkv.x()+at(i).getMx()); + pEkv.setY(pEkv.y()+at(i).getMy()); + pointsEkv.append(pEkv); + } + } + break; + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + { + const QSharedPointer curve = data->GeometricObject(at(i).getId()); + + const QPointF begin = StartSegment(data, i); + const QPointF end = EndSegment(data, i); + + QVector nodePoints = curve->GetSegmentPoints(begin, end, at(i).getReverse()); + if (getSeamAllowance() == true) + { + pointsEkv << biasPoints(nodePoints, at(i).getMx(), at(i).getMy()); + } + } + break; + default: + qDebug()<<"Get wrong tool type. Ignore."<< static_cast(at(i).getTypeTool()); + break; + } + } + return pointsEkv; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief listNodePoint return list nodes only with points. @@ -391,6 +472,75 @@ int VDetail::indexOfNode(const QVector &list, const quint32 &id) return -1; } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VDetail::StartSegment(const VContainer *data, const int &i) const +{ + QPointF begin; + if (CountNode() > 1) + { + if (i == 0) + { + if (at(CountNode()-1).getTypeTool() == Tool::NodePoint) + { + begin = data->GeometricObject(at(CountNode()-1).getId())->toQPointF(); + } + } + else + { + if (at(i-1).getTypeTool() == Tool::NodePoint) + { + begin = data->GeometricObject(at(i-1).getId())->toQPointF(); + } + } + } + return begin; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VDetail::EndSegment(const VContainer *data, const int &i) const +{ + QPointF end; + if (CountNode() > 2) + { + if (i == CountNode() - 1) + { + if (at(0).getTypeTool() == Tool::NodePoint) + { + end = data->GeometricObject(at(0).getId())->toQPointF(); + } + } + else + { + if (at(i+1).getTypeTool() == Tool::NodePoint) + { + end = data->GeometricObject(at(i+1).getId())->toQPointF(); + } + } + } + return end; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief biasPoints bias point. + * @param points vector of points. + * @param mx offset respect to x. + * @param my offset respect to y. + * @return new vector biased points. + */ +QVector VDetail::biasPoints(const QVector &points, const qreal &mx, const qreal &my) +{ + QVector p; + for (qint32 i = 0; i < points.size(); ++i) + { + QPointF point = points.at(i); + point.setX(point.x() + mx); + point.setY(point.y() + my); + p.append(point); + } + return p; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief append append in the end of list node. diff --git a/src/app/geometry/vdetail.h b/src/app/geometry/vdetail.h index 2e9bef2f4..366f7afaa 100644 --- a/src/app/geometry/vdetail.h +++ b/src/app/geometry/vdetail.h @@ -35,6 +35,7 @@ #include "../libs/vlayout/vabstractdetail.h" class VDetailData; +class VContainer; /** * @brief The VDetail class for path of object (points, arcs, splines). @@ -75,11 +76,19 @@ public: VDetail RemoveEdge(const quint32 &index) const; QList Missing(const VDetail &det) const; + + QVector ContourPoints(const VContainer *data) const; + QVector SeamAllowancePoints(const VContainer *data) const; private: QSharedDataPointer d; QVector listNodePoint()const; static int indexOfNode(const QVector &list, const quint32 &id); + + QPointF StartSegment(const VContainer *data, const int &i) const; + QPointF EndSegment(const VContainer *data, const int &i) const; + + static QVector biasPoints(const QVector &points, const qreal &mx, const qreal &my); }; #endif // VDETAIL_H