ctkCmdLineModuleParameter.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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 d 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 "ctkCmdLineModuleParameter.h"
  15. #include <QStringList>
  16. struct ctkCmdLineModuleParameterPrivate
  17. {
  18. ctkCmdLineModuleParameterPrivate()
  19. : Hidden(false), Constraints(false), Index(-1), Multiple(false), Aggregate("false")
  20. {}
  21. QString Tag;
  22. QString Name;
  23. QString Description;
  24. QString Label;
  25. //QString CPPType;
  26. QString Type;
  27. QString Reference;
  28. bool Hidden;
  29. QString ArgType;
  30. //QString StringToType;
  31. QString Default;
  32. QString Flag;
  33. QString LongFlag;
  34. bool Constraints;
  35. QString Minimum;
  36. QString Maximum;
  37. QString Step;
  38. QString Channel;
  39. int Index;
  40. int Multiple;
  41. QString Aggregate;
  42. QString FileExtensionsAsString;
  43. QStringList FileExtensions;
  44. QString CoordinateSystem;
  45. QStringList Elements;
  46. QString FlagAliasesAsString;
  47. QString DeprecatedFlagAliasesAsString;
  48. QString LongFlagAliasesAsString;
  49. QString DeprecatedLongFlagAliasesAsString;
  50. QStringList FlagAliases;
  51. QStringList DeprecatedFlagAliases;
  52. QStringList LongFlagAliases;
  53. QStringList DeprecatedLongFlagAliases;
  54. QStringList splitAndTrim(const QString& str, const QString& separator)
  55. {
  56. QStringList l = str.split(separator, QString::SkipEmptyParts);
  57. l.removeDuplicates();
  58. // trim the strings
  59. QMutableStringListIterator i(l);
  60. while(i.hasNext())
  61. {
  62. QString& n = i.next();
  63. n = n.trimmed();
  64. }
  65. return l;
  66. }
  67. };
  68. //----------------------------------------------------------------------------
  69. ctkCmdLineModuleParameter::ctkCmdLineModuleParameter()
  70. : d_ptr(new ctkCmdLineModuleParameterPrivate)
  71. { }
  72. //----------------------------------------------------------------------------
  73. ctkCmdLineModuleParameter::~ctkCmdLineModuleParameter()
  74. {
  75. delete d_ptr;
  76. }
  77. //----------------------------------------------------------------------------
  78. void ctkCmdLineModuleParameter::setTag(const QString& tag)
  79. {
  80. Q_D(ctkCmdLineModuleParameter);
  81. d->Tag = tag;
  82. }
  83. //----------------------------------------------------------------------------
  84. QString ctkCmdLineModuleParameter::tag() const
  85. {
  86. Q_D(const ctkCmdLineModuleParameter);
  87. return d->Tag;
  88. }
  89. ////----------------------------------------------------------------------------
  90. //void ctkCmdLineModuleParameter::setCPPType(const QString& type)
  91. //{
  92. // Q_D(ctkCmdLineModuleParameter);
  93. // d->CPPType = type;
  94. //}
  95. ////----------------------------------------------------------------------------
  96. //QString ctkCmdLineModuleParameter::cppType() const
  97. //{
  98. // Q_D(const ctkCmdLineModuleParameter);
  99. // return d->CPPType;
  100. //}
  101. //----------------------------------------------------------------------------
  102. void ctkCmdLineModuleParameter::setType(const QString& type)
  103. {
  104. Q_D(ctkCmdLineModuleParameter);
  105. d->Type = type;
  106. }
  107. //----------------------------------------------------------------------------
  108. QString ctkCmdLineModuleParameter::type() const
  109. {
  110. Q_D(const ctkCmdLineModuleParameter);
  111. return d->Type;
  112. }
  113. //----------------------------------------------------------------------------
  114. void ctkCmdLineModuleParameter::setReference(const QString& ref)
  115. {
  116. Q_D(ctkCmdLineModuleParameter);
  117. d->Reference = ref;
  118. }
  119. //----------------------------------------------------------------------------
  120. QString ctkCmdLineModuleParameter::reference() const
  121. {
  122. Q_D(const ctkCmdLineModuleParameter);
  123. return d->Reference;
  124. }
  125. //----------------------------------------------------------------------------
  126. void ctkCmdLineModuleParameter::setHidden(bool hidden)
  127. {
  128. Q_D(ctkCmdLineModuleParameter);
  129. d->Hidden = hidden;
  130. }
  131. //----------------------------------------------------------------------------
  132. bool ctkCmdLineModuleParameter::hidden() const
  133. {
  134. Q_D(const ctkCmdLineModuleParameter);
  135. return d->Hidden;
  136. }
  137. //----------------------------------------------------------------------------
  138. bool ctkCmdLineModuleParameter::isReturnParameter() const
  139. {
  140. Q_D(const ctkCmdLineModuleParameter);
  141. // could check for tag == float, int, float-vector, ...
  142. if (d->Channel == "output"
  143. && !this->isFlagParameter() && !this->isIndexParameter())
  144. {
  145. return true;
  146. }
  147. return false;
  148. }
  149. //----------------------------------------------------------------------------
  150. bool ctkCmdLineModuleParameter::isFlagParameter() const
  151. {
  152. Q_D(const ctkCmdLineModuleParameter);
  153. return (d->Flag != "" || d->LongFlag != "");
  154. }
  155. //----------------------------------------------------------------------------
  156. bool ctkCmdLineModuleParameter::isIndexParameter() const
  157. {
  158. Q_D(const ctkCmdLineModuleParameter);
  159. return (d->Index > -1);
  160. }
  161. //----------------------------------------------------------------------------
  162. void ctkCmdLineModuleParameter::setArgType(const QString& argType)
  163. {
  164. Q_D(ctkCmdLineModuleParameter);
  165. d->ArgType = argType;
  166. }
  167. //----------------------------------------------------------------------------
  168. QString ctkCmdLineModuleParameter::argType() const
  169. {
  170. Q_D(const ctkCmdLineModuleParameter);
  171. return d->ArgType;
  172. }
  173. ////----------------------------------------------------------------------------
  174. //void ctkCmdLineModuleParameter::setStringToType(const QString& stringToType)
  175. //{
  176. // Q_D(ctkCmdLineModuleParameter);
  177. // d->StringToType = stringToType;
  178. //}
  179. ////----------------------------------------------------------------------------
  180. //QString ctkCmdLineModuleParameter::stringToType() const
  181. //{
  182. // Q_D(const ctkCmdLineModuleParameter);
  183. // return d->StringToType;
  184. //}
  185. //----------------------------------------------------------------------------
  186. void ctkCmdLineModuleParameter::setName(const QString& name)
  187. {
  188. Q_D(ctkCmdLineModuleParameter);
  189. d->Name = name;
  190. }
  191. //----------------------------------------------------------------------------
  192. QString ctkCmdLineModuleParameter::name() const
  193. {
  194. Q_D(const ctkCmdLineModuleParameter);
  195. return d->Name;
  196. }
  197. //----------------------------------------------------------------------------
  198. void ctkCmdLineModuleParameter::setLongFlag(const QString& longFlag)
  199. {
  200. Q_D(ctkCmdLineModuleParameter);
  201. d->LongFlag = longFlag;
  202. }
  203. //----------------------------------------------------------------------------
  204. QString ctkCmdLineModuleParameter::longFlag() const
  205. {
  206. Q_D(const ctkCmdLineModuleParameter);
  207. return d->LongFlag;
  208. }
  209. //----------------------------------------------------------------------------
  210. void ctkCmdLineModuleParameter::setLongFlagAliasesAsString(const QString& aliases)
  211. {
  212. Q_D(ctkCmdLineModuleParameter);
  213. d->LongFlagAliases = d->splitAndTrim(aliases, ",");
  214. d->LongFlagAliasesAsString = d->LongFlagAliases.join(", ");
  215. }
  216. //----------------------------------------------------------------------------
  217. QString ctkCmdLineModuleParameter::longFlagAliasesAsString() const
  218. {
  219. Q_D(const ctkCmdLineModuleParameter);
  220. return d->LongFlagAliasesAsString;
  221. }
  222. //----------------------------------------------------------------------------
  223. QStringList ctkCmdLineModuleParameter::longFlagAliases() const
  224. {
  225. Q_D(const ctkCmdLineModuleParameter);
  226. return d->LongFlagAliases;
  227. }
  228. //----------------------------------------------------------------------------
  229. void ctkCmdLineModuleParameter::setDeprecatedLongFlagAliasesAsString(const QString& aliases)
  230. {
  231. Q_D(ctkCmdLineModuleParameter);
  232. d->DeprecatedLongFlagAliases = d->splitAndTrim(aliases, ",");
  233. d->DeprecatedLongFlagAliasesAsString = d->DeprecatedLongFlagAliases.join(", ");
  234. }
  235. //----------------------------------------------------------------------------
  236. QString ctkCmdLineModuleParameter::deprecatedLongFlagAliasesAsString() const
  237. {
  238. Q_D(const ctkCmdLineModuleParameter);
  239. return d->DeprecatedLongFlagAliasesAsString;
  240. }
  241. //----------------------------------------------------------------------------
  242. QStringList ctkCmdLineModuleParameter::deprecatedLongFlagAliases() const
  243. {
  244. Q_D(const ctkCmdLineModuleParameter);
  245. return d->DeprecatedLongFlagAliases;
  246. }
  247. //----------------------------------------------------------------------------
  248. void ctkCmdLineModuleParameter::setLabel(const QString& label)
  249. {
  250. Q_D(ctkCmdLineModuleParameter);
  251. d->Label = label;
  252. }
  253. //----------------------------------------------------------------------------
  254. QString ctkCmdLineModuleParameter::label() const
  255. {
  256. Q_D(const ctkCmdLineModuleParameter);
  257. return d->Label;
  258. }
  259. //----------------------------------------------------------------------------
  260. void ctkCmdLineModuleParameter::setConstraints(bool constraints)
  261. {
  262. Q_D(ctkCmdLineModuleParameter);
  263. d->Constraints = constraints;
  264. }
  265. //----------------------------------------------------------------------------
  266. bool ctkCmdLineModuleParameter::constraints() const
  267. {
  268. Q_D(const ctkCmdLineModuleParameter);
  269. return d->Constraints;
  270. }
  271. //----------------------------------------------------------------------------
  272. void ctkCmdLineModuleParameter::setMaximum(const QString& maximum)
  273. {
  274. Q_D(ctkCmdLineModuleParameter);
  275. d->Maximum = maximum;
  276. }
  277. //----------------------------------------------------------------------------
  278. QString ctkCmdLineModuleParameter::maximum() const
  279. {
  280. Q_D(const ctkCmdLineModuleParameter);
  281. return d->Maximum;
  282. }
  283. //----------------------------------------------------------------------------
  284. void ctkCmdLineModuleParameter::setMinimum(const QString& minimum)
  285. {
  286. Q_D(ctkCmdLineModuleParameter);
  287. d->Minimum = minimum;
  288. }
  289. //----------------------------------------------------------------------------
  290. QString ctkCmdLineModuleParameter::minimum() const
  291. {
  292. Q_D(const ctkCmdLineModuleParameter);
  293. return d->Minimum;
  294. }
  295. //----------------------------------------------------------------------------
  296. void ctkCmdLineModuleParameter::setStep(const QString& step)
  297. {
  298. Q_D(ctkCmdLineModuleParameter);
  299. d->Step = step;
  300. }
  301. //----------------------------------------------------------------------------
  302. QString ctkCmdLineModuleParameter::step() const
  303. {
  304. Q_D(const ctkCmdLineModuleParameter);
  305. return d->Step;
  306. }
  307. //----------------------------------------------------------------------------
  308. void ctkCmdLineModuleParameter::setDescription(const QString& description)
  309. {
  310. Q_D(ctkCmdLineModuleParameter);
  311. d->Description = description;
  312. }
  313. //----------------------------------------------------------------------------
  314. QString ctkCmdLineModuleParameter::description() const
  315. {
  316. Q_D(const ctkCmdLineModuleParameter);
  317. return d->Description;
  318. }
  319. //----------------------------------------------------------------------------
  320. void ctkCmdLineModuleParameter::setChannel(const QString& channel)
  321. {
  322. Q_D(ctkCmdLineModuleParameter);
  323. d->Channel = channel;
  324. }
  325. //----------------------------------------------------------------------------
  326. QString ctkCmdLineModuleParameter::channel() const
  327. {
  328. Q_D(const ctkCmdLineModuleParameter);
  329. return d->Channel;
  330. }
  331. //----------------------------------------------------------------------------
  332. void ctkCmdLineModuleParameter::setIndex(int index)
  333. {
  334. Q_D(ctkCmdLineModuleParameter);
  335. d->Index = index;
  336. }
  337. //----------------------------------------------------------------------------
  338. int ctkCmdLineModuleParameter::index() const
  339. {
  340. Q_D(const ctkCmdLineModuleParameter);
  341. return d->Index;
  342. }
  343. //----------------------------------------------------------------------------
  344. void ctkCmdLineModuleParameter::setDefaultValue(const QString& def)
  345. {
  346. Q_D(ctkCmdLineModuleParameter);
  347. d->Default = def;
  348. }
  349. //----------------------------------------------------------------------------
  350. QString ctkCmdLineModuleParameter::defaultValue() const
  351. {
  352. Q_D(const ctkCmdLineModuleParameter);
  353. return d->Default;
  354. }
  355. //----------------------------------------------------------------------------
  356. void ctkCmdLineModuleParameter::setFlag(const QString& flag)
  357. {
  358. Q_D(ctkCmdLineModuleParameter);
  359. d->Flag = flag;
  360. }
  361. //----------------------------------------------------------------------------
  362. QString ctkCmdLineModuleParameter::flag() const
  363. {
  364. Q_D(const ctkCmdLineModuleParameter);
  365. return d->Flag;
  366. }
  367. //----------------------------------------------------------------------------
  368. void ctkCmdLineModuleParameter::setFlagAliasesAsString(const QString& aliases)
  369. {
  370. Q_D(ctkCmdLineModuleParameter);
  371. d->FlagAliases = d->splitAndTrim(aliases, ",");
  372. d->FlagAliasesAsString = d->FlagAliases.join(", ");
  373. }
  374. //----------------------------------------------------------------------------
  375. QString ctkCmdLineModuleParameter::flagAliasesAsString() const
  376. {
  377. Q_D(const ctkCmdLineModuleParameter);
  378. return d->FlagAliasesAsString;
  379. }
  380. //----------------------------------------------------------------------------
  381. QStringList ctkCmdLineModuleParameter::flagAliases() const
  382. {
  383. Q_D(const ctkCmdLineModuleParameter);
  384. return d->FlagAliases;
  385. }
  386. //----------------------------------------------------------------------------
  387. void ctkCmdLineModuleParameter::setDeprecatedFlagAliasesAsString(const QString& aliases)
  388. {
  389. Q_D(ctkCmdLineModuleParameter);
  390. d->DeprecatedFlagAliases = d->splitAndTrim(aliases, ",");
  391. d->DeprecatedFlagAliasesAsString = d->DeprecatedFlagAliases.join(", ");
  392. }
  393. //----------------------------------------------------------------------------
  394. QString ctkCmdLineModuleParameter::deprecatedFlagAliasesAsString() const
  395. {
  396. Q_D(const ctkCmdLineModuleParameter);
  397. return d->DeprecatedFlagAliasesAsString;
  398. }
  399. //----------------------------------------------------------------------------
  400. QStringList ctkCmdLineModuleParameter::deprecatedFlagAliases() const
  401. {
  402. Q_D(const ctkCmdLineModuleParameter);
  403. return d->DeprecatedFlagAliases;
  404. }
  405. //----------------------------------------------------------------------------
  406. void ctkCmdLineModuleParameter::setMultiple(bool multiple)
  407. {
  408. Q_D(ctkCmdLineModuleParameter);
  409. d->Multiple = multiple;
  410. }
  411. //----------------------------------------------------------------------------
  412. bool ctkCmdLineModuleParameter::multiple() const
  413. {
  414. Q_D(const ctkCmdLineModuleParameter);
  415. return d->Multiple;
  416. }
  417. //----------------------------------------------------------------------------
  418. void ctkCmdLineModuleParameter::setAggregate(const QString& aggregate)
  419. {
  420. Q_D(ctkCmdLineModuleParameter);
  421. d->Aggregate = aggregate;
  422. }
  423. //----------------------------------------------------------------------------
  424. QString ctkCmdLineModuleParameter::aggregate() const
  425. {
  426. Q_D(const ctkCmdLineModuleParameter);
  427. return d->Aggregate;
  428. }
  429. //----------------------------------------------------------------------------
  430. void ctkCmdLineModuleParameter::setFileExtensionsAsString(const QString& extensions)
  431. {
  432. Q_D(ctkCmdLineModuleParameter);
  433. d->FileExtensions = d->splitAndTrim(extensions, ",");
  434. d->FileExtensionsAsString = d->FileExtensions.join(",");
  435. }
  436. //----------------------------------------------------------------------------
  437. QString ctkCmdLineModuleParameter::fileExtensionsAsString() const
  438. {
  439. Q_D(const ctkCmdLineModuleParameter);
  440. return d->FileExtensionsAsString;
  441. }
  442. //----------------------------------------------------------------------------
  443. QStringList ctkCmdLineModuleParameter::fileExtensions() const
  444. {
  445. Q_D(const ctkCmdLineModuleParameter);
  446. return d->FileExtensions;
  447. }
  448. //----------------------------------------------------------------------------
  449. void ctkCmdLineModuleParameter::setCoordinateSystem(const QString& coordinateSystem)
  450. {
  451. Q_D(ctkCmdLineModuleParameter);
  452. d->CoordinateSystem = coordinateSystem;
  453. }
  454. //----------------------------------------------------------------------------
  455. QString ctkCmdLineModuleParameter::coordinateSystem() const
  456. {
  457. Q_D(const ctkCmdLineModuleParameter);
  458. return d->CoordinateSystem;
  459. }
  460. //----------------------------------------------------------------------------
  461. void ctkCmdLineModuleParameter::addElement(const QString &elem)
  462. {
  463. Q_D(ctkCmdLineModuleParameter);
  464. d->Elements.push_back(elem);
  465. }
  466. //----------------------------------------------------------------------------
  467. void ctkCmdLineModuleParameter::setElements(const QStringList& elems)
  468. {
  469. Q_D(ctkCmdLineModuleParameter);
  470. d->Elements = elems;
  471. }
  472. //----------------------------------------------------------------------------
  473. QStringList ctkCmdLineModuleParameter::elements() const
  474. {
  475. Q_D(const ctkCmdLineModuleParameter);
  476. return d->Elements;
  477. }
  478. //----------------------------------------------------------------------------
  479. //QStringList& ctkCmdLineModuleParameter::elements()
  480. //{
  481. // return d->Elements;
  482. //}
  483. //----------------------------------------------------------------------------
  484. QTextStream& operator<<(QTextStream& os, const ctkCmdLineModuleParameter& parameter)
  485. {
  486. os << " Parameter" << '\n';
  487. os << " " << "Tag: " << parameter.tag() << '\n';
  488. os << " " << "Name: " << parameter.name() << '\n';
  489. os << " " << "Description: " << parameter.description() << '\n';
  490. os << " " << "Label: " << parameter.label() << '\n';
  491. os << " " << "Type: " << parameter.type() << '\n';
  492. os << " " << "Reference: " << parameter.reference() << '\n';
  493. os << " " << "Hidden: " << (parameter.hidden() ? "true" : "false") << '\n';
  494. //os << " " << "CPPType: " << parameter.cppType() << '\n';
  495. os << " " << "ArgType: " << parameter.argType() << '\n';
  496. //os << " " << "StringToType: " << parameter.stringToType() << '\n';
  497. os << " " << "Default: " << parameter.defaultValue() << '\n';
  498. os << " " << "Elements: " << parameter.elements().join(", ") << '\n';
  499. os << " " << "Constraints: " << (parameter.constraints() ? "true" : "false") << '\n';
  500. os << " " << "Minimum: " << parameter.minimum() << '\n';
  501. os << " " << "Maximum: " << parameter.maximum() << '\n';
  502. os << " " << "Step: " << parameter.step() << '\n';
  503. os << " " << "Flag: " << parameter.flag() << '\n';
  504. os << " " << "Flag aliases: " << parameter.flagAliasesAsString() << '\n';
  505. os << " " << "Deprecated Flag aliases: " << parameter.deprecatedFlagAliasesAsString() << '\n';
  506. os << " " << "LongFlag: " << parameter.longFlag() << '\n';
  507. os << " " << "LongFlag aliases: " << parameter.longFlagAliasesAsString() << '\n';
  508. os << " " << "Deprecated LongFlag aliases: " << parameter.deprecatedLongFlagAliasesAsString() << '\n';
  509. os << " " << "Channel: " << parameter.channel() << '\n';
  510. os << " " << "Index: " << parameter.index() << '\n';
  511. os << " " << "Multiple: " << (parameter.multiple() ? "true" : "false") << '\n';
  512. os << " " << "Aggregate: " << parameter.aggregate() << '\n';
  513. os << " " << "FileExtensions: " << parameter.fileExtensionsAsString() << '\n';
  514. os << " " << "CoordinateSystem: " << parameter.coordinateSystem() << '\n';
  515. return os;
  516. }