From afc31997d5c8a852ec66a67da34dd4c48a359654 Mon Sep 17 00:00:00 2001 From: DSCaskey <31944718+DSCaskey@users.noreply.github.com> Date: Sun, 24 Nov 2024 10:18:37 -0500 Subject: [PATCH 1/2] remove unstable debugging from layout generation --- src/libs/vlayout/vlayoutdef.h | 23 --- src/libs/vlayout/vlayoutgenerator.cpp | 7 - src/libs/vlayout/vlayoutpaper.cpp | 16 -- src/libs/vlayout/vlayoutpaper_p.h | 3 - src/libs/vlayout/vposition.cpp | 266 +++++++------------------- src/libs/vlayout/vposition.h | 176 ++++++++--------- 6 files changed, 148 insertions(+), 343 deletions(-) diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 20e672096a26..5dcd860c974d 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -69,27 +69,4 @@ enum class BestFrom : char Rotation = 0, Combine = 1 }; - -/* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable - * 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_PIECES // Show already arranged pieces -//# 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 22710fe57e02..565b0af4dd46 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -126,13 +126,6 @@ void VLayoutGenerator::Generate() papers.clear(); state = LayoutErrors::NoError; -#ifdef LAYOUT_DEBUG - const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug"); - QDir debugDir(path); - debugDir.removeRecursively(); - debugDir.mkpath(path); -#endif - emit Start(); if (bank->Prepare()) diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 79f6fb3beb09..4ebaac0b7137 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -238,8 +238,6 @@ bool VLayoutPaper::arrangePiece(const VLayoutPiece &piece, std::atomic_bool &sto d->localRotationIncrease = d->globalRotationIncrease; } - d->frame = 0; - return AddToSheet(piece, stop); } @@ -275,14 +273,6 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) VPosition *thread = new VPosition(d->globalContour, j, piece, i, &stop, d->localRotate, d->localRotationIncrease, d->saveLength); - //Info for debug - #ifdef LAYOUT_DEBUG - thread->setPaperIndex(d->paperIndex); - thread->setFrame(d->frame); - thread->setPieceCount(d->pieces.count()); - thread->setPieces(d->pieces); - #endif - thread->setAutoDelete(false); threads.append(thread); thread_pool->start(thread); @@ -334,12 +324,6 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece } d->pieces.append(workDetail); d->globalContour.SetContour(newGContour); - -#ifdef LAYOUT_DEBUG -# ifdef SHOW_BEST - VPosition::DrawDebug(d->globalContour, workDetail, UINT_MAX, d->paperIndex, d->pieces.count(), d->pieces); -# endif -#endif } return bestResult.ValidResult(); // Do we have the best result? diff --git a/src/libs/vlayout/vlayoutpaper_p.h b/src/libs/vlayout/vlayoutpaper_p.h index 5ac253234450..ce7367945551 100644 --- a/src/libs/vlayout/vlayoutpaper_p.h +++ b/src/libs/vlayout/vlayoutpaper_p.h @@ -71,7 +71,6 @@ class VLayoutPaperData : public QSharedData : pieces(QVector()), globalContour(VContour()), paperIndex(0), - frame(0), layoutWidth(0), globalRotate(true), localRotate(true), @@ -84,7 +83,6 @@ class VLayoutPaperData : public QSharedData : pieces(QVector()), globalContour(VContour(height, width)), paperIndex(0), - frame(0), layoutWidth(0), globalRotate(true), localRotate(true), @@ -98,7 +96,6 @@ class VLayoutPaperData : public QSharedData pieces(paper.pieces), globalContour(paper.globalContour), paperIndex(paper.paperIndex), - frame(paper.frame), layoutWidth(paper.layoutWidth), globalRotate(paper.globalRotate), localRotate(paper.localRotate), diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 482d8fac861c..ccd1b93578cb 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vposition.cpp - ** @author Douglas S Caskey - ** @date Dec 11, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. if not, see . - **************************************************************************/ - -/************************************************************************ - ** - ** @file vposition.cpp - ** @author Roman Telezhynskyi - ** @date 20 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vposition.cpp +// @author Douglas S Caskey +// @date Dec 11, 2022 +// +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vposition.cpp +// @author Roman Telezhynskyi +// @date 20 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #include "vposition.h" @@ -76,20 +75,20 @@ //--------------------------------------------------------------------------------------------------------------------- VPosition::VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, bool rotate, int rotationIncrease, bool saveLength) - : QRunnable(), - bestResult(VBestSquare(gContour.GetSize(), saveLength)), - gContour(gContour), - piece(piece), - i(i), - j(j), - paperIndex(0), - frame(0), - piecesCount(0), - pieces(), - stop(stop), - rotate(rotate), - rotationIncrease(rotationIncrease), - angle_between(0) + : QRunnable() + , bestResult(VBestSquare(gContour.GetSize(), saveLength)) + , gContour(gContour) + , piece(piece) + , i(i) + , j(j) + , paperIndex(0) + , frame(0) + , piecesCount(0) + , pieces() + , stop(stop) + , rotate(rotate) + , rotationIncrease(rotationIncrease) + , angle_between(0) { if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) { @@ -111,12 +110,6 @@ void VPosition::run() int dEdge = i;// For mirror piece edge will be different if (CheckCombineEdges(workpiece, j, dEdge)) { - #ifdef LAYOUT_DEBUG - # ifdef SHOW_CANDIDATE_BEST - DrawDebug(gContour, workpiece, frame+2, paperIndex, piecesCount, pieces); - # endif - #endif - SaveCandidate(bestResult, workpiece, j, dEdge, BestFrom::Combine); } frame = frame + 3; @@ -185,97 +178,6 @@ VBestSquare VPosition::getBestResult() const return bestResult; } -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex, - int piecesCount, const QVector &pieces) -{ - 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 path; - if (contour.GetContour().isEmpty()) - { - path = DrawContour(contour.CutEmptySheetEdge()); - path.translate(biasWidth/2, biasHeight/2); - paint.drawPath(path); - } - else - { - path = DrawContour(contour.GetContour()); - path.translate(biasWidth/2, biasHeight/2); - paint.drawPath(path); - } - -#ifdef SHOW_CANDIDATE - paint.setPen(QPen(Qt::darkGreen, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); - path = DrawContour(piece.getLayoutAllowancePoints()); - path.translate(biasWidth/2, biasHeight/2); - paint.drawPath(path); -#else - Q_UNUSED(piece) - Q_UNUSED(pieces) -#endif - -#ifdef ARRANGED_PIECES - paint.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); - path = drawPieces(pieces); - path.translate(biasWidth/2, biasHeight/2); - paint.drawPath(path); -#else - Q_UNUSED(pieces) -#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. - 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 fileName = QDir::homePath()+QStringLiteral("/LayoutDebug/")+QString("%1_%2_%3.png").arg(paperIndex) - .arg(piecesCount).arg(frame); - frameImage.save (fileName); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VPosition::Bias(int length, int maxLength) -{ - if (length < maxLength && length*2 < maxLength) - { - return length; - } - else - { - return maxLength-length; - } -} - //--------------------------------------------------------------------------------------------------------------------- void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type) @@ -295,12 +197,6 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge) CombineEdges(piece, globalEdge, dEdge); -#ifdef LAYOUT_DEBUG -# ifdef SHOW_COMBINE - DrawDebug(gContour, piece, frame, paperIndex, piecesCount, pieces); -# endif -#endif - CrossingType type = CrossingType::Intersection; if (SheetContains(piece.pieceBoundingRect())) { @@ -331,12 +227,6 @@ bool VPosition::CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge) if (flagMirror && not piece.IsForbidFlipping()) { - #ifdef LAYOUT_DEBUG - #ifdef SHOW_MIRROR - DrawDebug(gContour, piece, frame+1, paperIndex, piecesCount, pieces); - #endif - #endif - if (gContour.GetContour().isEmpty()) { dEdge = piece.pieceEdgeByPoint(globalEdge.p2()); @@ -382,12 +272,6 @@ bool VPosition::CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int an RotateEdges(piece, globalEdge, dEdge, angle); -#ifdef LAYOUT_DEBUG - #ifdef SHOW_ROTATION - DrawDebug(gContour, piece, frame, paperIndex, piecesCount, pieces); - #endif -#endif - CrossingType type = CrossingType::Intersection; if (SheetContains(piece.pieceBoundingRect())) { @@ -511,16 +395,8 @@ void VPosition::Rotate(int increase) if (CheckRotationEdges(workpiece, j, i, angle)) { - #ifdef LAYOUT_DEBUG - # ifdef SHOW_CANDIDATE_BEST - ++frame; - DrawDebug(gContour, workpiece, frame, paperIndex, piecesCount, pieces); - # endif - #endif - SaveCandidate(bestResult, workpiece, j, i, BestFrom::Rotation); } - ++frame; } } @@ -565,20 +441,6 @@ QPainterPath VPosition::DrawContour(const QVector &points) 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; } diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index 8f5a7f962b55..59531d110fb1 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vposition.h - ** @author Douglas S Caskey - ** @date Dec 11, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. if not, see . - **************************************************************************/ - -/************************************************************************ - ** - ** @file vposition.h - ** @author Roman Telezhynskyi - ** @date 20 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vposition.h +// @author Douglas S Caskey +// @date Dec 11, 2022 +// +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vposition.h +// @author Roman Telezhynskyi +// @date 20 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #ifndef VPOSITION_H #define VPOSITION_H @@ -67,46 +66,41 @@ class VPosition : public QRunnable { public: - VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, bool rotate, - int rotationIncrease, bool saveLength); - virtual ~VPosition() Q_DECL_OVERRIDE{} - - quint32 getPaperIndex() const; - void setPaperIndex(const quint32 &value); - - quint32 getFrame() const; - void setFrame(const quint32 &value); + VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, + std::atomic_bool *stop, bool rotate, int rotationIncrease, bool saveLength); + virtual ~VPosition() Q_DECL_OVERRIDE{} + virtual void run() Q_DECL_OVERRIDE; - quint32 getPieceCount() const; - void setPieceCount(const quint32 &value); + quint32 getPaperIndex() const; + void setPaperIndex(const quint32 &value); - void setPieces(const QVector &pieces); + quint32 getFrame() const; + void setFrame(const quint32 &value); - VBestSquare getBestResult() const; + quint32 getPieceCount() const; + void setPieceCount(const quint32 &value); - static void DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex, - int piecesCount, const QVector &pieces = QVector()); + void setPieces(const QVector &pieces); - static int Bias(int length, int maxLength); + VBestSquare getBestResult() const; private: Q_DISABLE_COPY(VPosition) - VBestSquare bestResult; - const VContour gContour; - const VLayoutPiece piece; - int i; - int j; - quint32 paperIndex; - quint32 frame; - quint32 piecesCount; + VBestSquare bestResult; + const VContour gContour; + const VLayoutPiece piece; + int i; + int j; + quint32 paperIndex; + quint32 frame; + quint32 piecesCount; QVector pieces; - std::atomic_bool *stop; - bool rotate; - int rotationIncrease; - /** - * @brief angle_between keep angle between global edge and piece edge. Need for optimization rotation. - */ - qreal angle_between; + std::atomic_bool *stop; + bool rotate; + int rotationIncrease; + + /// @brief angle_between keep angle between global edge and piece edge. Need for optimization rotation. + qreal angle_between; enum class CrossingType : char { @@ -122,24 +116,22 @@ class VPosition : public QRunnable EdgeError = 2 }; - virtual void run() Q_DECL_OVERRIDE; - - void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type); + void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type); - bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge); - bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const; + bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge); + bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const; - CrossingType Crossing(const VLayoutPiece &piece) const; - bool SheetContains(const QRectF &rect) const; + CrossingType Crossing(const VLayoutPiece &piece) const; + bool SheetContains(const QRectF &rect) const; - void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge); - void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const; + void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge); + void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const; static QPainterPath ShowDirection(const QLineF &edge); static QPainterPath DrawContour(const QVector &points); static QPainterPath drawPieces(const QVector &pieces); - void Rotate(int increase); + void Rotate(int increase); }; #endif // VPOSITION_H From 8d78dc0097bbed90667a342b6568333db3468e37 Mon Sep 17 00:00:00 2001 From: DSCaskey <31944718+DSCaskey@users.noreply.github.com> Date: Mon, 25 Nov 2024 08:33:09 -0500 Subject: [PATCH 2/2] more cleaning and comments --- src/app/seamly2d/core/vcmdexport.cpp | 2 +- .../dialogs/layoutsettings_dialog.cpp | 28 +- .../seamly2d/dialogs/layoutsettings_dialog.h | 8 +- src/app/seamly2d/mainwindow.cpp | 2 +- src/libs/vlayout/vbank.cpp | 11 +- src/libs/vlayout/vbank.h | 69 +- src/libs/vlayout/vlayoutgenerator.cpp | 665 ++++++++++++------ src/libs/vlayout/vlayoutgenerator.h | 167 +++-- src/libs/vlayout/vlayoutpaper.cpp | 301 ++++++-- src/libs/vlayout/vlayoutpaper.h | 115 +-- src/libs/vlayout/vlayoutpaper_p.h | 178 +++-- src/libs/vlayout/vlayoutpiece.cpp | 4 +- src/libs/vlayout/vlayoutpiece.h | 4 +- src/libs/vlayout/vposition.cpp | 507 +++++++------ src/libs/vlayout/vposition.h | 74 +- src/libs/vmisc/vsettings.cpp | 22 +- src/libs/vmisc/vsettings.h | 12 +- 17 files changed, 1263 insertions(+), 906 deletions(-) diff --git a/src/app/seamly2d/core/vcmdexport.cpp b/src/app/seamly2d/core/vcmdexport.cpp index 906a8cf74394..720297db80fb 100644 --- a/src/app/seamly2d/core/vcmdexport.cpp +++ b/src/app/seamly2d/core/vcmdexport.cpp @@ -431,7 +431,7 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH)))) { - diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag)); + diag.setLayoutGap(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag)); } diag.SetAutoCrop(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CROP)))); diff --git a/src/app/seamly2d/dialogs/layoutsettings_dialog.cpp b/src/app/seamly2d/dialogs/layoutsettings_dialog.cpp index 13710cecc5ae..93f4cb3528d7 100644 --- a/src/app/seamly2d/dialogs/layoutsettings_dialog.cpp +++ b/src/app/seamly2d/dialogs/layoutsettings_dialog.cpp @@ -172,13 +172,13 @@ void LayoutSettingsDialog::SetShift(qreal value) } //--------------------------------------------------------------------------------------------------------------------- -qreal LayoutSettingsDialog::GetLayoutWidth() const +qreal LayoutSettingsDialog::getLayoutGap() const { return UnitConvertor(ui->doubleSpinBoxLayoutWidth->value(), oldLayoutUnit, Unit::Px); } //--------------------------------------------------------------------------------------------------------------------- -void LayoutSettingsDialog::SetLayoutWidth(qreal value) +void LayoutSettingsDialog::setLayoutGap(qreal value) { ui->doubleSpinBoxLayoutWidth->setValue(UnitConvertor(value, Unit::Px, LayoutUnit())); } @@ -310,13 +310,13 @@ void LayoutSettingsDialog::SetUnitePages(bool save) } //--------------------------------------------------------------------------------------------------------------------- -bool LayoutSettingsDialog::IsStripOptimization() const +bool LayoutSettingsDialog::useStripOptimization() const { return ui->groupBoxStrips->isChecked(); } //--------------------------------------------------------------------------------------------------------------------- -void LayoutSettingsDialog::SetStripOptimization(bool save) +void LayoutSettingsDialog::setStripOptimization(bool save) { ui->groupBoxStrips->setChecked(save); } @@ -578,8 +578,8 @@ void LayoutSettingsDialog::Swap(bool checked) void LayoutSettingsDialog::DialogAccepted() { SCASSERT(generator != nullptr) - generator->SetLayoutWidth(GetLayoutWidth()); - generator->SetCaseType(GetGroup()); + generator->setLayoutGap(getLayoutGap()); + generator->setCaseType(GetGroup()); generator->SetPaperHeight(GetPaperHeight()); generator->SetPaperWidth(GetPaperWidth()); generator->SetShift(static_cast(qFloor(GetShift()))); @@ -588,9 +588,9 @@ void LayoutSettingsDialog::DialogAccepted() generator->SetAutoCrop(GetAutoCrop()); generator->SetSaveLength(IsSaveLength()); generator->SetUnitePages(IsUnitePages()); - generator->SetStripOptimization(IsStripOptimization()); + generator->setStripOptimization(useStripOptimization()); generator->SetMultiplier(GetMultiplier()); - generator->SetTestAsPaths(isTextAsPaths()); + generator->setTextAsPaths(isTextAsPaths()); if (IsIgnoreAllFields()) { @@ -671,7 +671,7 @@ void LayoutSettingsDialog::RestoreDefaults() InitPrinter(); ui->comboBoxPrinter->blockSignals(false); - SetLayoutWidth(VSettings::GetDefLayoutWidth()); + setLayoutGap(VSettings::getDefLayoutGap()); SetShift(VSettings::GetDefLayoutShift()); SetGroup(VSettings::GetDefLayoutGroup()); SetRotate(VSettings::GetDefLayoutRotate()); @@ -955,7 +955,7 @@ void LayoutSettingsDialog::MinimumLayoutSize() void LayoutSettingsDialog::ReadSettings() { const VSettings *settings = qApp->Seamly2DSettings(); - SetLayoutWidth(settings->GetLayoutWidth()); + setLayoutGap(settings->getLayoutGap()); SetShift(settings->GetLayoutShift()); const qreal width = UnitConvertor(settings->GetLayoutPaperWidth(), Unit::Px, LayoutUnit()); @@ -969,7 +969,7 @@ void LayoutSettingsDialog::ReadSettings() SetUnitePages(settings->GetLayoutUnitePages()); SetFields(settings->GetFields(GetDefPrinterFields())); SetIgnoreAllFields(settings->GetIgnoreAllFields()); - SetStripOptimization(settings->GetStripOptimization()); + setStripOptimization(settings->useStripOptimization()); SetMultiplier(settings->GetMultiplier()); setTextAsPaths(settings->GetTextAsPaths()); @@ -983,7 +983,7 @@ void LayoutSettingsDialog::ReadSettings() void LayoutSettingsDialog::WriteSettings() const { VSettings *settings = qApp->Seamly2DSettings(); - settings->SetLayoutWidth(GetLayoutWidth()); + settings->setLayoutGap(getLayoutGap()); settings->SetLayoutGroup(GetGroup()); settings->SetLayoutPaperHeight(GetPaperHeight()); settings->SetLayoutPaperWidth(GetPaperWidth()); @@ -995,7 +995,7 @@ void LayoutSettingsDialog::WriteSettings() const settings->SetLayoutUnitePages(IsUnitePages()); settings->SetFields(GetFields()); settings->SetIgnoreAllFields(IsIgnoreAllFields()); - settings->SetStripOptimization(IsStripOptimization()); + settings->setStripOptimization(useStripOptimization()); settings->SetMultiplier(GetMultiplier()); settings->setTextAsPaths(isTextAsPaths()); } @@ -1020,5 +1020,5 @@ void LayoutSettingsDialog::SetAdditionalOptions(bool value) SetAutoCrop(value); SetSaveLength(value); SetUnitePages(value); - SetStripOptimization(value); + setStripOptimization(value); } diff --git a/src/app/seamly2d/dialogs/layoutsettings_dialog.h b/src/app/seamly2d/dialogs/layoutsettings_dialog.h index 48f22a60f495..7ceb1f31800c 100644 --- a/src/app/seamly2d/dialogs/layoutsettings_dialog.h +++ b/src/app/seamly2d/dialogs/layoutsettings_dialog.h @@ -80,8 +80,8 @@ class LayoutSettingsDialog : public AbstractLayoutDialog qreal GetShift() const; void SetShift(qreal value); - qreal GetLayoutWidth() const; - void SetLayoutWidth(qreal value); + qreal getLayoutGap() const; + void setLayoutGap(qreal value); QMarginsF GetFields() const; void SetFields(const QMarginsF &value); @@ -104,8 +104,8 @@ class LayoutSettingsDialog : public AbstractLayoutDialog bool IsUnitePages() const; void SetUnitePages(bool save); - bool IsStripOptimization() const; - void SetStripOptimization(bool save); + bool useStripOptimization() const; + void setStripOptimization(bool save); quint8 GetMultiplier() const; void SetMultiplier(const quint8 &value); diff --git a/src/app/seamly2d/mainwindow.cpp b/src/app/seamly2d/mainwindow.cpp index 4ae387554db0..c1e40fc69001 100644 --- a/src/app/seamly2d/mainwindow.cpp +++ b/src/app/seamly2d/mainwindow.cpp @@ -7243,7 +7243,7 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) else { auto settings = expParams->DefaultGenerator(); - settings->SetTestAsPaths(expParams->isTextAsPaths()); + settings->setTextAsPaths(expParams->isTextAsPaths()); if (LayoutSettings(*settings.get())) { diff --git a/src/libs/vlayout/vbank.cpp b/src/libs/vlayout/vbank.cpp index e6423f5814b1..16248853020f 100644 --- a/src/libs/vlayout/vbank.cpp +++ b/src/libs/vlayout/vbank.cpp @@ -83,17 +83,18 @@ VBank::VBank() , small(QHash()) , layoutWidth(0) , caseType(Cases::CaseDesc) - , prepare(false), diagonal(0) + , prepare(false) + , diagonal(0) {} //--------------------------------------------------------------------------------------------------------------------- -qreal VBank::GetLayoutWidth() const +qreal VBank::getLayoutGap() const { return layoutWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VBank::SetLayoutWidth(const qreal &value) +void VBank::setLayoutGap(const qreal &value) { layoutWidth = value; Reset(); @@ -217,7 +218,7 @@ bool VBank::Prepare() diagonal = 0; for (int i=0; i < pieces.size(); ++i) { - pieces[i].SetLayoutWidth(layoutWidth); + pieces[i].setLayoutGap(layoutWidth); pieces[i].SetLayoutAllowancePoints(); const qreal d = pieces.at(i).Diagonal(); @@ -254,7 +255,7 @@ void VBank::Reset() } //--------------------------------------------------------------------------------------------------------------------- -void VBank::SetCaseType(Cases caseType) +void VBank::setCaseType(Cases caseType) { this->caseType = caseType; } diff --git a/src/libs/vlayout/vbank.h b/src/libs/vlayout/vbank.h index b71363cba3c9..2e98cd00b42e 100644 --- a/src/libs/vlayout/vbank.h +++ b/src/libs/vlayout/vbank.h @@ -75,52 +75,49 @@ class VBank public: VBank(); - qreal GetLayoutWidth() const; - void SetLayoutWidth(const qreal &value); + qreal getLayoutGap() const; + void setLayoutGap(const qreal &value); - void setPieces(const QVector &pieces); - int GetTiket(); + void setPieces(const QVector &pieces); + int GetTiket(); VLayoutPiece getPiece(int i) const; - void Arranged(int i); - void NotArranged(int i); + void Arranged(int i); + void NotArranged(int i); - bool Prepare(); - void Reset(); - void SetCaseType(Cases caseType); + bool Prepare(); + void Reset(); + void setCaseType(Cases caseType); - int allPieceCount() const; - int LeftArrange() const; - int ArrangedCount() const; + int allPieceCount() const; + int LeftArrange() const; + int ArrangedCount() const; - qreal GetBiggestDiagonal() const; + qreal GetBiggestDiagonal() const; private: Q_DISABLE_COPY(VBank) QVector pieces; - QHash unsorted; - - QHash big; - QHash middle; - QHash small; - - qreal layoutWidth; - - Cases caseType; - bool prepare; - qreal diagonal; - - void PrepareGroup(); - - void PrepareThreeGroups(); - void PrepareTwoGroups(); - void PrepareDescGroup(); - - int GetNextThreeGroups() const; - int GetNextTwoGroups() const; - int GetNextDescGroup() const; - - void SqMaxMin(qint64 &sMax, qint64 &sMin) const; + QHash unsorted; + QHash big; + QHash middle; + QHash small; + qreal layoutWidth; + Cases caseType; + bool prepare; + qreal diagonal; + + void PrepareGroup(); + + void PrepareThreeGroups(); + void PrepareTwoGroups(); + void PrepareDescGroup(); + + int GetNextThreeGroups() const; + int GetNextTwoGroups() const; + int GetNextDescGroup() const; + + void SqMaxMin(qint64 &sMax, qint64 &sMin) const; }; #if defined (Q_OS_WIN) && defined (Q_CC_MSVC) diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 565b0af4dd46..56ec769c2a84 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -1,53 +1,53 @@ -/*************************************************************************** - * * - * Copyright (C) 2017 Seamly, LLC * - * * - * https://github.com/fashionfreedom/seamly2d * - * * - *************************************************************************** - ** - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - ** - ************************************************************************** - - ************************************************************************ - ** - ** @file vlayoutgenerator.cpp - ** @author Roman Telezhynskyi - ** @date 2 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Seamly2D project - ** All Rights Reserved. - ** - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vlayoutgenerator.cpp +// @author Douglas S Caskey +// @date Nov 28, 2024 +// +// @copyright +// Copyright (C) 2017 - 2024 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vlayoutgenerator.cpp +// @author Roman Telezhynskyi +// @date 2 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #include "vlayoutgenerator.h" @@ -62,322 +62,454 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) - : QObject(parent), - papers(), - bank(new VBank()), - paperHeight(0), - paperWidth(0), - margins(), - usePrinterFields(true), -#ifdef Q_CC_MSVC - // See https://stackoverflow.com/questions/15750917/initializing-stdatomic-bool - stopGeneration(ATOMIC_VAR_INIT(false)), -#else - stopGeneration(false), -#endif - state(LayoutErrors::NoError), - shift(0), - rotate(true), - rotationIncrease(180), - autoCrop(false), - saveLength(false), - unitePages(false), - stripOptimizationEnabled(false), - multiplier(1), - stripOptimization(false), - textAsPaths(false) + : QObject(parent) + , m_papers() + , m_bank(new VBank()) + , m_paperHeight(0) + , m_paperWidth(0) + , m_margins() + , m_usePrinterFields(true) + , m_stopGeneration(false) + , m_state(LayoutErrors::NoError) + , m_shift(0) + , m_rotate(true) + , m_rotationIncrement(180) + , m_autoCrop(false) + , m_saveLength(false) + , m_unitePages(false) + , m_stripOptimized(false) + , m_multiplier(1) + , m_useStripOptimization(false) + , m_textAsPaths(false) {} +//--------------------------------------------------------------------------------------------------------------------- +/// Destroys this VLayoutGenerator. //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::~VLayoutGenerator() { - delete bank; + delete m_bank; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief setPieces sets the bank pieces. +/// +/// This method sets the bank to the vector of layout pieces. +/// +/// @param pieces vector of layout pieces. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::setPieces(const QVector &pieces) { - bank->setPieces(pieces); + m_bank->setPieces(pieces); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetLayoutWidth(qreal width) +/// @brief setLayoutGap sets layout gap width. +/// +/// This method sets the width of the gap layout. +/// +/// @param width width of gap. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::setLayoutGap(qreal width) { - bank->SetLayoutWidth(width); + m_bank->setLayoutGap(width); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetCaseType(Cases caseType) +/// @brief setCaseType sets the case type. +/// +/// This method sets the case type for choosing the next workpiece +/// as set in the layout settings dialog. +/// +/// @param caseType +/// - Three groups: big, middle, small. +/// - Two groups: big, small. +/// - Descending area. +/// @returns void +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::setCaseType(Cases caseType) { - bank->SetCaseType(caseType); + m_bank->setCaseType(caseType); } //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction int VLayoutGenerator::PieceCount() { - return bank->allPieceCount(); + return m_bank->allPieceCount(); } - +//--------------------------------------------------------------------------------------------------------------------- +/// @brief Generate generate layout. +/// +/// This method generates the pattern layout. +/// +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::Generate() { - stopGeneration.store(false); - papers.clear(); - state = LayoutErrors::NoError; + m_stopGeneration.store(false); + m_papers.clear(); + m_state = LayoutErrors::NoError; emit Start(); - if (bank->Prepare()) + if (m_bank->Prepare()) { - const int width = PageWidth(); - int height = PageHeight(); + const int width = pageWidth(); + int height = pageHeight(); - if (stripOptimization) + if (m_useStripOptimization) { - const qreal b = bank->GetBiggestDiagonal() * multiplier + bank->GetLayoutWidth(); + const qreal b = m_bank->GetBiggestDiagonal() * m_multiplier + m_bank->getLayoutGap(); if (height >= b*2) { - stripOptimizationEnabled = true; + m_stripOptimized = true; height = qFloor(height / qFloor(height/b)); } } - while (bank->allPieceCount() > 0) + while (m_bank->allPieceCount() > 0) { - if (stopGeneration.load()) + if (m_stopGeneration.load()) { break; } VLayoutPaper paper(height, width); - paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); - paper.SetPaperIndex(static_cast(papers.count())); - paper.SetRotate(rotate); - paper.SetRotationIncrease(rotationIncrease); - paper.SetSaveLength(saveLength); + paper.SetShift(m_shift); + paper.setLayoutGap(m_bank->getLayoutGap()); + paper.setPaperIndex(static_cast(m_papers.count())); + paper.SetRotate(m_rotate); + paper.SetRotationIncrease(m_rotationIncrement); + paper.SetSaveLength(m_saveLength); do { - const int index = bank->GetTiket(); - if (paper.arrangePiece(bank->getPiece(index), stopGeneration)) + const int index = m_bank->GetTiket(); + if (paper.arrangePiece(m_bank->getPiece(index), m_stopGeneration)) { - bank->Arranged(index); - emit Arranged(bank->ArrangedCount()); + m_bank->Arranged(index); + emit Arranged(m_bank->ArrangedCount()); } else { - bank->NotArranged(index); + m_bank->NotArranged(index); } - if (stopGeneration.load()) + if (m_stopGeneration.load()) { break; } - } while(bank->LeftArrange() > 0); + } while(m_bank->LeftArrange() > 0); - if (stopGeneration.load()) + if (m_stopGeneration.load()) { break; } if (paper.Count() > 0) { - papers.append(paper); + m_papers.append(paper); } else { - state = LayoutErrors::EmptyPaperError; - emit Error(state); + m_state = LayoutErrors::EmptyPaperError; + emit Error(m_state); return; } } } else { - state = LayoutErrors::PrepareLayoutError; - emit Error(state); + m_state = LayoutErrors::PrepareLayoutError; + emit Error(m_state); return; } - if (stripOptimizationEnabled) + if (m_stripOptimized) { - GatherPages(); + gatherPages(); } if (IsUnitePages()) { - UnitePages(); + unitePages(); } emit Finished(); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief State gets the error state. +/// +/// This method returns any layout generator errors. +/// +/// @returns m_state Could be one one the following: +/// - NoError +/// - PrepareLayoutError +/// - ProcessStoped +/// - EmptyPaperError //--------------------------------------------------------------------------------------------------------------------- LayoutErrors VLayoutGenerator::State() const { - return state; + return m_state; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetPapersItems gets a list of paper items. +/// +/// This method converts a vector of layout papers (pages) and returns a list of QGraphicItems. +/// +/// @returns list. //--------------------------------------------------------------------------------------------------------------------- QList VLayoutGenerator::GetPapersItems() const { QList list; - for (int i=0; i < papers.count(); ++i) + for (int i=0; i < m_papers.count(); ++i) { - list.append(papers.at(i).GetPaperItem(autoCrop, IsTestAsPaths())); + list.append(m_papers.at(i).getPaperItem(m_autoCrop, isTextAsPaths())); } return list; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief getAllPieceItems gets a list of all piece items. +/// +/// This method get all the piece item on the layout papers (pages). +/// +/// @Details If the item is a text item and isTextAsPaths is true, +/// text item is convetd to a path. +/// +/// @returns list QGraphicsItem of layout pieces. //--------------------------------------------------------------------------------------------------------------------- QList > VLayoutGenerator::getAllPieceItems() const { QList > list; - for (int i=0; i < papers.count(); ++i) + for (int i=0; i < m_papers.count(); ++i) { - list.append(papers.at(i).getPieceItems(IsTestAsPaths())); + list.append(m_papers.at(i).getPieceItems(isTextAsPaths())); } return list; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief getAllPieces gets a list of all pieces. +/// +/// This method get all the pieces on the layout papers (pages). +/// +/// @returns list Qvector of layout pieces. //--------------------------------------------------------------------------------------------------------------------- QVector > VLayoutGenerator::getAllPieces() const { QVector > list; - for (int i=0; i < papers.count(); ++i) + for (int i=0; i < m_papers.count(); ++i) { - list.append(papers.at(i).getPieces()); + list.append(m_papers.at(i).getPieces()); } return list; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief Abort abort layout generation. +/// +/// This method aborts the layout generation. +/// +/// @returns void //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::Abort() { - stopGeneration.store(true); - state = LayoutErrors::ProcessStoped; + m_stopGeneration.store(true); + m_state = LayoutErrors::ProcessStoped; QThreadPool::globalInstance()->clear(); } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutGenerator::IsStripOptimization() const +/// @brief useStripOptimization gets whether to use strip optimization. +/// +/// This method gets whether to use strip optimization when uniting pages. +/// +/// @returns m_useStripOptimization +/// - true if optimization should be used when uniting pages. +/// - false if otherwise. +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutGenerator::useStripOptimization() const { - return stripOptimization; + return m_useStripOptimization; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetStripOptimization(bool value) +/// @brief setStripOptimization sets whether to use strip optimization. +/// +/// This method sets whether to use strip optimization when uniting pages. +/// +/// @param bool value +/// - true if optimization should be used when uniting pages. +/// - false if otherwise. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::setStripOptimization(bool value) { - stripOptimization = value; + m_useStripOptimization = value; } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutGenerator::IsTestAsPaths() const +/// @brief isTextAsPaths gets whether to render text as path. +/// +/// This method gets whether text is rendered as a path. +/// +/// @returns m_unitePages true if text should be rendered as a path false if otherwise. +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutGenerator::isTextAsPaths() const { - return textAsPaths; + return m_textAsPaths; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::SetTestAsPaths(bool value) +/// @brief setTextAsPaths sets whether to render text as path. +/// +/// This method gets whether text is rendered as a path. +/// +/// @returns m_unitePages true if text should be rendered as a path false if otherwise. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::setTextAsPaths(bool value) { - textAsPaths = value; + m_textAsPaths = value; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetMultiplier gets the multipler. +/// +/// This method gets thew multipler used in the strip optimization. +/// +/// @returns m_multiplier. //--------------------------------------------------------------------------------------------------------------------- quint8 VLayoutGenerator::GetMultiplier() const { - return multiplier; + return m_multiplier; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetMultiplier sets the multipler. +/// +/// This method sets the multipler used in the strip optimization from the layout setting dialog. +/// +/// @param value from 1 to 10. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetMultiplier(const quint8 &value) { if (value > 10) { - multiplier = 10; + m_multiplier = 10; } else if (value == 0) { - multiplier = 1; + m_multiplier = 1; } else { - multiplier = value; + m_multiplier = value; } } //--------------------------------------------------------------------------------------------------------------------- -int VLayoutGenerator::PageHeight() const +/// @brief pageHeight gets the page height. +/// +/// This method gets the height of the page which equals the paper height minus +/// the top and bottom margins. +/// +/// @returns int page height. +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutGenerator::pageHeight() const { - return static_cast(paperHeight - (margins.top() + margins.bottom())); + return static_cast(m_paperHeight - (m_margins.top() + m_margins.bottom())); } //--------------------------------------------------------------------------------------------------------------------- -int VLayoutGenerator::PageWidth() const +/// @brief pageWidth gets the page width. +/// +/// This method gets the width of the page which equals the paper width minus +/// the left and right margins. +/// +/// @returns int paper width. +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutGenerator::pageWidth() const { - return static_cast(paperWidth - (margins.left() + margins.right())); + return static_cast(m_paperWidth - (m_margins.left() + m_margins.right())); } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::GatherPages() +/// @brief gatherPages Unite layout pages with optimization. +/// +/// This method unites the layout pages if there is more than 1 page with strip optimization. +/// +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::gatherPages() { - if (papers.size() < 2) + if (m_papers.size() < 2) { return; } QList> pieces; qreal length = 0; - int j = 0; // papers count + int j = 0; // m_papers count - for (int i = 0; i < papers.size(); ++i) + for (int i = 0; i < m_papers.size(); ++i) { - int paperHeight = qRound(papers.at(i).piecesBoundingRect().height()); + int m_paperHeight = qRound(m_papers.at(i).piecesBoundingRect().height()); - if (i != papers.size()-1) + if (i != m_papers.size()-1) { - paperHeight += qRound(bank->GetLayoutWidth()*2); + m_paperHeight += qRound(m_bank->getLayoutGap()*2); } - if (length + paperHeight <= PageHeight()) + if (length + m_paperHeight <= pageHeight()) { unitePieces(j, pieces, length, i); - length += paperHeight; + length += m_paperHeight; } else { length = 0; // Start new paper ++j;// New paper unitePieces(j, pieces, length, i); - length += paperHeight; + length += m_paperHeight; } } QVector nPapers; for (int i = 0; i < pieces.size(); ++i) { - VLayoutPaper paper(PageHeight(), PageWidth()); - paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); - paper.SetPaperIndex(static_cast(i)); - paper.SetRotate(rotate); - paper.SetRotationIncrease(rotationIncrease); - paper.SetSaveLength(saveLength); + VLayoutPaper paper(pageHeight(), pageWidth()); + paper.SetShift(m_shift); + paper.setLayoutGap(m_bank->getLayoutGap()); + paper.setPaperIndex(static_cast(i)); + paper.SetRotate(m_rotate); + paper.SetRotationIncrease(m_rotationIncrement); + paper.SetSaveLength(m_saveLength); paper.setPieces(pieces.at(i)); nPapers.append(paper); } - papers.clear(); - papers = nPapers; + m_papers.clear(); + m_papers = nPapers; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::UnitePages() +/// @brief unitePages Unite layout pages. +/// +/// This method unites the layout pages if there is more than 1 page. It first crops any page if +/// the autocrop is true, and then appends them 1 at a time into 1 page. +/// +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::unitePages() { - if (papers.size() < 2) + if (m_papers.size() < 2) { return; } @@ -385,30 +517,30 @@ void VLayoutGenerator::UnitePages() QList papersLength; QList > pieces; qreal length = 0; - int j = 0; // papers count + int j = 0; // m_papers count - for (int i = 0; i < papers.size(); ++i) + for (int i = 0; i < m_papers.size(); ++i) { int paperHeight = 0; - if (autoCrop) + if (m_autoCrop) { - paperHeight = qRound(papers.at(i).piecesBoundingRect().height()); + paperHeight = qRound(m_papers.at(i).piecesBoundingRect().height()); } else { - paperHeight = papers.at(i).GetHeight(); + paperHeight = m_papers.at(i).GetHeight(); } - if (i != papers.size()-1) + if (i != m_papers.size()-1) { - paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); + paperHeight = qRound(paperHeight + m_bank->getLayoutGap()*2); } if (length + paperHeight <= QIMAGE_MAX) { unitePieces(j, pieces, length, i); length += paperHeight; - UnitePapers(j, papersLength, length); + unitePapers(j, papersLength, length); } else { @@ -416,44 +548,61 @@ void VLayoutGenerator::UnitePages() ++j;// New paper unitePieces(j, pieces, length, i); length += paperHeight; - UnitePapers(j, papersLength, length); + unitePapers(j, papersLength, length); } } QVector nPapers; for (int i = 0; i < pieces.size(); ++i) { - VLayoutPaper paper(qFloor(papersLength.at(i)), PageWidth()); - paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); - paper.SetPaperIndex(static_cast(i)); - paper.SetRotate(rotate); - paper.SetRotationIncrease(rotationIncrease); - paper.SetSaveLength(saveLength); + VLayoutPaper paper(qFloor(papersLength.at(i)), pageWidth()); + paper.SetShift(m_shift); + paper.setLayoutGap(m_bank->getLayoutGap()); + paper.setPaperIndex(static_cast(i)); + paper.SetRotate(m_rotate); + paper.SetRotationIncrease(m_rotationIncrement); + paper.SetSaveLength(m_saveLength); paper.setPieces(pieces.at(i)); nPapers.append(paper); } - papers.clear(); - papers = nPapers; + m_papers.clear(); + m_papers = nPapers; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief unitePieces combines layout pieces. +/// +/// This method combines the layout pieces into one list . +/// +/// @param pieces list of layout pieces. +/// @param length length of page. +/// @param i number of page. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::unitePieces(int j, QList > &pieces, qreal length, int i) { if ((j == 0 && pieces.isEmpty()) || j >= pieces.size()) {//First or new pieces in paper - pieces.insert(j, movePieces(length, papers.at(i).getPieces())); + pieces.insert(j, movePieces(length, m_papers.at(i).getPieces())); } else { - pieces[j].append(movePieces(length, papers.at(i).getPieces())); + pieces[j].append(movePieces(length, m_papers.at(i).getPieces())); } } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::UnitePapers(int j, QList &papersLength, qreal length) +/// @brief unitePapers combines page lengths into one. +/// +/// This method combines the page lengths into one list . +/// +/// @param papersLength list of page lengths. +/// @param length length of page. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::unitePapers(int j, QList &papersLength, qreal length) { if ((j == 0 && papersLength.isEmpty()) || j >= papersLength.size()) { @@ -465,6 +614,14 @@ void VLayoutGenerator::UnitePapers(int j, QList &papersLength, qreal leng } } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief movePieces move pieces. +/// +/// This method combines the layout pieces into one list . +/// +/// @param length of page. +/// @param pieces vector of all the layout pieces. +/// @returns newPieces. Combined list of layout pieces from all the pages. //--------------------------------------------------------------------------------------------------------------------- QList VLayoutGenerator::movePieces(qreal length, const QVector &pieces) { @@ -484,123 +641,223 @@ QList VLayoutGenerator::movePieces(qreal length, const QVector= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) + if ((m_rotationIncrement >= 1 && m_rotationIncrement <= 180 && 360 % m_rotationIncrement == 0) == false) { - rotationIncrease = 180; + m_rotationIncrement = 180; } } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetRotate gets whether the paper should rotate. +/// +/// This method gets whether to rotate the paper. +/// +/// @returns true if the paper should be rotated, false otherwise. //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::GetRotate() const { - return rotate; + return m_rotate; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetRotate sets whether the paper should rotate. +/// +/// This method sets whether to rotate the paper. +/// +/// @param value true if the paper should be rotated, false otherwise. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetRotate(bool value) { - rotate = value; + m_rotate = value; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetPaperWidth gets the paper width. +/// +/// This method gets the width of the paper. +/// +/// @returns qreal paper width. //--------------------------------------------------------------------------------------------------------------------- qreal VLayoutGenerator::GetPaperWidth() const { - return paperWidth; + return m_paperWidth; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetPaperWidth sets layout width. +/// +/// This method sets the width of the paper. +/// +/// @param value width of paper. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetPaperWidth(qreal value) { - paperWidth = value; + m_paperWidth = value; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief IsUsePrinterFields gets whether to use the margins. +/// +/// This method gets whether to use the paper margins set in the layout dialog. +/// +/// @returns true if the layout paper should use the margins, false otherwise. //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::IsUsePrinterFields() const { - return usePrinterFields; + return m_usePrinterFields; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetPrinterFields gets the margins. +/// +/// This method gets the paper margins set in the layout dialog. +/// +/// @returns margins. //--------------------------------------------------------------------------------------------------------------------- QMarginsF VLayoutGenerator::GetPrinterFields() const { - return margins; + return m_margins; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetPrinterFields sets the paper marguins. +/// +/// This method sets whether to use the paper margins. +/// Also sets the paper margins set in the layout dialog. +/// +/// @param value paper margins. +/// @param usePrinterFields true if the layout paper should use the margins, false otherwise. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetPrinterFields(bool usePrinterFields, const QMarginsF &value) { - this->usePrinterFields = usePrinterFields; - margins = value; + m_usePrinterFields = usePrinterFields; + m_margins = value; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetShift gets the shift. +/// +/// This method gets the shift offset length that is set in the layout dialog. +/// +/// @returns shift. //--------------------------------------------------------------------------------------------------------------------- quint32 VLayoutGenerator::GetShift() const { - return shift; + return m_shift; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetShift sets the shift. +/// +/// This method sets the shift offset length that is set in the layout dialog. +/// +/// @param shift +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetShift(quint32 shift) { - this->shift = shift; + m_shift = shift; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetPaperHeight gets the paper height. +/// +/// This method gets the height of the paper. +/// +/// @returns qreal paper height. //--------------------------------------------------------------------------------------------------------------------- qreal VLayoutGenerator::GetPaperHeight() const { - return paperHeight; + return m_paperHeight; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetPaperHeight sets layout height. +/// +/// This method sets the height of the paper. +/// +/// @param value height of paper. //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::SetPaperHeight(qreal value) { - paperHeight = value; + m_paperHeight = value; } diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 2ff26cadb752..1a2433de0f6f 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vlayoutgenerator.h - ** @author Douglas S Caskey - ** @date Dec 27, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - **************************************************************************/ - -/************************************************************************ - ** - ** @file vlayoutgenerator.h - ** @author Roman Telezhynskyi - ** @date 2 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vlayoutgenerator.cpp +// @author Douglas S Caskey +// @date Nov 28, 2024 +// +// @copyright +// Copyright (C) 2017 - 2024 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vlayoutgenerator.cpp +// @author Roman Telezhynskyi +// @date 2 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #ifndef VLAYOUTGENERATOR_H #define VLAYOUTGENERATOR_H @@ -79,8 +78,8 @@ class VLayoutGenerator :public QObject virtual ~VLayoutGenerator() Q_DECL_OVERRIDE; void setPieces(const QVector &details); - void SetLayoutWidth(qreal width); - void SetCaseType(Cases caseType); + void setLayoutGap(qreal width); + void setCaseType(Cases caseType); int PieceCount(); qreal GetPaperHeight() const; @@ -123,11 +122,11 @@ class VLayoutGenerator :public QObject quint8 GetMultiplier() const; void SetMultiplier(const quint8 &value); - bool IsStripOptimization() const; - void SetStripOptimization(bool value); + bool useStripOptimization() const; + void setStripOptimization(bool value); - bool IsTestAsPaths() const; - void SetTestAsPaths(bool value); + bool isTextAsPaths() const; + void setTextAsPaths(bool value); signals: void Start(); @@ -140,33 +139,33 @@ public slots: private: Q_DISABLE_COPY(VLayoutGenerator) - QVector papers; - VBank *bank; - qreal paperHeight; - qreal paperWidth; - QMarginsF margins; - bool usePrinterFields; - std::atomic_bool stopGeneration; - LayoutErrors state; - quint32 shift; - bool rotate; - int rotationIncrease; - bool autoCrop; - bool saveLength; - bool unitePages; - bool stripOptimizationEnabled; - quint8 multiplier; - bool stripOptimization; - bool textAsPaths; - - int PageHeight() const; - int PageWidth() const; - - void GatherPages(); - void UnitePages(); - void unitePieces(int j, QList > &pieces, qreal length, int i); - void UnitePapers(int j, QList &papersLength, qreal length); - QList movePieces(qreal length, const QVector &pieces); + QVector m_papers; + VBank *m_bank; + qreal m_paperHeight; + qreal m_paperWidth; + QMarginsF m_margins; + bool m_usePrinterFields; + std::atomic_bool m_stopGeneration; + LayoutErrors m_state; + quint32 m_shift; + bool m_rotate; + int m_rotationIncrement; + bool m_autoCrop; + bool m_saveLength; + bool m_unitePages; + bool m_stripOptimized; + quint8 m_multiplier; + bool m_useStripOptimization; + bool m_textAsPaths; + + int pageHeight() const; + int pageWidth() const; + + void gatherPages(); + void unitePages(); + void unitePieces(int j, QList > &pieces, qreal length, int i); + void unitePapers(int j, QList &papersLength, qreal length); + QList movePieces(qreal length, const QVector &pieces); }; #endif // VLAYOUTGENERATOR_H diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 4ebaac0b7137..d67b09c992a2 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vlayoutpaper.cpp - ** @author Douglas S Caskey - ** @date Dec 27, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - **************************************************************************/ - -/************************************************************************ - ** - ** @file vlayoutpaper.cpp - ** @author Roman Telezhynskyi - ** @date 7 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vposition.cpp +// @author Douglas S Caskey +// @date Dec 27, 2022 +// +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vposition.cpp +// @author Roman Telezhynskyi +// @date 7 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #include "vlayoutpaper.h" @@ -74,7 +73,11 @@ #include "vposition.h" #ifdef Q_COMPILER_RVALUE_REFS -VLayoutPaper &VLayoutPaper::operator=(VLayoutPaper &&paper) Q_DECL_NOTHROW { Swap(paper); return *this; } +VLayoutPaper &VLayoutPaper::operator=(VLayoutPaper &&paper) Q_DECL_NOTHROW +{ + Swap(paper); + return *this; +} #endif void VLayoutPaper::Swap(VLayoutPaper &paper) Q_DECL_NOTHROW @@ -82,23 +85,25 @@ void VLayoutPaper::Swap(VLayoutPaper &paper) Q_DECL_NOTHROW //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper::VLayoutPaper() - :d(new VLayoutPaperData) + : d(new VLayoutPaperData) {} //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper::VLayoutPaper(int height, int width) - :d(new VLayoutPaperData(height, width)) + : d(new VLayoutPaperData(height, width)) {} //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper::VLayoutPaper(const VLayoutPaper &paper) - :d (paper.d) + : d(paper.d) {} +//--------------------------------------------------------------------------------------------------------------------- +/// Assigns paper to this paper and returns a reference to this. //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper &VLayoutPaper::operator=(const VLayoutPaper &paper) { - if ( &paper == this ) + if (&paper == this) { return *this; } @@ -106,28 +111,56 @@ VLayoutPaper &VLayoutPaper::operator=(const VLayoutPaper &paper) return *this; } +//--------------------------------------------------------------------------------------------------------------------- +/// Destroys this VLayoutPaper. //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper::~VLayoutPaper() {} +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetHeight gets the height of the paper. +/// +/// This method gets the height of the paper. +/// +/// @returns int height of paper. //--------------------------------------------------------------------------------------------------------------------- int VLayoutPaper::GetHeight() const { return d->globalContour.GetHeight(); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief setHeight sets the height of the paper. +/// +/// This method sets the height of the paper. +/// +/// @param height of paper. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::setHeight(int height) { d->globalContour.setHeight(height); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetHeight sets the height of the paper. +/// +/// This method sets the height of the paper. +/// +/// @returns int height of paper. //--------------------------------------------------------------------------------------------------------------------- int VLayoutPaper::GetWidth() const { return d->globalContour.GetWidth(); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief setHeight sets the width of the paper. +/// +/// This method sets the width of the paper. +/// +/// @param width of paper. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetWidth(int width) { @@ -135,13 +168,26 @@ void VLayoutPaper::SetWidth(int width) } //--------------------------------------------------------------------------------------------------------------------- -qreal VLayoutPaper::GetLayoutWidth() const +/// @brief getLayoutGap gets the gap width of the layout. +/// +/// This method gets the ga width of the layout. +/// +/// @returns qreal width of gap. +//--------------------------------------------------------------------------------------------------------------------- +qreal VLayoutPaper::getLayoutGap() const { return d->layoutWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPaper::SetLayoutWidth(qreal width) +/// @brief setLayoutGap sets the gap width of the layout. +/// +/// This method sets the gap width of the layout. +/// +/// @param width of gap. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPaper::setLayoutGap(qreal width) { if (width >= 0) { @@ -149,24 +195,54 @@ void VLayoutPaper::SetLayoutWidth(qreal width) } } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetShift gets the shift of the paper. +/// +/// This method gets the shift length of the paper as set in the layout settings dialog. +/// +/// @returns quint32 shift length. //--------------------------------------------------------------------------------------------------------------------- quint32 VLayoutPaper::GetShift() const { return d->globalContour.GetShift(); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetShift sets the shift of the paper. +/// +/// This method sets the shift of the paper. +/// +/// @param shift of the paper. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetShift(quint32 shift) { d->globalContour.SetShift(shift); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetRotate gets the paper rotation. +/// +/// This method gets whether the paper is rotated i.e. it's orientation. +/// +/// @returns bool. +/// - true paper is rotated. (landscape) +/// - false paper is not rotated. (portrait) //--------------------------------------------------------------------------------------------------------------------- bool VLayoutPaper::GetRotate() const { return d->globalRotate; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetRotate sets the paper is rotated. +/// +/// This method sets whether the paper is rotated i.e. the orientation. +/// +/// @param value +/// - true paper is rotated. (landscape) +/// - false paper is not rotated. (portrait) +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetRotate(bool value) { @@ -174,12 +250,25 @@ void VLayoutPaper::SetRotate(bool value) d->localRotate = d->globalRotate; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief GetRotationIncrease gets the rotation increment. +/// +/// This method gets the rotation increment. +/// +/// @returns int rotation increment. //--------------------------------------------------------------------------------------------------------------------- int VLayoutPaper::GetRotationIncrease() const { return d->globalRotationIncrease; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetRotationIncrease sets the rotation increment. +/// +/// This method sets the rotation increment. +/// +/// @param value rotation increment. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetRotationIncrease(int value) { @@ -195,12 +284,29 @@ void VLayoutPaper::SetRotationIncrease(int value) d->localRotationIncrease = d->globalRotationIncrease; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief IsSaveLength gets savelength of the layout. +/// +/// This method gets whether to save the length of the layout. +/// +/// @returns bool. +/// - true save length. +/// - false don't save length. //--------------------------------------------------------------------------------------------------------------------- bool VLayoutPaper::IsSaveLength() const { return d->saveLength; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief SetSaveLength sets savelength of the layout. +/// +/// This method sets whether to save the length of the layout. +/// +/// @param value. +/// - true save length. +/// - false don't save length. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetSaveLength(bool value) { @@ -208,7 +314,14 @@ void VLayoutPaper::SetSaveLength(bool value) } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPaper::SetPaperIndex(quint32 index) +/// @brief setPaperIndex sets the paper index. +/// +/// This method sets the paper index. +/// +/// @param index paper index. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPaper::setPaperIndex(quint32 index) { d->paperIndex = index; } @@ -227,7 +340,7 @@ bool VLayoutPaper::arrangePiece(const VLayoutPiece &piece, std::atomic_bool &sto return false;//Not enough edges } - if (piece.IsForbidFlipping() && not d->globalRotate) + if (piece.IsForbidFlipping() && !d->globalRotate) { // Compensate forbidden flipping by rotating. 180 degree will be enough. d->localRotate = true; d->localRotationIncrease = 180; @@ -238,9 +351,15 @@ bool VLayoutPaper::arrangePiece(const VLayoutPiece &piece, std::atomic_bool &sto d->localRotationIncrease = d->globalRotationIncrease; } - return AddToSheet(piece, stop); + return addToSheet(piece, stop); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief Count returns the number of piece. +/// +/// This method returns number of pieces used in the layout. +/// +/// @returns int count. //--------------------------------------------------------------------------------------------------------------------- int VLayoutPaper::Count() const { @@ -248,7 +367,15 @@ int VLayoutPaper::Count() const } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutPaper::AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) +/// @brief addToSheet add piece to layout page. +/// +/// This method adds a piece to a layout page. +/// +/// @param piece piece being added to page. +/// @param stop shared bool between threads. +/// @returns bool true if valid result, false if invalid result. +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutPaper::addToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) { VBestSquare bestResult(d->globalContour.GetSize(), d->saveLength); QThreadPool *thread_pool = QThreadPool::globalInstance(); @@ -276,8 +403,6 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) thread->setAutoDelete(false); threads.append(thread); thread_pool->start(thread); - - d->frame = d->frame + 3 + static_cast(360/d->localRotationIncrease*2); } } @@ -287,7 +412,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) QCoreApplication::processEvents(); QThread::msleep(250); } - while(thread_pool->activeThreadCount() > 0 && not stop.load()); + while(thread_pool->activeThreadCount() > 0 && !stop.load()); if (stop.load()) { @@ -304,11 +429,11 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop) qDeleteAll(threads.begin(), threads.end()); threads.clear(); - return SaveResult(bestResult, piece); + return saveResult(bestResult, piece); } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece &piece) +bool VLayoutPaper::saveResult(const VBestSquare &bestResult, const VLayoutPiece &piece) { if (bestResult.ValidResult()) { @@ -330,7 +455,15 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) const +/// @brief getPaperItem returns paper an item. +/// +/// This method returns a paper (page) as a QGraphicsRectItem. +/// +/// @param autoCrop If true autocrop the page, if false otherwise. +/// @param textAsPaths If true append text as a path, if false otherwise. +/// @returns paper. +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsRectItem *VLayoutPaper::getPaperItem(bool autoCrop, bool textAsPaths) const { QGraphicsRectItem *paper; if (autoCrop) @@ -360,6 +493,13 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) c return paper; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief getPieceItems returns the piece items in the layout. +/// +/// This method returns list of pieces used in the layout as graphicitems. +/// +/// @param textAsPaths if true append text as path, if false otherwise. +/// @returns QList VLayoutPaper::getPieceItems(bool textAsPaths) const { @@ -371,26 +511,45 @@ QList VLayoutPaper::getPieceItems(bool textAsPaths) const return list; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief getPieces returns the pieces in the layout. +/// +/// This method returns a vector of pieces used in the layout. +/// +/// @returns QVector. //--------------------------------------------------------------------------------------------------------------------- QVector VLayoutPaper::getPieces() const { return d->pieces; } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief setPieces sets the pieces in the layout. +/// +/// This method converts and sets a vector from list of pieces used in the layout. +/// +/// @param pieces list of layout pieces. +/// @returns void. //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::setPieces(const QList &pieces) { d->pieces = pieces.toVector(); } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief piecesBoundingRect returns the bounding rect of pieces. +/// +/// This method returns bounding rect of all the pieces used in the layout. +/// +/// @returns QRectF bounding rect of pieces. //--------------------------------------------------------------------------------------------------------------------- QRectF VLayoutPaper::piecesBoundingRect() const { - QRectF rec; + QRectF rect; for (int i=0; i < d->pieces.count(); ++i) { - rec = rec.united(d->pieces.at(i).pieceBoundingRect()); + rect = rect.united(d->pieces.at(i).pieceBoundingRect()); } - return rec; + return rect; } diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 086148b3b7ce..5f28c1362420 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vlayoutpaper.h - ** @author Douglas S Caskey - ** @date Dec 27, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - **************************************************************************/ - -/************************************************************************ - ** - ** @file vlayoutpaper.h - ** @author Roman Telezhynskyi - ** @date 7 1, 2015 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vposition.h +// @author Douglas S Caskey +// @date Dec 27, 2022 +// +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vposition.h +// @author Roman Telezhynskyi +// @date 7 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #ifndef VLAYOUTPAPER_H #define VLAYOUTPAPER_H @@ -80,6 +79,8 @@ class VLayoutPaper ~VLayoutPaper(); VLayoutPaper &operator=(const VLayoutPaper &paper); + +//check if the current compiler supports C++11's rvalue references #ifdef Q_COMPILER_RVALUE_REFS VLayoutPaper &operator=(VLayoutPaper &&paper) Q_DECL_NOTHROW; #endif @@ -92,8 +93,8 @@ class VLayoutPaper int GetWidth() const; void SetWidth(int width); - qreal GetLayoutWidth() const; - void SetLayoutWidth(qreal width); + qreal getLayoutGap() const; + void setLayoutGap(qreal width); quint32 GetShift() const; void SetShift(quint32 shift); @@ -107,11 +108,11 @@ class VLayoutPaper bool IsSaveLength() const; void SetSaveLength(bool value); - void SetPaperIndex(quint32 index); + void setPaperIndex(quint32 index); bool arrangePiece(const VLayoutPiece &piece, std::atomic_bool &stop); int Count() const; - Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const; + Q_REQUIRED_RESULT QGraphicsRectItem *getPaperItem(bool autoCrop, bool textAsPaths) const; Q_REQUIRED_RESULT QList getPieceItems(bool textAsPaths) const; QVector getPieces() const; @@ -121,8 +122,8 @@ class VLayoutPaper private: QSharedDataPointer d; - bool AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop); - bool SaveResult(const VBestSquare &bestResult, const VLayoutPiece &piece); + bool addToSheet(const VLayoutPiece &piece, std::atomic_bool &stop); + bool saveResult(const VBestSquare &bestResult, const VLayoutPiece &piece); }; Q_DECLARE_TYPEINFO(VLayoutPaper, Q_MOVABLE_TYPE); diff --git a/src/libs/vlayout/vlayoutpaper_p.h b/src/libs/vlayout/vlayoutpaper_p.h index ce7367945551..6594a45744ee 100644 --- a/src/libs/vlayout/vlayoutpaper_p.h +++ b/src/libs/vlayout/vlayoutpaper_p.h @@ -1,54 +1,53 @@ -/*************************************************************************** - ** @file vlayoutpaper_p.h - ** @author Douglas S Caskey - ** @date Dec 27, 2022 - ** - ** @copyright - ** Copyright (C) 2017 - 2022 Seamly, LLC - ** https://github.com/fashionfreedom/seamly2d - ** - ** @brief - ** Seamly2D is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Seamly2D is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Seamly2D. If not, see . - **************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// @file vposition_p.h +// @author Douglas S Caskey +// @date Dec 27, 2022 +// +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d +// +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . +//--------------------------------------------------------------------------------------------------------------------- -/************************************************************************ -** -** @file vlayoutpaper_p.h -** @author Roman Telezhynskyi -** @date 8 1, 2015 -** -** @brief -** @copyright -** This source code is part of the Valentina project, a pattern making -** program, whose allow create and modeling patterns of clothing. -** Copyright (C) 2013-2015 Valentina project -** All Rights Reserved. -** -** Valentina is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** Valentina is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Valentina. If not, see . -** -*************************************************************************/ +//--------------------------------------------------------------------------------------------------------------------- +// +// @file vposition_p.h +// @author Roman Telezhynskyi +// @date 8 1, 2015 +// +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. +// +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . +//--------------------------------------------------------------------------------------------------------------------- #ifndef VLAYOUTPAPER_P_H #define VLAYOUTPAPER_P_H @@ -68,58 +67,53 @@ class VLayoutPaperData : public QSharedData { public: VLayoutPaperData() - : pieces(QVector()), - globalContour(VContour()), - paperIndex(0), - layoutWidth(0), - globalRotate(true), - localRotate(true), - globalRotationIncrease(180), - localRotationIncrease(180), - saveLength(false) + : pieces(QVector()) + , globalContour(VContour()) + , paperIndex(0) + , layoutWidth(0) + , globalRotate(true) + , localRotate(true) + , globalRotationIncrease(180) + , localRotationIncrease(180) + , saveLength(false) {} VLayoutPaperData(int height, int width) - : pieces(QVector()), - globalContour(VContour(height, width)), - paperIndex(0), - layoutWidth(0), - globalRotate(true), - localRotate(true), - globalRotationIncrease(180), - localRotationIncrease(180), - saveLength(false) + : pieces(QVector()) + , globalContour(VContour(height, width)) + , paperIndex(0) + , layoutWidth(0) + , globalRotate(true) + , localRotate(true) + , globalRotationIncrease(180) + , localRotationIncrease(180) + , saveLength(false) {} VLayoutPaperData(const VLayoutPaperData &paper) - : QSharedData(paper), - pieces(paper.pieces), - globalContour(paper.globalContour), - paperIndex(paper.paperIndex), - layoutWidth(paper.layoutWidth), - globalRotate(paper.globalRotate), - localRotate(paper.localRotate), - globalRotationIncrease(paper.globalRotationIncrease), - localRotationIncrease(paper.localRotationIncrease), - saveLength(paper.saveLength) + : QSharedData(paper) + , pieces(paper.pieces) + , globalContour(paper.globalContour) + , paperIndex(paper.paperIndex) + , layoutWidth(paper.layoutWidth) + , globalRotate(paper.globalRotate) + , localRotate(paper.localRotate) + , globalRotationIncrease(paper.globalRotationIncrease) + , localRotationIncrease(paper.localRotationIncrease) + , saveLength(paper.saveLength) {} ~VLayoutPaperData() {} - /** @brief pieces list of arranged pieces. */ - QVector pieces; - - /** @brief globalContour list of global points contour. */ - VContour globalContour; - - quint32 paperIndex; - quint32 frame; - qreal layoutWidth; - bool globalRotate; - bool localRotate; - int globalRotationIncrease; - int localRotationIncrease; - bool saveLength; + QVector pieces; /// @brief pieces list of arranged pieces. + VContour globalContour; /// @brief globalContour list of global points contour. + quint32 paperIndex; + qreal layoutWidth; + bool globalRotate; + bool localRotate; + int globalRotationIncrease; + int localRotationIncrease; + bool saveLength; private: VLayoutPaperData& operator=(const VLayoutPaperData&) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index c35521552854..cefd8974eed7 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -700,13 +700,13 @@ void VLayoutPiece::setTransform(const QTransform &transform) } //--------------------------------------------------------------------------------------------------------------------- -qreal VLayoutPiece::GetLayoutWidth() const +qreal VLayoutPiece::getLayoutGap() const { return d->layoutWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetLayoutWidth(const qreal &value) +void VLayoutPiece::setLayoutGap(const qreal &value) { d->layoutWidth = value; } diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 7ad5d2cd1c38..8a2a38941d6d 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -131,8 +131,8 @@ class VLayoutPiece :public VAbstractPiece QTransform getTransform() const; void setTransform(const QTransform &transform); - qreal GetLayoutWidth() const; - void SetLayoutWidth(const qreal &value); + qreal getLayoutGap() const; + void setLayoutGap(const qreal &value); bool isMirror() const; void SetMirror(bool value); diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index ccd1b93578cb..a62966f5065f 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -1,63 +1,58 @@ //--------------------------------------------------------------------------------------------------------------------- -// @file vposition.cpp -// @author Douglas S Caskey -// @date Dec 11, 2022 +// @file vposition.cpp +// @author Douglas S Caskey +// @date Dec 11, 2022 // -// @copyright -// Copyright (C) 2017 - 2022 Seamly, LLC -// https://github.com/fashionfreedom/seamly2d +// @copyright +// Copyright (C) 2017 - 2022 Seamly, LLC +// https://github.com/fashionfreedom/seamly2d // -// @brief -// Seamly2D is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// @brief +// Seamly2D is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// Seamly2D is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// Seamly2D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// You should have received a copy of the GNU General Public License -// along with Seamly2D. if not, see . +// You should have received a copy of the GNU General Public License +// along with Seamly2D. if not, see . //--------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------- // -// @file vposition.cpp -// @author Roman Telezhynskyi -// @date 20 1, 2015 +// @file vposition.cpp +// @author Roman Telezhynskyi +// @date 20 1, 2015 // -// @brief -// @copyright -// This source code is part of the Valentina project, a pattern making -// program, whose allow create and modeling patterns of clothing. -// Copyright (C) 2013-2015 Valentina project -// All Rights Reserved. +// @brief +// @copyright +// This source code is part of the Valentina project, a pattern making +// program, whose allow create and modeling patterns of clothing. +// Copyright (C) 2013-2015 Valentina project +// All Rights Reserved. // -// Valentina is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// Valentina is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// Valentina is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// Valentina is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// You should have received a copy of the GNU General Public License -// along with Valentina. If not, see . +// You should have received a copy of the GNU General Public License +// along with Valentina. If not, see . //--------------------------------------------------------------------------------------------------------------------- #include "vposition.h" -#include -#include #include -#include #include -#include -#include #include #include #include @@ -73,389 +68,371 @@ #include "../vmisc/vmath.h" //--------------------------------------------------------------------------------------------------------------------- -VPosition::VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, - bool rotate, int rotationIncrease, bool saveLength) +/// @brief VPosition constructor +/// +/// This consrtucts an instance of VPosition. +/// @param sheet +/// @param sheetEdgeNum +/// @param piece +/// @param pieceEdgeNum +/// @param stop +/// @param rotate +/// @param rotationIncrement +/// @param saveLength +//--------------------------------------------------------------------------------------------------------------------- +VPosition::VPosition(const VContour &sheet, int sheetEdgeNum, const VLayoutPiece &piece, int pieceEdgeNum, + std::atomic_bool *stop, bool rotate, int rotationIncrement, bool saveLength) : QRunnable() - , bestResult(VBestSquare(gContour.GetSize(), saveLength)) - , gContour(gContour) - , piece(piece) - , i(i) - , j(j) - , paperIndex(0) - , frame(0) - , piecesCount(0) - , pieces() - , stop(stop) - , rotate(rotate) - , rotationIncrease(rotationIncrease) - , angle_between(0) + , m_bestResult(VBestSquare(sheet.GetSize(), saveLength)) + , m_sheet(sheet) + , m_sheetEdgeNum(sheetEdgeNum) + , m_piece(piece) + , m_pieceEdgeNum(pieceEdgeNum) + , m_stop(stop) + , m_rotate(rotate) + , m_rotationIncrement(rotationIncrement) + , m_angleBetween(0) { - if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) + if ((m_rotationIncrement >= 1 && m_rotationIncrement <= 180 && 360 % m_rotationIncrement == 0) == false) { - this->rotationIncrease = 180; + this->m_rotationIncrement = 180; } } +//--------------------------------------------------------------------------------------------------------------------- +/// @brief run run the thread to position piece. +/// +/// This method runs the thread that positions the piece near to the sheet edge. //--------------------------------------------------------------------------------------------------------------------- void VPosition::run() { - if (stop->load()) + if (m_stop->load()) { return; } // We should use copy of the piece. - VLayoutPiece workpiece = piece; + VLayoutPiece workpiece = m_piece; - int dEdge = i;// For mirror piece edge will be different - if (CheckCombineEdges(workpiece, j, dEdge)) + int pieceEdgeNum = m_pieceEdgeNum; // For flipped piece edge will be different + if (edgesIntersect(workpiece, pieceEdgeNum, m_sheetEdgeNum)) { - SaveCandidate(bestResult, workpiece, j, dEdge, BestFrom::Combine); + saveCandidate(m_bestResult, workpiece, pieceEdgeNum, m_sheetEdgeNum, BestFrom::Combine); } - frame = frame + 3; - if (rotate) + if (m_rotate) { - Rotate(rotationIncrease); + rotate(m_rotationIncrement); } else { - if (gContour.GetContour().isEmpty()) + if (m_sheet.GetContour().isEmpty()) { - Rotate(rotationIncrease); + rotate(m_rotationIncrement); } } } //--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -quint32 VPosition::getPaperIndex() const -{ - return paperIndex; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::setPaperIndex(const quint32 &value) -{ - paperIndex = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -quint32 VPosition::getFrame() const -{ - return frame; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::setFrame(const quint32 &value) -{ - frame = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -quint32 VPosition::getPieceCount() const -{ - return piecesCount; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::setPieceCount(const quint32 &value) -{ - piecesCount = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPosition::setPieces(const QVector &pieces) -{ - this->pieces = pieces; -} - +/// @brief getBestResult getter for m_bestResult. +/// +/// This method gets and returns m_bestResult. +/// +/// @returns VBestSquare m_bestResult. //--------------------------------------------------------------------------------------------------------------------- VBestSquare VPosition::getBestResult() const { - return bestResult; + return m_bestResult; } //--------------------------------------------------------------------------------------------------------------------- -void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, +/// @brief saveCandidate saves the best square. +/// +/// This method saves the resulting new size after adding the piece to the sheet. +/// +/// @param bestResult new sheet size saved here. +/// @param piece pattern piece being added to sheet. +/// @param pieceEdgeNum edge number of piece to be combined with the sheet edge. +/// @param sheetEdgeNum edge of sheet piece is being comibed with. +/// @param type type of best sqaure being saved. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VPosition::saveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int pieceEdgeNum, int sheetEdgeNum, BestFrom type) { - QVector newGContour = gContour.UniteWithContour(piece, globalI, detJ, type); - newGContour.append(newGContour.first()); - const QSizeF size = QPolygonF(newGContour).boundingRect().size(); - bestResult.NewResult(size, globalI, detJ, piece.getTransform(), piece.isMirror(), type); + QVector newContour = m_sheet.UniteWithContour(piece, sheetEdgeNum, pieceEdgeNum, type); + newContour.append(newContour.first()); + const QSizeF size = QPolygonF(newContour).boundingRect().size(); + bestResult.NewResult(size, sheetEdgeNum, pieceEdgeNum, piece.getTransform(), piece.isMirror(), type); } //--------------------------------------------------------------------------------------------------------------------- -bool VPosition::CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge) +/// @brief edgesIntersect check for intersection between piece and sheet +/// +/// This method checks if the pattern piece edge intersects with the sheet edge. +/// +/// @param piece pattern piece being added to sheet. +/// @param pieceEdgeNum edge number of piece to be combined with the sheet edge. +/// @param sheetEdgeNum edge of sheet piece is being comibed with. +/// @returns bool. +/// - true if there no intersection. +/// - false if it has an intersection. +//--------------------------------------------------------------------------------------------------------------------- +bool VPosition::edgesIntersect(VLayoutPiece &piece, int &pieceEdgeNum, int sheetEdgeNum) { - const QLineF globalEdge = gContour.GlobalEdge(j); - bool flagMirror = false; - bool flagSquare = false; + const QLineF sheetEdge = m_sheet.GlobalEdge(sheetEdgeNum); + bool isFlipped = false; + bool hasNoIntersectiom = false; - CombineEdges(piece, globalEdge, dEdge); + combineEdges(piece, pieceEdgeNum, sheetEdge); - CrossingType type = CrossingType::Intersection; - if (SheetContains(piece.pieceBoundingRect())) + IntersectionType type = IntersectionType::Intersection; + if (sheetContains(piece.pieceBoundingRect())) { - if (not gContour.GetContour().isEmpty()) + if (!m_sheet.GetContour().isEmpty()) { - type = Crossing(piece); + type = intersectionType(piece); } else { - type = CrossingType::NoIntersection; + type = IntersectionType::NoIntersection; } } switch (type) { - case CrossingType::EdgeError: - return false; - case CrossingType::Intersection: - piece.Mirror(globalEdge); - flagMirror = true; + case IntersectionType::Intersection: + piece.Mirror(sheetEdge); + isFlipped = true; break; - case CrossingType::NoIntersection: - flagSquare = true; + case IntersectionType::NoIntersection: + hasNoIntersectiom = true; break; default: break; } - if (flagMirror && not piece.IsForbidFlipping()) + if (isFlipped && !piece.IsForbidFlipping()) { - if (gContour.GetContour().isEmpty()) + if (m_sheet.GetContour().isEmpty()) { - dEdge = piece.pieceEdgeByPoint(globalEdge.p2()); + pieceEdgeNum = piece.pieceEdgeByPoint(sheetEdge.p2()); } else { - dEdge = piece.LayoutEdgeByPoint(globalEdge.p2()); + pieceEdgeNum = piece.LayoutEdgeByPoint(sheetEdge.p2()); } - if (dEdge <= 0) + if (pieceEdgeNum <= 0) { return false; } - CrossingType type = CrossingType::Intersection; - if (SheetContains(piece.pieceBoundingRect())) + IntersectionType type = IntersectionType::Intersection; + if (sheetContains(piece.pieceBoundingRect())) { - type = Crossing(piece); + type = intersectionType(piece); } switch (type) { - case CrossingType::EdgeError: - return false; - case CrossingType::Intersection: - flagSquare = false; + case IntersectionType::Intersection: + hasNoIntersectiom = false; break; - case CrossingType::NoIntersection: - flagSquare = true; + case IntersectionType::NoIntersection: + hasNoIntersectiom = true; break; default: break; } } - return flagSquare; + return hasNoIntersectiom; } //--------------------------------------------------------------------------------------------------------------------- -bool VPosition::CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const +/// @brief rotatedEdgeIntersects check for intersection between rotated piece and sheet +/// +/// This method checks if rotated pattern piece edge intersects with the sheet edge. +/// +/// @param piece pattern piece being added to sheet. +/// @param pieceEdgeNum edge number of piece to be combined with the sheet edge. +/// @param sheetEdgeNum edge of sheet piece is being comibed with. +/// @returns bool. +/// - true if there no intersection. +/// - false if it has an intersection. +//--------------------------------------------------------------------------------------------------------------------- +bool VPosition::rotatedEdgeIntersects(VLayoutPiece &piece, int pieceEdgeNum, int sheetEdgeNum, int angle) const { - const QLineF globalEdge = gContour.GlobalEdge(j); - bool flagSquare = false; + const QLineF sheetEdge = m_sheet.GlobalEdge(sheetEdgeNum); + bool hasNoIntersectiom = false; - RotateEdges(piece, globalEdge, dEdge, angle); + rotateEdges(piece, pieceEdgeNum, sheetEdge, angle); - CrossingType type = CrossingType::Intersection; - if (SheetContains(piece.pieceBoundingRect())) + IntersectionType type = IntersectionType::Intersection; + if (sheetContains(piece.pieceBoundingRect())) { - type = Crossing(piece); + type = intersectionType(piece); } switch (type) { - case CrossingType::EdgeError: - return false; - case CrossingType::Intersection: - flagSquare = false; + case IntersectionType::Intersection: + hasNoIntersectiom = false; break; - case CrossingType::NoIntersection: - flagSquare = true; + case IntersectionType::NoIntersection: + hasNoIntersectiom = true; break; default: break; } - return flagSquare; + return hasNoIntersectiom; } //--------------------------------------------------------------------------------------------------------------------- -VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &piece) const +/// @brief intersectionType get the intersection type between sheet and piece. +/// +/// This method checks if the bounding box of a piece intersects with sheet bounding box. +/// +/// @param piece layput piece. +/// @returns IntersectionType intersection type +/// - NoIntersection = 0, +/// - Intersection = 1, +//--------------------------------------------------------------------------------------------------------------------- +VPosition::IntersectionType VPosition::intersectionType(const VLayoutPiece &piece) const { - const QRectF gRect = gContour.BoundingRect(); - if (not gRect.intersects(piece.LayoutBoundingRect()) && not gRect.contains(piece.pieceBoundingRect())) + const QRectF globalRect = m_sheet.BoundingRect(); + if (!globalRect.intersects(piece.LayoutBoundingRect()) && !globalRect.contains(piece.pieceBoundingRect())) { // This we can determine efficiently. - return CrossingType::NoIntersection; + return IntersectionType::NoIntersection; } - const QPainterPath gPath = gContour.ContourPath(); - if (not gPath.intersects(piece.LayoutAllowancePath()) && not gPath.contains(piece.createMainPath())) + const QPainterPath globalPath = m_sheet.ContourPath(); + if (!globalPath.intersects(piece.LayoutAllowancePath()) && !globalPath.contains(piece.createMainPath())) { - return CrossingType::NoIntersection; + return IntersectionType::NoIntersection; } else { - return CrossingType::Intersection; + return IntersectionType::Intersection; } } //--------------------------------------------------------------------------------------------------------------------- -bool VPosition::SheetContains(const QRectF &rect) const +/// @brief sheetContains check if sheet contains piece. +/// +/// This method checks if the bounding box of a piece is contained in the sheet bounding box. +/// +/// @param rect bounding rectangle of the piece. +/// @returns bool +/// - true if sheet contains piece. +/// - false if sheet does not contain piece. +//--------------------------------------------------------------------------------------------------------------------- +bool VPosition::sheetContains(const QRectF &rect) const { - const QRectF bRect(0, 0, gContour.GetWidth(), gContour.GetHeight()); - return bRect.contains(rect); + const QRectF sheetRect(0, 0, m_sheet.GetWidth(), m_sheet.GetHeight()); + return sheetRect.contains(rect); } //--------------------------------------------------------------------------------------------------------------------- -void VPosition::CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge) +/// @brief combineEdges rotate and move piece to contour edge. +/// +/// This method rotates and moves piece near to the sheet edge. +/// +/// @param piece layout piece. +/// @param pieceEdgeNum piece edge number. +/// @param sheetEdge line that represents the sheet edge. +/// @returns void. +//--------------------------------------------------------------------------------------------------------------------- +void VPosition::combineEdges(VLayoutPiece &piece, const int &pieceEdgeNum, const QLineF &sheetEdge) { QLineF pieceEdge; - if (gContour.GetContour().isEmpty()) + if (m_sheet.GetContour().isEmpty()) { - pieceEdge = piece.pieceEdge(dEdge); + pieceEdge = piece.pieceEdge(pieceEdgeNum); } else { - pieceEdge = piece.LayoutEdge(dEdge); + pieceEdge = piece.LayoutEdge(pieceEdgeNum); } - // Find distance between two edges for two begin vertex. - const qreal dx = globalEdge.x2() - pieceEdge.x2(); - const qreal dy = globalEdge.y2() - pieceEdge.y2(); + // Find distance between sheet and piece edges. + const qreal dx = sheetEdge.x2() - pieceEdge.x2(); + const qreal dy = sheetEdge.y2() - pieceEdge.y2(); pieceEdge.translate(dx, dy); // Use values for translate piece edge. - angle_between = globalEdge.angleTo(pieceEdge); // Seek angle between two edges. + m_angleBetween = sheetEdge.angleTo(pieceEdge); // Seek angle between two edges. - // Now we move piece to position near to global contour edge. + // Move piece to position near to sheet edge. piece.Translate(dx, dy); - if (not qFuzzyIsNull(angle_between) || not qFuzzyCompare(angle_between, 360)) + if (!qFuzzyIsNull(m_angleBetween) || !qFuzzyCompare(m_angleBetween, 360)) { - piece.Rotate(pieceEdge.p2(), -angle_between); + piece.Rotate(pieceEdge.p2(), -m_angleBetween); } } //--------------------------------------------------------------------------------------------------------------------- -void VPosition::RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const +/// @brief rotateEdges rotate and move piece to sheet edge. +/// +/// This method rotates and moves piece near to the sheet edge. +/// +/// @param piece layout piece. +/// @param sheetEdge line that represents the sheet edge. +/// @param pieceEdgeNum piece edge number. +/// @param angle piece rotation angle. +/// @return void. +//--------------------------------------------------------------------------------------------------------------------- +void VPosition::rotateEdges(VLayoutPiece &piece, int pieceEdgeNum, const QLineF &sheetEdge, int angle) const { QLineF pieceEdge; - if (gContour.GetContour().isEmpty()) + if (m_sheet.GetContour().isEmpty()) { - pieceEdge = piece.pieceEdge(dEdge); + pieceEdge = piece.pieceEdge(pieceEdgeNum); } else { - pieceEdge = piece.LayoutEdge(dEdge); + pieceEdge = piece.LayoutEdge(pieceEdgeNum); } - // Find distance between two edges for two begin vertex. - const qreal dx = globalEdge.x2() - pieceEdge.x2(); - const qreal dy = globalEdge.y2() - pieceEdge.y2(); + // Find distance between sheet and piece edges. + const qreal dx = sheetEdge.x2() - pieceEdge.x2(); + const qreal dy = sheetEdge.y2() - pieceEdge.y2(); - pieceEdge.translate(dx, dy); // Use values for translate piece edge. - - // Now we move piece to position near to global contour edge. + // Move and rotate piece to position near to sheet edge. piece.Translate(dx, dy); - piece.Rotate(globalEdge.p2(), angle); + piece.Rotate(sheetEdge.p2(), angle); } //--------------------------------------------------------------------------------------------------------------------- -void VPosition::Rotate(int increase) +/// @brief rotate rotate the pattern piece. +/// +/// This method rotates the pattern piece by the number of degrees in incrmentuntil it +/// intersects with the sheet. The best square result is saved. +/// +/// @param increment pattern piece rotation angle. +/// @return void. +//--------------------------------------------------------------------------------------------------------------------- +void VPosition::rotate(int increment) { int startAngle = 0; - if (VFuzzyComparePossibleNulls(angle_between, 360)) + if (VFuzzyComparePossibleNulls(m_angleBetween, 360)) { - startAngle = increase; + startAngle = increment; } - for (int angle = startAngle; angle < 360; angle = angle+increase) + for (int angle = startAngle; angle < 360; angle = angle + increment) { - if (stop->load()) + if (m_stop->load()) { return; } // We should use copy of the piece. - VLayoutPiece workpiece = piece; - - if (CheckRotationEdges(workpiece, j, i, angle)) - { - SaveCandidate(bestResult, workpiece, j, i, BestFrom::Rotation); - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VPosition::ShowDirection(const QLineF &edge) -{ - const int arrowLength = 14; - QPainterPath path; - if (edge.length()/arrowLength < 5) - { - return path; - } + VLayoutPiece workpiece = m_piece; - 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; -} - -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VPosition::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)); - } - return path; -} - -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VPosition::drawPieces(const QVector &pieces) -{ - QPainterPath path; - path.setFillRule(Qt::WindingFill); - if (pieces.count() > 0) - { - for (int i = 0; i < pieces.size(); ++i) + if (rotatedEdgeIntersects(workpiece, m_pieceEdgeNum, m_sheetEdgeNum, angle)) { - path.addPath(pieces.at(i).createMainPath()); + saveCandidate(m_bestResult, workpiece, m_pieceEdgeNum, m_sheetEdgeNum, BestFrom::Rotation); } } - return path; } diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index 59531d110fb1..5eb1487a439e 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -66,72 +66,44 @@ class VPosition : public QRunnable { public: - VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, - std::atomic_bool *stop, bool rotate, int rotationIncrease, bool saveLength); + VPosition(const VContour &sheet, int sheetEdgeNum, const VLayoutPiece &piece, int pieceEdgeNum, + std::atomic_bool *stop, bool rotate, int rotationIncrement, bool saveLength); virtual ~VPosition() Q_DECL_OVERRIDE{} virtual void run() Q_DECL_OVERRIDE; - quint32 getPaperIndex() const; - void setPaperIndex(const quint32 &value); - - quint32 getFrame() const; - void setFrame(const quint32 &value); - - quint32 getPieceCount() const; - void setPieceCount(const quint32 &value); - - void setPieces(const QVector &pieces); - VBestSquare getBestResult() const; private: Q_DISABLE_COPY(VPosition) - VBestSquare bestResult; - const VContour gContour; - const VLayoutPiece piece; - int i; - int j; - quint32 paperIndex; - quint32 frame; - quint32 piecesCount; - QVector pieces; - std::atomic_bool *stop; - bool rotate; - int rotationIncrease; - - /// @brief angle_between keep angle between global edge and piece edge. Need for optimization rotation. - qreal angle_between; - - enum class CrossingType : char + VBestSquare m_bestResult; + const VContour m_sheet; + int m_sheetEdgeNum; + const VLayoutPiece m_piece; + int m_pieceEdgeNum; + std::atomic_bool *m_stop; + bool m_rotate; + int m_rotationIncrement; + qreal m_angleBetween; /// keep angle between global edge and piece edge. Need for optimizing rotation. + + enum class IntersectionType : char { NoIntersection = 0, - Intersection = 1, - EdgeError = 2 + Intersection = 1, }; - enum class InsideType : char - { - Outside = 0, - Inside = 1, - EdgeError = 2 - }; - - void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type); - - bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge); - bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const; + void saveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, + int pieceEdgeNum, int sheetEdgeNum, BestFrom type); - CrossingType Crossing(const VLayoutPiece &piece) const; - bool SheetContains(const QRectF &rect) const; + bool edgesIntersect(VLayoutPiece &piece, int &pieceEdgeNum, int sheetEdgeNum); + bool rotatedEdgeIntersects(VLayoutPiece &piece, int pieceEdgeNum, int sheetEdgeNum, int angle) const; - void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge); - void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const; + IntersectionType intersectionType(const VLayoutPiece &piece) const; + bool sheetContains(const QRectF &rect) const; - static QPainterPath ShowDirection(const QLineF &edge); - static QPainterPath DrawContour(const QVector &points); - static QPainterPath drawPieces(const QVector &pieces); + void combineEdges(VLayoutPiece &piece, const int &pieceEdgeNum, const QLineF &sheetEdge); + void rotateEdges(VLayoutPiece &piece, int pieceEdgeNum, const QLineF &sheetEdge, int angle) const; - void Rotate(int increase); + void rotate(int increment); }; #endif // VPOSITION_H diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index a5345b11ee8b..eb743c4c8cc4 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -88,7 +88,7 @@ const QString settingCommunityUsername = QStringLiteral("community/username" const QString settingCommunitySavePassword = QStringLiteral("community/savePassword"); const QString settingCommunityUserPassword = QStringLiteral("community/userpassword"); -const QString settingLayoutWidth = QStringLiteral("layout/width"); +const QString settingLayoutGap = QStringLiteral("layout/width"); const QString settingLayoutSorting = QStringLiteral("layout/sorting"); const QString settingLayoutPaperHeight = QStringLiteral("layout/paperHeight"); const QString settingLayoutPaperWidth = QStringLiteral("layout/paperWidth"); @@ -377,11 +377,11 @@ void VSettings::SetLayoutShift(qreal value) } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetLayoutWidth() const +qreal VSettings::getLayoutGap() const { - const qreal def = GetDefLayoutWidth(); + const qreal def = getDefLayoutGap(); bool ok = false; - const qreal lWidth = value(settingLayoutWidth, def).toDouble(&ok); + const qreal lWidth = value(settingLayoutGap, def).toDouble(&ok); if (ok) { return lWidth; @@ -393,15 +393,15 @@ qreal VSettings::GetLayoutWidth() const } //--------------------------------------------------------------------------------------------------------------------- -qreal VSettings::GetDefLayoutWidth() +qreal VSettings::getDefLayoutGap() { return UnitConvertor(2.5, Unit::Mm, Unit::Px); } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetLayoutWidth(qreal value) +void VSettings::setLayoutGap(qreal value) { - setValue(settingLayoutWidth, value); + setValue(settingLayoutGap, value); } //--------------------------------------------------------------------------------------------------------------------- @@ -582,19 +582,19 @@ void VSettings::SetIgnoreAllFields(bool value) } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetStripOptimization() const +bool VSettings::useStripOptimization() const { - return value(settingStripOptimization, GetDefStripOptimization()).toBool(); + return value(settingStripOptimization, useDefStripOptimization()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VSettings::GetDefStripOptimization() +bool VSettings::useDefStripOptimization() { return false; } //--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetStripOptimization(bool value) +void VSettings::setStripOptimization(bool value) { setValue(settingStripOptimization, value); } diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index f48cb3f056f1..5e4561f53396 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -127,9 +127,9 @@ class VSettings : public VCommonSettings static qreal GetDefLayoutShift(); void SetLayoutShift(qreal value); - qreal GetLayoutWidth() const; - static qreal GetDefLayoutWidth(); - void SetLayoutWidth(qreal value); + qreal getLayoutGap() const; + static qreal getDefLayoutGap(); + void setLayoutGap(qreal value); QMarginsF GetFields(const QMarginsF &def = QMarginsF()) const; void SetFields(const QMarginsF &value); @@ -162,9 +162,9 @@ class VSettings : public VCommonSettings static bool GetDefIgnoreAllFields(); void SetIgnoreAllFields(bool value); - bool GetStripOptimization() const; - static bool GetDefStripOptimization(); - void SetStripOptimization(bool value); + bool useStripOptimization() const; + static bool useDefStripOptimization(); + void setStripOptimization(bool value); quint8 GetMultiplier() const; static quint8 GetDefMultiplier();