1 /************************************************************************
2 **
3 ** @file vistoolpointofintersection.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 13 8, 2014
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2013-2015 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "vistoolpointofintersection.h"
30
31 #include <QGraphicsEllipseItem>
32 #include <QGraphicsLineItem>
33 #include <QLine>
34 #include <QPointF>
35 #include <QSharedPointer>
36 #include <Qt>
37 #include <new>
38
39 #include "../ifc/ifcdef.h"
40 #include "../vgeometry/vpointf.h"
41 #include "../vpatterndb/vcontainer.h"
42 #include "../visualization.h"
43 #include "visline.h"
44 #include "../vmisc/compatibility.h"
45
46 //---------------------------------------------------------------------------------------------------------------------
VisToolPointOfIntersection(const VContainer * data,QGraphicsItem * parent)47 VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, QGraphicsItem *parent)
48 : VisLine(data, parent), point2Id(NULL_ID), point(nullptr), axisP1(nullptr), axisP2(nullptr), axis2(nullptr)
49 {
50 axisP1 = InitPoint(supportColor, this);
51 axisP2 = InitPoint(supportColor, this); //-V656
52 axis2 = InitItem<VScaledLine>(supportColor, this);
53
54 point = InitPoint(mainColor, this);
55 }
56
57 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()58 void VisToolPointOfIntersection::RefreshGeometry()
59 {
60 QLineF axisL1;
61 if (object1Id <= NULL_ID)
62 {
63 axisL1 = Axis(Visualization::scenePos, 90);
64 DrawLine(this, axisL1, supportColor, Qt::DashLine);
65 }
66 else
67 {
68 const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
69 DrawPoint(axisP1, static_cast<QPointF>(*first), supportColor);
70
71 axisL1 = Axis(static_cast<QPointF>(*first), 90);
72 DrawLine(this, axisL1, supportColor, Qt::DashLine);
73
74 QLineF axisL2;
75 if (point2Id <= NULL_ID)
76 {
77 axisL2 = Axis(Visualization::scenePos, 180);
78 ShowIntersection(axisL1, axisL2, supportColor);
79 }
80 else
81 {
82 const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(point2Id);
83 DrawPoint(axisP2, static_cast<QPointF>(*second), supportColor);
84 axisL2 = Axis(static_cast<QPointF>(*second), 180);
85 ShowIntersection(axisL1, axisL2, mainColor);
86 }
87 DrawLine(axis2, axisL2, supportColor, Qt::DashLine);
88 }
89 }
90
91 //---------------------------------------------------------------------------------------------------------------------
setPoint2Id(const quint32 & value)92 void VisToolPointOfIntersection::setPoint2Id(const quint32 &value)
93 {
94 point2Id = value;
95 }
96
97 //---------------------------------------------------------------------------------------------------------------------
ShowIntersection(const QLineF & axis1,const QLineF & axis2,const QColor & color)98 void VisToolPointOfIntersection::ShowIntersection(const QLineF &axis1, const QLineF &axis2, const QColor &color)
99 {
100 QPointF p;
101 QLineF::IntersectType intersect = Intersects(axis1, axis2, &p);
102
103 if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
104 {
105 point->setVisible(true);
106 DrawPoint(point, p, color);
107 }
108 else
109 {
110 point->setVisible(false);
111 }
112 }
113