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-12-03 17:01:39 +01:00
|
|
|
#include "../../tools/vabstracttool.h"
|
2016-12-03 17:44:24 +01:00
|
|
|
#include "../../tools/vtoolseamallowance.h"
|
2017-01-21 14:24:40 +01:00
|
|
|
#include "../support/dialogeditwrongformula.h"
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
#include <QMenu>
|
2017-01-21 14:24:40 +01:00
|
|
|
#include <QTimer>
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent)
|
|
|
|
: DialogTool(data, toolId, parent),
|
2017-01-21 14:24:40 +01:00
|
|
|
ui(new Ui::DialogPiecePath),
|
|
|
|
m_showMode(false),
|
|
|
|
m_saWidth(0),
|
|
|
|
m_timerWidth(nullptr),
|
|
|
|
m_timerWidthBefore(nullptr),
|
|
|
|
m_timerWidthAfter(nullptr),
|
|
|
|
m_formulaBaseWidth(0),
|
|
|
|
m_formulaBaseWidthBefore(0),
|
|
|
|
m_formulaBaseWidthAfter(0)
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
InitOkCancel(ui);
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
InitPathTab();
|
|
|
|
InitSeamAllowanceTab();
|
2017-03-29 13:18:33 +02:00
|
|
|
InitPassmarksTab();
|
2016-11-23 13:50:30 +01:00
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
flagName = true;//We have default name of piece.
|
|
|
|
flagError = PathIsValid();
|
|
|
|
CheckState();
|
|
|
|
|
2016-11-29 15:29:09 +01:00
|
|
|
vis = new VisToolPiecePath(data);
|
2016-11-28 12:58:17 +01:00
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabSeamAllowance));
|
|
|
|
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabPassmarks));
|
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;
|
|
|
|
}
|
2016-12-03 18:18:58 +01:00
|
|
|
if (id != GetLastId())
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
2016-12-03 18:18:58 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SceneObject::Arc:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodeArc, reverse));
|
|
|
|
break;
|
2017-02-10 15:47:15 +01:00
|
|
|
case SceneObject::ElArc:
|
|
|
|
NewItem(VPieceNode(id, Tool::NodeElArc, reverse));
|
|
|
|
break;
|
2016-12-03 18:18:58 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ui->listWidget->count() > 1)
|
|
|
|
{
|
|
|
|
delete GetItemById(id);
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2016-12-03 18:18:58 +01:00
|
|
|
if (not qApp->getCurrentScene()->items().contains(visPath))
|
|
|
|
{
|
|
|
|
visPath->VisualMode(NULL_ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
visPath->RefreshGeometry();
|
|
|
|
}
|
2016-11-23 12:57:12 +01:00
|
|
|
}
|
|
|
|
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::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-12-03 17:44:24 +01:00
|
|
|
|
2017-01-13 15:06:03 +01:00
|
|
|
if (m_showMode)
|
|
|
|
{
|
|
|
|
VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(GetPieceId()));
|
|
|
|
SCASSERT(tool != nullptr);
|
|
|
|
auto visPath = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(visPath != nullptr);
|
|
|
|
visPath->setParentItem(tool);
|
|
|
|
}
|
2016-11-29 18:39:40 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 13:27:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormulaWidth->blockSignals(true);
|
|
|
|
ui->plainTextEditFormulaWidthBefore->blockSignals(true);
|
|
|
|
ui->plainTextEditFormulaWidthAfter->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-22 07:02:28 +01:00
|
|
|
QScopedPointer<QMenu> menu(new QMenu());
|
2016-11-22 12:04:34 +01:00
|
|
|
|
|
|
|
QListWidgetItem *rowItem = ui->listWidget->item(row);
|
|
|
|
SCASSERT(rowItem != nullptr);
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
QAction *actionPassmark = nullptr;
|
2016-11-22 12:04:34 +01:00
|
|
|
QAction *actionReverse = nullptr;
|
|
|
|
if (rowNode.GetTypeTool() != Tool::NodePoint)
|
|
|
|
{
|
|
|
|
actionReverse = menu->addAction(tr("Reverse"));
|
|
|
|
actionReverse->setCheckable(true);
|
|
|
|
actionReverse->setChecked(rowNode.GetReverse());
|
|
|
|
}
|
2017-03-29 13:18:33 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
actionPassmark = menu->addAction(tr("Passmark"));
|
|
|
|
actionPassmark->setCheckable(true);
|
|
|
|
actionPassmark->setChecked(rowNode.IsPassmark());
|
|
|
|
}
|
2016-11-22 12:04:34 +01:00
|
|
|
|
2016-12-03 18:51:25 +01:00
|
|
|
QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
|
|
|
|
2016-11-22 12:04:34 +01:00
|
|
|
QAction *selectedAction = menu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
|
|
|
|
if (selectedAction == actionDelete)
|
|
|
|
{
|
|
|
|
delete ui->listWidget->item(row);
|
|
|
|
}
|
2016-12-03 18:51:25 +01:00
|
|
|
else if (rowNode.GetTypeTool() != Tool::NodePoint && selectedAction == actionReverse)
|
2016-11-22 12:04:34 +01:00
|
|
|
{
|
|
|
|
rowNode.SetReverse(not rowNode.GetReverse());
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
2017-03-24 12:08:16 +01:00
|
|
|
rowItem->setText(GetNodeName(rowNode, true));
|
2017-03-29 13:18:33 +02:00
|
|
|
}
|
|
|
|
else if (selectedAction == actionPassmark)
|
|
|
|
{
|
|
|
|
rowNode.SetPassmark(not rowNode.IsPassmark());
|
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
rowItem->setText(GetNodeName(rowNode, true));
|
2016-11-22 12:04:34 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
ValidObjects(PathIsValid());
|
2016-11-22 12:04:34 +01:00
|
|
|
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
|
|
|
|
2017-03-30 13:12:23 +02:00
|
|
|
InitPassmarksList();
|
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)
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->plainTextEditFormulaWidthBefore->setDisabled(true);
|
|
|
|
ui->toolButtonExprBefore->setDisabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
ui->pushButtonDefBefore->setDisabled(true);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
ui->plainTextEditFormulaWidthAfter->setDisabled(true);
|
|
|
|
ui->toolButtonExprAfter->setDisabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
ui->pushButtonDefAfter->setDisabled(true);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
ui->comboBoxAngle->setDisabled(true);
|
|
|
|
|
|
|
|
ui->comboBoxAngle->blockSignals(true);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
const VPiecePath path = CreatePath();
|
2017-02-15 14:23:04 +01:00
|
|
|
const int nodeIndex = path.indexOfNode(CURRENT_DATA(ui->comboBoxNodes).toUInt());
|
2016-11-28 12:58:17 +01:00
|
|
|
if (nodeIndex != -1)
|
|
|
|
{
|
|
|
|
const VPieceNode &node = path.at(nodeIndex);
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
// Seam alowance before
|
|
|
|
ui->plainTextEditFormulaWidthBefore->setEnabled(true);
|
|
|
|
ui->toolButtonExprBefore->setEnabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
QString w1Formula = node.GetFormulaSABefore();
|
|
|
|
if (w1Formula != currentSeamAllowance)
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->pushButtonDefBefore->setEnabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
if (w1Formula.length() > 80)// increase height if needed.
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
this->DeployWidthBeforeFormulaTextEdit();
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
w1Formula = qApp->TrVars()->FormulaToUser(w1Formula, qApp->Settings()->GetOsSeparator());
|
|
|
|
ui->plainTextEditFormulaWidthBefore->setPlainText(w1Formula);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditFormulaWidthBefore);
|
|
|
|
|
|
|
|
// Seam alowance after
|
|
|
|
ui->plainTextEditFormulaWidthAfter->setEnabled(true);
|
|
|
|
ui->toolButtonExprAfter->setEnabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
QString w2Formula = node.GetFormulaSAAfter();
|
|
|
|
if (w2Formula != currentSeamAllowance)
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->pushButtonDefBefore->setEnabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
if (w2Formula.length() > 80)// increase height if needed.
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
this->DeployWidthAfterFormulaTextEdit();
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
w2Formula = qApp->TrVars()->FormulaToUser(w2Formula, qApp->Settings()->GetOsSeparator());
|
|
|
|
ui->plainTextEditFormulaWidthAfter->setPlainText(w2Formula);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditFormulaWidthAfter);
|
2016-11-28 12:58:17 +01:00
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
// Angle type
|
|
|
|
ui->comboBoxAngle->setEnabled(true);
|
2016-11-28 12:58:17 +01:00
|
|
|
const int index = ui->comboBoxAngle->findData(static_cast<unsigned char>(node.GetAngleType()));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxAngle->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->plainTextEditFormulaWidthBefore->setPlainText("");
|
|
|
|
ui->plainTextEditFormulaWidthAfter->setPlainText("");
|
2016-11-28 12:58:17 +01:00
|
|
|
ui->comboBoxAngle->setCurrentIndex(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->comboBoxAngle->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ReturnDefBefore()
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->plainTextEditFormulaWidthBefore->setPlainText(currentSeamAllowance);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::ReturnDefAfter()
|
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
ui->plainTextEditFormulaWidthAfter->setPlainText(currentSeamAllowance);
|
|
|
|
}
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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<VPieceNode>(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<VPieceNode>(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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::EvalWidth()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditWidth;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
const QString formula = ui->plainTextEditFormulaWidth->toPlainText();
|
2017-01-25 13:20:25 +01:00
|
|
|
m_saWidth = Eval(formula, flagFormula, ui->labelResultWidth, postfix, false, true);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
if (m_saWidth >= 0)
|
|
|
|
{
|
|
|
|
VContainer *locData = const_cast<VContainer *> (data);
|
|
|
|
locData->AddVariable(currentSeamAllowance, new VIncrement(locData, currentSeamAllowance, 0, m_saWidth,
|
|
|
|
QString().setNum(m_saWidth), true,
|
|
|
|
tr("Current seam aloowance")));
|
|
|
|
|
|
|
|
EvalWidthBefore();
|
|
|
|
EvalWidthAfter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::EvalWidthBefore()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditBefore;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
const QString formula = ui->plainTextEditFormulaWidthBefore->toPlainText();
|
|
|
|
bool flagFormula = false; // fake flag
|
2017-01-25 13:20:25 +01:00
|
|
|
Eval(formula, flagFormula, ui->labelResultBefore, postfix, false, true);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
UpdateNodeSABefore(GetFormulaSAWidthBefore());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::EvalWidthAfter()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditAfter;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
const QString formula = ui->plainTextEditFormulaWidthAfter->toPlainText();
|
|
|
|
bool flagFormula = false; // fake flag
|
2017-01-25 13:20:25 +01:00
|
|
|
Eval(formula, flagFormula, ui->labelResultAfter, postfix, false, true);
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
UpdateNodeSABefore(GetFormulaSAWidthAfter());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::FXWidth()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit seam allowance width"));
|
|
|
|
dialog->SetFormula(GetFormulaSAWidth());
|
|
|
|
dialog->setCheckLessThanZero(true);
|
|
|
|
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetFormulaSAWidth(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::FXWidthBefore()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit seam allowance width before"));
|
|
|
|
dialog->SetFormula(GetFormulaSAWidthBefore());
|
|
|
|
dialog->setCheckLessThanZero(true);
|
|
|
|
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetCurrentSABefore(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::FXWidthAfter()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit seam allowance width after"));
|
|
|
|
dialog->SetFormula(GetFormulaSAWidthAfter());
|
|
|
|
dialog->setCheckLessThanZero(true);
|
|
|
|
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetCurrentSAAfter(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::WidthChanged()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditWidth;
|
|
|
|
labelResultCalculation = ui->labelResultWidth;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidth, m_timerWidth, postfix);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::WidthBeforeChanged()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditBefore;
|
|
|
|
labelResultCalculation = ui->labelResultBefore;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
bool flagFormula = false;
|
|
|
|
ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
void DialogPiecePath::WidthAfterChanged()
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
labelEditFormula = ui->labelEditAfter;
|
|
|
|
labelResultCalculation = ui->labelResultAfter;
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
bool flagFormula = false;
|
|
|
|
ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
void DialogPiecePath::DeployWidthFormulaTextEdit()
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::DeployWidthBeforeFormulaTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormulaWidthBefore, ui->pushButtonGrowWidthBefore, m_formulaBaseWidthBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::DeployWidthAfterFormulaTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitPathTab()
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
ui->lineEditName->setClearButtonEnabled(true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FillComboBoxTypeLine(ui->comboBoxPenType, VAbstractTool::LineStylesPics());
|
|
|
|
|
|
|
|
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogPiecePath::NameChanged);
|
|
|
|
|
|
|
|
InitPathTypes();
|
|
|
|
connect(ui->comboBoxType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
ui->comboBoxPenType->setEnabled(GetType() == PiecePathType::InternalPath);
|
|
|
|
ValidObjects(PathIsValid());
|
|
|
|
});
|
|
|
|
|
|
|
|
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &DialogPiecePath::ShowContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitSeamAllowanceTab()
|
|
|
|
{
|
|
|
|
plainTextEditFormula = ui->plainTextEditFormulaWidth;
|
|
|
|
this->m_formulaBaseWidth = ui->plainTextEditFormulaWidth->height();
|
|
|
|
this->m_formulaBaseWidthBefore = ui->plainTextEditFormulaWidthBefore->height();
|
|
|
|
this->m_formulaBaseWidthAfter = ui->plainTextEditFormulaWidthAfter->height();
|
|
|
|
|
|
|
|
ui->plainTextEditFormulaWidth->installEventFilter(this);
|
|
|
|
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.
|
|
|
|
m_saWidth = UnitConvertor(1, Unit::Cm, qApp->patternUnit());
|
|
|
|
ui->plainTextEditFormulaWidth->setPlainText(qApp->LocaleToString(m_saWidth));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
InitNodeAngles(ui->comboBoxAngle);
|
|
|
|
connect(ui->comboBoxAngle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogPiecePath::NodeAngleChanged);
|
|
|
|
|
|
|
|
connect(ui->toolButtonExprWidth, &QPushButton::clicked, this, &DialogPiecePath::FXWidth);
|
|
|
|
connect(ui->toolButtonExprBefore, &QPushButton::clicked, this, &DialogPiecePath::FXWidthBefore);
|
|
|
|
connect(ui->toolButtonExprAfter, &QPushButton::clicked, this, &DialogPiecePath::FXWidthAfter);
|
|
|
|
|
|
|
|
connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPiecePath::WidthChanged);
|
|
|
|
connect(ui->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this,
|
|
|
|
&DialogPiecePath::WidthBeforeChanged);
|
|
|
|
connect(ui->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this,
|
|
|
|
&DialogPiecePath::WidthAfterChanged);
|
|
|
|
|
|
|
|
connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPiecePath::DeployWidthFormulaTextEdit);
|
|
|
|
connect(ui->pushButtonGrowWidthBefore, &QPushButton::clicked,
|
|
|
|
this, &DialogPiecePath::DeployWidthBeforeFormulaTextEdit);
|
|
|
|
connect(ui->pushButtonGrowWidthAfter, &QPushButton::clicked, this,
|
|
|
|
&DialogPiecePath::DeployWidthAfterFormulaTextEdit);
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitPassmarksTab()
|
|
|
|
{
|
|
|
|
InitPassmarksList();
|
|
|
|
connect(ui->comboBoxPassmarks, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogPiecePath::PassmarkChanged);
|
|
|
|
|
|
|
|
connect(ui->buttonGroupLineType, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
|
|
|
|
this, &DialogPiecePath::PassmarkLineTypeChanged);
|
|
|
|
connect(ui->buttonGroupAngleType, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
|
|
|
|
this, &DialogPiecePath::PassmarkAngleTypeChanged);
|
|
|
|
}
|
|
|
|
|
2016-11-23 13:50:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitPathTypes()
|
|
|
|
{
|
2016-12-03 17:01:39 +01:00
|
|
|
ui->comboBoxType->addItem(tr("Internal path"), static_cast<int>(PiecePathType::InternalPath));
|
2017-01-13 18:09:22 +01:00
|
|
|
ui->comboBoxType->addItem(tr("Custom seam allowance"), static_cast<int>(PiecePathType::CustomSeamAllowance));
|
2016-12-03 17:01:39 +01:00
|
|
|
|
|
|
|
ui->comboBoxPenType->setEnabled(GetType() == PiecePathType::InternalPath);
|
2016-11-23 13:50:30 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitNodesList()
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
const quint32 id = CURRENT_DATA(ui->comboBoxNodes).toUInt();
|
2016-11-28 12:58:17 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::InitPassmarksList()
|
|
|
|
{
|
|
|
|
const quint32 id = CURRENT_DATA(ui->comboBoxPassmarks).toUInt();
|
|
|
|
|
|
|
|
ui->comboBoxPassmarks->blockSignals(true);
|
|
|
|
ui->comboBoxPassmarks->clear();
|
|
|
|
|
|
|
|
const QVector<VPieceNode> nodes = GetListInternals<VPieceNode>(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::NodeAngleChanged(int index)
|
|
|
|
{
|
|
|
|
const int i = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (i != -1 && index != -1)
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
|
2016-11-28 12:58:17 +01:00
|
|
|
if (rowItem)
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(CURRENT_DATA(ui->comboBoxAngle).toUInt());
|
2016-11-28 12:58:17 +01:00
|
|
|
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-12-03 17:01:39 +01:00
|
|
|
SetPenType(path.GetPenType());
|
2016-11-29 18:39:40 +01:00
|
|
|
|
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
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
return static_cast<PiecePathType>(CURRENT_DATA(ui->comboBoxType).toInt());
|
2016-11-23 13:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetType(PiecePathType type)
|
|
|
|
{
|
|
|
|
const qint32 index = ui->comboBoxType->findData(static_cast<int>(type));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxType->setCurrentIndex(index);
|
|
|
|
}
|
2016-12-03 17:01:39 +01:00
|
|
|
|
|
|
|
ui->comboBoxPenType->setEnabled(type == PiecePathType::InternalPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Qt::PenStyle DialogPiecePath::GetPenType() const
|
|
|
|
{
|
|
|
|
return VAbstractTool::LineStyleToPenStyle(GetComboBoxCurrentData(ui->comboBoxPenType, TypeLineLine));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetPenType(const Qt::PenStyle &type)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxPenType, VAbstractTool::PenStyleToLineStyle(type));
|
|
|
|
vis->setLineStyle(type);
|
2016-11-23 13:50:30 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-03 18:18:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogPiecePath::GetLastId() const
|
|
|
|
{
|
|
|
|
const int count = ui->listWidget->count();
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->item(count-1);
|
|
|
|
const VPieceNode node = qvariant_cast<VPieceNode>(item->data(Qt::UserRole));
|
|
|
|
return node.GetId();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:58:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
void DialogPiecePath::SetCurrentSABefore(const QString &formula)
|
|
|
|
{
|
|
|
|
UpdateNodeSABefore(formula);
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetCurrentSAAfter(const QString &formula)
|
|
|
|
{
|
|
|
|
UpdateNodeSAAfter(formula);
|
|
|
|
ListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::UpdateNodeSABefore(const QString &formula)
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
|
|
|
const int index = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (index != -1)
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
|
2016-11-28 12:58:17 +01:00
|
|
|
if (rowItem)
|
|
|
|
{
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
2017-01-21 14:24:40 +01:00
|
|
|
rowNode.SetFormulaSABefore(formula);
|
2016-11-28 12:58:17 +01:00
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
void DialogPiecePath::UpdateNodeSAAfter(const QString &formula)
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
|
|
|
const int index = ui->comboBoxNodes->currentIndex();
|
|
|
|
if (index != -1)
|
|
|
|
{
|
2017-02-15 14:23:04 +01:00
|
|
|
QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
|
2016-11-28 12:58:17 +01:00
|
|
|
if (rowItem)
|
|
|
|
{
|
|
|
|
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
|
2017-01-21 14:24:40 +01:00
|
|
|
rowNode.SetFormulaSAAfter(formula);
|
2016-11-28 12:58:17 +01:00
|
|
|
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPiecePath::SetFormulaSAWidth(const QString &formula)
|
|
|
|
{
|
2017-03-29 13:18:33 +02:00
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
const QString width = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator());
|
|
|
|
// increase height if needed.
|
|
|
|
if (width.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployWidthFormulaTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormulaWidth->setPlainText(width);
|
|
|
|
|
|
|
|
VisToolPiecePath *path = qobject_cast<VisToolPiecePath *>(vis);
|
|
|
|
SCASSERT(path != nullptr)
|
|
|
|
path->SetPath(CreatePath());
|
|
|
|
|
2017-03-29 13:18:33 +02:00
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2017-01-21 14:24:40 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormulaWidth);
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:41:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogPiecePath::GetPieceId() const
|
|
|
|
{
|
2017-01-31 13:28:05 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxPiece);
|
2016-11-23 17:41:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2017-01-31 13:28:05 +01:00
|
|
|
ui->comboBoxPiece->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->comboBoxPiece->setCurrentIndex(0);
|
2016-11-23 17:41:01 +01:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-21 14:24:40 +01:00
|
|
|
QString DialogPiecePath::GetFormulaSAWidth() const
|
2016-11-28 12:58:17 +01:00
|
|
|
{
|
2017-01-21 14:24:40 +01:00
|
|
|
QString width = ui->plainTextEditFormulaWidth->toPlainText();
|
|
|
|
width.replace("\n", " ");
|
|
|
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
2016-11-28 12:58:17 +01:00
|
|
|
}
|
|
|
|
|
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-12-03 17:01:39 +01:00
|
|
|
path.SetPenType(GetType() == PiecePathType::InternalPath ? GetPenType() : Qt::SolidLine);
|
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
|
|
|
{
|
2017-01-13 15:06:39 +01:00
|
|
|
url += tr("First point of <b>custom seam allowance</b> cannot be equal to the last point!");
|
2016-11-23 12:57:12 +01:00
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (DoublePoints(ui->listWidget))
|
|
|
|
{
|
|
|
|
url += tr("You have double points!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-23 18:36:50 +01:00
|
|
|
else if (not EachPointLabelIsUnique(ui->listWidget))
|
|
|
|
{
|
|
|
|
url += tr("Each point in the path must be unique!");
|
|
|
|
ui->helpLabel->setText(url);
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-23 12:57:12 +01:00
|
|
|
}
|
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
|
|
|
{
|
2017-01-13 15:06:39 +01:00
|
|
|
url += tr("List of objects is empty!");
|
2016-11-23 13:50:30 +01:00
|
|
|
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);
|
|
|
|
}
|
2017-01-21 14:24:40 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogPiecePath::GetFormulaSAWidthBefore() const
|
|
|
|
{
|
|
|
|
QString width = ui->plainTextEditFormulaWidthBefore->toPlainText();
|
|
|
|
width.replace("\n", " ");
|
|
|
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogPiecePath::GetFormulaSAWidthAfter() const
|
|
|
|
{
|
|
|
|
QString width = ui->plainTextEditFormulaWidthAfter->toPlainText();
|
|
|
|
width.replace("\n", " ");
|
|
|
|
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
|
|
|
|
}
|