2020-09-28 15:38:32 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vdimensions.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 25 9, 2020
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2020 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
#include "vdimensions.h"
|
|
|
|
|
|
|
|
#include <QSet>
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units)
|
|
|
|
: m_units(units)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units, int min, int max, int step)
|
|
|
|
: m_units(units),
|
|
|
|
m_minValue(min),
|
|
|
|
m_maxValue(max),
|
|
|
|
m_step(step)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstartMeasurementDimension::IsValid()
|
|
|
|
{
|
|
|
|
m_error.clear();
|
|
|
|
return IsUnitsValid() && IsRangeValid() && IsStepValid() && IsBaseValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<int> VAbstartMeasurementDimension::ValidSteps() const
|
|
|
|
{
|
|
|
|
QVector<int> steps;
|
|
|
|
|
|
|
|
const int diff = m_maxValue - m_minValue;
|
|
|
|
if (diff == 0)
|
|
|
|
{
|
|
|
|
steps.append(0); // only one possible value
|
|
|
|
}
|
|
|
|
else if (diff > 0)
|
|
|
|
{
|
2020-10-05 09:13:44 +02:00
|
|
|
for (int i=1; i < 9; ++i)
|
2020-09-28 15:38:32 +02:00
|
|
|
{
|
2020-10-05 09:13:44 +02:00
|
|
|
const int step = (m_units == Unit::Mm ? i * 10 : i);
|
2020-09-28 15:38:32 +02:00
|
|
|
if (diff % step == 0)
|
|
|
|
{
|
|
|
|
steps.append(step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<int> VAbstartMeasurementDimension::ValidBases() const
|
2020-10-07 16:12:53 +02:00
|
|
|
{
|
|
|
|
return VAbstartMeasurementDimension::ValidBases(m_minValue, m_maxValue, m_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VAbstartMeasurementDimension::ValidBasesList() const
|
|
|
|
{
|
|
|
|
QVector<int> bases = ValidBases();
|
|
|
|
QStringList list;
|
|
|
|
for(auto &base : bases)
|
|
|
|
{
|
|
|
|
list.append(QString::number(base));
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<int> VAbstartMeasurementDimension::ValidBases(int min, int max, int step)
|
2020-09-28 15:38:32 +02:00
|
|
|
{
|
|
|
|
QVector<int> validBases;
|
|
|
|
|
|
|
|
if (step < 0)
|
|
|
|
{
|
|
|
|
return validBases;
|
|
|
|
}
|
|
|
|
else if (step == 0)
|
|
|
|
{
|
|
|
|
step = 1;
|
|
|
|
}
|
|
|
|
|
2020-10-07 16:12:53 +02:00
|
|
|
for (int value = min; value <= max; value += step)
|
2020-09-28 15:38:32 +02:00
|
|
|
{
|
|
|
|
validBases.append(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return validBases;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstartMeasurementDimension::IsRangeValid()
|
|
|
|
{
|
|
|
|
bool valid = m_minValue > 0 && m_maxValue > 0 && m_minValue >= RangeMin() && m_minValue <= RangeMax()
|
|
|
|
&& m_minValue <= m_maxValue;
|
|
|
|
|
|
|
|
if (not valid)
|
|
|
|
{
|
|
|
|
m_error = tr("Invalid min/max range");
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstartMeasurementDimension::IsStepValid()
|
|
|
|
{
|
|
|
|
bool valid = ValidSteps().indexOf(m_step) != -1;
|
|
|
|
if (not valid)
|
|
|
|
{
|
|
|
|
m_error = tr("Invalid step");
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VAbstartMeasurementDimension::IsBaseValid()
|
|
|
|
{
|
|
|
|
bool valid = ValidBases().indexOf(m_baseValue) != -1;
|
|
|
|
if (not valid)
|
|
|
|
{
|
|
|
|
m_error = tr("Base value invalid");
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-16 14:12:06 +02:00
|
|
|
bool VAbstartMeasurementDimension::IsUnitsValid() const
|
2020-09-28 15:38:32 +02:00
|
|
|
{
|
|
|
|
return m_units == Unit::Cm || m_units == Unit::Mm || m_units == Unit::Inch;
|
|
|
|
}
|
|
|
|
|
2020-10-06 17:00:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstartMeasurementDimension::DimensionName(MeasurementDimension type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2020-10-15 08:35:08 +02:00
|
|
|
case MeasurementDimension::X:
|
2020-10-20 15:29:11 +02:00
|
|
|
return tr("Height", "dimension");
|
2020-10-15 08:35:08 +02:00
|
|
|
case MeasurementDimension::Y:
|
2020-10-20 15:29:11 +02:00
|
|
|
return tr("Size", "dimension");
|
2020-10-15 08:35:08 +02:00
|
|
|
case MeasurementDimension::W:
|
2020-10-20 15:29:11 +02:00
|
|
|
return tr("Waist", "dimension");
|
2020-10-15 08:35:08 +02:00
|
|
|
case MeasurementDimension::Z:
|
2020-10-20 15:29:11 +02:00
|
|
|
return tr("Hip", "dimension");
|
2020-10-15 08:35:08 +02:00
|
|
|
default:
|
|
|
|
return QString();
|
2020-10-06 17:00:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstartMeasurementDimension::DimensionToolTip(MeasurementDimension type, bool circumference, bool fc)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case MeasurementDimension::X:
|
2020-10-20 15:29:11 +02:00
|
|
|
return tr("Height", "dimension");
|
2020-10-06 17:00:53 +02:00
|
|
|
case MeasurementDimension::Y:
|
|
|
|
if (circumference)
|
|
|
|
{
|
2020-10-20 15:29:11 +02:00
|
|
|
return fc ? tr("Chest full circumference", "dimension") : tr("Chest half circumference", "dimension");
|
2020-10-06 17:00:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tr("Size");
|
|
|
|
}
|
2020-10-20 15:29:11 +02:00
|
|
|
return circumference ? tr("Chest circumference", "dimension") : tr("Size", "dimension");
|
2020-10-06 17:00:53 +02:00
|
|
|
case MeasurementDimension::W:
|
2020-10-20 15:29:11 +02:00
|
|
|
return fc ? tr("Waist full circumference", "dimension") : tr("Waist half circumference", "dimension");
|
2020-10-06 17:00:53 +02:00
|
|
|
case MeasurementDimension::Z:
|
2020-10-20 15:29:11 +02:00
|
|
|
return fc ? tr("Hip full circumference", "dimension") : tr("Hip half circumference", "dimension");
|
2020-10-06 17:00:53 +02:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 15:38:32 +02:00
|
|
|
// VXMeasurementDimension
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VXMeasurementDimension::VXMeasurementDimension(Unit units)
|
|
|
|
: VAbstartMeasurementDimension(units)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VXMeasurementDimension::VXMeasurementDimension(Unit units, int min, int max, int step)
|
|
|
|
: VAbstartMeasurementDimension(units, min, max, step)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementDimension VXMeasurementDimension::Type() const
|
|
|
|
{
|
|
|
|
return MeasurementDimension::X;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VXMeasurementDimension::RangeMin() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
|
|
|
return 50;
|
|
|
|
case Unit::Mm:
|
|
|
|
return 500;
|
|
|
|
case Unit::Inch:
|
|
|
|
return 19;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VXMeasurementDimension::RangeMax() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
|
|
|
return 272;
|
|
|
|
case Unit::Mm:
|
|
|
|
return 2720;
|
|
|
|
case Unit::Inch:
|
|
|
|
return 107;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VYMeasurementDimension
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VYMeasurementDimension::VYMeasurementDimension(Unit units)
|
|
|
|
: VAbstartMeasurementDimension(units)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VYMeasurementDimension::VYMeasurementDimension(Unit units, int min, int max, int step)
|
|
|
|
: VAbstartMeasurementDimension(units, min, max, step)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementDimension VYMeasurementDimension::Type() const
|
|
|
|
{
|
|
|
|
return MeasurementDimension::Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VYMeasurementDimension::RangeMin() const
|
|
|
|
{
|
|
|
|
if (m_circumference)
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
|
|
|
return 22;
|
|
|
|
case Unit::Mm:
|
|
|
|
return 220;
|
|
|
|
case Unit::Inch:
|
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VYMeasurementDimension::RangeMax() const
|
|
|
|
{
|
|
|
|
if (m_circumference)
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
|
|
|
return 72;
|
|
|
|
case Unit::Mm:
|
|
|
|
return 720;
|
|
|
|
case Unit::Inch:
|
|
|
|
return 29;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-26 12:17:59 +01:00
|
|
|
return 60;
|
2020-09-28 15:38:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VWMeasurementDimension
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VWMeasurementDimension::VWMeasurementDimension(Unit units)
|
|
|
|
: VAbstartMeasurementDimension(units)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VWMeasurementDimension::VWMeasurementDimension(Unit units, int min, int max, int step)
|
|
|
|
: VAbstartMeasurementDimension(units, min, max, step)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementDimension VWMeasurementDimension::Type() const
|
|
|
|
{
|
|
|
|
return MeasurementDimension::W;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VWMeasurementDimension::RangeMin() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 20;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Mm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 200;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Inch:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 8;
|
2020-09-28 15:38:32 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VWMeasurementDimension::RangeMax() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 65;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Mm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 650;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Inch:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 26;
|
2020-09-28 15:38:32 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VZMeasurementDimension
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VZMeasurementDimension::VZMeasurementDimension(Unit units)
|
|
|
|
: VAbstartMeasurementDimension(units)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VZMeasurementDimension::VZMeasurementDimension(Unit units, int min, int max, int step)
|
|
|
|
: VAbstartMeasurementDimension(units, min, max, step)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementDimension VZMeasurementDimension::Type() const
|
|
|
|
{
|
|
|
|
return MeasurementDimension::Z;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VZMeasurementDimension::RangeMin() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 20;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Mm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 200;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Inch:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 8;
|
2020-09-28 15:38:32 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VZMeasurementDimension::RangeMax() const
|
|
|
|
{
|
|
|
|
switch(m_units)
|
|
|
|
{
|
|
|
|
case Unit::Cm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 75;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Mm:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 750;
|
2020-09-28 15:38:32 +02:00
|
|
|
case Unit::Inch:
|
2020-10-20 15:52:50 +02:00
|
|
|
return 30;
|
2020-09-28 15:38:32 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|