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