Implicit Sharing for class VSplinePath.
--HG-- branch : develop
This commit is contained in:
parent
2aaf98f20c
commit
d3b3011d15
|
@ -14,7 +14,8 @@ HEADERS += \
|
||||||
geometry/vgobject_p.h \
|
geometry/vgobject_p.h \
|
||||||
geometry/varc_p.h \
|
geometry/varc_p.h \
|
||||||
geometry/vspline_p.h \
|
geometry/vspline_p.h \
|
||||||
geometry/vsplinepoint_p.h
|
geometry/vsplinepoint_p.h \
|
||||||
|
geometry/vsplinepath_p.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
geometry/vsplinepoint.cpp \
|
geometry/vsplinepoint.cpp \
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode)
|
VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode)
|
||||||
:VGObject(type, idObject, mode)
|
:VGObject(type, idObject, mode)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -27,29 +27,32 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "vsplinepath.h"
|
#include "vsplinepath.h"
|
||||||
|
#include "vsplinepath_p.h"
|
||||||
#include "../exception/vexception.h"
|
#include "../exception/vexception.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode)
|
VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode)
|
||||||
: VAbstractCurve(GOType::SplinePath, idObject, mode), path(QVector<VSplinePoint>()), kCurve(kCurve),
|
: VAbstractCurve(GOType::SplinePath, idObject, mode), d(new VSplinePathData(kCurve))
|
||||||
maxCountPoints(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VSplinePath::VSplinePath(const VSplinePath &splPath)
|
VSplinePath::VSplinePath(const VSplinePath &splPath)
|
||||||
: VAbstractCurve(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()),
|
: VAbstractCurve(splPath), d(splPath.d)
|
||||||
maxCountPoints(splPath.getMaxCountPoints())
|
{}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VSplinePath::~VSplinePath()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VSplinePath::append(const VSplinePoint &point)
|
void VSplinePath::append(const VSplinePoint &point)
|
||||||
{
|
{
|
||||||
path.append(point);
|
d->path.append(point);
|
||||||
QString name = splPath;
|
QString name = splPath;
|
||||||
name.append(QString("_%1").arg(path.first().P().name()));
|
name.append(QString("_%1").arg(d->path.first().P().name()));
|
||||||
if (path.size() > 1)
|
if (d->path.size() > 1)
|
||||||
{
|
{
|
||||||
name.append(QString("_%1").arg(path.last().P().name()));
|
name.append(QString("_%1").arg(d->path.last().P().name()));
|
||||||
}
|
}
|
||||||
setName(name);
|
setName(name);
|
||||||
}
|
}
|
||||||
|
@ -57,13 +60,13 @@ void VSplinePath::append(const VSplinePoint &point)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
qint32 VSplinePath::Count() const
|
qint32 VSplinePath::Count() const
|
||||||
{
|
{
|
||||||
if (path.size() == 0)
|
if (d->path.size() == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return path.size() - 1;
|
return d->path.size() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +81,8 @@ VSpline VSplinePath::GetSpline(qint32 index) const
|
||||||
{
|
{
|
||||||
throw VException(tr("This spline does not exist."));
|
throw VException(tr("This spline does not exist."));
|
||||||
}
|
}
|
||||||
VSpline spl(path.at(index-1).P(), path.at(index).P(), path.at(index-1).Angle2(), path.at(index).Angle1(),
|
VSpline spl(d->path.at(index-1).P(), d->path.at(index).P(), d->path.at(index-1).Angle2(),
|
||||||
path.at(index-1).KAsm2(), path.at(index).KAsm1(), this->kCurve);
|
d->path.at(index).Angle1(), d->path.at(index-1).KAsm2(), d->path.at(index).KAsm1(), d->kCurve);
|
||||||
return spl;
|
return spl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +92,8 @@ QPainterPath VSplinePath::GetPath(PathDirection direction) const
|
||||||
QPainterPath painterPath;
|
QPainterPath painterPath;
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
for (qint32 i = 1; i <= Count(); ++i)
|
||||||
{
|
{
|
||||||
VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
|
VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(),
|
||||||
path.at(i-1).KAsm2(), path.at(i).KAsm1(), this->kCurve);
|
d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve);
|
||||||
painterPath.addPath(spl.GetPath(direction));
|
painterPath.addPath(spl.GetPath(direction));
|
||||||
}
|
}
|
||||||
return painterPath;
|
return painterPath;
|
||||||
|
@ -102,8 +105,8 @@ QVector<QPointF> VSplinePath::GetPoints() const
|
||||||
QVector<QPointF> pathPoints;
|
QVector<QPointF> pathPoints;
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
for (qint32 i = 1; i <= Count(); ++i)
|
||||||
{
|
{
|
||||||
VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
|
VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(),
|
||||||
path.at(i-1).KAsm2(), path.at(i).KAsm1(), this->kCurve);
|
d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve);
|
||||||
pathPoints += spl.GetPoints();
|
pathPoints += spl.GetPoints();
|
||||||
}
|
}
|
||||||
return pathPoints;
|
return pathPoints;
|
||||||
|
@ -115,8 +118,8 @@ qreal VSplinePath::GetLength() const
|
||||||
qreal length = 0;
|
qreal length = 0;
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
for (qint32 i = 1; i <= Count(); ++i)
|
||||||
{
|
{
|
||||||
VSpline spl(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(), path.at(i-1).KAsm2(),
|
VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(),
|
||||||
path.at(i).KAsm1(), kCurve);
|
d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve);
|
||||||
length += spl.GetLength();
|
length += spl.GetLength();
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
|
@ -131,11 +134,11 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos
|
||||||
}
|
}
|
||||||
if (pos == SplinePointPosition::FirstPoint)
|
if (pos == SplinePointPosition::FirstPoint)
|
||||||
{
|
{
|
||||||
path[indexSpline-1] = point;
|
d->path[indexSpline-1] = point;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
path[indexSpline] = point;
|
d->path[indexSpline] = point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,11 +151,11 @@ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition
|
||||||
}
|
}
|
||||||
if (pos == SplinePointPosition::FirstPoint)
|
if (pos == SplinePointPosition::FirstPoint)
|
||||||
{
|
{
|
||||||
return path.at(indexSpline-1);
|
return d->path.at(indexSpline-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return path.at(indexSpline);
|
return d->path.at(indexSpline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,22 +167,20 @@ VSplinePath &VSplinePath::operator =(const VSplinePath &path)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
VAbstractCurve::operator=(path);
|
VAbstractCurve::operator=(path);
|
||||||
this->path = path.GetSplinePath();
|
d = path.d;
|
||||||
this->kCurve = path.getKCurve();
|
|
||||||
this->maxCountPoints = path.getMaxCountPoints();
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VSplinePoint & VSplinePath::operator[](ptrdiff_t indx)
|
VSplinePoint & VSplinePath::operator[](ptrdiff_t indx)
|
||||||
{
|
{
|
||||||
return path[indx];
|
return d->path[indx];
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
const VSplinePoint &VSplinePath::at(ptrdiff_t indx) const
|
const VSplinePoint &VSplinePath::at(ptrdiff_t indx) const
|
||||||
{
|
{
|
||||||
return path[indx];
|
return d->path[indx];
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -205,8 +206,8 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
|
||||||
fullLength = 0;
|
fullLength = 0;
|
||||||
for (qint32 i = 1; i <= Count(); ++i)
|
for (qint32 i = 1; i <= Count(); ++i)
|
||||||
{
|
{
|
||||||
VSpline spl = VSpline(path.at(i-1).P(), path.at(i).P(), path.at(i-1).Angle2(), path.at(i).Angle1(),
|
VSpline spl = VSpline(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(),
|
||||||
path.at(i-1).KAsm2(), path.at(i).KAsm1(), kCurve);
|
d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve);
|
||||||
fullLength += spl.GetLength();
|
fullLength += spl.GetLength();
|
||||||
if (fullLength > length)
|
if (fullLength > length)
|
||||||
{
|
{
|
||||||
|
@ -221,11 +222,47 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
qint32 VSplinePath::getMaxCountPoints() const
|
qint32 VSplinePath::getMaxCountPoints() const
|
||||||
{
|
{
|
||||||
return maxCountPoints;
|
return d->maxCountPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VSplinePath::setMaxCountPoints(const qint32 &value)
|
void VSplinePath::setMaxCountPoints(const qint32 &value)
|
||||||
{
|
{
|
||||||
maxCountPoints = value;
|
d->maxCountPoints = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qint32 VSplinePath::CountPoint() const
|
||||||
|
{
|
||||||
|
return d->path.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<VSplinePoint> VSplinePath::GetSplinePath() const
|
||||||
|
{
|
||||||
|
return d->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VSplinePath::Clear()
|
||||||
|
{
|
||||||
|
d->path.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VSplinePath::getKCurve() const
|
||||||
|
{
|
||||||
|
return d->kCurve;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VSplinePath::setKCurve(const qreal &value)
|
||||||
|
{
|
||||||
|
d->kCurve = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
const QVector<VSplinePoint> *VSplinePath::GetPoint() const
|
||||||
|
{
|
||||||
|
return &d->path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
|
|
||||||
enum class SplinePointPosition : char { FirstPoint, LastPoint };
|
class VSplinePathData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VSplinePath class keep information about splinePath.
|
* @brief The VSplinePath class keep information about splinePath.
|
||||||
|
@ -57,6 +57,7 @@ public:
|
||||||
* @param splPath spline path.
|
* @param splPath spline path.
|
||||||
*/
|
*/
|
||||||
VSplinePath(const VSplinePath& splPath);
|
VSplinePath(const VSplinePath& splPath);
|
||||||
|
virtual ~VSplinePath();
|
||||||
/**
|
/**
|
||||||
* @brief append add point in the end of list points.
|
* @brief append add point in the end of list points.
|
||||||
* @param point new point.
|
* @param point new point.
|
||||||
|
@ -184,55 +185,8 @@ public:
|
||||||
* @param value max count.
|
* @param value max count.
|
||||||
*/
|
*/
|
||||||
void setMaxCountPoints(const qint32 &value);
|
void setMaxCountPoints(const qint32 &value);
|
||||||
protected:
|
private:
|
||||||
/**
|
QSharedDataPointer<VSplinePathData> d;
|
||||||
* @brief path list spline point.
|
|
||||||
*/
|
|
||||||
QVector<VSplinePoint> path;
|
|
||||||
/**
|
|
||||||
* @brief kCurve coefficient of curvature spline.
|
|
||||||
*/
|
|
||||||
qreal kCurve;
|
|
||||||
/**
|
|
||||||
* @brief maxCountPoints max count of points what can have spline path.
|
|
||||||
*/
|
|
||||||
qint32 maxCountPoints;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline qint32 VSplinePath::CountPoint() const
|
|
||||||
{
|
|
||||||
return path.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline QVector<VSplinePoint> VSplinePath::GetSplinePath() const
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline void VSplinePath::Clear()
|
|
||||||
{
|
|
||||||
path.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline qreal VSplinePath::getKCurve() const
|
|
||||||
{
|
|
||||||
return kCurve;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline void VSplinePath::setKCurve(const qreal &value)
|
|
||||||
{
|
|
||||||
kCurve = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline const QVector<VSplinePoint> *VSplinePath::GetPoint() const
|
|
||||||
{
|
|
||||||
return &path;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VSPLINEPATH_H
|
#endif // VSPLINEPATH_H
|
||||||
|
|
69
src/app/geometry/vsplinepath_p.h
Normal file
69
src/app/geometry/vsplinepath_p.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vsplinepath_p.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 20 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.
|
||||||
|
** 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/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VSPLINEPATH_P_H
|
||||||
|
#define VSPLINEPATH_P_H
|
||||||
|
|
||||||
|
#include <QSharedData>
|
||||||
|
#include "../options.h"
|
||||||
|
#include "vsplinepoint.h"
|
||||||
|
|
||||||
|
class VSplinePathData : public QSharedData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
VSplinePathData()
|
||||||
|
: path(QVector<VSplinePoint>()), kCurve(1), maxCountPoints(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
VSplinePathData(qreal kCurve)
|
||||||
|
: path(QVector<VSplinePoint>()), kCurve(kCurve), maxCountPoints(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
VSplinePathData(const VSplinePathData &splPath)
|
||||||
|
: QSharedData(splPath), path(splPath.path), kCurve(splPath.kCurve), maxCountPoints(splPath.maxCountPoints)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual ~VSplinePathData() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief path list spline point.
|
||||||
|
*/
|
||||||
|
QVector<VSplinePoint> path;
|
||||||
|
/**
|
||||||
|
* @brief kCurve coefficient of curvature spline.
|
||||||
|
*/
|
||||||
|
qreal kCurve;
|
||||||
|
/**
|
||||||
|
* @brief maxCountPoints max count of points what can have spline path.
|
||||||
|
*/
|
||||||
|
qint32 maxCountPoints;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // VSPLINEPATH_P_H
|
|
@ -79,6 +79,7 @@ enum class NodeDetail : char { Contour, Modeling };
|
||||||
enum class Contour : char { OpenContour, CloseContour };
|
enum class Contour : char { OpenContour, CloseContour };
|
||||||
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
|
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
|
||||||
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
|
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
|
||||||
|
enum class SplinePointPosition : char { FirstPoint, LastPoint };
|
||||||
|
|
||||||
enum class GHeights : unsigned char { ALL,
|
enum class GHeights : unsigned char { ALL,
|
||||||
H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,
|
H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user