Seamly2D
Code documentation
vabstractcurve.h
Go to the documentation of this file.
1 /******************************************************************************
2  * @file vabstractcurve.h
3  ** @author Douglas S Caskey
4  ** @date 21 Mar, 2023
5  **
6  ** @brief
7  ** @copyright
8  ** This source code is part of the Seamly2D project, a pattern making
9  ** program to create and model patterns of clothing.
10  ** Copyright (C) 2017-2023 Seamly2D project
11  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12  **
13  ** Seamly2D is free software: you can redistribute it and/or modify
14  ** You should have received a copy of the GNU General Public License
15  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
16  **
17  *****************************************************************************/
18 
19 /************************************************************************
20  **
21  ** @file vabstractcurve.h
22  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
23  ** @date 25 6, 2014
24  **
25  ** @brief
26  ** @copyright
27  ** This source code is part of the Valentine project, a pattern making
28  ** program, whose allow create and modeling patterns of clothing.
29  ** Copyright (C) 2013-2015 Seamly2D project
30  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
31  **
32  ** Seamly2D is free software: you can redistribute it and/or modify
33  ** it under the terms of the GNU General Public License as published by
34  ** the Free Software Foundation, either version 3 of the License, or
35  ** (at your option) any later version.
36  **
37  ** Seamly2D is distributed in the hope that it will be useful,
38  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
39  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40  ** GNU General Public License for more details.
41  **
42  ** You should have received a copy of the GNU General Public License
43  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
44  **
45  *************************************************************************/
46 
47 #ifndef VABSTRACTCURVE_H
48 #define VABSTRACTCURVE_H
49 
50 #include <qcompilerdetection.h>
51 #include <QPointF>
52 #include <QSharedDataPointer>
53 #include <QString>
54 #include <QTypeInfo>
55 #include <QVector>
56 #include <QtGlobal>
57 
58 #include "../ifc/ifcdef.h"
59 #include "../vmisc/vmath.h"
60 #include "vgeometrydef.h"
61 #include "vgobject.h"
62 
63 typedef QPair<QLineF, QLineF> DirectionArrow;
64 
65 class QPainterPath;
66 class VAbstractCurveData;
67 
68 class VAbstractCurve :public VGObject
69 {
70 public:
71  explicit VAbstractCurve(const GOType &type, const quint32 &idObject = NULL_ID,
72  const Draw &mode = Draw::Calculation);
73  explicit VAbstractCurve(const VAbstractCurve &curve);
74  virtual ~VAbstractCurve() Q_DECL_OVERRIDE;
75 
77 #ifdef Q_COMPILER_RVALUE_REFS
78  VAbstractCurve &operator = (VAbstractCurve &&curve) Q_DECL_NOTHROW;
79 #endif
80 
81  void Swap(VAbstractCurve &curve) Q_DECL_NOTHROW;
82 
83  virtual QVector<QPointF> getPoints() const =0;
84  static QVector<QPointF> GetSegmentPoints(const QVector<QPointF> &points, const QPointF &begin, const QPointF &end,
85  bool reverse = false);
86  QVector<QPointF> GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse = false) const;
87 
88  virtual QPainterPath GetPath() const;
89  virtual qreal GetLength() const =0;
90  qreal GetLengthByPoint(const QPointF &point) const;
91  virtual QVector<QPointF> IntersectLine(const QLineF &line) const;
92  virtual bool IsIntersectLine(const QLineF &line) const;
93 
94  static bool isPointOnCurve(const QVector<QPointF> &points, const QPointF &p);
95  bool isPointOnCurve(const QPointF &p) const;
96 
97  virtual qreal GetStartAngle () const=0;
98  virtual qreal GetEndAngle () const=0;
99 
100  quint32 GetDuplicate() const;
101  void SetDuplicate(quint32 number);
102 
103  QString getLineColor() const;
104  void setLineColor(const QString &color);
105 
106  QString GetPenStyle() const;
107  void SetPenStyle(const QString &penStyle);
108 
109  QString getLineWeight() const;
110  void setLineWeight(const QString &lineWeight);
111 
112  static qreal PathLength(const QVector<QPointF> &path);
113 
114  QPointF getFirstPoint();
115  QPointF getLastPoint();
116 
117  static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line);
118 
119  virtual QString NameForHistory(const QString &toolName) const=0;
121  static QPainterPath ShowDirection(const QVector<DirectionArrow> &arrows, qreal width);
122 
123  static const qreal lengthCurveDirectionArrow;
124 
125 protected:
126  virtual void CreateName() =0;
127 
128 private:
129  QSharedDataPointer<VAbstractCurveData> d;
130 
131  static QVector<QPointF> FromBegin(const QVector<QPointF> &points, const QPointF &begin, bool *ok = nullptr);
132  static QVector<QPointF> ToEnd(const QVector<QPointF> &points, const QPointF &end, bool *ok = nullptr);
133 };
134 
136 
137 #endif // VABSTRACTCURVE_H
virtual qreal GetEndAngle() const =0
QPointF getLastPoint()
QString getLineWeight() const
getLineWeight return weight of the lines
void SetDuplicate(quint32 number)
virtual QVector< DirectionArrow > DirectionArrows() const
virtual ~VAbstractCurve() Q_DECL_OVERRIDE
virtual QVector< QPointF > IntersectLine(const QLineF &line) const
IntersectLine return list of points for real intersection with line.
virtual QVector< QPointF > getPoints() const =0
static qreal PathLength(const QVector< QPointF > &path)
void SetPenStyle(const QString &penStyle)
VAbstractCurve & operator=(const VAbstractCurve &curve)
virtual qreal GetStartAngle() const =0
VAbstractCurve(const GOType &type, const quint32 &idObject=null_id, const Draw &mode=Draw::Calculation)
virtual void CreateName()=0
void setLineColor(const QString &color)
virtual bool IsIntersectLine(const QLineF &line) const
virtual QString NameForHistory(const QString &toolName) const =0
void setLineWeight(const QString &lineWeight)
setLineWeight set weight of the lines
QString GetPenStyle() const
static QVector< QPointF > ToEnd(const QVector< QPointF > &points, const QPointF &end, bool *ok=nullptr)
quint32 GetDuplicate() const
static QVector< QPointF > FromBegin(const QVector< QPointF > &points, const QPointF &begin, bool *ok=nullptr)
void Swap(VAbstractCurve &curve) Q_DECL_NOTHROW
QSharedDataPointer< VAbstractCurveData > d
virtual QPainterPath GetPath() const
static const qreal lengthCurveDirectionArrow
QString getLineColor() const
qreal GetLengthByPoint(const QPointF &point) const
static bool isPointOnCurve(const QVector< QPointF > &points, const QPointF &p)
static QVector< QPointF > CurveIntersectLine(const QVector< QPointF > &points, const QLineF &line)
static QPainterPath ShowDirection(const QVector< DirectionArrow > &arrows, qreal width)
virtual qreal GetLength() const =0
QPointF getFirstPoint()
static QVector< QPointF > GetSegmentPoints(const QVector< QPointF > &points, const QPointF &begin, const QPointF &end, bool reverse=false)
The VGObject class keep information graphical objects.
Definition: vgobject.h:74
#define NULL_ID
Definition: ifcdef.h:76
Q_DECLARE_TYPEINFO(VAbstractCurve, Q_MOVABLE_TYPE)
QPair< QLineF, QLineF > DirectionArrow
GOType
Definition: vgeometrydef.h:56
Draw
Definition: vgeometrydef.h:55
@ Calculation