Fix bug with calculator and tools visualization.

--HG--
branch : develop
This commit is contained in:
dismine 2014-09-20 18:00:29 +03:00
parent 936244948c
commit 7673deade8
13 changed files with 63 additions and 51 deletions

View File

@ -42,7 +42,6 @@ defineTest(copyToDestdir) {
GCC_CXXFLAGS += \
-O0 \
-Wall \
-Wextra \
-pedantic \
@ -84,7 +83,6 @@ GCC_CXXFLAGS += \
-ftrapv
CLANG_CXXFLAGS += \
-O0 \
-fparse-all-comments \
-Wabi \
-Wabstract-final-class \

View File

@ -55,8 +55,7 @@ Calculator::Calculator(const VContainer *data)
InitCharacterSets();
setAllowSubexpressions(false);//Only one expression per time
SetArgSep(',');
SetDecSep('.');
SetSepForEval();
}
//---------------------------------------------------------------------------------------------------------------------
@ -82,30 +81,7 @@ Calculator::Calculator(const QString &formula, bool fromUser)
setAllowSubexpressions(false);//Only one expression per time
SetVarFactory(AddVariable, this);
// Add unary operators
if (fromUser)
{
bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
SetDecSep(loc.decimalPoint().toLatin1());
SetThousandsSep(loc.groupSeparator().toLatin1());
SetArgSep(';');
}
else
{
SetArgSep(',');
SetDecSep('.');
}
}
else
{
SetArgSep(',');
SetDecSep('.');
}
SetSepForTr(fromUser);
SetExpr(formula);
//Need run for making tokens. Don't catch exception here, because we want know if formula has error.
@ -126,6 +102,7 @@ Calculator::~Calculator()
qreal Calculator::EvalFormula(const QString &formula)
{
SetVarFactory(AddVariable, this);
SetSepForEval();//Reset separators options
SetExpr(formula);
@ -214,7 +191,7 @@ void Calculator::InitCharacterSets()
DefineOprtChars(symbols + QStringLiteral("+-*^/?<>=#!$%&|~'_"));
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
// Factory function for creating new parser variables
// This could as well be a function performing database queries.
qreal* Calculator::AddVariable(const QString &a_szName, void *a_pUserData)
@ -225,3 +202,38 @@ qreal* Calculator::AddVariable(const QString &a_szName, void *a_pUserData)
static qreal value = 0;
return &value;
}
//---------------------------------------------------------------------------------------------------------------------
void Calculator::SetSepForEval()
{
SetArgSep(',');
SetDecSep('.');
}
//---------------------------------------------------------------------------------------------------------------------
void Calculator::SetSepForTr(bool fromUser)
{
if (fromUser)
{
bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool();
if (osSeparatorValue)
{
QLocale loc = QLocale::system();
SetDecSep(loc.decimalPoint().toLatin1());
SetThousandsSep(loc.groupSeparator().toLatin1());
SetArgSep(';');
}
else
{
SetArgSep(',');
SetDecSep('.');
}
}
else
{
SetArgSep(',');
SetDecSep('.');
}
}

View File

@ -66,6 +66,8 @@ private:
void InitVariables(const VContainer *data, const QMap<int, QString> &tokens, const QString &formula);
void InitCharacterSets();
static qreal* AddVariable(const QString &a_szName, void *a_pUserData);
void SetSepForEval();
void SetSepForTr(bool fromUser);
};
#endif // CALCULATOR_H

View File

@ -86,7 +86,7 @@ void VToolAlongLine::FullUpdateFromFile()
VisToolAlongLine * visual = qobject_cast<VisToolAlongLine *>(vis);
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
}
@ -200,7 +200,7 @@ void VToolAlongLine::ShowVisualization(bool show)
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
vis = visual;

View File

@ -286,7 +286,7 @@ void VToolArc::ShowVisualization(bool show)
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(id);
visual->setPoint1Id(arc->GetCenter().id());
visual->setRadius(arc->GetFormulaRadius());
visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius()));
visual->setF1(arc->GetFormulaF1());
visual->setF2(arc->GetFormulaF2());
visual->RefreshGeometry();
@ -372,7 +372,7 @@ void VToolArc::RefreshGeometry()
VisToolArc *visual = qobject_cast<VisToolArc *>(vis);
visual->setPoint1Id(arc->GetCenter().id());
visual->setRadius(arc->GetFormulaRadius());
visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius()));
visual->setF1(arc->GetFormulaF1());
visual->setF2(arc->GetFormulaF2());
visual->RefreshGeometry();

View File

@ -238,7 +238,7 @@ void VToolBisector::FullUpdateFromFile()
visual->setPoint1Id(firstPointId);
visual->setPoint2Id(basePointId);
visual->setPoint3Id(thirdPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
}
@ -355,7 +355,7 @@ void VToolBisector::ShowVisualization(bool show)
visual->setPoint1Id(firstPointId);
visual->setPoint2Id(basePointId);
visual->setPoint3Id(thirdPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
vis = visual;

View File

@ -194,7 +194,7 @@ void VToolCutArc::ShowVisualization(bool show)
scene->addItem(visual);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
vis = visual;
}
@ -226,7 +226,7 @@ void VToolCutArc::FullUpdateFromFile()
{
VisToolCutArc *visual = qobject_cast<VisToolCutArc *>(vis);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
}
}

View File

@ -202,7 +202,7 @@ void VToolCutSpline::ShowVisualization(bool show)
scene->addItem(visual);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
vis = visual;
}
@ -238,7 +238,7 @@ void VToolCutSpline::FullUpdateFromFile()
{
VisToolCutSpline *visual = qobject_cast<VisToolCutSpline *>(vis);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
}
}

View File

@ -257,7 +257,7 @@ void VToolCutSplinePath::ShowVisualization(bool show)
scene->addItem(visual);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
vis = visual;
}
@ -293,7 +293,7 @@ void VToolCutSplinePath::FullUpdateFromFile()
{
VisToolCutSplinePath *visual = qobject_cast<VisToolCutSplinePath *>(vis);
visual->setPoint1Id(curveCutId);
visual->setLength(formula);
visual->setLength(qApp->FormulaToUser(formula));
visual->RefreshGeometry();
}
}

View File

@ -191,8 +191,8 @@ void VToolEndLine::FullUpdateFromFile()
{
VisToolEndLine *visual = qobject_cast<VisToolEndLine *>(vis);
visual->setPoint1Id(basePointId);
visual->setLength(formulaLength);
visual->setAngle(formulaAngle);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
}
@ -287,8 +287,8 @@ void VToolEndLine::ShowVisualization(bool show)
scene->addItem(visual);
visual->setPoint1Id(basePointId);
visual->setLength(formulaLength);
visual->setAngle(formulaAngle);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(qApp->FormulaToUser(formulaAngle));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
vis = visual;

View File

@ -216,7 +216,7 @@ void VToolNormal::FullUpdateFromFile()
VisToolNormal *visual = qobject_cast<VisToolNormal *>(vis);
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(angle);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
@ -332,7 +332,7 @@ void VToolNormal::ShowVisualization(bool show)
visual->setPoint1Id(basePointId);
visual->setPoint2Id(secondPointId);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setAngle(angle);
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();

View File

@ -236,7 +236,7 @@ void VToolPointOfContact::FullUpdateFromFile()
visual->setPoint1Id(firstPointId);
visual->setLineP2Id(secondPointId);
visual->setRadiusId(center);
visual->setRadius(arcRadius);
visual->setRadius(qApp->FormulaToUser(arcRadius));
visual->RefreshGeometry();
}
}
@ -344,7 +344,7 @@ void VToolPointOfContact::ShowVisualization(bool show)
visual->setPoint1Id(firstPointId);
visual->setLineP2Id(secondPointId);
visual->setRadiusId(center);
visual->setRadius(arcRadius);
visual->setRadius(qApp->FormulaToUser(arcRadius));
visual->RefreshGeometry();
vis = visual;
}

View File

@ -242,7 +242,7 @@ void VToolShoulderPoint::FullUpdateFromFile()
visual->setPoint1Id(pShoulder);
visual->setLineP1Id(basePointId);
visual->setLineP2Id(p2Line);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
}
@ -359,7 +359,7 @@ void VToolShoulderPoint::ShowVisualization(bool show)
visual->setPoint1Id(pShoulder);
visual->setLineP1Id(basePointId);
visual->setLineP2Id(p2Line);
visual->setLength(formulaLength);
visual->setLength(qApp->FormulaToUser(formulaLength));
visual->setLineStyle(VAbstractTool::LineStyle(typeLine));
visual->RefreshGeometry();
vis = visual;