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