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
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2013-12-29 17:48:57 +01:00
|
|
|
**
|
|
|
|
** 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
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
#include <QPainterPath>
|
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
|
|
|
|
2021-09-25 16:18:33 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
|
|
|
|
|
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();
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto operator= (const VGObject &obj) -> VGObject&;
|
2017-04-19 12:27:17 +02:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
2023-07-13 16:49:20 +02:00
|
|
|
VGObject(VGObject &&obj) noexcept;
|
|
|
|
auto operator=(VGObject &&obj) noexcept -> VGObject &;
|
2017-04-19 12:27:17 +02:00
|
|
|
#endif
|
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto getIdObject() const -> quint32;
|
|
|
|
void setIdObject(const quint32 &value);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
virtual auto name() const -> QString;
|
|
|
|
void setName(const QString &name);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto getMode() const -> Draw;
|
|
|
|
void setMode(const Draw &value);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto getType() const -> GOType;
|
|
|
|
void setType(const GOType &type);
|
2014-08-20 14:01:35 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto id() const -> quint32;
|
|
|
|
virtual void setId(const quint32 &id);
|
2014-10-23 10:38:57 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
virtual void SetAlias(const QString &alias);
|
|
|
|
auto GetAlias() const -> QString;
|
2020-11-04 09:55:34 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
virtual void SetAliasSuffix(const QString &aliasSuffix);
|
|
|
|
auto GetAliasSuffix() const -> QString;
|
2020-11-04 09:55:34 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto ObjectName() const -> QString;
|
2020-11-04 09:55:34 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
auto getIdTool() const -> quint32;
|
2016-02-02 14:38:30 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
virtual auto ToJson() const -> QJsonObject;
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
static auto BuildLine(const QPointF &p1, const qreal& length, const qreal &angle) -> QLineF;
|
|
|
|
static auto BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect) -> QPointF;
|
|
|
|
static auto BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect) -> QLineF;
|
|
|
|
static auto BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect) -> QLineF;
|
|
|
|
|
|
|
|
static auto ContactPoints (const QPointF &p, const QPointF ¢er, qreal radius, QPointF &p1, QPointF &p2) -> int;
|
|
|
|
static auto LineIntersectRect(const QRectF &rec, const QLineF &line) -> QPointF;
|
|
|
|
static auto IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1,
|
|
|
|
QPointF &p2) -> int;
|
|
|
|
static auto LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1,
|
|
|
|
QPointF &p2) -> qint32;
|
|
|
|
static auto ClosestPoint(const QLineF &line, const QPointF &point) -> QPointF;
|
|
|
|
static auto addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k) -> QPointF;
|
|
|
|
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
|
|
|
|
static auto IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2,
|
|
|
|
qreal accuracy = accuracyPointOnLine) -> bool;
|
|
|
|
static auto IsLineSegmentOnLineSegment (const QLineF &seg1, const QLineF &seg2,
|
|
|
|
qreal accuracy = accuracyPointOnLine) -> bool;
|
|
|
|
static auto CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2) -> QPointF;
|
|
|
|
static auto IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2,
|
|
|
|
qreal accuracy = accuracyPointOnLine) -> bool;
|
|
|
|
static auto GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints) -> int;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static auto PainterPath(const QVector<T> &points) -> QPainterPath;
|
2014-10-23 10:38:57 +02:00
|
|
|
|
2016-09-10 15:40:38 +02:00
|
|
|
protected:
|
2023-05-02 16:38:30 +02:00
|
|
|
static auto FlippingMatrix(const QLineF &axis) -> QTransform;
|
2014-08-20 14:01:35 +02:00
|
|
|
private:
|
|
|
|
QSharedDataPointer<VGObjectData> d;
|
2015-05-07 11:39:08 +02:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
static auto PointInCircle (const QPointF &p, const QPointF ¢er, qreal radius) -> int;
|
2013-12-29 17:48:57 +01:00
|
|
|
};
|
|
|
|
|
2021-09-25 16:18:33 +02:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE); // NOLINT
|
2015-11-25 19:56:17 +01:00
|
|
|
|
2023-05-02 16:38:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
inline auto VGObject::PainterPath(const QVector<T> &points) -> QPainterPath
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
if (not points.isEmpty())
|
|
|
|
{
|
|
|
|
path.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
path.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
path.lineTo(points.at(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
#endif // VGOBJECT_H
|