valentina/src/libs/vgeometry/vgobject.h

154 lines
5.5 KiB
C
Raw Normal View History

/************************************************************************
**
** @file vgobject.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 27 12, 2013
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 Valentina project
** <https://gitlab.com/smart-pattern/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
2023-05-02 16:38:30 +02:00
#include <QPainterPath>
#include <QSharedDataPointer>
#include <QString>
#include <QTypeInfo>
#include <QVector>
#include <QtGlobal>
#include "../vmisc/def.h"
2024-01-06 13:20:56 +01:00
#include "vgeometrydef.h"
class QLineF;
class QPoint;
class QPointF;
class QRectF;
class VGObjectData;
class QTransform;
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")
/**
* @brief The VGObject class keep information graphical objects.
*/
class VGObject
{
public:
VGObject();
2015-10-20 16:32:01 +02:00
explicit VGObject(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation);
VGObject(const VGObject &obj);
virtual ~VGObject();
2024-01-06 13:20:56 +01:00
auto operator=(const VGObject &obj) -> VGObject &;
2024-02-19 10:14:02 +01:00
2023-07-13 16:49:20 +02:00
VGObject(VGObject &&obj) noexcept;
auto operator=(VGObject &&obj) noexcept -> VGObject &;
2023-05-02 16:38:30 +02:00
auto getIdObject() const -> quint32;
void setIdObject(const quint32 &value);
2023-05-02 16:38:30 +02:00
virtual auto name() const -> QString;
void setName(const QString &name);
2023-05-02 16:38:30 +02:00
auto getMode() const -> Draw;
void setMode(const Draw &value);
2023-05-02 16:38:30 +02:00
auto getType() const -> GOType;
void setType(const GOType &type);
2023-05-02 16:38:30 +02:00
auto id() const -> quint32;
virtual void setId(const quint32 &id);
2023-05-02 16:38:30 +02:00
virtual void SetAlias(const QString &alias);
auto GetAlias() const -> QString;
2023-05-02 16:38:30 +02:00
virtual void SetAliasSuffix(const QString &aliasSuffix);
auto GetAliasSuffix() const -> QString;
2023-05-02 16:38:30 +02:00
auto ObjectName() const -> QString;
2023-05-02 16:38:30 +02:00
auto getIdTool() const -> quint32;
2023-05-02 16:38:30 +02:00
virtual auto ToJson() const -> QJsonObject;
2024-01-06 13:20:56 +01:00
static auto BuildLine(const QPointF &p1, const qreal &length, const qreal &angle) -> QLineF;
2023-05-02 16:38:30 +02:00
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;
2024-01-06 13:20:56 +01:00
static auto ContactPoints(const QPointF &p, const QPointF &center, qreal radius, QPointF &p1, QPointF &p2) -> int;
2023-05-02 16:38:30 +02:00
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;
2024-01-06 13:20:56 +01:00
static auto LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2)
-> qint32;
2023-05-02 16:38:30 +02:00
static auto ClosestPoint(const QLineF &line, const QPointF &point) -> QPointF;
2024-01-06 13:20:56 +01:00
static auto addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k) -> QPointF;
2023-05-02 16:38:30 +02:00
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
2024-01-06 13:20:56 +01:00
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;
2023-05-02 16:38:30 +02:00
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;
2024-01-06 13:20:56 +01:00
template <class T> static auto PainterPath(const QVector<T> &points) -> QPainterPath;
2023-05-02 16:38:30 +02:00
static auto FlippingMatrix(const QLineF &axis) -> QTransform;
2024-01-06 13:20:56 +01:00
private:
QSharedDataPointer<VGObjectData> d;
2024-01-06 13:20:56 +01:00
static auto PointInCircle(const QPointF &p, const QPointF &center, qreal radius) -> int;
};
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
2023-05-02 16:38:30 +02:00
//---------------------------------------------------------------------------------------------------------------------
2024-01-06 13:20:56 +01:00
template <class T> inline auto VGObject::PainterPath(const QVector<T> &points) -> QPainterPath
2023-05-02 16:38:30 +02:00
{
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;
}
#endif // VGOBJECT_H