| 1 | /*
 | 
|---|
| 2 |  * QSeisData.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Jan 30, 2011
 | 
|---|
| 5 |  *      Author: landvogt
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | // include config.h
 | 
|---|
| 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 10 | #include <config.h>
 | 
|---|
| 11 | #endif
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "QSeisData.hpp"
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "UIElements/Views/Qt4/Plotting/QSeisPlotCurve.hpp"
 | 
|---|
| 16 | #include "UIElements/Views/Qt4/Plotting/QSeisCurveRegistry.hpp"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | // have this after(!) all Qt includes
 | 
|---|
| 19 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | /** Constructor for QSeisData.
 | 
|---|
| 22 |  *
 | 
|---|
| 23 |  *  We create the QSeisPlotCurve instance here by calling createCurve().
 | 
|---|
| 24 |  *
 | 
|---|
| 25 |  * @param name file name data is associated with
 | 
|---|
| 26 |  * @param columnNo column number in the file this instance represents
 | 
|---|
| 27 |  */
 | 
|---|
| 28 | QSeisData::QSeisData(QString name, quint32 columnNo) :
 | 
|---|
| 29 |          intName(name), columnNumber(columnNo)
 | 
|---|
| 30 | {
 | 
|---|
| 31 |     createCurve();
 | 
|---|
| 32 | }
 | 
|---|
| 33 | 
 | 
|---|
| 34 | /** Constructor for QSeisData.
 | 
|---|
| 35 |  *
 | 
|---|
| 36 |  * Note that we do not spawn any QSeisCurve instance here.
 | 
|---|
| 37 |  *
 | 
|---|
| 38 |  * @param xValues predefined set of x values
 | 
|---|
| 39 |  * @param yValues predefined set of y values
 | 
|---|
| 40 |  * @param name file for this data set
 | 
|---|
| 41 |  */
 | 
|---|
| 42 | QSeisData::QSeisData(std::vector<double> xValues, std::vector<double> yValues, QString name) :
 | 
|---|
| 43 |         intName(name), xData(xValues), yData(yValues)
 | 
|---|
| 44 | {
 | 
|---|
| 45 | 
 | 
|---|
| 46 | }
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /** Destructor for QSeisData.
 | 
|---|
| 49 |  *
 | 
|---|
| 50 |  */
 | 
|---|
| 51 | QSeisData::~QSeisData()
 | 
|---|
| 52 | {
 | 
|---|
| 53 | }
 | 
|---|
| 54 | 
 | 
|---|
| 55 | /** Create QSeisCurve instance for this data set if not yet present.
 | 
|---|
| 56 |  *
 | 
|---|
| 57 |  * We check in QSeisCurveRegistry whether a curve associated with \a intName is
 | 
|---|
| 58 |  * already present. If so, we associated with it, overwriting any association
 | 
|---|
| 59 |  * which another QSeisData has (probably from an old file that was deleted but
 | 
|---|
| 60 |  * whose data has been preserved so far). If not, we create a new instance and
 | 
|---|
| 61 |  * register it.
 | 
|---|
| 62 |  *
 | 
|---|
| 63 |  * \note We make this instance child of the curve such that it is destroyed when
 | 
|---|
| 64 |  *       then curve is destroyed.
 | 
|---|
| 65 |  *
 | 
|---|
| 66 |  */
 | 
|---|
| 67 | void QSeisData::createCurve()
 | 
|---|
| 68 | {
 | 
|---|
| 69 |     QSeisPlotCurve *new_curve = NULL;
 | 
|---|
| 70 |     // if curve is already present, replace binding to this one
 | 
|---|
| 71 |     if (QSeisCurveRegistry::getInstance().isPresentByName(intName.toStdString())) {
 | 
|---|
| 72 |         new_curve = QSeisCurveRegistry::getInstance().getByName(intName.toStdString());
 | 
|---|
| 73 |     } else {
 | 
|---|
| 74 | //      QString type = QSeisXMLParser::getInstance().getTypeOfName(intName);
 | 
|---|
| 75 | //        new_curve = new QSeisPlotCurve(intName, type);
 | 
|---|
| 76 |     }
 | 
|---|
| 77 |     connect(this, SIGNAL(dataChanged(QwtData*)), new_curve, SLOT(updateCurve(QwtData*)));
 | 
|---|
| 78 |     connect(this, SIGNAL(dataOutOfDate()), new_curve, SLOT(markAsOutOfDate()));
 | 
|---|
| 79 |     connect(new_curve, SIGNAL(dataRequested()), this, SIGNAL(dataRequested()));
 | 
|---|
| 80 |     setParent(new_curve);
 | 
|---|
| 81 | 
 | 
|---|
| 82 |     // if replacing present curve, notify
 | 
|---|
| 83 |     if (QSeisCurveRegistry::getInstance().isPresentByName(intName.toStdString())) {
 | 
|---|
| 84 |         emit dataChanged(this);
 | 
|---|
| 85 |     } else {
 | 
|---|
| 86 |         QSeisCurveRegistry::getInstance().registerInstance(new_curve);
 | 
|---|
| 87 |     }
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | /** Slot for updating of the data contents.
 | 
|---|
| 91 |  *
 | 
|---|
| 92 |  *  We get here all data because then QSeisParser (who gives the signal) can
 | 
|---|
| 93 |  *  bind to all QSeisData instances' slots at once.
 | 
|---|
| 94 |  *
 | 
|---|
| 95 |  * @param newData new data to store
 | 
|---|
| 96 |  */
 | 
|---|
| 97 | void QSeisData::updateData(const std::vector<std::vector<double> > &newData)
 | 
|---|
| 98 | {
 | 
|---|
| 99 |     xData.clear();
 | 
|---|
| 100 |     yData.clear();
 | 
|---|
| 101 |     if (newData.size() > columnNumber)
 | 
|---|
| 102 |     {
 | 
|---|
| 103 |         xData = newData[0];
 | 
|---|
| 104 |         yData = newData[columnNumber];
 | 
|---|
| 105 |     }
 | 
|---|
| 106 |     emit dataChanged((QwtData *)this);
 | 
|---|
| 107 | }
 | 
|---|
| 108 | 
 | 
|---|
| 109 | /** Copy function.
 | 
|---|
| 110 |  *
 | 
|---|
| 111 |  * This is defined in QwtData, hence we need to implement it.
 | 
|---|
| 112 |  *
 | 
|---|
| 113 |  * @return copy of this instance
 | 
|---|
| 114 |  */
 | 
|---|
| 115 | QSeisData* QSeisData::copy() const
 | 
|---|
| 116 | {
 | 
|---|
| 117 |     return new QSeisData(xData, yData, intName);
 | 
|---|
| 118 | }
 | 
|---|
| 119 | 
 | 
|---|
| 120 | /** Getter for size of the data set, i.e. number of tupels.
 | 
|---|
| 121 |  *
 | 
|---|
| 122 |  * @return number of data tupels.
 | 
|---|
| 123 |  */
 | 
|---|
| 124 | size_t QSeisData::size() const
 | 
|---|
| 125 | {
 | 
|---|
| 126 |     return xData.size();
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | /** Getter for specific x value
 | 
|---|
| 130 |  *
 | 
|---|
| 131 |  * @param i index of value
 | 
|---|
| 132 |  * @return \a xData[i] or 0. if not present
 | 
|---|
| 133 |  */
 | 
|---|
| 134 | double QSeisData::x(size_t i) const
 | 
|---|
| 135 | {
 | 
|---|
| 136 |     if (i < xData.size())
 | 
|---|
| 137 |         return xData.at(i);
 | 
|---|
| 138 |     else
 | 
|---|
| 139 |         return 0.0f;
 | 
|---|
| 140 | }
 | 
|---|
| 141 | 
 | 
|---|
| 142 | /** Getter for specific y value
 | 
|---|
| 143 |  *
 | 
|---|
| 144 |  * @param i index of value
 | 
|---|
| 145 |  * @return \a yData[i] or 0. if not present
 | 
|---|
| 146 |  */
 | 
|---|
| 147 | double QSeisData::y(size_t i) const
 | 
|---|
| 148 | {
 | 
|---|
| 149 |     if (i < yData.size())
 | 
|---|
| 150 |         return yData.at(i);
 | 
|---|
| 151 |     else
 | 
|---|
| 152 |         return 0.0f;
 | 
|---|
| 153 | }
 | 
|---|