2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file dialogspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @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) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
#include "dialogspline.h"
|
|
|
|
#include "ui_dialogspline.h"
|
|
|
|
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../../geometry/vpointf.h"
|
|
|
|
#include "../../container/vcontainer.h"
|
2014-08-18 16:42:53 +02:00
|
|
|
#include "../../visualization/vistoolspline.h"
|
2014-10-03 12:32:12 +02:00
|
|
|
#include <QDebug>
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogSpline create dialog
|
|
|
|
* @param data container with data
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2014-07-29 14:19:11 +02:00
|
|
|
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
2015-02-03 09:32:32 +01:00
|
|
|
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1),
|
2015-02-03 09:17:59 +01:00
|
|
|
kCurve(1), path(nullptr)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
ui->setupUi(this);
|
2014-08-18 16:42:53 +02:00
|
|
|
InitOkCancelApply(ui);
|
2013-12-21 12:36:51 +01:00
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxP1);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP4);
|
2015-02-02 12:10:02 +01:00
|
|
|
FillComboBoxLineColors(ui->comboBoxColor);
|
|
|
|
|
2014-07-14 17:57:12 +02:00
|
|
|
connect(ui->comboBoxP1, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogSpline::PointNameChanged);
|
|
|
|
connect(ui->comboBoxP4, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogSpline::PointNameChanged);
|
2014-08-18 16:42:53 +02:00
|
|
|
|
|
|
|
path = new VisToolSpline(data);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogSpline::~DialogSpline()
|
|
|
|
{
|
2014-12-26 14:56:07 +01:00
|
|
|
if (qApp->getCurrentScene()->items().contains(path))
|
|
|
|
{ // In some cases scene delete object yourself. If not make check program will crash.
|
|
|
|
delete path;
|
|
|
|
}
|
2013-08-05 10:37:56 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief getP1 return id first point of spline
|
|
|
|
* @return id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 DialogSpline::getP1() const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxP1);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
|
|
|
|
* @param id id of point or detail
|
|
|
|
* @param type type of object
|
|
|
|
*/
|
2014-07-15 16:42:41 +02:00
|
|
|
void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
if (type == SceneObject::Point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
switch (number)
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
case 0:
|
|
|
|
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
path->VisualMode(id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2014-11-09 11:57:49 +01:00
|
|
|
if (getCurrentObjectId(ui->comboBoxP1) != id)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id);
|
|
|
|
qint32 index = ui->comboBoxP4->findText(point->name());
|
|
|
|
if ( index != -1 )
|
|
|
|
{ // -1 for not found
|
|
|
|
ui->comboBoxP4->setCurrentIndex(index);
|
|
|
|
emit ToolTip("");
|
|
|
|
index = ui->comboBoxP1->currentIndex();
|
|
|
|
quint32 p1Id = qvariant_cast<quint32>(ui->comboBoxP1->itemData(index));
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2014-11-09 11:57:49 +01:00
|
|
|
QPointF p1 = data->GeometricObject<VPointF>(p1Id)->toQPointF();
|
|
|
|
QPointF p4 = data->GeometricObject<VPointF>(id)->toQPointF();
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2014-11-09 11:57:49 +01:00
|
|
|
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
|
|
|
|
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2014-11-09 11:57:49 +01:00
|
|
|
path->setPoint4Id(id);
|
|
|
|
path->RefreshGeometry();
|
|
|
|
prepare = true;
|
|
|
|
DialogAccepted();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"Can't find object by name"<<point->name();
|
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-08-17 20:49:29 +02:00
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-13 12:20:30 +02:00
|
|
|
void DialogSpline::SaveData()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
angle1 = ui->spinBoxAngle1->value();
|
|
|
|
angle2 = ui->spinBoxAngle2->value();
|
|
|
|
kAsm1 = ui->doubleSpinBoxKasm1->value();
|
|
|
|
kAsm2 = ui->doubleSpinBoxKasm2->value();
|
|
|
|
kCurve = ui->doubleSpinBoxKcurve->value();
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2015-02-03 09:17:59 +01:00
|
|
|
path->setPoint1Id(getP1());
|
|
|
|
path->setPoint4Id(getP4());
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setAngle1(angle1);
|
|
|
|
path->setAngle2(angle2);
|
|
|
|
path->setKAsm1(kAsm1);
|
|
|
|
path->setKAsm2(kAsm2);
|
|
|
|
path->setKCurve(kCurve);
|
|
|
|
path->RefreshGeometry();
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 17:57:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::PointNameChanged()
|
|
|
|
{
|
|
|
|
QSet<quint32> set;
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxP1));
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxP4));
|
|
|
|
|
2014-07-14 18:28:41 +02:00
|
|
|
QColor color = okColor;
|
2014-07-14 17:57:12 +02:00
|
|
|
if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
|
|
|
|
{
|
|
|
|
flagError = false;
|
2014-07-14 18:28:41 +02:00
|
|
|
color = errorColor;
|
2014-07-14 17:57:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
2014-07-14 18:28:41 +02:00
|
|
|
color = okColor;
|
2014-07-14 17:57:12 +02:00
|
|
|
}
|
2014-07-14 18:28:41 +02:00
|
|
|
ChangeColor(ui->labelFirstPoint, color);
|
|
|
|
ChangeColor(ui->labelSecondPoint, color);
|
2014-07-14 17:57:12 +02:00
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2014-07-15 16:28:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::UpdateList()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Does nothing. We redefine this slot because it is only one now way block update list of variable.
|
|
|
|
* This dialog doesn't work with formula. Don't delete. Help avoid crash.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2014-08-18 16:42:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::ShowVisualization()
|
|
|
|
{
|
|
|
|
if (prepare == false)
|
|
|
|
{
|
|
|
|
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
|
|
|
|
scene->addItem(path);
|
|
|
|
path->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setKCurve set coefficient curve
|
|
|
|
* @param value value. Can be >= 0.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSpline::setKCurve(const qreal &value)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
kCurve = value;
|
|
|
|
ui->doubleSpinBoxKcurve->setValue(value);
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setKCurve(kCurve);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2015-02-03 10:27:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSpline::getColor() const
|
|
|
|
{
|
|
|
|
return GetLineColor(ui->comboBoxColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::setColor(const QString &value)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxColor, value);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setKAsm2 set second coefficient asymmetry
|
|
|
|
* @param value value. Can be >= 0.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSpline::setKAsm2(const qreal &value)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
kAsm2 = value;
|
|
|
|
ui->doubleSpinBoxKasm2->setValue(value);
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setKAsm2(kAsm2);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setKAsm1 set first coefficient asymmetry
|
|
|
|
* @param value value. Can be >= 0.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSpline::setKAsm1(const qreal &value)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
kAsm1 = value;
|
|
|
|
ui->doubleSpinBoxKasm1->setValue(value);
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setKAsm1(kAsm1);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setAngle2 set second angle of spline
|
|
|
|
* @param value angle in degree
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSpline::setAngle2(const qreal &value)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
angle2 = value;
|
2013-08-20 12:26:02 +02:00
|
|
|
ui->spinBoxAngle2->setValue(static_cast<qint32>(value));
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setAngle2(angle2);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setAngle1 set first angle of spline
|
|
|
|
* @param value angle in degree
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSpline::setAngle1(const qreal &value)
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
angle1 = value;
|
2013-08-20 12:26:02 +02:00
|
|
|
ui->spinBoxAngle1->setValue(static_cast<qint32>(value));
|
2014-08-18 16:42:53 +02:00
|
|
|
path->setAngle1(angle1);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setP4 set id fourth point of spline
|
|
|
|
* @param value id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void DialogSpline::setP4(const quint32 &value)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxP4, value);
|
|
|
|
path->setPoint4Id(value);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setP1 set id first point of spline
|
|
|
|
* @param value id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void DialogSpline::setP1(const quint32 &value)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxP1, value);
|
|
|
|
path->setPoint1Id(value);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief getP4 return id fourth point of spline
|
|
|
|
* @return id
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 DialogSpline::getP4() const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxP4);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
2015-02-02 16:11:48 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getAngle1 return first angle of spline
|
|
|
|
* @return angle in degree
|
|
|
|
*/
|
|
|
|
qreal DialogSpline::getAngle1() const
|
|
|
|
{
|
|
|
|
return angle1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getAngle2 return second angle of spline
|
|
|
|
* @return angle in degree
|
|
|
|
*/
|
|
|
|
qreal DialogSpline::getAngle2() const
|
|
|
|
{
|
|
|
|
return angle2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getKAsm1 return first coefficient asymmetry
|
|
|
|
* @return value. Can be >= 0.
|
|
|
|
*/
|
|
|
|
qreal DialogSpline::getKAsm1() const
|
|
|
|
{
|
|
|
|
return kAsm1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getKAsm2 return second coefficient asymmetry
|
|
|
|
* @return value. Can be >= 0.
|
|
|
|
*/
|
|
|
|
qreal DialogSpline::getKAsm2() const
|
|
|
|
{
|
|
|
|
return kAsm2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getKCurve return coefficient curve
|
|
|
|
* @return value. Can be >= 0.
|
|
|
|
*/
|
|
|
|
qreal DialogSpline::getKCurve() const
|
|
|
|
{
|
|
|
|
return kCurve;
|
|
|
|
}
|