Seamly2D
Code documentation
vistoolcubicbezier.cpp
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 vistoolcubicbezier.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 10 3, 2016
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) 2016 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 #include "vistoolcubicbezier.h"
53 
54 #include <QGraphicsLineItem>
55 #include <QLineF>
56 #include <QPainterPath>
57 #include <QPointF>
58 #include <QSharedPointer>
59 #include <Qt>
60 #include <new>
61 
62 #include "../ifc/ifcdef.h"
63 #include "../vgeometry/vabstractcurve.h"
64 #include "../vgeometry/vcubicbezier.h"
65 #include "../vgeometry/vpointf.h"
66 #include "../vpatterndb/vcontainer.h"
67 #include "../visualization.h"
68 #include "vispath.h"
69 #include "../vwidgets/scalesceneitems.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *parent)
73  : VisPath(data, parent),
74  object2Id(NULL_ID),
75  object3Id(NULL_ID),
76  object4Id(NULL_ID),
77  point1(nullptr),
78  point2(nullptr),
79  point3(nullptr),
80  point4(nullptr),
81  helpLine1(nullptr),
82  helpLine2(nullptr)
83 {
84  helpLine1 = InitItem<VScaledLine>(mainColor, this);
85  helpLine2 = InitItem<VScaledLine>(mainColor, this);
86 
87  point1 = InitPoint(supportColor, this);
88  point2 = InitPoint(supportColor, this); //-V656
89  point3 = InitPoint(supportColor, this); //-V656
90  point4 = InitPoint(supportColor, this); //-V656
91 }
92 
93 //---------------------------------------------------------------------------------------------------------------------
95 {
96  if (object1Id > NULL_ID)
97  {
99  DrawPoint(point1, static_cast<QPointF>(*first), Qt::DashLine);
100 
101  if (object2Id <= NULL_ID)
102  {
103  DrawLine(helpLine1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), mainColor,
104  lineWeight, Qt::DashLine);
105  }
106  else
107  {
108  const auto second = Visualization::data->GeometricObject<VPointF>(object2Id);
109  DrawPoint(point2, static_cast<QPointF>(*second), supportColor);
110  DrawLine(helpLine1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), mainColor,
111  lineWeight, Qt::DashLine);
112 
113  if (object3Id <= NULL_ID)
114  {
115  VCubicBezier spline(*first, *second, VPointF(Visualization::scenePos),
117  DrawPath(this, spline.GetPath(), mainColor, lineStyle, lineWeight, Qt::RoundCap);
118  }
119  else
120  {
122  DrawPoint(point3, static_cast<QPointF>(*third), supportColor);
123 
124  if (object4Id <= NULL_ID)
125  {
126  VCubicBezier spline(*first, *second, *third, VPointF(Visualization::scenePos));
127  DrawPath(this, spline.GetPath(), mainColor, lineStyle, lineWeight, Qt::RoundCap);
128  DrawLine(helpLine2, QLineF(static_cast<QPointF>(*third), Visualization::scenePos), mainColor,
129  lineWeight, Qt::DashLine);
130  }
131  else
132  {
133  const auto fourth = Visualization::data->GeometricObject<VPointF>(object4Id);
134  DrawPoint(point4, static_cast<QPointF>(*fourth), supportColor);
135  DrawLine(helpLine2, QLineF(static_cast<QPointF>(*fourth), static_cast<QPointF>(*third)),
136  mainColor, lineWeight, Qt::DashLine);
137 
138  VCubicBezier spline(*first, *second, *third, *fourth);
139  DrawPath(this, spline.GetPath(), spline.DirectionArrows(), mainColor, lineStyle,
140  lineWeight, Qt::RoundCap);
141  }
142  }
143  }
144  }
145 }
146 
147 //---------------------------------------------------------------------------------------------------------------------
148 void VisToolCubicBezier::setObject2Id(const quint32 &value)
149 {
150  object2Id = value;
151 }
152 
153 //---------------------------------------------------------------------------------------------------------------------
154 void VisToolCubicBezier::setObject3Id(const quint32 &value)
155 {
156  object3Id = value;
157 }
158 
159 //---------------------------------------------------------------------------------------------------------------------
160 void VisToolCubicBezier::setObject4Id(const quint32 &value)
161 {
162  object4Id = value;
163 }
virtual QVector< DirectionArrow > DirectionArrows() const
virtual QPainterPath GetPath() const
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
The VPointF class keep data of point.
Definition: vpointf.h:75
VScaledEllipse * point2
virtual void RefreshGeometry() Q_DECL_OVERRIDE
VScaledLine * helpLine1
void setObject2Id(const quint32 &value)
VScaledLine * helpLine2
void setObject4Id(const quint32 &value)
VScaledEllipse * point3
VScaledEllipse * point4
VScaledEllipse * point1
void setObject3Id(const quint32 &value)
VisToolCubicBezier(const VContainer *data, QGraphicsItem *parent=nullptr)
QColor supportColor
QColor mainColor
Definition: visualization.h:99
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
const VContainer * data
Definition: visualization.h:97
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style=Qt::SolidLine, const qreal &weight=0.35, Qt::PenCapStyle cap=Qt::SquareCap)
QPointF scenePos
Definition: visualization.h:98
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, const qreal &lineWeight, Qt::PenStyle style=Qt::SolidLine)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
Qt::PenStyle lineStyle
#define NULL_ID
Definition: ifcdef.h:76