Seamly2D
Code documentation
vistoolpointofcontact.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 vistoolpointofcontact.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 14 8, 2014
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) 2013-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 
52 #include "vistoolpointofcontact.h"
53 
54 #include <QGraphicsEllipseItem>
55 #include <QLineF>
56 #include <QPointF>
57 #include <QSharedPointer>
58 #include <Qt>
59 #include <new>
60 
61 #include "../../tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h"
62 #include "../ifc/ifcdef.h"
63 #include "../vgeometry/vpointf.h"
64 #include "../vpatterndb/vcontainer.h"
65 #include "../visualization.h"
66 #include "visline.h"
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent)
70  :VisLine(data, parent), lineP2Id(NULL_ID), radiusId(NULL_ID), point(nullptr), lineP1(nullptr), lineP2(nullptr),
71  arc_point(nullptr), circle(nullptr), radius(0)
72 {
74  lineP1 = InitPoint(supportColor, this);
75  lineP2 = InitPoint(supportColor, this);
76  circle = InitItem<VScaledEllipse>(supportColor, this);
77 
78  point = InitPoint(mainColor, this);
79 }
80 
81 //---------------------------------------------------------------------------------------------------------------------
83 {
84  if (object1Id > NULL_ID)
85  {
87  DrawPoint(lineP1, static_cast<QPointF>(*first), supportColor);
88 
89  if (lineP2Id <= NULL_ID)
90  {
91  DrawLine(this, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor, lineWeight);
92  }
93  else
94  {
96  DrawPoint(lineP2, static_cast<QPointF>(*second), supportColor);
97  DrawLine(this, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)),
99 
100  if (radiusId <= NULL_ID)
101  {
102  return;
103  }
104  else
105  {
107  DrawPoint(arc_point, static_cast<QPointF>(*third), supportColor);
108 
109  if (not qFuzzyIsNull(radius))
110  {
111  QPointF fPoint = VToolPointOfContact::FindPoint(radius, static_cast<QPointF>(*third),
112  static_cast<QPointF>(*first),
113  static_cast<QPointF>(*second));
114  DrawPoint(point, fPoint, mainColor);
115 
116  circle->setRect(PointRect(radius));
117  DrawPoint(circle, static_cast<QPointF>(*third), supportColor, Qt::DashLine);
118  }
119  }
120  }
121  }
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 void VisToolPointOfContact::setLineP2Id(const quint32 &value)
126 {
127  lineP2Id = value;
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
131 void VisToolPointOfContact::setRadiusId(const quint32 &value)
132 {
133  radiusId = value;
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
137 void VisToolPointOfContact::setRadius(const QString &expression)
138 {
139  radius = FindLength(expression, Visualization::data->DataVariables());
140 }
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
static QPointF FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint, const QPointF &secondPoint)
FindPoint return point intersection arc and line.
void setLineP2Id(const quint32 &value)
void setRadiusId(const quint32 &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setRadius(const QString &expression)
VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent=nullptr)
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
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
QRectF PointRect(qreal radius)
Definition: global.cpp:95
#define NULL_ID
Definition: ifcdef.h:76