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 dialoglineintersect.cpp
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@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-07-31 13:34:39 +02:00
|
|
|
#include "dialoglineintersect.h"
|
|
|
|
#include "ui_dialoglineintersect.h"
|
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QPushButton>
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogLineIntersect::DialogLineIntersect(const VContainer *data, Draw::Draws mode, QWidget *parent)
|
|
|
|
:DialogTool(data, mode, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()),
|
|
|
|
p1Line1(0), p2Line1(0), p1Line2(0), p2Line2(0), flagPoint(true)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
ui->setupUi(this);
|
|
|
|
number = 0;
|
|
|
|
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
|
|
|
connect(bOk, &QPushButton::clicked, this, &DialogLineIntersect::DialogAccepted);
|
2013-10-06 18:22:21 +02:00
|
|
|
labelEditNamePoint = ui->labelEditNamePoint;
|
2013-07-31 13:34:39 +02:00
|
|
|
flagName = false;
|
|
|
|
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
|
|
|
connect(bCansel, &QPushButton::clicked, this, &DialogLineIntersect::DialogRejected);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP1Line1);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP2Line1);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP1Line2);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP2Line2);
|
|
|
|
|
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersect::NamePointChanged);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogLineIntersect::~DialogLineIntersect()
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2013-11-06 20:46:07 +01:00
|
|
|
void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
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-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-11-18 17:37:17 +01:00
|
|
|
point = data->GetPointModeling(id);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (number == 0)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
qint32 index = ui->comboBoxP1Line1->findText(point.name());
|
2013-11-04 21:35:15 +01:00
|
|
|
if ( index != -1 )
|
|
|
|
{ // -1 for not found
|
2013-07-31 13:34:39 +02:00
|
|
|
ui->comboBoxP1Line1->setCurrentIndex(index);
|
|
|
|
p1Line1 = id;
|
|
|
|
number++;
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip(tr("Select second point of first line"));
|
2013-07-31 13:34:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (number == 1)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
qint32 index = ui->comboBoxP2Line1->findText(point.name());
|
2013-11-04 21:35:15 +01:00
|
|
|
if ( index != -1 )
|
|
|
|
{ // -1 for not found
|
2013-07-31 13:34:39 +02:00
|
|
|
ui->comboBoxP2Line1->setCurrentIndex(index);
|
|
|
|
p2Line1 = id;
|
|
|
|
number++;
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip(tr("Select first point of second line"));
|
2013-07-31 13:34:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (number == 2)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
qint32 index = ui->comboBoxP1Line2->findText(point.name());
|
2013-11-04 21:35:15 +01:00
|
|
|
if ( index != -1 )
|
|
|
|
{ // -1 for not found
|
2013-07-31 13:34:39 +02:00
|
|
|
ui->comboBoxP1Line2->setCurrentIndex(index);
|
|
|
|
p1Line2 = id;
|
|
|
|
number++;
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip(tr("Select second point of second line"));
|
2013-07-31 13:34:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (number == 3)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
qint32 index = ui->comboBoxP2Line2->findText(point.name());
|
2013-11-04 21:35:15 +01:00
|
|
|
if ( index != -1 )
|
|
|
|
{ // -1 for not found
|
2013-07-31 13:34:39 +02:00
|
|
|
ui->comboBoxP2Line2->setCurrentIndex(index);
|
|
|
|
p2Line2 = id;
|
|
|
|
number = 0;
|
2013-10-07 13:11:56 +02:00
|
|
|
emit ToolTip("");
|
2013-07-31 13:34:39 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
if (isInitialized == false)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
flagPoint = CheckIntersecion();
|
|
|
|
CheckState();
|
|
|
|
this->show();
|
|
|
|
connect(ui->comboBoxP1Line1,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogLineIntersect::P1Line1Changed);
|
|
|
|
connect(ui->comboBoxP2Line1,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogLineIntersect::P2Line1Changed);
|
|
|
|
connect(ui->comboBoxP1Line2,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogLineIntersect::P1Line2Changed);
|
|
|
|
connect(ui->comboBoxP2Line2,
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
&DialogLineIntersect::P2Line2Changed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::DialogAccepted()
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
pointName = ui->lineEditNamePoint->text();
|
2013-12-18 12:13:32 +01:00
|
|
|
p1Line1 = getCurrentObjectId(ui->comboBoxP1Line1);
|
|
|
|
p2Line1 = getCurrentObjectId(ui->comboBoxP2Line1);
|
|
|
|
p1Line2 = getCurrentObjectId(ui->comboBoxP1Line2);
|
|
|
|
p2Line2 = getCurrentObjectId(ui->comboBoxP2Line2);
|
2013-07-31 13:34:39 +02:00
|
|
|
emit DialogClosed(QDialog::Accepted);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::P1Line1Changed( int index)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p1Line1 = qvariant_cast<qint64>(ui->comboBoxP1Line1->itemData(index));
|
|
|
|
flagPoint = CheckIntersecion();
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::P2Line1Changed(int index)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p2Line1 = qvariant_cast<qint64>(ui->comboBoxP2Line1->itemData(index));
|
|
|
|
flagPoint = CheckIntersecion();
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::P1Line2Changed(int index)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p1Line2 = qvariant_cast<qint64>(ui->comboBoxP1Line2->itemData(index));
|
|
|
|
flagPoint = CheckIntersecion();
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::P2Line2Changed(int index)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p2Line2 = qvariant_cast<qint64>(ui->comboBoxP2Line2->itemData(index));
|
|
|
|
flagPoint = CheckIntersecion();
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::CheckState()
|
|
|
|
{
|
2013-10-14 16:44:33 +02:00
|
|
|
Q_ASSERT(bOk != 0);
|
2013-09-12 15:25:24 +02:00
|
|
|
bOk->setEnabled(flagName && flagPoint);
|
2013-07-31 13:34:39 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
bool DialogLineIntersect::CheckIntersecion()
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
VPointF p1L1 = data->GetPoint(p1Line1);
|
|
|
|
VPointF p2L1 = data->GetPoint(p2Line1);
|
|
|
|
VPointF p1L2 = data->GetPoint(p1Line2);
|
|
|
|
VPointF p2L2 = data->GetPoint(p2Line2);
|
|
|
|
|
2013-08-15 22:39:00 +02:00
|
|
|
QLineF line1(p1L1.toQPointF(), p2L1.toQPointF());
|
|
|
|
QLineF line2(p1L2.toQPointF(), p2L2.toQPointF());
|
2013-07-31 13:34:39 +02:00
|
|
|
QPointF fPoint;
|
|
|
|
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
return true;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::setP2Line2(const qint64 &value)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p2Line2 = value;
|
|
|
|
ChangeCurrentData(ui->comboBoxP2Line2, value);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::setP1Line2(const qint64 &value)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p1Line2 = value;
|
|
|
|
ChangeCurrentData(ui->comboBoxP1Line2, value);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::setP2Line1(const qint64 &value)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p2Line1 = value;
|
|
|
|
ChangeCurrentData(ui->comboBoxP2Line1, value);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::setP1Line1(const qint64 &value)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
p1Line1 = value;
|
|
|
|
ChangeCurrentData(ui->comboBoxP1Line1, value);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void DialogLineIntersect::setPointName(const QString &value)
|
|
|
|
{
|
2013-07-31 13:34:39 +02:00
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|