当前位置: 首页>>代码示例>>C++>>正文


C++ MyParser::Eval方法代码示例

本文整理汇总了C++中MyParser::Eval方法的典型用法代码示例。如果您正苦于以下问题:C++ MyParser::Eval方法的具体用法?C++ MyParser::Eval怎么用?C++ MyParser::Eval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyParser的用法示例。


在下文中一共展示了MyParser::Eval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: trapezf

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;
    }
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:29,代码来源:Integration.cpp

示例2: interpretText

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));
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:26,代码来源:DoubleSpinBox.cpp

示例3: Filter

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;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:29,代码来源:Integration.cpp

示例4: valid

/** 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);
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:35,代码来源:AxisDetails.cpp

示例5: transformValue

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;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:26,代码来源:ScaleDraw.cpp

示例6: setFormula

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;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:50,代码来源:NonLinearFit.cpp

示例7: catch

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;
}
开发者ID:DanNixon,项目名称:mantid,代码行数:18,代码来源:UserFunction.cpp

示例8: transformValue

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;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:21,代码来源:ScaleDraw.cpp

示例9: if

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(),
//.........这里部分代码省略.........
开发者ID:rosswhitfield,项目名称:mantid,代码行数:101,代码来源:Plot3DDialog.cpp

示例10: filter

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;
}
开发者ID:liyulun,项目名称:mantid,代码行数:63,代码来源:FilterDialog.cpp

示例11: updateBars

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());
	}
//.........这里部分代码省略.........
开发者ID:highperformancecoder,项目名称:scidavis,代码行数:101,代码来源:Plot3DDialog.cpp

示例12: acceptPolar

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);
    }
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:96,代码来源:FunctionDialog.cpp

示例13: acceptFunction

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;
//.........这里部分代码省略.........
开发者ID:dezed,项目名称:mantid,代码行数:101,代码来源:SurfaceDialog.cpp

示例14: acceptParametricSurface

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;
	}

//.........这里部分代码省略.........
开发者ID:dezed,项目名称:mantid,代码行数:101,代码来源:SurfaceDialog.cpp

示例15: loadData

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){}
				}
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:101,代码来源:FunctionCurve.cpp


注:本文中的MyParser::Eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。