diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 2bac1951c..2055678ae 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -31,6 +31,9 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolbisector.h" +#include "../../widgets/vmaingraphicsscene.h" +#include "../../tools/vabstracttool.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,8 +43,8 @@ */ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) :DialogTool(data, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), - formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0), - formulaBaseHeight(0) + formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0), formulaBaseHeight(0), line(nullptr), + prepare(false) { ui->setupUi(this); InitVariables(ui); @@ -72,6 +75,8 @@ DialogBisector::DialogBisector(const VContainer *data, QWidget *parent) this, &DialogBisector::PointNameChanged); connect(ui->comboBoxThirdPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogBisector::PointNameChanged); + + line = new VisToolBisector(data); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,6 +110,18 @@ void DialogBisector::PointNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogBisector::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor); + scene->addItem(line); + line->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogBisector::DeployFormulaTextEdit() { @@ -114,6 +131,7 @@ void DialogBisector::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogBisector::~DialogBisector() { + delete line; delete ui; } @@ -125,44 +143,59 @@ DialogBisector::~DialogBisector() */ void DialogBisector::ChosenObject(quint32 id, const SceneObject &type) { - if (type == SceneObject::Point) + if (prepare == false)// After first choose we ignore all objects { - const VPointF *point = data->GeometricObject(id); - if (number == 0) + if (type == SceneObject::Point) { - qint32 index = ui->comboBoxFirstPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxFirstPoint->setCurrentIndex(index); - number++; - emit ToolTip(tr("Select second point of angle")); - return; - } - } - if (number == 1) - { - qint32 index = ui->comboBoxSecondPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxSecondPoint->setCurrentIndex(index); - number++; - emit ToolTip(tr("Select third point of angle")); - return; - } - } - if (number == 2) - { - qint32 index = ui->comboBoxThirdPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxThirdPoint->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->comboBoxFirstPoint->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxFirstPoint->setCurrentIndex(index); + number++; + VMainGraphicsScene *scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + line->VisualMode(id, scene->getScenePos()); + scene->addItem(line); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor); + connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolBisector::MousePos); + emit ToolTip(tr("Select second point of angle")); + return; + } + } + if (number == 1) + { + qint32 index = ui->comboBoxSecondPoint->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxSecondPoint->setCurrentIndex(index); + number++; + line->setPoint2Id(id); + line->RefreshGeometry(); + emit ToolTip(tr("Select third point of angle")); + return; + } + } + if (number == 2) + { + qint32 index = ui->comboBoxThirdPoint->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxThirdPoint->setCurrentIndex(index); + number = 0; + line->setPoint3Id(id); + line->setMainColor(Qt::red); + line->RefreshGeometry(); + prepare = true; + emit ToolTip(""); + } + if (isInitialized == false) + { + this->setModal(true); + this->show(); + } } } } @@ -188,6 +221,7 @@ void DialogBisector::setTypeLine(const QString &value) { typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); } //--------------------------------------------------------------------------------------------------------------------- @@ -204,6 +238,7 @@ void DialogBisector::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + line->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -215,6 +250,7 @@ void DialogBisector::setFormula(const QString &value) void DialogBisector::setFirstPointId(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxFirstPoint, firstPointId, value, id); + line->setPoint1Id(firstPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -226,6 +262,7 @@ void DialogBisector::setFirstPointId(const quint32 &value, const quint32 &id) void DialogBisector::setSecondPointId(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxSecondPoint, secondPointId, value, id); + line->setPoint2Id(secondPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -237,6 +274,7 @@ void DialogBisector::setSecondPointId(const quint32 &value, const quint32 &id) void DialogBisector::setThirdPointId(const quint32 &value, const quint32 &id) { setPointId(ui->comboBoxThirdPoint, thirdPointId, value, id); + line->setPoint3Id(thirdPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -265,4 +303,11 @@ void DialogBisector::SaveData() firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint); secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); thirdPointId = getCurrentObjectId(ui->comboBoxThirdPoint); + + line->setPoint1Id(firstPointId); + line->setPoint2Id(secondPointId); + line->setPoint3Id(thirdPointId); + line->setLength(formula); + line->setLineStyle(VAbstractTool::LineStyle(typeLine)); + line->RefreshGeometry(); } diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 50f81b405..288daf43e 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -36,6 +36,8 @@ namespace Ui class DialogBisector; } +class VisToolBisector; + /** * @brief The DialogBisector class dialog for ToolBisector. Help create point and edit option. */ @@ -80,6 +82,8 @@ public slots: */ void FormulaTextChanged(); virtual void PointNameChanged(); +protected: + virtual void ShowVisualization(); private: Q_DISABLE_COPY(DialogBisector) @@ -109,6 +113,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + VisToolBisector *line; + bool prepare; /** * @brief SaveData Put dialog data in local variables diff --git a/src/app/dialogs/tools/dialogbisector.ui b/src/app/dialogs/tools/dialogbisector.ui index 12b0f12cc..7bc3e1392 100644 --- a/src/app/dialogs/tools/dialogbisector.ui +++ b/src/app/dialogs/tools/dialogbisector.ui @@ -269,7 +269,7 @@ - + 0 0 @@ -293,7 +293,7 @@ - + 0 0 @@ -317,7 +317,7 @@ - + 0 0 diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 3bc3cd623..31edd4178 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -65,6 +65,23 @@ VToolBisector::VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, } } +//--------------------------------------------------------------------------------------------------------------------- +qreal VToolBisector::BisectorAngle(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint) +{ + QLineF line1(secondPoint, firstPoint); + QLineF line2(secondPoint, thirdPoint); + qreal angle = line1.angleTo(line2); + if (angle>180) + { + angle = 360 - angle; + return line1.angle()-angle/2; + } + else + { + return line1.angle()+angle/2; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FindPoint find bisector point. @@ -78,17 +95,7 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon const QPointF &thirdPoint, const qreal &length) { QLineF line1(secondPoint, firstPoint); - QLineF line2(secondPoint, thirdPoint); - qreal angle = line1.angleTo(line2); - if (angle>180) - { - angle = 360 - angle; - line1.setAngle(line1.angle()-angle/2); - } - else - { - line1.setAngle(line1.angle()+angle/2); - } + line1.setAngle(BisectorAngle(firstPoint, secondPoint, thirdPoint)); line1.setLength(length); return line1.p2(); } diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 58a1a7951..1b6bf211a 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -42,6 +42,7 @@ public: VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + static qreal BisectorAngle(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint); static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const QPointF &thirdPoint, const qreal& length); virtual void setDialog(); diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index 078aef6ec..9f0f41cca 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -147,6 +147,7 @@ QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color) point->setBrush(QBrush(Qt::NoBrush)); point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor)); point->setRect(PointRect()); + point->setFlags(QGraphicsItem::ItemStacksBehindParent); return point; } @@ -160,6 +161,61 @@ QGraphicsLineItem *VisLine::InitLine(const QColor &color) return line; } +qreal VisLine::CorrectAngle(const qreal &angle) const +{ + qreal ang = angle; + if (angle > 360) + { + ang = angle - 360 * qFloor(angle/360); + } + + switch(qFloor((qAbs(ang)+22.5)/45)) + { + case 0: // <22.5 + return 0; + case 1: // <67.5 + return 45; + case 2: // <112.5 + return 90; + case 3: // <157.5 + return 135; + case 4: // <202.5 + return 180; + case 5: // <247.5 + return 225; + case 6: // < 292.5 + return 270; + case 7: // <337.5 + return 315; + default: // <360 + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const +{ + QLineF line = QLineF(); + line.setP1(firstPoint); + line.setAngle(angle); + + QRectF scRect = this->scene()->sceneRect(); + qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2)); + line.setLength(diagonal); + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) + { + line.setAngle(CorrectAngle(line.angle())); + } + return VAbstractTool::LineIntersectRect(scRect, line); +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VisLine::Ray(const QPointF &firstPoint) const +{ + QLineF line = QLineF(firstPoint, scenePos); + return Ray(firstPoint, line.angle()); +} + //--------------------------------------------------------------------------------------------------------------------- void VisLine::setMainColor(const QColor &value) { diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index 0a93ecf20..e94f2b324 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -71,6 +71,10 @@ protected: QGraphicsEllipseItem *InitPoint(const QColor &color); QGraphicsLineItem *InitLine(const QColor &color); + + qreal CorrectAngle(const qreal &angle) const; + QPointF Ray(const QPointF &firstPoint, const qreal &angle) const; + QPointF Ray(const QPointF &firstPoint) const; private: Q_DISABLE_COPY(VisLine) }; diff --git a/src/app/visualization/vistoolalongline.cpp b/src/app/visualization/vistoolalongline.cpp index 69335c05e..16e7478b8 100644 --- a/src/app/visualization/vistoolalongline.cpp +++ b/src/app/visualization/vistoolalongline.cpp @@ -72,8 +72,7 @@ void VisToolAlongLine::RefreshGeometry() { DrawLine(line, QLineF(first->toQPointF(), scenePos), supportColor); } - - if (point2Id > 0) + else { const VPointF *second = data->GeometricObject(point2Id); DrawPoint(lineP2, second->toQPointF(), supportColor); diff --git a/src/app/visualization/vistoolbisector.cpp b/src/app/visualization/vistoolbisector.cpp new file mode 100644 index 000000000..c1cd58386 --- /dev/null +++ b/src/app/visualization/vistoolbisector.cpp @@ -0,0 +1,121 @@ +/************************************************************************ + ** + ** @file vistoolbisector.cpp + ** @author Roman Telezhynskyi + ** @date 24 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 "vistoolbisector.h" +#include "../geometry/vpointf.h" +#include "../container/vcontainer.h" +#include "../tools/drawTools/vtoolbisector.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent) + :VisLine(data, parent), point2Id(0), point3Id(0), point(nullptr), line1P1(nullptr), line1P2(nullptr), + line1(nullptr), line2P2(nullptr), line2(nullptr), length(0) +{ + line1P1 = InitPoint(supportColor); + line1P2 = InitPoint(supportColor); + line1 = InitLine(supportColor); + + line2P2 = InitPoint(supportColor); + line2 = InitLine(supportColor); + + point = InitPoint(mainColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolBisector::setPoint2Id(const quint32 &value) +{ + point2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolBisector::setPoint3Id(const quint32 &value) +{ + point3Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolBisector::setLength(const QString &expression) +{ + length = FindLength(expression); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolBisector::~VisToolBisector() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolBisector::RefreshGeometry() +{ + if (point1Id > 0) + { + const VPointF *first = data->GeometricObject(point1Id); + DrawPoint(line1P1, first->toQPointF(), supportColor); + + if (point2Id <= 0) + { + DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor); + } + else + { + const VPointF *second = data->GeometricObject(point2Id); + DrawPoint(line1P2, second->toQPointF(), supportColor); + + DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + + if (point3Id <= 0) + { + DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor); + } + else + { + const VPointF *third = data->GeometricObject(point3Id); + DrawPoint(line2P2, third->toQPointF(), supportColor); + + DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(), + third->toQPointF()); + QLineF mainLine = Line(second->toQPointF(), length, angle); + DrawLine(this, mainLine, mainColor, lineStyle); + + DrawPoint(point, mainLine.p2(), mainColor); + } + else + { + qreal angle = VToolBisector::BisectorAngle(first->toQPointF(), second->toQPointF(), + third->toQPointF()); + QPointF endRay = Ray(second->toQPointF(), angle); + QLineF mainLine = Line(second->toQPointF(), QLineF(second->toQPointF(), endRay).length(), angle); + DrawLine(this, mainLine, mainColor, lineStyle); + } + } + } + } +} diff --git a/src/app/visualization/vistoolbisector.h b/src/app/visualization/vistoolbisector.h new file mode 100644 index 000000000..9b8aade23 --- /dev/null +++ b/src/app/visualization/vistoolbisector.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vistoolbisector.h + ** @author Roman Telezhynskyi + ** @date 24 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 VISTOOLBISECTOR_H +#define VISTOOLBISECTOR_H + +#include "visline.h" + +class VisToolBisector :public VisLine +{ + Q_OBJECT +public: + VisToolBisector(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolBisector(); + + virtual void RefreshGeometry(); + void setPoint2Id(const quint32 &value); + void setPoint3Id(const quint32 &value); + void setLength(const QString &expression); +private: + Q_DISABLE_COPY(VisToolBisector) + quint32 point2Id; + quint32 point3Id; + QGraphicsEllipseItem *point; + QGraphicsEllipseItem *line1P1; + QGraphicsEllipseItem *line1P2; + QGraphicsLineItem *line1; + QGraphicsEllipseItem *line2P2; + QGraphicsLineItem *line2; + qreal length; +}; + +#endif // VISTOOLBISECTOR_H diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index 7529ce474..6b74bdfd5 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -62,7 +62,7 @@ void VisToolEndLine::RefreshGeometry() } else { - second = CorrectRay(first->toQPointF()); + second = Ray(first->toQPointF()); } line = QLineF(first->toQPointF(), second); } @@ -92,51 +92,6 @@ qreal VisToolEndLine::Angle() const return this->line().angle(); } -//--------------------------------------------------------------------------------------------------------------------- -qreal VisToolEndLine::CorrectAngle(const qreal &angle) const -{ - qreal ang = angle; - if (angle > 360) - { - ang = angle - 360 * qFloor(angle/360); - } - - switch(qFloor((qAbs(ang)+22.5)/45)) - { - case 0: // <22.5 - return 0; - case 1: // <67.5 - return 45; - case 2: // <112.5 - return 90; - case 3: // <157.5 - return 135; - case 4: // <202.5 - return 180; - case 5: // <247.5 - return 225; - case 6: // < 292.5 - return 270; - case 7: // <337.5 - return 315; - default: // <360 - return 0; - } -} - -QPointF VisToolEndLine::CorrectRay(const QPointF &firstPoint) const -{ - QLineF line = QLineF(firstPoint, scenePos); - QRectF scRect = this->scene()->sceneRect(); - qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2)); - line.setLength(diagonal); - if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) - { - line.setAngle(CorrectAngle(line.angle())); - } - return VAbstractTool::LineIntersectRect(scRect, line); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolEndLine::setAngle(const qreal &value) { diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h index 1171e6194..32e8b17fa 100644 --- a/src/app/visualization/vistoolendline.h +++ b/src/app/visualization/vistoolendline.h @@ -50,8 +50,6 @@ private: qreal length; qreal angle; QGraphicsEllipseItem *point; - qreal CorrectAngle(const qreal &angle) const; - QPointF CorrectRay(const QPointF &firstPoint) const; }; #endif // VISTOOLENDLINE_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index a165515dd..4c9c409d8 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -6,7 +6,8 @@ HEADERS += \ visualization/visline.h \ visualization/vistoolline.h \ visualization/vistoolendline.h \ - visualization/vistoolalongline.h + visualization/vistoolalongline.h \ + visualization/vistoolbisector.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -16,4 +17,5 @@ SOURCES += \ visualization/visline.cpp \ visualization/vistoolline.cpp \ visualization/vistoolendline.cpp \ - visualization/vistoolalongline.cpp + visualization/vistoolalongline.cpp \ + visualization/vistoolbisector.cpp