ctkExampleDicomAppLogic.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "ctkExampleDicomAppLogic_p.h"
  16. #include "ctkExampleDicomAppPlugin_p.h"
  17. #include <QtPlugin>
  18. #include <QRect>
  19. #include <QDebug>
  20. #include <QPushButton>
  21. #include <QApplication>
  22. ctkExampleDicomAppLogic::ctkExampleDicomAppLogic()
  23. : hostTracker(ctkExampleDicomAppPlugin::getPluginContext()), button(NULL)
  24. {
  25. hostTracker.open();
  26. connect(this, SIGNAL(stateChanged(int)), this, SLOT(changeState(int)), Qt::QueuedConnection);
  27. emit stateChanged(ctkDicomAppHosting::IDLE);
  28. }
  29. ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
  30. {
  31. }
  32. ctkDicomAppHosting::State ctkExampleDicomAppLogic::getState()
  33. {
  34. return ctkDicomAppHosting::IDLE;
  35. }
  36. bool ctkExampleDicomAppLogic::setState(ctkDicomAppHosting::State newState)
  37. {
  38. qDebug() << "setState called";
  39. emit stateChanged(newState);
  40. return true;
  41. }
  42. bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
  43. {
  44. return false;
  45. }
  46. void ctkExampleDicomAppLogic::do_something()
  47. {
  48. button = new QPushButton("Button from App");
  49. connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  50. try
  51. {
  52. QRect preferred(50,50,100,100);
  53. qDebug() << " Asking:getAvailableScreen";
  54. QRect rect = getHostInterface()->getAvailableScreen(preferred);
  55. qDebug() << " got sth:" << rect.top();
  56. button->move(rect.topLeft());
  57. button->resize(rect.size());
  58. }
  59. catch (const std::runtime_error& e)
  60. {
  61. qCritical() << e.what();
  62. return;
  63. }
  64. button->show();
  65. }
  66. void ctkExampleDicomAppLogic::changeState(int anewstate)
  67. {
  68. ctkDicomAppHosting::State newstate = static_cast<ctkDicomAppHosting::State>(anewstate);
  69. if (newstate == ctkDicomAppHosting::INPROGRESS)
  70. {
  71. do_something();
  72. }
  73. try
  74. {
  75. getHostInterface()->notifyStateChanged(newstate);
  76. }
  77. catch (const std::runtime_error& e)
  78. {
  79. qCritical() << e.what();
  80. return;
  81. }
  82. if (newstate == ctkDicomAppHosting::CANCELED)
  83. {
  84. qDebug() << " Received changeState(CANCELED) ... now releasing all resources and afterwards changing to state IDLE.";
  85. qDebug() << " Changing to state IDLE.";
  86. try
  87. {
  88. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  89. }
  90. catch (const std::runtime_error& e)
  91. {
  92. qCritical() << e.what();
  93. return;
  94. }
  95. }
  96. if (newstate == ctkDicomAppHosting::EXIT)
  97. {
  98. qDebug() << " Received changeState(EXIT) ... exiting.";
  99. qApp->quit();
  100. }
  101. }
  102. bool ctkExampleDicomAppLogic::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
  103. {
  104. Q_UNUSED(lastData)
  105. QString s;
  106. if(button==NULL)
  107. {
  108. qCritical() << "Button is null!";
  109. return false;
  110. }
  111. s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  112. if(data.patients.count()>0)
  113. {
  114. s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
  115. if(data.patients.begin()->studies.count()>0)
  116. {
  117. s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
  118. if(data.patients.begin()->studies.begin()->series.count()>0)
  119. {
  120. s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
  121. // QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
  122. uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
  123. s=s+" uuid:"+uuid.toString();
  124. }
  125. }
  126. }
  127. button->setText(s);
  128. return false;
  129. }
  130. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  131. QList<QUuid> objectUUIDs,
  132. QList<QString> acceptableTransferSyntaxUIDs,
  133. bool includeBulkData)
  134. {
  135. Q_UNUSED(objectUUIDs)
  136. Q_UNUSED(acceptableTransferSyntaxUIDs)
  137. Q_UNUSED(includeBulkData)
  138. return QList<ctkDicomAppHosting::ObjectLocator>();
  139. }
  140. void ctkExampleDicomAppLogic::releaseData(QList<QUuid> objectUUIDs)
  141. {
  142. Q_UNUSED(objectUUIDs)
  143. }
  144. ctkDicomHostInterface* ctkExampleDicomAppLogic::getHostInterface() const
  145. {
  146. ctkDicomHostInterface* host = hostTracker.getService();
  147. if (!host) throw std::runtime_error("DICOM Host Interface not available");
  148. return host;
  149. }
  150. void ctkExampleDicomAppLogic::buttonClicked()
  151. {
  152. QList<QUuid> uuidlist;
  153. uuidlist.append(uuid);
  154. QString transfersyntax("1.2.840.10008.1.2.1");
  155. QList<QString> transfersyntaxlist;
  156. transfersyntaxlist.append(transfersyntax);
  157. QList<ctkDicomAppHosting::ObjectLocator> locators;
  158. locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  159. qDebug() << "got locators! " << QString().setNum(locators.count());
  160. QString s;
  161. s=s+" loc.count:"+QString().setNum(locators.count());
  162. if(locators.count()>0)
  163. {
  164. s=s+" URI: "+locators.begin()->URI;
  165. qDebug() << "URI: " << locators.begin()->URI;
  166. }
  167. button->setText(s);
  168. }