bool GraphWidget::loadScript(const char* szFileName) { std::ifstream ifsFile; ifsFile.open(szFileName, std::ios::in); if (!ifsFile.fail()) { int iCurveCount; float fEndTime; ifsFile >> fEndTime; if (fEndTime <= 0.0f) return false; endTime(fEndTime); ifsFile >> iCurveCount; if (iCurveCount != m_pcrvvCurves.size()) { #ifdef _DEBUG assert(0); #endif // _DEBUG return false; } for (int i = 0; i < iCurveCount; ++i) { int iType; ifsFile >> iType; curveType(i, iType); m_pcrvvCurves[i]->fromStream(ifsFile); } return true; }
/*! Draw sticks \param painter Painter \param xMap x map \param yMap y map \param from index of the first point to be painted \param to index of the last point to be painted \sa draw(), drawCurve(), drawDots() */ void PlotCurve::drawSticks(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { if (d_skip_symbols < 2) { QwtPlotCurve::drawSticks(painter, xMap, yMap, from, to); return; } double x0 = xMap.transform(baseline()); double y0 = yMap.transform(baseline()); for (int i = from; i <= to; i += d_skip_symbols) { const double xi = xMap.transform(x(i)); const double yi = yMap.transform(y(i)); if (curveType() == Xfy) { if (xi == x0) continue; QwtPainter::drawLine(painter, QPointF(x0, yi), QPointF(xi, yi)); } else { if (yi == y0) continue; QwtPainter::drawLine(painter, QPointF(xi, y0), QPointF(xi, yi)); } } }
bool GraphWidget::loadModelScript(const char* szFileName) { std::ifstream ifsFile; ifsFile.open(szFileName, std::ios::in); if (ifsFile.fail()) return false; int iModelCurveCount; // number of curves in model that is currently loaded int iFileCurveCount; // number of curves in model as reported by the ani file float fEndTime; // As of 01sp, curves for the camera show up in the left "model controls" pane. // The ani file format doesn't save the camera curves, so we don't want to count // them when we're calculating the total number of curves in the model. iModelCurveCount = m_pcrvvCurves.size() - NUM_CAM_CURVES; ifsFile >> fEndTime; if (fEndTime <= 0.0f) return false; endTime(fEndTime); ifsFile >> iFileCurveCount; if (iFileCurveCount != iModelCurveCount) { #ifdef _DEBUG assert(0); #endif // _DEBUG return false; } for (int i = 0; i < iModelCurveCount; ++i) { int iType; ifsFile >> iType; curveType(i, iType); m_pcrvvCurves[i]->fromStream(ifsFile); } return true; }
bool GraphWidget::loadCameraScript(const char* szFileName) { std::ifstream ifsFile; ifsFile.open(szFileName, std::ios::in); if (ifsFile.fail()) return false; // As of 01sp, curves for the camera show up in the left "model controls" pane. // The ani file format doesn't save the camera curves, so we don't want to count // them when we're calculating the total number of curves in the model. int iIndexCameraCurve = m_pcrvvCurves.size() - NUM_CAM_CURVES; // the first camera curve for (int i = 0; i < NUM_CAM_CURVES; i++, iIndexCameraCurve++) { int iType; ifsFile >> iType; curveType(iIndexCameraCurve, iType); m_pcrvvCurves[iIndexCameraCurve]->fromStream(ifsFile); } return true; }
QString PlotCurve::saveCurveLayout() { QString s = "<Style>" + QString::number(d_plot_style) + "</Style>\n"; if (d_plot_style == Graph::Spline) s += "<LineStyle>5</LineStyle>\n"; else if (d_plot_style == Graph::VerticalSteps) s += "<LineStyle>6</LineStyle>\n"; else s += "<LineStyle>" + QString::number(this->style()) + "</LineStyle>\n"; QPen pen = this->pen(); if (pen.style() != Qt::NoPen) { s += "<Pen>\n"; s += "\t<Color>" + pen.color().name() + "</Color>\n"; if (pen.color().alpha() != 255) s += "\t<Alpha>" + QString::number(pen.color().alpha()) + "</Alpha>\n"; s += "\t<Style>" + QString::number(pen.style()-1) + "</Style>\n"; s += "\t<Width>" + QString::number(pen.widthF()) + "</Width>\n"; s += "</Pen>\n"; } QBrush brush = this->brush(); if (brush.style() != Qt::NoBrush) { s += "<Brush>\n"; s += "\t<Color>" + brush.color().name() + "</Color>\n"; if (brush.color().alpha() != 255) s += "\t<Alpha>" + QString::number(brush.color().alpha()) + "</Alpha>\n"; s += "\t<Style>" + QString::number(PatternBox::patternIndex(brush.style())) + "</Style>\n"; s += "</Brush>\n"; } const QwtSymbol symbol = this->symbol(); if (symbol.style() != QwtSymbol::NoSymbol) { s += "<Symbol>\n"; s += "\t<Style>" + QString::number(SymbolBox::symbolIndex(symbol.style())) + "</Style>\n"; s += "\t<Size>" + QString::number(symbol.size().width()) + "</Size>\n"; s += "\t<SymbolPen>\n"; s += "\t\t<Color>" + symbol.pen().color().name() + "</Color>\n"; if (symbol.pen().color().alpha() != 255) s += "\t<Alpha>" + QString::number(symbol.pen().color().alpha()) + "</Alpha>\n"; s += "\t\t<Width>" + QString::number(symbol.pen().widthF()) + "</Width>\n"; s += "\t</SymbolPen>\n"; brush = this->brush(); if (brush.style() != Qt::NoBrush) { s += "\t<SymbolBrush>\n"; s += "\t\t<Color>" + symbol.brush().color().name() + "</Color>\n"; if (symbol.brush().color().alpha() != 255) s += "\t<Alpha>" + QString::number(symbol.brush().color().alpha()) + "</Alpha>\n"; s += "\t\t<Style>" + QString::number(PatternBox::patternIndex(symbol.brush().style())) + "</Style>\n"; s += "\t</SymbolBrush>\n"; } s += "</Symbol>\n"; } s += "<xAxis>" + QString::number(xAxis()) + "</xAxis>\n"; s += "<yAxis>" + QString::number(yAxis()) + "</yAxis>\n"; s += "<CurveType>" + QString::number(curveType()) + "</CurveType>\n"; s += "<Visible>" + QString::number(isVisible()) + "</Visible>\n"; return s; }
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; }