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 dialogspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)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
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/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-08-05 10:37:56 +02:00
|
|
|
#include "dialogspline.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QColor>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
#include "../../tools/vabstracttool.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../visualization/visualization.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../../visualization/path/vistoolspline.h"
|
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
|
|
|
#include "../support/dialogeditwrongformula.h"
|
2015-10-08 20:11:50 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
2016-02-12 19:10:01 +01:00
|
|
|
#include "../vgeometry/vspline.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vmisc/vcommonsettings.h"
|
2015-10-08 20:11:50 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
|
|
|
#include "ui_dialogspline.h"
|
|
|
|
#include "vtranslatevars.h"
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogSpline create dialog
|
|
|
|
* @param data container with data
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2019-02-11 12:25:27 +01:00
|
|
|
DialogSpline::DialogSpline(const VContainer *data, quint32 toolId, QWidget *parent)
|
2016-02-25 20:23:16 +01:00
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogSpline),
|
|
|
|
spl(),
|
|
|
|
newDuplicate(-1),
|
|
|
|
formulaBaseHeightAngle1(0),
|
|
|
|
formulaBaseHeightAngle2(0),
|
|
|
|
formulaBaseHeightLength1(0),
|
|
|
|
formulaBaseHeightLength2(0),
|
|
|
|
timerAngle1(new QTimer(this)),
|
|
|
|
timerAngle2(new QTimer(this)),
|
|
|
|
timerLength1(new QTimer(this)),
|
|
|
|
timerLength2(new QTimer(this)),
|
|
|
|
flagAngle1(false),
|
|
|
|
flagAngle2(false),
|
|
|
|
flagLength1(false),
|
2019-02-11 12:25:27 +01:00
|
|
|
flagLength2(false),
|
|
|
|
flagError(false)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
ui->setupUi(this);
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height();
|
|
|
|
formulaBaseHeightAngle2 = ui->plainTextEditAngle2F->height();
|
|
|
|
formulaBaseHeightLength1 = ui->plainTextEditLength1F->height();
|
|
|
|
formulaBaseHeightLength2 = ui->plainTextEditLength2F->height();
|
|
|
|
|
|
|
|
ui->plainTextEditAngle1F->installEventFilter(this);
|
|
|
|
ui->plainTextEditAngle2F->installEventFilter(this);
|
|
|
|
ui->plainTextEditLength1F->installEventFilter(this);
|
|
|
|
ui->plainTextEditLength2F->installEventFilter(this);
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
timerAngle1->setSingleShot(true);
|
|
|
|
timerAngle2->setSingleShot(true);
|
|
|
|
timerLength1->setSingleShot(true);
|
|
|
|
timerLength2->setSingleShot(true);
|
|
|
|
|
2016-02-25 20:23:16 +01:00
|
|
|
connect(timerAngle1, &QTimer::timeout, this, &DialogSpline::EvalAngle1);
|
|
|
|
connect(timerAngle2, &QTimer::timeout, this, &DialogSpline::EvalAngle2);
|
|
|
|
connect(timerLength1, &QTimer::timeout, this, &DialogSpline::EvalLength1);
|
|
|
|
connect(timerLength2, &QTimer::timeout, this, &DialogSpline::EvalLength2);
|
|
|
|
|
2014-08-18 16:42:53 +02:00
|
|
|
InitOkCancelApply(ui);
|
2013-12-21 12:36:51 +01:00
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxP1);
|
|
|
|
FillComboBoxPoints(ui->comboBoxP4);
|
2015-02-02 12:10:02 +01:00
|
|
|
FillComboBoxLineColors(ui->comboBoxColor);
|
2017-05-16 12:07:53 +02:00
|
|
|
FillComboBoxTypeLine(ui->comboBoxPenStyle, CurvePenStylesPics());
|
2015-02-02 12:10:02 +01:00
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
|
|
|
|
|
2019-07-24 15:45:22 +02:00
|
|
|
connect(ui->comboBoxP1, &QComboBox::currentTextChanged,
|
2014-07-14 17:57:12 +02:00
|
|
|
this, &DialogSpline::PointNameChanged);
|
2019-07-24 15:45:22 +02:00
|
|
|
connect(ui->comboBoxP4, &QComboBox::currentTextChanged,
|
2014-07-14 17:57:12 +02:00
|
|
|
this, &DialogSpline::PointNameChanged);
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2016-02-25 20:23:16 +01:00
|
|
|
connect(ui->toolButtonExprAngle1, &QPushButton::clicked, this, &DialogSpline::FXAngle1);
|
|
|
|
connect(ui->toolButtonExprAngle2, &QPushButton::clicked, this, &DialogSpline::FXAngle2);
|
|
|
|
connect(ui->toolButtonExprLength1, &QPushButton::clicked, this, &DialogSpline::FXLength1);
|
|
|
|
connect(ui->toolButtonExprLength2, &QPushButton::clicked, this, &DialogSpline::FXLength2);
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
connect(ui->plainTextEditAngle1F, &QPlainTextEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
timerAngle1->start(formulaTimerTimeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->plainTextEditAngle2F, &QPlainTextEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
timerAngle2->start(formulaTimerTimeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->plainTextEditLength1F, &QPlainTextEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
timerLength1->start(formulaTimerTimeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->plainTextEditLength2F, &QPlainTextEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
timerLength2->start(formulaTimerTimeout);
|
|
|
|
});
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
connect(ui->pushButtonGrowAngle1, &QPushButton::clicked, this, &DialogSpline::DeployAngle1TextEdit);
|
|
|
|
connect(ui->pushButtonGrowAngle2, &QPushButton::clicked, this, &DialogSpline::DeployAngle2TextEdit);
|
|
|
|
connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSpline::DeployLength1TextEdit);
|
|
|
|
connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSpline::DeployLength2TextEdit);
|
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolSpline(data);
|
2016-02-12 19:10:01 +01:00
|
|
|
auto path = qobject_cast<VisToolSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2016-02-12 19:10:01 +01:00
|
|
|
|
|
|
|
auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2016-02-12 19:10:01 +01:00
|
|
|
connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSpline::MouseLeftPressed);
|
|
|
|
connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSpline::MouseLeftReleased);
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
SetTabStopDistance(ui->plainTextEditToolNotes);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogSpline::~DialogSpline()
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2014-07-15 16:42:41 +02:00
|
|
|
void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
if (type == SceneObject::Point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-12 19:10:01 +01:00
|
|
|
auto *path = qobject_cast<VisToolSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-08-18 16:42:53 +02:00
|
|
|
switch (number)
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2014-08-18 16:42:53 +02:00
|
|
|
case 0:
|
|
|
|
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
|
|
|
|
{
|
2016-02-12 19:10:01 +01:00
|
|
|
++number;
|
2014-08-18 16:42:53 +02:00
|
|
|
path->VisualMode(id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2014-11-09 11:57:49 +01:00
|
|
|
if (getCurrentObjectId(ui->comboBoxP1) != id)
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
if (SetObject(id, ui->comboBoxP4, QString()))
|
2016-02-12 19:10:01 +01:00
|
|
|
{
|
|
|
|
++number;
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
path->setObject4Id(id);
|
2014-11-09 11:57:49 +01:00
|
|
|
path->RefreshGeometry();
|
|
|
|
prepare = true;
|
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-08-17 20:49:29 +02:00
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-13 12:20:30 +02:00
|
|
|
void DialogSpline::SaveData()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-15 15:30:48 +01:00
|
|
|
const quint32 d = spl.GetDuplicate();//Save previous value
|
2016-02-25 20:23:16 +01:00
|
|
|
spl = CurrentSpline();
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2016-02-16 13:00:56 +01:00
|
|
|
newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast<quint32>(newDuplicate));
|
2016-02-15 15:30:48 +01:00
|
|
|
|
2016-02-13 22:39:47 +01:00
|
|
|
auto path = qobject_cast<VisToolSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2016-02-15 10:02:55 +01:00
|
|
|
path->setObject1Id(GetP1()->id());
|
|
|
|
path->setObject4Id(GetP4()->id());
|
2016-02-25 20:23:16 +01:00
|
|
|
path->SetAngle1(spl.GetStartAngle());
|
|
|
|
path->SetAngle2(spl.GetEndAngle());
|
|
|
|
path->SetKAsm1(spl.GetKasm1());
|
|
|
|
path->SetKAsm2(spl.GetKasm2());
|
|
|
|
path->SetKCurve(spl.GetKcurve());
|
2017-10-11 12:51:06 +02:00
|
|
|
path->setApproximationScale(spl.GetApproximationScale());
|
2016-02-13 22:39:47 +01:00
|
|
|
path->SetMode(Mode::Show);
|
2014-08-18 16:42:53 +02:00
|
|
|
path->RefreshGeometry();
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2016-02-25 20:23:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditAngle1F->blockSignals(true);
|
|
|
|
ui->plainTextEditAngle2F->blockSignals(true);
|
|
|
|
ui->plainTextEditLength1F->blockSignals(true);
|
|
|
|
ui->plainTextEditLength2F->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::DeployAngle1TextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::DeployAngle2TextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::DeployLength1TextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::DeployLength2TextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::FXAngle1()
|
|
|
|
{
|
2018-05-07 13:32:17 +02:00
|
|
|
auto* dialog = new DialogEditWrongFormula(data, toolId, this);
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->setWindowTitle(tr("Edit first control point angle"));
|
2016-03-05 16:27:07 +01:00
|
|
|
QString angle1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->SetFormula(angle1F);
|
2016-08-26 18:20:03 +02:00
|
|
|
dialog->setPostfix(degreeSymbol);
|
2016-02-25 20:23:16 +01:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
// increase height if needed.
|
|
|
|
if (angle1F.length() > 80)
|
|
|
|
{
|
|
|
|
DeployAngle1TextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditAngle1F->setPlainText(angle1F);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditAngle1F);
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::FXAngle2()
|
|
|
|
{
|
2018-05-07 13:32:17 +02:00
|
|
|
auto* dialog = new DialogEditWrongFormula(data, toolId, this);
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->setWindowTitle(tr("Edit second control point angle"));
|
2016-03-05 16:27:07 +01:00
|
|
|
QString angle2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->SetFormula(angle2F);
|
2016-08-26 18:20:03 +02:00
|
|
|
dialog->setPostfix(degreeSymbol);
|
2016-02-25 20:23:16 +01:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
// increase height if needed.
|
|
|
|
if (angle2F.length() > 80)
|
|
|
|
{
|
|
|
|
DeployAngle1TextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditAngle2F->setPlainText(angle2F);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditAngle2F);
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::FXLength1()
|
|
|
|
{
|
2018-05-07 13:32:17 +02:00
|
|
|
auto* dialog = new DialogEditWrongFormula(data, toolId, this);
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->setWindowTitle(tr("Edit first control point length"));
|
2016-03-05 16:27:07 +01:00
|
|
|
QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->SetFormula(length1F);
|
2020-10-15 17:05:21 +02:00
|
|
|
dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true));
|
2016-02-25 20:23:16 +01:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
// increase height if needed.
|
|
|
|
if (length1F.length() > 80)
|
|
|
|
{
|
|
|
|
DeployLength1TextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditLength1F->setPlainText(length1F);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditLength1F);
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::FXLength2()
|
|
|
|
{
|
2018-05-07 13:32:17 +02:00
|
|
|
auto* dialog = new DialogEditWrongFormula(data, toolId, this);
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->setWindowTitle(tr("Edit second control point length"));
|
2016-03-05 16:27:07 +01:00
|
|
|
QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
dialog->SetFormula(length2F);
|
2020-10-15 17:05:21 +02:00
|
|
|
dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true));
|
2016-02-25 20:23:16 +01:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
// increase height if needed.
|
|
|
|
if (length2F.length() > 80)
|
|
|
|
{
|
|
|
|
DeployLength2TextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditLength2F->setPlainText(length2F);
|
|
|
|
MoveCursorToEnd(ui->plainTextEditLength2F);
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2016-02-15 10:02:55 +01: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));
|
|
|
|
}
|
|
|
|
|
2016-02-25 20:23:16 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::EvalAngle1()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
FormulaData formulaData;
|
|
|
|
formulaData.formula = ui->plainTextEditAngle1F->toPlainText();
|
|
|
|
formulaData.variables = data->DataVariables();
|
|
|
|
formulaData.labelEditFormula = ui->labelEditAngle1;
|
|
|
|
formulaData.labelResult = ui->labelResultAngle1;
|
|
|
|
formulaData.postfix = degreeSymbol;
|
|
|
|
formulaData.checkZero = false;
|
|
|
|
|
|
|
|
Eval(formulaData, flagAngle1);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::EvalAngle2()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
FormulaData formulaData;
|
|
|
|
formulaData.formula = ui->plainTextEditAngle2F->toPlainText();
|
|
|
|
formulaData.variables = data->DataVariables();
|
|
|
|
formulaData.labelEditFormula = ui->labelEditAngle2;
|
|
|
|
formulaData.labelResult = ui->labelResultAngle2;
|
|
|
|
formulaData.postfix = degreeSymbol;
|
|
|
|
formulaData.checkZero = false;
|
|
|
|
|
|
|
|
Eval(formulaData, flagAngle2);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::EvalLength1()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
FormulaData formulaData;
|
|
|
|
formulaData.formula = ui->plainTextEditLength1F->toPlainText();
|
|
|
|
formulaData.variables = data->DataVariables();
|
|
|
|
formulaData.labelEditFormula = ui->labelEditLength1;
|
|
|
|
formulaData.labelResult = ui->labelResultLength1;
|
2020-10-15 17:05:21 +02:00
|
|
|
formulaData.postfix = UnitsToStr(qApp->patternUnits(), true);
|
2019-02-11 12:25:27 +01:00
|
|
|
formulaData.checkZero = false;
|
|
|
|
formulaData.checkLessThanZero = true;
|
|
|
|
|
|
|
|
Eval(formulaData, flagLength1);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::EvalLength2()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
FormulaData formulaData;
|
|
|
|
formulaData.formula = ui->plainTextEditLength2F->toPlainText();
|
|
|
|
formulaData.variables = data->DataVariables();
|
|
|
|
formulaData.labelEditFormula = ui->labelEditLength2;
|
|
|
|
formulaData.labelResult = ui->labelResultLength2;
|
2020-10-15 17:05:21 +02:00
|
|
|
formulaData.postfix = UnitsToStr(qApp->patternUnits(), true);
|
2019-02-11 12:25:27 +01:00
|
|
|
formulaData.checkZero = false;
|
|
|
|
formulaData.checkLessThanZero = true;
|
|
|
|
|
|
|
|
Eval(formulaData, flagLength2);
|
2016-02-25 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSpline DialogSpline::CurrentSpline() const
|
|
|
|
{
|
|
|
|
QString angle1F = ui->plainTextEditAngle1F->toPlainText();
|
|
|
|
QString angle2F = ui->plainTextEditAngle2F->toPlainText();
|
|
|
|
QString length1F = ui->plainTextEditLength1F->toPlainText();
|
|
|
|
QString length2F = ui->plainTextEditLength2F->toPlainText();
|
|
|
|
|
2017-08-04 19:29:43 +02:00
|
|
|
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
|
2016-02-25 20:23:16 +01:00
|
|
|
|
2017-10-23 09:45:58 +02:00
|
|
|
const qreal angle1 = Visualization::FindValFromUser(angle1F, vars);
|
|
|
|
const qreal angle2 = Visualization::FindValFromUser(angle2F, vars);
|
|
|
|
const qreal length1 = Visualization::FindLengthFromUser(length1F, vars);
|
|
|
|
const qreal length2 = Visualization::FindLengthFromUser(length2F, vars);
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
const bool separator = qApp->Settings()->GetOsSeparator();
|
|
|
|
|
2016-03-05 16:27:07 +01:00
|
|
|
angle1F = qApp->TrVars()->TryFormulaFromUser(angle1F, separator);
|
|
|
|
angle2F = qApp->TrVars()->TryFormulaFromUser(angle2F, separator);
|
|
|
|
length1F = qApp->TrVars()->TryFormulaFromUser(length1F, separator);
|
|
|
|
length2F = qApp->TrVars()->TryFormulaFromUser(length2F, separator);
|
2016-02-25 20:23:16 +01:00
|
|
|
|
2016-02-27 15:49:10 +01:00
|
|
|
VSpline spline(*GetP1(), *GetP4(), angle1, angle1F, angle2, angle2F, length1, length1F, length2, length2F);
|
2017-10-11 12:51:06 +02:00
|
|
|
spline.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value());
|
|
|
|
spline.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine));
|
|
|
|
spline.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack));
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
return spline;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:57:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::PointNameChanged()
|
|
|
|
{
|
|
|
|
QSet<quint32> set;
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxP1));
|
|
|
|
set.insert(getCurrentObjectId(ui->comboBoxP4));
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
QColor color;
|
2014-07-14 17:57:12 +02:00
|
|
|
if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
|
|
|
|
{
|
|
|
|
flagError = false;
|
2014-07-14 18:28:41 +02:00
|
|
|
color = errorColor;
|
2016-02-15 15:30:48 +01:00
|
|
|
|
2016-02-16 13:00:56 +01:00
|
|
|
ui->lineEditSplineName->setText(tr("Invalid spline"));
|
2014-07-14 17:57:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
2019-02-11 12:25:27 +01:00
|
|
|
color = OkColor(this);
|
2016-02-15 15:30:48 +01:00
|
|
|
|
|
|
|
if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() &&
|
|
|
|
getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id())
|
|
|
|
{
|
|
|
|
newDuplicate = -1;
|
2017-04-11 12:42:42 +02:00
|
|
|
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
|
2016-02-15 15:30:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-07 17:07:07 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
VSpline spline(*GetP1(), *GetP4(), spl.GetStartAngle(), spl.GetEndAngle(), spl.GetKasm1(),
|
|
|
|
spl.GetKasm2(), spl.GetKcurve());
|
|
|
|
if (not data->IsUnique(spline.name()))
|
|
|
|
{
|
|
|
|
newDuplicate = static_cast<qint32>(DNumber(spline.name()));
|
|
|
|
spline.SetDuplicate(static_cast<quint32>(newDuplicate));
|
|
|
|
}
|
|
|
|
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name()));
|
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &)
|
2016-02-15 15:30:48 +01:00
|
|
|
{
|
2019-11-07 17:07:07 +01:00
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
2016-02-15 15:30:48 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 17:57:12 +02:00
|
|
|
}
|
2016-02-16 13:00:56 +01:00
|
|
|
ChangeColor(ui->labelName, color);
|
2014-07-14 18:28:41 +02:00
|
|
|
ChangeColor(ui->labelFirstPoint, color);
|
|
|
|
ChangeColor(ui->labelSecondPoint, color);
|
2014-07-14 17:57:12 +02:00
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (prepare && click)
|
|
|
|
{
|
|
|
|
auto *path = qobject_cast<VisToolSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2016-02-27 15:49:10 +01:00
|
|
|
spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4());
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2016-05-23 17:23:39 +02:00
|
|
|
const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
|
|
|
const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2016-02-25 20:23:16 +01:00
|
|
|
ui->plainTextEditAngle1F->setPlainText(angle1F);
|
|
|
|
ui->plainTextEditAngle2F->setPlainText(angle2F);
|
2016-05-23 17:23:39 +02:00
|
|
|
ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator()));
|
|
|
|
ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator()));
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2016-02-15 15:30:48 +01:00
|
|
|
if (not data->IsUnique(spl.name()))
|
|
|
|
{
|
|
|
|
spl.SetDuplicate(DNumber(spl.name()));
|
|
|
|
}
|
|
|
|
|
2017-04-11 12:42:42 +02:00
|
|
|
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
|
2016-02-15 15:30:48 +01:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
DialogAccepted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 16:42:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::ShowVisualization()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
AddVisualization<VisToolSpline>();
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-15 10:02:55 +01:00
|
|
|
VSpline DialogSpline::GetSpline() const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-15 10:02:55 +01:00
|
|
|
return spl;
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-02-15 10:02:55 +01:00
|
|
|
void DialogSpline::SetSpline(const VSpline &spline)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-02-15 10:02:55 +01:00
|
|
|
spl = spline;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2017-10-11 12:51:06 +02:00
|
|
|
ui->doubleSpinBoxApproximationScale->setValue(spl.GetApproximationScale());
|
|
|
|
ChangeCurrentData(ui->comboBoxColor, spl.GetColor());
|
|
|
|
ChangeCurrentData(ui->comboBoxPenStyle, spl.GetPenStyle());
|
|
|
|
|
2016-02-15 10:02:55 +01:00
|
|
|
setCurrentPointId(ui->comboBoxP1, spl.GetP1().id());
|
|
|
|
setCurrentPointId(ui->comboBoxP4, spl.GetP4().id());
|
2016-02-25 20:23:16 +01:00
|
|
|
|
2016-05-23 17:23:39 +02:00
|
|
|
const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
|
|
|
const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
ui->plainTextEditAngle1F->setPlainText(angle1F);
|
|
|
|
ui->plainTextEditAngle2F->setPlainText(angle2F);
|
|
|
|
|
2016-05-23 17:23:39 +02:00
|
|
|
const QString length1F = qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
|
|
|
const QString length2F = qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2016-02-25 20:23:16 +01:00
|
|
|
|
|
|
|
ui->plainTextEditLength1F->setPlainText(length1F);
|
|
|
|
ui->plainTextEditLength2F->setPlainText(length2F);
|
2017-04-11 12:42:42 +02:00
|
|
|
ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
|
2016-02-15 15:30:48 +01:00
|
|
|
|
2016-02-15 10:02:55 +01:00
|
|
|
auto path = qobject_cast<VisToolSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2016-02-15 10:02:55 +01:00
|
|
|
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());
|
2017-10-11 12:51:06 +02:00
|
|
|
path->setApproximationScale(spl.GetApproximationScale());
|
2015-02-02 16:11:48 +01:00
|
|
|
}
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogSpline::SetNotes(const QString ¬es)
|
|
|
|
{
|
|
|
|
ui->plainTextEditToolNotes->setPlainText(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogSpline::GetNotes() const
|
|
|
|
{
|
|
|
|
return ui->plainTextEditToolNotes->toPlainText();
|
|
|
|
}
|