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
|
2013-12-18 12:13:32 +01: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 "dialogcutspline.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QToolButton>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vpatterndb/vtranslatevars.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"
|
|
|
|
|
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
|
|
|
|
*/
|
2014-07-29 14:19:11 +02:00
|
|
|
DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
2016-04-01 16:32:36 +02:00
|
|
|
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), formulaBaseHeight(0)
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-12-09 11:40:43 +01:00
|
|
|
|
|
|
|
ui->lineEditNamePoint->setClearButtonEnabled(true);
|
|
|
|
|
2014-06-19 13:43:02 +02:00
|
|
|
InitFormulaUI(ui);
|
2014-09-05 10:01:46 +02:00
|
|
|
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
|
2013-12-18 12:13:32 +01:00
|
|
|
labelEditNamePoint = ui->labelEditNamePoint;
|
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-18 12:13:32 +01:00
|
|
|
flagFormula = false;
|
2017-03-31 10:54:05 +02:00
|
|
|
DialogTool::CheckState();
|
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);
|
2013-12-18 12:13:32 +01:00
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged);
|
2014-06-19 11:29:56 +02:00
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged);
|
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
|
2014-09-06 14:47:25 +02:00
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolCutSpline(data);
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2014-07-29 15:08:38 +02:00
|
|
|
void DialogCutSpline::setSplineId(const 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);
|
|
|
|
}
|
|
|
|
|
2014-06-19 11:29:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutSpline::DeployFormulaTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
|
|
|
}
|
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());
|
2017-07-02 13:34:36 +02:00
|
|
|
dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
|
2015-04-29 19:54:03 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetFormula(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|