ctkSlicerModuleStringConverter.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 CISTIB - Universtitat Pompeu Fabra
  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 "ctkSlicerModuleStringConverter.h"
  15. #include <QVector>
  16. void ctkSlicerModuleStringConverter::update()
  17. {
  18. SetTarget( );
  19. SetAllParameters( );
  20. }
  21. const QVariant ctkSlicerModuleStringConverter::GetOutput()
  22. {
  23. return this->CommandLineAsString;
  24. }
  25. void ctkSlicerModuleStringConverter::SetAllParameters()
  26. {
  27. foreach( const ctkModuleParameterGroup* itGroup, this->ModuleDescription.parameterGroups())
  28. {
  29. foreach( const ctkModuleParameter* itParam, itGroup->parameters())
  30. {
  31. SetParameterValue( *itParam );
  32. }
  33. }
  34. }
  35. void ctkSlicerModuleStringConverter::SetParameterValue( const ctkModuleParameter &param )
  36. {
  37. QString prefix;
  38. QString flag;
  39. bool hasFlag = false;
  40. if ( param["LongFlag"] != "")
  41. {
  42. prefix = "--";
  43. flag = param["LongFlag"];
  44. hasFlag = true;
  45. }
  46. else if (param["Flag"] != "")
  47. {
  48. prefix = "-";
  49. flag = param["Flag"];
  50. hasFlag = true;
  51. }
  52. if (hasFlag)
  53. {
  54. if ( param["Tag"] != "boolean"
  55. && param["Tag"] != "file"
  56. && param["Tag"] != "directory"
  57. && param["Tag"] != "string"
  58. && param["Tag"] != "integer-vector"
  59. && param["Tag"] != "float-vector"
  60. && param["Tag"] != "double-vector"
  61. && param["Tag"] != "string-vector"
  62. && param["Tag"] != "image"
  63. && param["Tag"] != "point"
  64. && param["Tag"] != "region"
  65. && param["Tag"] != "transform"
  66. && param["Tag"] != "geometry"
  67. && param["Tag"] != "table"
  68. && param["Tag"] != "measurement")
  69. {
  70. // simple parameter, write flag and value
  71. this->CommandLineAsString.push_back(prefix + flag);
  72. this->CommandLineAsString.push_back(param["Default"]);
  73. }
  74. else if (param["Tag"] == "boolean" && param["Default"] == "true")
  75. {
  76. this->CommandLineAsString.push_back(prefix + flag);
  77. }
  78. else if (param["Tag"] == "file"
  79. || param["Tag"] == "directory"
  80. || param["Tag"] == "string"
  81. || param["Tag"] == "integer-vector"
  82. || param["Tag"] == "float-vector"
  83. || param["Tag"] == "double-vector"
  84. || param["Tag"] == "string-vector")
  85. {
  86. // Only write out the flag if value is not empty
  87. if ( param["Default"] != "")
  88. {
  89. this->CommandLineAsString.push_back(prefix + flag);
  90. this->CommandLineAsString.push_back( param["Default"] );
  91. }
  92. }
  93. // data passed as parameter
  94. else if ( param["Tag"] == "image"
  95. || param["Tag"] == "geometry"
  96. || param["Tag"] == "transform"
  97. || param["Tag"] == "table"
  98. || param["Tag"] == "measurement" )
  99. {
  100. if ( param["Default"] != "")
  101. {
  102. this->CommandLineAsString.push_back(prefix + flag);
  103. this->CommandLineAsString.push_back(param["Default"]);
  104. }
  105. }
  106. else if ( param["Tag"] == "region" )
  107. {
  108. this->CommandLineAsString.push_back(prefix + flag);
  109. this->CommandLineAsString.push_back( param["Default"] );
  110. }
  111. else if ( param["Tag"] == "point" )
  112. {
  113. QStringList points = param["Default"].split( ";");
  114. foreach ( const QString &it, points )
  115. {
  116. this->CommandLineAsString.push_back(prefix + flag);
  117. this->CommandLineAsString.push_back( it );
  118. }
  119. }
  120. }
  121. // If index is not empty -> It's a command line argument arg0, arg1, ... without flag prefix
  122. if ( param["Index"] != "")
  123. {
  124. this->CommandLineAsString.push_back( param["Default"] );
  125. }
  126. }
  127. void ctkSlicerModuleStringConverter::SetTarget()
  128. {
  129. this->CommandLineAsString.clear();
  130. if (!this->ModuleDescription["Location"].isEmpty() &&
  131. this->ModuleDescription["Location"] != this->ModuleDescription["Target"])
  132. {
  133. this->CommandLineAsString.push_back(this->ModuleDescription["Location"]);
  134. }
  135. this->CommandLineAsString.push_back( this->ModuleDescription["Target"] );
  136. }