38 const QStringList &curvesIncluded,
40 const QString &delimiter,
47 unsigned int &numWritesSoFar)
const
51 int curveCount = curvesIncluded.count();
52 int xThetaCount = xThetaValues.count();
53 QVector<QVector<QString*> > yRadiusValues (curveCount, QVector<QString*> (xThetaCount));
54 initializeYRadiusValues (curvesIncluded,
57 loadYRadiusValues (modelExportOverride,
69 outputXThetaYRadiusValues (modelExportOverride,
86 const QStringList &curvesIncluded,
88 const QString &delimiter,
95 unsigned int &numWritesSoFar)
const
99 QStringList::const_iterator itr;
100 for (itr = curvesIncluded.begin(); itr != curvesIncluded.end(); itr++) {
103 const int CURVE_COUNT = 1;
104 QString curveIncluded = *itr;
105 QStringList curvesIncludedIter (curveIncluded);
107 int xThetaCount = xThetaValues.count();
108 QVector<QVector<QString*> > yRadiusValues (CURVE_COUNT, QVector<QString*> (xThetaCount));
109 initializeYRadiusValues (curvesIncludedIter,
112 loadYRadiusValues (modelExportOverride,
123 outputXThetaYRadiusValues (modelExportOverride,
143 unsigned int &numWritesSoFar)
const
171 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
181 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
196 if (xThetaValuesMerged.count() > 0) {
200 exportAllPerLineXThetaValuesMerged (modelExportOverride,
214 exportOnePerLineXThetaValuesMerged (modelExportOverride,
231void ExportFileFunctions::initializeYRadiusValues (
const QStringList &curvesIncluded,
233 QVector<QVector<QString*> > &yRadiusValues)
const
238 int curveCount = curvesIncluded.count();
239 int xThetaCount = xThetaValuesMerged.count();
240 for (
int row = 0; row < xThetaCount; row++) {
241 for (
int col = 0; col < curveCount; col++) {
242 yRadiusValues [col] [row] =
new QString;
247double ExportFileFunctions::linearlyInterpolate (
const Points &points,
256 QPointF posGraphBefore;
257 bool foundIt =
false;
258 for (
int ip = 0; !foundIt && (ip < points.count()); ip++) {
260 const Point &point = points.at (ip);
269 if (xThetaValue <= posGraph.x() && (ip > 0)) {
284 posGraphBefore = posGraph;
289 if (points.count() > 1) {
293 int N = points.count();
294 const Point &pointLast = points.at (N - 1);
295 const Point &pointBefore = points.at (N - 2);
296 QPointF posGraphLast;
306 }
else if (points.count() == 1) {
309 yRadius = posGraphBefore.y();
324 const QStringList &curvesIncluded,
331 QVector<QVector<QString*> > &yRadiusValues)
const
336 int curveCount = curvesIncluded.count();
337 for (
int col = 0; col < curveCount; col++) {
339 const QString curveName = curvesIncluded.at (col);
347 loadYRadiusValuesForCurveRaw (document.
modelCoords(),
356 yRadiusValues [col]);
362 loadYRadiusValuesForCurveInterpolatedSmooth (document.
modelCoords(),
373 yRadiusValues [col]);
377 loadYRadiusValuesForCurveInterpolatedStraight (document.
modelCoords(),
386 yRadiusValues [col]);
392void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedSmooth (
const DocumentModelCoords &modelCoords,
400 const QString &curveName,
403 QVector<QString*> &yRadiusValues)
const
409 vector<SplinePair> xy;
410 ExportOrdinalsSmooth ordinalsSmooth;
420 FormatCoordsUnits format;
421 QString dummyXThetaOut;
423 if (points.count() == 0) {
426 for (
int row = 0; row < xThetaValues.count(); row++) {
427 *(yRadiusValues [row]) =
"";
430 }
else if (points.count() == 1 ||
431 points.count() == 2) {
434 for (
int row = 0; row < xThetaValues.count(); row++) {
436 double xTheta = xThetaValues.at (row);
438 if (points.count() == 1) {
439 yRadius = xy.at (0).y ();
441 double x0 = xy.at (0).x ();
442 double x1 = xy.at (1).x ();
443 double y0 = xy.at (0).y ();
444 double y1 = xy.at (1).y ();
445 double numerator = (xTheta - x0);
446 double denominator = (x1 - x0);
447 if (qAbs (denominator) < qAbs (numerator) / 1.0e6) {
449 yRadius = xy.at (0).y ();
451 double s = numerator / denominator;
452 yRadius = (1.0 - s) * y0 + s * y1;
455 if (xThetaIsNotOutOfBounds (xTheta,
465 *(yRadiusValues [row]),
468 *(yRadiusValues [row]) =
"";
478 const int MAX_ITERATIONS = 32;
488 for (
int row = 0; row < xThetaValues.count(); row++) {
490 double xTheta = xThetaValues.at (row);
492 LinearToLog linearToLog;
494 SplinePair splinePairFound = spline.findSplinePairForFunctionX (linearToLog.
linearize (xTheta, isLogXTheta),
496 double yRadius = linearToLog.
delinearize (splinePairFound.
y (),
500 if (xThetaIsNotOutOfBounds (xTheta,
510 *(yRadiusValues [row]),
513 *(yRadiusValues [row]) =
"";
520void ExportFileFunctions::loadYRadiusValuesForCurveInterpolatedStraight (
const DocumentModelCoords &modelCoords,
526 const QString &curveName,
529 QVector<QString*> &yRadiusValues)
const
533 FormatCoordsUnits format;
536 QString dummyXThetaOut;
537 for (
int row = 0; row < xThetaValues.count(); row++) {
539 double xTheta = xThetaValues.at (row);
542 *(yRadiusValues [row]) =
"";
543 if (points.count () > 0) {
545 double yRadius = linearlyInterpolate (points,
550 if (xThetaIsNotOutOfBounds (xTheta,
560 *(yRadiusValues [row]),
567void ExportFileFunctions::loadYRadiusValuesForCurveRaw (
const DocumentModelCoords &modelCoords,
573 const QString &curveName,
576 QVector<QString*> &yRadiusValues)
const
580 FormatCoordsUnits format;
584 for (
int pt = 0; pt < points.count(); pt++) {
586 const Point &point = points.at (pt);
594 double closestSeparation = 0.0;
596 for (
int row = 0; row < xThetaValues.count(); row++) {
598 double xTheta = xThetaValues.at (row);
600 double separation = qAbs (posGraph.x() - xTheta);
603 (separation < closestSeparation)) {
605 closestSeparation = separation;
612 if (xThetaIsNotOutOfBounds (posGraph.x(),
616 QString dummyXThetaOut;
623 *(yRadiusValues [rowClosest]),
626 *(yRadiusValues [rowClosest]) =
"";
635 const QStringList &curvesIncluded,
638 QVector<QVector<QString*> > &yRadiusValues,
639 const QString &delimiter,
641 unsigned int &numWritesSoFar)
const
648 modelExportOverride.
header (),
653 str << modelExportOverride.
xLabel();
654 QStringList::const_iterator itrHeader;
655 for (itrHeader = curvesIncluded.begin(); itrHeader != curvesIncluded.end(); itrHeader++) {
656 QString curveName = *itrHeader;
657 str << delimiter << curveName;
663 FormatCoordsUnits format;
664 const double DUMMY_Y_RADIUS = 1.0;
666 for (
int row = 0; row < xThetaValuesMerged.count(); row++) {
668 if (rowHasAtLeastOneYRadiusEntry (yRadiusValues,
671 double xTheta = xThetaValuesMerged.at (row);
674 QString xThetaString, yRadiusString;
686 for (
int col = 0; col < yRadiusValues.count(); col++) {
688 QString yRadiusString = *(yRadiusValues [col] [row]);
700bool ExportFileFunctions::rowHasAtLeastOneYRadiusEntry (
const QVector<QVector<QString*> > &yRadiusValues,
703 bool hasEntry =
false;
705 for (
int col = 0; col < yRadiusValues.count(); col++) {
707 QString entry = *(yRadiusValues [col] [row]);
708 if (!entry.isEmpty()) {
719bool ExportFileFunctions::xThetaIsNotOutOfBounds (
double xTheta,
720 const QString &curveName,
726 if (curveLimitsMin.contains (curveName)) {
727 ok = ok && (curveLimitsMin [curveName] <= xTheta);
730 if (curveLimitsMax.contains (curveName)) {
731 ok = ok && (xTheta <= curveLimitsMax [curveName]);
@ CONNECT_AS_FUNCTION_STRAIGHT
@ CONNECT_AS_FUNCTION_SMOOTH
QHash< QString, double > CurveLimits
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QString exportDelimiterToText(ExportDelimiter exportDelimiter, bool isGnuplotDelimiter)
@ EXPORT_LAYOUT_ALL_PER_LINE
@ EXPORT_POINTS_SELECTION_FUNCTIONS_RAW
@ EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_GRID_LINES
QList< double > ExportValuesXOrY
log4cpp::Category * mainCat
QMap< double, bool > ValuesVectorXOrY
CurveLimits curveLimitsMax() const
Endpoint maxima for each curve, if extrapolation has been disabled.
ValuesVectorXOrY xThetaValuesRaw() const
Resulting x/theta values for all included functions.
CurveLimits curveLimitsMin() const
Endpoint minima for each curve, if extrapolation has been disabled.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting,...
virtual CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Callback for collecting X/Theta independent variables, for functions, in preparation for exporting,...
virtual CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
LineStyle lineStyle() const
Get method for LineStyle.
CurveStyle curveStyle() const
Return the curve style.
const Points points() const
Return a shallow copy of the Points.
Model for DlgSettingsCoords and CmdSettingsCoords.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Storage of one imported image and the data attached to that image.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
void destroy2DArray(QVector< QVector< QString * > > &array) const
Deallocate memory for array.
double linearlyInterpolateYRadiusFromTwoPoints(double xThetaValue, const DocumentModelCoords &modelCoords, const QPointF &posGraphBefore, const QPointF &posGraph) const
Interpolate (if xThetaValue is between posGraphBefore.x() and posGraph.x()) or extrapolate (if xTheta...
QString wrapInDoubleQuotesIfNeeded(const DocumentModelExportFormat &modelExportOverride, const QString &valueString) const
RFC 4180 says if values are delimited by a comma AND a value has commas in it (for locale like Englis...
QString gnuplotComment() const
Gnuplot comment delimiter.
QStringList curvesToInclude(const DocumentModelExportFormat &modelExportOverride, const Document &document, const QStringList &curvesGraphsNames, CurveConnectAs curveConnectAs1, CurveConnectAs curveConnectAs2) const
Identify curves to include in export. The specified DocumentModelExportFormat overrides same data in ...
void insertLineSeparator(bool isFirst, ExportHeader exportHeader, QTextStream &str) const
Insert line(s) between successive sets of curves.
ExportFileFunctions()
Single constructor.
void exportToFile(const DocumentModelExportFormat &modelExportOverride, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, QTextStream &str, unsigned int &numWritesSoFar) const
Export Document points according to the settings.
void loadSplinePairsWithTransformation(const Points &points, const Transformation &transformation, bool isLogXTheta, bool isLogYRadius, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, converting screen coordinates to graph coor...
Creates the set of merged x/theta values for exporting functions, using interpolation.
ExportValuesXOrY xThetaValues() const
Resulting x/theta values for all included functions.
CurveConnectAs curveConnectAs() const
Get method for connect type.
double delinearize(double value, bool isLog) const
Convert linear coordinates to log. This is a noop if the output is supposed to be linear.
double linearize(double value, bool isLog) const
Convert log coordinates to linear. This is a noop if the input is already linear.
Model for DlgSettingsMainWindow.
QPointF posScreen() const
Accessor for screen position.
double y() const
Get method for y.
#define LOG4CPP_INFO_S(logger)