Seamly2D
Code documentation
vistoolshoulderpoint.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 vistoolshoulderpoint.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 25 7, 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 "vistoolshoulderpoint.h"
53 
54 #include <QGraphicsLineItem>
55 #include <QLineF>
56 #include <QPointF>
57 #include <QSharedPointer>
58 #include <Qt>
59 #include <new>
60 
61 #include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h"
62 #include "../ifc/ifcdef.h"
63 #include "../vgeometry/vgobject.h"
64 #include "../vgeometry/vpointf.h"
65 #include "../vpatterndb/vcontainer.h"
66 #include "../visualization.h"
67 #include "visline.h"
68 
69 //---------------------------------------------------------------------------------------------------------------------
70 VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent)
71  :VisLine(data, parent), lineP1Id(NULL_ID), lineP2Id(NULL_ID), point(nullptr), line1P1(nullptr), line1P2(nullptr),
72  line1(nullptr), line2P2(nullptr), line2(nullptr), line3(nullptr), length(0)
73 {
75  line1P2 = InitPoint(supportColor, this); //-V656
76  line1 = InitItem<VScaledLine>(supportColor, this);
77 
79  line2 = InitItem<VScaledLine>(supportColor, this);
80  line3 = InitItem<VScaledLine>(supportColor, this); //-V656
81 
82  point = InitPoint(mainColor, this);
83 }
84 
85 //---------------------------------------------------------------------------------------------------------------------
87 {
88  if (object1Id > NULL_ID)
89  {
91  DrawPoint(line1P1, static_cast<QPointF>(*first), supportColor);
92 
93  if (lineP1Id <= NULL_ID)
94  {
95  DrawLine(line1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor, lineWeight);
96  }
97  else
98  {
100  DrawPoint(line1P2, static_cast<QPointF>(*second), supportColor);
101 
102  DrawLine(line1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)),
104 
105  if (lineP2Id <= NULL_ID)
106  {
107  DrawLine(line2, QLineF(static_cast<QPointF>(*second), Visualization::scenePos),
109  }
110  else
111  {
113  DrawPoint(line2P2, static_cast<QPointF>(*third), supportColor);
114 
115  DrawLine(line2, QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third)),
117 
118  if (not qFuzzyIsNull(length))
119  {
120  QPointF fPoint = VToolShoulderPoint::FindPoint(static_cast<QPointF>(*second),
121  static_cast<QPointF>(*third),
122  static_cast<QPointF>(*first), length);
123  QLineF mainLine = QLineF(static_cast<QPointF>(*second), fPoint);
124  DrawLine(this, mainLine, mainColor, lineWeight, lineStyle);
125 
126  DrawPoint(point, mainLine.p2(), mainColor);
127  DrawLine(line3, QLineF(static_cast<QPointF>(*first), mainLine.p2()), supportColor,
128  lineWeight, Qt::DashLine);
129  }
130  else
131  {
132  qreal angle = QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third)).angle();
133  QPointF endRay = Ray(static_cast<QPointF>(*second), angle);
134  QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*second),
135  QLineF(static_cast<QPointF>(*second), endRay).length(),
136  angle);
137  DrawLine(this, mainLine, mainColor, lineWeight, lineStyle);
138  }
139  }
140  }
141  }
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
145 void VisToolShoulderPoint::setLineP1Id(const quint32 &value)
146 {
147  lineP1Id = value;
148 }
149 
150 //---------------------------------------------------------------------------------------------------------------------
151 void VisToolShoulderPoint::setLineP2Id(const quint32 &value)
152 {
153  lineP2Id = value;
154 }
155 
156 //---------------------------------------------------------------------------------------------------------------------
157 void VisToolShoulderPoint::setLength(const QString &expression)
158 {
159  length = FindLength(expression, Visualization::data->DataVariables());
160 }
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
static QLineF BuildLine(const QPointF &p1, const qreal &length, const qreal &angle)
Definition: vgobject.cpp:241
The VPointF class keep data of point.
Definition: vpointf.h:75
static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, const qreal &length)
FindPoint find point.
QPointF Ray(const QPointF &firstPoint, const qreal &angle) const
Definition: visline.cpp:85
VScaledEllipse * line1P2
VScaledEllipse * line1P1
void setLength(const QString &expression)
void setLineP1Id(const quint32 &value)
VScaledEllipse * line2P2
VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent=nullptr)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setLineP2Id(const quint32 &value)
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
Qt::PenStyle lineStyle
#define NULL_ID
Definition: ifcdef.h:76