2014-10-23 10:38:57 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogcurveintersectaxis.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 21 10, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2014-10-23 10:38:57 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-10-23 10:38:57 +02:00
|
|
|
** <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 "dialogcurveintersectaxis.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <new>
|
2014-10-23 10:38:57 +02:00
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
|
|
|
#include "../vwidgets/vabstractmainwindow.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../../visualization/line/vistoolcurveintersectaxis.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../visualization/visualization.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../support/dialogeditwrongformula.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vmisc/vcommonsettings.h"
|
|
|
|
#include "ui_dialogcurveintersectaxis.h"
|
2015-04-29 19:46:53 +02:00
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
2017-03-29 12:09:49 +02:00
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogCurveIntersectAxis),
|
|
|
|
formulaAngle(),
|
|
|
|
formulaBaseHeightAngle(0),
|
|
|
|
m_firstRelease(false)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
ui->lineEditNamePoint->setClearButtonEnabled(true);
|
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
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-23 10:38:57 +02:00
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
flagFormula = false;
|
2017-03-31 10:54:05 +02:00
|
|
|
DialogTool::CheckState();
|
2014-10-23 10:38:57 +02:00
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxAxisPoint);
|
|
|
|
FillComboBoxCurves(ui->comboBoxCurve);
|
2017-05-16 12:07:53 +02:00
|
|
|
FillComboBoxTypeLine(ui->comboBoxLineType, LineStylesPics());
|
2015-02-02 12:10:02 +01:00
|
|
|
FillComboBoxLineColors(ui->comboBoxLineColor);
|
2014-10-23 10:38:57 +02:00
|
|
|
|
2015-04-29 19:46:53 +02:00
|
|
|
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::FXAngle);
|
2014-10-23 10:38:57 +02:00
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCurveIntersectAxis::NamePointChanged);
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCurveIntersectAxis::AngleTextChanged);
|
|
|
|
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::DeployAngleTextEdit);
|
|
|
|
connect(timerFormula, &QTimer::timeout, this, &DialogCurveIntersectAxis::EvalAngle);
|
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolCurveIntersectAxis(data);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogCurveIntersectAxis::~DialogCurveIntersectAxis()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCurveIntersectAxis::SetPointName(const QString &value)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCurveIntersectAxis::GetTypeLine() const
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2016-10-17 13:53:46 +02:00
|
|
|
return GetComboBoxCurrentData(ui->comboBoxLineType, TypeLineLine);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCurveIntersectAxis::SetTypeLine(const QString &value)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2015-02-02 12:55:42 +01:00
|
|
|
ChangeCurrentData(ui->comboBoxLineType, value);
|
2017-05-16 12:07:53 +02:00
|
|
|
vis->setLineStyle(LineStyleToPenStyle(value));
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCurveIntersectAxis::GetAngle() const
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2016-03-05 16:27:07 +01:00
|
|
|
return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator());
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCurveIntersectAxis::SetAngle(const QString &value)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
|
2014-10-23 10:38:57 +02:00
|
|
|
// 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-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2015-02-03 11:17:04 +01:00
|
|
|
line->SetAngle(formulaAngle);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-10-29 14:40:56 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
quint32 DialogCurveIntersectAxis::GetBasePointId() const
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxAxisPoint);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCurveIntersectAxis::SetBasePointId(const quint32 &value)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentPointId(ui->comboBoxAxisPoint, value);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2014-10-23 10:38:57 +02:00
|
|
|
line->setAxisPointId(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogCurveIntersectAxis::getCurveId() const
|
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxCurve);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::setCurveId(const quint32 &value)
|
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentCurveId(ui->comboBoxCurve, value);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2016-01-24 17:15:08 +01:00
|
|
|
line->setObject1Id(value);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
2015-02-03 10:27:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCurveIntersectAxis::GetLineColor() const
|
2015-02-03 10:27:33 +01:00
|
|
|
{
|
2016-10-17 13:53:46 +02:00
|
|
|
return GetComboBoxCurrentData(ui->comboBoxLineColor, ColorBlack);
|
2015-02-03 10:27:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCurveIntersectAxis::SetLineColor(const QString &value)
|
2015-02-03 10:27:33 +01:00
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxLineColor, value);
|
|
|
|
}
|
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (prepare)
|
|
|
|
{
|
|
|
|
if (click)
|
|
|
|
{
|
2017-03-29 12:09:49 +02:00
|
|
|
// The check need to ignore first release of mouse button.
|
|
|
|
// User can select point by clicking on a label.
|
|
|
|
if (not m_firstRelease)
|
|
|
|
{
|
|
|
|
m_firstRelease = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
/*We will ignore click if poinet is in point circle*/
|
2015-05-12 17:15:10 +02:00
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2015-02-03 11:17:04 +01:00
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF line = QLineF(static_cast<QPointF>(*point), scene->getScenePos());
|
2014-10-23 10:38:57 +02:00
|
|
|
|
|
|
|
//Radius of point circle, but little bigger. Need handle with hover sizes.
|
2017-10-19 14:56:57 +02:00
|
|
|
if (line.length() <= ScaledRadius(SceneScale(qApp->getCurrentScene()))*1.5)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2015-02-03 11:17:04 +01:00
|
|
|
this->SetAngle(line->Angle());//Show in dialog angle what user choose
|
2014-10-23 10:38:57 +02:00
|
|
|
emit ToolTip("");
|
2015-07-03 21:22:52 +02:00
|
|
|
|
|
|
|
DialogAccepted();// Just set default values and don't show dialog
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
switch (number)
|
|
|
|
{
|
|
|
|
case (0):
|
2016-12-20 16:05:34 +01:00
|
|
|
if (type == SceneObject::Spline
|
|
|
|
|| type == SceneObject::Arc
|
|
|
|
|| type == SceneObject::ElArc
|
|
|
|
|| type == SceneObject::SplinePath)
|
2014-10-23 10:38:57 +02:00
|
|
|
{
|
|
|
|
if (SetObject(id, ui->comboBoxCurve, tr("Select axis point")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
line->VisualMode(id);
|
2016-07-26 12:45:17 +02:00
|
|
|
VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(window != nullptr)
|
2016-07-26 12:45:17 +02:00
|
|
|
connect(line, &VisToolCurveIntersectAxis::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
|
2016-07-26 14:32:55 +02:00
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (1):
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
|
|
|
if (SetObject(id, ui->comboBoxAxisPoint, ""))
|
|
|
|
{
|
|
|
|
line->setAxisPointId(id);
|
|
|
|
line->RefreshGeometry();
|
|
|
|
prepare = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::EvalAngle()
|
|
|
|
{
|
2014-10-24 16:23:41 +02:00
|
|
|
Eval(ui->plainTextEditFormula->toPlainText(), flagError, ui->labelResultCalculation, degreeSymbol, false);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::AngleTextChanged()
|
|
|
|
{
|
2016-03-05 13:30:18 +01:00
|
|
|
ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula, degreeSymbol);
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::DeployAngleTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
|
|
|
|
}
|
|
|
|
|
2015-04-29 19:46:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::FXAngle()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit angle"));
|
|
|
|
dialog->SetFormula(GetAngle());
|
2015-07-03 17:54:25 +02:00
|
|
|
dialog->setPostfix(degreeSymbol);
|
2015-04-29 19:46:53 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetAngle(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2014-10-23 10:38:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::ShowVisualization()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
AddVisualization<VisToolCurveIntersectAxis>();
|
2014-10-23 10:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::SaveData()
|
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
|
|
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
VisToolCurveIntersectAxis *line = qobject_cast<VisToolCurveIntersectAxis *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(line != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
line->setObject1Id(getCurveId());
|
2015-02-03 11:17:04 +01:00
|
|
|
line->setAxisPointId(GetBasePointId());
|
|
|
|
line->SetAngle(formulaAngle);
|
2017-05-16 12:07:53 +02:00
|
|
|
line->setLineStyle(LineStyleToPenStyle(GetTypeLine()));
|
2014-10-23 10:38:57 +02:00
|
|
|
line->RefreshGeometry();
|
|
|
|
}
|
2014-11-22 19:37:59 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCurveIntersectAxis::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|