Improving contour edge for empty sheet.

It must follow sheet orientation, plus added control of numbers of points with
shift option.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-12-28 15:57:24 +02:00
parent 6bc160075b
commit bcb7def7b8
2 changed files with 18 additions and 7 deletions

View File

@ -211,27 +211,30 @@ int VContour::GlobalEdgesCount() const
int count = 0; int count = 0;
if (not d->globalContour.isEmpty()) if (not d->globalContour.isEmpty())
{ {
return 10; count = d->globalContour.count();
} }
else else
{ {
return d->globalContour.count(); const qreal shift = d->shift == 0 ? ToPixel(0.5, Unit::Cm) : d->shift;
count = qFloor(EmptySheetEdge().length()/shift);
} }
return count;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QLineF VContour::GlobalEdge(int i) const QLineF VContour::GlobalEdge(int i) const
{ {
QLineF edge;
if (d->globalContour.isEmpty()) //-V807 if (d->globalContour.isEmpty()) //-V807
{ {
// Because sheet is blank we have one global edge for all cases - Ox axis. // Because sheet is blank we have one global edge for all cases.
if (i < 1 || i > GlobalEdgesCount()) if (i < 1 || i > GlobalEdgesCount())
{ // Doesn't exist such edge { // Doesn't exist such edge
return EmptySheetEdge(); return EmptySheetEdge();
} }
const qreal nShift = EmptySheetEdge().length()/GlobalEdgesCount(); const qreal nShift = EmptySheetEdge().length()/GlobalEdgesCount();
return QLineF(nShift*(i-1), 0, nShift*i, 0); edge = IsPortrait() ? QLineF(nShift*(i-1), 0, nShift*i, 0) : QLineF(0, nShift*(i-1), 0, nShift*i);
} }
else else
{ {
@ -239,7 +242,7 @@ QLineF VContour::GlobalEdge(int i) const
{ // Doesn't exist such edge { // Doesn't exist such edge
return QLineF(); return QLineF();
} }
QLineF edge;
if (i < GlobalEdgesCount()) if (i < GlobalEdgesCount())
{ {
edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i)); edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i));
@ -248,8 +251,8 @@ QLineF VContour::GlobalEdge(int i) const
{ // Closed countour { // Closed countour
edge = QLineF(d->globalContour.at(GlobalEdgesCount()-1), d->globalContour.at(0)); edge = QLineF(d->globalContour.at(GlobalEdgesCount()-1), d->globalContour.at(0));
} }
return edge;
} }
return edge;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -355,8 +358,14 @@ void VContour::AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail
}while (processedEdges < nD); }while (processedEdges < nD);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VContour::IsPortrait() const
{
return d->paperHeight >= d->paperWidth;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QLineF VContour::EmptySheetEdge() const QLineF VContour::EmptySheetEdge() const
{ {
return QLineF(0, 0, d->paperWidth - 5, 0); return IsPortrait() ? QLineF(0, 0, d->paperWidth, 0) : QLineF(0, 0, 0, d->paperHeight);
} }

View File

@ -93,6 +93,8 @@ private:
QSharedDataPointer<VContourData> d; QSharedDataPointer<VContourData> d;
void AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const; void AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const;
bool IsPortrait() const;
}; };
Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE);