valentina/src/app/dialogs/tools/dialogspline.cpp

216 lines
7.0 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 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 <QPushButton>
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogSpline create dialog
* @param data container with data
* @param parent parent widget
*/
DialogSpline::DialogSpline(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogSpline), number(0), p1(0), p4(0), angle1(0), angle2(0),
kAsm1(1), kAsm2(1), kCurve(1)
{
2013-08-05 10:37:56 +02:00
ui->setupUi(this);
2014-03-06 14:28:46 +01:00
InitOkCansel(ui);
FillComboBoxPoints(ui->comboBoxP1);
FillComboBoxPoints(ui->comboBoxP4);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
DialogSpline::~DialogSpline()
{
2013-08-05 10:37:56 +02:00
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getP1 return id first point of spline
* @return id
*/
quint32 DialogSpline::getP1() const
{
return p1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @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-03-11 12:43:24 +01:00
void DialogSpline::ChoosedObject(quint32 id, const Valentina::Scenes &type)
{
2014-03-11 12:43:24 +01:00
if (type == Valentina::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
if (number == 0)
{
qint32 index = ui->comboBoxP1->findText(point->name());
if ( index != -1 )
{ // -1 for not found
2013-08-05 10:37:56 +02:00
ui->comboBoxP1->setCurrentIndex(index);
number++;
emit ToolTip(tr("Select last point of curve"));
2013-08-05 10:37:56 +02:00
return;
}
}
if (number == 1)
{
qint32 index = ui->comboBoxP4->findText(point->name());
if ( index != -1 )
{ // -1 for not found
2013-08-05 10:37:56 +02:00
ui->comboBoxP4->setCurrentIndex(index);
number = 0;
emit ToolTip("");
2013-08-05 10:37:56 +02:00
index = ui->comboBoxP1->currentIndex();
quint32 p1Id = qvariant_cast<quint32>(ui->comboBoxP1->itemData(index));
QPointF p1 = data->GeometricObject<const VPointF *>(p1Id)->toQPointF();
QPointF p4 = data->GeometricObject<const VPointF *>(id)->toQPointF();
2013-08-20 12:26:02 +02:00
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
2013-08-05 10:37:56 +02:00
}
if (isInitialized == false)
{
2013-08-05 10:37:56 +02:00
this->show();
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
void DialogSpline::DialogAccepted()
{
p1 = getCurrentObjectId(ui->comboBoxP1);
p4 = getCurrentObjectId(ui->comboBoxP4);
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();
emit DialogClosed(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setKCurve set coefficient curve
* @param value value. Can be >= 0.
*/
void DialogSpline::setKCurve(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kCurve = value;
ui->doubleSpinBoxKcurve->setValue(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setKAsm2 set second coefficient asymmetry
* @param value value. Can be >= 0.
*/
void DialogSpline::setKAsm2(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kAsm2 = value;
ui->doubleSpinBoxKasm2->setValue(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setKAsm1 set first coefficient asymmetry
* @param value value. Can be >= 0.
*/
void DialogSpline::setKAsm1(const qreal &value)
{
2013-08-05 10:37:56 +02:00
kAsm1 = value;
ui->doubleSpinBoxKasm1->setValue(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setAngle2 set second angle of spline
* @param value angle in degree
*/
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));
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setAngle1 set first angle of spline
* @param value angle in degree
*/
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));
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setP4 set id fourth point of spline
* @param value id
*/
void DialogSpline::setP4(const quint32 &value)
{
2013-08-05 10:37:56 +02:00
p4 = value;
ChangeCurrentData(ui->comboBoxP4, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setP1 set id first point of spline
* @param value id
*/
void DialogSpline::setP1(const quint32 &value)
{
2013-08-05 10:37:56 +02:00
p1 = value;
ChangeCurrentData(ui->comboBoxP1, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getP4 return id fourth point of spline
* @return id
*/
quint32 DialogSpline::getP4() const
{
return p4;
}