2015-01-21 19:56:59 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vbestsquare.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 21 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 19:56:59 +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 19:56:59 +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 "vbestsquare.h"
|
2019-03-26 18:02:12 +01:00
|
|
|
#include "vbestsquare_p.h"
|
2019-06-18 13:28:16 +02:00
|
|
|
#include "../vmisc/def.h"
|
2015-01-21 19:56:59 +01:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMatrix>
|
|
|
|
|
2018-12-31 12:35:42 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:31:02 +01:00
|
|
|
Q_DECL_CONSTEXPR inline qint64 Square(QSizeF size)
|
2018-12-31 12:35:42 +01:00
|
|
|
{
|
|
|
|
return static_cast<qint64>(size.width()*size.height());
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2015-01-21 19:56:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-06-18 13:36:20 +02:00
|
|
|
VBestSquare::VBestSquare(QSizeF sheetSize, bool saveLength, bool isPortrait)
|
|
|
|
: d(new VBestSquareData(sheetSize, saveLength, isPortrait))
|
2019-03-26 18:02:12 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquare::VBestSquare(const VBestSquare &res)
|
|
|
|
: d(res.d)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquare::~VBestSquare()
|
2015-01-21 19:56:59 +01:00
|
|
|
{}
|
|
|
|
|
2019-03-27 10:45:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquare &VBestSquare::operator=(const VBestSquare &res)
|
|
|
|
{
|
|
|
|
if ( &res == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
d = res.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-01-21 19:56:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:31:02 +01:00
|
|
|
void VBestSquare::NewResult(const VBestSquareResData &data)
|
2015-01-21 19:56:59 +01:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
auto SaveResult = [this, data]()
|
2018-12-31 12:35:42 +01:00
|
|
|
{
|
2019-03-26 18:02:12 +01:00
|
|
|
d->valideResult = true;
|
2019-03-27 08:31:02 +01:00
|
|
|
d->data = data;
|
2018-12-31 12:35:42 +01:00
|
|
|
};
|
|
|
|
|
2019-03-27 08:31:02 +01:00
|
|
|
const qint64 candidateSquare = Square(data.bestSize);
|
2018-12-28 14:53:18 +01:00
|
|
|
|
2019-06-18 13:28:16 +02:00
|
|
|
if (candidateSquare > 0 && data.type >= d->data.type && candidateSquare <= Square(d->data.bestSize))
|
2015-05-08 12:10:56 +02:00
|
|
|
{
|
2019-06-18 13:28:16 +02:00
|
|
|
if (not HasValidResult())
|
|
|
|
{
|
|
|
|
SaveResult(); // First result
|
|
|
|
}
|
|
|
|
else
|
2015-05-08 12:10:56 +02:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
if (d->saveLength)
|
|
|
|
{
|
2019-06-18 13:28:16 +02:00
|
|
|
if (VFuzzyComparePossibleNulls(data.depthPosition, d->data.depthPosition)
|
|
|
|
&& IsImprovedSidePosition(data.sidePosition))
|
|
|
|
{
|
|
|
|
SaveResult();
|
|
|
|
}
|
|
|
|
else if (data.depthPosition < d->data.depthPosition)
|
2019-03-27 08:31:02 +01:00
|
|
|
{
|
|
|
|
SaveResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-18 13:28:16 +02:00
|
|
|
if (IsImprovedSidePosition(data.sidePosition)
|
|
|
|
|| VFuzzyComparePossibleNulls(data.sidePosition, d->data.sidePosition))
|
|
|
|
{
|
|
|
|
SaveResult();
|
|
|
|
}
|
2019-03-27 08:31:02 +01:00
|
|
|
}
|
2015-05-08 12:10:56 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-21 19:56:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBestSquare::NewResult(const VBestSquare &best)
|
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
if (best.HasValidResult() && d->saveLength == best.IsSaveLength())
|
2015-01-21 19:56:59 +01:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
NewResult(best.BestResultData());
|
2015-01-21 19:56:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 18:02:12 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:31:02 +01:00
|
|
|
QSizeF VBestSquare::BestSize() const
|
2019-03-26 18:02:12 +01:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.bestSize;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:31:02 +01:00
|
|
|
int VBestSquare::GContourEdge() const
|
2019-03-26 18:02:12 +01:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.globalI;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VBestSquare::DetailEdge() const
|
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.detJ;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QTransform VBestSquare::Matrix() const
|
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.resMatrix;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:31:02 +01:00
|
|
|
bool VBestSquare::HasValidResult() const
|
2019-03-26 18:02:12 +01:00
|
|
|
{
|
|
|
|
return d->valideResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBestSquare::Mirror() const
|
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.resMirror;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
BestFrom VBestSquare::Type() const
|
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
return d->data.type;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-06-24 11:14:10 +02:00
|
|
|
bool VBestSquare::IsTerminatedByException() const
|
2019-03-26 18:02:12 +01:00
|
|
|
{
|
2019-06-24 11:14:10 +02:00
|
|
|
return d->terminatedByException;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VBestSquare::ReasonTerminatedByException() const
|
|
|
|
{
|
|
|
|
return d->exceptionReason;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBestSquare::TerminatedByException(const QString &reason)
|
|
|
|
{
|
|
|
|
d->valideResult = false;
|
|
|
|
d->terminatedByException = true;
|
|
|
|
d->exceptionReason = reason;
|
2019-03-27 08:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBestSquareResData VBestSquare::BestResultData() const
|
|
|
|
{
|
|
|
|
return d->data;
|
2019-03-26 18:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBestSquare::IsSaveLength() const
|
|
|
|
{
|
|
|
|
return d->saveLength;
|
|
|
|
}
|
2019-03-27 08:31:02 +01:00
|
|
|
|
2019-06-18 13:28:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBestSquare::IsImprovedSidePosition(qreal sidePosition) const
|
|
|
|
{
|
|
|
|
const bool lessThan = d->data.sidePosition < sidePosition;
|
|
|
|
const bool greaterThan = d->data.sidePosition > sidePosition;
|
|
|
|
|
|
|
|
return IsPortrait() ? greaterThan : lessThan;
|
|
|
|
}
|
|
|
|
|
2019-03-27 08:31:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBestSquare::IsPortrait() const
|
|
|
|
{
|
2019-06-18 13:36:20 +02:00
|
|
|
return d->isPortrait;
|
2019-03-27 08:31:02 +01:00
|
|
|
}
|