Fixed issue #198.

--HG--
branch : develop
This commit is contained in:
dismine 2014-12-12 14:35:54 +02:00
parent 8c2a06e63f
commit 0efbe1745c
2 changed files with 37 additions and 60 deletions

View File

@ -35,6 +35,7 @@
#include <QDebug> #include <QDebug>
#include <QPainterPath> #include <QPainterPath>
#include "../container/vcontainer.h" #include "../container/vcontainer.h"
#include <QtMath>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer *data) const QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer *data) const
@ -63,73 +64,21 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer
case (Tool::NodeArc): case (Tool::NodeArc):
{ {
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(detail.at(i).getId()); const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, arc->GetPoints()); // Detail points clockwise, but arc we draw counterclockwise. Main contour need reverse.
qreal lenReverse = GetLengthContour(points, GetReversePoint(arc->GetPoints())); const QVector<QPointF> reversedPoints = GetReversePoint(arc->GetPoints());
if (len1 <= lenReverse) AddContour(reversedPoints, points, pointsEkv, detail, i);
{
points << arc->GetPoints();
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(arc->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(arc->GetPoints());
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(GetReversePoint(arc->GetPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
} }
break; break;
case (Tool::NodeSpline): case (Tool::NodeSpline):
{ {
const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(detail.at(i).getId()); const QSharedPointer<VSpline> spline = data->GeometricObject<VSpline>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, spline->GetPoints()); AddContour(spline->GetPoints(), points, pointsEkv, detail, i);
qreal lenReverse = GetLengthContour(points, GetReversePoint(spline->GetPoints()));
if (len1 <= lenReverse)
{
points << spline->GetPoints();
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(spline->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(spline->GetPoints());
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(GetReversePoint(spline->GetPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
} }
break; break;
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
{ {
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(detail.at(i).getId()); const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, splinePath->GetPoints()); AddContour(splinePath->GetPoints(), points, pointsEkv, detail, i);
qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPoints()));
if (len1 <= lenReverse)
{
points << splinePath->GetPoints();
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(splinePath->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << GetReversePoint(splinePath->GetPoints());
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(GetReversePoint(splinePath->GetPoints()), detail.at(i).getMx(),
detail.at(i).getMy());
}
}
} }
break; break;
default: default:
@ -167,7 +116,7 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VEquidistant::GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints) int VEquidistant::GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints)
{ {
qreal length = 0; qreal length = 0;
QVector<QPointF> points; QVector<QPointF> points;
@ -177,7 +126,7 @@ qreal VEquidistant::GetLengthContour(const QVector<QPointF> &contour, const QVec
QLineF line(points.at(i), points.at(i+1)); QLineF line(points.at(i), points.at(i+1));
length += line.length(); length += line.length();
} }
return length; return qFloor(length);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -451,3 +400,28 @@ QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle
pLine.setLength( width ); pLine.setLength( width );
return pLine.p2(); return pLine.p2();
} }
//---------------------------------------------------------------------------------------------------------------------
void VEquidistant::AddContour(const QVector<QPointF> &nodePoints, QVector<QPointF> &points, QVector<QPointF> &pointsEkv,
const VDetail &detail, int i)
{
int len1 = GetLengthContour(points, nodePoints);
QVector<QPointF> reversedPoints = GetReversePoint(nodePoints);
int lenReverse = GetLengthContour(points, reversedPoints);
if (len1 <= lenReverse)
{
points << nodePoints;
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(nodePoints, detail.at(i).getMx(), detail.at(i).getMy());
}
}
else
{
points << reversedPoints;
if (detail.getSeamAllowance() == true)
{
pointsEkv << biasPoints(reversedPoints, detail.at(i).getMx(), detail.at(i).getMy());
}
}
}

View File

@ -56,7 +56,7 @@ private:
* @param newPoints point whos we try to add to contour. * @param newPoints point whos we try to add to contour.
* @return length length of contour. * @return length length of contour.
*/ */
static qreal GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints); static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
/** /**
* @brief biasPoints bias point. * @brief biasPoints bias point.
* @param points vector of points. * @param points vector of points.
@ -114,6 +114,9 @@ private:
* @return point of parallel line. * @return point of parallel line.
*/ */
static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width);
static void AddContour(const QVector<QPointF> &nodePoints, QVector<QPointF> &points,
QVector<QPointF> &pointsEkv, const VDetail &detail, int i);
}; };
#endif // VEQUIDISTANT_H #endif // VEQUIDISTANT_H