Seamly2D
Code documentation
vistooltriangle.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 vistooltriangle.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 "vistooltriangle.h"
53 
54 #include <QGraphicsLineItem>
55 #include <QGraphicsPathItem>
56 #include <QPainterPath>
57 #include <QPen>
58 #include <QPointF>
59 #include <QSharedPointer>
60 #include <new>
61 
62 #include "../../tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h"
63 #include "../ifc/ifcdef.h"
64 #include "../vgeometry/vpointf.h"
65 #include "../vmisc/vabstractapplication.h"
66 #include "../vmisc/vmath.h"
67 #include "../vpatterndb/vcontainer.h"
68 #include "../visualization.h"
69 #include "visline.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent)
73  :VisLine(data, parent), object2Id(NULL_ID), hypotenuseP1Id(NULL_ID), hypotenuseP2Id(NULL_ID), point(nullptr),
74  axisP1(nullptr), axisP2(nullptr), axis(nullptr), hypotenuseP1(nullptr), hypotenuseP2(nullptr), foot1(nullptr),
75  foot2(nullptr)
76 {
77  axisP1 = InitPoint(supportColor, this);
78  axisP2 = InitPoint(supportColor, this);
79  axis = InitItem<ArrowedLineItem>(supportColor, this);
82  foot1 = InitItem<VScaledLine>(supportColor, this);
83  foot2 = InitItem<VScaledLine>(supportColor, this); //-V656
84 
85  point = InitPoint(mainColor, this);
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
90 {
91  if (object1Id > NULL_ID)
92  {
94  DrawPoint(axisP1, static_cast<QPointF>(*first), supportColor);
95 
96  if (object2Id <= NULL_ID)
97  {
98  drawArrowedLine(axis, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor);
99  }
100  else
101  {
103  DrawPoint(axisP2, static_cast<QPointF>(*second), supportColor);
104 
105  drawArrowedLine(axis, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
106 
107  if (hypotenuseP1Id <= NULL_ID)
108  {
109  return;
110  }
111  else
112  {
114  DrawPoint(hypotenuseP1, static_cast<QPointF>(*third), supportColor);
115 
116  if (hypotenuseP2Id <= NULL_ID)
117  {
118  DrawLine(this, QLineF(static_cast<QPointF>(*third), Visualization::scenePos), supportColor,
119  lineWeight, Qt::DashLine);
120 
121  QPointF trPoint = VToolTriangle::FindPoint(static_cast<QPointF>(*first),
122  static_cast<QPointF>(*second),
123  static_cast<QPointF>(*third), Visualization::scenePos);
124  DrawPoint(point, trPoint, mainColor);
125 
126  DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor,
127  lineWeight, Qt::DashLine);
128  DrawLine(foot2, QLineF(Visualization::scenePos, trPoint), supportColor, lineWeight, Qt::DashLine);
129  }
130  else
131  {
133  DrawPoint(hypotenuseP2, static_cast<QPointF>(*forth), supportColor);
134 
135  DrawLine(this, QLineF(static_cast<QPointF>(*third), static_cast<QPointF>(*forth)), supportColor,
136  lineWeight, Qt::DashLine);
137 
138  QPointF trPoint = VToolTriangle::FindPoint(static_cast<QPointF>(*first),
139  static_cast<QPointF>(*second),
140  static_cast<QPointF>(*third),
141  static_cast<QPointF>(*forth));
142  DrawPoint(point, trPoint, mainColor);
143 
144  DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor,
145  lineWeight, Qt::DashLine);
146  DrawLine(foot2, QLineF(static_cast<QPointF>(*forth), trPoint), supportColor,
147  lineWeight, Qt::DashLine);
148  }
149  }
150  }
151  }
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
155 void VisToolTriangle::setObject2Id(const quint32 &value)
156 {
157  object2Id = value;
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
161 void VisToolTriangle::setHypotenuseP1Id(const quint32 &value)
162 {
163  hypotenuseP1Id = value;
164 }
165 
166 //---------------------------------------------------------------------------------------------------------------------
167 void VisToolTriangle::setHypotenuseP2Id(const quint32 &value)
168 {
169  hypotenuseP2Id = value;
170 }
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 QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, const QPointF &secondPoint)
FindPoint find point intersection two foots right triangle.
quint32 hypotenuseP2Id
VScaledEllipse * axisP1
void setObject2Id(const quint32 &value)
void setHypotenuseP1Id(const quint32 &value)
VScaledEllipse * hypotenuseP1
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setHypotenuseP2Id(const quint32 &value)
ArrowedLineItem * axis
VScaledLine * foot2
VScaledEllipse * point
quint32 hypotenuseP1Id
VScaledEllipse * axisP2
VisToolTriangle(const VContainer *data, QGraphicsItem *parent=nullptr)
VScaledLine * foot1
VScaledEllipse * hypotenuseP2
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
void drawArrowedLine(ArrowedLineItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
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
#define NULL_ID
Definition: ifcdef.h:76