2013-12-18 12:13:32 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogcutspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-12-18 12:13:32 +01:00
|
|
|
** @date 15 12, 2013
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-12-18 12:13:32 +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-12-18 12:13:32 +01:00
|
|
|
**
|
|
|
|
** 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 "dialogcutspline.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
2019-02-11 12:25:27 +01:00
|
|
|
#include <QTimer>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QToolButton>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
2019-02-11 12:25:27 +01:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../visualization/path/vistoolcutspline.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"
|
|
|
|
#include "../ifc/xml/vdomdocument.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_dialogcutspline.h"
|
2019-10-29 14:43:25 +01:00
|
|
|
#include "../vgeometry/vspline.h"
|
2020-11-06 13:48:37 +01:00
|
|
|
#include "../qmuparser/qmudef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogCutSpline create dialog.
|
|
|
|
* @param data container with data
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2019-02-11 12:25:27 +01:00
|
|
|
DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget *parent)
|
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogCutSpline),
|
|
|
|
formula(),
|
|
|
|
formulaBaseHeight(0),
|
|
|
|
pointName(),
|
|
|
|
timerFormula(new QTimer(this)),
|
|
|
|
flagFormula(false),
|
|
|
|
flagName(true)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-12-09 11:40:43 +01:00
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
timerFormula->setSingleShot(true);
|
|
|
|
connect(timerFormula, &QTimer::timeout, this, &DialogCutSpline::EvalFormula);
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
ui->lineEditNamePoint->setClearButtonEnabled(true);
|
|
|
|
|
2014-09-05 10:01:46 +02:00
|
|
|
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
|
2014-06-19 14:01:38 +02:00
|
|
|
this->formulaBaseHeight = ui->plainTextEditFormula->height();
|
2014-10-29 19:00:38 +01:00
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
2014-03-06 14:28:46 +01:00
|
|
|
|
2014-09-06 14:47:25 +02:00
|
|
|
InitOkCancelApply(ui);
|
2013-12-21 12:36:51 +01:00
|
|
|
|
2016-04-01 16:32:36 +02:00
|
|
|
FillComboBoxSplines(ui->comboBoxSpline);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2015-04-29 19:54:03 +02:00
|
|
|
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength);
|
2019-02-11 12:25:27 +01:00
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
|
|
|
|
CheckState();
|
|
|
|
});
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
|
|
|
|
{
|
|
|
|
timerFormula->start(formulaTimerTimeout);
|
|
|
|
});
|
2014-06-19 11:29:56 +02:00
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
|
2019-10-29 14:43:25 +01:00
|
|
|
connect(ui->comboBoxSpline, &QComboBox::currentTextChanged, this, &DialogCutSpline::SplineChanged);
|
2014-09-06 14:47:25 +02:00
|
|
|
|
2020-11-04 16:40:02 +01:00
|
|
|
connect(ui->lineEditAlias1, &QLineEdit::textEdited, this, &DialogCutSpline::ValidateAlias);
|
|
|
|
connect(ui->lineEditAlias2, &QLineEdit::textEdited, this, &DialogCutSpline::ValidateAlias);
|
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolCutSpline(data);
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
SetTabStopDistance(ui->plainTextEditToolNotes);
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-12-18 12:13:32 +01:00
|
|
|
DialogCutSpline::~DialogCutSpline()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutSpline::GetPointName() const
|
|
|
|
{
|
|
|
|
return pointName;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetPointName set name of point
|
2014-06-02 16:28:02 +02:00
|
|
|
* @param value name
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutSpline::SetPointName(const QString &value)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetFormula set string of formula
|
2014-06-02 16:28:02 +02:00
|
|
|
* @param value formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutSpline::SetFormula(const QString &value)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
|
2014-06-19 11:29:56 +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 (formula.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployFormulaTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2014-09-06 14:47:25 +02:00
|
|
|
path->setLength(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-10-29 14:40:56 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief setSplineId set id spline
|
|
|
|
* @param value id
|
|
|
|
*/
|
2019-02-11 12:25:27 +01:00
|
|
|
void DialogCutSpline::setSplineId(quint32 value)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2016-04-01 16:32:36 +02:00
|
|
|
setCurrentSplineId(ui->comboBoxSpline, value);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2016-01-24 17:15:08 +01:00
|
|
|
path->setObject1Id(value);
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
|
2015-02-08 11:23:26 +01: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 DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (type == SceneObject::Spline)
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
if (SetObject(id, ui->comboBoxSpline, QString()))
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
vis->VisualMode(id);
|
2014-09-06 14:47:25 +02:00
|
|
|
prepare = true;
|
2014-08-17 20:49:29 +02:00
|
|
|
this->setModal(true);
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-13 12:20:30 +02:00
|
|
|
void DialogCutSpline::SaveData()
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
2014-06-19 11:29:56 +02:00
|
|
|
formula = ui->plainTextEditFormula->toPlainText();
|
2014-09-06 14:47:25 +02:00
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
path->setObject1Id(getSplineId());
|
2014-09-06 14:47:25 +02:00
|
|
|
path->setLength(formula);
|
|
|
|
path->RefreshGeometry();
|
2013-12-18 12:13:32 +01:00
|
|
|
}
|
2014-06-19 11:29:56 +02:00
|
|
|
|
2014-11-22 19:37:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:43:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::SplineChanged()
|
|
|
|
{
|
2019-11-24 11:49:40 +01:00
|
|
|
CurrentCurveLength(getSplineId(), const_cast<VContainer *> (data));
|
2019-10-29 14:43:25 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 16:40:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::ValidateAlias()
|
|
|
|
{
|
2020-11-06 13:48:37 +01:00
|
|
|
QRegularExpression rx(NameRegExp());
|
2020-11-07 10:18:13 +01:00
|
|
|
|
2020-11-04 16:40:02 +01:00
|
|
|
VSpline spl1;
|
|
|
|
spl1.SetAliasSuffix(GetAliasSuffix1());
|
2020-11-07 10:18:13 +01:00
|
|
|
|
|
|
|
VSpline spl2;
|
|
|
|
spl2.SetAliasSuffix(GetAliasSuffix2());
|
|
|
|
|
2020-11-06 13:48:37 +01:00
|
|
|
if (not GetAliasSuffix1().isEmpty() &&
|
2020-11-07 10:18:13 +01:00
|
|
|
(not rx.match(spl1.GetAlias()).hasMatch() ||
|
|
|
|
(originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) ||
|
|
|
|
spl1.GetAlias() == spl2.GetAlias()))
|
2020-11-04 16:40:02 +01:00
|
|
|
{
|
|
|
|
flagAlias1 = false;
|
|
|
|
ChangeColor(ui->labelAlias1, errorColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagAlias1 = true;
|
|
|
|
ChangeColor(ui->labelAlias1, OkColor(this));
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:18:13 +01:00
|
|
|
if (not GetAliasSuffix2().isEmpty() &&
|
|
|
|
(not rx.match(spl2.GetAlias()).hasMatch() ||
|
|
|
|
(originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(spl2.GetAlias())) ||
|
|
|
|
spl1.GetAlias() == spl2.GetAlias()))
|
2020-11-04 16:40:02 +01:00
|
|
|
{
|
|
|
|
flagAlias2 = false;
|
|
|
|
ChangeColor(ui->labelAlias2, errorColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagAlias2 = true;
|
|
|
|
ChangeColor(ui->labelAlias2, OkColor(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2014-06-19 11:29:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::DeployFormulaTextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
2014-06-19 11:29:56 +02:00
|
|
|
}
|
2014-09-06 14:47:25 +02:00
|
|
|
|
2015-04-29 19:54:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::FXLength()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit length"));
|
|
|
|
dialog->SetFormula(GetFormula());
|
2020-10-15 17:05:21 +02:00
|
|
|
dialog->setPostfix(UnitsToStr(qApp->patternUnits(), true));
|
2015-04-29 19:54:03 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetFormula(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::EvalFormula()
|
|
|
|
{
|
|
|
|
FormulaData formulaData;
|
|
|
|
formulaData.formula = ui->plainTextEditFormula->toPlainText();
|
|
|
|
formulaData.variables = data->DataVariables();
|
|
|
|
formulaData.labelEditFormula = ui->labelEditFormula;
|
|
|
|
formulaData.labelResult = ui->labelResultCalculation;
|
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;
|
|
|
|
|
|
|
|
Eval(formulaData, flagFormula);
|
|
|
|
}
|
|
|
|
|
2014-09-06 14:47:25 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::ShowVisualization()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
AddVisualization<VisToolCutSpline>();
|
2014-09-06 14:47:25 +02:00
|
|
|
}
|
2015-02-02 16:11:48 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief GetFormula return string of formula
|
2015-02-02 16:11:48 +01:00
|
|
|
* @return formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCutSpline::GetFormula() const
|
2015-02-02 16:11:48 +01:00
|
|
|
{
|
2016-03-05 16:27:07 +01:00
|
|
|
return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
2015-02-02 16:11:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getSplineId return id base point of line
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
quint32 DialogCutSpline::getSplineId() const
|
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxSpline);
|
2015-02-02 16:11:48 +01:00
|
|
|
}
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::SetNotes(const QString ¬es)
|
|
|
|
{
|
|
|
|
ui->plainTextEditToolNotes->setPlainText(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutSpline::GetNotes() const
|
|
|
|
{
|
|
|
|
return ui->plainTextEditToolNotes->toPlainText();
|
|
|
|
}
|
2020-11-04 16:40:02 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::SetAliasSuffix1(const QString &alias)
|
|
|
|
{
|
2020-11-07 10:18:13 +01:00
|
|
|
originAliasSuffix1 = alias;
|
|
|
|
ui->lineEditAlias1->setText(originAliasSuffix1);
|
2020-11-04 16:40:02 +01:00
|
|
|
ValidateAlias();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutSpline::GetAliasSuffix1() const
|
|
|
|
{
|
|
|
|
return ui->lineEditAlias1->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::SetAliasSuffix2(const QString &alias)
|
|
|
|
{
|
2020-11-07 10:18:13 +01:00
|
|
|
originAliasSuffix2 = alias;
|
|
|
|
ui->lineEditAlias2->setText(originAliasSuffix2);
|
2020-11-04 16:40:02 +01:00
|
|
|
ValidateAlias();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutSpline::GetAliasSuffix2() const
|
|
|
|
{
|
|
|
|
return ui->lineEditAlias2->text();
|
|
|
|
}
|