2015-06-05 15:43:41 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogpointfromcircleandtangent.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-05 15:43:41 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <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 "dialogpointfromcircleandtangent.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <Qt>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
|
|
|
#include "../../visualization/visualization.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../../visualization/line/vistoolpointfromcircleandtangent.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#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_dialogpointfromcircleandtangent.h"
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContainer *data, const quint32 &toolId,
|
|
|
|
QWidget *parent)
|
|
|
|
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointFromCircleAndTangent), flagCircleRadius(false),
|
2017-03-31 16:21:18 +02:00
|
|
|
timerCircleRadius(nullptr), circleRadius(), formulaBaseHeightCircleRadius(0)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
ui->lineEditNamePoint->setClearButtonEnabled(true);
|
|
|
|
|
2015-06-05 15:43:41 +02:00
|
|
|
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
|
|
|
|
labelEditNamePoint = ui->labelEditNamePoint;
|
|
|
|
|
|
|
|
plainTextEditFormula = ui->plainTextEditRadius;
|
|
|
|
this->formulaBaseHeightCircleRadius = ui->plainTextEditRadius->height();
|
|
|
|
|
|
|
|
ui->plainTextEditRadius->installEventFilter(this);
|
|
|
|
|
|
|
|
timerCircleRadius = new QTimer(this);
|
|
|
|
connect(timerCircleRadius, &QTimer::timeout, this, &DialogPointFromCircleAndTangent::EvalCircleRadius);
|
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
CheckState();
|
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxCircleCenter);
|
|
|
|
FillComboBoxPoints(ui->comboBoxTangentPoint);
|
|
|
|
FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
|
|
|
|
|
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointFromCircleAndTangent::NamePointChanged);
|
|
|
|
connect(ui->comboBoxCircleCenter,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogPointFromCircleAndTangent::PointChanged);
|
|
|
|
|
|
|
|
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this,
|
|
|
|
&DialogPointFromCircleAndTangent::FXCircleRadius);
|
|
|
|
|
|
|
|
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this,
|
|
|
|
&DialogPointFromCircleAndTangent::CircleRadiusChanged);
|
|
|
|
|
|
|
|
connect(ui->pushButtonGrowRadius, &QPushButton::clicked, this,
|
|
|
|
&DialogPointFromCircleAndTangent::DeployCircleRadiusTextEdit);
|
|
|
|
|
|
|
|
vis = new VisToolPointFromCircleAndTangent(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogPointFromCircleAndTangent::~DialogPointFromCircleAndTangent()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::SetPointName(const QString &value)
|
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogPointFromCircleAndTangent::GetCircleCenterId() const
|
|
|
|
{
|
|
|
|
return getCurrentObjectId(ui->comboBoxCircleCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::SetCircleCenterId(const quint32 &value)
|
|
|
|
{
|
|
|
|
setCurrentPointId(ui->comboBoxCircleCenter, value);
|
|
|
|
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2016-01-24 17:15:08 +01:00
|
|
|
point->setObject2Id(value);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogPointFromCircleAndTangent::GetCircleRadius() const
|
|
|
|
{
|
2016-03-05 16:27:07 +01:00
|
|
|
return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditRadius->toPlainText(),
|
|
|
|
qApp->Settings()->GetOsSeparator());
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::SetCircleRadius(const QString &value)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
const QString formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
|
2015-06-05 15:43:41 +02:00
|
|
|
// increase height if needed.
|
|
|
|
if (formula.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployCircleRadiusTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditRadius->setPlainText(formula);
|
|
|
|
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
point->setCRadius(formula);
|
|
|
|
|
|
|
|
MoveCursorToEnd(ui->plainTextEditRadius);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogPointFromCircleAndTangent::GetTangentPointId() const
|
|
|
|
{
|
|
|
|
return getCurrentObjectId(ui->comboBoxTangentPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::SetTangentPointId(const quint32 &value)
|
|
|
|
{
|
|
|
|
setCurrentPointId(ui->comboBoxTangentPoint, value);
|
|
|
|
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2016-01-24 17:15:08 +01:00
|
|
|
point->setObject1Id(value);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
CrossCirclesPoint DialogPointFromCircleAndTangent::GetCrossCirclesPoint() const
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
return getCurrentCrossPoint<CrossCirclesPoint>(ui->comboBoxResult);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-28 15:22:36 +01:00
|
|
|
void DialogPointFromCircleAndTangent::SetCrossCirclesPoint(const CrossCirclesPoint &p)
|
2015-06-05 15:43:41 +02:00
|
|
|
{
|
|
|
|
const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
ui->comboBoxResult->setCurrentIndex(index);
|
|
|
|
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
point->setCrossPoint(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
|
|
|
{
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
|
|
|
|
switch (number)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (SetObject(id, ui->comboBoxTangentPoint, tr("Select a circle center")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
point->VisualMode(id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (getCurrentObjectId(ui->comboBoxTangentPoint) != id)
|
|
|
|
{
|
|
|
|
if (SetObject(id, ui->comboBoxCircleCenter, ""))
|
|
|
|
{
|
|
|
|
number = 0;
|
2016-01-24 17:15:08 +01:00
|
|
|
point->setObject2Id(id);
|
2015-06-05 15:43:41 +02:00
|
|
|
point->RefreshGeometry();
|
|
|
|
prepare = true;
|
|
|
|
this->setModal(true);
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::PointChanged()
|
|
|
|
{
|
|
|
|
QColor color = okColor;
|
|
|
|
if (getCurrentObjectId(ui->comboBoxCircleCenter) == getCurrentObjectId(ui->comboBoxTangentPoint))
|
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
|
|
|
color = okColor;
|
|
|
|
}
|
|
|
|
ChangeColor(ui->labelCircleCenter, color);
|
|
|
|
ChangeColor(ui->labelTangentPoint, color);
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::DeployCircleRadiusTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditRadius, ui->pushButtonGrowRadius, formulaBaseHeightCircleRadius);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::CircleRadiusChanged()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditRadius;
|
|
|
|
labelResultCalculation = ui->labelResultCircleRadius;
|
2017-07-02 13:34:36 +02:00
|
|
|
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
2016-03-05 13:30:18 +01:00
|
|
|
ValFormulaChanged(flagCircleRadius, ui->plainTextEditRadius, timerCircleRadius, postfix);
|
2015-06-05 15:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::FXCircleRadius()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit radius"));
|
|
|
|
dialog->SetFormula(GetCircleRadius());
|
2017-07-02 13:34:36 +02:00
|
|
|
dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
|
2015-06-05 15:43:41 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetCircleRadius(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::EvalCircleRadius()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditRadius;
|
2017-07-02 13:34:36 +02:00
|
|
|
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
2015-06-05 15:43:41 +02:00
|
|
|
const qreal radius = Eval(ui->plainTextEditRadius->toPlainText(), flagCircleRadius,
|
|
|
|
ui->labelResultCircleRadius, postfix);
|
|
|
|
|
|
|
|
if (radius < 0)
|
|
|
|
{
|
|
|
|
flagCircleRadius = false;
|
|
|
|
ChangeColor(labelEditFormula, Qt::red);
|
|
|
|
ui->labelResultCircleRadius->setText(tr("Error"));
|
|
|
|
ui->labelResultCircleRadius->setToolTip(tr("Radius can't be negative"));
|
|
|
|
|
|
|
|
DialogPointFromCircleAndTangent::CheckState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::ShowVisualization()
|
|
|
|
{
|
|
|
|
AddVisualization<VisToolPointFromCircleAndTangent>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::SaveData()
|
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
|
|
|
|
|
|
|
QString radius = ui->plainTextEditRadius->toPlainText();
|
|
|
|
radius.replace("\n", " ");
|
|
|
|
|
|
|
|
VisToolPointFromCircleAndTangent *point = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(point != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
point->setObject1Id(GetTangentPointId());
|
|
|
|
point->setObject2Id(GetCircleCenterId());
|
2015-06-05 15:43:41 +02:00
|
|
|
point->setCRadius(radius);
|
|
|
|
point->setCrossPoint(GetCrossCirclesPoint());
|
|
|
|
point->RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditRadius->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogPointFromCircleAndTangent::CheckState()
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bOk != nullptr)
|
2015-06-05 15:43:41 +02:00
|
|
|
bOk->setEnabled(flagFormula && flagName && flagError && flagCircleRadius);
|
|
|
|
// In case dialog hasn't apply button
|
|
|
|
if ( bApply != nullptr)
|
|
|
|
{
|
|
|
|
bApply->setEnabled(bOk->isEnabled());
|
|
|
|
}
|
|
|
|
}
|