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 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(); } }
void ExpDecayDialog::fit() { QString curve = boxName->currentText(); QwtPlotCurve *c = graph->curve(curve); QStringList curvesList = graph->analysableCurvesList(); if (!c || !curvesList.contains(curve)){ QMessageBox::critical(this,tr("QtiPlot - Warning"), tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curve)); boxName->clear(); boxName->addItems(curvesList); return; } ApplicationWindow *app = (ApplicationWindow *)this->parent(); if (!app) return; if (fitter) delete fitter; if (slopes == 3){ double x_init[7] = {1.0, boxFirst->value(), 1.0, boxSecond->value(), 1.0, boxThird->value(), boxYOffset->value()}; fitter = new ThreeExpFit(app, graph); fitter->setInitialGuesses(x_init); } else if (slopes == 2) { double x_init[5] = {1.0, boxFirst->value(), 1.0, boxSecond->value(), boxYOffset->value()}; fitter = new TwoExpFit(app, graph); fitter->setInitialGuesses(x_init); } else if (slopes == 1 || slopes == -1){ double x_init[3] = {boxAmplitude->value(), slopes*boxFirst->value(), boxYOffset->value()}; fitter = new ExponentialFit(app, graph, slopes == -1); fitter->setInitialGuesses(x_init); } if (fitter->setDataFromCurve(boxName->currentText(), boxStart->value(), c->maxXValue())){ fitter->setColor(boxColor->currentItem()); fitter->scaleErrors(app->fit_scale_errors); fitter->setOutputPrecision(app->fit_output_precision); fitter->generateFunction(app->generateUniformFitPoints, app->fitPoints); fitter->fit(); double *results = fitter->results(); boxFirst->setValue(results[1]); if (slopes < 2){ boxAmplitude->setValue(results[0]); boxYOffset->setValue(results[2]); } else if (slopes == 2){ boxSecond->setValue(results[3]); boxYOffset->setValue(results[4]); } else if (slopes == 3){ boxSecond->setValue(results[3]); boxThird->setValue(results[5]); boxYOffset->setValue(results[6]); } } }
//! 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()]); }
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)); };
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; }