2014-09-07 18:51:22 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vistoolsplinepath.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.
|
|
|
|
** Copyright (C) 2014 Valentina project
|
|
|
|
** <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 "vistoolsplinepath.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
|
|
|
|
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath()),
|
|
|
|
mode(Mode::Creation)
|
|
|
|
{
|
|
|
|
line = InitItem<QGraphicsLineItem>(mainColor, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VisToolSplinePath::~VisToolSplinePath()
|
|
|
|
{
|
|
|
|
qDeleteAll(points.begin(), points.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSplinePath::RefreshGeometry()
|
|
|
|
{
|
|
|
|
if (path.CountPoint() > 0)
|
|
|
|
{
|
|
|
|
QVector<VSplinePoint> pathPoints = path.GetSplinePath();
|
|
|
|
if (path.CountPoint() == 1)
|
|
|
|
{
|
|
|
|
QGraphicsEllipseItem *point = this->getPoint(0);
|
|
|
|
DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor);
|
|
|
|
|
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos);
|
|
|
|
DrawLine(line, sceneLine, mainColor, lineStyle);
|
|
|
|
|
|
|
|
path[0].SetAngle2(sceneLine.angle());
|
|
|
|
emit PathChanged(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < pathPoints.size(); ++i)
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
QGraphicsEllipseItem *point = this->getPoint(static_cast<unsigned>(i));
|
2014-09-07 18:51:22 +02:00
|
|
|
DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == Mode::Creation)
|
|
|
|
{
|
|
|
|
QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(),
|
|
|
|
Visualization::scenePos);
|
|
|
|
DrawLine(line, sceneLine, mainColor, lineStyle);
|
|
|
|
|
|
|
|
path[pathPoints.size() - 1].SetAngle2(sceneLine.angle());
|
|
|
|
emit PathChanged(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
|
|
|
|
}
|
2014-11-21 18:24:16 +01:00
|
|
|
if (path.CountPoint() < 3)
|
|
|
|
{
|
|
|
|
Visualization::toolTip = QString(tr("<b>Curve path</b>: select three or more points"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Visualization::toolTip = QString(tr("<b>Curve path</b>: select three or more points, "
|
|
|
|
"<b>Enter</b> - finish creation"));
|
|
|
|
}
|
2014-09-07 18:51:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSplinePath::setPath(const VSplinePath &value)
|
|
|
|
{
|
|
|
|
path = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSplinePath VisToolSplinePath::getPath()
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Mode VisToolSplinePath::getMode() const
|
|
|
|
{
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VisToolSplinePath::setMode(const Mode &value)
|
|
|
|
{
|
|
|
|
mode = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QGraphicsEllipseItem *VisToolSplinePath::getPoint(unsigned int i)
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
if (static_cast<unsigned int>(points.size() - 1) >= i && points.isEmpty() == false)
|
2014-09-11 16:15:49 +02:00
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
return points.at(static_cast<int>(i));
|
2014-09-07 18:51:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsEllipseItem * point = InitPoint(supportColor, this);
|
|
|
|
points.append(point);
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|