diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index fa2bfc845..bb30141d2 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -57,6 +57,7 @@ enum class BestFrom : char # define SHOW_VERTICES // Show contour vertices # define SHOW_DIRECTION // Show contour direction # define ARRANGED_DETAILS // Show already arranged details +//# define SHOW_SHEET // Show sheet rect // Debugging # define SHOW_CANDIDATE // Show each position diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 2efdaf603..f100965bf 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -50,7 +50,7 @@ VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detai bool rotate, int rotationIncrease, bool saveLength) :QRunnable(), bestResult(VBestSquare(gContour.GetSize(), saveLength)), gContour(gContour), detail(detail), i(i), j(j), paperIndex(0), frame(0), detailsCount(0), details(QVector()), stop(stop), rotate(rotate), - rotationIncrease(rotationIncrease) + rotationIncrease(rotationIncrease), angle_between(0) { if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) { @@ -161,7 +161,7 @@ void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail, QPainterPath p; if (contour.GetContour().isEmpty()) { - p = DrawContour(contour.CutEdge(QLineF(0, 0, contour.GetWidth(), 0))); + p = DrawContour(contour.CutEdge(contour.EmptySheetEdge())); p.translate(biasWidth/2, biasHeight/2); paint.drawPath(p); } @@ -195,8 +195,10 @@ void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail, 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(); @@ -246,7 +248,7 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &deta } //--------------------------------------------------------------------------------------------------------------------- -bool VPosition::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const +bool VPosition::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) { const QLineF globalEdge = gContour.GlobalEdge(j); bool flagMirror = false; @@ -263,7 +265,14 @@ bool VPosition::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) cons CrossingType type = CrossingType::Intersection; if (SheetContains(detail.BoundingRect())) { - type = Crossing(detail, j, dEdge); + if (not gContour.GetContour().isEmpty()) + { + type = Crossing(detail, j, dEdge); + } + else + { + type = CrossingType::NoIntersection; + } } switch (type) @@ -561,7 +570,7 @@ bool VPosition::SheetContains(const QRectF &rect) const } //--------------------------------------------------------------------------------------------------------------------- -void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge) const +void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge) { QLineF detailEdge = detail.Edge(dEdge); @@ -571,11 +580,14 @@ void VPosition::CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, co detailEdge.translate(dx, dy); // Use values for translate detail edge. - const qreal angle_between = globalEdge.angleTo(detailEdge); // Seek angle between two edges. + angle_between = globalEdge.angleTo(detailEdge); // Seek angle between two edges. // Now we move detail to position near to global contour edge. detail.Translate(dx, dy); - detail.Rotate(detailEdge.p2(), -angle_between); + if (not qFuzzyCompare(angle_between+360, 0+360)) + { + detail.Rotate(detailEdge.p2(), -angle_between); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -660,7 +672,12 @@ QVector VPosition::CutEdge(const QLineF &edge, unsigned int shift) //--------------------------------------------------------------------------------------------------------------------- void VPosition::Rotate(int increase) { - for (int angle = 0; angle < 360; angle = angle+increase) + int startAngle = 0; + if (qFuzzyCompare(angle_between+360, 0+360)) + { + startAngle = increase; + } + for (int angle = startAngle; angle < 360; angle = angle+increase) { if (*stop) { diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index a4f62c718..bcfc79496 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -82,6 +82,10 @@ private: volatile bool *stop; bool rotate; int rotationIncrease; + /** + * @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation. + */ + qreal angle_between; enum class CrossingType : char { @@ -101,7 +105,7 @@ private: void SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &detail, int globalI, int detJ, BestFrom type); - bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const; + bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge); bool CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int angle) const; CrossingType Crossing(const VLayoutDetail &detail, const int &globalI, const int &detailI) const; @@ -109,7 +113,7 @@ private: qreal CheckSide(const QLineF &edge, const QPointF &p) const; bool SheetContains(const QRectF &rect) const; - void CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge) const; + void CombineEdges(VLayoutDetail &detail, const QLineF &globalEdge, const int &dEdge); void RotateEdges(VLayoutDetail &detail, const QLineF &globalEdge, int dEdge, int angle) const; QPolygonF GlobalPolygon() const;