Seamly2D
Code documentation
intersect_circles_visual.cpp
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file intersect_circles_visual.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date 29 5, 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 "../../tools/drawTools/toolpoint/toolsinglepoint/intersect_circles_tool.h"
36 #include "../ifc/ifcdef.h"
37 #include "../vgeometry/vpointf.h"
38 #include "../vmisc/vabstractapplication.h"
39 #include "../vmisc/vcommonsettings.h"
40 #include "../vpatterndb/vcontainer.h"
41 #include "../vwidgets/vmaingraphicsscene.h"
42 #include "../visualization.h"
43 
44 #include <QGraphicsEllipseItem>
45 #include <QPen>
46 #include <QPointF>
47 #include <QSharedPointer>
48 #include <Qt>
49 #include <new>
50 
51 //---------------------------------------------------------------------------------------------------------------------
53  : VisLine(data, parent)
54  , object2Id(NULL_ID)
55  , c1Radius(0)
56  , c2Radius(0)
57  , crossPoint(CrossCirclesPoint::FirstPoint)
58  , point(nullptr)
59  , c1Center(nullptr)
60  , c2Center(nullptr)
61  , c1Path(nullptr)
62  , c2Path(nullptr)
63  , m_secondrySupportColor(QColor(qApp->Settings()->getSecondarySupportColor()))
64  , m_tertiarySupportColor(QColor(qApp->Settings()->getTertiarySupportColor()))
65 {
66  this->setPen(QPen(Qt::NoPen)); // don't use parent this time
67 
68  c1Path = InitItem<QGraphicsEllipseItem>(m_secondrySupportColor, this);
69  c2Path = InitItem<QGraphicsEllipseItem>(m_tertiarySupportColor, this);
70  point = InitPoint(mainColor, this);
72  c2Center = InitPoint(supportColor, this); //-V656
73 }
74 
75 //---------------------------------------------------------------------------------------------------------------------
77 {
78  if (object1Id > NULL_ID)
79  {
81  DrawPoint(c1Center, static_cast<QPointF>(*first), supportColor);
82 
83  if (object2Id > NULL_ID)
84  {
86  DrawPoint(c2Center, static_cast<QPointF>(*second), supportColor);
87 
88  if (c1Radius > 0 && c2Radius > 0)
89  {
90  c1Path->setRect(PointRect(c1Radius));
91  DrawPoint(c1Path, static_cast<QPointF>(*first), m_secondrySupportColor, Qt::DashLine);
92 
93  c2Path->setRect(PointRect(c2Radius));
94  DrawPoint(c2Path, static_cast<QPointF>(*second), m_tertiarySupportColor, Qt::DashLine);
95 
96  const QPointF fPoint = IntersectCirclesTool::FindPoint(static_cast<QPointF>(*first),
97  static_cast<QPointF>(*second),
99  DrawPoint(point, fPoint, mainColor);
100  }
101  }
102  }
103 }
104 
105 //---------------------------------------------------------------------------------------------------------------------
106 void IntersectCirclesVisual::VisualMode(const quint32 &id)
107 {
108  VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
109  SCASSERT(scene != nullptr)
110 
111  this->object1Id = id;
113  RefreshGeometry();
114 
115  AddOnScene();
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
119 void IntersectCirclesVisual::setObject2Id(const quint32 &value)
120 {
121  object2Id = value;
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 void IntersectCirclesVisual::setC1Radius(const QString &value)
126 {
127  c1Radius = FindLength(value, Visualization::data->DataVariables());
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
131 void IntersectCirclesVisual::setC2Radius(const QString &value)
132 {
133  c2Radius = FindLength(value, Visualization::data->DataVariables());
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
138 {
139  crossPoint = value;
140 }
static QPointF FindPoint(const QPointF &c1Point, const QPointF &c2Point, qreal c1Radius, qreal c2Radius, const CrossCirclesPoint crossPoint)
void setC1Radius(const QString &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
QGraphicsEllipseItem * c2Path
QGraphicsEllipseItem * c1Path
void setObject2Id(const quint32 &value)
void setCrossPoint(const CrossCirclesPoint &value)
virtual void VisualMode(const quint32 &id) Q_DECL_OVERRIDE
IntersectCirclesVisual(const VContainer *data, QGraphicsItem *parent=nullptr)
void setC2Radius(const QString &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 VMainGraphicsScene class main scene.
QPointF getScenePos() const
The VPointF class keep data of point.
Definition: vpointf.h:75
virtual void AddOnScene() Q_DECL_OVERRIDE
Definition: visline.cpp:149
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
VScaledEllipse * InitPoint(const QColor &color, QGraphicsItem *parent, qreal z=0) const
quint32 object1Id
#define SCASSERT(cond)
Definition: def.h:317
QRectF PointRect(qreal radius)
Definition: global.cpp:95
#define NULL_ID
Definition: ifcdef.h:76
CrossCirclesPoint
#define qApp
Definition: vapplication.h:67