Improve recipe export.
Add support for final measurements.
This commit is contained in:
parent
06bc9f8baf
commit
10e05b6f6f
|
@ -37,6 +37,7 @@
|
||||||
#include "../vgeometry/vsplinepath.h"
|
#include "../vgeometry/vsplinepath.h"
|
||||||
#include "../vgeometry/vcubicbezierpath.h"
|
#include "../vgeometry/vcubicbezierpath.h"
|
||||||
#include "../vtools/tools/drawTools/drawtools.h"
|
#include "../vtools/tools/drawTools/drawtools.h"
|
||||||
|
#include "../vpatterndb/calculator.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -88,7 +89,7 @@ VPatternRecipe::VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObj
|
||||||
|
|
||||||
QDomElement recipeElement = createElement(QStringLiteral("recipe"));
|
QDomElement recipeElement = createElement(QStringLiteral("recipe"));
|
||||||
recipeElement.appendChild(createComment(FileComment()));
|
recipeElement.appendChild(createComment(FileComment()));
|
||||||
SetAttribute(recipeElement, QStringLiteral("version"), QStringLiteral("1.0.0"));
|
SetAttribute(recipeElement, QStringLiteral("version"), QStringLiteral("1.1.0"));
|
||||||
|
|
||||||
recipeElement.appendChild(Prerequisite());
|
recipeElement.appendChild(Prerequisite());
|
||||||
recipeElement.appendChild(Content());
|
recipeElement.appendChild(Content());
|
||||||
|
@ -252,6 +253,8 @@ QDomElement VPatternRecipe::Content()
|
||||||
content.appendChild(Draft(draw));
|
content.appendChild(Draft(draw));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content.appendChild(FinalMeasurements());
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,6 +405,46 @@ QT_WARNING_POP
|
||||||
throw VExceptionInvalidHistory(tr("Can't create history record for the tool."));
|
throw VExceptionInvalidHistory(tr("Can't create history record for the tool."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::FinalMeasurements()
|
||||||
|
{
|
||||||
|
QDomElement recipeFinalMeasurements = createElement(QStringLiteral("finalMeasurements"));
|
||||||
|
|
||||||
|
const QVector<VFinalMeasurement> measurements = m_pattern->GetFinalMeasurements();
|
||||||
|
|
||||||
|
for (auto &m : measurements)
|
||||||
|
{
|
||||||
|
recipeFinalMeasurements.appendChild(FinalMeasurement(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipeFinalMeasurements;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::FinalMeasurement(const VFinalMeasurement &fm)
|
||||||
|
{
|
||||||
|
QDomElement recipeFinalMeasurement = createElement(QStringLiteral("finalMeasurement"));
|
||||||
|
|
||||||
|
SetAttribute(recipeFinalMeasurement, QStringLiteral("description"), fm.description);
|
||||||
|
SetAttribute(recipeFinalMeasurement, QStringLiteral("name"), fm.name);
|
||||||
|
SetAttribute(recipeFinalMeasurement, QStringLiteral("formula"), fm.formula); // TODO: localize
|
||||||
|
|
||||||
|
QScopedPointer<Calculator> cal(new Calculator());
|
||||||
|
const qreal result = cal->EvalFormula(m_data->DataVariables(), fm.formula);
|
||||||
|
if (qIsInf(result) || qIsNaN(result))
|
||||||
|
{
|
||||||
|
const QString errorMsg = QString("%1\n\n%1").arg(tr("Reading final measurements error."),
|
||||||
|
tr("Value for final measurtement '%1' is infinite or NaN. "
|
||||||
|
"Please, check your calculations.").arg(fm.name));
|
||||||
|
qApp->IsPedantic() ? throw VException(errorMsg) :
|
||||||
|
qWarning() << VAbstractApplication::patternMessageSignature + errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAttribute(recipeFinalMeasurement, QStringLiteral("value"), result);
|
||||||
|
|
||||||
|
return recipeFinalMeasurement;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QDomElement VPatternRecipe::BasePoint(const VToolRecord &record)
|
QDomElement VPatternRecipe::BasePoint(const VToolRecord &record)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,7 @@ class VIncrement;
|
||||||
class VToolRecord;
|
class VToolRecord;
|
||||||
class VFormula;
|
class VFormula;
|
||||||
class VAbstractOperation;
|
class VAbstractOperation;
|
||||||
|
class VFinalMeasurement;
|
||||||
|
|
||||||
class VPatternRecipe : public VDomDocument
|
class VPatternRecipe : public VDomDocument
|
||||||
{
|
{
|
||||||
|
@ -65,6 +66,9 @@ private:
|
||||||
QDomElement Draft(const QDomElement &draft);
|
QDomElement Draft(const QDomElement &draft);
|
||||||
QDomElement Step(const VToolRecord &tool);
|
QDomElement Step(const VToolRecord &tool);
|
||||||
|
|
||||||
|
QDomElement FinalMeasurements();
|
||||||
|
QDomElement FinalMeasurement(const VFinalMeasurement &fm);
|
||||||
|
|
||||||
QDomElement BasePoint(const VToolRecord &record);
|
QDomElement BasePoint(const VToolRecord &record);
|
||||||
QDomElement EndLine(const VToolRecord &record);
|
QDomElement EndLine(const VToolRecord &record);
|
||||||
QDomElement Line(const VToolRecord &record);
|
QDomElement Line(const VToolRecord &record);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user