Seamly2D
Code documentation
pattern_piece_visual.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file pattern_piece_visual.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file vistoolpiece.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 5 11, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "pattern_piece_visual.h"
54 #include "../vpatterndb/vpiecepath.h"
55 #include "../vgeometry/vpointf.h"
56 #include "../vwidgets/scalesceneitems.h"
57 
58 //---------------------------------------------------------------------------------------------------------------------
59 PatternPieceVisual::PatternPieceVisual(const VContainer *data, QGraphicsItem *parent)
60  : VisPath(data, parent)
61  , m_points()
62  , m_line1(nullptr)
63  , m_line2(nullptr)
64  , m_piece()
65 {
66  m_line1 = InitItem<VScaledLine>(supportColor, this);
67  m_line2 = InitItem<VScaledLine>(supportColor, this);
68 }
69 
70 //---------------------------------------------------------------------------------------------------------------------
72 {
73  HideAllItems();
74 
75  if (m_piece.GetPath().CountNodes() > 0)
76  {
77  DrawPath(this, m_piece.MainPathPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap);
78 
80 
81  for (int i = 0; i < nodes.size(); ++i)
82  {
83  VScaledEllipse *point = GetPoint(static_cast<quint32>(i), mainColor);
84  point->setBrush(QBrush(mainColor, Qt::SolidPattern));
85  DrawPoint(point, nodes.at(i).toQPointF(), mainColor);
86  }
87  }
88 }
89 
90 //---------------------------------------------------------------------------------------------------------------------
92 {
93  m_piece = piece;
94 }
95 
96 //---------------------------------------------------------------------------------------------------------------------
97 VScaledEllipse *PatternPieceVisual::GetPoint(quint32 i, const QColor &color)
98 {
99  return GetPointItem(m_points, i, color, this);
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
104 {
105  if (m_line1)
106  {
107  m_line1->setVisible(false);
108  }
109 
110  if (m_line2)
111  {
112  m_line2->setVisible(false);
113  }
114 
115  for (int i=0; i < m_points.size(); ++i)
116  {
117  if (QGraphicsEllipseItem *item = m_points.at(i))
118  {
119  item->setVisible(false);
120  }
121  }
122 }
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void SetPiece(const VPiece &piece)
QVector< VScaledEllipse * > m_points
VScaledEllipse * GetPoint(quint32 i, const QColor &color)
PatternPieceVisual(const VContainer *data, QGraphicsItem *parent=nullptr)
The VContainer class container of all variables.
Definition: vcontainer.h:141
qint32 CountNodes() const
Definition: vpiecepath.cpp:209
Definition: vpiece.h:88
QPainterPath MainPathPath(const VContainer *data) const
Definition: vpiece.cpp:303
QVector< VPointF > MainPathNodePoints(const VContainer *data, bool showExcluded=false) const
Definition: vpiece.cpp:182
VPiecePath GetPath() const
Definition: vpiece.cpp:156
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)
static VScaledEllipse * GetPointItem(QVector< VScaledEllipse * > &points, quint32 i, const QColor &color, QGraphicsItem *parent)