2016-02-10 05:59:29 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vellipticalarc.cpp
|
|
|
|
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
|
|
|
|
** @date February 1, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-02-10 05:59:29 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
|
|
|
** <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 "vellipticalarc.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-02-10 05:59:29 +01:00
|
|
|
#include <QLineF>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QPoint>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "vabstractcurve.h"
|
|
|
|
#include "vellipticalarc_p.h"
|
|
|
|
#include "vspline.h"
|
2016-02-10 05:59:29 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VEllipticalArc default constructor.
|
|
|
|
*/
|
|
|
|
VEllipticalArc::VEllipticalArc()
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(GOType::EllipticalArc), d (new VEllipticalArcData)
|
2016-02-10 05:59:29 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VEllipticalArc constructor.
|
|
|
|
* @param center center point.
|
|
|
|
* @param radius1 arc major radius.
|
|
|
|
* @param radius2 arc minor radius.
|
|
|
|
* @param f1 start angle (degree).
|
|
|
|
* @param f2 end angle (degree).
|
|
|
|
*/
|
2016-04-10 13:40:04 +02:00
|
|
|
VEllipticalArc::VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, const QString &formulaRadius1,
|
|
|
|
const QString &formulaRadius2, qreal f1, const QString &formulaF1, qreal f2,
|
2016-12-17 02:41:33 +01:00
|
|
|
const QString &formulaF2, qreal rotationAngle, const QString &formulaRotationAngle,
|
|
|
|
quint32 idObject, Draw mode)
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(GOType::EllipticalArc, center, f1, formulaF1, f2, formulaF2, idObject, mode),
|
2016-12-17 02:41:33 +01:00
|
|
|
d (new VEllipticalArcData(radius1, radius2, formulaRadius1, formulaRadius2, rotationAngle, formulaRotationAngle))
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
2016-02-27 15:53:17 +01:00
|
|
|
CreateName();
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 13:40:04 +02:00
|
|
|
VEllipticalArc::VEllipticalArc(const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal f2,
|
|
|
|
qreal rotationAngle)
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(GOType::EllipticalArc, center, f1, f2, NULL_ID, Draw::Calculation),
|
|
|
|
d (new VEllipticalArcData(radius1, radius2, rotationAngle))
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
2016-02-27 15:53:17 +01:00
|
|
|
CreateName();
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 13:40:04 +02:00
|
|
|
VEllipticalArc::VEllipticalArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius1,
|
|
|
|
qreal radius2, const QString &formulaRadius1, const QString &formulaRadius2, qreal f1,
|
2016-12-17 02:41:33 +01:00
|
|
|
const QString &formulaF1, qreal rotationAngle, const QString &formulaRotationAngle,
|
|
|
|
quint32 idObject, Draw mode)
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(GOType::EllipticalArc, formulaLength, center, f1, formulaF1, idObject, mode),
|
2016-12-17 02:41:33 +01:00
|
|
|
d (new VEllipticalArcData(radius1, radius2, formulaRadius1, formulaRadius2, rotationAngle, formulaRotationAngle))
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
2016-02-27 15:53:17 +01:00
|
|
|
CreateName();
|
2016-02-10 05:59:29 +01:00
|
|
|
FindF2(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-10 13:40:04 +02:00
|
|
|
VEllipticalArc::VEllipticalArc(qreal length, const VPointF ¢er, qreal radius1, qreal radius2, qreal f1,
|
|
|
|
qreal rotationAngle)
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(GOType::EllipticalArc, center, f1, NULL_ID, Draw::Calculation),
|
|
|
|
d (new VEllipticalArcData(radius1, radius2, rotationAngle))
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
2016-02-27 15:53:17 +01:00
|
|
|
CreateName();
|
2016-02-10 05:59:29 +01:00
|
|
|
FindF2(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VEllipticalArc copy constructor
|
|
|
|
* @param arc arc
|
|
|
|
*/
|
|
|
|
VEllipticalArc::VEllipticalArc(const VEllipticalArc &arc)
|
2016-04-10 16:40:55 +02:00
|
|
|
: VAbstractArc(arc), d (arc.d)
|
2016-02-10 05:59:29 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief operator = assignment operator
|
|
|
|
* @param arc arc
|
|
|
|
* @return arc
|
|
|
|
*/
|
|
|
|
VEllipticalArc &VEllipticalArc::operator =(const VEllipticalArc &arc)
|
|
|
|
{
|
|
|
|
if ( &arc == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
VAbstractArc::operator=(arc);
|
2016-02-10 05:59:29 +01:00
|
|
|
d = arc.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-04-10 13:40:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-01-05 18:41:09 +01:00
|
|
|
VEllipticalArc VEllipticalArc::Rotate(QPointF originPoint, qreal degrees, const QString &prefix) const
|
2016-04-10 13:40:04 +02:00
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
originPoint = d->m_transform.inverted().map(originPoint);
|
2017-07-27 15:01:18 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
QTransform t = d->m_transform;
|
|
|
|
t.translate(originPoint.x(), originPoint.y());
|
|
|
|
t.rotate(-degrees);
|
|
|
|
t.translate(-originPoint.x(), -originPoint.y());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
VEllipticalArc elArc(VAbstractArc::GetCenter(), GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(),
|
|
|
|
VAbstractArc::GetEndAngle(), GetRotationAngle());
|
2016-04-10 13:40:04 +02:00
|
|
|
elArc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
elArc.SetColor(GetColor());
|
|
|
|
elArc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
elArc.SetFlipped(IsFlipped());
|
2018-01-05 18:41:09 +01:00
|
|
|
elArc.SetTransform(t);
|
2016-04-10 13:40:04 +02:00
|
|
|
return elArc;
|
|
|
|
}
|
|
|
|
|
2016-02-10 05:59:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-09-10 20:40:30 +02:00
|
|
|
VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
VEllipticalArc elArc(VAbstractArc::GetCenter(), GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(),
|
|
|
|
VAbstractArc::GetEndAngle(), GetRotationAngle());
|
2016-09-10 20:40:30 +02:00
|
|
|
elArc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
elArc.SetColor(GetColor());
|
|
|
|
elArc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
elArc.SetFlipped(not IsFlipped());
|
2018-01-05 18:41:09 +01:00
|
|
|
elArc.SetTransform(d->m_transform * VGObject::FlippingMatrix(d->m_transform.inverted().map(axis)));
|
2016-09-10 20:40:30 +02:00
|
|
|
return elArc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-10-04 16:34:37 +02:00
|
|
|
VEllipticalArc VEllipticalArc::Move(qreal length, qreal angle, const QString &prefix) const
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
const VPointF oldCenter = VAbstractArc::GetCenter();
|
|
|
|
const VPointF center = oldCenter.Move(length, angle);
|
2017-07-27 15:01:18 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
const QPointF position = d->m_transform.inverted().map(center.toQPointF()) -
|
|
|
|
d->m_transform.inverted().map(oldCenter.toQPointF());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
QTransform t = d->m_transform;
|
|
|
|
t.translate(position.x(), position.y());
|
2017-07-27 15:01:18 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
VEllipticalArc elArc(oldCenter, GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(),
|
|
|
|
VAbstractArc::GetEndAngle(), GetRotationAngle());
|
2016-10-04 16:34:37 +02:00
|
|
|
elArc.setName(name() + prefix);
|
2017-05-16 12:07:53 +02:00
|
|
|
elArc.SetColor(GetColor());
|
|
|
|
elArc.SetPenStyle(GetPenStyle());
|
2017-07-27 15:01:18 +02:00
|
|
|
elArc.SetFlipped(IsFlipped());
|
2018-01-05 18:41:09 +01:00
|
|
|
elArc.SetTransform(t);
|
2016-10-04 16:34:37 +02:00
|
|
|
return elArc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-10 05:59:29 +01:00
|
|
|
VEllipticalArc::~VEllipticalArc()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetLength return arc length.
|
|
|
|
* @return length.
|
|
|
|
*/
|
|
|
|
qreal VEllipticalArc::GetLength() const
|
|
|
|
{
|
2016-04-02 13:59:43 +02:00
|
|
|
qreal length = PathLength(GetPoints());
|
2016-02-10 05:59:29 +01:00
|
|
|
|
2016-04-10 16:40:55 +02:00
|
|
|
if (IsFlipped())
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
|
|
|
length = length * -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetP1 return point associated with start angle.
|
|
|
|
* @return point.
|
|
|
|
*/
|
|
|
|
QPointF VEllipticalArc::GetP1() const
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
return GetTransform().map(GetP(VAbstractArc::GetStartAngle()));
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetP2 return point associated with end angle.
|
|
|
|
* @return point.
|
|
|
|
*/
|
|
|
|
QPointF VEllipticalArc::GetP2 () const
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
return GetTransform().map(GetP(VAbstractArc::GetEndAngle()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QTransform VEllipticalArc::GetTransform() const
|
|
|
|
{
|
|
|
|
return d->m_transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VEllipticalArc::SetTransform(const QTransform &matrix, bool combine)
|
|
|
|
{
|
|
|
|
d->m_transform = combine ? d->m_transform * matrix : matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF VEllipticalArc::GetCenter() const
|
|
|
|
{
|
|
|
|
VPointF center = VAbstractArc::GetCenter();
|
|
|
|
const QPointF p = d->m_transform.map(center.toQPointF());
|
|
|
|
center.setX(p.x());
|
|
|
|
center.setY(p.y());
|
|
|
|
return center;
|
2016-02-12 19:17:55 +01:00
|
|
|
}
|
2016-02-10 05:59:29 +01:00
|
|
|
|
2016-02-12 19:17:55 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetPoints return list of points needed for drawing arc.
|
|
|
|
* @return list of points
|
|
|
|
*/
|
|
|
|
QVector<QPointF> VEllipticalArc::GetPoints() const
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
const QPointF center = VAbstractArc::GetCenter().toQPointF();
|
|
|
|
QRectF box(center.x() - d->radius1, center.y() - d->radius2, d->radius1*2, d->radius2*2);
|
2017-09-13 08:17:21 +02:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
QLineF startLine(center.x(), center.y(), center.x() + d->radius1, center.y());
|
2017-09-13 08:17:21 +02:00
|
|
|
QLineF endLine = startLine;
|
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
startLine.setAngle(VAbstractArc::GetStartAngle());
|
|
|
|
endLine.setAngle(VAbstractArc::GetEndAngle());
|
2017-09-13 08:17:21 +02:00
|
|
|
qreal sweepAngle = startLine.angleTo(endLine);
|
|
|
|
|
|
|
|
if (qFuzzyIsNull(sweepAngle))
|
|
|
|
{
|
|
|
|
sweepAngle = 360;
|
|
|
|
}
|
|
|
|
|
2017-09-13 06:29:35 +02:00
|
|
|
QPainterPath path;
|
2018-01-05 18:41:09 +01:00
|
|
|
path.arcTo(box, VAbstractArc::GetStartAngle(), sweepAngle);
|
2016-02-10 05:59:29 +01:00
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
QTransform t = d->m_transform;
|
|
|
|
t.translate(center.x(), center.y());
|
2017-09-13 06:29:35 +02:00
|
|
|
t.rotate(-GetRotationAngle());
|
2018-01-05 18:41:09 +01:00
|
|
|
t.translate(-center.x(), -center.y());
|
2016-02-12 19:17:55 +01:00
|
|
|
|
2017-09-13 06:29:35 +02:00
|
|
|
path = t.map(path);
|
2016-02-12 19:17:55 +01:00
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
QPolygonF polygon;
|
|
|
|
const QList<QPolygonF> sub = path.toSubpathPolygons();
|
|
|
|
if (not sub.isEmpty())
|
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
polygon = path.toSubpathPolygons().constFirst();
|
|
|
|
#else
|
|
|
|
polygon = path.toSubpathPolygons().first(); // clazy:exclude=detaching-temporary
|
|
|
|
#endif
|
2017-10-23 09:45:58 +02:00
|
|
|
if (not polygon.isEmpty())
|
|
|
|
{
|
|
|
|
polygon.removeFirst(); // remove point (0;0)
|
|
|
|
}
|
|
|
|
}
|
2016-02-12 19:17:55 +01:00
|
|
|
|
2017-09-13 06:29:35 +02:00
|
|
|
return polygon;
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VEllipticalArc::GetStartAngle() const
|
|
|
|
{
|
|
|
|
return QLineF(GetCenter().toQPointF(), GetP1()).angle() - GetRotationAngle();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VEllipticalArc::GetEndAngle() const
|
|
|
|
{
|
|
|
|
return QLineF(GetCenter().toQPointF(), GetP2()).angle() - GetRotationAngle();
|
|
|
|
}
|
|
|
|
|
2016-02-10 05:59:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CutArc cut arc into two arcs.
|
|
|
|
* @param length length first arc.
|
|
|
|
* @param arc1 first arc.
|
|
|
|
* @param arc2 second arc.
|
|
|
|
* @return point cutting
|
|
|
|
*/
|
|
|
|
QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const
|
|
|
|
{
|
2016-02-26 20:30:20 +01:00
|
|
|
//Always need return two arcs, so we must correct wrong length.
|
|
|
|
qreal len = 0;
|
2016-04-02 19:47:04 +02:00
|
|
|
const qreal minLength = ToPixel(1, Unit::Mm);
|
|
|
|
const qreal fullLength = GetLength();
|
|
|
|
|
|
|
|
if (fullLength <= minLength)
|
|
|
|
{
|
|
|
|
arc1 = VEllipticalArc();
|
|
|
|
arc2 = VEllipticalArc();
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
|
|
|
|
const qreal maxLength = fullLength - minLength;
|
|
|
|
|
|
|
|
if (length < minLength)
|
2016-02-26 20:30:20 +01:00
|
|
|
{
|
2016-04-02 19:47:04 +02:00
|
|
|
len = minLength;
|
2016-02-26 20:30:20 +01:00
|
|
|
}
|
2016-04-02 19:47:04 +02:00
|
|
|
else if (length > maxLength)
|
2016-02-26 20:30:20 +01:00
|
|
|
{
|
2016-04-02 19:47:04 +02:00
|
|
|
len = maxLength;
|
2016-02-26 20:30:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the first arc has given length and startAngle just like in the origin arc
|
2016-04-10 16:40:55 +02:00
|
|
|
arc1 = VEllipticalArc (len, QString().setNum(length), GetCenter(), d->radius1, d->radius2,
|
|
|
|
d->formulaRadius1, d->formulaRadius2, GetStartAngle(), GetFormulaF1(), d->rotationAngle,
|
2016-12-17 02:41:33 +01:00
|
|
|
GetFormulaRotationAngle(), getIdObject(), getMode());
|
2016-02-26 20:30:20 +01:00
|
|
|
// the second arc has startAngle just like endAngle of the first arc
|
|
|
|
// and it has endAngle just like endAngle of the origin arc
|
2016-04-10 16:40:55 +02:00
|
|
|
arc2 = VEllipticalArc (GetCenter(), d->radius1, d->radius2, d->formulaRadius1, d->formulaRadius2,
|
|
|
|
arc1.GetEndAngle(), arc1.GetFormulaF2(), GetEndAngle(), GetFormulaF2(), d->rotationAngle,
|
2016-12-17 02:41:33 +01:00
|
|
|
GetFormulaRotationAngle(), getIdObject(), getMode());
|
2016-02-26 20:30:20 +01:00
|
|
|
return arc1.GetP1();
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VEllipticalArc::CutArc(const qreal &length) const
|
|
|
|
{
|
2016-02-26 20:30:20 +01:00
|
|
|
VEllipticalArc arc1;
|
|
|
|
VEllipticalArc arc2;
|
|
|
|
return this->CutArc(length, arc1, arc2);
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-27 15:53:17 +01:00
|
|
|
void VEllipticalArc::CreateName()
|
2016-02-10 05:59:29 +01:00
|
|
|
{
|
2017-08-08 17:27:36 +02:00
|
|
|
QString name = ELARC_ + QString("%1").arg(this->GetCenter().name());
|
2016-02-27 15:53:17 +01:00
|
|
|
|
|
|
|
if (VAbstractCurve::id() != NULL_ID)
|
|
|
|
{
|
|
|
|
name += QString("_%1").arg(VAbstractCurve::id());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetDuplicate() > 0)
|
|
|
|
{
|
|
|
|
name += QString("_%1").arg(GetDuplicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
setName(name);
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VEllipticalArc::FindF2(qreal length)
|
|
|
|
{
|
2016-02-24 16:34:03 +01:00
|
|
|
qreal gap = 180;
|
|
|
|
if (length < 0)
|
|
|
|
{
|
2016-04-10 16:40:55 +02:00
|
|
|
SetFlipped(true);
|
2016-02-24 16:34:03 +01:00
|
|
|
gap = -gap;
|
|
|
|
}
|
|
|
|
while (length > MaxLength())
|
|
|
|
{
|
2018-01-05 18:41:09 +01:00
|
|
|
length = MaxLength();
|
2016-02-24 16:34:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need to calculate the second angle
|
|
|
|
// first approximation of angle between start and end angles
|
|
|
|
|
2017-09-13 08:17:21 +02:00
|
|
|
QLineF radius1(GetCenter().x(), GetCenter().y(), GetCenter().x() + d->radius1, GetCenter().y());
|
|
|
|
radius1.setAngle(GetStartAngle());
|
|
|
|
radius1.setAngle(radius1.angle() + gap);
|
|
|
|
qreal endAngle = radius1.angle();
|
2016-04-10 16:40:55 +02:00
|
|
|
|
|
|
|
// we need to set the end angle, because we want to use GetLength()
|
|
|
|
SetFormulaF2(QString::number(endAngle), endAngle);
|
2016-02-24 16:34:03 +01:00
|
|
|
|
|
|
|
qreal lenBez = GetLength(); // first approximation of length
|
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
const qreal eps = ToPixel(0.001, Unit::Mm);
|
2016-02-24 16:34:03 +01:00
|
|
|
|
|
|
|
while (qAbs(lenBez - length) > eps)
|
|
|
|
{
|
|
|
|
gap = gap/2;
|
2016-04-10 13:40:04 +02:00
|
|
|
if (gap < 0.0001)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-02-24 16:34:03 +01:00
|
|
|
if (lenBez > length)
|
|
|
|
{ // we selected too big end angle
|
2017-09-13 08:17:21 +02:00
|
|
|
radius1.setAngle(endAngle - qAbs(gap));
|
2016-02-24 16:34:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // we selected too little end angle
|
2017-09-13 08:17:21 +02:00
|
|
|
radius1.setAngle(endAngle + qAbs(gap));
|
2016-02-24 16:34:03 +01:00
|
|
|
}
|
2017-09-13 08:17:21 +02:00
|
|
|
endAngle = radius1.angle();
|
2016-02-26 20:27:55 +01:00
|
|
|
// we need to set d->f2, because we use it when we calculate GetLength
|
2016-04-10 16:40:55 +02:00
|
|
|
SetFormulaF2(QString::number(endAngle), endAngle);
|
2016-02-24 16:34:03 +01:00
|
|
|
lenBez = GetLength();
|
|
|
|
}
|
2016-04-10 16:40:55 +02:00
|
|
|
SetFormulaLength(QString::number(qApp->fromPixel(lenBez)));
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VEllipticalArc::MaxLength() const
|
|
|
|
{
|
2016-04-10 13:40:04 +02:00
|
|
|
const qreal h = qPow(d->radius1 - d->radius2, 2) / qPow(d->radius1 + d->radius2, 2);
|
|
|
|
const qreal ellipseLength = M_PI * (d->radius1 + d->radius2) * (1+3*h/(10+qSqrt(4-3*h)));
|
2016-02-19 10:43:46 +01:00
|
|
|
return ellipseLength;
|
2016-02-10 05:59:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 18:41:09 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VEllipticalArc::GetP(qreal angle) const
|
|
|
|
{
|
|
|
|
QLineF line(0, 0, 100, 0);
|
|
|
|
line.setAngle(angle);
|
|
|
|
|
|
|
|
const qreal a = line.p2().x() / GetRadius1();
|
|
|
|
const qreal b = line.p2().y() / GetRadius2();
|
|
|
|
const qreal k = qSqrt(a*a + b*b);
|
|
|
|
QPointF p(line.p2().x() / k, line.p2().y() / k);
|
|
|
|
|
|
|
|
QLineF line2(QPointF(), p);
|
|
|
|
SCASSERT(VFuzzyComparePossibleNulls(line2.angle(), line.angle()))
|
|
|
|
|
|
|
|
line2.setAngle(line2.angle() + GetRotationAngle());
|
|
|
|
return line2.p2() + VAbstractArc::GetCenter().toQPointF();
|
|
|
|
}
|
|
|
|
|
2016-02-10 05:59:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-12-17 02:41:33 +01:00
|
|
|
* @brief GetFormulaRadius1 return formula for major radius.
|
2016-02-10 05:59:29 +01:00
|
|
|
* @return radius.
|
|
|
|
*/
|
|
|
|
QString VEllipticalArc::GetFormulaRadius1() const
|
|
|
|
{
|
|
|
|
return d->formulaRadius1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-12-17 02:41:33 +01:00
|
|
|
* @brief GetFormulaRadius2 return formula for minor radius.
|
2016-02-10 05:59:29 +01:00
|
|
|
* @return radius.
|
|
|
|
*/
|
|
|
|
QString VEllipticalArc::GetFormulaRadius2() const
|
|
|
|
{
|
|
|
|
return d->formulaRadius2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-12 19:19:46 +01:00
|
|
|
/**
|
2016-12-17 02:41:33 +01:00
|
|
|
* @brief GetFormulaRotationAngle return formula for rotation angle.
|
2016-02-12 19:19:46 +01:00
|
|
|
* @return rotationAngle.
|
|
|
|
*/
|
2016-12-17 02:41:33 +01:00
|
|
|
QString VEllipticalArc::GetFormulaRotationAngle() const
|
2016-02-12 19:19:46 +01:00
|
|
|
{
|
2016-12-17 02:41:33 +01:00
|
|
|
return d->formulaRotationAngle;
|
2016-02-12 19:19:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-10 05:59:29 +01:00
|
|
|
void VEllipticalArc::SetFormulaRadius1(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaRadius1 = formula;
|
|
|
|
d->radius1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VEllipticalArc::SetFormulaRadius2(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaRadius2 = formula;
|
|
|
|
d->radius2 = value;
|
|
|
|
}
|
|
|
|
|
2016-12-17 02:41:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VEllipticalArc::SetFormulaRotationAngle(const QString &formula, qreal value)
|
|
|
|
{
|
|
|
|
d->formulaRotationAngle = formula;
|
|
|
|
d->rotationAngle = value;
|
|
|
|
}
|
|
|
|
|
2016-02-10 05:59:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-12-17 02:41:33 +01:00
|
|
|
* @brief GetRadius1 return elliptical arc major radius.
|
2016-02-10 05:59:29 +01:00
|
|
|
* @return string with formula.
|
|
|
|
*/
|
|
|
|
qreal VEllipticalArc::GetRadius1() const
|
|
|
|
{
|
|
|
|
return d->radius1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-12-17 02:41:33 +01:00
|
|
|
* @brief GetRadius2 return elliptical arc minor radius.
|
2016-02-10 05:59:29 +01:00
|
|
|
* @return string with formula.
|
|
|
|
*/
|
|
|
|
qreal VEllipticalArc::GetRadius2() const
|
|
|
|
{
|
|
|
|
return d->radius2;
|
|
|
|
}
|
2016-12-17 02:41:33 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetRotationAngle return rotation angle.
|
|
|
|
* @return rotationAngle.
|
|
|
|
*/
|
|
|
|
qreal VEllipticalArc::GetRotationAngle() const
|
|
|
|
{
|
|
|
|
return d->rotationAngle;
|
|
|
|
}
|