2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "CDMUtilities.h"
47 namespace CDMUtilities
49 template <typename Container>
50 Container& splitter::split
53 const typename Container::value_type& s,
54 const typename Container::value_type& delimiters,
63 if (empties == no_empties)
65 next = s.find_first_not_of(delimiters, next + 1);
66 if (next == Container::value_type::npos)
73 next = s.find_first_of(delimiters, current);
74 result.push_back(s.substr(current, next - current));
76 while (next != Container::value_type::npos);
80 const std::string fixPath(const std::string& path)
82 std::string pathFixed = "";
86 std::vector<std::string> pathSplit;
88 splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
90 if(0 < pathSplit.size())
91 pathFixed = pathSplit[0];
93 for (int i = 1; i < (int)(pathSplit.size()); i++)
95 pathFixed += CDMUtilities::SLASH + pathSplit[i];
98 // ------ LINUX / MacOS
99 //break path into folders
100 std::vector<std::string> pathSplit;
102 splitter::split(pathSplit, path, CDMUtilities::SLASH, splitter::no_empties);
104 for (int i = 0; i < pathSplit.size(); i++)
106 pathFixed += CDMUtilities::SLASH + pathSplit[i];
113 int openTextEditor(const std::string& file)
115 wxConfigBase* pConfig = wxConfigBase::Get();
116 std::string command = crea::wx2std(pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR)));
119 command += " \"" + file + "\"";
122 return system(command.c_str());
125 int openFileExplorer(const std::string& file)
127 wxConfigBase* pConfig = wxConfigBase::Get();
128 std::string command = crea::wx2std(pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER)));
131 command += " \"" + file + "\"";
134 return system(command.c_str());
137 int openFileWithCommand(const std::string& file, const std::string& command)
139 std::string comm = command;
141 comm += " \"" + file + "\"";
144 return system(comm.c_str());
149 std::string comm = "bbEditor &";
150 return system(comm.c_str());
153 int openCreaToolsTools()
156 std::string comm = "creaTools &";
158 std::string comm = "creaTools.sh &";
161 return system(comm.c_str());
164 int openTerminal(const std::string& command)
166 wxConfigBase* pConfig = wxConfigBase::Get();
167 std::string comm = crea::wx2std(pConfig->Read(wxT("TERMINAl"), crea::std2wx(CDMUtilities::TERMINAL)));
169 comm += + " " + command;
171 return system(comm.c_str());
174 bool createEmptyClass(const std::string& name, const std::string& path)
176 std::vector<std::string> words;
177 splitter::split(words,name," \\/\",.'`",splitter::no_empties);
178 std::string fixedName = "";
179 for (int i = 0; i < (int)(words.size()); i++)
181 fixedName += words[i];
184 if(fixedName == "" || path == "")
189 std::string nameupper = fixedName;
190 std::transform(nameupper.begin(), nameupper.end(),nameupper.begin(),::toupper);
192 std::ofstream out((path + SLASH + fixedName + ".h").c_str());
198 out << "/*" << std::endl;
199 out << "# ---------------------------------------------------------------------" << std::endl;
200 out << "#" << std::endl;
201 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
202 out << "# pour la Sante)" << std::endl;
203 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
204 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
205 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
206 out << "#" << std::endl;
207 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
208 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
209 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
210 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
211 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
212 out << "# or in the file LICENSE.txt." << std::endl;
213 out << "#" << std::endl;
214 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
215 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
216 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
217 out << "# economic rights, and the successive licensors have only limited" << std::endl;
218 out << "# liability." << std::endl;
219 out << "#" << std::endl;
220 out << "# The fact that you are presently reading this means that you have had" << std::endl;
221 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
222 out << "# ------------------------------------------------------------------------" << std::endl;
223 out << "*/" << std::endl;
224 out << "" << std::endl;
225 out << "#ifndef _" << nameupper << "_H_" << std::endl;
226 out << "#define _" << nameupper << "_H_" << std::endl;
227 out << "" << std::endl;
228 out << "//---------------------------------------------" << std::endl;
229 out << "// Class Name: " << fixedName << "" << std::endl;
230 out << "// [classdescription]" << std::endl;
231 out << "//---------------------------------------------" << std::endl;
232 out << "" << std::endl;
233 out << "class " << fixedName << "" << std::endl;
234 out << "{" << std::endl;
235 out << "" << std::endl;
236 out << "//---------------------------------------------" << std::endl;
237 out << "//Methods and attributes exposed to other classes" << std::endl;
238 out << "//---------------------------------------------" << std::endl;
239 out << "public :" << std::endl;
240 out << " " << fixedName << "();" << std::endl;
241 out << " ~" << fixedName << "();" << std::endl;
242 out << "" << std::endl;
243 out << "//--Method template----------------------------" << std::endl;
244 out << "// void FunctionName(int& parameterA);" << std::endl;
245 out << "" << std::endl;
246 out << "" << std::endl;
247 out << "//---------------------------------------------" << std::endl;
248 out << "//Methods and attributes exposed only to classes" << std::endl;
249 out << "//that are derived from this class" << std::endl;
250 out << "//---------------------------------------------" << std::endl;
251 out << "protected:" << std::endl;
252 out << "" << std::endl;
253 out << "//---------------------------------------------" << std::endl;
254 out << "//Methods and attributes only visible by this class" << std::endl;
255 out << "//---------------------------------------------" << std::endl;
256 out << "private:" << std::endl;
257 out << "" << std::endl;
258 out << "};" << std::endl;
259 out << "" << std::endl;
260 out << "//-end of _" << nameupper << "_H_------------------------------------------------------" << std::endl;
261 out << "#endif" << std::endl;
265 out.open((path + CDMUtilities::SLASH + fixedName + ".cpp").c_str());
271 out << "/*" << std::endl;
272 out << "# ---------------------------------------------------------------------" << std::endl;
273 out << "#" << std::endl;
274 out << "# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image" << std::endl;
275 out << "# pour la Sante)" << std::endl;
276 out << "# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton" << std::endl;
277 out << "# Previous Authors : Laurent Guigues, Jean-Pierre Roux" << std::endl;
278 out << "# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil" << std::endl;
279 out << "#" << std::endl;
280 out << "# This software is governed by the CeCILL-B license under French law and" << std::endl;
281 out << "# abiding by the rules of distribution of free software. You can use," << std::endl;
282 out << "# modify and/ or redistribute the software under the terms of the CeCILL-B" << std::endl;
283 out << "# license as circulated by CEA, CNRS and INRIA at the following URL" << std::endl;
284 out << "# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html" << std::endl;
285 out << "# or in the file LICENSE.txt." << std::endl;
286 out << "#" << std::endl;
287 out << "# As a counterpart to the access to the source code and rights to copy," << std::endl;
288 out << "# modify and redistribute granted by the license, users are provided only" << std::endl;
289 out << "# with a limited warranty and the software's author, the holder of the" << std::endl;
290 out << "# economic rights, and the successive licensors have only limited" << std::endl;
291 out << "# liability." << std::endl;
292 out << "#" << std::endl;
293 out << "# The fact that you are presently reading this means that you have had" << std::endl;
294 out << "# knowledge of the CeCILL-B license and that you accept its terms." << std::endl;
295 out << "# ------------------------------------------------------------------------" << std::endl;
296 out << "*/" << std::endl;
297 out << "" << std::endl;
298 out << "#include \"" << fixedName << ".h\"" << std::endl;
299 out << "" << std::endl;
300 out << "" << fixedName << "::" << fixedName << "()" << std::endl;
301 out << "{" << std::endl;
302 out << "}" << std::endl;
303 out << "" << std::endl;
304 out << "" << fixedName << "::~" << fixedName << "()" << std::endl;
305 out << "{" << std::endl;
306 out << "}" << std::endl;
307 out << "" << std::endl;
308 out << "//---------------------------------------------" << std::endl;
309 out << "//Method template" << std::endl;
310 out << "//---------------------------------------------" << std::endl;
311 out << "/*" << std::endl;
312 out << "void " << fixedName << "::FunctionName(int& parameterA)" << std::endl;
313 out << "{" << std::endl;
314 out << " parameterA = 2 * parameterA;" << std::endl;
315 out << " return;" << std::endl;
316 out << "}" << std::endl;
317 out << "*/" << std::endl;
322 std::string stringify(const std::string& line)
325 for (int i = 0; i < (int)(line.size()); i++)
331 res.push_back(line[i]);