Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-25 17:08:12 +03:00
parent 129e579612
commit bc87f5ffbe
10 changed files with 156 additions and 83 deletions

View file

@ -7,7 +7,8 @@ HEADERS += \
geometry/varc.h \ geometry/varc.h \
geometry/vgobject.h \ geometry/vgobject.h \
geometry/vpointf.h \ geometry/vpointf.h \
geometry/vequidistant.h geometry/vequidistant.h \
geometry/vabstractcurve.h
SOURCES += \ SOURCES += \
geometry/vsplinepoint.cpp \ geometry/vsplinepoint.cpp \
@ -18,4 +19,5 @@ SOURCES += \
geometry/varc.cpp \ geometry/varc.cpp \
geometry/vgobject.cpp \ geometry/vgobject.cpp \
geometry/vpointf.cpp \ geometry/vpointf.cpp \
geometry/vequidistant.cpp geometry/vequidistant.cpp \
geometry/vabstractcurve.cpp

View file

@ -0,0 +1,67 @@
/************************************************************************
**
** @file vabstractcurve.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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/>.
**
*************************************************************************/
#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<QPointF> 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"<<Q_FUNC_INFO;
}
return path;
}

View file

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vabstractcurve.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 VABSTRACTCURVE_H
#define VABSTRACTCURVE_H
#include "vgobject.h"
#include <QPointF>
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<QPointF> 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

View file

@ -42,7 +42,7 @@
* @brief VArc default constructor. * @brief VArc default constructor.
*/ */
VArc::VArc () 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()) formulaRadius(QString()), center(VPointF())
{} {}
@ -56,7 +56,7 @@ 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)
: 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) radius(radius), formulaRadius(formulaRadius), center(center)
{ {
_name = QString (arc_+"%1").arg(this->GetCenter().name()); _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 * @param arc arc
*/ */
VArc::VArc(const VArc &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()), formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()),
center(arc.GetCenter()) center(arc.GetCenter())
{} {}
@ -81,7 +81,7 @@ VArc::VArc(const VArc &arc)
*/ */
VArc &VArc::operator =(const VArc &arc) VArc &VArc::operator =(const VArc &arc)
{ {
VGObject::operator=(arc); VAbstractCurve::operator=(arc);
this->f1 = arc.GetF1(); this->f1 = arc.GetF1();
this->formulaF1 = arc.GetFormulaF1(); this->formulaF1 = arc.GetFormulaF1();
this->f2 = arc.GetF2(); this->f2 = arc.GetF2();
@ -195,16 +195,6 @@ QVector<QPointF> VArc::GetPoints() const
return points; 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. * @brief CutArc cut arc into two arcs.

View file

@ -29,7 +29,7 @@
#ifndef VARC_H #ifndef VARC_H
#define VARC_H #define VARC_H
#include "vgobject.h" #include "vabstractcurve.h"
#include "vpointf.h" #include "vpointf.h"
#include <QCoreApplication> #include <QCoreApplication>
@ -38,7 +38,7 @@ class QPainterPath;
/** /**
* @brief VArc class for anticlockwise arc. * @brief VArc class for anticlockwise arc.
*/ */
class VArc: public VGObject class VArc: public VAbstractCurve
{ {
Q_DECLARE_TR_FUNCTIONS(VArc) Q_DECLARE_TR_FUNCTIONS(VArc)
public: public:
@ -60,7 +60,6 @@ public:
QPainterPath GetPath() const; QPainterPath GetPath() const;
qreal AngleArc() const; qreal AngleArc() const;
QVector<QPointF> GetPoints () const; QVector<QPointF> GetPoints () const;
virtual QString name() const;
QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const;
virtual void setId(const quint32 &id); virtual void setId(const quint32 &id);
private: private:

View file

@ -111,22 +111,22 @@ QPainterPath VEquidistant::ContourPath(const quint32 &idDetail, const VContainer
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
{ {
const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(detail.at(i).getId()); const VSplinePath *splinePath = data->GeometricObject<const VSplinePath *>(detail.at(i).getId());
qreal len1 = GetLengthContour(points, splinePath->GetPathPoints()); qreal len1 = GetLengthContour(points, splinePath->GetPoints());
qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPathPoints())); qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath->GetPoints()));
if (len1 <= lenReverse) if (len1 <= lenReverse)
{ {
points << splinePath->GetPathPoints(); points << splinePath->GetPoints();
if (detail.getSeamAllowance() == true) 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 else
{ {
points << GetReversePoint(splinePath->GetPathPoints()); points << GetReversePoint(splinePath->GetPoints());
if (detail.getSeamAllowance() == true) 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()); detail.at(i).getMy());
} }
} }

View file

@ -39,7 +39,7 @@
* @brief VSpline default constructor * @brief VSpline default constructor
*/ */
VSpline::VSpline() 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) kAsm1(1), kAsm2(1), kCurve(1)
{} {}
@ -49,7 +49,7 @@ VSpline::VSpline()
* @param spline spline from which the copy. * @param spline spline from which the copy.
*/ */
VSpline::VSpline ( const VSpline & spline ) 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()), angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()),
kCurve(spline.GetKcurve()) 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, VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
quint32 idObject, Draw mode) 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) angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve)
{ {
CreateName(); CreateName();
@ -102,7 +102,7 @@ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm
* @param p4 second point spline. * @param p4 second point spline.
*/ */
VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject, Draw mode) 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) kAsm2(1), kCurve(1)
{ {
CreateName(); CreateName();
@ -135,16 +135,6 @@ qreal VSpline::GetLength () const
return LengthBezier ( GetP1().toQPointF(), this->p2, this->p3, GetP4().toQPointF()); 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. * @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()); _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<QPointF> 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"<<Q_FUNC_INFO;
}
return splinePath;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SplinePoints return list with spline points. * @brief SplinePoints return list with spline points.
@ -722,7 +688,7 @@ QVector<QPointF> VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qre
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSpline &VSpline::operator =(const VSpline &spline) VSpline &VSpline::operator =(const VSpline &spline)
{ {
VGObject::operator=(spline); VAbstractCurve::operator=(spline);
this->p1 = spline.GetP1 (); this->p1 = spline.GetP1 ();
this->p2 = spline.GetP2 (); this->p2 = spline.GetP2 ();
this->p3 = spline.GetP3 (); this->p3 = spline.GetP3 ();

View file

@ -29,8 +29,8 @@
#ifndef VSPLINE_H #ifndef VSPLINE_H
#define VSPLINE_H #define VSPLINE_H
#include "vabstractcurve.h"
#include "vpointf.h" #include "vpointf.h"
#include "vgobject.h"
#include <QLineF> #include <QLineF>
#include <QPointF> #include <QPointF>
@ -41,7 +41,7 @@ class QPainterPath;
/** /**
* @brief VSpline class that implements the spline. * @brief VSpline class that implements the spline.
*/ */
class VSpline :public VGObject class VSpline :public VAbstractCurve
{ {
public: public:
VSpline(); VSpline();
@ -58,7 +58,6 @@ public:
qreal GetAngle1 () const; qreal GetAngle1 () const;
qreal GetAngle2() const; qreal GetAngle2() const;
qreal GetLength () const; qreal GetLength () const;
QString name () const;
qreal GetKasm1() const; qreal GetKasm1() const;
qreal GetKasm2() const; qreal GetKasm2() const;
qreal GetKcurve() const; qreal GetKcurve() const;
@ -67,7 +66,6 @@ public:
qreal LengthT(qreal t) const; qreal LengthT(qreal t) const;
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
QVector<QPointF> GetPoints () const; QVector<QPointF> GetPoints () const;
QPainterPath GetPath() const;
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
qreal kAsm2, qreal kCurve); qreal kAsm2, qreal kCurve);

View file

@ -31,12 +31,12 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode) VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode)
: VGObject(GOType::SplinePath, idObject, mode), path(QVector<VSplinePoint>()), kCurve(kCurve), maxCountPoints(0) : VAbstractCurve(GOType::SplinePath, idObject, mode), path(QVector<VSplinePoint>()), kCurve(kCurve), maxCountPoints(0)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSplinePath::VSplinePath(const VSplinePath &splPath) VSplinePath::VSplinePath(const VSplinePath &splPath)
: VGObject(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), : VAbstractCurve(splPath), path(*splPath.GetPoint()), kCurve(splPath.getKCurve()),
maxCountPoints(splPath.getMaxCountPoints()) maxCountPoints(splPath.getMaxCountPoints())
{} {}
@ -95,7 +95,7 @@ QPainterPath VSplinePath::GetPath() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VSplinePath::GetPathPoints() const 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)
@ -157,7 +157,7 @@ VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSplinePath &VSplinePath::operator =(const VSplinePath &path) VSplinePath &VSplinePath::operator =(const VSplinePath &path)
{ {
VGObject::operator=(path); VAbstractCurve::operator=(path);
this->path = path.GetSplinePath(); this->path = path.GetSplinePath();
this->kCurve = path.getKCurve(); this->kCurve = path.getKCurve();
this->maxCountPoints = path.getMaxCountPoints(); this->maxCountPoints = path.getMaxCountPoints();
@ -212,9 +212,6 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
return QPointF(); return QPointF();
} }
//---------------------------------------------------------------------------------------------------------------------
QString VSplinePath::name() const{return _name;}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qint32 VSplinePath::getMaxCountPoints() const qint32 VSplinePath::getMaxCountPoints() const
{ {

View file

@ -29,7 +29,7 @@
#ifndef VSPLINEPATH_H #ifndef VSPLINEPATH_H
#define VSPLINEPATH_H #define VSPLINEPATH_H
#include "vgobject.h" #include "vabstractcurve.h"
#include "vspline.h" #include "vspline.h"
#include "vsplinepoint.h" #include "vsplinepoint.h"
#include <QCoreApplication> #include <QCoreApplication>
@ -41,7 +41,7 @@ enum class SplinePointPosition : char { FirstPoint, LastPoint };
/** /**
* @brief The VSplinePath class keep information about splinePath. * @brief The VSplinePath class keep information about splinePath.
*/ */
class VSplinePath :public VGObject class VSplinePath :public VAbstractCurve
{ {
Q_DECLARE_TR_FUNCTIONS(VSplinePath) Q_DECLARE_TR_FUNCTIONS(VSplinePath)
public: public:
@ -87,7 +87,7 @@ public:
* @brief GetPathPoints return list of points what located on path. * @brief GetPathPoints return list of points what located on path.
* @return list. * @return list.
*/ */
QVector<QPointF> GetPathPoints() const; QVector<QPointF> GetPoints() const;
/** /**
* @brief GetSplinePath return list with spline points. * @brief GetSplinePath return list with spline points.
* @return list. * @return list.
@ -172,11 +172,6 @@ public:
*/ */
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const; 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. * @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 * Because cutting point can change position spline can have diffirent count of points. Need know max value. This