1 /************************************************************************
2 **
3 ** @file vistoolarc.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 15 8, 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 "vistoolarc.h"
30
31 #include <QPainterPath>
32 #include <QPointF>
33 #include <QSharedPointer>
34 #include <Qt>
35 #include <new>
36
37 #include "../ifc/ifcdef.h"
38 #include "../vgeometry/vabstractcurve.h"
39 #include "../vgeometry/varc.h"
40 #include "../vgeometry/vpointf.h"
41 #include "../vpatterndb/vcontainer.h"
42 #include "../visualization.h"
43 #include "vispath.h"
44 #include "../vwidgets/scalesceneitems.h"
45
46 //---------------------------------------------------------------------------------------------------------------------
VisToolArc(const VContainer * data,QGraphicsItem * parent)47 VisToolArc::VisToolArc(const VContainer *data, QGraphicsItem *parent)
48 :VisPath(data, parent), arcCenter(nullptr), radius(0), f1(0), f2(0)
49 {
50 arcCenter = InitPoint(mainColor, this);
51 }
52
53 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()54 void VisToolArc::RefreshGeometry()
55 {
56 if (object1Id > NULL_ID)
57 {
58 const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
59 DrawPoint(arcCenter, static_cast<QPointF>(*first), supportColor);
60
61 if (not qFuzzyIsNull(radius) && f1 >= 0 && f2 >= 0)
62 {
63 VArc arc = VArc (*first, radius, f1, f2);
64 arc.SetApproximationScale(m_approximationScale);
65 DrawPath(this, arc.GetPath(), arc.DirectionArrows(), mainColor, lineStyle, Qt::RoundCap);
66 }
67 }
68 }
69
70 //---------------------------------------------------------------------------------------------------------------------
setRadius(const QString & expression)71 void VisToolArc::setRadius(const QString &expression)
72 {
73 radius = FindLengthFromUser(expression, Visualization::data->DataVariables());
74 }
75
76 //---------------------------------------------------------------------------------------------------------------------
setF1(const QString & expression)77 void VisToolArc::setF1(const QString &expression)
78 {
79 f1 = FindValFromUser(expression, Visualization::data->DataVariables());
80 }
81
82 //---------------------------------------------------------------------------------------------------------------------
setF2(const QString & expression)83 void VisToolArc::setF2(const QString &expression)
84 {
85 f2 = FindValFromUser(expression, Visualization::data->DataVariables());
86 }
87