2013-09-18 21:16:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Valentina project All Rights Reserved.
|
|
|
|
**
|
|
|
|
** This file is part of Valentina.
|
|
|
|
**
|
|
|
|
** Tox 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.
|
|
|
|
**
|
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-08-09 08:49:34 +02:00
|
|
|
#include "dialogsplinepath.h"
|
|
|
|
#include "ui_dialogsplinepath.h"
|
2013-11-06 18:06:00 +01:00
|
|
|
#include "../geometry/vsplinepoint.h"
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogSplinePath::DialogSplinePath(const VContainer *data, Draw::Draws mode, QWidget *parent)
|
|
|
|
:DialogTool(data, mode, parent), ui(new Ui::DialogSplinePath), path(VSplinePath())
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted);
|
|
|
|
|
|
|
|
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
|
|
|
connect(bCansel, &QPushButton::clicked, this, &DialogSplinePath::DialogRejected);
|
|
|
|
FillComboBoxPoints(ui->comboBoxPoint);
|
|
|
|
|
|
|
|
path = VSplinePath(data->DataPoints());
|
|
|
|
|
|
|
|
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChenged);
|
|
|
|
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogSplinePath::currentPointChanged);
|
|
|
|
connect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle1Changed);
|
|
|
|
connect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle2Changed);
|
|
|
|
connect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm1Changed);
|
|
|
|
connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm2Changed);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogSplinePath::~DialogSplinePath()
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::SetPath(const VSplinePath &value)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
this->path = value;
|
2013-11-04 21:35:15 +01:00
|
|
|
ui->listWidget->clear();
|
|
|
|
for (qint32 i = 0; i < path.CountPoint(); ++i)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
NewItem(path[i].P(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2());
|
|
|
|
}
|
|
|
|
ui->listWidget->setFocus(Qt::OtherFocusReason);
|
|
|
|
ui->doubleSpinBoxKcurve->setValue(path.getKCurve());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::ChoosedObject(qint64 id, Scene::Scenes type)
|
|
|
|
{
|
|
|
|
if (idDetail == 0 && mode == Draw::Modeling)
|
|
|
|
{
|
|
|
|
if (type == Scene::Detail)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
idDetail = id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (mode == Draw::Modeling)
|
|
|
|
{
|
|
|
|
if (CheckObject(id) == false)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (type == Scene::Point)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
NewItem(id, 1, 0, 1);
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip(tr("Select point of curve path"));
|
2013-08-09 08:49:34 +02:00
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::DialogAccepted()
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
path.Clear();
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
QListWidgetItem *item = ui->listWidget->item(i);
|
|
|
|
path.append( qvariant_cast<VSplinePoint>(item->data(Qt::UserRole)));
|
|
|
|
}
|
|
|
|
path.setKCurve(ui->doubleSpinBoxKcurve->value());
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip("");
|
2013-08-09 08:49:34 +02:00
|
|
|
emit DialogClosed(QDialog::Accepted);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::PointChenged(int row)
|
|
|
|
{
|
|
|
|
if (ui->listWidget->count() == 0)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QListWidgetItem *item = ui->listWidget->item( row );
|
|
|
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
|
|
|
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
|
|
|
|
EnableFields();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::currentPointChanged(int index)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
qint64 id = qvariant_cast<qint64>(ui->comboBoxPoint->itemData(index));
|
|
|
|
qint32 row = ui->listWidget->currentRow();
|
|
|
|
QListWidgetItem *item = ui->listWidget->item( row );
|
|
|
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
|
|
|
p.SetP(id);
|
|
|
|
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
|
|
|
|
EnableFields();
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(p));
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::Angle1Changed(int index)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
SetAngle(index+180);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::Angle2Changed(int index)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
SetAngle(index);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::KAsm1Changed(qreal d)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
qint32 row = ui->listWidget->currentRow();
|
|
|
|
QListWidgetItem *item = ui->listWidget->item( row );
|
|
|
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
|
|
|
p.SetKAsm1(d);
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(p));
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::KAsm2Changed(qreal d)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
qint32 row = ui->listWidget->currentRow();
|
|
|
|
QListWidgetItem *item = ui->listWidget->item( row );
|
|
|
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
|
|
|
p.SetKAsm2(d);
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(p));
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VPointF point;
|
2013-11-04 21:35:15 +01:00
|
|
|
if (mode == Draw::Calculation)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
point = data->GetPoint(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
point = data->GetModelingPoint(id);
|
|
|
|
}
|
2013-08-09 08:49:34 +02:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(point.name());
|
|
|
|
item->setFont(QFont("Times", 12, QFont::Bold));
|
|
|
|
VSplinePoint p(id, kAsm1, angle, kAsm2);
|
|
|
|
DataPoint(id, kAsm1, angle+180, kAsm2, angle);
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(p));
|
|
|
|
ui->listWidget->addItem(item);
|
|
|
|
EnableFields();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
disconnect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogSplinePath::currentPointChanged);
|
|
|
|
disconnect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle1Changed);
|
|
|
|
disconnect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle2Changed);
|
|
|
|
disconnect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm1Changed);
|
|
|
|
disconnect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm2Changed);
|
|
|
|
|
|
|
|
ChangeCurrentData(ui->comboBoxPoint, id);
|
|
|
|
ui->doubleSpinBoxKasm1->setValue(kAsm1);
|
|
|
|
ui->doubleSpinBoxKasm2->setValue(kAsm2);
|
2013-08-20 12:26:02 +02:00
|
|
|
ui->spinBoxAngle2->setValue(static_cast<qint32>(angle2));
|
|
|
|
ui->spinBoxAngle1->setValue(static_cast<qint32>(angle1));
|
2013-08-09 08:49:34 +02:00
|
|
|
|
|
|
|
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogSplinePath::currentPointChanged);
|
|
|
|
connect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle1Changed);
|
|
|
|
connect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::Angle2Changed);
|
|
|
|
connect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm1Changed);
|
|
|
|
connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
this, &DialogSplinePath::KAsm2Changed);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::EnableFields()
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
ui->doubleSpinBoxKasm1->setEnabled(true);
|
|
|
|
ui->spinBoxAngle1->setEnabled(true);
|
|
|
|
ui->doubleSpinBoxKasm2->setEnabled(true);
|
|
|
|
ui->spinBoxAngle2->setEnabled(true);
|
|
|
|
qint32 row = ui->listWidget->currentRow();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (row == 0)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
ui->doubleSpinBoxKasm1->setEnabled(false);
|
|
|
|
ui->spinBoxAngle1->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (row == ui->listWidget->count()-1)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
ui->doubleSpinBoxKasm2->setEnabled(false);
|
|
|
|
ui->spinBoxAngle2->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogSplinePath::SetAngle(qint32 angle)
|
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
qint32 row = ui->listWidget->currentRow();
|
|
|
|
QListWidgetItem *item = ui->listWidget->item( row );
|
|
|
|
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
|
|
|
|
p.SetAngle(angle);
|
|
|
|
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(p));
|
|
|
|
}
|