From 0c73e7f760de99c58c3b4493c33a226e1895d808 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 17 Aug 2015 15:36:55 +0300 Subject: [PATCH] Convert measurements to a pattern file's unit. --HG-- branch : feature --- src/libs/vformat/vmeasurements.cpp | 35 +++++++++++++++++++++++++----- src/libs/vpatterndb/vcontainer.cpp | 6 +++++ src/libs/vpatterndb/vcontainer.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 1a086881d..aba0cfa6d 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -170,6 +170,12 @@ void VMeasurements::MoveDown(const QString &name) //--------------------------------------------------------------------------------------------------------------------- void VMeasurements::ReadMeasurements() const { + // 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 + VContainer *tempData = new VContainer(data->GetTrVars(), data->GetPatternUnit()); + const QDomNodeList list = elementsByTagName(TagMeasurement); for (int i=0; i < list.size(); ++i) { @@ -198,23 +204,40 @@ void VMeasurements::ReadMeasurements() const } VMeasurement *meash; + VMeasurement *tempMeash; if (type == MeasurementsType::Standard) { - const qreal base = GetParametrDouble(dom, AttrBase, "0"); - const qreal ksize = GetParametrDouble(dom, AttrSizeIncrease, "0"); - const qreal kheight = GetParametrDouble(dom, AttrHeightIncrease, "0"); + qreal base = GetParametrDouble(dom, AttrBase, "0"); + qreal ksize = GetParametrDouble(dom, AttrSizeIncrease, "0"); + qreal kheight = GetParametrDouble(dom, AttrHeightIncrease, "0"); - meash = new VMeasurement(i, name, BaseSize(), BaseHeight(), base, ksize, kheight, fullName, description); + tempMeash = new VMeasurement(i, name, BaseSize(), BaseHeight(), base, ksize, kheight); + + base = UnitConvertor(base, MUnit(), *data->GetPatternUnit()); + ksize = UnitConvertor(ksize, MUnit(), *data->GetPatternUnit()); + kheight = UnitConvertor(kheight, MUnit(), *data->GetPatternUnit()); + + const qreal baseSize = UnitConvertor(BaseSize(), MUnit(), *data->GetPatternUnit()); + const qreal baseHeight = UnitConvertor(BaseHeight(), MUnit(), *data->GetPatternUnit()); + + meash = new VMeasurement(i, name, baseSize, baseHeight, base, ksize, kheight, fullName, description); } else { - QString formula = GetParametrString(dom, AttrValue, "0"); + const QString formula = GetParametrString(dom, AttrValue, "0"); bool ok = false; - const qreal value = EvalFormula(data, formula, &ok); + qreal value = EvalFormula(tempData, formula, &ok); + + tempMeash = new VMeasurement(tempData, i, name, value, formula, ok); + + value = UnitConvertor(value, MUnit(), *data->GetPatternUnit()); meash = new VMeasurement(data, i, name, value, formula, ok, fullName, description); } + tempData->AddVariable(name, tempMeash); data->AddVariable(name, meash); } + + delete tempData; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index cd4d14b68..729cf1015 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -480,6 +480,12 @@ const Unit *VContainer::GetPatternUnit() const return d->patternUnit; } +//--------------------------------------------------------------------------------------------------------------------- +const VTranslateVars *VContainer::GetTrVars() const +{ + return d->trVars; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VariableExist check if exist variable this same name. diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 78e4aa2f3..b230e6620 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -162,6 +162,7 @@ public: static bool IsUnique(const QString &name); const Unit *GetPatternUnit() const; + const VTranslateVars *GetTrVars() const; private: /**