ctkExampleDicomAppLogic.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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())
  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. QPushButton *button = new QPushButton("Button from App");
  49. try
  50. {
  51. QRect preferred(50,50,100,100);
  52. qDebug() << " Asking:getAvailableScreen";
  53. QRect rect = getHostInterface()->getAvailableScreen(preferred);
  54. qDebug() << " got sth:" << rect.top();
  55. button->move(rect.topLeft());
  56. button->resize(rect.size());
  57. }
  58. catch (const std::runtime_error& e)
  59. {
  60. qCritical() << e.what();
  61. return;
  62. }
  63. button->show();
  64. }
  65. void ctkExampleDicomAppLogic::changeState(int anewstate)
  66. {
  67. ctkDicomAppHosting::State newstate = static_cast<ctkDicomAppHosting::State>(anewstate);
  68. try
  69. {
  70. getHostInterface()->notifyStateChanged(newstate);
  71. }
  72. catch (const std::runtime_error& e)
  73. {
  74. qCritical() << e.what();
  75. return;
  76. }
  77. if (newstate == ctkDicomAppHosting::INPROGRESS)
  78. {
  79. do_something();
  80. }
  81. if (newstate == ctkDicomAppHosting::CANCELED)
  82. {
  83. qDebug() << " Received changeState(CANCELED) ... now releasing all resources and afterwards changing to state IDLE.";
  84. qDebug() << " Changing to state IDLE.";
  85. try
  86. {
  87. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  88. }
  89. catch (const std::runtime_error& e)
  90. {
  91. qCritical() << e.what();
  92. return;
  93. }
  94. }
  95. if (newstate == ctkDicomAppHosting::EXIT)
  96. {
  97. qDebug() << " Received changeState(EXIT) ... exiting.";
  98. qApp->quit();
  99. }
  100. }
  101. bool ctkExampleDicomAppLogic::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
  102. {
  103. Q_UNUSED(data)
  104. Q_UNUSED(lastData)
  105. return false;
  106. }
  107. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  108. QList<QUuid> objectUUIDs,
  109. QList<QString> acceptableTransferSyntaxUIDs,
  110. bool includeBulkData)
  111. {
  112. Q_UNUSED(objectUUIDs)
  113. Q_UNUSED(acceptableTransferSyntaxUIDs)
  114. Q_UNUSED(includeBulkData)
  115. return QList<ctkDicomAppHosting::ObjectLocator>();
  116. }
  117. void ctkExampleDicomAppLogic::releaseData(QList<QUuid> objectUUIDs)
  118. {
  119. Q_UNUSED(objectUUIDs)
  120. }
  121. ctkDicomHostInterface* ctkExampleDicomAppLogic::getHostInterface() const
  122. {
  123. ctkDicomHostInterface* host = hostTracker.getService();
  124. if (!host) throw std::runtime_error("DICOM Host Interface not available");
  125. return host;
  126. }