2013-11-15 13:41:26 +01:00
|
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
|
** @file varc.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
** @brief
|
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +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.
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
|
** 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.
|
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
|
** 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/>.
|
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
|
#include "varc.h"
|
2015-08-11 15:41:03 +02:00
|
|
|
|
|
2014-06-17 11:50:11 +02:00
|
|
|
|
#include <QLineF>
|
|
|
|
|
#include <QPointF>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
|
#include "../vmisc/def.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
|
#include "../vmisc/vmath.h"
|
2020-07-13 15:28:13 +02:00
|
|
|
|
#include "../vmisc/compatibility.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
|
#include "vabstractcurve.h"
|
|
|
|
|
#include "varc_p.h"
|
|
|
|
|
#include "vspline.h"
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief VArc default constructor.
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
VArc::VArc ()
|
2016-04-10 16:40:55 +02:00
|
|
|
|
: VAbstractArc(GOType::Arc),
|
|
|
|
|
d (new VArcData)
|
2014-05-02 13:11:30 +02:00
|
|
|
|
{}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief VArc constructor.
|
|
|
|
|
* @param center center point.
|
|
|
|
|
* @param radius arc radius.
|
|
|
|
|
* @param f1 start angle (degree).
|
|
|
|
|
* @param f2 end angle (degree).
|
|
|
|
|
*/
|
2016-04-10 16:40:55 +02:00
|
|
|
|
VArc::VArc (const VPointF ¢er, qreal radius, const QString &formulaRadius, qreal f1, const QString &formulaF1,
|
|
|
|
|
qreal f2, const QString &formulaF2, quint32 idObject, Draw mode)
|
|
|
|
|
: VAbstractArc(GOType::Arc, center, f1, formulaF1, f2, formulaF2, idObject, mode),
|
|
|
|
|
d (new VArcData(radius, formulaRadius))
|
2013-11-12 13:48:45 +01:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
CreateName();
|
2013-11-12 13:48:45 +01:00
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
2014-08-15 15:54:24 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 16:40:55 +02:00
|
|
|
|
VArc::VArc(const VPointF ¢er, qreal radius, qreal f1, qreal f2)
|
|
|
|
|
: VAbstractArc(GOType::Arc, center, f1, f2, NULL_ID, Draw::Calculation),
|
|
|
|
|
d (new VArcData(radius))
|
2014-08-15 15:54:24 +02:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
CreateName();
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 16:40:55 +02:00
|
|
|
|
VArc::VArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius,
|
|
|
|
|
const QString &formulaRadius, qreal f1, const QString &formulaF1, quint32 idObject, Draw mode)
|
|
|
|
|
: VAbstractArc(GOType::Arc, formulaLength, center, f1, formulaF1, idObject, mode),
|
|
|
|
|
d (new VArcData(radius, formulaRadius))
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
CreateName();
|
2015-06-09 12:21:10 +02:00
|
|
|
|
FindF2(length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 16:40:55 +02:00
|
|
|
|
VArc::VArc(qreal length, const VPointF ¢er, qreal radius, qreal f1)
|
|
|
|
|
: VAbstractArc(GOType::Arc, center, f1, NULL_ID, Draw::Calculation),
|
|
|
|
|
d (new VArcData(radius))
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
CreateName();
|
2015-06-09 12:21:10 +02:00
|
|
|
|
FindF2(length);
|
2014-08-15 15:54:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief VArc copy constructor
|
|
|
|
|
* @param arc arc
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
VArc::VArc(const VArc &arc)
|
2016-04-10 16:40:55 +02:00
|
|
|
|
: VAbstractArc(arc), d (arc.d)
|
2014-05-02 13:11:30 +02:00
|
|
|
|
{}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief operator = assignment operator
|
|
|
|
|
* @param arc arc
|
|
|
|
|
* @return arc
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
VArc &VArc::operator =(const VArc &arc)
|
|
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
|
if ( &arc == this )
|
|
|
|
|
{
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
|
VAbstractArc::operator=(arc);
|
2014-08-20 14:23:21 +02:00
|
|
|
|
d = arc.d;
|
2013-08-13 18:48:36 +02:00
|
|
|
|
return *this;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
|
VArc::VArc(VArc &&arc) Q_DECL_NOTHROW
|
|
|
|
|
: VAbstractArc(arc), d (arc.d)
|
|
|
|
|
{}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
|
VArc &VArc::operator=(VArc &&arc) Q_DECL_NOTHROW
|
2019-12-30 12:00:57 +01:00
|
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
|
VAbstractArc::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 13:40:04 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const
|
|
|
|
|
{
|
|
|
|
|
const VPointF center = GetCenter().Rotate(originPoint, degrees);
|
|
|
|
|
|
|
|
|
|
const QPointF p1 = VPointF::RotatePF(originPoint, GetP1(), degrees);
|
|
|
|
|
const QPointF p2 = VPointF::RotatePF(originPoint, GetP2(), degrees);
|
|
|
|
|
|
2017-07-27 15:01:18 +02:00
|
|
|
|
const qreal f1 = QLineF(static_cast<QPointF>(center), p1).angle();
|
|
|
|
|
const qreal f2 = QLineF(static_cast<QPointF>(center), p2).angle();
|
|
|
|
|
|
|
|
|
|
VArc arc(center, GetRadius(), f1, f2);
|
2016-04-10 13:40:04 +02:00
|
|
|
|
arc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
|
arc.SetColor(GetColor());
|
|
|
|
|
arc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
arc.SetFlipped(IsFlipped());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
arc.SetApproximationScale(GetApproximationScale());
|
2016-04-10 13:40:04 +02:00
|
|
|
|
return arc;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-10 17:18:11 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VArc VArc::Flip(const QLineF &axis, const QString &prefix) const
|
|
|
|
|
{
|
|
|
|
|
const VPointF center = GetCenter().Flip(axis);
|
|
|
|
|
|
|
|
|
|
const QPointF p1 = VPointF::FlipPF(axis, GetP1());
|
|
|
|
|
const QPointF p2 = VPointF::FlipPF(axis, GetP2());
|
|
|
|
|
|
2017-07-27 15:01:18 +02:00
|
|
|
|
const qreal f1 = QLineF(static_cast<QPointF>(center), p1).angle();
|
|
|
|
|
const qreal f2 = QLineF(static_cast<QPointF>(center), p2).angle();
|
|
|
|
|
|
|
|
|
|
VArc arc(center, GetRadius(), f1, f2);
|
2016-09-10 17:18:11 +02:00
|
|
|
|
arc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
|
arc.SetColor(GetColor());
|
|
|
|
|
arc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
arc.SetFlipped(not IsFlipped());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
arc.SetApproximationScale(GetApproximationScale());
|
2016-09-10 17:18:11 +02:00
|
|
|
|
return arc;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 16:34:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VArc VArc::Move(qreal length, qreal angle, const QString &prefix) const
|
|
|
|
|
{
|
|
|
|
|
const VPointF center = GetCenter().Move(length, angle);
|
|
|
|
|
|
|
|
|
|
const QPointF p1 = VPointF::MovePF(GetP1(), length, angle);
|
|
|
|
|
const QPointF p2 = VPointF::MovePF(GetP2(), length, angle);
|
|
|
|
|
|
2017-07-27 15:01:18 +02:00
|
|
|
|
const qreal f1 = QLineF(static_cast<QPointF>(center), p1).angle();
|
|
|
|
|
const qreal f2 = QLineF(static_cast<QPointF>(center), p2).angle();
|
|
|
|
|
|
|
|
|
|
VArc arc(center, GetRadius(), f1, f2);
|
2016-10-04 16:34:37 +02:00
|
|
|
|
arc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
|
arc.SetColor(GetColor());
|
|
|
|
|
arc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
arc.SetFlipped(IsFlipped());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
arc.SetApproximationScale(GetApproximationScale());
|
2016-10-04 16:34:37 +02:00
|
|
|
|
return arc;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 14:23:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
VArc::~VArc()
|
|
|
|
|
{}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetLength return arc length.
|
|
|
|
|
* @return length.
|
|
|
|
|
*/
|
2014-01-10 10:16:55 +01:00
|
|
|
|
qreal VArc::GetLength() const
|
|
|
|
|
{
|
2016-04-11 04:52:32 +02:00
|
|
|
|
qreal length = d->radius * qDegreesToRadians(AngleArc());
|
2016-04-10 16:40:55 +02:00
|
|
|
|
if (IsFlipped())
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
length *= -1;
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return length;
|
2014-01-10 10:16:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetP1 return point associated with start angle.
|
|
|
|
|
* @return point.
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
QPointF VArc::GetP1() const
|
|
|
|
|
{
|
2014-08-20 14:23:21 +02:00
|
|
|
|
QPointF p1 ( GetCenter().x () + d->radius, GetCenter().y () );
|
2017-03-31 16:04:11 +02:00
|
|
|
|
QLineF centerP1(static_cast<QPointF>(GetCenter()), p1);
|
2016-04-10 16:40:55 +02:00
|
|
|
|
centerP1.setAngle(GetStartAngle());
|
2013-08-06 09:56:09 +02:00
|
|
|
|
return centerP1.p2();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetP2 return point associated with end angle.
|
|
|
|
|
* @return точку point.
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
QPointF VArc::GetP2 () const
|
|
|
|
|
{
|
2014-08-20 14:23:21 +02:00
|
|
|
|
QPointF p2 ( GetCenter().x () + d->radius, GetCenter().y () );
|
2017-03-31 16:04:11 +02:00
|
|
|
|
QLineF centerP2(static_cast<QPointF>(GetCenter()), p2);
|
2016-04-10 16:40:55 +02:00
|
|
|
|
centerP2.setAngle(GetEndAngle());
|
2013-08-06 09:56:09 +02:00
|
|
|
|
return centerP2.p2();
|
2013-08-05 10:37:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief GetPoints return list of points needed for drawing arc.
|
|
|
|
|
* @return list of points
|
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
|
QVector<QPointF> VArc::GetPoints() const
|
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
|
QVector<QPointF> points;
|
2015-12-07 22:33:11 +01:00
|
|
|
|
QVector<qreal> sectionAngle;
|
|
|
|
|
|
2019-04-03 08:37:43 +02:00
|
|
|
|
QPointF pStart = IsFlipped() ? GetP2() : GetP1();
|
2015-12-07 22:33:11 +01:00
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
|
{
|
2015-12-07 22:33:11 +01:00
|
|
|
|
qreal angle = AngleArc();
|
|
|
|
|
|
|
|
|
|
if (qFuzzyIsNull(angle))
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2015-12-07 22:33:11 +01:00
|
|
|
|
points.append(pStart);
|
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (angle > 360 || angle < 0)
|
|
|
|
|
{// Filter incorect value
|
|
|
|
|
QLineF dummy(0,0, 100, 0);
|
|
|
|
|
dummy.setAngle(angle);
|
|
|
|
|
angle = dummy.angle();
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
2015-12-07 22:33:11 +01:00
|
|
|
|
|
|
|
|
|
const qreal angleInterpolation = 45; //degree
|
|
|
|
|
const int sections = qFloor(angle / angleInterpolation);
|
|
|
|
|
for (int i = 0; i < sections; ++i)
|
|
|
|
|
{
|
|
|
|
|
sectionAngle.append(angleInterpolation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qreal tail = angle - sections * angleInterpolation;
|
|
|
|
|
if (tail > 0)
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2015-12-07 22:33:11 +01:00
|
|
|
|
sectionAngle.append(tail);
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
2015-12-07 22:33:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sectionAngle.size(); ++i)
|
|
|
|
|
{
|
2016-04-11 04:52:32 +02:00
|
|
|
|
const qreal lDistance = GetRadius() * 4.0/3.0 * qTan(qDegreesToRadians(sectionAngle.at(i)) * 0.25);
|
2015-12-07 22:33:11 +01:00
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
|
const QPointF center = static_cast<QPointF>(GetCenter());
|
2015-12-07 22:33:11 +01:00
|
|
|
|
|
|
|
|
|
QLineF lineP1P2(pStart, center);
|
|
|
|
|
lineP1P2.setAngle(lineP1P2.angle() - 90.0);
|
|
|
|
|
lineP1P2.setLength(lDistance);
|
|
|
|
|
|
|
|
|
|
QLineF lineP4P3(center, pStart);
|
|
|
|
|
lineP4P3.setAngle(lineP4P3.angle() + sectionAngle.at(i));
|
|
|
|
|
lineP4P3.setLength(GetRadius());//in case of computing error
|
|
|
|
|
lineP4P3 = QLineF(lineP4P3.p2(), center);
|
|
|
|
|
lineP4P3.setAngle(lineP4P3.angle() + 90.0);
|
|
|
|
|
lineP4P3.setLength(lDistance);
|
|
|
|
|
|
|
|
|
|
VSpline spl(VPointF(pStart), lineP1P2.p2(), lineP4P3.p2(), VPointF(lineP4P3.p1()), 1.0);
|
2017-10-11 12:51:06 +02:00
|
|
|
|
spl.SetApproximationScale(GetApproximationScale());
|
2015-12-07 22:33:11 +01:00
|
|
|
|
QVector<QPointF> splPoints = spl.GetPoints();
|
|
|
|
|
if (not splPoints.isEmpty() && i != sectionAngle.size() - 1)
|
2014-01-11 11:11:42 +01:00
|
|
|
|
{
|
2015-12-07 22:33:11 +01:00
|
|
|
|
splPoints.removeLast();
|
2014-01-11 11:11:42 +01:00
|
|
|
|
}
|
2015-12-07 22:33:11 +01:00
|
|
|
|
|
|
|
|
|
points << splPoints;
|
|
|
|
|
pStart = lineP4P3.p1();
|
|
|
|
|
}
|
2020-07-13 15:28:13 +02:00
|
|
|
|
return IsFlipped() ? Reverse(points) : points;
|
2013-08-28 10:55:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief CutArc cut arc into two arcs.
|
|
|
|
|
* @param length length first arc.
|
|
|
|
|
* @param arc1 first arc.
|
|
|
|
|
* @param arc2 second arc.
|
|
|
|
|
* @return point cutting
|
|
|
|
|
*/
|
2019-04-03 08:37:43 +02:00
|
|
|
|
QPointF VArc::CutArc(qreal length, VArc &arc1, VArc &arc2) const
|
2014-01-08 15:05:32 +01:00
|
|
|
|
{
|
|
|
|
|
//Always need return two arcs, so we must correct wrong length.
|
2016-04-02 19:47:04 +02:00
|
|
|
|
const qreal fullLength = GetLength();
|
|
|
|
|
|
2019-04-03 08:37:43 +02:00
|
|
|
|
if (qAbs(fullLength) < ToPixel(2, Unit::Mm))
|
2016-04-02 19:47:04 +02:00
|
|
|
|
{
|
|
|
|
|
arc1 = VArc();
|
|
|
|
|
arc2 = VArc();
|
|
|
|
|
return QPointF();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 08:37:43 +02:00
|
|
|
|
QLineF line(static_cast<QPointF>(GetCenter()), GetP1());
|
2016-04-02 19:47:04 +02:00
|
|
|
|
|
2019-04-03 08:37:43 +02:00
|
|
|
|
if (not IsFlipped())
|
2014-01-08 15:05:32 +01:00
|
|
|
|
{
|
2019-04-03 08:37:43 +02:00
|
|
|
|
if (length < 0)
|
|
|
|
|
{
|
|
|
|
|
length = fullLength + length;
|
|
|
|
|
}
|
|
|
|
|
length = qBound(ToPixel(1, Unit::Mm), length, fullLength - ToPixel(1, Unit::Mm));
|
|
|
|
|
|
|
|
|
|
line.setAngle(line.angle() + qRadiansToDegrees(length/d->radius));
|
2014-01-08 15:05:32 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-04-03 08:37:43 +02:00
|
|
|
|
if (length > 0)
|
|
|
|
|
{
|
|
|
|
|
length = fullLength + length;
|
|
|
|
|
}
|
|
|
|
|
length = qBound(fullLength + ToPixel(1, Unit::Mm), length, ToPixel(-1, Unit::Mm));
|
2016-04-11 04:52:32 +02:00
|
|
|
|
|
2019-04-03 08:37:43 +02:00
|
|
|
|
line.setAngle(line.angle() - qRadiansToDegrees(qAbs(length)/d->radius));
|
|
|
|
|
}
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
|
arc1 = VArc (GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(),
|
2014-08-20 14:23:21 +02:00
|
|
|
|
QString().setNum(line.angle()), getIdObject(), getMode());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
arc1.SetApproximationScale(GetApproximationScale());
|
2019-04-03 08:37:43 +02:00
|
|
|
|
arc1.SetFlipped(IsFlipped());
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
|
arc2 = VArc (GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(),
|
|
|
|
|
GetFormulaF2(), getIdObject(), getMode());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
arc2.SetApproximationScale(GetApproximationScale());
|
2019-04-03 08:37:43 +02:00
|
|
|
|
arc2.SetFlipped(IsFlipped());
|
2014-01-10 10:16:55 +01:00
|
|
|
|
return line.p2();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-15 16:37:22 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-04-03 08:37:43 +02:00
|
|
|
|
QPointF VArc::CutArc(qreal length) const
|
2014-08-15 16:37:22 +02:00
|
|
|
|
{
|
|
|
|
|
VArc arc1;
|
|
|
|
|
VArc arc2;
|
|
|
|
|
return this->CutArc(length, arc1, arc2);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 12:21:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-15 15:30:48 +01:00
|
|
|
|
void VArc::CreateName()
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
|
QString name = ARC_ + QString("%1").arg(this->GetCenter().name());
|
|
|
|
|
|
2020-06-02 17:11:52 +02:00
|
|
|
|
if (getMode() == Draw::Modeling && getIdObject() != NULL_ID)
|
|
|
|
|
{
|
|
|
|
|
name += QString("_%1").arg(getIdObject());
|
|
|
|
|
}
|
|
|
|
|
else if (VAbstractCurve::id() != NULL_ID)
|
2016-02-15 15:30:48 +01:00
|
|
|
|
{
|
|
|
|
|
name += QString("_%1").arg(VAbstractCurve::id());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GetDuplicate() > 0)
|
|
|
|
|
{
|
|
|
|
|
name += QString("_%1").arg(GetDuplicate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setName(name);
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void VArc::FindF2(qreal length)
|
|
|
|
|
{
|
2016-04-10 16:40:55 +02:00
|
|
|
|
SetFlipped(length < 0);
|
2015-06-09 12:21:10 +02:00
|
|
|
|
|
|
|
|
|
if (length >= MaxLength())
|
|
|
|
|
{
|
|
|
|
|
length = MaxLength();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-11 04:52:32 +02:00
|
|
|
|
qreal arcAngle = qAbs(qRadiansToDegrees(length/d->radius));
|
2015-06-09 12:21:10 +02:00
|
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
|
if (IsFlipped())
|
2015-06-09 12:21:10 +02:00
|
|
|
|
{
|
|
|
|
|
arcAngle = arcAngle * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineF startAngle(0, 0, 100, 0);
|
2016-04-10 16:40:55 +02:00
|
|
|
|
startAngle.setAngle(GetStartAngle() + arcAngle);// We use QLineF just because it is easy way correct angle value
|
2015-06-09 12:21:10 +02:00
|
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
|
SetFormulaF2(QString().number(startAngle.angle()), startAngle.angle());
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
qreal VArc::MaxLength() const
|
|
|
|
|
{
|
2016-03-23 12:52:55 +01:00
|
|
|
|
return M_2PI*d->radius;
|
2015-06-09 12:21:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 14:23:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
/**
|
|
|
|
|
* @brief GetRadius return arc radius.
|
|
|
|
|
* @return radius.
|
|
|
|
|
*/
|
|
|
|
|
QString VArc::GetFormulaRadius() const
|
|
|
|
|
{
|
|
|
|
|
return d->formulaRadius;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 16:34:45 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-07 14:31:53 +02:00
|
|
|
|
void VArc::SetFormulaRadius(const QString &formula, qreal value)
|
2014-09-01 16:34:45 +02:00
|
|
|
|
{
|
2015-05-07 14:31:53 +02:00
|
|
|
|
d->formulaRadius = formula;
|
|
|
|
|
d->radius = value;
|
2014-09-01 16:34:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 14:23:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
/**
|
|
|
|
|
* @brief GetRadius return formula for radius.
|
|
|
|
|
* @return string with formula.
|
|
|
|
|
*/
|
|
|
|
|
qreal VArc::GetRadius() const
|
|
|
|
|
{
|
|
|
|
|
return d->radius;
|
|
|
|
|
}
|