Seamly2D
Code documentation
vgobject.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vgobject.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 27 12, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VGOBJECT_H
53 #define VGOBJECT_H
54 
55 #include <QSharedDataPointer>
56 #include <QString>
57 #include <QTypeInfo>
58 #include <QVector>
59 #include <QtGlobal>
60 
61 #include "vgeometrydef.h"
62 
63 class QLineF;
64 class QPoint;
65 class QPointF;
66 class QRectF;
67 class VGObjectData;
68 class QTransform;
69 
70 /**
71  * @brief The VGObject class keep information graphical objects.
72  */
73 class VGObject
74 {
75 public:
76  VGObject();
77  explicit VGObject(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation);
78  VGObject(const VGObject &obj);
79 
80  virtual ~VGObject();
81 
82  VGObject& operator= (const VGObject &obj);
83 #ifdef Q_COMPILER_RVALUE_REFS
84  VGObject &operator=(VGObject &&obj) Q_DECL_NOTHROW;
85 #endif
86 
87  void Swap(VGObject &obj) Q_DECL_NOTHROW;
88  quint32 getIdObject() const;
89  void setIdObject(const quint32 &value);
90 
91  virtual QString name() const;
92  void setName(const QString &name);
93 
94  Draw getMode() const;
95  void setMode(const Draw &value);
96 
97  GOType getType() const;
98  void setType(const GOType &type);
99 
100  quint32 id() const;
101  virtual void setId(const quint32 &id);
102 
103  quint32 getIdTool() const;
104 
105  static QLineF BuildLine(const QPointF &p1, const qreal& length, const qreal &angle);
106  static QPointF BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect);
107  static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect);
108  static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect);
109 
110  static int ContactPoints (const QPointF &p, const QPointF &center, qreal radius, QPointF &p1, QPointF &p2);
111  static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line);
112  static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1,
113  QPointF &p2);
114  static qint32 LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1,
115  QPointF &p2);
116  static QPointF ClosestPoint(const QLineF &line, const QPointF &point);
117  static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k);
118  static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
119  static bool IsPointOnLineSegment (const QPointF &t, const QPointF &p1, const QPointF &p2);
120  static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2);
121 
122  template <typename T>
123  static QVector<T> GetReversePoints(const QVector<T> &points);
124  static int GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints);
125 
126  static const double accuracyPointOnLine;
127 protected:
128  static QTransform flipTransform(const QLineF &axis);
129 private:
130  QSharedDataPointer<VGObjectData> d;
131 
132  static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t);
133  static double GetEpsilon(const QPointF &p1, const QPointF &p2);
134 
135  static int PointInCircle (const QPointF &p, const QPointF &center, qreal radius);
136 };
137 
138 //---------------------------------------------------------------------------------------------------------------------
139 /**
140  * @brief GetReversePoint return revers container of points.
141  * @param points container with points.
142  * @return reverced points.
143  */
144 template <typename T>
146 {
147  if (points.isEmpty())
148  {
149  return points;
150  }
151  QVector<T> reversePoints(points.size());
152  qint32 j = 0;
153  for (qint32 i = points.size() - 1; i >= 0; --i)
154  {
155  reversePoints.replace(j, points.at(i));
156  ++j;
157  }
158  return reversePoints;
159 }
160 
161 Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE);
162 
163 #endif // VGOBJECT_H
The VGObject class keep information graphical objects.
Definition: vgobject.h:74
static bool IsPointOnLineSegment(const QPointF &t, const QPointF &p1, const QPointF &p2)
IsPointOnLineSegment Check if the point is on the line segment.
Definition: vgobject.cpp:484
static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t)
PerpDotProduct Calculates the area of the parallelogram of the three points. This is actually the sam...
Definition: vgobject.cpp:530
GOType getType() const
getType return object type.
Definition: vgobject.cpp:188
static double GetEpsilon(const QPointF &p1, const QPointF &p2)
GetEpsilon solve the floating-point accuraccy problem.
Definition: vgobject.cpp:545
void setMode(const Draw &value)
setMode set mode creation.
Definition: vgobject.cpp:178
void setType(const GOType &type)
Definition: vgobject.cpp:195
void setIdObject(const quint32 &value)
setIdObject set parent id.
Definition: vgobject.cpp:138
static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect)
Definition: vgobject.cpp:271
static qint32 LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2)
LineIntersectCircle find point intersection line and circle.
Definition: vgobject.cpp:391
VGObject()
VGObject default constructor.
Definition: vgobject.cpp:79
static QPointF ClosestPoint(const QLineF &line, const QPointF &point)
ClosestPoint find point projection of point onto line.
Definition: vgobject.cpp:436
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
VGObject & operator=(const VGObject &obj)
operator = assignment operator.
Definition: vgobject.cpp:109
static QTransform flipTransform(const QLineF &axis)
Definition: vgobject.cpp:591
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c)
LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0.
Definition: vgobject.cpp:469
static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2)
Definition: vgobject.cpp:342
static QVector< T > GetReversePoints(const QVector< T > &points)
GetReversePoint return revers container of points.
Definition: vgobject.h:145
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2)
IsPointOnLineviaPDP use the perp dot product (PDP) way.
Definition: vgobject.cpp:516
static int PointInCircle(const QPointF &p, const QPointF &center, qreal radius)
Definition: vgobject.cpp:555
static QPointF BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect)
Definition: vgobject.cpp:251
virtual ~VGObject()
Definition: vgobject.cpp:120
static QLineF BuildLine(const QPointF &p1, const qreal &length, const qreal &angle)
Definition: vgobject.cpp:241
QSharedDataPointer< VGObjectData > d
Definition: vgobject.h:130
void Swap(VGObject &obj) Q_DECL_NOTHROW
Definition: vgobject.cpp:72
quint32 getIdObject() const
getIdObject return parent id.
Definition: vgobject.cpp:128
static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line)
LineIntersectRect find point intersection line and rect.
Definition: vgobject.cpp:313
void setName(const QString &name)
setName set name graphical object.
Definition: vgobject.cpp:158
Draw getMode() const
getMode return mode creation.
Definition: vgobject.cpp:168
quint32 id() const
id return id object.
Definition: vgobject.cpp:205
virtual void setId(const quint32 &id)
setId set id object.
Definition: vgobject.cpp:215
static QPointF addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k)
Definition: vgobject.cpp:456
static int GetLengthContour(const QVector< QPointF > &contour, const QVector< QPointF > &newPoints)
GetLengthContour return length of contour.
Definition: vgobject.cpp:577
static int ContactPoints(const QPointF &p, const QPointF &center, qreal radius, QPointF &p1, QPointF &p2)
Definition: vgobject.cpp:286
quint32 getIdTool() const
Definition: vgobject.cpp:221
static const double accuracyPointOnLine
Definition: vgobject.h:126
GOType
Definition: vgeometrydef.h:56
Draw
Definition: vgeometrydef.h:55
@ Calculation
Q_DECLARE_TYPEINFO(VGObject, Q_MOVABLE_TYPE)