2014-08-14 17:48:31 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistoollineintersect.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 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 17:48:31 +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 "vistoollineintersect.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QGraphicsLineItem>
|
|
|
|
#include <QLine>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <new>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../visualization.h"
|
|
|
|
#include "visline.h"
|
2014-08-14 17:48:31 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolLineIntersect::VisToolLineIntersect(const VContainer *data, QGraphicsItem *parent)
|
2014-08-17 17:20:55 +02:00
|
|
|
:VisLine(data, parent), line1P2Id(NULL_ID), line2P1Id(NULL_ID), line2P2Id(NULL_ID), point(nullptr),
|
|
|
|
line1P1(nullptr), line1P2(nullptr), line1(nullptr), line2P1(nullptr), line2P2(nullptr)
|
2014-08-14 17:48:31 +02:00
|
|
|
{
|
2014-08-15 15:54:24 +02:00
|
|
|
line1P1 = InitPoint(supportColor, this);
|
|
|
|
line1P2 = InitPoint(supportColor, this);
|
2014-08-16 14:14:55 +02:00
|
|
|
line1 = InitItem<QGraphicsLineItem>(supportColor, this);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2014-08-15 15:54:24 +02:00
|
|
|
line2P1 = InitPoint(supportColor, this);
|
|
|
|
line2P2 = InitPoint(supportColor, this);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2014-08-15 15:54:24 +02:00
|
|
|
point = InitPoint(mainColor, this);
|
2014-08-14 17:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolLineIntersect::~VisToolLineIntersect()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolLineIntersect::RefreshGeometry()
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object1Id > NULL_ID)
|
2014-08-14 17:48:31 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawPoint(line1P1, static_cast<QPointF>(*first), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (line1P2Id <= NULL_ID)
|
2014-08-14 17:48:31 +02:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawLine(line1, QLineF(static_cast<QPointF>(*first), Visualization::scenePos), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(line1P2Id);
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawPoint(line1P2, static_cast<QPointF>(*second), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawLine(line1, QLineF(static_cast<QPointF>(*first), static_cast<QPointF>(*second)), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (line2P1Id <= NULL_ID)
|
2014-08-14 17:48:31 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> third = Visualization::data->GeometricObject<VPointF>(line2P1Id);
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawPoint(line2P1, static_cast<QPointF>(*third), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2014-10-24 16:16:31 +02:00
|
|
|
if (line2P2Id <= NULL_ID)
|
2014-08-14 17:48:31 +02:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawLine(this, QLineF(static_cast<QPointF>(*third), Visualization::scenePos), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
|
|
|
|
QLineF l2(static_cast<QPointF>(*third), Visualization::scenePos);
|
2014-08-14 17:48:31 +02:00
|
|
|
QPointF fPoint;
|
|
|
|
QLineF::IntersectType intersect = l1.intersect(l2, &fPoint);
|
|
|
|
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
|
|
|
|
{
|
|
|
|
DrawPoint(point, fPoint, mainColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> forth = Visualization::data->GeometricObject<VPointF>(line2P2Id);
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawPoint(line2P2, static_cast<QPointF>(*forth), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
DrawLine(this, QLineF(static_cast<QPointF>(*third), static_cast<QPointF>(*forth)), supportColor);
|
2014-08-14 17:48:31 +02:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF l1(static_cast<QPointF>(*first), static_cast<QPointF>(*second));
|
|
|
|
QLineF l2(static_cast<QPointF>(*third), static_cast<QPointF>(*forth));
|
2014-08-14 17:48:31 +02:00
|
|
|
QPointF fPoint;
|
|
|
|
QLineF::IntersectType intersect = l1.intersect(l2, &fPoint);
|
|
|
|
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
|
|
|
|
{
|
|
|
|
DrawPoint(point, fPoint, mainColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolLineIntersect::setLine1P2Id(const quint32 &value)
|
|
|
|
{
|
|
|
|
line1P2Id = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolLineIntersect::setLine2P1Id(const quint32 &value)
|
|
|
|
{
|
|
|
|
line2P1Id = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolLineIntersect::setLine2P2Id(const quint32 &value)
|
|
|
|
{
|
|
|
|
line2P2Id = value;
|
|
|
|
}
|