diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 81362cb04..c5d5ba4f6 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -276,6 +276,13 @@ QString DialogHistory::Record(const VToolRecord &tool) SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); } + case Tool::ArcWithLength: + { + const QSharedPointer arc = data->GeometricObject(tool.getId()); + SCASSERT(arc != nullptr); + return QString(tr("Arc with center in point %1 and length %2")).arg(PointName(arc->GetCenter().id())) + .arg(arc->GetLength()); + } case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); diff --git a/src/app/dialogs/dialogs.h b/src/app/dialogs/dialogs.h index dddeeed3e..9e55341a3 100644 --- a/src/app/dialogs/dialogs.h +++ b/src/app/dialogs/dialogs.h @@ -31,6 +31,7 @@ #include "tools/dialogalongline.h" #include "tools/dialogarc.h" +#include "tools/dialogarcwithlength.h" #include "tools/dialogbisector.h" #include "tools/dialogdetail.h" #include "tools/dialogendline.h" diff --git a/src/app/dialogs/dialogs.pri b/src/app/dialogs/dialogs.pri index 33234c153..0bf0be853 100644 --- a/src/app/dialogs/dialogs.pri +++ b/src/app/dialogs/dialogs.pri @@ -48,7 +48,8 @@ HEADERS += \ $$PWD/tools/dialogpointofintersectionarcs.h \ $$PWD/tools/dialogpointofintersectioncircles.h \ $$PWD/tools/dialogpointfromcircleandtangent.h \ - dialogs/tools/dialogpointfromarcandtangent.h + $$PWD/tools/dialogpointfromarcandtangent.h \ + $$PWD/tools/dialogarcwithlength.h SOURCES += \ $$PWD/tools/dialogtriangle.cpp \ @@ -95,7 +96,8 @@ SOURCES += \ $$PWD/tools/dialogpointofintersectionarcs.cpp \ $$PWD/tools/dialogpointofintersectioncircles.cpp \ $$PWD/tools/dialogpointfromcircleandtangent.cpp \ - dialogs/tools/dialogpointfromarcandtangent.cpp + $$PWD/tools/dialogpointfromarcandtangent.cpp \ + $$PWD/tools/dialogarcwithlength.cpp FORMS += \ $$PWD/tools/dialogtriangle.ui \ @@ -136,4 +138,5 @@ FORMS += \ $$PWD/tools/dialogpointofintersectionarcs.ui \ $$PWD/tools/dialogpointofintersectioncircles.ui \ $$PWD/tools/dialogpointfromcircleandtangent.ui \ - dialogs/tools/dialogpointfromarcandtangent.ui + $$PWD/tools/dialogpointfromarcandtangent.ui \ + $$PWD/tools/dialogarcwithlength.ui diff --git a/src/app/dialogs/tools/dialogarcwithlength.cpp b/src/app/dialogs/tools/dialogarcwithlength.cpp new file mode 100644 index 000000000..f8d718081 --- /dev/null +++ b/src/app/dialogs/tools/dialogarcwithlength.cpp @@ -0,0 +1,381 @@ +/************************************************************************ + ** + ** @file dialogarcwithlength.cpp + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "dialogarcwithlength.h" +#include "ui_dialogarcwithlength.h" + +#include +#include + +#include "../../libs/vgeometry/vpointf.h" +#include "../../container/vcontainer.h" +#include "../../libs/ifc/xml/vdomdocument.h" +#include "../../visualization/vistoolarcwithlength.h" +#include "dialogeditwrongformula.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 &toolId, QWidget *parent) + :DialogTool(data, toolId, parent), ui(new Ui::DialogArcWithLength), flagRadius(false), flagF1(false), + flagLength(false), timerRadius(nullptr), timerF1(nullptr), timerLength(nullptr), radius(QString()), f1(QString()), + length(QString()),formulaBaseHeightRadius(0), formulaBaseHeightF1(0), formulaBaseHeightLength(0), angleF1(INT_MIN) +{ + ui->setupUi(this); + + plainTextEditFormula = ui->plainTextEditRadius; + this->formulaBaseHeightLength = ui->plainTextEditRadius->height(); + this->formulaBaseHeightF1 = ui->plainTextEditF1->height(); + this->formulaBaseHeightLength = ui->plainTextEditLength->height(); + + ui->plainTextEditRadius->installEventFilter(this); + ui->plainTextEditF1->installEventFilter(this); + ui->plainTextEditLength->installEventFilter(this); + + timerRadius = new QTimer(this); + connect(timerRadius, &QTimer::timeout, this, &DialogArcWithLength::Radius); + + timerF1 = new QTimer(this); + connect(timerF1, &QTimer::timeout, this, &DialogArcWithLength::EvalF); + + timerLength = new QTimer(this); + connect(timerLength, &QTimer::timeout, this, &DialogArcWithLength::Length); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxCenter); + FillComboBoxLineColors(ui->comboBoxColor); + + CheckState(); + + connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogArcWithLength::FXRadius); + connect(ui->toolButtonExprF1, &QPushButton::clicked, this, &DialogArcWithLength::FXF1); + connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogArcWithLength::FXLength); + + connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::RadiusChanged); + connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::F1Changed); + connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::LengthChanged); + + connect(ui->pushButtonGrowLengthRadius, &QPushButton::clicked, this, &DialogArcWithLength::DeployRadiusTextEdit); + connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArcWithLength::DeployF1TextEdit); + connect(ui->pushButtonGrowLengthArcLength, &QPushButton::clicked, this, &DialogArcWithLength::DeployLengthTextEdit); + + vis = new VisToolArcWithLength(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogArcWithLength::~DialogArcWithLength() +{ + DeleteVisualization(); + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogArcWithLength::GetCenter() const +{ + return getCurrentObjectId(ui->comboBoxCenter); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SetCenter(const quint32 &value) +{ + ChangeCurrentData(ui->comboBoxCenter, value); + vis->setPoint1Id(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArcWithLength::GetRadius() const +{ + return qApp->FormulaFromUser(radius); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SetRadius(const QString &value) +{ + radius = qApp->FormulaToUser(value); + // increase height if needed. + if (radius.length() > 80) + { + this->DeployRadiusTextEdit(); + } + ui->plainTextEditRadius->setPlainText(radius); + + VisToolArcWithLength *path = qobject_cast(vis); + SCASSERT(path != nullptr); + path->setRadius(radius); + + MoveCursorToEnd(ui->plainTextEditRadius); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArcWithLength::GetF1() const +{ + return qApp->FormulaFromUser(f1); +} + +void DialogArcWithLength::SetF1(const QString &value) +{ + f1 = qApp->FormulaToUser(value); + // increase height if needed. + if (f1.length() > 80) + { + this->DeployF1TextEdit(); + } + ui->plainTextEditF1->setPlainText(f1); + + VisToolArcWithLength *path = qobject_cast(vis); + SCASSERT(path != nullptr); + path->setF1(f1); + + MoveCursorToEnd(ui->plainTextEditF1); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArcWithLength::GetLength() const +{ + return qApp->FormulaFromUser(length); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SetLength(const QString &value) +{ + length = qApp->FormulaToUser(value); + // increase height if needed. + if (length.length() > 80) + { + this->DeployLengthTextEdit(); + } + ui->plainTextEditLength->setPlainText(length); + + VisToolArcWithLength *path = qobject_cast(vis); + SCASSERT(path != nullptr); + path->setLength(radius); + + MoveCursorToEnd(ui->plainTextEditLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArcWithLength::GetColor() const +{ + return GetComboBoxCurrentData(ui->comboBoxColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SetColor(const QString &value) +{ + ChangeCurrentData(ui->comboBoxColor, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type) +{ + if (prepare == false)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (SetObject(id, ui->comboBoxCenter, "")) + { + vis->VisualMode(id); + prepare = true; + this->setModal(true); + this->show(); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::DeployRadiusTextEdit() +{ + DeployFormula(ui->plainTextEditRadius, ui->pushButtonGrowLengthArcLength, formulaBaseHeightRadius); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::DeployF1TextEdit() +{ + DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::DeployLengthTextEdit() +{ + DeployFormula(ui->plainTextEditLength, ui->pushButtonGrowLengthArcLength, formulaBaseHeightLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::RadiusChanged() +{ + labelEditFormula = ui->labelEditRadius; + labelResultCalculation = ui->labelResultRadius; + ValFormulaChanged(flagRadius, ui->plainTextEditRadius, timerRadius); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::F1Changed() +{ + labelEditFormula = ui->labelEditF1; + labelResultCalculation = ui->labelResultF1; + ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::LengthChanged() +{ + labelEditFormula = ui->labelEditLength; + labelResultCalculation = ui->labelResultLength; + ValFormulaChanged(flagLength, ui->plainTextEditLength, timerLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::FXRadius() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit radius")); + dialog->SetFormula(GetRadius()); + if (dialog->exec() == QDialog::Accepted) + { + SetRadius(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::FXF1() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit the first angle")); + dialog->SetFormula(GetF1()); + if (dialog->exec() == QDialog::Accepted) + { + SetF1(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::FXLength() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit the arc length")); + dialog->SetFormula(GetLength()); + if (dialog->exec() == QDialog::Accepted) + { + SetLength(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagRadius && flagF1 && flagLength); + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(bOk->isEnabled()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SaveData() +{ + radius = ui->plainTextEditRadius->toPlainText(); + radius.replace("\n", " "); + + f1 = ui->plainTextEditF1->toPlainText(); + f1.replace("\n", " "); + + length = ui->plainTextEditLength->toPlainText(); + length.replace("\n", " "); + + VisToolArcWithLength *path = qobject_cast(vis); + SCASSERT(path != nullptr); + + path->setPoint1Id(GetCenter()); + path->setRadius(radius); + path->setF1(f1); + path->setLength(length); + path->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditRadius->blockSignals(true); + ui->plainTextEditF1->blockSignals(true); + ui->plainTextEditLength->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::Radius() +{ + labelEditFormula = ui->labelEditRadius; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const qreal radius = Eval(ui->plainTextEditRadius->toPlainText(), flagRadius, ui->labelResultRadius, postfix); + + if (radius < 0) + { + flagRadius = false; + ChangeColor(labelEditFormula, Qt::red); + ui->labelResultRadius->setText(tr("Error")); + ui->labelResultRadius->setToolTip(tr("Radius can't be negative")); + + DialogArcWithLength::CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::Length() +{ + labelEditFormula = ui->labelEditLength; + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + const qreal length = Eval(ui->plainTextEditLength->toPlainText(), flagLength, ui->labelResultLength, postfix); + + if (qFuzzyCompare(length+1, 0+1)) + { + flagLength = false; + ChangeColor(labelEditFormula, Qt::red); + ui->labelResultLength->setText(tr("Error")); + ui->labelResultLength->setToolTip(tr("Length can't be equal 0")); + + DialogArcWithLength::CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::EvalF() +{ + labelEditFormula = ui->labelEditF1; + angleF1 = Eval(ui->plainTextEditF1->toPlainText(), flagF1, ui->labelResultF1, degreeSymbol, false); +} diff --git a/src/app/dialogs/tools/dialogarcwithlength.h b/src/app/dialogs/tools/dialogarcwithlength.h new file mode 100644 index 000000000..f02749f66 --- /dev/null +++ b/src/app/dialogs/tools/dialogarcwithlength.h @@ -0,0 +1,128 @@ +/************************************************************************ + ** + ** @file dialogarcwithlength.h + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef DIALOGARCWITHLENGTH_H +#define DIALOGARCWITHLENGTH_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogArcWithLength; +} + +class DialogArcWithLength : public DialogTool +{ + Q_OBJECT + +public: + DialogArcWithLength(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + ~DialogArcWithLength(); + + quint32 GetCenter() const; + void SetCenter(const quint32 &value); + + QString GetRadius() const; + void SetRadius(const QString &value); + + QString GetF1() const; + void SetF1(const QString &value); + + QString GetLength() const; + void SetLength(const QString &value); + + QString GetColor() const; + void SetColor(const QString &value); + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type); + /** + * @brief DeployFormulaTextEdit grow or shrink formula input + */ + void DeployRadiusTextEdit(); + void DeployF1TextEdit(); + void DeployLengthTextEdit(); + + void RadiusChanged(); + void F1Changed(); + void LengthChanged(); + + void FXRadius(); + void FXF1(); + void FXLength(); + +protected: + virtual void CheckState(); + virtual void ShowVisualization(); + /** + * @brief SaveData Put dialog data in local variables + */ + virtual void SaveData(); + virtual void closeEvent(QCloseEvent *event); + +private: + Q_DISABLE_COPY(DialogArcWithLength) + Ui::DialogArcWithLength *ui; + + /** @brief flagRadius true if value of radius is correct */ + bool flagRadius; + + /** @brief flagF1 true if value of first angle is correct */ + bool flagF1; + + bool flagLength; + + /** @brief timerRadius timer of check formula of radius */ + QTimer *timerRadius; + + /** @brief timerF1 timer of check formula of first angle */ + QTimer *timerF1; + + QTimer *timerLength; + + /** @brief radius formula of radius */ + QString radius; + + /** @brief f1 formula of first angle */ + QString f1; + + QString length; + + /** @brief formulaBaseHeight base height defined by dialogui */ + int formulaBaseHeightRadius; + int formulaBaseHeightF1; + int formulaBaseHeightLength; + + qreal angleF1; + + void Radius(); + void Length(); + void EvalF(); +}; + +#endif // DIALOGARCWITHLENGTH_H diff --git a/src/app/dialogs/tools/dialogarcwithlength.ui b/src/app/dialogs/tools/dialogarcwithlength.ui new file mode 100644 index 000000000..7bf711e4d --- /dev/null +++ b/src/app/dialogs/tools/dialogarcwithlength.ui @@ -0,0 +1,629 @@ + + + DialogArcWithLength + + + + 0 + 0 + 339 + 329 + + + + Dialog + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Radius + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of radius + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 24 + + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + First angle + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of first angle + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 24 + + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Length + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Arc length + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 24 + + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + Center point + + + + + + + Select point of center of arc + + + + + + + + + + Color + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogArcWithLength + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogArcWithLength + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/app/dialogs/tools/dialogpointfromcircleandtangent.ui b/src/app/dialogs/tools/dialogpointfromcircleandtangent.ui index edd8015ec..50564e271 100644 --- a/src/app/dialogs/tools/dialogpointfromcircleandtangent.ui +++ b/src/app/dialogs/tools/dialogpointfromcircleandtangent.ui @@ -137,7 +137,7 @@ - Value of first angle + Radius _ diff --git a/src/app/dialogs/tools/dialogpointofintersectioncircles.ui b/src/app/dialogs/tools/dialogpointofintersectioncircles.ui index 0490431af..d2948009e 100644 --- a/src/app/dialogs/tools/dialogpointofintersectioncircles.ui +++ b/src/app/dialogs/tools/dialogpointofintersectioncircles.ui @@ -137,7 +137,7 @@ - Value of radius + Radius of the first circle _ @@ -312,7 +312,7 @@ - Value of first angle + Radius of the second circle _ diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 7df3198d9..a48869939 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -735,6 +735,16 @@ void MainWindow::ToolPointFromArcAndTangent(bool checked) &MainWindow::ApplyDialog); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolArcWithLength(bool checked) +{ + SetToolButtonWithApply(checked, Tool::ArcWithLength, + "://cursor/arc_with_length_cursor.png", + tr("Select point of the center of the arc"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief About show widows about. @@ -1037,6 +1047,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonPointFromCircleAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromCircleAndTangent); connect(ui->toolButtonPointFromArcAndTangent, &QToolButton::clicked, this, &MainWindow::ToolPointFromArcAndTangent); + connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength); } //--------------------------------------------------------------------------------------------------------------------- @@ -1113,6 +1124,9 @@ void MainWindow::CancelTool() case Tool::Arc: ui->toolButtonArc->setChecked(false); break; + case Tool::ArcWithLength: + ui->toolButtonArcWithLength->setChecked(false); + break; case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); break; @@ -1156,6 +1170,12 @@ void MainWindow::CancelTool() case Tool::PointOfIntersectionCircles: ui->toolButtonPointOfIntersectionCircles->setChecked(false); break; + case Tool::PointFromCircleAndTangent: + ui->toolButtonPointFromCircleAndTangent->setChecked(false); + break; + case Tool::PointFromArcAndTangent: + ui->toolButtonPointFromArcAndTangent->setChecked(false); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: @@ -2185,6 +2205,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonPointOfIntersectionCircles->setEnabled(drawTools); ui->toolButtonPointFromCircleAndTangent->setEnabled(drawTools); ui->toolButtonPointFromArcAndTangent->setEnabled(drawTools); + ui->toolButtonArcWithLength->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -2559,6 +2580,10 @@ void MainWindow::LastUsedTool() ui->toolButtonPointFromArcAndTangent->setChecked(true); ToolPointFromArcAndTangent(true); break; + case Tool::ArcWithLength: + ui->toolButtonArcWithLength->setChecked(true); + ToolArcWithLength(true); + break; case Tool::NodePoint: case Tool::NodeArc: case Tool::NodeSpline: diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index e580938d1..d43b58855 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -119,6 +119,7 @@ public slots: void ToolPointOfIntersectionCircles(bool checked); void ToolPointFromCircleAndTangent(bool checked); void ToolPointFromArcAndTangent(bool checked); + void ToolArcWithLength(bool checked); void ClosedDialogDetail(int result); void ClosedDialogUnionDetails(int result); diff --git a/src/app/mainwindow.ui b/src/app/mainwindow.ui index b0cc13ffe..bd049ec1c 100644 --- a/src/app/mainwindow.ui +++ b/src/app/mainwindow.ui @@ -48,14 +48,14 @@ - 0 + 3 0 0 - 130 + 100 272 @@ -346,7 +346,7 @@ 0 0 - 145 + 100 58 @@ -429,8 +429,8 @@ 0 0 - 145 - 104 + 100 + 156 @@ -590,8 +590,8 @@ 0 0 - 145 - 150 + 130 + 196 @@ -796,6 +796,32 @@ + + + + false + + + Arc with given length + + + ... + + + + :/toolicon/32x32/arc_with_length.png:/toolicon/32x32/arc_with_length.png + + + + 32 + 32 + + + + true + + + @@ -803,7 +829,7 @@ 0 0 - 145 + 100 58 @@ -886,8 +912,8 @@ 0 0 - 145 - 386 + 98 + 58 diff --git a/src/app/options.h b/src/app/options.h index f265dfc5f..6bd5239da 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -75,6 +75,7 @@ enum class Tool : unsigned char CutSpline, CutArc, Arc, + ArcWithLength, SplinePath, CutSplinePath, PointOfContact, @@ -92,18 +93,19 @@ enum class Tool : unsigned char PointOfIntersection, PointFromCircleAndTangent, PointFromArcAndTangent, - UnionDetails // 34 + UnionDetails // 35 }; enum class Vis : unsigned char { - ControlPointSpline = 35, // increase this value if need more positions in Tool enum + ControlPointSpline = 36, // increase this value if need more positions in Tool enum GraphicsSimpleTextItem, SimpleSplinePath, Line, Path, ToolAlongLine, ToolArc, + ToolArcWithLength, ToolBisector, ToolCutArc, ToolEndLine, diff --git a/src/app/share/resources/cursor.qrc b/src/app/share/resources/cursor.qrc index a4059e34f..a09044ac0 100644 --- a/src/app/share/resources/cursor.qrc +++ b/src/app/share/resources/cursor.qrc @@ -28,5 +28,6 @@ cursor/point_of_intersection_circles.png cursor/point_from_circle_and_tangent_cursor.png cursor/point_from_arc_and_tangent_cursor.png + cursor/arc_with_length_cursor.png diff --git a/src/app/share/resources/cursor/arc_with_length_cursor.png b/src/app/share/resources/cursor/arc_with_length_cursor.png new file mode 100644 index 000000000..280d2063b Binary files /dev/null and b/src/app/share/resources/cursor/arc_with_length_cursor.png differ diff --git a/src/app/share/resources/toolicon.qrc b/src/app/share/resources/toolicon.qrc index b54b46c86..116a34024 100644 --- a/src/app/share/resources/toolicon.qrc +++ b/src/app/share/resources/toolicon.qrc @@ -26,5 +26,6 @@ toolicon/32x32/triangle.png toolicon/32x32/union.png toolicon/32x32/new_detail.png + toolicon/32x32/arc_with_length.png diff --git a/src/app/share/resources/toolicon/32x32/arc_with_length.png b/src/app/share/resources/toolicon/32x32/arc_with_length.png new file mode 100644 index 000000000..58817ace3 Binary files /dev/null and b/src/app/share/resources/toolicon/32x32/arc_with_length.png differ diff --git a/src/app/share/resources/toolicon/svg/arc_with_length.svg b/src/app/share/resources/toolicon/svg/arc_with_length.svg new file mode 100644 index 000000000..0299f69a5 --- /dev/null +++ b/src/app/share/resources/toolicon/svg/arc_with_length.svg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/app/tools/drawTools/drawtools.h b/src/app/tools/drawTools/drawtools.h index e9a73ca45..1b8c70894 100644 --- a/src/app/tools/drawTools/drawtools.h +++ b/src/app/tools/drawTools/drawtools.h @@ -31,6 +31,7 @@ #include "vtoolalongline.h" #include "vtoolarc.h" +#include "vtoolarcwithlength.h" #include "vtoolbisector.h" #include "vtoolendline.h" #include "vtoolline.h" diff --git a/src/app/tools/drawTools/vtoolarcwithlength.cpp b/src/app/tools/drawTools/vtoolarcwithlength.cpp new file mode 100644 index 000000000..176d6b3a7 --- /dev/null +++ b/src/app/tools/drawTools/vtoolarcwithlength.cpp @@ -0,0 +1,319 @@ +/************************************************************************ + ** + ** @file vtoolarcwithlength.cpp + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "vtoolarcwithlength.h" +#include "../../container/calculator.h" +#include "../../dialogs/tools/dialogarcwithlength.h" +#include "../../libs/vgeometry/varc.h" +#include "../container/vformula.h" +#include "../../visualization/vistoolarcwithlength.h" + +#include + +const QString VToolArcWithLength::TagName = QStringLiteral("arc"); +const QString VToolArcWithLength::ToolType = QStringLiteral("arcWithLength"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolArcWithLength::VToolArcWithLength(VPattern *doc, VContainer *data, quint32 id, const QString &color, + const Source &typeCreation, QGraphicsItem *parent) + :VAbstractSpline(doc, data, id, parent) +{ + sceneType = SceneObject::Arc; + lineColor = color; + + this->setPath(ToolPath()); + this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); + this->setFlag(QGraphicsItem::ItemIsFocusable, true); + this->setAcceptHoverEvents(true); + + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogArcWithLength *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + dialogTool->SetCenter(arc->GetCenter().id()); + dialogTool->SetF1(arc->GetFormulaF1()); + dialogTool->SetLength(arc->GetFormulaLength()); + dialogTool->SetRadius(arc->GetFormulaRadius()); + dialogTool->SetColor(lineColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolArcWithLength *VToolArcWithLength::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogArcWithLength *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 center = dialogTool->GetCenter(); + QString radius = dialogTool->GetRadius(); + QString f1 = dialogTool->GetF1(); + QString length = dialogTool->GetLength(); + const QString color = dialogTool->GetColor(); + VToolArcWithLength* point = nullptr; + point=Create(0, center, radius, f1, length, color, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, + QString &length, const QString &color, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation) +{ + qreal calcRadius = 0, calcF1 = 0, calcLength = 0; + + calcRadius = qApp->toPixel(CheckFormula(_id, radius, data)); + calcLength = qApp->toPixel(CheckFormula(_id, length, data)); + calcF1 = CheckFormula(_id, f1, data); + + VPointF c = *data->GeometricObject(center); + VArc *arc = new VArc(calcLength, length, c, calcRadius, radius, calcF1, f1); + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = data->AddGObject(arc); + data->AddArc(id); + } + else + { + data->UpdateGObject(id, arc); + data->AddArc(id); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::ArcWithLength, doc); + if (parse == Document::FullParse) + { + VToolArcWithLength *toolArc = new VToolArcWithLength(doc, data, id, color, typeCreation); + scene->addItem(toolArc); + connect(toolArc, &VToolArcWithLength::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, toolArc, &VToolArcWithLength::SetFactor); + connect(scene, &VMainGraphicsScene::DisableItem, toolArc, &VToolArcWithLength::Disable); + doc->AddTool(id, toolArc); + doc->IncrementReferens(center); + return toolArc; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolArcWithLength::getTagName() const +{ + return VToolArcWithLength::TagName; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolArcWithLength::getCenter() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + return arc->GetCenter().id(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::setCenter(const quint32 &value) +{ + if (value != NULL_ID) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + + QSharedPointer point = VAbstractTool::data.GeometricObject(value); + arc->SetCenter(*point.data()); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArcWithLength::GetFormulaRadius() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula radius(arc->GetFormulaRadius(), getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SetFormulaRadius(const VFormula &value) +{ + if (value.error() == false) + { + if (value.getDoubleValue() > 0)// Formula don't check this, but radius can't be 0 or negative + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaRadius(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); + SaveOption(obj); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArcWithLength::GetFormulaF1() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f1(arc->GetFormulaF1(), getData()); + f1.setCheckZero(false); + f1.setToolId(id); + f1.setPostfix(degreeSymbol); + return f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SetFormulaF1(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + + if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetEndAngle() + 1)==false)// Angles can't be equal + { + arc->SetFormulaF1(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); + SaveOption(obj); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArcWithLength::GetFormulaLength() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula radius(arc->GetFormulaLength(), getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SetFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaLength(value.GetFormula(FormulaType::FromUser), value.getDoubleValue()); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(this, event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::RemoveReferens() +{ + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + doc->DecrementReferens(arc->GetCenter().id()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogArcWithLength *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetCenter())); + doc->SetAttribute(domElement, AttrRadius, dialogTool->GetRadius()); + doc->SetAttribute(domElement, AttrAngle1, dialogTool->GetF1()); + doc->SetAttribute(domElement, AttrLength, dialogTool->GetLength()); + doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VAbstractSpline::SaveOptions(tag, obj); + + QSharedPointer arc = qSharedPointerDynamicCast(obj); + SCASSERT(arc.isNull() == false); + + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, arc->GetCenter().id()); + doc->SetAttribute(tag, AttrRadius, arc->GetFormulaRadius()); + doc->SetAttribute(tag, AttrAngle1, arc->GetFormulaF1()); + doc->SetAttribute(tag, AttrLength, arc->GetFormulaLength()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::SetVisualization() +{ + if (vis != nullptr) + { + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + VisToolArcWithLength *visual = qobject_cast(vis); + SCASSERT(visual != nullptr) + + visual->setPoint1Id(arc->GetCenter().id()); + visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius())); + visual->setF1(qApp->FormulaToUser(arc->GetFormulaF1())); + visual->setLength(qApp->FormulaToUser(arc->GetFormulaLength())); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArcWithLength::RefreshGeometry() +{ + this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPath(ToolPath()); + + SetVisualization(); +} diff --git a/src/app/tools/drawTools/vtoolarcwithlength.h b/src/app/tools/drawTools/vtoolarcwithlength.h new file mode 100644 index 000000000..38d3e7cbd --- /dev/null +++ b/src/app/tools/drawTools/vtoolarcwithlength.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file vtoolarcwithlength.h + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef VTOOLARCWITHLENGTH_H +#define VTOOLARCWITHLENGTH_H + +#include "vabstractspline.h" + +class VFormula; + +class VToolArcWithLength : public VAbstractSpline +{ + Q_OBJECT +public: + VToolArcWithLength(VPattern *doc, VContainer *data, quint32 id, const QString &color, const Source &typeCreation, + QGraphicsItem * parent = nullptr); + + virtual void setDialog(); + static VToolArcWithLength* Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolArcWithLength* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, + QString &length, const QString &color, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation); + static const QString TagName; + static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::ArcWithLength)}; + virtual QString getTagName() const; + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + VFormula GetFormulaRadius() const; + void SetFormulaRadius(const VFormula &value); + + VFormula GetFormulaF1() const; + void SetFormulaF1(const VFormula &value); + + VFormula GetFormulaLength() const; + void SetFormulaLength(const VFormula &value); + + virtual void ShowVisualization(bool show); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void RemoveReferens(); + virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void SetVisualization(); +private: + void RefreshGeometry(); + +}; + +#endif // VTOOLARCWITHLENGTH_H diff --git a/src/app/tools/tools.pri b/src/app/tools/tools.pri index 1d2ace23b..43251ec38 100644 --- a/src/app/tools/tools.pri +++ b/src/app/tools/tools.pri @@ -42,7 +42,8 @@ HEADERS += \ $$PWD/drawTools/vtoolpointofintersectionarcs.h \ $$PWD/drawTools/vtoolpointofintersectioncircles.h \ $$PWD/drawTools/vtoolpointfromcircleandtangent.h \ - tools/drawTools/vtoolpointfromarcandtangent.h + $$PWD/drawTools/vtoolpointfromarcandtangent.h \ + $$PWD/drawTools/vtoolarcwithlength.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -82,4 +83,5 @@ SOURCES += \ $$PWD/drawTools/vtoolpointofintersectionarcs.cpp \ $$PWD/drawTools/vtoolpointofintersectioncircles.cpp \ $$PWD/drawTools/vtoolpointfromcircleandtangent.cpp \ - tools/drawTools/vtoolpointfromarcandtangent.cpp + $$PWD/drawTools/vtoolpointfromarcandtangent.cpp \ + $$PWD/drawTools/vtoolarcwithlength.cpp diff --git a/src/app/visualization/vistoolarc.h b/src/app/visualization/vistoolarc.h index 57fa4b66f..ebdf2c562 100644 --- a/src/app/visualization/vistoolarc.h +++ b/src/app/visualization/vistoolarc.h @@ -29,7 +29,6 @@ #ifndef VISTOOLARC_H #define VISTOOLARC_H - #include "vispath.h" class VisToolArc : public VisPath diff --git a/src/app/visualization/vistoolarcwithlength.cpp b/src/app/visualization/vistoolarcwithlength.cpp new file mode 100644 index 000000000..423468c92 --- /dev/null +++ b/src/app/visualization/vistoolarcwithlength.cpp @@ -0,0 +1,77 @@ +/************************************************************************ + ** + ** @file vistoolarcwithlength.cpp + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "vistoolarcwithlength.h" +#include "../libs/vgeometry/vpointf.h" +#include "../libs/vgeometry/varc.h" +#include "../container/vcontainer.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolArcWithLength::VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), arcCenter(nullptr), radius(0), f1(0), length(0) +{ + arcCenter = InitPoint(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolArcWithLength::~VisToolArcWithLength() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolArcWithLength::RefreshGeometry() +{ + if (point1Id > NULL_ID) + { + const QSharedPointer first = Visualization::data->GeometricObject(point1Id); + DrawPoint(arcCenter, first->toQPointF(), supportColor); + + if (qFuzzyCompare(1 + radius, 1 + 0) == false && f1 >= 0 && qFuzzyCompare(1 + length, 1 + 0) == false) + { + VArc arc = VArc (length, *first, radius, f1); + DrawPath(this, arc.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolArcWithLength::setRadius(const QString &expression) +{ + radius = FindLength(expression); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolArcWithLength::setF1(const QString &expression) +{ + f1 = FindVal(expression); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolArcWithLength::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolarcwithlength.h b/src/app/visualization/vistoolarcwithlength.h new file mode 100644 index 000000000..9d33a1e7c --- /dev/null +++ b/src/app/visualization/vistoolarcwithlength.h @@ -0,0 +1,55 @@ +/************************************************************************ + ** + ** @file vistoolarcwithlength.h + ** @author Roman Telezhynskyi + ** @date 9 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef VISTOOLARCWITHLENGTH_H +#define VISTOOLARCWITHLENGTH_H + +#include "vispath.h" + +class VisToolArcWithLength : public VisPath +{ + Q_OBJECT +public: + VisToolArcWithLength(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolArcWithLength(); + + virtual void RefreshGeometry(); + void setRadius(const QString &expression); + void setF1(const QString &expression); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolArcWithLength)}; +private: + Q_DISABLE_COPY(VisToolArcWithLength) + QGraphicsEllipseItem *arcCenter; + qreal radius; + qreal f1; + qreal length; +}; + +#endif // VISTOOLARCWITHLENGTH_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 2db154543..22b859b49 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -30,7 +30,8 @@ HEADERS += \ $$PWD/vistoolpointofintersectionarcs.h \ $$PWD/vistoolpointofintersectioncircles.h \ $$PWD/vistoolpointfromcircleandtangent.h \ - visualization/vistoolpointfromarcandtangent.h + $$PWD/vistoolpointfromarcandtangent.h \ + $$PWD/vistoolarcwithlength.h SOURCES += \ $$PWD/vgraphicssimpletextitem.cpp \ @@ -61,4 +62,5 @@ SOURCES += \ $$PWD/vistoolpointofintersectionarcs.cpp \ $$PWD/vistoolpointofintersectioncircles.cpp \ $$PWD/vistoolpointfromcircleandtangent.cpp \ - visualization/vistoolpointfromarcandtangent.cpp + $$PWD/vistoolpointfromarcandtangent.cpp \ + $$PWD/vistoolarcwithlength.cpp diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index ae4ce5842..0f10f6a66 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -86,6 +86,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolArc::Type: ShowOptionsToolArc(item); break; + case VToolArcWithLength::Type: + ShowOptionsToolArcWithLength(item); + break; case VToolBisector::Type: ShowOptionsToolBisector(item); break; @@ -185,6 +188,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolArc::Type: UpdateOptionsToolArc(); break; + case VToolArcWithLength::Type: + UpdateOptionsToolArcWithLength(); + break; case VToolBisector::Type: UpdateOptionsToolBisector(); break; @@ -299,6 +305,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolArc::Type: ChangeDataToolArc(prop); break; + case VToolArcWithLength::Type: + ChangeDataToolArcWithLength(prop); + break; case VToolBisector::Type: ChangeDataToolBisector(prop); break; @@ -650,6 +659,36 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArc(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolArcWithLength(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolArcWithLength *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 8: // VAbstractTool::AttrRadius + i->SetFormulaRadius(value.value()); + break; + case 9: // VAbstractTool::AttrAngle1 + i->SetFormulaF1(value.value()); + break; + case 4: // VAbstractTool::AttrLength + i->SetFormulaLength(value.value()); + break; + case 27: // VAbstractTool::AttrTypeColor + i->SetLineColor(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Arc with given length")); + + AddPropertyFormula(tr("Radius"), i->GetFormulaRadius(), VAbstractTool::AttrRadius); + AddPropertyFormula(tr("First angle"), i->GetFormulaF1(), VAbstractTool::AttrAngle1); + AddPropertyFormula(tr("Length"), i->GetFormulaLength(), VAbstractTool::AttrLength); + AddPropertyLineColor(i, tr("Color"), VAbstractTool::ColorsList(), VAbstractTool::AttrColor); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) { @@ -1555,7 +1607,6 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() { VToolArc *i = qgraphicsitem_cast(currentItem); - QVariant valueRadius; valueRadius.setValue(i->GetFormulaRadius()); idToProperty[VAbstractTool::AttrRadius]->setValue(valueRadius); @@ -1572,6 +1623,27 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() idToProperty[VAbstractTool::AttrColor]->setValue(index); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolArcWithLength() +{ + VToolArcWithLength *i = qgraphicsitem_cast(currentItem); + + QVariant valueRadius; + valueRadius.setValue(i->GetFormulaRadius()); + idToProperty[VAbstractTool::AttrRadius]->setValue(valueRadius); + + QVariant valueFirstAngle; + valueFirstAngle.setValue(i->GetFormulaF1()); + idToProperty[VAbstractTool::AttrAngle1]->setValue(valueFirstAngle); + + QVariant valueLength; + valueLength.setValue(i->GetFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueLength); + + const qint32 index = VLineColorProperty::IndexOfColor(VAbstractTool::ColorsList(), i->GetLineColor()); + idToProperty[VAbstractTool::AttrColor]->setValue(index); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector() { diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index 0b0d068de..604ed84f5 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -92,6 +92,7 @@ private: void ChangeDataToolEndLine(VPE::VProperty *property); void ChangeDataToolAlongLine(VPE::VProperty *property); void ChangeDataToolArc(VPE::VProperty *property); + void ChangeDataToolArcWithLength(VPE::VProperty *property); void ChangeDataToolBisector(VPE::VProperty *property); void ChangeDataToolCutArc(VPE::VProperty *property); void ChangeDataToolCutSpline(VPE::VProperty *property); @@ -117,6 +118,7 @@ private: void ShowOptionsToolEndLine(QGraphicsItem *item); void ShowOptionsToolAlongLine(QGraphicsItem *item); void ShowOptionsToolArc(QGraphicsItem *item); + void ShowOptionsToolArcWithLength(QGraphicsItem *item); void ShowOptionsToolBisector(QGraphicsItem *item); void ShowOptionsToolCutArc(QGraphicsItem *item); void ShowOptionsToolCutSpline(QGraphicsItem *item); @@ -142,6 +144,7 @@ private: void UpdateOptionsToolEndLine(); void UpdateOptionsToolAlongLine(); void UpdateOptionsToolArc(); + void UpdateOptionsToolArcWithLength(); void UpdateOptionsToolBisector(); void UpdateOptionsToolCutArc(); void UpdateOptionsToolCutSpline(); diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index b788ab6e0..6fd90b777 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2091,7 +2091,7 @@ void VPattern::ParseArcElement(VMainGraphicsScene *scene, QDomElement &domElemen Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); quint32 id = 0; - QStringList arcs = QStringList() << VToolArc::ToolType << VNodeArc::ToolType; + QStringList arcs = QStringList() << VToolArc::ToolType << VNodeArc::ToolType << VToolArcWithLength::ToolType; switch (arcs.indexOf(type)) { @@ -2151,6 +2151,44 @@ void VPattern::ParseArcElement(VMainGraphicsScene *scene, QDomElement &domElemen throw excep; } break; + case 2: //VToolArcWithLength::ToolType + try + { + ToolsCommonAttributes(domElement, id); + const quint32 center = GetParametrUInt(domElement, VAbstractTool::AttrCenter, NULL_ID_STR); + const QString radius = GetParametrString(domElement, VAbstractTool::AttrRadius, "10"); + QString r = radius;//need for saving fixed formula; + const QString f1 = GetParametrString(domElement, VAbstractTool::AttrAngle1, "180"); + QString f1Fix = f1;//need for saving fixed formula; + const QString length = GetParametrString(domElement, VAbstractTool::AttrLength, "10"); + QString lengthFix = length;//need for saving fixed length; + const QString color = GetParametrString(domElement, VAbstractTool::AttrColor, + VAbstractTool::ColorBlack); + + VToolArcWithLength::Create(id, center, r, f1Fix, lengthFix, color, scene, this, data, parse, + Source::FromFile); + //Rewrite attribute formula. Need for situation when we have wrong formula. + if (r != radius || f1Fix != f1 || lengthFix != length) + { + SetAttribute(domElement, VAbstractTool::AttrRadius, r); + SetAttribute(domElement, VAbstractTool::AttrAngle1, f1Fix); + SetAttribute(domElement, VAbstractTool::AttrLength, lengthFix); + haveLiteChange(); + } + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + catch (qmu::QmuParserError &e) + { + VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement); + excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr())); + throw excep; + } + break; default: qDebug() << "Illegal arc type in VDomDocument::ParseArcElement()."; break; diff --git a/src/libs/ifc/schema/pattern/v0.1.4.xsd b/src/libs/ifc/schema/pattern/v0.1.4.xsd index e6acac940..caabf1851 100644 --- a/src/libs/ifc/schema/pattern/v0.1.4.xsd +++ b/src/libs/ifc/schema/pattern/v0.1.4.xsd @@ -153,6 +153,7 @@ + diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index 7e0047826..8a4cd9468 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -185,7 +185,7 @@ QPainterPath VAbstractCurve::ShowDirection(const QVector &points) const { /*Need find coordinate midle of curve. Universal way is take all points and find sum.*/ - const qreal seek_length = GetLength()/2.0; + const qreal seek_length = qAbs(GetLength())/2.0; qreal found_length = 0; QLineF arrow; for (qint32 i = 1; i <= points.size()-1; ++i) diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index be7c64a88..5080f92c5 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -216,8 +216,7 @@ QVector VArc::GetPoints() const points.append(line.p2()); } } while (i <= angle); - // Detail points clockwise, but arc we draw counterclockwise. Main contour need reverse. - return GetReversePoints(points); + return points; } //---------------------------------------------------------------------------------------------------------------------