1 /************************************************************************
2  **
3  **  @file   vgobject.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   27 12, 2013
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2013-2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VGOBJECT_H
30 #define VGOBJECT_H
31 
32 #include <QSharedDataPointer>
33 #include <QString>
34 #include <QTypeInfo>
35 #include <QVector>
36 #include <QtGlobal>
37 
38 #include "vgeometrydef.h"
39 #include "../vmisc/def.h"
40 
41 class QLineF;
42 class QPoint;
43 class QPointF;
44 class QRectF;
45 class VGObjectData;
46 class QTransform;
47 
48 /**
49  * @brief The VGObject class keep information graphical objects.
50  */
51 class VGObject
52 {
53 public:
54     VGObject();
55     explicit VGObject(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation);
56     VGObject(const VGObject &obj);
57 
58     virtual ~VGObject();
59 
60     VGObject& operator= (const VGObject &obj);
61 #ifdef Q_COMPILER_RVALUE_REFS
62     VGObject(const VGObject &&obj) Q_DECL_NOTHROW;
63     VGObject &operator=(VGObject &&obj) Q_DECL_NOTHROW;
64 #endif
65 
66     quint32         getIdObject() const;
67     void            setIdObject(const quint32 &value);
68 
69     virtual QString name() const;
70     void            setName(const QString &name);
71 
72     Draw            getMode() const;
73     void            setMode(const Draw &value);
74 
75     GOType          getType() const;
76     void            setType(const GOType &type);
77 
78     quint32         id() const;
79     virtual void    setId(const quint32 &id);
80 
81     virtual void    SetAlias(const QString &alias);
82     QString         GetAlias() const;
83 
84     virtual void    SetAliasSuffix(const QString &aliasSuffix);
85     QString         GetAliasSuffix() const;
86 
87     QString ObjectName() const;
88 
89     quint32         getIdTool() const;
90 
91     virtual QJsonObject ToJson() const;
92 
93     static QLineF  BuildLine(const QPointF &p1, const qreal& length, const qreal &angle);
94     static QPointF BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect);
95     static QLineF  BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect);
96     static QLineF  BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect);
97 
98     static int     ContactPoints (const QPointF &p, const QPointF &center, qreal radius, QPointF &p1, QPointF &p2);
99     static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line);
100     static int     IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1,
101                                        QPointF &p2);
102     static qint32  LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1,
103                                        QPointF &p2);
104     static QPointF ClosestPoint(const QLineF &line, const QPointF &point);
105     static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k);
106     static void    LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
107     static bool    IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2,
108                                          qreal accuracy = accuracyPointOnLine);
109     static bool    IsLineSegmentOnLineSegment (const QLineF &seg1, const QLineF &seg2,
110                                                qreal accuracy = accuracyPointOnLine);
111     static QPointF CorrectDistortion(const QPointF &t, const QPointF &p1, const QPointF &p2);
112     static bool    IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2,
113                                        qreal accuracy = accuracyPointOnLine);
114     static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
115 protected:
116     static QTransform FlippingMatrix(const QLineF &axis);
117 private:
118     QSharedDataPointer<VGObjectData> d;
119 
120     static int     PointInCircle (const QPointF &p, const QPointF &center, qreal radius);
121 };
122 
123 Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE);
124 
125 #endif // VGOBJECT_H
126