Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-27 12:22:44 +02:00
parent 3b908ae328
commit 61be0a0a93
10 changed files with 228 additions and 461 deletions

View File

@ -20,7 +20,6 @@
****************************************************************************/
#include "calculator.h"
#include <QDebug>
#define DELIMITER 1
#define VARIABLE 2

View File

@ -22,15 +22,13 @@
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QString>
#include "vcontainer.h"
/**
* @brief The Calculator клас калькулятора формул лекал. Виконує розрахунок формул з підставлянням
* значеннь зміних.
*/
class Calculator
{
class Calculator{
public:
/**
* @brief Calculator конструктор класу. Використовується при розрахунку лекала.

View File

@ -20,8 +20,6 @@
****************************************************************************/
#include "vcontainer.h"
#include <QDebug>
#include "options.h"
#include <exception/vexceptionbadid.h>
qint64 VContainer::_id = 0;
@ -85,14 +83,6 @@ val VContainer::GetObject(const QHash<key, val> &obj, key id){
}
}
VPointF VContainer::GetPoint(qint64 id) const{
return GetObject(points, id);
}
VPointF VContainer::GetModelingPoint(qint64 id) const{
return GetObject(modelingPoints, id);
}
VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{
Q_ASSERT(!name.isEmpty());
return GetObject(standartTable, name);
@ -123,44 +113,16 @@ qreal VContainer::GetLineAngle(const QString &name) const{
return GetObject(lineAngles, name);
}
VSpline VContainer::GetSpline(qint64 id) const{
return GetObject(splines, id);
qint64 VContainer::AddPoint(const VPointF &point){
return AddObject(points, point);
}
VSpline VContainer::GetModelingSpline(qint64 id) const{
return GetObject(modelingSplines, id);
qint64 VContainer::AddModelingPoint(const VPointF &point){
return AddObject(modelingPoints, point);
}
VArc VContainer::GetArc(qint64 id) const{
return GetObject(arcs, id);
}
VArc VContainer::GetModelingArc(qint64 id) const{
return GetObject(modelingArcs, id);
}
VSplinePath VContainer::GetSplinePath(qint64 id) const{
return GetObject(splinePaths, id);
}
VSplinePath VContainer::GetModelingSplinePath(qint64 id) const{
return GetObject(modelingSplinePaths, id);
}
VDetail VContainer::GetDetail(qint64 id) const{
return GetObject(details, id);
}
void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::AddIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
qint64 VContainer::getId(){
return _id;
qint64 VContainer::AddDetail(const VDetail &detail){
return AddObject(details, detail);
}
qint64 VContainer::getNextId(){
@ -444,10 +406,6 @@ void VContainer::PrepareDetails(QVector<VItem *> &list) const{
}
}
void VContainer::RemoveIncrementTableRow(const QString& name){
incrementTable.remove(name);
}
template <typename val>
void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, const val& point){
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
@ -455,50 +413,6 @@ void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, const v
UpdateId(id);
}
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
UpdateObject(points, id, point);
}
void VContainer::UpdateModelingPoint(qint64 id, const VPointF &point){
UpdateObject(modelingPoints, id, point);
}
void VContainer::UpdateDetail(qint64 id, const VDetail &detail){
UpdateObject(details, id, detail);
}
void VContainer::UpdateSpline(qint64 id, const VSpline &spl){
UpdateObject(splines, id, spl);
}
void VContainer::UpdateModelingSpline(qint64 id, const VSpline &spl){
UpdateObject(modelingSplines, id, spl);
}
void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){
UpdateObject(splinePaths, id, splPath);
}
void VContainer::UpdateModelingSplinePath(qint64 id, const VSplinePath &splPath){
UpdateObject(modelingSplinePaths, id, splPath);
}
void VContainer::UpdateArc(qint64 id, const VArc &arc){
UpdateObject(arcs, id, arc);
}
void VContainer::UpdateModelingArc(qint64 id, const VArc &arc){
UpdateObject(modelingArcs, id, arc);
}
void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
void VContainer::AddLengthSpline(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
lengthSplines[name] = value;
@ -557,46 +471,6 @@ void VContainer::ClearObject(){
splinePaths.clear();
}
void VContainer::ClearIncrementTable(){
incrementTable.clear();
}
void VContainer::ClearLengthLines(){
lengthLines.clear();
}
void VContainer::ClearLengthSplines(){
lengthSplines.clear();
}
void VContainer::ClearLengthArcs(){
lengthArcs.clear();
}
void VContainer::ClearLineAngles(){
lineAngles.clear();
}
void VContainer::SetSize(qint32 size){
base["Сг"] = size;
}
void VContainer::SetGrowth(qint32 growth){
base["Р"] = growth;
}
qint32 VContainer::size() const{
return base.value("Сг");
}
qint32 VContainer::growth() const{
return base.value("Р");
}
bool VContainer::IncrementTableContains(const QString& name){
return incrementTable.contains(name);
}
qreal VContainer::FindVar(const QString &name, bool *ok)const{
if(base.contains(name)){
*ok = true;
@ -631,70 +505,6 @@ qreal VContainer::FindVar(const QString &name, bool *ok)const{
return 0;
}
const QHash<qint64, VPointF> *VContainer::DataPoints() const{
return &points;
}
const QHash<qint64, VPointF> *VContainer::DataModelingPoints() const{
return &modelingPoints;
}
const QHash<qint64, VSpline> *VContainer::DataSplines() const{
return &splines;
}
const QHash<qint64, VSpline> *VContainer::DataModelingSplines() const{
return &modelingSplines;
}
const QHash<qint64, VArc> *VContainer::DataArcs() const{
return &arcs;
}
const QHash<qint64, VArc> *VContainer::DataModelingArcs() const{
return &modelingArcs;
}
const QHash<QString, qint32> *VContainer::DataBase() const{
return &base;
}
const QHash<QString, VStandartTableCell> *VContainer::DataStandartTable() const{
return &standartTable;
}
const QHash<QString, VIncrementTableRow> *VContainer::DataIncrementTable() const{
return &incrementTable;
}
const QHash<QString, qreal> *VContainer::DataLengthLines() const{
return &lengthLines;
}
const QHash<QString, qreal> *VContainer::DataLengthSplines() const{
return &lengthSplines;
}
const QHash<QString, qreal> *VContainer::DataLengthArcs() const{
return &lengthArcs;
}
const QHash<QString, qreal> *VContainer::DataLineAngles() const{
return &lineAngles;
}
const QHash<qint64, VSplinePath> *VContainer::DataSplinePaths() const{
return &splinePaths;
}
const QHash<qint64, VSplinePath> *VContainer::DataModelingSplinePaths() const{
return &modelingSplinePaths;
}
const QHash<qint64, VDetail> *VContainer::DataDetails() const{
return &details;
}
void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId, Draw::Draws mode){
QString nameLine = GetNameLine(firstPointId, secondPointId, mode);
VPointF first;
@ -711,25 +521,6 @@ void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId
AddLineAngle(nameLine, QLineF(first.toQPointF(), second.toQPointF()).angle());
}
template <typename key, typename val>
qint64 VContainer::AddObject(QHash<key, val> &obj, const val& value){
qint64 id = getNextId();
obj[id] = value;
return id;
}
qint64 VContainer::AddPoint(const VPointF& point){
return AddObject(points, point);
}
qint64 VContainer::AddModelingPoint(const VPointF &point){
return AddObject(modelingPoints, point);
}
qint64 VContainer::AddDetail(const VDetail &detail){
return AddObject(details, detail);
}
qint64 VContainer::AddSpline(const VSpline &spl){
return AddObject(splines, spl);
}
@ -754,6 +545,13 @@ qint64 VContainer::AddModelingArc(const VArc &arc){
return AddObject(modelingArcs, arc);
}
template <typename key, typename val>
qint64 VContainer::AddObject(QHash<key, val> &obj, const val& value){
qint64 id = getNextId();
obj[id] = value;
return id;
}
QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, Draw::Draws mode) const{
VPointF first;
VPointF second;
@ -827,6 +625,42 @@ QString VContainer::GetNameArc(const qint64 &center, const qint64 &id, Draw::Dra
return QString ("Arc_%1_%2").arg(centerPoint.name()).arg(id);
}
void VContainer::UpdatePoint(qint64 id, const VPointF &point){
UpdateObject(points, id, point);
}
void VContainer::UpdateModelingPoint(qint64 id, const VPointF &point){
UpdateObject(modelingPoints, id, point);
}
void VContainer::UpdateDetail(qint64 id, const VDetail &detail){
UpdateObject(details, id, detail);
}
void VContainer::UpdateSpline(qint64 id, const VSpline &spl){
UpdateObject(splines, id, spl);
}
void VContainer::UpdateModelingSpline(qint64 id, const VSpline &spl){
UpdateObject(modelingSplines, id, spl);
}
void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){
UpdateObject(splinePaths, id, splPath);
}
void VContainer::UpdateModelingSplinePath(qint64 id, const VSplinePath &splPath){
UpdateObject(modelingSplinePaths, id, splPath);
}
void VContainer::UpdateArc(qint64 id, const VArc &arc){
UpdateObject(arcs, id, arc);
}
void VContainer::UpdateModelingArc(qint64 id, const VArc &arc){
UpdateObject(modelingArcs, id, arc);
}
void VContainer::AddLengthLine(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
lengthLines[name] = value;

View File

@ -22,20 +22,17 @@
#ifndef VCONTAINER_H
#define VCONTAINER_H
#include <QTableWidget>
#include "vstandarttablecell.h"
#include "vincrementtablerow.h"
#include "geometry/varc.h"
#include "geometry/vsplinepath.h"
#include "geometry/vdetail.h"
#include "widgets/vitem.h"
#include <QCoreApplication>
/**
* @brief The VContainer class
*/
class VContainer
{
class VContainer{
Q_DECLARE_TR_FUNCTIONS(VContainer)
public:
/**
@ -50,27 +47,29 @@ public:
* @param id
* @return
*/
VPointF GetPoint(qint64 id) const;
VPointF GetModelingPoint(qint64 id) const;
inline VPointF GetPoint(qint64 id) const {return GetObject(points, id);}
inline VPointF GetModelingPoint(qint64 id) const {return GetObject(modelingPoints, id);}
VStandartTableCell GetStandartTableCell(const QString& name) const;
VIncrementTableRow GetIncrementTableRow(const QString& name) const;
qreal GetLine(const QString &name) const;
qreal GetLengthArc(const QString &name) const;
qreal GetLengthSpline(const QString &name) const;
qreal GetLineAngle(const QString &name) const;
VSpline GetSpline(qint64 id) const;
VSpline GetModelingSpline(qint64 id) const;
VArc GetArc(qint64 id) const;
VArc GetModelingArc(qint64 id) const;
VSplinePath GetSplinePath(qint64 id) const;
VSplinePath GetModelingSplinePath(qint64 id) const;
VDetail GetDetail(qint64 id) const;
static qint64 getId();
inline VSpline GetSpline(qint64 id) const {return GetObject(splines, id);}
inline VSpline GetModelingSpline(qint64 id) const {return GetObject(modelingSplines, id);}
inline VArc GetArc(qint64 id) const {return GetObject(arcs, id);}
inline VArc GetModelingArc(qint64 id) const {return GetObject(modelingArcs, id);}
inline VSplinePath GetSplinePath(qint64 id) const {return GetObject(splinePaths, id);}
inline VSplinePath GetModelingSplinePath(qint64 id) const {return GetObject(modelingSplinePaths, id);}
inline VDetail GetDetail(qint64 id) const {return GetObject(details, id);}
static qint64 getId() {return _id;}
qint64 AddPoint(const VPointF& point);
qint64 AddModelingPoint(const VPointF& point);
qint64 AddDetail(const VDetail& detail);
void AddStandartTableCell(const QString& name, const VStandartTableCell& cell);
void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell);
inline void AddStandartTableCell(const QString& name, const VStandartTableCell& cell)
{standartTable[name] = cell;}
inline void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell)
{incrementTable[name] = cell;}
void AddLengthLine(const QString &name, const qreal &value);
void AddLengthSpline(const QString &name, const qreal &value);
void AddLengthArc(const qint64 &center, const qint64 &id);
@ -92,8 +91,7 @@ public:
Draw::Draws mode = Draw::Calculation) const;
QString GetNameSplinePath(const VSplinePath &path,
Draw::Draws mode = Draw::Calculation) const;
QString GetNameArc(const qint64 &center, const qint64 &id,
Draw::Draws mode = Draw::Calculation) const;
QString GetNameArc(const qint64 &center, const qint64 &id, Draw::Draws mode = Draw::Calculation) const;
void UpdatePoint(qint64 id, const VPointF& point);
void UpdateModelingPoint(qint64 id, const VPointF& point);
void UpdateDetail(qint64 id, const VDetail& detail);
@ -103,51 +101,52 @@ public:
void UpdateModelingSplinePath(qint64 id, const VSplinePath& splPath);
void UpdateArc(qint64 id, const VArc& arc);
void UpdateModelingArc(qint64 id, const VArc& arc);
void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell);
void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell);
inline void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell)
{standartTable[name] = cell;}
inline void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell)
{incrementTable[name] = cell;}
qreal GetValueStandartTableCell(const QString& name) const;
qreal GetValueIncrementTableRow(const QString& name) const;
void Clear();
void ClearObject();
void ClearIncrementTable();
void ClearLengthLines();
void ClearLengthSplines();
void ClearLengthArcs();
void ClearLineAngles();
void SetSize(qint32 size);
void SetGrowth(qint32 growth);
qint32 size() const;
qint32 growth() const;
inline void ClearIncrementTable() {incrementTable.clear();}
inline void ClearLengthLines() {lengthLines.clear();}
inline void ClearLengthSplines() {lengthSplines.clear();}
inline void ClearLengthArcs() {lengthArcs.clear();}
inline void ClearLineAngles() {lineAngles.clear();}
inline void SetSize(qint32 size) {base["Сг"] = size;}
inline void SetGrowth(qint32 growth) {base["Р"] = growth;}
inline qint32 size() const {return base.value("Сг");}
inline qint32 growth() const {return base.value("Р");}
qreal FindVar(const QString& name, bool *ok)const;
bool IncrementTableContains(const QString& name);
inline bool IncrementTableContains(const QString& name) {return incrementTable.contains(name);}
static qint64 getNextId();
void RemoveIncrementTableRow(const QString& name);
const QHash<qint64, VPointF> *DataPoints() const;
const QHash<qint64, VPointF> *DataModelingPoints() const;
const QHash<qint64, VSpline> *DataSplines() const;
const QHash<qint64, VSpline> *DataModelingSplines() const;
const QHash<qint64, VArc> *DataArcs() const;
const QHash<qint64, VArc> *DataModelingArcs() const;
const QHash<QString, qint32> *DataBase() const;
const QHash<QString, VStandartTableCell> *DataStandartTable() const;
const QHash<QString, VIncrementTableRow> *DataIncrementTable() const;
const QHash<QString, qreal> *DataLengthLines() const;
const QHash<QString, qreal> *DataLengthSplines() const;
const QHash<QString, qreal> *DataLengthArcs() const;
const QHash<QString, qreal> *DataLineAngles() const;
const QHash<qint64, VSplinePath> *DataSplinePaths() const;
const QHash<qint64, VSplinePath> *DataModelingSplinePaths() const;
const QHash<qint64, VDetail> *DataDetails() const;
inline void RemoveIncrementTableRow(const QString& name) {incrementTable.remove(name);}
inline const QHash<qint64, VPointF> *DataPoints() const {return &points;}
inline const QHash<qint64, VPointF> *DataModelingPoints() const {return &modelingPoints;}
inline const QHash<qint64, VSpline> *DataSplines() const {return &splines;}
inline const QHash<qint64, VSpline> *DataModelingSplines() const {return &modelingSplines;}
inline const QHash<qint64, VArc> *DataArcs() const {return &arcs;}
inline const QHash<qint64, VArc> *DataModelingArcs() const {return &modelingArcs;}
inline const QHash<QString, qint32> *DataBase() const {return &base;}
inline const QHash<QString, VStandartTableCell> *DataStandartTable() const {return &standartTable;}
inline const QHash<QString, VIncrementTableRow> *DataIncrementTable() const {return &incrementTable;}
inline const QHash<QString, qreal> *DataLengthLines() const {return &lengthLines;}
inline const QHash<QString, qreal> *DataLengthSplines() const {return &lengthSplines;}
inline const QHash<QString, qreal> *DataLengthArcs() const {return &lengthArcs;}
inline const QHash<QString, qreal> *DataLineAngles() const {return &lineAngles;}
inline const QHash<qint64, VSplinePath> *DataSplinePaths() const {return &splinePaths;}
inline const QHash<qint64, VSplinePath> *DataModelingSplinePaths() const {return &modelingSplinePaths;}
inline const QHash<qint64, VDetail> *DataDetails() const {return &details;}
static void UpdateId(qint64 newId);
QPainterPath ContourPath(qint64 idDetail) const;
QVector<QPointF> biasPoints(const QVector<QPointF> &points, const qreal &mx, const qreal &my) const;
QPainterPath Equidistant(QVector<QPointF> points, const Detail::Equidistant &eqv,
const qreal &width)const;
QPainterPath Equidistant(QVector<QPointF> points, const Detail::Equidistant &eqv, const qreal &width)const;
static QLineF ParallelLine(const QLineF &line, qreal width );
static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width);
QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)const;
QVector<QPointF> CheckLoops(const QVector<QPointF> &points) const;
void PrepareDetails(QVector<VItem*> & list)const;
void PrepareDetails(QVector<VItem *> & list) const;
private:
static qint64 _id;
QHash<QString, qint32> base;
@ -166,13 +165,12 @@ private:
QHash<qint64, VSplinePath> splinePaths;
QHash<qint64, VSplinePath> modelingSplinePaths;
QHash<qint64, VDetail> details;
template <typename key, typename val> static val GetObject(const QHash<key,val> &obj, key id);
template <typename val> static void UpdateObject(QHash<qint64, val> &obj, const qint64 &id,
const val& point);
template <typename key, typename val> static qint64 AddObject(QHash<key, val> &obj, const val& value);
void CreateManTableIGroup ();
QVector<QPointF> GetReversePoint(const QVector<QPointF> &points)const;
qreal GetLengthContour(const QVector<QPointF> &contour, const QVector<QPointF> &newPoints)const;
template <typename key, typename val> static val GetObject(const QHash<key,val> &obj, key id);
template <typename val> static void UpdateObject(QHash<qint64, val> &obj, const qint64 &id, const val& point);
template <typename key, typename val> static qint64 AddObject(QHash<key, val> &obj, const val& value);
};
#endif // VCONTAINER_H

View File

@ -29,42 +29,4 @@ VIncrementTableRow::VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal
kgrowth(kgrowth), description(description){
}
QString VIncrementTableRow::getDescription() const{
return description;
}
void VIncrementTableRow::setDescription(const QString &value){
description = value;
}
qreal VIncrementTableRow::getKgrowth() const{
return kgrowth;
}
void VIncrementTableRow::setKgrowth(const qreal &value){
kgrowth = value;
}
qreal VIncrementTableRow::getKsize() const{
return ksize;
}
void VIncrementTableRow::setKsize(const qreal &value){
ksize = value;
}
qreal VIncrementTableRow::getBase() const{
return base;
}
void VIncrementTableRow::setBase(const qreal &value){
base = value;
}
qint64 VIncrementTableRow::getId() const{
return id;
}
void VIncrementTableRow::setId(const qint64 &value){
id = value;
}

View File

@ -22,23 +22,21 @@
#ifndef VINCREMENTTABLEROW_H
#define VINCREMENTTABLEROW_H
#include <QString>
class VIncrementTableRow{
public:
VIncrementTableRow();
VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth,
QString description = QString());
qint64 getId() const;
void setId(const qint64 &value);
qreal getBase() const;
void setBase(const qreal &value);
qreal getKsize() const;
void setKsize(const qreal &value);
qreal getKgrowth() const;
void setKgrowth(const qreal &value);
QString getDescription() const;
void setDescription(const QString &value);
inline qint64 getId() const {return id;}
inline void setId(const qint64 &value) {id = value;}
inline qreal getBase() const {return base;}
inline void setBase(const qreal &value) {base = value;}
inline qreal getKsize() const {return ksize;}
inline void setKsize(const qreal &value) {ksize = value;}
inline qreal getKgrowth() const {return kgrowth;}
inline void setKgrowth(const qreal &value) {kgrowth = value;}
inline QString getDescription() const {return description;}
inline void setDescription(const QString &value) {description = value;}
private:
qint64 id;
qreal base;

View File

@ -22,10 +22,6 @@
#ifndef VPOINTF_H
#define VPOINTF_H
#include <QPointF>
#include <QString>
#include "options.h"
class VPointF{
public:
inline VPointF ()

View File

@ -27,19 +27,3 @@ VStandartTableCell::VStandartTableCell():base(0), ksize(0), kgrowth(0), descript
VStandartTableCell::VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description):base(base),
ksize(ksize), kgrowth(kgrowth), description(description){
}
qint32 VStandartTableCell::GetBase() const{
return base;
}
qreal VStandartTableCell::GetKsize() const{
return ksize;
}
qreal VStandartTableCell::GetKgrowth() const{
return kgrowth;
}
QString VStandartTableCell::GetDescription() const{
return description;
}

View File

@ -22,16 +22,14 @@
#ifndef VSTANDARTTABLECELL_H
#define VSTANDARTTABLECELL_H
#include <QString>
class VStandartTableCell{
public:
VStandartTableCell();
VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description = QString());
qint32 GetBase() const;
qreal GetKsize() const;
qreal GetKgrowth() const;
QString GetDescription() const;
inline qint32 GetBase() const {return base;}
inline qreal GetKsize() const {return ksize;}
inline qreal GetKgrowth() const {return kgrowth;}
inline QString GetDescription() const {return description;}
private:
qint32 base;
qreal ksize;