From 0ef10c01b0a8f8d6f1efb675f7f6abf0f5c82320 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 21 Jan 2017 15:24:40 +0200 Subject: [PATCH] A piece seam allowance can be controlled by formula. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 19 +- src/app/valentina/xml/vpattern.h | 2 +- src/libs/ifc/schema/pattern/v0.4.0.xsd | 10 +- src/libs/ifc/xml/vabstractpattern.cpp | 10 +- src/libs/vpatterndb/vnodedetail.cpp | 16 +- src/libs/vpatterndb/vpiece.cpp | 14 + src/libs/vpatterndb/vpiece.h | 3 + src/libs/vpatterndb/vpiece_p.h | 8 +- src/libs/vpatterndb/vpiecenode.cpp | 69 +- src/libs/vpatterndb/vpiecenode.h | 19 +- src/libs/vpatterndb/vpiecenode_p.h | 9 + src/libs/vpatterndb/vpiecepath.cpp | 8 +- .../support/dialogeditwrongformula.cpp | 11 +- .../dialogs/support/dialogeditwrongformula.h | 2 + .../vtools/dialogs/tools/dialogpiecepath.cpp | 418 ++++++++--- .../vtools/dialogs/tools/dialogpiecepath.h | 44 +- .../vtools/dialogs/tools/dialogpiecepath.ui | 680 +++++++++++++++--- .../dialogs/tools/dialogseamallowance.cpp | 365 ++++++++-- .../dialogs/tools/dialogseamallowance.h | 40 +- .../dialogs/tools/dialogseamallowance.ui | 673 ++++++++++++++--- src/libs/vtools/dialogs/tools/dialogtool.cpp | 15 +- src/libs/vtools/dialogs/tools/dialogtool.h | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.cpp | 95 --- src/libs/vtools/tools/drawTools/vdrawtool.h | 1 - src/libs/vtools/tools/vabstracttool.cpp | 105 ++- src/libs/vtools/tools/vabstracttool.h | 2 + src/libs/vtools/tools/vtoolseamallowance.cpp | 24 +- src/libs/vtools/tools/vtoolseamallowance.h | 2 +- src/libs/vtools/tools/vtooluniondetails.cpp | 7 +- 29 files changed, 2144 insertions(+), 529 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 5c1479232..6bee26a2b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -296,8 +296,9 @@ void VPattern::setCurrentData() const VDataTool *vTool = tools.value(id); *data = vTool->getData(); - //Delete special variable if exist + //Delete special variables if exist data->RemoveVariable(currentLength); + data->RemoveVariable(currentSeamAllowance); qCDebug(vXML, "Data successfully updated."); } else @@ -690,7 +691,7 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const * @param domElement tag in xml tree. * @param parse parser file mode. */ -void VPattern::ParseDetailElement(const QDomElement &domElement, const Document &parse) +void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse) { Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try @@ -701,12 +702,13 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.SetMx(qApp->toPixel(GetParametrDouble(domElement, AttrMx, "0.0"))); detail.SetMy(qApp->toPixel(GetParametrDouble(domElement, AttrMy, "0.0"))); detail.SetSeamAllowance(GetParametrBool(domElement, VToolSeamAllowance::AttrSeamAllowance, falseStr)); - detail.SetSAWidth(GetParametrDouble(domElement, VToolSeamAllowance::AttrWidth, "0.0")); detail.SetForbidFlipping(GetParametrBool(domElement, VToolSeamAllowance::AttrForbidFlipping, QString().setNum(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()))); detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); + const QString width = GetParametrString(domElement, VToolSeamAllowance::AttrWidth, "0.0"); + QString w = width;//need for saving fixed formula; const uint version = GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1"); const QStringList tags = QStringList() << TagNodes @@ -757,7 +759,14 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } } } - VToolSeamAllowance::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); + VToolSeamAllowance::Create(id, detail, w, sceneDetail, this, data, parse, Source::FromFile); + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (w != width) + { + SetAttribute(domElement, VToolSeamAllowance::AttrWidth, w); + modified = true; + haveLiteChange(); + } } catch (const VExceptionBadId &e) { @@ -877,7 +886,7 @@ void VPattern::ParseDetails(const QDomElement &domElement, const Document &parse { if (domNode.isElement()) { - const QDomElement domElement = domNode.toElement(); + QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { if (domElement.tagName() == TagDetail) diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 31cff3136..19a3010a7 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -118,7 +118,7 @@ private: void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); - void ParseDetailElement(const QDomElement &domElement, const Document &parse); + void ParseDetailElement(QDomElement &domElement, const Document &parse); void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const; void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const; void ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const; diff --git a/src/libs/ifc/schema/pattern/v0.4.0.xsd b/src/libs/ifc/schema/pattern/v0.4.0.xsd index fd1f4d635..bcb5da26f 100644 --- a/src/libs/ifc/schema/pattern/v0.4.0.xsd +++ b/src/libs/ifc/schema/pattern/v0.4.0.xsd @@ -370,8 +370,8 @@ - - + + @@ -503,8 +503,8 @@ - - + + @@ -547,7 +547,7 @@ - + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index f51ea8eaf..87755a387 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -634,8 +634,10 @@ VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement) { const quint32 id = VDomDocument::GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); const bool reverse = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0"); - const qreal saBefore = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1"); - const qreal saAfter = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1"); + const QString saBefore = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSABefore, + currentSeamAllowance); + const QString saAfter = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSAAfter, + currentSeamAllowance); const PieceNodeAngle angle = static_cast(VDomDocument::GetParametrUInt(domElement, AttrAngle, "0")); const QString t = VDomDocument::GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint); @@ -669,8 +671,8 @@ VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement) throw e; } VPieceNode node(id, tool, reverse); - node.SetSABefore(saBefore); - node.SetSAAfter(saAfter); + node.SetFormulaSABefore(saBefore); + node.SetFormulaSAAfter(saAfter); node.SetAngleType(angle); return node; diff --git a/src/libs/vpatterndb/vnodedetail.cpp b/src/libs/vpatterndb/vnodedetail.cpp index a26b86887..b7fcf60ba 100644 --- a/src/libs/vpatterndb/vnodedetail.cpp +++ b/src/libs/vpatterndb/vnodedetail.cpp @@ -199,29 +199,29 @@ QVector VNodeDetail::Convert(const VContainer *data, const QVector VNodeDetail::Convert(const VContainer *data, const QVector 1) { - path[0].SetSABefore(0); - path[path.CountNodes()-1].SetSAAfter(0); + path[0].SetFormulaSABefore("0"); + path[path.CountNodes()-1].SetFormulaSAAfter("0"); } return path.GetNodes(); diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 9fc8a2a10..85200418d 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -269,6 +269,20 @@ void VPiece::SetUnited(bool united) d->m_united = united; } +//--------------------------------------------------------------------------------------------------------------------- +QString VPiece::GetFormulaSAWidth() const +{ + return d->m_formulaWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetFormulaSAWidth(const QString &formula, qreal value) +{ + SetSAWidth(value); + const qreal width = GetSAWidth(); + width >= 0 ? d->m_formulaWidth = formula : d->m_formulaWidth = QLatin1String("0"); +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::GetInternalPaths() const { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index fcd2c9948..0ea0180e4 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -79,6 +79,9 @@ public: bool IsUnited() const; void SetUnited(bool united); + QString GetFormulaSAWidth() const; + void SetFormulaSAWidth(const QString &formula, qreal value); + QVector GetInternalPaths() const; void SetInternalPaths(const QVector &iPaths); void AppendInternalPath(quint32 path); diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index 53791ae3b..f937e8488 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -56,7 +56,8 @@ public: m_internalPaths(), m_ppData(), m_piPatternInfo(), - m_glGrainline() + m_glGrainline(), + m_formulaWidth("0") {} VPieceData(const VPieceData &detail) @@ -70,7 +71,8 @@ public: m_internalPaths(detail.m_internalPaths), m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), - m_glGrainline(detail.m_glGrainline) + m_glGrainline(detail.m_glGrainline), + m_formulaWidth(detail.m_formulaWidth) {} ~VPieceData(); @@ -96,6 +98,8 @@ public: /** @brief m_glGrainline grainline geometry object*/ VGrainlineGeometry m_glGrainline; + QString m_formulaWidth; + private: VPieceData &operator=(const VPieceData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vpatterndb/vpiecenode.cpp b/src/libs/vpatterndb/vpiecenode.cpp index 1401121eb..a03d7e476 100644 --- a/src/libs/vpatterndb/vpiecenode.cpp +++ b/src/libs/vpatterndb/vpiecenode.cpp @@ -28,8 +28,11 @@ #include "vpiecenode.h" #include "vpiecenode_p.h" +#include "vcontainer.h" +#include "calculator.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- VPieceNode::VPieceNode() @@ -101,15 +104,15 @@ void VPieceNode::SetReverse(bool reverse) } //--------------------------------------------------------------------------------------------------------------------- -qreal VPieceNode::GetSABefore() const +qreal VPieceNode::GetSABefore(const VContainer *data) const { - return d->m_saBefore; + return EvalFormula(data, d->m_formulaWidthBefore); } //--------------------------------------------------------------------------------------------------------------------- -qreal VPieceNode::GetSABefore(Unit unit) const +qreal VPieceNode::GetSABefore(const VContainer *data, Unit unit) const { - qreal value = d->m_saBefore; + qreal value = EvalFormula(data, d->m_formulaWidthBefore); if (value >= 0) { value = ToPixel(value, unit); @@ -118,24 +121,30 @@ qreal VPieceNode::GetSABefore(Unit unit) const } //--------------------------------------------------------------------------------------------------------------------- -void VPieceNode::SetSABefore(qreal value) +QString VPieceNode::GetFormulaSABefore() const +{ + return d->m_formulaWidthBefore; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceNode::SetFormulaSABefore(const QString &formula) { if (d->m_typeTool == Tool::NodePoint) { - value < 0 ? d->m_saBefore = -1: d->m_saBefore = value; + d->m_formulaWidthBefore = formula; } } //--------------------------------------------------------------------------------------------------------------------- -qreal VPieceNode::GetSAAfter() const +qreal VPieceNode::GetSAAfter(const VContainer *data) const { - return d->m_saAfter; + return EvalFormula(data, d->m_formulaWidthAfter); } //--------------------------------------------------------------------------------------------------------------------- -qreal VPieceNode::GetSAAfter(Unit unit) const +qreal VPieceNode::GetSAAfter(const VContainer *data, Unit unit) const { - qreal value = d->m_saAfter; + qreal value = EvalFormula(data, d->m_formulaWidthAfter); if (value >= 0) { value = ToPixel(value, unit); @@ -144,11 +153,17 @@ qreal VPieceNode::GetSAAfter(Unit unit) const } //--------------------------------------------------------------------------------------------------------------------- -void VPieceNode::SetSAAfter(qreal value) +QString VPieceNode::GetFormulaSAAfter() const +{ + return d->m_formulaWidthAfter; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceNode::SetFormulaSAAfter(const QString &formula) { if (d->m_typeTool == Tool::NodePoint) { - value < 0 ? d->m_saAfter = -1: d->m_saAfter = value; + d->m_formulaWidthAfter = formula; } } @@ -167,6 +182,36 @@ void VPieceNode::SetAngleType(PieceNodeAngle type) } } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPieceNode::EvalFormula(const VContainer *data, QString formula) const +{ + if (formula.isEmpty()) + { + return -1; + } + else + { + try + { + // Replace line return character with spaces for calc if exist + formula.replace("\n", " "); + QScopedPointer cal(new Calculator()); + const qreal result = cal->EvalFormula(data->PlainVariables(), formula); + + if (qIsInf(result) || qIsNaN(result)) + { + return -1; + } + return result; + } + catch (qmu::QmuParserError &e) + { + Q_UNUSED(e) + return -1; + } + } +} + // Friend functions //--------------------------------------------------------------------------------------------------------------------- QDataStream& operator<<(QDataStream& out, const VPieceNode& p) diff --git a/src/libs/vpatterndb/vpiecenode.h b/src/libs/vpatterndb/vpiecenode.h index 89c212cb2..9114b6c33 100644 --- a/src/libs/vpatterndb/vpiecenode.h +++ b/src/libs/vpatterndb/vpiecenode.h @@ -37,6 +37,7 @@ class VPieceNodeData; class QDataStream; +class VContainer; class VPieceNode { @@ -59,18 +60,24 @@ public: bool GetReverse() const; void SetReverse(bool reverse); - qreal GetSABefore() const; - qreal GetSABefore(Unit unit) const; - void SetSABefore(qreal value); + qreal GetSABefore(const VContainer *data) const; + qreal GetSABefore(const VContainer *data, Unit unit) const; - qreal GetSAAfter() const; - qreal GetSAAfter(Unit unit) const; - void SetSAAfter(qreal value); + QString GetFormulaSABefore() const; + void SetFormulaSABefore(const QString &formula); + + qreal GetSAAfter(const VContainer *data) const; + qreal GetSAAfter(const VContainer *data, Unit unit) const; + + QString GetFormulaSAAfter() const; + void SetFormulaSAAfter(const QString &formula); PieceNodeAngle GetAngleType() const; void SetAngleType(PieceNodeAngle type); private: QSharedDataPointer d; + + qreal EvalFormula(const VContainer *data, QString formula) const; }; Q_DECLARE_METATYPE(VPieceNode) diff --git a/src/libs/vpatterndb/vpiecenode_p.h b/src/libs/vpatterndb/vpiecenode_p.h index 25a1c0bad..98c6c6797 100644 --- a/src/libs/vpatterndb/vpiecenode_p.h +++ b/src/libs/vpatterndb/vpiecenode_p.h @@ -45,6 +45,8 @@ public: m_reverse(false), m_saBefore(-1), m_saAfter(-1), + m_formulaWidthBefore("-1"), + m_formulaWidthAfter("-1"), m_angleType(PieceNodeAngle::ByLength) {} @@ -54,6 +56,8 @@ public: m_reverse(reverse), m_saBefore(-1), m_saAfter(-1), + m_formulaWidthBefore("-1"), + m_formulaWidthAfter("-1"), m_angleType(PieceNodeAngle::ByLength) { if (m_typeTool == Tool::NodePoint) @@ -69,6 +73,8 @@ public: m_reverse(node.m_reverse), m_saBefore(node.m_saBefore), m_saAfter(node.m_saAfter), + m_formulaWidthBefore(node.m_formulaWidthBefore), + m_formulaWidthAfter(node.m_formulaWidthAfter), m_angleType(node.m_angleType) {} @@ -86,6 +92,9 @@ public: qreal m_saBefore; qreal m_saAfter; + QString m_formulaWidthBefore; + QString m_formulaWidthAfter; + PieceNodeAngle m_angleType; private: diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 9d3e6216d..2a35473e4 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -656,8 +656,8 @@ VSAPoint VPiecePath::PreparePointEkv(const VPieceNode &node, const VContainer *d const QSharedPointer point = data->GeometricObject(node.GetId()); VSAPoint p(point->toQPointF()); - p.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - p.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + p.SetSAAfter(node.GetSAAfter(data, *data->GetPatternUnit())); + p.SetSABefore(node.GetSABefore(data, *data->GetPatternUnit())); p.SetAngleType(node.GetAngleType()); return p; @@ -762,8 +762,8 @@ VSAPoint VPiecePath::CurvePoint(const VSAPoint &candidate, const VContainer *dat if (curve->IsPointOnCurve(p)) { point = VSAPoint(p); - point.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - point.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + point.SetSAAfter(node.GetSAAfter(data, *data->GetPatternUnit())); + point.SetSABefore(node.GetSABefore(data, *data->GetPatternUnit())); point.SetAngleType(node.GetAngleType()); } } diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index 731b3d2ab..db8590590 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -77,7 +77,7 @@ enum {ColumnName = 0, ColumnFullName}; //--------------------------------------------------------------------------------------------------------------------- DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0), - checkZero(false), postfix(QString()), restoreCursor(false) + checkZero(false), checkLessThanZero(false), postfix(QString()), restoreCursor(false) { ui->setupUi(this); InitVariables(); @@ -156,7 +156,8 @@ void DialogEditWrongFormula::EvalFormula() { SCASSERT(plainTextEditFormula != nullptr) SCASSERT(labelResultCalculation != nullptr) - Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, checkZero); + Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, checkZero, + checkLessThanZero); } //--------------------------------------------------------------------------------------------------------------------- @@ -383,6 +384,12 @@ void DialogEditWrongFormula::setCheckZero(bool value) checkZero = value; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::setCheckLessThanZero(bool value) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::setPostfix(const QString &value) { diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h index 247aeb33c..41b623bdd 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h @@ -70,6 +70,7 @@ public: QString GetFormula() const; void SetFormula(const QString &value); void setCheckZero(bool value); + void setCheckLessThanZero(bool value); void setPostfix(const QString &value); public slots: virtual void DialogAccepted() Q_DECL_OVERRIDE; @@ -109,6 +110,7 @@ private: int formulaBaseHeight; bool checkZero; + bool checkLessThanZero; QString postfix; bool restoreCursor; diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index d9d017a80..9e71a3a27 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -32,72 +32,34 @@ #include "visualization/path/vistoolpiecepath.h" #include "../../tools/vabstracttool.h" #include "../../tools/vtoolseamallowance.h" +#include "../support/dialogeditwrongformula.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent) : DialogTool(data, toolId, parent), - ui(new Ui::DialogPiecePath), - m_showMode(false) + ui(new Ui::DialogPiecePath), + m_showMode(false), + m_saWidth(0), + m_timerWidth(nullptr), + m_timerWidthBefore(nullptr), + m_timerWidthAfter(nullptr), + m_formulaBaseWidth(0), + m_formulaBaseWidthBefore(0), + m_formulaBaseWidthAfter(0) { ui->setupUi(this); InitOkCancel(ui); -#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) - ui->lineEditName->setClearButtonEnabled(true); -#endif - - FillComboBoxTypeLine(ui->comboBoxPenType, VAbstractTool::LineStylesPics()); - - connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogPiecePath::NameChanged); - - InitPathTypes(); - connect(ui->comboBoxType, static_cast(&QComboBox::currentIndexChanged), - [this]() - { - ui->comboBoxPenType->setEnabled(GetType() == PiecePathType::InternalPath); - ValidObjects(PathIsValid()); - }); + InitPathTab(); + InitSeamAllowanceTab(); flagName = true;//We have default name of piece. flagError = PathIsValid(); CheckState(); - const QString suffix = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit(), true); - ui->doubleSpinBoxSeams->setSuffix(suffix); - ui->doubleSpinBoxSABefore->setSuffix(suffix); - ui->doubleSpinBoxSAAfter->setSuffix(suffix); - - if(qApp->patternUnit() == Unit::Inch) - { - ui->doubleSpinBoxSeams->setDecimals(5); - ui->doubleSpinBoxSABefore->setDecimals(5); - ui->doubleSpinBoxSAAfter->setDecimals(5); - } - - InitNodesList(); - connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, - &DialogPiecePath::NodeChanged); - - connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefBefore); - connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefAfter); - - connect(ui->doubleSpinBoxSeams, static_cast(&QDoubleSpinBox::valueChanged), - [this](){NodeChanged(ui->comboBoxNodes->currentIndex());}); - - connect(ui->doubleSpinBoxSABefore, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogPiecePath::ChangedSABefore); - connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogPiecePath::ChangedSAAfter); - - InitNodeAngles(ui->comboBoxAngle); - connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, - &DialogPiecePath::NodeAngleChanged); - - ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogPiecePath::ShowContextMenu); - vis = new VisToolPiecePath(data); ui->tabWidget->removeTab(1); @@ -314,14 +276,18 @@ void DialogPiecePath::NameChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::NodeChanged(int index) { - ui->doubleSpinBoxSABefore->setDisabled(true); - ui->doubleSpinBoxSAAfter->setDisabled(true); + ui->plainTextEditFormulaWidthBefore->setDisabled(true); + ui->toolButtonExprBefore->setDisabled(true); ui->pushButtonDefBefore->setDisabled(true); + + ui->plainTextEditFormulaWidthAfter->setDisabled(true); + ui->toolButtonExprAfter->setDisabled(true); ui->pushButtonDefAfter->setDisabled(true); + ui->comboBoxAngle->setDisabled(true); - ui->doubleSpinBoxSABefore->blockSignals(true); - ui->doubleSpinBoxSAAfter->blockSignals(true); + ui->plainTextEditFormulaWidthBefore->blockSignals(true); + ui->plainTextEditFormulaWidthAfter->blockSignals(true); ui->comboBoxAngle->blockSignals(true); if (index != -1) @@ -337,32 +303,42 @@ void DialogPiecePath::NodeChanged(int index) { const VPieceNode &node = path.at(nodeIndex); - ui->doubleSpinBoxSABefore->setEnabled(true); - ui->doubleSpinBoxSAAfter->setEnabled(true); - ui->comboBoxAngle->setEnabled(true); + // Seam alowance before + ui->plainTextEditFormulaWidthBefore->setEnabled(true); + ui->toolButtonExprBefore->setEnabled(true); - qreal w1 = node.GetSABefore(); - if (w1 < 0) - { - w1 = ui->doubleSpinBoxSeams->value(); - } - else + QString w1Formula = node.GetFormulaSABefore(); + if (w1Formula != currentSeamAllowance) { ui->pushButtonDefBefore->setEnabled(true); } - ui->doubleSpinBoxSABefore->setValue(w1); - - qreal w2 = node.GetSAAfter(); - if (w2 < 0) + if (w1Formula.length() > 80)// increase height if needed. { - w2 = ui->doubleSpinBoxSeams->value(); + this->DeployWidthBeforeFormulaTextEdit(); } - else - { - ui->pushButtonDefAfter->setEnabled(true); - } - ui->doubleSpinBoxSAAfter->setValue(w2); + w1Formula = qApp->TrVars()->FormulaToUser(w1Formula, qApp->Settings()->GetOsSeparator()); + ui->plainTextEditFormulaWidthBefore->setPlainText(w1Formula); + MoveCursorToEnd(ui->plainTextEditFormulaWidthBefore); + // Seam alowance after + ui->plainTextEditFormulaWidthAfter->setEnabled(true); + ui->toolButtonExprAfter->setEnabled(true); + + QString w2Formula = node.GetFormulaSAAfter(); + if (w2Formula != currentSeamAllowance) + { + ui->pushButtonDefBefore->setEnabled(true); + } + if (w2Formula.length() > 80)// increase height if needed. + { + this->DeployWidthAfterFormulaTextEdit(); + } + w2Formula = qApp->TrVars()->FormulaToUser(w2Formula, qApp->Settings()->GetOsSeparator()); + ui->plainTextEditFormulaWidthAfter->setPlainText(w2Formula); + MoveCursorToEnd(ui->plainTextEditFormulaWidthAfter); + + // Angle type + ui->comboBoxAngle->setEnabled(true); const int index = ui->comboBoxAngle->findData(static_cast(node.GetAngleType())); if (index != -1) { @@ -372,38 +348,238 @@ void DialogPiecePath::NodeChanged(int index) } else { - ui->doubleSpinBoxSABefore->setValue(0); - ui->doubleSpinBoxSAAfter->setValue(0); + ui->plainTextEditFormulaWidthBefore->setPlainText(""); + ui->plainTextEditFormulaWidthAfter->setPlainText(""); ui->comboBoxAngle->setCurrentIndex(-1); } - ui->doubleSpinBoxSABefore->blockSignals(false); - ui->doubleSpinBoxSAAfter->blockSignals(false); + ui->plainTextEditFormulaWidthBefore->blockSignals(false); + ui->plainTextEditFormulaWidthAfter->blockSignals(false); ui->comboBoxAngle->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::ReturnDefBefore() { - SetCurrentSABefore(-1); + ui->plainTextEditFormulaWidthBefore->setPlainText(currentSeamAllowance); } //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::ReturnDefAfter() { - SetCurrentSAAfter(-1); + ui->plainTextEditFormulaWidthAfter->setPlainText(currentSeamAllowance); } //--------------------------------------------------------------------------------------------------------------------- -void DialogPiecePath::ChangedSABefore(double d) +void DialogPiecePath::EvalWidth() { - SetCurrentSABefore(d); + labelEditFormula = ui->labelEditWidth; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidth->toPlainText(); + m_saWidth = Eval(formula, flagFormula, ui->labelResultWidth, postfix, true, true); + + if (m_saWidth >= 0) + { + VContainer *locData = const_cast (data); + locData->AddVariable(currentSeamAllowance, new VIncrement(locData, currentSeamAllowance, 0, m_saWidth, + QString().setNum(m_saWidth), true, + tr("Current seam aloowance"))); + + EvalWidthBefore(); + EvalWidthAfter(); + } } //--------------------------------------------------------------------------------------------------------------------- -void DialogPiecePath::ChangedSAAfter(double d) +void DialogPiecePath::EvalWidthBefore() { - SetCurrentSAAfter(d); + labelEditFormula = ui->labelEditBefore; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidthBefore->toPlainText(); + bool flagFormula = false; // fake flag + Eval(formula, flagFormula, ui->labelResultBefore, postfix, true, true); + + UpdateNodeSABefore(GetFormulaSAWidthBefore()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::EvalWidthAfter() +{ + labelEditFormula = ui->labelEditAfter; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidthAfter->toPlainText(); + bool flagFormula = false; // fake flag + Eval(formula, flagFormula, ui->labelResultAfter, postfix, true, true); + + UpdateNodeSABefore(GetFormulaSAWidthAfter()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::FXWidth() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width")); + dialog->SetFormula(GetFormulaSAWidth()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetFormulaSAWidth(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::FXWidthBefore() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width before")); + dialog->SetFormula(GetFormulaSAWidthBefore()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetCurrentSABefore(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::FXWidthAfter() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width after")); + dialog->SetFormula(GetFormulaSAWidthAfter()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetCurrentSAAfter(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::WidthChanged() +{ + labelEditFormula = ui->labelEditWidth; + labelResultCalculation = ui->labelResultWidth; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidth, m_timerWidth, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::WidthBeforeChanged() +{ + labelEditFormula = ui->labelEditBefore; + labelResultCalculation = ui->labelResultBefore; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + bool flagFormula = false; + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::WidthAfterChanged() +{ + labelEditFormula = ui->labelEditAfter; + labelResultCalculation = ui->labelResultAfter; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + bool flagFormula = false; + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::DeployWidthFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseWidth); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::DeployWidthBeforeFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidthBefore, ui->pushButtonGrowWidthBefore, m_formulaBaseWidthBefore); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::DeployWidthAfterFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitPathTab() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + ui->lineEditName->setClearButtonEnabled(true); +#endif + + FillComboBoxTypeLine(ui->comboBoxPenType, VAbstractTool::LineStylesPics()); + + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogPiecePath::NameChanged); + + InitPathTypes(); + connect(ui->comboBoxType, static_cast(&QComboBox::currentIndexChanged), + [this]() + { + ui->comboBoxPenType->setEnabled(GetType() == PiecePathType::InternalPath); + ValidObjects(PathIsValid()); + }); + + ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogPiecePath::ShowContextMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitSeamAllowanceTab() +{ + plainTextEditFormula = ui->plainTextEditFormulaWidth; + this->m_formulaBaseWidth = ui->plainTextEditFormulaWidth->height(); + this->m_formulaBaseWidthBefore = ui->plainTextEditFormulaWidthBefore->height(); + this->m_formulaBaseWidthAfter = ui->plainTextEditFormulaWidthAfter->height(); + + ui->plainTextEditFormulaWidth->installEventFilter(this); + ui->plainTextEditFormulaWidthBefore->installEventFilter(this); + ui->plainTextEditFormulaWidthAfter->installEventFilter(this); + + m_timerWidth = new QTimer(this); + connect(m_timerWidth, &QTimer::timeout, this, &DialogPiecePath::EvalWidth); + + m_timerWidthBefore = new QTimer(this); + connect(m_timerWidthBefore, &QTimer::timeout, this, &DialogPiecePath::EvalWidthBefore); + + m_timerWidthAfter = new QTimer(this); + connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogPiecePath::EvalWidthAfter); + + // Default value for seam allowence is 1 cm. But pattern have different units, so just set 1 in dialog not enough. + m_saWidth = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + ui->plainTextEditFormulaWidth->setPlainText(qApp->LocaleToString(m_saWidth)); + + InitNodesList(); + connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPiecePath::NodeChanged); + + connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefBefore); + connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefAfter); + + InitNodeAngles(ui->comboBoxAngle); + connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPiecePath::NodeAngleChanged); + + connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPiecePath::FXWidth); + connect(ui->toolButtonExprBefore, &QPushButton::clicked, this, &DialogPiecePath::FXWidthBefore); + connect(ui->toolButtonExprAfter, &QPushButton::clicked, this, &DialogPiecePath::FXWidthAfter); + + connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPiecePath::WidthChanged); + connect(ui->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this, + &DialogPiecePath::WidthBeforeChanged); + connect(ui->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this, + &DialogPiecePath::WidthAfterChanged); + + connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPiecePath::DeployWidthFormulaTextEdit); + connect(ui->pushButtonGrowWidthBefore, &QPushButton::clicked, + this, &DialogPiecePath::DeployWidthBeforeFormulaTextEdit); + connect(ui->pushButtonGrowWidthAfter, &QPushButton::clicked, this, + &DialogPiecePath::DeployWidthAfterFormulaTextEdit); } //--------------------------------------------------------------------------------------------------------------------- @@ -582,7 +758,21 @@ quint32 DialogPiecePath::GetLastId() const } //--------------------------------------------------------------------------------------------------------------------- -void DialogPiecePath::SetCurrentSABefore(qreal value) +void DialogPiecePath::SetCurrentSABefore(const QString &formula) +{ + UpdateNodeSABefore(formula); + ListChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetCurrentSAAfter(const QString &formula) +{ + UpdateNodeSAAfter(formula); + ListChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::UpdateNodeSABefore(const QString &formula) { const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) @@ -597,16 +787,14 @@ void DialogPiecePath::SetCurrentSABefore(qreal value) if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - rowNode.SetSABefore(value); + rowNode.SetFormulaSABefore(formula); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); - - ListChanged(); } } } //--------------------------------------------------------------------------------------------------------------------- -void DialogPiecePath::SetCurrentSAAfter(qreal value) +void DialogPiecePath::UpdateNodeSAAfter(const QString &formula) { const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) @@ -621,14 +809,30 @@ void DialogPiecePath::SetCurrentSAAfter(qreal value) if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - rowNode.SetSAAfter(value); + rowNode.SetFormulaSAAfter(formula); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); - - ListChanged(); } } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetFormulaSAWidth(const QString &formula) +{ + const QString width = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (width.length() > 80) + { + this->DeployWidthFormulaTextEdit(); + } + ui->plainTextEditFormulaWidth->setPlainText(width); + + VisToolPiecePath *path = qobject_cast(vis); + SCASSERT(path != nullptr) + path->SetPath(CreatePath()); + + MoveCursorToEnd(ui->plainTextEditFormulaWidth); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 DialogPiecePath::GetPieceId() const { @@ -667,17 +871,11 @@ void DialogPiecePath::SetPieceId(quint32 id) } //--------------------------------------------------------------------------------------------------------------------- -void DialogPiecePath::SetSAWidth(qreal width) +QString DialogPiecePath::GetFormulaSAWidth() const { - if (width >=0) - { - ui->tabWidget->addTab(ui->tabSeamAllowance, tr("Seam allowance")); - ui->doubleSpinBoxSeams->setValue(width); - } - else - { - ui->tabWidget->removeTab(1); - } + QString width = ui->plainTextEditFormulaWidth->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -758,3 +956,19 @@ void DialogPiecePath::NewItem(const VPieceNode &node) { NewNodeItem(ui->listWidget, node); } + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPiecePath::GetFormulaSAWidthBefore() const +{ + QString width = ui->plainTextEditFormulaWidthBefore->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPiecePath::GetFormulaSAWidthAfter() const +{ + QString width = ui->plainTextEditFormulaWidthAfter->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); +} diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.h b/src/libs/vtools/dialogs/tools/dialogpiecepath.h index c1f06c163..4739d8ea3 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.h +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.h @@ -51,7 +51,8 @@ public: quint32 GetPieceId() const; void SetPieceId(quint32 id); - void SetSAWidth(qreal width); + QString GetFormulaSAWidth() const; + void SetFormulaSAWidth(const QString &formula); virtual void SetPiecesList(const QVector &list) Q_DECL_OVERRIDE; @@ -72,14 +73,39 @@ private slots: void NodeChanged(int index); void ReturnDefBefore(); void ReturnDefAfter(); - void ChangedSABefore(double d); - void ChangedSAAfter(double d); + + void EvalWidth(); + void EvalWidthBefore(); + void EvalWidthAfter(); + + void FXWidth(); + void FXWidthBefore(); + void FXWidthAfter(); + + void WidthChanged(); + void WidthBeforeChanged(); + void WidthAfterChanged(); + + void DeployWidthFormulaTextEdit(); + void DeployWidthBeforeFormulaTextEdit(); + void DeployWidthAfterFormulaTextEdit(); private: Q_DISABLE_COPY(DialogPiecePath) Ui::DialogPiecePath *ui; - bool m_showMode; + bool m_showMode; + qreal m_saWidth; + QTimer *m_timerWidth; + QTimer *m_timerWidthBefore; + QTimer *m_timerWidthAfter; + + int m_formulaBaseWidth; + int m_formulaBaseWidthBefore; + int m_formulaBaseWidthAfter; + + void InitPathTab(); + void InitSeamAllowanceTab(); void InitPathTypes(); void InitListPieces(); void InitNodesList(); @@ -101,8 +127,14 @@ private: quint32 GetLastId() const; - void SetCurrentSABefore(qreal value); - void SetCurrentSAAfter(qreal value); + void SetCurrentSABefore(const QString &formula); + void SetCurrentSAAfter(const QString &formula); + + void UpdateNodeSABefore(const QString &formula); + void UpdateNodeSAAfter(const QString &formula); + + QString GetFormulaSAWidthBefore() const; + QString GetFormulaSAWidthAfter() const; }; #endif // DIALOGPIECEPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui index 6ee68ac25..10d360ffd 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui @@ -7,7 +7,7 @@ 0 0 480 - 409 + 437 @@ -121,19 +121,53 @@ Seam allowance - + - - + + - + 0 0 - - + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + Width: @@ -141,29 +175,7 @@ - - - - 0 - 0 - - - - true - - - 900.990000000000009 - - - 0.100000000000000 - - - 0.000000000000000 - - - - - + Qt::Horizontal @@ -175,6 +187,125 @@ + + + + false + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + false + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + @@ -182,44 +313,108 @@ Nodes - - - QFormLayout::ExpandingFieldsGrow - - - - - Node: - - - - - - - - - - Seam allowance before node - - - Before: - - - - - + + + - - - 900.990000000000009 - - - 0.100000000000000 + + + Node: + + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Before: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + false + Return to default width @@ -228,32 +423,197 @@ - - - - - - Seam allowance after node - - - After: - - - - - - - - - 900.990000000000009 + + + + false - - 0.100000000000000 + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + false + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + After: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + false + Return to default width @@ -262,17 +622,157 @@ + + + + false + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + - - - - Angle: - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + false + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + - - + + + + + + Angle: + + + + + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 9be77474d..a9d1b5a44 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -37,6 +37,7 @@ #include "../support/dialogeditwrongformula.h" #include +#include #include //--------------------------------------------------------------------------------------------------------------------- @@ -55,7 +56,14 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_oldGeom(), m_oldGrainline(), m_iRotBaseHeight(0), - m_iLenBaseHeight(0) + m_iLenBaseHeight(0), + m_formulaBaseWidth(0), + m_formulaBaseWidthBefore(0), + m_formulaBaseWidthAfter(0), + m_timerWidth(nullptr), + m_timerWidthBefore(nullptr), + m_timerWidthAfter(nullptr), + m_saWidth(0) { ui->setupUi(this); @@ -84,6 +92,9 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogSeamAllowance::~DialogSeamAllowance() { + VContainer *locData = const_cast (data); + locData->RemoveVariable(currentSeamAllowance); + delete ui; } @@ -141,10 +152,12 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) CustomSAChanged(0); ui->checkBoxForbidFlipping->setChecked(piece.IsForbidFlipping()); - ui->doubleSpinBoxSeams->setValue(piece.GetSAWidth()); ui->checkBoxSeams->setChecked(piece.IsSeamAllowance()); ui->lineEditName->setText(piece.GetName()); + ui->plainTextEditFormulaWidth->setPlainText(piece.GetFormulaSAWidth()); + m_saWidth = piece.GetSAWidth(); + m_mx = piece.GetMx(); m_my = piece.GetMy(); @@ -283,7 +296,7 @@ void DialogSeamAllowance::SaveData() void DialogSeamAllowance::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError); + bOk->setEnabled(flagName && flagError && flagFormula); // In case dialog hasn't apply button if ( bApply != nullptr && applyAllowed) { @@ -506,7 +519,7 @@ void DialogSeamAllowance::ShowCustomSAContextMenu(const QPoint &pos) dialog->SetPieceId(toolId); if (record.includeType == PiecePathIncludeType::AsMainPath) { - dialog->SetSAWidth(ui->doubleSpinBoxSeams->value()); + dialog->SetFormulaSAWidth(GetFormulaSAWidth()); } dialog->EnbleShowMode(true); m_dialog = dialog; @@ -580,14 +593,18 @@ void DialogSeamAllowance::EnableSeamAllowance(bool enable) //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::NodeChanged(int index) { - ui->doubleSpinBoxSABefore->setDisabled(true); - ui->doubleSpinBoxSAAfter->setDisabled(true); + ui->plainTextEditFormulaWidthBefore->setDisabled(true); + ui->toolButtonExprBefore->setDisabled(true); ui->pushButtonDefBefore->setDisabled(true); + + ui->plainTextEditFormulaWidthAfter->setDisabled(true); + ui->toolButtonExprAfter->setDisabled(true); ui->pushButtonDefAfter->setDisabled(true); + ui->comboBoxAngle->setDisabled(true); - ui->doubleSpinBoxSABefore->blockSignals(true); - ui->doubleSpinBoxSAAfter->blockSignals(true); + ui->plainTextEditFormulaWidthBefore->blockSignals(true); + ui->plainTextEditFormulaWidthAfter->blockSignals(true); ui->comboBoxAngle->blockSignals(true); if (index != -1) @@ -603,32 +620,42 @@ void DialogSeamAllowance::NodeChanged(int index) { const VPieceNode &node = piece.GetPath().at(nodeIndex); - ui->doubleSpinBoxSABefore->setEnabled(true); - ui->doubleSpinBoxSAAfter->setEnabled(true); - ui->comboBoxAngle->setEnabled(true); + // Seam alowance before + ui->plainTextEditFormulaWidthBefore->setEnabled(true); + ui->toolButtonExprBefore->setEnabled(true); - qreal w1 = node.GetSABefore(); - if (w1 < 0) - { - w1 = piece.GetSAWidth(); - } - else + QString w1Formula = node.GetFormulaSABefore(); + if (w1Formula != currentSeamAllowance) { ui->pushButtonDefBefore->setEnabled(true); } - ui->doubleSpinBoxSABefore->setValue(w1); - - qreal w2 = node.GetSAAfter(); - if (w2 < 0) + if (w1Formula.length() > 80)// increase height if needed. { - w2 = piece.GetSAWidth(); + this->DeployWidthBeforeFormulaTextEdit(); } - else + w1Formula = qApp->TrVars()->FormulaToUser(w1Formula, qApp->Settings()->GetOsSeparator()); + ui->plainTextEditFormulaWidthBefore->setPlainText(w1Formula); + MoveCursorToEnd(ui->plainTextEditFormulaWidthBefore); + + // Seam alowance after + ui->plainTextEditFormulaWidthAfter->setEnabled(true); + ui->toolButtonExprAfter->setEnabled(true); + + QString w2Formula = node.GetFormulaSAAfter(); + if (w2Formula != currentSeamAllowance) { ui->pushButtonDefAfter->setEnabled(true); } - ui->doubleSpinBoxSAAfter->setValue(w2); + if (w2Formula.length() > 80)// increase height if needed. + { + this->DeployWidthAfterFormulaTextEdit(); + } + w2Formula = qApp->TrVars()->FormulaToUser(w2Formula, qApp->Settings()->GetOsSeparator()); + ui->plainTextEditFormulaWidthAfter->setPlainText(w2Formula); + MoveCursorToEnd(ui->plainTextEditFormulaWidthAfter); + // Angle type + ui->comboBoxAngle->setEnabled(true); const int index = ui->comboBoxAngle->findData(static_cast(node.GetAngleType())); if (index != -1) { @@ -638,13 +665,13 @@ void DialogSeamAllowance::NodeChanged(int index) } else { - ui->doubleSpinBoxSABefore->setValue(0); - ui->doubleSpinBoxSAAfter->setValue(0); + ui->plainTextEditFormulaWidthBefore->setPlainText(""); + ui->plainTextEditFormulaWidthAfter->setPlainText(""); ui->comboBoxAngle->setCurrentIndex(-1); } - ui->doubleSpinBoxSABefore->blockSignals(false); - ui->doubleSpinBoxSAAfter->blockSignals(false); + ui->plainTextEditFormulaWidthBefore->blockSignals(false); + ui->plainTextEditFormulaWidthAfter->blockSignals(false); ui->comboBoxAngle->blockSignals(false); } @@ -752,25 +779,13 @@ void DialogSeamAllowance::NodeAngleChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ReturnDefBefore() { - SetCurrentSABefore(-1); + ui->plainTextEditFormulaWidthBefore->setPlainText(currentSeamAllowance); } //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ReturnDefAfter() { - SetCurrentSAAfter(-1); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ChangedSABefore(double d) -{ - SetCurrentSABefore(d); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ChangedSAAfter(double d) -{ - SetCurrentSAAfter(d); + ui->plainTextEditFormulaWidthAfter->setPlainText(currentSeamAllowance); } //--------------------------------------------------------------------------------------------------------------------- @@ -1061,6 +1076,142 @@ void DialogSeamAllowance::ResetWarning() ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EvalWidth() +{ + labelEditFormula = ui->labelEditWidth; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidth->toPlainText(); + m_saWidth = Eval(formula, flagFormula, ui->labelResultWidth, postfix, true, true); + + if (m_saWidth >= 0) + { + VContainer *locData = const_cast (data); + locData->AddVariable(currentSeamAllowance, new VIncrement(locData, currentSeamAllowance, 0, m_saWidth, + QString().setNum(m_saWidth), true, + tr("Current seam allowance"))); + + EvalWidthBefore(); + EvalWidthAfter(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EvalWidthBefore() +{ + labelEditFormula = ui->labelEditBefore; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidthBefore->toPlainText(); + bool flagFormula = false; // fake flag + Eval(formula, flagFormula, ui->labelResultBefore, postfix, true, true); + + UpdateNodeSABefore(GetFormulaSAWidthBefore()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EvalWidthAfter() +{ + labelEditFormula = ui->labelEditAfter; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const QString formula = ui->plainTextEditFormulaWidthAfter->toPlainText(); + bool flagFormula = false; // fake flag + Eval(formula, flagFormula, ui->labelResultAfter, postfix, true, true); + + UpdateNodeSAAfter(GetFormulaSAWidthAfter()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::FXWidth() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width")); + dialog->SetFormula(GetFormulaSAWidth()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetFormulaSAWidth(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::FXWidthBefore() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width before")); + dialog->SetFormula(GetFormulaSAWidthBefore()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetCurrentSABefore(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::FXWidthAfter() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit seam allowance width after")); + dialog->SetFormula(GetFormulaSAWidthAfter()); + dialog->setCheckLessThanZero(true); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetCurrentSAAfter(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::WidthChanged() +{ + labelEditFormula = ui->labelEditWidth; + labelResultCalculation = ui->labelResultWidth; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidth, m_timerWidth, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::WidthBeforeChanged() +{ + labelEditFormula = ui->labelEditBefore; + labelResultCalculation = ui->labelResultBefore; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + bool flagFormula = false; + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::WidthAfterChanged() +{ + labelEditFormula = ui->labelEditAfter; + labelResultCalculation = ui->labelResultAfter; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + bool flagFormula = false; + ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployWidthFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseWidth); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployWidthBeforeFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidthBefore, ui->pushButtonGrowWidthBefore, m_formulaBaseWidthBefore); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployWidthAfterFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter); +} + //--------------------------------------------------------------------------------------------------------------------- VPiece DialogSeamAllowance::CreatePiece() const { @@ -1089,11 +1240,14 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.SetForbidFlipping(ui->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(ui->checkBoxSeams->isChecked()); - piece.SetSAWidth(ui->doubleSpinBoxSeams->value()); piece.SetName(ui->lineEditName->text()); piece.SetMx(m_mx); piece.SetMy(m_my); + QString width = ui->plainTextEditFormulaWidth->toPlainText(); + width.replace("\n", " "); + piece.SetFormulaSAWidth(width, m_saWidth); + piece.GetPatternPieceData().SetLetter(ui->lineEditLetter->text()); for (int i = 0; i < m_conMCP.count(); ++i) @@ -1306,7 +1460,21 @@ quint32 DialogSeamAllowance::GetLastId() const } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetCurrentSABefore(qreal value) +void DialogSeamAllowance::SetCurrentSABefore(const QString &formula) +{ + UpdateNodeSABefore(formula); + ListChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetCurrentSAAfter(const QString &formula) +{ + UpdateNodeSAAfter(formula); + ListChanged(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateNodeSABefore(const QString &formula) { const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) @@ -1321,16 +1489,14 @@ void DialogSeamAllowance::SetCurrentSABefore(qreal value) if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - rowNode.SetSABefore(value); + rowNode.SetFormulaSABefore(formula); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); - - ListChanged(); } } } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetCurrentSAAfter(qreal value) +void DialogSeamAllowance::UpdateNodeSAAfter(const QString &formula) { const int index = ui->comboBoxNodes->currentIndex(); if (index != -1) @@ -1345,10 +1511,8 @@ void DialogSeamAllowance::SetCurrentSAAfter(qreal value) if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); - rowNode.SetSAAfter(value); + rowNode.SetFormulaSAAfter(formula); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); - - ListChanged(); } } } @@ -1367,21 +1531,29 @@ void DialogSeamAllowance::InitMainPathTab() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitSeamAllowanceTab() { + plainTextEditFormula = ui->plainTextEditFormulaWidth; + this->m_formulaBaseWidth = ui->plainTextEditFormulaWidth->height(); + this->m_formulaBaseWidthBefore = ui->plainTextEditFormulaWidthBefore->height(); + this->m_formulaBaseWidthAfter = ui->plainTextEditFormulaWidthAfter->height(); + + ui->plainTextEditFormulaWidth->installEventFilter(this); + ui->plainTextEditFormulaWidthBefore->installEventFilter(this); + ui->plainTextEditFormulaWidthAfter->installEventFilter(this); + + m_timerWidth = new QTimer(this); + connect(m_timerWidth, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidth); + + m_timerWidthBefore = new QTimer(this); + connect(m_timerWidthBefore, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthBefore); + + m_timerWidthAfter = new QTimer(this); + connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthAfter); + connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); - const QString suffix = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit(), true); - ui->doubleSpinBoxSeams->setSuffix(suffix); - ui->doubleSpinBoxSABefore->setSuffix(suffix); - ui->doubleSpinBoxSAAfter->setSuffix(suffix); - - if(qApp->patternUnit() == Unit::Inch) - { - ui->doubleSpinBoxSeams->setDecimals(5); - ui->doubleSpinBoxSABefore->setDecimals(5); - ui->doubleSpinBoxSAAfter->setDecimals(5); - } // Default value for seam allowence is 1 cm. But pattern have different units, so just set 1 in dialog not enough. - ui->doubleSpinBoxSeams->setValue(UnitConvertor(1, Unit::Cm, qApp->patternUnit())); + m_saWidth = UnitConvertor(1, Unit::Cm, qApp->patternUnit()); + ui->plainTextEditFormulaWidth->setPlainText(qApp->LocaleToString(m_saWidth)); InitNodesList(); connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, @@ -1390,14 +1562,6 @@ void DialogSeamAllowance::InitSeamAllowanceTab() connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefBefore); connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefAfter); - connect(ui->doubleSpinBoxSeams, static_cast(&QDoubleSpinBox::valueChanged), - [this](){NodeChanged(ui->comboBoxNodes->currentIndex());}); - - connect(ui->doubleSpinBoxSABefore, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSeamAllowance::ChangedSABefore); - connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSeamAllowance::ChangedSAAfter); - InitNodeAngles(ui->comboBoxAngle); connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, &DialogSeamAllowance::NodeAngleChanged); @@ -1412,6 +1576,22 @@ void DialogSeamAllowance::InitSeamAllowanceTab() &DialogSeamAllowance::CSAEndPointChanged); connect(ui->comboBoxIncludeType, static_cast(&QComboBox::currentIndexChanged), this, &DialogSeamAllowance::CSAIncludeTypeChanged); + + connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidth); + connect(ui->toolButtonExprBefore, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthBefore); + connect(ui->toolButtonExprAfter, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthAfter); + + connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::WidthChanged); + connect(ui->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::WidthBeforeChanged); + connect(ui->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::WidthAfterChanged); + + connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogSeamAllowance::DeployWidthFormulaTextEdit); + connect(ui->pushButtonGrowWidthBefore, &QPushButton::clicked, + this, &DialogSeamAllowance::DeployWidthBeforeFormulaTextEdit); + connect(ui->pushButtonGrowWidthAfter, &QPushButton::clicked, this, + &DialogSeamAllowance::DeployWidthAfterFormulaTextEdit); } //--------------------------------------------------------------------------------------------------------------------- @@ -1513,6 +1693,49 @@ void DialogSeamAllowance::InitGrainlineTab() m_iLenBaseHeight = ui->lineEditLenFormula->height(); } +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSeamAllowance::GetFormulaSAWidth() const +{ + QString width = ui->plainTextEditFormulaWidth->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula) +{ + const QString width = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (width.length() > 80) + { + this->DeployWidthFormulaTextEdit(); + } + ui->plainTextEditFormulaWidth->setPlainText(width); + + VisToolPiece *path = qobject_cast(vis); + SCASSERT(path != nullptr) + const VPiece p = CreatePiece(); + path->SetPiece(p); + + MoveCursorToEnd(ui->plainTextEditFormulaWidth); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSeamAllowance::GetFormulaSAWidthBefore() const +{ + QString width = ui->plainTextEditFormulaWidthBefore->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSeamAllowance::GetFormulaSAWidthAfter() const +{ + QString width = ui->plainTextEditFormulaWidthAfter->toPlainText(); + width.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateCurrentCustomSARecord() { diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 4e7f659a8..ece3aff7a 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -53,6 +53,8 @@ public: VPiece GetPiece() const; void SetPiece(const VPiece &m_piece); + QString GetFormulaSAWidth() const; + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; @@ -84,8 +86,6 @@ private slots: void NodeAngleChanged(int index); void ReturnDefBefore(); void ReturnDefAfter(); - void ChangedSABefore(double d); - void ChangedSAAfter(double d); void CustomSAChanged(int row); void PathDialogClosed(int result); @@ -98,6 +98,22 @@ private slots: void DeployLength(); void ResetWarning(); + void EvalWidth(); + void EvalWidthBefore(); + void EvalWidthAfter(); + + void FXWidth(); + void FXWidthBefore(); + void FXWidthAfter(); + + void WidthChanged(); + void WidthBeforeChanged(); + void WidthAfterChanged(); + + void DeployWidthFormulaTextEdit(); + void DeployWidthBeforeFormulaTextEdit(); + void DeployWidthAfterFormulaTextEdit(); + private: Q_DISABLE_COPY(DialogSeamAllowance) @@ -119,6 +135,14 @@ private: VGrainlineGeometry m_oldGrainline; int m_iRotBaseHeight; int m_iLenBaseHeight; + int m_formulaBaseWidth; + int m_formulaBaseWidthBefore; + int m_formulaBaseWidthAfter; + + QTimer *m_timerWidth; + QTimer *m_timerWidthBefore; + QTimer *m_timerWidthAfter; + qreal m_saWidth; VPiece CreatePiece() const; @@ -137,8 +161,11 @@ private: quint32 GetLastId() const; - void SetCurrentSABefore(qreal value); - void SetCurrentSAAfter(qreal value); + void SetCurrentSABefore(const QString &formula); + void SetCurrentSAAfter(const QString &formula); + + void UpdateNodeSABefore(const QString &formula); + void UpdateNodeSAAfter(const QString &formula); void InitMainPathTab(); void InitSeamAllowanceTab(); @@ -148,6 +175,11 @@ private: void InitInternalPathsTab(); void InitPatternPieceDataTab(); void InitGrainlineTab(); + + void SetFormulaSAWidth(const QString &formula); + + QString GetFormulaSAWidthBefore() const; + QString GetFormulaSAWidthAfter() const; }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index ff18f4b2d..315098dc5 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -7,7 +7,7 @@ 0 0 521 - 493 + 611 @@ -21,7 +21,7 @@ - 4 + 1 @@ -94,7 +94,7 @@ Seam allowance - + @@ -119,50 +119,62 @@ false - - - 9 - + 0 - + - + 0 0 - - + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + Width: - - - - - 0 - 0 - - - - 900.990000000000009 - - - 0.100000000000000 - - - 1.000000000000000 - - - @@ -176,6 +188,119 @@ + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + @@ -183,42 +308,115 @@ Nodes - - - QFormLayout::ExpandingFieldsGrow + + + 0 - - - - Node: - - - - - - - - - - Seam allowance before node - - - Before: - - - - - + + - - - 900.990000000000009 + + + + 0 + 0 + - - 0.100000000000000 + + Node: + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Before: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -229,30 +427,186 @@ - - - - - - Seam allowance after node - - - After: - - - - - - - - - 900.990000000000009 + + + + Formula wizard - - 0.100000000000000 + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + After: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -263,17 +617,154 @@ + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + - - - - Angle: - - + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + - - + + + + + + Angle: + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -293,6 +784,12 @@ false + + 6 + + + 9 + 0 diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 7791854c6..b0d71b549 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -582,7 +582,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim return; } timer->setSingleShot(true); - timer->start(1000); + timer->start(300); } //--------------------------------------------------------------------------------------------------------------------- @@ -594,13 +594,11 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim * @param postfix unit name * @param checkZero true - if formula can't be equal zero */ -qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QString& postfix, bool checkZero) +qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QString& postfix, bool checkZero, + bool checkLessThanZero) { - qDebug() << "Eval started"; SCASSERT(label != nullptr) - qDebug() << "Label ok"; SCASSERT(labelEditFormula != nullptr) - qDebug() << "lef ok"; qreal result = INT_MIN;//Value can be 0, so use max imposible value @@ -640,6 +638,13 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt label->setText(tr("Error") + " (" + postfix + ")"); label->setToolTip(tr("Value can't be 0")); } + else if (checkLessThanZero && result < 0) + { + flag = false; + ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error") + " (" + postfix + ")"); + label->setToolTip(tr("Value can't be lass than 0")); + } else { label->setText(qApp->LocaleToString(result) + " " +postfix); diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index e437aaad3..460a28d18 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -231,7 +231,7 @@ protected: void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer, const QString &postfix = QString()); qreal Eval(const QString &text, bool &flag, QLabel *label, const QString &postfix, - bool checkZero = true); + bool checkZero = true, bool checkLessThanZero = false); void setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule = FillComboBox::NoChildren, diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index 4de01fb70..db85d3d0a 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -28,7 +28,6 @@ #include "vdrawtool.h" -#include #include #include #include @@ -41,10 +40,6 @@ #include "../ifc/ifcdef.h" #include "../ifc/xml/vdomdocument.h" #include "../ifc/xml/vabstractpattern.h" -#include "../ifc/exception/vexceptionundo.h" -#include "../vpatterndb/calculator.h" -#include "../../dialogs/support/dialogeditwrongformula.h" -#include "../../dialogs/support/dialogundo.h" #include "../../undocommands/addtocalc.h" #include "../../undocommands/savetooloptions.h" #include "../qmuparser/qmuparsererror.h" @@ -292,96 +287,6 @@ void VDrawTool::DetailsMode(bool mode) // Do nothing. } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CheckFormula check formula. - * - * Try calculate formula. If find error show dialog that allow user try fix formula. If user can't throw exception. In - * successes case return result calculation and fixed formula string. If formula ok don't touch formula. - * - * @param toolId [in] tool's id. - * @param formula [in|out] string with formula. - * @param data [in] container with variables. Need for math parser. - * @throw QmuParserError. - * @return result of calculation formula. - */ -qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContainer *data) -{ - SCASSERT(data != nullptr) - qreal result = 0; - try - { - QScopedPointer cal(new Calculator()); - result = cal->EvalFormula(data->PlainVariables(), formula); - - if (qIsInf(result) || qIsNaN(result)) - { - qDebug() << "Invalid the formula value"; - return 0; - } - } - catch (qmu::QmuParserError &e) - { - qDebug() << "\nMath parser error:\n" - << "--------------------------------------\n" - << "Message: " << e.GetMsg() << "\n" - << "Expression: " << e.GetExpr() << "\n" - << "--------------------------------------"; - - if (qApp->IsAppInGUIMode()) - { - QScopedPointer dialogUndo(new DialogUndo(qApp->getMainWindow())); - forever - { - if (dialogUndo->exec() == QDialog::Accepted) - { - const UndoButton resultUndo = dialogUndo->Result(); - if (resultUndo == UndoButton::Fix) - { - auto *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); - dialog->setWindowTitle(tr("Edit wrong formula")); - dialog->SetFormula(formula); - if (dialog->exec() == QDialog::Accepted) - { - formula = dialog->GetFormula(); - /* Need delete dialog here because parser in dialog don't allow use correct separator for - * parsing here. */ - delete dialog; - QScopedPointer cal1(new Calculator()); - result = cal1->EvalFormula(data->PlainVariables(), formula); - - if (qIsInf(result) || qIsNaN(result)) - { - qDebug() << "Invalid the formula value"; - return 0; - } - - break; - } - else - { - delete dialog; - } - } - else - { - throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula)); - } - } - else - { - throw; - } - } - } - else - { - throw; - } - } - return result; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToCalculation add tool to calculation tag in pattern file. diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index cbb1281aa..105e212e6 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -75,7 +75,6 @@ public: /** @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} virtual void DialogLinkDestroy(); - static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data); QString getLineType() const; virtual void SetTypeLine(const QString &value); diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 1198a0683..7cd873b5f 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -52,11 +52,13 @@ #include #include #include +#include #include "../vgeometry/vpointf.h" #include "../vpropertyexplorer/checkablemessagebox.h" #include "../vwidgets/vmaingraphicsview.h" #include "../ifc/exception/vexception.h" +#include "../ifc/exception/vexceptionundo.h" #include "../ifc/xml/vtoolrecord.h" #include "../undocommands/deltool.h" #include "../vgeometry/../ifc/ifcdef.h" @@ -71,8 +73,11 @@ #include "../vmisc/logging.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/calculator.h" #include "../vwidgets/vgraphicssimpletextitem.h" #include "nodeDetails/nodedetails.h" +#include "../dialogs/support/dialogundo.h" +#include "../dialogs/support/dialogeditwrongformula.h" class QGraphicsEllipseItem; class QGraphicsLineItem; @@ -152,6 +157,96 @@ VAbstractTool::~VAbstractTool() } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief CheckFormula check formula. + * + * Try calculate formula. If find error show dialog that allow user try fix formula. If user can't throw exception. In + * successes case return result calculation and fixed formula string. If formula ok don't touch formula. + * + * @param toolId [in] tool's id. + * @param formula [in|out] string with formula. + * @param data [in] container with variables. Need for math parser. + * @throw QmuParserError. + * @return result of calculation formula. + */ +qreal VAbstractTool::CheckFormula(const quint32 &toolId, QString &formula, VContainer *data) +{ + SCASSERT(data != nullptr) + qreal result = 0; + try + { + QScopedPointer cal(new Calculator()); + result = cal->EvalFormula(data->PlainVariables(), formula); + + if (qIsInf(result) || qIsNaN(result)) + { + qDebug() << "Invalid the formula value"; + return 0; + } + } + catch (qmu::QmuParserError &e) + { + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; + + if (qApp->IsAppInGUIMode()) + { + QScopedPointer dialogUndo(new DialogUndo(qApp->getMainWindow())); + forever + { + if (dialogUndo->exec() == QDialog::Accepted) + { + const UndoButton resultUndo = dialogUndo->Result(); + if (resultUndo == UndoButton::Fix) + { + auto *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); + dialog->setWindowTitle(tr("Edit wrong formula")); + dialog->SetFormula(formula); + if (dialog->exec() == QDialog::Accepted) + { + formula = dialog->GetFormula(); + /* Need delete dialog here because parser in dialog don't allow use correct separator for + * parsing here. */ + delete dialog; + QScopedPointer cal1(new Calculator()); + result = cal1->EvalFormula(data->PlainVariables(), formula); + + if (qIsInf(result) || qIsNaN(result)) + { + qDebug() << "Invalid the formula value"; + return 0; + } + + break; + } + else + { + delete dialog; + } + } + else + { + throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula)); + } + } + else + { + throw; + } + } + } + else + { + throw; + } + } + return result; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DeleteTool full delete object form scene and file. @@ -536,16 +631,14 @@ QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagNa } else { - const qreal w1 = node.GetSABefore(); - if (w1 >= 0) + if (node.GetFormulaSABefore() != currentSeamAllowance) { - doc->SetAttribute(nod, VAbstractPattern::AttrSABefore, w1); + doc->SetAttribute(nod, VAbstractPattern::AttrSABefore, node.GetFormulaSABefore()); } - const qreal w2 = node.GetSAAfter(); - if (w2 >= 0) + if (node.GetFormulaSAAfter() != currentSeamAllowance) { - doc->SetAttribute(nod, VAbstractPattern::AttrSAAfter, w2); + doc->SetAttribute(nod, VAbstractPattern::AttrSAAfter, node.GetFormulaSAAfter()); } } diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index 1b24d6d39..e4bec6a15 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -73,6 +73,8 @@ public: static const QString AttrInUse; + static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data); + static const QStringList StylesList(); static Qt::PenStyle LineStyleToPenStyle(const QString &typeLine); static QString PenStyleToLineStyle(Qt::PenStyle penStyle); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 9fcc89f9d..35382ced9 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -91,10 +91,11 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics DialogSeamAllowance *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); VPiece detail = dialogTool->GetPiece(); + QString width = detail.GetFormulaSAWidth(); qApp->getUndoStack()->beginMacro("add detail"); detail.GetPath().SetNodes(PrepareNodes(detail.GetPath(), scene, doc, data)); - VToolSeamAllowance *piece = Create(0, detail, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSeamAllowance *piece = Create(0, detail, width, scene, doc, data, Document::FullParse, Source::FromGui); if (piece != nullptr) { @@ -104,16 +105,24 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics } //--------------------------------------------------------------------------------------------------------------------- -VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, const VPiece &newPiece, VMainGraphicsScene *scene, +VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation, const QString &drawName) { if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { + data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, newPiece.GetSAWidth(), + width, true, tr("Current seam allowance"))); id = data->AddPiece(newPiece); } else { + const qreal calcWidth = CheckFormula(id, width, data); + newPiece.SetFormulaSAWidth(width, calcWidth); + + data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, calcWidth, + width, true, tr("Current seam allowance"))); + data->UpdatePiece(id, newPiece); if (parse != Document::FullParse) { @@ -121,19 +130,20 @@ VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, const VPiece &newPiec } } VAbstractTool::AddRecord(id, Tool::Piece, doc); + VToolSeamAllowance *piece = nullptr; if (parse == Document::FullParse) { - VToolSeamAllowance *piece = new VToolSeamAllowance(doc, data, id, typeCreation, scene, drawName); + piece = new VToolSeamAllowance(doc, data, id, typeCreation, scene, drawName); scene->addItem(piece); connect(piece, &VToolSeamAllowance::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover); connect(scene, &VMainGraphicsScene::EnableDetailItemSelection, piece, &VToolSeamAllowance::AllowSelecting); connect(scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight); doc->AddTool(id, piece); - - return piece; } - return nullptr; + //Very important to delete it. Only this tool need this special variable. + data->RemoveVariable(currentLength); + return piece; } //--------------------------------------------------------------------------------------------------------------------- @@ -163,7 +173,7 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl doc->SetAttribute(domElement, AttrInLayout, piece.IsInLayout()); doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping()); doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance()); - doc->SetAttribute(domElement, AttrWidth, piece.GetSAWidth()); + doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth()); doc->SetAttribute(domElement, AttrUnited, piece.IsUnited()); } diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index f3f0f8111..742b42979 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -51,7 +51,7 @@ public: static VToolSeamAllowance* Create(DialogTool *m_dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolSeamAllowance* Create(quint32 id, const VPiece &newPiece, VMainGraphicsScene *scene, + static VToolSeamAllowance* Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation, const QString &m_drawName = QString()); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index b5768ab8c..f3b116ad6 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -1182,11 +1182,12 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q CreateUnitedInternalPaths(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); newDetail.SetName(QObject::tr("United detail")); - newDetail.SetSAWidth(d1.GetSAWidth()); + QString formulaSAWidth = d1.GetFormulaSAWidth(); + newDetail.SetFormulaSAWidth(formulaSAWidth, d1.GetSAWidth()); newDetail.SetMx(d1.GetMx()); newDetail.SetMy(d1.GetMy()); - VToolSeamAllowance::Create(0, newDetail, initData.scene, initData.doc, initData.data, initData.parse, - Source::FromTool, drawName); + VToolSeamAllowance::Create(0, newDetail, formulaSAWidth, initData.scene, initData.doc, initData.data, + initData.parse, Source::FromTool, drawName); auto RemoveDetail = [initData](quint32 id) {