Improve saving a layout result.
--HG-- branch : develop
This commit is contained in:
parent
f1f5806be3
commit
b80103e088
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "vbestsquare.h"
|
||||
#include "vbestsquare_p.h"
|
||||
#include "../vmisc/def.h"
|
||||
|
||||
#include <QMatrix>
|
||||
|
||||
|
@ -76,21 +77,33 @@ void VBestSquare::NewResult(const VBestSquareResData &data)
|
|||
|
||||
const qint64 candidateSquare = Square(data.bestSize);
|
||||
|
||||
if (candidateSquare > 0)
|
||||
if (candidateSquare > 0 && data.type >= d->data.type && candidateSquare <= Square(d->data.bestSize))
|
||||
{
|
||||
if (data.type >= d->data.type && candidateSquare <= Square(d->data.bestSize)
|
||||
&& data.depthPosition <= d->data.depthPosition)
|
||||
if (not HasValidResult())
|
||||
{
|
||||
SaveResult(); // First result
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d->saveLength)
|
||||
{
|
||||
if (data.depthPosition <= d->data.depthPosition)
|
||||
if (VFuzzyComparePossibleNulls(data.depthPosition, d->data.depthPosition)
|
||||
&& IsImprovedSidePosition(data.sidePosition))
|
||||
{
|
||||
SaveResult();
|
||||
}
|
||||
else if (data.depthPosition < d->data.depthPosition)
|
||||
{
|
||||
SaveResult();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveResult();
|
||||
if (IsImprovedSidePosition(data.sidePosition)
|
||||
|| VFuzzyComparePossibleNulls(data.sidePosition, d->data.sidePosition))
|
||||
{
|
||||
SaveResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,6 +178,15 @@ bool VBestSquare::IsSaveLength() const
|
|||
return d->saveLength;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VBestSquare::IsImprovedSidePosition(qreal sidePosition) const
|
||||
{
|
||||
const bool lessThan = d->data.sidePosition < sidePosition;
|
||||
const bool greaterThan = d->data.sidePosition > sidePosition;
|
||||
|
||||
return IsPortrait() ? greaterThan : lessThan;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VBestSquare::IsPortrait() const
|
||||
{
|
||||
|
|
|
@ -69,10 +69,12 @@ public:
|
|||
VBestSquareResData BestResultData() const;
|
||||
|
||||
bool IsSaveLength() const;
|
||||
bool IsImprovedSidePosition(qreal sidePosition) const;
|
||||
bool IsPortrait() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<VBestSquareData> d;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_TYPEINFO(VBestSquare, Q_MOVABLE_TYPE);
|
||||
|
|
|
@ -63,6 +63,8 @@ struct VBestSquareResData
|
|||
BestFrom type{BestFrom::Rotation};
|
||||
// cppcheck-suppress unusedStructMember
|
||||
qreal depthPosition{INT_MAX};
|
||||
// cppcheck-suppress unusedStructMember
|
||||
qreal sidePosition{0};
|
||||
};
|
||||
|
||||
struct VCachedPositions
|
||||
|
|
|
@ -179,6 +179,7 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
|
|||
paper.SetFollowGrainline(followGrainline);
|
||||
paper.SetRotationNumber(rotationNumber);
|
||||
paper.SetSaveLength(saveLength);
|
||||
paper.SetOriginPaperPortrait(IsPortrait());
|
||||
do
|
||||
{
|
||||
const int index = bank->GetNext();
|
||||
|
|
|
@ -192,6 +192,18 @@ void VLayoutPaper::SetPaperIndex(quint32 index)
|
|||
d->paperIndex = index;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VLayoutPaper::IsOriginPaperPortrait() const
|
||||
{
|
||||
return d->originPaperOrientation;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VLayoutPaper::SetOriginPaperPortrait(bool portrait)
|
||||
{
|
||||
d->originPaperOrientation = portrait;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VLayoutPaper::ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop)
|
||||
{
|
||||
|
@ -253,6 +265,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
|
|||
data.rotationNumber = d->localRotationNumber;
|
||||
data.followGrainline = d->followGrainline;
|
||||
data.positionsCache = d->positionsCache;
|
||||
data.isOriginPaperOrientationPortrait = d->originPaperOrientation;
|
||||
|
||||
auto *thread = new VPosition(data, &stop, d->saveLength);
|
||||
//Info for debug
|
||||
|
|
|
@ -90,6 +90,9 @@ public:
|
|||
|
||||
void SetPaperIndex(quint32 index);
|
||||
|
||||
bool IsOriginPaperPortrait() const;
|
||||
void SetOriginPaperPortrait(bool portrait);
|
||||
|
||||
bool ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop);
|
||||
int Count() const;
|
||||
Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const;
|
||||
|
|
|
@ -64,7 +64,8 @@ public:
|
|||
globalRotationNumber(paper.globalRotationNumber),
|
||||
localRotationNumber(paper.localRotationNumber),
|
||||
saveLength(paper.saveLength),
|
||||
followGrainline(paper.followGrainline)
|
||||
followGrainline(paper.followGrainline),
|
||||
originPaperOrientation(paper.originPaperOrientation)
|
||||
{}
|
||||
|
||||
~VLayoutPaperData() {}
|
||||
|
@ -86,6 +87,7 @@ public:
|
|||
int localRotationNumber{2};
|
||||
bool saveLength{false};
|
||||
bool followGrainline{false};
|
||||
bool originPaperOrientation{true};
|
||||
|
||||
private:
|
||||
VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE;
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "../vmisc/vabstractapplication.h"
|
||||
#include "../vpatterndb/calculator.h"
|
||||
#include "../vpatterndb/vpassmark.h"
|
||||
#include "../vpatterndb/vpiecenode.h"
|
||||
#include "../vgeometry/vpointf.h"
|
||||
#include "../vgeometry/vplacelabelitem.h"
|
||||
#include "vlayoutdef.h"
|
||||
|
|
|
@ -315,8 +315,9 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai
|
|||
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
|
||||
newGContour.append(newGContour.first());
|
||||
const QSizeF size = QPolygonF(newGContour).boundingRect().size();
|
||||
const qreal depthPosition = m_data.gContour.IsPortrait() ? detail.DetailBoundingRect().y() :
|
||||
detail.DetailBoundingRect().x();
|
||||
const QRectF boundingRect = detail.DetailBoundingRect();
|
||||
const qreal depthPosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.y() : boundingRect.x();
|
||||
const qreal sidePosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.x() : boundingRect.y();
|
||||
|
||||
VBestSquareResData data;
|
||||
data.bestSize = size;
|
||||
|
@ -326,6 +327,7 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai
|
|||
data.resMirror = detail.IsMirror();
|
||||
data.type = type;
|
||||
data.depthPosition = depthPosition;
|
||||
data.sidePosition = sidePosition;
|
||||
|
||||
bestResult.NewResult(data);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ struct VPositionData
|
|||
int rotationNumber{0};
|
||||
bool followGrainline{false};
|
||||
QVector<VCachedPositions> positionsCache{};
|
||||
bool isOriginPaperOrientationPortrait{true};
|
||||
};
|
||||
|
||||
class VPosition : public QRunnable
|
||||
|
@ -140,8 +141,7 @@ private:
|
|||
*/
|
||||
inline QLineF VPosition::FabricGrainline() const
|
||||
{
|
||||
return m_data.gContour.GetHeight() >= m_data.gContour.GetWidth() ? QLineF(10, 10, 10, 100) :
|
||||
QLineF(10, 10, 100, 10);
|
||||
return m_data.isOriginPaperOrientationPortrait ? QLineF(10, 10, 10, 100) : QLineF(10, 10, 100, 10);
|
||||
}
|
||||
|
||||
#endif // VPOSITION_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user