2014-07-24 15:26:59 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistoolbisector.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 24 7, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2014-07-24 15:26:59 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2014-07-24 15:26:59 +02:00
|
|
|
**
|
|
|
|
** 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 "vistoolbisector.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <new>
|
|
|
|
|
|
|
|
#include "../../tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
2015-06-20 08:23:04 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../visualization.h"
|
|
|
|
#include "visline.h"
|
2022-08-19 15:34:52 +02:00
|
|
|
#include "../vmisc/vmodifierkey.h"
|
2014-07-24 15:26:59 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent)
|
2022-08-19 15:25:38 +02:00
|
|
|
:VisLine(data, parent)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
m_line1P1 = InitPoint(supportColor, this);
|
|
|
|
m_line1P2 = InitPoint(supportColor, this); //-V656
|
|
|
|
m_line1 = InitItem<VScaledLine>(supportColor, this);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
m_line2P2 = InitPoint(supportColor, this);
|
|
|
|
m_line2 = InitItem<VScaledLine>(supportColor, this);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
m_point = InitPoint(mainColor, this);
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-01-24 17:15:08 +01:00
|
|
|
void VisToolBisector::setObject2Id(const quint32 &value)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
m_object2Id = value;
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-01-24 17:15:08 +01:00
|
|
|
void VisToolBisector::setObject3Id(const quint32 &value)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
m_object3Id = value;
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolBisector::setLength(const QString &expression)
|
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
m_length = FindLengthFromUser(expression, Visualization::data->DataVariables());
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolBisector::RefreshGeometry()
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object1Id > NULL_ID)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawPoint(m_line1P1, static_cast<QPointF>(*first), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
if (m_object2Id <= NULL_ID)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawLine(m_line1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(m_object2Id);
|
|
|
|
DrawPoint(m_line1P2, static_cast<QPointF>(*second), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawLine(m_line1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
if (m_object3Id <= NULL_ID)
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawLine(m_line2, QLineF(static_cast<QPointF>(*second), Visualization::scenePos), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-19 15:25:38 +02:00
|
|
|
const QSharedPointer<VPointF> third = Visualization::data->GeometricObject<VPointF>(m_object3Id);
|
|
|
|
DrawPoint(m_line2P2, static_cast<QPointF>(*third), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawLine(m_line2, QLineF(static_cast<QPointF>(*second), static_cast<QPointF>(*third)), supportColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
if (not qFuzzyIsNull(m_length))
|
2014-07-24 15:26:59 +02:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
qreal angle = VToolBisector::BisectorAngle(static_cast<QPointF>(*first),
|
|
|
|
static_cast<QPointF>(*second),
|
|
|
|
static_cast<QPointF>(*third));
|
2022-08-19 15:25:38 +02:00
|
|
|
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*second), m_length, angle);
|
2014-07-24 15:26:59 +02:00
|
|
|
DrawLine(this, mainLine, mainColor, lineStyle);
|
|
|
|
|
2022-08-19 15:25:38 +02:00
|
|
|
DrawPoint(m_point, mainLine.p2(), mainColor);
|
2014-07-24 15:26:59 +02:00
|
|
|
}
|
2022-08-19 15:34:52 +02:00
|
|
|
else if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
QLineF cursorLine (static_cast<QPointF>(*second), Visualization::scenePos);
|
|
|
|
QLineF baseLine(static_cast<QPointF>(*second), static_cast<QPointF>(*third));
|
|
|
|
|
|
|
|
qreal angle = VToolBisector::BisectorAngle(static_cast<QPointF>(*first),
|
|
|
|
static_cast<QPointF>(*second),
|
|
|
|
static_cast<QPointF>(*third));
|
|
|
|
|
|
|
|
baseLine.setAngle(angle);
|
|
|
|
|
|
|
|
qreal len = cursorLine.length();
|
|
|
|
qreal angleTo = baseLine.angleTo(cursorLine);
|
|
|
|
if (angleTo > 90 && angleTo < 270)
|
|
|
|
{
|
|
|
|
len *= -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*second), len, angle);
|
|
|
|
|
|
|
|
DrawLine(this, mainLine, mainColor, lineStyle);
|
|
|
|
|
|
|
|
DrawPoint(m_point, mainLine.p2(), mainColor);
|
|
|
|
|
|
|
|
const QString prefix = UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true);
|
|
|
|
Visualization::toolTip = tr("Length = %1%2; "
|
|
|
|
"<b>Mouse click</b> - finish selecting the length, "
|
|
|
|
"<b>%3</b> - skip")
|
|
|
|
.arg(NumberToUser(len), prefix, VModifierKey::EnterKey());
|
|
|
|
}
|
2014-07-24 15:26:59 +02:00
|
|
|
else
|
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
qreal angle = VToolBisector::BisectorAngle(static_cast<QPointF>(*first),
|
|
|
|
static_cast<QPointF>(*second),
|
|
|
|
static_cast<QPointF>(*third));
|
|
|
|
QPointF endRay = Ray(static_cast<QPointF>(*second), angle);
|
|
|
|
QLineF mainLine = VGObject::BuildLine(static_cast<QPointF>(*second),
|
|
|
|
QLineF(static_cast<QPointF>(*second), endRay).length(),
|
|
|
|
angle);
|
2014-07-24 15:26:59 +02:00
|
|
|
DrawLine(this, mainLine, mainColor, lineStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|