Implicit Sharing for class VArc.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 15:23:21 +03:00
parent d75969b331
commit 7a8ba8f707
5 changed files with 261 additions and 125 deletions

View File

@ -39,7 +39,7 @@ class QPainterPath;
class VAbstractCurve :public VGObject class VAbstractCurve :public VGObject
{ {
public: public:
VAbstractCurve(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation); VAbstractCurve(const GOType &type, const quint32 &idObject = NULL_ID, const Draw &mode = Draw::Calculation);
VAbstractCurve(const VAbstractCurve &curve); VAbstractCurve(const VAbstractCurve &curve);
VAbstractCurve& operator= (const VAbstractCurve &curve); VAbstractCurve& operator= (const VAbstractCurve &curve);
virtual QVector<QPointF> GetPoints() const =0; virtual QVector<QPointF> GetPoints() const =0;

View File

@ -27,6 +27,7 @@
*************************************************************************/ *************************************************************************/
#include "varc.h" #include "varc.h"
#include "varc_p.h"
#include <QDebug> #include <QDebug>
#include <QLineF> #include <QLineF>
#include <QPainterPath> #include <QPainterPath>
@ -42,8 +43,7 @@
* @brief VArc default constructor. * @brief VArc default constructor.
*/ */
VArc::VArc () VArc::VArc ()
:VAbstractCurve(GOType::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), :VAbstractCurve(GOType::Arc), d (new VArcData)
formulaRadius(QString()), center(VPointF())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -56,21 +56,20 @@ VArc::VArc ()
*/ */
VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
QString formulaF2, quint32 idObject, Draw mode) QString formulaF2, quint32 idObject, Draw mode)
: VAbstractCurve(GOType::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), : VAbstractCurve(GOType::Arc, idObject, mode),
radius(radius), formulaRadius(formulaRadius), center(center) d (new VArcData(center, radius, formulaRadius, f1, formulaF1, f2, formulaF2))
{ {
setName(QString (arc_+"%1").arg(this->GetCenter().name())); setName(QString (arc_+"%1").arg(this->GetCenter().name()));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2) VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2)
: VAbstractCurve(GOType::Arc, 0, Draw::Calculation), f1(f1), formulaF1(QStringLiteral("")), f2(f2), : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1, f2))
formulaF2(QStringLiteral("")), radius(radius), formulaRadius(QStringLiteral("")), center(center)
{ {
setName(QString (arc_+"%1").arg(this->GetCenter().name())); setName(QString (arc_+"%1").arg(this->GetCenter().name()));
formulaF1 = QString("%1").arg(f1); d->formulaF1 = QString("%1").arg(f1);
formulaF2 = QString("%1").arg(f2); d->formulaF2 = QString("%1").arg(f2);
formulaRadius = QString("%1").arg(radius); d->formulaRadius = QString("%1").arg(radius);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -79,9 +78,7 @@ VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2)
* @param arc arc * @param arc arc
*/ */
VArc::VArc(const VArc &arc) VArc::VArc(const VArc &arc)
: VAbstractCurve(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), : VAbstractCurve(arc), d (arc.d)
formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()),
center(arc.GetCenter())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -97,16 +94,14 @@ VArc &VArc::operator =(const VArc &arc)
return *this; return *this;
} }
VAbstractCurve::operator=(arc); VAbstractCurve::operator=(arc);
this->f1 = arc.GetF1(); d = arc.d;
this->formulaF1 = arc.GetFormulaF1();
this->f2 = arc.GetF2();
this->formulaF2 = arc.GetFormulaF2();
this->radius = arc.GetRadius();
this->formulaRadius = arc.GetFormulaRadius();
this->center = arc.GetCenter();
return *this; return *this;
} }
//---------------------------------------------------------------------------------------------------------------------
VArc::~VArc()
{}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetLength return arc length. * @brief GetLength return arc length.
@ -114,7 +109,7 @@ VArc &VArc::operator =(const VArc &arc)
*/ */
qreal VArc::GetLength() const qreal VArc::GetLength() const
{ {
return (M_PI * radius)/180 * AngleArc(); return (M_PI * d->radius)/180 * AngleArc();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -124,9 +119,9 @@ qreal VArc::GetLength() const
*/ */
QPointF VArc::GetP1() const QPointF VArc::GetP1() const
{ {
QPointF p1 ( GetCenter().x () + radius, GetCenter().y () ); QPointF p1 ( GetCenter().x () + d->radius, GetCenter().y () );
QLineF centerP1(GetCenter().toQPointF(), p1); QLineF centerP1(GetCenter().toQPointF(), p1);
centerP1.setAngle(f1); centerP1.setAngle(d->f1);
return centerP1.p2(); return centerP1.p2();
} }
@ -137,9 +132,9 @@ QPointF VArc::GetP1() const
*/ */
QPointF VArc::GetP2 () const QPointF VArc::GetP2 () const
{ {
QPointF p2 ( GetCenter().x () + radius, GetCenter().y () ); QPointF p2 ( GetCenter().x () + d->radius, GetCenter().y () );
QLineF centerP2(GetCenter().toQPointF(), p2); QLineF centerP2(GetCenter().toQPointF(), p2);
centerP2.setAngle(f2); centerP2.setAngle(d->f2);
return centerP2.p2(); return centerP2.p2();
} }
@ -151,9 +146,9 @@ QPointF VArc::GetP2 () const
qreal VArc::AngleArc() const qreal VArc::AngleArc() const
{ {
QLineF l1(0, 0, 100, 100); QLineF l1(0, 0, 100, 100);
l1.setAngle(f1); l1.setAngle(d->f1);
QLineF l2(0, 0, 100, 100); QLineF l2(0, 0, 100, 100);
l2.setAngle(f2); l2.setAngle(d->f2);
return l1.angleTo(l2); return l1.angleTo(l2);
} }
@ -171,13 +166,13 @@ QVector<QPointF> VArc::GetPoints() const
qreal s = angle/(k/4); qreal s = angle/(k/4);
do do
{ {
QLineF line(center.toQPointF(), GetP1()); QLineF line(d->center.toQPointF(), GetP1());
line.setAngle(line.angle()+i); line.setAngle(line.angle()+i);
points.append(line.p2()); points.append(line.p2());
i = i + s; i = i + s;
if (i > angle) if (i > angle)
{ {
QLineF line(center.toQPointF(), GetP1()); QLineF line(d->center.toQPointF(), GetP1());
line.setAngle(line.angle()+angle); line.setAngle(line.angle()+angle);
points.append(line.p2()); points.append(line.p2());
} }
@ -210,15 +205,15 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const
len = length; len = length;
} }
qreal n = (len*180)/(M_PI*radius); qreal n = (len*180)/(M_PI*d->radius);
QLineF line(GetCenter().toQPointF(), GetP1()); QLineF line(GetCenter().toQPointF(), GetP1());
line.setAngle(line.angle()+n); line.setAngle(line.angle()+n);
arc1 = VArc (center, radius, formulaRadius, f1, formulaF1, line.angle(), QString().setNum(line.angle()), arc1 = VArc (d->center, d->radius, d->formulaRadius, d->f1, d->formulaF1, line.angle(),
getIdObject(), getMode()); QString().setNum(line.angle()), getIdObject(), getMode());
arc2 = VArc (center, radius, formulaRadius, line.angle(), QString().setNum(line.angle()), f2, formulaF2, arc2 = VArc (d->center, d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), d->f2,
getIdObject(), getMode()); d->formulaF2, getIdObject(), getMode());
return line.p2(); return line.p2();
} }
@ -239,5 +234,75 @@ QPointF VArc::CutArc(const qreal &length) const
void VArc::setId(const quint32 &id) void VArc::setId(const quint32 &id)
{ {
VAbstractCurve::setId(id); VAbstractCurve::setId(id);
setName(QString (arc_+"%1_%2").arg(center.name()).arg(id)); setName(QString (arc_+"%1_%2").arg(d->center.name()).arg(id));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF1 return start angle.
* @return angle in degree.
*/
QString VArc::GetFormulaF1() const
{
return d->formulaF1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF1 return formula for start angle.
* @return string with formula.
*/
qreal VArc::GetF1() const
{
return d->f1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF2 return end angle.
* @return angle in degree.
*/
QString VArc::GetFormulaF2() const
{
return d->formulaF2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF2 return formula for end angle.
* @return string with formula.
*/
qreal VArc::GetF2() const
{
return d->f2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetRadius return arc radius.
* @return radius.
*/
QString VArc::GetFormulaRadius() const
{
return d->formulaRadius;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetRadius return formula for radius.
* @return string with formula.
*/
qreal VArc::GetRadius() const
{
return d->radius;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetCenter return center point.
* @return center point.
*/
VPointF VArc::GetCenter() const
{
return d->center;
} }

View File

@ -34,6 +34,7 @@
#include <QCoreApplication> #include <QCoreApplication>
class QPainterPath; class QPainterPath;
class VArcData;
/** /**
* @brief VArc class for anticlockwise arc. * @brief VArc class for anticlockwise arc.
@ -48,6 +49,8 @@ public:
VArc (VPointF center, qreal radius, qreal f1, qreal f2); VArc (VPointF center, qreal radius, qreal f1, qreal f2);
VArc(const VArc &arc); VArc(const VArc &arc);
VArc& operator= (const VArc &arc); VArc& operator= (const VArc &arc);
virtual ~VArc();
QString GetFormulaF1 () const; QString GetFormulaF1 () const;
qreal GetF1 () const; qreal GetF1 () const;
QString GetFormulaF2 () const; QString GetFormulaF2 () const;
@ -64,96 +67,7 @@ public:
QPointF CutArc (const qreal &length) const; QPointF CutArc (const qreal &length) const;
virtual void setId(const quint32 &id); virtual void setId(const quint32 &id);
private: private:
/** @brief f1 start angle in degree. */ QSharedDataPointer<VArcData> d;
qreal f1;
/** @brief formulaF1 formula for start angle. */
QString formulaF1;
/** @brief f2 end angle in degree. */
qreal f2;
/** @brief formulaF2 formula for end angle. */
QString formulaF2;
/** @brief radius arc radius. */
qreal radius;
/** @brief formulaRadius formula for arc radius. */
QString formulaRadius;
/** @brief center center point of arc. */
VPointF center;
}; };
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF1 return start angle.
* @return angle in degree.
*/
inline QString VArc::GetFormulaF1() const
{
return formulaF1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF1 return formula for start angle.
* @return string with formula.
*/
inline qreal VArc::GetF1() const
{
return f1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF2 return end angle.
* @return angle in degree.
*/
inline QString VArc::GetFormulaF2() const
{
return formulaF2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetF2 return formula for end angle.
* @return string with formula.
*/
inline qreal VArc::GetF2() const
{
return f2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetRadius return arc radius.
* @return radius.
*/
inline QString VArc::GetFormulaRadius() const
{
return formulaRadius;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetRadius return formula for radius.
* @return string with formula.
*/
inline qreal VArc::GetRadius() const
{
return radius;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetCenter return center point.
* @return center point.
*/
inline VPointF VArc::GetCenter() const
{
return center;
}
#endif // VARC_H #endif // VARC_H

89
src/app/geometry/varc_p.h Normal file
View File

@ -0,0 +1,89 @@
/************************************************************************
**
** @file varc_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 VARC_P_H
#define VARC_P_H
#include <QSharedData>
#include "../options.h"
#include "vpointf.h"
class VArcData : public QSharedData
{
public:
VArcData ()
: f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()),
center(VPointF())
{}
VArcData (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2,
QString formulaF2)
: f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius),
center(center)
{}
VArcData(VPointF center, qreal radius, qreal f1, qreal f2)
: f1(f1), formulaF1(QStringLiteral("")), f2(f2), formulaF2(QStringLiteral("")), radius(radius),
formulaRadius(QStringLiteral("")), center(center)
{
formulaF1 = QString("%1").arg(f1);
formulaF2 = QString("%1").arg(f2);
formulaRadius = QString("%1").arg(radius);
}
VArcData(const VArcData &arc)
: QSharedData(arc), f1(arc.f1), formulaF1(arc.formulaF1), f2(arc.f2), formulaF2(arc.formulaF2),
radius(arc.radius), formulaRadius(arc.formulaRadius), center(arc.center)
{}
virtual ~VArcData() {}
/** @brief f1 start angle in degree. */
qreal f1;
/** @brief formulaF1 formula for start angle. */
QString formulaF1;
/** @brief f2 end angle in degree. */
qreal f2;
/** @brief formulaF2 formula for end angle. */
QString formulaF2;
/** @brief radius arc radius. */
qreal radius;
/** @brief formulaRadius formula for arc radius. */
QString formulaRadius;
/** @brief center center point of arc. */
VPointF center;
};
#endif // VARC_P_H

View File

@ -0,0 +1,68 @@
/************************************************************************
**
** @file vgobject_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 VGOBJECT_P_H
#define VGOBJECT_P_H
#include <QSharedData>
#include "../options.h"
class VGObjectData : public QSharedData
{
public:
VGObjectData()
:_id(NULL_ID), type(GOType::Unknown), idObject(NULL_ID), _name(QString()), mode(Draw::Calculation)
{}
VGObjectData(const GOType &type, const quint32 &idObject, const Draw &mode)
:_id(NULL_ID), type(type), idObject(idObject), _name(QString()), mode(mode)
{}
VGObjectData(const VGObjectData &obj)
:QSharedData(obj), _id(obj._id), type(obj.type), idObject(obj.idObject), _name(obj._name), mode(obj.mode)
{}
virtual ~VGObjectData() {}
/** @brief _id id in container. Ned for arcs, spline and spline paths. */
quint32 _id;
/** @brief type type of graphical object */
GOType type;
/** @brief idObject id of parent object. Only for modeling. All another return 0. */
quint32 idObject;
/** @brief _name object name */
QString _name;
/** @brief mode object created in calculation or drawing mode */
Draw mode;
};
#endif // VGOBJECT_P_H