diff --git a/src/app/geometry/vabstractcurve.h b/src/app/geometry/vabstractcurve.h index f3d70aa5f..f157eb8af 100644 --- a/src/app/geometry/vabstractcurve.h +++ b/src/app/geometry/vabstractcurve.h @@ -39,7 +39,7 @@ class QPainterPath; class VAbstractCurve :public VGObject { 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& operator= (const VAbstractCurve &curve); virtual QVector GetPoints() const =0; diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index 0c4d5a512..b2773455e 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "varc.h" +#include "varc_p.h" #include #include #include @@ -42,8 +43,7 @@ * @brief VArc default constructor. */ VArc::VArc () - :VAbstractCurve(GOType::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), - formulaRadius(QString()), center(VPointF()) + :VAbstractCurve(GOType::Arc), d (new VArcData) {} //--------------------------------------------------------------------------------------------------------------------- @@ -56,21 +56,20 @@ VArc::VArc () */ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, QString formulaF2, quint32 idObject, Draw mode) - : VAbstractCurve(GOType::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), - radius(radius), formulaRadius(formulaRadius), center(center) + : VAbstractCurve(GOType::Arc, idObject, mode), + d (new VArcData(center, radius, formulaRadius, f1, formulaF1, f2, formulaF2)) { setName(QString (arc_+"%1").arg(this->GetCenter().name())); } //--------------------------------------------------------------------------------------------------------------------- VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2) - : VAbstractCurve(GOType::Arc, 0, Draw::Calculation), f1(f1), formulaF1(QStringLiteral("")), f2(f2), - formulaF2(QStringLiteral("")), radius(radius), formulaRadius(QStringLiteral("")), center(center) + : VAbstractCurve(GOType::Arc, NULL_ID, Draw::Calculation), d (new VArcData(center, radius, f1, f2)) { setName(QString (arc_+"%1").arg(this->GetCenter().name())); - formulaF1 = QString("%1").arg(f1); - formulaF2 = QString("%1").arg(f2); - formulaRadius = QString("%1").arg(radius); + d->formulaF1 = QString("%1").arg(f1); + d->formulaF2 = QString("%1").arg(f2); + d->formulaRadius = QString("%1").arg(radius); } //--------------------------------------------------------------------------------------------------------------------- @@ -79,9 +78,7 @@ VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2) * @param arc arc */ VArc::VArc(const VArc &arc) - : VAbstractCurve(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), - formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()), - center(arc.GetCenter()) + : VAbstractCurve(arc), d (arc.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -97,16 +94,14 @@ VArc &VArc::operator =(const VArc &arc) return *this; } VAbstractCurve::operator=(arc); - this->f1 = arc.GetF1(); - this->formulaF1 = arc.GetFormulaF1(); - this->f2 = arc.GetF2(); - this->formulaF2 = arc.GetFormulaF2(); - this->radius = arc.GetRadius(); - this->formulaRadius = arc.GetFormulaRadius(); - this->center = arc.GetCenter(); + d = arc.d; return *this; } +//--------------------------------------------------------------------------------------------------------------------- +VArc::~VArc() +{} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetLength return arc length. @@ -114,7 +109,7 @@ VArc &VArc::operator =(const VArc &arc) */ 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 p1 ( GetCenter().x () + radius, GetCenter().y () ); + QPointF p1 ( GetCenter().x () + d->radius, GetCenter().y () ); QLineF centerP1(GetCenter().toQPointF(), p1); - centerP1.setAngle(f1); + centerP1.setAngle(d->f1); return centerP1.p2(); } @@ -137,9 +132,9 @@ QPointF VArc::GetP1() 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); - centerP2.setAngle(f2); + centerP2.setAngle(d->f2); return centerP2.p2(); } @@ -151,9 +146,9 @@ QPointF VArc::GetP2 () const qreal VArc::AngleArc() const { QLineF l1(0, 0, 100, 100); - l1.setAngle(f1); + l1.setAngle(d->f1); QLineF l2(0, 0, 100, 100); - l2.setAngle(f2); + l2.setAngle(d->f2); return l1.angleTo(l2); } @@ -171,13 +166,13 @@ QVector VArc::GetPoints() const qreal s = angle/(k/4); do { - QLineF line(center.toQPointF(), GetP1()); + QLineF line(d->center.toQPointF(), GetP1()); line.setAngle(line.angle()+i); points.append(line.p2()); i = i + s; if (i > angle) { - QLineF line(center.toQPointF(), GetP1()); + QLineF line(d->center.toQPointF(), GetP1()); line.setAngle(line.angle()+angle); points.append(line.p2()); } @@ -210,15 +205,15 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const len = length; } - qreal n = (len*180)/(M_PI*radius); + qreal n = (len*180)/(M_PI*d->radius); QLineF line(GetCenter().toQPointF(), GetP1()); line.setAngle(line.angle()+n); - arc1 = VArc (center, radius, formulaRadius, f1, formulaF1, line.angle(), QString().setNum(line.angle()), - getIdObject(), getMode()); + arc1 = VArc (d->center, d->radius, d->formulaRadius, d->f1, d->formulaF1, line.angle(), + QString().setNum(line.angle()), getIdObject(), getMode()); - arc2 = VArc (center, radius, formulaRadius, line.angle(), QString().setNum(line.angle()), f2, formulaF2, - getIdObject(), getMode()); + arc2 = VArc (d->center, d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), d->f2, + d->formulaF2, getIdObject(), getMode()); return line.p2(); } @@ -239,5 +234,75 @@ QPointF VArc::CutArc(const qreal &length) const void VArc::setId(const quint32 &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; } diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index 00a5c8d97..bd48b8568 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -34,6 +34,7 @@ #include class QPainterPath; +class VArcData; /** * @brief VArc class for anticlockwise arc. @@ -48,6 +49,8 @@ public: VArc (VPointF center, qreal radius, qreal f1, qreal f2); VArc(const VArc &arc); VArc& operator= (const VArc &arc); + virtual ~VArc(); + QString GetFormulaF1 () const; qreal GetF1 () const; QString GetFormulaF2 () const; @@ -64,96 +67,7 @@ public: QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id); private: - /** @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; + QSharedDataPointer d; }; -//--------------------------------------------------------------------------------------------------------------------- -/** - * @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 diff --git a/src/app/geometry/varc_p.h b/src/app/geometry/varc_p.h new file mode 100644 index 000000000..f405a23f3 --- /dev/null +++ b/src/app/geometry/varc_p.h @@ -0,0 +1,89 @@ +/************************************************************************ + ** + ** @file varc_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 VARC_P_H +#define VARC_P_H + +#include +#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 diff --git a/src/app/geometry/vgobject_p.h b/src/app/geometry/vgobject_p.h new file mode 100644 index 000000000..f1acb679d --- /dev/null +++ b/src/app/geometry/vgobject_p.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file vgobject_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 VGOBJECT_P_H +#define VGOBJECT_P_H + +#include +#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