diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 904c32fb9..6355f8a7b 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -67,52 +67,6 @@ QVector PieceMissingNodes(const QVector &d1Nodes, const QVecto return r; } -//--------------------------------------------------------------------------------------------------------------------- -QVector FilterRecords(QVector records) -{ - if (records.size() < 2) - { - return records; - } - - bool foundFilter = false;// Need in case "filter" will stay empty. - CustomSARecord filter; - int startIndex = records.size()-1; - - for (int i = 0; i < records.size(); ++i) - { - if (records.at(i).startPoint < static_cast(startIndex)) - { - startIndex = i; - filter = records.at(i); - foundFilter = true; - } - } - - if (not foundFilter) - { - return records; // return as is - } - - records.remove(startIndex); - - QVector secondRound; - for (int i = 0; i < records.size(); ++i) - { - if (records.at(i).startPoint > filter.endPoint) - { - secondRound.append(records.at(i)); - } - } - - QVector filtered; - filtered.append(filter); - - filtered += FilterRecords(secondRound); - - return filtered; -} - //--------------------------------------------------------------------------------------------------------------------- qreal PassmarkLength(const VSAPoint &passmarkSAPoint, qreal width) { @@ -733,6 +687,55 @@ QVector VPiece::GetValidRecords() const return records; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::FilterRecords(QVector records) const +{ + if (records.size() < 2) + { + return records; + } + + bool foundFilter = false;// Need in case "filter" will stay empty. + CustomSARecord filter; + int startIndex = d->m_path.CountNodes()-1; + + for (int i = 0; i < records.size(); ++i) + { + const int indexStartPoint = d->m_path.indexOfNode(records.at(i).startPoint); + if (indexStartPoint < startIndex) + { + startIndex = i; + filter = records.at(i); + foundFilter = true; + } + } + + if (not foundFilter) + { + return records; // return as is + } + + records.remove(startIndex); + + QVector secondRound; + for (int i = 0; i < records.size(); ++i) + { + const int indexStartPoint = d->m_path.indexOfNode(records.at(i).startPoint); + const int indexEndPoint = d->m_path.indexOfNode(filter.endPoint); + if (indexStartPoint > indexEndPoint) + { + secondRound.append(records.at(i)); + } + } + + QVector filtered; + filtered.append(filter); + + filtered += FilterRecords(secondRound); + + return filtered; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::GetNodeSAPoints(int index, const VContainer *data) const { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 1235f16f4..7f5c40ec6 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -114,6 +114,7 @@ private: QSharedDataPointer d; QVector GetValidRecords() const; + QVector FilterRecords(QVector records) const; QVector GetNodeSAPoints(int index, const VContainer *data) const; diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index 6f218628b..49faa85ec 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -55,6 +55,7 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget InitPathTab(); InitSeamAllowanceTab(); + InitPassmarksTab(); flagName = true;//We have default name of piece. flagError = PathIsValid(); @@ -62,7 +63,8 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget vis = new VisToolPiecePath(data); - ui->tabWidget->removeTab(1); + ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSeamAllowance)); + ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabPassmarks)); } //--------------------------------------------------------------------------------------------------------------------- @@ -224,6 +226,7 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos) SCASSERT(rowItem != nullptr); VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + QAction *actionPassmark = nullptr; QAction *actionReverse = nullptr; if (rowNode.GetTypeTool() != Tool::NodePoint) { @@ -231,6 +234,12 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos) actionReverse->setCheckable(true); actionReverse->setChecked(rowNode.GetReverse()); } + else + { + actionPassmark = menu->addAction(tr("Passmark")); + actionPassmark->setCheckable(true); + actionPassmark->setChecked(rowNode.IsPassmark()); + } QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); @@ -238,16 +247,21 @@ void DialogPiecePath::ShowContextMenu(const QPoint &pos) if (selectedAction == actionDelete) { delete ui->listWidget->item(row); - ValidObjects(PathIsValid()); } else if (rowNode.GetTypeTool() != Tool::NodePoint && selectedAction == actionReverse) { rowNode.SetReverse(not rowNode.GetReverse()); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setText(GetNodeName(rowNode, true)); - ValidObjects(PathIsValid()); + } + else if (selectedAction == actionPassmark) + { + rowNode.SetPassmark(not rowNode.IsPassmark()); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + rowItem->setText(GetNodeName(rowNode, true)); } + ValidObjects(PathIsValid()); ListChanged(); } @@ -357,6 +371,68 @@ void DialogPiecePath::NodeChanged(int index) ui->comboBoxAngle->blockSignals(false); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::PassmarkChanged(int index) +{ + ui->radioButtonOneLine->setDisabled(true); + ui->radioButtonTwoLines->setDisabled(true); + ui->radioButtonThreeLines->setDisabled(true); + + ui->radioButtonStraightforward->setDisabled(true); + ui->radioButtonBisector->setDisabled(true); + + ui->groupBoxLineType->blockSignals(true); + ui->groupBoxAngleType->blockSignals(true); + + if (index != -1) + { + const VPiecePath path = CreatePath(); + const int nodeIndex = path.indexOfNode(CURRENT_DATA(ui->comboBoxPassmarks).toUInt()); + if (nodeIndex != -1) + { + const VPieceNode &node = path.at(nodeIndex); + + // Line type + ui->radioButtonOneLine->setEnabled(true); + ui->radioButtonTwoLines->setEnabled(true); + ui->radioButtonThreeLines->setEnabled(true); + + switch(node.GetPassmarkLineType()) + { + case PassmarkLineType::OneLine: + ui->radioButtonOneLine->setChecked(true); + break; + case PassmarkLineType::TwoLines: + ui->radioButtonTwoLines->setChecked(true); + break; + case PassmarkLineType::ThreeLines: + ui->radioButtonThreeLines->setChecked(true); + break; + default: + break; + } + + // Angle type + ui->radioButtonStraightforward->setEnabled(true); + ui->radioButtonBisector->setEnabled(true); + + switch(node.GetPassmarkAngleType()) + { + case PassmarkAngleType::Straightforward: + ui->radioButtonStraightforward->setChecked(true); + break; + case PassmarkAngleType::Bisector: + ui->radioButtonBisector->setChecked(true); + break; + default: + break; + } + } + } + ui->groupBoxLineType->blockSignals(false); + ui->groupBoxAngleType->blockSignals(false); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::ReturnDefBefore() { @@ -369,6 +445,70 @@ void DialogPiecePath::ReturnDefAfter() ui->plainTextEditFormulaWidthAfter->setPlainText(currentSeamAllowance); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::PassmarkLineTypeChanged(int id) +{ + const int i = ui->comboBoxPassmarks->currentIndex(); + if (i != -1) + { + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxPassmarks).toUInt()); + if (rowItem) + { + VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + + PassmarkLineType lineType = PassmarkLineType::OneLine; + if (id == ui->buttonGroupLineType->id(ui->radioButtonOneLine)) + { + lineType = PassmarkLineType::OneLine; + } + else if (id == ui->buttonGroupLineType->id(ui->radioButtonTwoLines)) + { + lineType = PassmarkLineType::TwoLines; + } + else if (id == ui->buttonGroupLineType->id(ui->radioButtonThreeLines)) + { + lineType = PassmarkLineType::ThreeLines; + } + + rowNode.SetPassmarkLineType(lineType); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + rowItem->setText(GetNodeName(rowNode, true)); + + ListChanged(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::PassmarkAngleTypeChanged(int id) +{ + const int i = ui->comboBoxPassmarks->currentIndex(); + if (i != -1) + { + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxPassmarks).toUInt()); + if (rowItem) + { + VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + + PassmarkAngleType angleType = PassmarkAngleType::Straightforward; + if (id == ui->buttonGroupAngleType->id(ui->radioButtonStraightforward)) + { + angleType = PassmarkAngleType::Straightforward; + } + else if (id == ui->buttonGroupAngleType->id(ui->radioButtonBisector)) + { + angleType = PassmarkAngleType::Bisector; + } + + rowNode.SetPassmarkAngleType(angleType); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + rowItem->setText(GetNodeName(rowNode, true)); + + ListChanged(); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::EvalWidth() { @@ -581,6 +721,19 @@ void DialogPiecePath::InitSeamAllowanceTab() &DialogPiecePath::DeployWidthAfterFormulaTextEdit); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitPassmarksTab() +{ + InitPassmarksList(); + connect(ui->comboBoxPassmarks, static_cast(&QComboBox::currentIndexChanged), + this, &DialogPiecePath::PassmarkChanged); + + connect(ui->buttonGroupLineType, static_cast(&QButtonGroup::buttonClicked), + this, &DialogPiecePath::PassmarkLineTypeChanged); + connect(ui->buttonGroupAngleType, static_cast(&QButtonGroup::buttonClicked), + this, &DialogPiecePath::PassmarkAngleTypeChanged); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitPathTypes() { @@ -624,6 +777,40 @@ void DialogPiecePath::InitNodesList() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitPassmarksList() +{ + const quint32 id = CURRENT_DATA(ui->comboBoxPassmarks).toUInt(); + + ui->comboBoxPassmarks->blockSignals(true); + ui->comboBoxPassmarks->clear(); + + const QVector nodes = GetListInternals(ui->listWidget); + + for (int i = 0; i < nodes.size(); ++i) + { + const VPieceNode node = nodes.at(i); + if (node.GetTypeTool() == Tool::NodePoint && node.IsPassmark()) + { + const QString name = GetNodeName(node); + + ui->comboBoxPassmarks->addItem(name, node.GetId()); + } + } + ui->comboBoxPassmarks->blockSignals(false); + + const int index = ui->comboBoxPassmarks->findData(id); + if (index != -1) + { + ui->comboBoxPassmarks->setCurrentIndex(index); + PassmarkChanged(index);// Need in case combox index was not changed + } + else + { + ui->comboBoxPassmarks->count() > 0 ? PassmarkChanged(0) : PassmarkChanged(-1); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::NodeAngleChanged(int index) { @@ -783,6 +970,11 @@ void DialogPiecePath::UpdateNodeSAAfter(const QString &formula) //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::SetFormulaSAWidth(const QString &formula) { + if (formula.isEmpty()) + { + return; + } + const QString width = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (width.length() > 80) @@ -795,6 +987,16 @@ void DialogPiecePath::SetFormulaSAWidth(const QString &formula) SCASSERT(path != nullptr) path->SetPath(CreatePath()); + if (ui->tabWidget->indexOf(ui->tabSeamAllowance) == -1) + { + ui->tabWidget->addTab(ui->tabSeamAllowance, tr("Seam allowance")); + } + + if (ui->tabWidget->indexOf(ui->tabPassmarks) == -1) + { + ui->tabWidget->addTab(ui->tabPassmarks, tr("Passmarks")); + } + MoveCursorToEnd(ui->plainTextEditFormulaWidth); } diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.h b/src/libs/vtools/dialogs/tools/dialogpiecepath.h index 19e79e4cd..2bb252704 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.h +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.h @@ -70,8 +70,11 @@ private slots: void ListChanged(); void NameChanged(); void NodeChanged(int index); + void PassmarkChanged(int index); void ReturnDefBefore(); void ReturnDefAfter(); + void PassmarkLineTypeChanged(int id); + void PassmarkAngleTypeChanged(int id); void EvalWidth(); void EvalWidthBefore(); @@ -105,9 +108,11 @@ private: void InitPathTab(); void InitSeamAllowanceTab(); + void InitPassmarksTab(); void InitPathTypes(); void InitListPieces(); void InitNodesList(); + void InitPassmarksList(); void NodeAngleChanged(int index); VPiecePath CreatePath() const; diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui index 10d360ffd..7089b91d6 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui @@ -792,6 +792,129 @@ + + + Passmarks + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Passmark: + + + + + + + + + + + + true + + + Lines + + + + + + false + + + One line + + + buttonGroupLineType + + + + + + + false + + + Two lines + + + buttonGroupLineType + + + + + + + false + + + Three lines + + + buttonGroupLineType + + + + + + + + + + Angle + + + + + + false + + + Straightforward + + + buttonGroupAngleType + + + + + + + false + + + Bisector + + + buttonGroupAngleType + + + + + + + + + + Qt::Vertical + + + + 20 + 85 + + + + + + @@ -843,4 +966,8 @@ + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 38abeda24..58c5820bd 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -256,6 +256,9 @@ protected: template void AddVisualization(); + template + QVector GetListInternals(const QListWidget *list) const; + void ChangeColor(QWidget *widget, const QColor &color); virtual void ShowVisualization() {} /** @@ -294,6 +297,20 @@ private: }; +//--------------------------------------------------------------------------------------------------------------------- +template +QVector DialogTool::GetListInternals(const QListWidget *list) const +{ + SCASSERT(list != nullptr) + QVector internals; + for (qint32 i = 0; i < list->count(); ++i) + { + QListWidgetItem *item = list->item(i); + internals.append(qvariant_cast(item->data(Qt::UserRole))); + } + return internals; +} + //--------------------------------------------------------------------------------------------------------------------- inline VAbstractTool *DialogTool::GetAssociatedTool() { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 2a5b80c5b..a77530fa5 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2029,10 +2029,10 @@ void DialogSeamAllowance::PatternPinPointChanged() VPiece DialogSeamAllowance::CreatePiece() const { VPiece piece; - piece.GetPath().SetNodes(GetPieceInternals(uiTabPaths->listWidgetMainPath)); - piece.SetCustomSARecords(GetPieceInternals(uiTabPaths->listWidgetCustomSA)); - piece.SetInternalPaths(GetPieceInternals(uiTabPaths->listWidgetInternalPaths)); - piece.SetPins(GetPieceInternals(uiTabPins->listWidgetPins)); + piece.GetPath().SetNodes(GetListInternals(uiTabPaths->listWidgetMainPath)); + piece.SetCustomSARecords(GetListInternals(uiTabPaths->listWidgetCustomSA)); + piece.SetInternalPaths(GetListInternals(uiTabPaths->listWidgetInternalPaths)); + piece.SetPins(GetListInternals(uiTabPins->listWidgetPins)); piece.SetForbidFlipping(uiTabPaths->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(uiTabPaths->checkBoxSeams->isChecked()); piece.SetName(uiTabLabels->lineEditName->text()); @@ -2232,7 +2232,7 @@ void DialogSeamAllowance::InitNodesList() uiTabPaths->comboBoxNodes->blockSignals(true); uiTabPaths->comboBoxNodes->clear(); - const QVector nodes = GetPieceInternals(uiTabPaths->listWidgetMainPath); + const QVector nodes = GetListInternals(uiTabPaths->listWidgetMainPath); for (int i = 0; i < nodes.size(); ++i) { @@ -2266,7 +2266,7 @@ void DialogSeamAllowance::InitPassmarksList() uiTabPassmarks->comboBoxPassmarks->blockSignals(true); uiTabPassmarks->comboBoxPassmarks->clear(); - const QVector nodes = GetPieceInternals(uiTabPaths->listWidgetMainPath); + const QVector nodes = GetListInternals(uiTabPaths->listWidgetMainPath); for (int i = 0; i < nodes.size(); ++i) { @@ -2495,7 +2495,7 @@ void DialogSeamAllowance::InitCSAPoint(QComboBox *box) box->clear(); box->addItem(tr("Empty"), NULL_ID); - const QVector nodes = GetPieceInternals(uiTabPaths->listWidgetMainPath); + const QVector nodes = GetListInternals(uiTabPaths->listWidgetMainPath); for (int i = 0; i < nodes.size(); ++i) { @@ -2522,7 +2522,7 @@ void DialogSeamAllowance::InitPinPoint(QComboBox *box) box->clear(); box->addItem(QLatin1String("<") + tr("no pin") + QLatin1String(">"), NULL_ID); - const QVector pins = GetPieceInternals(uiTabPins->listWidgetPins); + const QVector pins = GetListInternals(uiTabPins->listWidgetPins); for (int i = 0; i < pins.size(); ++i) { @@ -2803,20 +2803,6 @@ void DialogSeamAllowance::ClearFields() uiTabLabels->comboBoxPlacement->setCurrentIndex(0); } -//--------------------------------------------------------------------------------------------------------------------- -template -QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const -{ - SCASSERT(list != nullptr) - QVector internals; - for (qint32 i = 0; i < list->count(); ++i) - { - QListWidgetItem *item = list->item(i); - internals.append(qvariant_cast(item->data(Qt::UserRole))); - } - return internals; -} - //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula) { @@ -2984,7 +2970,7 @@ void DialogSeamAllowance::ShowPins() m_visPins = new VisPiecePins(data); } - m_visPins->SetPins(GetPieceInternals(uiTabPins->listWidgetPins)); + m_visPins->SetPins(GetListInternals(uiTabPins->listWidgetPins)); if (not qApp->getCurrentScene()->items().contains(m_visPins)) { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h index 98a8ee41e..76472f446 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.h @@ -256,9 +256,6 @@ private: void SetFormulaSAWidth(const QString &formula); - template - QVector GetPieceInternals(const QListWidget *list) const; - void SetGrainlineAngle(QString angleFormula); void SetGrainlineLength(QString lengthFormula);