Seamly2D
Code documentation
vistoollineintersectaxis.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 vislineintersectaxis.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 19 10, 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 
53 
54 #include <QColor>
55 #include <QGraphicsLineItem>
56 #include <QLine>
57 #include <QPointF>
58 #include <QSharedPointer>
59 #include <Qt>
60 #include <new>
61 
62 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.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 //---------------------------------------------------------------------------------------------------------------------
71  : VisLine(data, parent), point2Id(NULL_ID), axisPointId(NULL_ID), angle(-1), point(nullptr), lineP1(nullptr),
72  lineP2(nullptr), basePoint(nullptr), baseLine(nullptr), axisLine(nullptr), line_intersection(nullptr)
73 {
74  this->mainColor = Qt::red;
75 
76  lineP1 = InitPoint(supportColor, this);
77  lineP2 = InitPoint(supportColor, this);
79  baseLine = InitItem<VScaledLine>(supportColor, this);
80  axisLine = InitItem<VScaledLine>(supportColor, this);
81  line_intersection = InitItem<VScaledLine>(supportColor, this);
82  point = InitPoint(mainColor, this);
83 }
84 
85 //---------------------------------------------------------------------------------------------------------------------
87 {
88  if (object1Id > NULL_ID)
89  {
91  DrawPoint(lineP1, static_cast<QPointF>(*first), supportColor);
92 
93  if (point2Id <= NULL_ID)
94  {
95  DrawLine(baseLine, QLineF(static_cast<QPointF>(*first), Visualization::scenePos),
97  }
98  else
99  {
101  DrawPoint(lineP2, static_cast<QPointF>(*second), supportColor);
102 
103  const QLineF base_line(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
105 
106  if (axisPointId > NULL_ID)
107  {
108  QLineF axis;
111  {
112  axis = Axis(static_cast<QPointF>(*third), Visualization::scenePos);
113  }
114  else
115  {
116  axis = Axis(static_cast<QPointF>(*third), angle);
117  }
118  DrawPoint(basePoint, static_cast<QPointF>(*third), mainColor);
119  DrawLine(axisLine, axis, supportColor, lineWeight, Qt::DashLine);
120 
121  QPointF p = VToolLineIntersectAxis::FindPoint(axis, base_line);
122  QLineF axis_line(static_cast<QPointF>(*third), p);
123  DrawLine(this, axis_line, mainColor, lineWeight, lineStyle);
124 
126  ShowIntersection(axis_line, base_line);
127 
128  Visualization::toolTip = tr("<b>Intersection line and axis</b>: angle = %1°, "
129  "Hold <b>SHIFT</b> to constrain angle, "
130  "Press <b>ENTER</b> to finish tool creation")
131  .arg(this->line().angle());
132  }
133  }
134  }
135 }
136 
137 //---------------------------------------------------------------------------------------------------------------------
139 {
140  return QString("%1").arg(this->line().angle());
141 }
142 
143 //---------------------------------------------------------------------------------------------------------------------
144 void VisToolLineIntersectAxis::SetAngle(const QString &expression)
145 {
146  angle = FindVal(expression, Visualization::data->DataVariables());
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
150 void VisToolLineIntersectAxis::setPoint2Id(const quint32 &value)
151 {
152  point2Id = value;
153 }
154 
155 //---------------------------------------------------------------------------------------------------------------------
157 {
158  axisPointId = value;
159 }
160 
161 //---------------------------------------------------------------------------------------------------------------------
162 void VisToolLineIntersectAxis::ShowIntersection(const QLineF &axis_line, const QLineF &base_line)
163 {
164  QPointF p;
165  QLineF::IntersectType intersect = axis_line.intersects(base_line, &p);
166  if (intersect == QLineF::UnboundedIntersection)
167  {
168  line_intersection->setVisible(true);
169  DrawLine(line_intersection, QLineF(base_line.p1(), axis_line.p2()), supportColor, lineWeight, Qt::DashLine);
170  }
171  else if (intersect == QLineF::BoundedIntersection || intersect == QLineF::NoIntersection)
172  {
173  line_intersection->setVisible(false);
174  }
175 }
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 &axis, const QLineF &line)
QLineF Axis(const QPointF &p, const qreal &angle) const
Definition: visline.cpp:123
void setPoint2Id(const quint32 &value)
void setAxisPointId(const quint32 &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void ShowIntersection(const QLineF &axis_line, const QLineF &base_line)
void SetAngle(const QString &expression)
VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent=nullptr)
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
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
Qt::PenStyle lineStyle
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
Definition: def.h:490
#define NULL_ID
Definition: ifcdef.h:76