00001
00002
00003
00004
00005
00006
00007 #include "Curve.h"
00008 #include "CurvesGraphs.h"
00009 #include "CurveStyles.h"
00010 #include "DocumentSerialize.h"
00011 #include "EngaugeAssert.h"
00012 #include "Logger.h"
00013 #include "Point.h"
00014 #include <qdebug.h>
00015 #include <QTextStream>
00016 #include <QXmlStreamWriter>
00017 #include "Transformation.h"
00018 #include "Xml.h"
00019
00020 CurvesGraphs::CurvesGraphs()
00021 {
00022 }
00023
00024 void CurvesGraphs::addGraphCurveAtEnd (Curve curve)
00025 {
00026 m_curvesGraphs.push_back (curve);
00027 }
00028
00029 void CurvesGraphs::addPoint (const Point &point)
00030 {
00031 QString curveName = Point::curveNameFromPointIdentifier (point.identifier());
00032
00033 Curve *curve = curveForCurveName (curveName);
00034 curve->addPoint (point);
00035 }
00036
00037 Curve *CurvesGraphs::curveForCurveName (const QString &curveName)
00038 {
00039
00040 CurveList::iterator itr;
00041 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00042
00043 Curve &curve = *itr;
00044 if (curveName == curve.curveName ()) {
00045 return &curve;
00046 }
00047 }
00048
00049 return 0;
00050 }
00051
00052 const Curve *CurvesGraphs::curveForCurveName (const QString &curveName) const
00053 {
00054
00055 CurveList::const_iterator itr;
00056 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00057
00058 const Curve &curve = *itr;
00059 if (curveName == curve.curveName ()) {
00060 return &curve;
00061 }
00062 }
00063
00064 return 0;
00065 }
00066
00067 QStringList CurvesGraphs::curvesGraphsNames () const
00068 {
00069 QStringList names;
00070
00071 CurveList::const_iterator itr;
00072 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00073
00074 const Curve &curve = *itr;
00075 names << curve.curveName ();
00076 }
00077
00078 return names;
00079 }
00080
00081 int CurvesGraphs::curvesGraphsNumPoints (const QString &curveName) const
00082 {
00083
00084 CurveList::const_iterator itr;
00085 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00086
00087 const Curve &curve = *itr;
00088 if (curve.curveName () == curveName) {
00089 return curve.numPoints ();
00090 }
00091 }
00092
00093 return 0;
00094 }
00095
00096 void CurvesGraphs::editPointGraph (bool isX,
00097 bool isY,
00098 double x,
00099 double y,
00100 const QStringList &identifiers,
00101 const Transformation &transformation)
00102 {
00103 CurveList::iterator itr;
00104 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00105
00106 Curve &curve = *itr;
00107 curve.editPointGraph (isX,
00108 isY,
00109 x,
00110 y,
00111 identifiers,
00112 transformation);
00113 }
00114 }
00115
00116 void CurvesGraphs::iterateThroughCurvePoints (const QString &curveNameWanted,
00117 const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00118 {
00119
00120 CurveList::const_iterator itr;
00121 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00122
00123 const Curve &curve = *itr;
00124 if (curve.curveName () == curveNameWanted) {
00125
00126 curve.iterateThroughCurvePoints (ftorWithCallback);
00127 return;
00128 }
00129 }
00130
00131 ENGAUGE_ASSERT (false);
00132 }
00133
00134 void CurvesGraphs::iterateThroughCurveSegments (const QString &curveNameWanted,
00135 const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00136 {
00137
00138 CurveList::const_iterator itr;
00139 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00140
00141 const Curve &curve = *itr;
00142 if (curve.curveName () == curveNameWanted) {
00143
00144 curve.iterateThroughCurveSegments (ftorWithCallback);
00145 return;
00146 }
00147 }
00148
00149 ENGAUGE_ASSERT (false);
00150 }
00151
00152 void CurvesGraphs::iterateThroughCurvesPoints (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00153 {
00154 CurveList::const_iterator itr;
00155 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00156
00157 const Curve &curve = *itr;
00158 curve.iterateThroughCurvePoints (ftorWithCallback);
00159 }
00160 }
00161
00162 void CurvesGraphs::iterateThroughCurvesPoints (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00163 {
00164 CurveList::const_iterator itr;
00165 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00166
00167 const Curve &curve = *itr;
00168 curve.iterateThroughCurvePoints (ftorWithCallback);
00169 }
00170 }
00171
00172 void CurvesGraphs::loadPreVersion6(QDataStream &str)
00173 {
00174 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::loadPreVersion6";
00175
00176 int i;
00177
00178
00179 m_curvesGraphs.clear();
00180
00181 qint32 numberCurvesGraphs;
00182 str >> numberCurvesGraphs;
00183 for (i = 0; i < numberCurvesGraphs; i++) {
00184 Curve curve (str);
00185 m_curvesGraphs.append (curve);
00186 }
00187
00188 qint32 numberCurvesMeasures;
00189 str >> numberCurvesMeasures;
00190 for (i = 0; i < numberCurvesMeasures; i++) {
00191 Curve curve (str);
00192
00193
00194 }
00195 }
00196
00197 void CurvesGraphs::loadXml(QXmlStreamReader &reader)
00198 {
00199 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::loadXml";
00200
00201 bool success = true;
00202
00203
00204 m_curvesGraphs.clear();
00205
00206
00207 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00208 (reader.name() != DOCUMENT_SERIALIZE_CURVES_GRAPHS)){
00209
00210 loadNextFromReader(reader);
00211 if (reader.atEnd()) {
00212 success = false;
00213 break;
00214 }
00215
00216 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
00217 (reader.name () == DOCUMENT_SERIALIZE_CURVE)) {
00218
00219 Curve curve (reader);
00220
00221
00222
00223 QString DUPLICATE = QString ("-%1").arg (QObject::tr ("DUPLICATE"));
00224 QString curveName = curve.curveName();
00225 while (curvesGraphsNames().contains (curveName)) {
00226 curveName += DUPLICATE;
00227 }
00228 curve.setCurveName (curveName);
00229
00230
00231 m_curvesGraphs.push_back (curve);
00232
00233 }
00234 }
00235
00236 if (!success) {
00237 reader.raiseError (QObject::tr ("Cannot read graph curves data"));
00238 }
00239 }
00240
00241 int CurvesGraphs::numCurves () const
00242 {
00243 return m_curvesGraphs.count ();
00244 }
00245
00246 void CurvesGraphs::printStream (QString indentation,
00247 QTextStream &str) const
00248 {
00249 str << indentation << "CurvesGraphs\n";
00250
00251 indentation += INDENTATION_DELTA;
00252
00253 CurveList::const_iterator itr;
00254 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00255
00256 const Curve &curve = *itr;
00257 curve.printStream (indentation,
00258 str);
00259 }
00260 }
00261
00262 void CurvesGraphs::removePoint (const QString &pointIdentifier)
00263 {
00264 QString curveName = Point::curveNameFromPointIdentifier(pointIdentifier);
00265
00266 Curve *curve = curveForCurveName (curveName);
00267 curve->removePoint (pointIdentifier);
00268 }
00269
00270 void CurvesGraphs::saveXml(QXmlStreamWriter &writer) const
00271 {
00272 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::saveXml";
00273
00274 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVES_GRAPHS);
00275
00276 CurveList::const_iterator itr;
00277 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00278
00279 const Curve &curve = *itr;
00280 curve.saveXml (writer);
00281 }
00282
00283 writer.writeEndElement();
00284 }
00285
00286 void CurvesGraphs::updatePointOrdinals (const Transformation &transformation)
00287 {
00288 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::updatePointOrdinals";
00289
00290 CurveList::iterator itr;
00291 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00292
00293 Curve &curve = *itr;
00294 curve.updatePointOrdinals (transformation);
00295 }
00296 }