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

287 lines
10 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 "../vgeometry/vpointf.h"
#include "../vgeometry/vspline.h"
#include "../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)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), spl(), newDuplicate(-1)
{
2013-08-05 10:37:56 +02:00
ui->setupUi(this);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxP1);
FillComboBoxPoints(ui->comboBoxP4);
FillComboBoxLineColors(ui->comboBoxColor);
CheckState();
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);
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSpline::MouseLeftPressed);
connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSpline::MouseLeftReleased);
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
DialogSpline::~DialogSpline()
{
DeleteVisualization<VisToolSpline>();
2013-08-05 10:37:56 +02:00
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @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)
{
auto *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)
{
if (SetObject(id, ui->comboBoxP4, ""))
{
++number;
path->setObject4Id(id);
path->RefreshGeometry();
prepare = true;
}
}
break;
2014-08-17 20:49:29 +02:00
}
default:
break;
2013-08-05 10:37:56 +02:00
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SaveData()
{
const qreal angle1 = ui->spinBoxAngle1->value();
const qreal angle2 = ui->spinBoxAngle2->value();
const qreal kAsm1 = ui->doubleSpinBoxKasm1->value();
const qreal kAsm2 = ui->doubleSpinBoxKasm2->value();
const qreal kCurve = ui->doubleSpinBoxKcurve->value();
const quint32 d = spl.GetDuplicate();//Save previous value
spl = VSpline(*GetP1(), *GetP4(), angle1, angle2, kAsm1, kAsm2, kCurve);
newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast<quint32>(newDuplicate));
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject1Id(GetP1()->id());
path->setObject4Id(GetP4()->id());
2015-02-03 11:17:04 +01:00
path->SetAngle1(angle1);
path->SetAngle2(angle2);
path->SetKAsm1(kAsm1);
path->SetKAsm2(kAsm2);
path->SetKCurve(kCurve);
path->SetMode(Mode::Show);
path->RefreshGeometry();
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VPointF> DialogSpline::GetP1() const
{
return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
}
//---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VPointF> DialogSpline::GetP4() const
{
return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
}
//---------------------------------------------------------------------------------------------------------------------
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;
ui->lineEditSplineName->setText(tr("Invalid spline"));
}
else
{
flagError = true;
color = okColor;
if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() &&
getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id())
{
newDuplicate = -1;
ui->lineEditSplineName->setText(spl.name());
}
else
{
VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(), spl.GetKasm2(),
spl.GetKcurve());
if (not data->IsUnique(spline.name()))
{
newDuplicate = DNumber(spline.name());
spline.SetDuplicate(newDuplicate);
}
ui->lineEditSplineName->setText(spline.name());
}
}
ChangeColor(ui->labelName, color);
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowDialog(bool click)
{
if (prepare && click)
{
auto *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4(), ui->doubleSpinBoxKcurve->value());
ui->spinBoxAngle1->setValue(static_cast<qint32>(spl.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spl.GetEndAngle()));
ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2());
if (not data->IsUnique(spl.name()))
{
spl.SetDuplicate(DNumber(spl.name()));
}
ui->lineEditSplineName->setText(spl.name());
DialogAccepted();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowVisualization()
{
AddVisualization<VisToolSpline>();
}
//---------------------------------------------------------------------------------------------------------------------
VSpline DialogSpline::GetSpline() const
{
return spl;
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SetSpline(const VSpline &spline)
{
spl = spline;
2013-08-05 10:37:56 +02:00
setCurrentPointId(ui->comboBoxP1, spl.GetP1().id());
setCurrentPointId(ui->comboBoxP4, spl.GetP4().id());
ui->spinBoxAngle1->setValue(static_cast<qint32>(spl.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spl.GetEndAngle()));
ui->doubleSpinBoxKasm1->setValue(spl.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spl.GetKasm2());
ui->doubleSpinBoxKcurve->setValue(spl.GetKcurve());
ui->lineEditSplineName->setText(spl.name());
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject1Id(spl.GetP1().id());
path->setObject4Id(spl.GetP4().id());
path->SetAngle1(spl.GetStartAngle());
path->SetAngle2(spl.GetEndAngle());
path->SetKAsm1(spl.GetKasm1());
path->SetKAsm2(spl.GetKasm2());
path->SetKCurve(spl.GetKcurve());
2013-08-05 10:37:56 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogSpline::GetColor() const
{
return GetComboBoxCurrentData(ui->comboBoxColor);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::SetColor(const QString &value)
{
ChangeCurrentData(ui->comboBoxColor, value);
}