ctkHostAppExampleWidget.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkHostAppExampleWidget.h"
  16. #include "ui_ctkHostAppExampleWidget.h"
  17. #include "ctkExampleDicomHost.h"
  18. #include "ctkDicomAppService.h"
  19. #include <ctkDicomAppHostingTypesHelper.h>
  20. #include <QDebug>
  21. #include <QFileDialog>
  22. #include <QProcess>
  23. ctkHostAppExampleWidget::ctkHostAppExampleWidget(QWidget *parent) :
  24. QWidget(parent),
  25. ui(new Ui::ctkHostAppExampleWidget)
  26. {
  27. qDebug() << "setup ui";
  28. ui->setupUi(this);
  29. ui->crashLabel->setVisible(false);
  30. ui->messageOutput->setVisible(false);
  31. this->host = new ctkExampleDicomHost(ui->placeholderFrame);
  32. connect(&this->host->getAppProcess(),SIGNAL(error(QProcess::ProcessError)),SLOT(appProcessError(QProcess::ProcessError)));
  33. connect(&this->host->getAppProcess(),SIGNAL(stateChanged(QProcess::ProcessState)),SLOT(appProcessStateChanged(QProcess::ProcessState)));
  34. connect(ui->placeholderFrame,SIGNAL(resized()),SLOT(placeholderResized()));
  35. connect(this->host,SIGNAL( stateChangedReceived(ctkDicomAppHosting::State)),SLOT(appStateChanged(ctkDicomAppHosting::State)));
  36. }
  37. ctkHostAppExampleWidget::~ctkHostAppExampleWidget()
  38. {
  39. delete host;
  40. delete ui;
  41. }
  42. void ctkHostAppExampleWidget::startButtonClicked()
  43. {
  44. qDebug() << "start button clicked";
  45. if (host)
  46. {
  47. host->StartApplication(appFileName);
  48. }
  49. }
  50. void ctkHostAppExampleWidget::runButtonClicked()
  51. {
  52. qDebug() << "run button clicked";
  53. if (host)
  54. {
  55. bool reply = host->getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
  56. qDebug() << " setState(INPROGRESS) returned: " << reply;
  57. }
  58. }
  59. void ctkHostAppExampleWidget::stopButtonClicked()
  60. {
  61. qDebug() << "stop button clicked";
  62. }
  63. void ctkHostAppExampleWidget::loadButtonClicked()
  64. {
  65. qDebug() << "load button clicked";
  66. this->setAppFileName(QFileDialog::getOpenFileName(this,"Choose hosted application",QApplication::applicationDirPath()));
  67. }
  68. void ctkHostAppExampleWidget::setAppFileName(QString name)
  69. {
  70. this->appFileName = name;
  71. if (QFile(this->appFileName).permissions() & QFile::ExeUser )
  72. {
  73. this->ui->applicationPathLabel->setText(this->appFileName);
  74. }
  75. else
  76. {
  77. this->ui->applicationPathLabel->setText(QString("<font color='red'>Not executable:</font>").append(this->appFileName));
  78. }
  79. }
  80. void ctkHostAppExampleWidget::appProcessError(QProcess::ProcessError error)
  81. {
  82. if (error == QProcess::Crashed)
  83. {
  84. qDebug() << "crash detected";
  85. ui->crashLabel->setVisible(true);
  86. }
  87. }
  88. void ctkHostAppExampleWidget::appProcessStateChanged(QProcess::ProcessState state)
  89. {
  90. QString labelText;
  91. switch (state){
  92. case QProcess::Running:
  93. ui->processStateLabel->setText("Running");
  94. break;
  95. case QProcess::NotRunning:
  96. if (host->getAppProcess().exitStatus() == QProcess::CrashExit )
  97. {
  98. labelText = "crashed";
  99. }
  100. else
  101. {
  102. labelText = "Not Running, last exit code ";
  103. labelText.append(QString::number(host->getAppProcess().exitCode()));
  104. }
  105. ui->processStateLabel->setText(labelText);
  106. break;
  107. case QProcess::Starting:
  108. ui->processStateLabel->setText("Starting");
  109. break;
  110. default:
  111. ;
  112. }
  113. }
  114. void ctkHostAppExampleWidget::placeholderResized()
  115. {
  116. qDebug() << "resized";
  117. //ui->placeholderFrame->printPosition();
  118. }
  119. void ctkHostAppExampleWidget::appStateChanged(ctkDicomAppHosting::State state)
  120. {
  121. ui->statusLabel->setText(ctkDicomSoapState::toStringValue(state));
  122. if (state == ctkDicomAppHosting::INPROGRESS)
  123. {
  124. ctkDicomAppHosting::AvailableData data;
  125. ctkDicomAppHosting::Patient patient;
  126. patient.name = "John Doe";
  127. patient.id = "0000";
  128. patient.assigningAuthority = "authority";
  129. patient.sex = "male";
  130. patient.birthDate = "today";
  131. patient.objectDescriptors = QList<ctkDicomAppHosting::ObjectDescriptor>();
  132. ctkDicomAppHosting::ObjectDescriptor ourObjectDescriptor;
  133. ourObjectDescriptor.descriptorUUID = QUuid("{11111111-1111-1111-1111-111111111111}");
  134. ourObjectDescriptor.mimeType = "text/plain";
  135. ourObjectDescriptor.classUID = "lovelyClass";
  136. ourObjectDescriptor.transferSyntaxUID = "transSyntaxUId";
  137. ourObjectDescriptor.modality = "modMod";
  138. data.objectDescriptors = QList<ctkDicomAppHosting::ObjectDescriptor>();
  139. data.objectDescriptors.append (ourObjectDescriptor);
  140. data.patients = QList<ctkDicomAppHosting::Patient>();
  141. data.patients.append (patient);
  142. bool reply = host->getDicomAppService()->notifyDataAvailable (data,true);
  143. qDebug() << " notifyDataAvailable(1111) returned: " << reply;
  144. }
  145. }