valentina/src/libs/vtools/dialogs/tools/dialogspline.cpp

368 lines
12 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file dialogspline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
**
** @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-2015 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/>.
**
*************************************************************************/
2013-08-05 10:37:56 +02:00
#include "dialogspline.h"
#include "ui_dialogspline.h"
#include "../../libs/vgeometry/vpointf.h"
#include "../../libs/vpatterndb/vcontainer.h"
#include "../../visualization/vistoolspline.h"
#include <QDebug>
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogSpline create dialog
* @param data container with data
* @param parent parent widget
*/
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),
kCurve(1)
{
2013-08-05 10:37:56 +02:00
ui->setupUi(this);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxP1);
FillComboBoxPoints(ui->comboBoxP4);
FillComboBoxLineColors(ui->comboBoxColor);
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);
vis = new VisToolSpline(data);
FixateSize();
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
DialogSpline::~DialogSpline()
{
DeleteVisualization<VisToolSpline>();
2013-08-05 10:37:56 +02:00
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetP1 return id first point of spline
* @return id
*/
2015-02-03 11:17:04 +01:00
quint32 DialogSpline::GetP1() const
{
return getCurrentObjectId(ui->comboBoxP1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @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
*/
void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
switch (number)
2014-08-17 20:49:29 +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
{
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));
QPointF p1 = data->GeometricObject<VPointF>(p1Id)->toQPointF();
QPointF p4 = data->GeometricObject<VPointF>(id)->toQPointF();
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
path->setPoint4Id(id);
path->RefreshGeometry();
prepare = true;
DialogAccepted();
}
else
{
qWarning()<<"Can't find object by name"<<point->name();
}
}
break;
2014-08-17 20:49:29 +02:00
}
default:
break;
2013-08-05 10:37:56 +02:00
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SaveData()
{
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();
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->setPoint1Id(GetP1());
path->setPoint4Id(GetP4());
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
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::PointNameChanged()
{
QSet<quint32> set;
set.insert(getCurrentObjectId(ui->comboBoxP1));
set.insert(getCurrentObjectId(ui->comboBoxP4));
QColor color = okColor;
if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
{
flagError = false;
color = errorColor;
}
else
{
flagError = true;
color = okColor;
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowVisualization()
{
AddVisualization<VisToolSpline>();
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetKCurve set coefficient curve
* @param value value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
void DialogSpline::SetKCurve(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kCurve = value;
ui->doubleSpinBoxKcurve->setValue(value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->SetKCurve(kCurve);
2013-08-05 10:37:56 +02:00
}
2015-02-03 10:27:33 +01:00
//---------------------------------------------------------------------------------------------------------------------
2015-02-03 11:17:04 +01:00
QString DialogSpline::GetColor() const
2015-02-03 10:27:33 +01:00
{
2015-02-03 11:17:04 +01:00
return GetComboBoxCurrentData(ui->comboBoxColor);
2015-02-03 10:27:33 +01:00
}
//---------------------------------------------------------------------------------------------------------------------
2015-02-03 11:17:04 +01:00
void DialogSpline::SetColor(const QString &value)
2015-02-03 10:27:33 +01:00
{
ChangeCurrentData(ui->comboBoxColor, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetKAsm2 set second coefficient asymmetry
* @param value value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
void DialogSpline::SetKAsm2(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kAsm2 = value;
ui->doubleSpinBoxKasm2->setValue(value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->SetKAsm2(kAsm2);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetKAsm1 set first coefficient asymmetry
* @param value value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
void DialogSpline::SetKAsm1(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kAsm1 = value;
ui->doubleSpinBoxKasm1->setValue(value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->SetKAsm1(kAsm1);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetAngle2 set second angle of spline
* @param value angle in degree
*/
2015-02-03 11:17:04 +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));
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->SetAngle2(angle2);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetAngle1 set first angle of spline
* @param value angle in degree
*/
2015-02-03 11:17:04 +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));
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
2015-02-03 11:17:04 +01:00
path->SetAngle1(angle1);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetP4 set id fourth point of spline
* @param value id
*/
2015-02-03 11:17:04 +01:00
void DialogSpline::SetP4(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP4, value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setPoint4Id(value);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetP1 set id first point of spline
* @param value id
*/
2015-02-03 11:17:04 +01:00
void DialogSpline::SetP1(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP1, value);
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setPoint1Id(value);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetP4 return id fourth point of spline
* @return id
*/
2015-02-03 11:17:04 +01:00
quint32 DialogSpline::GetP4() const
{
return getCurrentObjectId(ui->comboBoxP4);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetAngle1 return first angle of spline
* @return angle in degree
*/
2015-02-03 11:17:04 +01:00
qreal DialogSpline::GetAngle1() const
{
return angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetAngle2 return second angle of spline
* @return angle in degree
*/
2015-02-03 11:17:04 +01:00
qreal DialogSpline::GetAngle2() const
{
return angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetKAsm1 return first coefficient asymmetry
* @return value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
qreal DialogSpline::GetKAsm1() const
{
return kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetKAsm2 return second coefficient asymmetry
* @return value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
qreal DialogSpline::GetKAsm2() const
{
return kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetKCurve return coefficient curve
* @return value. Can be >= 0.
*/
2015-02-03 11:17:04 +01:00
qreal DialogSpline::GetKCurve() const
{
return kCurve;
}