Seamly2D
Code documentation
vistoolpointfromarcandtangent.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 vistoolpointfromarcandtangent.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 6 6, 2015
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) 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 <QGraphicsLineItem>
55 #include <QGraphicsPathItem>
56 #include <QLineF>
57 #include <QPainterPath>
58 #include <QSharedPointer>
59 #include <Qt>
60 #include <new>
61 
62 #include "../../tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h"
63 #include "../ifc/ifcdef.h"
64 #include "../vgeometry/vabstractcurve.h"
65 #include "../vgeometry/varc.h"
66 #include "../vgeometry/vgobject.h"
67 #include "../vgeometry/vpointf.h"
68 #include "../vpatterndb/vcontainer.h"
69 #include "../visualization.h"
70 #include "visline.h"
71 
72 //---------------------------------------------------------------------------------------------------------------------
74  : VisLine(data, parent), arcId(NULL_ID), crossPoint(CrossCirclesPoint::FirstPoint),
75  point(nullptr), tangent(nullptr), arcPath(nullptr), tangentLine2(nullptr)
76 {
77  arcPath = InitItem<VCurvePathItem>(Qt::darkGreen, this);
78  point = InitPoint(mainColor, this);
80  tangentLine2 = InitItem<VScaledLine>(supportColor, this);
81 }
82 
83 //---------------------------------------------------------------------------------------------------------------------
85 {
86  if (object1Id > NULL_ID)// tangent point
87  {
89  DrawPoint(tangent, static_cast<QPointF>(*tan), supportColor);
90 
91  if (arcId > NULL_ID)// circle center
92  {
94  DrawPath(arcPath, arc->GetPath(), arc->DirectionArrows(), Qt::darkGreen, Qt::SolidLine,
95  lineWeight, Qt::RoundCap);
96 
97  FindRays(static_cast<QPointF>(*tan), arc.data());
98 
99  const QPointF fPoint = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(*tan), arc.data(),
100  crossPoint);
101  DrawPoint(point, fPoint, mainColor);
102  }
103  }
104 }
105 
106 //---------------------------------------------------------------------------------------------------------------------
107 void VisToolPointFromArcAndTangent::setArcId(const quint32 &value)
108 {
109  arcId = value;
110 }
111 
112 //---------------------------------------------------------------------------------------------------------------------
114 {
115  crossPoint = value;
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
119 void VisToolPointFromArcAndTangent::FindRays(const QPointF &p, const VArc *arc)
120 {
121  QPointF p1, p2;
122  const QPointF center = static_cast<QPointF>(arc->GetCenter());
123  const qreal radius = arc->GetRadius();
124  const int res = VGObject::ContactPoints (p, center, radius, p1, p2);
125 
126  QLineF r1Arc(center, p1);
127  r1Arc.setLength(radius+10);
128 
129  QLineF r2Arc(center, p2);
130  r2Arc.setLength(radius+10);
131 
132  switch(res)
133  {
134  case 2:
135  {
136  int localRes = 0;
137  if (arc->IsIntersectLine(r1Arc))
138  {
139  ++localRes;
140  }
141 
142  if (arc->IsIntersectLine(r2Arc))
143  {
144  ++localRes;
145  }
146 
147  switch(localRes)
148  {
149  case 2:
150  DrawRay(this, p, p1, supportColor, Qt::DashLine);
151  DrawRay(tangentLine2, p, p2, supportColor, Qt::DashLine);
152  break;
153  case 1:
154  DrawRay(this, p, p1, supportColor, Qt::DashLine);
155  tangentLine2->setVisible(false);
156  break;
157  case 0:
158  default:
159  this->setVisible(false);
160  tangentLine2->setVisible(false);
161  break;
162  }
163 
164  break;
165  }
166  case 1:
167  DrawRay(this, p, p1, supportColor, Qt::DashLine);
168  tangentLine2->setVisible(false);
169  break;
170  case 3:
171  case 0:
172  default:
173  this->setVisible(false);
174  tangentLine2->setVisible(false);
175  break;
176  }
177 }
virtual VPointF GetCenter() const
virtual bool IsIntersectLine(const QLineF &line) const
VArc class for anticlockwise arc.
Definition: varc.h:74
qreal GetRadius() const
GetRadius return formula for radius.
Definition: varc.cpp:482
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
static QPointF FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType)
void DrawRay(VScaledLine *lineItem, const QPointF &p, const QPointF &pTangent, const QColor &color, Qt::PenStyle style)
Definition: visline.cpp:155
void FindRays(const QPointF &p, const VArc *arc)
VisToolPointFromArcAndTangent(const VContainer *data, QGraphicsItem *parent=nullptr)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setCrossPoint(const CrossCirclesPoint &value)
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
void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style=Qt::SolidLine, const qreal &weight=0.35, Qt::PenCapStyle cap=Qt::SquareCap)
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
#define NULL_ID
Definition: ifcdef.h:76
CrossCirclesPoint