#include "CDMUtilities.h"
#include<vector>
+#include<string>
+#include<iostream>
+#include<fstream>
+#include<algorithm>
+#include<cstdlib>
+
+#include<creaWx.h>
+#include<wx/config.h>
namespace CDMUtilities
{
{
if (empties == no_empties)
{
- next = s.find_first_not_of( delimiters, next + 1 );
- if (next == Container::value_type::npos) break;
+ next = s.find_first_not_of(delimiters, next + 1);
+ if (next == Container::value_type::npos)
+ {
+ break;
+ }
next -= 1;
}
current = next + 1;
- next = s.find_first_of( delimiters, current );
- result.push_back( s.substr( current, next - current ) );
+ next = s.find_first_of(delimiters, current);
+ result.push_back(s.substr(current, next - current));
}
while (next != Container::value_type::npos);
return result;
}
- const std::string& fixPath(const std::string& path)
+ const std::string fixPath(const std::string& path)
{
std::string pathFixed = "";
- #if(_WIN32)
+#if(_WIN32)
// ------ Windows
- //TODO: implementation for windows
- #else
+ std::vector<std::string> pathSplit;
+
+ splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
+
+ if(0 < pathSplit.size())
+ pathFixed = pathSplit[0];
+
+ for (int i = 1; i < (int)(pathSplit.size()); i++)
+ {
+ pathFixed += CDMUtilities::SLASH + pathSplit[i];
+ }
+#else
// ------ LINUX / MacOS
//break path into folders
- std::vector<std::string> pathSlpit;
- splitter::split(pathSlpit, path, "\"/", splitter::no_empties);
- for (int i = 0; i < pathSlpit.size(); i++)
+ std::vector<std::string> pathSplit;
+
+ splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
+
+ for (int i = 0; i < pathSplit.size(); i++)
{
- std::cout << pathSlpit[i];
- pathFixed += "/" + pathSlpit[i];
+ pathFixed += CDMUtilities::SLASH + pathSplit[i];
}
- #endif
+#endif
return pathFixed;
}
+
+ int openTextEditor(const std::string& file)
+ {
+ wxConfigBase* pConfig = wxConfigBase::Get();
+ std::string command = crea::wx2std(pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR)));
+
+ if(file != "")
+ command += " \"" + file + "\"";
+ command += " &";
+
+ return system(command.c_str());
+ }
+
+ int openFileExplorer(const std::string& file)
+ {
+ wxConfigBase* pConfig = wxConfigBase::Get();
+ std::string command = crea::wx2std(pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER)));
+
+ if(file != "")
+ command += " \"" + file + "\"";
+ command += " &";
+
+ return system(command.c_str());
+ }
+
+ int openFileWithCommand(const std::string& file, const std::string& command)
+ {
+ std::string comm = command;
+ if(file != "")
+ comm += " \"" + file + "\"";
+ comm += " &";
+
+ return system(comm.c_str());
+ }
+
+ int openBBEditor()
+ {
+ std::string comm = "bbEditor &";
+ return system(comm.c_str());
+ }
+
+ int openCreaToolsTools()
+ {
+#ifdef _WIN32
+ std::string comm = "creaTools &";
+#else
+ std::string comm = "creaTools.sh &";
+#endif
+
+ return system(comm.c_str());
+ }
+
+ int openTerminal(const std::string& command)
+ {
+ wxConfigBase* pConfig = wxConfigBase::Get();
+ std::string comm = crea::wx2std(pConfig->Read(wxT("TERMINAl"), crea::std2wx(CDMUtilities::TERMINAL)));
+ if (command != "")
+ comm += + " " + command;
+ comm += " &";
+ return system(comm.c_str());
+ }
+
+ bool createEmptyClass(const std::string& name, const std::string& path)
+ {
+ std::vector<std::string> words;
+ splitter::split(words,name," \\/\",.'`",splitter::no_empties);
+ std::string fixedName = "";
+ for (int i = 0; i < (int)(words.size()); i++)
+ {
+ fixedName += words[i];
+ }
+
+ if(fixedName == "" || path == "")
+ {
+ return false;
+ }
+
+ std::string nameupper = fixedName;
+ std::transform(nameupper.begin(), nameupper.end(),nameupper.begin(),::toupper);
+
+ std::ofstream out((path + SLASH + fixedName + ".h").c_str());
+ if( !out.is_open())
+ {
+ return false;
+ }
+
+ out << "/*" << std::endl;
+ out << "# ---------------------------------------------------------------------" << std::endl;
+ out << "#" << std::endl;
+ out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
+ out << "# pour la Sante)" << std::endl;
+ out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
+ out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
+ out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
+ out << "#" << std::endl;
+ out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
+ out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
+ out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
+ out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
+ out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
+ out << "# or in the file LICENSE.txt." << std::endl;
+ out << "#" << std::endl;
+ out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
+ out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
+ out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
+ out << "# economic rights, and the successive licensors have only limited" << std::endl;
+ out << "# liability." << std::endl;
+ out << "#" << std::endl;
+ out << "# The fact that you are presently reading this means that you have had" << std::endl;
+ out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
+ out << "# ------------------------------------------------------------------------" << std::endl;
+ out << "*/" << std::endl;
+ out << "" << std::endl;
+ out << "#ifndef _" << nameupper << "_H_" << std::endl;
+ out << "#define _" << nameupper << "_H_" << std::endl;
+ out << "" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "// Class Name: " << fixedName << "" << std::endl;
+ out << "// [classdescription]" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "" << std::endl;
+ out << "class " << fixedName << "" << std::endl;
+ out << "{" << std::endl;
+ out << "" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "//Methods and attributes exposed to other classes" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "public :" << std::endl;
+ out << " " << fixedName << "();" << std::endl;
+ out << " ~" << fixedName << "();" << std::endl;
+ out << "" << std::endl;
+ out << "//--Method template----------------------------" << std::endl;
+ out << "// void FunctionName(int& parameterA);" << std::endl;
+ out << "" << std::endl;
+ out << "" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "//Methods and attributes exposed only to classes" << std::endl;
+ out << "//that are derived from this class" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "protected:" << std::endl;
+ out << "" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "//Methods and attributes only visible by this class" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "private:" << std::endl;
+ out << "" << std::endl;
+ out << "};" << std::endl;
+ out << "" << std::endl;
+ out << "//-end of _" << nameupper << "_H_------------------------------------------------------" << std::endl;
+ out << "#endif" << std::endl;
+
+ out.close();
+
+ out.open((path + CDMUtilities::SLASH + fixedName + ".cpp").c_str());
+ if( !out.is_open())
+ {
+ return false;
+ }
+
+ out << "/*" << std::endl;
+ out << "# ---------------------------------------------------------------------" << std::endl;
+ out << "#" << std::endl;
+ out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
+ out << "# pour la Sante)" << std::endl;
+ out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
+ out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
+ out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
+ out << "#" << std::endl;
+ out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
+ out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
+ out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
+ out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
+ out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
+ out << "# or in the file LICENSE.txt." << std::endl;
+ out << "#" << std::endl;
+ out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
+ out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
+ out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
+ out << "# economic rights, and the successive licensors have only limited" << std::endl;
+ out << "# liability." << std::endl;
+ out << "#" << std::endl;
+ out << "# The fact that you are presently reading this means that you have had" << std::endl;
+ out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
+ out << "# ------------------------------------------------------------------------" << std::endl;
+ out << "*/" << std::endl;
+ out << "" << std::endl;
+ out << "#include \"" << fixedName << ".h\"" << std::endl;
+ out << "" << std::endl;
+ out << "" << fixedName << "::" << fixedName << "()" << std::endl;
+ out << "{" << std::endl;
+ out << "}" << std::endl;
+ out << "" << std::endl;
+ out << "" << fixedName << "::~" << fixedName << "()" << std::endl;
+ out << "{" << std::endl;
+ out << "}" << std::endl;
+ out << "" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "//Method template" << std::endl;
+ out << "//---------------------------------------------" << std::endl;
+ out << "/*" << std::endl;
+ out << "void " << fixedName << "::FunctionName(int& parameterA)" << std::endl;
+ out << "{" << std::endl;
+ out << " parameterA = 2 * parameterA;" << std::endl;
+ out << " return;" << std::endl;
+ out << "}" << std::endl;
+ out << "*/" << std::endl;
+
+ return true;
+ }
+
+ std::string stringify(const std::string& line)
+ {
+ std::string res;
+ for (int i = 0; i < (int)(line.size()); i++)
+ {
+ if(line[i] == '\\')
+ res.push_back('\\');
+ if(line[i] == '\"')
+ res.push_back('\\');
+ res.push_back(line[i]);
+ }
+ return res;
+ }
+
}