2015-01-21 22:49:38 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vposition.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 20 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-01-21 22:49:38 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-01-21 22:49:38 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vposition.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDir>
|
2015-01-21 22:49:38 +01:00
|
|
|
#include <QImage>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLineF>
|
2015-01-21 22:49:38 +01:00
|
|
|
#include <QPainter>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPicture>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QPolygonF>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QSizeF>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
2019-06-18 14:10:08 +02:00
|
|
|
#include <QThreadPool>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <Qt>
|
|
|
|
|
|
|
|
#include "../vmisc/def.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2019-06-18 14:10:08 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
|
|
|
#include "../vmisc/backport/qscopeguard.h"
|
|
|
|
#else
|
|
|
|
#include <QScopeGuard>
|
|
|
|
#endif
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-26 17:54:59 +01:00
|
|
|
VPosition::VPosition(const VPositionData &data, std::atomic_bool *stop, bool saveLength)
|
2017-02-22 13:04:47 +01:00
|
|
|
: QRunnable(),
|
2019-06-18 13:36:20 +02:00
|
|
|
m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait)),
|
2019-03-26 17:54:59 +01:00
|
|
|
m_data(data),
|
2017-02-22 13:04:47 +01:00
|
|
|
stop(stop),
|
2019-03-26 17:54:59 +01:00
|
|
|
angle_between(0)
|
2015-01-22 15:11:50 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
if (m_data.rotationNumber > 360 || m_data.rotationNumber < 1)
|
2015-01-22 15:11:50 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
m_data.rotationNumber = 2;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-21 22:49:38 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPosition::run()
|
|
|
|
{
|
2017-02-22 13:04:47 +01:00
|
|
|
if (stop->load())
|
2015-01-22 12:39:04 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-24 11:14:10 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FindBestPosition();
|
|
|
|
}
|
|
|
|
catch (const VException &e)
|
|
|
|
{
|
|
|
|
m_bestResult.TerminatedByException(QStringLiteral("%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
m_bestResult.TerminatedByException(QString::fromLatin1(e.what()));
|
|
|
|
return;
|
|
|
|
}
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquare VPosition::getBestResult() const
|
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
return m_bestResult;
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 14:10:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquare VPosition::ArrangeDetail(const VPositionData &data, std::atomic_bool *stop, bool saveLength)
|
|
|
|
{
|
|
|
|
VBestSquare bestResult(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait);
|
|
|
|
|
|
|
|
if (stop->load())
|
|
|
|
{
|
|
|
|
return bestResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First need set size of paper
|
|
|
|
if (data.gContour.GetHeight() <= 0 || data.gContour.GetWidth() <= 0)
|
|
|
|
{
|
|
|
|
return bestResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VLayoutPiece detail = data.detail;
|
|
|
|
const int detailEdgesCount = detail.LayoutEdgesCount();
|
|
|
|
if (detailEdgesCount < 3 || detail.DetailEdgesCount() < 3)
|
|
|
|
{
|
|
|
|
return bestResult;//Not enough edges
|
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer<QThreadPool> thread_pool(new QThreadPool());
|
|
|
|
QVector<VPosition *> threads;
|
|
|
|
|
2019-07-18 16:34:43 +02:00
|
|
|
auto Cleanup = qScopeGuard([&threads]
|
|
|
|
{
|
|
|
|
Q_ASSERT(not threads.isEmpty());
|
|
|
|
qDeleteAll(threads.begin(), threads.end());
|
|
|
|
});
|
2019-06-18 14:10:08 +02:00
|
|
|
|
|
|
|
for (int j=1; j <= data.gContour.GlobalEdgesCount(); ++j)
|
|
|
|
{
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
for (int i=1; i<= detailEdgesCount; ++i)
|
|
|
|
{
|
|
|
|
VPositionData linkedData = data;
|
|
|
|
linkedData.i = i;
|
|
|
|
linkedData.j = j;
|
|
|
|
|
|
|
|
auto *thread = new VPosition(linkedData, stop, saveLength);
|
|
|
|
thread->setAutoDelete(false);
|
|
|
|
threads.append(thread);
|
|
|
|
thread_pool->start(thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:34:43 +02:00
|
|
|
Q_ASSERT(not threads.isEmpty());
|
|
|
|
|
2019-06-18 14:10:08 +02:00
|
|
|
// Wait for done
|
|
|
|
do
|
|
|
|
{
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QThread::msleep(250);
|
|
|
|
}
|
|
|
|
while(thread_pool->activeThreadCount() > 0 && not stop->load());
|
|
|
|
|
|
|
|
if (stop->load())
|
|
|
|
{
|
|
|
|
return bestResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &thread : threads)
|
|
|
|
{
|
|
|
|
bestResult.NewResult(thread->getBestResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestResult;
|
|
|
|
}
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ,
|
2015-01-21 22:49:38 +01:00
|
|
|
BestFrom type)
|
|
|
|
{
|
2019-03-27 08:03:19 +01:00
|
|
|
if (bestResult.IsSaveLength())
|
|
|
|
{
|
|
|
|
m_data.gContour.CeateEmptySheetContour();
|
|
|
|
}
|
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
|
2015-01-21 22:49:38 +01:00
|
|
|
newGContour.append(newGContour.first());
|
2015-05-08 12:10:56 +02:00
|
|
|
const QSizeF size = QPolygonF(newGContour).boundingRect().size();
|
2019-06-18 13:28:16 +02:00
|
|
|
const QRectF boundingRect = detail.DetailBoundingRect();
|
|
|
|
const qreal depthPosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.y() : boundingRect.x();
|
|
|
|
const qreal sidePosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.x() : boundingRect.y();
|
2019-03-27 08:31:02 +01:00
|
|
|
|
|
|
|
VBestSquareResData data;
|
|
|
|
data.bestSize = size;
|
|
|
|
data.globalI = globalI; // Edge of global contour
|
|
|
|
data.detJ = detJ; // Edge of detail
|
|
|
|
data.resMatrix = detail.GetMatrix(); // Matrix for rotation and translation detail
|
|
|
|
data.resMirror = detail.IsMirror();
|
|
|
|
data.type = type;
|
|
|
|
data.depthPosition = depthPosition;
|
2019-06-18 13:28:16 +02:00
|
|
|
data.sidePosition = sidePosition;
|
2019-03-27 08:31:02 +01:00
|
|
|
|
|
|
|
bestResult.NewResult(data);
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
bool VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge)
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
const QLineF globalEdge = m_data.gContour.GlobalEdge(j);
|
2015-01-21 22:49:38 +01:00
|
|
|
bool flagMirror = false;
|
|
|
|
bool flagSquare = false;
|
|
|
|
|
|
|
|
CombineEdges(detail, globalEdge, dEdge);
|
|
|
|
|
|
|
|
CrossingType type = CrossingType::Intersection;
|
2017-12-17 14:06:46 +01:00
|
|
|
if (not detail.IsForceFlipping() && SheetContains(detail.DetailBoundingRect()))
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
if (not m_data.gContour.GetContour().isEmpty())
|
2015-05-15 17:16:15 +02:00
|
|
|
{
|
2016-03-28 10:53:02 +02:00
|
|
|
type = Crossing(detail);
|
2015-05-15 17:16:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = CrossingType::NoIntersection;
|
|
|
|
}
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CrossingType::EdgeError:
|
|
|
|
return false;
|
|
|
|
case CrossingType::Intersection:
|
|
|
|
detail.Mirror(globalEdge);
|
|
|
|
flagMirror = true;
|
|
|
|
break;
|
|
|
|
case CrossingType::NoIntersection:
|
2016-03-28 10:53:02 +02:00
|
|
|
flagSquare = true;
|
2015-03-16 13:23:02 +01:00
|
|
|
break;
|
2015-01-21 22:49:38 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
if (flagMirror && not detail.IsForbidFlipping())
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-07-21 09:19:00 +02:00
|
|
|
dEdge = detail.LayoutEdgeByPoint(globalEdge.p2());
|
2016-12-10 17:38:34 +01:00
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
if (dEdge <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CrossingType type = CrossingType::Intersection;
|
2016-12-10 17:38:34 +01:00
|
|
|
if (SheetContains(detail.DetailBoundingRect()))
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2016-03-28 10:53:02 +02:00
|
|
|
type = Crossing(detail);
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CrossingType::EdgeError:
|
|
|
|
return false;
|
|
|
|
case CrossingType::Intersection:
|
|
|
|
flagSquare = false;
|
|
|
|
break;
|
|
|
|
case CrossingType::NoIntersection:
|
2016-03-28 10:53:02 +02:00
|
|
|
flagSquare = true;
|
2015-03-16 13:23:02 +01:00
|
|
|
break;
|
2015-01-21 22:49:38 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flagSquare;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-12-27 14:54:29 +01:00
|
|
|
bool VPosition::CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal angle) const
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
const QLineF globalEdge = m_data.gContour.GlobalEdge(j);
|
2015-01-21 22:49:38 +01:00
|
|
|
bool flagSquare = false;
|
|
|
|
|
2017-12-17 14:06:46 +01:00
|
|
|
if (detail.IsForceFlipping())
|
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
detail.Mirror(not m_data.followGrainline ? globalEdge : QLineF(10, 10, 10, 100));
|
2017-12-17 14:06:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
RotateEdges(detail, globalEdge, dEdge, angle);
|
|
|
|
|
|
|
|
CrossingType type = CrossingType::Intersection;
|
2016-12-10 17:38:34 +01:00
|
|
|
if (SheetContains(detail.DetailBoundingRect()))
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2016-03-28 10:53:02 +02:00
|
|
|
type = Crossing(detail);
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CrossingType::EdgeError:
|
|
|
|
return false;
|
|
|
|
case CrossingType::Intersection:
|
|
|
|
flagSquare = false;
|
|
|
|
break;
|
|
|
|
case CrossingType::NoIntersection:
|
2016-03-28 10:53:02 +02:00
|
|
|
flagSquare = true;
|
2015-03-16 13:23:02 +01:00
|
|
|
break;
|
2015-01-21 22:49:38 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return flagSquare;
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPosition::RotateOnAngle(qreal angle)
|
|
|
|
{
|
|
|
|
// We should use copy of the detail.
|
2019-03-26 17:54:59 +01:00
|
|
|
VLayoutPiece workDetail = m_data.detail;
|
2018-12-27 14:54:29 +01:00
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
if (CheckRotationEdges(workDetail, m_data.j, m_data.i, angle))
|
2018-12-27 14:54:29 +01:00
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
SaveCandidate(m_bestResult, workDetail, m_data.j, m_data.i, BestFrom::Rotation);
|
2018-12-27 14:54:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VPosition::CrossingType VPosition::Crossing(const VLayoutPiece &detail) const
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-04-10 14:54:18 +02:00
|
|
|
if (m_data.positionsCache.isEmpty())
|
2016-03-28 10:22:15 +02:00
|
|
|
{
|
|
|
|
return CrossingType::NoIntersection;
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:54:18 +02:00
|
|
|
const QVector<QPointF> layoutPoints = detail.GetLayoutAllowancePoints();
|
|
|
|
const QRectF layoutBoundingRect = VLayoutPiece::BoundingRect(layoutPoints);
|
|
|
|
const QPainterPath layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints);
|
|
|
|
|
|
|
|
const QVector<QPointF> contourPoints = detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn() ?
|
2019-05-27 16:04:26 +02:00
|
|
|
detail.GetMappedSeamAllowancePoints() : detail.GetMappedContourPoints();
|
2019-04-10 14:54:18 +02:00
|
|
|
const QRectF detailBoundingRect = VLayoutPiece::BoundingRect(contourPoints);
|
|
|
|
const QPainterPath contourPath = VLayoutPiece::PainterPath(contourPoints);
|
|
|
|
|
|
|
|
for(auto &position : m_data.positionsCache)
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-04-10 14:54:18 +02:00
|
|
|
if (position.boundingRect.intersects(layoutBoundingRect) || position.boundingRect.contains(detailBoundingRect))
|
|
|
|
{
|
|
|
|
if (position.layoutAllowancePath.contains(contourPath) ||
|
|
|
|
position.layoutAllowancePath.intersects(layoutAllowancePath))
|
|
|
|
{
|
|
|
|
return CrossingType::Intersection;
|
|
|
|
}
|
|
|
|
}
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
2019-04-10 14:54:18 +02:00
|
|
|
|
|
|
|
return CrossingType::NoIntersection;
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPosition::SheetContains(const QRectF &rect) const
|
|
|
|
{
|
2019-03-15 14:33:30 +01:00
|
|
|
const QRectF bRect(-accuracyPointOnLine, -accuracyPointOnLine, m_data.gContour.GetWidth()+accuracyPointOnLine,
|
|
|
|
m_data.gContour.GetHeight()+accuracyPointOnLine);
|
2015-01-21 22:49:38 +01:00
|
|
|
return bRect.contains(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-12-28 12:08:53 +01:00
|
|
|
void VPosition::CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge)
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-07-21 09:19:00 +02:00
|
|
|
QLineF detailEdge = detail.LayoutEdge(dEdge);
|
2015-01-21 22:49:38 +01:00
|
|
|
|
|
|
|
// Find distance between two edges for two begin vertex.
|
|
|
|
const qreal dx = globalEdge.x2() - detailEdge.x2();
|
|
|
|
const qreal dy = globalEdge.y2() - detailEdge.y2();
|
|
|
|
|
|
|
|
detailEdge.translate(dx, dy); // Use values for translate detail edge.
|
|
|
|
|
2015-05-15 17:16:15 +02:00
|
|
|
angle_between = globalEdge.angleTo(detailEdge); // Seek angle between two edges.
|
2015-01-21 22:49:38 +01:00
|
|
|
|
|
|
|
// Now we move detail to position near to global contour edge.
|
|
|
|
detail.Translate(dx, dy);
|
2016-03-23 15:09:30 +01:00
|
|
|
if (not qFuzzyIsNull(angle_between) || not qFuzzyCompare(angle_between, 360))
|
2015-05-15 17:16:15 +02:00
|
|
|
{
|
|
|
|
detail.Rotate(detailEdge.p2(), -angle_between);
|
|
|
|
}
|
2015-01-21 22:49:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-12-27 14:54:29 +01:00
|
|
|
void VPosition::RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, qreal angle) const
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
2019-07-21 09:19:00 +02:00
|
|
|
QLineF detailEdge = detail.LayoutEdge(dEdge);
|
2015-01-21 22:49:38 +01:00
|
|
|
// Now we move detail to position near to global contour edge.
|
2019-07-21 09:19:00 +02:00
|
|
|
detail.Translate(globalEdge.x2() - detailEdge.x2(), globalEdge.y2() - detailEdge.y2());
|
2015-01-21 22:49:38 +01:00
|
|
|
detail.Rotate(globalEdge.p2(), angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
void VPosition::Rotate(int number)
|
2015-01-22 12:47:20 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
const qreal step = 360/number;
|
|
|
|
qreal startAngle = 0;
|
2016-03-23 15:09:30 +01:00
|
|
|
if (VFuzzyComparePossibleNulls(angle_between, 360))
|
2015-05-15 17:16:15 +02:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
startAngle = step;
|
2015-05-15 17:16:15 +02:00
|
|
|
}
|
2019-03-29 18:52:37 +01:00
|
|
|
for (qreal angle = startAngle; angle < 360; angle = angle+step)
|
2015-01-22 12:47:20 +01:00
|
|
|
{
|
2017-02-22 13:04:47 +01:00
|
|
|
if (stop->load())
|
2015-01-22 12:47:20 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
RotateOnAngle(angle);
|
|
|
|
}
|
|
|
|
}
|
2015-01-22 12:47:20 +01:00
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPosition::FollowGrainline()
|
|
|
|
{
|
|
|
|
if (stop->load())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-01-22 12:47:20 +01:00
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
QLineF detailGrainline(10, 10, 100, 10);
|
2019-03-26 17:54:59 +01:00
|
|
|
detailGrainline.setAngle(m_data.detail.GrainlineAngle());
|
2018-12-27 14:54:29 +01:00
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
if (m_data.detail.IsForceFlipping())
|
2018-12-31 10:33:20 +01:00
|
|
|
{
|
2019-03-26 17:54:59 +01:00
|
|
|
VLayoutPiece workDetail = m_data.detail; // We need copy for temp change
|
|
|
|
workDetail.Mirror(not m_data.followGrainline ? m_data.gContour.GlobalEdge(m_data.j) : QLineF(10, 10, 10, 100));
|
2018-12-31 10:33:20 +01:00
|
|
|
detailGrainline = workDetail.GetMatrix().map(detailGrainline);
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
const qreal angle = detailGrainline.angleTo(FabricGrainline());
|
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
if (m_data.detail.GrainlineArrowType() == ArrowType::atBoth ||
|
|
|
|
m_data.detail.GrainlineArrowType() == ArrowType::atFront)
|
2018-12-27 14:54:29 +01:00
|
|
|
{
|
|
|
|
RotateOnAngle(angle);
|
|
|
|
}
|
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
if (m_data.detail.GrainlineArrowType() == ArrowType::atBoth ||
|
|
|
|
m_data.detail.GrainlineArrowType() == ArrowType::atRear)
|
2018-12-27 14:54:29 +01:00
|
|
|
{
|
|
|
|
RotateOnAngle(angle+180);
|
2015-01-22 12:47:20 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 17:54:59 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPosition::FindBestPosition()
|
|
|
|
{
|
|
|
|
if (not m_data.followGrainline || not m_data.detail.IsGrainlineEnabled())
|
|
|
|
{
|
|
|
|
// We should use copy of the detail.
|
|
|
|
VLayoutPiece workDetail = m_data.detail;
|
|
|
|
|
|
|
|
int dEdge = m_data.i;// For mirror detail edge will be different
|
|
|
|
if (CheckCombineEdges(workDetail, m_data.j, dEdge))
|
|
|
|
{
|
|
|
|
SaveCandidate(m_bestResult, workDetail, m_data.j, dEdge, BestFrom::Combine);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_data.rotate)
|
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
Rotate(m_data.rotationNumber);
|
2019-03-26 17:54:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FollowGrainline();
|
|
|
|
}
|
|
|
|
}
|