double ScaleDraw::transformValue(double value) const
{
    if (!formula_string.isEmpty())
    {
        double lbl=0.0;
        try
        {
            MyParser parser;
            if (formula_string.contains("x"))
                parser.DefineVar("x", &value);
            else if (formula_string.contains("y"))
                parser.DefineVar("y", &value);

            parser.SetExpr(formula_string.ascii());
            lbl=parser.Eval();
        }
        catch(mu::ParserError &)
        {
            return 0;
        }

        return lbl;
    }
    else
        return value;
}
void DoubleSpinBox::interpretText()
{
	bool ok = false;
	QString s = text();
	double value = locale().toDouble(s, &ok);
	if (ok && value == d_value)
		return;

	if (!ok){
		MyParser parser;
		parser.setLocale(QLocale());
		parser.addGSLConstants();
		try {
			parser.SetExpr(s.toAscii().constData());
			value = parser.Eval();
		} catch (mu::ParserError &e){
			lineEdit()->setText(textFromValue(d_value));
			return;
		}
	}

	if (setValue(value))
        emit valueChanged(d_value);
    else
        lineEdit()->setText(textFromValue(d_value));
}
Integration::Integration(const QString& formula, const QString& var, ApplicationWindow *parent, Graph *g, double start, double end)
: Filter(parent, g),
d_formula(formula),
d_variable(var)
{
	d_init_err = false;
	d_n = 0;
	d_from = start;
	d_to = end;
	if (d_to == d_from)
		d_init_err = true;

	MyParser parser;
	double x = 0.0;
	parser.DefineVar(d_variable.ascii(), &x);
	parser.SetExpr(d_formula.ascii());
	try {
		parser.Eval();
	} catch(mu::ParserError &e) {
		QMessageBox::critical(parent, tr("QtiPlot - Input error"), QString::fromStdString(e.GetMsg()));
		d_init_err = true;
	}

	setObjectName(tr("Integration"));
	d_integrand = AnalyticalFunction;
	d_method = 1;
    d_max_iterations = 20;
    d_sort_data = false;
}
/** Checks to see if this axis has valid parameters
*
*/
bool AxisDetails::valid()
{
  if (m_cmbAxisType->currentIndex() == ScaleDraw::Numeric)
  {
    if (m_chkShowFormula->isChecked())
    {
      QString formula = m_txtFormula->text().lower();
      try
      {
        double value = 1.0;
        MyParser parser;
        if (formula.contains("x"))
        {
          parser.DefineVar("x", &value);
        }
        else if (formula.contains("y"))
        {
          parser.DefineVar("y", &value);
        }
        parser.SetExpr(formula.ascii());
        parser.Eval();
      }
      catch(mu::ParserError &e)
      {
        QMessageBox::critical(this, tr("MantidPlot - Formula input error"), QString::fromStdString(e.GetMsg())+"\n"+tr("Valid variables are 'x' for Top/Bottom axes and 'y' for Left/Right axes!"));
        return false;
      }
    }
  }
  Table *w = m_app->table(m_cmbColName->currentText());
  return m_initialised && m_graph && !((m_cmbAxisType->currentIndex() == ScaleDraw::Text || m_cmbAxisType->currentIndex() == ScaleDraw::ColHeader) && !w);
}
示例#5
0
文件: main.cpp 项目: 01iv3r/OpenPilot
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyParser b;
    b.start();

//    return a.exec();
}
void NonLinearFit::calculateFitCurveData(double *X, double *Y)
{
	MyParser parser;
	for (int i=0; i<d_p; i++)
		parser.DefineVar(d_param_names[i].ascii(), &d_results[i]);

	QMapIterator<QString, double> i(d_constants);
 	while (i.hasNext()) {
     	i.next();
		parser.DefineConst(i.key().ascii(), i.value());
 	}

	double x;
	parser.DefineVar("x", &x);
	parser.SetExpr(d_formula.ascii());

	if (d_gen_function){
		double X0 = d_x[0];
		double step = (d_x[d_n - 1] - X0)/(d_points - 1);
		for (int i=0; i<d_points; i++){
		    x = X0 + i*step;
			X[i] = x;
			Y[i] = parser.EvalRemoveSingularity(&x, false);
		}
	} else {
		for (int i=0; i<d_points; i++) {
		    x = d_x[i];
			X[i] = x;
			Y[i] = parser.EvalRemoveSingularity(&x, false);
		}
	}
}
示例#7
0
double UserFunction2D::operator()(double x, double y) {
  if (d_formula.isEmpty())
    return 0.0;

  MyParser parser;
  double result = 0.0;
  try {
    parser.DefineVar("x", &x);
    parser.DefineVar("y", &y);

    parser.SetExpr((const std::string)d_formula.toAscii().constData());
    result = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(nullptr, "MantidPlot - Input function error",
                          QString::fromStdString(e.GetMsg()));
  }
  return result;
}
double ScaleDraw::transformValue(double value) const
{
	if (!d_formula.isEmpty()){
		double lbl=0.0;
		try{
			MyParser parser;
			if (d_formula.contains("x", Qt::CaseInsensitive))
				parser.DefineVar("x", &value);
			else if (d_formula.contains("y", Qt::CaseInsensitive))
				parser.DefineVar("y", &value);

			parser.SetExpr(d_formula.lower().ascii());
			lbl = parser.Eval();
        }
        catch(mu::ParserError &){
			return 0;
        }
		return lbl;
    } else
        return value;
}
示例#9
0
 void Parse(ParserStatus & currentStatus, TCHAR & element)
 {
     if (currentStatus < ParserStatus::Error)
     {
         const ParserStatus myStatus = parser.Parse(element);
         if (myStatus > currentStatus)
         {
             currentStatus = myStatus;
         }
     }
     next.Parse(currentStatus, element);
 }
double Integration::trapezf(int n)
{
    MyParser parser;
	double x = d_from;
	parser.DefineVar(d_variable.ascii(), &x);
	parser.SetExpr(d_formula.ascii());

    static double s;
    if (n == 1){
		x = d_from;
		double aux = parser.Eval();
		x = d_to;
        return (s = 0.5*(d_to - d_from)*(aux + parser.Eval()));
    } else {
        int it = 1;
        for(int j=1; j < n-1; j++)
            it<<=1;

        double tnm = it;
        double del = (d_to - d_from)/tnm;
        x = d_from + 0.5*del;
        double sum = 0.0;
        for(int j=1; j <= it; j++, x += del)
            sum += parser.Eval();

        s = 0.5*(s + (d_to - d_from)*sum/tnm);
        return s;
    }
}
void NonLinearFit::removeDataSingularities()
{
	MyParser parser;
	for (int i = 0; i < d_p; i++){
		double param = gsl_vector_get(d_param_init, i);
		parser.DefineVar(d_param_names[i].ascii(), &param);
	}

	QMapIterator<QString, double> it(d_constants);
 	while (it.hasNext()) {
     	it.next();
		parser.DefineConst(it.key().ascii(), it.value());
 	}

	double xvar;
	parser.DefineVar("x", &xvar);
	parser.SetExpr(d_formula.ascii());

    for (int i = 0; i < d_n; i++){
    	xvar = d_x[i];
    	try {
			parser.EvalRemoveSingularity(&xvar);
    	} catch(MyParser::Pole){
			QApplication::restoreOverrideCursor();
			QMessageBox::critical((ApplicationWindow *)parent(), QObject::tr("QtiPlot"),
			QObject::tr("Ignored data point at x = %1.").arg(xvar));

    		removePole(i);
    	}
    }
}
bool NonLinearFit::setFormula(const QString& s, bool guess)
{
	if (s.isEmpty()){
		QMessageBox::critical((ApplicationWindow *)parent(),  tr("QtiPlot - Input function error"),
				tr("Please enter a valid non-empty expression! Operation aborted!"));
		d_init_err = true;
		return false;
	}

	if (d_formula == s)
		return true;

	if (guess)
		setParametersList(guessParameters(s));
	if (!d_p){
		QMessageBox::critical((ApplicationWindow *)parent(), tr("QtiPlot - Fit Error"),
				tr("There are no parameters specified for this fit operation. Please define a list of parameters first!"));
		d_init_err = true;
		return false;
	}

	try {
		double *param = new double[d_p];
		MyParser parser;
		double xvar;
		parser.DefineVar("x", &xvar);
		for (int k = 0; k < (int)d_p; k++){
			param[k] = gsl_vector_get(d_param_init, k);
			parser.DefineVar(d_param_names[k].ascii(), &param[k]);
		}

		QMapIterator<QString, double> i(d_constants);
 		while (i.hasNext()) {
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

		parser.SetExpr(s.ascii());
		parser.Eval() ;
		delete[] param;
	} catch(mu::ParserError &e){
		QMessageBox::critical((ApplicationWindow *)parent(),  tr("QtiPlot - Input function error"), QString::fromStdString(e.GetMsg()));
		d_init_err = true;
		return false;
	}

	d_init_err = false;
	d_formula = s;
	return true;
}
double NonLinearFit::eval(double *par, double x)
{
	MyParser parser;
	for (int i=0; i<d_p; i++)
		parser.DefineVar(d_param_names[i].ascii(), &par[i]);

	QMapIterator<QString, double> i(d_constants);
 	while (i.hasNext()) {
     	i.next();
		parser.DefineConst(i.key().ascii(), i.value());
 	}

	parser.DefineVar("x", &x);
	parser.SetExpr(d_formula.ascii());
    return parser.EvalRemoveSingularity(&x, false);
}
示例#14
0
double user_d(const gsl_vector * x, void *params) {
    int n = ((struct FitData *)params)->n;
    int p = ((struct FitData *)params)->p;
    double *X = ((struct FitData *)params)->X;
    double *Y = ((struct FitData *)params)->Y;
    double *sigma = ((struct FitData *)params)->sigma;

	NonLinearFit *fitter = (NonLinearFit *)((struct FitData *) params)->fitter;
	const char *function = fitter->formula().ascii();
	QStringList parNames = fitter->parameterNames();

    double val=0;
    MyParser parser;
    try {
        double *parameters = new double[p];
        double xvar;
        parser.DefineVar("x", &xvar);
        for (int i=0; i < p; i++) {
            parameters[i]=gsl_vector_get(x,i);
            parser.DefineVar(parNames[i].ascii(), &parameters[i]);
        }

		QMapIterator<QString, double> i(fitter->constants());
 		while (i.hasNext()){
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

        parser.SetExpr(function);
        for (int j = 0; j < n; j++) {
            xvar = X[j];
			double s = 1.0/sqrt(sigma[j]);
            try {
				double t = (parser.EvalRemoveSingularity(&xvar) - Y[j])/s;
				val += t*t;
			} catch (MyParser::Pole) {
				return GSL_POSINF; //weird, I know. blame gsl.
			}
        }
        delete[] parameters;
    } catch (mu::ParserError &e) {
        QMessageBox::critical(0,"QtiPlot - Input function error",QString::fromStdString(e.GetMsg()));
        return GSL_EINVAL;
    }
    return val;
}
示例#15
0
int user_df(const gsl_vector *x, void *params, gsl_matrix *J) {
    int n = ((struct FitData *)params)->n;
    int p = ((struct FitData *)params)->p;
    double *X = ((struct FitData *)params)->X;
    double *sigma = ((struct FitData *)params)->sigma;

	NonLinearFit *fitter = (NonLinearFit *)((struct FitData *) params)->fitter;
	const char *function = fitter->formula().ascii();
	QStringList parNames = fitter->parameterNames();

	try {
        double *param = new double[p];
        MyParser parser;
        double xvar;
        parser.DefineVar("x", &xvar);
        for (int k=0; k<p; k++) {
            param[k] = gsl_vector_get(x,k);
            parser.DefineVar(parNames[k].ascii(), &param[k]);
        }

		QMapIterator<QString, double> i(fitter->constants());
 		while (i.hasNext()){
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

        parser.SetExpr(function);
        for (int i = 0; i < n; i++) {
            xvar = X[i];
			double s = 1.0/sqrt(sigma[i]);
            for (int j = 0; j < p; j++)
	        try {
				gsl_matrix_set (J, i, j, 1.0/s*parser.DiffRemoveSingularity(&xvar, &param[j], param[j]));
			} catch (MyParser::Pole) {
				return GSL_ESING;
			}
        }
        delete[] param;
    } catch (mu::ParserError &) {
        return GSL_EINVAL;
    }
    return GSL_SUCCESS;
}
示例#16
0
void FunctionDialog::acceptPolar() {
  QString from = boxPolarFrom->text().toLower();
  QString to = boxPolarTo->text().toLower();
  QString points = boxPolarPoints->text().toLower();

  double start, end;
  try {
    MyParser parser;
    parser.SetExpr(from.toAscii().constData());
    start = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Start limit error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarFrom->setFocus();
    return;
  }

  try {
    MyParser parser;
    parser.SetExpr(to.toAscii().constData());
    end = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - End limit error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarTo->setFocus();
    return;
  }

  if (start >= end) {
    QMessageBox::critical(
        0, tr("MantidPlot - Input error"),
        tr("Please enter parameter limits that satisfy: from < end!"));
    boxPolarTo->setFocus();
    return;
  }

  QString rformula = boxPolarRadius->currentText();
  QString tformula = boxPolarTheta->currentText();
  bool error = false;

  try {
    MyParser parser;
    double parameter = start;
    ;
    parser.DefineVar((boxPolarParameter->text()).toAscii().constData(),
                     &parameter);
    parser.SetExpr(rformula.toAscii().constData());
    parser.Eval();
    // cppcheck-suppress unreadVariable
    parameter = end;
    parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Input function error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarRadius->setFocus();
    error = true;
  }
  try {
    MyParser parser;
    double parameter = start;
    ;
    parser.DefineVar((boxPolarParameter->text()).toAscii().constData(),
                     &parameter);
    parser.SetExpr(tformula.toAscii().constData());
    parser.Eval();
    // cppcheck-suppress unreadVariable
    parameter = end;
    parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Input function error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarTheta->setFocus();
    error = true;
  }
  // Collecting all the information
  int type = boxType->currentIndex();
  QStringList formulas;
  formulas += rformula;
  formulas += tformula;
  if (!error) {
    d_app->updateFunctionLists(type, formulas);

    if (!graph)
      d_app->newFunctionPlot(formulas, start, end, boxPolarPoints->value(),
                             boxPolarParameter->text(), type);
    else {
      if (curveID >= 0)
        graph->modifyFunctionCurve(curveID, type, formulas,
                                   boxPolarParameter->text(), start, end,
                                   boxPolarPoints->value());
      else
        graph->addFunction(formulas, start, end, boxPolarPoints->value(),
                           boxPolarParameter->text(), type);
    }
  }
}
bool Plot3DDialog::updatePlot()
{
	int axis=-1;

	if (generalDialog->currentWidget()==(QWidget*)bars)
	{
		emit updateBars(boxBarsRad->text().toDouble());
	}

	if (generalDialog->currentWidget()==(QWidget*)points)
	{
		if (boxPointStyle->currentItem() == 0)
			emit updatePoints(boxSize->text().toDouble(), boxSmooth->isChecked());
		else if (boxPointStyle->currentItem() == 1)
			emit updateCross(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(),
					boxCrossSmooth->isChecked(), boxBoxed->isChecked());
		else if (boxPointStyle->currentItem() == 2)
			emit updateCones(boxConesRad->text().toDouble(), boxQuality->value());
	}

	if (generalDialog->currentWidget()==(QWidget*)title)
	{
		emit updateTitle(boxTitle->text(),titleColor,titleFont);
	}

	if (generalDialog->currentWidget()==(QWidget*)colors)
	{
		emit updateTransparency(boxTransparency->value()*0.01);
		emit updateDataColors(fromColor,toColor);
		emit updateColors(meshColor,axesColor,numColor,labelColor,bgColor,gridColor);
	}

	if (generalDialog->currentWidget()==(QWidget*)general)
	{
		emit showColorLegend(boxLegend->isChecked());
		emit updateMeshLineWidth(boxMeshLineWidth->value());
		emit adjustLabels(boxDistance->value());
		emit updateResolution (boxResolution->value());
		emit showColorLegend(boxLegend->isChecked());
		emit setNumbersFont(numbersFont);
		emit updateZoom(boxZoom->value()*0.01);
		emit updateScaling(boxXScale->value()*0.01,boxYScale->value()*0.01,
				boxZScale->value()*0.01);
	}

	if (generalDialog->currentWidget()==(QWidget*)scale)
	{
		axis=axesList->currentRow();
		QString from=boxFrom->text().toLower();
		QString to=boxTo->text().toLower();
		double start,end;
		bool error=false;
		try
		{
			MyParser parser;
			parser.SetExpr(from.toAscii().constData());
			start=parser.Eval();
		}
		catch(mu::ParserError &e)
		{
			QMessageBox::critical(0,tr("Start limit error"),  QString::fromStdString(e.GetMsg()));
			boxFrom->setFocus();
			error=true;
			return false;
		}
		try
		{
			MyParser parser;
			parser.SetExpr(to.toAscii().constData());
			end=parser.Eval();
		}
		catch(mu::ParserError &e)
		{
			QMessageBox::critical(0,tr("End limit error"), QString::fromStdString(e.GetMsg()));
			boxTo->setFocus();
			error=true;
			return false;
		}

		if (start>=end)
		{
			QMessageBox::critical(0,tr("Input error"),
					tr("Please enter scale limits that satisfy: from < to!"));
			boxTo->setFocus();
			return false;
		}

		if (! error)
			emit updateScale(axis,scaleOptions(axis, start, end,
						boxMajors->text(), boxMinors->text()));
	}

	if (generalDialog->currentWidget()==(QWidget*)axes)
	{
		axis=axesList2->currentRow();
		labels[axis] = boxLabel->text();
		emit updateLabel(axis, boxLabel->text(),axisFont(axis));
		emit updateTickLength(axis,boxMajorLength->text().toDouble(),
				boxMinorLength->text().toDouble());
	}

	return true;
}
示例#18
0
void SurfaceDialog::acceptFunction()
{
ApplicationWindow *app = static_cast<ApplicationWindow *>(this->parent());

QString Xfrom=boxXFrom->text().lower();
QString Xto=boxXTo->text().lower();
QString Yfrom=boxYFrom->text().lower();
QString Yto=boxYTo->text().lower();
QString Zfrom=boxZFrom->text().lower();
QString Zto=boxZTo->text().lower();

double fromX, toX, fromY,toY, fromZ,toZ;
try
	{
	MyParser parser;
	parser.SetExpr(Xfrom.ascii());
	fromX=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - X Start limit error"), QString::fromStdString(e.GetMsg()));
	boxXFrom->setFocus();
	return;
	}
try
	{
	MyParser parser;
	parser.SetExpr(Xto.ascii());
	toX=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - X End limit error"), QString::fromStdString(e.GetMsg()));
	boxXTo->setFocus();
	return;
	}

try
	{
	MyParser parser;
	parser.SetExpr(Yfrom.ascii());
	fromY=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - Y Start limit error"), QString::fromStdString(e.GetMsg()));
	boxYFrom->setFocus();
	return;
	}
try
	{
	MyParser parser;
	parser.SetExpr(Yto.ascii());
	toY=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - Y End limit error"), QString::fromStdString(e.GetMsg()));
	boxYTo->setFocus();
	return;
	}
try
	{
	MyParser parser;
	parser.SetExpr(Zfrom.ascii());
	fromZ=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - Z Start limit error"), QString::fromStdString(e.GetMsg()));
	boxZFrom->setFocus();
	return;
	}
try
	{
	MyParser parser;
	parser.SetExpr(Zto.ascii());
	toZ=parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(app, tr("MantidPlot - Z End limit error"), QString::fromStdString(e.GetMsg()));
	boxZTo->setFocus();
	return;
	}

if (fromX >= toX || fromY >= toY || fromZ >= toZ)
	{
	QMessageBox::critical(app, tr("MantidPlot - Input error"),
				tr("Please enter limits that satisfy: from < end!"));
	boxXTo->setFocus();
	return;
	}

QString formula=boxFunction->currentText();
bool error=false;
try
	{
	MyParser parser;
	double x=fromX;
	double y=fromY;
	parser.DefineVar("x", &x);
	parser.DefineVar("y", &y);
	parser.SetExpr(formula.ascii());

	
	parser.Eval();
  // cppcheck-suppress unreadVariable
	x=toX; 
  // cppcheck-suppress unreadVariable
	y=toY;
	parser.Eval();
	}
catch(mu::ParserError &e)
	{
	QMessageBox::critical(0, tr("MantidPlot - Input function error"), QString::fromStdString(e.GetMsg()));
	boxFunction->setFocus();
	error=true;
	}

if (!error){
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
	if (!d_graph){
		app->plotSurface(boxFunction->currentText(),fromX, toX, fromY, toY, fromZ, toZ,
					 boxFuncColumns->value(), boxFuncRows->value());
	} else
		d_graph->addFunction(boxFunction->currentText(),fromX, toX, fromY, toY, fromZ, toZ,
					 boxFuncColumns->value(), boxFuncRows->value());

	app->updateSurfaceFuncList(boxFunction->currentText());
    QApplication::restoreOverrideCursor();
	close();
	}
}
bool FunctionCurve::loadData(int points, bool xLog10Scale)
{
    if (!points)
        points = dataSize();

	double *X = (double *)malloc(points*sizeof(double));
	if (!X){
		QMessageBox::critical(0, QObject::tr("QtiPlot - Memory Allocation Error"),
		QObject::tr("Not enough memory, operation aborted!"));
		return false;
	}
	double *Y = (double *)malloc(points*sizeof(double));
	if (!Y){
		QMessageBox::critical(0, QObject::tr("QtiPlot - Memory Allocation Error"),
		QObject::tr("Not enough memory, operation aborted!"));
		free(X);
		return false;
	}

	double step = (d_to - d_from)/(double)(points - 1.0);
	if (d_function_type == Normal){
		MyParser parser;
		double x = d_from;
		try {
			parser.DefineVar(d_variable.ascii(), &x);
			QMapIterator<QString, double> i(d_constants);
			while (i.hasNext()){
				i.next();
				parser.DefineConst(i.key().ascii(), i.value());
			}
			parser.SetExpr(d_formulas[0].ascii());

			int lastButOne = points - 1;
			try {
				double xl = x, xr;
				double y = parser.EvalRemoveSingularity(&x, false);
				bool wellDefinedFunction = true;
				if (!gsl_finite(y)){// try to find a first well defined point (might help for some not really bad functions)
					wellDefinedFunction = false;
					for (int i = 0; i < lastButOne; i++){
						xl = x;
						x += step;
						xr = x;
						y = parser.Eval();
						if (gsl_finite(y)){
							wellDefinedFunction = true;
							int iter = 0;
							double x0 = x, y0 = y;
							while(fabs(xr - xl)/step > 1e-15 && iter < points){
								x = 0.5*(xl + xr);
								y = parser.Eval();
								if (gsl_finite(y)){
									xr = x;
									x0 = x;
									y0 = y;
								} else
									xl = x;
								iter++;
							}
							d_from = x0;
							X[0] = x0;
							Y[0] = y0;
							step = (d_to - d_from)/(double)(lastButOne);
							break;
						}
					}
					if (!wellDefinedFunction){
						QMessageBox::critical(0, QObject::tr("QtiPlot"),
						QObject::tr("The function %1 is not defined in the specified interval!").arg(d_formulas[0]));
						free(X); free(Y);
						return false;
					}
				} else {
					X[0] = d_from;
					Y[0] = y;
				}
			} catch (MyParser::Pole) {}

			ScaleEngine *sc_engine = 0;
			if (plot())
				sc_engine = (ScaleEngine *)plot()->axisScaleEngine(xAxis());

			if (xLog10Scale || (d_from > 0 && d_to > 0 && sc_engine &&
				sc_engine->type() == ScaleTransformation::Log10)){
				step = log10(d_to/d_from)/(double)(points - 1);
				for (int i = 1; i < lastButOne; i++ ){
					x = d_from*pow(10, i*step);
					X[i] = x;
					try {
						Y[i] = parser.EvalRemoveSingularity(&x, false);
					} catch (MyParser::Pole){}
				}
			} else {
				for (int i = 1; i < lastButOne; i++ ){
					x += step;
					X[i] = x;
					try {
						Y[i] = parser.EvalRemoveSingularity(&x, false);
					} catch (MyParser::Pole){}
				}
			}
			//the last point might be outside the interval, therefore we calculate it separately at its precise value
			x = d_to;
			X[lastButOne] = x;
			try {
				Y[lastButOne] = parser.EvalRemoveSingularity(&x, false);
			} catch (MyParser::Pole){}
		} catch(mu::ParserError &e) {}
	} else if (d_function_type == Parametric || d_function_type == Polar) {
		QStringList aux = d_formulas;
		MyParser xparser;
		MyParser yparser;
		double par;
		if (d_function_type == Polar) {
			QString swap=aux[0];
			aux[0]="("+swap+")*cos("+aux[1]+")";
			aux[1]="("+swap+")*sin("+aux[1]+")";
		}

		try {
			QMapIterator<QString, double> i(d_constants);
			while (i.hasNext()){
				i.next();
				xparser.DefineConst(i.key().ascii(), i.value());
				yparser.DefineConst(i.key().ascii(), i.value());
			}

			xparser.DefineVar(d_variable.ascii(), &par);
			yparser.DefineVar(d_variable.ascii(), &par);
			xparser.SetExpr(aux[0].ascii());
			yparser.SetExpr(aux[1].ascii());
			par = d_from;
			for (int i = 0; i<points; i++ ){
				X[i] = xparser.Eval();
				Y[i] = yparser.Eval();
				par += step;
			}
		} catch(mu::ParserError &) {}
	}

	if (curveType() == QwtPlotCurve::Yfx)
		setData(X, Y, points);
	else
		setData(Y, X, points);
	free(X); free(Y);
	return true;
}
示例#20
0
void SurfaceDialog::acceptParametricSurface()
{
	ApplicationWindow *app = static_cast<ApplicationWindow *>(this->parent());

	MyParser parser;
	double u = 1.0, v = 1.0;
	parser.DefineVar("u", &u);
	parser.DefineVar("v", &v);

    int list_size = 15;
    QString x_formula = boxX->text();
	try {
		parser.SetExpr(x_formula.ascii());
		parser.Eval();
	} catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - X Formula Error"), QString::fromStdString(e.GetMsg()));
		boxX->setFocus();
		return;
	}

    app->d_param_surface_func.remove(x_formula);
	app->d_param_surface_func.push_front(x_formula);
	while ((int)app->d_param_surface_func.size() > list_size)
		app->d_param_surface_func.pop_back();

    QString y_formula = boxY->text();
	try {
		parser.SetExpr(y_formula.ascii());
		parser.Eval();
	} catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - Y Formula Error"), QString::fromStdString(e.GetMsg()));
		boxY->setFocus();
		return;
	}

    app->d_param_surface_func.remove(y_formula);
	app->d_param_surface_func.push_front(y_formula);
	while ((int)app->d_param_surface_func.size() > list_size)
		app->d_param_surface_func.pop_back();

    QString z_formula = boxZ->text();
	try {
		parser.SetExpr(z_formula.ascii());
		parser.Eval();
	} catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - Z Formula Error"), QString::fromStdString(e.GetMsg()));
		boxZ->setFocus();
		return;
	}

    app->d_param_surface_func.remove(z_formula);
	app->d_param_surface_func.push_front(z_formula);
	while ((int)app->d_param_surface_func.size() > list_size)
		app->d_param_surface_func.pop_back();

	QString ufrom = boxUFrom->text().lower();
	QString uto = boxUTo->text().lower();
	QString vfrom = boxVFrom->text().lower();
	QString vto = boxVTo->text().lower();
	double ul, ur, vl, vr;
	try{
		parser.SetExpr(ufrom.ascii());
		ul = parser.Eval();
	}
	catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - u start limit error"), QString::fromStdString(e.GetMsg()));
		boxUFrom->setFocus();
		return;
	}

	try{
		parser.SetExpr(uto.ascii());
		ur = parser.Eval();
	}
	catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - u end limit error"), QString::fromStdString(e.GetMsg()));
		boxUTo->setFocus();
		return;
	}

	try{
		parser.SetExpr(vfrom.ascii());
		vl = parser.Eval();
	}
	catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - v start limit error"), QString::fromStdString(e.GetMsg()));
		boxVFrom->setFocus();
		return;
	}

	try{
		parser.SetExpr(vto.ascii());
		vr = parser.Eval();
	}
	catch(mu::ParserError &e){
		QMessageBox::critical(app, tr("MantidPlot - u end limit error"), QString::fromStdString(e.GetMsg()));
		boxVTo->setFocus();
		return;
	}

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
	if (!d_graph)
		app->plotParametricSurface(x_formula, y_formula, z_formula,
							   ul, ur, vl, vr, boxColumns->value(), boxRows->value(),
							   boxUPeriodic->isChecked(), boxVPeriodic->isChecked());
	else
		d_graph->addParametricSurface(x_formula, y_formula, z_formula,
							   ul, ur, vl, vr, boxColumns->value(), boxRows->value(),
							   boxUPeriodic->isChecked(), boxVPeriodic->isChecked());
    QApplication::restoreOverrideCursor();
	close();
}
bool Plot3DDialog::updatePlot()
{
	if (!d_plot)
		return false;

    ApplicationWindow *app = (ApplicationWindow *)this->parent();
    if (!app)
        return false;

	if (generalDialog->currentPage()==(QWidget*)bars){
		d_plot->setBarRadius(boxBarsRad->text().toDouble());
		d_plot->setBarStyle();
	} else if (generalDialog->currentPage() == (QWidget*)points){
		if (boxPointStyle->currentIndex() == 0) {
			d_plot->setDotOptions(boxSize->text().toDouble(), boxSmooth->isChecked());
			d_plot->setDotStyle();
		} else if (boxPointStyle->currentIndex() == 1){
			d_plot->setCrossOptions(boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(),
					boxCrossSmooth->isChecked(), boxBoxed->isChecked());
            d_plot->setCrossStyle();
        } else if (boxPointStyle->currentIndex() == 2) {
			d_plot->setConeOptions(boxConesRad->text().toDouble(), boxQuality->value());
			d_plot->setConeStyle();
        }

        app->custom3DActions(d_plot);
	} else if (generalDialog->currentPage()==(QWidget*)title){
		d_plot->setTitle(boxTitle->text().remove("\n"), btnTitleColor->color(), titleFont);
	} else if (generalDialog->currentPage()==(QWidget*)colors){
		d_plot->changeTransparency(boxTransparency->value()*0.01);
		d_plot->setDataColors(btnFromColor->color(), btnToColor->color());
		d_plot->setMeshColor(btnMesh->color());
		d_plot->setAxesColor(btnAxes->color());
		d_plot->setNumbersColor(btnNumbers->color());
		d_plot->setLabelsColor(btnLabels->color());
		d_plot->setBackgroundColor(btnBackground->color());
		d_plot->setGridColor(btnGrid->color());
	} else if (generalDialog->currentPage()==(QWidget*)general){
		d_plot->showColorLegend(boxLegend->isChecked());
		d_plot->setResolution(boxResolution->value());
		d_plot->setMeshLineWidth(boxMeshLineWidth->value());
		d_plot->setLabelsDistance(boxDistance->value());
		d_plot->setNumbersFont(numbersFont);
		d_plot->setZoom(boxZoom->value()*0.01);
		d_plot->setScale(boxXScale->value()*0.01, boxYScale->value()*0.01, boxZScale->value()*0.01);
	} else if (generalDialog->currentPage()==(QWidget*)scale){
		int axis = axesList->currentRow();
		QString from=boxFrom->text().lower();
		QString to=boxTo->text().lower();
		double start, end;
		try {
			MyParser parser;
			parser.SetExpr(from.ascii());
			start = parser.Eval();
		} catch(mu::ParserError &e){
			QMessageBox::critical(0,tr("QtiPlot - Start limit error"),  QString::fromStdString(e.GetMsg()));
			boxFrom->setFocus();
			return false;
		}

		try {
			MyParser parser;
			parser.SetExpr(to.ascii());
			end = parser.Eval();
		} catch(mu::ParserError &e){
			QMessageBox::critical(0,tr("QtiPlot - End limit error"), QString::fromStdString(e.GetMsg()));
			boxTo->setFocus();
			return false;
		}

        d_plot->updateScale(axis, scaleOptions(axis, start, end, boxMajors->text(), boxMinors->text()));
	} else if (generalDialog->currentPage()==(QWidget*)axes){
		int axis = axesList2->currentRow();
		labels[axis] = boxLabel->text();

		switch(axis)
		{
		case 0:
			d_plot->setXAxisLabel(boxLabel->text().remove("\n"));
			d_plot->setXAxisLabelFont(axisFont(axis));
			d_plot->setXAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble());
		break;
		case 1:
			d_plot->setYAxisLabel(boxLabel->text().remove("\n"));
			d_plot->setYAxisLabelFont(axisFont(axis));
			d_plot->setYAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble());
		break;
		case 2:
			d_plot->setZAxisLabel(boxLabel->text().remove("\n"));
			d_plot->setZAxisLabelFont(axisFont(axis));
			d_plot->setZAxisTickLength(boxMajorLength->text().toDouble(), boxMinorLength->text().toDouble());
		break;
		}
	}

    d_plot->update();
    app->modifiedProject(d_plot);
	return true;
}
示例#22
0
int main(int argc, char* argv[])
{
	MyParser p;
	ifstream is;
	string xml;
	string chunk;
	char buff[64];
	int len;
	

	// disable CDATA composed of whitespaces
	p.set_skip_whitespaces(true);
	
	// check if one (only one) file name given
	if (argc != 2) {
		cout<<"usage: xmlsp_test2 xml_file_to_parse"<<endl;
		return 0;
	}	

	// open input file
	is.open(argv[1]);
	if (!is) {
		cerr<<"File \""<<argv[1]<<"\" can not be opened"<<endl;
		return 1;
	}

	// begin parsing
	if (!p.begin()) {
		cerr<<"Failed to initialize parser"<<endl;
		return 1;
	}

	// first parse use chunks
	cout<<"Parsing \""<<argv[1]<<"\" as stream:"<<endl;

	// read chunks, parse them, and save for one chunk parse
	while (!is.eof() && is.good()) {
		// read file
		is.read(buff, 64);
		len = is.gcount();
		xml.append(buff, len);
		chunk.assign(buff, len);

		// try to parse
		if (p.parse_chunk(chunk) == false) {
			cout<<"Failed to parse chunk"<<endl;
			is.close();
			return 1;
		}
	}


	if (is.bad()) {
		cerr<<"Reading file failed"<<endl;
		is.close();
		return 1;
	}

	is.close();

	if (!p.end()) {
		cerr<<"Failed to finalize parsing"<<endl;
		return 1;
	}
	

	cout<<"Parse 1 finished"<<endl<<endl<<endl;

	cout<<"Parsing \""<<argv[1]<<"\" as single chunk:"<<endl;
	if (p.parse(xml)) {
		cout<<"Parse 2 finished"<<endl;
	} else {
		cerr<<"Failed to parse xml file"<<endl;
	}
}
示例#23
0
void FitDialog::accept()
{
	QString curve = boxCurve->currentText();
	QStringList curvesList = d_graph->curvesList();
	if (curvesList.contains(curve) <= 0)
	{
		QMessageBox::critical(this,tr("Warning"),
				tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curve));
		boxCurve->clear();
		boxCurve->addItems(curvesList);
		return;
	}

	if (!validInitialValues())
		return;

	QString from=boxFrom->text().toLower();
	QString to=boxTo->text().toLower();
	QString tolerance=boxTolerance->text().toLower();
	double start, end, eps;
	try
	{
		MyParser parser;
		parser.SetExpr(CONFS(from).toAscii().constData());
		start=parser.Eval();
	}
	catch(mu::ParserError &e)
	{
		QMessageBox::critical(this, tr("Start limit error"),QString::fromStdString(e.GetMsg()));
		boxFrom->setFocus();
		return;
	}

	try
	{
		MyParser parser;
		parser.SetExpr(CONFS(to).toAscii().constData());
		end=parser.Eval();
	}
	catch(mu::ParserError &e)
	{
		QMessageBox::critical(this, tr("End limit error"),QString::fromStdString(e.GetMsg()));
		boxTo->setFocus();
		return;
	}

	if (start>=end)
	{
		QMessageBox::critical(0, tr("Input error"),
				tr("Please enter x limits that satisfy: from < end!"));
		boxTo->setFocus();
		return;
	}

	try
	{
		MyParser parser;
		parser.SetExpr(CONFS(tolerance).toAscii().constData());
		eps=parser.Eval();
	}
	catch(mu::ParserError &e)
	{
		QMessageBox::critical(0, tr("Tolerance input error"),QString::fromStdString(e.GetMsg()));
		boxTolerance->setFocus();
		return;
	}

	if (eps<0 || eps>=1)
	{
		QMessageBox::critical(0, tr("Tolerance input error"),
				tr("The tolerance value must be positive and less than 1!"));
		boxTolerance->setFocus();
		return;
	}

	int i, n=0, rows=boxParams->rowCount();
	if (!boxParams->isColumnHidden(2))
	{
		for (i=0;i<rows;i++)
		{//count the non-constant parameters
            QCheckBox *cb = (QCheckBox*)boxParams->cellWidget(i, 2);
			if (!cb->isChecked())
				n++;
		}
	}
	else
		n=rows;

	QStringList parameters;
	double *paramsInit = new double[n];
	QString formula;

	// recursively define variables for user functions used in formula
	bool found_uf;
	do {
		found_uf = false;
		for (i=0; i<d_user_function_names.count(); i++)
			if (boxFunction->text().contains(d_user_function_names[i])) {
				QStringList l = d_user_functions[i].split("=");
				formula += QString("%1=%2\n")
						.arg(d_user_function_names[i])
						.arg(l[1]);
				found_uf = true;
			}
	} while (found_uf);
	formula += boxFunction->text();

	// define variables for builtin functions used in formula
	for (i=0; i<d_built_in_function_names.count(); i++)
		if (formula.contains(d_built_in_function_names[i]))
			formula.prepend(QString("%1=%2\n")
					.arg(d_built_in_function_names[i])
					.arg(d_built_in_functions[i]));


        if (!boxParams->isColumnHidden(2))
        {
            int j = 0;
            for (i=0;i<rows;i++)
            {
                QCheckBox *cb = (QCheckBox*)boxParams->cellWidget(i, 2);
                if (!cb->isChecked())
                {
                    paramsInit[j] = QLocale().toDouble(boxParams->item(i,1)->text());
                    parameters << boxParams->item(i,0)->text();
                    j++;
                }
                else
                    formula.prepend(QString("%1=%2\n")
                                    .arg(boxParams->item(i,0)->text())
                                    .arg(CONFS(boxParams->item(i,1)->text())));
            }
        }
        else
        {
            for (i=0;i<n;i++)
            {
                paramsInit[i] = QLocale().toDouble(boxParams->item(i,1)->text());
                parameters << boxParams->item(i,0)->text();
            }
        }

        ApplicationWindow *app = (ApplicationWindow *)this->parent();

        if (d_fitter)
        {
            delete d_fitter;
            d_fitter  = 0;
        }

        if (boxUseBuiltIn->isChecked() && categoryBox->currentRow() == 1)
            fitBuiltInFunction(funcBox->currentItem()->text(), paramsInit);
        else if (boxUseBuiltIn->isChecked() && categoryBox->currentRow() == 3)
        {
            d_fitter = new PluginFit(app, d_graph);
            if (!((PluginFit*)d_fitter)->load(d_plugin_files_list[funcBox->currentRow()])){
                d_fitter  = 0;
                return;}
            d_fitter->setInitialGuesses(paramsInit);
        }
        else
        {
            d_fitter = new NonLinearFit(app, d_graph);
            ((NonLinearFit*)d_fitter)->setParametersList(parameters);
            ((NonLinearFit*)d_fitter)->setFormula(formula);
            d_fitter->setInitialGuesses(paramsInit);
        }
        delete[] paramsInit;

        if (!d_fitter->setDataFromCurve(curve, start, end) ||
            !d_fitter->setYErrorSource ((Fit::ErrorSource)boxYErrorSource->currentIndex(),
                                        tableNamesBox->currentText()+"_"+colNamesBox->currentText()))
        {
            delete d_fitter;
            d_fitter  = 0;
            return;
        }

        d_fitter->setTolerance (eps);
        d_fitter->setAlgorithm((Fit::Algorithm)boxAlgorithm->currentIndex());
        d_fitter->setColor(boxColor->currentIndex());
        d_fitter->generateFunction(generatePointsBtn->isChecked(), generatePointsBox->value());
        d_fitter->setMaximumIterations(boxPoints->value());
        d_fitter->scaleErrors(scaleErrorsBox->isChecked());

        if (d_fitter->name() == tr("MultiPeak") && ((MultiPeakFit *)d_fitter)->peaks() > 1)
        {
            ((MultiPeakFit *)d_fitter)->enablePeakCurves(app->generatePeakCurves);
            ((MultiPeakFit *)d_fitter)->setPeakCurvesColor(app->peakCurvesColor);
        }

        d_fitter->fit();
        double *res = d_fitter->results();
        if (!boxParams->isColumnHidden(2))
        {
            int j = 0;
            for (i=0;i<rows;i++)
            {
                QCheckBox *cb = (QCheckBox*)boxParams->cellWidget(i, 2);
                if (!cb->isChecked())
                    boxParams->item(i, 1)->setText(QLocale().toString(res[j++], 'g', boxPrecision->value()));
            }
        }
        else
        {
            for (i=0;i<rows;i++)
                boxParams->item(i, 1)->setText(QLocale().toString(res[i], 'g', boxPrecision->value()));
        }
}
示例#24
0
void FilterDialog::filter() {
  double from = 0.0, to = 0.0;
  try {
    MyParser parser;
    parser.SetExpr(boxStart->text().replace(",", ".").toAscii().constData());
    from = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(this, tr("MantidPlot - Frequency input error"),
                          QString::fromStdString(e.GetMsg()));
    boxStart->setFocus();
    return;
  }

  if (from < 0) {
    QMessageBox::critical(this, tr("MantidPlot - Frequency input error"),
                          tr("Please enter positive frequency values!"));
    boxStart->setFocus();
    return;
  }

  if (filter_type >= FFTFilter::BandPass) {
    try {
      MyParser parser;
      parser.SetExpr(boxEnd->text().replace(",", ".").toAscii().constData());
      to = parser.Eval();
    } catch (mu::ParserError &e) {
      QMessageBox::critical(this, tr("MantidPlot - High Frequency input error"),
                            QString::fromStdString(e.GetMsg()));
      boxEnd->setFocus();
      return;
    }

    if (to < 0) {
      QMessageBox::critical(this, tr("MantidPlot - High Frequency input error"),
                            tr("Please enter positive frequency values!"));
      boxEnd->setFocus();
      return;
    }

    if (from >= to) {
      QMessageBox::critical(
          this, tr("MantidPlot - Frequency input error"),
          tr("Please enter frequency limits that satisfy: Low < High !"));
      boxEnd->setFocus();
      return;
    }
  }

  FFTFilter *f = new FFTFilter(dynamic_cast<ApplicationWindow *>(parent()),
                               graph, boxName->currentText(), filter_type);
  if (filter_type == FFTFilter::BandPass) {
    f->setBand(from, to);
    f->enableOffset(boxOffset->isChecked());
  } else if (filter_type == FFTFilter::BandBlock) {
    f->setBand(from, to);
    f->enableOffset(!boxOffset->isChecked());
  } else
    f->setCutoff(from);

  f->setColor(boxColor->currentIndex());
  f->run();
  delete f;
}
示例#25
0
bool Plot3DDialog::updatePlot() {
  if (!d_plot)
    return false;

  ApplicationWindow *app = static_cast<ApplicationWindow *>(this->parent());
  if (!app)
    return false;

  if (generalDialog->currentWidget() == static_cast<QWidget *>(bars)) {
    d_plot->setBarRadius(boxBarsRad->text().toDouble());
    d_plot->setBarStyle();
  } else if (generalDialog->currentWidget() == static_cast<QWidget *>(points)) {
    if (boxPointStyle->currentIndex() == 0) {
      d_plot->setDotOptions(boxSize->text().toDouble(), boxSmooth->isChecked());
      d_plot->setDotStyle();
    } else if (boxPointStyle->currentIndex() == 1) {
      d_plot->setCrossOptions(
          boxCrossRad->text().toDouble(), boxCrossLinewidth->text().toDouble(),
          boxCrossSmooth->isChecked(), boxBoxed->isChecked());
      d_plot->setCrossStyle();
    } else if (boxPointStyle->currentIndex() == 2) {
      d_plot->setConeOptions(boxConesRad->text().toDouble(),
                             boxQuality->value());
      d_plot->setConeStyle();
    }

    app->custom3DActions(d_plot);
  } else if (generalDialog->currentWidget() == static_cast<QWidget *>(title)) {
    d_plot->setTitle(boxTitle->toPlainText().remove("\n"),
                     btnTitleColor->color(), titleFont);
  } else if (generalDialog->currentWidget() == static_cast<QWidget *>(colors)) {
    d_plot->changeTransparency(boxTransparency->value() * 0.01);
    d_plot->setDataColors(btnFromColor->color(), btnToColor->color());
    d_plot->setMeshColor(btnMesh->color());
    d_plot->setAxesColor(btnAxes->color());
    d_plot->setNumbersColor(btnNumbers->color());
    d_plot->setLabelsColor(btnLabels->color());
    d_plot->setBackgroundColor(btnBackground->color());
    d_plot->setGridColor(btnGrid->color());
  } else if (generalDialog->currentWidget() ==
             static_cast<QWidget *>(general)) {
    d_plot->showColorLegend(boxLegend->isChecked());
    d_plot->setResolution(boxResolution->value());
    d_plot->setMeshLineWidth(boxMeshLineWidth->value());
    d_plot->setLabelsDistance(boxDistance->value());
    d_plot->setNumbersFont(numbersFont);
    d_plot->setZoom(zoom * boxZoom->value() * 0.01);
    d_plot->setScale(xScale * boxXScale->value() * 0.01,
                     yScale * boxYScale->value() * 0.01,
                     zScale * boxZScale->value() * 0.01);
  } else if (generalDialog->currentWidget() == static_cast<QWidget *>(scale)) {
    int axis = axesList->currentRow();
    QString from = boxFrom->text().toLower();
    QString to = boxTo->text().toLower();
    double start, end;
    try {
      MyParser parser;
      parser.SetExpr(from.toAscii().constData());
      start = parser.Eval();
    } catch (mu::ParserError &e) {
      QMessageBox::critical(0, tr("MantidPlot - Start limit error"),
                            QString::fromStdString(e.GetMsg()));
      boxFrom->setFocus();
      return false;
    }

    try {
      MyParser parser;
      parser.SetExpr(to.toAscii().constData());
      end = parser.Eval();
    } catch (mu::ParserError &e) {
      QMessageBox::critical(0, tr("MantidPlot - End limit error"),
                            QString::fromStdString(e.GetMsg()));
      boxTo->setFocus();
      return false;
    }

    /*double xsc = d_plot->xScale();
    double ysc = d_plot->yScale();
    double zsc = d_plot->zScale();
    if (axis == 2)
    {
        double start0 = scales[0].toDouble();
        double end0 = scales[1].toDouble();
        zsc *= (end0 - start0)/(end - start);
        QMessageBox::information(this,"OK","OK");
    }*/

    d_plot->updateScale(axis, scaleOptions(axis, start, end, boxMajors->text(),
                                           boxMinors->text()));
    // d_plot->setScale(xsc,ysc,zsc*0.1);
  } else if (generalDialog->currentWidget() == static_cast<QWidget *>(axes)) {
    int axis = axesList2->currentRow();
    labels[axis] = boxLabel->toPlainText();

    switch (axis) {
    case 0:
      d_plot->setXAxisLabel(boxLabel->toPlainText().remove("\n"));
      d_plot->setXAxisLabelFont(axisFont(axis));
      d_plot->setXAxisTickLength(boxMajorLength->text().toDouble(),
                                 boxMinorLength->text().toDouble());
      break;
    case 1:
      d_plot->setYAxisLabel(boxLabel->toPlainText().remove("\n"));
      d_plot->setYAxisLabelFont(axisFont(axis));
      d_plot->setYAxisTickLength(boxMajorLength->text().toDouble(),
                                 boxMinorLength->text().toDouble());
      break;
    case 2:
      d_plot->setZAxisLabel(boxLabel->toPlainText().remove("\n"));
      d_plot->setZAxisLabelFont(axisFont(axis));
      d_plot->setZAxisTickLength(boxMajorLength->text().toDouble(),
                                 boxMinorLength->text().toDouble());
      break;
    }
  }

  d_plot->update();
  app->modifiedProject(d_plot);
  return true;
}
示例#26
0
void IntDialog::accept()
{
QString curveName = boxName->currentText();
QwtPlotCurve *c = graph->curve(curveName);
QStringList curvesList = graph->analysableCurvesList();
if (!c || !curvesList.contains(curveName))
	{
	QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") +" - "+ tr("Warning"),
		tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curveName));
	boxName->clear();
	boxName->insertStringList(curvesList);
	return;
	}

double start = 0, stop = 0;
double minx = c->minXValue();
double maxx = c->maxXValue();

// Check the Xmin
QString from = boxStart->text().toLower();
if(from=="min")
	{
	boxStart->setText(QString::number(minx));
	return;
	}
else if(from=="max")
	{
	boxStart->setText(QString::number(maxx));
	return;
	}
else
	{
	try
		{
		MyParser parser;
		parser.SetExpr((boxStart->text()).toAscii().constData());
		start=parser.Eval();

		if(start<minx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number larger or equal to the minimum value of X, for the lower limit.\n If you do not know that value, type min in the box."));
			boxStart->clear();
			boxStart->setFocus();
			return;
		}
		if(start > maxx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number smaller or equal to the maximum value of X, for the lower limit.\n If you do not know that value, type max in the box."));
			boxStart->clear();
			boxStart->setFocus();
			return;
			}
		}
	catch(mu::ParserError &e)
		{
		QMessageBox::critical((ApplicationWindow *)parent(),tr("Start limit error"),QString::fromStdString(e.GetMsg()));
		boxStart->clear();
		boxStart->setFocus();
		return;
		}
	}

// Check Xmax
QString end=boxEnd->text().toLower();
if(end=="min")
	{
	boxEnd->setText(QString::number(minx));
	return;
	}
else if(end=="max")
	{
	boxEnd->setText(QString::number(maxx));
	return;
	}
else
	{
	try
		{
		MyParser parser;
		parser.SetExpr((boxEnd->text()).toAscii().constData());
		stop = parser.Eval();
		if(stop > maxx)
			{
			//FIXME: I don't understand why this doesn't work for FunctionCurves!!(Ion)
			/*QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number smaller or equal to the maximum value of X, for the upper limit.\n If you do not know that value, type max in the box."));
			boxEnd->clear();
			boxEnd->setFocus();
			return;
			*/
			boxEnd->setText(QString::number(maxx));
			}
		if(stop < minx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number larger or equal to the minimum value of X, for the upper limit.\n If you do not know that value, type min in the box."));
			boxEnd->clear();
			boxEnd->setFocus();
			return;
			}
		}
	catch(mu::ParserError &e)
		{
		QMessageBox::critical((ApplicationWindow *)parent(), tr("End limit error"),QString::fromStdString(e.GetMsg()));
		boxEnd->clear();
		boxEnd->setFocus();
		return;
		}
	}

Integration *i = new Integration((ApplicationWindow *)this->parent(), graph, curveName,
                                 boxStart->text().toDouble(), boxEnd->text().toDouble());
i->setMethod((Integration::InterpolationMethod)boxMethod->currentIndex());
i->run();
delete i;
}