2013-12-29 17:48:57 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vgobject.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-12-29 17:48:57 +01:00
|
|
|
** @date 27 12, 2013
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-12-29 17:48:57 +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-12-29 17:48:57 +01:00
|
|
|
** <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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VGOBJECT_H
|
|
|
|
#define VGOBJECT_H
|
|
|
|
|
2014-08-20 14:01:35 +02:00
|
|
|
#include <QSharedDataPointer>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QString>
|
|
|
|
#include <QTypeInfo>
|
2014-12-21 21:33:31 +01:00
|
|
|
#include <QVector>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#include "vgeometrydef.h"
|
2018-07-25 10:26:09 +02:00
|
|
|
#include "../vmisc/def.h"
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
class QLineF;
|
2015-12-03 20:56:40 +01:00
|
|
|
class QPoint;
|
2014-10-23 10:38:57 +02:00
|
|
|
class QPointF;
|
|
|
|
class QRectF;
|
2016-08-08 13:44:49 +02:00
|
|
|
class VGObjectData;
|
2016-09-10 15:40:38 +02:00
|
|
|
class QTransform;
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-01-21 15:04:17 +01:00
|
|
|
/**
|
|
|
|
* @brief The VGObject class keep information graphical objects.
|
|
|
|
*/
|
2013-12-30 20:33:30 +01:00
|
|
|
class VGObject
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
VGObject();
|
2015-10-20 16:32:01 +02:00
|
|
|
explicit VGObject(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation);
|
2013-12-29 17:48:57 +01:00
|
|
|
VGObject(const VGObject &obj);
|
2017-04-19 12:27:17 +02:00
|
|
|
|
2014-08-20 14:01:35 +02:00
|
|
|
virtual ~VGObject();
|
|
|
|
|
2017-04-19 12:27:17 +02:00
|
|
|
VGObject& operator= (const VGObject &obj);
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
VGObject &operator=(VGObject &&obj) Q_DECL_NOTHROW { Swap(obj); return *this; }
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 12:32:06 +02:00
|
|
|
inline void Swap(VGObject &obj) Q_DECL_NOTHROW
|
2017-04-19 12:27:17 +02:00
|
|
|
{ std::swap(d, obj.d); }
|
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
quint32 getIdObject() const;
|
|
|
|
void setIdObject(const quint32 &value);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
virtual QString name() const;
|
|
|
|
void setName(const QString &name);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
Draw getMode() const;
|
|
|
|
void setMode(const Draw &value);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
GOType getType() const;
|
2014-08-20 14:01:35 +02:00
|
|
|
void setType(const GOType &type);
|
|
|
|
|
2014-07-25 13:53:39 +02:00
|
|
|
quint32 id() const;
|
|
|
|
virtual void setId(const quint32 &id);
|
2014-10-23 10:38:57 +02:00
|
|
|
|
2016-02-02 14:38:30 +01:00
|
|
|
quint32 getIdTool() const;
|
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
static QLineF BuildLine(const QPointF &p1, const qreal& length, const qreal &angle);
|
|
|
|
static QPointF BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect);
|
|
|
|
static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect);
|
|
|
|
static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect);
|
|
|
|
|
2015-06-05 15:43:41 +02:00
|
|
|
static int ContactPoints (const QPointF &p, const QPointF ¢er, qreal radius, QPointF &p1, QPointF &p2);
|
2014-11-11 09:16:37 +01:00
|
|
|
static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line);
|
2015-05-25 14:49:28 +02:00
|
|
|
static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1,
|
|
|
|
QPointF &p2);
|
2014-10-23 10:38:57 +02:00
|
|
|
static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1,
|
|
|
|
QPointF &p2);
|
|
|
|
static QPointF ClosestPoint(const QLineF &line, const QPointF &point);
|
|
|
|
static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k);
|
|
|
|
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
|
2016-01-08 16:59:51 +01:00
|
|
|
static bool IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2);
|
2016-05-26 10:26:54 +02:00
|
|
|
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2);
|
2014-12-16 14:33:00 +01:00
|
|
|
|
2016-11-29 13:10:53 +01:00
|
|
|
template <typename T>
|
|
|
|
static QVector<T> GetReversePoints(const QVector<T> &points);
|
2014-12-16 14:33:00 +01:00
|
|
|
static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
|
2016-08-16 17:23:38 +02:00
|
|
|
|
2016-12-08 12:56:17 +01:00
|
|
|
static const double accuracyPointOnLine;
|
2016-09-10 15:40:38 +02:00
|
|
|
protected:
|
|
|
|
static QTransform FlippingMatrix(const QLineF &axis);
|
2014-08-20 14:01:35 +02:00
|
|
|
private:
|
|
|
|
QSharedDataPointer<VGObjectData> d;
|
2015-05-07 11:39:08 +02:00
|
|
|
|
2017-02-12 14:02:07 +01:00
|
|
|
static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t);
|
|
|
|
static double GetEpsilon(const QPointF &p1, const QPointF &p2);
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
static int PointInCircle (const QPointF &p, const QPointF ¢er, qreal radius);
|
2013-12-29 17:48:57 +01:00
|
|
|
};
|
|
|
|
|
2016-11-29 13:10:53 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetReversePoint return revers container of points.
|
|
|
|
* @param points container with points.
|
|
|
|
* @return reverced points.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
QVector<T> VGObject::GetReversePoints(const QVector<T> &points)
|
|
|
|
{
|
|
|
|
if (points.isEmpty())
|
|
|
|
{
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
QVector<T> reversePoints(points.size());
|
|
|
|
qint32 j = 0;
|
|
|
|
for (qint32 i = points.size() - 1; i >= 0; --i)
|
|
|
|
{
|
|
|
|
reversePoints.replace(j, points.at(i));
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
return reversePoints;
|
|
|
|
}
|
|
|
|
|
2015-11-25 19:56:17 +01:00
|
|
|
Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE);
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
#endif // VGOBJECT_H
|