00001
00002
00003
00004
00005
00006
00007 #include "CallbackAddPointsInCurvesGraphs.h"
00008 #include "CallbackCheckAddPointAxis.h"
00009 #include "CallbackCheckEditPointAxis.h"
00010 #include "CallbackNextOrdinal.h"
00011 #include "CallbackRemovePointsInCurvesGraphs.h"
00012 #include "CoordSystem.h"
00013 #include "Curve.h"
00014 #include "CurvesGraphs.h"
00015 #include "CurveStyles.h"
00016 #include "DocumentSerialize.h"
00017 #include "EngaugeAssert.h"
00018 #include "EnumsToQt.h"
00019 #include <iostream>
00020 #include "Logger.h"
00021 #include "OrdinalGenerator.h"
00022 #include "Point.h"
00023 #include <QByteArray>
00024 #include <QDataStream>
00025 #include <QDebug>
00026 #include <QFile>
00027 #include <QImage>
00028 #include <QtToString.h>
00029 #include <QXmlStreamReader>
00030 #include <QXmlStreamWriter>
00031 #include "SettingsForGraph.h"
00032 #include "Transformation.h"
00033 #include "Version.h"
00034 #include "Xml.h"
00035
00036 const int FOUR_BYTES = 4;
00037
00038 CoordSystem::CoordSystem () :
00039 m_curveAxes (new Curve (AXIS_CURVE_NAME,
00040 ColorFilterSettings::defaultFilter (),
00041 CurveStyle (LineStyle::defaultAxesCurve(),
00042 PointStyle::defaultAxesCurve ())))
00043 {
00044 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::CoordSystem";
00045
00046 SettingsForGraph settingsForGraph;
00047
00048
00049 for (int indexOneBased = 1; indexOneBased <= settingsForGraph.numberOfCurvesForImport (); indexOneBased++) {
00050
00051 QString curveName = settingsForGraph.defaultCurveName (indexOneBased,
00052 DEFAULT_GRAPH_CURVE_NAME);
00053 m_curvesGraphs.addGraphCurveAtEnd (Curve (curveName,
00054 ColorFilterSettings::defaultFilter (),
00055 CurveStyle (LineStyle::defaultGraphCurve (m_curvesGraphs.numCurves ()),
00056 PointStyle::defaultGraphCurve (m_curvesGraphs.numCurves ()))));
00057
00058 resetSelectedCurveNameIfNecessary ();
00059 }
00060 }
00061
00062 void CoordSystem::addGraphCurveAtEnd (const QString &curveName)
00063 {
00064 m_curvesGraphs.addGraphCurveAtEnd (Curve (curveName,
00065 ColorFilterSettings::defaultFilter (),
00066 CurveStyle (LineStyle::defaultGraphCurve(m_curvesGraphs.numCurves()),
00067 PointStyle::defaultGraphCurve(m_curvesGraphs.numCurves()))));
00068
00069 resetSelectedCurveNameIfNecessary ();
00070 }
00071
00072 void CoordSystem::addPointAxisWithGeneratedIdentifier (const QPointF &posScreen,
00073 const QPointF &posGraph,
00074 QString &identifier,
00075 double ordinal,
00076 bool isXOnly)
00077 {
00078 Point point (AXIS_CURVE_NAME,
00079 posScreen,
00080 posGraph,
00081 ordinal,
00082 isXOnly);
00083 m_curveAxes->addPoint (point);
00084
00085 identifier = point.identifier();
00086
00087 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointAxisWithGeneratedIdentifier"
00088 << " ordinal=" << ordinal
00089 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
00090 << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
00091 << " identifier=" << identifier.toLatin1 ().data ();
00092 }
00093
00094 void CoordSystem::addPointAxisWithSpecifiedIdentifier (const QPointF &posScreen,
00095 const QPointF &posGraph,
00096 const QString &identifier,
00097 double ordinal,
00098 bool isXOnly)
00099 {
00100 Point point (AXIS_CURVE_NAME,
00101 identifier,
00102 posScreen,
00103 posGraph,
00104 ordinal,
00105 isXOnly);
00106 m_curveAxes->addPoint (point);
00107
00108 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointAxisWithSpecifiedIdentifier"
00109 << " ordinal=" << ordinal
00110 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
00111 << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
00112 << " identifier=" << identifier.toLatin1 ().data ();
00113 }
00114
00115 void CoordSystem::addPointGraphWithGeneratedIdentifier (const QString &curveName,
00116 const QPointF &posScreen,
00117 QString &identifier,
00118 double ordinal)
00119 {
00120 Point point (curveName,
00121 posScreen,
00122 ordinal);
00123 m_curvesGraphs.addPoint (point);
00124
00125 identifier = point.identifier();
00126
00127 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointGraphWithGeneratedIdentifier"
00128 << " ordinal=" << ordinal
00129 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
00130 << " identifier=" << identifier.toLatin1 ().data ();
00131 }
00132
00133 void CoordSystem::addPointGraphWithSpecifiedIdentifier (const QString &curveName,
00134 const QPointF &posScreen,
00135 const QString &identifier,
00136 double ordinal)
00137 {
00138 Point point (curveName,
00139 identifier,
00140 posScreen,
00141 ordinal);
00142 m_curvesGraphs.addPoint (point);
00143
00144 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointGraphWithSpecifiedIdentifier"
00145 << " ordinal=" << ordinal
00146 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
00147 << " identifier=" << identifier.toLatin1 ().data ();
00148 }
00149
00150 void CoordSystem::addPointsInCurvesGraphs (CurvesGraphs &curvesGraphs)
00151 {
00152 CallbackAddPointsInCurvesGraphs ftor (*this);
00153
00154 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00155 &CallbackAddPointsInCurvesGraphs::callback);
00156
00157 curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00158 }
00159
00160 bool CoordSystem::bytesIndicatePreVersion6 (const QByteArray &bytes) const
00161 {
00162 QByteArray preVersion6MagicNumber;
00163 preVersion6MagicNumber.resize (FOUR_BYTES);
00164
00165
00166 preVersion6MagicNumber[0] = '\x00';
00167 preVersion6MagicNumber[1] = '\x00';
00168 preVersion6MagicNumber[2] = '\xCA';
00169 preVersion6MagicNumber[3] = '\xFE';
00170
00171 return (bytes == preVersion6MagicNumber);
00172 }
00173
00174 void CoordSystem::checkAddPointAxis (const QPointF &posScreen,
00175 const QPointF &posGraph,
00176 bool &isError,
00177 QString &errorMessage,
00178 bool isXOnly,
00179 DocumentAxesPointsRequired documentAxesPointsRequired)
00180 {
00181 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::checkAddPointAxis"
00182 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
00183 << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ();
00184
00185 CallbackCheckAddPointAxis ftor (m_modelCoords,
00186 posScreen,
00187 posGraph,
00188 documentAxesPointsRequired,
00189 isXOnly);
00190
00191 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00192 &CallbackCheckAddPointAxis::callback);
00193 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00194
00195 isError = ftor.isError ();
00196 errorMessage = ftor.errorMessage ();
00197 }
00198
00199 void CoordSystem::checkEditPointAxis (const QString &pointIdentifier,
00200 const QPointF &posScreen,
00201 const QPointF &posGraph,
00202 bool &isError,
00203 QString &errorMessage,
00204 DocumentAxesPointsRequired documentAxesPointsRequired)
00205 {
00206 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::checkEditPointAxis"
00207 << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ();
00208
00209 CallbackCheckEditPointAxis ftor (m_modelCoords,
00210 pointIdentifier,
00211 posScreen,
00212 posGraph,
00213 documentAxesPointsRequired);
00214
00215 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00216 &CallbackCheckEditPointAxis::callback);
00217 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00218
00219 isError = ftor.isError ();
00220 errorMessage = ftor.errorMessage ();
00221 }
00222
00223 const Curve &CoordSystem::curveAxes () const
00224 {
00225 ENGAUGE_CHECK_PTR (m_curveAxes);
00226
00227 return *m_curveAxes;
00228 }
00229
00230 Curve *CoordSystem::curveForCurveName (const QString &curveName)
00231 {
00232 if (curveName == AXIS_CURVE_NAME) {
00233
00234 return m_curveAxes;
00235
00236 } else {
00237
00238 return m_curvesGraphs.curveForCurveName (curveName);
00239
00240 }
00241 }
00242
00243 const Curve *CoordSystem::curveForCurveName (const QString &curveName) const
00244 {
00245 if (curveName == AXIS_CURVE_NAME) {
00246
00247 return m_curveAxes;
00248
00249 } else {
00250
00251 return m_curvesGraphs.curveForCurveName (curveName);
00252
00253 }
00254 }
00255
00256 const CurvesGraphs &CoordSystem::curvesGraphs () const
00257 {
00258 return m_curvesGraphs;
00259 }
00260
00261 QStringList CoordSystem::curvesGraphsNames() const
00262 {
00263 return m_curvesGraphs.curvesGraphsNames();
00264 }
00265
00266 int CoordSystem::curvesGraphsNumPoints(const QString &curveName) const
00267 {
00268 return m_curvesGraphs.curvesGraphsNumPoints(curveName);
00269 }
00270
00271 void CoordSystem::editPointAxis (const QPointF &posGraph,
00272 const QString &identifier)
00273 {
00274 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::editPointAxis"
00275 << " posGraph=(" << posGraph.x () << ", " << posGraph.y () << ") identifier="
00276 << " identifier=" << identifier.toLatin1 ().data ();
00277
00278 m_curveAxes->editPointAxis (posGraph,
00279 identifier);
00280 }
00281
00282 void CoordSystem::editPointGraph (bool isX,
00283 bool isY,
00284 double x,
00285 double y,
00286 const QStringList &identifiers,
00287 const Transformation &transformation)
00288 {
00289 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::editPointGraph posGraph=("
00290 << " x=" << (isX ? QString::number (x).toLatin1().data() : "")
00291 << " y=" << (isY ? QString::number (y).toLatin1().data() : "")
00292 << ") identifiers=" << identifiers.join(" ").toLatin1 ().data ();
00293
00294 m_curvesGraphs.editPointGraph (isX,
00295 isY,
00296 x,
00297 y,
00298 identifiers,
00299 transformation);
00300 }
00301
00302 bool CoordSystem::isXOnly (const QString &pointIdentifier) const
00303 {
00304 return m_curveAxes->isXOnly (pointIdentifier);
00305 }
00306
00307 void CoordSystem::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00308 {
00309 ENGAUGE_CHECK_PTR (m_curveAxes);
00310
00311 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00312 }
00313
00314 void CoordSystem::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00315 {
00316 ENGAUGE_CHECK_PTR (m_curveAxes);
00317
00318 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00319 }
00320
00321 void CoordSystem::iterateThroughCurveSegments (const QString &curveName,
00322 const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00323 {
00324 if (curveName == AXIS_CURVE_NAME) {
00325 m_curveAxes->iterateThroughCurveSegments(ftorWithCallback);
00326 } else {
00327 m_curvesGraphs.iterateThroughCurveSegments(curveName,
00328 ftorWithCallback);
00329 }
00330 }
00331
00332 void CoordSystem::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00333 {
00334 ENGAUGE_CHECK_PTR (m_curveAxes);
00335
00336 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00337 }
00338
00339 void CoordSystem::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00340 {
00341 ENGAUGE_CHECK_PTR (m_curveAxes);
00342
00343 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00344 }
00345
00346 bool CoordSystem::loadCurvesFile(const QString & )
00347 {
00348 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadCurvesFile";
00349
00350 return true;
00351 }
00352
00353 void CoordSystem::loadPreVersion6 (QDataStream &str,
00354 double version,
00355 DocumentAxesPointsRequired &documentAxesPointsRequired)
00356 {
00357 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadPreVersion6";
00358
00359 qint32 int32;
00360 double dbl, radius = 0.0;
00361 QString st;
00362
00363 str >> st;
00364 str >> st;
00365 str >> int32;
00366 m_modelCoords.setCoordsType((CoordsType) int32);
00367 if (version >= 3) {
00368 str >> (double &) radius;
00369 }
00370 m_modelCoords.setOriginRadius(radius);
00371 str >> int32;
00372 m_modelCoords.setCoordUnitsRadius(COORD_UNITS_NON_POLAR_THETA_NUMBER);
00373 m_modelCoords.setCoordUnitsTheta((CoordUnitsPolarTheta) int32);
00374 str >> int32;
00375 m_modelCoords.setCoordScaleXTheta((CoordScale) int32);
00376 str >> int32;
00377 m_modelCoords.setCoordScaleYRadius((CoordScale) int32);
00378
00379 str >> int32;
00380 m_modelExport.setDelimiter((ExportDelimiter) int32);
00381 str >> int32;
00382 m_modelExport.setLayoutFunctions((ExportLayoutFunctions) int32);
00383 str >> int32;
00384 m_modelExport.setPointsSelectionFunctions((ExportPointsSelectionFunctions) int32);
00385 m_modelExport.setPointsSelectionRelations(EXPORT_POINTS_SELECTION_RELATIONS_RAW);
00386 m_modelExport.setPointsIntervalUnitsFunctions((ExportPointsIntervalUnits) int32);
00387 m_modelExport.setPointsIntervalUnitsRelations((ExportPointsIntervalUnits) int32);
00388 str >> int32;
00389 m_modelExport.setHeader((ExportHeader) int32);
00390 if (version >= 5.1) {
00391 str >> st;
00392 if (m_modelCoords.coordsType() == COORDS_TYPE_CARTESIAN) {
00393 m_modelExport.setXLabel(st);
00394 }
00395 str >> st;
00396 if (m_modelCoords.coordsType() == COORDS_TYPE_POLAR) {
00397 m_modelExport.setXLabel(st);
00398 }
00399 }
00400
00401
00402 str >> int32;
00403 str >> dbl;
00404 str >> int32;
00405 m_modelGridRemoval.setRemoveDefinedGridLines(int32);
00406 str >> int32;
00407 str >> int32;
00408 m_modelGridRemoval.setCountX(int32);
00409 str >> int32;
00410 m_modelGridRemoval.setCountY(int32);
00411 str >> int32;
00412 m_modelGridRemoval.setGridCoordDisableX((GridCoordDisable) int32);
00413 str >> int32;
00414 m_modelGridRemoval.setGridCoordDisableY((GridCoordDisable) int32);
00415 str >> dbl;
00416 m_modelGridRemoval.setStartX(dbl);
00417 str >> dbl;
00418 m_modelGridRemoval.setStartY(dbl);
00419 str >> dbl;
00420 m_modelGridRemoval.setStepX(dbl);
00421 str >> dbl;
00422 m_modelGridRemoval.setStepY(dbl);
00423 str >> dbl;
00424 m_modelGridRemoval.setStopX(dbl);
00425 str >> dbl;
00426 m_modelGridRemoval.setStopY(dbl);
00427 str >> dbl;
00428 m_modelGridRemoval.setCloseDistance(dbl);
00429 str >> int32;
00430 if (version >= 5) {
00431 QColor color;
00432 str >> color;
00433 } else {
00434 str >> int32;
00435 }
00436 str >> int32;
00437 str >> int32;
00438 str >> dbl;
00439
00440 str >> int32;
00441 m_modelGridDisplay.setStable(int32);
00442 str >> int32;
00443 m_modelGridDisplay.setCountX(int32);
00444 str >> int32;
00445 m_modelGridDisplay.setCountY(int32);
00446 str >> int32;
00447 m_modelGridDisplay.setDisableX((GridCoordDisable) int32);
00448 str >> int32;
00449 m_modelGridDisplay.setDisableY((GridCoordDisable) int32);
00450 str >> dbl;
00451 m_modelGridDisplay.setStartX (dbl);
00452 str >> dbl;
00453 m_modelGridDisplay.setStartY (dbl);
00454 str >> dbl;
00455 m_modelGridDisplay.setStepX (dbl);
00456 str >> dbl;
00457 m_modelGridDisplay.setStepY (dbl);
00458 str >> dbl;
00459 m_modelGridDisplay.setStopX (dbl);
00460 str >> dbl;
00461 m_modelGridDisplay.setStopY (dbl);
00462
00463 str >> int32;
00464 m_modelSegments.setMinLength(int32);
00465 str >> int32;
00466 m_modelSegments.setPointSeparation(int32);
00467 str >> int32;
00468 m_modelSegments.setLineWidth(int32);
00469 str >> int32;
00470 m_modelSegments.setLineColor((ColorPalette) int32);
00471
00472 str >> int32;
00473 str >> int32;
00474 m_modelPointMatch.setMaxPointSize(int32);
00475 str >> int32;
00476 m_modelPointMatch.setPaletteColorAccepted((ColorPalette) int32);
00477 str >> int32;
00478 m_modelPointMatch.setPaletteColorRejected((ColorPalette) int32);
00479 if (version < 4) {
00480 m_modelPointMatch.setPaletteColorCandidate(COLOR_PALETTE_BLUE);
00481 } else {
00482 str >> int32;
00483 m_modelPointMatch.setPaletteColorCandidate((ColorPalette) int32);
00484 }
00485
00486 str >> int32;
00487 str >> int32;
00488 str >> int32;
00489 str >> int32;
00490 str >> int32;
00491 str >> int32;
00492 str >> int32;
00493 str >> int32;
00494 str >> int32;
00495 str >> int32;
00496 str >> int32;
00497
00498
00499 Curve *curveAxesIn = new Curve (str);
00500 Curve *curveScaleIn = new Curve (str);
00501 if (curveScaleIn->numPoints() == 2) {
00502
00503 documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_2;
00504 m_curveAxes = curveScaleIn;
00505 m_curveAxes->setCurveName (AXIS_CURVE_NAME);
00506 delete curveAxesIn;
00507 } else {
00508
00509 documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
00510 m_curveAxes = curveAxesIn;
00511 delete curveScaleIn;
00512 }
00513 m_curvesGraphs.loadPreVersion6 (str);
00514
00515
00516 if (m_curveAxes->numPoints () >= documentAxesPointsRequired) {
00517 m_modelGridRemoval.setStable();
00518 }
00519
00520 resetSelectedCurveNameIfNecessary ();
00521 }
00522
00523 void CoordSystem::loadVersion6 (QXmlStreamReader &reader,
00524 DocumentAxesPointsRequired &documentAxesPointsRequired)
00525 {
00526 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadVersion6";
00527
00528 documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
00529
00530
00531 while (!reader.atEnd() &&
00532 !reader.hasError()) {
00533 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
00534
00535 if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
00536 (tokenType == QXmlStreamReader::EndElement)) {
00537
00538
00539 break;
00540 }
00541
00542
00543 if (tokenType == QXmlStreamReader::StartElement) {
00544
00545
00546 QString tag = reader.name().toString();
00547 if (tag == DOCUMENT_SERIALIZE_AXES_CHECKER){
00548 m_modelAxesChecker.loadXml (reader);
00549 } else if (tag == DOCUMENT_SERIALIZE_COORDS) {
00550 m_modelCoords.loadXml (reader);
00551 } else if (tag == DOCUMENT_SERIALIZE_CURVE) {
00552 m_curveAxes = new Curve (reader);
00553 } else if (tag == DOCUMENT_SERIALIZE_CURVES_GRAPHS) {
00554 m_curvesGraphs.loadXml (reader);
00555 } else if (tag == DOCUMENT_SERIALIZE_DIGITIZE_CURVE) {
00556 m_modelDigitizeCurve.loadXml (reader);
00557 } else if (tag == DOCUMENT_SERIALIZE_EXPORT) {
00558 m_modelExport.loadXml (reader);
00559 } else if (tag == DOCUMENT_SERIALIZE_GENERAL || tag == DOCUMENT_SERIALIZE_COMMON) {
00560 m_modelGeneral.loadXml (reader);
00561 } else if (tag == DOCUMENT_SERIALIZE_GRID_REMOVAL) {
00562 m_modelGridRemoval.loadXml (reader);
00563 } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
00564 ENGAUGE_ASSERT (false);
00565 } else if (tag == DOCUMENT_SERIALIZE_POINT_MATCH) {
00566 m_modelPointMatch.loadXml (reader);
00567 } else if (tag == DOCUMENT_SERIALIZE_SEGMENTS) {
00568 m_modelSegments.loadXml (reader);
00569 } else {
00570 m_successfulRead = false;
00571 m_reasonForUnsuccessfulRead = QString ("%1 '%2' %3")
00572 .arg (QObject::tr ("Unexpected xml token"))
00573 .arg (tag)
00574 .arg ("encountered");
00575 break;
00576 }
00577 }
00578 }
00579
00580 resetSelectedCurveNameIfNecessary ();
00581 }
00582
00583 void CoordSystem::loadVersions7AndUp (QXmlStreamReader &reader)
00584 {
00585 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadVersions7AndUp";
00586
00587
00588 while (!reader.atEnd() &&
00589 !reader.hasError()) {
00590 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
00591
00592 if ((reader.name() == DOCUMENT_SERIALIZE_COORD_SYSTEM) &&
00593 (tokenType == QXmlStreamReader::EndElement)) {
00594
00595
00596 break;
00597 }
00598
00599
00600 if (tokenType == QXmlStreamReader::StartElement) {
00601
00602
00603 QString tag = reader.name().toString();
00604 if (tag == DOCUMENT_SERIALIZE_AXES_CHECKER){
00605 m_modelAxesChecker.loadXml (reader);
00606 } else if (tag == DOCUMENT_SERIALIZE_COORDS) {
00607 m_modelCoords.loadXml (reader);
00608 } else if (tag == DOCUMENT_SERIALIZE_CURVE) {
00609 m_curveAxes = new Curve (reader);
00610 } else if (tag == DOCUMENT_SERIALIZE_CURVES_GRAPHS) {
00611 m_curvesGraphs.loadXml (reader);
00612 } else if (tag == DOCUMENT_SERIALIZE_DIGITIZE_CURVE) {
00613 m_modelDigitizeCurve.loadXml (reader);
00614 } else if (tag == DOCUMENT_SERIALIZE_EXPORT) {
00615 m_modelExport.loadXml (reader);
00616 } else if (tag == DOCUMENT_SERIALIZE_GENERAL || tag == DOCUMENT_SERIALIZE_COMMON) {
00617 m_modelGeneral.loadXml (reader);
00618 } else if (tag == DOCUMENT_SERIALIZE_GRID_DISPLAY) {
00619 m_modelGridDisplay.loadXml (reader);
00620 } else if (tag == DOCUMENT_SERIALIZE_GRID_REMOVAL) {
00621 m_modelGridRemoval.loadXml (reader);
00622 } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
00623 ENGAUGE_ASSERT (false);
00624 } else if (tag == DOCUMENT_SERIALIZE_POINT_MATCH) {
00625 m_modelPointMatch.loadXml (reader);
00626 } else if (tag == DOCUMENT_SERIALIZE_SEGMENTS) {
00627 m_modelSegments.loadXml (reader);
00628 } else {
00629 m_successfulRead = false;
00630 m_reasonForUnsuccessfulRead = QString ("Unexpected xml token '%1' encountered").arg (tag);
00631 break;
00632 }
00633 }
00634 }
00635
00636 resetSelectedCurveNameIfNecessary ();
00637 }
00638
00639 DocumentModelAxesChecker CoordSystem::modelAxesChecker() const
00640 {
00641 return m_modelAxesChecker;
00642 }
00643
00644 DocumentModelColorFilter CoordSystem::modelColorFilter() const
00645 {
00646
00647 DocumentModelColorFilter modelColorFilter(*this);
00648
00649 return modelColorFilter;
00650 }
00651
00652 DocumentModelCoords CoordSystem::modelCoords() const
00653 {
00654 return m_modelCoords;
00655 }
00656
00657 CurveStyles CoordSystem::modelCurveStyles() const
00658 {
00659
00660 CurveStyles modelCurveStyles(*this);
00661
00662 return modelCurveStyles;
00663 }
00664
00665 DocumentModelDigitizeCurve CoordSystem::modelDigitizeCurve() const
00666 {
00667 return m_modelDigitizeCurve;
00668 }
00669
00670 DocumentModelExportFormat CoordSystem::modelExport() const
00671 {
00672 return m_modelExport;
00673 }
00674
00675 DocumentModelGeneral CoordSystem::modelGeneral() const
00676 {
00677 return m_modelGeneral;
00678 }
00679
00680 DocumentModelGridDisplay CoordSystem::modelGridDisplay() const
00681 {
00682 return m_modelGridDisplay;
00683 }
00684
00685 DocumentModelGridRemoval CoordSystem::modelGridRemoval() const
00686 {
00687 return m_modelGridRemoval;
00688 }
00689
00690 DocumentModelPointMatch CoordSystem::modelPointMatch() const
00691 {
00692 return m_modelPointMatch;
00693 }
00694
00695 DocumentModelSegments CoordSystem::modelSegments() const
00696 {
00697 return m_modelSegments;
00698 }
00699
00700 void CoordSystem::movePoint (const QString &pointIdentifier,
00701 const QPointF &deltaScreen)
00702 {
00703 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00704
00705 Curve *curve = curveForCurveName (curveName);
00706 ENGAUGE_ASSERT (curve != 0);
00707 curve->movePoint (pointIdentifier,
00708 deltaScreen);
00709 }
00710
00711 int CoordSystem::nextOrdinalForCurve (const QString &curveName) const
00712 {
00713 CallbackNextOrdinal ftor (curveName);
00714
00715 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00716 &CallbackNextOrdinal::callback);
00717
00718 if (curveName == AXIS_CURVE_NAME) {
00719 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00720 } else {
00721 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00722 }
00723
00724 return ftor.nextOrdinal ();
00725 }
00726
00727 QPointF CoordSystem::positionGraph (const QString &pointIdentifier) const
00728 {
00729 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00730
00731 const Curve *curve = curveForCurveName (curveName);
00732 return curve->positionGraph (pointIdentifier);
00733 }
00734
00735 QPointF CoordSystem::positionScreen (const QString &pointIdentifier) const
00736 {
00737 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00738
00739 const Curve *curve = curveForCurveName (curveName);
00740 return curve->positionScreen (pointIdentifier);
00741 }
00742
00743 void CoordSystem::print () const
00744 {
00745 QString text;
00746 QTextStream str (&text);
00747
00748 printStream ("",
00749 str);
00750 std::cerr << text.toLatin1().data();
00751 }
00752
00753 void CoordSystem::printStream (QString indentation,
00754 QTextStream &str) const
00755 {
00756 str << indentation << "Graph\n";
00757
00758 indentation += INDENTATION_DELTA;
00759
00760
00761
00762
00763 m_curveAxes->printStream (indentation,
00764 str);
00765 m_curvesGraphs.printStream (indentation,
00766 str);
00767
00768 m_modelAxesChecker.printStream (indentation,
00769 str);
00770 m_modelCoords.printStream (indentation,
00771 str);
00772 m_modelDigitizeCurve.printStream (indentation,
00773 str);
00774 m_modelExport.printStream (indentation,
00775 str);
00776 m_modelGeneral.printStream (indentation,
00777 str);
00778 m_modelGridDisplay.printStream (indentation,
00779 str);
00780 m_modelGridRemoval.printStream (indentation,
00781 str);
00782 m_modelPointMatch.printStream (indentation,
00783 str);
00784 m_modelSegments.printStream (indentation,
00785 str);
00786 }
00787
00788 QString CoordSystem::reasonForUnsuccessfulRead () const
00789 {
00790 ENGAUGE_ASSERT (!m_successfulRead);
00791
00792 return m_reasonForUnsuccessfulRead;
00793 }
00794
00795 void CoordSystem::removePointAxis (const QString &identifier)
00796 {
00797 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::removePointAxis identifier=" << identifier.toLatin1 ().data ();
00798
00799 m_curveAxes->removePoint (identifier);
00800 }
00801
00802 void CoordSystem::removePointGraph (const QString &identifier)
00803 {
00804 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::removePointGraph identifier=" << identifier.toLatin1 ().data ();
00805
00806 m_curvesGraphs.removePoint (identifier);
00807 }
00808
00809 void CoordSystem::removePointsInCurvesGraphs (CurvesGraphs &curvesGraphs)
00810 {
00811 CallbackRemovePointsInCurvesGraphs ftor (*this);
00812
00813 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00814 &CallbackRemovePointsInCurvesGraphs::callback);
00815
00816 curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00817 }
00818
00819 void CoordSystem::resetSelectedCurveNameIfNecessary ()
00820 {
00821 if (m_selectedCurveName.isEmpty () ||
00822 curveForCurveName (m_selectedCurveName) == 0) {
00823
00824
00825 m_selectedCurveName = m_curvesGraphs.curvesGraphsNames().first();
00826 }
00827
00828 }
00829
00830 void CoordSystem::saveXml (QXmlStreamWriter &writer) const
00831 {
00832 writer.writeStartElement(DOCUMENT_SERIALIZE_COORD_SYSTEM);
00833
00834
00835 m_modelGeneral.saveXml (writer);
00836 m_modelCoords.saveXml (writer);
00837 m_modelDigitizeCurve.saveXml (writer);
00838 m_modelExport.saveXml (writer);
00839 m_modelAxesChecker.saveXml (writer);
00840 m_modelGridDisplay.saveXml (writer);
00841 m_modelGridRemoval.saveXml (writer);
00842 m_modelPointMatch.saveXml (writer);
00843 m_modelSegments.saveXml (writer);
00844 m_curveAxes->saveXml (writer);
00845 m_curvesGraphs.saveXml (writer);
00846 writer.writeEndElement();
00847 }
00848
00849 QString CoordSystem::selectedCurveName () const
00850 {
00851 return m_selectedCurveName;
00852 }
00853
00854 void CoordSystem::setCurveAxes (const Curve &curveAxes)
00855 {
00856 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::setCurveAxes";
00857
00858 if (m_curveAxes != 0) {
00859 delete m_curveAxes;
00860 m_curveAxes = 0;
00861 }
00862
00863 m_curveAxes = new Curve (curveAxes);
00864 }
00865
00866 void CoordSystem::setCurvesGraphs (const CurvesGraphs &curvesGraphs)
00867 {
00868 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::setCurvesGraphs";
00869
00870 m_curvesGraphs = curvesGraphs;
00871
00872 resetSelectedCurveNameIfNecessary ();
00873 }
00874
00875 void CoordSystem::setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
00876 {
00877 m_modelAxesChecker = modelAxesChecker;
00878 }
00879
00880 void CoordSystem::setModelColorFilter(const DocumentModelColorFilter &modelColorFilter)
00881 {
00882
00883 ColorFilterSettingsList::const_iterator itr;
00884 for (itr = modelColorFilter.colorFilterSettingsList().constBegin ();
00885 itr != modelColorFilter.colorFilterSettingsList().constEnd();
00886 itr++) {
00887
00888 QString curveName = itr.key();
00889 const ColorFilterSettings &colorFilterSettings = itr.value();
00890
00891 Curve *curve = curveForCurveName (curveName);
00892 curve->setColorFilterSettings (colorFilterSettings);
00893 }
00894 }
00895
00896 void CoordSystem::setModelCoords (const DocumentModelCoords &modelCoords)
00897 {
00898 m_modelCoords = modelCoords;
00899 }
00900
00901 void CoordSystem::setModelCurveStyles(const CurveStyles &modelCurveStyles)
00902 {
00903
00904 QStringList curveNames = modelCurveStyles.curveNames();
00905 QStringList::iterator itr;
00906 for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
00907
00908 QString curveName = *itr;
00909 const CurveStyle &curveStyle = modelCurveStyles.curveStyle (curveName);
00910
00911 Curve *curve = curveForCurveName (curveName);
00912 curve->setCurveStyle (curveStyle);
00913 }
00914 }
00915
00916 void CoordSystem::setModelDigitizeCurve (const DocumentModelDigitizeCurve &modelDigitizeCurve)
00917 {
00918 m_modelDigitizeCurve = modelDigitizeCurve;
00919 }
00920
00921 void CoordSystem::setModelExport(const DocumentModelExportFormat &modelExport)
00922 {
00923 m_modelExport = modelExport;
00924 }
00925
00926 void CoordSystem::setModelGeneral (const DocumentModelGeneral &modelGeneral)
00927 {
00928 m_modelGeneral = modelGeneral;
00929 }
00930
00931 void CoordSystem::setModelGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
00932 {
00933 m_modelGridDisplay = modelGridDisplay;
00934 }
00935
00936 void CoordSystem::setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
00937 {
00938 m_modelGridRemoval = modelGridRemoval;
00939 }
00940
00941 void CoordSystem::setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
00942 {
00943 m_modelPointMatch = modelPointMatch;
00944 }
00945
00946 void CoordSystem::setModelSegments(const DocumentModelSegments &modelSegments)
00947 {
00948 m_modelSegments = modelSegments;
00949 }
00950
00951 void CoordSystem::setSelectedCurveName(const QString &selectedCurveName)
00952 {
00953 m_selectedCurveName = selectedCurveName;
00954 }
00955
00956 bool CoordSystem::successfulRead () const
00957 {
00958 return m_successfulRead;
00959 }
00960
00961 void CoordSystem::updatePointOrdinals (const Transformation &transformation)
00962 {
00963 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::updatePointOrdinals";
00964
00965
00966 m_curvesGraphs.updatePointOrdinals (transformation);
00967 }