42 #include "ui_formulaeditor.h"
43 #include "mainwindow.h"
56 #include <QMessageBox>
70 QString oldStringX =
"";
71 QString oldStringA =
"";
72 QString oldStringB =
"";
73 QString oldStringC =
"";
74 QString oldStringD =
"";
75 QString oldStringE =
"";
76 QString oldStringF =
"";
77 QString oldStringG =
"";
78 QString oldStringH =
"";
79 QString Formulaeditor::g_strF =
"";
80 QString errorText =
"";
81 QList<qreal> atomList;
92 Formulaeditor::Formulaeditor(QWidget *parent) : QWidget(parent), ui(new
Ui::
Formulaeditor)
97 move(settings.value(
"pos_formula_editor", QPoint(200, 200)).toPoint());
98 resize(settings.value(
"size_formula_editor", QSize(555, 418)).toSize());
101 ui->l_PaintAtom->addWidget(callAtomPaintWindow);
105 m_strStandardFunction.append(
"");
106 m_strStandardFunction.append(
"PI");
107 m_strStandardFunction.append(
"ABS");
108 m_strStandardFunction.append(
"SQRT");
109 m_strStandardFunction.append(
"SINH");
110 m_strStandardFunction.append(
"COSH");
111 m_strStandardFunction.append(
"TANH");
112 m_strStandardFunction.append(
"ARCTAN");
113 m_strStandardFunction.append(
"LN");
114 m_strStandardFunction.append(
"LOG");
115 m_strStandardFunction.append(
"EXP");
116 m_strStandardFunction.append(
"SIN");
117 m_strStandardFunction.append(
"COS");
118 m_strStandardFunction.append(
"TAN");
119 m_strStandardFunction.append(
"COT");
120 m_strStandardFunction.append(
"ARCSIN");
121 m_strStandardFunction.append(
"ARCCOS");
122 m_strStandardFunction.append(
"INT");
123 m_strStandardFunction.append(
"RAD");
124 m_strStandardFunction.append(
"DEG");
125 m_strStandardFunction.append(
"SIGN");
126 m_strStandardFunction.append(
"ARSINH");
127 m_strStandardFunction.append(
"ARCOSH");
128 m_strStandardFunction.append(
"ARTANH");
129 m_strStandardFunction.append(
"KGV");
130 m_strStandardFunction.append(
"GGT");
132 callAtomPaintWindow->update();
138 Formulaeditor::~Formulaeditor()
145 void Formulaeditor::closeEvent(QCloseEvent * event)
149 if(!this->isMaximized())
151 settings.setValue(
"pos_formula_editor", pos());
152 settings.setValue(
"size_formula_editor", size());
158 void AtomPaintWindow::paintEvent(QPaintEvent *event)
161 paint_signal(atomList, this->size());
166 void AtomPaintWindow::paint_signal(QList<qreal> valueList, QSize windowSize)
168 QPainter painter(
this);
169 painter.setRenderHint(QPainter::Antialiasing,
true);
170 painter.fillRect(0,0,windowSize.width(),windowSize.height(),QBrush(Qt::white));
173 if(valueList.length() > 0)
175 qint32 borderMarginHeigth = 15;
176 qint32 borderMarginWidth = 5;
181 qint32 drawFactor = 0;
182 qint32 startDrawFactor = 1;
183 qint32 decimalPlace = 0;
185 QList<qreal> internListValue;
187 internListValue.clear();
188 while(i < valueList.length())
190 internListValue.append(valueList.at(i));
195 painter.fillRect(0,0,windowSize.width(),windowSize.height(),QBrush(Qt::white));
199 while(i < valueList.length())
201 if(valueList.at(i) > maxPos)
202 maxPos = valueList.at(i);
204 if(valueList.at(i) < maxNeg )
205 maxNeg = valueList.at(i);
209 if(maxPos > fabs(maxNeg)) absMin = maxNeg;
210 else absMin = maxPos;
218 absMin = absMin * 10;
221 if(fabs(absMin) >= 1)
break;
226 while(drawFactor > 0)
229 while(i < valueList.length())
231 qreal replaceValue = internListValue.at(i) * 10;
232 internListValue.replace(i, replaceValue);
235 startDrawFactor = startDrawFactor * 10;
237 maxPos = maxPos * 10;
238 maxNeg = maxNeg * 10;
244 if(maxNeg <= 0) maxmax = maxPos - maxNeg;
245 else maxmax = maxPos + maxNeg;
249 qreal scaleYText = (qreal)maxmax / (qreal)10;
250 qint32 negScale = floor((maxNeg * 10 / maxmax)+0.5);
254 qint32 negScale2 = negScale;
255 qint32 maxStrLenght = 0;
260 qreal scaledYText = negScale2 * scaleYText / (qreal)startDrawFactor;
261 string2 = QString::number(scaledYText,
'f', decimalPlace + 1);
263 if(string2.length()> maxStrLenght) maxStrLenght = string2.length();
268 maxStrLenght = 6 + maxStrLenght * 6;
273 qreal inStartValue = startValue;
274 qreal inEndValue = endValue;
277 qreal scaleX = ((qreal)(windowSize.width() - maxStrLenght - 6 * borderMarginWidth))/ ((qreal)valueList.length() - 1);
278 qreal scaleY = (qreal)(windowSize.height() - borderMarginHeigth) / (qreal)maxmax;
281 qreal scaleXAchse = (qreal)(windowSize.width() - maxStrLenght - 6 * borderMarginWidth) / (qreal)15;
282 qreal scaleYAchse = (qreal)(windowSize.height() - borderMarginHeigth) / (qreal)10;
285 qint32 xAxisTextPos = 8;
286 if(maxNeg == 0) xAxisTextPos = -10;
290 qreal internStepWidth = (endValue - startValue) / 15;
291 qint32 decimalPlaceX = 0;
292 if(internStepWidth > 0.000999999999999)
294 if(internStepWidth > 0.009999999)
296 if(internStepWidth > 0.0999999999)
298 if(internStepWidth > 0.999999)
304 qreal scaledYText = negScale * scaleYText / (qreal)startDrawFactor;
306 string = QString::number(scaledYText,
'f', decimalPlace + 1);
312 while(h < valueList.length())
314 polygon.append(QPointF(h * scaleX + maxStrLenght + 10, -((internListValue.at(h) * scaleY + ((i - 1) * scaleYAchse)-(windowSize.height()) + borderMarginHeigth / 2))));
320 inStartValue = startValue;
321 while(inStartValue <= inEndValue)
324 painter.drawText(j * scaleXAchse + maxStrLenght + 3, -(((i - 1) * scaleYAchse)-(windowSize.height())) + xAxisTextPos, str.append(QString::number(inStartValue,
'f', decimalPlaceX)));
325 painter.drawLine(j * scaleXAchse + maxStrLenght + 10, -(((i - 1) * scaleYAchse)-(windowSize.height() - borderMarginHeigth / 2 - 2)), j * scaleXAchse + maxStrLenght + 10 , -(((i - 1) * scaleYAchse)-(windowSize.height() - borderMarginHeigth / 2 + 2)));
327 inStartValue += internStepWidth;
329 painter.drawLine(maxStrLenght, -(((i - 1) * scaleYAchse)-(windowSize.height()) + borderMarginHeigth / 2), windowSize.width()-5, -(((i - 1) * scaleYAchse)-(windowSize.height()) + borderMarginHeigth / 2));
332 painter.drawText(3, -((i - 1) * scaleYAchse - windowSize.height()) - borderMarginHeigth/2 + 4,
string);
333 painter.drawLine(maxStrLenght - 2, -(((i - 1) * scaleYAchse)-(windowSize.height()) + borderMarginHeigth / 2), maxStrLenght + 2, -(((i - 1) * scaleYAchse)-(windowSize.height()) + borderMarginHeigth / 2));
338 painter.drawLine(maxStrLenght, 2, maxStrLenght, windowSize.height() - 2);
340 painter.drawPolyline(polygon);
347 void Formulaeditor::on_tb_Formula_textChanged(
const QString &arg1)
349 ui->btt_Save->setEnabled(
false);
350 QList<QChar> foundChar;
352 for(qint32 i = 0; i < arg1.length(); i++)
354 bool beforeFound =
false;
355 bool nextfound =
false;
356 QChar upperChar = arg1.at(i).toUpper();
357 if((upperChar >=
'A' && upperChar <=
'H') || upperChar ==
'X')
361 QChar beforeUpperChar = arg1.at(i - 1).toUpper();
362 if(beforeUpperChar <
'A' || (beforeUpperChar >
'Z' && beforeUpperChar < 126)) beforeFound =
true;
364 else beforeFound =
true;
366 if(i < arg1.length() - 1)
368 QChar nextUpperChar = arg1.at(i+1).toUpper();
369 if(nextUpperChar <
'A' || (nextUpperChar >
'Z' && nextUpperChar < 126)) nextfound =
true;
371 else nextfound =
true;
374 if(beforeFound && nextfound)
376 if(upperChar ==
'A') foundChar.append(upperChar);
377 else if(upperChar ==
'B') foundChar.append(upperChar);
378 else if(upperChar ==
'C') foundChar.append(upperChar);
379 else if(upperChar ==
'D') foundChar.append(upperChar);
380 else if(upperChar ==
'E') foundChar.append(upperChar);
381 else if(upperChar ==
'F') foundChar.append(upperChar);
382 else if(upperChar ==
'G') foundChar.append(upperChar);
383 else if(upperChar ==
'H') foundChar.append(upperChar);
384 else if(upperChar ==
'X') foundChar.append(upperChar);
389 ui->lb_A->setEnabled(
false);
390 ui->tb_A->setEnabled(
false);
391 ui->lb_B->setEnabled(
false);
392 ui->tb_B->setEnabled(
false);
393 ui->lb_C->setEnabled(
false);
394 ui->tb_C->setEnabled(
false);
395 ui->lb_D->setEnabled(
false);
396 ui->tb_D->setEnabled(
false);
397 ui->lb_E->setEnabled(
false);
398 ui->tb_E->setEnabled(
false);
399 ui->lb_F->setEnabled(
false);
400 ui->tb_F->setEnabled(
false);
401 ui->lb_G->setEnabled(
false);
402 ui->tb_G->setEnabled(
false);
403 ui->lb_H->setEnabled(
false);
404 ui->tb_H->setEnabled(
false);
405 ui->lb_StartValue->setEnabled(
false);
406 ui->lb_StepWidth->setEnabled(
false);
407 ui->lb_EndValue->setEnabled(
false);
408 ui->dsb_StartValue->setEnabled(
false);
409 ui->dsb_StepWidth->setEnabled(
false);
410 ui->dsb_EndValue->setEnabled(
false);
412 for(qint32 j = 0; j < foundChar.length(); j++)
414 if(foundChar.at(j) ==
'A')
416 ui->lb_A->setEnabled(
true);
417 ui->tb_A->setEnabled(
true);
419 else if(foundChar.at(j) ==
'B')
421 ui->lb_B->setEnabled(
true);
422 ui->tb_B->setEnabled(
true);
424 else if(foundChar.at(j) ==
'C')
426 ui->lb_C->setEnabled(
true);
427 ui->tb_C->setEnabled(
true);
429 else if(foundChar.at(j) ==
'D')
431 ui->lb_D->setEnabled(
true);
432 ui->tb_D->setEnabled(
true);
434 else if(foundChar.at(j) ==
'E')
436 ui->lb_E->setEnabled(
true);
437 ui->tb_E->setEnabled(
true);
439 else if(foundChar.at(j) ==
'F')
441 ui->lb_F->setEnabled(
true);
442 ui->tb_F->setEnabled(
true);
444 else if(foundChar.at(j) ==
'G')
446 ui->lb_G->setEnabled(
true);
447 ui->tb_G->setEnabled(
true);
449 else if(foundChar.at(j) ==
'H')
451 ui->lb_H->setEnabled(
true);
452 ui->tb_H->setEnabled(
true);
454 else if(foundChar.at(j) ==
'X')
456 ui->lb_StartValue->setEnabled(
true);
457 ui->lb_StepWidth->setEnabled(
true);
458 ui->lb_EndValue->setEnabled(
true);
459 ui->dsb_StartValue->setEnabled(
true);
460 ui->dsb_StepWidth->setEnabled(
true);
461 ui->dsb_EndValue->setEnabled(
true);
468 void Formulaeditor::on_tb_A_textChanged(
const QString &arg1)
472 if(ok) oldStringA = arg1;
473 else if(arg1 !=
"") ui->tb_A->setText(oldStringA);
476 void Formulaeditor::on_tb_B_textChanged(
const QString &arg1)
480 if(ok) oldStringB = arg1;
481 else if(arg1 !=
"") ui->tb_B->setText(oldStringB);
484 void Formulaeditor::on_tb_C_textChanged(
const QString &arg1)
488 if(ok) oldStringC = arg1;
489 else if(arg1 !=
"") ui->tb_C->setText(oldStringC);
492 void Formulaeditor::on_tb_D_textChanged(
const QString &arg1)
496 if(ok) oldStringD = arg1;
497 else if(arg1 !=
"") ui->tb_D->setText(oldStringD);
500 void Formulaeditor::on_tb_E_textChanged(
const QString &arg1)
504 if(ok) oldStringE = arg1;
505 else if(arg1 !=
"") ui->tb_E->setText(oldStringE);
508 void Formulaeditor::on_tb_F_textChanged(
const QString &arg1)
512 if(ok) oldStringF = arg1;
513 else if(arg1 !=
"") ui->tb_F->setText(oldStringF);
516 void Formulaeditor::on_tb_G_textChanged(
const QString &arg1)
520 if(ok) oldStringG = arg1;
521 else if(arg1 !=
"") ui->tb_G->setText(oldStringG);
524 void Formulaeditor::on_tb_H_textChanged(
const QString &arg1)
528 if(ok) oldStringH = arg1;
529 else if(arg1 !=
"") ui->tb_H->setText(oldStringH);
532 void Formulaeditor::on_dsb_StartValue_editingFinished()
534 ui->dsb_EndValue->setMinimum(ui->dsb_StartValue->value() + ui->dsb_StepWidth->value());
537 void Formulaeditor::on_dsb_StepWidth_editingFinished()
539 ui->dsb_EndValue->setMinimum(ui->dsb_StartValue->value() + ui->dsb_StepWidth->value());
544 void Formulaeditor::on_btt_Test_clicked()
557 double retValue = FormulaParser.
calculation(ui->tb_Formula->text(), ui->dsb_StartValue->value());
559 if(errorText.isEmpty())
561 if(ui->lb_StartValue->isEnabled())
562 ui->btt_Save->setEnabled(
true);
563 if(retValue < 0.0000000000001 && retValue > -0.0000000000001)
565 ui->lb_Result->setText(QString(
"result start value = %1").arg(retValue));
569 ui->lb_Result->setText(errorText);
573 QList<qreal> resultsList;
575 startValue = ui->dsb_StartValue->value();
576 qreal internStartValue = startValue;
577 endValue = ui->dsb_EndValue->value();
578 stepWidth = ui->dsb_StepWidth->value();
581 QMessageBox::warning(
this, tr(
"error"), tr(
"Increment can not be null."));
585 if(ui->dsb_StartValue->isEnabled() && ui->dsb_EndValue->isEnabled() && ui->dsb_StepWidth->isEnabled())
587 while(internStartValue <= endValue)
589 resultsList.append(FormulaParser.
calculation(ui->tb_Formula->text(), internStartValue ));
590 internStartValue += stepWidth;
595 qreal result = FormulaParser.
calculation(ui->tb_Formula->text(), internStartValue );
596 ui->lb_Result->setText(QString(
"result = %1").arg(result));
599 atomList = resultsList;
600 atomLength = resultsList.length();
602 callAtomPaintWindow->update();
609 void Formulaeditor::on_btt_Save_clicked()
611 QFile saveFile(QDir::homePath() +
"/" +
"Matching-Pursuit-Toolbox/user.fml");
612 if(!saveFile.exists())
614 if (saveFile.open(QIODevice::ReadWrite | QIODevice::Text))
618 if (saveFile.open(QIODevice::WriteOnly| QIODevice::Append))
620 QTextStream stream( &saveFile);
621 stream << ui->tb_Formula->text() <<
"\n";
625 ui->tb_Formula->clear();
626 ui->tb_A->setText(
"0");
627 ui->tb_B->setText(
"0");
628 ui->tb_C->setText(
"0");
629 ui->tb_D->setText(
"0");
630 ui->tb_E->setText(
"0");
631 ui->tb_F->setText(
"0");
632 ui->tb_G->setText(
"0");
633 ui->tb_H->setText(
"0");
634 ui->lb_Result->setText(
"result start value = ---");
638 emit formula_saved();
646 qreal Formulaeditor::sign_factor(qint32& nPosition, QString& strCharacter)
648 if (strCharacter ==
"-")
650 char_n(nPosition, strCharacter);
651 return (-1.0) * factor(nPosition, strCharacter);
653 else return factor(nPosition, strCharacter);
662 if (strFormula.length() < 1)
return;
665 strFormula.replace(
"PI",
"3.14159265358979323846");
666 strFormula.replace(
"pi",
"3.14159265358979323846");
667 strFormula.replace(
"Pi",
"3.14159265358979323846");
668 strFormula.replace(
"pI",
"3.14159265358979323846");
669 strFormula.replace(
" ",
"");
670 strFormula.replace(
",",
".");
671 strFormula.replace(
"[",
"(");
672 strFormula.replace(
"]",
")");
673 strFormula.replace(
"{",
"(");
674 strFormula.replace(
"}",
")");
676 strFormula.replace(
"*(1)",
"");
677 strFormula.replace(
"(1)*",
"");
679 strFormula.replace(
"*(x)",
"*x");
680 strFormula.replace(
"((x)*",
"(x*");
681 strFormula.replace(
"+(x)*",
"+x*");
682 strFormula.replace(
"-(x)*",
"-x*");
683 strFormula.replace(
"*(x)*",
"*x*");
684 strFormula.replace(
"(sin(x))",
"sin(x)");
685 strFormula.replace(
"(cos(x))",
"cos(x)");
686 strFormula.replace(
"(cot(x))",
"cot(x)");
687 strFormula.replace(
"(tan(x))",
"tan(x)");
688 strFormula.replace(
"(exp(x))",
"exp(x)");
689 strFormula.replace(
"(log(x))",
"log(x)");
690 strFormula.replace(
"(ln(x))",
"ln(x)");
693 for (qint32 i = 0; i < strFormula.length(); i++)
695 if(QString::compare(strFormula.at(i),
"(") == 0)
700 if(QString::compare(strFormula.at(i),
")") == 0)
706 if (level == 0 && i < strFormula.length() - 1)
715 while (strFormula.at(0) ==
'(' && strFormula.at(strFormula.length() - 1) ==
')')
717 strFormula = strFormula.mid(1, strFormula.length() - 2);
722 while (strFormula.at(0) ==
'+'
723 || strFormula.at(0) ==
' ')
725 strFormula = strFormula.mid(1);
727 strFormula.trimmed();
733 qint32 l = strFormula.length();
735 for (qint32 i = 0; i < l; i++)
737 if (strFormula.at(i) ==
'(')
744 if (i == 0 || (i > 0 && (strFormula.at(i-1) ==
'(' || strFormula.at(min) ==
'(')))
750 else if (strFormula.at(i) ==
')')
753 if (level > 0 && strFormula.at(i+1) ==
')')
756 QString left = strFormula.left(i);
757 QString mid = strFormula.mid(i+1);
758 strFormula = left +
"|" + mid;
761 left = strFormula.left(Pos[level] + 1);
762 mid = strFormula.mid(Pos[level+1] + 1);
763 strFormula = left +
"|" + mid;
769 strFormula.replace(
"|",
"");
777 QString strCharacter;
780 if (strFormula.length() < 1)
return 0.0;
786 m_strFunction = strFormula;
787 m_dFktValue = xValue;
788 if (m_dFktValue == 0)
789 m_dFktValue = FLT_MIN;
791 char_n(nPosition, strCharacter);
793 result = expression(nPosition, strCharacter);
800 double Formulaeditor::expression(
int& nPosition, QString& strCharacter)
803 double erg = simple_expression(nPosition, strCharacter);
804 while (strCharacter ==
"+" || strCharacter ==
"-")
806 strOperator = strCharacter;
807 char_n(nPosition, strCharacter);
808 if (strOperator ==
"+")
809 erg += simple_expression(nPosition, strCharacter);
810 else if (strOperator ==
"-")
811 erg -= simple_expression(nPosition, strCharacter);
819 double Formulaeditor::simple_expression(
int& nPosition, QString& strCharacter)
823 s = term(nPosition, strCharacter);
824 while (strCharacter ==
"*" || strCharacter ==
"/")
826 strOperator = strCharacter;
827 char_n(nPosition, strCharacter);
828 if (strOperator ==
"*")
829 s = s * term(nPosition, strCharacter);
830 else if (strOperator ==
"/")
832 dum = term(nPosition, strCharacter);
833 if (dum != 0) s = s / dum;
834 else errorText = QString(
"Divide by 0 is not possible.");
842 double Formulaeditor::term(
int& nPosition, QString& strCharacter)
845 t = sign_factor(nPosition, strCharacter);
846 while (strCharacter ==
"^")
848 char_n(nPosition, strCharacter);
849 vz = sign_factor(nPosition, strCharacter);
851 if ((t <= 0 && fabs(vz) <= 1) || (t <= 0 && vz != qint32(vz))) errorText = QString(
"Extraction of square root of negative numbers is not possible using dense matrix algebra.");
859 double Formulaeditor::char_n(
int& nPosition, QString& strCharacter)
864 if (nPosition <= m_strFunction.length())
865 strCharacter = m_strFunction.mid(nPosition - 1, 1);
867 strCharacter = str_char(
"?");
869 while (strCharacter ==
" ");
878 m_strFormula = Formula;
890 double Formulaeditor::factor(qint32& nPosition, QString& strCharacter)
893 qint32 wI = 0, wL = 0, wBeginn = 0, wError = 0;
895 if (strCharacter == str_char(0))
return 0.0;
897 if (((strCharacter >=
"0") && (strCharacter <=
"9")) || (strCharacter ==
"."))
903 char_n(nPosition, strCharacter);
905 while ((((strCharacter >=
"0") && (strCharacter <=
"9")) || (strCharacter ==
".")));
907 if (strCharacter ==
".")
911 char_n(nPosition, strCharacter);
913 while (!(((qint8)strCharacter.at(0).digitValue() >= 0) && ((qint8)strCharacter.at(0).digitValue() <= 9)) || (strCharacter.at(0) ==
'.'));
916 QString g_strF = m_strFunction.mid(wBeginn - 1, nPosition - wBeginn);
917 f = g_strF.toFloat();
921 QString strCharacterUpper = strCharacter.toUpper();
922 if (strCharacter ==
"(")
924 char_n(nPosition, strCharacter);
925 f = expression(nPosition, strCharacter);
926 if (strCharacter ==
")")
927 char_n(nPosition, strCharacter);
929 else if (strCharacterUpper ==
"X")
931 char_n(nPosition, strCharacter);
936 bool gefunden =
false;
937 qint32 AnzStdFunctions = m_strStandardFunction.length() - 1;
938 for (wI = 1; wI <= AnzStdFunctions; wI++)
940 wL = m_strStandardFunction.at(wI).length();
941 QString strFunktionUpper = m_strFunction.mid(nPosition - 1, wL);
942 strFunktionUpper = strFunktionUpper.toUpper();
943 QString strDummy(m_strStandardFunction.at(wI));
944 strDummy = strDummy.toUpper();
945 if (strFunktionUpper == strDummy)
948 nPosition = nPosition + wL - 1;
949 char_n(nPosition, strCharacter);
951 f = factor(nPosition, strCharacter);
953 if (strFunktionUpper ==
"ABS")
955 else if (strFunktionUpper ==
"SQRT")
960 else if (strFunktionUpper ==
"SINH")
962 else if (strFunktionUpper ==
"COSH")
964 else if (strFunktionUpper ==
"TANH")
966 else if (strFunktionUpper ==
"ARCTAN")
968 else if (strFunktionUpper ==
"LN")
975 else if (strFunktionUpper ==
"LOG")
982 else if (strFunktionUpper ==
"EXP")
989 else if (strFunktionUpper ==
"SIN")
991 else if (strFunktionUpper ==
"COS")
993 else if (strFunktionUpper ==
"COT")
995 else if (strFunktionUpper ==
"TAN")
1002 else if (strFunktionUpper ==
"ARCSIN")
1009 else if (strFunktionUpper ==
"ARCCOS")
1016 else if (strFunktionUpper ==
"SIGN")
1018 else if (strFunktionUpper ==
"RAD")
1020 else if (strFunktionUpper ==
"DEG")
1022 else if (strFunktionUpper ==
"ARSINH")
1024 else if (strFunktionUpper ==
"ARCOSH")
1031 else if (strFunktionUpper ==
"ARTANH")
1043 char_n(nPosition, strCharacter);
1044 if (strCharacterUpper ==
"A")
1045 f = m_dFunctionConstant[0];
1046 else if (strCharacterUpper ==
"B")
1047 f = m_dFunctionConstant[1];
1048 else if (strCharacterUpper ==
"C")
1049 f = m_dFunctionConstant[2];
1050 else if (strCharacterUpper ==
"D")
1051 f = m_dFunctionConstant[3];
1052 else if (strCharacterUpper ==
"E")
1053 f = m_dFunctionConstant[4];
1054 else if (strCharacterUpper ==
"F")
1055 f = m_dFunctionConstant[5];
1056 else if (strCharacterUpper ==
"G")
1057 f = m_dFunctionConstant[6];
1058 else if (strCharacterUpper ==
"H")
1059 f = m_dFunctionConstant[7];
1064 if (wError == -1) errorText = QString(
"General Parser Error blocked!");
1074 if (index >= 0 && index < 9) m_dFunctionConstant[index] = val;
1075 else errorText = QString(
"Error in SetFunctConst()");
1078 QString Formulaeditor::str_char(QString DecimalZahl)
1080 if(DecimalZahl ==
"?")
return QString(
"?");
1081 else return DecimalZahl;
1084 double Formulaeditor::SINQ(
double Winkel_grad)
1086 double Winkel_rad = PI * Winkel_grad / 180.0;
1087 return sin(Winkel_rad);
1090 double Formulaeditor::COSQ(
double Winkel_grad)
1093 double Winkel_rad = PI * Winkel_grad / 180.0;
1094 return cos(Winkel_rad);
1097 double Formulaeditor::cot(
double x)
1099 return cos(x)/sin(x);
1102 double Formulaeditor::DEG(
double x )
1105 return x * 180.0 / PI;
1108 double Formulaeditor::RAD(
double x )
1111 return x * PI / 180.0;
1114 QString Formulaeditor::get_next_token(QString &strSrc,
const QString strDelim)
1117 int idx = strSrc.indexOf(strDelim);
1120 token = strSrc.left(idx);
1121 strSrc = strSrc.right(strSrc.length() - (idx + 1) );
1131 long double Formulaeditor::signl(
long double x)
1133 if (x > 0.0L)
return 1.0L;
1134 if (x < 0.0L)
return -1.0L;
1138 double Formulaeditor::ArSinh(
double x)
1141 return -log(-x + sqrt(sqr(-x) + 1));
1142 return log(x + sqrt(sqr(x) + 1));
1145 double Formulaeditor::ArCosh(
double x)
1147 return log(x + sqrt(sqr(x) - 1));
1150 double Formulaeditor::ArTanh(
double x)
1152 return 0.5*logl((1 + x)/ (1 - x));
1155 double Formulaeditor::ArCoth(
double x)
1157 return 0.5*log((x + 1)/ (x - 1));
1160 double Formulaeditor::sqr(
double x)