ctkModuleParameterGroup.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ctkModuleParameter* ctkModuleParameterGroup::parameter( const QString& parameterName )const
  32. {
  33. foreach(ctkModuleParameter* param, this->Parameters)
  34. {
  35. if ((*param)["Name"] == parameterName)
  36. {
  37. return param;
  38. }
  39. }
  40. return 0;
  41. }
  42. //----------------------------------------------------------------------------
  43. bool ctkModuleParameterGroup::hasReturnParameters() const
  44. {
  45. // iterate over each parameter in this group
  46. foreach(const ctkModuleParameter* param, this->Parameters)
  47. {
  48. if (param->isReturnParameter())
  49. {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. //----------------------------------------------------------------------------
  56. bool ctkModuleParameterGroup::
  57. writeParameterFile(QTextStream& in, bool withHandlesToBulkParameters)const
  58. {
  59. // iterate over each parameter in this group
  60. foreach(const ctkModuleParameter* moduleParameter, this->Parameters)
  61. {
  62. const ctkModuleParameter& param = *moduleParameter;
  63. // write out all parameters or just the ones that are not bulk parameters
  64. if (withHandlesToBulkParameters
  65. || (!withHandlesToBulkParameters
  66. && (param[ "Tag" ] != "image"
  67. && param[ "Tag" ] != "geometry"
  68. && param[ "Tag" ] != "transform"
  69. && param[ "Tag" ] != "table"
  70. && param[ "Tag" ] != "measurement"
  71. && param[ "Tag" ] != "point" // point and region are special
  72. && param[ "Tag" ] != "region")))
  73. {
  74. in << param[ "Name" ] << " = " << param[ "Default" ] << endl;
  75. // multiple="true" may have to be handled differently
  76. }
  77. }
  78. return true;
  79. }
  80. //----------------------------------------------------------------------------
  81. QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group)
  82. {
  83. os << QHash<QString, QString>(group);
  84. os << " Parameters: " << endl;
  85. foreach (const ctkModuleParameter* it, group.Parameters)
  86. {
  87. os << *it;
  88. }
  89. return os;
  90. }