From 386760ff3f5f2d90c50e0fef9e323b9dda24edb8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 2 Jan 2023 11:32:21 +0200 Subject: [PATCH] New placeholders CurrentArea and CurrentSeamLineArea. #193 --- src/libs/vlayout/vtextmanager.cpp | 39 ++++++++++- src/libs/vmisc/literals.cpp | 66 ++++++++++--------- src/libs/vmisc/literals.h | 2 + .../floatItemData/vpiecelabeldata.cpp | 12 ++++ .../floatItemData/vpiecelabeldata.h | 3 + .../floatItemData/vpiecelabeldata_p.h | 48 ++++---------- src/libs/vpatterndb/variables/vpiecearea.cpp | 26 +++++--- src/libs/vpatterndb/variables/vpiecearea.h | 2 + src/libs/vpatterndb/vpiece.cpp | 2 + .../dialogs/support/dialogeditlabel.cpp | 35 ++++++++++ 10 files changed, 157 insertions(+), 78 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 61ddf47be..6c542bcd4 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -278,6 +278,9 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) -> VContainer completeData = doc->GetCompleteData(); completeData.FillPiecesAreas(VAbstractValApplication::VApp()->patternUnits()); + placeholders.insert(pl_currentArea, QString()); + placeholders.insert(pl_currentSeamLineArea, QString()); + for (int i=0; i < measurements.size(); ++i) { const VFinalMeasurement &m = measurements.at(i); @@ -319,7 +322,8 @@ auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) -> } //--------------------------------------------------------------------------------------------------------------------- -void InitPiecePlaceholders(QMap &placeholders, const QString &name, const VPieceLabelData& data) +void InitPiecePlaceholders(QMap &placeholders, const QString &name, const VPieceLabelData& data, + const VContainer *pattern) { placeholders[pl_pLetter] = data.GetLetter(); placeholders[pl_pAnnotation] = data.GetAnnotation(); @@ -334,6 +338,37 @@ void InitPiecePlaceholders(QMap &placeholders, const QString & { placeholders[pl_wOnFold] = QObject::tr("on fold"); } + + VContainer completeData = *pattern; + completeData.FillPiecesAreas(VAbstractValApplication::VApp()->patternUnits()); + + QScopedPointer cal(new Calculator()); + + try + { + const QString formula = pieceArea_ + data.GetAreaShartName(); + const qreal result = cal->EvalFormula(completeData.DataVariables(), formula); + placeholders[pl_currentArea] = QString::number(result); + } + catch (qmu::QmuParserError &e) + { + const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg()); + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + + try + { + const QString formula = pieceSeamLineArea_ + data.GetAreaShartName(); + const qreal result = cal->EvalFormula(completeData.DataVariables(), formula); + placeholders[pl_currentSeamLineArea] = QString::number(result); + } + catch (qmu::QmuParserError &e) + { + const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg()); + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -592,7 +627,7 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data, co QMap placeholders = PreparePlaceholders(VAbstractValApplication::VApp()->getCurrentDocument(), pattern); - InitPiecePlaceholders(placeholders, qsName, data); + InitPiecePlaceholders(placeholders, qsName, data, pattern); QVector lines = data.GetLabelTemplate(); diff --git a/src/libs/vmisc/literals.cpp b/src/libs/vmisc/literals.cpp index ab9f672c6..66fe758f9 100644 --- a/src/libs/vmisc/literals.cpp +++ b/src/libs/vmisc/literals.cpp @@ -122,38 +122,40 @@ const QString pl_dimensionYLabel = QStringLiteral("dimensionYLabel"); const QString pl_dimensionWLabel = QStringLiteral("dimensionWLabel"); const QString pl_dimensionZLabel = QStringLiteral("dimensionZLabel"); -const QString pl_date = QStringLiteral("date"); -const QString pl_time = QStringLiteral("time"); -const QString pl_birthDate = QStringLiteral("birthDate"); -const QString pl_patternName = QStringLiteral("patternName"); -const QString pl_patternNumber = QStringLiteral("patternNumber"); -const QString pl_author = QStringLiteral("author"); -const QString pl_customer = QStringLiteral("customer"); -const QString pl_email = QStringLiteral("email"); -const QString pl_userMaterial = QStringLiteral("userMaterial"); -const QString pl_pExt = QStringLiteral("pExt"); -const QString pl_pUnits = QStringLiteral("pUnits"); -const QString pl_pFileName = QStringLiteral("pFileName"); -const QString pl_mFileName = QStringLiteral("mFileName"); -const QString pl_mExt = QStringLiteral("mExt"); -const QString pl_mUnits = QStringLiteral("mUnits"); -const QString pl_mSizeUnits = QStringLiteral("mSizeUnits"); -const QString pl_pLetter = QStringLiteral("pLetter"); -const QString pl_pAnnotation = QStringLiteral("pAnnotation"); -const QString pl_pOrientation = QStringLiteral("pOrientation"); -const QString pl_pRotation = QStringLiteral("pRotation"); -const QString pl_pTilt = QStringLiteral("pTilt"); -const QString pl_pFoldPosition = QStringLiteral("pFoldPosition"); -const QString pl_pName = QStringLiteral("pName"); -const QString pl_pQuantity = QStringLiteral("pQuantity"); -const QString pl_mFabric = QStringLiteral("mFabric"); -const QString pl_mLining = QStringLiteral("mLining"); -const QString pl_mInterfacing = QStringLiteral("mInterfacing"); -const QString pl_mInterlining = QStringLiteral("mInterlining"); -const QString pl_wCut = QStringLiteral("wCut"); -const QString pl_wOnFold = QStringLiteral("wOnFold"); -const QString pl_measurement = QStringLiteral("measurement_"); -const QString pl_finalMeasurement = QStringLiteral("finalMeasurement_"); +const QString pl_date = QStringLiteral("date"); +const QString pl_time = QStringLiteral("time"); +const QString pl_birthDate = QStringLiteral("birthDate"); +const QString pl_patternName = QStringLiteral("patternName"); +const QString pl_patternNumber = QStringLiteral("patternNumber"); +const QString pl_author = QStringLiteral("author"); +const QString pl_customer = QStringLiteral("customer"); +const QString pl_email = QStringLiteral("email"); +const QString pl_userMaterial = QStringLiteral("userMaterial"); +const QString pl_pExt = QStringLiteral("pExt"); +const QString pl_pUnits = QStringLiteral("pUnits"); +const QString pl_pFileName = QStringLiteral("pFileName"); +const QString pl_mFileName = QStringLiteral("mFileName"); +const QString pl_mExt = QStringLiteral("mExt"); +const QString pl_mUnits = QStringLiteral("mUnits"); +const QString pl_mSizeUnits = QStringLiteral("mSizeUnits"); +const QString pl_pLetter = QStringLiteral("pLetter"); +const QString pl_pAnnotation = QStringLiteral("pAnnotation"); +const QString pl_pOrientation = QStringLiteral("pOrientation"); +const QString pl_pRotation = QStringLiteral("pRotation"); +const QString pl_pTilt = QStringLiteral("pTilt"); +const QString pl_pFoldPosition = QStringLiteral("pFoldPosition"); +const QString pl_pName = QStringLiteral("pName"); +const QString pl_pQuantity = QStringLiteral("pQuantity"); +const QString pl_mFabric = QStringLiteral("mFabric"); +const QString pl_mLining = QStringLiteral("mLining"); +const QString pl_mInterfacing = QStringLiteral("mInterfacing"); +const QString pl_mInterlining = QStringLiteral("mInterlining"); +const QString pl_wCut = QStringLiteral("wCut"); +const QString pl_wOnFold = QStringLiteral("wOnFold"); +const QString pl_measurement = QStringLiteral("measurement_"); +const QString pl_finalMeasurement = QStringLiteral("finalMeasurement_"); +const QString pl_currentArea = QStringLiteral("currentArea"); +const QString pl_currentSeamLineArea = QStringLiteral("currentSeamLineArea"); const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); diff --git a/src/libs/vmisc/literals.h b/src/libs/vmisc/literals.h index 008e28d01..c7a359db6 100644 --- a/src/libs/vmisc/literals.h +++ b/src/libs/vmisc/literals.h @@ -137,6 +137,8 @@ extern const QString pl_wCut; extern const QString pl_wOnFold; extern const QString pl_measurement; extern const QString pl_finalMeasurement; +extern const QString pl_currentArea; +extern const QString pl_currentSeamLineArea; extern const QString cursorArrowOpenHand; extern const QString cursorArrowCloseHand; diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp index b1279e8d2..2a40d2487 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.cpp @@ -177,6 +177,18 @@ void VPieceLabelData::SetOnFold(bool onFold) d->m_onFold = onFold; } +//--------------------------------------------------------------------------------------------------------------------- +QString VPieceLabelData::GetAreaShartName() const +{ + return d->m_areaShortName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceLabelData::SetAreaShartName(const QString &val) +{ + d->m_areaShortName = val; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPieceLabelData::GetLabelTemplate() const { diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h index 5e2243d59..7da6ae2fd 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata.h @@ -82,6 +82,9 @@ public: bool IsOnFold() const; void SetOnFold(bool onFold); + QString GetAreaShartName() const; + void SetAreaShartName(const QString &val); + QVector GetLabelTemplate() const; void SetLabelTemplate(const QVector &lines); diff --git a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h index d70224b13..bbd56c799 100644 --- a/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h +++ b/src/libs/vpatterndb/floatItemData/vpiecelabeldata_p.h @@ -43,48 +43,26 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") class VPieceLabelDataPrivate : public QSharedData { public: - VPieceLabelDataPrivate() - : m_qsLetter(), - m_annotation(), - m_orientation(), - m_rotationWay(), - m_tilt(), - m_foldPosition(), - m_quantity(1), - m_onFold(false), - m_lines() - {} - - VPieceLabelDataPrivate(const VPieceLabelDataPrivate &data) - : QSharedData(data), - m_qsLetter(data.m_qsLetter), - m_annotation(data.m_annotation), - m_orientation(data.m_orientation), - m_rotationWay(data.m_rotationWay), - m_tilt(data.m_tilt), - m_foldPosition(data.m_foldPosition), - m_quantity(data.m_quantity), - m_onFold(data.m_onFold), - m_lines(data.m_lines) - {} - + VPieceLabelDataPrivate() = default; + VPieceLabelDataPrivate(const VPieceLabelDataPrivate &data) = default; ~VPieceLabelDataPrivate() = default; /** @brief m_qsLetter Detail letter (should be no more than 3 characters) */ - QString m_qsLetter; - QString m_annotation; - QString m_orientation; - QString m_rotationWay; - QString m_tilt; - QString m_foldPosition; + QString m_qsLetter{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_annotation{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_orientation{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_rotationWay{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_tilt{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_foldPosition{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_areaShortName{}; // NOLINT(misc-non-private-member-variables-in-classes) - quint16 m_quantity; - bool m_onFold; + quint16 m_quantity{1}; // NOLINT(misc-non-private-member-variables-in-classes) + bool m_onFold{false}; // NOLINT(misc-non-private-member-variables-in-classes) - QVector m_lines; + QVector m_lines{}; // NOLINT(misc-non-private-member-variables-in-classes) private: - Q_DISABLE_ASSIGN(VPieceLabelDataPrivate) + Q_DISABLE_ASSIGN_MOVE(VPieceLabelDataPrivate) // NOLINT }; QT_WARNING_POP diff --git a/src/libs/vpatterndb/variables/vpiecearea.cpp b/src/libs/vpatterndb/variables/vpiecearea.cpp index 3806c9204..e55c02414 100644 --- a/src/libs/vpatterndb/variables/vpiecearea.cpp +++ b/src/libs/vpatterndb/variables/vpiecearea.cpp @@ -46,15 +46,7 @@ VPieceArea::VPieceArea(PieceAreaType type, quint32 pieceId, const VPiece &piece, // cppcheck-suppress unknownMacro SCASSERT(data != nullptr) - QString shortName = piece.GetShortName(); - if (shortName.isEmpty()) - { - shortName = piece.GetName().replace(QChar(QChar::Space), '_').left(25); - if (shortName.isEmpty() || not QRegularExpression(VPiece::ShortNameRegExp()).match(shortName).hasMatch()) - { - shortName = QObject::tr("Unknown", "piece area"); - } - } + QString shortName = PieceShortName(piece); if (type == PieceAreaType::External) { @@ -116,3 +108,19 @@ auto VPieceArea::GetPieceId() const -> quint32 { return d->m_pieceId; } + +//--------------------------------------------------------------------------------------------------------------------- +auto VPieceArea::PieceShortName(const VPiece &piece) -> QString +{ + QString shortName = piece.GetShortName(); + if (shortName.isEmpty()) + { + shortName = piece.GetName().replace(QChar(QChar::Space), '_').left(25); + if (shortName.isEmpty() || not QRegularExpression(VPiece::ShortNameRegExp()).match(shortName).hasMatch()) + { + shortName = QObject::tr("Unknown", "piece area"); + } + } + + return shortName; +} diff --git a/src/libs/vpatterndb/variables/vpiecearea.h b/src/libs/vpatterndb/variables/vpiecearea.h index 83f05e331..481a5ae2b 100644 --- a/src/libs/vpatterndb/variables/vpiecearea.h +++ b/src/libs/vpatterndb/variables/vpiecearea.h @@ -53,6 +53,8 @@ public: void SetValue(quint32 pieceId, const VPiece &piece, const VContainer *data, Unit unit); auto GetPieceId() const -> quint32; + + static auto PieceShortName(const VPiece &piece) -> QString; private: QSharedDataPointer d; }; diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index f6222683d..3dc8bdd28 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -41,6 +41,7 @@ #include "../vmisc/testpath.h" #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/variables/vpiecearea.h" #include #include @@ -572,6 +573,7 @@ QVector VPiece::MissingPlaceLabels(const VPiece &det) const void VPiece::SetPatternPieceData(const VPieceLabelData &data) { d->m_ppData = data; + d->m_ppData.SetAreaShartName(VPieceArea::PieceShortName(*this)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 1fc9e4e7f..f044b17ef 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -41,6 +41,7 @@ #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/variables/vmeasurement.h" +#include "../vpatterndb/variables/vpiecearea.h" #include "../tools/dialogtool.h" #include @@ -625,6 +626,9 @@ void DialogEditLabel::InitPlaceholders() VContainer completeData = m_doc->GetCompleteData(); completeData.FillPiecesAreas(VAbstractValApplication::VApp()->patternUnits()); + m_placeholders.insert(pl_currentArea, qMakePair(tr("Piece full area"), QString())); + m_placeholders.insert(pl_currentSeamLineArea, qMakePair(tr("Piece seam line area"), QString())); + for (int i=0; i < measurements.size(); ++i) { const VFinalMeasurement &m = measurements.at(i); @@ -770,6 +774,37 @@ void DialogEditLabel::SetPiece(const VPiece &piece) { m_placeholders[pl_wOnFold].second = tr("on fold"); } + + VContainer completeData = m_doc->GetCompleteData(); + completeData.FillPiecesAreas(VAbstractValApplication::VApp()->patternUnits()); + + QScopedPointer cal(new Calculator()); + + try + { + const QString formula = pieceArea_ + VPieceArea::PieceShortName(piece); + const qreal result = cal->EvalFormula(completeData.DataVariables(), formula); + m_placeholders[pl_currentArea].second = QString::number(result); + } + catch (qmu::QmuParserError &e) + { + const QString errorMsg = QObject::tr("Failed to prepare full piece area placeholder. %2.").arg(e.GetMsg()); + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + + try + { + const QString formula = pieceSeamLineArea_ + VPieceArea::PieceShortName(piece); + const qreal result = cal->EvalFormula(completeData.DataVariables(), formula); + m_placeholders[pl_currentSeamLineArea].second = QString::number(result); + } + catch (qmu::QmuParserError &e) + { + const QString errorMsg = QObject::tr("Failed to prepare piece seam line area placeholder. %2.").arg(e.GetMsg()); + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } } //---------------------------------------------------------------------------------------------------------------------