Changeset 10984 for fact/Evidence
- Timestamp:
- 06/10/11 15:02:24 (14 years ago)
- Location:
- fact/Evidence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/GUI.cc
r10928 r10984 46 46 if (Format.size() == 1 && Format[0] != 'C') return new EddPlot(Service, Index); 47 47 else return new EddText(Service); 48 49 48 50 } 49 51 … … 235 237 setAcceptDrops(true); 236 238 setAxisScaleDraw(QwtPlot::xBottom, new EddTimeScale); 237 239 238 240 // Update time range on plot when axis change (update() results in paintEvent()) 239 241 connect(axisWidget(QwtPlot::xBottom), SIGNAL(scaleDivChanged()), SLOT(update())); … … 252 254 Menu->insertAction(Menu->actions().value(1), Action); 253 255 254 // Maximum number if points in curve (will be increased in Update()) 255 SizeLimit = 0; 256 // Set timer to regularly update plot if new data available 257 SingleShot = new QTimer(this); 258 connect(SingleShot, SIGNAL(timeout()), this, SLOT(UpdatePlot())); 259 SingleShot->setSingleShot(true); 256 260 257 261 // DIM client … … 284 288 List.append(N); 285 289 290 // Request new history buffer 291 const struct EvidenceHistory::Item *R; 292 class EvidenceHistory *Hist; 293 294 if ((Hist = Handler->GetHistory(Name)) != NULL) { 295 double Number=0; 296 while ((R=Hist->Next()) != NULL) { 297 switch (*(Hist->GetFormat())) { 298 case 'I': 299 case 'L': Number = *((int *) R->Data + N.Index); break; 300 case 'S': Number = *((short *) R->Data + N.Index); break; 301 case 'F': Number = *((float *) R->Data + N.Index); break; 302 case 'D': Number = *((double *) R->Data + N.Index); break; 303 case 'X': Number = *((long long *) R->Data + N.Index); break; 304 default: break; 305 } 306 AddPoint(List.size()-1, R->Time, Number); 307 } 308 } 309 Handler->DropHistory(Name); 286 310 Handler->Subscribe(Name); 311 312 SingleShot->start(100); 287 313 } 288 314 … … 290 316 void EddPlot::Update(QString Name, int Time, QByteArray, QString Format, QString Text) { 291 317 292 bool DoUpdate = false; 293 294 // Determine which plot item this call belongs to 295 int ItemNo; 296 for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) { 297 298 DoUpdate = true; 299 300 // If size limit reached, clear buffer 301 if (List[ItemNo].Signal->dataSize() > SizeLimit) List[ItemNo].Signal->setData(QPolygonF()); 302 303 // If buffer empty, request new history buffer 304 if (List[ItemNo].Signal->dataSize() == 0) { 305 int Count=0; 306 const struct EvidenceHistory::Item *R; 307 class EvidenceHistory *Hist; 308 309 if ((Hist = Handler->GetHistory(List[ItemNo].Name)) != NULL) { 310 double Number=0; 311 while ((R=Hist->Next()) != NULL) { 312 switch (*(Hist->GetFormat())) { 313 case 'I': 314 case 'L': Number = *((int *) R->Data + List[ItemNo].Index); break; 315 case 'S': Number = *((short *) R->Data + List[ItemNo].Index); break; 316 case 'F': Number = *((float *) R->Data + List[ItemNo].Index); break; 317 case 'D': Number = *((double *) R->Data + List[ItemNo].Index); break; 318 case 'X': Number = *((long long *) R->Data + List[ItemNo].Index); break; 319 default: break; 320 } 321 AddPoint(ItemNo, R->Time, Number); 322 Count++; 323 } 324 325 // Local buffer at least twice as large as longest history 326 if (SizeLimit < 2*Count) SizeLimit = 2*Count; 327 } 328 Handler->DropHistory(List[ItemNo].Name); 329 } 330 331 // Append data only if service available 318 for (int ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) { 319 320 // Append data if service available 332 321 if (SetStatus(this, Name, Time, Format)) { 333 322 QString Txt = Text; … … 335 324 AddPoint(ItemNo, Time, atof(Txt.toAscii().data())); 336 325 } 337 } 338 339 if (DoUpdate) UpdatePlot();326 327 NewData = true; 328 } 340 329 } 341 330 … … 412 401 setCanvasBackground(EddPlotBackgroundColor); 413 402 setMargin(15); 403 NewData = false; 414 404 415 405 // Plot navigation … … 460 450 Menu->addAction("Single trace", this, SLOT(MenuSingleTrace())); 461 451 Menu->addSeparator(); 452 Menu->addAction("Set update rate", this, SLOT(MenuSetUpdateRate())); 453 Menu->addSeparator(); 462 454 Menu->addAction("Save as ASCII", this, SLOT(MenuSaveASCII())); 463 455 Menu->addAction("Save plot", this, SLOT(MenuSave())); 464 456 Menu->addAction("Print plot", this, SLOT(MenuPrint())); 465 457 Menu->addAction("Plot help", this, SLOT(MenuPlotHelp())); 458 459 // Set timer to regularly update plot if new data available 460 Timer = new QTimer(this); 461 connect(Timer, SIGNAL(timeout()), this, SLOT(UpdatePlot())); 462 Timer->start(2000); 466 463 } 467 464 … … 527 524 Symbol.setStyle(QwtSymbol::Ellipse); 528 525 Symbol.setSize(4); 526 527 // Only update if called by timer if new data is available 528 if (sender() == Timer && !NewData) return; 529 NewData = false; 529 530 530 531 // Select engine for linear or logarithmic scale … … 560 561 } 561 562 } 562 563 563 564 // Plot data 564 565 Items[ItemNo].Signal->setData(Items[ItemNo].x.data(), y, DataPoints); … … 716 717 } 717 718 UpdatePlot(); 719 } 720 721 // Set maximum update rate of plot 722 void EddBasePlot::MenuSetUpdateRate() { 723 724 bool OK; 725 double Rate; 726 727 Rate = QInputDialog::getDouble(this, "Edd Request", 728 "Minimum period between plot updates (sec)", (double) Timer->interval()/1000, 0, std::numeric_limits<double>::max(), 2, &OK); 729 if (OK) Timer->setInterval(Rate*1000); 718 730 } 719 731 -
fact/Evidence/GUI.h
r10928 r10984 22 22 #include <qwt_color_map.h> 23 23 24 #include <limits .h>24 #include <limits> 25 25 #include <float.h> 26 #include <limits> 26 27 27 28 #include "dic.hxx" … … 72 73 ~EddBasePlot(); 73 74 75 QTimer *Timer; 76 bool NewData; 74 77 QwtPlotCurve *NewCurve(QwtText); 75 78 void ClearCurve(unsigned int); … … 86 89 void contextMenuEvent(QContextMenuEvent *); 87 90 void MenuSingleTrace(); 91 void MenuSetUpdateRate(); 88 92 void MenuZoomOut(); 89 93 void MenuSaveASCII(); … … 172 176 private: 173 177 QwtLegend *Legend; 174 int SizeLimit;178 QTimer *SingleShot; 175 179 176 180 void dragEnterEvent(QDragEnterEvent *);
Note:
See TracChangeset
for help on using the changeset viewer.