From 2ff611b9233b6bd5af69fb71d5a40fc2ad946aa6 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 25 Jul 2014 12:55:27 +0300 Subject: [PATCH] Visualization for VToolShoulderPoint. --HG-- branch : develop --- src/app/dialogs/tools/dialogalongline.cpp | 1 - src/app/dialogs/tools/dialogbisector.cpp | 1 - src/app/dialogs/tools/dialogendline.cpp | 1 - src/app/dialogs/tools/dialogshoulderpoint.cpp | 119 +++++++++++------ src/app/dialogs/tools/dialogshoulderpoint.h | 6 + src/app/mainwindow.cpp | 2 +- src/app/visualization/visline.cpp | 2 +- src/app/visualization/visline.h | 2 +- src/app/visualization/vistoolendline.cpp | 10 -- src/app/visualization/vistoolendline.h | 1 - .../visualization/vistoolshoulderpoint.cpp | 121 ++++++++++++++++++ src/app/visualization/vistoolshoulderpoint.h | 59 +++++++++ src/app/visualization/visualization.pri | 6 +- 13 files changed, 276 insertions(+), 55 deletions(-) create mode 100644 src/app/visualization/vistoolshoulderpoint.cpp create mode 100644 src/app/visualization/vistoolshoulderpoint.h diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 8160aeb4d..aa076d02c 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -158,7 +158,6 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type) if (isInitialized == false) { line->setPoint2Id(id); - line->setMainColor(Qt::red); line->RefreshGeometry(); prepare = true; diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 2055678ae..92dc8adb5 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -186,7 +186,6 @@ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type) ui->comboBoxThirdPoint->setCurrentIndex(index); number = 0; line->setPoint3Id(id); - line->setMainColor(Qt::red); line->RefreshGeometry(); prepare = true; emit ToolTip(""); diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index e1eec0b57..305f71c24 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -207,7 +207,6 @@ void DialogEndLine::ShowDialog(bool click) } this->setModal(true); this->setAngle(line->Angle());//Show in dialog angle what user choose - line->setMainColor(Qt::red);//Now linw will be red emit ToolTip(""); this->show(); } diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 22d6507df..4f050134b 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -31,6 +31,9 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolshoulderpoint.h" +#include "../../widgets/vmaingraphicsscene.h" +#include "../../tools/vabstracttool.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,7 +43,8 @@ */ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0) + typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0), formulaBaseHeight(0), line (nullptr), + prepare(false) { ui->setupUi(this); InitVariables(ui); @@ -70,6 +74,8 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, QWidget *parent this, &DialogShoulderPoint::PointNameChanged); connect(ui->comboBoxPShoulder, static_cast(&QComboBox::currentIndexChanged), this, &DialogShoulderPoint::PointNameChanged); + + line = new VisToolShoulderPoint(data); } //--------------------------------------------------------------------------------------------------------------------- @@ -103,6 +109,19 @@ void DialogShoulderPoint::PointNameChanged() CheckState(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogShoulderPoint::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); + scene->addItem(line); + line->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogShoulderPoint::DeployFormulaTextEdit() { @@ -112,6 +131,7 @@ void DialogShoulderPoint::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogShoulderPoint::~DialogShoulderPoint() { + delete line; delete ui; } @@ -123,44 +143,59 @@ DialogShoulderPoint::~DialogShoulderPoint() */ void DialogShoulderPoint::ChosenObject(quint32 id, const SceneObject &type) { - if (type == SceneObject::Point) + if (prepare == false) { - const VPointF *point = data->GeometricObject(id); - if (number == 0) + if (type == SceneObject::Point) { - qint32 index = ui->comboBoxP1Line->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxP1Line->setCurrentIndex(index); - number++; - emit ToolTip(tr("Select second point of line")); - return; - } - } - if (number == 1) - { - qint32 index = ui->comboBoxP2Line->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxP2Line->setCurrentIndex(index); - number++; - emit ToolTip(tr("Select point of shoulder")); - return; - } - } - if (number == 2) - { - qint32 index = ui->comboBoxPShoulder->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxPShoulder->setCurrentIndex(index); - number = 0; - emit ToolTip(""); - } - if (isInitialized == false) + const VPointF *point = data->GeometricObject(id); + if (number == 0) { - this->setModal(true); - this->show(); + qint32 index = ui->comboBoxPShoulder->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxPShoulder->setCurrentIndex(index); + number++; + VMainGraphicsScene *scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + line->VisualMode(id, scene->getScenePos()); + scene->addItem(line); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolShoulderPoint::SetFactor); + connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolShoulderPoint::MousePos); + emit ToolTip(tr("Select first point of line")); + return; + } + } + if (number == 1) + { + qint32 index = ui->comboBoxP1Line->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxP1Line->setCurrentIndex(index); + number++; + line->setLineP1Id(id); + line->RefreshGeometry(); + emit ToolTip(tr("Select second point of line")); + return; + } + } + if (number == 2) + { + qint32 index = ui->comboBoxP2Line->findText(point->name()); + + if ( index != -1 ) + { // -1 for not found + ui->comboBoxP2Line->setCurrentIndex(index); + number = 0; + line->setLineP2Id(id); + line->RefreshGeometry(); + prepare = true; + emit ToolTip(""); + } + if (isInitialized == false) + { + this->setModal(true); + this->show(); + } } } } @@ -192,6 +227,13 @@ void DialogShoulderPoint::SaveData() p1Line = getCurrentObjectId(ui->comboBoxP1Line); p2Line = getCurrentObjectId(ui->comboBoxP2Line); pShoulder = getCurrentObjectId(ui->comboBoxPShoulder); + + line->setPoint1Id(pShoulder); + line->setLineP1Id(p1Line); + line->setLineP2Id(p2Line); + line->setLength(formula); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); + line->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -203,6 +245,7 @@ void DialogShoulderPoint::SaveData() void DialogShoulderPoint::setPShoulder(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxPShoulder, pShoulder, value, id); + line->setPoint1Id(pShoulder); } //--------------------------------------------------------------------------------------------------------------------- @@ -214,6 +257,7 @@ void DialogShoulderPoint::setPShoulder(const quint32 &value, const quint32 &id) void DialogShoulderPoint::setP2Line(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxP2Line, p2Line, value, id); + line->setLineP2Id(p2Line); } //--------------------------------------------------------------------------------------------------------------------- @@ -225,6 +269,7 @@ void DialogShoulderPoint::setP2Line(const quint32 &value, const quint32 &id) void DialogShoulderPoint::setP1Line(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxP1Line, p1Line, value, id); + line->setLineP1Id(p1Line); } //--------------------------------------------------------------------------------------------------------------------- @@ -241,6 +286,7 @@ void DialogShoulderPoint::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + line->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -252,6 +298,7 @@ void DialogShoulderPoint::setTypeLine(const QString &value) { typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index ce2ac4d8c..a64da204b 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -36,6 +36,8 @@ namespace Ui class DialogShoulderPoint; } +class VisToolShoulderPoint; + /** * @brief The DialogShoulderPoint class dialog for ToolShoulderPoint. Help create point and edit option. */ @@ -79,6 +81,8 @@ public slots: */ void FormulaTextChanged(); virtual void PointNameChanged(); +protected: + virtual void ShowVisualization(); private: Q_DISABLE_COPY(DialogShoulderPoint) @@ -108,6 +112,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + VisToolShoulderPoint *line; + bool prepare; /** * @brief SaveData Put dialog data in local variables diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index b4cdc7f5d..59688e346 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -481,7 +481,7 @@ void MainWindow::ClosedDialogAlongLine(int result) void MainWindow::ToolShoulderPoint(bool checked) { SetToolButtonWithApply(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", - tr("Select first point of line"), &MainWindow::ClosedDialogShoulderPoint, + tr("Select point of shoulder"), &MainWindow::ClosedDialogShoulderPoint, &MainWindow::ApplyDialogShoulderPoint); } diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index 9f0f41cca..a246ce827 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -38,6 +38,7 @@ VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString()) { this->setZValue(1);// Show on top real tool + this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); } //--------------------------------------------------------------------------------------------------------------------- @@ -232,7 +233,6 @@ void VisLine::setScenePos(const QPointF &value) //--------------------------------------------------------------------------------------------------------------------- void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos) { - this->mainColor = Qt::black; this->point1Id = pointId; this->scenePos = scenePos; RefreshGeometry(); diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index e94f2b324..5ffc57a28 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -46,7 +46,7 @@ public: void setLineStyle(const Qt::PenStyle &value); virtual void RefreshGeometry()=0; void setScenePos(const QPointF &value); - virtual void VisualMode(const quint32 &pointId, const QPointF &scenePos); + void VisualMode(const quint32 &pointId, const QPointF &scenePos); void setMainColor(const QColor &value); signals: void ToolTip(const QString &toolTip); diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index 6b74bdfd5..3ae5b4f5b 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -76,16 +76,6 @@ void VisToolEndLine::RefreshGeometry() "Enter - finish creation")).arg(this->line().angle()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos) -{ - this->mainColor = Qt::black; - this->point1Id = pointId; - this->scenePos = scenePos; - RefreshGeometry(); -} - - //--------------------------------------------------------------------------------------------------------------------- qreal VisToolEndLine::Angle() const { diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h index 32e8b17fa..bffc99af4 100644 --- a/src/app/visualization/vistoolendline.h +++ b/src/app/visualization/vistoolendline.h @@ -41,7 +41,6 @@ public: virtual ~VisToolEndLine(); virtual void RefreshGeometry(); - void VisualMode(const quint32 &pointId, const QPointF &scenePos); qreal Angle() const; void setAngle(const qreal &value); void setLength(const QString &expression); diff --git a/src/app/visualization/vistoolshoulderpoint.cpp b/src/app/visualization/vistoolshoulderpoint.cpp new file mode 100644 index 000000000..af7864228 --- /dev/null +++ b/src/app/visualization/vistoolshoulderpoint.cpp @@ -0,0 +1,121 @@ +/************************************************************************ + ** + ** @file vistoolshoulderpoint.cpp + ** @author Roman Telezhynskyi + ** @date 25 7, 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 "vistoolshoulderpoint.h" +#include "../tools/drawTools/vtoolshoulderpoint.h" +#include "../geometry/vpointf.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent) + :VisLine(data, parent), lineP1Id(0), lineP2Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr), + line1(nullptr), line2P2(nullptr), line2(nullptr), line3(nullptr), length(0) +{ + line1P1 = InitPoint(supportColor); + line1P2 = InitPoint(supportColor); + line1 = InitLine(supportColor); + + line2P2 = InitPoint(supportColor); + line2 = InitLine(supportColor); + line3 = InitLine(supportColor); + + point = InitPoint(mainColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolShoulderPoint::~VisToolShoulderPoint() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolShoulderPoint::RefreshGeometry() +{ + if (point1Id > 0) + { + const VPointF *first = data->GeometricObject(point1Id); + DrawPoint(line1P1, first->toQPointF(), supportColor); + + if (lineP1Id <= 0) + { + DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor); + } + else + { + const VPointF *second = data->GeometricObject(lineP1Id); + DrawPoint(line1P2, second->toQPointF(), supportColor); + + DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + + if (lineP2Id <= 0) + { + DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor); + } + else + { + const VPointF *third = data->GeometricObject(lineP2Id); + DrawPoint(line2P2, third->toQPointF(), supportColor); + + DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + QPointF fPoint = VToolShoulderPoint::FindPoint(second->toQPointF(), third->toQPointF(), + first->toQPointF(), length); + QLineF mainLine = QLineF(second->toQPointF(), fPoint); + DrawLine(this, mainLine, mainColor, lineStyle); + + DrawPoint(point, mainLine.p2(), mainColor); + DrawLine(line3, QLineF(first->toQPointF(), mainLine.p2()), supportColor, Qt::DashLine); + } + else + { + qreal angle = QLineF(second->toQPointF(), third->toQPointF()).angle(); + QPointF endRay = Ray(second->toQPointF(), angle); + QLineF mainLine = Line(second->toQPointF(), QLineF(second->toQPointF(), endRay).length(), angle); + DrawLine(this, mainLine, mainColor, lineStyle); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolShoulderPoint::setLineP1Id(const quint32 &value) +{ + lineP1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolShoulderPoint::setLineP2Id(const quint32 &value) +{ + lineP2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolShoulderPoint::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolshoulderpoint.h b/src/app/visualization/vistoolshoulderpoint.h new file mode 100644 index 000000000..6511f253b --- /dev/null +++ b/src/app/visualization/vistoolshoulderpoint.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file vistoolshoulderpoint.h + ** @author Roman Telezhynskyi + ** @date 25 7, 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 VISTOOLSHOULDERPOINT_H +#define VISTOOLSHOULDERPOINT_H + +#include "visline.h" + +class VisToolShoulderPoint : public VisLine +{ + Q_OBJECT +public: + VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolShoulderPoint(); + + virtual void RefreshGeometry(); + void setLineP1Id(const quint32 &value); + void setLineP2Id(const quint32 &value); + void setLength(const QString &expression); +private: + Q_DISABLE_COPY(VisToolShoulderPoint) + quint32 lineP1Id; + quint32 lineP2Id; + QGraphicsEllipseItem *point; + QGraphicsEllipseItem *line1P1; + QGraphicsEllipseItem *line1P2; + QGraphicsLineItem *line1; + QGraphicsEllipseItem *line2P2; + QGraphicsLineItem *line2; + QGraphicsLineItem *line3; + qreal length; +}; + +#endif // VISTOOLSHOULDERPOINT_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 4c9c409d8..25170f9e7 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -7,7 +7,8 @@ HEADERS += \ visualization/vistoolline.h \ visualization/vistoolendline.h \ visualization/vistoolalongline.h \ - visualization/vistoolbisector.h + visualization/vistoolbisector.h \ + visualization/vistoolshoulderpoint.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -18,4 +19,5 @@ SOURCES += \ visualization/vistoolline.cpp \ visualization/vistoolendline.cpp \ visualization/vistoolalongline.cpp \ - visualization/vistoolbisector.cpp + visualization/vistoolbisector.cpp \ + visualization/vistoolshoulderpoint.cpp