ctkQtTestingMainWindow.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // QT includes
  2. #include <QDebug>
  3. #include <QFileDialog>
  4. #include <QMainWindow>
  5. #include <QTextStream>
  6. #include <QXmlStreamAttributes>
  7. #include <QXmlStreamReader>
  8. #include <QXmlStreamWriter>
  9. // QtTesting includes
  10. #include "pqTestUtility.h"
  11. #include "pqEventObserver.h"
  12. #include "pqEventSource.h"
  13. // VTK includes
  14. #include <vtkActor.h>
  15. #include <vtkCubeSource.h>
  16. #include <vtkLineSource.h>
  17. #include <vtkPlaneWidget.h>
  18. #include <vtkPolyDataMapper.h>
  19. #include <vtkProperty.h>
  20. #include <vtkRenderer.h>
  21. #include <vtkSmartPointer.h>
  22. #include <vtkSphereSource.h>
  23. #include <vtkRenderWindow.h>
  24. #include <vtkRenderWindowInteractor.h>
  25. #include <vtkSplineWidget2.h>
  26. #include <vtkBoxWidget.h>
  27. // CTK includes
  28. #include "ctkQtTestingMainWindow.h"
  29. #include "ctkXMLEventObserver.h"
  30. #include "ctkXMLEventSource.h"
  31. //-----------------------------------------------------------------------------
  32. ctkQtTestingMainWindow::ctkQtTestingMainWindow()
  33. {
  34. this->Ui.setupUi(this);
  35. QObject::connect(Ui.RecordButton, SIGNAL(toggled(bool)), this, SLOT(record(bool)));
  36. QObject::connect(Ui.PlayBackButton, SIGNAL(clicked()), this, SLOT(play()));
  37. this->TestUtility = new ctkQtTestingUtility(this);
  38. this->TestUtility->addEventObserver("xml", new ctkXMLEventObserver(this->TestUtility));
  39. this->TestUtility->addEventSource("xml", new ctkXMLEventSource(this->TestUtility));
  40. Ui.renderView->setBackgroundColor(QColor(Qt::gray));
  41. Ui.renderView->setBackgroundColor2(QColor(Qt::darkBlue));
  42. Ui.renderView->setGradientBackground(true);
  43. Ui.renderView->setCornerAnnotationText("ctk Qt test");
  44. // Create a cube.
  45. vtkSmartPointer<vtkCubeSource> cubeSource =
  46. vtkSmartPointer<vtkCubeSource>::New();
  47. // Create a mapper and actor.
  48. vtkSmartPointer<vtkPolyDataMapper> mapper =
  49. vtkSmartPointer<vtkPolyDataMapper>::New();
  50. mapper->SetInputConnection(cubeSource->GetOutputPort());
  51. vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  52. actor->SetMapper(mapper);
  53. // Add the actors to the scene
  54. Ui.renderView->renderer()->AddActor(actor);
  55. // vtkSmartPointer<vtkBoxWidget> boxWidget =
  56. // vtkSmartPointer<vtkBoxWidget>::New();
  57. // boxWidget->SetInteractor(Ui.renderView->interactor());
  58. // boxWidget->SetPlaceFactor(1.0);
  59. // boxWidget->PlaceWidget();
  60. // boxWidget->On();
  61. Ui.renderView->resetCamera();
  62. }
  63. //-----------------------------------------------------------------------------
  64. ctkQtTestingMainWindow::~ctkQtTestingMainWindow()
  65. {
  66. if(TestUtility)
  67. {
  68. delete this->TestUtility;
  69. }
  70. }
  71. //-----------------------------------------------------------------------------
  72. void ctkQtTestingMainWindow::record(bool start)
  73. {
  74. if (start)
  75. {
  76. QString filename = QFileDialog::getSaveFileName (this, "Test File Name",
  77. QString(), "XML Files (*.xml)");
  78. if (!filename.isEmpty())
  79. {
  80. qDebug() << "Start recording";
  81. QFileInfo fileInfo(filename);
  82. if (fileInfo.suffix() != "xml")
  83. {
  84. filename += ".xml";
  85. }
  86. this->TestUtility->recordTests(filename);
  87. }
  88. }
  89. else
  90. {
  91. qDebug() << "Stop recording";
  92. this->TestUtility->stopRecords(1);
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. void ctkQtTestingMainWindow::play()
  97. {
  98. qDebug() << "Start Playback";
  99. QString filename = QFileDialog::getOpenFileName (this, "Test File Name",
  100. QString(), "XML Files (*.xml)");
  101. if (!filename.isEmpty())
  102. {
  103. this->TestUtility->playTests(filename);
  104. }
  105. qDebug() << "End Playback";
  106. }