ctkCmdLineModuleFrontend.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "ctkCmdLineModuleFrontend.h"
  16. #include "ctkCmdLineModuleDescription.h"
  17. #include "ctkCmdLineModuleParameter.h"
  18. #include "ctkCmdLineModuleParameterGroup.h"
  19. #include "ctkCmdLineModuleReference.h"
  20. #include "ctkCmdLineModuleFuture.h"
  21. #include <QUrl>
  22. //----------------------------------------------------------------------------
  23. struct ctkCmdLineModuleFrontendPrivate
  24. {
  25. ctkCmdLineModuleFrontendPrivate(const ctkCmdLineModuleReference& moduleRef)
  26. : ModuleReference(moduleRef)
  27. {
  28. }
  29. ctkCmdLineModuleReference ModuleReference;
  30. QList<QString> ParameterNames;
  31. ctkCmdLineModuleFuture Future;
  32. };
  33. //----------------------------------------------------------------------------
  34. ctkCmdLineModuleFrontend::ctkCmdLineModuleFrontend(const ctkCmdLineModuleReference& moduleRef)
  35. : d(new ctkCmdLineModuleFrontendPrivate(moduleRef))
  36. {
  37. }
  38. //----------------------------------------------------------------------------
  39. void ctkCmdLineModuleFrontend::setFuture(const ctkCmdLineModuleFuture &future)
  40. {
  41. d->Future = future;
  42. }
  43. //----------------------------------------------------------------------------
  44. ctkCmdLineModuleFrontend::~ctkCmdLineModuleFrontend()
  45. {
  46. }
  47. QList<QString> ctkCmdLineModuleFrontend::parameterNames() const
  48. {
  49. if (!d->ParameterNames.isEmpty()) return d->ParameterNames;
  50. foreach (ctkCmdLineModuleParameterGroup paramGroup,
  51. moduleReference().description().parameterGroups())
  52. {
  53. foreach (ctkCmdLineModuleParameter param, paramGroup.parameters())
  54. {
  55. d->ParameterNames.push_back(param.name());
  56. }
  57. }
  58. return d->ParameterNames;
  59. }
  60. //----------------------------------------------------------------------------
  61. ctkCmdLineModuleReference ctkCmdLineModuleFrontend::moduleReference() const
  62. {
  63. return d->ModuleReference;
  64. }
  65. //----------------------------------------------------------------------------
  66. QUrl ctkCmdLineModuleFrontend::location() const
  67. {
  68. return d->ModuleReference.location();
  69. }
  70. //----------------------------------------------------------------------------
  71. ctkCmdLineModuleFuture ctkCmdLineModuleFrontend::future() const
  72. {
  73. return d->Future;
  74. }
  75. //----------------------------------------------------------------------------
  76. bool ctkCmdLineModuleFrontend::isRunning() const
  77. {
  78. return d->Future.isRunning();
  79. }
  80. //----------------------------------------------------------------------------
  81. bool ctkCmdLineModuleFrontend::isPaused() const
  82. {
  83. return d->Future.isPaused();
  84. }
  85. //----------------------------------------------------------------------------
  86. QHash<QString, QVariant> ctkCmdLineModuleFrontend::values() const
  87. {
  88. QHash<QString,QVariant> result;
  89. foreach(QString parameterName, parameterNames())
  90. {
  91. result.insert(parameterName, value(parameterName));
  92. }
  93. return result;
  94. }
  95. //----------------------------------------------------------------------------
  96. void ctkCmdLineModuleFrontend::setValues(const QHash<QString, QVariant> &values)
  97. {
  98. QHashIterator<QString,QVariant> iter(values);
  99. while(iter.hasNext())
  100. {
  101. iter.next();
  102. setValue(iter.key(), iter.value());
  103. }
  104. }
  105. //----------------------------------------------------------------------------
  106. QList<ctkCmdLineModuleParameter> ctkCmdLineModuleFrontend::parameters(const QString &type, ParameterFilters filters)
  107. {
  108. ctkCmdLineModuleDescription description = this->moduleReference().description();
  109. QList<ctkCmdLineModuleParameter> parameters;
  110. foreach(ctkCmdLineModuleParameterGroup group, description.parameterGroups())
  111. {
  112. foreach(ctkCmdLineModuleParameter param, group.parameters())
  113. {
  114. if (filters.testFlag(Input) &&
  115. (param.channel().isEmpty() || param.channel().compare("input", Qt::CaseInsensitive) == 0))
  116. {
  117. if (type.isEmpty() || param.tag().compare(type, Qt::CaseInsensitive) == 0)
  118. {
  119. parameters << param;
  120. }
  121. }
  122. if (filters.testFlag(Output) && param.channel().compare("output", Qt::CaseInsensitive) == 0)
  123. {
  124. if (type.isEmpty() || param.tag().compare(type, Qt::CaseInsensitive) == 0)
  125. {
  126. parameters << param;
  127. }
  128. }
  129. }
  130. }
  131. return parameters;
  132. }
  133. //----------------------------------------------------------------------------
  134. void ctkCmdLineModuleFrontend::resetValues()
  135. {
  136. foreach(ctkCmdLineModuleParameter param, this->parameters())
  137. {
  138. this->setValue(param.name(), param.defaultValue());
  139. }
  140. }