Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations Friends Pages
ExportFileAbstractBase.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CoordScale.h"
8 #include "CurveConnectAs.h"
9 #include "Document.h"
10 #include "DocumentModelCoords.h"
11 #include "EngaugeAssert.h"
12 #include "ExportFileAbstractBase.h"
13 #include "Logger.h"
14 #include <qdebug.h>
15 #include <qmath.h>
16 #include <QTextStream>
17 #include "Transformation.h"
18 
19 using namespace std;
20 
22 {
23 }
24 
26  const Document &document,
27  const QStringList &curvesGraphsNames,
28  CurveConnectAs curveConnectAs1,
29  CurveConnectAs curveConnectAs2) const
30 {
31  LOG4CPP_INFO_S ((*mainCat)) << "ExportFileAbstractBase::curvesToInclude";
32 
33  QStringList curvesToInclude;
34 
35  // Build a list of curves to include by subtracting the excluded curves from the the complete list.
36  // Special case is to use only first included curve if appropriate flag is set
37  QStringList::const_iterator itr;
38  for (itr = curvesGraphsNames.begin(); itr != curvesGraphsNames.end(); itr++) {
39 
40  QString curvesGraphName = *itr;
41 
42  if (!modelExportOverride.curveNamesNotExported().contains (curvesGraphName)) {
43 
44  const Curve *curve = document.curveForCurveName(curvesGraphName);
45  ENGAUGE_CHECK_PTR (curve);
46 
47  // Not excluded which means it gets included, but only if it is a function
48  if (curve->curveStyle().lineStyle().curveConnectAs() == curveConnectAs1 ||
49  curve->curveStyle().lineStyle().curveConnectAs() == curveConnectAs2) {
50 
51  curvesToInclude.push_back (curvesGraphName);
52  }
53  }
54  }
55 
56  return curvesToInclude;
57 }
58 
59 void ExportFileAbstractBase::destroy2DArray (QVector<QVector<QString*> > &array) const
60 {
61  LOG4CPP_INFO_S ((*mainCat)) << "ExportFileAbstractBase::destroy2DArray";
62 
63  int colCount = array.count();
64  int rowCount = array [0].count();
65  for (int row = 0; row < rowCount; row++) {
66  for (int col = 0; col < colCount; col++) {
67  delete array [col] [row];
68  }
69  }
70 }
71 
73 {
74  return QString ("# ");
75 }
76 
78  ExportHeader exportHeader,
79  QTextStream &str) const
80 {
81  // Insert line(s) between previous curve and this curve
82  if (!isFirst) {
83  if (exportHeader == EXPORT_HEADER_GNUPLOT) {
84  str << "\n\n"; // Gnuplot requires two blank lines between curves
85  } else {
86  str << "\n"; // Single blank line
87  }
88  }
89 }
90 
92  const DocumentModelCoords &modelCoords,
93  const QPointF &posGraphBefore,
94  const QPointF &posGraph) const
95 {
96  // X coordinate scaling is linear or log
97  double s;
98  if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
99  s = (xThetaValue - posGraphBefore.x()) / (posGraph.x() - posGraphBefore.x());
100  } else {
101  s = (qLn (xThetaValue) - qLn (posGraphBefore.x())) / (qLn (posGraph.x()) - qLn (posGraphBefore.x()));
102  }
103 
104  // Y coordinate scaling is linear or log
105  double yRadius;
106  if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
107  yRadius = (1.0 - s) * posGraphBefore.y() + s * posGraph.y();
108  } else {
109  yRadius = qExp ((1.0 - s) * qLn (posGraphBefore.y()) + s * qLn (posGraph.y()));
110  }
111 
112  return yRadius;
113 }
114 
116  const QString &valueString) const
117 {
118  QString newValueString = valueString;
119 
120  if ((modelExportOverride.delimiter () == EXPORT_DELIMITER_COMMA) &&
121  (valueString.indexOf (",") >= 0)) {
122 
123  // Eliminate ambiguities according to RFC 4180
124  newValueString = QString ("\"%1\"").arg (valueString);
125  }
126 
127  return newValueString;
128 }
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
void insertLineSeparator(bool isFirst, ExportHeader exportHeader, QTextStream &str) const
Insert line(s) between successive sets of curves.
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...
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
LineStyle lineStyle() const
Get method for LineStyle.
Definition: CurveStyle.cpp:26
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 ...
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
QString gnuplotComment() const
Gnuplot comment delimiter.
ExportDelimiter delimiter() const
Get method for delimiter.
QStringList curveNamesNotExported() const
Get method for curve names not exported.
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
Container for one set of digitized Points.
Definition: Curve.h:33
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...
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
Definition: Document.cpp:331
CurveStyle curveStyle() const
Return the curve style.
Definition: Curve.cpp:148
void destroy2DArray(QVector< QVector< QString * > > &array) const
Deallocate memory for array.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Definition: LineStyle.cpp:63
ExportFileAbstractBase()
Single constructor.