diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 019712899..89a67f97c 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -73,26 +73,4 @@ struct VCachedPositions 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 diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 904303ce6..1e63928b5 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -144,13 +144,6 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout) return; } -#ifdef LAYOUT_DEBUG - const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug"); - QDir debugDir(path); - debugDir.removeRecursively(); - debugDir.mkpath(path); -#endif - if (bank->PrepareUnsorted()) { if (timer.hasExpired(timeout)) diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index e6bb6744f..7d02f462f 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -229,8 +229,6 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &s d->localRotationNumber = d->globalRotationNumber; } - d->frame = 0; - return AddToSheet(detail, stop); } @@ -268,21 +266,9 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop data.isOriginPaperOrientationPortrait = d->originPaperOrientation; 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); threads.append(thread); thread_pool->start(thread); - -#ifdef LAYOUT_DEBUG - d->frame = d->frame + 3 + static_cast(360/d->localRotationIncrease*2); -#endif } } @@ -341,12 +327,6 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece positionChache.boundingRect = VLayoutPiece::BoundingRect(layoutPoints); positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints); 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? diff --git a/src/libs/vlayout/vlayoutpaper_p.h b/src/libs/vlayout/vlayoutpaper_p.h index 224d570eb..d4826b0da 100644 --- a/src/libs/vlayout/vlayoutpaper_p.h +++ b/src/libs/vlayout/vlayoutpaper_p.h @@ -57,7 +57,6 @@ public: positionsCache(paper.positionsCache), globalContour(paper.globalContour), paperIndex(paper.paperIndex), - frame(paper.frame), layoutWidth(paper.layoutWidth), globalRotate(paper.globalRotate), localRotate(paper.localRotate), @@ -79,7 +78,6 @@ public: VContour globalContour{}; quint32 paperIndex{0}; - quint32 frame{0}; qreal layoutWidth{0}; bool globalRotate{true}; bool localRotate{true}; diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 9ac38660e..6312636d3 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -49,101 +49,11 @@ #include "../vmisc/def.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 &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 &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) : QRunnable(), m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait)), m_data(data), -#ifdef LAYOUT_DEBUG - paperIndex(0), - frame(0), - detailsCount(0), - details(), -#endif stop(stop), angle_between(0) { @@ -164,145 +74,12 @@ void VPosition::run() 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 &details) -{ - this->details = details; -} -#endif - //--------------------------------------------------------------------------------------------------------------------- VBestSquare VPosition::getBestResult() const { return m_bestResult; } -#ifdef LAYOUT_DEBUG -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::DrawDebug(const VContour &contour, const VLayoutPiece &detail, int frame, quint32 paperIndex, - int detailsCount, const QVector &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, BestFrom type) @@ -341,12 +118,6 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge) CombineEdges(detail, globalEdge, dEdge); -#ifdef LAYOUT_DEBUG -# ifdef SHOW_COMBINE - DrawDebug(gContour, detail, frame, paperIndex, detailsCount, details); -# endif -#endif - CrossingType type = CrossingType::Intersection; 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()) { - #ifdef LAYOUT_DEBUG - #ifdef SHOW_MIRROR - DrawDebug(gContour, detail, frame+1, paperIndex, detailsCount, details); - #endif - #endif - if (m_data.gContour.GetContour().isEmpty()) { dEdge = detail.DetailEdgeByPoint(globalEdge.p2()); @@ -433,12 +198,6 @@ bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal RotateEdges(detail, globalEdge, dEdge, angle); -#ifdef LAYOUT_DEBUG - #ifdef SHOW_ROTATION - DrawDebug(gContour, detail, frame, paperIndex, detailsCount, details); - #endif -#endif - CrossingType type = CrossingType::Intersection; if (SheetContains(detail.DetailBoundingRect())) { @@ -469,18 +228,8 @@ void VPosition::RotateOnAngle(qreal 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); } -#ifdef LAYOUT_DEBUG - ++frame; -#endif } //--------------------------------------------------------------------------------------------------------------------- @@ -640,17 +389,8 @@ void VPosition::FindBestPosition() int dEdge = m_data.i;// For mirror detail edge will be different 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); } -#ifdef LAYOUT_DEBUG - frame = frame + 3; -#endif if (m_data.rotate) { diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index 4b2f31ba2..d476ecd1f 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -61,38 +61,12 @@ public: 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 &details); -#endif - VBestSquare getBestResult() const; -#ifdef LAYOUT_DEBUG - static void DrawDebug(const VContour &contour, const VLayoutPiece &detail, int frame, quint32 paperIndex, - int detailsCount, const QVector &details = QVector()); - - static int Bias(int length, int maxLength); -#endif - private: Q_DISABLE_COPY(VPosition) VBestSquare m_bestResult; VPositionData m_data; -#ifdef LAYOUT_DEBUG - quint32 paperIndex; - quint32 frame; - quint32 detailsCount; - QVector details; -#endif std::atomic_bool *stop; /** * @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation.