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 "../../container/calculator.h"
#include "../../dialogs/tools/dialogalongline.h" #include "../../dialogs/tools/dialogalongline.h"
#include "exception/vexceptionobjecterror.h"
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); 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); const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF()); QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());
try
{
Calculator cal(data); Calculator cal(data);
const qreal result = cal.EvalFormula(formula); const qreal result = cal.EvalFormula(formula);
line.setLength(qApp->toPixel(result)); 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;
}
quint32 id = _id; quint32 id = _id;
if (typeCreation == Valentina::FromGui) if (typeCreation == Valentina::FromGui)

View File

@ -93,8 +93,6 @@ void VToolArc::Create(const quint32 _id, const quint32 &center, const QString &r
{ {
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
try
{
Calculator cal(data); Calculator cal(data);
qreal result = cal.EvalFormula(radius); qreal result = cal.EvalFormula(radius);
@ -102,19 +100,6 @@ void VToolArc::Create(const quint32 _id, const quint32 &center, const QString &r
calcF1 = cal.EvalFormula(f1); calcF1 = cal.EvalFormula(f1);
calcF2 = cal.EvalFormula(f2); 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;
}
VPointF c = *data->GeometricObject<const VPointF *>(center); VPointF c = *data->GeometricObject<const VPointF *>(center);
VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 ); 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 *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId); const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
thirdPoint->toQPointF(), qApp->toPixel(result)); 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) VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
{ {
const VArc *arc = data->GeometricObject<const VArc *>(arcId); const VArc *arc = data->GeometricObject<const VArc *>(arcId);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
VArc arc1; VArc arc1;
VArc arc2; 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); const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
QPointF spl1p2, spl1p3, spl2p2, spl2p3; QPointF spl1p2, spl1p3, spl2p2, spl2p3;
QPointF point = spl->CutSpline(qApp->toPixel(result), 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); const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
Q_CHECK_PTR(splPath); Q_CHECK_PTR(splPath);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
quint32 id = _id; quint32 id = _id;
QPointF spl1p2, spl1p3, spl2p2, spl2p3; 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); const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
line.setLength(qApp->toPixel(result)); line.setLength(qApp->toPixel(result));
line.setAngle(angle); 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 *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId); const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
qApp->toPixel(result), angle); 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 *firstP = data->GeometricObject<const VPointF *>(firstPointId);
const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId); const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(radius); const qreal 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;
}
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(), QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(),
firstP->toQPointF(), secondP->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 *secondPoint = data->GeometricObject<const VPointF *>(p2Line);
const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder); const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder);
qreal result = 0;
try
{
Calculator cal(data); Calculator cal(data);
result = cal.EvalFormula(formula); const qreal 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;
}
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(), QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
shoulderPoint->toQPointF(), qApp->toPixel(result)); shoulderPoint->toQPointF(), qApp->toPixel(result));

View File

@ -39,6 +39,7 @@
#include "vindividualmeasurements.h" #include "vindividualmeasurements.h"
#include <QMessageBox> #include <QMessageBox>
#include <qmuparsererror.h>
const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagPattern = QStringLiteral("pattern");
const QString VPattern::TagCalculation = QStringLiteral("calculation"); const QString VPattern::TagCalculation = QStringLiteral("calculation");
@ -845,6 +846,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 2: //VToolAlongLine::ToolType case 2: //VToolAlongLine::ToolType
try try
@ -868,6 +880,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 3: //VToolShoulderPoint::ToolType case 3: //VToolShoulderPoint::ToolType
try try
@ -892,6 +915,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 4: //VToolNormal::ToolType case 4: //VToolNormal::ToolType
try try
@ -916,6 +950,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 5: //VToolBisector::ToolType case 5: //VToolBisector::ToolType
try try
@ -940,6 +985,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 6: //VToolLineIntersect::ToolType case 6: //VToolLineIntersect::ToolType
try try
@ -984,6 +1040,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 8: //VNodePoint::ToolType case 8: //VNodePoint::ToolType
try try
@ -1089,6 +1156,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 13: //VToolCutSplinePath::ToolType case 13: //VToolCutSplinePath::ToolType
try try
@ -1109,6 +1187,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 14: //VToolCutArc::ToolType case 14: //VToolCutArc::ToolType
try try
@ -1128,6 +1217,17 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, const QDomElement &d
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
default: default:
qDebug() << "Illegal point type in VDomDocument::ParsePointElement()."; qDebug() << "Illegal point type in VDomDocument::ParsePointElement().";
@ -1311,6 +1411,17 @@ void VPattern::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &dom
excep.AddMoreInformation(e.ErrorMessage()); excep.AddMoreInformation(e.ErrorMessage());
throw excep; 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; break;
case 1: //VNodeArc::ToolType case 1: //VNodeArc::ToolType
try try