diff --git a/src/app/dialogs/tools/dialogspline.cpp b/src/app/dialogs/tools/dialogspline.cpp index 07351826c..8654c7557 100644 --- a/src/app/dialogs/tools/dialogspline.cpp +++ b/src/app/dialogs/tools/dialogspline.cpp @@ -31,6 +31,7 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolspline.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,10 +41,10 @@ */ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), number(0), p1(NULL_ID), p4(NULL_ID), angle1(0), - angle2(0), kAsm1(1), kAsm2(1), kCurve(1) + angle2(0), kAsm1(1), kAsm2(1), kCurve(1), path(nullptr) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); @@ -51,11 +52,14 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge this, &DialogSpline::PointNameChanged); connect(ui->comboBoxP4, static_cast(&QComboBox::currentIndexChanged), this, &DialogSpline::PointNameChanged); + + path = new VisToolSpline(data); } //--------------------------------------------------------------------------------------------------------------------- DialogSpline::~DialogSpline() { + delete path; delete ui; } @@ -77,44 +81,50 @@ quint32 DialogSpline::getP1() const */ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) { - if (type == SceneObject::Point) + if (prepare == false)// After first choose we ignore all objects { - switch (number) + if (type == SceneObject::Point) { - case 0: - if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve"))) - { - number++; - } - break; - case 1: + switch (number) { - const VPointF *point = data->GeometricObject(id); - qint32 index = ui->comboBoxP4->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxP4->setCurrentIndex(index); - emit ToolTip(""); - index = ui->comboBoxP1->currentIndex(); - quint32 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); - - QPointF p1 = data->GeometricObject(p1Id)->toQPointF(); - QPointF p4 = data->GeometricObject(id)->toQPointF(); - - ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); - ui->spinBoxAngle2->setValue(static_cast(QLineF(p4, p1).angle())); - - this->setModal(true); - this->show(); - } - else + case 0: + if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve"))) + { + number++; + path->VisualMode(id); + } + break; + case 1: { - qWarning()<<"Can't find object by name"<name(); + const VPointF *point = data->GeometricObject(id); + qint32 index = ui->comboBoxP4->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxP4->setCurrentIndex(index); + emit ToolTip(""); + index = ui->comboBoxP1->currentIndex(); + quint32 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); + + QPointF p1 = data->GeometricObject(p1Id)->toQPointF(); + QPointF p4 = data->GeometricObject(id)->toQPointF(); + + ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); + ui->spinBoxAngle2->setValue(static_cast(QLineF(p4, p1).angle())); + + path->setPoint4Id(id); + path->RefreshGeometry(); + prepare = true; + DialogAccepted(); + } + else + { + qWarning()<<"Can't find object by name"<name(); + } + break; } - break; + default: + break; } - default: - break; } } } @@ -129,6 +139,15 @@ void DialogSpline::SaveData() kAsm1 = ui->doubleSpinBoxKasm1->value(); kAsm2 = ui->doubleSpinBoxKasm2->value(); kCurve = ui->doubleSpinBoxKcurve->value(); + + path->setPoint1Id(p1); + path->setPoint4Id(p4); + path->setAngle1(angle1); + path->setAngle2(angle2); + path->setKAsm1(kAsm1); + path->setKAsm2(kAsm2); + path->setKCurve(kCurve); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -163,6 +182,18 @@ void DialogSpline::UpdateList() */ } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setKCurve set coefficient curve @@ -172,6 +203,7 @@ void DialogSpline::setKCurve(const qreal &value) { kCurve = value; ui->doubleSpinBoxKcurve->setValue(value); + path->setKCurve(kCurve); } //--------------------------------------------------------------------------------------------------------------------- @@ -183,6 +215,7 @@ void DialogSpline::setKAsm2(const qreal &value) { kAsm2 = value; ui->doubleSpinBoxKasm2->setValue(value); + path->setKAsm2(kAsm2); } //--------------------------------------------------------------------------------------------------------------------- @@ -194,6 +227,7 @@ void DialogSpline::setKAsm1(const qreal &value) { kAsm1 = value; ui->doubleSpinBoxKasm1->setValue(value); + path->setKAsm1(kAsm1); } //--------------------------------------------------------------------------------------------------------------------- @@ -205,6 +239,7 @@ void DialogSpline::setAngle2(const qreal &value) { angle2 = value; ui->spinBoxAngle2->setValue(static_cast(value)); + path->setAngle2(angle2); } //--------------------------------------------------------------------------------------------------------------------- @@ -216,6 +251,7 @@ void DialogSpline::setAngle1(const qreal &value) { angle1 = value; ui->spinBoxAngle1->setValue(static_cast(value)); + path->setAngle1(angle1); } //--------------------------------------------------------------------------------------------------------------------- @@ -226,6 +262,7 @@ void DialogSpline::setAngle1(const qreal &value) void DialogSpline::setP4(const quint32 &value) { setPointId(ui->comboBoxP4, p4, value); + path->setPoint4Id(p4); } //--------------------------------------------------------------------------------------------------------------------- @@ -236,6 +273,7 @@ void DialogSpline::setP4(const quint32 &value) void DialogSpline::setP1(const quint32 &value) { setPointId(ui->comboBoxP1, p1, value); + path->setPoint1Id(p1); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogspline.h b/src/app/dialogs/tools/dialogspline.h index d288d7615..20d97f396 100644 --- a/src/app/dialogs/tools/dialogspline.h +++ b/src/app/dialogs/tools/dialogspline.h @@ -36,6 +36,8 @@ namespace Ui class DialogSpline; } +class VisToolSpline; + /** * @brief The DialogSpline class dialog for ToolSpline. Help create spline and edit option. */ @@ -71,6 +73,7 @@ public slots: virtual void PointNameChanged(); virtual void UpdateList(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -104,6 +107,8 @@ private: /** @brief kCurve coefficient curve */ qreal kCurve; + + VisToolSpline *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogspline.ui b/src/app/dialogs/tools/dialogspline.ui index 721ffae3b..f8bda5f49 100644 --- a/src/app/dialogs/tools/dialogspline.ui +++ b/src/app/dialogs/tools/dialogspline.ui @@ -202,7 +202,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4ee42633a..8c4ecbb83 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -473,8 +473,10 @@ void MainWindow::ToolLineIntersect(bool checked) */ void MainWindow::ToolSpline(bool checked) { - SetToolButton(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", - tr("Select first point curve"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", + tr("Select first point curve"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 1488c72cb..4b4e312c0 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -107,8 +107,9 @@ void VToolSpline::setDialog() * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. + * @return the created tool */ -void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogSpline *dialogTool = qobject_cast(dialog); @@ -120,8 +121,14 @@ void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern const qreal angle1 = dialogTool->getAngle1(); const qreal angle2 = dialogTool->getAngle2(); const qreal kCurve = dialogTool->getKCurve(); - Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolSpline *spl = nullptr; + spl = Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, doc, data, Document::FullParse, + Source::FromGui); + if (spl != nullptr) + { + spl->dialog=dialogTool; + } + return spl; } //--------------------------------------------------------------------------------------------------------------------- @@ -140,11 +147,12 @@ void VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. + * @return the created tool */ -void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) { VPointF point1 = *data->GeometricObject(p1); VPointF point4 = *data->GeometricObject(p4); @@ -175,7 +183,9 @@ void VToolSpline::Create(const quint32 _id, const quint32 &p1, const quint32 &p4 doc->AddTool(id, spl); doc->IncrementReferens(p1); doc->IncrementReferens(p4); + return spl; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index 7d1490c66..153d4f917 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -42,11 +42,11 @@ public: VToolSpline (VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem * parent = nullptr ); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolSpline *Create(const quint32 _id, const quint32 &p1, const quint32 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); static const QString ToolType; public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index f9e20fda0..e1e113cd3 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -41,15 +41,6 @@ VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) VisLine::~VisLine() {} -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style) -{ - SCASSERT (lineItem != nullptr); - - lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); - lineItem->setLine(line); -} - //--------------------------------------------------------------------------------------------------------------------- QLineF VisLine::Line(const QPointF &p1, const qreal &length, const qreal &angle) { diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index b271d6b87..ec7933a1f 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -43,8 +43,6 @@ public: virtual ~VisLine(); protected: - void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, - Qt::PenStyle style = Qt::SolidLine); QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle); qreal CorrectAngle(const qreal &angle) const; QPointF Ray(const QPointF &firstPoint, const qreal &angle) const; diff --git a/src/app/visualization/vistoolspline.cpp b/src/app/visualization/vistoolspline.cpp new file mode 100644 index 000000000..4cf8c4f09 --- /dev/null +++ b/src/app/visualization/vistoolspline.cpp @@ -0,0 +1,119 @@ +/************************************************************************ + ** + ** @file vistoolspline.cpp + ** @author Roman Telezhynskyi + ** @date 18 8, 2014 + ** + ** @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) 2014 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 "vistoolspline.h" +#include "../geometry/vpointf.h" +#include "../geometry/vspline.h" +#include "../container/vcontainer.h" + +const int EMPTY_ANGLE = -1; + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), point4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE), + angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1) +{ + lineP1 = InitPoint(supportColor, this); + lineP4 = InitPoint(supportColor, this); + line = InitItem(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSpline::~VisToolSpline() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::RefreshGeometry() +{ + if (point1Id > 0) + { + const VPointF *first = Visualization::data->GeometricObject(point1Id); + DrawPoint(lineP1, first->toQPointF(), supportColor); + + if (point4Id <= 0) + { + DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), mainColor); + } + else + { + const VPointF *second = Visualization::data->GeometricObject(point4Id); + DrawPoint(lineP4, second->toQPointF(), supportColor); + + if (qFuzzyCompare(angle1, EMPTY_ANGLE) || qFuzzyCompare(angle2, EMPTY_ANGLE)) + { + DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), mainColor); + } + else + { + VSpline spline(*first, *second, angle1, angle2, kAsm1, kAsm2, kCurve); + DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setPoint4Id(const quint32 &value) +{ + point4Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setAngle1(const qreal &value) +{ + angle1 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setAngle2(const qreal &value) +{ + angle2 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setKAsm1(const qreal &value) +{ + kAsm1 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setKAsm2(const qreal &value) +{ + kAsm2 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::setKCurve(const qreal &value) +{ + kCurve = value; +} + + + + + diff --git a/src/app/visualization/vistoolspline.h b/src/app/visualization/vistoolspline.h new file mode 100644 index 000000000..1a2c9f9f9 --- /dev/null +++ b/src/app/visualization/vistoolspline.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file vistoolspline.h + ** @author Roman Telezhynskyi + ** @date 18 8, 2014 + ** + ** @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) 2014 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 VISTOOLSPLINE_H +#define VISTOOLSPLINE_H + +#include "vispath.h" + +class VisToolSpline : public VisPath +{ + Q_OBJECT +public: + VisToolSpline(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolSpline(); + + virtual void RefreshGeometry(); + + void setPoint4Id(const quint32 &value); + void setAngle1(const qreal &value); + void setAngle2(const qreal &value); + void setKAsm1(const qreal &value); + void setKAsm2(const qreal &value); + void setKCurve(const qreal &value); +protected: + Q_DISABLE_COPY(VisToolSpline) + quint32 point4Id; + QGraphicsEllipseItem *lineP1; + QGraphicsEllipseItem *lineP4; + QGraphicsLineItem *line; + qreal angle1; + qreal angle2; + qreal kAsm1; + qreal kAsm2; + qreal kCurve; +}; + +#endif // VISTOOLSPLINE_H diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp index e548df081..914d8ba06 100644 --- a/src/app/visualization/visualization.cpp +++ b/src/app/visualization/visualization.cpp @@ -168,3 +168,12 @@ void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, c point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style)); point->setVisible(true); } + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style) +{ + SCASSERT (lineItem != nullptr); + + lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); + lineItem->setLine(line); +} diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h index db0968c14..835e46f56 100644 --- a/src/app/visualization/visualization.h +++ b/src/app/visualization/visualization.h @@ -73,6 +73,8 @@ protected: qreal FindVal(const QString &expression); void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); + void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, + Qt::PenStyle style = Qt::SolidLine); template void AddItem(Item *item) diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 5fe9225ef..b3397108a 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -18,7 +18,8 @@ HEADERS += \ visualization/visualization.h \ visualization/vistoolarc.h \ visualization/vispath.h \ - visualization/vistoolcutarc.h + visualization/vistoolcutarc.h \ + visualization/vistoolspline.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -40,4 +41,5 @@ SOURCES += \ visualization/visualization.cpp \ visualization/vistoolarc.cpp \ visualization/vispath.cpp \ - visualization/vistoolcutarc.cpp + visualization/vistoolcutarc.cpp \ + visualization/vistoolspline.cpp