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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/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"
|
2013-12-29 17:48:57 +01:00
|
|
|
#include "vspline.h"
|
2013-11-06 16:49:07 +01:00
|
|
|
#include "../exception/vexception.h"
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QDebug>
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-11-12 13:48:45 +01:00
|
|
|
class QRectF;
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VArc::VArc ()
|
2013-12-29 17:48:57 +01:00
|
|
|
:VGObject(GObject::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0),
|
|
|
|
formulaRadius(QString()), center(VPointF())
|
|
|
|
{
|
|
|
|
}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
|
2014-03-11 12:43:24 +01:00
|
|
|
QString formulaF2, quint32 idObject, Valentina::Draws mode)
|
2013-12-31 09:44:54 +01:00
|
|
|
: VGObject(GObject::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2),
|
|
|
|
radius(radius), formulaRadius(formulaRadius), center(center)
|
2013-11-12 13:48:45 +01:00
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
_name = QString ("Arc_%1").arg(this->GetCenter().name());
|
2013-11-12 13:48:45 +01:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VArc::VArc(const VArc &arc)
|
2013-12-29 17:48:57 +01:00
|
|
|
: VGObject(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()),
|
2013-08-28 10:55:11 +02:00
|
|
|
formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()),
|
2013-12-29 17:48:57 +01:00
|
|
|
center(arc.GetCenter())
|
|
|
|
{
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VArc &VArc::operator =(const VArc &arc)
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
VGObject::operator=(arc);
|
2013-08-13 18:48:36 +02:00
|
|
|
this->f1 = arc.GetF1();
|
|
|
|
this->formulaF1 = arc.GetFormulaF1();
|
|
|
|
this->f2 = arc.GetF2();
|
|
|
|
this->formulaF2 = arc.GetFormulaF2();
|
|
|
|
this->radius = arc.GetRadius();
|
|
|
|
this->formulaRadius = arc.GetFormulaRadius();
|
|
|
|
this->center = arc.GetCenter();
|
|
|
|
return *this;
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-01-10 10:16:55 +01:00
|
|
|
qreal VArc::GetLength() const
|
|
|
|
{
|
|
|
|
return (M_PI * radius)/180 * AngleArc();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
QPointF VArc::GetP1() const
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
QPointF p1 ( GetCenter().x () + radius, GetCenter().y () );
|
|
|
|
QLineF centerP1(GetCenter().toQPointF(), p1);
|
2013-08-05 10:37:56 +02:00
|
|
|
centerP1.setAngle(f1);
|
2013-08-06 09:56:09 +02:00
|
|
|
return centerP1.p2();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
QPointF VArc::GetP2 () const
|
|
|
|
{
|
2013-12-29 17:48:57 +01:00
|
|
|
QPointF p2 ( GetCenter().x () + radius, GetCenter().y () );
|
|
|
|
QLineF centerP2(GetCenter().toQPointF(), p2);
|
2013-08-05 10:37:56 +02:00
|
|
|
centerP2.setAngle(f2);
|
2013-08-06 09:56:09 +02:00
|
|
|
return centerP2.p2();
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
QPainterPath VArc::GetPath() const
|
|
|
|
{
|
2014-01-10 10:16:55 +01:00
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
QVector<QPointF> points = GetPoints();
|
|
|
|
if (points.count() >= 2)
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < points.count()-1; ++i)
|
|
|
|
{
|
|
|
|
path.moveTo(points[i]);
|
|
|
|
path.lineTo(points[i+1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"points.count() < 2"<<Q_FUNC_INFO;
|
2014-01-10 10:16:55 +01:00
|
|
|
}
|
|
|
|
return path;
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
qreal VArc::AngleArc() const
|
|
|
|
{
|
|
|
|
QLineF l1(0, 0, 100, 100);
|
2013-08-28 10:55:11 +02:00
|
|
|
l1.setAngle(f1);
|
2013-11-04 21:35:15 +01:00
|
|
|
QLineF l2(0, 0, 100, 100);
|
2013-08-28 10:55:11 +02:00
|
|
|
l2.setAngle(f2);
|
|
|
|
return l1.angleTo(l2);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
QVector<QPointF> VArc::GetPoints() const
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
QVector<QPointF> points;
|
2014-01-10 10:16:55 +01:00
|
|
|
qreal i = 0;
|
2014-01-11 11:11:42 +01:00
|
|
|
qreal angle = AngleArc();
|
|
|
|
qint32 k = static_cast<qint32>(angle);
|
|
|
|
qreal s = angle/(k/4);
|
2014-01-10 10:16:55 +01:00
|
|
|
do
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-01-10 10:16:55 +01:00
|
|
|
QLineF line(center.toQPointF(), GetP1());
|
|
|
|
line.setAngle(line.angle()+i);
|
|
|
|
points.append(line.p2());
|
2014-01-11 11:11:42 +01:00
|
|
|
i = i + s;
|
2014-01-27 17:01:24 +01:00
|
|
|
if (i > angle)
|
2014-01-11 11:11:42 +01:00
|
|
|
{
|
|
|
|
QLineF line(center.toQPointF(), GetP1());
|
|
|
|
line.setAngle(line.angle()+angle);
|
|
|
|
points.append(line.p2());
|
|
|
|
}
|
2014-01-27 17:01:24 +01:00
|
|
|
} while (i <= angle);
|
2013-08-28 10:55:11 +02:00
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2014-01-10 10:16:55 +01:00
|
|
|
QString VArc::name() const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-01-10 10:16:55 +01:00
|
|
|
return _name;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2014-01-08 15:05:32 +01:00
|
|
|
|
|
|
|
QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const
|
|
|
|
{
|
|
|
|
//Always need return two arcs, so we must correct wrong length.
|
|
|
|
qreal len = 0;
|
|
|
|
if (length < this->GetLength()*0.02)
|
|
|
|
{
|
|
|
|
len = this->GetLength()*0.02;
|
|
|
|
}
|
|
|
|
else if ( length > this->GetLength()*0.98)
|
|
|
|
{
|
|
|
|
len = this->GetLength()*0.98;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal n = (len*180)/(M_PI*radius);
|
|
|
|
QLineF line(GetCenter().toQPointF(), GetP1());
|
|
|
|
line.setAngle(line.angle()+n);
|
|
|
|
|
|
|
|
arc1 = VArc (center, radius, formulaRadius, f1, formulaF1, line.angle(), QString().setNum(line.angle()),
|
|
|
|
idObject, mode);
|
|
|
|
|
|
|
|
arc2 = VArc (center, radius, formulaRadius, line.angle(), QString().setNum(line.angle()), f2, formulaF2,
|
|
|
|
idObject, mode);
|
2014-01-10 10:16:55 +01:00
|
|
|
return line.p2();
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:40:24 +01:00
|
|
|
void VArc::setId(const quint32 &id)
|
2014-01-10 10:16:55 +01:00
|
|
|
{
|
|
|
|
_id = id;
|
|
|
|
_name = QString ("Arc_%1_%2").arg(center.name()).arg(id);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|