Fixed bugs in VArc and VSpline. Bug in DataPoints.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-10 21:45:58 +03:00
parent 80b5fe6d5e
commit 7f3b2f76ee
18 changed files with 87 additions and 50 deletions

View File

@ -21,15 +21,16 @@
#include "varc.h"
#include <QDebug>
#include "exception/vexception.h"
VArc::VArc () : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()),
center(0), points(0), mode(Draw::Calculation), idObject(0){
center(0), points(QHash<qint64, VPointF>()), mode(Draw::Calculation), idObject(0){
}
VArc::VArc (const QHash<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2, QString formulaF2, Draw::Draws mode, qint64 idObject)
: f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius),
center(center), points(points), mode(mode), idObject(idObject){
center(center), points(*points), mode(mode), idObject(idObject){
}
VArc::VArc(const VArc &arc): f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()),
@ -85,11 +86,11 @@ qint64 VArc::GetCenter() const{
}
QPointF VArc::GetCenterPoint() const{
if(points->contains(center)){
return points->value(center).toQPointF();
if(points.contains(center)){
return points.value(center).toQPointF();
} else {
qCritical()<<"Не можу знайти id = "<<center<<" в таблиці.";
throw"Не можу знайти точку за id.";
QString error = QString(tr("Can't find id = %1 in table.")).arg(center);
throw VException(error);
}
return QPointF();
}
@ -108,7 +109,7 @@ QPointF VArc::GetP2 () const{
return centerP2.p2();
}
const QHash<qint64, VPointF> *VArc::GetDataPoints() const{
const QHash<qint64, VPointF> VArc::GetDataPoints() const{
return points;
}
@ -133,9 +134,11 @@ qreal VArc::AngleArc() const{
qint32 VArc::NumberSplOfArc() const{
qint32 angArc = static_cast<qint32> (AngleArc ());
switch( angArc ){
case 0:
throw "Кут дуги не може бути 0 градусів.";
case 0:{
QString error = QString(tr("Angle of arc can't be 0 degree."));
throw VException(error);
break;
}
case 90:
return 1;
case 180:
@ -161,7 +164,8 @@ QVector<QPointF> VArc::GetPoints() const{
QVector<QPointF> VArc::SplOfArc(qint32 number) const{
qint32 n = NumberSplOfArc ();
if( number > n ){
throw "Дуга не складається з такої кількості сплайнів.";
QString error = QString(tr("Arc have not this number of part."));
throw VException(error);
}
qreal f1 = GetF1 ();
qreal f2 = GetF2 ();

View File

@ -23,11 +23,13 @@
#define VARC_H
#include "vspline.h"
#include <QCoreApplication>
/**
* @brief VArc клас, що реалізує дугу. Дуга розраховується за годиниковою стрілкою.
*/
class VArc{
Q_DECLARE_TR_FUNCTIONS(VArc)
public:
/**
* @brief VArc конструктор по замовчуванню.
@ -84,7 +86,7 @@ public:
* @return точку кінця дуги.
*/
QPointF GetP2 () const;
const QHash<qint64, VPointF> *GetDataPoints() const;
const QHash<qint64, VPointF> GetDataPoints() const;
/**
* @brief GetPath будує шлях по даній дузі.
* @return повертає шлях.
@ -119,7 +121,7 @@ private:
* @brief center центральна точка дуги.
*/
qint64 center;
const QHash<qint64, VPointF> *points;
QHash<qint64, VPointF> points;
Draw::Draws mode;
qint64 idObject;
};

View File

@ -23,7 +23,7 @@
#include <QDebug>
VSpline::VSpline():p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1),
kCurve(1), points(0), mode(Draw::Calculation), idObject(0){
kCurve(1), points(QHash<qint64, VPointF>()), mode(Draw::Calculation), idObject(0){
}
VSpline::VSpline ( const VSpline & spline ):p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()),
@ -34,14 +34,14 @@ VSpline::VSpline ( const VSpline & spline ):p1(spline.GetP1 ()), p2(spline.GetP2
VSpline::VSpline (const QHash<qint64, VPointF> *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2,
qreal kAsm1, qreal kAsm2 , qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(QPointF()), p3(QPointF()),
p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve), points(points),
p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve), points(*points),
mode(mode), idObject(idObject){
ModifiSpl ( p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve );
}
VSpline::VSpline (const QHash<qint64, VPointF> *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4,
qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(p2), p3(p3), p4(p4), angle1(0),
angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(points), mode(mode), idObject(idObject){
angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(*points), mode(mode), idObject(idObject){
ModifiSpl ( p1, p2, p3, p4, kCurve);
}
@ -129,8 +129,8 @@ qint64 VSpline::GetP1 () const{
}
VPointF VSpline::GetPointP1() const{
if(points->contains(p1)){
return points->value(p1);
if(points.contains(p1)){
return points.value(p1);
} else {
qCritical()<<"Не можу знайти id = "<<p1<<" в таблиці.";
throw"Не можу знайти точку за id.";
@ -151,8 +151,8 @@ qint64 VSpline::GetP4() const{
}
VPointF VSpline::GetPointP4() const{
if(points->contains(p4)){
return points->value(p4);
if(points.contains(p4)){
return points.value(p4);
} else {
qCritical()<<"Не можу знайти id = "<<p4<<" в таблиці.";
throw"Не можу знайти точку за id.";
@ -190,7 +190,7 @@ qreal VSpline::GetKcurve() const{
return kCurve;
}
const QHash<qint64, VPointF> *VSpline::GetDataPoints() const{
const QHash<qint64, VPointF> VSpline::GetDataPoints() const{
return points;
}

View File

@ -136,7 +136,7 @@ public:
qreal GetKasm1() const;
qreal GetKasm2() const;
qreal GetKcurve() const;
const QHash<qint64, VPointF> *GetDataPoints() const;
const QHash<qint64, VPointF> GetDataPoints() const;
/**
* @brief CrossingSplLine перевіряє перетин сплайну з лінією.
* @param line лінія з якою перевіряється перетин.
@ -224,7 +224,7 @@ private:
qreal kAsm1;
qreal kAsm2;
qreal kCurve;
const QHash<qint64, VPointF> *points;
QHash<qint64, VPointF> points;
Draw::Draws mode;
qint64 idObject;
/**

View File

@ -22,16 +22,16 @@
#include "vsplinepath.h"
#include "exception/vexception.h"
VSplinePath::VSplinePath(): path(QVector<VSplinePoint>()), kCurve(1), mode(Draw::Calculation), points(0),
idObject(0){
VSplinePath::VSplinePath(): path(QVector<VSplinePoint>()), kCurve(1), mode(Draw::Calculation),
points(QHash<qint64, VPointF>()), idObject(0){
}
VSplinePath::VSplinePath(const QHash<qint64, VPointF> *points, qreal kCurve, Draw::Draws mode, qint64 idObject): path(QVector<VSplinePoint>()),
kCurve(kCurve), mode(mode), points(points), idObject(idObject){
kCurve(kCurve), mode(mode), points(*points), idObject(idObject){
}
VSplinePath::VSplinePath(const VSplinePath &splPath): path(*splPath.GetPoint()),
kCurve(splPath.getKCurve()), mode(splPath.getMode()), points( splPath.GetDataPoints()),
kCurve(splPath.getKCurve()), mode(splPath.getMode()), points(splPath.GetDataPoints()),
idObject(splPath.getIdObject()){
}
@ -66,7 +66,7 @@ VSpline VSplinePath::GetSpline(qint32 index) const{
if(index < 1 || index > Count()){
throw VException(tr("This spline is not exist."));
}
VSpline spl(points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(),
VSpline spl(&points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(),
path[index-1].KAsm2(), path[index].KAsm1(), this->kCurve);
return spl;
}
@ -74,8 +74,8 @@ VSpline VSplinePath::GetSpline(qint32 index) const{
QPainterPath VSplinePath::GetPath() const{
QPainterPath painterPath;
for(qint32 i = 1; i <= Count(); ++i){
VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
path[i].KAsm1(), this->kCurve);
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve);
painterPath.addPath(spl.GetPath());
}
return painterPath;
@ -84,8 +84,8 @@ QPainterPath VSplinePath::GetPath() const{
QVector<QPointF> VSplinePath::GetPathPoints() const{
QVector<QPointF> pathPoints;
for(qint32 i = 1; i <= Count(); ++i){
VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
path[i].KAsm1(), this->kCurve);
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(),
path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve);
QVector<QPointF> splP = spl.GetPoints();
for(qint32 j = 0; j < splP.size(); ++j){
pathPoints.append(splP[j]);
@ -101,14 +101,14 @@ QVector<VSplinePoint> VSplinePath::GetSplinePath() const{
qreal VSplinePath::GetLength() const{
qreal length = 0;
for(qint32 i = 1; i <= Count(); ++i){
VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(),
path[i].KAsm1(), kCurve);
length += spl.GetLength();
}
return length;
}
const QHash<qint64, VPointF> *VSplinePath::GetDataPoints() const{
QHash<qint64, VPointF> VSplinePath::GetDataPoints() const{
return points;
}

View File

@ -60,7 +60,7 @@ public:
QVector<QPointF> GetPathPoints() const;
QVector<VSplinePoint> GetSplinePath() const;
qreal GetLength() const;
const QHash<qint64, VPointF> *GetDataPoints() const;
QHash<qint64, VPointF> GetDataPoints() const;
void UpdatePoint(qint32 indexSpline, SplinePoint::Position pos, VSplinePoint point);
VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const;
/**
@ -85,7 +85,7 @@ protected:
QVector<VSplinePoint> path;
qreal kCurve;
Draw::Draws mode;
const QHash<qint64, VPointF> *points;
QHash<qint64, VPointF> points;
qint64 idObject;
};

View File

@ -128,15 +128,17 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
} else {
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
VDrawTool::AddRecord(id, Tool::AlongLineTool, doc);
data->AddLine(firstPointId, id);
data->AddLine(id, secondPointId);
if(parse == Document::FullParse){
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId,
secondPointId, typeLine, typeCreation);

View File

@ -87,13 +87,14 @@ void VToolArc::Create(const qint64 _id, const qint64 &center, const QString &rad
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddArc(arc);
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
} else {
data->UpdateArc(id, arc);
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength());
VDrawTool::AddRecord(id, Tool::ArcTool, doc);
if(parse == Document::FullParse){
VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation);

View File

@ -93,13 +93,14 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(firstPointId, id);
VDrawTool::AddRecord(id, Tool::BisectorTool, doc);
if(parse == Document::FullParse){
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula,

View File

@ -74,13 +74,14 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(basePointId, id);
} else {
data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
data->AddLine(basePointId, id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(basePointId, id);
VDrawTool::AddRecord(id, Tool::EndLineTool, doc);
if(parse == Document::FullParse){
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle,

View File

@ -60,12 +60,13 @@ void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->getNextId();
data->AddLine(firstPoint, secondPoint);
} else {
data->AddLine(firstPoint, secondPoint);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(firstPoint, secondPoint);
VDrawTool::AddRecord(id, Tool::LineTool, doc);
if(parse == Document::FullParse){
VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeCreation);

View File

@ -72,16 +72,20 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
VDrawTool::AddRecord(id, Tool::LineIntersectTool, doc);
if(parse == Document::FullParse){
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id,

View File

@ -74,13 +74,14 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
} else {
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(firstPointId, id);
VDrawTool::AddRecord(id, Tool::NormalTool, doc);
if(parse == Document::FullParse){
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle,

View File

@ -96,8 +96,14 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
} else {
data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(firstPointId, id);
data->AddLine(secondPointId, id);
data->AddLine(center, id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}

View File

@ -99,14 +99,16 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
} else {
data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLine(p1Line, id);
data->AddLine(p2Line, id);
VDrawTool::AddRecord(id, Tool::ShoulderPointTool, doc);
if(parse == Document::FullParse){
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula,

View File

@ -94,13 +94,14 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddSpline(spline);
data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength());
} else {
data->UpdateSpline(id, spline);
data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength());
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength());
VDrawTool::AddRecord(id, Tool::SplineTool, doc);
if(parse == Document::FullParse){
VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation);

View File

@ -82,13 +82,14 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddSplinePath(path);
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
} else {
data->UpdateSplinePath(id, path);
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
if(parse != Document::FullParse){
doc->UpdateToolData(id, data);
}
}
data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength());
VDrawTool::AddRecord(id, Tool::SplinePathTool, doc);
if(parse == Document::FullParse){
VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation);

View File

@ -95,6 +95,16 @@ bool VApplication::notify(QObject *receiver, QEvent *event){
msgBox.exec();
abort();
}
catch(const VException &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Something wrong!!"));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
catch(std::exception& e) {
qCritical() << "Exception thrown:" << e.what();
}