Improve saving a layout result.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-06-18 14:28:16 +03:00
parent f1f5806be3
commit b80103e088
10 changed files with 58 additions and 10 deletions

View File

@ -28,6 +28,7 @@
#include "vbestsquare.h" #include "vbestsquare.h"
#include "vbestsquare_p.h" #include "vbestsquare_p.h"
#include "../vmisc/def.h"
#include <QMatrix> #include <QMatrix>
@ -76,21 +77,33 @@ void VBestSquare::NewResult(const VBestSquareResData &data)
const qint64 candidateSquare = Square(data.bestSize); 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) if (not HasValidResult())
&& data.depthPosition <= d->data.depthPosition) {
SaveResult(); // First result
}
else
{ {
if (d->saveLength) 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(); SaveResult();
} }
} }
else else
{ {
SaveResult(); if (IsImprovedSidePosition(data.sidePosition)
|| VFuzzyComparePossibleNulls(data.sidePosition, d->data.sidePosition))
{
SaveResult();
}
} }
} }
} }
@ -165,6 +178,15 @@ bool VBestSquare::IsSaveLength() const
return d->saveLength; 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 bool VBestSquare::IsPortrait() const
{ {

View File

@ -69,10 +69,12 @@ public:
VBestSquareResData BestResultData() const; VBestSquareResData BestResultData() const;
bool IsSaveLength() const; bool IsSaveLength() const;
bool IsImprovedSidePosition(qreal sidePosition) const;
bool IsPortrait() const; bool IsPortrait() const;
private: private:
QSharedDataPointer<VBestSquareData> d; QSharedDataPointer<VBestSquareData> d;
}; };
Q_DECLARE_TYPEINFO(VBestSquare, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(VBestSquare, Q_MOVABLE_TYPE);

View File

@ -63,6 +63,8 @@ struct VBestSquareResData
BestFrom type{BestFrom::Rotation}; BestFrom type{BestFrom::Rotation};
// cppcheck-suppress unusedStructMember // cppcheck-suppress unusedStructMember
qreal depthPosition{INT_MAX}; qreal depthPosition{INT_MAX};
// cppcheck-suppress unusedStructMember
qreal sidePosition{0};
}; };
struct VCachedPositions struct VCachedPositions

View File

@ -179,6 +179,7 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
paper.SetFollowGrainline(followGrainline); paper.SetFollowGrainline(followGrainline);
paper.SetRotationNumber(rotationNumber); paper.SetRotationNumber(rotationNumber);
paper.SetSaveLength(saveLength); paper.SetSaveLength(saveLength);
paper.SetOriginPaperPortrait(IsPortrait());
do do
{ {
const int index = bank->GetNext(); const int index = bank->GetNext();

View File

@ -192,6 +192,18 @@ void VLayoutPaper::SetPaperIndex(quint32 index)
d->paperIndex = 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) 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.rotationNumber = d->localRotationNumber;
data.followGrainline = d->followGrainline; data.followGrainline = d->followGrainline;
data.positionsCache = d->positionsCache; data.positionsCache = d->positionsCache;
data.isOriginPaperOrientationPortrait = d->originPaperOrientation;
auto *thread = new VPosition(data, &stop, d->saveLength); auto *thread = new VPosition(data, &stop, d->saveLength);
//Info for debug //Info for debug

View File

@ -90,6 +90,9 @@ public:
void SetPaperIndex(quint32 index); void SetPaperIndex(quint32 index);
bool IsOriginPaperPortrait() const;
void SetOriginPaperPortrait(bool portrait);
bool ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop); bool ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop);
int Count() const; int Count() const;
Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const; Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const;

View File

@ -64,7 +64,8 @@ public:
globalRotationNumber(paper.globalRotationNumber), globalRotationNumber(paper.globalRotationNumber),
localRotationNumber(paper.localRotationNumber), localRotationNumber(paper.localRotationNumber),
saveLength(paper.saveLength), saveLength(paper.saveLength),
followGrainline(paper.followGrainline) followGrainline(paper.followGrainline),
originPaperOrientation(paper.originPaperOrientation)
{} {}
~VLayoutPaperData() {} ~VLayoutPaperData() {}
@ -86,6 +87,7 @@ public:
int localRotationNumber{2}; int localRotationNumber{2};
bool saveLength{false}; bool saveLength{false};
bool followGrainline{false}; bool followGrainline{false};
bool originPaperOrientation{true};
private: private:
VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE; VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE;

View File

@ -51,6 +51,7 @@
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../vpatterndb/vpassmark.h" #include "../vpatterndb/vpassmark.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vgeometry/vplacelabelitem.h" #include "../vgeometry/vplacelabelitem.h"
#include "vlayoutdef.h" #include "vlayoutdef.h"

View File

@ -315,8 +315,9 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type); QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
newGContour.append(newGContour.first()); newGContour.append(newGContour.first());
const QSizeF size = QPolygonF(newGContour).boundingRect().size(); const QSizeF size = QPolygonF(newGContour).boundingRect().size();
const qreal depthPosition = m_data.gContour.IsPortrait() ? detail.DetailBoundingRect().y() : const QRectF boundingRect = detail.DetailBoundingRect();
detail.DetailBoundingRect().x(); const qreal depthPosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.y() : boundingRect.x();
const qreal sidePosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.x() : boundingRect.y();
VBestSquareResData data; VBestSquareResData data;
data.bestSize = size; data.bestSize = size;
@ -326,6 +327,7 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai
data.resMirror = detail.IsMirror(); data.resMirror = detail.IsMirror();
data.type = type; data.type = type;
data.depthPosition = depthPosition; data.depthPosition = depthPosition;
data.sidePosition = sidePosition;
bestResult.NewResult(data); bestResult.NewResult(data);
} }

View File

@ -50,6 +50,7 @@ struct VPositionData
int rotationNumber{0}; int rotationNumber{0};
bool followGrainline{false}; bool followGrainline{false};
QVector<VCachedPositions> positionsCache{}; QVector<VCachedPositions> positionsCache{};
bool isOriginPaperOrientationPortrait{true};
}; };
class VPosition : public QRunnable class VPosition : public QRunnable
@ -140,8 +141,7 @@ private:
*/ */
inline QLineF VPosition::FabricGrainline() const inline QLineF VPosition::FabricGrainline() const
{ {
return m_data.gContour.GetHeight() >= m_data.gContour.GetWidth() ? QLineF(10, 10, 10, 100) : return m_data.isOriginPaperOrientationPortrait ? QLineF(10, 10, 10, 100) : QLineF(10, 10, 100, 10);
QLineF(10, 10, 100, 10);
} }
#endif // VPOSITION_H #endif // VPOSITION_H