2016-04-10 16:40:55 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vabstractarc.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 10 4, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-04-10 16:40:55 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-04-10 16:40:55 +02: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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vabstractarc.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
2016-04-10 16:40:55 +02:00
|
|
|
#include "vabstractarc_p.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vpointf.h"
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractArc::VAbstractArc(const GOType &type, const quint32 &idObject, const Draw &mode)
|
2023-07-13 16:49:20 +02:00
|
|
|
: VAbstractCurve(type, idObject, mode),
|
|
|
|
d(new VAbstractArcData())
|
|
|
|
{
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2,
|
|
|
|
const QString &formulaF2, quint32 idObject, Draw mode)
|
2023-07-13 16:49:20 +02:00
|
|
|
: VAbstractCurve(type, idObject, mode),
|
|
|
|
d(new VAbstractArcData(center, f1, formulaF1, f2, formulaF2))
|
|
|
|
{
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, qreal f2, quint32 idObject, Draw mode)
|
2023-07-13 16:49:20 +02:00
|
|
|
: VAbstractCurve(type, idObject, mode),
|
|
|
|
d(new VAbstractArcData(center, f1, f2))
|
|
|
|
{
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VAbstractArc::VAbstractArc(const GOType &type, const QString &formulaLength, const VPointF ¢er, qreal f1,
|
|
|
|
const QString &formulaF1, quint32 idObject, Draw mode)
|
|
|
|
: VAbstractCurve(type, idObject, mode),
|
|
|
|
d(new VAbstractArcData(formulaLength, center, f1, formulaF1))
|
|
|
|
{
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractArc::VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, quint32 idObject, Draw mode)
|
2023-07-13 16:49:20 +02:00
|
|
|
: VAbstractCurve(type, idObject, mode),
|
|
|
|
d(new VAbstractArcData(center, f1))
|
|
|
|
{
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VAbstractArc::VAbstractArc(const VAbstractArc &arc) = default;
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::operator=(const VAbstractArc &arc) -> VAbstractArc &
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
2023-07-13 16:49:20 +02:00
|
|
|
if (&arc == this)
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VAbstractCurve::operator=(arc);
|
|
|
|
d = arc.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VAbstractArc::VAbstractArc(VAbstractArc &&arc) noexcept
|
|
|
|
: VAbstractCurve(std::move(arc)),
|
|
|
|
d(std::move(arc.d))
|
|
|
|
{
|
|
|
|
}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
auto VAbstractArc::operator=(VAbstractArc &&arc) noexcept -> VAbstractArc &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VAbstractCurve::operator=(arc);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, arc.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VAbstractArc::~VAbstractArc() = default;
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetFormulaF1() const -> QString
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->formulaF1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetFormulaF1(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaF1 = formula;
|
|
|
|
d->f1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetStartAngle() const -> qreal
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->f1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetFormulaF2() const -> QString
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->formulaF2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetFormulaF2(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaF2 = formula;
|
|
|
|
d->f2 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetEndAngle() const -> qreal
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetCenter() const -> VPointF
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->center;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetCenter(const VPointF &point)
|
|
|
|
{
|
|
|
|
d->center = point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::GetFormulaLength() const -> QString
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->formulaLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetFormulaLength(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaLength = formula;
|
|
|
|
FindF2(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::setId(const quint32 &id)
|
|
|
|
{
|
|
|
|
VAbstractCurve::setId(id);
|
|
|
|
CreateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::NameForHistory(const QString &toolName) const -> QString
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
2023-07-13 16:49:20 +02:00
|
|
|
QString name = toolName + QStringLiteral(" %1").arg(GetCenter().name());
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
if (VAbstractCurve::id() != NULL_ID)
|
|
|
|
{
|
2023-07-13 16:49:20 +02:00
|
|
|
name += QStringLiteral("_%1").arg(VAbstractCurve::id());
|
2016-04-10 16:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetDuplicate() > 0)
|
|
|
|
{
|
2023-07-13 16:49:20 +02:00
|
|
|
name += QStringLiteral("_%1").arg(GetDuplicate());
|
2016-04-10 16:40:55 +02:00
|
|
|
}
|
2020-11-04 10:01:20 +01:00
|
|
|
|
2020-11-04 13:50:17 +01:00
|
|
|
QString alias;
|
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
2023-07-13 16:49:20 +02:00
|
|
|
alias = QStringLiteral("%1 %2").arg(toolName, GetAliasSuffix());
|
2020-11-04 13:50:17 +01:00
|
|
|
}
|
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
return not alias.isEmpty() ? QStringLiteral("%1 (%2)").arg(alias, name) : name;
|
2016-04-10 16:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::IsFlipped() const -> bool
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
return d->isFlipped;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-05-20 16:08:32 +02:00
|
|
|
auto VAbstractArc::AngleArc() const -> qreal
|
2016-04-10 16:40:55 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
const qreal angleDiff = qAbs(GetStartAngle() - GetEndAngle());
|
|
|
|
if (VFuzzyComparePossibleNulls(angleDiff, 0) || VFuzzyComparePossibleNulls(angleDiff, 360))
|
|
|
|
{
|
|
|
|
return 360;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QLineF l1(0, 0, 100, 0);
|
|
|
|
l1.setAngle(GetStartAngle());
|
|
|
|
QLineF l2(0, 0, 100, 0);
|
|
|
|
l2.setAngle(GetEndAngle());
|
|
|
|
|
|
|
|
qreal ang = l1.angleTo(l2);
|
|
|
|
|
|
|
|
if (IsFlipped())
|
|
|
|
{
|
|
|
|
ang = 360 - ang;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ang;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetFlipped(bool value)
|
|
|
|
{
|
|
|
|
d->isFlipped = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractArc::SetFormulaLength(const QString &formula)
|
|
|
|
{
|
|
|
|
d->formulaLength = formula;
|
|
|
|
}
|