MainExplorerWindow.cxx 14.6 KB
Newer Older
1
2
/* Distributed under the Apache License, Version 2.0.
See accompanying NOTICE file for details.*/
Aaron Bray's avatar
Aaron Bray committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <QApplication>
#include <QDockWidget>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLayout>
#include <QMainWindow>
#include <QWidget>
#include <QPlainTextEdit>
#include <QFile>
#include <QDoubleSpinBox>
#include <QGroupBox>
#include <QScrollBar>
#include <QTimer>
#include <QThread>
#include <QPointer>
#include <QtCharts/QChart>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
#include <QCloseEvent>
#include <QMessageBox>

#include "cdm/CommonDataModel.h"
#include "cdm/utils/FileUtils.h"

#ifdef PARAVIEW
  #include <pqActiveObjects.h>
  #include <pqAlwaysConnectedBehavior.h>
  #include <pqApplicationCore.h>
  #include <pqObjectBuilder.h>
  #include <pqPersistentMainWindowStateBehavior.h>
  #include <pqContextView.h>
  #include <pqXYChartView.h>
  #include <pqRenderView.h>

  #include <vtkSMProxy.h>
  #include <vtkSMPropertyHelper.h>
  #include <vtkSMReaderFactory.h>

  #include "GeometryView.h"
#endif

#include "MainExplorerWindow.h"
46
#include "ExplorerIntroWidget.h"
Aaron Bray's avatar
Aaron Bray committed
47
#include "ui_MainExplorerWindow.h"
48
#include "DataRequestViewWidget.h"
Aaron Bray's avatar
Aaron Bray committed
49
50
#include "VitalsMonitorWidget.h"
#include "DynamicControlsWidget.h"
51
#include "EnviornmentWidget.h"
Aaron Bray's avatar
Aaron Bray committed
52
53
#include "cdm/CommonDataModel.h"
#include "PulsePhysiologyEngine.h"
54
#include "cdm/engine/SEDataRequestManager.h"
Aaron Bray's avatar
Aaron Bray committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "cdm/engine/SEEngineTracker.h"
#include "cdm/properties/SEScalarTime.h"

class MainExplorerWindow::Controls : public Ui::MainExplorerWindow
{
public:

  virtual ~Controls()
  {
    delete Pulse;
#ifdef PARAVIEW
    delete GeometryView;
    delete ParaViewRenderView;
#endif
69
    delete ExplorerIntroWidget;
Aaron Bray's avatar
Aaron Bray committed
70
    delete VitalsMonitorWidget;
71
    delete DataRequestViewWidget;
72
	delete EnviornmentWidget;
Aaron Bray's avatar
Aaron Bray committed
73
74
75
76
77
78
79
80
81
    delete DynamicControls;
  }

#ifdef PARAVIEW  
  QPointer<GeometryView>            GeometryView;
  pqRenderView*                     ParaViewRenderView;
#endif
  QPulse*                           Pulse=nullptr;
  QPointer<QThread>                 Thread;
82
  QExplorerIntroWidget*             ExplorerIntroWidget=nullptr;
Aaron Bray's avatar
Aaron Bray committed
83
  QVitalsMonitorWidget*             VitalsMonitorWidget=nullptr;
84
  QDataRequestViewWidget*           DataRequestViewWidget=nullptr;
85
  QEnviornmentWidget*				EnviornmentWidget = nullptr;
Aaron Bray's avatar
Aaron Bray committed
86
87
  QDynamicControlsWidget*           DynamicControls=nullptr;
  std::stringstream                 Status;  
88
89
  double                            CurrentSimTime_s; 
  InputMode                         Mode=InputMode::None;
Aaron Bray's avatar
Aaron Bray committed
90
91
92
93
94
95
};

MainExplorerWindow::MainExplorerWindow()
{
  m_Controls = new Controls();
  m_Controls->setupUi(this);
Aaron Bray's avatar
Aaron Bray committed
96
  setWindowIcon(QIcon("resource/pulse.ico"));
Aaron Bray's avatar
Aaron Bray committed
97
98
99
100
101
102
103
104
105
106
107
#ifdef PARAVIEW 
  new pqAlwaysConnectedBehavior(this);
  new pqPersistentMainWindowStateBehavior(this);
  vtkSMReaderFactory::AddReaderToWhitelist("sources", "XMLPolyDataReader");
  vtkSMReaderFactory::AddReaderToWhitelist("sources", "XMLUnstructuredGridReader");
  pqApplicationCore::instance()->loadConfigurationXML("<xml/>");
#endif
  // This is the widget all input widgets will use
  m_Controls->InputWidget->show();
  m_Controls->InputWidget->raise();
  m_Controls->InputWidget->setVisible(true);
108
  m_Controls->InputLayout->setAlignment(Qt::AlignHCenter);
Aaron Bray's avatar
Aaron Bray committed
109
110
111
112
113
114
115
116
117
118
119
120

  // This is the logger widget
  m_Controls->OutputWidget->show();
  m_Controls->OutputWidget->raise();
  m_Controls->OutputWidget->setVisible(true);
  m_Controls->LogBox->setFontPointSize(10);
  
  m_Controls->Thread = new QThread(parent());
  m_Controls->Pulse = new QPulse(*m_Controls->Thread, *m_Controls->LogBox);
  m_Controls->Pulse->RegisterListener(this);
  m_Controls->Status << "Current Simulation Time : 0s";

121
122
123
124
  m_Controls->ExplorerIntroWidget = new QExplorerIntroWidget(this);
  m_Controls->ExplorerIntroWidget->setTitleBarWidget(new QWidget());
  m_Controls->ExplorerIntroWidget->setVisible(true);
  m_Controls->InputLayout->addWidget(m_Controls->ExplorerIntroWidget);
Aaron Bray's avatar
Aaron Bray committed
125
126

  // Add the IDynamic Controls to the main control area
127
  m_Controls->DynamicControls = new QDynamicControlsWidget(*m_Controls->Pulse, this);
Aaron Bray's avatar
Aaron Bray committed
128
  m_Controls->DynamicControls->setTitleBarWidget(new QWidget());
129
130
  m_Controls->DynamicControls->setVisible(false);
  m_Controls->InputLayout->addWidget(m_Controls->DynamicControls);
Aaron Bray's avatar
Aaron Bray committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

  int tabIdx = 0; // Order is ParaView, Vitals, DataRequests
  //this->setCentralWidget(m_Controls->TabWidget);
#ifdef PARAVIEW
  // Add ParaView view to the tabWidget
  m_Controls->ParaViewRenderView =
      qobject_cast<pqRenderView*>(pqApplicationCore::instance()->getObjectBuilder()->createView(
                                  pqRenderView::renderViewType(),pqActiveObjects::instance().activeServer()));
  m_Controls->GeometryView = new GeometryView(m_Controls->ParaViewRenderView, this);
  m_Controls->GeometryView->LoadGeometry();
  m_Controls->TabWidget->widget(tabIdx++)->layout()->addWidget(m_Controls->ParaViewRenderView->widget());
#else
  m_Controls->TabWidget->removeTab(0);
#endif  
  m_Controls->VitalsMonitorWidget = new QVitalsMonitorWidget(*m_Controls->LogBox, this);
  m_Controls->TabWidget->widget(tabIdx++)->layout()->addWidget(m_Controls->VitalsMonitorWidget);
  m_Controls->TabWidget->setCurrentIndex(tabIdx - 1);
148
149
150
  m_Controls->DataRequestViewWidget = new QDataRequestViewWidget(*m_Controls->Pulse, this);
  m_Controls->DataRequestViewWidget->setTitleBarWidget(new QWidget());
  m_Controls->TabWidget->widget(tabIdx++)->layout()->addWidget(m_Controls->DataRequestViewWidget);
Aaron Bray's avatar
Aaron Bray committed
151
  m_Controls->EnviornmentWidget = new QEnviornmentWidget(*m_Controls->Pulse, this);
152
153
  m_Controls->EnviornmentWidget->setTitleBarWidget(new QWidget());
  m_Controls->TabWidget->widget(tabIdx++)->layout()->addWidget(m_Controls->EnviornmentWidget);
Aaron Bray's avatar
Aaron Bray committed
154

155
  m_Controls->StartEngine->setVisible(false);
Aaron Bray's avatar
Aaron Bray committed
156
  m_Controls->RunInRealtime->setVisible(false);
157
  m_Controls->PlayPause->setVisible(false);
Aaron Bray's avatar
Aaron Bray committed
158
  m_Controls->ResetExplorer->setVisible(false);
159
  m_Controls->ResetEngine->setVisible(false);
Aaron Bray's avatar
Aaron Bray committed
160
161

  connect(m_Controls->RunInRealtime, SIGNAL(clicked()), this, SLOT(RunInRealtime()));
162
  connect(m_Controls->PlayPause,     SIGNAL(clicked()), this, SLOT(PlayPause()));
Aaron Bray's avatar
Aaron Bray committed
163
  connect(m_Controls->ResetExplorer, SIGNAL(clicked()), this, SLOT(ResetExplorer()));
164
165
166

  connect(m_Controls->StartEngine,   SIGNAL(clicked()), this, SLOT(StartEngine()));
  connect(m_Controls->ResetEngine,   SIGNAL(clicked()), this, SLOT(ResetEngine()));
Aaron Bray's avatar
Aaron Bray committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
}

MainExplorerWindow::~MainExplorerWindow()
{
  
  delete m_Controls;
}


void MainExplorerWindow::closeEvent(QCloseEvent *event)
{
  // Are these questions too annoying?
  /*QMessageBox::StandardButton resBtn = QMessageBox::question(this, "Explorer",
    tr("Are you sure you want to exit?\n"),
    QMessageBox::No | QMessageBox::Yes,
    QMessageBox::Yes);
  if (resBtn != QMessageBox::Yes) {
    event->ignore();
  }
  else {
    event->accept();
  }*/
  m_Controls->Pulse->Stop();
  QMainWindow::closeEvent(event);
}

void MainExplorerWindow::PlayPause()
{
  if (m_Controls->Pulse->PlayPause())
196
    m_Controls->PlayPause->setText("Play");
Aaron Bray's avatar
Aaron Bray committed
197
  else
198
    m_Controls->PlayPause->setText("Pause");
Aaron Bray's avatar
Aaron Bray committed
199
200
201
202
203
204
205
206
207
208
209
210
211
}

void MainExplorerWindow::RunInRealtime()
{
  if (m_Controls->Pulse->ToggleRealtime())
    m_Controls->RunInRealtime->setChecked(true);
  else
    m_Controls->RunInRealtime->setChecked(false);
}

void MainExplorerWindow::ResetExplorer()
{
  m_Controls->Pulse->Reset();
212
  m_Controls->Mode = InputMode::None;
213
  m_Controls->DataRequestViewWidget->Reset();
214
  m_Controls->EnviornmentWidget->Reset();
Aaron Bray's avatar
Aaron Bray committed
215
216
  m_Controls->VitalsMonitorWidget->Reset();
  m_Controls->RunInRealtime->setChecked(true);
217
  m_Controls->PlayPause->setText("Pause");
Aaron Bray's avatar
Aaron Bray committed
218
  m_Controls->LogBox->clear();
219
  m_Controls->Status.str("");
Aaron Bray's avatar
Aaron Bray committed
220
221
  m_Controls->Status << "Current Simulation Time : 0s";
  m_Controls->StatusBar->showMessage(QString(m_Controls->Status.str().c_str()));
222
  m_Controls->StartEngine->setVisible(false);
Aaron Bray's avatar
Aaron Bray committed
223
  m_Controls->RunInRealtime->setVisible(false);
224
  m_Controls->PlayPause->setVisible(false);
Aaron Bray's avatar
Aaron Bray committed
225
  m_Controls->ResetExplorer->setVisible(false);
226
227
228
229
  m_Controls->ResetEngine->setVisible(false);
  m_Controls->ExplorerIntroWidget->setVisible(true);
  m_Controls->DynamicControls->setVisible(false);
  m_Controls->DynamicControls->Reset();
Aaron Bray's avatar
Aaron Bray committed
230
231
}

232
void MainExplorerWindow::ResetEngine()
Aaron Bray's avatar
Aaron Bray committed
233
234
235
236
237
{
  m_Controls->Pulse->Reset();
#ifdef PARAVIEW
  m_Controls->GeometryView->Reset();
#endif
238
  m_Controls->DynamicControls->Reset();
239
  m_Controls->DataRequestViewWidget->Reset();
240
  m_Controls->EnviornmentWidget->Reset();
Aaron Bray's avatar
Aaron Bray committed
241
242
  m_Controls->VitalsMonitorWidget->Reset();
  m_Controls->RunInRealtime->setChecked(true);
243
  m_Controls->PlayPause->setText("Pause");
Aaron Bray's avatar
Aaron Bray committed
244
  m_Controls->LogBox->clear();
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

  switch (m_Controls->Mode)
  {
  case InputMode::Showcase:
    StartShowcase();
    break;
  case InputMode::Scenario:
    SetupScenarioEditor();
    break;
  case InputMode::State:
    SetupEngineState();
    break;
  case InputMode::Patient:
    SetupPatientEditor();
    break;
  }
Aaron Bray's avatar
Aaron Bray committed
261
262
}

263
264

void MainExplorerWindow::StartShowcase()
Aaron Bray's avatar
Aaron Bray committed
265
{
266
267
  m_Controls->ExplorerIntroWidget->setVisible(false);
  m_Controls->DynamicControls->setVisible(true);
268
  m_Controls->StartEngine->setVisible(false);
269
  m_Controls->PlayPause->setVisible(true);
270
  m_Controls->RunInRealtime->setVisible(true);
Aaron Bray's avatar
Aaron Bray committed
271
  m_Controls->ResetExplorer->setVisible(true);
272
  m_Controls->ResetEngine->setVisible(true);
273
  m_Controls->EnviornmentWidget->EnableControls(false, false);
274
275
276
277
278
279
280
281
282
283
284
285
286

  if (!m_Controls->DynamicControls->SetupShowcase(m_Controls->ExplorerIntroWidget->GetSelectedShowcase()))
  {
    QMessageBox msgBox(this);
    msgBox.setWindowTitle("Error!");
    QString err = "Unable to setup the : " + m_Controls->ExplorerIntroWidget->GetSelectedShowcase() + " showcase scenario";
    msgBox.setText(err);
    msgBox.exec();
    return;
  }
  m_Controls->Mode = InputMode::Showcase;
  // Start up the engine right away!
  m_Controls->Pulse->Start();
Aaron Bray's avatar
Aaron Bray committed
287
288
}

289
void MainExplorerWindow::SetupScenarioEditor()
Aaron Bray's avatar
Aaron Bray committed
290
{
291
292
293
294
295
296
297
298
299
300
  m_Controls->Pulse->GetEngineTracker().Clear();
  if (m_Controls->DynamicControls->SetupScenarioEditor())
  {
    m_Controls->ExplorerIntroWidget->setVisible(false);
    m_Controls->DynamicControls->setVisible(true);
    m_Controls->StartEngine->setVisible(true);
    m_Controls->PlayPause->setVisible(false);
    m_Controls->RunInRealtime->setVisible(false);
    m_Controls->ResetExplorer->setVisible(true);
    m_Controls->ResetEngine->setVisible(false);
301
    m_Controls->EnviornmentWidget->EnableControls(true, false);
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

    m_Controls->Mode = InputMode::Scenario;
  }
  else
  {
    ResetExplorer();
  }
}

void MainExplorerWindow::SetupEngineState()
{
  if (m_Controls->DynamicControls->SetupEngineState())
  {
    m_Controls->ExplorerIntroWidget->setVisible(false);
    m_Controls->DynamicControls->setVisible(true);
    m_Controls->StartEngine->setVisible(true);
    m_Controls->PlayPause->setVisible(false);
    m_Controls->RunInRealtime->setVisible(false);
    m_Controls->ResetExplorer->setVisible(true);
    m_Controls->ResetEngine->setVisible(false);
322
    m_Controls->EnviornmentWidget->EnableControls(false, false);
323
324
325
326
327
328
329
330
331
332
333
334

    m_Controls->Mode = InputMode::State;
  }
  else
  {
    ResetExplorer();
  }
}

void MainExplorerWindow::SetupPatientEditor()
{
  m_Controls->Pulse->GetEngineTracker().Clear();
335
336
  m_Controls->ExplorerIntroWidget->setVisible(false);
  m_Controls->DynamicControls->setVisible(true);
337
338
339
340
341
  m_Controls->StartEngine->setVisible(true);
  m_Controls->PlayPause->setVisible(false);
  m_Controls->RunInRealtime->setVisible(false);
  m_Controls->ResetExplorer->setVisible(true);
  m_Controls->ResetEngine->setVisible(false);
342
  m_Controls->EnviornmentWidget->EnableControls(true, false);
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

  m_Controls->DynamicControls->SetupPatientEditor();
  m_Controls->Mode = InputMode::Patient;
}
void MainExplorerWindow::StartEngine()
{
  // Make Sure We have a patient...
  if (!m_Controls->DynamicControls->ValidPatient())
  {
    QMessageBox msgBox(this);
    msgBox.setWindowTitle("Error!");
    QString err = "Please ensure patient has at least a name";
    msgBox.setText(err);
    msgBox.exec();
    return;
  }

  m_Controls->StartEngine->setVisible(false);
361
  m_Controls->PlayPause->setVisible(true);
362
  m_Controls->RunInRealtime->setVisible(true);
363
  m_Controls->RunInRealtime->setChecked(true);
364

Aaron Bray's avatar
Aaron Bray committed
365
  m_Controls->ResetExplorer->setVisible(true);
366
  m_Controls->ResetEngine->setVisible(true);
367

368
369
370
371
  m_Controls->PlayPause->setEnabled(false);
  m_Controls->ResetEngine->setEnabled(false);
  m_Controls->ResetExplorer->setEnabled(false);

372
  m_Controls->DynamicControls->PrepStabilization(m_Controls->Mode);
Aaron Bray's avatar
Aaron Bray committed
373
374
375
  m_Controls->Pulse->Start();
}

376

377
378
379
380
381
void MainExplorerWindow::AtSteadyState(PhysiologyEngine& pulse)
{// This is called from a thread, you should NOT update UI here
 // This is where we pull data from pulse, and push any actions to it
  m_Controls->DynamicControls->AtSteadyState(pulse);
  m_Controls->VitalsMonitorWidget->AtSteadyState(pulse);
382
  m_Controls->DataRequestViewWidget->AtSteadyState(pulse);
383
  m_Controls->EnviornmentWidget->AtSteadyState(pulse);
384
385
}
void MainExplorerWindow::AtSteadyStateUpdateUI()
Aaron Bray's avatar
Aaron Bray committed
386
{// This is called from a slot, you can update UI here
387
388
  m_Controls->DynamicControls->AtSteadyStateUpdateUI();
  m_Controls->VitalsMonitorWidget->AtSteadyStateUpdateUI();
389
  m_Controls->DataRequestViewWidget->AtSteadyStateUpdateUI();
390
  m_Controls->EnviornmentWidget->AtSteadyStateUpdateUI();
391
392
393
394
395
396
397
398
399
400
401

  m_Controls->PlayPause->setEnabled(true);
  m_Controls->ResetEngine->setEnabled(true);
  m_Controls->ResetExplorer->setEnabled(true);
}

void MainExplorerWindow::ProcessPhysiology(PhysiologyEngine& pulse)
{// This is called from a thread, you should NOT update UI here
 // This is where we pull data from pulse, and push any actions to it
  m_Controls->DynamicControls->ProcessPhysiology(pulse);
  m_Controls->VitalsMonitorWidget->ProcessPhysiology(pulse);
402
  m_Controls->DataRequestViewWidget->ProcessPhysiology(pulse);
403
  m_Controls->EnviornmentWidget->ProcessPhysiology(pulse);
404
405
406
407
408
409
  m_Controls->CurrentSimTime_s = pulse.GetSimulationTime(TimeUnit::s);
}
void MainExplorerWindow::PhysiologyUpdateUI()
{// This is called from a slot, you can update UI here
  m_Controls->DynamicControls->PhysiologyUpdateUI();
  m_Controls->VitalsMonitorWidget->PhysiologyUpdateUI();
410
  m_Controls->DataRequestViewWidget->PhysiologyUpdateUI();
411
  m_Controls->EnviornmentWidget->PhysiologyUpdateUI();
412

Aaron Bray's avatar
Aaron Bray committed
413
414
415
416
417
418
419
420
  m_Controls->Status.str("");
  m_Controls->Status << "Current Simulation Time : " << m_Controls->CurrentSimTime_s << "s";
  m_Controls->StatusBar->showMessage(QString(m_Controls->Status.str().c_str()));
#ifdef PARAVIEW
  m_Controls->ParaViewRenderView->render();
#endif
}

421
422
423
424