diff --git a/ChangeLog.txt b/ChangeLog.txt index 7a63ca82d..6bbe4128b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -35,6 +35,7 @@ - [#779] Add more roll paper size templates. - [#783] Flipping control. - [#790] Generate unique name for each detail. +- [#792] New feature. Visibility trigger for internal path. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 4f84a73f6..6c000c945 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3644,6 +3644,11 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme initData.path.SetPenType(LineStyleToPenStyle(GetParametrString(domElement, AttrTypeLine, TypeLineLine))); initData.path.SetCutPath(GetParametrBool(domElement, AttrCut, falseStr)); + if (initData.path.GetType() == PiecePathType::InternalPath) + { + initData.path.SetVisibilityTrigger(GetParametrString(domElement, AttrVisible, "1")); + } + VToolPiecePath::Create(initData); } catch (const VExceptionBadId &e) diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index b4f294443..ba0f1a16f 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -46,6 +46,7 @@ schema/pattern/v0.7.2.xsd schema/pattern/v0.7.3.xsd schema/pattern/v0.7.4.xsd + schema/pattern/v0.7.5.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.7.5.xsd b/src/libs/ifc/schema/pattern/v0.7.5.xsd new file mode 100644 index 000000000..93d1457dc --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.7.5.xsd @@ -0,0 +1,1047 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 80a11d4d7..fc7b2d815 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.4"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.4.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.7.5"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.7.5.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -220,7 +220,8 @@ QString VPatternConverter::XSDSchema(int ver) const std::make_pair(0x000701, QStringLiteral("://schema/pattern/v0.7.1.xsd")), std::make_pair(0x000702, QStringLiteral("://schema/pattern/v0.7.2.xsd")), std::make_pair(0x000703, QStringLiteral("://schema/pattern/v0.7.3.xsd")), - std::make_pair(0x000704, CurrentSchema) + std::make_pair(0x000704, QStringLiteral("://schema/pattern/v0.7.4.xsd")), + std::make_pair(0x000705, CurrentSchema) }; if (schemas.contains(ver)) @@ -419,6 +420,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000704), m_convertedFileName); V_FALLTHROUGH case (0x000704): + ToV0_7_5(); + ValidateXML(XSDSchema(0x000705), m_convertedFileName); + V_FALLTHROUGH + case (0x000705): break; default: InvalidVersion(m_ver); @@ -436,7 +441,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 4), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 7, 5), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -950,6 +955,16 @@ void VPatternConverter::ToV0_7_4() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_7_5() +{ + // TODO. Delete if minimal supported version is 0.7.5 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 5), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.7.5")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index bc123b11f..38b72a427 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 4); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 7, 5); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -117,6 +117,7 @@ private: void ToV0_7_2(); void ToV0_7_3(); void ToV0_7_4(); + void ToV0_7_5(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 1756552b2..2b5416ed6 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -31,6 +31,7 @@ #include "vcontainer.h" #include "../vgeometry/vpointf.h" #include "../vlayout/vabstractpiece.h" +#include "calculator.h" #include @@ -249,6 +250,18 @@ void VPiecePath::SetCutPath(bool cut) d->m_cut = cut; } +//--------------------------------------------------------------------------------------------------------------------- +QString VPiecePath::GetVisibilityTrigger() const +{ + return d->m_visibilityTrigger; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiecePath::SetVisibilityTrigger(const QString &formula) +{ + d->m_visibilityTrigger = formula; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiecePath::PathPoints(const VContainer *data) const { @@ -780,6 +793,39 @@ QPointF VPiecePath::NodeNextPoint(const VContainer *data, int i) const return point; } +//--------------------------------------------------------------------------------------------------------------------- +bool VPiecePath::IsVisible(const QHash> *vars) const +{ + SCASSERT(vars != nullptr) + bool visible = true; + try + { + QString formula = GetVisibilityTrigger(); + // Replace line return character with spaces for calc if exist + formula.replace("\n", " "); + qDebug() << "Formula: " << formula; + QScopedPointer cal(new Calculator()); + const qreal result = cal->EvalFormula(vars, formula); + qDebug() << "Result: " << result; + + if (qIsInf(result) || qIsNaN(result)) + { + qWarning() << QObject::tr("Visibility trigger contains error and will be ignored"); + } + + if (qFuzzyIsNull(result)) + { + visible = false; + } + } + catch (qmu::QmuParserError &e) + { + qDebug() << "Parser error: " << e.GetMsg(); + qWarning() << QObject::tr("Visibility trigger contains error and will be ignored"); + } + return visible; +} + //--------------------------------------------------------------------------------------------------------------------- int VPiecePath::indexOfNode(const QVector &nodes, quint32 id) { diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index adaecb980..04fbb9b6e 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -41,6 +41,7 @@ class VContainer; class QPainterPath; class VPointF; class VPieceNode; +class VInternalVariable; class VPiecePath { @@ -81,6 +82,9 @@ public: bool IsCutPath() const; void SetCutPath(bool cut); + QString GetVisibilityTrigger() const; + void SetVisibilityTrigger(const QString &formula); + QVector PathPoints(const VContainer *data) const; QVector PathNodePoints(const VContainer *data, bool showExcluded = true) const; QVector SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const; @@ -106,6 +110,8 @@ public: QPointF NodePreviousPoint(const VContainer *data, int i) const; QPointF NodeNextPoint(const VContainer *data, int i) const; + bool IsVisible(const QHash > *vars) const; + static int indexOfNode(const QVector &nodes, quint32 id); static int FindInLoopNotExcludedUp(int start, const QVector &nodes); diff --git a/src/libs/vpatterndb/vpiecepath_p.h b/src/libs/vpatterndb/vpiecepath_p.h index 463e9c0a4..fe705ed09 100644 --- a/src/libs/vpatterndb/vpiecepath_p.h +++ b/src/libs/vpatterndb/vpiecepath_p.h @@ -47,7 +47,8 @@ public: m_type(PiecePathType::Unknown), m_name(), m_penType(Qt::SolidLine), - m_cut(false) + m_cut(false), + m_visibilityTrigger("1") {} explicit VPiecePathData(PiecePathType type) @@ -55,7 +56,8 @@ public: m_type(type), m_name(), m_penType(Qt::SolidLine), - m_cut(false) + m_cut(false), + m_visibilityTrigger("1") {} VPiecePathData(const VPiecePathData &path) @@ -64,7 +66,8 @@ public: m_type(path.m_type), m_name(path.m_name), m_penType(path.m_penType), - m_cut(path.m_cut) + m_cut(path.m_cut), + m_visibilityTrigger(path.m_visibilityTrigger) {} ~VPiecePathData(); @@ -74,6 +77,7 @@ public: QString m_name; Qt::PenStyle m_penType; bool m_cut; + QString m_visibilityTrigger; private: VPiecePathData &operator=(const VPiecePathData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index f559413d6..c82bf94c9 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -43,12 +43,17 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget ui(new Ui::DialogPiecePath), m_showMode(false), m_saWidth(0), - m_timerWidth(nullptr), - m_timerWidthBefore(nullptr), - m_timerWidthAfter(nullptr), + m_timerWidth(new QTimer(this)), + m_timerWidthBefore(new QTimer(this)), + m_timerWidthAfter(new QTimer(this)), + m_timerVisible(new QTimer(this)), m_formulaBaseWidth(0), m_formulaBaseWidthBefore(0), - m_formulaBaseWidthAfter(0) + m_formulaBaseWidthAfter(0), + m_formulaBaseVisible(0), + m_flagFormulaBefore(true), + m_flagFormulaAfter(true), + m_flagFormulaVisible(true) { ui->setupUi(this); InitOkCancel(ui); @@ -56,6 +61,9 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget InitPathTab(); InitSeamAllowanceTab(); InitPassmarksTab(); + InitControlTab(); + + EvalVisible(); flagName = true;//We have default name of piece. flagError = PathIsValid(); @@ -189,7 +197,37 @@ void DialogPiecePath::ShowDialog(bool click) void DialogPiecePath::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError); + if (GetType() != PiecePathType::InternalPath) + {// Works only for internal paths + m_flagFormulaVisible = true; + } + + bOk->setEnabled(flagName && flagError && flagFormula && m_flagFormulaBefore && m_flagFormulaAfter + && m_flagFormulaVisible); + + const int tabSeamAllowanceIndex = ui->tabWidget->indexOf(ui->tabSeamAllowance); + if (flagFormula && m_flagFormulaBefore && m_flagFormulaAfter) + { + ui->tabWidget->setTabIcon(tabSeamAllowanceIndex, QIcon()); + } + else + { + const QIcon icon = QIcon::fromTheme("dialog-warning", + QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png")); + ui->tabWidget->setTabIcon(tabSeamAllowanceIndex, icon); + } + + const int tabControlIndex = ui->tabWidget->indexOf(ui->tabControl); + if (m_flagFormulaVisible) + { + ui->tabWidget->setTabIcon(tabControlIndex, QIcon()); + } + else + { + const QIcon icon = QIcon::fromTheme("dialog-warning", + QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png")); + ui->tabWidget->setTabIcon(tabControlIndex, icon); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -213,6 +251,7 @@ void DialogPiecePath::closeEvent(QCloseEvent *event) ui->plainTextEditFormulaWidth->blockSignals(true); ui->plainTextEditFormulaWidthBefore->blockSignals(true); ui->plainTextEditFormulaWidthAfter->blockSignals(true); + ui->plainTextEditFormulaVisible->blockSignals(true); DialogTool::closeEvent(event); } @@ -594,8 +633,7 @@ void DialogPiecePath::EvalWidthBefore() labelEditFormula = ui->labelEditBefore; const QString postfix = UnitsToStr(qApp->patternUnit(), true); QString formula = ui->plainTextEditFormulaWidthBefore->toPlainText(); - bool flagFormula = false; // fake flag - Eval(formula, flagFormula, ui->labelResultBefore, postfix, false, true); + Eval(formula, m_flagFormulaBefore, ui->labelResultBefore, postfix, false, true); formula = GetFormulaSAWidthBefore(); if (formula != currentSeamAllowance) @@ -612,8 +650,7 @@ void DialogPiecePath::EvalWidthAfter() labelEditFormula = ui->labelEditAfter; const QString postfix = UnitsToStr(qApp->patternUnit(), true); QString formula = ui->plainTextEditFormulaWidthAfter->toPlainText(); - bool flagFormula = false; // fake flag - Eval(formula, flagFormula, ui->labelResultAfter, postfix, false, true); + Eval(formula, m_flagFormulaAfter, ui->labelResultAfter, postfix, false, true); formula = GetFormulaSAWidthAfter(); if (formula != currentSeamAllowance) @@ -624,10 +661,18 @@ void DialogPiecePath::EvalWidthAfter() UpdateNodeSAAfter(formula); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::EvalVisible() +{ + labelEditFormula = ui->labelEditVisible; + QString formula = ui->plainTextEditFormulaVisible->toPlainText(); + Eval(formula, m_flagFormulaVisible, ui->labelResultVisible, "", false, true); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::FXWidth() { - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit seam allowance width")); dialog->SetFormula(GetFormulaSAWidth()); dialog->setCheckLessThanZero(true); @@ -636,13 +681,12 @@ void DialogPiecePath::FXWidth() { SetFormulaSAWidth(dialog->GetFormula()); } - delete dialog; } //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::FXWidthBefore() { - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit seam allowance width before")); dialog->SetFormula(GetFormulaSAWidthBefore()); dialog->setCheckLessThanZero(true); @@ -651,13 +695,12 @@ void DialogPiecePath::FXWidthBefore() { SetCurrentSABefore(dialog->GetFormula()); } - delete dialog; } //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::FXWidthAfter() { - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); dialog->setWindowTitle(tr("Edit seam allowance width after")); dialog->SetFormula(GetFormulaSAWidthAfter()); dialog->setCheckLessThanZero(true); @@ -666,7 +709,18 @@ void DialogPiecePath::FXWidthAfter() { SetCurrentSAAfter(dialog->GetFormula()); } - delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::FXVisible() +{ + QScopedPointer dialog(new DialogEditWrongFormula(data, toolId, this)); + dialog->setWindowTitle(tr("Control visibility")); + dialog->SetFormula(GetFormulaVisible()); + if (dialog->exec() == QDialog::Accepted) + { + SetFormulaVisible(dialog->GetFormula()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -684,8 +738,7 @@ void DialogPiecePath::WidthBeforeChanged() labelEditFormula = ui->labelEditBefore; labelResultCalculation = ui->labelResultBefore; const QString postfix = UnitsToStr(qApp->patternUnit(), true); - bool flagFormula = false; - ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix); + ValFormulaChanged(m_flagFormulaBefore, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix); } //--------------------------------------------------------------------------------------------------------------------- @@ -694,8 +747,15 @@ void DialogPiecePath::WidthAfterChanged() labelEditFormula = ui->labelEditAfter; labelResultCalculation = ui->labelResultAfter; const QString postfix = UnitsToStr(qApp->patternUnit(), true); - bool flagFormula = false; - ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix); + ValFormulaChanged(m_flagFormulaAfter, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::VisibleChanged() +{ + labelEditFormula = ui->labelEditVisible; + labelResultCalculation = ui->labelResultVisible; + ValFormulaChanged(m_flagFormulaVisible, ui->plainTextEditFormulaVisible, m_timerVisible, ""); } //--------------------------------------------------------------------------------------------------------------------- @@ -716,6 +776,12 @@ void DialogPiecePath::DeployWidthAfterFormulaTextEdit() DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::DeployVisibleFormulaTextEdit() +{ + DeployFormula(ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitPathTab() { @@ -731,6 +797,7 @@ void DialogPiecePath::InitPathTab() { ui->comboBoxPenType->setEnabled(GetType() == PiecePathType::InternalPath); ui->checkBoxCut->setEnabled(GetType() == PiecePathType::InternalPath); + ui->tabControl->setEnabled(GetType() == PiecePathType::InternalPath); ValidObjects(PathIsValid()); }); @@ -750,13 +817,8 @@ void DialogPiecePath::InitSeamAllowanceTab() 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. @@ -804,6 +866,20 @@ void DialogPiecePath::InitPassmarksTab() this, &DialogPiecePath::PassmarkAngleTypeChanged); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitControlTab() +{ + this->m_formulaBaseVisible = ui->plainTextEditFormulaVisible->height(); + + ui->plainTextEditFormulaVisible->installEventFilter(this); + + connect(m_timerVisible, &QTimer::timeout, this, &DialogPiecePath::EvalVisible); + connect(ui->toolButtonExprVisible, &QPushButton::clicked, this, &DialogPiecePath::FXVisible); + connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, &DialogPiecePath::VisibleChanged); + connect(ui->pushButtonGrowVisible, &QPushButton::clicked, this, + &DialogPiecePath::DeployVisibleFormulaTextEdit); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitPathTypes() { @@ -925,6 +1001,15 @@ void DialogPiecePath::SetPiecePath(const VPiecePath &path) SetPenType(path.GetPenType()); SetCutPath(path.IsCutPath()); + if (path.GetType() == PiecePathType::InternalPath) + { + SetFormulaVisible(path.GetVisibilityTrigger()); + } + else + { + ui->plainTextEditFormulaVisible->setPlainText("1"); + } + ValidObjects(PathIsValid()); ListChanged(); @@ -1141,6 +1226,15 @@ VPiecePath DialogPiecePath::CreatePath() const path.SetPenType(GetType() == PiecePathType::InternalPath ? GetPenType() : Qt::SolidLine); path.SetCutPath(GetType() == PiecePathType::InternalPath ? IsCutPath() : false); + if (GetType() == PiecePathType::InternalPath) + { + path.SetVisibilityTrigger(GetFormulaVisible()); + } + else + { + path.SetVisibilityTrigger("1"); + } + return path; } @@ -1222,3 +1316,24 @@ QString DialogPiecePath::GetFormulaSAWidthAfter() const width.replace("\n", " "); return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator()); } + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogPiecePath::GetFormulaVisible() const +{ + QString formula = ui->plainTextEditFormulaVisible->toPlainText(); + formula.replace("\n", " "); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetFormulaVisible(const QString &formula) +{ + const QString f = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (f.length() > 80) + { + this->DeployVisibleFormulaTextEdit(); + } + ui->plainTextEditFormulaVisible->setPlainText(f); + MoveCursorToEnd(ui->plainTextEditFormulaVisible); +} diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.h b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.h index 1a5fae1dd..6f3b4d5ca 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.h @@ -79,18 +79,22 @@ private slots: void EvalWidth(); void EvalWidthBefore(); void EvalWidthAfter(); + void EvalVisible(); void FXWidth(); void FXWidthBefore(); void FXWidthAfter(); + void FXVisible(); void WidthChanged(); void WidthBeforeChanged(); void WidthAfterChanged(); + void VisibleChanged(); void DeployWidthFormulaTextEdit(); void DeployWidthBeforeFormulaTextEdit(); void DeployWidthAfterFormulaTextEdit(); + void DeployVisibleFormulaTextEdit(); private: Q_DISABLE_COPY(DialogPiecePath) @@ -101,14 +105,21 @@ private: QTimer *m_timerWidth; QTimer *m_timerWidthBefore; QTimer *m_timerWidthAfter; + QTimer *m_timerVisible; int m_formulaBaseWidth; int m_formulaBaseWidthBefore; int m_formulaBaseWidthAfter; + int m_formulaBaseVisible; + + bool m_flagFormulaBefore; + bool m_flagFormulaAfter; + bool m_flagFormulaVisible; void InitPathTab(); void InitSeamAllowanceTab(); void InitPassmarksTab(); + void InitControlTab(); void InitPathTypes(); void InitNodesList(); void InitPassmarksList(); @@ -141,6 +152,9 @@ private: QString GetFormulaSAWidthBefore() const; QString GetFormulaSAWidthAfter() const; + + QString GetFormulaVisible() const; + void SetFormulaVisible(const QString &formula); }; #endif // DIALOGPIECEPATH_H diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.ui b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.ui index d8a9db64a..d3134a413 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.ui +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.ui @@ -1002,6 +1002,215 @@ + + + Control + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Visible + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + 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 + + + + Create a formula that regulates visibility. Values different from "0" make a path visible. + + + true + + + 1 + + + + + + + true + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 6d070b789..94acdaee2 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -192,6 +192,7 @@ void VToolPiecePath::AddAttributes(VAbstractPattern *doc, QDomElement &domElemen if (path.GetType() == PiecePathType::InternalPath) { + doc->SetAttribute(domElement, VAbstractPattern::AttrVisible, path.GetVisibilityTrigger()); doc->SetAttribute(domElement, AttrCut, path.IsCutPath()); } } @@ -308,6 +309,8 @@ void VToolPiecePath::RefreshGeometry() QPen pen = this->pen(); pen.setStyle(path.GetPenType()); this->setPen(pen); + + setVisible(path.IsVisible(this->getData()->DataVariables())); } }