Seamly2D
Code documentation
vistoolheight.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 vistoolheight.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 13 8, 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 "vistoolheight.h"
53 
54 #include <QGraphicsLineItem>
55 #include <QLine>
56 #include <QPointF>
57 #include <QSharedPointer>
58 #include <Qt>
59 #include <new>
60 
61 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h"
62 #include "../ifc/ifcdef.h"
63 #include "../vgeometry/vpointf.h"
64 #include "../vpatterndb/vcontainer.h"
65 #include "../visualization.h"
66 #include "visline.h"
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent)
70  : VisLine(data, parent), lineP1Id(NULL_ID), lineP2Id(NULL_ID), point(nullptr), base_point(nullptr), lineP1(nullptr),
71  lineP2(nullptr), line(nullptr), line_intersection(nullptr)
72 {
74  lineP1 = InitPoint(supportColor, this);
75  lineP2 = InitPoint(supportColor, this);
76  line = InitItem<VScaledLine>(supportColor, this);
77  line_intersection = InitItem<VScaledLine>(supportColor, this); //-V656
78 
79  point = InitPoint(mainColor, this);
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {
85  if (object1Id > NULL_ID)
86  {
88  DrawPoint(base_point, static_cast<QPointF>(*first), supportColor);
89 
90  if (lineP1Id <= NULL_ID)
91  {
92  DrawLine(this, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), mainColor, lineWeight);
93  }
94  else
95  {
97  DrawPoint(lineP1, static_cast<QPointF>(*second), supportColor);
98 
99  QLineF base_line;
100  if (lineP2Id <= NULL_ID)
101  {
102  base_line = QLineF(static_cast<QPointF>(*second), Visualization::scenePos);
103  DrawLine(line, base_line, supportColor, lineWeight);
104  }
105  else
106  {
108  DrawPoint(lineP2, static_cast<QPointF>(*third), supportColor);
109 
110  base_line = QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third));
111  }
112 
113  DrawLine(line, base_line, supportColor, lineWeight);
114 
115  QPointF height = VToolHeight::FindPoint(base_line, static_cast<QPointF>(*first));
116  DrawPoint(point, height, mainColor);
117 
118  QLineF height_line(static_cast<QPointF>(*first), height);
119  DrawLine(this, height_line, mainColor, lineWeight, lineStyle);
120 
121  ShowIntersection(height_line, base_line);
122  }
123  }
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
127 void VisToolHeight::setLineP1Id(const quint32 &value)
128 {
129  lineP1Id = value;
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
133 void VisToolHeight::setLineP2Id(const quint32 &value)
134 {
135  lineP2Id = value;
136 }
137 
138 //---------------------------------------------------------------------------------------------------------------------
139 void VisToolHeight::ShowIntersection(const QLineF &height_line, const QLineF &base_line)
140 {
141  QPointF p;
142  QLineF::IntersectType intersect = height_line.intersects(base_line, &p);
143  if (intersect == QLineF::UnboundedIntersection)
144  {
145  line_intersection->setVisible(true);
146  DrawLine(line_intersection, QLineF(base_line.p1(), height_line.p2()), supportColor, Qt::DashLine);
147  }
148  else if (intersect == QLineF::BoundedIntersection)
149  {
150  line_intersection->setVisible(false);
151  }
152 }
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
static QPointF FindPoint(const QLineF &line, const QPointF &point)
FindPoint find projection base point onto line.
VScaledEllipse * lineP1
Definition: vistoolheight.h:86
VisToolHeight(const VContainer *data, QGraphicsItem *parent=nullptr)
VScaledLine * line_intersection
Definition: vistoolheight.h:89
VScaledEllipse * lineP2
Definition: vistoolheight.h:87
VScaledEllipse * base_point
Definition: vistoolheight.h:85
void setLineP2Id(const quint32 &value)
void ShowIntersection(const QLineF &height_line, const QLineF &base_line)
quint32 lineP2Id
Definition: vistoolheight.h:83
virtual void RefreshGeometry() Q_DECL_OVERRIDE
quint32 lineP1Id
Definition: vistoolheight.h:82
VScaledEllipse * point
Definition: vistoolheight.h:84
VScaledLine * line
Definition: vistoolheight.h:88
void setLineP1Id(const quint32 &value)
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
QPointF scenePos
Definition: visualization.h:98
virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, const qreal &lineWeight, Qt::PenStyle style=Qt::SolidLine)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
Qt::PenStyle lineStyle
#define NULL_ID
Definition: ifcdef.h:76