| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | /*=============================================================================Library: CTKCopyright (c) 2010 CISTIB - Universtitat Pompeu FabraLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.=============================================================================*/#include "ctkSlicerModuleStringConverter.h"#include <QVector>void ctkSlicerModuleStringConverter::update(){  SetTarget( );  SetAllParameters( );}const QVariant ctkSlicerModuleStringConverter::GetOutput(){  return this->CommandLineAsString;}void ctkSlicerModuleStringConverter::SetAllParameters(){  foreach( const ctkModuleParameterGroup* itGroup, this->ModuleDescription.parameterGroups())  {    foreach( const ctkModuleParameter* itParam, itGroup->parameters())    {      SetParameterValue( *itParam );    }  }}void ctkSlicerModuleStringConverter::SetParameterValue( const ctkModuleParameter ¶m ){  QString prefix;  QString flag;  bool hasFlag = false;  if ( param["LongFlag"] != "")  {    prefix = "--";    flag = param["LongFlag"];    hasFlag = true;  }  else if (param["Flag"] != "")  {    prefix = "-";    flag = param["Flag"];    hasFlag = true;  }  if (hasFlag)  {    if (   param["Tag"] != "boolean"      && param["Tag"] != "file"       && param["Tag"] != "directory"      && param["Tag"] != "string"      && param["Tag"] != "integer-vector"      && param["Tag"] != "float-vector"      && param["Tag"] != "double-vector"      && param["Tag"] != "string-vector"      && param["Tag"] != "image"      && param["Tag"] != "point"      && param["Tag"] != "region"      && param["Tag"] != "transform"      && param["Tag"] != "geometry"      && param["Tag"] != "table"      && param["Tag"] != "measurement")    {      // simple parameter, write flag and value      this->CommandLineAsString.push_back(prefix + flag);      this->CommandLineAsString.push_back(param["Default"]);    }    else if (param["Tag"] == "boolean" && param["Default"] == "true")    {      this->CommandLineAsString.push_back(prefix + flag);    }    else if (param["Tag"] == "file"       || param["Tag"] == "directory"      || param["Tag"] == "string"      || param["Tag"] == "integer-vector"      || param["Tag"] == "float-vector"      || param["Tag"] == "double-vector"      || param["Tag"] == "string-vector")    {      // Only write out the flag if value is not empty      if ( param["Default"] != "")      {        this->CommandLineAsString.push_back(prefix + flag);        this->CommandLineAsString.push_back( param["Default"] );      }    }    // data passed as parameter    else if ( param["Tag"] == "image"       || param["Tag"] == "geometry"      || param["Tag"] == "transform"       || param["Tag"] == "table"       || param["Tag"] == "measurement" )    {      if ( param["Default"] != "")      {        this->CommandLineAsString.push_back(prefix + flag);        this->CommandLineAsString.push_back(param["Default"]);      }    }    else if ( param["Tag"] == "region" )    {      this->CommandLineAsString.push_back(prefix + flag);      this->CommandLineAsString.push_back( param["Default"] );    }    else if ( param["Tag"] == "point" )    {      QStringList points = param["Default"].split( ";");      foreach ( const QString &it, points )      {        this->CommandLineAsString.push_back(prefix + flag);        this->CommandLineAsString.push_back( it );      }    }  }  // If index is not empty -> It's a command line argument arg0, arg1, ... without flag prefix  if ( param["Index"] != "")  {    this->CommandLineAsString.push_back( param["Default"] );  }}void ctkSlicerModuleStringConverter::SetTarget(){  this->CommandLineAsString.clear();  if (!this->ModuleDescription["Location"].isEmpty() &&     this->ModuleDescription["Location"] != this->ModuleDescription["Target"])  {    this->CommandLineAsString.push_back(this->ModuleDescription["Location"]);  }  this->CommandLineAsString.push_back( this->ModuleDescription["Target"] );}
 |