2014-09-08 10:23:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistoolcutsplinepath.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 9, 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-09-08 10:23: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 "vistoolcutsplinepath.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../../vpatterndb/vcontainer.h"
|
|
|
|
#include "../../vgeometry/vsplinepath.h"
|
2014-09-08 10:23:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent)
|
|
|
|
:VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0)
|
|
|
|
{
|
|
|
|
splPath1 = InitItem<QGraphicsPathItem>(Qt::darkGreen, this);
|
|
|
|
splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
|
|
|
splPath2 = InitItem<QGraphicsPathItem>(Qt::darkRed, this);
|
|
|
|
splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
|
|
|
|
|
|
|
point = InitPoint(mainColor, this);
|
|
|
|
point->setZValue(2);
|
|
|
|
point->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolCutSplinePath::~VisToolCutSplinePath()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolCutSplinePath::RefreshGeometry()
|
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
if (object1Id > NULL_ID)
|
2014-09-08 10:23:53 +02:00
|
|
|
{
|
2016-01-24 17:15:08 +01:00
|
|
|
const QSharedPointer<VSplinePath> splPath = Visualization::data->GeometricObject<VSplinePath>(object1Id);
|
2014-09-08 10:23:53 +02:00
|
|
|
DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap);
|
|
|
|
|
|
|
|
if (qFuzzyCompare(1 + length, 1 + 0) == false)
|
|
|
|
{
|
|
|
|
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
|
|
|
qint32 p1 = 0, p2 = 0;
|
|
|
|
|
2014-11-11 11:04:14 +01:00
|
|
|
// TODO make refactoring. CutSplPath repeat twice. Here and in VToolCutSpline.
|
2014-09-08 10:23:53 +02:00
|
|
|
const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
|
|
|
VPointF p = VPointF(cutPoint);
|
|
|
|
|
|
|
|
VSplinePoint splP1 = splPath->at(p1);
|
|
|
|
VSplinePoint splP2 = splPath->at(p2);
|
2015-02-03 11:17:04 +01:00
|
|
|
const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p, splPath->GetKCurve());
|
|
|
|
const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P(), splPath->GetKCurve());
|
2014-09-08 10:23:53 +02:00
|
|
|
|
|
|
|
VSplinePath spPath1 = VSplinePath();
|
|
|
|
VSplinePath spPath2 = VSplinePath();
|
|
|
|
|
|
|
|
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
|
|
|
{
|
|
|
|
if (i <= p1 && i < p2)
|
|
|
|
{
|
|
|
|
if (i == p1)
|
|
|
|
{
|
2015-06-02 15:53:19 +02:00
|
|
|
spPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetStartAngle()+180, spl1.GetKasm1(),
|
|
|
|
spl1.GetStartAngle()));
|
2014-09-08 10:23:53 +02:00
|
|
|
VSplinePoint cutPoint;
|
2015-06-02 15:53:19 +02:00
|
|
|
cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl1.GetEndAngle(), spl2.GetKasm1(),
|
|
|
|
spl1.GetEndAngle()+180);
|
2014-09-08 10:23:53 +02:00
|
|
|
spPath1.append(cutPoint);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
spPath1.append(splPath->at(i));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i == p2)
|
|
|
|
{
|
2015-06-02 15:53:19 +02:00
|
|
|
const VSplinePoint cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl2.GetStartAngle()+180,
|
|
|
|
spl2.GetKasm1(), spl2.GetStartAngle());
|
2014-09-08 10:23:53 +02:00
|
|
|
spPath2.append(cutPoint);
|
2015-06-02 15:53:19 +02:00
|
|
|
spPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetEndAngle(), splP2.KAsm2(),
|
|
|
|
spl2.GetEndAngle()+180));
|
2014-09-08 10:23:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
spPath2.append(splPath->at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 11:17:04 +01:00
|
|
|
spPath1.SetKCurve(splPath->GetKCurve());
|
|
|
|
spPath2.SetKCurve(splPath->GetKCurve());
|
2014-11-11 11:04:14 +01:00
|
|
|
|
2014-09-08 10:23:53 +02:00
|
|
|
DrawPoint(point, cutPoint, mainColor);
|
|
|
|
|
|
|
|
DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap);
|
|
|
|
DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolCutSplinePath::setLength(const QString &expression)
|
|
|
|
{
|
2016-02-25 20:23:16 +01:00
|
|
|
length = FindLength(expression, Visualization::data->PlainVariables());
|
2014-09-08 10:23:53 +02:00
|
|
|
}
|