1 /************************************************************************
2 **
3 ** @file vistoolcutsplinepath.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 7 9, 2014
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 #include "vistoolcutsplinepath.h"
30
31 #include <QGraphicsEllipseItem>
32 #include <QGraphicsPathItem>
33 #include <QPointF>
34 #include <QSharedPointer>
35 #include <Qt>
36 #include <new>
37
38 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h"
39 #include "../ifc/ifcdef.h"
40 #include "../vgeometry/vabstractcubicbezierpath.h"
41 #include "../vgeometry/vabstractcurve.h"
42 #include "../vgeometry/vpointf.h"
43 #include "../vgeometry/vsplinepath.h"
44 #include "../vpatterndb/vcontainer.h"
45 #include "../visualization.h"
46 #include "vispath.h"
47
48 //---------------------------------------------------------------------------------------------------------------------
VisToolCutSplinePath(const VContainer * data,QGraphicsItem * parent)49 VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent)
50 :VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0)
51 {
52 splPath1 = InitItem<VCurvePathItem>(Qt::darkGreen, this);
53 splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
54 splPath2 = InitItem<VCurvePathItem>(Qt::darkRed, this);
55 splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
56
57 point = InitPoint(mainColor, this);
58 point->setZValue(2);
59 point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
60 }
61
62 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()63 void VisToolCutSplinePath::RefreshGeometry()
64 {
65 if (object1Id > NULL_ID)
66 {
67 const auto splPath = Visualization::data->GeometricObject<VAbstractCubicBezierPath>(object1Id);
68 DrawPath(this, splPath->GetPath(), splPath->DirectionArrows(), supportColor, lineStyle, Qt::RoundCap);
69
70 if (not qFuzzyIsNull(length))
71 {
72 VSplinePath *spPath1 = nullptr;
73 VSplinePath *spPath2 = nullptr;
74 VPointF *p = VToolCutSplinePath::CutSplinePath(length, splPath, "X", &spPath1, &spPath2);
75 SCASSERT(p != nullptr)
76 SCASSERT(spPath1 != nullptr)
77 SCASSERT(spPath2 != nullptr)
78
79 DrawPoint(point, static_cast<QPointF>(*p), mainColor);
80 delete p;
81
82 DrawPath(splPath1, spPath1->GetPath(), spPath1->DirectionArrows(), Qt::darkGreen, lineStyle, Qt::RoundCap);
83 DrawPath(splPath2, spPath2->GetPath(), spPath2->DirectionArrows(), Qt::darkRed, lineStyle, Qt::RoundCap);
84
85 delete spPath1;
86 delete spPath2;
87 }
88 }
89 }
90
91 //---------------------------------------------------------------------------------------------------------------------
setLength(const QString & expression)92 void VisToolCutSplinePath::setLength(const QString &expression)
93 {
94 length = FindLengthFromUser(expression, Visualization::data->DataVariables());
95 }
96