Seamly2D
Code documentation
vistoolcurveintersectaxis.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 vistoolcurveintersectaxis.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 21 10, 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 
53 
54 #include <QColor>
55 #include <QGraphicsLineItem>
56 #include <QGraphicsPathItem>
57 #include <QLineF>
58 #include <QPainterPath>
59 #include <QPointF>
60 #include <QSharedPointer>
61 #include <Qt>
62 #include <new>
63 
64 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h"
65 #include "../ifc/ifcdef.h"
66 #include "../vgeometry/vabstractcurve.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), axisPointId(NULL_ID), angle(-1), point(nullptr), basePoint(nullptr), baseLine(nullptr),
75  axisLine(nullptr), visCurve(nullptr)
76 {
77  this->mainColor = Qt::red;
78 
79  visCurve = InitItem<VCurvePathItem>(Qt::darkGreen, this);
81  baseLine = InitItem<VScaledLine>(supportColor, this);
82  axisLine = InitItem<VScaledLine>(supportColor, this); //-V656
83  point = InitPoint(mainColor, this);
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
88 {
89  if (object1Id > NULL_ID)
90  {
92  DrawPath(visCurve, curve->GetPath(), curve->DirectionArrows(), supportColor, Qt::SolidLine,
93  lineWeight, Qt::RoundCap);
94 
95  if (axisPointId > NULL_ID)
96  {
97  QLineF axis;
100  {
101  axis = Axis(static_cast<QPointF>(*first), Visualization::scenePos);
102  }
103  else
104  {
105  axis = Axis(static_cast<QPointF>(*first), angle);
106  }
107  DrawPoint(basePoint, static_cast<QPointF>(*first), mainColor);
108  DrawLine(axisLine, axis, supportColor, lineWeight, Qt::DashLine);
109 
110  QPointF intersectPoint;
111  const bool isIntersect = VToolCurveIntersectAxis::FindPoint(static_cast<QPointF>(*first), axis.angle(),
112  curve, &intersectPoint);
113  if (isIntersect)
114  {
115  QLineF axis_line(static_cast<QPointF>(*first), intersectPoint);
116  DrawLine(this, axis_line, mainColor, lineWeight, lineStyle);
117  DrawPoint(point, intersectPoint, mainColor);
118  }
119 
120  Visualization::toolTip = tr("<b>Intersection curve and axis</b>: angle = %1°, "
121  "Hold <b>SHIFT</b> to constrain angle, "
122  "Press <b>ENTER</b> to finish tool creation ")
123  .arg(this->line().angle());
124  }
125  }
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
130 {
131  return QString("%1").arg(this->line().angle());
132 }
133 
134 //---------------------------------------------------------------------------------------------------------------------
135 void VisToolCurveIntersectAxis::SetAngle(const QString &expression)
136 {
137  angle = FindVal(expression, Visualization::data->DataVariables());
138 }
139 
140 //---------------------------------------------------------------------------------------------------------------------
142 {
143  axisPointId = value;
144 }
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 bool FindPoint(const QPointF &point, qreal angle, const QSharedPointer< VAbstractCurve > &curve, QPointF *intersectPoint)
QLineF Axis(const QPointF &p, const qreal &angle) const
Definition: visline.cpp:123
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void SetAngle(const QString &expression)
void setAxisPointId(const quint32 &value)
VisToolCurveIntersectAxis(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)
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)
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
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
Qt::PenStyle lineStyle
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
Definition: def.h:490
#define NULL_ID
Definition: ifcdef.h:76