[35302b] | 1 | /*
|
---|
| 2 | * QSeisPlot.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 "UIElements/Views/Qt4/Plotting/QSeisPlot.hpp"
|
---|
| 14 | #include "UIElements/Views/Qt4/Plotting/XMLParser/QSeisXMLParser.hpp"
|
---|
| 15 | #include "UIElements/Views/Qt4/Plotting/XMLParser/QSeisXMLParser_plottype.hpp"
|
---|
| 16 |
|
---|
| 17 | #include <iostream>
|
---|
| 18 | #include <qwt_plot_marker.h>
|
---|
| 19 |
|
---|
| 20 | // have this after(!) all Qt includes
|
---|
| 21 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 22 |
|
---|
| 23 | QSeisPlot::QSeisPlot(QWidget *parent,QString type) : QwtPlot(parent)
|
---|
| 24 | {
|
---|
| 25 | //no title as there are already the different tabs
|
---|
| 26 | setTitle("");
|
---|
| 27 | //display legend on the right hand side
|
---|
| 28 | //no legend displayed - list names are colored instead
|
---|
| 29 | //insertLegend(new QwtLegend(), QwtPlot::RightLegend);
|
---|
| 30 |
|
---|
[b677ab] | 31 | {
|
---|
| 32 | const std::string name("energy");
|
---|
| 33 | const std::string xlabel("Distance");
|
---|
| 34 | const std::string ylabel("Energy");
|
---|
| 35 | const std::string style("");
|
---|
| 36 | const std::vector<int> xunits;
|
---|
| 37 | const std::vector<int> yunits;
|
---|
| 38 | const std::vector<std::string> unitnames;
|
---|
| 39 | const std::map<std::string,std::string> unitmap;
|
---|
| 40 | m_plottype = new plottype(name,xlabel,ylabel,style,xunits,yunits, unitnames,unitmap);
|
---|
| 41 | }
|
---|
| 42 | // plottype* tmp = QSeisXMLParser::getInstance().return_plottype_by_name(type.toStdString());
|
---|
| 43 | ASSERT(m_plottype != NULL,
|
---|
[35302b] | 44 | "QSeisPlot::QSeisPlot() - could not find desired plottype by name "+type.toStdString()+".");
|
---|
[0ac3e3] | 45 | // std::cout << "Type is " << type.toStdString() << ", " << m_plottype << std::endl;
|
---|
[35302b] | 46 |
|
---|
| 47 | //label axes
|
---|
[b677ab] | 48 | const std::string xlabel = m_plottype->get_label(plottype::X);
|
---|
| 49 | const std::string ylabel = m_plottype->get_label(plottype::Y);
|
---|
| 50 | const std::string xunits = m_plottype->get_units(plottype::X);
|
---|
| 51 | const std::string yunits = m_plottype->get_units(plottype::Y);
|
---|
[35302b] | 52 | setAxisTitle(xBottom, (xlabel+std::string(" [")+xunits+std::string("]")).c_str());
|
---|
| 53 | setAxisTitle(yLeft, (ylabel+std::string(" [")+yunits+std::string("]")).c_str());
|
---|
| 54 |
|
---|
| 55 | //add zero line
|
---|
| 56 | QwtPlotMarker *zeroLine = new QwtPlotMarker();
|
---|
| 57 | zeroLine->setLineStyle(QwtPlotMarker::HLine);
|
---|
| 58 | zeroLine->setYValue(0.0);
|
---|
| 59 | zeroLine->attach(this);
|
---|
| 60 |
|
---|
| 61 | zoomer = new ScrollZoomer(canvas());
|
---|
| 62 |
|
---|
| 63 | #ifdef QWTPANNER
|
---|
| 64 | panner = new QwtPlotPanner(canvas());
|
---|
| 65 | panner->setMouseButton(Qt::MidButton);
|
---|
| 66 | #else
|
---|
| 67 | panning = false;
|
---|
| 68 | startPan = QPointF(0.0f, 0.0f);
|
---|
| 69 | #endif
|
---|
| 70 |
|
---|
| 71 | //init colors
|
---|
| 72 | availableColors.append(QColor(Qt::darkYellow));
|
---|
| 73 | availableColors.append(QColor(Qt::darkMagenta));
|
---|
| 74 | availableColors.append(QColor(Qt::darkCyan));
|
---|
| 75 | availableColors.append(QColor(Qt::darkGreen));
|
---|
| 76 | availableColors.append(QColor(Qt::darkRed));
|
---|
| 77 | availableColors.append(QColor(Qt::yellow));
|
---|
| 78 | availableColors.append(QColor(Qt::magenta));
|
---|
| 79 | availableColors.append(QColor(Qt::cyan));
|
---|
| 80 | availableColors.append(QColor(Qt::green));
|
---|
| 81 | availableColors.append(QColor(Qt::red));
|
---|
| 82 | availableColors.append(QColor(Qt::blue));
|
---|
| 83 | availableColors.append(QColor(Qt::black));
|
---|
| 84 |
|
---|
| 85 | color_map.insert(std::make_pair("black",QColor(Qt::black)));
|
---|
| 86 | color_map.insert(std::make_pair("red",QColor(Qt::red)));
|
---|
| 87 | color_map.insert(std::make_pair("blue",QColor(Qt::blue)));
|
---|
| 88 | color_map.insert(std::make_pair("green",QColor(Qt::green)));
|
---|
| 89 | color_map.insert(std::make_pair("cyan",QColor(Qt::cyan)));
|
---|
| 90 | color_map.insert(std::make_pair("yellow",QColor(Qt::yellow)));
|
---|
| 91 | color_map.insert(std::make_pair("magenta",QColor(Qt::magenta)));
|
---|
| 92 | color_map.insert(std::make_pair("darkYellow",QColor(Qt::darkYellow)));
|
---|
| 93 | color_map.insert(std::make_pair("darkMagenta",QColor(Qt::darkMagenta)));
|
---|
| 94 | color_map.insert(std::make_pair("darkCyan",QColor(Qt::darkCyan)));
|
---|
| 95 | color_map.insert(std::make_pair("darkGreen",QColor(Qt::darkGreen)));
|
---|
| 96 | color_map.insert(std::make_pair("darkRed",QColor(Qt::darkRed)));
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | QSeisPlot::~QSeisPlot()
|
---|
| 100 | {
|
---|
[b677ab] | 101 | delete m_plottype;
|
---|
[35302b] | 102 | }
|
---|
| 103 |
|
---|
| 104 | void QSeisPlot::loadSettingsFromXML(QString fileName)
|
---|
| 105 | {
|
---|
| 106 | //load settings from XML file sometime in the future
|
---|
| 107 | qDebug("loadSettingsFromXML %s", fileName.toAscii().constData());
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | void QSeisPlot::resetZoomer()
|
---|
| 111 | {
|
---|
| 112 | if (axisAutoScale(xBottom) && axisAutoScale(yLeft))
|
---|
| 113 | zoomer->setZoomBase(0);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | #ifndef QWTPANNER
|
---|
| 117 | void QSeisPlot::mouseMoveEvent(QMouseEvent *event)
|
---|
| 118 | {
|
---|
| 119 | if ((event->buttons() == Qt::MidButton) && (panning))
|
---|
| 120 | {
|
---|
| 121 | double xPos = invTransform(xBottom, event->pos().x() - canvas()->pos().x());
|
---|
| 122 | double yPos = invTransform(yLeft, event->pos().y() - canvas()->pos().y());
|
---|
| 123 | zoomer->moveBy(xPos-startPan.x(), yPos-startPan.y());
|
---|
| 124 | startPan = QPointF(xPos, yPos);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | void QSeisPlot::mousePressEvent(QMouseEvent *event)
|
---|
| 129 | {
|
---|
| 130 | //start panning only above the plot canvas
|
---|
| 131 | if ((event->button() == Qt::MidButton)
|
---|
| 132 | && (event->pos().x() >= canvas()->pos().x())
|
---|
| 133 | && (event->pos().x() <= (canvas()->pos().x() + canvas()->width()))
|
---|
| 134 | && (event->pos().y() >= canvas()->pos().y())
|
---|
| 135 | && (event->pos().y() <= (canvas()->pos().y() + canvas()->height())))
|
---|
| 136 | {
|
---|
| 137 | panning = true;
|
---|
| 138 | startPan = QPointF(invTransform(xBottom, event->pos().x() - canvas()->pos().x()),
|
---|
| 139 | invTransform(yLeft, event->pos().y() - canvas()->pos().y()));
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | void QSeisPlot::mouseReleaseEvent(QMouseEvent *event)
|
---|
| 144 | {
|
---|
| 145 | if (event->button() == Qt::MidButton)
|
---|
| 146 | {
|
---|
| 147 | panning = false;
|
---|
| 148 | startPan = QPointF(0.0f, 0.0f);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | #endif
|
---|
| 152 |
|
---|
| 153 | QColor QSeisPlot::getCurveColor(std::string curve_color)
|
---|
| 154 | {
|
---|
| 155 | if(color_map.count(curve_color)!=0) {
|
---|
| 156 | if(availableColors.count(color_map[curve_color])!=0) {
|
---|
| 157 | return color_map[curve_color];
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | QColor retColor = QColor(Qt::black);
|
---|
| 161 | if (!availableColors.isEmpty())
|
---|
| 162 | {
|
---|
| 163 | retColor = availableColors.last();
|
---|
| 164 | availableColors.removeLast();
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | return retColor;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | void QSeisPlot::freeCurveColor(QColor color)
|
---|
| 171 | {
|
---|
| 172 | if (color != QColor(Qt::black) && (!availableColors.contains(color)))
|
---|
| 173 | {
|
---|
| 174 | availableColors.append(color);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void QSeisPlot::resetPlot()
|
---|
| 179 | {
|
---|
| 180 | setAxisAutoScale(QwtPlot::xBottom);
|
---|
| 181 | setAxisAutoScale(QwtPlot::yLeft);
|
---|
| 182 | replot();
|
---|
| 183 | zoomer->setZoomBase(0);
|
---|
| 184 | }
|
---|