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 vpointf.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
|
2013-11-15 13:41:26 +01:00
|
|
|
** <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-07-13 12:51:31 +02:00
|
|
|
#include "vpointf.h"
|
2014-08-20 16:20:53 +02:00
|
|
|
#include "vpointf_p.h"
|
2016-04-10 13:40:04 +02:00
|
|
|
#include <QLineF>
|
2014-06-08 20:10:57 +02:00
|
|
|
#include <QPointF>
|
|
|
|
#include <QString>
|
2016-09-10 15:40:38 +02:00
|
|
|
#include <QTransform>
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2014-08-20 16:20:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VPointF creat empty point
|
|
|
|
*/
|
|
|
|
VPointF::VPointF()
|
|
|
|
:VGObject(GOType::Point, 0, Draw::Calculation), d(new VPointFData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF::VPointF(const VPointF &point)
|
|
|
|
:VGObject(point), d(point.d)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF::VPointF(const QPointF &point)
|
|
|
|
:VGObject(VPointF()), d(new VPointFData(point))
|
|
|
|
{}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-01 09:35:13 +02:00
|
|
|
/**
|
|
|
|
* @brief VPointF create new point
|
|
|
|
* @param x x coordinate
|
|
|
|
* @param y y coordinate
|
2014-07-25 13:53:39 +02:00
|
|
|
* @param name point label
|
2014-06-01 09:35:13 +02:00
|
|
|
* @param mx offset name respect to x
|
|
|
|
* @param my offset name respect to y
|
|
|
|
*/
|
2014-07-25 13:53:39 +02:00
|
|
|
VPointF::VPointF(qreal x, qreal y, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
|
2014-08-20 16:20:53 +02:00
|
|
|
:VGObject(GOType::Point, idObject, mode), d(new VPointFData(x, y, mx, my))
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 14:01:35 +02:00
|
|
|
setName(name);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VPointF create new point
|
|
|
|
* @param point point
|
|
|
|
* @param name point label
|
|
|
|
* @param mx offset name respect to x
|
|
|
|
* @param my offset name respect to y
|
|
|
|
*/
|
|
|
|
VPointF::VPointF(const QPointF &point, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
|
2014-08-20 16:20:53 +02:00
|
|
|
:VGObject(GOType::Point, idObject, mode), d(new VPointFData(point, mx, my))
|
2014-07-25 13:53:39 +02:00
|
|
|
{
|
2014-08-20 14:01:35 +02:00
|
|
|
setName(name);
|
2014-07-25 13:53:39 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-20 16:20:53 +02:00
|
|
|
VPointF::~VPointF()
|
2014-05-02 13:11:30 +02:00
|
|
|
{}
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2014-06-02 09:43:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-01 09:35:13 +02:00
|
|
|
/**
|
|
|
|
* @brief operator = assignment operator
|
|
|
|
* @param point point
|
|
|
|
* @return point
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VPointF &VPointF::operator =(const VPointF &point)
|
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
if ( &point == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
VGObject::operator=(point);
|
2014-08-20 16:20:53 +02:00
|
|
|
d = point.d;
|
2013-09-29 12:29:29 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2014-06-01 09:35:13 +02:00
|
|
|
|
2016-04-10 13:40:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-05-20 17:55:21 +02:00
|
|
|
VPointF::operator QPointF() const
|
2014-06-08 20:10:57 +02:00
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
return toQPointF();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const
|
|
|
|
{
|
|
|
|
const QPointF p = RotatePF(originPoint, toQPointF(), degrees);
|
2017-09-20 11:10:57 +02:00
|
|
|
VPointF rotated(p, name() + prefix, mx(), my());
|
|
|
|
rotated.SetShowLabel(IsShowLabel());
|
|
|
|
return rotated;
|
2014-08-20 16:20:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-10 15:40:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const
|
|
|
|
{
|
2016-09-10 17:18:11 +02:00
|
|
|
const QPointF p = FlipPF(axis, toQPointF());
|
2017-09-20 11:10:57 +02:00
|
|
|
VPointF flipped(p, name() + prefix, mx(), my());
|
|
|
|
flipped.SetShowLabel(IsShowLabel());
|
|
|
|
return flipped;
|
2016-09-10 15:40:38 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 16:34:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const
|
|
|
|
{
|
|
|
|
const QPointF p = MovePF(toQPointF(), length, angle);
|
2017-09-20 11:10:57 +02:00
|
|
|
VPointF moved(p, name() + prefix, mx(), my());
|
|
|
|
moved.SetShowLabel(IsShowLabel());
|
|
|
|
return moved;
|
2016-10-04 16:34:37 +02:00
|
|
|
}
|
|
|
|
|
2014-08-20 16:20:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief mx return offset name respect to x
|
|
|
|
* @return offset
|
|
|
|
*/
|
|
|
|
qreal VPointF::mx() const
|
|
|
|
{
|
|
|
|
return d->_mx;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief my return offset name respect to y
|
|
|
|
* @return offset
|
|
|
|
*/
|
|
|
|
qreal VPointF::my() const
|
|
|
|
{
|
|
|
|
return d->_my;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief setMx set offset name respect to x
|
|
|
|
* @param mx offset
|
|
|
|
*/
|
|
|
|
void VPointF::setMx(qreal mx)
|
|
|
|
{
|
|
|
|
d->_mx = mx;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief setMy set offset name respect to y
|
|
|
|
* @param my offset
|
|
|
|
*/
|
|
|
|
void VPointF::setMy(qreal my)
|
|
|
|
{
|
|
|
|
d->_my = my;
|
|
|
|
}
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VPointF::toQPointF() const
|
|
|
|
{
|
|
|
|
return QPointF(d->_x, d->_y);
|
|
|
|
}
|
|
|
|
|
2014-08-20 16:20:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief x return x coordinate
|
|
|
|
* @return value
|
|
|
|
*/
|
|
|
|
qreal VPointF::x() const
|
|
|
|
{
|
|
|
|
return d->_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief setX set x coordinate
|
|
|
|
* @param value x coordinate
|
|
|
|
*/
|
|
|
|
void VPointF::setX(const qreal &value)
|
|
|
|
{
|
|
|
|
d->_x = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief y return y coordinate
|
|
|
|
* @return value
|
|
|
|
*/
|
|
|
|
qreal VPointF::y() const
|
|
|
|
{
|
|
|
|
return d->_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief setY set y coordinate
|
|
|
|
* @param value y coordinate
|
|
|
|
*/
|
|
|
|
void VPointF::setY(const qreal &value)
|
|
|
|
{
|
|
|
|
d->_y = value;
|
2014-06-08 20:10:57 +02:00
|
|
|
}
|
2016-04-10 13:40:04 +02:00
|
|
|
|
2017-09-16 16:25:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VPointF::IsShowLabel() const
|
|
|
|
{
|
|
|
|
return d->m_showLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-17 08:17:37 +02:00
|
|
|
void VPointF::SetShowLabel(bool hide)
|
2017-09-16 16:25:14 +02:00
|
|
|
{
|
|
|
|
d->m_showLabel = hide;
|
|
|
|
}
|
|
|
|
|
2016-04-10 13:40:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees)
|
|
|
|
{
|
|
|
|
QLineF axis(originPoint, point);
|
|
|
|
axis.setAngle(axis.angle() + degrees);
|
|
|
|
return axis.p2();
|
|
|
|
}
|
2016-09-10 17:18:11 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point)
|
|
|
|
{
|
|
|
|
const QTransform matrix = FlippingMatrix(axis);
|
|
|
|
return matrix.map(point);
|
|
|
|
}
|
2016-10-04 16:34:37 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VPointF::MovePF(const QPointF &originPoint, qreal length, qreal angle)
|
|
|
|
{
|
|
|
|
QLineF line(originPoint.x(), originPoint.y(), originPoint.x() + length, originPoint.y());
|
|
|
|
line.setAngle(angle);
|
|
|
|
return line.p2();
|
|
|
|
}
|