2014-10-20 19:41:02 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialoglineintersectaxis.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 19 10, 2014
|
|
|
|
**
|
|
|
|
** @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) 2014 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialoglineintersectaxis.h"
|
|
|
|
#include "ui_dialoglineintersectaxis.h"
|
|
|
|
|
|
|
|
#include "../../geometry/vpointf.h"
|
|
|
|
#include "../../container/vcontainer.h"
|
|
|
|
#include "../../visualization/vistoollineintersectaxis.h"
|
|
|
|
#include "../../widgets/vmaingraphicsscene.h"
|
|
|
|
#include "../../tools/vabstracttool.h"
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
2015-02-03 09:45:27 +01:00
|
|
|
:DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersectAxis), formulaAngle(QString()),
|
|
|
|
formulaBaseHeightAngle(0), line(nullptr)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
InitVariables(ui);
|
|
|
|
InitFormulaUI(ui);
|
|
|
|
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
|
|
|
|
labelEditNamePoint = ui->labelEditNamePoint;
|
|
|
|
this->formulaBaseHeightAngle = ui->plainTextEditFormula->height();
|
2014-10-29 19:00:38 +01:00
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
2014-10-20 19:41:02 +02:00
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
flagFormula = false;
|
|
|
|
CheckState();
|
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxAxisPoint);
|
|
|
|
FillComboBoxPoints(ui->comboBoxFirstLinePoint);
|
|
|
|
FillComboBoxPoints(ui->comboBoxSecondLinePoint);
|
2015-01-29 16:47:02 +01:00
|
|
|
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
|
2015-02-02 12:10:02 +01:00
|
|
|
FillComboBoxLineColors(ui->comboBoxLineColor);
|
2014-10-20 19:41:02 +02:00
|
|
|
|
|
|
|
connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::PutAngle);
|
|
|
|
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogLineIntersectAxis::PutVal);
|
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersectAxis::NamePointChanged);
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogLineIntersectAxis::AngleTextChanged);
|
|
|
|
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::DeployAngleTextEdit);
|
|
|
|
connect(timerFormula, &QTimer::timeout, this, &DialogLineIntersectAxis::EvalAngle);
|
2014-11-08 16:04:14 +01:00
|
|
|
connect(ui->comboBoxFirstLinePoint,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogLineIntersectAxis::PointNameChanged);
|
|
|
|
connect(ui->comboBoxSecondLinePoint,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogLineIntersectAxis::PointNameChanged);
|
|
|
|
connect(ui->comboBoxAxisPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogLineIntersectAxis::PointNameChanged);
|
2014-10-20 19:41:02 +02:00
|
|
|
|
|
|
|
line = new VisToolLineIntersectAxis(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogLineIntersectAxis::~DialogLineIntersectAxis()
|
|
|
|
{
|
2014-12-26 14:56:07 +01:00
|
|
|
if (qApp->getCurrentScene()->items().contains(line))
|
|
|
|
{ // In some cases scene delete object yourself. If not make check program will crash.
|
|
|
|
delete line;
|
|
|
|
}
|
2014-10-20 19:41:02 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetPointName(const QString &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogLineIntersectAxis::GetTypeLine() const
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
return GetComboBoxCurrentData(ui->comboBoxLineType);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetTypeLine(const QString &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-02 12:55:42 +01:00
|
|
|
ChangeCurrentData(ui->comboBoxLineType, value);
|
2015-02-03 09:45:27 +01:00
|
|
|
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(value));
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogLineIntersectAxis::GetAngle() const
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
|
|
|
return qApp->FormulaFromUser(formulaAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetAngle(const QString &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
|
|
|
formulaAngle = qApp->FormulaToUser(value);
|
|
|
|
// increase height if needed. TODO : see if I can get the max number of caracters in one line
|
|
|
|
// of this PlainTextEdit to change 80 to this value
|
|
|
|
if (formulaAngle.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployAngleTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formulaAngle);
|
2015-02-03 11:17:04 +01:00
|
|
|
line->SetAngle(formulaAngle);
|
2014-10-29 14:40:56 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
quint32 DialogLineIntersectAxis::GetBasePointId() const
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxAxisPoint);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetBasePointId(const quint32 &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxAxisPoint, value);
|
2014-10-20 19:41:02 +02:00
|
|
|
line->setAxisPointId(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
quint32 DialogLineIntersectAxis::GetFirstPointId() const
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxFirstLinePoint);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetFirstPointId(const quint32 &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxFirstLinePoint, value);
|
2014-10-20 19:41:02 +02:00
|
|
|
line->setPoint1Id(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
quint32 DialogLineIntersectAxis::GetSecondPointId() const
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxSecondLinePoint);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetSecondPointId(const quint32 &value)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxSecondLinePoint, value);
|
2014-10-20 19:41:02 +02:00
|
|
|
line->setPoint2Id(value);
|
|
|
|
}
|
|
|
|
|
2015-02-03 10:27:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogLineIntersectAxis::GetLineColor() const
|
2015-02-03 10:27:33 +01:00
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
return GetComboBoxCurrentData(ui->comboBoxLineColor);
|
2015-02-03 10:27:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogLineIntersectAxis::SetLineColor(const QString &value)
|
2015-02-03 10:27:33 +01:00
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxLineColor, value);
|
|
|
|
}
|
|
|
|
|
2014-10-20 19:41:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (prepare)
|
|
|
|
{
|
|
|
|
if (click)
|
|
|
|
{
|
|
|
|
/*We will ignore click if poinet is in point circle*/
|
|
|
|
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
|
|
|
SCASSERT(scene != nullptr);
|
2015-02-03 11:17:04 +01:00
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
|
2014-10-20 19:41:02 +02:00
|
|
|
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
|
|
|
|
|
|
|
|
//Radius of point circle, but little bigger. Need handle with hover sizes.
|
|
|
|
qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
|
|
|
|
if (line.length() <= radius)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->setModal(true);
|
2015-02-03 11:17:04 +01:00
|
|
|
this->SetAngle(line->Angle());//Show in dialog angle what user choose
|
2014-10-20 19:41:02 +02:00
|
|
|
emit ToolTip("");
|
|
|
|
timerFormula->start();
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
|
|
|
{
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
|
|
|
switch (number)
|
|
|
|
{
|
|
|
|
case (0):
|
|
|
|
if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second point of line")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
line->VisualMode(id);
|
2014-10-25 16:05:30 +02:00
|
|
|
connect(line, &VisToolLineIntersectAxis::ToolTip, this, &DialogTool::ShowVisToolTip);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (1):
|
2014-11-08 16:49:59 +01:00
|
|
|
if (getCurrentObjectId(ui->comboBoxFirstLinePoint) != id)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2014-11-08 16:49:59 +01:00
|
|
|
if (SetObject(id, ui->comboBoxSecondLinePoint, tr("Select axis point")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
line->setPoint2Id(id);
|
|
|
|
line->RefreshGeometry();
|
|
|
|
}
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (2):
|
2014-11-08 16:49:59 +01:00
|
|
|
{
|
|
|
|
QSet<quint32> set;
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxFirstLinePoint));
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxSecondLinePoint));
|
|
|
|
set.insert(id);
|
|
|
|
|
|
|
|
if (set.size() == 3)
|
2014-10-20 19:41:02 +02:00
|
|
|
{
|
2014-11-08 16:49:59 +01:00
|
|
|
if (SetObject(id, ui->comboBoxAxisPoint, ""))
|
|
|
|
{
|
|
|
|
line->setAxisPointId(id);
|
|
|
|
line->RefreshGeometry();
|
|
|
|
prepare = true;
|
|
|
|
}
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
2014-11-08 16:49:59 +01:00
|
|
|
}
|
2014-10-20 19:41:02 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::PutAngle()
|
|
|
|
{
|
|
|
|
PutValHere(ui->plainTextEditFormula, ui->listWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::EvalAngle()
|
|
|
|
{
|
2014-10-24 16:23:41 +02:00
|
|
|
Eval(ui->plainTextEditFormula->toPlainText(), flagError, ui->labelResultCalculation, degreeSymbol, false);
|
2014-10-20 19:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::AngleTextChanged()
|
|
|
|
{
|
|
|
|
ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::DeployAngleTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
|
|
|
|
}
|
|
|
|
|
2014-11-08 16:04:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::PointNameChanged()
|
|
|
|
{
|
|
|
|
QSet<quint32> set;
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxFirstLinePoint));
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxSecondLinePoint));
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxAxisPoint));
|
|
|
|
|
|
|
|
QColor color = okColor;
|
|
|
|
if (set.size() != 3)
|
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
|
|
|
color = okColor;
|
|
|
|
}
|
|
|
|
ChangeColor(ui->labelFirstLinePoint, color);
|
|
|
|
ChangeColor(ui->labelSecondLinePoint, color);
|
|
|
|
ChangeColor(ui->labelAxisPoint, color);
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2014-10-20 19:41:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::ShowVisualization()
|
|
|
|
{
|
|
|
|
if (prepare == false)
|
|
|
|
{
|
|
|
|
//TODO move to parent class!
|
|
|
|
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
|
|
|
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLineIntersectAxis::SetFactor);
|
|
|
|
scene->addItem(line);
|
|
|
|
line->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::SaveData()
|
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
|
|
|
|
|
|
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
|
|
|
formulaAngle.replace("\n", " ");
|
|
|
|
|
2015-02-03 11:17:04 +01:00
|
|
|
line->setPoint1Id(GetFirstPointId());
|
|
|
|
line->setPoint2Id(GetSecondPointId());
|
|
|
|
line->setAxisPointId(GetBasePointId());
|
|
|
|
line->SetAngle(formulaAngle);
|
|
|
|
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(GetTypeLine()));
|
2014-10-20 19:41:02 +02:00
|
|
|
line->RefreshGeometry();
|
|
|
|
}
|
2014-11-22 19:37:59 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLineIntersectAxis::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|