From d3b3011d15148019de8f47feb5bc4174d24ad648 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 20 Aug 2014 17:05:19 +0300 Subject: [PATCH] Implicit Sharing for class VSplinePath. --HG-- branch : develop --- src/app/geometry/geometry.pri | 3 +- src/app/geometry/vabstractcurve.cpp | 1 - src/app/geometry/vsplinepath.cpp | 99 ++++++++++++++++++++--------- src/app/geometry/vsplinepath.h | 54 ++-------------- src/app/geometry/vsplinepath_p.h | 69 ++++++++++++++++++++ src/app/options.h | 1 + 6 files changed, 144 insertions(+), 83 deletions(-) create mode 100644 src/app/geometry/vsplinepath_p.h diff --git a/src/app/geometry/geometry.pri b/src/app/geometry/geometry.pri index 46c9abacb..f26b6b320 100644 --- a/src/app/geometry/geometry.pri +++ b/src/app/geometry/geometry.pri @@ -14,7 +14,8 @@ HEADERS += \ geometry/vgobject_p.h \ geometry/varc_p.h \ geometry/vspline_p.h \ - geometry/vsplinepoint_p.h + geometry/vsplinepoint_p.h \ + geometry/vsplinepath_p.h SOURCES += \ geometry/vsplinepoint.cpp \ diff --git a/src/app/geometry/vabstractcurve.cpp b/src/app/geometry/vabstractcurve.cpp index 40adc24d9..d8a056bf7 100644 --- a/src/app/geometry/vabstractcurve.cpp +++ b/src/app/geometry/vabstractcurve.cpp @@ -31,7 +31,6 @@ #include #include -//--------------------------------------------------------------------------------------------------------------------- VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode) :VGObject(type, idObject, mode) {} diff --git a/src/app/geometry/vsplinepath.cpp b/src/app/geometry/vsplinepath.cpp index cc24ca401..98d99ffd1 100644 --- a/src/app/geometry/vsplinepath.cpp +++ b/src/app/geometry/vsplinepath.cpp @@ -27,29 +27,32 @@ *************************************************************************/ #include "vsplinepath.h" +#include "vsplinepath_p.h" #include "../exception/vexception.h" //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::SplinePath, idObject, mode), path(QVector()), kCurve(kCurve), - maxCountPoints(0) + : VAbstractCurve(GOType::SplinePath, idObject, mode), d(new VSplinePathData(kCurve)) {} //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const VSplinePath &splPath) - : VAbstractCurve(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), - maxCountPoints(splPath.getMaxCountPoints()) + : VAbstractCurve(splPath), d(splPath.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath::~VSplinePath() {} //--------------------------------------------------------------------------------------------------------------------- void VSplinePath::append(const VSplinePoint &point) { - path.append(point); + d->path.append(point); QString name = splPath; - name.append(QString("_%1").arg(path.first().P().name())); - if (path.size() > 1) + name.append(QString("_%1").arg(d->path.first().P().name())); + 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); } @@ -57,13 +60,13 @@ void VSplinePath::append(const VSplinePoint &point) //--------------------------------------------------------------------------------------------------------------------- qint32 VSplinePath::Count() const { - if (path.size() == 0) + if (d->path.size() == 0) { return 0; } 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.")); } - VSpline spl(path.at(index-1).P(), path.at(index).P(), path.at(index-1).Angle2(), path.at(index).Angle1(), - path.at(index-1).KAsm2(), path.at(index).KAsm1(), this->kCurve); + VSpline spl(d->path.at(index-1).P(), d->path.at(index).P(), d->path.at(index-1).Angle2(), + d->path.at(index).Angle1(), d->path.at(index-1).KAsm2(), d->path.at(index).KAsm1(), d->kCurve); return spl; } @@ -89,8 +92,8 @@ QPainterPath VSplinePath::GetPath(PathDirection direction) const QPainterPath painterPath; 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(), path.at(i).KAsm1(), this->kCurve); + VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(), + d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve); painterPath.addPath(spl.GetPath(direction)); } return painterPath; @@ -102,8 +105,8 @@ QVector VSplinePath::GetPoints() const QVector pathPoints; 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(), path.at(i).KAsm1(), this->kCurve); + VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(), + d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve); pathPoints += spl.GetPoints(); } return pathPoints; @@ -115,8 +118,8 @@ qreal VSplinePath::GetLength() const qreal length = 0; 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(), - path.at(i).KAsm1(), kCurve); + VSpline spl(d->path.at(i-1).P(), d->path.at(i).P(), d->path.at(i-1).Angle2(), d->path.at(i).Angle1(), + d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve); length += spl.GetLength(); } return length; @@ -131,11 +134,11 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos } if (pos == SplinePointPosition::FirstPoint) { - path[indexSpline-1] = point; + d->path[indexSpline-1] = point; } else { - path[indexSpline] = point; + d->path[indexSpline] = point; } } @@ -148,11 +151,11 @@ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition } if (pos == SplinePointPosition::FirstPoint) { - return path.at(indexSpline-1); + return d->path.at(indexSpline-1); } else { - return path.at(indexSpline); + return d->path.at(indexSpline); } } @@ -164,22 +167,20 @@ VSplinePath &VSplinePath::operator =(const VSplinePath &path) return *this; } VAbstractCurve::operator=(path); - this->path = path.GetSplinePath(); - this->kCurve = path.getKCurve(); - this->maxCountPoints = path.getMaxCountPoints(); + d = path.d; return *this; } //--------------------------------------------------------------------------------------------------------------------- VSplinePoint & VSplinePath::operator[](ptrdiff_t indx) { - return path[indx]; + return d->path[indx]; } //--------------------------------------------------------------------------------------------------------------------- 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; 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(), - path.at(i-1).KAsm2(), path.at(i).KAsm1(), kCurve); + 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(), + d->path.at(i-1).KAsm2(), d->path.at(i).KAsm1(), d->kCurve); fullLength += spl.GetLength(); if (fullLength > length) { @@ -221,11 +222,47 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF //--------------------------------------------------------------------------------------------------------------------- qint32 VSplinePath::getMaxCountPoints() const { - return maxCountPoints; + return d->maxCountPoints; } //--------------------------------------------------------------------------------------------------------------------- void VSplinePath::setMaxCountPoints(const qint32 &value) { - maxCountPoints = value; + d->maxCountPoints = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VSplinePath::CountPoint() const +{ + return d->path.size(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector 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 *VSplinePath::GetPoint() const +{ + return &d->path; } diff --git a/src/app/geometry/vsplinepath.h b/src/app/geometry/vsplinepath.h index 1ee368326..e0c3592f9 100644 --- a/src/app/geometry/vsplinepath.h +++ b/src/app/geometry/vsplinepath.h @@ -36,7 +36,7 @@ #include #include -enum class SplinePointPosition : char { FirstPoint, LastPoint }; +class VSplinePathData; /** * @brief The VSplinePath class keep information about splinePath. @@ -57,6 +57,7 @@ public: * @param splPath spline path. */ VSplinePath(const VSplinePath& splPath); + virtual ~VSplinePath(); /** * @brief append add point in the end of list points. * @param point new point. @@ -184,55 +185,8 @@ public: * @param value max count. */ void setMaxCountPoints(const qint32 &value); -protected: - /** - * @brief path list spline point. - */ - QVector path; - /** - * @brief kCurve coefficient of curvature spline. - */ - qreal kCurve; - /** - * @brief maxCountPoints max count of points what can have spline path. - */ - qint32 maxCountPoints; +private: + QSharedDataPointer d; }; -//--------------------------------------------------------------------------------------------------------------------- -inline qint32 VSplinePath::CountPoint() const -{ - return path.size(); -} - -//--------------------------------------------------------------------------------------------------------------------- -inline QVector 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 *VSplinePath::GetPoint() const -{ - return &path; -} - #endif // VSPLINEPATH_H diff --git a/src/app/geometry/vsplinepath_p.h b/src/app/geometry/vsplinepath_p.h new file mode 100644 index 000000000..739f01d0a --- /dev/null +++ b/src/app/geometry/vsplinepath_p.h @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file vsplinepath_p.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VSPLINEPATH_P_H +#define VSPLINEPATH_P_H + +#include +#include "../options.h" +#include "vsplinepoint.h" + +class VSplinePathData : public QSharedData +{ +public: + + VSplinePathData() + : path(QVector()), kCurve(1), maxCountPoints(0) + {} + + VSplinePathData(qreal kCurve) + : path(QVector()), 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 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 diff --git a/src/app/options.h b/src/app/options.h index 787641d49..7cfebe1f2 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -79,6 +79,7 @@ enum class NodeDetail : char { Contour, Modeling }; enum class Contour : char { OpenContour, CloseContour }; enum class EquidistantType : char { OpenEquidistant, CloseEquidistant }; enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown }; +enum class SplinePointPosition : char { FirstPoint, LastPoint }; enum class GHeights : unsigned char { ALL, H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,