diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index 66445f613..5383350d7 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -30,6 +30,8 @@ #include "ui_dialogtriangle.h" #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistooltriangle.h" +#include "../../widgets/vmaingraphicsscene.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -39,12 +41,12 @@ */ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(0), - axisP2Id(0), firstPointId(0), secondPointId(0) + axisP2Id(0), firstPointId(0), secondPointId(0), line (nullptr) { ui->setupUi(this); labelEditNamePoint = ui->labelEditNamePoint; - InitOkCancel(ui); + InitOkCancelApply(ui); flagName = false; CheckState(); @@ -62,11 +64,14 @@ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QW this, &DialogTriangle::PointNameChanged); connect(ui->comboBoxAxisP2, static_cast(&QComboBox::currentIndexChanged), this, &DialogTriangle::PointNameChanged); + + line = new VisToolTriangle(data); } //--------------------------------------------------------------------------------------------------------------------- DialogTriangle::~DialogTriangle() { + delete line; delete ui; } @@ -86,21 +91,29 @@ void DialogTriangle::ChosenObject(quint32 id, const SceneObject &type) case (0): ChangeCurrentText(ui->comboBoxAxisP1, point->name()); number++; + line->VisualMode(id); emit ToolTip(tr("Select second point of axis")); break; case (1): ChangeCurrentText(ui->comboBoxAxisP2, point->name()); number++; + line->setPoint2Id(id); + line->RefreshGeometry(); emit ToolTip(tr("Select first point")); break; case (2): ChangeCurrentText(ui->comboBoxFirstPoint, point->name()); number++; + line->setHypotenuseP1Id(id); + line->RefreshGeometry(); emit ToolTip(tr("Select second point")); break; case (3): ChangeCurrentText(ui->comboBoxSecondPoint, point->name()); number = 0; + line->setHypotenuseP2Id(id); + line->RefreshGeometry(); + prepare = true; emit ToolTip(tr("")); if (isInitialized == false) { @@ -122,6 +135,12 @@ void DialogTriangle::SaveData() secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint); axisP1Id = getCurrentObjectId(ui->comboBoxAxisP1); axisP2Id = getCurrentObjectId(ui->comboBoxAxisP2); + + line->setPoint1Id(axisP1Id); + line->setPoint2Id(axisP2Id); + line->setHypotenuseP1Id(firstPointId); + line->setHypotenuseP2Id(secondPointId); + line->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -134,7 +153,7 @@ void DialogTriangle::PointNameChanged() set.insert(getCurrentObjectId(ui->comboBoxAxisP2)); QColor color = okColor; - if (set.size() != 4) + if (set.size() < 3)//Need tree or more unique points for creation triangle { flagError = false; color = errorColor; @@ -151,6 +170,18 @@ void DialogTriangle::PointNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTriangle::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor); + scene->addItem(line); + line->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setPointName set name of point @@ -170,6 +201,7 @@ void DialogTriangle::setPointName(const QString &value) void DialogTriangle::setSecondPointId(const quint32 &value) { setPointId(ui->comboBoxSecondPoint, secondPointId, value); + line->setHypotenuseP2Id(secondPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -180,6 +212,7 @@ void DialogTriangle::setSecondPointId(const quint32 &value) void DialogTriangle::setFirstPointId(const quint32 &value) { setPointId(ui->comboBoxFirstPoint, firstPointId, value); + line->setHypotenuseP1Id(firstPointId); } //--------------------------------------------------------------------------------------------------------------------- @@ -190,6 +223,7 @@ void DialogTriangle::setFirstPointId(const quint32 &value) void DialogTriangle::setAxisP2Id(const quint32 &value) { setPointId(ui->comboBoxAxisP2, axisP2Id, value); + line->setPoint2Id(axisP2Id); } //--------------------------------------------------------------------------------------------------------------------- @@ -200,4 +234,5 @@ void DialogTriangle::setAxisP2Id(const quint32 &value) void DialogTriangle::setAxisP1Id(const quint32 &value) { setPointId(ui->comboBoxAxisP1, axisP1Id, value); + line->setPoint1Id(axisP1Id); } diff --git a/src/app/dialogs/tools/dialogtriangle.h b/src/app/dialogs/tools/dialogtriangle.h index 256c58d4a..5c0828e1e 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -36,6 +36,8 @@ namespace Ui class DialogTriangle; } +class VisToolTriangle; + /** * @brief The DialogTriangle class dialog for ToolTriangle. Help create point and edit option. */ @@ -64,6 +66,7 @@ public slots: virtual void ChosenObject(quint32 id, const SceneObject &type); virtual void PointNameChanged(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -91,6 +94,8 @@ private: /** @brief secondPointId id second point of line */ quint32 secondPointId; + + VisToolTriangle *line; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtriangle.ui b/src/app/dialogs/tools/dialogtriangle.ui index 0a5f3223f..4ac997de3 100644 --- a/src/app/dialogs/tools/dialogtriangle.ui +++ b/src/app/dialogs/tools/dialogtriangle.ui @@ -6,7 +6,7 @@ 0 0 - 267 + 285 220 @@ -82,6 +82,12 @@ + + + 0 + 0 + + First point of axis @@ -100,6 +106,12 @@ + + + 0 + 0 + + Second point of axis @@ -118,6 +130,12 @@ + + + 0 + 0 + + First point @@ -136,6 +154,12 @@ + + + 0 + 0 + + Second point @@ -156,7 +180,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 e671b8050..a25eee5d3 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -580,8 +580,10 @@ void MainWindow::ToolHeight(bool checked) */ void MainWindow::ToolTriangle(bool checked) { - SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", - tr("Select first point of axis"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", + tr("Select first point of axis"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index 3bb91e32a..38486eff1 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -30,6 +30,8 @@ #include "../../dialogs/tools/dialogtriangle.h" #include "../../geometry/vpointf.h" +#include + const QString VToolTriangle::ToolType = QStringLiteral("triangle"); //--------------------------------------------------------------------------------------------------------------------- @@ -86,8 +88,9 @@ void VToolTriangle::setDialog() * @param scene pointer to scene. * @param doc dom document container. * @param data container with variables. + * @return the created tool */ -void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolTriangle* VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogTriangle *dialogTool = qobject_cast(dialog); @@ -97,8 +100,14 @@ void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte const quint32 firstPointId = dialogTool->getFirstPointId(); const quint32 secondPointId = dialogTool->getSecondPointId(); const QString pointName = dialogTool->getPointName(); - Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data, - Document::FullParse, Source::FromGui); + VToolTriangle* point = nullptr; + point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data, + Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -117,11 +126,12 @@ void VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPatte * @param data container with variables. * @param parse parser file mode. * @param typeCreation way we create this tool. + * @return the created tool */ -void VToolTriangle::Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id, - const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolTriangle* VToolTriangle::Create(const quint32 _id, const QString &pointName, const quint32 &axisP1Id, + const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation) { const VPointF *axisP1 = data->GeometricObject(axisP1Id); const VPointF *axisP2 = data->GeometricObject(axisP2Id); @@ -157,7 +167,9 @@ void VToolTriangle::Create(const quint32 _id, const QString &pointName, const qu doc->IncrementReferens(axisP2Id); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -172,39 +184,31 @@ void VToolTriangle::Create(const quint32 _id, const QString &pointName, const qu QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, const QPointF &secondPoint) { - qreal c = QLineF(firstPoint, secondPoint).length(); - qreal a = QLineF(axisP2, firstPoint).length(); - qreal b = QLineF(axisP2, secondPoint).length(); - if (fabs(c*c - (a*a + b*b)) < 0.0001) + QLineF axis(axisP1, axisP2); + QLineF hypotenuse(firstPoint, secondPoint); + + QPointF startPoint; + QLineF::IntersectType intersect = axis.intersect(hypotenuse, &startPoint); + if (intersect != QLineF::UnboundedIntersection && intersect != QLineF::BoundedIntersection) { - QLineF l1(axisP2, firstPoint); - QLineF l2(axisP2, secondPoint); - if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1) - { - return axisP2; - } + return QPointF(); } - QLineF line = QLineF(axisP1, axisP2); - qreal step = 0.01; + qreal step = 1; + + QLineF line; + line.setP1(startPoint); + line.setAngle(axis.angle()); + line.setLength(step); + + int c = qFloor(hypotenuse.length()); while (1) { line.setLength(line.length()+step); - a = QLineF(line.p2(), firstPoint).length(); - b = QLineF(line.p2(), secondPoint).length(); - if (qFuzzyCompare(c*c, a*a + b*b)) + int a = qFloor(QLineF(line.p2(), firstPoint).length()); + int b = qFloor(QLineF(line.p2(), secondPoint).length()); + if (c*c <= (a*a + b*b)) { - QLineF l1(axisP2, firstPoint); - QLineF l2(axisP2, secondPoint); - if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1) - { - return line.p2(); - } - } - if (c*c < a*a + b*b) - { - //Still don't know why this code handled. Need to think about that. - qDebug()<<"Can't find point."<setPos(pos); point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor)); + point->setVisible(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -183,19 +183,11 @@ QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color) point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor)); point->setRect(PointRect()); point->setFlags(QGraphicsItem::ItemStacksBehindParent); + point->setVisible(false); return point; } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsLineItem *VisLine::InitLine(const QColor &color) -{ - QGraphicsLineItem *line = new QGraphicsLineItem(this); - line->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); - line->setZValue(1); - line->setFlags(QGraphicsItem::ItemStacksBehindParent); - return line; -} - qreal VisLine::CorrectAngle(const qreal &angle) const { qreal ang = angle; @@ -291,3 +283,18 @@ void VisLine::setPoint1Id(const quint32 &value) { point1Id = value; } + +//--------------------------------------------------------------------------------------------------------------------- +QLineF VisLine::Axis(const QPointF &p, const qreal &angle) const +{ + QPointF endP1 = Ray(p, angle+180); + QPointF endP2 = Ray(p, angle); + return QLineF(endP1, endP2); +} + +//--------------------------------------------------------------------------------------------------------------------- +QLineF VisLine::Axis(const QPointF &p1, const QPointF &p2) const +{ + QLineF line(p1, p2); + return Axis(p1, line.angle()); +} diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index e9ff543ae..516bd771b 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -33,6 +33,8 @@ #include #include +#include "../widgets/vapplication.h" + class VContainer; class VisLine: public QObject, public QGraphicsLineItem @@ -71,11 +73,21 @@ protected: QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle); QGraphicsEllipseItem *InitPoint(const QColor &color); - QGraphicsLineItem *InitLine(const QColor &color); + template + Item *InitItem(const QColor &color) + { + Item *item = new Item(this); + item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); + item->setZValue(1); + item->setFlags(QGraphicsItem::ItemStacksBehindParent); + return item; + } qreal CorrectAngle(const qreal &angle) const; QPointF Ray(const QPointF &firstPoint, const qreal &angle) const; QPointF Ray(const QPointF &firstPoint) const; + QLineF Axis(const QPointF &p, const qreal &angle) const; + QLineF Axis(const QPointF &p1, const QPointF &p2) const; private: Q_DISABLE_COPY(VisLine) }; diff --git a/src/app/visualization/vistoolalongline.cpp b/src/app/visualization/vistoolalongline.cpp index 16e7478b8..88d35c31f 100644 --- a/src/app/visualization/vistoolalongline.cpp +++ b/src/app/visualization/vistoolalongline.cpp @@ -29,7 +29,6 @@ #include "vistoolalongline.h" #include "../container/vcontainer.h" #include "../geometry/vpointf.h" -#include "../widgets/vapplication.h" //--------------------------------------------------------------------------------------------------------------------- VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent) @@ -40,7 +39,7 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent lineP1 = InitPoint(supportColor); lineP2 = InitPoint(supportColor); - line = InitLine(supportColor); + line = InitItem(supportColor); point = InitPoint(mainColor); } diff --git a/src/app/visualization/vistoolbisector.cpp b/src/app/visualization/vistoolbisector.cpp index c1cd58386..c9f374aa9 100644 --- a/src/app/visualization/vistoolbisector.cpp +++ b/src/app/visualization/vistoolbisector.cpp @@ -38,10 +38,10 @@ VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent) { line1P1 = InitPoint(supportColor); line1P2 = InitPoint(supportColor); - line1 = InitLine(supportColor); + line1 = InitItem(supportColor); line2P2 = InitPoint(supportColor); - line2 = InitLine(supportColor); + line2 = InitItem(supportColor); point = InitPoint(mainColor); } diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index ae229dd9f..dbd80ad7c 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -29,7 +29,6 @@ #include "vistoolendline.h" #include "../geometry/vpointf.h" #include "../container/vcontainer.h" -#include "../widgets/vapplication.h" #include "../tools/vabstracttool.h" #include diff --git a/src/app/visualization/vistoolheight.cpp b/src/app/visualization/vistoolheight.cpp index 8c340b4df..bde4a5c92 100644 --- a/src/app/visualization/vistoolheight.cpp +++ b/src/app/visualization/vistoolheight.cpp @@ -38,8 +38,8 @@ VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent) base_point = InitPoint(supportColor); lineP1 = InitPoint(supportColor); lineP2 = InitPoint(supportColor); - line = InitLine(supportColor); - line_intersection = InitLine(supportColor); + line = InitItem(supportColor); + line_intersection = InitItem(supportColor); point = InitPoint(mainColor); } diff --git a/src/app/visualization/vistoolline.cpp b/src/app/visualization/vistoolline.cpp index f799b5cbc..7732af60a 100644 --- a/src/app/visualization/vistoolline.cpp +++ b/src/app/visualization/vistoolline.cpp @@ -29,7 +29,6 @@ #include "vistoolline.h" #include "../container/vcontainer.h" #include "../geometry/vpointf.h" -#include "../widgets/vapplication.h" #include "../tools/drawTools/vdrawtool.h" //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolnormal.cpp b/src/app/visualization/vistoolnormal.cpp index fe27b0dc0..68f858759 100644 --- a/src/app/visualization/vistoolnormal.cpp +++ b/src/app/visualization/vistoolnormal.cpp @@ -39,7 +39,7 @@ VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent) lineP1 = InitPoint(supportColor); lineP2 = InitPoint(supportColor); - line = InitLine(supportColor); + line = InitItem(supportColor); point = InitPoint(mainColor); } diff --git a/src/app/visualization/vistoolpointofintersection.cpp b/src/app/visualization/vistoolpointofintersection.cpp index ea0684e70..397e7ed43 100644 --- a/src/app/visualization/vistoolpointofintersection.cpp +++ b/src/app/visualization/vistoolpointofintersection.cpp @@ -36,7 +36,7 @@ VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, Q { axisP1 = InitPoint(supportColor); axisP2 = InitPoint(supportColor); - axis2 = InitLine(supportColor); + axis2 = InitItem(supportColor); point = InitPoint(mainColor); } @@ -78,14 +78,6 @@ void VisToolPointOfIntersection::setPoint2Id(const quint32 &value) point2Id = value; } -//--------------------------------------------------------------------------------------------------------------------- -QLineF VisToolPointOfIntersection::Axis(const QPointF &p, const qreal &angle) const -{ - QPointF endP1 = Ray(p, angle); - QPointF endP2 = Ray(p, angle+180); - return QLineF(endP1, endP2); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersection::ShowIntersection(const QLineF &axis1, const QLineF &axis2) { diff --git a/src/app/visualization/vistoolpointofintersection.h b/src/app/visualization/vistoolpointofintersection.h index 291f7802a..e17c1ee05 100644 --- a/src/app/visualization/vistoolpointofintersection.h +++ b/src/app/visualization/vistoolpointofintersection.h @@ -49,7 +49,6 @@ private: QGraphicsEllipseItem *axisP2; QGraphicsLineItem *axis2;//axis1 is class themself - QLineF Axis(const QPointF &p, const qreal &angle) const; void ShowIntersection(const QLineF &axis1, const QLineF &axis2); }; diff --git a/src/app/visualization/vistoolshoulderpoint.cpp b/src/app/visualization/vistoolshoulderpoint.cpp index af7864228..d2f866aee 100644 --- a/src/app/visualization/vistoolshoulderpoint.cpp +++ b/src/app/visualization/vistoolshoulderpoint.cpp @@ -37,11 +37,11 @@ VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem { line1P1 = InitPoint(supportColor); line1P2 = InitPoint(supportColor); - line1 = InitLine(supportColor); + line1 = InitItem(supportColor); line2P2 = InitPoint(supportColor); - line2 = InitLine(supportColor); - line3 = InitLine(supportColor); + line2 = InitItem(supportColor); + line3 = InitItem(supportColor); point = InitPoint(mainColor); } diff --git a/src/app/visualization/vistooltriangle.cpp b/src/app/visualization/vistooltriangle.cpp new file mode 100644 index 000000000..d86108c9e --- /dev/null +++ b/src/app/visualization/vistooltriangle.cpp @@ -0,0 +1,183 @@ +/************************************************************************ + ** + ** @file vistooltriangle.cpp + ** @author Roman Telezhynskyi + ** @date 13 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 "vistooltriangle.h" +#include "../geometry/vpointf.h" +#include "../container/vcontainer.h" +#include "../tools/drawTools/vtooltriangle.h" +#include "QtMath" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent) + :VisLine(data, parent), point2Id(0), hypotenuseP1Id(0), hypotenuseP2Id(0), point(nullptr), axisP1(nullptr), + axisP2(nullptr), axis(nullptr), hypotenuseP1(nullptr), hypotenuseP2(nullptr), foot1(nullptr), foot2(nullptr) +{ + axisP1 = InitPoint(supportColor); + axisP2 = InitPoint(supportColor); + axis = InitItem(supportColor); + hypotenuseP1 = InitPoint(supportColor); + hypotenuseP2 = InitPoint(supportColor); + foot1 = InitItem(supportColor); + foot2 = InitItem(supportColor); + + point = InitPoint(mainColor); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolTriangle::~VisToolTriangle() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::RefreshGeometry() +{ + if (point1Id > 0) + { + const VPointF *first = data->GeometricObject(point1Id); + DrawPoint(axisP1, first->toQPointF(), supportColor); + + if (point2Id <= 0) + { + DrawAimedAxis(axis, QLineF(first->toQPointF(), scenePos), supportColor); + } + else + { + const VPointF *second = data->GeometricObject(point2Id); + DrawPoint(axisP2, second->toQPointF(), supportColor); + + DrawAimedAxis(axis, QLineF(first->toQPointF(), second->toQPointF()), supportColor); + + if (hypotenuseP1Id <= 0) + { + return; + } + else + { + const VPointF *third = data->GeometricObject(hypotenuseP1Id); + DrawPoint(hypotenuseP1, third->toQPointF(), supportColor); + + if (hypotenuseP2Id <= 0) + { + DrawLine(this, QLineF(third->toQPointF(), scenePos), supportColor, Qt::DashLine); + + QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(), + third->toQPointF(), scenePos); + DrawPoint(point, trPoint, mainColor); + + DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine); + DrawLine(foot2, QLineF(scenePos, trPoint), supportColor, Qt::DashLine); + } + else + { + const VPointF *forth = data->GeometricObject(hypotenuseP2Id); + DrawPoint(hypotenuseP2, forth->toQPointF(), supportColor); + + DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor, Qt::DashLine); + + QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(), + third->toQPointF(), forth->toQPointF()); + DrawPoint(point, trPoint, mainColor); + + DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine); + DrawLine(foot2, QLineF(forth->toQPointF(), trPoint), supportColor, Qt::DashLine); + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::setPoint2Id(const quint32 &value) +{ + point2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::setHypotenuseP1Id(const quint32 &value) +{ + hypotenuseP1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::setHypotenuseP2Id(const quint32 &value) +{ + hypotenuseP2Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color, + Qt::PenStyle style) +{ + SCASSERT (item != nullptr); + + item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); + + QPainterPath path; + path.moveTo(line.p1()); + path.lineTo(line.p2()); + + qreal arrow_step = 60/factor; + qreal arrow_size = 10/factor; + + if (line.length() < arrow_step) + { + DrawArrow(line, path, arrow_size); + } + + QLineF axis; + axis.setP1(line.p1()); + axis.setAngle(line.angle()); + axis.setLength(arrow_step); + + int steps = qFloor(line.length()/arrow_step); + for(int i=0; isetPath(path); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolTriangle::DrawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size) +{ + QLineF arrowPart1; + arrowPart1.setP1(axis.p2()); + arrowPart1.setLength(arrow_size); + arrowPart1.setAngle(axis.angle()+180+35); + + path.moveTo(arrowPart1.p1()); + path.lineTo(arrowPart1.p2()); + + QLineF arrowPart2; + arrowPart2.setP1(axis.p2()); + arrowPart2.setLength(arrow_size); + arrowPart2.setAngle(axis.angle()+180-35); + + path.moveTo(arrowPart2.p1()); + path.lineTo(arrowPart2.p2()); +} diff --git a/src/app/visualization/vistooltriangle.h b/src/app/visualization/vistooltriangle.h new file mode 100644 index 000000000..b34b5cd0e --- /dev/null +++ b/src/app/visualization/vistooltriangle.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vistooltriangle.h + ** @author Roman Telezhynskyi + ** @date 13 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 VISTOOLTRIANGLE_H +#define VISTOOLTRIANGLE_H + +#include "visline.h" + +class VisToolTriangle : public VisLine +{ + Q_OBJECT +public: + VisToolTriangle(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolTriangle(); + + virtual void RefreshGeometry(); + + void setPoint2Id(const quint32 &value); + void setHypotenuseP1Id(const quint32 &value); + void setHypotenuseP2Id(const quint32 &value); +private: + Q_DISABLE_COPY(VisToolTriangle) + quint32 point2Id;//axis second point + quint32 hypotenuseP1Id; + quint32 hypotenuseP2Id; + QGraphicsEllipseItem *point; + QGraphicsEllipseItem *axisP1; + QGraphicsEllipseItem *axisP2; + QGraphicsPathItem *axis; + QGraphicsEllipseItem *hypotenuseP1; + QGraphicsEllipseItem *hypotenuseP2; + QGraphicsLineItem *foot1; + QGraphicsLineItem *foot2; + + void DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color, + Qt::PenStyle style = Qt::SolidLine); + void DrawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size); +}; + +#endif // VISTOOLTRIANGLE_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 63a4dd5ba..f646db34e 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -11,7 +11,8 @@ HEADERS += \ visualization/vistoolshoulderpoint.h \ visualization/vistoolnormal.h \ visualization/vistoolheight.h \ - visualization/vistoolpointofintersection.h + visualization/vistoolpointofintersection.h \ + visualization/vistooltriangle.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -26,4 +27,5 @@ SOURCES += \ visualization/vistoolshoulderpoint.cpp \ visualization/vistoolnormal.cpp \ visualization/vistoolheight.cpp \ - visualization/vistoolpointofintersection.cpp + visualization/vistoolpointofintersection.cpp \ + visualization/vistooltriangle.cpp