2015-01-21 22:49:38 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vposition.h
|
|
|
|
** @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
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-01-21 22:49:38 +01:00
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VPOSITION_H
|
|
|
|
#define VPOSITION_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
2015-01-21 22:49:38 +01:00
|
|
|
#include <QRunnable>
|
|
|
|
#include <QVector>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QtGlobal>
|
2017-02-22 13:04:47 +01:00
|
|
|
#include <atomic>
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2020-11-26 18:10:09 +01:00
|
|
|
#ifdef LAYOUT_DEBUG
|
|
|
|
#include <QMutex>
|
|
|
|
#endif
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
#include "vbestsquare.h"
|
|
|
|
#include "vcontour.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vlayoutdef.h"
|
2017-01-22 10:02:02 +01:00
|
|
|
#include "vlayoutpiece.h"
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2019-03-26 17:54:59 +01:00
|
|
|
struct VPositionData
|
|
|
|
{
|
|
|
|
VContour gContour{};
|
|
|
|
VLayoutPiece detail{};
|
|
|
|
int i{-1};
|
|
|
|
int j{-1};
|
|
|
|
bool rotate{false};
|
2019-03-29 18:52:37 +01:00
|
|
|
int rotationNumber{0};
|
2019-03-26 17:54:59 +01:00
|
|
|
bool followGrainline{false};
|
2019-07-22 15:42:37 +02:00
|
|
|
QVector<VCachedPositions> positionsCache{};
|
2019-06-18 13:28:16 +02:00
|
|
|
bool isOriginPaperOrientationPortrait{true};
|
2020-11-26 18:10:09 +01:00
|
|
|
#ifdef LAYOUT_DEBUG
|
|
|
|
QVector<VLayoutPiece> details{};
|
|
|
|
QMutex *mutex{nullptr};
|
|
|
|
#endif
|
2019-03-26 17:54:59 +01:00
|
|
|
};
|
|
|
|
|
2019-08-22 14:32:45 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
|
|
|
|
2019-08-22 09:57:38 +02:00
|
|
|
class VPosition
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
|
|
|
public:
|
2022-08-16 15:01:17 +02:00
|
|
|
VPosition() = default;
|
2019-03-26 17:54:59 +01:00
|
|
|
VPosition(const VPositionData &data, std::atomic_bool *stop, bool saveLength);
|
2019-08-22 17:09:47 +02:00
|
|
|
VPosition(const VPosition&) = default;
|
2022-08-16 15:01:17 +02:00
|
|
|
auto operator=(const VPosition&) -> VPosition& = default;
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
VPosition(VPosition&&) = default;
|
|
|
|
auto operator=(VPosition&&) -> VPosition& = default;
|
|
|
|
#endif
|
2021-09-25 16:18:33 +02:00
|
|
|
~VPosition()= default;
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2021-09-25 16:18:33 +02:00
|
|
|
void run();
|
2019-03-26 17:54:59 +01:00
|
|
|
|
2022-08-16 15:01:17 +02:00
|
|
|
auto getBestResult() const -> VBestSquare;
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2022-08-16 15:01:17 +02:00
|
|
|
static auto ArrangeDetail(const VPositionData &data, std::atomic_bool *stop, bool saveLength) -> VBestSquare;
|
2019-06-18 14:10:08 +02:00
|
|
|
|
2020-11-26 18:10:09 +01:00
|
|
|
#ifdef LAYOUT_DEBUG
|
|
|
|
static void DumpFrame(const VContour &contour, const VLayoutPiece &detail, QMutex *mutex,
|
|
|
|
const QVector<VLayoutPiece> &details);
|
|
|
|
#endif
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
private:
|
2019-08-22 09:57:38 +02:00
|
|
|
bool m_isValid{false};
|
|
|
|
VBestSquare m_bestResult{};
|
|
|
|
VPositionData m_data{};
|
|
|
|
std::atomic_bool *stop{nullptr};
|
2015-05-15 17:16:15 +02:00
|
|
|
/**
|
|
|
|
* @brief angle_between keep angle between global edge and detail edge. Need for optimization rotation.
|
|
|
|
*/
|
2019-08-22 09:57:38 +02:00
|
|
|
qreal angle_between{0};
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2020-01-07 11:54:01 +01:00
|
|
|
enum class CrossingType : qint8
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
|
|
|
NoIntersection = 0,
|
|
|
|
Intersection = 1,
|
|
|
|
EdgeError = 2
|
|
|
|
};
|
|
|
|
|
2020-01-07 11:54:01 +01:00
|
|
|
enum class InsideType : qint8
|
2015-01-21 22:49:38 +01:00
|
|
|
{
|
|
|
|
Outside = 0,
|
|
|
|
Inside = 1,
|
|
|
|
EdgeError = 2
|
|
|
|
};
|
|
|
|
|
2017-01-22 10:02:02 +01:00
|
|
|
void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, BestFrom type);
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2022-08-16 15:01:17 +02:00
|
|
|
auto CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge) -> bool;
|
|
|
|
auto CheckRotationEdges(VLayoutPiece &detail, int j, int dEdge, qreal angle) const -> bool;
|
2018-12-27 14:54:29 +01:00
|
|
|
|
|
|
|
void RotateOnAngle(qreal angle);
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2022-08-16 15:01:17 +02:00
|
|
|
auto Crossing(const VLayoutPiece &detail) const -> CrossingType;
|
|
|
|
auto SheetContains(const QRectF &rect) const -> bool;
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2018-12-28 12:08:53 +01:00
|
|
|
void CombineEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge);
|
2019-08-22 14:33:32 +02:00
|
|
|
static void RotateEdges(VLayoutPiece &detail, const QLineF &globalEdge, int dEdge, qreal angle);
|
2015-01-21 22:49:38 +01:00
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
void Rotate(int number);
|
2018-12-27 14:54:29 +01:00
|
|
|
void FollowGrainline();
|
|
|
|
|
2022-08-16 15:01:17 +02:00
|
|
|
auto FabricGrainline() const -> QLineF;
|
2019-03-26 17:54:59 +01:00
|
|
|
|
|
|
|
void FindBestPosition();
|
2015-01-21 22:49:38 +01:00
|
|
|
};
|
|
|
|
|
2019-08-22 14:32:45 +02:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VPosition::FabricGrainline return fabric gainline accoding to paper orientation
|
|
|
|
* @return fabric gainline line
|
|
|
|
*/
|
2022-08-16 15:01:17 +02:00
|
|
|
inline auto VPosition::FabricGrainline() const -> QLineF
|
2018-12-27 14:54:29 +01:00
|
|
|
{
|
2019-06-18 13:28:16 +02:00
|
|
|
return m_data.isOriginPaperOrientationPortrait ? QLineF(10, 10, 10, 100) : QLineF(10, 10, 100, 10);
|
2018-12-27 14:54:29 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 22:49:38 +01:00
|
|
|
#endif // VPOSITION_H
|