Changeset 142 for Evidence/Edd
- Timestamp:
- 01/13/10 12:47:33 (15 years ago)
- Location:
- Evidence/Edd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Edd/Edd.cc
r139 r142 1 1 2 /* ============================================================ 2 3 … … 19 20 Qt::gray, Qt::darkGray, Qt::lightGray}; 20 21 22 class GUI *Handler; 23 21 24 ////////////////////////////////////////// 22 25 // Text display for arbitary DIM service// … … 26 29 Edd_Indicator::Edd_Indicator(QString DIMService, QWidget *P): QLineEdit(P) { 27 30 28 ServiceName = qstrdup(DIMService.toAscii().data());29 30 31 // Widget properties 31 32 setReadOnly(true); 32 33 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 } 34 40 35 41 // Context menu 36 42 Menu = new QMenu(this); 43 Menu->addAction("Open history", this, SLOT(MenuOpenHistory())); 37 44 Menu->addAction("Copy service", this, SLOT(MenuCopyService())); 38 45 39 46 // 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); 41 48 } 42 49 … … 44 51 Edd_Indicator::~Edd_Indicator() { 45 52 delete Data; 46 delete[] ServiceName; 47 } 48 49 // Handling of DIM service update 50 void Edd_Indicator::infoHandler() { 51 53 } 54 55 // Update widget 56 void Edd_Indicator::Update(DimInfo *Info, int Time, QString Format, QByteArray Data, QString Text) { 57 58 if (Info != this->Data) return; 59 52 60 QPalette Pal = palette(); 53 QString S;54 61 55 62 // 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 78 88 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 update91 emit(YEP(S));92 93 // Update status tip94 QDateTime Time = QDateTime::fromTime_t(getInfo()->getTimestamp());95 setStatusTip(QString("%1: Last update %2 Format '%3'").arg(ServiceName, Time.toString()).arg(getInfo()->getFormat()));96 89 } 97 90 … … 111 104 112 105 // If not, open new plot 113 LastPlot = new Edd_Plot(ServiceName); 114 LastPlot->show(); 106 Edd_Indicator::MenuOpenHistory(); 115 107 } 116 108 … … 129 121 QDrag *Drag = new QDrag(this); 130 122 QMimeData *MimeData = new QMimeData; 131 MimeData->setText(QString( ServiceName));123 MimeData->setText(QString(Data->getName())); 132 124 Drag->setMimeData(MimeData); 133 125 Drag->exec(); … … 142 134 } 143 135 136 // Open history plot 137 void Edd_Indicator::MenuOpenHistory() { 138 139 LastPlot = new Edd_Plot(Data->getName()); 140 LastPlot->show(); 141 } 142 144 143 // Copy service name 145 144 void Edd_Indicator::MenuCopyService() { 146 145 147 QApplication::clipboard()->setText(QString( ServiceName));146 QApplication::clipboard()->setText(QString(Data->getName())); 148 147 } 149 148 … … 161 160 162 161 // Graph properties 163 QwtText XAxisTitle("Time (RJD-55000)"); 162 setAutoReplot(false); 163 QwtText XAxisTitle("Time (RJD-55200)"); 164 164 XAxisTitle.setFont(QFont("Helvetica", 10)); 165 165 setAxisTitle(QwtPlot::xBottom, XAxisTitle); 166 setAutoReplot(false);167 166 setCanvasBackground(QColor(Qt::yellow)); 168 167 169 168 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,canvas()); 170 169 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &))); … … 176 175 Legend = new QwtLegend(); 177 176 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 } 181 182 182 183 // Context menu … … 222 223 223 224 QString HistName = Name+".hist"; 224 225 225 226 // Lock before accessing Items list 226 227 QMutexLocker Locker(&Mutex); … … 233 234 } 234 235 } 235 236 236 237 // Generate new curve and subscribe to service 237 238 struct PlotItem New; … … 239 240 New.Signal->attach(this); 240 241 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))])); 242 243 New.x = NULL; 243 244 New.y = NULL; 244 245 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); 247 248 248 249 Items.append(New); 249 250 } 250 251 251 // 252 // Handle update of DIM service 253 // 254 void Edd_Plot::infoHandler() { 252 // Update widget (must happen in GUI thread) 253 void Edd_Plot::Update(DimInfo *Info, int Time, QString Format, QByteArray Data, QString Text) { 255 254 256 255 // 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())); 260 258 } 261 259 … … 265 263 // Determine which plot item this call belongs to 266 264 int ItemNo; 267 for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (I tems[ItemNo].Data == getInfo()) {265 for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (Info == Items[ItemNo].Data) { 268 266 // 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); 271 269 272 270 delete[] Items[ItemNo].x; … … 302 300 303 301 // 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 (I tems[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) { 308 306 // This is a live service 309 307 … … 313 311 // Append data 314 312 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()); 317 315 Items[ItemNo].Live.append(Data); 318 316 319 317 // Update largest and smallest value 320 318 if (Data.Value > Items[ItemNo].Largest) Items[ItemNo].Largest = Data.Value; … … 324 322 Locker.unlock(); 325 323 326 // Do not call replot() directly from this thread! 327 emit(YEP()); 328 } 329 324 UpdatePlot(); 325 } 330 326 331 327 // … … 333 329 // 334 330 void Edd_Plot::UpdatePlot() { 331 332 static QwtSymbol Symbol, Sym1; 333 Symbol.setStyle(QwtSymbol::Ellipse); 334 Symbol.setSize(4); 335 335 336 336 if (!YLogAction->isChecked()) { … … 342 342 QMutexLocker Locker(&Mutex); 343 343 344 setStatusTip(StatusTip); 345 344 346 for (int ItemNo=0; ItemNo<Items.size(); ItemNo++) { 345 347 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 352 355 double *x = new double [DataPoints]; 353 356 double *y = new double [DataPoints]; 354 357 355 358 // Adapt time scale and normalize y scale if requested 356 359 for (int i=0; i<DataPoints; i++) { 357 360 if (i < Items[ItemNo].Count) { 358 x[i] = Items[ItemNo].x[i] / 86400.0 + 40587.5 - 55 000;361 x[i] = Items[ItemNo].x[i] / 86400.0 + 40587.5 - 55200; 359 362 y[i] = Items[ItemNo].y[i]; 360 363 } 361 364 else { 362 x[i]= Items[ItemNo].Live[i-Items[ItemNo].Count].Seconds / 86400.0 + 40587.5 - 55 000;365 x[i]= Items[ItemNo].Live[i-Items[ItemNo].Count].Seconds / 86400.0 + 40587.5 - 55200; 363 366 y[i] = Items[ItemNo].Live[i-Items[ItemNo].Count].Value; 364 367 } … … 498 501 499 502 503 ////////////////// 504 // Text display // 505 ////////////////// 506 507 // Constructor 508 Edd_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 526 Edd_Textout::~Edd_Textout() { 527 528 delete Data; 529 } 530 531 // Handling of DIM service update 532 void 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 500 559 // 501 560 // Main GUI (all widgets have ultimately Central as parent) 502 561 // 503 562 GUI::GUI() { 504 505 Edd_Indicator *Value; 506 Edd_Plot *Graph; 507 QString Text; 563 564 Handler = this; 508 565 509 566 // Set features of main window … … 511 568 setCentralWidget(Central); 512 569 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 514 578 // TextBox for value 515 579 //Value = new Edd_Indicator((char *) "SQM/NSB", Central); … … 532 596 MainWidget = new QWidget(); 533 597 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); 534 616 535 617 // Layout of all widgets … … 557 639 Graph->AddService(Text); 558 640 } 641 559 642 BiasLayout->addWidget(Graph, 0, 4, 12, 3); 560 643 Value = new Edd_Indicator("BIAS/Status"); … … 562 645 BiasLayout->addWidget(Value, 0, 0, 1, 3); 563 646 647 Textout = new Edd_Textout("BIAS/Textout"); 648 Textout->setFixedWidth(400); 649 BiasLayout->addWidget(Textout, 10, 0, 4, 4); 650 564 651 // Environment page 565 652 EnvironmentWidget = new QWidget(); … … 580 667 Value = new Edd_Indicator("SQM/NSB"); 581 668 EnvironmentLayout->addWidget(Value, 6, 0, 1, 1); 582 669 583 670 // Tab widget 584 671 TabWidget = new QTabWidget(Central); … … 595 682 QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit())); 596 683 QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q); 684 685 // Show main window 686 show(); 597 687 } 598 688 … … 601 691 } 602 692 693 603 694 void GUI::MenuAbout() { 604 695 QString Rev(SVN_REVISION); 605 Rev.remove(0,1).chop( 1);696 Rev.remove(0,1).chop(2); 606 697 607 698 QMessageBox::about(this, "About Edd","Evidence Data Display\n\n" 608 699 "Written by Oliver Grimm, IPP, ETH Zurich\n" 609 700 "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" 611 702 "Evidence control system based on DIM (http://dim.web.cern.ch).\n\n" 612 703 "Comments to oliver.grimm@phys.ethz.ch."); … … 639 730 } 640 731 732 // Handling of DIM service update 733 void 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 641 747 //--------------------------------------------------------------------- 642 748 //************************ All functions **************************** … … 654 760 655 761 int main(int argc, char *argv[]) { 656 QApplication app(argc, argv); 657 762 763 QApplication app(argc, argv); 658 764 GUI MainWindow; 659 MainWindow.setGeometry(100, 100, 800, 650); 660 MainWindow.setWindowTitle("Edd - Evidence Data Display"); 661 MainWindow.show(); 662 765 663 766 return app.exec(); 664 767 } -
Evidence/Edd/Edd.h
r139 r142 15 15 #include <qwt_legend.h> 16 16 #include <qwt_legend_item.h> 17 #include <qwt_symbol.h> 17 18 18 19 #include <limits.h> … … 22 23 #include "Evidence.h" 23 24 24 #define NO_LINK "__&DIM&NOLINK&__" // for checking if DIMserver is alive25 25 #define SVN_REVISION "$Revision$" 26 26 27 27 // General indicator for DIM service 28 class Edd_Indicator: public QLineEdit, public DimClient , public DimBrowser{28 class Edd_Indicator: public QLineEdit, public DimClient { 29 29 Q_OBJECT 30 31 char *ServiceName;32 DimStampedInfo *Data;33 30 34 31 QMenu *Menu; 35 32 QPoint dragStart; 36 33 QwtPlot *LastPlot; 37 38 void infoHandler(); 34 35 DimStampedInfo *Data; 36 39 37 void mousePressEvent(QMouseEvent *); 40 38 void mouseReleaseEvent(QMouseEvent *); … … 45 43 ~Edd_Indicator(); 46 44 45 bool ShowAsTime; 46 47 47 private slots: 48 void Update(DimInfo *, int, QString, QByteArray, QString); 48 49 void contextMenuEvent(QContextMenuEvent *); 50 void MenuOpenHistory(); 49 51 void MenuCopyService(); 50 51 signals:52 void YEP(QString);53 52 }; 54 53 … … 72 71 QMutex Mutex; 73 72 73 QString StatusTip; 74 74 75 QMenu *Menu; 75 76 QAction *YLogAction; … … 82 83 QwtLegend *Legend; 83 84 84 void infoHandler();85 85 void dragEnterEvent(QDragEnterEvent *); 86 86 void dropEvent(QDropEvent *); … … 93 93 private slots: 94 94 void UpdatePlot(); 95 void Update(DimInfo* Info, int, QString, QByteArray, QString); 96 95 97 void HandleZoom(const QwtDoubleRect &); 96 98 void contextMenuEvent(QContextMenuEvent *); … … 101 103 void MenuPrint(); 102 104 void MenuPasteService(); 103 104 signals: 105 void YEP(); 105 }; 106 106 107 // Textout indicator for DIM service 108 class 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); 107 121 }; 108 122 109 123 // Main window class 110 class GUI: public QMainWindow, public DimBrowser {124 class GUI: public QMainWindow, public DimBrowser, public DimInfo { 111 125 Q_OBJECT 112 126 … … 118 132 QTabWidget *TabWidget; 119 133 120 void closeEvent(QCloseEvent *); 121 134 void closeEvent(QCloseEvent *); 135 void infoHandler(); 136 122 137 public: 123 138 GUI(); … … 127 142 void MenuAbout(); 128 143 void MenuNewHistory(); 144 145 signals: 146 void YEP(DimInfo *, int, QString = QString(), QByteArray = QByteArray(), QString = QString()); 129 147 }; 130 148
Note:
See TracChangeset
for help on using the changeset viewer.