Catch math parser exceptions.

--HG--
branch : feature
This commit is contained in:
dismine 2014-05-21 13:12:52 +03:00
parent 8c2c8a8a7e
commit e4ab794211
11 changed files with 138 additions and 182 deletions

View file

@ -30,6 +30,8 @@
#include "../../container/calculator.h"
#include "../../dialogs/tools/dialogalongline.h"
#include "exception/vexceptionobjecterror.h"
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
//---------------------------------------------------------------------------------------------------------------------
@ -180,24 +182,9 @@ void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const Q
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());
try
{
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
line.setLength(qApp->toPixel(result));
}
catch(qmu::QmuParserError &e)
{
//TODO show error
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
line.setLength(qApp->toPixel(result));
quint32 id = _id;
if (typeCreation == Valentina::FromGui)

View file

@ -93,28 +93,13 @@ void VToolArc::Create(const quint32 _id, const quint32 &center, const QString &r
{
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
try
{
Calculator cal(data);
Calculator cal(data);
qreal result = cal.EvalFormula(radius);
calcRadius = qApp->toPixel(result);
qreal result = cal.EvalFormula(radius);
calcRadius = qApp->toPixel(result);
calcF1 = cal.EvalFormula(f1);
calcF2 = cal.EvalFormula(f2);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
calcF1 = cal.EvalFormula(f1);
calcF2 = cal.EvalFormula(f2);
VPointF c = *data->GeometricObject<const VPointF *>(center);
VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 );

View file

@ -114,24 +114,8 @@ void VToolBisector::Create(const quint32 _id, const QString &formula, const quin
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
thirdPoint->toQPointF(), qApp->toPixel(result));

View file

@ -95,24 +95,9 @@ void VToolCutArc::Create(const quint32 _id, const QString &pointName, const QStr
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
{
const VArc *arc = data->GeometricObject<const VArc *>(arcId);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
VArc arc1;
VArc arc2;

View file

@ -97,24 +97,8 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName,
{
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);

View file

@ -98,24 +98,8 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, con
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
Q_CHECK_PTR(splPath);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
quint32 id = _id;
QPointF spl1p2, spl1p3, spl2p2, spl2p3;

View file

@ -89,24 +89,8 @@ void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QSt
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
line.setLength(qApp->toPixel(result));
line.setAngle(angle);

View file

@ -91,24 +91,8 @@ void VToolNormal::Create(const quint32 _id, const QString &formula, const quint3
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
qApp->toPixel(result), angle);

View file

@ -117,24 +117,8 @@ void VToolPointOfContact::Create(const quint32 _id, const QString &radius, const
const VPointF *firstP = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(radius);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(radius);
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(),
firstP->toQPointF(), secondP->toQPointF());

View file

@ -119,24 +119,8 @@ void VToolShoulderPoint::Create(const quint32 _id, const QString &formula, const
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(p2Line);
const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder);
qreal result = 0;
try
{
Calculator cal(data);
result = cal.EvalFormula(formula);
}
catch(qmu::QmuParserError &e)
{
//TODO show error message
qDebug() << "\nError:\n"
<< "--------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: \"" << e.GetExpr() << "\"\n"
<< "Token: \"" << e.GetToken() << "\"\n"
<< "Position: " << e.GetPos() << "\n"
<< "Errc: " << QString::number(e.GetCode(), 16);
return;
}
Calculator cal(data);
const qreal result = cal.EvalFormula(formula);
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
shoulderPoint->toQPointF(), qApp->toPixel(result));

View file

@ -39,6 +39,7 @@
#include "vindividualmeasurements.h"
#include <QMessageBox>
#include <qmuparsererror.h>
const QString VPattern::TagPattern = QStringLiteral("pattern");
const QString VPattern::TagCalculation = QStringLiteral("calculation");
@ -845,6 +846,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 2: //VToolAlongLine::ToolType
try
@ -868,6 +880,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 3: //VToolShoulderPoint::ToolType
try
@ -892,6 +915,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 4: //VToolNormal::ToolType
try
@ -916,6 +950,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 5: //VToolBisector::ToolType
try
@ -940,6 +985,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 6: //VToolLineIntersect::ToolType
try
@ -984,6 +1040,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 8: //VNodePoint::ToolType
try
@ -1089,6 +1156,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating cut spline point"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 13: //VToolCutSplinePath::ToolType
try
@ -1109,6 +1187,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating cut spline path point"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 14: //VToolCutArc::ToolType
try
@ -1128,6 +1217,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating cut arc point"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
default:
qDebug() << "Illegal point type in VDomDocument::ParsePointElement().";
@ -1311,6 +1411,17 @@ void VPattern::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &dom
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch(qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement);
QString message( "Message: " + e.GetMsg() + "\n"+
+ "Expression: \"" + e.GetExpr() + "\"\n"+
+ "Token: \"" + e.GetToken() + "\"\n"+
+ "Position: " + QString::number(e.GetPos()) + "\n"+
+ "Errc: " + QString::number(e.GetCode(), 16));
excep.AddMoreInformation(message);
throw excep;
}
break;
case 1: //VNodeArc::ToolType
try