X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcreaDevManagerLib%2FCDMUtilities.cpp;h=09e25f31c06d8a64f1ea9896d214a145f94e1a4d;hb=58f32bff34779e30ecef47a095f08c96aae6edba;hp=a73282f247a68f3ee4e736840ec6b2b277c39421;hpb=e2223b619fa37daaf6103b34b39e789efc1a0b94;p=crea.git diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index a73282f..09e25f3 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -35,6 +35,11 @@ #include "CDMUtilities.h" #include +#include +#include +#include +#include +#include namespace CDMUtilities { @@ -54,37 +59,272 @@ 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 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 pathSlpit; - splitter::split(pathSlpit, path, "\"/", splitter::no_empties); - for (int i = 0; i < pathSlpit.size(); i++) + std::vector 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) + { + std::string command = TEXT_EDITOR; + + if(file != "") + command += " \"" + file + "\""; + command += " &"; + + return system(command.c_str()); + } + + int openFileExplorer(const std::string& file) + { + std::string command = 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) + { + std::string comm = TERMINAL; + if (command != "") + comm += + " " + command; + comm += " &"; + return system(comm.c_str()); + } + + bool createEmptyClass(const std::string& name, const std::string& path) + { + std::vector 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 < line.size(); i++) + { + if(line[i] == '\\') + res.push_back('\\'); + if(line[i] == '\"') + res.push_back('\\'); + res.push_back(line[i]); + } + return res; + } + }