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"
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../libs/vgeometry/vpointf.h"
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../libs/vpatterndb/vcontainer.h"
|
2014-08-14 13:16:02 +02:00
|
|
|
#include "../tools/drawTools/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)
|
2014-08-17 17:20:55 +02:00
|
|
|
:VisLine(data, parent), point2Id(NULL_ID), hypotenuseP1Id(NULL_ID), hypotenuseP2Id(NULL_ID), point(nullptr),
|
|
|
|
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);
|
|
|
|
foot2 = InitItem<QGraphicsLineItem>(supportColor, this);
|
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()
|
|
|
|
{
|
2014-10-24 16:16:31 +02:00
|
|
|
if (point1Id > NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(point1Id);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(axisP1, first->toQPointF(), supportColor);
|
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (point2Id <= NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2014-08-15 12:48:11 +02:00
|
|
|
DrawAimedAxis(axis, QLineF(first->toQPointF(), Visualization::scenePos), supportColor);
|
2014-08-14 13:16:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(point2Id);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(axisP2, second->toQPointF(), supportColor);
|
|
|
|
|
|
|
|
DrawAimedAxis(axis, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
|
|
|
|
|
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);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(hypotenuseP1, third->toQPointF(), supportColor);
|
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (hypotenuseP2Id <= NULL_ID)
|
2014-08-14 13:16:02 +02:00
|
|
|
{
|
2014-08-15 12:48:11 +02:00
|
|
|
DrawLine(this, QLineF(third->toQPointF(), Visualization::scenePos), supportColor, Qt::DashLine);
|
2014-08-14 13:16:02 +02:00
|
|
|
|
|
|
|
QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(),
|
2014-08-15 12:48:11 +02:00
|
|
|
third->toQPointF(), Visualization::scenePos);
|
2014-08-14 13:16:02 +02:00
|
|
|
DrawPoint(point, trPoint, mainColor);
|
|
|
|
|
|
|
|
DrawLine(foot1, QLineF(third->toQPointF(), 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);
|
2014-08-14 13:16:02 +02:00
|
|
|
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);
|
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());
|
|
|
|
}
|