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 posGraph=("
00269 << posGraph.x () << ", " << posGraph.y () << ") identifier="
00270 << identifier.toLatin1 ().data ();
00271
00272 m_curveAxes->editPoint (posGraph,
00273 identifier);
00274 }
00275
00276 bool CoordSystem::isXOnly (const QString &pointIdentifier) const
00277 {
00278 return m_curveAxes->isXOnly (pointIdentifier);
00279 }
00280
00281 void CoordSystem::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00282 {
00283 ENGAUGE_CHECK_PTR (m_curveAxes);
00284
00285 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00286 }
00287
00288 void CoordSystem::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00289 {
00290 ENGAUGE_CHECK_PTR (m_curveAxes);
00291
00292 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00293 }
00294
00295 void CoordSystem::iterateThroughCurveSegments (const QString &curveName,
00296 const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00297 {
00298 if (curveName == AXIS_CURVE_NAME) {
00299 m_curveAxes->iterateThroughCurveSegments(ftorWithCallback);
00300 } else {
00301 m_curvesGraphs.iterateThroughCurveSegments(curveName,
00302 ftorWithCallback);
00303 }
00304 }
00305
00306 void CoordSystem::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00307 {
00308 ENGAUGE_CHECK_PTR (m_curveAxes);
00309
00310 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00311 }
00312
00313 void CoordSystem::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00314 {
00315 ENGAUGE_CHECK_PTR (m_curveAxes);
00316
00317 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00318 }
00319
00320 bool CoordSystem::loadCurvesFile(const QString & )
00321 {
00322 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadCurvesFile";
00323
00324 return true;
00325 }
00326
00327 void CoordSystem::loadPreVersion6 (QDataStream &str,
00328 double version)
00329 {
00330 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadPreVersion6";
00331
00332 qint32 int32;
00333 double dbl, radius = 0.0;
00334 QString st;
00335
00336 m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
00337
00338 str >> st;
00339 str >> st;
00340 str >> int32;
00341 m_modelCoords.setCoordsType((CoordsType) int32);
00342 if (version >= 3) {
00343 str >> (double &) radius;
00344 }
00345 m_modelCoords.setOriginRadius(radius);
00346 str >> int32;
00347 m_modelCoords.setCoordUnitsRadius(COORD_UNITS_NON_POLAR_THETA_NUMBER);
00348 m_modelCoords.setCoordUnitsTheta((CoordUnitsPolarTheta) int32);
00349 str >> int32;
00350 m_modelCoords.setCoordScaleXTheta((CoordScale) int32);
00351 str >> int32;
00352 m_modelCoords.setCoordScaleYRadius((CoordScale) int32);
00353
00354 str >> int32;
00355 m_modelExport.setDelimiter((ExportDelimiter) int32);
00356 str >> int32;
00357 m_modelExport.setLayoutFunctions((ExportLayoutFunctions) int32);
00358 str >> int32;
00359 m_modelExport.setPointsSelectionFunctions((ExportPointsSelectionFunctions) int32);
00360 m_modelExport.setPointsIntervalUnitsRelations((ExportPointsIntervalUnits) int32);
00361 str >> int32;
00362 m_modelExport.setHeader((ExportHeader) int32);
00363 if (version >= 5.1) {
00364 str >> st;
00365 if (m_modelCoords.coordsType() == COORDS_TYPE_CARTESIAN) {
00366 m_modelExport.setXLabel(st);
00367 }
00368 str >> st;
00369 if (m_modelCoords.coordsType() == COORDS_TYPE_POLAR) {
00370 m_modelExport.setXLabel(st);
00371 }
00372 }
00373
00374
00375 str >> int32;
00376 str >> dbl;
00377 str >> int32;
00378 m_modelGridRemoval.setRemoveDefinedGridLines(int32);
00379 str >> int32;
00380 str >> int32;
00381 m_modelGridRemoval.setCountX(int32);
00382 str >> int32;
00383 m_modelGridRemoval.setCountY(int32);
00384 str >> int32;
00385 m_modelGridRemoval.setGridCoordDisableX((GridCoordDisable) int32);
00386 str >> int32;
00387 m_modelGridRemoval.setGridCoordDisableY((GridCoordDisable) int32);
00388 str >> dbl;
00389 m_modelGridRemoval.setStartX(dbl);
00390 str >> dbl;
00391 m_modelGridRemoval.setStartY(dbl);
00392 str >> dbl;
00393 m_modelGridRemoval.setStepX(dbl);
00394 str >> dbl;
00395 m_modelGridRemoval.setStepY(dbl);
00396 str >> dbl;
00397 m_modelGridRemoval.setStopX(dbl);
00398 str >> dbl;
00399 m_modelGridRemoval.setStopY(dbl);
00400 str >> dbl;
00401 m_modelGridRemoval.setCloseDistance(dbl);
00402 str >> int32;
00403 if (version >= 5) {
00404 QColor color;
00405 str >> color;
00406 } else {
00407 str >> int32;
00408 }
00409 str >> int32;
00410 str >> int32;
00411 str >> dbl;
00412
00413 str >> int32;
00414 m_modelGridDisplay.setStable(int32);
00415 str >> int32;
00416 m_modelGridDisplay.setCountX(int32);
00417 str >> int32;
00418 m_modelGridDisplay.setCountY(int32);
00419 str >> int32;
00420 m_modelGridDisplay.setDisableX((GridCoordDisable) int32);
00421 str >> int32;
00422 m_modelGridDisplay.setDisableY((GridCoordDisable) int32);
00423 str >> dbl;
00424 m_modelGridDisplay.setStartX (dbl);
00425 str >> dbl;
00426 m_modelGridDisplay.setStartY (dbl);
00427 str >> dbl;
00428 m_modelGridDisplay.setStepX (dbl);
00429 str >> dbl;
00430 m_modelGridDisplay.setStepY (dbl);
00431 str >> dbl;
00432 m_modelGridDisplay.setStopX (dbl);
00433 str >> dbl;
00434 m_modelGridDisplay.setStopY (dbl);
00435
00436 str >> int32;
00437 m_modelSegments.setMinLength(int32);
00438 str >> int32;
00439 m_modelSegments.setPointSeparation(int32);
00440 str >> int32;
00441 m_modelSegments.setLineWidth(int32);
00442 str >> int32;
00443 m_modelSegments.setLineColor((ColorPalette) int32);
00444
00445 str >> int32;
00446 str >> int32;
00447 m_modelPointMatch.setMaxPointSize(int32);
00448 str >> int32;
00449 m_modelPointMatch.setPaletteColorAccepted((ColorPalette) int32);
00450 str >> int32;
00451 m_modelPointMatch.setPaletteColorRejected((ColorPalette) int32);
00452 if (version < 4) {
00453 m_modelPointMatch.setPaletteColorCandidate(COLOR_PALETTE_BLUE);
00454 } else {
00455 str >> int32;
00456 m_modelPointMatch.setPaletteColorCandidate((ColorPalette) int32);
00457 }
00458
00459 str >> int32;
00460 str >> int32;
00461 str >> int32;
00462 str >> int32;
00463 str >> int32;
00464 str >> int32;
00465 str >> int32;
00466 str >> int32;
00467 str >> int32;
00468 str >> int32;
00469 str >> int32;
00470
00471 m_curveAxes = new Curve (str);
00472 Curve curveScale (str);
00473 m_curvesGraphs.loadPreVersion6 (str);
00474
00475
00476 if (m_curveAxes->numPoints () > 2) {
00477 m_modelGridRemoval.setStable();
00478 }
00479
00480 resetSelectedCurveNameIfNecessary ();
00481 }
00482
00483 void CoordSystem::loadVersion6 (QXmlStreamReader &reader)
00484 {
00485 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadVersion6";
00486
00487 m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
00488
00489
00490 while (!reader.atEnd() &&
00491 !reader.hasError()) {
00492 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
00493
00494 if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
00495 (tokenType == QXmlStreamReader::EndElement)) {
00496
00497
00498 break;
00499 }
00500
00501
00502 if (tokenType == QXmlStreamReader::StartElement) {
00503
00504
00505 QString tag = reader.name().toString();
00506 if (tag == DOCUMENT_SERIALIZE_AXES_CHECKER){
00507 m_modelAxesChecker.loadXml (reader);
00508 } else if (tag == DOCUMENT_SERIALIZE_COORDS) {
00509 m_modelCoords.loadXml (reader);
00510 } else if (tag == DOCUMENT_SERIALIZE_CURVE) {
00511 m_curveAxes = new Curve (reader);
00512 } else if (tag == DOCUMENT_SERIALIZE_CURVES_GRAPHS) {
00513 m_curvesGraphs.loadXml (reader);
00514 } else if (tag == DOCUMENT_SERIALIZE_DIGITIZE_CURVE) {
00515 m_modelDigitizeCurve.loadXml (reader);
00516 } else if (tag == DOCUMENT_SERIALIZE_EXPORT) {
00517 m_modelExport.loadXml (reader);
00518 } else if (tag == DOCUMENT_SERIALIZE_GENERAL || tag == DOCUMENT_SERIALIZE_COMMON) {
00519 m_modelGeneral.loadXml (reader);
00520 } else if (tag == DOCUMENT_SERIALIZE_GRID_REMOVAL) {
00521 m_modelGridRemoval.loadXml (reader);
00522 } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
00523 ENGAUGE_ASSERT (false);
00524 } else if (tag == DOCUMENT_SERIALIZE_POINT_MATCH) {
00525 m_modelPointMatch.loadXml (reader);
00526 } else if (tag == DOCUMENT_SERIALIZE_SEGMENTS) {
00527 m_modelSegments.loadXml (reader);
00528 } else {
00529 m_successfulRead = false;
00530 m_reasonForUnsuccessfulRead = QString ("%1 '%2' %3")
00531 .arg (QObject::tr ("Unexpected xml token"))
00532 .arg (tag)
00533 .arg ("encountered");
00534 break;
00535 }
00536 }
00537 }
00538
00539 resetSelectedCurveNameIfNecessary ();
00540 }
00541
00542 void CoordSystem::loadVersions7AndUp (QXmlStreamReader &reader,
00543 DocumentAxesPointsRequired documentAxesPointsRequired)
00544 {
00545 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::loadVersions7AndUp";
00546
00547 m_documentAxesPointsRequired = documentAxesPointsRequired;
00548
00549
00550 while (!reader.atEnd() &&
00551 !reader.hasError()) {
00552 QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
00553
00554 if ((reader.name() == DOCUMENT_SERIALIZE_COORD_SYSTEM) &&
00555 (tokenType == QXmlStreamReader::EndElement)) {
00556
00557
00558 break;
00559 }
00560
00561
00562 if (tokenType == QXmlStreamReader::StartElement) {
00563
00564
00565 QString tag = reader.name().toString();
00566 if (tag == DOCUMENT_SERIALIZE_AXES_CHECKER){
00567 m_modelAxesChecker.loadXml (reader);
00568 } else if (tag == DOCUMENT_SERIALIZE_COORDS) {
00569 m_modelCoords.loadXml (reader);
00570 } else if (tag == DOCUMENT_SERIALIZE_CURVE) {
00571 m_curveAxes = new Curve (reader);
00572 } else if (tag == DOCUMENT_SERIALIZE_CURVES_GRAPHS) {
00573 m_curvesGraphs.loadXml (reader);
00574 } else if (tag == DOCUMENT_SERIALIZE_DIGITIZE_CURVE) {
00575 m_modelDigitizeCurve.loadXml (reader);
00576 } else if (tag == DOCUMENT_SERIALIZE_EXPORT) {
00577 m_modelExport.loadXml (reader);
00578 } else if (tag == DOCUMENT_SERIALIZE_GENERAL || tag == DOCUMENT_SERIALIZE_COMMON) {
00579 m_modelGeneral.loadXml (reader);
00580 } else if (tag == DOCUMENT_SERIALIZE_GRID_DISPLAY) {
00581 m_modelGridDisplay.loadXml (reader);
00582 } else if (tag == DOCUMENT_SERIALIZE_GRID_REMOVAL) {
00583 m_modelGridRemoval.loadXml (reader);
00584 } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
00585 ENGAUGE_ASSERT (false);
00586 } else if (tag == DOCUMENT_SERIALIZE_POINT_MATCH) {
00587 m_modelPointMatch.loadXml (reader);
00588 } else if (tag == DOCUMENT_SERIALIZE_SEGMENTS) {
00589 m_modelSegments.loadXml (reader);
00590 } else {
00591 m_successfulRead = false;
00592 m_reasonForUnsuccessfulRead = QString ("Unexpected xml token '%1' encountered").arg (tag);
00593 break;
00594 }
00595 }
00596 }
00597
00598 resetSelectedCurveNameIfNecessary ();
00599 }
00600
00601 DocumentModelAxesChecker CoordSystem::modelAxesChecker() const
00602 {
00603 return m_modelAxesChecker;
00604 }
00605
00606 DocumentModelColorFilter CoordSystem::modelColorFilter() const
00607 {
00608
00609 DocumentModelColorFilter modelColorFilter(*this);
00610
00611 return modelColorFilter;
00612 }
00613
00614 DocumentModelCoords CoordSystem::modelCoords() const
00615 {
00616 return m_modelCoords;
00617 }
00618
00619 CurveStyles CoordSystem::modelCurveStyles() const
00620 {
00621
00622 CurveStyles modelCurveStyles(*this);
00623
00624 return modelCurveStyles;
00625 }
00626
00627 DocumentModelDigitizeCurve CoordSystem::modelDigitizeCurve() const
00628 {
00629 return m_modelDigitizeCurve;
00630 }
00631
00632 DocumentModelExportFormat CoordSystem::modelExport() const
00633 {
00634 return m_modelExport;
00635 }
00636
00637 DocumentModelGeneral CoordSystem::modelGeneral() const
00638 {
00639 return m_modelGeneral;
00640 }
00641
00642 DocumentModelGridDisplay CoordSystem::modelGridDisplay() const
00643 {
00644 return m_modelGridDisplay;
00645 }
00646
00647 DocumentModelGridRemoval CoordSystem::modelGridRemoval() const
00648 {
00649 return m_modelGridRemoval;
00650 }
00651
00652 DocumentModelPointMatch CoordSystem::modelPointMatch() const
00653 {
00654 return m_modelPointMatch;
00655 }
00656
00657 DocumentModelSegments CoordSystem::modelSegments() const
00658 {
00659 return m_modelSegments;
00660 }
00661
00662 void CoordSystem::movePoint (const QString &pointIdentifier,
00663 const QPointF &deltaScreen)
00664 {
00665 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00666
00667 Curve *curve = curveForCurveName (curveName);
00668 ENGAUGE_ASSERT (curve != 0);
00669 curve->movePoint (pointIdentifier,
00670 deltaScreen);
00671 }
00672
00673 int CoordSystem::nextOrdinalForCurve (const QString &curveName) const
00674 {
00675 CallbackNextOrdinal ftor (curveName);
00676
00677 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00678 &CallbackNextOrdinal::callback);
00679
00680 if (curveName == AXIS_CURVE_NAME) {
00681 m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
00682 } else {
00683 m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00684 }
00685
00686 return ftor.nextOrdinal ();
00687 }
00688
00689 QPointF CoordSystem::positionGraph (const QString &pointIdentifier) const
00690 {
00691 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00692
00693 const Curve *curve = curveForCurveName (curveName);
00694 return curve->positionGraph (pointIdentifier);
00695 }
00696
00697 QPointF CoordSystem::positionScreen (const QString &pointIdentifier) const
00698 {
00699 QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
00700
00701 const Curve *curve = curveForCurveName (curveName);
00702 return curve->positionScreen (pointIdentifier);
00703 }
00704
00705 void CoordSystem::print () const
00706 {
00707 QString text;
00708 QTextStream str (&text);
00709
00710 printStream ("",
00711 str);
00712 std::cerr << text.toLatin1().data();
00713 }
00714
00715 void CoordSystem::printStream (QString indentation,
00716 QTextStream &str) const
00717 {
00718 str << indentation << "Graph\n";
00719
00720 indentation += INDENTATION_DELTA;
00721
00722
00723
00724
00725 m_curveAxes->printStream (indentation,
00726 str);
00727 m_curvesGraphs.printStream (indentation,
00728 str);
00729
00730 m_modelAxesChecker.printStream (indentation,
00731 str);
00732 m_modelCoords.printStream (indentation,
00733 str);
00734 m_modelDigitizeCurve.printStream (indentation,
00735 str);
00736 m_modelExport.printStream (indentation,
00737 str);
00738 m_modelGeneral.printStream (indentation,
00739 str);
00740 m_modelGridDisplay.printStream (indentation,
00741 str);
00742 m_modelGridRemoval.printStream (indentation,
00743 str);
00744 m_modelPointMatch.printStream (indentation,
00745 str);
00746 m_modelSegments.printStream (indentation,
00747 str);
00748 }
00749
00750 QString CoordSystem::reasonForUnsuccessfulRead () const
00751 {
00752 ENGAUGE_ASSERT (!m_successfulRead);
00753
00754 return m_reasonForUnsuccessfulRead;
00755 }
00756
00757 void CoordSystem::removePointAxis (const QString &identifier)
00758 {
00759 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::removePointAxis identifier=" << identifier.toLatin1 ().data ();
00760
00761 m_curveAxes->removePoint (identifier);
00762 }
00763
00764 void CoordSystem::removePointGraph (const QString &identifier)
00765 {
00766 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::removePointGraph identifier=" << identifier.toLatin1 ().data ();
00767
00768 m_curvesGraphs.removePoint (identifier);
00769 }
00770
00771 void CoordSystem::removePointsInCurvesGraphs (CurvesGraphs &curvesGraphs)
00772 {
00773 CallbackRemovePointsInCurvesGraphs ftor (*this);
00774
00775 Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
00776 &CallbackRemovePointsInCurvesGraphs::callback);
00777
00778 curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
00779 }
00780
00781 void CoordSystem::resetSelectedCurveNameIfNecessary ()
00782 {
00783 if (m_selectedCurveName.isEmpty () ||
00784 curveForCurveName (m_selectedCurveName) == 0) {
00785
00786
00787 m_selectedCurveName = m_curvesGraphs.curvesGraphsNames().first();
00788 }
00789
00790 }
00791
00792 void CoordSystem::saveXml (QXmlStreamWriter &writer) const
00793 {
00794 writer.writeStartElement(DOCUMENT_SERIALIZE_COORD_SYSTEM);
00795
00796
00797 m_modelGeneral.saveXml (writer);
00798 m_modelCoords.saveXml (writer);
00799 m_modelDigitizeCurve.saveXml (writer);
00800 m_modelExport.saveXml (writer);
00801 m_modelAxesChecker.saveXml (writer);
00802 m_modelGridDisplay.saveXml (writer);
00803 m_modelGridRemoval.saveXml (writer);
00804 m_modelPointMatch.saveXml (writer);
00805 m_modelSegments.saveXml (writer);
00806 m_curveAxes->saveXml (writer);
00807 m_curvesGraphs.saveXml (writer);
00808 writer.writeEndElement();
00809 }
00810
00811 QString CoordSystem::selectedCurveName () const
00812 {
00813 return m_selectedCurveName;
00814 }
00815
00816 void CoordSystem::setCurveAxes (const Curve &curveAxes)
00817 {
00818 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::setCurveAxes";
00819
00820 if (m_curveAxes != 0) {
00821 delete m_curveAxes;
00822 m_curveAxes = 0;
00823 }
00824
00825 m_curveAxes = new Curve (curveAxes);
00826 }
00827
00828 void CoordSystem::setCurvesGraphs (const CurvesGraphs &curvesGraphs)
00829 {
00830 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::setCurvesGraphs";
00831
00832 m_curvesGraphs = curvesGraphs;
00833
00834 resetSelectedCurveNameIfNecessary ();
00835 }
00836
00837 void CoordSystem::setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
00838 {
00839 m_modelAxesChecker = modelAxesChecker;
00840 }
00841
00842 void CoordSystem::setModelColorFilter(const DocumentModelColorFilter &modelColorFilter)
00843 {
00844
00845 ColorFilterSettingsList::const_iterator itr;
00846 for (itr = modelColorFilter.colorFilterSettingsList().constBegin ();
00847 itr != modelColorFilter.colorFilterSettingsList().constEnd();
00848 itr++) {
00849
00850 QString curveName = itr.key();
00851 const ColorFilterSettings &colorFilterSettings = itr.value();
00852
00853 Curve *curve = curveForCurveName (curveName);
00854 curve->setColorFilterSettings (colorFilterSettings);
00855 }
00856 }
00857
00858 void CoordSystem::setModelCoords (const DocumentModelCoords &modelCoords)
00859 {
00860 m_modelCoords = modelCoords;
00861 }
00862
00863 void CoordSystem::setModelCurveStyles(const CurveStyles &modelCurveStyles)
00864 {
00865
00866 QStringList curveNames = modelCurveStyles.curveNames();
00867 QStringList::iterator itr;
00868 for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
00869
00870 QString curveName = *itr;
00871 const CurveStyle &curveStyle = modelCurveStyles.curveStyle (curveName);
00872
00873 Curve *curve = curveForCurveName (curveName);
00874 curve->setCurveStyle (curveStyle);
00875 }
00876 }
00877
00878 void CoordSystem::setModelDigitizeCurve (const DocumentModelDigitizeCurve &modelDigitizeCurve)
00879 {
00880 m_modelDigitizeCurve = modelDigitizeCurve;
00881 }
00882
00883 void CoordSystem::setModelExport(const DocumentModelExportFormat &modelExport)
00884 {
00885 m_modelExport = modelExport;
00886 }
00887
00888 void CoordSystem::setModelGeneral (const DocumentModelGeneral &modelGeneral)
00889 {
00890 m_modelGeneral = modelGeneral;
00891 }
00892
00893 void CoordSystem::setModelGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
00894 {
00895 m_modelGridDisplay = modelGridDisplay;
00896 }
00897
00898 void CoordSystem::setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
00899 {
00900 m_modelGridRemoval = modelGridRemoval;
00901 }
00902
00903 void CoordSystem::setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
00904 {
00905 m_modelPointMatch = modelPointMatch;
00906 }
00907
00908 void CoordSystem::setModelSegments(const DocumentModelSegments &modelSegments)
00909 {
00910 m_modelSegments = modelSegments;
00911 }
00912
00913 void CoordSystem::setSelectedCurveName(const QString &selectedCurveName)
00914 {
00915 m_selectedCurveName = selectedCurveName;
00916 }
00917
00918 bool CoordSystem::successfulRead () const
00919 {
00920 return m_successfulRead;
00921 }
00922
00923 void CoordSystem::updatePointOrdinals (const Transformation &transformation)
00924 {
00925 LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::updatePointOrdinals";
00926
00927
00928 m_curvesGraphs.updatePointOrdinals (transformation);
00929 }