Esempio n. 1
0
QwtDoubleRect Plot::boundingRect ()
{
QMapIterator<int, QwtPlotCurve *> it = d_curves.begin();
QwtPlotCurve *c = (QwtPlotCurve *)it.data();

double minX = c->minXValue();
double minY = c->minYValue();
double maxX = c->maxXValue();
double maxY = c->maxYValue();

it++;

for (it; it != d_curves.end(); ++it) 
	{
	QwtPlotCurve *c = (QwtPlotCurve *)it.data();
	if (!c)
		continue;

	minX = (c->minXValue() < minX) ? c->minXValue() : minX;
	maxX = (c->maxXValue() > maxX) ? c->maxXValue() : maxX;
	minY = (c->minYValue() < minY) ? c->minYValue() : minY;
	maxY = (c->maxYValue() > maxY) ? c->maxYValue() : maxY;
	}

QwtDoubleRect r;
r.setLeft(minX);
r.setRight(maxX);
r.setTop(minY);
r.setBottom(maxY);
return r;
}
void Data_analysis_gui::set_x_axis_logscale( bool on ) {

  /*
  if (plot_->axisScaleEngine(QwtPlot::xBottom)->transformation()->type() ==
      QwtScaleTransformation::Log10 && on)
    return;

  if (plot_->axisScaleEngine(QwtPlot::xBottom)->transformation()->type() ==
      QwtScaleTransformation::Linear && (!on))
    return;
  */
  
  // Nico: the following check may be unnecessary
  if( on ) {
    // Before allowing to go to log scaling, make sure all values are > 0:
    // if some are < 0, return without doing anything
        QwtPlotItemList L = plot_->itemList();
    for (int i = 0; i < L.size(); ++i) {
      if (L[i]->rtti() == QwtPlotItem::Rtti_PlotCurve) {
	QwtPlotCurve * curve = dynamic_cast<QwtPlotCurve*>(L[i]);
	if (curve->minXValue() <= 0)
	  return;
      }
    }

    plot_->setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine);
  }

  else
    plot_->setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
  
  plot_->replot();
}
Esempio n. 3
0
void PlotSettingsDialog::
setAutoScale( const std::vector<QwtPlot*>& plots, QwtPlot::Axis axis ) {
    const double margin = 1.05;

    for( unsigned int i=0 ; i < plots.size() ; i++ ) {
        double max = -9e99;
        double min =  9e99;
        QwtPlotItemList L = plots[i]->itemList();
        for (int id = 0; id < L.size(); ++id) {
            if (L[id]->rtti() != QwtPlotItem::Rtti_PlotCurve)
                continue;

            QwtPlotCurve *curve = dynamic_cast<QwtPlotCurve*>(L[i]);
            if( axis == QwtPlot::xBottom ) {
                max = std::max( max, curve->maxXValue() );
                min = std::min( min, curve->minXValue() );
            }
            else {
                max = std::max( max, curve->maxYValue() );
                min = std::min( min, curve->minYValue() );
            }
        }
        plots[i]->setAxisScale( axis, min*(2-margin), max*margin );
        plots[i]->replot();
    }
}
Esempio n. 4
0
//! Rebuild the scales and maps
void QwtPlot::updateAxes()
{
    int i;
    bool resetDone[axisCnt];
    for (i = 0; i < axisCnt; i++)
        resetDone[i] = FALSE;

    //
    //  Adjust autoscalers
    //

    QIntDictIterator<QwtPlotCurve> itc(*d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        if (c->dataSize() > 0)  // don't scale curves with no data
        {                       //  (minXValue() et al. would return 0.0)
            int axis = c->xAxis();
            if ( !resetDone[axis] )
            {
                d_as[axis].reset();
                resetDone[axis] = TRUE;
            }
            d_as[axis].adjust(c->minXValue(), c->maxXValue());

            axis = c->yAxis();
            if ( !resetDone[axis] )
            {
                d_as[axis].reset();
                resetDone[axis] = TRUE;
            }
            d_as[axis].adjust(c->minYValue(), c->maxYValue());
        }
    }

    //
    // Adjust scales
    //
    for (i=0; i<axisCnt; i++)
    {
        d_sdiv[i] = d_as[i].scaleDiv();
        d_scale[i]->setScaleDiv(d_sdiv[i]);
    }

    d_grid.setXDiv(d_sdiv[d_grid.xAxis()]);
    d_grid.setYDiv(d_sdiv[d_grid.yAxis()]);
}
Esempio n. 5
0
void fitDialog::activateCurve(int index)
{
    QwtPlotCurve *c = graph->curve(index);
    if (!c)
        return;

    if (graph->selectorsEnabled() && graph->selectedCurveID() == graph->curveKey(index))
    {
        double start = graph->selectedXStartValue();
        double end = graph->selectedXEndValue();
        boxFrom->setText(QString::number(QMIN(start, end), 'g', 15));
        boxTo->setText(QString::number(QMAX(start, end), 'g', 15));
    }
    else
    {
        boxFrom->setText(QString::number(c->minXValue(), 'g', 15));
        boxTo->setText(QString::number(c->maxXValue(), 'g', 15));
    }
};
void polynomFitDialog::activateCurve(int index)
{
QwtPlotCurve *c = graph->curve(index);
if (!c)
	return;

if (graph->selectorsEnabled() && graph->selectedCurveID() == graph->curveKey(index))
	{
	double start = graph->selectedXStartValue();
	double end = graph->selectedXEndValue();
	boxStart->setText(QString::number(QMIN(start, end), 'g', 15));
	boxEnd->setText(QString::number(QMAX(start, end), 'g', 15));
	}
else
	{
	boxStart->setText(QString::number(c->minXValue(), 'g', 15));
	boxEnd->setText(QString::number(c->maxXValue(), 'g', 15));
	}

boxPoints->setValue(QMAX(c->dataSize(), 100));
};
Esempio n. 7
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;
}