Seamly2D
Code documentation
vistoolcutsplinepath.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 vistoolcutsplinepath.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 7 9, 2014
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 #include "vistoolcutsplinepath.h"
53 
54 #include <QGraphicsEllipseItem>
55 #include <QGraphicsPathItem>
56 #include <QPointF>
57 #include <QSharedPointer>
58 #include <Qt>
59 #include <new>
60 
61 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"
62 #include "../ifc/ifcdef.h"
63 #include "../vgeometry/vabstractcubicbezierpath.h"
64 #include "../vgeometry/vabstractcurve.h"
65 #include "../vgeometry/vpointf.h"
66 #include "../vgeometry/vsplinepath.h"
67 #include "../vpatterndb/vcontainer.h"
68 #include "../visualization.h"
69 #include "vispath.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent)
73  :VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0)
74 {
75  splPath1 = InitItem<VCurvePathItem>(Qt::darkGreen, this);
76  splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
77  splPath2 = InitItem<VCurvePathItem>(Qt::darkRed, this);
78  splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
79 
80  point = InitPoint(mainColor, this);
81  point->setZValue(2);
82  point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
83 }
84 
85 //---------------------------------------------------------------------------------------------------------------------
87 {
88  if (object1Id > NULL_ID)
89  {
91  DrawPath(this, splPath->GetPath(), splPath->DirectionArrows(), supportColor, lineStyle,
92  lineWeight, Qt::RoundCap);
93 
94  if (not qFuzzyIsNull(length))
95  {
96  VSplinePath *spPath1 = nullptr;
97  VSplinePath *spPath2 = nullptr;
98  VPointF *p = VToolCutSplinePath::CutSplinePath(length, splPath, "X", &spPath1, &spPath2);
99  SCASSERT(p != nullptr)
100  SCASSERT(spPath1 != nullptr)
101  SCASSERT(spPath2 != nullptr)
102 
103  DrawPoint(point, static_cast<QPointF>(*p), mainColor);
104  delete p;
105 
106  DrawPath(splPath1, spPath1->GetPath(), spPath1->DirectionArrows(), Qt::darkGreen, lineStyle,
107  lineWeight, Qt::RoundCap);
108  DrawPath(splPath2, spPath2->GetPath(), spPath2->DirectionArrows(), Qt::darkRed, lineStyle,
109  lineWeight, Qt::RoundCap);
110 
111  delete spPath1;
112  delete spPath2;
113  }
114  }
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
118 void VisToolCutSplinePath::setLength(const QString &expression)
119 {
120  length = FindLength(expression, Visualization::data->DataVariables());
121 }
virtual QPainterPath GetPath() const Q_DECL_OVERRIDE
GetPath return QPainterPath which reprezent spline path.
virtual QVector< DirectionArrow > DirectionArrows() const Q_DECL_OVERRIDE
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
The VSplinePath class keep information about splinePath.
Definition: vsplinepath.h:72
static Q_REQUIRED_RESULT VPointF * CutSplinePath(qreal length, const QSharedPointer< VAbstractCubicBezierPath > &splPath, const QString &pName, VSplinePath **splPath1, VSplinePath **splPath2)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
VCurvePathItem * splPath1
void setLength(const QString &expression)
VCurvePathItem * splPath2
VisToolCutSplinePath(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)
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
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)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
Qt::PenStyle lineStyle
#define SCASSERT(cond)
Definition: def.h:317
const QString splPath
Definition: ifcdef.cpp:419
#define NULL_ID
Definition: ifcdef.h:76