2014-08-18 16:42:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistoolspline.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 18 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-18 16:42:53 +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 "vistoolspline.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
2016-03-24 15:49:15 +01:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-02-12 19:10:01 +01:00
|
|
|
#include "../vwidgets/vcontrolpointspline.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../visualization.h"
|
|
|
|
#include "vispath.h"
|
2014-08-18 16:42:53 +02:00
|
|
|
|
|
|
|
const int EMPTY_ANGLE = -1;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent)
|
2016-02-12 19:10:01 +01:00
|
|
|
: VisPath(data, parent),
|
|
|
|
object4Id(NULL_ID),
|
2016-02-12 20:43:33 +01:00
|
|
|
point1(nullptr),
|
|
|
|
point4(nullptr),
|
2016-02-12 19:10:01 +01:00
|
|
|
angle1(EMPTY_ANGLE),
|
|
|
|
angle2(EMPTY_ANGLE),
|
|
|
|
kAsm1(1),
|
|
|
|
kAsm2(1),
|
|
|
|
kCurve(1),
|
|
|
|
isLeftMousePressed(false),
|
|
|
|
p2Selected(false),
|
|
|
|
p3Selected(false),
|
|
|
|
p2(),
|
|
|
|
p3(),
|
|
|
|
controlPoints()
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
2016-02-12 20:43:33 +01:00
|
|
|
point1 = InitPoint(supportColor, this);
|
|
|
|
point4 = InitPoint(supportColor, this); //-V656
|
2016-02-12 19:10:01 +01:00
|
|
|
|
|
|
|
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this);
|
|
|
|
controlPoint1->hide();
|
|
|
|
controlPoints.append(controlPoint1);
|
|
|
|
|
|
|
|
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, *data->GetPatternUnit(), this);
|
|
|
|
controlPoint2->hide();
|
|
|
|
controlPoints.append(controlPoint2);
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolSpline::~VisToolSpline()
|
2016-07-13 13:05:37 +02:00
|
|
|
{
|
|
|
|
emit ToolTip("");
|
|
|
|
}
|
2014-08-18 16:42:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSpline::RefreshGeometry()
|
|
|
|
{
|
2016-02-12 19:32:31 +01:00
|
|
|
//Radius of point circle, but little bigger. Need handle with hover sizes.
|
|
|
|
const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
|
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object1Id > NULL_ID)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
2016-02-12 19:10:01 +01:00
|
|
|
const auto first = Visualization::data->GeometricObject<VPointF>(object1Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(point1, *first, supportColor);
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
if (isLeftMousePressed && not p2Selected)
|
|
|
|
{
|
|
|
|
p2 = Visualization::scenePos;
|
2016-05-14 21:28:09 +02:00
|
|
|
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, *first);
|
2016-02-12 19:32:31 +01:00
|
|
|
|
|
|
|
if (not controlPoints[0]->isVisible())
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
if (QLineF(*first, p2).length() > radius)
|
2016-02-12 19:32:31 +01:00
|
|
|
{
|
|
|
|
controlPoints[0]->show();
|
|
|
|
}
|
2016-02-13 17:30:21 +01:00
|
|
|
else
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
p2 = *first;
|
2016-02-13 17:30:21 +01:00
|
|
|
}
|
2016-02-12 19:32:31 +01:00
|
|
|
}
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p2Selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object4Id <= NULL_ID)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
2016-02-27 15:49:10 +01:00
|
|
|
VSpline spline(*first, p2, Visualization::scenePos, VPointF(Visualization::scenePos));
|
2016-02-12 19:10:01 +01:00
|
|
|
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-12 19:10:01 +01:00
|
|
|
const auto second = Visualization::data->GeometricObject<VPointF>(object4Id);
|
2016-05-14 21:28:09 +02:00
|
|
|
DrawPoint(point4, *second, supportColor);
|
2014-08-18 16:42:53 +02:00
|
|
|
|
2016-02-12 19:10:01 +01:00
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
if (isLeftMousePressed && not p3Selected)
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
QLineF ctrlLine (*second, Visualization::scenePos);
|
2016-02-12 19:10:01 +01:00
|
|
|
ctrlLine.setAngle(ctrlLine.angle()+180);
|
|
|
|
p3 = ctrlLine.p2();
|
2016-05-14 21:28:09 +02:00
|
|
|
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, *second);
|
2016-02-12 19:32:31 +01:00
|
|
|
|
|
|
|
if (not controlPoints[1]->isVisible())
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
if (QLineF(*second, p3).length() > radius)
|
2016-02-12 19:32:31 +01:00
|
|
|
{
|
|
|
|
controlPoints[1]->show();
|
|
|
|
}
|
2016-02-13 17:30:21 +01:00
|
|
|
else
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
p3 = *second;
|
2016-02-13 17:30:21 +01:00
|
|
|
}
|
2016-02-12 19:32:31 +01:00
|
|
|
}
|
2016-02-12 19:10:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p3Selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 15:09:30 +01:00
|
|
|
if (VFuzzyComparePossibleNulls(angle1, EMPTY_ANGLE) || VFuzzyComparePossibleNulls(angle2, EMPTY_ANGLE))
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
2016-02-27 15:49:10 +01:00
|
|
|
VSpline spline(*first, p2, p3, *second);
|
2016-02-12 19:10:01 +01:00
|
|
|
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VSpline spline(*first, *second, angle1, angle2, kAsm1, kAsm2, kCurve);
|
|
|
|
DrawPath(this, spline.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
2016-07-13 13:05:37 +02:00
|
|
|
Visualization::toolTip = tr("Use <b>Shift</b> for sticking angle!");
|
|
|
|
emit ToolTip(Visualization::toolTip);
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-01-24 17:15:08 +01:00
|
|
|
void VisToolSpline::setObject4Id(const quint32 &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
object4Id = value;
|
2014-08-18 16:42:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VisToolSpline::SetAngle1(const qreal &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
|
|
|
angle1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VisToolSpline::SetAngle2(const qreal &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
|
|
|
angle2 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VisToolSpline::SetKAsm1(const qreal &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
|
|
|
kAsm1 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VisToolSpline::SetKAsm2(const qreal &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
|
|
|
kAsm2 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-02-03 11:17:04 +01:00
|
|
|
void VisToolSpline::SetKCurve(const qreal &value)
|
2014-08-18 16:42:53 +02:00
|
|
|
{
|
|
|
|
kCurve = value;
|
|
|
|
}
|
2016-02-12 19:10:01 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VisToolSpline::GetP2() const
|
|
|
|
{
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VisToolSpline::GetP3() const
|
|
|
|
{
|
|
|
|
return p3;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSpline::MouseLeftPressed()
|
|
|
|
{
|
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
isLeftMousePressed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSpline::MouseLeftReleased()
|
|
|
|
{
|
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
isLeftMousePressed = false;
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|