ctkModuleParameterGroup.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================================*/
  14. #include "ctkModuleParameterGroup.h"
  15. //----------------------------------------------------------------------------
  16. ctkModuleParameterGroup::~ctkModuleParameterGroup()
  17. {
  18. foreach(ctkModuleParameter* param, this->Parameters)
  19. {
  20. delete param;
  21. }
  22. this->Parameters.clear();
  23. }
  24. //----------------------------------------------------------------------------
  25. void ctkModuleParameterGroup::addParameter( ctkModuleParameter* parameter )
  26. {
  27. Q_ASSERT(parameter);
  28. this->Parameters.push_back(parameter);
  29. }
  30. //----------------------------------------------------------------------------
  31. const QVector<ctkModuleParameter*>& ctkModuleParameterGroup::parameters() const
  32. {
  33. return this->Parameters;
  34. }
  35. //----------------------------------------------------------------------------
  36. ctkModuleParameter* ctkModuleParameterGroup::parameter( const QString& parameterName )const
  37. {
  38. foreach(ctkModuleParameter* param, this->Parameters)
  39. {
  40. if ((*param)["Name"] == parameterName)
  41. {
  42. return param;
  43. }
  44. }
  45. return 0;
  46. }
  47. //----------------------------------------------------------------------------
  48. bool ctkModuleParameterGroup::hasReturnParameters() const
  49. {
  50. // iterate over each parameter in this group
  51. foreach(const ctkModuleParameter* param, this->Parameters)
  52. {
  53. if (param->isReturnParameter())
  54. {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. //----------------------------------------------------------------------------
  61. bool ctkModuleParameterGroup::
  62. writeParameterFile(QTextStream& in, bool withHandlesToBulkParameters)const
  63. {
  64. // iterate over each parameter in this group
  65. foreach(const ctkModuleParameter* moduleParameter, this->Parameters)
  66. {
  67. const ctkModuleParameter& param = *moduleParameter;
  68. // write out all parameters or just the ones that are not bulk parameters
  69. if (withHandlesToBulkParameters
  70. || (!withHandlesToBulkParameters
  71. && (param[ "Tag" ] != "image"
  72. && param[ "Tag" ] != "geometry"
  73. && param[ "Tag" ] != "transform"
  74. && param[ "Tag" ] != "table"
  75. && param[ "Tag" ] != "measurement"
  76. && param[ "Tag" ] != "point" // point and region are special
  77. && param[ "Tag" ] != "region")))
  78. {
  79. in << param[ "Name" ] << " = " << param[ "Default" ] << endl;
  80. // multiple="true" may have to be handled differently
  81. }
  82. }
  83. return true;
  84. }
  85. //----------------------------------------------------------------------------
  86. QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group)
  87. {
  88. os << QHash<QString, QString>(group);
  89. os << " Parameters: " << endl;
  90. foreach (const ctkModuleParameter* it, group.Parameters)
  91. {
  92. os << *it;
  93. }
  94. return os;
  95. }