2014-08-14 13:16:02 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistooltriangle.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @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.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-08-14 13:16:02 +02:00
|
|
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vistooltriangle.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../../tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h"
|
2014-10-03 12:32:12 +02:00
|
|
|
#include <QtCore/qmath.h>
|
2014-08-14 13:16:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent)
|
2016-01-24 17:15:08 +01:00
|
|
|
:VisLine(data, parent), object2Id(NULL_ID), hypotenuseP1Id(NULL_ID), hypotenuseP2Id(NULL_ID), point(nullptr),
|
2014-08-17 17:20:55 +02:00
|
|
|
axisP1(nullptr), axisP2(nullptr), axis(nullptr), hypotenuseP1(nullptr), hypotenuseP2(nullptr), foot1(nullptr),
|
|
|
|
foot2(nullptr)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2014-08-15 15:54:24 +02:00
|
|
|
axisP1 = InitPoint(supportColor, this);
|
|
|
|
axisP2 = InitPoint(supportColor, this);
|
2014-08-16 14:14:55 +02:00
|
|
|
axis = InitItem<QGraphicsPathItem>(supportColor, this);
|
2014-08-15 15:54:24 +02:00
|
|
|
hypotenuseP1 = InitPoint(supportColor, this);
|
|
|
|
hypotenuseP2 = InitPoint(supportColor, this);
|
2014-08-16 14:14:55 +02:00
|
|
|
foot1 = InitItem<QGraphicsLineItem>(supportColor, this);
|
2015-10-28 15:22:36 +01:00
|
|
|
foot2 = InitItem<QGraphicsLineItem>(supportColor, this); //-V656
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2014-08-15 15:54:24 +02:00
|
|
|
point = InitPoint(mainColor, this);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolTriangle::~VisToolTriangle()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolTriangle::RefreshGeometry()
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object1Id > NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(axisP1, *first, supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object2Id <= NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawAimedAxis(axis, QLineF(*first, Visualization::scenePos), supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object2Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(axisP2, *second, supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawAimedAxis(axis, QLineF(*first, *second), supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (hypotenuseP1Id <= NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> third = Visualization::data->GeometricObject<VPointF>(hypotenuseP1Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(hypotenuseP1, *third, supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (hypotenuseP2Id <= NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawLine(this, QLineF(*third, Visualization::scenePos), supportColor, Qt::DashLine);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
QPointF trPoint = VToolTriangle::FindPoint(*first, *second, *third, Visualization::scenePos);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(point, trPoint, mainColor);
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawLine(foot1, QLineF(*third, trPoint), supportColor, Qt::DashLine);
|
2014-08-15 12:48:11 +02:00
|
|
|
DrawLine(foot2, QLineF(Visualization::scenePos, trPoint), supportColor, Qt::DashLine);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> forth = Visualization::data->GeometricObject<VPointF>(hypotenuseP2Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(hypotenuseP2, *forth, supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawLine(this, QLineF(*third, *forth), supportColor, Qt::DashLine);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
QPointF trPoint = VToolTriangle::FindPoint(*first, *second, *third, *forth);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(point, trPoint, mainColor);
|
|
|
|
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawLine(foot1, QLineF(*third, trPoint), supportColor, Qt::DashLine);
|
|
|
|
DrawLine(foot2, QLineF(*forth, trPoint), supportColor, Qt::DashLine);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-01-24 17:15:08 +01:00
|
|
|
void VisToolTriangle::setObject2Id(const quint32 &value)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
object2Id = value;
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
|
2015-06-15 11:32:27 +02:00
|
|
|
item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style));
|
2014-08-14 13:16:02 +02:00
|
|
|
|
|
|
|
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);
|
2014-09-10 19:57:08 +02:00
|
|
|
for (int i=0; i<steps; ++i)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
|
|
|
DrawArrow(axis, path, arrow_size);
|
|
|
|
axis.setLength(axis.length()+arrow_step);
|
|
|
|
}
|
|
|
|
item->setPath(path);
|
2014-12-25 17:22:32 +01:00
|
|
|
item->setVisible(true);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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());
|
|
|
|
}
|