Seamly2D
Code documentation
vistoolnormal.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 vistoolnormal.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 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 "vistoolnormal.h"
53 
54 #include <QColor>
55 #include <QGraphicsLineItem>
56 #include <QLineF>
57 #include <QPointF>
58 #include <QSharedPointer>
59 #include <Qt>
60 #include <new>
61 
62 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h"
63 #include "../ifc/ifcdef.h"
64 #include "../vgeometry/vpointf.h"
65 #include "../vpatterndb/vcontainer.h"
66 #include "../visualization.h"
67 #include "visline.h"
68 
69 //---------------------------------------------------------------------------------------------------------------------
70 VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent)
71  : VisLine(data, parent), object2Id(NULL_ID), point(nullptr), lineP1(nullptr), lineP2(nullptr), line(nullptr),
72  length(0), angle(0)
73 {
74  this->mainColor = Qt::red;
75 
76  lineP1 = InitPoint(supportColor, this);
77  lineP2 = InitPoint(supportColor, this); //-V656
78  line = InitItem<VScaledLine>(supportColor, this);
79 
80  point = InitPoint(mainColor, this);
81 }
82 
83 //---------------------------------------------------------------------------------------------------------------------
85 {
86  if (object1Id > NULL_ID)
87  {
89  DrawPoint(lineP1, static_cast<QPointF>(*first), supportColor);
90 
91  if (object2Id <= NULL_ID)
92  {
93  QLineF line_mouse(static_cast<QPointF>(*first), Visualization::scenePos);
94  DrawLine(line, line_mouse, supportColor, lineWeight);
95 
96  QLineF normal = line_mouse.normalVector();
97  QPointF endRay = Ray(normal.p1(), normal.angle());
98  DrawLine(this, QLineF(normal.p1(), endRay), mainColor, lineWeight);
99  }
100  else
101  {
103  DrawPoint(lineP2, static_cast<QPointF>(*second), supportColor);
104 
105  QLineF line_mouse(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
106  DrawLine(line, line_mouse, supportColor, lineWeight);
107 
108  if (qFuzzyIsNull(length))
109  {
110  QLineF normal = line_mouse.normalVector();
111  QPointF endRay = Ray(normal.p1(), normal.angle());
112  DrawLine(this, QLineF(normal.p1(), endRay), mainColor, lineWeight);
113  }
114  else
115  {
116  QPointF fPoint = VToolNormal::FindPoint(static_cast<QPointF>(*first), static_cast<QPointF>(*second),
117  length, angle);
118  QLineF mainLine = QLineF(static_cast<QPointF>(*first), fPoint);
119  DrawLine(this, mainLine, mainColor, lineWeight, lineStyle);
120 
121  DrawPoint(point, mainLine.p2(), mainColor);
122  }
123  }
124  }
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
128 void VisToolNormal::setObject2Id(const quint32 &value)
129 {
130  object2Id = value;
131 }
132 
133 //---------------------------------------------------------------------------------------------------------------------
134 void VisToolNormal::setLength(const QString &expression)
135 {
136  length = FindLength(expression, Visualization::data->DataVariables());
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
141 {
142  return angle;
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 void VisToolNormal::SetAngle(const qreal &value)
147 {
148  angle = value;
149 }
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 &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle=0)
FindPoint return normal point.
QPointF Ray(const QPointF &firstPoint, const qreal &angle) const
Definition: visline.cpp:85
virtual void RefreshGeometry() Q_DECL_OVERRIDE
VScaledEllipse * lineP2
Definition: vistoolnormal.h:86
void SetAngle(const qreal &value)
VScaledEllipse * point
Definition: vistoolnormal.h:84
VScaledEllipse * lineP1
Definition: vistoolnormal.h:85
VScaledLine * line
Definition: vistoolnormal.h:87
void setObject2Id(const quint32 &value)
void setLength(const QString &expression)
quint32 object2Id
Definition: vistoolnormal.h:83
VisToolNormal(const VContainer *data, QGraphicsItem *parent=nullptr)
qreal GetAngle() const
QColor supportColor
QColor mainColor
Definition: visualization.h:99
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style=Qt::SolidLine)
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
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