Seamly2D
Code documentation
vmeasurement.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 vstandardtablecell.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
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 "vmeasurement.h"
53 
54 #include <QMap>
55 #include <QMessageLogger>
56 #include <QtDebug>
57 
58 #include "../ifc/ifcdef.h"
59 #include "vvariable.h"
60 #include "vmeasurement_p.h"
61 
62 #ifdef Q_COMPILER_RVALUE_REFS
64 { Swap(m); return *this; }
65 #endif
66 
67 void VMeasurement::Swap(VMeasurement &m) Q_DECL_NOTHROW
68 { VVariable::Swap(m); std::swap(d, m.d); }
69 
70 //---------------------------------------------------------------------------------------------------------------------
71 /**
72  * @brief VMeasurement create measurement for multisize table
73  * @param name measurement's name
74  * @param base value in base size and height
75  * @param ksize increment in sizes
76  * @param kheight increment in heights
77  * @param gui_text shor tooltip for user
78  * @param description measurement full description
79  * @param tagName measurement's tag name in file
80  */
81 VMeasurement::VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base,
82  const qreal &ksize, const qreal &kheight, const QString &gui_text,
83  const QString &description, const QString &tagName)
84  :VVariable(name, description),
85  d(new VMeasurementData(index, gui_text, tagName, baseSize, baseHeight, base, ksize, kheight))
86 {
89 }
90 
91 //---------------------------------------------------------------------------------------------------------------------
92 /**
93  * @brief VMeasurement create measurement for individual table
94  * @param name measurement's name
95  * @param base value in base size and height
96  * @param gui_text shor tooltip for user
97  * @param description measurement full description
98  * @param tagName measurement's tag name in file
99  */
100 VMeasurement::VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base,
101  const QString &formula, bool ok, const QString &gui_text, const QString &description,
102  const QString &tagName)
103  :VVariable(name, description), d(new VMeasurementData(data, index, formula, ok, gui_text, tagName, base))
104 {
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111  :VVariable(m), d(m.d)
112 {}
113 
114 //---------------------------------------------------------------------------------------------------------------------
116 {
117  if ( &m == this )
118  {
119  return *this;
120  }
122  d = m.d;
123  return *this;
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
128 {}
129 
130 //---------------------------------------------------------------------------------------------------------------------
131 QStringList VMeasurement::ListHeights(QMap<GHeights, bool> heights, Unit patternUnit)
132 {
133  QStringList list;
134  if (patternUnit == Unit::Inch)
135  {
136  qWarning()<<"Multisize table doesn't support inches.";
137  return list;
138  }
139 
140  QMap<GHeights, bool>::const_iterator i = heights.constBegin();
141  while (i != heights.constEnd())
142  {
143  if (i.value() && i.key() != GHeights::ALL)
144  {
145  ListValue(list, static_cast<int>(i.key()), patternUnit);
146  }
147  ++i;
148  }
149 
150  if (list.isEmpty())
151  {
152  list = VMeasurement::WholeListHeights(patternUnit);
153  }
154  return list;
155 }
156 
157 //---------------------------------------------------------------------------------------------------------------------
158 QStringList VMeasurement::ListSizes(QMap<GSizes, bool> sizes, Unit patternUnit)
159 {
160  QStringList list;
161  if (patternUnit == Unit::Inch)
162  {
163  qWarning()<<"Multisize table doesn't support inches.";
164  return list;
165  }
166 
167  QMap<GSizes, bool>::const_iterator i = sizes.constBegin();
168  while (i != sizes.constEnd())
169  {
170  if (i.value() && i.key() != GSizes::ALL)
171  {
172  ListValue(list, static_cast<int>(i.key()), patternUnit);
173  }
174  ++i;
175  }
176 
177  if (list.isEmpty())
178  {
179  list = VMeasurement::WholeListSizes(patternUnit);
180  }
181  return list;
182 }
183 
184 //---------------------------------------------------------------------------------------------------------------------
185 QStringList VMeasurement::WholeListHeights(Unit patternUnit)
186 {
187  QStringList list;
188  if (patternUnit == Unit::Inch)
189  {
190  qWarning()<<"Multisize table doesn't support inches.";
191  return list;
192  }
193 
194  for (int i = static_cast<int>(GHeights::H50); i<= static_cast<int>(GHeights::H200); i = i+heightStep)
195  {
196  ListValue(list, i, patternUnit);
197  }
198 
199  return list;
200 }
201 
202 //---------------------------------------------------------------------------------------------------------------------
203 QStringList VMeasurement::WholeListSizes(Unit patternUnit)
204 {
205  QStringList list;
206  if (patternUnit == Unit::Inch)
207  {
208  qWarning()<<"Multisize table doesn't support inches.";
209  return list;
210  }
211 
212  for (int i = static_cast<int>(GSizes::S22); i<= static_cast<int>(GSizes::S72); i = i+sizeStep)
213  {
214  ListValue(list, i, patternUnit);
215  }
216 
217  return list;
218 }
219 
220 //---------------------------------------------------------------------------------------------------------------------
221 bool VMeasurement::IsGradationSizeValid(const QString &size)
222 {
223  if (not size.isEmpty())
224  {
225  const QStringList sizes = VMeasurement::WholeListSizes(Unit::Cm);
226  return sizes.contains(size);
227  }
228  else
229  {
230  return false;
231  }
232 }
233 
234 //---------------------------------------------------------------------------------------------------------------------
235 bool VMeasurement::IsGradationHeightValid(const QString &height)
236 {
237  if (not height.isEmpty())
238  {
239  const QStringList heights = VMeasurement::WholeListHeights(Unit::Cm);
240  return heights.contains(height);
241  }
242  else
243  {
244  return false;
245  }
246 }
247 
248 //---------------------------------------------------------------------------------------------------------------------
250 {
251  if (d->currentUnit == nullptr || d->currentSize == nullptr || d->currentHeight == nullptr)
252  {
254  }
255 
256  if (*d->currentUnit == Unit::Inch)
257  {
258  qWarning("Gradation doesn't support inches");
259  return 0;
260  }
261 
262  const qreal sizeIncrement = UnitConvertor(2.0, Unit::Cm, *d->currentUnit);
263  const qreal heightIncrement = UnitConvertor(6.0, Unit::Cm, *d->currentUnit);
264 
265  // Formula for calculation gradation
266  const qreal k_size = ( *d->currentSize - d->baseSize ) / sizeIncrement;
267  const qreal k_height = ( *d->currentHeight - d->baseHeight ) / heightIncrement;
268  return d->base + k_size * d->ksize + k_height * d->kheight;
269 }
270 
271 //---------------------------------------------------------------------------------------------------------------------
272 void VMeasurement::ListValue(QStringList &list, qreal value, Unit patternUnit)
273 {
274  const qreal val = UnitConvertor(value, Unit::Cm, patternUnit);
275  const QString strVal = QString("%1").arg(val);
276  list.append(strVal);
277 }
278 
279 //---------------------------------------------------------------------------------------------------------------------
280 /**
281  * @brief getGuiText measurement name for tooltip
282  * @return measurement name
283  */
285 {
286  return d->gui_text;
287 }
288 
289 //---------------------------------------------------------------------------------------------------------------------
290 QString VMeasurement::TagName() const
291 {
292  return d->_tagName;
293 }
294 
295 //---------------------------------------------------------------------------------------------------------------------
296 void VMeasurement::setTagName(const QString &tagName)
297 {
298  d->_tagName = tagName;
299 }
300 
301 //---------------------------------------------------------------------------------------------------------------------
303 {
304  return d->formula;
305 }
306 
307 //---------------------------------------------------------------------------------------------------------------------
309 {
310  return GetName().indexOf(CustomMSign) == 0;
311 }
312 
313 //---------------------------------------------------------------------------------------------------------------------
315 {
316  return static_cast<int>(d->index);
317 }
318 
319 //---------------------------------------------------------------------------------------------------------------------
321 {
322  return d->formulaOk;
323 }
324 
325 //---------------------------------------------------------------------------------------------------------------------
327 {
328  return qFuzzyIsNull(d->base) && qFuzzyIsNull(d->ksize) && qFuzzyIsNull(d->kheight);
329 }
330 
331 //---------------------------------------------------------------------------------------------------------------------
333 {
334  return CalcValue();
335 }
336 
337 //---------------------------------------------------------------------------------------------------------------------
339 {
342 }
343 
344 //---------------------------------------------------------------------------------------------------------------------
346 {
347  return &d->data;
348 }
349 
350 //---------------------------------------------------------------------------------------------------------------------
351 void VMeasurement::SetSize(qreal *size)
352 {
353  d->currentSize = size;
354 }
355 
356 //---------------------------------------------------------------------------------------------------------------------
357 void VMeasurement::SetHeight(qreal *height)
358 {
359  d->currentHeight = height;
360 }
361 
362 //---------------------------------------------------------------------------------------------------------------------
363 void VMeasurement::SetUnit(const Unit *unit)
364 {
365  d->currentUnit = unit;
366 }
367 
368 //---------------------------------------------------------------------------------------------------------------------
369 /**
370  * @brief GetBase return value in base size and height
371  * @return value
372  */
374 {
375  return d->base;
376 }
377 
378 //---------------------------------------------------------------------------------------------------------------------
379 void VMeasurement::SetBase(const qreal &value)
380 {
381  d->base = value;
382 }
383 
384 //---------------------------------------------------------------------------------------------------------------------
385 /**
386  * @brief GetKsize return increment in sizes
387  * @return increment
388  */
390 {
391  return d->ksize;
392 }
393 
394 //---------------------------------------------------------------------------------------------------------------------
395 // cppcheck-suppress unusedFunction
396 void VMeasurement::SetKsize(const qreal &value)
397 {
398  d->ksize = value;
399 }
400 
401 //---------------------------------------------------------------------------------------------------------------------
402 /**
403  * @brief GetKheight return increment in heights
404  * @return increment
405  */
407 {
408  return d->kheight;
409 }
410 
411 //---------------------------------------------------------------------------------------------------------------------
412 // cppcheck-suppress unusedFunction
413 void VMeasurement::SetKheight(const qreal &value)
414 {
415  d->kheight = value;
416 }
The VContainer class container of all variables.
Definition: vcontainer.h:141
void SetType(const VarType &type)
QString GetName() const
virtual qreal GetValue() const
void SetValue(const qreal &value)
The VMeasurement class keep data row of multisize table.
Definition: vmeasurement.h:74
QString GetFormula() const
QString TagName() const
qreal GetKheight() const
GetKheight return increment in heights.
VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base, const qreal &ksize, const qreal &kheight, const QString &gui_text=QString(), const QString &description=QString(), const QString &tagName=QString())
VMeasurement create measurement for multisize table.
QSharedDataPointer< VMeasurementData > d
Definition: vmeasurement.h:132
void SetSize(qreal *size)
void SetHeight(qreal *height)
virtual qreal GetValue() const Q_DECL_OVERRIDE
void SetKsize(const qreal &value)
void SetUnit(const Unit *unit)
void SetBase(const qreal &value)
static QStringList WholeListSizes(Unit patternUnit)
void setTagName(const QString &tagName)
qreal CalcValue() const
void Swap(VMeasurement &m) Q_DECL_NOTHROW
static QStringList WholeListHeights(Unit patternUnit)
static void ListValue(QStringList &list, qreal value, Unit patternUnit)
static QStringList ListSizes(QMap< GSizes, bool > sizes, Unit patternUnit)
virtual ~VMeasurement() Q_DECL_OVERRIDE
bool isCustom() const
bool IsFormulaOk() const
void SetKheight(const qreal &value)
static bool IsGradationSizeValid(const QString &size)
qreal GetKsize() const
GetKsize return increment in sizes.
static QStringList ListHeights(QMap< GHeights, bool > heights, Unit patternUnit)
VMeasurement & operator=(const VMeasurement &m)
VContainer * GetData()
int Index() const
virtual bool isNotUsed() const Q_DECL_OVERRIDE
static bool IsGradationHeightValid(const QString &height)
QString getGuiText() const
getGuiText measurement name for tooltip
qreal GetBase() const
GetBase return value in base size and height.
VVariable & operator=(const VVariable &var)
Definition: vvariable.cpp:86
void Swap(VVariable &var) Q_DECL_NOTHROW
Definition: vvariable.cpp:65
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
static const int heightStep
Definition: def.h:279
Unit
Definition: def.h:105
static const int sizeStep
Definition: def.h:286
const QString CustomMSign
Definition: ifcdef.cpp:70