2015-07-14 19:22:31 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vmeasurements.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 7, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-07-14 19:22:31 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-07-14 19:22:31 +02:00
|
|
|
**
|
|
|
|
** 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 "vmeasurements.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <qnumeric.h>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDomNode>
|
|
|
|
#include <QDomNodeList>
|
|
|
|
#include <QDomText>
|
|
|
|
#include <QLatin1Char>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QtDebug>
|
2018-03-14 14:39:15 +01:00
|
|
|
#include <QGlobalStatic>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vvitconverter.h"
|
|
|
|
#include "../ifc/xml/vvstconverter.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2015-10-15 14:37:10 +02:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../qmuparser/qmuparsererror.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/calculator.h"
|
|
|
|
#include "../vpatterndb/variables/vmeasurement.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2017-06-01 12:04:25 +02:00
|
|
|
#include "../vpatterndb/measurements.h"
|
|
|
|
#include "../vpatterndb/pmsystems.h"
|
2017-05-29 15:33:36 +02:00
|
|
|
#include "../vmisc/projectversion.h"
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
const QString VMeasurements::TagVST = QStringLiteral("vst");
|
|
|
|
const QString VMeasurements::TagVIT = QStringLiteral("vit");
|
|
|
|
const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements");
|
|
|
|
const QString VMeasurements::TagNotes = QStringLiteral("notes");
|
|
|
|
const QString VMeasurements::TagPersonal = QStringLiteral("personal");
|
2017-09-19 15:07:48 +02:00
|
|
|
const QString VMeasurements::TagCustomer = QStringLiteral("customer");
|
2015-07-16 11:38:54 +02:00
|
|
|
const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date");
|
2015-10-13 10:13:43 +02:00
|
|
|
const QString VMeasurements::TagGender = QStringLiteral("gender");
|
2015-10-16 19:26:05 +02:00
|
|
|
const QString VMeasurements::TagPMSystem = QStringLiteral("pm_system");
|
2015-07-16 11:38:54 +02:00
|
|
|
const QString VMeasurements::TagEmail = QStringLiteral("email");
|
2015-07-18 13:08:44 +02:00
|
|
|
const QString VMeasurements::TagReadOnly = QStringLiteral("read-only");
|
2015-07-19 14:28:01 +02:00
|
|
|
const QString VMeasurements::TagMeasurement = QStringLiteral("m");
|
2020-10-01 12:32:02 +02:00
|
|
|
const QString VMeasurements::TagDimensions = QStringLiteral("dimensions");
|
|
|
|
const QString VMeasurements::TagDimension = QStringLiteral("dimension");
|
|
|
|
const QString VMeasurements::TagRestrictions = QStringLiteral("restrictions");
|
2020-10-05 14:14:38 +02:00
|
|
|
const QString VMeasurements::TagRestriction = QStringLiteral("restriction");
|
2020-10-03 17:52:31 +02:00
|
|
|
const QString VMeasurements::TagCorrections = QStringLiteral("corrections");
|
|
|
|
const QString VMeasurements::TagCorrection = QStringLiteral("correction");
|
2020-10-08 12:34:38 +02:00
|
|
|
const QString VMeasurements::TagLabels = QStringLiteral("labels");
|
|
|
|
const QString VMeasurements::TagLabel = QStringLiteral("label");
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
const QString VMeasurements::AttrBase = QStringLiteral("base");
|
|
|
|
const QString VMeasurements::AttrValue = QStringLiteral("value");
|
|
|
|
const QString VMeasurements::AttrShiftA = QStringLiteral("shiftA");
|
|
|
|
const QString VMeasurements::AttrShiftB = QStringLiteral("shiftB");
|
|
|
|
const QString VMeasurements::AttrShiftC = QStringLiteral("shiftC");
|
|
|
|
const QString VMeasurements::AttrCorrection = QStringLiteral("correction");
|
|
|
|
const QString VMeasurements::AttrCoordinates = QStringLiteral("coordinates");
|
2021-01-19 20:13:17 +01:00
|
|
|
const QString VMeasurements::AttrExclude = QStringLiteral("exclude");
|
2020-10-03 17:52:31 +02:00
|
|
|
const QString VMeasurements::AttrSpecialUnits = QStringLiteral("specialUnits");
|
|
|
|
const QString VMeasurements::AttrDescription = QStringLiteral("description");
|
|
|
|
const QString VMeasurements::AttrName = QStringLiteral("name");
|
|
|
|
const QString VMeasurements::AttrFullName = QStringLiteral("full_name");
|
|
|
|
const QString VMeasurements::AttrMin = QStringLiteral("min");
|
|
|
|
const QString VMeasurements::AttrMax = QStringLiteral("max");
|
|
|
|
const QString VMeasurements::AttrStep = QStringLiteral("step");
|
|
|
|
const QString VMeasurements::AttrCircumference = QStringLiteral("circumference");
|
2020-10-01 13:16:21 +02:00
|
|
|
const QString VMeasurements::AttrFullCircumference = QStringLiteral("fullCircumference");
|
2020-10-08 12:34:38 +02:00
|
|
|
const QString VMeasurements::AttrLabel = QStringLiteral("label");
|
2020-10-15 08:35:08 +02:00
|
|
|
const QString VMeasurements::AttrDimension = QStringLiteral("dimension");
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2015-10-13 10:13:43 +02:00
|
|
|
const QString VMeasurements::GenderMale = QStringLiteral("male");
|
|
|
|
const QString VMeasurements::GenderFemale = QStringLiteral("female");
|
|
|
|
const QString VMeasurements::GenderUnknown = QStringLiteral("unknown");
|
2015-07-14 19:22:31 +02:00
|
|
|
|
2020-10-15 08:35:08 +02:00
|
|
|
const QString VMeasurements::DimensionN = QStringLiteral("n");
|
2020-10-01 12:32:02 +02:00
|
|
|
const QString VMeasurements::DimensionX = QStringLiteral("x");
|
|
|
|
const QString VMeasurements::DimensionY = QStringLiteral("y");
|
|
|
|
const QString VMeasurements::DimensionW = QStringLiteral("w");
|
|
|
|
const QString VMeasurements::DimensionZ = QStringLiteral("z");
|
|
|
|
|
2017-05-29 15:33:36 +02:00
|
|
|
namespace
|
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, defBirthDate, (QLatin1String("1800-01-01")))
|
|
|
|
|
2017-05-29 15:33:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString FileComment()
|
|
|
|
{
|
2017-09-01 16:04:19 +02:00
|
|
|
return QString("Measurements created with Valentina v%1 (https://valentinaproject.bitbucket.io/).")
|
|
|
|
.arg(APP_VERSION_STR);
|
2017-05-29 15:33:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::VMeasurements(VContainer *data)
|
2021-05-07 10:19:06 +02:00
|
|
|
: data(data),
|
2018-09-18 15:38:16 +02:00
|
|
|
type(MeasurementsType::Unknown)
|
2015-07-15 09:16:59 +02:00
|
|
|
{
|
|
|
|
SCASSERT(data != nullptr)
|
|
|
|
}
|
2015-07-14 19:22:31 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VMeasurements::VMeasurements(Unit unit, VContainer *data)
|
2021-05-07 10:19:06 +02:00
|
|
|
: data(data),
|
2018-09-18 15:38:16 +02:00
|
|
|
type(MeasurementsType::Individual)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(data != nullptr)
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2020-10-05 10:45:16 +02:00
|
|
|
CreateEmptyIndividualFile(unit);
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-01 12:32:02 +02:00
|
|
|
VMeasurements::VMeasurements(Unit unit, const QVector<MeasurementDimension_p > &dimensions,
|
|
|
|
VContainer *data)
|
2021-05-07 10:19:06 +02:00
|
|
|
: data(data),
|
|
|
|
type(MeasurementsType::Multisize)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(data != nullptr)
|
2015-07-16 11:38:54 +02:00
|
|
|
|
2020-10-01 12:32:02 +02:00
|
|
|
CreateEmptyMultisizeFile(unit, dimensions);
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::setXMLContent(const QString &fileName)
|
|
|
|
{
|
|
|
|
VDomDocument::setXMLContent(fileName);
|
|
|
|
type = ReadType();
|
2021-05-07 10:19:06 +02:00
|
|
|
m_units = ReadUnits();
|
|
|
|
m_dimensions = ReadDimensions();
|
2015-07-25 14:59:40 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 15:33:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurements::SaveDocument(const QString &fileName, QString &error)
|
|
|
|
{
|
|
|
|
// Update comment with Valentina version
|
|
|
|
QDomNode commentNode = documentElement().firstChild();
|
|
|
|
if (commentNode.isComment())
|
|
|
|
{
|
|
|
|
QDomComment comment = commentNode.toComment();
|
|
|
|
comment.setData(FileComment());
|
|
|
|
}
|
|
|
|
|
|
|
|
return VDomDocument::SaveDocument(fileName, error);
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
void VMeasurements::AddEmpty(const QString &name, const QString &formula)
|
2015-07-19 14:28:01 +02:00
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
const QDomElement element = MakeEmpty(name, formula);
|
2015-07-19 14:28:01 +02:00
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).appendChild(element);
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
void VMeasurements::AddEmptyAfter(const QString &after, const QString &name, const QString &formula)
|
2015-07-21 19:26:33 +02:00
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
const QDomElement element = MakeEmpty(name, formula);
|
2015-07-21 19:26:33 +02:00
|
|
|
const QDomElement sibling = FindM(after);
|
|
|
|
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
|
|
|
|
if (sibling.isNull())
|
2015-07-19 14:28:01 +02:00
|
|
|
{
|
2015-07-21 19:26:33 +02:00
|
|
|
list.at(0).appendChild(element);
|
2015-07-19 14:28:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-21 19:26:33 +02:00
|
|
|
list.at(0).insertAfter(element, sibling);
|
2015-07-19 14:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::Remove(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).removeChild(FindM(name));
|
|
|
|
}
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveTop(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList mList = elementsByTagName(TagMeasurement);
|
|
|
|
if (mList.size() >= 2)
|
|
|
|
{
|
|
|
|
const QDomNode top = mList.at(0);
|
|
|
|
if (not top.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertBefore(node, top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:01:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveUp(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomElement prSibling = node.previousSiblingElement(TagMeasurement);
|
|
|
|
if (not prSibling.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertBefore(node, prSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveDown(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomElement nextSibling = node.nextSiblingElement(TagMeasurement);
|
|
|
|
if (not nextSibling.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertAfter(node, nextSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::MoveBottom(const QString &name)
|
|
|
|
{
|
|
|
|
const QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList mList = elementsByTagName(TagMeasurement);
|
|
|
|
if (mList.size() >= 2)
|
|
|
|
{
|
|
|
|
const QDomNode bottom = mList.at(mList.size()-1);
|
|
|
|
if (not bottom.isNull())
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagBodyMeasurements);
|
|
|
|
list.at(0).insertAfter(node, bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VMeasurements::Units() const -> Unit
|
|
|
|
{
|
|
|
|
return m_units;
|
|
|
|
}
|
|
|
|
|
2020-01-09 14:14:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::StoreNames(bool store)
|
|
|
|
{
|
|
|
|
m_keepNames = store;
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
void VMeasurements::ReadMeasurements(qreal baseA, qreal baseB, qreal baseC) const
|
2015-07-24 12:06:39 +02:00
|
|
|
{
|
2015-08-17 14:36:55 +02:00
|
|
|
// For conversion values we must first calculate all data in measurement file's unit.
|
|
|
|
// That's why we need two containers: one for converted values, second for real data.
|
|
|
|
|
|
|
|
// Container for values in measurement file's unit
|
2020-10-03 17:52:31 +02:00
|
|
|
QSharedPointer<VContainer> tempData;
|
|
|
|
|
|
|
|
if (type == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
tempData = QSharedPointer<VContainer>::create(data->GetTrVars(), data->GetPatternUnit(),
|
|
|
|
VContainer::UniqueNamespace());
|
|
|
|
}
|
2015-08-17 14:36:55 +02:00
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
|
2019-04-20 19:19:30 +02:00
|
|
|
const QString name = GetParametrString(dom, AttrName).simplified();
|
2018-01-20 11:31:12 +01:00
|
|
|
const QString description = GetParametrEmptyString(dom, AttrDescription);
|
|
|
|
const QString fullName = GetParametrEmptyString(dom, AttrFullName);
|
2020-10-03 17:52:31 +02:00
|
|
|
const bool specialUnits = GetParametrBool(dom, AttrSpecialUnits, falseStr);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
2017-04-14 10:30:00 +02:00
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
QSharedPointer<VMeasurement> tempMeash;
|
2017-07-12 20:21:48 +02:00
|
|
|
if (type == MeasurementsType::Multisize)
|
2015-07-24 12:06:39 +02:00
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
qreal base = GetParametrDouble(dom, AttrBase, QChar('0'));
|
2020-10-03 17:52:31 +02:00
|
|
|
qreal shiftA = GetParametrDouble(dom, AttrShiftA, QChar('0'));
|
|
|
|
qreal shiftB = GetParametrDouble(dom, AttrShiftB, QChar('0'));
|
|
|
|
qreal shiftC = GetParametrDouble(dom, AttrShiftC, QChar('0'));
|
|
|
|
QMap<QString, qreal> corrections = ReadCorrections(dom);
|
|
|
|
|
|
|
|
qreal convertedBaseA = DimensionABase();
|
|
|
|
qreal convertedBaseB = DimensionBBase();
|
|
|
|
qreal convertedBaseC = DimensionCBase();
|
|
|
|
qreal convertedStepA = DimensionAStep();
|
|
|
|
qreal convertedStepB = DimensionBStep();
|
|
|
|
qreal convertedStepC = DimensionCStep();
|
|
|
|
|
|
|
|
if (not specialUnits)
|
|
|
|
{
|
2021-05-07 10:19:06 +02:00
|
|
|
base = UnitConvertor(base, Units(), *data->GetPatternUnit());
|
|
|
|
shiftA = UnitConvertor(shiftA, Units(), *data->GetPatternUnit());
|
|
|
|
shiftB = UnitConvertor(shiftB, Units(), *data->GetPatternUnit());
|
|
|
|
shiftC = UnitConvertor(shiftC, Units(), *data->GetPatternUnit());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
QMutableMapIterator<QString, qreal> iterator(corrections);
|
|
|
|
while (iterator.hasNext())
|
|
|
|
{
|
|
|
|
iterator.next();
|
2021-05-07 10:19:06 +02:00
|
|
|
iterator.setValue(UnitConvertor(iterator.value(), Units(), *data->GetPatternUnit()));
|
2020-10-03 17:52:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
convertedBaseA = UnitConvertor(convertedBaseA, Units(), *data->GetPatternUnit());
|
|
|
|
convertedBaseB = UnitConvertor(convertedBaseB, Units(), *data->GetPatternUnit());
|
|
|
|
convertedBaseC = UnitConvertor(convertedBaseC, Units(), *data->GetPatternUnit());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
convertedStepA = UnitConvertor(convertedStepA, Units(), *data->GetPatternUnit());
|
|
|
|
convertedStepB = UnitConvertor(convertedStepB, Units(), *data->GetPatternUnit());
|
|
|
|
convertedStepC = UnitConvertor(convertedStepC, Units(), *data->GetPatternUnit());
|
2020-10-03 17:52:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
meash = QSharedPointer<VMeasurement>::create(static_cast<quint32>(i), name,
|
|
|
|
convertedBaseA, convertedBaseB, convertedBaseC, base);
|
|
|
|
meash->SetBaseA(baseA);
|
|
|
|
meash->SetBaseB(baseB);
|
|
|
|
meash->SetBaseC(baseC);
|
|
|
|
|
|
|
|
meash->SetShiftA(shiftA);
|
|
|
|
meash->SetShiftB(shiftB);
|
|
|
|
meash->SetShiftC(shiftC);
|
|
|
|
|
|
|
|
meash->SetStepA(convertedStepA);
|
|
|
|
meash->SetStepB(convertedStepB);
|
|
|
|
meash->SetStepC(convertedStepC);
|
|
|
|
|
|
|
|
meash->SetSpecialUnits(specialUnits);
|
|
|
|
meash->SetCorrections(corrections);
|
|
|
|
meash->SetGuiText(fullName);
|
|
|
|
meash->SetDescription(description);
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-15 08:35:08 +02:00
|
|
|
const IMD dimension =
|
|
|
|
VMeasurements::StrToIMD(GetParametrString(dom, AttrDimension, VMeasurements::IMDToStr(IMD::N)));
|
2018-04-12 12:13:19 +02:00
|
|
|
const QString formula = GetParametrString(dom, AttrValue, QChar('0'));
|
2015-07-24 12:06:39 +02:00
|
|
|
bool ok = false;
|
2017-04-14 10:30:00 +02:00
|
|
|
qreal value = EvalFormula(tempData.data(), formula, &ok);
|
2015-08-17 14:36:55 +02:00
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
tempMeash = QSharedPointer<VMeasurement>::create(tempData.data(), static_cast<quint32>(i), name, value,
|
|
|
|
formula, ok);
|
2015-08-17 14:36:55 +02:00
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
if (not specialUnits)
|
|
|
|
{
|
2021-05-07 10:19:06 +02:00
|
|
|
value = UnitConvertor(value, Units(), *data->GetPatternUnit());
|
2020-10-03 17:52:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
meash = QSharedPointer<VMeasurement>::create(data, static_cast<quint32>(i), name, value, formula, ok);
|
|
|
|
meash->SetGuiText(fullName);
|
|
|
|
meash->SetDescription(description);
|
|
|
|
meash->SetSpecialUnits(specialUnits);
|
2020-10-15 08:35:08 +02:00
|
|
|
meash->SetDimension(dimension);
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
2020-10-03 17:52:31 +02:00
|
|
|
|
2020-01-09 14:14:05 +01:00
|
|
|
if (m_keepNames)
|
|
|
|
{
|
2020-10-03 17:52:31 +02:00
|
|
|
if (not tempData.isNull())
|
|
|
|
{
|
|
|
|
tempData->AddUniqueVariable(tempMeash);
|
|
|
|
}
|
2020-01-09 14:14:05 +01:00
|
|
|
data->AddUniqueVariable(meash);
|
|
|
|
}
|
2020-01-10 07:57:19 +01:00
|
|
|
else
|
|
|
|
{
|
2020-10-03 17:52:31 +02:00
|
|
|
if (not tempData.isNull())
|
|
|
|
{
|
|
|
|
tempData->AddVariable(tempMeash);
|
|
|
|
}
|
2020-01-10 07:57:19 +01:00
|
|
|
data->AddVariable(meash);
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::ClearForExport()
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (qmu::QmuTokenParser::IsSingle(domElement.attribute(AttrValue)))
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
SetAttribute(domElement, AttrValue, QChar('0'));
|
2015-10-15 14:37:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
MeasurementsType VMeasurements::Type() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionABase() const
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
if (type == MeasurementsType::Multisize)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2020-10-01 12:32:02 +02:00
|
|
|
const auto dimensions = Dimensions();
|
|
|
|
if (not dimensions.isEmpty())
|
|
|
|
{
|
|
|
|
return dimensions.first()->BaseValue();
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
2020-10-01 12:32:02 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionBBase() const
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
if (type == MeasurementsType::Multisize)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2020-10-01 12:32:02 +02:00
|
|
|
const auto dimensions = Dimensions();
|
|
|
|
if (not dimensions.isEmpty() && dimensions.size() >= 2)
|
|
|
|
{
|
|
|
|
return dimensions.values().at(1)->BaseValue();
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
2020-10-01 12:32:02 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionCBase() const
|
2020-10-01 12:32:02 +02:00
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Multisize)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2020-10-01 12:32:02 +02:00
|
|
|
const auto dimensions = Dimensions();
|
2020-10-03 17:52:31 +02:00
|
|
|
if (not dimensions.isEmpty() && dimensions.size() == 3)
|
2020-10-01 12:32:02 +02:00
|
|
|
{
|
|
|
|
return dimensions.last()->BaseValue();
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
2020-10-01 12:32:02 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionAStep() const
|
2020-10-03 17:52:31 +02:00
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Multisize)
|
|
|
|
{
|
|
|
|
const auto dimensions = Dimensions();
|
|
|
|
if (not dimensions.isEmpty())
|
|
|
|
{
|
|
|
|
return dimensions.first()->Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionBStep() const
|
2020-10-03 17:52:31 +02:00
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Multisize)
|
|
|
|
{
|
|
|
|
const auto dimensions = Dimensions();
|
|
|
|
if (not dimensions.isEmpty() && dimensions.size() >= 2)
|
|
|
|
{
|
|
|
|
return dimensions.values().at(1)->Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
qreal VMeasurements::DimensionCStep() const
|
2020-10-03 17:52:31 +02:00
|
|
|
{
|
|
|
|
if (type == MeasurementsType::Multisize)
|
|
|
|
{
|
|
|
|
const auto dimensions = Dimensions();
|
|
|
|
if (not dimensions.isEmpty() && dimensions.size() == 3)
|
|
|
|
{
|
|
|
|
return dimensions.last()->Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::Notes() const
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
return UniqueTagText(TagNotes, QString());
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetNotes(const QString &text)
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-07-18 15:25:56 +02:00
|
|
|
{
|
|
|
|
setTagText(TagNotes, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-19 15:07:48 +02:00
|
|
|
QString VMeasurements::Customer() const
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
return UniqueTagText(TagCustomer, QString());
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-19 15:07:48 +02:00
|
|
|
void VMeasurements::SetCustomer(const QString &text)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-07-18 15:25:56 +02:00
|
|
|
{
|
2017-09-19 15:07:48 +02:00
|
|
|
setTagText(TagCustomer, text);
|
2015-07-18 15:25:56 +02:00
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDate VMeasurements::BirthDate() const
|
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
return QDate::fromString(UniqueTagText(TagBirthDate, *defBirthDate), "yyyy-MM-dd");
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetBirthDate(const QDate &date)
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-07-18 15:25:56 +02:00
|
|
|
{
|
|
|
|
setTagText(TagBirthDate, date.toString("yyyy-MM-dd"));
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
GenderType VMeasurements::Gender() const
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
return StrToGender(UniqueTagText(TagGender, GenderUnknown));
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
void VMeasurements::SetGender(const GenderType &gender)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-07-18 15:25:56 +02:00
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
setTagText(TagGender, GenderToStr(gender));
|
2015-07-18 15:25:56 +02:00
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::PMSystem() const
|
|
|
|
{
|
|
|
|
return UniqueTagText(TagPMSystem, ClearPMCode(p998_S));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetPMSystem(const QString &system)
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-10-16 19:26:05 +02:00
|
|
|
{
|
|
|
|
setTagText(TagPMSystem, ClearPMCode(system));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::Email() const
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
return UniqueTagText(TagEmail, QString());
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetEmail(const QString &text)
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
if (not IsReadOnly())
|
2015-07-18 15:25:56 +02:00
|
|
|
{
|
|
|
|
setTagText(TagEmail, text);
|
|
|
|
}
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-04 12:28:47 +01:00
|
|
|
bool VMeasurements::IsReadOnly() const
|
2015-07-18 13:08:44 +02:00
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
return UniqueTagText(TagReadOnly, falseStr) == trueStr;
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetReadOnly(bool ro)
|
|
|
|
{
|
2019-02-11 13:16:49 +01:00
|
|
|
setTagText(TagReadOnly, ro ? trueStr : falseStr);
|
2015-07-18 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 13:16:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurements::IsFullCircumference() const
|
|
|
|
{
|
2020-10-01 18:03:28 +02:00
|
|
|
QDomElement dimenstionsTag = documentElement().firstChildElement(TagDimensions);
|
2020-10-01 13:16:21 +02:00
|
|
|
if (not dimenstionsTag.isNull())
|
|
|
|
{
|
|
|
|
return GetParametrBool(dimenstionsTag, AttrFullCircumference, falseStr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug()<<"Can't read full circumference "<<Q_FUNC_INFO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetFullCircumference(bool fc)
|
|
|
|
{
|
2020-10-01 18:03:28 +02:00
|
|
|
QDomElement dimenstionsTag = documentElement().firstChildElement(TagDimensions);
|
2020-10-01 13:16:21 +02:00
|
|
|
if (not dimenstionsTag.isNull())
|
|
|
|
{
|
|
|
|
SetAttributeOrRemoveIf(dimenstionsTag, AttrFullCircumference, fc, not fc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug()<<"Can't save full circumference "<<Q_FUNC_INFO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMName(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrName, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMValue(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrValue, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
void VMeasurements::SetMBaseValue(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
2015-07-25 07:41:04 +02:00
|
|
|
SetAttribute(node, AttrBase, value);
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
void VMeasurements::SetMShiftA(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
2020-10-03 17:52:31 +02:00
|
|
|
SetAttribute(node, AttrShiftA, value);
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
void VMeasurements::SetMShiftB(const QString &name, double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
2020-10-03 17:52:31 +02:00
|
|
|
SetAttribute(node, AttrShiftB, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMShiftC(const QString &name, double value)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrShiftC, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMSpecialUnits(const QString &name, bool special)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttributeOrRemoveIf(node, AttrSpecialUnits, special, not special);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMCorrectionValue(const QString &name, qreal baseA, qreal baseB, qreal baseC, double value)
|
|
|
|
{
|
|
|
|
QDomElement mElement = FindM(name);
|
|
|
|
if (not mElement.isNull())
|
|
|
|
{
|
|
|
|
QMap<QString, qreal> corrections = ReadCorrections(mElement);
|
|
|
|
const QString hash = VMeasurement::CorrectionHash(baseA, baseB, baseC);
|
|
|
|
|
|
|
|
if (not qFuzzyIsNull(value))
|
|
|
|
{
|
|
|
|
corrections.insert(hash, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (corrections.contains(hash))
|
|
|
|
{
|
|
|
|
corrections.remove(hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteCorrections(mElement, corrections);
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMDescription(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrDescription, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
}
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMFullName(const QString &name, const QString &text)
|
|
|
|
{
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttribute(node, AttrFullName, text);
|
|
|
|
}
|
2015-09-29 16:04:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
}
|
|
|
|
|
2020-10-15 08:35:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetMDimension(const QString &name, IMD type)
|
|
|
|
{
|
|
|
|
ClearDimension(type);
|
|
|
|
QDomElement node = FindM(name);
|
|
|
|
if (not node.isNull())
|
|
|
|
{
|
|
|
|
SetAttributeOrRemoveIf(node, AttrDimension, VMeasurements::IMDToStr(type), type == IMD::N);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("Can't find measurement '%1'").arg(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::MeasurementForDimension(IMD type) const
|
|
|
|
{
|
|
|
|
const QString d = VMeasurements::IMDToStr(type);
|
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domElement.attribute(AttrDimension) == d)
|
|
|
|
{
|
|
|
|
return domElement.attribute(AttrName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-10-01 12:32:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-07 10:19:06 +02:00
|
|
|
auto VMeasurements::Dimensions() const -> VDimensions
|
2020-10-01 12:32:02 +02:00
|
|
|
{
|
2021-05-07 10:19:06 +02:00
|
|
|
return m_dimensions;
|
2020-10-01 12:32:02 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-19 20:13:17 +01:00
|
|
|
auto VMeasurements::GetRestrictions() const -> QMap<QString, VDimensionRestriction >
|
2020-10-03 06:34:25 +02:00
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
QMap<QString, VDimensionRestriction > restrictions;
|
2020-10-05 14:14:38 +02:00
|
|
|
|
|
|
|
const QDomNodeList list = elementsByTagName(TagRestriction);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement res = list.at(i).toElement();
|
|
|
|
|
|
|
|
QString coordinates = GetParametrString(res, AttrCoordinates);
|
2021-01-18 19:43:53 +01:00
|
|
|
const qreal min = GetParametrDouble(res, AttrMin, QChar('0'));
|
|
|
|
const qreal max = GetParametrDouble(res, AttrMax, QChar('0'));
|
2021-01-19 20:13:17 +01:00
|
|
|
const QString exclude = GetParametrEmptyString(res, AttrExclude);
|
2020-10-05 14:14:38 +02:00
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
restrictions.insert(coordinates, VDimensionRestriction(min, max, exclude));
|
2020-10-05 14:14:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return restrictions;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-19 20:13:17 +01:00
|
|
|
void VMeasurements::SetRestrictions(const QMap<QString, VDimensionRestriction> &restrictions)
|
2020-10-05 14:14:38 +02:00
|
|
|
{
|
|
|
|
QDomElement root = documentElement();
|
|
|
|
QDomElement restrictionsTag = root.firstChildElement(TagRestrictions);
|
|
|
|
|
|
|
|
if (restrictionsTag.isNull())
|
|
|
|
{
|
|
|
|
qDebug() << "Can't find restrictions tag";
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveAllChildren(restrictionsTag);
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
auto i = restrictions.constBegin();
|
2020-10-05 14:14:38 +02:00
|
|
|
while (i != restrictions.constEnd())
|
|
|
|
{
|
|
|
|
QDomElement restrictionTag = createElement(TagRestriction);
|
|
|
|
|
|
|
|
SetAttribute(restrictionTag, AttrCoordinates, i.key());
|
2021-01-19 20:13:17 +01:00
|
|
|
SetAttributeOrRemoveIf(restrictionTag, AttrMin, i.value().GetMin(), qFuzzyIsNull(i.value().GetMin()));
|
|
|
|
SetAttributeOrRemoveIf(restrictionTag, AttrMax, i.value().GetMax(), qFuzzyIsNull(i.value().GetMax()));
|
|
|
|
SetAttributeOrRemoveIf(restrictionTag, AttrExclude, i.value().GetExcludeString(),
|
|
|
|
i.value().GetExcludeString().isEmpty());
|
2020-10-05 14:14:38 +02:00
|
|
|
|
|
|
|
restrictionsTag.appendChild(restrictionTag);
|
|
|
|
++i;
|
|
|
|
}
|
2020-10-03 06:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-19 20:13:17 +01:00
|
|
|
auto VMeasurements::Restriction(qreal base, qreal base2) const -> VDimensionRestriction
|
2020-10-03 06:34:25 +02:00
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
const QMap<QString, VDimensionRestriction > restrictions = GetRestrictions();
|
2020-10-05 14:14:38 +02:00
|
|
|
const QString hash = VMeasurement::CorrectionHash(base, base2, 0);
|
2021-01-19 20:13:17 +01:00
|
|
|
return restrictions.value(hash);
|
2020-10-03 06:34:25 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 12:34:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SetDimensionLabels(const QMap<MeasurementDimension, DimesionLabels> &labels)
|
|
|
|
{
|
|
|
|
const QDomNodeList list = elementsByTagName(TagDimension);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement dom = list.at(i).toElement();
|
|
|
|
const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType));
|
|
|
|
|
|
|
|
if (labels.contains(type))
|
|
|
|
{
|
|
|
|
SaveDimesionLabels(dom, labels.value(type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
m_dimensions = ReadDimensions(); // Refresh cache
|
2020-10-08 12:34:38 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
QString VMeasurements::GenderToStr(const GenderType &sex)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
|
|
|
switch (sex)
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
case GenderType::Male:
|
|
|
|
return GenderMale;
|
|
|
|
case GenderType::Female:
|
|
|
|
return GenderFemale;
|
|
|
|
case GenderType::Unknown:
|
2015-07-16 11:38:54 +02:00
|
|
|
default:
|
2015-10-13 10:13:43 +02:00
|
|
|
return GenderUnknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
GenderType VMeasurements::StrToGender(const QString &sex)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
const QStringList genders = QStringList() << GenderMale << GenderFemale << GenderUnknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
switch (genders.indexOf(sex))
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
case 0: // GenderMale
|
|
|
|
return GenderType::Male;
|
|
|
|
case 1: // GenderFemale
|
|
|
|
return GenderType::Female;
|
|
|
|
case 2: // GenderUnknown
|
2015-07-16 11:38:54 +02:00
|
|
|
default:
|
2015-10-13 10:13:43 +02:00
|
|
|
return GenderType::Unknown;
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 12:32:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::DimensionTypeToStr(const MeasurementDimension &type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MeasurementDimension::Y:
|
|
|
|
return DimensionY;
|
|
|
|
case MeasurementDimension::W:
|
|
|
|
return DimensionW;
|
|
|
|
case MeasurementDimension::Z:
|
|
|
|
return DimensionZ;
|
|
|
|
case MeasurementDimension::X:
|
|
|
|
default:
|
|
|
|
return DimensionX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementDimension VMeasurements::StrToDimensionType(const QString &type)
|
|
|
|
{
|
|
|
|
const QStringList dimensions = QStringList{DimensionX, DimensionY, DimensionW, DimensionZ};
|
|
|
|
switch (dimensions.indexOf(type))
|
|
|
|
{
|
|
|
|
case 1: // DimensionY
|
|
|
|
return MeasurementDimension::Y;
|
|
|
|
case 2: // DimensionW
|
|
|
|
return MeasurementDimension::W;
|
|
|
|
case 3: // DimensionZ
|
|
|
|
return MeasurementDimension::Z;
|
|
|
|
case 0: // DimensionX
|
|
|
|
default:
|
|
|
|
return MeasurementDimension::X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-15 08:35:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::IMDToStr(const IMD &type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case IMD::X:
|
|
|
|
return DimensionX;
|
|
|
|
case IMD::Y:
|
|
|
|
return DimensionY;
|
|
|
|
case IMD::W:
|
|
|
|
return DimensionW;
|
|
|
|
case IMD::Z:
|
|
|
|
return DimensionZ;
|
|
|
|
case IMD::N:
|
|
|
|
default:
|
|
|
|
return DimensionN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
IMD VMeasurements::StrToIMD(const QString &type)
|
|
|
|
{
|
|
|
|
const QStringList dimensions = QStringList{DimensionN, DimensionX, DimensionY, DimensionW, DimensionZ};
|
|
|
|
switch (dimensions.indexOf(type))
|
|
|
|
{
|
|
|
|
case 1: // DimensionX
|
|
|
|
return IMD::X;
|
|
|
|
case 2: // DimensionY
|
|
|
|
return IMD::Y;
|
|
|
|
case 3: // DimensionW
|
|
|
|
return IMD::W;
|
|
|
|
case 4: // DimensionZ
|
|
|
|
return IMD::Z;
|
|
|
|
case 0: // DimensionN
|
|
|
|
default:
|
|
|
|
return IMD::N;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::IMDName(IMD type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case IMD::N:
|
|
|
|
return tr("None");
|
|
|
|
case IMD::X:
|
|
|
|
return tr("Height");
|
|
|
|
case IMD::Y:
|
|
|
|
return tr("Size");
|
|
|
|
case IMD::W:
|
|
|
|
return tr("Waist");
|
2021-02-03 16:17:43 +01:00
|
|
|
case IMD::Z:
|
|
|
|
return tr("Hip");
|
2020-10-15 08:35:08 +02:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:01:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurements::ListAll() const
|
|
|
|
{
|
|
|
|
QStringList listNames;
|
|
|
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
listNames.append(domElement.attribute(AttrName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return listNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VMeasurements::ListKnown() const
|
|
|
|
{
|
|
|
|
QStringList listNames;
|
|
|
|
const QStringList list = ListAll();
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
if (list.at(i).indexOf(CustomMSign) != 0)
|
2015-07-26 09:01:26 +02:00
|
|
|
{
|
|
|
|
listNames.append(list.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return listNames;
|
|
|
|
}
|
|
|
|
|
2015-09-22 16:41:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VMeasurements::IsDefinedKnownNamesValid() const
|
|
|
|
{
|
|
|
|
QStringList names = AllGroupNames();
|
2015-10-27 07:11:41 +01:00
|
|
|
|
2015-09-22 16:41:05 +02:00
|
|
|
QSet<QString> set;
|
2018-04-03 10:15:58 +02:00
|
|
|
for (const auto &var : names)
|
2015-09-22 16:41:05 +02:00
|
|
|
{
|
|
|
|
set.insert(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
names = ListKnown();
|
2018-04-03 10:15:58 +02:00
|
|
|
for (const auto &var : qAsConst(names))
|
2015-09-22 16:41:05 +02:00
|
|
|
{
|
|
|
|
if (not set.contains(var))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-18 09:24:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-04 19:29:43 +02:00
|
|
|
VContainer *VMeasurements::GetData() const
|
2015-08-18 09:24:51 +02:00
|
|
|
{
|
2017-08-04 19:29:43 +02:00
|
|
|
return data;
|
2015-08-18 09:24:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-01 12:32:02 +02:00
|
|
|
void VMeasurements::CreateEmptyMultisizeFile(Unit unit,
|
|
|
|
const QVector<MeasurementDimension_p > &dimensions)
|
2015-07-16 11:38:54 +02:00
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
QDomElement mElement = this->createElement(TagVST);
|
|
|
|
|
2017-05-29 15:33:36 +02:00
|
|
|
mElement.appendChild(createComment(FileComment()));
|
2019-07-10 12:07:29 +02:00
|
|
|
mElement.appendChild(CreateElementWithText(TagVersion, VVSTConverter::MeasurementMaxVerStr));
|
|
|
|
mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
|
2015-07-16 11:38:54 +02:00
|
|
|
mElement.appendChild(createElement(TagNotes));
|
2019-07-10 12:07:29 +02:00
|
|
|
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
|
|
|
|
mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
|
2020-10-01 12:32:02 +02:00
|
|
|
mElement.appendChild(CreateDimensions(dimensions));
|
|
|
|
mElement.appendChild(createElement(TagRestrictions));
|
2015-07-16 11:38:54 +02:00
|
|
|
mElement.appendChild(createElement(TagBodyMeasurements));
|
|
|
|
|
|
|
|
this->appendChild(mElement);
|
2019-07-10 12:07:29 +02:00
|
|
|
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
|
|
|
|
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
|
2021-05-07 10:19:06 +02:00
|
|
|
|
|
|
|
// Cache data
|
|
|
|
m_units = unit;
|
|
|
|
m_dimensions = ReadDimensions();
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::CreateEmptyIndividualFile(Unit unit)
|
|
|
|
{
|
|
|
|
this->clear();
|
|
|
|
QDomElement mElement = this->createElement(TagVIT);
|
|
|
|
|
2017-05-29 15:33:36 +02:00
|
|
|
mElement.appendChild(createComment(FileComment()));
|
2019-07-10 12:07:29 +02:00
|
|
|
mElement.appendChild(CreateElementWithText(TagVersion, VVITConverter::MeasurementMaxVerStr));
|
|
|
|
mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
|
2015-07-16 11:38:54 +02:00
|
|
|
mElement.appendChild(createElement(TagNotes));
|
2019-07-10 12:07:29 +02:00
|
|
|
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
|
|
|
|
mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
|
2015-10-16 19:26:05 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
QDomElement personal = createElement(TagPersonal);
|
2017-09-19 15:07:48 +02:00
|
|
|
personal.appendChild(createElement(TagCustomer));
|
2019-07-10 12:07:29 +02:00
|
|
|
personal.appendChild(CreateElementWithText(TagBirthDate, *defBirthDate));
|
|
|
|
personal.appendChild(CreateElementWithText(TagGender, GenderToStr(GenderType::Unknown)));
|
2015-07-25 17:18:01 +02:00
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
personal.appendChild(createElement(TagEmail));
|
|
|
|
mElement.appendChild(personal);
|
|
|
|
|
|
|
|
mElement.appendChild(createElement(TagBodyMeasurements));
|
|
|
|
|
|
|
|
this->appendChild(mElement);
|
2019-07-10 12:07:29 +02:00
|
|
|
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
|
|
|
|
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
|
2021-05-07 10:19:06 +02:00
|
|
|
|
|
|
|
// Cache data
|
|
|
|
m_units = unit;
|
|
|
|
m_dimensions = ReadDimensions();
|
2015-07-16 11:38:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 12:32:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VMeasurements::CreateDimensions(const QVector<MeasurementDimension_p > &dimensions)
|
|
|
|
{
|
|
|
|
QDomElement dimensionsTag = createElement(TagDimensions);
|
|
|
|
|
|
|
|
for(auto &dimension : dimensions)
|
|
|
|
{
|
|
|
|
QDomElement dimensionTag = createElement(TagDimension);
|
|
|
|
|
|
|
|
SetAttribute(dimensionTag, AttrType, DimensionTypeToStr(dimension->Type()));
|
|
|
|
SetAttribute(dimensionTag, AttrBase, dimension->BaseValue());
|
|
|
|
SetAttribute(dimensionTag, AttrMin, dimension->MinValue());
|
|
|
|
SetAttribute(dimensionTag, AttrMax, dimension->MaxValue());
|
|
|
|
SetAttribute(dimensionTag, AttrStep, dimension->Step());
|
|
|
|
|
|
|
|
if (dimension->Type() == MeasurementDimension::Y)
|
|
|
|
{
|
|
|
|
SetAttribute(dimensionTag, AttrCircumference, dimension->IsCircumference());
|
|
|
|
}
|
|
|
|
|
|
|
|
dimensionsTag.appendChild(dimensionTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dimensionsTag;
|
|
|
|
}
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const
|
|
|
|
{
|
2021-05-07 10:19:06 +02:00
|
|
|
const qreal defVal = UnitConvertor(defValue, Unit::Cm, Units());
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
const QDomNodeList nodeList = this->elementsByTagName(tag);
|
|
|
|
if (nodeList.isEmpty())
|
|
|
|
{
|
|
|
|
return defVal;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QDomNode domNode = nodeList.at(0);
|
|
|
|
if (domNode.isNull() == false && domNode.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement domElement = domNode.toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
return GetParametrDouble(domElement, attr, QString("%1").arg(defVal));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defVal;
|
|
|
|
}
|
2015-07-21 19:26:33 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-01 13:25:05 +02:00
|
|
|
QDomElement VMeasurements::MakeEmpty(const QString &name, const QString &formula)
|
2015-07-21 19:26:33 +02:00
|
|
|
{
|
|
|
|
QDomElement element = createElement(TagMeasurement);
|
|
|
|
|
|
|
|
SetAttribute(element, AttrName, name);
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
if (type == MeasurementsType::Multisize)
|
2015-07-21 19:26:33 +02:00
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
SetAttribute(element, AttrBase, QChar('0'));
|
2015-07-21 19:26:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-12 12:13:19 +02:00
|
|
|
SetAttribute(element, AttrValue, formula.isEmpty() ? QChar('0') : formula);
|
2015-07-21 19:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDomElement VMeasurements::FindM(const QString &name) const
|
|
|
|
{
|
2015-10-03 00:49:15 +02:00
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
qWarning() << tr("The measurement name is empty!");
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
const QString parameter = domElement.attribute(AttrName);
|
|
|
|
if (parameter == name)
|
|
|
|
{
|
|
|
|
return domElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDomElement();
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MeasurementsType VMeasurements::ReadType() const
|
|
|
|
{
|
|
|
|
QDomElement root = documentElement();
|
|
|
|
if (root.tagName() == TagVST)
|
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
return MeasurementsType::Multisize;
|
2015-07-25 14:59:40 +02:00
|
|
|
}
|
|
|
|
else if (root.tagName() == TagVIT)
|
|
|
|
{
|
|
|
|
return MeasurementsType::Individual;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return MeasurementsType::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VMeasurements::ReadUnits() const -> Unit
|
|
|
|
{
|
|
|
|
Unit units = StrToUnits(UniqueTagText(TagUnit, unitCM));
|
|
|
|
|
|
|
|
if (units == Unit::Px)
|
|
|
|
{
|
|
|
|
units = Unit::Cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return units;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VMeasurements::ReadDimensions() const -> VDimensions
|
|
|
|
{
|
|
|
|
if (type != MeasurementsType::Multisize)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
VDimensions dimensions;
|
|
|
|
|
|
|
|
const Unit units = Units();
|
|
|
|
const QDomNodeList list = elementsByTagName(TagDimension);
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const QDomElement dom = list.at(i).toElement();
|
|
|
|
const MeasurementDimension type = StrToDimensionType(GetParametrString(dom, AttrType));
|
|
|
|
const qreal min = GetParametrDouble(dom, AttrMin, QChar('0'));
|
|
|
|
const qreal max = GetParametrDouble(dom, AttrMax, QChar('0'));
|
|
|
|
const qreal step = GetParametrDouble(dom, AttrStep, QStringLiteral("-1"));
|
|
|
|
const qreal base = GetParametrDouble(dom, AttrBase, QChar('0'));
|
|
|
|
|
|
|
|
const DimesionLabels labels = ReadDimensionLabels(dom);
|
|
|
|
|
|
|
|
if (type == MeasurementDimension::X)
|
|
|
|
{
|
|
|
|
auto dimension = QSharedPointer<VXMeasurementDimension>::create(units, min, max, step);
|
|
|
|
dimension->SetBaseValue(base);
|
|
|
|
dimension->SetLabels(labels);
|
|
|
|
dimensions.insert(type, dimension);
|
|
|
|
}
|
|
|
|
else if (type == MeasurementDimension::Y)
|
|
|
|
{
|
|
|
|
auto dimension = QSharedPointer<VYMeasurementDimension>::create(units, min, max, step);
|
|
|
|
dimension->SetBaseValue(base);
|
|
|
|
dimension->SetCircumference(GetParametrBool(dom, AttrCircumference, trueStr));
|
|
|
|
dimension->SetLabels(labels);
|
|
|
|
dimensions.insert(type, dimension);
|
|
|
|
}
|
|
|
|
else if (type == MeasurementDimension::W)
|
|
|
|
{
|
|
|
|
auto dimension = QSharedPointer<VWMeasurementDimension>::create(units, min, max, step);
|
|
|
|
dimension->SetBaseValue(base);
|
|
|
|
dimension->SetLabels(labels);
|
|
|
|
dimensions.insert(type, dimension);
|
|
|
|
}
|
|
|
|
else if (type == MeasurementDimension::Z)
|
|
|
|
{
|
|
|
|
auto dimension = QSharedPointer<VZMeasurementDimension>::create(units, min, max, step);
|
|
|
|
dimension->SetBaseValue(base);
|
|
|
|
dimension->SetLabels(labels);
|
|
|
|
dimensions.insert(type, dimension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dimensions;
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool *ok) const
|
|
|
|
{
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
*ok = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-05-24 14:25:58 +02:00
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
2018-01-24 21:08:53 +01:00
|
|
|
const qreal result = cal->EvalFormula(data->DataVariables(), formula);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
2016-05-24 14:06:35 +02:00
|
|
|
(qIsInf(result) || qIsNaN(result)) ? *ok = false : *ok = true;
|
2015-07-24 12:06:39 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
2015-10-19 15:21:06 +02:00
|
|
|
Q_UNUSED(e)
|
2015-07-24 12:06:39 +02:00
|
|
|
*ok = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-16 19:26:05 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VMeasurements::ClearPMCode(const QString &code) const
|
|
|
|
{
|
|
|
|
QString clear = code;
|
|
|
|
const int index = clear.indexOf(QLatin1Char('p'));
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
clear.remove(0, 1);
|
|
|
|
}
|
|
|
|
return clear;
|
|
|
|
}
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<QString, qreal> VMeasurements::ReadCorrections(const QDomElement &mElement) const
|
|
|
|
{
|
|
|
|
if (mElement.isNull())
|
|
|
|
{
|
|
|
|
return QMap<QString, qreal>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement correctionsTag = mElement.firstChildElement(TagCorrections);
|
|
|
|
if (correctionsTag.isNull())
|
|
|
|
{
|
|
|
|
return QMap<QString, qreal>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QMap<QString, qreal> corrections;
|
|
|
|
|
|
|
|
QDomNode correctionTag = correctionsTag.firstChild();
|
|
|
|
while (not correctionTag.isNull())
|
|
|
|
{
|
|
|
|
if (correctionTag.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement c = correctionTag.toElement();
|
|
|
|
const QString hash = GetParametrString(c, AttrCoordinates);
|
|
|
|
const qreal correction = GetParametrDouble(c, AttrCorrection, QChar('0'));
|
|
|
|
|
|
|
|
corrections.insert(hash, correction);
|
|
|
|
}
|
|
|
|
correctionTag = correctionTag.nextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return corrections;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::WriteCorrections(QDomElement &mElement, const QMap<QString, qreal> &corrections)
|
|
|
|
{
|
|
|
|
QDomElement correctionsTag = mElement.firstChildElement(TagCorrections);
|
|
|
|
if (not corrections.isEmpty())
|
|
|
|
{
|
|
|
|
if (not correctionsTag.isNull())
|
|
|
|
{
|
|
|
|
RemoveAllChildren(correctionsTag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
correctionsTag = createElement(TagCorrections);
|
|
|
|
mElement.appendChild(correctionsTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMap<QString, qreal>::const_iterator i = corrections.constBegin();
|
|
|
|
while (i != corrections.constEnd())
|
|
|
|
{
|
|
|
|
QDomElement correctionTag = createElement(TagCorrection);
|
|
|
|
|
|
|
|
SetAttribute(correctionTag, AttrCorrection, i.value());
|
|
|
|
SetAttribute(correctionTag, AttrCoordinates, i.key());
|
|
|
|
|
|
|
|
correctionsTag.appendChild(correctionTag);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not correctionsTag.isNull())
|
|
|
|
{
|
|
|
|
mElement.removeChild(correctionsTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 12:34:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::SaveDimesionLabels(QDomElement &dElement, const DimesionLabels &labels)
|
|
|
|
{
|
|
|
|
if (dElement.isNull())
|
|
|
|
{
|
|
|
|
qDebug() << "Invalid dimension tag";
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement labelsTag = dElement.firstChildElement(TagLabels);
|
|
|
|
if (not labels.isEmpty())
|
|
|
|
{
|
|
|
|
if (not labelsTag.isNull())
|
|
|
|
{
|
|
|
|
RemoveAllChildren(labelsTag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelsTag = createElement(TagLabels);
|
|
|
|
dElement.appendChild(labelsTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
DimesionLabels::const_iterator i = labels.constBegin();
|
|
|
|
while (i != labels.constEnd())
|
|
|
|
{
|
|
|
|
if (not i.value().isEmpty())
|
|
|
|
{
|
|
|
|
QDomElement labelTag = createElement(TagLabel);
|
|
|
|
|
|
|
|
SetAttribute(labelTag, AttrValue, i.key());
|
|
|
|
SetAttribute(labelTag, AttrLabel, i.value());
|
|
|
|
|
|
|
|
labelsTag.appendChild(labelTag);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not labelsTag.isNull())
|
|
|
|
{
|
|
|
|
dElement.removeChild(labelsTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DimesionLabels VMeasurements::ReadDimensionLabels(const QDomElement &dElement) const
|
|
|
|
{
|
|
|
|
if (dElement.isNull())
|
|
|
|
{
|
|
|
|
return DimesionLabels();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement labelsTag = dElement.firstChildElement(TagLabels);
|
|
|
|
if (labelsTag.isNull())
|
|
|
|
{
|
|
|
|
return DimesionLabels();
|
|
|
|
}
|
|
|
|
|
|
|
|
DimesionLabels labels;
|
|
|
|
|
|
|
|
QDomNode labelTag = labelsTag.firstChild();
|
|
|
|
while (not labelTag.isNull())
|
|
|
|
{
|
|
|
|
if (labelTag.isElement())
|
|
|
|
{
|
|
|
|
const QDomElement l = labelTag.toElement();
|
2021-01-18 19:43:53 +01:00
|
|
|
const qreal value = GetParametrDouble(l, AttrValue, QChar('0'));
|
2020-10-08 12:34:38 +02:00
|
|
|
const QString label = GetParametrEmptyString(l, AttrLabel);
|
|
|
|
|
|
|
|
if (value > 0 && not label.isEmpty())
|
|
|
|
{
|
|
|
|
labels.insert(value, label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
labelTag = labelTag.nextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return labels;
|
|
|
|
}
|
2020-10-15 08:35:08 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VMeasurements::ClearDimension(IMD type)
|
|
|
|
{
|
|
|
|
const QString d = VMeasurements::IMDToStr(type);
|
|
|
|
QDomNodeList list = elementsByTagName(TagMeasurement);
|
|
|
|
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
QDomElement domElement = list.at(i).toElement();
|
|
|
|
if (domElement.isNull() == false)
|
|
|
|
{
|
|
|
|
if (domElement.attribute(AttrDimension) == d)
|
|
|
|
{
|
|
|
|
domElement.removeAttribute(AttrDimension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|