Resolved issue #595. GapWidth affecting to the margins.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-12-10 18:38:34 +02:00
parent 67a6b67afc
commit 9b679d7c3e
9 changed files with 179 additions and 149 deletions

View File

@ -46,6 +46,7 @@
- [#570] Tiled PDF : Margin values correctly taken into account
- [#580] Extend the list of heights.
- [#582] Issue with standard path to shared data on Linux.
- [#595] GapWidth affecting to the margins.
# Version 0.4.5 October 15, 2016
- [#435] Valentina doesn't change the cursor.

View File

@ -130,7 +130,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
QVector<QPointF> newContour;
if (d->globalContour.isEmpty()) //-V807
{
AppendWhole(newContour, detail, detJ);
AppendWhole(newContour, detail, 0);
}
else
{
@ -139,7 +139,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
return QVector<QPointF>();
}
if (detJ <= 0 || detJ > detail.EdgesCount())
if (detJ <= 0 || detJ > detail.LayoutEdgesCount())
{
return QVector<QPointF>();
}
@ -166,7 +166,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
else
{
int processedEdges = 0;
const int nD = detail.EdgesCount();
const int nD = detail.LayoutEdgesCount();
int j = detJ+1;
do
{
@ -176,7 +176,7 @@ QVector<QPointF> VContour::UniteWithContour(const VLayoutDetail &detail, int glo
}
if (j != detJ)
{
const QVector<QPointF> points = CutEdge(detail.Edge(j));
const QVector<QPointF> points = CutEdge(detail.LayoutEdge(j));
for (int i = 0; i < points.size()-1; ++i)
{
newContour.append(points.at(i));
@ -336,7 +336,7 @@ QPainterPath VContour::ContourPath() const
void VContour::AppendWhole(QVector<QPointF> &contour, const VLayoutDetail &detail, int detJ) const
{
int processedEdges = 0;
const int nD = detail.EdgesCount();
const int nD = detail.LayoutEdgesCount();
int j = detJ+1;
do
{
@ -344,7 +344,7 @@ void VContour::AppendWhole(QVector<QPointF> &contour, const VLayoutDetail &detai
{
j=1;
}
const QVector<QPointF> points = CutEdge(detail.Edge(j));
const QVector<QPointF> points = CutEdge(detail.LayoutEdge(j));
for (int i = 0; i < points.size()-1; ++i)
{
contour.append(points.at(i));

View File

@ -87,7 +87,7 @@ VLayoutDetail::~VLayoutDetail()
// cppcheck-suppress unusedFunction
QVector<QPointF> VLayoutDetail::GetContourPoints() const
{
return d->contour;
return Map(d->contour);
}
//---------------------------------------------------------------------------------------------------------------------
@ -100,7 +100,7 @@ void VLayoutDetail::SetCountourPoints(const QVector<QPointF> &points)
// cppcheck-suppress unusedFunction
QVector<QPointF> VLayoutDetail::GetSeamAllowencePoints() const
{
return d->seamAllowence;
return Map(d->seamAllowence);
}
//---------------------------------------------------------------------------------------------------------------------
@ -326,67 +326,39 @@ void VLayoutDetail::Mirror(const QLineF &edge)
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::EdgesCount() const
int VLayoutDetail::DetailEdgesCount() const
{
return DetailPath().count();
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::LayoutEdgesCount() const
{
return d->layoutAllowence.count();
}
//---------------------------------------------------------------------------------------------------------------------
QLineF VLayoutDetail::Edge(int i) const
QLineF VLayoutDetail::DetailEdge(int i) const
{
if (i < 1 || i > EdgesCount())
{ // Doesn't exist such edge
return QLineF();
}
int i1, i2;
if (i < EdgesCount())
{
i1 = i-1;
i2 = i;
}
else
{
i1 = EdgesCount()-1;
i2 = 0;
}
if (d->mirror)
{
const int oldI1 = i1;
const int size = d->layoutAllowence.size()-1; //-V807
i1 = size - i2;
i2 = size - oldI1;
return QLineF(d->matrix.map(d->layoutAllowence.at(i2)), d->matrix.map(d->layoutAllowence.at(i1)));
}
else
{
return QLineF(d->matrix.map(d->layoutAllowence.at(i1)), d->matrix.map(d->layoutAllowence.at(i2)));
}
return Edge(DetailPath(), i);
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::EdgeByPoint(const QPointF &p1) const
QLineF VLayoutDetail::LayoutEdge(int i) const
{
if (p1.isNull())
{
return 0;
}
return Edge(d->layoutAllowence, i);
}
if (EdgesCount() < 3)
{
return 0;
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::DetailEdgeByPoint(const QPointF &p1) const
{
return EdgeByPoint(DetailPath(), p1);
}
const QVector<QPointF> points = GetLayoutAllowencePoints();
for (int i=0; i< points.size(); i++)
{
if (points.at(i) == p1)
{
return i+1;
}
}
return 0; // Did not find edge
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::LayoutEdgeByPoint(const QPointF &p1) const
{
return EdgeByPoint(d->layoutAllowence, p1);
}
//---------------------------------------------------------------------------------------------------------------------
@ -462,7 +434,8 @@ void VLayoutDetail::SetLayoutAllowencePoints()
{
if (getSeamAllowance())
{
d->layoutAllowence = Equidistant(d->seamAllowence, EquidistantType::CloseEquidistant, d->layoutWidth);
d->layoutAllowence = Equidistant(GetSeamAllowencePoints(), EquidistantType::CloseEquidistant,
d->layoutWidth);
if (d->layoutAllowence.isEmpty() == false)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
@ -474,7 +447,7 @@ void VLayoutDetail::SetLayoutAllowencePoints()
}
else
{
d->layoutAllowence = Equidistant(d->contour, EquidistantType::CloseEquidistant, d->layoutWidth);
d->layoutAllowence = Equidistant(GetContourPoints(), EquidistantType::CloseEquidistant, d->layoutWidth);
if (d->layoutAllowence.isEmpty() == false)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
@ -529,7 +502,7 @@ QPainterPath VLayoutDetail::ContourPath() const
QPainterPath path;
// contour
QVector<QPointF> points = Map(d->contour);
QVector<QPointF> points = GetContourPoints();
path.moveTo(points.at(0));
for (qint32 i = 1; i < points.count(); ++i)
{
@ -540,7 +513,7 @@ QPainterPath VLayoutDetail::ContourPath() const
// seam allowence
if (getSeamAllowance() == true)
{
points = Map(d->seamAllowence);
points = GetSeamAllowencePoints();
if (getClosed() == true)
{
@ -762,6 +735,19 @@ QGraphicsItem* VLayoutDetail::GetGrainlineItem() const
return item;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VLayoutDetail::DetailPath() const
{
if (getSeamAllowance())
{
return d->seamAllowence;
}
else
{
return d->contour;
}
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutDetail::IsMirror() const
{
@ -831,3 +817,61 @@ qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2)
return qSqrt(dX*dX + dY*dY);
}
//---------------------------------------------------------------------------------------------------------------------
QLineF VLayoutDetail::Edge(const QVector<QPointF> &path, int i) const
{
if (i < 1 || i > path.count())
{ // Doesn't exist such edge
return QLineF();
}
int i1, i2;
if (i < path.count())
{
i1 = i-1;
i2 = i;
}
else
{
i1 = path.count()-1;
i2 = 0;
}
if (d->mirror)
{
const int oldI1 = i1;
const int size = path.size()-1; //-V807
i1 = size - i2;
i2 = size - oldI1;
return QLineF(d->matrix.map(path.at(i2)), d->matrix.map(path.at(i1)));
}
else
{
return QLineF(d->matrix.map(path.at(i1)), d->matrix.map(path.at(i2)));
}
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutDetail::EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const
{
if (p1.isNull())
{
return 0;
}
if (path.count() < 3)
{
return 0;
}
const QVector<QPointF> points = Map(path);
for (int i=0; i < points.size(); i++)
{
if (points.at(i) == p1)
{
return i+1;
}
}
return 0; // Did not find edge
}

View File

@ -97,9 +97,14 @@ public:
void Rotate(const QPointF &originPoint, qreal degrees);
void Mirror(const QLineF &edge);
int EdgesCount() const;
QLineF Edge(int i) const;
int EdgeByPoint(const QPointF &p1) const;
int DetailEdgesCount() const;
int LayoutEdgesCount() const;
QLineF DetailEdge(int i) const;
QLineF LayoutEdge(int i) const;
int DetailEdgeByPoint(const QPointF &p1) const;
int LayoutEdgeByPoint(const QPointF &p1) const;
QRectF DetailBoundingRect() const;
QRectF LayoutBoundingRect() const;
@ -119,12 +124,17 @@ public:
private:
QSharedDataPointer<VLayoutDetailData> d;
QVector<QPointF> DetailPath() const;
QVector<QPointF> Map(const QVector<QPointF> &points) const;
static QVector<QPointF> RoundPoints(const QVector<QPointF> &points);
static QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng);
QVector<QPointF> Mirror(const QVector<QPointF>& points) const;
static qreal GetDistance(const QPointF& pt1, const QPointF& pt2);
QLineF Edge(const QVector<QPointF> &path, int i) const;
int EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const;
};
Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE);

View File

@ -279,7 +279,13 @@ void VLayoutGenerator::GatherPages()
for (int i = 0; i < papers.size(); ++i)
{
const int paperHeight = qRound(papers.at(i).BoundingRect().height());
int paperHeight = qRound(papers.at(i).DetailsBoundingRect().height());
if (i != papers.size()-1)
{
paperHeight += qRound(bank->GetLayoutWidth()*2);
}
if (length + paperHeight <= PageHeight())
{
UniteDetails(j, nDetails, length, i);
@ -331,14 +337,17 @@ void VLayoutGenerator::UnitePages()
int paperHeight = 0;
if (autoCrop)
{
paperHeight = qRound(papers.at(i).BoundingRect().height());
paperHeight = qRound(papers.at(i).DetailsBoundingRect().height());
}
else
{
paperHeight = papers.at(i).GetHeight();
}
paperHeight = qRound(paperHeight + bank->GetLayoutWidth());
if (i != papers.size()-1)
{
paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2);
}
if (length + paperHeight <= QIMAGE_MAX)
{

View File

@ -193,7 +193,7 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail, volatile bool &sto
return false;
}
if (detail.EdgesCount() < 3)
if (detail.LayoutEdgesCount() < 3 || detail.DetailEdgesCount() < 3)
{
return false;//Not enough edges
}
@ -228,9 +228,20 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, volatile bool &stop)
thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads;
int detailEdgesCount = 0;
if (d->globalContour.GetContour().isEmpty())
{
detailEdgesCount = detail.DetailEdgesCount();
}
else
{
detailEdgesCount = detail.LayoutEdgesCount();
}
for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j)
{
for (int i=1; i<= detail.EdgesCount(); ++i)
for (int i=1; i<= detailEdgesCount; ++i)
{
VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->localRotate,
d->localRotationIncrease,
@ -311,14 +322,13 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop) const
QGraphicsRectItem *paper;
if (autoCrop)
{
QGraphicsScene *scene = new QGraphicsScene();
QScopedPointer<QGraphicsScene> scene(new QGraphicsScene());
QList<QGraphicsItem *> list = GetItemDetails();
for (int i=0; i < list.size(); ++i)
{
scene->addItem(list.at(i));
}
const int height = scene->itemsBoundingRect().toRect().height() + static_cast<int>(d->layoutWidth)*2;
delete scene;
const int height = scene->itemsBoundingRect().toRect().height();
if (d->globalContour.GetHeight() > height) //-V807
{
paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), height));
@ -371,12 +381,12 @@ void VLayoutPaper::SetDetails(const QList<VLayoutDetail> &details)
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VLayoutPaper::BoundingRect() const
QRectF VLayoutPaper::DetailsBoundingRect() const
{
QRectF rec;
for (int i=0; i < d->details.count(); ++i)
{
rec = rec.united(d->details.at(i).LayoutBoundingRect());
rec = rec.united(d->details.at(i).DetailBoundingRect());
}
return rec;

View File

@ -85,7 +85,7 @@ public:
QVector<VLayoutDetail> GetDetails() const;
void SetDetails(const QList<VLayoutDetail>& details);
QRectF BoundingRect() const;
QRectF DetailsBoundingRect() const;
private:
QSharedDataPointer<VLayoutPaperData> d;

View File

@ -267,7 +267,7 @@ bool VPosition::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge)
#endif
CrossingType type = CrossingType::Intersection;
if (SheetContains(detail.LayoutBoundingRect()))
if (SheetContains(detail.DetailBoundingRect()))
{
if (not gContour.GetContour().isEmpty())
{
@ -302,14 +302,22 @@ bool VPosition::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge)
#endif
#endif
dEdge = detail.EdgeByPoint(globalEdge.p2());
if (gContour.GetContour().isEmpty())
{
dEdge = detail.DetailEdgeByPoint(globalEdge.p2());
}
else
{
dEdge = detail.LayoutEdgeByPoint(globalEdge.p2());
}
if (dEdge <= 0)
{
return false;
}
CrossingType type = CrossingType::Intersection;
if (SheetContains(detail.LayoutBoundingRect()))
if (SheetContains(detail.DetailBoundingRect()))
{
type = Crossing(detail);
}
@ -346,7 +354,7 @@ bool VPosition::CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int
#endif
CrossingType type = CrossingType::Intersection;
if (SheetContains(detail.LayoutBoundingRect()))
if (SheetContains(detail.DetailBoundingRect()))
{
type = Crossing(detail);
}
@ -398,7 +406,15 @@ bool VPosition::SheetContains(const QRectF &rect) const
//---------------------------------------------------------------------------------------------------------------------
void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge)
{
QLineF detailEdge = detail.Edge(dEdge);
QLineF detailEdge;
if (gContour.GetContour().isEmpty())
{
detailEdge = detail.DetailEdge(dEdge);
}
else
{
detailEdge = detail.LayoutEdge(dEdge);
}
// Find distance between two edges for two begin vertex.
const qreal dx = globalEdge.x2() - detailEdge.x2();
@ -419,7 +435,15 @@ void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, co
//---------------------------------------------------------------------------------------------------------------------
void VPosition::RotateEdges(VLayoutDetail &detail, const QLineF &globalEdge, int dEdge, int angle) const
{
QLineF detailEdge = detail.Edge(dEdge);
QLineF detailEdge;
if (gContour.GetContour().isEmpty())
{
detailEdge = detail.DetailEdge(dEdge);
}
else
{
detailEdge = detail.LayoutEdge(dEdge);
}
// Find distance between two edges for two begin vertex.
const qreal dx = globalEdge.x2() - detailEdge.x2();
@ -432,69 +456,6 @@ void VPosition::RotateEdges(VLayoutDetail &detail, const QLineF &globalEdge, int
detail.Rotate(globalEdge.p2(), angle);
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::AppendWhole(QVector<QPointF> &contour, const VLayoutDetail &detail, int detJ, quint32 shift)
{
int processedEdges = 0;
const int nD = detail.EdgesCount();
int j = detJ+1;
do
{
if (j > nD)
{
j=1;
}
const QVector<QPointF> points = CutEdge(detail.Edge(j), shift);
for (int i = 0; i < points.size()-1; ++i)
{
contour.append(points.at(i));
}
++processedEdges;
++j;
}while (processedEdges < nD);
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
QPolygonF VPosition::GlobalPolygon() const
{
QVector<QPointF> points = gContour.GetContour();
points.append(points.first());
return QPolygonF(points);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VPosition::CutEdge(const QLineF &edge, quint32 shift)
{
QVector<QPointF> points;
if (shift == 0)
{
points.append(edge.p1());
points.append(edge.p2());
}
else
{
const int n = qFloor(edge.length()/shift);
if (n <= 0)
{
points.append(edge.p1());
points.append(edge.p2());
}
else
{
const qreal nShift = edge.length()/n;
for (int i = 1; i <= n+1; ++i)
{
QLineF l1 = edge;
l1.setLength(nShift*(i-1));
points.append(l1.p2());
}
}
}
return points;
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::Rotate(int increase)
{

View File

@ -116,15 +116,10 @@ private:
void CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge);
void RotateEdges(VLayoutDetail &detail, const QLineF &globalEdge, int dEdge, int angle) const;
QPolygonF GlobalPolygon() const;
static QPainterPath ShowDirection(const QLineF &edge);
static QPainterPath DrawContour(const QVector<QPointF> &points);
static QPainterPath DrawDetails(const QVector<VLayoutDetail> &details);
static void AppendWhole(QVector<QPointF> &contour, const VLayoutDetail &detail, int detJ, quint32 shift);
static QVector<QPointF> CutEdge(const QLineF &edge, quint32 shift);
void Rotate(int increase);
};