Seamly2D
Code documentation
vabstractarc.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 vabstractarc.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 10 4, 2016
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) 2016 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 "vabstractarc.h"
53 
54 #include <QLineF>
55 
56 #include "../vmisc/def.h"
57 #include "vabstractarc_p.h"
58 #include "vpointf.h"
59 
60 #ifdef Q_COMPILER_RVALUE_REFS
62 {
63  Swap(arc); return *this;
64 }
65 #endif
66 
67 void VAbstractArc::Swap(VAbstractArc &arc) Q_DECL_NOTHROW
68 { VAbstractCurve::Swap(arc); std::swap(d, arc.d); }
69 
70 //---------------------------------------------------------------------------------------------------------------------
71 VAbstractArc::VAbstractArc(const GOType &type, const quint32 &idObject, const Draw &mode)
72  : VAbstractCurve(type, idObject, mode), d (new VAbstractArcData())
73 {}
74 
75 //---------------------------------------------------------------------------------------------------------------------
76 VAbstractArc::VAbstractArc(const GOType &type, const VPointF &center, qreal f1, const QString &formulaF1, qreal f2,
77  const QString &formulaF2, quint32 idObject, Draw mode)
78  : VAbstractCurve(type, idObject, mode)
79  , d (new VAbstractArcData(center, f1, formulaF1, f2, formulaF2))
80 {}
81 
82 //---------------------------------------------------------------------------------------------------------------------
83 VAbstractArc::VAbstractArc(const GOType &type, const VPointF &center, qreal f1, qreal f2, quint32 idObject, Draw mode)
84  : VAbstractCurve(type, idObject, mode)
85  , d (new VAbstractArcData(center, f1, f2))
86 {}
87 
88 //---------------------------------------------------------------------------------------------------------------------
89 VAbstractArc::VAbstractArc(const GOType &type, const QString &formulaLength, const VPointF &center,
90  qreal f1, const QString &formulaF1, quint32 idObject, Draw mode)
91  : VAbstractCurve(type, idObject, mode)
92  , d (new VAbstractArcData(formulaLength, center, f1, formulaF1))
93 {}
94 
95 //---------------------------------------------------------------------------------------------------------------------
96 VAbstractArc::VAbstractArc(const GOType &type, const VPointF &center, qreal f1, quint32 idObject, Draw mode)
97  : VAbstractCurve(type, idObject, mode)
98  , d (new VAbstractArcData(center, f1))
99 {}
100 
101 //---------------------------------------------------------------------------------------------------------------------
103  : VAbstractCurve(arc)
104  , d (arc.d)
105 {}
106 
107 //---------------------------------------------------------------------------------------------------------------------
109 {
110  if ( &arc == this )
111  {
112  return *this;
113  }
115  d = arc.d;
116  return *this;
117 }
118 
119 //---------------------------------------------------------------------------------------------------------------------
121 {}
122 
123 //---------------------------------------------------------------------------------------------------------------------
125 {
126  return d->formulaF1;
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
130 void VAbstractArc::SetFormulaF1(const QString &formula, qreal value)
131 {
132  d->formulaF1 = formula;
133  d->f1 = value;
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
138 {
139  return d->f1;
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
144 {
145  return d->formulaF2;
146 }
147 
148 //---------------------------------------------------------------------------------------------------------------------
149 void VAbstractArc::SetFormulaF2(const QString &formula, qreal value)
150 {
151  d->formulaF2 = formula;
152  d->f2 = value;
153 }
154 
155 //---------------------------------------------------------------------------------------------------------------------
157 {
158  return d->f2;
159 }
160 
161 //---------------------------------------------------------------------------------------------------------------------
163 {
164  return d->center;
165 }
166 
167 //---------------------------------------------------------------------------------------------------------------------
169 {
170  d->center = point;
171 }
172 
173 //---------------------------------------------------------------------------------------------------------------------
175 {
176  return d->formulaLength;
177 }
178 
179 //---------------------------------------------------------------------------------------------------------------------
180 void VAbstractArc::SetFormulaLength(const QString &formula, qreal value)
181 {
182  d->formulaLength = formula;
183  FindF2(value);
184 }
185 
186 //---------------------------------------------------------------------------------------------------------------------
187 void VAbstractArc::setId(const quint32 &id)
188 {
190  CreateName();
191 }
192 
193 //---------------------------------------------------------------------------------------------------------------------
194 QString VAbstractArc::NameForHistory(const QString &toolName) const
195 {
196  QString name = toolName + QString(" %1").arg(GetCenter().name());
197 
198  if (VAbstractCurve::id() != NULL_ID)
199  {
200  name += QString("_%1").arg(VAbstractCurve::id());
201  }
202 
203  if (GetDuplicate() > 0)
204  {
205  name += QString("_%1").arg(GetDuplicate());
206  }
207  return name;
208 }
209 
210 //---------------------------------------------------------------------------------------------------------------------
212 {
213  return d->isFlipped;
214 }
215 
216 //---------------------------------------------------------------------------------------------------------------------
218 {
219  {
220  const qreal angleDiff = qAbs(GetStartAngle() - GetEndAngle());
221  if (VFuzzyComparePossibleNulls(angleDiff, 0) || VFuzzyComparePossibleNulls(angleDiff, 360))
222  {
223  return 360;
224  }
225  }
226  QLineF l1(0, 0, 100, 0);
227  l1.setAngle(GetStartAngle());
228  QLineF l2(0, 0, 100, 0);
229  l2.setAngle(GetEndAngle());
230 
231  qreal ang = l1.angleTo(l2);
232 
233  if (IsFlipped())
234  {
235  ang = 360 - ang;
236  }
237 
238  return ang;
239 }
240 
241 //---------------------------------------------------------------------------------------------------------------------
242 void VAbstractArc::SetFlipped(bool value)
243 {
244  d->isFlipped = value;
245 }
246 
247 //---------------------------------------------------------------------------------------------------------------------
248 void VAbstractArc::SetFormulaLength(const QString &formula)
249 {
250  d->formulaLength = formula;
251 }
qreal AngleArc() const
QSharedDataPointer< VAbstractArcData > d
Definition: vabstractarc.h:122
VAbstractArc(const GOType &type, const quint32 &idObject=null_id, const Draw &mode=Draw::Calculation)
void Swap(VAbstractArc &arc) Q_DECL_NOTHROW
virtual VPointF GetCenter() const
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE
QString GetFormulaF1() const
VAbstractArc & operator=(const VAbstractArc &arc)
QString GetFormulaLength() const
void SetCenter(const VPointF &point)
virtual void FindF2(qreal length)=0
QString GetFormulaF2() const
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE
setId set id object.
void SetFormulaF2(const QString &formula, qreal value)
void SetFormulaLength(const QString &formula, qreal value)
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
void SetFormulaF1(const QString &formula, qreal value)
virtual ~VAbstractArc()
bool IsFlipped() const
void SetFlipped(bool value)
VAbstractCurve & operator=(const VAbstractCurve &curve)
virtual void CreateName()=0
quint32 GetDuplicate() const
void Swap(VAbstractCurve &curve) Q_DECL_NOTHROW
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
quint32 id() const
id return id object.
Definition: vgobject.cpp:205
virtual void setId(const quint32 &id)
setId set id object.
Definition: vgobject.cpp:215
The VPointF class keep data of point.
Definition: vpointf.h:75
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
Definition: def.h:490
#define NULL_ID
Definition: ifcdef.h:76
GOType
Definition: vgeometrydef.h:56
Draw
Definition: vgeometrydef.h:55