2014-01-08 15:05:32 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogcutarc.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-01-08 15:05:32 +01:00
|
|
|
** @date 7 1, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2014-01-08 15:05: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.
|
2014-01-08 15:05: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 "dialogcutarc.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/vistoolcutarc.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_dialogcutarc.h"
|
2019-10-29 14:43:25 +01:00
|
|
|
#include "../vgeometry/varc.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogCutArc create dialog.
|
|
|
|
* @param data container with data
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2019-02-11 12:25:27 +01:00
|
|
|
DialogCutArc::DialogCutArc(const VContainer *data, quint32 toolId, QWidget *parent)
|
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogCutArc),
|
|
|
|
formula(),
|
|
|
|
pointName(),
|
|
|
|
formulaBaseHeight(0),
|
|
|
|
timerFormula(new QTimer(this)),
|
|
|
|
flagFormula(false),
|
|
|
|
flagName(true)
|
2014-01-08 15:05: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, &DialogCutArc::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));
|
2019-02-11 12:25:27 +01:00
|
|
|
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-05-30 21:03:17 +02:00
|
|
|
InitOkCancelApply(ui);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2016-04-01 16:32:36 +02:00
|
|
|
FillComboBoxArcs(ui->comboBoxArc);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2015-04-29 19:50:15 +02:00
|
|
|
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutArc::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-09 18:37:11 +02:00
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit);
|
2014-08-15 16:37:22 +02:00
|
|
|
|
2019-10-29 14:43:25 +01:00
|
|
|
connect(ui->comboBoxArc, &QComboBox::currentTextChanged, this, &DialogCutArc::ArcChanged);
|
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolCutArc(data);
|
2014-06-09 18:37:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-29 19:50:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::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:50:15 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetFormula(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::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-08-15 16:37:22 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::ShowVisualization()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
AddVisualization<VisToolCutArc>();
|
2014-08-15 16:37:22 +02:00
|
|
|
}
|
|
|
|
|
2014-06-09 18:37:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::DeployFormulaTextEdit()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-08 15:05:32 +01:00
|
|
|
DialogCutArc::~DialogCutArc()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:25:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutArc::GetPointName() const
|
|
|
|
{
|
|
|
|
return pointName;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +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 DialogCutArc::ChosenObject(quint32 id, const SceneObject &type)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (type == SceneObject::Arc)
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
if (SetObject(id, ui->comboBoxArc, QString()))
|
2014-08-17 20:49:29 +02:00
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
vis->VisualMode(id);
|
2014-08-17 20:49:29 +02:00
|
|
|
prepare = true;
|
|
|
|
this->setModal(true);
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-09 18:37:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::SaveData()
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
2014-06-09 18:37:11 +02:00
|
|
|
formula = ui->plainTextEditFormula->toPlainText();
|
2014-08-15 16:37:22 +02:00
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(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(getArcId());
|
2014-08-15 16:37:22 +02:00
|
|
|
path->setLength(formula);
|
|
|
|
path->RefreshGeometry();
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-11-22 19:37:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:43:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::ArcChanged()
|
|
|
|
{
|
2019-11-24 11:49:40 +01:00
|
|
|
CurrentCurveLength(getArcId(), const_cast<VContainer *> (data));
|
2019-10-29 14:43:25 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
|
|
|
* @brief setArcId set id of arc
|
|
|
|
* @param value id
|
|
|
|
*/
|
2019-02-11 12:25:27 +01:00
|
|
|
void DialogCutArc::setArcId(quint32 value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2016-04-01 16:32:36 +02:00
|
|
|
setCurrentArcId(ui->comboBoxArc, value);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2016-01-24 17:15:08 +01:00
|
|
|
path->setObject1Id(value);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetFormula set string with formula length
|
2014-05-30 10:32:40 +02:00
|
|
|
* @param value string with formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutArc::SetFormula(const QString &value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
|
2014-06-09 18:37:11 +02:00
|
|
|
// increase height if needed.
|
|
|
|
if (formula.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployFormulaTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(path != nullptr)
|
2014-08-15 16:37:22 +02:00
|
|
|
path->setLength(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-10-29 14:40:56 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetPointName set name point on arc
|
2014-05-30 10:32:40 +02:00
|
|
|
* @param value name
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutArc::SetPointName(const QString &value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
2014-05-30 10:32:40 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief GetFormula return string with formula length
|
2014-05-30 10:32:40 +02:00
|
|
|
* @return formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCutArc::GetFormula() const
|
2014-05-30 10:32:40 +02:00
|
|
|
{
|
2016-03-05 16:27:07 +01:00
|
|
|
return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
2014-05-30 10:32:40 +02:00
|
|
|
}
|
2015-02-02 16:11:48 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getArcId return id of arc
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
quint32 DialogCutArc::getArcId() const
|
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxArc);
|
2015-02-02 16:11:48 +01:00
|
|
|
}
|