From bc87f5ffbec2b9afec6901506da5b9206c482608 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 25 Jun 2014 17:08:12 +0300 Subject: [PATCH] Refactoring. --HG-- branch : develop --- src/app/geometry/geometry.pri | 6 ++- src/app/geometry/vabstractcurve.cpp | 67 +++++++++++++++++++++++++++++ src/app/geometry/vabstractcurve.h | 59 +++++++++++++++++++++++++ src/app/geometry/varc.cpp | 18 ++------ src/app/geometry/varc.h | 5 +-- src/app/geometry/vequidistant.cpp | 12 +++--- src/app/geometry/vspline.cpp | 44 +++---------------- src/app/geometry/vspline.h | 6 +-- src/app/geometry/vsplinepath.cpp | 11 ++--- src/app/geometry/vsplinepath.h | 11 ++--- 10 files changed, 156 insertions(+), 83 deletions(-) create mode 100644 src/app/geometry/vabstractcurve.cpp create mode 100644 src/app/geometry/vabstractcurve.h diff --git a/src/app/geometry/geometry.pri b/src/app/geometry/geometry.pri index a56d4f80e..22661128d 100644 --- a/src/app/geometry/geometry.pri +++ b/src/app/geometry/geometry.pri @@ -7,7 +7,8 @@ HEADERS += \ geometry/varc.h \ geometry/vgobject.h \ geometry/vpointf.h \ - geometry/vequidistant.h + geometry/vequidistant.h \ + geometry/vabstractcurve.h SOURCES += \ geometry/vsplinepoint.cpp \ @@ -18,4 +19,5 @@ SOURCES += \ geometry/varc.cpp \ geometry/vgobject.cpp \ geometry/vpointf.cpp \ - geometry/vequidistant.cpp + geometry/vequidistant.cpp \ + geometry/vabstractcurve.cpp diff --git a/src/app/geometry/vabstractcurve.cpp b/src/app/geometry/vabstractcurve.cpp new file mode 100644 index 000000000..bacd9d757 --- /dev/null +++ b/src/app/geometry/vabstractcurve.cpp @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vabstractcurve.cpp + ** @author Roman Telezhynskyi + ** @date 25 6, 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 . + ** + *************************************************************************/ + +#include "vabstractcurve.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode) + :VGObject(type, idObject, mode) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCurve::VAbstractCurve(const VAbstractCurve &curve) + :VGObject(curve) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractCurve &VAbstractCurve::operator=(const VAbstractCurve &curve) +{ + VGObject::operator=(curve); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VAbstractCurve::GetPath() const +{ + QPainterPath path; + + QVector points = GetPoints(); + if (points.count() >= 2) + { + for (qint32 i = 0; i < points.count()-1; ++i) + { + path.moveTo(points.at(i)); + path.lineTo(points.at(i+1)); + } + } + else + { + qDebug()<<"points.count() < 2"< + ** @date 25 6, 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 VABSTRACTCURVE_H +#define VABSTRACTCURVE_H + +#include "vgobject.h" +#include + +class QPainterPath; + +class VAbstractCurve :public VGObject +{ +public: + VAbstractCurve(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation); + VAbstractCurve(const VAbstractCurve &curve); + VAbstractCurve& operator= (const VAbstractCurve &curve); + virtual QVector GetPoints() const =0; + virtual QPainterPath GetPath() const; + virtual QString name() const; + virtual qreal GetLength() const =0; +}; + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief name return curve name. This name used in variables. + * @return name + */ +inline QString VAbstractCurve::name() const +{ + return _name; +} + +#endif // VABSTRACTCURVE_H diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index dd7718f91..e871d849f 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -42,7 +42,7 @@ * @brief VArc default constructor. */ VArc::VArc () - :VGObject(GOType::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), + :VAbstractCurve(GOType::Arc), f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()), center(VPointF()) {} @@ -56,7 +56,7 @@ VArc::VArc () */ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, QString formulaF2, quint32 idObject, Draw mode) - : VGObject(GOType::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), + : VAbstractCurve(GOType::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius), center(center) { _name = QString (arc_+"%1").arg(this->GetCenter().name()); @@ -68,7 +68,7 @@ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QStri * @param arc arc */ VArc::VArc(const VArc &arc) - : VGObject(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), + : VAbstractCurve(arc), f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()), center(arc.GetCenter()) {} @@ -81,7 +81,7 @@ VArc::VArc(const VArc &arc) */ VArc &VArc::operator =(const VArc &arc) { - VGObject::operator=(arc); + VAbstractCurve::operator=(arc); this->f1 = arc.GetF1(); this->formulaF1 = arc.GetFormulaF1(); this->f2 = arc.GetF2(); @@ -195,16 +195,6 @@ QVector VArc::GetPoints() const return points; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief name return arc name. This name used in variables. - * @return name - */ -QString VArc::name() const -{ - return _name; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief CutArc cut arc into two arcs. diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index e9b6ca53c..41cc1dbf4 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -29,7 +29,7 @@ #ifndef VARC_H #define VARC_H -#include "vgobject.h" +#include "vabstractcurve.h" #include "vpointf.h" #include @@ -38,7 +38,7 @@ class QPainterPath; /** * @brief VArc class for anticlockwise arc. */ -class VArc: public VGObject +class VArc: public VAbstractCurve { Q_DECLARE_TR_FUNCTIONS(VArc) public: @@ -60,7 +60,6 @@ public: QPainterPath GetPath() const; qreal AngleArc() const; QVector GetPoints () const; - virtual QString name() const; QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; virtual void setId(const quint32 &id); private: diff --git a/src/app/geometry/vequidistant.cpp b/src/app/geometry/vequidistant.cpp index 9ee6c10f0..94abf849a 100644 --- a/src/app/geometry/vequidistant.cpp +++ b/src/app/geometry/vequidistant.cpp @@ -111,22 +111,22 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer case (Tool::NodeSplinePath): { const VSplinePath *splinePath = data->GeometricObject(detail.at(i).getId()); - qreal len1 = GetLengthContour(points, splinePath->GetPathPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPathPoints())); + qreal len1 = GetLengthContour(points, splinePath->GetPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPoints())); if (len1 <= lenReverse) { - points << splinePath->GetPathPoints(); + points << splinePath->GetPoints(); if (detail.getSeamAllowance() == true) { - pointsEkv << biasPoints(splinePath->GetPathPoints(), detail.at(i).getMx(), detail.at(i).getMy()); + pointsEkv << biasPoints(splinePath->GetPoints(), detail.at(i).getMx(), detail.at(i).getMy()); } } else { - points << GetReversePoint(splinePath->GetPathPoints()); + points << GetReversePoint(splinePath->GetPoints()); if (detail.getSeamAllowance() == true) { - pointsEkv << biasPoints(GetReversePoint(splinePath->GetPathPoints()), detail.at(i).getMx(), + pointsEkv << biasPoints(GetReversePoint(splinePath->GetPoints()), detail.at(i).getMx(), detail.at(i).getMy()); } } diff --git a/src/app/geometry/vspline.cpp b/src/app/geometry/vspline.cpp index 51ad88a07..daa06cda1 100644 --- a/src/app/geometry/vspline.cpp +++ b/src/app/geometry/vspline.cpp @@ -39,7 +39,7 @@ * @brief VSpline default constructor */ VSpline::VSpline() - :VGObject(GOType::Spline), p1(VPointF()), p2(QPointF()), p3(QPointF()), p4(VPointF()), angle1(0), angle2(0), + :VAbstractCurve(GOType::Spline), p1(VPointF()), p2(QPointF()), p3(QPointF()), p4(VPointF()), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1) {} @@ -49,7 +49,7 @@ VSpline::VSpline() * @param spline spline from which the copy. */ VSpline::VSpline ( const VSpline & spline ) - :VGObject(spline), p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), + :VAbstractCurve(spline), p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()) {} @@ -67,7 +67,7 @@ VSpline::VSpline ( const VSpline & spline ) */ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, quint32 idObject, Draw mode) - :VGObject(GOType::Spline, idObject, mode), p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), + :VAbstractCurve(GOType::Spline, idObject, mode), p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve) { CreateName(); @@ -102,7 +102,7 @@ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm * @param p4 second point spline. */ VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject, Draw mode) - :VGObject(GOType::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), + :VAbstractCurve(GOType::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1) { CreateName(); @@ -135,16 +135,6 @@ qreal VSpline::GetLength () const return LengthBezier ( GetP1().toQPointF(), this->p2, this->p3, GetP4().toQPointF()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief name return spline name. Used for variables. - * @return name. - */ -QString VSpline::name() const -{ - return _name; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief CrossingSplLine check intersection spline with line. @@ -665,30 +655,6 @@ void VSpline::CreateName() _name = QString(spl_+"%1_%2").arg(this->GetP1().name(), this->GetP4().name()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetPath return QPainterPath for this spline. - * @return path. - */ -QPainterPath VSpline::GetPath() const -{ - QPainterPath splinePath; - QVector points = GetPoints (); - if (points.count() >= 2) - { - for (qint32 i = 0; i < points.count()-1; ++i) - { - splinePath.moveTo(points.at(i)); - splinePath.lineTo(points.at(i+1)); - } - } - else - { - qDebug()<<"points.count() < 2"< VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qre //--------------------------------------------------------------------------------------------------------------------- VSpline &VSpline::operator =(const VSpline &spline) { - VGObject::operator=(spline); + VAbstractCurve::operator=(spline); this->p1 = spline.GetP1 (); this->p2 = spline.GetP2 (); this->p3 = spline.GetP3 (); diff --git a/src/app/geometry/vspline.h b/src/app/geometry/vspline.h index 629ca99cf..4f4ea8bbc 100644 --- a/src/app/geometry/vspline.h +++ b/src/app/geometry/vspline.h @@ -29,8 +29,8 @@ #ifndef VSPLINE_H #define VSPLINE_H +#include "vabstractcurve.h" #include "vpointf.h" -#include "vgobject.h" #include #include @@ -41,7 +41,7 @@ class QPainterPath; /** * @brief VSpline class that implements the spline. */ -class VSpline :public VGObject +class VSpline :public VAbstractCurve { public: VSpline(); @@ -58,7 +58,6 @@ public: qreal GetAngle1 () const; qreal GetAngle2() const; qreal GetLength () const; - QString name () const; qreal GetKasm1() const; qreal GetKasm2() const; qreal GetKcurve() const; @@ -67,7 +66,6 @@ public: qreal LengthT(qreal t) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; QVector GetPoints () const; - QPainterPath GetPath() const; // cppcheck-suppress unusedFunction static QVector SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve); diff --git a/src/app/geometry/vsplinepath.cpp b/src/app/geometry/vsplinepath.cpp index 003d7ea90..34235d7dc 100644 --- a/src/app/geometry/vsplinepath.cpp +++ b/src/app/geometry/vsplinepath.cpp @@ -31,12 +31,12 @@ //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode) - : VGObject(GOType::SplinePath, idObject, mode), path(QVector()), kCurve(kCurve), maxCountPoints(0) + : VAbstractCurve(GOType::SplinePath, idObject, mode), path(QVector()), kCurve(kCurve), maxCountPoints(0) {} //--------------------------------------------------------------------------------------------------------------------- VSplinePath::VSplinePath(const VSplinePath &splPath) - : VGObject(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), + : VAbstractCurve(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), maxCountPoints(splPath.getMaxCountPoints()) {} @@ -95,7 +95,7 @@ QPainterPath VSplinePath::GetPath() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VSplinePath::GetPathPoints() const +QVector VSplinePath::GetPoints() const { QVector pathPoints; for (qint32 i = 1; i <= Count(); ++i) @@ -157,7 +157,7 @@ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition //--------------------------------------------------------------------------------------------------------------------- VSplinePath &VSplinePath::operator =(const VSplinePath &path) { - VGObject::operator=(path); + VAbstractCurve::operator=(path); this->path = path.GetSplinePath(); this->kCurve = path.getKCurve(); this->maxCountPoints = path.getMaxCountPoints(); @@ -212,9 +212,6 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF return QPointF(); } -//--------------------------------------------------------------------------------------------------------------------- -QString VSplinePath::name() const{return _name;} - //--------------------------------------------------------------------------------------------------------------------- qint32 VSplinePath::getMaxCountPoints() const { diff --git a/src/app/geometry/vsplinepath.h b/src/app/geometry/vsplinepath.h index e31553eea..3d22c88bd 100644 --- a/src/app/geometry/vsplinepath.h +++ b/src/app/geometry/vsplinepath.h @@ -29,7 +29,7 @@ #ifndef VSPLINEPATH_H #define VSPLINEPATH_H -#include "vgobject.h" +#include "vabstractcurve.h" #include "vspline.h" #include "vsplinepoint.h" #include @@ -41,7 +41,7 @@ enum class SplinePointPosition : char { FirstPoint, LastPoint }; /** * @brief The VSplinePath class keep information about splinePath. */ -class VSplinePath :public VGObject +class VSplinePath :public VAbstractCurve { Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: @@ -87,7 +87,7 @@ public: * @brief GetPathPoints return list of points what located on path. * @return list. */ - QVector GetPathPoints() const; + QVector GetPoints() const; /** * @brief GetSplinePath return list with spline points. * @return list. @@ -172,11 +172,6 @@ public: */ QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; - /** - * @brief name return spline path name. - * @return name. - */ - virtual QString name() const; /** * @brief getMaxCountPoints return max count of points what can have spline path. This method use tool union detail. * Because cutting point can change position spline can have diffirent count of points. Need know max value. This