2016-11-22 12:04:34 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogpiecepath.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 22 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
|
|
|
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialogpiecepath.h"
|
|
|
|
#include "ui_dialogpiecepath.h"
|
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2016-11-23 12:57:12 +01:00
|
|
|
#include "visualization/path/vistoolpiecepath.h"
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent)
|
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogPiecePath),
|
2016-11-29 15:29:09 +01:00
|
|
|
m_showMode(false)
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
InitOkCancel(ui);
|
|
|
|
|
2016-11-23 17:43:31 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
ui->lineEditName->setClearButtonEnabled(true);
|
|
|
|
#endif
|
|
|
|
|
2016-11-23 13:50:30 +01:00
|
|
|
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogPiecePath::NameChanged);
|
|
|
|
|
|
|
|
InitPathTypes();
|
|
|
|
connect(ui->comboBoxType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
[this](){ValidObjects(PathIsValid());});
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
flagName = true;//We have default name of piece.
|
|
|
|
flagError = PathIsValid();
|
|
|
|
CheckState();
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
const QString suffix = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
ui->doubleSpinBoxSeams->setSuffix(suffix);
|
|
|
|
ui->doubleSpinBoxSABefore->setSuffix(suffix);
|
|
|
|
ui->doubleSpinBoxSAAfter->setSuffix(suffix);
|
|
|
|
|
|
|
|
if(qApp->patternUnit() == Unit::Inch)
|
|
|
|
{
|
|
|
|
ui->doubleSpinBoxSeams->setDecimals(5);
|
|
|
|
ui->doubleSpinBoxSABefore->setDecimals(5);
|
|
|
|
ui->doubleSpinBoxSAAfter->setDecimals(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitNodesList();
|
|
|
|
connect(ui->comboBoxNodes, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogPiecePath::NodeChanged);
|
|
|
|
|
|
|
|
connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefBefore);
|
|
|
|
connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefAfter);
|
|
|
|
|
|
|
|
connect(ui->doubleSpinBoxSeams, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
[this](){NodeChanged(ui->comboBoxNodes->currentIndex());});
|
|
|
|
|
|
|
|
connect(ui->doubleSpinBoxSABefore, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogPiecePath::ChangedSABefore);
|
|
|
|
connect(ui->doubleSpinBoxSAAfter, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogPiecePath::ChangedSAAfter);
|
|
|
|
|
|
|
|
InitNodeAngles(ui->comboBoxAngle);
|
|
|
|
connect(ui->comboBoxAngle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogPiecePath::NodeAngleChanged);
|
|
|
|
|
2016-11-29 16:45:43 +01:00
|
|
|
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogPiecePath::ShowContextMenu);
|
|
|
|
|
2016-11-29 15:29:09 +01:00
|
|
|
vis = new VisToolPiecePath(data);
|
2016-11-28 12:58:17 +01:00
|
|
|
|
|
|
|
ui->tabWidget->removeTab(1);
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogPiecePath::~DialogPiecePath()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-28 09:45:57 +01:00
|
|
|
void DialogPiecePath::EnbleShowMode(bool disable)
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
|
|
|
m_showMode = disable;
|
2016-11-29 15:29:09 +01:00
|
|
|
ui->comboBoxType->setDisabled(m_showMode);
|
|
|
|
ui->comboBoxPiece->setDisabled(m_showMode);
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (not prepare)
|
|
|
|
{
|
|
|
|
bool reverse = false;
|
|
|
|
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
reverse = true;
|
|
|
|
}
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SceneObject::Arc:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodeArc, reverse));
|
|
|
|
break;
|
|
|
|
case SceneObject::Point:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodePoint));
|
|
|
|
break;
|
|
|
|
case SceneObject::Spline:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodeSpline, reverse));
|
|
|
|
break;
|
|
|
|
case SceneObject::SplinePath:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodeSplinePath, reverse));
|
|
|
|
break;
|
|
|
|
case (SceneObject::Line):
|
|
|
|
case (SceneObject::Detail):
|
|
|
|
case (SceneObject::Unknown):
|
|
|
|
default:
|
|
|
|
qDebug() << "Got wrong scene object. Ignore.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValidObjects(PathIsValid());
|
|
|
|
|
|
|
|
if (not m_showMode)
|
|
|
|
{
|
2016-11-23 12:57:12 +01:00
|
|
|
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(visPath != nullptr);
|
|
|
|
const VPiecePath p = CreatePath();
|
|
|
|
visPath->SetPath(p);
|
|
|
|
|
|
|
|
if (p.CountNodes() == 1)
|
|
|
|
{
|
|
|
|
emit ToolTip(tr("Select main path objects, <b>Shift</b> - reverse direction curve, "
|
|
|
|
"<b>Enter</b> - finish creation"));
|
|
|
|
|
|
|
|
visPath->VisualMode(NULL_ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
visPath->RefreshGeometry();
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (click == false)
|
|
|
|
{
|
2016-11-23 17:50:52 +01:00
|
|
|
if (CreatePath().CountNodes() > 0)
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
2016-11-23 17:50:52 +01:00
|
|
|
emit ToolTip("");
|
|
|
|
prepare = true;
|
|
|
|
|
|
|
|
if (not m_showMode)
|
|
|
|
{
|
|
|
|
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(visPath != nullptr);
|
|
|
|
visPath->SetMode(Mode::Show);
|
|
|
|
visPath->RefreshGeometry();
|
|
|
|
}
|
|
|
|
setModal(true);
|
|
|
|
show();
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SaveData()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::CheckState()
|
|
|
|
{
|
|
|
|
SCASSERT(bOk != nullptr);
|
2016-11-23 13:50:30 +01:00
|
|
|
bOk->setEnabled(flagName && flagError);
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-29 18:39:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ShowVisualization()
|
|
|
|
{
|
|
|
|
AddVisualization<VisToolPiecePath>();
|
|
|
|
}
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ShowContextMenu(const QPoint &pos)
|
|
|
|
{
|
|
|
|
const int row = ui->listWidget->currentRow();
|
|
|
|
if (ui->listWidget->count() == 0 || row == -1 || row >= ui->listWidget->count())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
|
|
|
actionDelete->setEnabled(m_showMode);//Because we can't undo this operation when creating a piece.
|
|
|
|
|
|
|
|
QListWidgetItem *rowItem = ui->listWidget->item(row);
|
|
|
|
SCASSERT(rowItem != nullptr);
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
|
|
|
|
|
|
|
QAction *actionReverse = nullptr;
|
|
|
|
if (rowNode.GetTypeTool() != Tool::NodePoint)
|
|
|
|
{
|
|
|
|
actionReverse = menu->addAction(tr("Reverse"));
|
|
|
|
actionReverse->setCheckable(true);
|
|
|
|
actionReverse->setChecked(rowNode.GetReverse());
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
|
|
|
|
if (selectedAction == actionDelete)
|
|
|
|
{
|
|
|
|
delete ui->listWidget->item(row);
|
|
|
|
ValidObjects(PathIsValid());
|
|
|
|
}
|
|
|
|
else if (selectedAction == actionReverse)
|
|
|
|
{
|
|
|
|
rowNode.SetReverse(not rowNode.GetReverse());
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
rowItem->setText(GetNodeName(rowNode));
|
|
|
|
ValidObjects(PathIsValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ListChanged()
|
|
|
|
{
|
|
|
|
if (not m_showMode)
|
|
|
|
{
|
2016-11-23 12:57:12 +01:00
|
|
|
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(visPath != nullptr);
|
|
|
|
visPath->SetPath(CreatePath());
|
|
|
|
visPath->RefreshGeometry();
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
2016-11-28 12:58:17 +01:00
|
|
|
|
|
|
|
InitNodesList();
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::NameChanged()
|
|
|
|
{
|
|
|
|
if (ui->lineEditName->text().isEmpty())
|
|
|
|
{
|
|
|
|
flagName = false;
|
|
|
|
ChangeColor(ui->labelName, Qt::red);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagName = true;
|
|
|
|
ChangeColor(ui->labelName, okColor);
|
|
|
|
}
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::NodeChanged(int index)
|
|
|
|
{
|
|
|
|
ui->doubleSpinBoxSABefore->setDisabled(true);
|
|
|
|
ui->doubleSpinBoxSAAfter->setDisabled(true);
|
|
|
|
ui->pushButtonDefBefore->setDisabled(true);
|
|
|
|
ui->pushButtonDefAfter->setDisabled(true);
|
|
|
|
ui->comboBoxAngle->setDisabled(true);
|
|
|
|
|
|
|
|
ui->doubleSpinBoxSABefore->blockSignals(true);
|
|
|
|
ui->doubleSpinBoxSAAfter->blockSignals(true);
|
|
|
|
ui->comboBoxAngle->blockSignals(true);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
|
|
|
|
#else
|
|
|
|
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
const VPiecePath path = CreatePath();
|
|
|
|
const int nodeIndex = path.indexOfNode(id);
|
|
|
|
if (nodeIndex != -1)
|
|
|
|
{
|
|
|
|
const VPieceNode &node = path.at(nodeIndex);
|
|
|
|
|
|
|
|
ui->doubleSpinBoxSABefore->setEnabled(true);
|
|
|
|
ui->doubleSpinBoxSAAfter->setEnabled(true);
|
|
|
|
ui->comboBoxAngle->setEnabled(true);
|
|
|
|
|
|
|
|
qreal w1 = node.GetSABefore();
|
|
|
|
if (w1 < 0)
|
|
|
|
{
|
2016-11-29 15:29:09 +01:00
|
|
|
w1 = ui->doubleSpinBoxSeams->value();
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->pushButtonDefBefore->setEnabled(true);
|
|
|
|
}
|
|
|
|
ui->doubleSpinBoxSABefore->setValue(w1);
|
|
|
|
|
|
|
|
qreal w2 = node.GetSAAfter();
|
|
|
|
if (w2 < 0)
|
|
|
|
{
|
2016-11-29 15:29:09 +01:00
|
|
|
w2 = ui->doubleSpinBoxSeams->value();
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->pushButtonDefAfter->setEnabled(true);
|
|
|
|
}
|
|
|
|
ui->doubleSpinBoxSAAfter->setValue(w2);
|
|
|
|
|
|
|
|
const int index = ui->comboBoxAngle->findData(static_cast<unsigned char>(node.GetAngleType()));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxAngle->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->doubleSpinBoxSABefore->setValue(0);
|
|
|
|
ui->doubleSpinBoxSAAfter->setValue(0);
|
|
|
|
ui->comboBoxAngle->setCurrentIndex(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->doubleSpinBoxSABefore->blockSignals(false);
|
|
|
|
ui->doubleSpinBoxSAAfter->blockSignals(false);
|
|
|
|
ui->comboBoxAngle->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ReturnDefBefore()
|
|
|
|
{
|
|
|
|
SetCurrentSABefore(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ReturnDefAfter()
|
|
|
|
{
|
|
|
|
SetCurrentSAAfter(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ChangedSABefore(double d)
|
|
|
|
{
|
|
|
|
SetCurrentSABefore(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ChangedSAAfter(double d)
|
|
|
|
{
|
|
|
|
SetCurrentSAAfter(d);
|
|
|
|
}
|
|
|
|
|
2016-11-23 13:50:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitPathTypes()
|
|
|
|
{
|
2016-11-24 20:31:27 +01:00
|
|
|
ui->comboBoxType->addItem(tr("Custom seam allowance"), static_cast<int>(PiecePathType::CustomSeamAllowance));
|
2016-11-23 13:50:30 +01:00
|
|
|
//ui->comboBoxType->addItem(tr("Internal path"), static_cast<int>(PiecePathType::InternalPath));
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitNodesList()
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt();
|
|
|
|
#else
|
|
|
|
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ui->comboBoxNodes->blockSignals(true);
|
|
|
|
ui->comboBoxNodes->clear();
|
|
|
|
|
|
|
|
const VPiecePath path = CreatePath();
|
|
|
|
|
|
|
|
for (int i = 0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
const VPieceNode node = path.at(i);
|
|
|
|
if (node.GetTypeTool() == Tool::NodePoint)
|
|
|
|
{
|
|
|
|
const QString name = GetNodeName(node);
|
|
|
|
|
|
|
|
ui->comboBoxNodes->addItem(name, node.GetId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui->comboBoxNodes->blockSignals(false);
|
|
|
|
|
|
|
|
const int index = ui->comboBoxNodes->findData(id);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxNodes->setCurrentIndex(index);
|
|
|
|
NodeChanged(index);// Need in case combox index was not changed
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->comboBoxNodes->count() > 0 ? NodeChanged(0) : NodeChanged(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::NodeAngleChanged(int index)
|
|
|
|
{
|
|
|
|
const int i = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (i != -1 && index != -1)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const quint32 id = ui->comboBoxNodes->itemData(i).toUInt();
|
|
|
|
#else
|
|
|
|
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QListWidgetItem *rowItem = GetItemById(id);
|
|
|
|
if (rowItem)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->itemData(index).toUInt());
|
|
|
|
#else
|
|
|
|
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->currentData().toUInt());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
|
|
|
rowNode.SetAngleType(angle);
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-23 12:57:12 +01:00
|
|
|
VPiecePath DialogPiecePath::GetPiecePath() const
|
|
|
|
{
|
|
|
|
return CreatePath();
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-23 12:57:12 +01:00
|
|
|
void DialogPiecePath::SetPiecePath(const VPiecePath &path)
|
|
|
|
{
|
|
|
|
ui->listWidget->clear();
|
|
|
|
for (int i = 0; i < path.CountNodes(); ++i)
|
|
|
|
{
|
|
|
|
NewItem(path.at(i));
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:26:51 +01:00
|
|
|
SetType(path.GetType());
|
2016-11-28 09:42:37 +01:00
|
|
|
ui->lineEditName->setText(path.GetName());
|
2016-11-24 20:26:51 +01:00
|
|
|
|
2016-11-29 18:39:40 +01:00
|
|
|
VisToolPiecePath *visPath = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(visPath != nullptr);
|
|
|
|
visPath->SetPath(path);
|
|
|
|
|
2016-11-23 12:57:12 +01:00
|
|
|
ValidObjects(PathIsValid());
|
2016-11-22 12:04:34 +01:00
|
|
|
|
2016-11-23 12:57:12 +01:00
|
|
|
ListChanged();
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
|
2016-11-23 13:50:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
PiecePathType DialogPiecePath::GetType() const
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const PiecePathType type =
|
|
|
|
static_cast<PiecePathType>(ui->comboBoxType->itemData(ui->comboBoxType->currentIndex()).toInt());
|
|
|
|
#else
|
|
|
|
const PiecePathType type = static_cast<PiecePathType>(ui->comboBoxType->currentData().toInt());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetType(PiecePathType type)
|
|
|
|
{
|
|
|
|
const qint32 index = ui->comboBoxType->findData(static_cast<int>(type));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxType->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QListWidgetItem *DialogPiecePath::GetItemById(quint32 id)
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->item(i);
|
|
|
|
const VPieceNode node = qvariant_cast<VPieceNode>(item->data(Qt::UserRole));
|
|
|
|
|
|
|
|
if (node.GetId() == id)
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetCurrentSABefore(qreal value)
|
|
|
|
{
|
|
|
|
const int index = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
|
|
|
|
#else
|
|
|
|
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QListWidgetItem *rowItem = GetItemById(id);
|
|
|
|
if (rowItem)
|
|
|
|
{
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
|
|
|
rowNode.SetSABefore(value);
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetCurrentSAAfter(qreal value)
|
|
|
|
{
|
|
|
|
const int index = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
|
|
|
|
#else
|
|
|
|
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QListWidgetItem *rowItem = GetItemById(id);
|
|
|
|
if (rowItem)
|
|
|
|
{
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
|
|
|
rowNode.SetSAAfter(value);
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:41:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogPiecePath::GetPieceId() const
|
|
|
|
{
|
|
|
|
quint32 id = NULL_ID;
|
|
|
|
|
|
|
|
if (ui->comboBoxPiece->count() > 0)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
id = ui->comboBoxPiece->itemData(ui->comboBoxPiece->currentIndex()).toUInt();
|
|
|
|
#else
|
|
|
|
id = ui->comboBoxPiece->currentData().toUInt();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetPieceId(quint32 id)
|
|
|
|
{
|
|
|
|
if (ui->comboBoxPiece->count() <= 0)
|
|
|
|
{
|
|
|
|
const VPiece piece = data->GetPiece(id);
|
|
|
|
ui->comboBoxPiece->addItem(piece.GetName(), id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const qint32 index = ui->comboBoxPiece->findData(id);
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxType->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
2016-11-29 15:29:09 +01:00
|
|
|
|
|
|
|
ValidObjects(PathIsValid());
|
2016-11-23 17:41:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetSAWidth(qreal width)
|
|
|
|
{
|
|
|
|
if (width >=0)
|
|
|
|
{
|
2016-11-29 15:29:09 +01:00
|
|
|
ui->tabWidget->addTab(ui->tabSeamAllowance, tr("Seam allowance"));
|
|
|
|
ui->doubleSpinBoxSeams->setValue(width);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->tabWidget->removeTab(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:41:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetPiecesList(const QVector<quint32> &list)
|
|
|
|
{
|
|
|
|
for (int i=0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
const VPiece piece = data->GetPiece(list.at(i));
|
|
|
|
ui->comboBoxPiece->addItem(piece.GetName(), list.at(i));
|
|
|
|
}
|
|
|
|
ValidObjects(PathIsValid());
|
|
|
|
}
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-23 12:57:12 +01:00
|
|
|
VPiecePath DialogPiecePath::CreatePath() const
|
|
|
|
{
|
|
|
|
VPiecePath path;
|
|
|
|
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->item(i);
|
|
|
|
path.Append(qvariant_cast<VPieceNode>(item->data(Qt::UserRole)));
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
|
2016-11-24 20:26:51 +01:00
|
|
|
path.SetType(GetType());
|
2016-11-28 09:42:37 +01:00
|
|
|
path.SetName(ui->lineEditName->text());
|
2016-11-24 20:26:51 +01:00
|
|
|
|
2016-11-23 12:57:12 +01:00
|
|
|
return path;
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogPiecePath::PathIsValid() const
|
|
|
|
{
|
2016-11-23 12:57:12 +01:00
|
|
|
QString url = DialogWarningIcon();
|
|
|
|
|
|
|
|
if(CreatePath().PathPoints(data).count() < 2)
|
|
|
|
{
|
|
|
|
url += tr("You need more points!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-24 20:31:27 +01:00
|
|
|
if (GetType() == PiecePathType::CustomSeamAllowance && FirstPointEqualLast(ui->listWidget))
|
2016-11-23 12:57:12 +01:00
|
|
|
{
|
|
|
|
url += tr("First point cannot be equal to the last point!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (DoublePoints(ui->listWidget))
|
|
|
|
{
|
|
|
|
url += tr("You have double points!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 13:50:30 +01:00
|
|
|
|
2016-11-23 17:36:37 +01:00
|
|
|
if (not m_showMode && ui->comboBoxPiece->count() <= 0)
|
2016-11-23 13:50:30 +01:00
|
|
|
{
|
|
|
|
url += tr("List of pieces is empty!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
ui->helpLabel->setText(tr("Ready!"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ValidObjects(bool value)
|
|
|
|
{
|
|
|
|
flagError = value;
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::NewItem(const VPieceNode &node)
|
|
|
|
{
|
|
|
|
NewNodeItem(ui->listWidget, node);
|
|
|
|
}
|