1 /************************************************************************
2  **
3  **  @file   vistoolpointofintersectioncurves.cpp
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   24 1, 2016
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) 2016 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 "vistoolpointofintersectioncurves.h"
30 
31 #include <QGraphicsPathItem>
32 #include <QPainterPath>
33 #include <QPointF>
34 #include <QSharedPointer>
35 #include <Qt>
36 #include <new>
37 
38 #include "../../tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h"
39 #include "../ifc/ifcdef.h"
40 #include "../vgeometry/vabstractcurve.h"
41 #include "../vmisc/vabstractapplication.h"
42 #include "../vpatterndb/vcontainer.h"
43 #include "../vwidgets/vmaingraphicsscene.h"
44 #include "../vwidgets/scalesceneitems.h"
45 #include "../visualization.h"
46 #include "visualization/path/vispath.h"
47 
48 //---------------------------------------------------------------------------------------------------------------------
VisToolPointOfIntersectionCurves(const VContainer * data,QGraphicsItem * parent)49 VisToolPointOfIntersectionCurves::VisToolPointOfIntersectionCurves(const VContainer *data, QGraphicsItem *parent)
50     :VisPath(data, parent),
51       object2Id(NULL_ID),
52       vCrossPoint(VCrossCurvesPoint::HighestPoint),
53       hCrossPoint(HCrossCurvesPoint::LeftmostPoint),
54       point(nullptr),
55       visCurve2(nullptr)
56 {
57     visCurve2 = InitItem<VCurvePathItem>(supportColor, this);
58     point = InitPoint(mainColor, this);
59 }
60 
61 //---------------------------------------------------------------------------------------------------------------------
RefreshGeometry()62 void VisToolPointOfIntersectionCurves::RefreshGeometry()
63 {
64     if (object1Id > NULL_ID)
65     {
66         auto curve1 = Visualization::data->GeometricObject<VAbstractCurve>(object1Id);
67         DrawPath(this, curve1->GetPath(), curve1->DirectionArrows(), supportColor, Qt::SolidLine, Qt::RoundCap);
68 
69         if (object2Id > NULL_ID)
70         {
71             auto curve2 = Visualization::data->GeometricObject<VAbstractCurve>(object2Id);
72             DrawPath(visCurve2, curve2->GetPath(), curve2->DirectionArrows(), supportColor, Qt::SolidLine,
73                      Qt::RoundCap);
74 
75             QPointF p;
76             VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(), vCrossPoint,
77                                                       hCrossPoint, &p);
78             DrawPoint(point, p, mainColor);
79         }
80     }
81 }
82 
83 //---------------------------------------------------------------------------------------------------------------------
VisualMode(const quint32 & id)84 void VisToolPointOfIntersectionCurves::VisualMode(const quint32 &id)
85 {
86     auto scene = qobject_cast<VMainGraphicsScene *>(VAbstractValApplication::VApp()->getCurrentScene());
87     SCASSERT(scene != nullptr)
88 
89     this->object1Id = id;
90     Visualization::scenePos = scene->getScenePos();
91     RefreshGeometry();
92 
93     AddOnScene();
94 }
95 
96 //---------------------------------------------------------------------------------------------------------------------
setObject2Id(const quint32 & value)97 void VisToolPointOfIntersectionCurves::setObject2Id(const quint32 &value)
98 {
99     object2Id = value;
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
setVCrossPoint(const VCrossCurvesPoint & value)103 void VisToolPointOfIntersectionCurves::setVCrossPoint(const VCrossCurvesPoint &value)
104 {
105     vCrossPoint = value;
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
setHCrossPoint(const HCrossCurvesPoint & value)109 void VisToolPointOfIntersectionCurves::setHCrossPoint(const HCrossCurvesPoint &value)
110 {
111     hCrossPoint = value;
112 }
113