diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index e16eb5add..c90dd6c78 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -695,6 +695,7 @@ struct CustomSARecord bool reverse; }; +Q_DECLARE_METATYPE(CustomSARecord) Q_DECLARE_TYPEINFO(CustomSARecord, Q_MOVABLE_TYPE); /**************************************************************************** diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index a77a15540..bd42a1945 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -252,36 +252,7 @@ void VPiece::SetCustomSARecords(const QVector &records) */ QVector VPiece::MissingNodes(const VPiece &det) const { - const QVector pNodes = d->m_path.GetNodes(); - if (pNodes.size() == det.GetPath().CountNodes()) //-V807 - { - return QVector(); - } - - QSet set1; - for (qint32 i = 0; i < pNodes.size(); ++i) - { - set1.insert(pNodes.at(i).GetId()); - } - - QSet set2; - for (qint32 j = 0; j < det.GetPath().CountNodes(); ++j) - { - set2.insert(det.GetPath().at(j).GetId()); - } - - const QList set3 = set1.subtract(set2).toList(); - QVector nodes; - for (qint32 i = 0; i < set3.size(); ++i) - { - const int index = indexOfNode(pNodes, set3.at(i)); - if (index != -1) - { - nodes.append(pNodes.at(index).GetId()); - } - } - - return nodes; + return d->m_path.MissingNodes(det.GetPath()); } //--------------------------------------------------------------------------------------------------------------------- @@ -315,17 +286,6 @@ QVector VPiece::MissingCSAPath(const VPiece &det) const return r; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief indexOfNode return index in list node using id object. - * @param id object (arc, point, spline, splinePath) id. - * @return index in list or -1 id can't find. - */ -int VPiece::indexOfNode(const quint32 &id) const -{ - return indexOfNode(d->m_path.GetNodes(), id); -} - //--------------------------------------------------------------------------------------------------------------------- void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VContainer *data, const QSharedPointer &curve, int i, bool reverse) const @@ -410,23 +370,3 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont } } } - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief indexOfNode return index in list node using id object. - * @param list list nodes detail. - * @param id object (arc, point, spline, splinePath) id. - * @return index in list or -1 id can't find. - */ -int VPiece::indexOfNode(const QVector &list, quint32 id) -{ - for (int i = 0; i < list.size(); ++i) - { - if (list.at(i).GetId() == id) - { - return i; - } - } - qDebug()<<"Can't find node."; - return -1; -} diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 255beb9a4..3eca969ed 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -81,15 +81,11 @@ public: QVector MissingNodes(const VPiece &det) const; QVector MissingCSAPath(const VPiece &det) const; - int indexOfNode(const quint32 &id) const; - private: QSharedDataPointer d; void CurveSeamAllowanceSegment(QVector &pointsEkv, const VContainer *data, const QSharedPointer &curve, int i, bool reverse) const; - - static int indexOfNode(const QVector &list, quint32 id); }; Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE); diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 78e7fcbd0..87e1a9484 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -314,3 +314,51 @@ VSAPoint VPiecePath::EndSegment(const VContainer *data, int i, bool reverse) con } return end; } + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiecePath::MissingNodes(const VPiecePath &path) const +{ + if (d->m_nodes.size() == path.CountNodes()) //-V807 + { + return QVector(); + } + + QSet set1; + for (qint32 i = 0; i < d->m_nodes.size(); ++i) + { + set1.insert(d->m_nodes.at(i).GetId()); + } + + QSet set2; + for (qint32 j = 0; j < path.CountNodes(); ++j) + { + set2.insert(path.at(j).GetId()); + } + + const QList set3 = set1.subtract(set2).toList(); + QVector nodes; + for (qint32 i = 0; i < set3.size(); ++i) + { + const int index = indexOfNode(set3.at(i)); + if (index != -1) + { + nodes.append(d->m_nodes.at(index).GetId()); + } + } + + return nodes; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPiecePath::indexOfNode(quint32 id) const +{ + for (int i = 0; i < d->m_nodes.size(); ++i) + { + if (d->m_nodes.at(i).GetId() == id) + { + return i; + } + } + qDebug()<<"Can't find node."; + return -1; +} diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 5d83e0580..facfa10f2 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -74,6 +74,10 @@ public: VSAPoint StartSegment(const VContainer *data, int i, bool reverse) const; VSAPoint EndSegment(const VContainer *data, int i, bool reverse) const; + QVector MissingNodes(const VPiecePath &path) const; + + int indexOfNode(quint32 id) const; + private: QSharedDataPointer d; }; diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 653e21f4a..0b08a1595 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -31,6 +31,8 @@ #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" #include "visualization/path/vistoolpiece.h" +#include "dialogpiecepath.h" +#include "../../undocommands/savepiecepathoptions.h" #include @@ -40,7 +42,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & ui(new Ui::DialogSeamAllowance), applyAllowed(false),// By default disabled m_mx(0), - m_my(0) + m_my(0), + m_dialog() { ui->setupUi(this); @@ -82,15 +85,25 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSeamAllowance::ChangedSAAfter); - ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogSeamAllowance::ShowContextMenu); - connect(ui->listWidget->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); + ui->listWidgetMainPath->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetMainPath, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowMainPathContextMenu); + connect(ui->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); InitNodeAngles(); connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, &DialogSeamAllowance::NodeAngleChanged); + ui->listWidgetCustomSA->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetCustomSA, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowCustomSAContextMenu); + connect(ui->listWidgetCustomSA, &QListWidget::currentRowChanged, this, &DialogSeamAllowance::CustomSAChanged); + connect(ui->comboBoxStartPoint, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::CSAStartPointChanged); + connect(ui->comboBoxEndPoint, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::CSAEndPointChanged); + if (not applyAllowed) { vis = new VisToolPiece(data); @@ -123,12 +136,31 @@ VPiece DialogSeamAllowance::GetPiece() const //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::SetPiece(const VPiece &piece) { - ui->listWidget->clear(); + ui->listWidgetMainPath->clear(); for (int i = 0; i < piece.GetPath().CountNodes(); ++i) { - NewItem(piece.GetPath().at(i)); + NewMainPathItem(piece.GetPath().at(i)); } + ui->listWidgetCustomSA->blockSignals(true); + ui->listWidgetCustomSA->clear(); + const QVector records = piece.GetCustomSARecords(); + for (int i = 0; i < records.size(); ++i) + { + NewCustomSA(records.at(i)); + } + ui->listWidgetCustomSA->blockSignals(false); + + ui->comboBoxStartPoint->blockSignals(true); + ui->comboBoxStartPoint->clear(); + ui->comboBoxStartPoint->blockSignals(false); + + ui->comboBoxEndPoint->blockSignals(true); + ui->comboBoxEndPoint->clear(); + ui->comboBoxEndPoint->blockSignals(false); + + CustomSAChanged(0); + ui->checkBoxForbidFlipping->setChecked(piece.IsForbidFlipping()); ui->doubleSpinBoxSeams->setValue(piece.GetSAWidth()); ui->checkBoxSeams->setChecked(piece.IsSeamAllowance()); @@ -159,16 +191,16 @@ void DialogSeamAllowance::ChosenObject(quint32 id, const SceneObject &type) switch (type) { case SceneObject::Arc: - NewItem(VPieceNode(id, Tool::NodeArc, reverse)); + NewMainPathItem(VPieceNode(id, Tool::NodeArc, reverse)); break; case SceneObject::Point: - NewItem(VPieceNode(id, Tool::NodePoint)); + NewMainPathItem(VPieceNode(id, Tool::NodePoint)); break; case SceneObject::Spline: - NewItem(VPieceNode(id, Tool::NodeSpline, reverse)); + NewMainPathItem(VPieceNode(id, Tool::NodeSpline, reverse)); break; case SceneObject::SplinePath: - NewItem(VPieceNode(id, Tool::NodeSplinePath, reverse)); + NewMainPathItem(VPieceNode(id, Tool::NodeSplinePath, reverse)); break; case (SceneObject::Line): case (SceneObject::Detail): @@ -241,10 +273,10 @@ void DialogSeamAllowance::CheckState() } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ShowContextMenu(const QPoint &pos) +void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos) { - const int row = ui->listWidget->currentRow(); - if (ui->listWidget->count() == 0 || row == -1 || row >= ui->listWidget->count()) + const int row = ui->listWidgetMainPath->currentRow(); + if (ui->listWidgetMainPath->count() == 0 || row == -1 || row >= ui->listWidgetMainPath->count()) { return; } @@ -253,7 +285,7 @@ void DialogSeamAllowance::ShowContextMenu(const QPoint &pos) QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); actionDelete->setEnabled(applyAllowed);//Because we can't undo this operation when creating a piece. - QListWidgetItem *rowItem = ui->listWidget->item(row); + QListWidgetItem *rowItem = ui->listWidgetMainPath->item(row); SCASSERT(rowItem != nullptr); VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); @@ -265,10 +297,10 @@ void DialogSeamAllowance::ShowContextMenu(const QPoint &pos) actionReverse->setChecked(rowNode.GetReverse()); } - QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos)); + QAction *selectedAction = menu->exec(ui->listWidgetMainPath->viewport()->mapToGlobal(pos)); if (selectedAction == actionDelete) { - delete ui->listWidget->item(row); + delete ui->listWidgetMainPath->item(row); ValidObjects(MainPathIsValid()); } else if (selectedAction == actionReverse) @@ -282,6 +314,52 @@ void DialogSeamAllowance::ShowContextMenu(const QPoint &pos) ListChanged(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ShowCustomSAContextMenu(const QPoint &pos) +{ + const int row = ui->listWidgetCustomSA->currentRow(); + if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) + { + return; + } + + QMenu *menu = new QMenu(this); + QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); + + QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); + SCASSERT(rowItem != nullptr); + CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); + + QAction *actionReverse = menu->addAction(tr("Reverse")); + actionReverse->setCheckable(true); + actionReverse->setChecked(record.reverse); + + QAction *actionOption = menu->addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + + QAction *selectedAction = menu->exec(ui->listWidgetCustomSA->viewport()->mapToGlobal(pos)); + if (selectedAction == actionDelete) + { + delete ui->listWidgetCustomSA->item(row); + } + else if (selectedAction == actionReverse) + { + record.reverse = not record.reverse; + rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); + rowItem->setText(GetCustomSARecordName(record)); + } + else if (selectedAction == actionOption) + { + auto *dialog = new DialogPiecePath(data, record.path, this); + dialog->SetPiecePath(data->GetPiecePath(record.path)); + dialog->SetPieceId(toolId); + dialog->EnbleShowMode(true); + m_dialog = dialog; + m_dialog->setModal(true); + connect(m_dialog.data(), &DialogTool::DialogClosed, this, &DialogSeamAllowance::PathDialogClosed); + m_dialog->show(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ListChanged() { @@ -299,6 +377,7 @@ void DialogSeamAllowance::ListChanged() void DialogSeamAllowance::EnableSeamAllowance(bool enable) { ui->groupBoxAutomatic->setEnabled(enable); + ui->groupBoxCustom->setEnabled(enable); if (enable) { @@ -327,7 +406,7 @@ void DialogSeamAllowance::NodeChanged(int index) const quint32 id = ui->comboBoxNodes->currentData().toUInt(); #endif const VPiece piece = CreatePiece(); - const int nodeIndex = piece.indexOfNode(id); + const int nodeIndex = piece.GetPath().indexOfNode(id); if (nodeIndex != -1) { const VPieceNode &node = piece.GetPath().at(nodeIndex); @@ -377,6 +456,52 @@ void DialogSeamAllowance::NodeChanged(int index) ui->comboBoxAngle->blockSignals(false); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::CSAStartPointChanged(int index) +{ + const int row = ui->listWidgetCustomSA->currentRow(); + if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) + { + return; + } + +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 startPoint = ui->comboBoxStartPoint->itemData(index).toUInt(); +#else + Q_UNUSED(index); + const quint32 startPoint = ui->comboBoxStartPoint->currentData().toUInt(); +#endif + + QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); + SCASSERT(rowItem != nullptr); + CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); + record.startPoint = startPoint; + rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::CSAEndPointChanged(int index) +{ + const int row = ui->listWidgetCustomSA->currentRow(); + if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) + { + return; + } + +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 endPoint = ui->comboBoxEndPoint->itemData(index).toUInt(); +#else + Q_UNUSED(index); + const quint32 endPoint = ui->comboBoxEndPoint->currentData().toUInt(); +#endif + + QListWidgetItem *rowItem = ui->listWidgetCustomSA->item(row); + SCASSERT(rowItem != nullptr); + CustomSARecord record = qvariant_cast(rowItem->data(Qt::UserRole)); + record.endPoint = endPoint; + rowItem->setData(Qt::UserRole, QVariant::fromValue(record)); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::NodeAngleChanged(int index) { @@ -431,13 +556,69 @@ void DialogSeamAllowance::ChangedSAAfter(double d) SetCurrentSAAfter(d); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::CustomSAChanged(int row) +{ + if (ui->listWidgetCustomSA->count() == 0 || row == -1 || row >= ui->listWidgetCustomSA->count()) + { + return; + } + + ui->comboBoxStartPoint->blockSignals(true); + ui->comboBoxEndPoint->blockSignals(true); + + InitCSAPoint(ui->comboBoxStartPoint); + InitCSAPoint(ui->comboBoxEndPoint); + + const QListWidgetItem *item = ui->listWidgetCustomSA->item( row ); + SCASSERT(item != nullptr); + const CustomSARecord record = qvariant_cast(item->data(Qt::UserRole)); + + { + const int index = ui->comboBoxStartPoint->findData(record.startPoint); + if (index != -1) + { + ui->comboBoxStartPoint->setCurrentIndex(index); + } + } + + { + const int index = ui->comboBoxEndPoint->findData(record.endPoint); + if (index != -1) + { + ui->comboBoxEndPoint->setCurrentIndex(index); + } + } + + ui->comboBoxStartPoint->blockSignals(false); + ui->comboBoxEndPoint->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::PathDialogClosed(int result) +{ + if (result == QDialog::Accepted) + { + SCASSERT(not m_dialog.isNull()); + DialogPiecePath *dialogTool = qobject_cast(m_dialog.data()); + SCASSERT(dialogTool != nullptr); + const VPiecePath newPath = dialogTool->GetPiecePath(); + const VPiecePath oldPath = data->GetPiecePath(dialogTool->GetPieceId()); + + SavePiecePathOptions *saveCommand = new SavePiecePathOptions(newPath, oldPath, qApp->getCurrentDocument(), + const_cast(data), toolId); + qApp->getUndoStack()->push(saveCommand); + } + delete m_dialog; +} + //--------------------------------------------------------------------------------------------------------------------- VPiece DialogSeamAllowance::CreatePiece() const { VPiece piece; - for (qint32 i = 0; i < ui->listWidget->count(); ++i) + for (qint32 i = 0; i < ui->listWidgetMainPath->count(); ++i) { - QListWidgetItem *item = ui->listWidget->item(i); + QListWidgetItem *item = ui->listWidgetMainPath->item(i); piece.GetPath().Append(qvariant_cast(item->data(Qt::UserRole))); } @@ -451,9 +632,43 @@ VPiece DialogSeamAllowance::CreatePiece() const } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::NewItem(const VPieceNode &node) +void DialogSeamAllowance::NewMainPathItem(const VPieceNode &node) { - NewNodeItem(ui->listWidget, node); + NewNodeItem(ui->listWidgetMainPath, node); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::NewCustomSA(const CustomSARecord &record) +{ + if (record.path > NULL_ID) + { + const QString name = GetCustomSARecordName(record); + + QListWidgetItem *item = new QListWidgetItem(name); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(record)); + ui->listWidgetCustomSA->addItem(item); + ui->listWidgetCustomSA->setCurrentRow(ui->listWidgetCustomSA->count()-1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSeamAllowance::GetCustomSARecordName(const CustomSARecord &record) const +{ + QString name; + + if (record.path > NULL_ID) + { + const VPiecePath path = data->GetPiecePath(record.path); + name = path.GetName(); + + if (record.reverse) + { + name = QLatin1String("- ") + name; + } + } + + return name; } //--------------------------------------------------------------------------------------------------------------------- @@ -475,13 +690,13 @@ bool DialogSeamAllowance::MainPathIsValid() const ui->helpLabel->setText(url); return false; } - if (FirstPointEqualLast(ui->listWidget)) + if (FirstPointEqualLast(ui->listWidgetMainPath)) { url += tr("First point cannot be equal to the last point!"); ui->helpLabel->setText(url); return false; } - else if (DoublePoints(ui->listWidget)) + else if (DoublePoints(ui->listWidgetMainPath)) { url += tr("You have double points!"); ui->helpLabel->setText(url); @@ -576,9 +791,9 @@ void DialogSeamAllowance::InitNodeAngles() //--------------------------------------------------------------------------------------------------------------------- QListWidgetItem *DialogSeamAllowance::GetItemById(quint32 id) { - for (qint32 i = 0; i < ui->listWidget->count(); ++i) + for (qint32 i = 0; i < ui->listWidgetMainPath->count(); ++i) { - QListWidgetItem *item = ui->listWidget->item(i); + QListWidgetItem *item = ui->listWidgetMainPath->item(i); const VPieceNode node = qvariant_cast(item->data(Qt::UserRole)); if (node.GetId() == id) @@ -636,3 +851,23 @@ void DialogSeamAllowance::SetCurrentSAAfter(qreal value) } } } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitCSAPoint(QComboBox *box) +{ + SCASSERT(box != nullptr); + box->clear(); + box->addItem(tr("Empty"), NULL_ID); + + const VPiece piece = CreatePiece(); + + for (int i = 0; i < piece.GetPath().CountNodes(); ++i) + { + const VPieceNode &node = piece.GetPath().at(i); + if (node.GetTypeTool() == Tool::NodePoint) + { + const QString name = GetNodeName(node); + box->addItem(name, node.GetId()); + } + } +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 114967881..f90fa75df 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -60,15 +60,20 @@ protected: virtual void CheckState() Q_DECL_OVERRIDE; private slots: - void ShowContextMenu(const QPoint &pos); + void ShowMainPathContextMenu(const QPoint &pos); + void ShowCustomSAContextMenu(const QPoint &pos); void ListChanged(); void EnableSeamAllowance(bool enable); void NodeChanged(int index); + void CSAStartPointChanged(int index); + void CSAEndPointChanged(int index); void NodeAngleChanged(int index); void ReturnDefBefore(); void ReturnDefAfter(); void ChangedSABefore(double d); void ChangedSAAfter(double d); + void CustomSAChanged(int row); + void PathDialogClosed(int result); private: Q_DISABLE_COPY(DialogSeamAllowance) @@ -78,14 +83,19 @@ private: qreal m_mx; qreal m_my; + QPointer m_dialog; + VPiece CreatePiece() const; - void NewItem(const VPieceNode &node); + void NewMainPathItem(const VPieceNode &node); + void NewCustomSA(const CustomSARecord &record); + QString GetCustomSARecordName(const CustomSARecord &record) const; bool MainPathIsValid() const; void ValidObjects(bool value); bool MainPathIsClockwise() const; void InitNodesList(); void InitNodeAngles(); + void InitCSAPoint(QComboBox *box); QListWidgetItem *GetItemById(quint32 id); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 6af522a18..e27204d0f 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -7,21 +7,21 @@ 0 0 559 - 423 + 476 Dialog - + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - 0 + 1 @@ -42,7 +42,7 @@ - :/icon/32x32/clockwise.png + :/icon/32x32/clockwise.png @@ -69,7 +69,7 @@ - + QAbstractItemView::InternalMove @@ -94,7 +94,7 @@ Seam allowance - + @@ -113,10 +113,19 @@ Automatic + + false + false + + 9 + + + 0 + @@ -269,22 +278,75 @@ + + + + + + + false + + + Custom + + + false + + + + 0 + - + - Qt::Vertical + Qt::Horizontal - - - 20 - 219 - - - + + + + QFormLayout::ExpandingFieldsGrow + + + + + Start point: + + + + + + + + + + End point: + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -301,7 +363,9 @@ - + + + buttonBox diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 7527af36c..492c6d17d 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -151,6 +151,14 @@ void VToolPiecePath::AddNodes(VAbstractPattern *doc, QDomElement &domElement, co } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiecePath &path) +{ + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + doc->SetAttribute(domElement, AttrName, path.GetName()); + doc->SetAttribute(domElement, AttrType, static_cast(path.GetType())); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolPiecePath::FullUpdateFromFile() { @@ -175,11 +183,9 @@ void VToolPiecePath::AllowSelecting(bool enabled) void VToolPiecePath::AddToFile() { QDomElement domElement = doc->createElement(getTagName()); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - const VPiecePath path = VAbstractTool::data.GetPiecePath(id); - doc->SetAttribute(domElement, AttrType, static_cast(path.GetType())); + + AddAttributes(doc, domElement, id, path); if (idTool != NULL_ID) { diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h index c204dac34..18f4e236d 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -52,6 +52,7 @@ public: static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node); static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path); + static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiecePath &path); public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/undocommands/savepiecepathoptions.cpp b/src/libs/vtools/undocommands/savepiecepathoptions.cpp new file mode 100644 index 000000000..61f155e4b --- /dev/null +++ b/src/libs/vtools/undocommands/savepiecepathoptions.cpp @@ -0,0 +1,139 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 26 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "savepiecepathoptions.h" + +#include +#include +#include + +#include "../ifc/xml/vabstractpattern.h" +#include "../vmisc/logging.h" +#include "../tools/nodeDetails/vtoolpiecepath.h" + +class QDomElement; +class QUndoCommand; + +//--------------------------------------------------------------------------------------------------------------------- +SavePiecePathOptions::SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath, + VAbstractPattern *doc, VContainer *data, quint32 id, + QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_oldPath(oldPath), + m_newPath(newPath), + m_data(data) +{ + setText(tr("save path options")); + nodeId = id; +} + +//--------------------------------------------------------------------------------------------------------------------- +SavePiecePathOptions::~SavePiecePathOptions() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void SavePiecePathOptions::undo() +{ + qCDebug(vUndo, "Undo."); + + QDomElement domElement = doc->elementById(nodeId); + if (domElement.isElement()) + { + VToolPiecePath::AddAttributes(doc, domElement, nodeId, m_oldPath); + doc->RemoveAllChildren(domElement);//Very important to clear before rewrite + VToolPiecePath::AddNodes(doc, domElement, m_oldPath); + + IncrementReferences(m_oldPath.MissingNodes(m_newPath)); + + SCASSERT(m_data); + m_data->UpdatePiecePath(nodeId, m_oldPath); + } + else + { + qCDebug(vUndo, "Can't find path with id = %u.", nodeId); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void SavePiecePathOptions::redo() +{ + qCDebug(vUndo, "Redo."); + + QDomElement domElement = doc->elementById(nodeId); + if (domElement.isElement()) + { + VToolPiecePath::AddAttributes(doc, domElement, nodeId, m_newPath); + doc->RemoveAllChildren(domElement);//Very important to clear before rewrite + VToolPiecePath::AddNodes(doc, domElement, m_newPath); + + DecrementReferences(m_oldPath.MissingNodes(m_newPath)); + + SCASSERT(m_data); + m_data->UpdatePiecePath(nodeId, m_oldPath); + } + else + { + qCDebug(vUndo, "Can't find path with id = %u.", nodeId); + return; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool SavePiecePathOptions::mergeWith(const QUndoCommand *command) +{ + const SavePiecePathOptions *saveCommand = static_cast(command); + SCASSERT(saveCommand != nullptr); + const quint32 id = saveCommand->PathId(); + + if (id != nodeId) + { + return false; + } + + m_newPath = saveCommand->NewPath(); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +int SavePiecePathOptions::id() const +{ + return static_cast(UndoCommand::SavePiecePathOptions); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 SavePiecePathOptions::PathId() const +{ + return nodeId; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath SavePiecePathOptions::NewPath() const +{ + return m_newPath; +} diff --git a/src/libs/vtools/undocommands/savepiecepathoptions.h b/src/libs/vtools/undocommands/savepiecepathoptions.h new file mode 100644 index 000000000..f869df012 --- /dev/null +++ b/src/libs/vtools/undocommands/savepiecepathoptions.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 26 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef SAVEPIECEPATHOPTIONS_H +#define SAVEPIECEPATHOPTIONS_H + +#include + +#include "../vpatterndb/vpiecepath.h" +#include "vundocommand.h" + +class QUndoCommand; +class VAbstractPattern; + +class SavePiecePathOptions : public VUndoCommand +{ +public: + SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc, + VContainer *data, quint32 id, QUndoCommand *parent = nullptr); + virtual ~SavePiecePathOptions(); + + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; + virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE; + virtual int id() const Q_DECL_OVERRIDE; + quint32 PathId() const; + VPiecePath NewPath() const; +private: + Q_DISABLE_COPY(SavePiecePathOptions) + + const VPiecePath m_oldPath; + VPiecePath m_newPath; + + VContainer *m_data; +}; + +#endif // SAVEPIECEPATHOPTIONS_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index c73295eee..a682f0e26 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -26,7 +26,8 @@ HEADERS += \ $$PWD/deletepiece.h \ $$PWD/movepiece.h \ $$PWD/savepieceoptions.h \ - $$PWD/togglepieceinlayout.h + $$PWD/togglepieceinlayout.h \ + $$PWD/savepiecepathoptions.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -53,4 +54,5 @@ SOURCES += \ $$PWD/deletepiece.cpp \ $$PWD/movepiece.cpp \ $$PWD/savepieceoptions.cpp \ - $$PWD/togglepieceinlayout.cpp + $$PWD/togglepieceinlayout.cpp \ + $$PWD/savepiecepathoptions.cpp diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index dea2b9ff8..b6211a239 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -55,6 +55,7 @@ enum class UndoCommand: char { AddPatternPiece, SaveToolOptions, SaveDetailOptions, SavePieceOptions, + SavePiecePathOptions, MovePiece, DeleteTool, DeletePatternPiece,