Remove obsolete debugging system.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-06-18 14:53:00 +03:00
parent 9030cfd52e
commit d16b0d5501
6 changed files with 0 additions and 337 deletions

View File

@ -73,26 +73,4 @@ struct VCachedPositions
QPainterPath layoutAllowancePath{}; QPainterPath layoutAllowancePath{};
}; };
/* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable
* Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer
*/
//#define LAYOUT_DEBUG // Enable debug mode
// This block help rule debug mode. Don't turn all options at the same time!
#ifdef LAYOUT_DEBUG
// Nice looking
# define SHOW_VERTICES // Show contour vertices
# define SHOW_DIRECTION // Show contour direction
# define ARRANGED_DETAILS // Show already arranged details
//# define SHOW_SHEET // Show sheet rect
// Debugging
# define SHOW_CANDIDATE // Show each position
//# define SHOW_ROTATION // For each position show rotation part
//# define SHOW_COMBINE // For each position show edge combine part
//# define SHOW_MIRROR // For each position show mirror part
//# define SHOW_CANDIDATE_BEST // For only correct positions that pass checks
# define SHOW_BEST // Show only best position for workpiece
#endif//LAYOUT_DEBUG
#endif // VLAYOUTDEF_H #endif // VLAYOUTDEF_H

View File

@ -144,13 +144,6 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return; return;
} }
#ifdef LAYOUT_DEBUG
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug");
QDir debugDir(path);
debugDir.removeRecursively();
debugDir.mkpath(path);
#endif
if (bank->PrepareUnsorted()) if (bank->PrepareUnsorted())
{ {
if (timer.hasExpired(timeout)) if (timer.hasExpired(timeout))

View File

@ -229,8 +229,6 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &s
d->localRotationNumber = d->globalRotationNumber; d->localRotationNumber = d->globalRotationNumber;
} }
d->frame = 0;
return AddToSheet(detail, stop); return AddToSheet(detail, stop);
} }
@ -268,21 +266,9 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
data.isOriginPaperOrientationPortrait = d->originPaperOrientation; data.isOriginPaperOrientationPortrait = d->originPaperOrientation;
auto *thread = new VPosition(data, &stop, d->saveLength); auto *thread = new VPosition(data, &stop, d->saveLength);
//Info for debug
#ifdef LAYOUT_DEBUG
thread->setPaperIndex(d->paperIndex);
thread->setFrame(d->frame);
thread->setDetailsCount(d->details.count());
thread->setDetails(d->details);
#endif
thread->setAutoDelete(false); thread->setAutoDelete(false);
threads.append(thread); threads.append(thread);
thread_pool->start(thread); thread_pool->start(thread);
#ifdef LAYOUT_DEBUG
d->frame = d->frame + 3 + static_cast<quint32>(360/d->localRotationIncrease*2);
#endif
} }
} }
@ -341,12 +327,6 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece
positionChache.boundingRect = VLayoutPiece::BoundingRect(layoutPoints); positionChache.boundingRect = VLayoutPiece::BoundingRect(layoutPoints);
positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints); positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints);
d->positionsCache.append(positionChache); d->positionsCache.append(positionChache);
#ifdef LAYOUT_DEBUG
# ifdef SHOW_BEST
VPosition::DrawDebug(d->globalContour, workDetail, UINT_MAX, d->paperIndex, d->details.count(), d->details);
# endif
#endif
} }
return bestResult.HasValidResult(); // Do we have the best result? return bestResult.HasValidResult(); // Do we have the best result?

View File

@ -57,7 +57,6 @@ public:
positionsCache(paper.positionsCache), positionsCache(paper.positionsCache),
globalContour(paper.globalContour), globalContour(paper.globalContour),
paperIndex(paper.paperIndex), paperIndex(paper.paperIndex),
frame(paper.frame),
layoutWidth(paper.layoutWidth), layoutWidth(paper.layoutWidth),
globalRotate(paper.globalRotate), globalRotate(paper.globalRotate),
localRotate(paper.localRotate), localRotate(paper.localRotate),
@ -79,7 +78,6 @@ public:
VContour globalContour{}; VContour globalContour{};
quint32 paperIndex{0}; quint32 paperIndex{0};
quint32 frame{0};
qreal layoutWidth{0}; qreal layoutWidth{0};
bool globalRotate{true}; bool globalRotate{true};
bool localRotate{true}; bool localRotate{true};

View File

@ -49,101 +49,11 @@
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
namespace
{
//---------------------------------------------------------------------------------------------------------------------
#ifdef SHOW_DIRECTION
QPainterPath ShowDirection(const QLineF &edge)
{
const int arrowLength = 14;
QPainterPath path;
if (edge.length()/arrowLength < 5)
{
return path;
}
QLineF arrow = edge;
arrow.setLength(edge.length()/2.0);
//Reverse line because we want start arrow from this point
arrow = QLineF(arrow.p2(), arrow.p1());
const qreal angle = arrow.angle();//we each time change line angle, better save original angle value
arrow.setLength(arrowLength);//arrow length in pixels
arrow.setAngle(angle-35);
path.moveTo(arrow.p1());
path.lineTo(arrow.p2());
arrow.setAngle(angle+35);
path.moveTo(arrow.p1());
path.lineTo(arrow.p2());
return path;
}
#endif
#ifdef LAYOUT_DEBUG
//---------------------------------------------------------------------------------------------------------------------
QPainterPath DrawContour(const QVector<QPointF> &points)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
if (points.count() >= 2)
{
for (qint32 i = 0; i < points.count()-1; ++i)
{
path.moveTo(points.at(i));
path.lineTo(points.at(i+1));
}
path.lineTo(points.at(0));
#ifdef SHOW_DIRECTION
for (qint32 i = 0; i < points.count()-1; ++i)
{
path.addPath(ShowDirection(QLineF(points.at(i), points.at(i+1))));
}
#endif
#ifdef SHOW_VERTICES
for (qint32 i = 0; i < points.count(); ++i)
{
path.addRect(points.at(i).x()-3, points.at(i).y()-3, 6, 6);
}
#endif
}
return path;
}
#endif
//---------------------------------------------------------------------------------------------------------------------
#ifdef ARRANGED_DETAILS
QPainterPath DrawDetails(const QVector<VLayoutPiece> &details)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
if (details.count() > 0)
{
for (auto &detail : details)
{
path.addPath(detail.ContourPath());
}
}
return path;
}
#endif
} //anonymous namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPosition::VPosition(const VPositionData &data, std::atomic_bool *stop, bool saveLength) VPosition::VPosition(const VPositionData &data, std::atomic_bool *stop, bool saveLength)
: QRunnable(), : QRunnable(),
m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait)), m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait)),
m_data(data), m_data(data),
#ifdef LAYOUT_DEBUG
paperIndex(0),
frame(0),
detailsCount(0),
details(),
#endif
stop(stop), stop(stop),
angle_between(0) angle_between(0)
{ {
@ -164,145 +74,12 @@ void VPosition::run()
FindBestPosition(); FindBestPosition();
} }
#ifdef LAYOUT_DEBUG
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
quint32 VPosition::getPaperIndex() const
{
return paperIndex;
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::setPaperIndex(quint32 value)
{
paperIndex = value;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
quint32 VPosition::getFrame() const
{
return frame;
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::setFrame(quint32 value)
{
frame = value;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
quint32 VPosition::getDetailsCount() const
{
return detailsCount;
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::setDetailsCount(quint32 value)
{
detailsCount = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VPosition::setDetails(const QVector<VLayoutPiece> &details)
{
this->details = details;
}
#endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VBestSquare VPosition::getBestResult() const VBestSquare VPosition::getBestResult() const
{ {
return m_bestResult; return m_bestResult;
} }
#ifdef LAYOUT_DEBUG
//---------------------------------------------------------------------------------------------------------------------
void VPosition::DrawDebug(const VContour &contour, const VLayoutPiece &detail, int frame, quint32 paperIndex,
int detailsCount, const QVector<VLayoutPiece> &details)
{
const int biasWidth = Bias(contour.GetWidth(), QIMAGE_MAX);
const int biasHeight = Bias(contour.GetHeight(), QIMAGE_MAX);
QPicture picture;
QPainter paint;
paint.begin(&picture);
paint.setPen(QPen(Qt::black, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
QPainterPath p;
if (contour.GetContour().isEmpty())
{
p = DrawContour(contour.CutEmptySheetEdge());
p.translate(biasWidth/2, biasHeight/2);
paint.drawPath(p);
}
else
{
p = DrawContour(contour.GetContour());
p.translate(biasWidth/2, biasHeight/2);
paint.drawPath(p);
}
#ifdef SHOW_CANDIDATE
paint.setPen(QPen(Qt::darkGreen, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
p = DrawContour(detail.GetLayoutAllowancePoints());
p.translate(biasWidth/2, biasHeight/2);
paint.drawPath(p);
#else
Q_UNUSED(detail)
Q_UNUSED(details)
#endif
#ifdef ARRANGED_DETAILS
paint.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
p = DrawDetails(details);
p.translate(biasWidth/2, biasHeight/2);
paint.drawPath(p);
#else
Q_UNUSED(details)
#endif
// Calculate bounding rect before draw sheet rect
const QRect pictureRect = picture.boundingRect();
// Sheet
#ifdef SHOW_SHEET
paint.setPen(QPen(Qt::darkRed, 15, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
paint.drawRect(QRectF(biasWidth/2, biasHeight/2, contour.GetWidth(), contour.GetHeight()));
#endif
paint.end();
// Dump frame to image
// Note. If program was build with Address Sanitizer possible crashes. Address Sanitizer doesn't support big
// allocations. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer
QImage frameImage(pictureRect.width()+biasWidth, pictureRect.height()+biasHeight, QImage::Format_RGB32);
if (frameImage.isNull())
{
return;
}
frameImage.fill(Qt::white);
QPainter paintFrameImage;
paintFrameImage.begin(&frameImage);
paintFrameImage.drawPicture(0, 0, picture);
paintFrameImage.end();
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug/%1_%2_%3.png").arg(paperIndex)
.arg(detailsCount).arg(frame);
frameImage.save (path);
}
//---------------------------------------------------------------------------------------------------------------------
int VPosition::Bias(int length, int maxLength)
{
return length < maxLength && length*2 < maxLength ? length : maxLength-length;
}
#endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ,
BestFrom type) BestFrom type)
@ -341,12 +118,6 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge)
CombineEdges(detail, globalEdge, dEdge); CombineEdges(detail, globalEdge, dEdge);
#ifdef LAYOUT_DEBUG
# ifdef SHOW_COMBINE
DrawDebug(gContour, detail, frame, paperIndex, detailsCount, details);
# endif
#endif
CrossingType type = CrossingType::Intersection; CrossingType type = CrossingType::Intersection;
if (not detail.IsForceFlipping() && SheetContains(detail.DetailBoundingRect())) if (not detail.IsForceFlipping() && SheetContains(detail.DetailBoundingRect()))
{ {
@ -377,12 +148,6 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge)
if (flagMirror && not detail.IsForbidFlipping()) if (flagMirror && not detail.IsForbidFlipping())
{ {
#ifdef LAYOUT_DEBUG
#ifdef SHOW_MIRROR
DrawDebug(gContour, detail, frame+1, paperIndex, detailsCount, details);
#endif
#endif
if (m_data.gContour.GetContour().isEmpty()) if (m_data.gContour.GetContour().isEmpty())
{ {
dEdge = detail.DetailEdgeByPoint(globalEdge.p2()); dEdge = detail.DetailEdgeByPoint(globalEdge.p2());
@ -433,12 +198,6 @@ bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal
RotateEdges(detail, globalEdge, dEdge, angle); RotateEdges(detail, globalEdge, dEdge, angle);
#ifdef LAYOUT_DEBUG
#ifdef SHOW_ROTATION
DrawDebug(gContour, detail, frame, paperIndex, detailsCount, details);
#endif
#endif
CrossingType type = CrossingType::Intersection; CrossingType type = CrossingType::Intersection;
if (SheetContains(detail.DetailBoundingRect())) if (SheetContains(detail.DetailBoundingRect()))
{ {
@ -469,18 +228,8 @@ void VPosition::RotateOnAngle(qreal angle)
if (CheckRotationEdges(workDetail, m_data.j, m_data.i, angle)) if (CheckRotationEdges(workDetail, m_data.j, m_data.i, angle))
{ {
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
++frame;
DrawDebug(gContour, workDetail, frame, paperIndex, detailsCount, details);
# endif
#endif
SaveCandidate(m_bestResult, workDetail, m_data.j, m_data.i, BestFrom::Rotation); SaveCandidate(m_bestResult, workDetail, m_data.j, m_data.i, BestFrom::Rotation);
} }
#ifdef LAYOUT_DEBUG
++frame;
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -640,17 +389,8 @@ void VPosition::FindBestPosition()
int dEdge = m_data.i;// For mirror detail edge will be different int dEdge = m_data.i;// For mirror detail edge will be different
if (CheckCombineEdges(workDetail, m_data.j, dEdge)) if (CheckCombineEdges(workDetail, m_data.j, dEdge))
{ {
#ifdef LAYOUT_DEBUG
# ifdef SHOW_CANDIDATE_BEST
DrawDebug(gContour, workDetail, frame+2, paperIndex, detailsCount, details);
# endif
#endif
SaveCandidate(m_bestResult, workDetail, m_data.j, dEdge, BestFrom::Combine); SaveCandidate(m_bestResult, workDetail, m_data.j, dEdge, BestFrom::Combine);
} }
#ifdef LAYOUT_DEBUG
frame = frame + 3;
#endif
if (m_data.rotate) if (m_data.rotate)
{ {

View File

@ -61,38 +61,12 @@ public:
virtual void run() override; virtual void run() override;
#ifdef LAYOUT_DEBUG
quint32 getPaperIndex() const;
void setPaperIndex(quint32 value);
quint32 getFrame() const;
void setFrame(quint32 value);
quint32 getDetailsCount() const;
void setDetailsCount(quint32 value);
void setDetails(const QVector<VLayoutPiece> &details);
#endif
VBestSquare getBestResult() const; VBestSquare getBestResult() const;
#ifdef LAYOUT_DEBUG
static void DrawDebug(const VContour &contour, const VLayoutPiece &detail, int frame, quint32 paperIndex,
int detailsCount, const QVector<VLayoutPiece> &details = QVector<VLayoutPiece>());
static int Bias(int length, int maxLength);
#endif
private: private:
Q_DISABLE_COPY(VPosition) Q_DISABLE_COPY(VPosition)
VBestSquare m_bestResult; VBestSquare m_bestResult;
VPositionData m_data; VPositionData m_data;
#ifdef LAYOUT_DEBUG
quint32 paperIndex;
quint32 frame;
quint32 detailsCount;
QVector<VLayoutPiece> details;
#endif
std::atomic_bool *stop; std::atomic_bool *stop;
/** /**
* @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation. * @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation.