Engauge Digitizer  2
TestExport.cpp
1 #include "CurveConnectAs.h"
2 #include "Document.h"
3 #include "DocumentModelExportFormat.h"
4 #include "ExportFileFunctions.h"
5 #include "ExportValuesXOrY.h"
6 #include "LineStyle.h"
7 #include "Logger.h"
8 #include "MainWindow.h"
9 #include "MainWindowModel.h"
10 #include "PointStyle.h"
11 #include <QImage>
12 #include <qmath.h>
13 #include <QtTest/QtTest>
14 #include "Spline.h"
15 #include "SplinePair.h"
16 #include "Test/TestExport.h"
17 #include "Transformation.h"
18 
19 QTEST_MAIN (TestExport)
20 
21 using namespace std;
22 
23 TestExport::TestExport(QObject *parent) :
24  QObject(parent)
25 {
26 }
27 
28 void TestExport::cleanupTestCase ()
29 {
30 
31 }
32 
33 void TestExport::initTestCase ()
34 {
35  const QString NO_ERROR_REPORT_LOG_FILE;
36  const QString NO_REGRESSION_OPEN_FILE;
37  const bool NO_GNUPLOT_LOG_FILES = false;
38  const bool NO_REGRESSION_IMPORT = false;
39  const bool NO_RESET = false;
40  const bool DEBUG_FLAG = false;
41  const QStringList NO_LOAD_STARTUP_FILES;
42 
43  initializeLogging ("engauge_test",
44  "engauge_test.log",
45  DEBUG_FLAG);
46 
47  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
48  NO_REGRESSION_OPEN_FILE,
49  NO_GNUPLOT_LOG_FILES,
50  NO_REGRESSION_IMPORT,
51  NO_RESET,
52  NO_LOAD_STARTUP_FILES);
53  w.show ();
54 }
55 
56 void TestExport::testLogExtrapolationFunctionsAll ()
57 {
58  const QString CURVE_NAME ("Curve1");
59  const QString DELIMITER (" ");
60  const int LINE_WIDTH = 2, POINT_LINE_WIDTH = 1;
61  const ColorPalette LINE_COLOR = COLOR_PALETTE_BLACK, POINT_COLOR = COLOR_PALETTE_BLACK;
62  const int RADIUS = 5;
63 
64  QImage nullImage;
65  DocumentModelCoords modelCoords;
66  DocumentModelExportFormat modelExportOverride;
67  DocumentModelGeneral modelGeneral;
68  Document document (nullImage);
69  MainWindowModel modelMainWindow;
70  QStringList curvesIncluded (CURVE_NAME);
71  ExportValuesXOrY xThetaValues;
72  Transformation transformation;
73  QString dummy;
74  QTextStream str (&dummy);
75 
76  CurveStyles curveStyles (document.coordSystem ());
77  CurveStyle curveStyle (LineStyle (LINE_WIDTH,
78  LINE_COLOR,
79  CONNECT_AS_FUNCTION_SMOOTH),
80  PointStyle (POINT_SHAPE_CIRCLE,
81  RADIUS,
82  POINT_LINE_WIDTH,
83  POINT_COLOR));
84  curveStyles.setCurveStyle (CURVE_NAME, curveStyle);
85  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
86  modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
87  modelCoords.setCoordsType (COORDS_TYPE_CARTESIAN);
88  modelGeneral.setCursorSize (3);
89  modelGeneral.setExtraPrecision (1);
90 
91  document.setModelCurveStyles (curveStyles);
92  document.setModelCoords (modelCoords);
93  document.setModelGeneral (modelGeneral);
94 
95  modelExportOverride.setPointsSelectionFunctions (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
96  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (845, 305), "Curve1\t0", 0);
97  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (850, 294), "Curve1\t1", 1);
98  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (862, 272), "Curve1\t2", 2);
99  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (876, 244), "Curve1\t3", 3);
100  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (887, 222), "Curve1\t4", 4);
101  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (899, 200), "Curve1\t5", 5);
102  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (910, 177), "Curve1\t6", 6);
103  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (922, 155), "Curve1\t7", 7);
104  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (933, 133), "Curve1\t8", 8);
105  document.addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (945, 110), "Curve1\t9", 9);
106  xThetaValues << 0.0009999; // Just outside of the coordinates added to the document
107  xThetaValues << 0.001;
108  xThetaValues << 0.01;
109  xThetaValues << 0.1;
110  xThetaValues << 1;
111  xThetaValues << 10;
112  xThetaValues << 100;
113  xThetaValues << 1000;
114  QTransform matrixScreen ( 51, 52, 1123,
115  548, 10, 548,
116  1, 1, 1);
117  QTransform matrixGraph (qLn (0.001), qLn (0.001), qLn (1000),
118  qLn ( 1), qLn ( 100), qLn ( 1),
119  1, 1, 1);
120  transformation.updateTransformFromMatrices (matrixScreen,
121  matrixGraph);
122  transformation.setModelCoords (modelCoords,
123  modelGeneral,
124  modelMainWindow);
125 
126  bool success = true;
127  try {
128  bool isLogXTheta = (modelCoords.coordScaleXTheta() == COORD_SCALE_LOG);
129  bool isLogYRadius = (modelCoords.coordScaleYRadius() == COORD_SCALE_LOG);
130  unsigned int numWritesSoFar = 0;
131 
132  ExportFileFunctions exportFile;
133  exportFile.exportAllPerLineXThetaValuesMerged (modelExportOverride,
134  document,
135  modelMainWindow,
136  curvesIncluded,
137  xThetaValues,
138  DELIMITER,
139  transformation,
140  isLogXTheta,
141  isLogYRadius,
142  str,
143  numWritesSoFar);
144  }
145  catch (...)
146  {
147  success = false;
148  }
149 
150  QVERIFY (success);
151 }
void setPointsSelectionFunctions(ExportPointsSelectionFunctions exportPointsSelectionFunctions)
Set method for point selection for functions.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
void setCursorSize(int cursorSize)
Set method for effective cursor size.
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
void setModelGeneral(const DocumentModelGeneral &modelGeneral)
Set method for DocumentModelGeneral.
Definition: Document.cpp:1008
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:22
const CoordSystem & coordSystem() const
Currently active CoordSystem.
Definition: Document.cpp:297
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
void addPointGraphWithSpecifiedIdentifier(const QString &curveName, const QPointF &posScreen, const QString &identifier, double ordinal)
Add a single graph point with the specified point identifer. Note that PointStyle is not applied to t...
Definition: Document.cpp:205
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
void setModelCoords(const DocumentModelCoords &modelCoords)
Set method for DocumentModelCoords.
Definition: Document.cpp:970
Unit test of Export classes.
Definition: TestExport.h:7
Affine transformation between screen and graph coordinates, based on digitized axis points...
Details for a specific Point.
Definition: PointStyle.h:20
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
void setModelCurveStyles(const CurveStyles &modelCurveStyles)
Set method for CurveStyles.
Definition: Document.cpp:977
Model for DlgSettingsMainWindow.
Model for DlgSettingsCoords and CmdSettingsCoords.
Container for LineStyle and PointStyle for one Curve.
Definition: CurveStyle.h:18
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
Details for a specific Line.
Definition: LineStyle.h:19
Strategy class for exporting to a file. This strategy is external to the Document class so that class...
void setExtraPrecision(int extraPrecision)
Set method for extra digits of precision.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:86
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.
void setCoordsType(CoordsType coordsType)
Set method for coordinates type.