Changeset 142 for Evidence/Edd


Ignore:
Timestamp:
01/13/10 12:47:33 (15 years ago)
Author:
ogrimm
Message:
Various updates
Location:
Evidence/Edd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Edd/Edd.cc

    r139 r142  
     1
    12/* ============================================================
    23
     
    1920        Qt::gray, Qt::darkGray, Qt::lightGray};
    2021
     22class GUI *Handler;
     23
    2124//////////////////////////////////////////
    2225// Text display for arbitary DIM service//
     
    2629Edd_Indicator::Edd_Indicator(QString DIMService, QWidget *P): QLineEdit(P) {
    2730
    28   ServiceName = qstrdup(DIMService.toAscii().data());
    29  
    3031  // Widget properties
    3132  setReadOnly(true);
    3233  setMaximumWidth(100);
    33   connect(this, SIGNAL(YEP(QString)), this, SLOT(setText(QString)));
     34  ShowAsTime = false;
     35 
     36  // Connect to DIM handler
     37  if (connect(Handler, SIGNAL(YEP(DimInfo*, int, QString, QByteArray, QString)), SLOT(Update(DimInfo*, int, QString, QByteArray, QString))) == false) {
     38    printf("Failed connection for %s\n", DIMService.toAscii().data());
     39  }
    3440
    3541  // Context menu
    3642  Menu = new QMenu(this);
     43  Menu->addAction("Open history", this, SLOT(MenuOpenHistory()));
    3744  Menu->addAction("Copy service", this, SLOT(MenuCopyService()));
    3845
    3946  // DIM client
    40   Data = new DimStampedInfo(ServiceName, INT_MAX, (char *) NO_LINK, this);
     47  Data = new DimStampedInfo(DIMService.toAscii().data(), INT_MAX, (char *) NO_LINK, Handler);
    4148}
    4249
     
    4451Edd_Indicator::~Edd_Indicator() {
    4552  delete Data;
    46   delete[] ServiceName;
    47 }
    48 
    49 // Handling of DIM service update
    50 void Edd_Indicator::infoHandler() {
    51 
     53}
     54
     55// Update widget
     56void Edd_Indicator::Update(DimInfo *Info, int Time, QString Format, QByteArray Data, QString Text) {
     57
     58  if (Info != this->Data) return;
     59   
    5260  QPalette Pal = palette(); 
    53   QString S;
    5461
    5562  // Check if service available
    56   if (getInfo()->getSize() == strlen(NO_LINK)+1 && strcmp(getInfo()->getString(), NO_LINK) == 0) {
    57     emit(YEP(QString("n/a")));
    58     setStatusTip(QString("%1:  unavailable").arg(ServiceName));
    59     Pal.setColor(backgroundRole(), Qt::red);
    60     setPalette(Pal);
    61     return;
    62   }
    63   Pal.setColor(backgroundRole(), Qt::white);
    64 
    65   // Translate data into ASCII
    66   char *Text = EvidenceServer::ToString(getInfo());
    67 
    68   // If this is a status indicator, adapt background colour
    69   if (getInfo()->getSize() == (int) strlen(Text)+3) {
    70     switch (*((char *) getInfo()->getData() + strlen(Text) + 2)) {
    71       case 0:  Pal.setColor(backgroundRole(), Qt::white); break;
    72       case 1:  Pal.setColor(backgroundRole(), Qt::cyan); break;
    73       case 2:  Pal.setColor(backgroundRole(), Qt::red); break;
    74       case 3:  Pal.setColor(backgroundRole(), Qt::red); break;
    75       default: break;
    76     }
    77   }
     63  if (Time == -1) {
     64    setText("n/a");
     65        setStatusTip(QString("%1:  unavailable").arg(Info->getName()));
     66    Pal.setColor(QPalette::Base, Qt::lightGray);
     67  }
     68  else {
     69    // If this is a status indicator, adapt background colour
     70    if (Data.size() == Text.size()+2) {
     71      switch (Data[Text.size() + 2]) {
     72        case 0:  Pal.setColor(QPalette::Base, Qt::white); break;
     73        case 1:  Pal.setColor(QPalette::Base, Qt::cyan); break;
     74        case 2:  Pal.setColor(QPalette::Base, Qt::red); break;
     75        case 3:  Pal.setColor(QPalette::Base, Qt::red); break;
     76        default: break;
     77      }
     78    }
     79    else Pal.setColor(QPalette::Base, Qt::white);
     80       
     81        if (!ShowAsTime) setText(Text);
     82        else setText(QDateTime::fromTime_t(Text.toInt()).toString());
     83       
     84    // Update status tip
     85    setStatusTip(QString("%1:  Last update %2  Format '%3'").arg(Info->getName(), QDateTime::fromTime_t(Time).toString()).arg(Format));
     86  }
     87 
    7888  setPalette(Pal);
    79  
    80   if (Text != NULL) {
    81     QTextStream(&S) << Text;
    82         free(Text);
    83   }
    84   else QTextStream(&S) << "Cannot interpret format identifier";
    85    
    86   if (strlen(getInfo()->getFormat()) > 1) {
    87     QTextStream(&S) << " (DIM format string longer)";
    88   }
    89  
    90   // Trigger display update
    91   emit(YEP(S));
    92  
    93   // Update status tip
    94   QDateTime Time = QDateTime::fromTime_t(getInfo()->getTimestamp());
    95   setStatusTip(QString("%1:  Last update %2  Format '%3'").arg(ServiceName, Time.toString()).arg(getInfo()->getFormat()));
    9689}
    9790
     
    111104
    112105  // If not, open new plot
    113   LastPlot = new Edd_Plot(ServiceName);
    114   LastPlot->show();
     106  Edd_Indicator::MenuOpenHistory();
    115107}
    116108
     
    129121  QDrag *Drag = new QDrag(this);
    130122  QMimeData *MimeData = new QMimeData;
    131   MimeData->setText(QString(ServiceName));
     123  MimeData->setText(QString(Data->getName()));
    132124  Drag->setMimeData(MimeData);
    133125  Drag->exec();
     
    142134}
    143135
     136// Open history plot
     137void Edd_Indicator::MenuOpenHistory() {
     138 
     139  LastPlot = new Edd_Plot(Data->getName());
     140  LastPlot->show();
     141}
     142
    144143// Copy service name
    145144void Edd_Indicator::MenuCopyService() {
    146145 
    147   QApplication::clipboard()->setText(QString(ServiceName));
     146  QApplication::clipboard()->setText(QString(Data->getName()));
    148147}
    149148
     
    161160 
    162161  // Graph properties
    163   QwtText XAxisTitle("Time (RJD-55000)");
     162  setAutoReplot(false);
     163  QwtText XAxisTitle("Time (RJD-55200)");
    164164  XAxisTitle.setFont(QFont("Helvetica", 10));
    165165  setAxisTitle(QwtPlot::xBottom, XAxisTitle);
    166   setAutoReplot(false);
    167166  setCanvasBackground(QColor(Qt::yellow));
    168  
     167
    169168  Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,canvas());
    170169  connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
     
    176175  Legend = new QwtLegend();
    177176  insertLegend(Legend, QwtPlot::TopLegend);
    178    
    179   // Threads may not call replot directly, but only through this signal
    180   connect(this, SIGNAL(YEP()), this, SLOT(UpdatePlot()));
     177
     178  // Connect to DIM handler
     179  if (connect(Handler, SIGNAL(YEP(DimInfo *, int, QString, QByteArray, QString)), SLOT(Update(DimInfo *, int, QString, QByteArray, QString))) == false) {
     180    printf("Failed connection for %s\n", DIMService.toAscii().data());
     181  }
    181182
    182183  // Context menu
     
    222223
    223224  QString HistName = Name+".hist";
    224  
     225
    225226  // Lock before accessing Items list
    226227  QMutexLocker Locker(&Mutex);
     
    233234    }
    234235  } 
    235 
     236 
    236237  // Generate new curve and subscribe to service
    237238  struct PlotItem New;
     
    239240  New.Signal->attach(this);
    240241  New.Signal->setTitle(HistName);
    241   New.Signal->setPen(QColor(LineColors[Items.size()%(sizeof(LineColors)/sizeof(Qt::GlobalColor))]));
     242  New.Signal->setPen(QColor(LineColors[Items.size() % (sizeof(LineColors)/sizeof(Qt::GlobalColor))]));
    242243  New.x = NULL;
    243244  New.y = NULL;
    244245  New.Count = 0;
    245   New.Data = new DimStampedInfo(HistName.toAscii(), NO_LINK, this);
    246   New.LiveData = new DimStampedInfo(Name.toAscii(), NO_LINK, this);
     246  New.Data = new DimStampedInfo(HistName.toAscii().data(), (char *) NO_LINK, Handler);
     247  New.LiveData = new DimStampedInfo(Name.toAscii().data(), (char *) NO_LINK, Handler);
    247248
    248249  Items.append(New);
    249250}
    250251
    251 //
    252 // Handle update of DIM service
    253 //
    254 void Edd_Plot::infoHandler() {
     252// Update widget (must happen in GUI thread)
     253void Edd_Plot::Update(DimInfo *Info, int Time, QString Format, QByteArray Data, QString Text) {
    255254
    256255  // Check if service available
    257   if (getInfo()->getSize() == strlen(NO_LINK)+1 && strcmp(getInfo()->getString(), NO_LINK) == 0) {
    258     setStatusTip(QString("%1:  unavailable").arg(getInfo()->getName()));
    259     return;
     256  if (Time == -1) {
     257        setStatusTip(QString("%1:  unavailable").arg(Info->getName()));
    260258  }
    261259
     
    265263  // Determine which plot item this call belongs to
    266264  int ItemNo;
    267   for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (Items[ItemNo].Data == getInfo()) {
     265  for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (Info == Items[ItemNo].Data) {
    268266    // This is a history service 
    269     EvidenceHistoryItem *Curr = (EvidenceHistoryItem *) getInfo()->getData();
    270     int Count=0, DataPoints = getInfo()->getSize()/sizeof(struct EvidenceHistoryItem);
     267    EvidenceHistoryItem *Curr = (EvidenceHistoryItem *) Data.data();
     268    int Count=0, DataPoints = Data.size()/sizeof(struct EvidenceHistoryItem);
    271269
    272270    delete[] Items[ItemNo].x;
     
    302300
    303301    // Update status tip
    304     QDateTime Time = QDateTime::fromTime_t(getInfo()->getTimestamp());
    305     setStatusTip(QString("%1:  Last update %2  Format '%3'").arg(getInfo()->getName(), Time.toString()).arg(getInfo()->getFormat()));
    306 
    307   } else if (Items[ItemNo].LiveData == getInfo()) {
     302    QDateTime Timex = QDateTime::fromTime_t(Time);
     303    StatusTip = QString("%1:  Last update %2  Format '%3'").arg(Info->getName(), Timex.toString()).arg(Format);
     304
     305  } else if (Info == Items[ItemNo].LiveData) {
    308306    // This is a live service
    309307
     
    313311    // Append data
    314312    struct EvidenceHistoryItem Data;
    315     Data.Seconds = getInfo()->getTimestamp();
    316     Data.Value = atof(EvidenceServer::ToString(getInfo()));           
     313    Data.Seconds = Time;
     314    Data.Value = atof(Text.toAscii().data());           
    317315    Items[ItemNo].Live.append(Data);
    318    
     316
    319317    // Update largest and smallest value   
    320318    if (Data.Value > Items[ItemNo].Largest) Items[ItemNo].Largest = Data.Value;
     
    324322  Locker.unlock();
    325323
    326   // Do not call replot() directly from this thread!
    327   emit(YEP());
    328 }
    329 
     324  UpdatePlot();
     325}
    330326
    331327//
     
    333329//
    334330void Edd_Plot::UpdatePlot() {
     331
     332  static QwtSymbol Symbol, Sym1;
     333  Symbol.setStyle(QwtSymbol::Ellipse);
     334  Symbol.setSize(4);
    335335
    336336  if (!YLogAction->isChecked()) {
     
    342342  QMutexLocker Locker(&Mutex);
    343343
     344  setStatusTip(StatusTip);
     345 
    344346  for (int ItemNo=0; ItemNo<Items.size(); ItemNo++) {
    345347
    346     if (Items[ItemNo].Count == 0) continue;
    347 
    348     if (StyleAction->isChecked()) Items[ItemNo].Signal->setStyle(QwtPlotCurve::Dots);
    349     else Items[ItemNo].Signal->setStyle(QwtPlotCurve::Lines);
    350 
    351     int DataPoints = Items[ItemNo].Count + Items[ItemNo].Live.size();     
     348    if (StyleAction->isChecked()) Items[ItemNo].Signal->setSymbol(Symbol);
     349    else Items[ItemNo].Signal->setSymbol(Sym1);
     350
     351    int DataPoints = Items[ItemNo].Count + Items[ItemNo].Live.size();
     352       
     353        if (DataPoints == 0) continue;
     354   
    352355    double *x = new double [DataPoints];
    353356    double *y = new double [DataPoints];
    354     
     357 
    355358    // Adapt time scale and normalize y scale if requested
    356359    for (int i=0; i<DataPoints; i++) {
    357360      if (i < Items[ItemNo].Count) {
    358         x[i] = Items[ItemNo].x[i] / 86400.0 + 40587.5 - 55000;
     361        x[i] = Items[ItemNo].x[i] / 86400.0 + 40587.5 - 55200;
    359362        y[i] = Items[ItemNo].y[i];
    360363      }
    361364      else {
    362         x[i]= Items[ItemNo].Live[i-Items[ItemNo].Count].Seconds / 86400.0 + 40587.5 - 55000;
     365        x[i]= Items[ItemNo].Live[i-Items[ItemNo].Count].Seconds / 86400.0 + 40587.5 - 55200;
    363366        y[i] = Items[ItemNo].Live[i-Items[ItemNo].Count].Value;
    364367      }
     
    498501
    499502
     503//////////////////
     504// Text display //
     505//////////////////
     506
     507// Constructor
     508Edd_Textout::Edd_Textout(QString DIMService, QWidget *P): QTextEdit(P) {
     509
     510  // Widget properties
     511  setReadOnly(true);
     512  setAutoFillBackground(true);
     513  document()->setMaximumBlockCount(1000);
     514  Accumulate = true;
     515 
     516  // Connect to DIM handler
     517  if (connect(Handler, SIGNAL(YEP(DimInfo*, int, QString, QByteArray, QString)), SLOT(Update(DimInfo*, int, QString, QByteArray, QString))) == false) {
     518    printf("Failed connection for %s\n", DIMService.toAscii().data());
     519  }
     520
     521  // DIM client
     522  Data = new DimStampedInfo(DIMService.toAscii().data(), INT_MAX, (char *) NO_LINK, Handler);
     523}
     524
     525// Destructor
     526Edd_Textout::~Edd_Textout() {
     527
     528  delete Data;
     529}
     530
     531// Handling of DIM service update
     532void Edd_Textout::Update(DimInfo *Info, int Time, QString Format, QByteArray, QString Text) {
     533
     534  if (Info != this->Data) return;
     535 
     536  QPalette Pal = palette(); 
     537
     538  // Check if service available
     539  if (Time == -1) {
     540        setStatusTip(QString("%1:  unavailable").arg(Info->getName()));
     541    Pal.setColor(QPalette::Base, Qt::lightGray);
     542  }
     543  else {
     544    Pal.setColor(QPalette::Base, Qt::white);
     545
     546        // Clear display in case text should not accumulate
     547        if (Accumulate == false) clear();
     548       
     549    // Add if service contains only a string
     550    if (Format == "C") insertPlainText(Text);
     551
     552    // Update status tip
     553    setStatusTip(QString("%1:  Last update %2  Format '%3'").arg(Info->getName(), QDateTime::fromTime_t(Time).toString()).arg(Format));
     554  }
     555  setPalette(Pal);
     556}
     557
     558
    500559//
    501560// Main GUI (all widgets have ultimately Central as parent)
    502561//
    503562GUI::GUI() {
    504 
    505   Edd_Indicator *Value;
    506   Edd_Plot *Graph;
    507   QString Text;
     563 
     564  Handler = this;
    508565 
    509566  // Set features of main window
     
    511568  setCentralWidget(Central);
    512569  setStatusBar(new QStatusBar(this));
    513  
     570  setGeometry(100, 100, 800, 650);
     571  setWindowTitle("Edd - Evidence Data Display");
     572
     573  Edd_Indicator *Value;
     574  Edd_Plot *Graph;
     575  Edd_Textout *Textout;
     576  QString Text;
     577
    514578   // TextBox for value
    515579  //Value = new Edd_Indicator((char *) "SQM/NSB", Central);
     
    532596  MainWidget = new QWidget();
    533597  MainLayout = new QGridLayout(MainWidget);
     598
     599  Value = new Edd_Indicator("DColl/DataSizekB");
     600  MainLayout->addWidget(Value, 3, 5, 1, 1);
     601
     602  Value = new Edd_Indicator("DColl/LogSizekB");
     603  MainLayout->addWidget(Value, 4, 5, 1, 1);
     604
     605  Value = new Edd_Indicator("Config/ModifyTime");
     606  Value->setMaximumWidth(200);
     607  Value->ShowAsTime = true;
     608  MainLayout->addWidget(Value, 5, 5, 1, 1);
     609
     610  Value = new Edd_Indicator("Alarm/MasterAlarm");
     611  MainLayout->addWidget(Value, 2, 0, 1, 1);
     612
     613  Textout = new Edd_Textout("Alarm/Summary");
     614  Textout->Accumulate = false;
     615  MainLayout->addWidget(Textout, 3, 0, 2, 1);
    534616
    535617  // Layout of all widgets
     
    557639    Graph->AddService(Text);
    558640  }
     641
    559642  BiasLayout->addWidget(Graph, 0, 4, 12, 3);
    560643  Value = new Edd_Indicator("BIAS/Status");
     
    562645  BiasLayout->addWidget(Value, 0, 0, 1, 3);     
    563646
     647  Textout = new Edd_Textout("BIAS/Textout");
     648  Textout->setFixedWidth(400);
     649  BiasLayout->addWidget(Textout, 10, 0, 4, 4);     
     650 
    564651  // Environment page
    565652  EnvironmentWidget = new QWidget();
     
    580667  Value = new Edd_Indicator("SQM/NSB");
    581668  EnvironmentLayout->addWidget(Value, 6, 0, 1, 1);     
    582    
     669
    583670  // Tab widget
    584671  TabWidget = new QTabWidget(Central);
     
    595682  QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
    596683  QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
     684
     685  // Show main window
     686  show();
    597687
    598688   
     
    601691}
    602692
     693
    603694void GUI::MenuAbout() {
    604695  QString Rev(SVN_REVISION);
    605   Rev.remove(0,1).chop(1);
     696  Rev.remove(0,1).chop(2);
    606697 
    607698  QMessageBox::about(this, "About Edd","Evidence Data Display\n\n"
    608699    "Written by Oliver Grimm, IPP, ETH Zurich\n"
    609700    "This version compiled "__DATE__" ("+Rev+")\n\n"
    610     "Graphical user interface implemented with Qt.\n"
     701    "Graphical user interface implemented with Qt and Qwt.\n"
    611702    "Evidence control system based on DIM (http://dim.web.cern.ch).\n\n"
    612703    "Comments to oliver.grimm@phys.ethz.ch.");
     
    639730}
    640731
     732// Handling of DIM service update
     733void GUI::infoHandler() {
     734
     735  // Check if service available
     736  if (getInfo()->getSize() == strlen(NO_LINK)+1 && strcmp(getInfo()->getString(), NO_LINK) == 0) {
     737    YEP(getInfo(), -1);
     738  }
     739  else {
     740    char *Txt = EvidenceServer::ToString(getInfo());
     741
     742    YEP(getInfo(), getInfo()->getTimestamp(), getInfo()->getFormat(), QByteArray((char *) getInfo()->getData(), getInfo()->getSize()), QString(Txt));
     743                free(Txt);
     744  }
     745}
     746
    641747//---------------------------------------------------------------------
    642748//************************ All functions ****************************
     
    654760
    655761int main(int argc, char *argv[]) {
    656   QApplication app(argc, argv);
    657  
     762
     763  QApplication app(argc, argv);
    658764  GUI MainWindow;
    659   MainWindow.setGeometry(100, 100, 800, 650);
    660   MainWindow.setWindowTitle("Edd - Evidence Data Display");
    661   MainWindow.show();
    662  
     765
    663766  return app.exec();
    664767}
  • Evidence/Edd/Edd.h

    r139 r142  
    1515#include <qwt_legend.h>
    1616#include <qwt_legend_item.h>
     17#include <qwt_symbol.h>
    1718
    1819#include <limits.h>
     
    2223#include "Evidence.h"
    2324
    24 #define NO_LINK "__&DIM&NOLINK&__" // for checking if DIMserver is alive
    2525#define SVN_REVISION "$Revision$"
    2626                 
    2727// General indicator for DIM service
    28 class Edd_Indicator: public QLineEdit, public DimClient, public DimBrowser {
     28class Edd_Indicator: public QLineEdit, public DimClient {
    2929    Q_OBJECT
    30 
    31     char *ServiceName;
    32     DimStampedInfo *Data;
    3330
    3431    QMenu *Menu;
    3532    QPoint dragStart;
    3633    QwtPlot *LastPlot;
    37        
    38     void infoHandler();
     34       
     35    DimStampedInfo *Data;
     36       
    3937    void mousePressEvent(QMouseEvent *);
    4038    void mouseReleaseEvent(QMouseEvent *);
     
    4543    ~Edd_Indicator();
    4644
     45        bool ShowAsTime;
     46       
    4747  private slots:
     48        void Update(DimInfo *, int, QString, QByteArray, QString);
    4849    void contextMenuEvent(QContextMenuEvent *);   
     50    void MenuOpenHistory();
    4951    void MenuCopyService();
    50 
    51   signals:
    52     void YEP(QString);
    5352};
    5453
     
    7271    QMutex Mutex;
    7372   
     73        QString StatusTip;
     74       
    7475    QMenu *Menu;
    7576    QAction *YLogAction;
     
    8283    QwtLegend *Legend;
    8384   
    84     void infoHandler();   
    8585    void dragEnterEvent(QDragEnterEvent *);
    8686    void dropEvent(QDropEvent *);
     
    9393  private slots:
    9494    void UpdatePlot();
     95        void Update(DimInfo* Info, int, QString, QByteArray, QString);
     96
    9597    void HandleZoom(const QwtDoubleRect &);
    9698    void contextMenuEvent(QContextMenuEvent *);   
     
    101103    void MenuPrint();
    102104    void MenuPasteService();
    103  
    104  signals:
    105      void YEP();
     105};
    106106
     107// Textout indicator for DIM service
     108class Edd_Textout: public QTextEdit, public DimClient {
     109    Q_OBJECT
     110
     111    DimStampedInfo *Data;
     112
     113  public:
     114    Edd_Textout(QString, QWidget * = NULL);
     115    ~Edd_Textout();
     116       
     117        bool Accumulate;
     118       
     119  private slots:
     120        void Update(DimInfo* Info, int, QString, QByteArray, QString);
    107121};
    108122
    109123// Main window class
    110 class GUI: public QMainWindow, public DimBrowser {
     124class GUI: public QMainWindow, public DimBrowser, public DimInfo {
    111125    Q_OBJECT
    112126
     
    118132    QTabWidget *TabWidget;
    119133           
    120     void closeEvent(QCloseEvent *);
    121 
     134    void closeEvent(QCloseEvent *);
     135        void infoHandler();
     136       
    122137  public:
    123138    GUI();
     
    127142    void MenuAbout();
    128143    void MenuNewHistory();
     144       
     145  signals:
     146    void YEP(DimInfo *, int, QString = QString(), QByteArray = QByteArray(), QString = QString());
    129147};
    130148
Note: See TracChangeset for help on using the changeset viewer.