Seamly2D
Code documentation
intersect_circletangent_visual.cpp
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file intersect_circletangent_visual.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date 5 6, 2015
6  **
7  ** @author Douglas S. Caskey
8  ** @date 7.16.2022
9  **
10  ** @copyright
11  ** Copyright (C) 2013-2022 Seamly2D project.
12  ** This source code is part of the Seamly2D project, a pattern making
13  ** program, whose allow create and modeling patterns of clothing.
14  **
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
19  ** by the Free Software Foundation, either version 3 of the License,
20  ** or (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 "../ifc/ifcdef.h"
36 #include "../visualization.h"
37 #include "../vgeometry/vgobject.h"
38 #include "../vgeometry/vpointf.h"
39 #include "../vmisc/vcommonsettings.h"
40 #include "../vpatterndb/vcontainer.h"
41 #include "../../tools/drawTools/toolpoint/toolsinglepoint/intersect_circletangent_tool.h"
42 
43 #include <QGraphicsEllipseItem>
44 #include <QGraphicsLineItem>
45 #include <QSharedPointer>
46 #include <Qt>
47 #include <new>
48 
49 //---------------------------------------------------------------------------------------------------------------------
51  : VisLine(data, parent)
52  , object2Id(NULL_ID)
53  , cRadius(0)
54  , crossPoint(CrossCirclesPoint::FirstPoint)
55  , point(nullptr)
56  , tangent(nullptr)
57  , cCenter(nullptr)
58  , cPath(nullptr)
59  , tangent2(nullptr)
60  , m_secondarySupportColor(QColor(qApp->Settings()->getSecondarySupportColor()))
61 
62 {
63  cPath = InitItem<QGraphicsEllipseItem>(m_secondarySupportColor, this);
64  point = InitPoint(mainColor, this);
66  cCenter = InitPoint(supportColor, this); //-V656
67  tangent2 = InitItem<VScaledLine>(supportColor, this);
68 }
69 
70 //---------------------------------------------------------------------------------------------------------------------
72 {
73  if (object1Id > NULL_ID)// tangent point
74  {
76  DrawPoint(tangent, static_cast<QPointF>(*tan), supportColor);
77 
78  if (object2Id > NULL_ID)// circle center
79  {
81  DrawPoint(cCenter, static_cast<QPointF>(*center), supportColor);
82 
83  if (cRadius > 0)
84  {
85  cPath->setRect(PointRect(cRadius));
86  DrawPoint(cPath, static_cast<QPointF>(*center), m_secondarySupportColor, Qt::DashLine);
87 
88  FindRays(static_cast<QPointF>(*tan), static_cast<QPointF>(*center), cRadius);
89 
90  const QPointF fPoint = IntersectCircleTangentTool::FindPoint(static_cast<QPointF>(*tan),
91  static_cast<QPointF>(*center),
93  DrawPoint(point, fPoint, mainColor);
94  }
95  }
96  }
97 }
98 
99 //---------------------------------------------------------------------------------------------------------------------
101 {
102  object2Id = value;
103 }
104 
105 //---------------------------------------------------------------------------------------------------------------------
107 {
108  cRadius = FindLength(value, Visualization::data->DataVariables());
109 }
110 
111 //---------------------------------------------------------------------------------------------------------------------
113 {
114  crossPoint = value;
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
118 void IntersectCircleTangentVisual::FindRays(const QPointF &p, const QPointF &center, qreal radius)
119 {
120  QPointF p1, p2;
121  const int res = VGObject::ContactPoints (p, center, radius, p1, p2);
122 
123  switch(res)
124  {
125  case 2:
126  DrawRay(this, p, p1, supportColor, Qt::DashLine);
127  DrawRay(tangent2, p, p2, supportColor, Qt::DashLine);
128  break;
129  case 1:
130  DrawRay(this, p, p1, supportColor, Qt::DashLine);
131  tangent2->setVisible(false);
132  break;
133  default:
134  this->setVisible(false);
135  tangent2->setVisible(false);
136  break;
137  }
138 }
static QPointF FindPoint(const QPointF &p, const QPointF &center, qreal radius, const CrossCirclesPoint crossPoint)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setCrossPoint(const CrossCirclesPoint &value)
IntersectCircleTangentVisual(const VContainer *data, QGraphicsItem *parent=nullptr)
void FindRays(const QPointF &p, const QPointF &center, qreal radius)
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
static int ContactPoints(const QPointF &p, const QPointF &center, qreal radius, QPointF &p1, QPointF &p2)
Definition: vgobject.cpp:286
The VPointF class keep data of point.
Definition: vpointf.h:75
void DrawRay(VScaledLine *lineItem, const QPointF &p, const QPointF &pTangent, const QColor &color, Qt::PenStyle style)
Definition: visline.cpp:155
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
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
QRectF PointRect(qreal radius)
Definition: global.cpp:95
#define NULL_ID
Definition: ifcdef.h:76
CrossCirclesPoint
#define qApp
Definition: vapplication.h:67