2016-03-18 22:11:14 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogcubicbezierpath.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 18 3, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-03-18 22:11:14 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-03-18 22:11:14 +01:00
|
|
|
**
|
|
|
|
** 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 "dialogcubicbezierpath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QVector>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
#include "../../tools/vabstracttool.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../visualization/path/vistoolcubicbezierpath.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../visualization/visualization.h"
|
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-07-26 12:45:17 +02:00
|
|
|
#include "../vwidgets/vabstractmainwindow.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "dialogtool.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "ui_dialogcubicbezierpath.h"
|
|
|
|
|
|
|
|
class QWidget;
|
2016-03-18 22:11:14 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-02-11 12:25:27 +01:00
|
|
|
DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, quint32 toolId, QWidget *parent)
|
2016-03-18 22:11:14 +01:00
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogCubicBezierPath),
|
|
|
|
path(),
|
2019-02-11 12:25:27 +01:00
|
|
|
newDuplicate(-1),
|
|
|
|
flagError(false)
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
bOk->setEnabled(false);
|
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxPoint);
|
|
|
|
FillComboBoxLineColors(ui->comboBoxColor);
|
2017-05-16 12:07:53 +02:00
|
|
|
FillComboBoxTypeLine(ui->comboBoxPenStyle, CurvePenStylesPics());
|
2016-03-18 22:11:14 +01:00
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
|
|
|
|
|
2016-03-18 22:11:14 +01:00
|
|
|
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogCubicBezierPath::PointChanged);
|
2018-01-12 14:25:20 +01:00
|
|
|
connect(ui->comboBoxPoint, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2016-03-18 22:11:14 +01:00
|
|
|
this, &DialogCubicBezierPath::currentPointChanged);
|
|
|
|
|
2020-11-04 13:50:58 +01:00
|
|
|
connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogCubicBezierPath::ValidateAlias);
|
|
|
|
|
2016-03-18 22:11:14 +01:00
|
|
|
vis = new VisToolCubicBezierPath(data);
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
SetTabStopDistance(ui->plainTextEditToolNotes);
|
2016-03-18 22:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogCubicBezierPath::~DialogCubicBezierPath()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezierPath DialogCubicBezierPath::GetPath() const
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value)
|
|
|
|
{
|
|
|
|
this->path = value;
|
|
|
|
ui->listWidget->blockSignals(true);
|
|
|
|
ui->listWidget->clear();
|
|
|
|
for (qint32 i = 0; i < path.CountPoints(); ++i)
|
|
|
|
{
|
|
|
|
NewItem(path.at(i));
|
|
|
|
}
|
|
|
|
ui->listWidget->setFocus(Qt::OtherFocusReason);
|
2017-04-11 12:42:42 +02:00
|
|
|
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name()));
|
2017-10-11 12:51:06 +02:00
|
|
|
ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale());
|
|
|
|
|
2020-11-04 13:50:58 +01:00
|
|
|
ui->lineEditAlias->setText(path.GetAliasSuffix());
|
|
|
|
ValidateAlias();
|
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle());
|
|
|
|
ChangeCurrentData(ui->comboBoxColor, path.GetColor());
|
2016-03-18 22:11:14 +01:00
|
|
|
|
|
|
|
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visPath != nullptr)
|
2016-03-18 22:11:14 +01:00
|
|
|
visPath->setPath(path);
|
|
|
|
ui->listWidget->blockSignals(false);
|
2016-03-19 15:29:26 +01:00
|
|
|
|
|
|
|
if (ui->listWidget->count() > 0)
|
|
|
|
{
|
|
|
|
ui->listWidget->setCurrentRow(0);
|
|
|
|
}
|
2020-05-30 17:14:50 +02:00
|
|
|
|
|
|
|
ValidatePath();
|
2016-03-18 22:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
2016-03-19 15:20:09 +01:00
|
|
|
if (AllPathBackboneIds().contains(id))
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto point = data->GeometricObject<VPointF>(id);
|
|
|
|
NewItem(*point);
|
|
|
|
|
|
|
|
SavePath();
|
|
|
|
|
|
|
|
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visPath != nullptr)
|
2016-03-18 22:11:14 +01:00
|
|
|
visPath->setPath(path);
|
|
|
|
|
|
|
|
if (path.CountPoints() == 1)
|
|
|
|
{
|
|
|
|
visPath->VisualMode(NULL_ID);
|
2016-07-26 12:45:17 +02:00
|
|
|
VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(window != nullptr)
|
2016-07-26 12:45:17 +02:00
|
|
|
connect(visPath, &VisToolCubicBezierPath::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
|
2016-03-18 22:11:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
visPath->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (click == false)
|
|
|
|
{
|
2016-03-19 15:20:09 +01:00
|
|
|
const int size = path.CountPoints();
|
|
|
|
if (size >= 7)
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
2016-03-19 15:20:09 +01:00
|
|
|
if (size - VCubicBezierPath::SubSplPointsCount(path.CountSubSpl()) == 0)
|
2016-03-18 22:11:14 +01:00
|
|
|
{// Accept only if all subpaths are completed
|
2018-03-14 15:01:24 +01:00
|
|
|
emit ToolTip(QString());
|
2016-03-18 22:11:14 +01:00
|
|
|
|
|
|
|
if (not data->IsUnique(path.name()))
|
|
|
|
{
|
|
|
|
path.SetDuplicate(DNumber(path.name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogAccepted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::ShowVisualization()
|
|
|
|
{
|
|
|
|
AddVisualization<VisToolCubicBezierPath>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::SaveData()
|
|
|
|
{
|
|
|
|
const quint32 d = path.GetDuplicate();//Save previous value
|
|
|
|
SavePath();
|
|
|
|
newDuplicate <= -1 ? path.SetDuplicate(d) : path.SetDuplicate(static_cast<quint32>(newDuplicate));
|
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
path.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine));
|
|
|
|
path.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack));
|
|
|
|
path.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value());
|
2020-11-04 13:50:58 +01:00
|
|
|
path.SetAliasSuffix(ui->lineEditAlias->text());
|
2017-10-11 12:51:06 +02:00
|
|
|
|
2016-03-18 22:11:14 +01:00
|
|
|
auto visPath = qobject_cast<VisToolCubicBezierPath *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(visPath != nullptr)
|
2016-03-18 22:11:14 +01:00
|
|
|
visPath->setPath(path);
|
|
|
|
visPath->SetMode(Mode::Show);
|
|
|
|
visPath->RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::PointChanged(int row)
|
|
|
|
{
|
|
|
|
if (ui->listWidget->count() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto p = qvariant_cast<VPointF>(ui->listWidget->item(row)->data(Qt::UserRole));
|
|
|
|
DataPoint(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::currentPointChanged(int index)
|
|
|
|
{
|
|
|
|
const quint32 id = qvariant_cast<quint32>(ui->comboBoxPoint->itemData(index));
|
|
|
|
|
2019-11-07 17:07:07 +01:00
|
|
|
try
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
2019-11-07 17:07:07 +01:00
|
|
|
QListWidgetItem *item = ui->listWidget->item( ui->listWidget->currentRow() );
|
|
|
|
const auto point = data->GeometricObject<VPointF>(id);
|
|
|
|
DataPoint(*point);
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(*point));
|
2016-03-18 22:11:14 +01:00
|
|
|
|
2020-05-30 17:14:50 +02:00
|
|
|
ValidatePath();
|
2016-03-18 22:11:14 +01:00
|
|
|
}
|
2019-11-07 17:07:07 +01:00
|
|
|
catch (const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
flagError = false;
|
2020-05-30 17:14:50 +02:00
|
|
|
ChangeColor(ui->labelName, errorColor);
|
|
|
|
ChangeColor(ui->labelPoint, errorColor);
|
2019-11-07 17:07:07 +01:00
|
|
|
|
|
|
|
ui->lineEditSplPathName->setText(tr("Cannot find point with id %1").arg(id));
|
|
|
|
}
|
2016-03-18 22:11:14 +01:00
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2020-11-04 13:50:58 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::ValidateAlias()
|
|
|
|
{
|
|
|
|
VCubicBezierPath tempPath = path;
|
|
|
|
tempPath.SetAliasSuffix(ui->lineEditAlias->text());
|
|
|
|
if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(tempPath.GetAlias()))
|
|
|
|
{
|
|
|
|
flagAlias = false;
|
|
|
|
ChangeColor(ui->labelAlias, errorColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagAlias = true;
|
|
|
|
ChangeColor(ui->labelAlias, OkColor(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2016-03-18 22:11:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::NewItem(const VPointF &point)
|
|
|
|
{
|
2018-05-07 13:32:17 +02:00
|
|
|
auto* item = new QListWidgetItem(point.name());
|
2018-04-08 18:45:23 +02:00
|
|
|
item->setFont(NodeFont(item->font()));
|
2016-03-18 22:11:14 +01:00
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(point));
|
|
|
|
|
|
|
|
ui->listWidget->addItem(item);
|
|
|
|
ui->listWidget->setCurrentItem(item);
|
|
|
|
if (ui->listWidget->count() >= 7)
|
|
|
|
{
|
|
|
|
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
bOk->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataPoint(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::DataPoint(const VPointF &p)
|
|
|
|
{
|
|
|
|
ui->comboBoxPoint->blockSignals(true);
|
|
|
|
ChangeCurrentData(ui->comboBoxPoint, p.id());
|
|
|
|
ui->comboBoxPoint->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::SavePath()
|
|
|
|
{
|
|
|
|
path.Clear();
|
|
|
|
path = ExtractPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-19 15:20:09 +01:00
|
|
|
QSet<quint32> DialogCubicBezierPath::AllPathBackboneIds() const
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
|
|
|
QVector<quint32> points;
|
|
|
|
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
points.append(qvariant_cast<VPointF>(ui->listWidget->item(i)->data(Qt::UserRole)).id());
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<quint32> ids;
|
2016-03-19 15:20:09 +01:00
|
|
|
const qint32 count = VCubicBezierPath::CountSubSpl(points.size());// Count subpaths
|
|
|
|
for (qint32 i = 1; i <= count; ++i)
|
2016-03-18 22:11:14 +01:00
|
|
|
{
|
2016-03-19 15:20:09 +01:00
|
|
|
const qint32 base = VCubicBezierPath::SubSplOffset(i);
|
2016-03-18 22:11:14 +01:00
|
|
|
ids.insert(points.at(base));// The first subpath's point
|
|
|
|
ids.insert(points.at(base + 3));// The last subpath's point
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogCubicBezierPath::IsPathValid() const
|
|
|
|
{
|
|
|
|
if (path.CountPoints() < 7)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 15:20:09 +01:00
|
|
|
return (AllPathBackboneIds().size() == path.CountSubSpl() + 1);
|
2016-03-18 22:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezierPath DialogCubicBezierPath::ExtractPath() const
|
|
|
|
{
|
|
|
|
QVector<VPointF> points;
|
|
|
|
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
points.append(qvariant_cast<VPointF>(ui->listWidget->item(i)->data(Qt::UserRole)));
|
|
|
|
}
|
|
|
|
return VCubicBezierPath(points);
|
|
|
|
}
|
2020-05-30 17:14:50 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::ValidatePath()
|
|
|
|
{
|
|
|
|
QColor color;
|
|
|
|
|
|
|
|
if (not IsPathValid())
|
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
|
|
|
|
ui->lineEditSplPathName->setText(tr("Invalid spline path"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
|
|
|
color = OkColor(this);
|
|
|
|
|
|
|
|
auto first = qvariant_cast<VPointF>(ui->listWidget->item(0)->data(Qt::UserRole));
|
|
|
|
auto last = qvariant_cast<VPointF>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));
|
|
|
|
|
|
|
|
if (first.id() == path.at(0).id() && last.id() == path.at(path.CountPoints()-1).id())
|
|
|
|
{
|
|
|
|
newDuplicate = -1;
|
|
|
|
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VCubicBezierPath newPath = ExtractPath();
|
|
|
|
|
|
|
|
if (not data->IsUnique(newPath.name()))
|
|
|
|
{
|
|
|
|
newDuplicate = static_cast<qint32>(DNumber(newPath.name()));
|
|
|
|
newPath.SetDuplicate(static_cast<quint32>(newDuplicate));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(newPath.name()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChangeColor(ui->labelName, color);
|
|
|
|
ChangeColor(ui->labelPoint, color);
|
|
|
|
}
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCubicBezierPath::SetNotes(const QString ¬es)
|
|
|
|
{
|
|
|
|
ui->plainTextEditToolNotes->setPlainText(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCubicBezierPath::GetNotes() const
|
|
|
|
{
|
|
|
|
return ui->plainTextEditToolNotes->toPlainText();
|
|
|
|
}
|