1 /************************************************************************
2 **
3 ** @file
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 22 11, 2016
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) 2016 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 "vistoolpiecepath.h"
30 #include "../vwidgets/vsimplepoint.h"
31 #include "../vgeometry/vpointf.h"
32 #include "../vwidgets/scalesceneitems.h"
33
34 #include <QGraphicsSceneMouseEvent>
35
36 //---------------------------------------------------------------------------------------------------------------------
VisToolPiecePath(const VContainer * data,QGraphicsItem * parent)37 VisToolPiecePath::VisToolPiecePath(const VContainer *data, QGraphicsItem *parent)
38 : VisPath(data, parent),
39 m_points(),
40 m_line(nullptr),
41 m_path(),
42 m_cuttingPath()
43 {
44 m_line = InitItem<VScaledLine>(supportColor, this);
45 }
46
47 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()48 void VisToolPiecePath::RefreshGeometry()
49 {
50 HideAllItems();
51
52 if (m_path.CountNodes() > 0)
53 {
54 DrawPath(this, m_path.PainterPath(Visualization::data, m_cuttingPath), mainColor, m_path.GetPenType(),
55 Qt::RoundCap);
56
57 const QVector<VPointF> nodes = m_path.PathNodePoints(Visualization::data);
58
59 for (int i = 0; i < nodes.size(); ++i)
60 {
61 VSimplePoint *point = GetPoint(static_cast<quint32>(i), supportColor);
62 point->RefreshPointGeometry(nodes.at(i)); // Keep first, you can hide only objects those have shape
63 point->SetOnlyPoint(mode == Mode::Creation);
64 point->setVisible(true);
65 }
66
67 if (mode == Mode::Creation)
68 {
69 const QVector<QPointF> points = m_path.PathPoints(Visualization::data);
70 if (points.size() > 0)
71 {
72 DrawLine(m_line, QLineF(points.last(), Visualization::scenePos), supportColor, Qt::DashLine);
73 }
74 }
75 }
76 }
77
78 //---------------------------------------------------------------------------------------------------------------------
SetPath(const VPiecePath & path)79 void VisToolPiecePath::SetPath(const VPiecePath &path)
80 {
81 m_path = path;
82 }
83
84 //---------------------------------------------------------------------------------------------------------------------
SetCuttingPath(const QVector<QPointF> & cuttingPath)85 void VisToolPiecePath::SetCuttingPath(const QVector<QPointF> &cuttingPath)
86 {
87 m_cuttingPath = cuttingPath;
88 }
89
90 //---------------------------------------------------------------------------------------------------------------------
mousePressEvent(QGraphicsSceneMouseEvent * event)91 void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event)
92 {
93 event->ignore();
94 }
95
96 //---------------------------------------------------------------------------------------------------------------------
GetPoint(quint32 i,const QColor & color)97 VSimplePoint *VisToolPiecePath::GetPoint(quint32 i, const QColor &color)
98 {
99 return VisPath::GetPoint(m_points, i, color);
100 }
101
102 //---------------------------------------------------------------------------------------------------------------------
HideAllItems()103 void VisToolPiecePath::HideAllItems()
104 {
105 if (m_line)
106 {
107 m_line->setVisible(false);
108 }
109
110 for (auto item : qAsConst(m_points))
111 {
112 if (item)
113 {
114 item->setVisible(false);
115 }
116 }
117 }
118