Skip to content

Commit

Permalink
-timeline implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
arne committed Jun 11, 2012
1 parent 9f62dff commit 61a3218
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 53 deletions.
22 changes: 21 additions & 1 deletion maxdoas/scriptwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ QScriptValue TScriptStringListConstructor(QScriptContext *context, QScriptEngine
return engine->newQObject(object, QScriptEngine::ScriptOwnership);
}

QScriptValue TTimeLineConstructor(QScriptContext *context, QScriptEngine *engine)
{
(void)context;
QObject *object = new ttimeline();
return engine->newQObject(object, QScriptEngine::ScriptOwnership);
}

QScriptValue TDirListConstructor(QScriptContext *context, QScriptEngine *engine)
{
QObject *slo = context->argument(0).toQObject();
Expand Down Expand Up @@ -575,6 +582,13 @@ QScriptValue getSpectSerialNo(QScriptContext *context, QScriptEngine *engine){
return scanner->getSpectSerialNo();
}

QScriptValue msSinceEpoch(QScriptContext *context, QScriptEngine *engine){
(void)context;
(void)engine;
double result = QDateTime::currentMSecsSinceEpoch();
return result;
}

TScriptWrapper::TScriptWrapper(THWDriver* hwdriver)
{
scanner = TScanner::instance(hwdriver);
Expand All @@ -591,10 +605,12 @@ TScriptWrapper::TScriptWrapper(THWDriver* hwdriver)
QScriptValue isAbortingFree = ScriptEngine->newFunction(FreeObject);
ScriptEngine->globalObject().setProperty("free", isAbortingFree);

QScriptValue msSinceEpochFun = ScriptEngine->newFunction(msSinceEpoch);
ScriptEngine->globalObject().setProperty("msSinceEpoch", msSinceEpochFun);

QScriptValue leadingZeroFun = ScriptEngine->newFunction(leadingZero);
ScriptEngine->globalObject().setProperty("leadingZero", leadingZeroFun);


QScriptValue SetAutoIntegrationTimeFun = ScriptEngine->newFunction(SetAutoIntegrationTime);
ScriptEngine->globalObject().setProperty("SetAutoIntegrationTime", SetAutoIntegrationTimeFun);

Expand Down Expand Up @@ -701,6 +717,10 @@ TScriptWrapper::TScriptWrapper(THWDriver* hwdriver)
QScriptValue metasl = ScriptEngine->newQMetaObject(&QObject::staticMetaObject, qdsl);
ScriptEngine->globalObject().setProperty("TStringList", metasl);

QScriptValue qdtl = ScriptEngine->newFunction(TTimeLineConstructor);
QScriptValue metatl = ScriptEngine->newQMetaObject(&QObject::staticMetaObject, qdtl);
ScriptEngine->globalObject().setProperty("TTimeLine", metatl);

QScriptValue plotobj = ScriptEngine->newQObject(TSpectrumPlotter::instance(0),QScriptEngine::ScriptOwnership);
ScriptEngine->globalObject().setProperty("plot", plotobj);

Expand Down
3 changes: 1 addition & 2 deletions maxdoas/tmirrorcoordinate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ QPointF TMirrorCoordinate::getElevationCoordinate(){
//X -> Azimuth
//Y -> Zenith
QPointF result;
double Zenith;
double Azimuth;
double Elevation;
//Zenith = 90+(MirrorMotorAngle-90)*cos(StationaryMotorAngle)
Expand All @@ -96,7 +95,7 @@ QPointF TMirrorCoordinate::getElevationCoordinate(){

if (AngleCoordinate.y() >= 0){
}else{
if (AngleCoordinate.x() > 0)
if (AngleCoordinate.x() >= 0)
Azimuth = 180-Azimuth;
else
Azimuth = -180-Azimuth;
Expand Down
105 changes: 58 additions & 47 deletions maxdoas/tspectrumplotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
#include <qwt_color_map.h>
#include <qwt_interval.h>

class DateTimeScaleDraw: public QwtScaleDraw
{
public:
DateTimeScaleDraw()
{
}

virtual QwtText label(double v) const
{
QDateTime upTime;
upTime.setMSecsSinceEpoch((qint64)v);
return upTime.toString("dd.MM.yy hh:mm");
}
};


class ColorMap: public QwtLinearColorMap
{
public:
Expand Down Expand Up @@ -635,53 +651,48 @@ void TSpectrumPlotter::plotVectorField(TRetrievalImage *img,int plotIndex,int av
void TSpectrumPlotter::plotTimeLine(ttimeline *tl,int plotIndex){
TPlot *plot = getPlot(plotIndex);
QwtPlotSpectroCurve * s = plot->getImgPlot();
// QVector< QwtPoint3D > * vec = new QVector< QwtPoint3D >(img->getHeight()*img->getWidth());
// double minval=0,maxval=0,val;
// for(int y =0; y<img->getHeight();y++){
// for(int x =0; x<img->getWidth();x++){
// QwtPoint3D p3d;// = new QwtPoint3D();
// TMirrorCoordinate * mc;
// mc = img->valueBuffer[y][x]->mirrorCoordinate;

// p3d.setX(mc->getAngleCoordinate().x());
// p3d.setY(mc->getAngleCoordinate().y());
// val = img->valueBuffer[y][x]->val;
// p3d.setZ(val);
// if ((minval > val)||((y+x)==0)){
// minval = val;
// }
// if ((maxval < val)||((y+x)==0)){
// maxval = val;
// }
// vec->replace(y*img->getWidth()+x,p3d);
// }
// }
// s->setPenWidth(Pixelsize);
// QwtInterval interval;
// if (nextColorbarMin == nextColorbarMax)
// interval.setInterval(minval,maxval);
// else
// interval.setInterval(nextColorbarMin,nextColorbarMax);
// s->setColorRange(interval);
// s->setSamples(*vec);

// plot->getPlot()->enableAxis(QwtPlot::xTop,true);
// QwtScaleWidget *rightAxis = plot->getPlot()->axisWidget(QwtPlot::xTop);
// //rightAxis->setTitle("Intensity");
// rightAxis->setColorBarEnabled(true);
// rightAxis->setColorMap( interval, new ColorMap());
// plot->getPlot()->setAxisScale(QwtPlot::xTop,interval.minValue(),interval.maxValue());
// rightAxis->setColorBarWidth(20);
// plot->getPlot()->replot();
// if(!nextTitle.isEmpty())
// plot->getPlot()->setTitle(nextTitle);
// nextTitle = "";
// if(!nextXTitle.isEmpty())
// plot->getPlot()->setAxisTitle(QwtPlot::xBottom,nextXTitle);
// nextXTitle = "";
// if(!nextYTitle.isEmpty())
// plot->getPlot()->setAxisTitle(QwtPlot::yLeft,nextYTitle);
// nextYTitle = "";
double xbuf[tl->getEntryCount()];
double ybuf[tl->getEntryCount()];

for(int i=0;i<tl->getEntryCount();i++){
xbuf[i] = tl->getEntryX(i);
ybuf[i] = tl->getEntryY(i);
}
QwtPlot * p = plot->getPlot();
QwtPlotCurve * c = plot->getCurve(0);
QPen pe;

c->setSamples(xbuf,ybuf,tl->getEntryCount());
c->setPen(pe);

if(!nextTitle.isEmpty())
p->setTitle(nextTitle);
nextTitle = "";
if(!nextXTitle.isEmpty())
p->setAxisTitle(QwtPlot::xBottom,nextXTitle);
nextXTitle = "";
if(!nextYTitle.isEmpty())
p->setAxisTitle(QwtPlot::yLeft,nextYTitle);
nextYTitle = "";
if(nextXRange.first != nextXRange.second)
p->setAxisScale(QwtPlot::xBottom,nextXRange.first,nextXRange.second);


p->setAxisScaleDraw(QwtPlot::xBottom, new DateTimeScaleDraw());
p->setAxisLabelRotation(QwtPlot::xBottom, -50.0);
p->setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
nextXRange.first = 0;
nextXRange.second = 0;
if(nextYRange.first != nextYRange.second)
p->setAxisScale(QwtPlot::yLeft,nextYRange.first,nextYRange.second);
nextYRange.first = 0;
nextYRange.second = 0;
if(nextColor != NULL)
c->setPen(*nextColor);
delete nextColor;
nextColor = NULL;

p->replot();
}


Expand Down
21 changes: 19 additions & 2 deletions maxdoas/ttimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ void ttimeline::setYAxisName(QString name)
xAxisName = name;
}

void ttimeline::addPoint(QDateTime time, double val)
int ttimeline::getEntryCount()
{
timeLine.append(QPair<QDateTime,float>(time,val));

return timeLine.count();
}

void ttimeline::addPoint(double ms, double val)
{
timeLine.append(QPair<QDateTime,float>(QDateTime::fromMSecsSinceEpoch(ms),val));
}

double ttimeline::getEntryX(int i)
{
return timeLine[i].first.toMSecsSinceEpoch();
}

double ttimeline::getEntryY(int i)
{
return timeLine[i].second;
}


8 changes: 7 additions & 1 deletion maxdoas/ttimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ class ttimeline:public QObject, QScriptable

public slots:
void plot(int plotIndex);
void addPoint(QDateTime time,double val);
//void addPoint(QDateTime time,double val);
void addPoint(double ms,double val);
void setXAxisName(QString name);
void setYAxisName(QString name);

public:
int getEntryCount();
double getEntryX(int i);
double getEntryY(int i);

private:
QString xAxisName;
QString yAxisName;
Expand Down
4 changes: 4 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Sum = 0
tl = TTimeLine();
for (i=1; i<=10; i++){
print('hello'+ Sum.toString());
tl.addPoint(msSinceEpoch(),Sum);
tl.plot(0);
Sum += 1
sleep(1000);
}
plot.plotToFile("pdf","test1.pdf",0,300,200,72)

0 comments on commit 61a3218

Please sign in to comment.