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::iterateThroughCurvePoints (const QString &curveNameWanted,
00097 const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00098 {
00099
00100 CurveList::const_iterator itr;
00101 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00102
00103 const Curve &curve = *itr;
00104 if (curve.curveName () == curveNameWanted) {
00105
00106 curve.iterateThroughCurvePoints (ftorWithCallback);
00107 return;
00108 }
00109 }
00110
00111 ENGAUGE_ASSERT (false);
00112 }
00113
00114 void CurvesGraphs::iterateThroughCurveSegments (const QString &curveNameWanted,
00115 const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00116 {
00117
00118 CurveList::const_iterator itr;
00119 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00120
00121 const Curve &curve = *itr;
00122 if (curve.curveName () == curveNameWanted) {
00123
00124 curve.iterateThroughCurveSegments (ftorWithCallback);
00125 return;
00126 }
00127 }
00128
00129 ENGAUGE_ASSERT (false);
00130 }
00131
00132 void CurvesGraphs::iterateThroughCurvesPoints (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
00133 {
00134 CurveList::const_iterator itr;
00135 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00136
00137 const Curve &curve = *itr;
00138 curve.iterateThroughCurvePoints (ftorWithCallback);
00139 }
00140 }
00141
00142 void CurvesGraphs::iterateThroughCurvesPoints (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
00143 {
00144 CurveList::const_iterator itr;
00145 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00146
00147 const Curve &curve = *itr;
00148 curve.iterateThroughCurvePoints (ftorWithCallback);
00149 }
00150 }
00151
00152 void CurvesGraphs::loadPreVersion6(QDataStream &str)
00153 {
00154 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::loadPreVersion6";
00155
00156 int i;
00157
00158
00159 m_curvesGraphs.clear();
00160
00161 qint32 numberCurvesGraphs;
00162 str >> numberCurvesGraphs;
00163 for (i = 0; i < numberCurvesGraphs; i++) {
00164 Curve curve (str);
00165 m_curvesGraphs.append (curve);
00166 }
00167
00168 qint32 numberCurvesMeasures;
00169 str >> numberCurvesMeasures;
00170 for (i = 0; i < numberCurvesMeasures; i++) {
00171 Curve curve (str);
00172
00173
00174 }
00175 }
00176
00177 void CurvesGraphs::loadXml(QXmlStreamReader &reader)
00178 {
00179 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::loadXml";
00180
00181 bool success = true;
00182
00183
00184 m_curvesGraphs.clear();
00185
00186
00187 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00188 (reader.name() != DOCUMENT_SERIALIZE_CURVES_GRAPHS)){
00189
00190 loadNextFromReader(reader);
00191 if (reader.atEnd()) {
00192 success = false;
00193 break;
00194 }
00195
00196 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
00197 (reader.name () == DOCUMENT_SERIALIZE_CURVE)) {
00198
00199 Curve curve (reader);
00200
00201
00202
00203 QString DUPLICATE = QString ("-%1").arg (QObject::tr ("DUPLICATE"));
00204 QString curveName = curve.curveName();
00205 while (curvesGraphsNames().contains (curveName)) {
00206 curveName += DUPLICATE;
00207 }
00208 curve.setCurveName (curveName);
00209
00210
00211 m_curvesGraphs.push_back (curve);
00212
00213 }
00214 }
00215
00216 if (!success) {
00217 reader.raiseError (QObject::tr ("Cannot read graph curves data"));
00218 }
00219 }
00220
00221 int CurvesGraphs::numCurves () const
00222 {
00223 return m_curvesGraphs.count ();
00224 }
00225
00226 void CurvesGraphs::printStream (QString indentation,
00227 QTextStream &str) const
00228 {
00229 str << indentation << "CurvesGraphs\n";
00230
00231 indentation += INDENTATION_DELTA;
00232
00233 CurveList::const_iterator itr;
00234 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00235
00236 const Curve &curve = *itr;
00237 curve.printStream (indentation,
00238 str);
00239 }
00240 }
00241
00242 void CurvesGraphs::removePoint (const QString &pointIdentifier)
00243 {
00244 QString curveName = Point::curveNameFromPointIdentifier(pointIdentifier);
00245
00246 Curve *curve = curveForCurveName (curveName);
00247 curve->removePoint (pointIdentifier);
00248 }
00249
00250 void CurvesGraphs::saveXml(QXmlStreamWriter &writer) const
00251 {
00252 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::saveXml";
00253
00254 writer.writeStartElement(DOCUMENT_SERIALIZE_CURVES_GRAPHS);
00255
00256 CurveList::const_iterator itr;
00257 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00258
00259 const Curve &curve = *itr;
00260 curve.saveXml (writer);
00261 }
00262
00263 writer.writeEndElement();
00264 }
00265
00266 void CurvesGraphs::updatePointOrdinals (const Transformation &transformation)
00267 {
00268 LOG4CPP_INFO_S ((*mainCat)) << "CurvesGraphs::updatePointOrdinals";
00269
00270 CurveList::iterator itr;
00271 for (itr = m_curvesGraphs.begin (); itr != m_curvesGraphs.end (); itr++) {
00272
00273 Curve &curve = *itr;
00274 curve.updatePointOrdinals (transformation);
00275 }
00276 }