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 "modelCDMPackage.h"
41 #include "CDMUtilities.h"
43 modelCDMPackage::modelCDMPackage()
47 modelCDMPackage::modelCDMPackage(const std::string& path, const int& level)
49 this->type = wxDIR_DIRS;
52 //TODO: set pathMakeLists for windows
53 std::string pathMakeLists = path + "/CMakeLists.txt";
55 std::ifstream confFile;
56 confFile.open((pathMakeLists).c_str());
59 while(confFile.is_open() && !confFile.eof())
62 std::getline(confFile,word,'(');
63 std::vector<std::string> wordBits;
64 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
66 if(wordBits[wordBits.size()-1] == "SET")
69 std::getline(confFile,word,')');
70 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
71 if(wordBits[0] == "BBTK_PACKAGE_NAME")
74 for (int i = 2; i < wordBits.size(); i++)
76 word += " " + wordBits[i];
79 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
81 this->namePackage = wordBits[0];
83 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
86 for (int i = 2; i < wordBits.size(); i++)
88 word += " " + wordBits[i];
91 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
93 this->authors = wordBits[0];
95 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
98 for (int i = 2; i < wordBits.size(); i++)
100 word += " " + wordBits[i];
103 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
105 this->description = wordBits[0];
107 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
109 this->version = wordBits[1];
111 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
113 this->version += "." + wordBits[1];
115 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
117 this->version += "." + wordBits[1];
122 std::vector<std::string> words;
123 std::string delimiters;
124 //TODO::fix for windows
126 CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
127 this->name = words[words.size()-1];
131 //check all folders and files
132 wxDir dir(crea::std2wx((path).c_str()));
138 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
141 std::string stdfileName = crea::wx2std(fileName);
142 //if src, check for black boxes
143 if(stdfileName == "src")
145 wxDir srcF(crea::std2wx((path + delimiters + "src").c_str()));
149 bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES);
152 if(crea::wx2std(srcName.substr(0,2)) == "bb")
154 modelCDMBlackBox* blackbox = new modelCDMBlackBox(crea::wx2std(srcName), path + delimiters + "src", this->level + 1);
155 this->blackBoxes.push_back(blackbox);
156 this->children.push_back(blackbox);
158 innerCont = srcF.GetNext(&srcName);
162 //if is an unknown folder, create folder
165 this->children.push_back(new modelCDMFolder(path + delimiters + stdfileName, this->level + 1));
167 cont = dir.GetNext(&fileName);
171 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
174 std::string stdfileName = crea::wx2std(fileName);
176 //if CMakeLists, create CMakeLists
177 if(stdfileName == "CMakeLists.txt")
179 this->CMakeLists = new modelCDMCMakeListsFile(path + delimiters + stdfileName, this->level + 1);
180 this->children.push_back(this->CMakeLists);
184 this->children.push_back(new modelCDMFile(path + delimiters + stdfileName, this->level + 1));
186 //if is an unknown file, create file
187 cont = dir.GetNext(&fileName);
190 this->SortChildren();
193 modelCDMPackage::~modelCDMPackage()
197 const std::string& modelCDMPackage::GetNamePackage() const
199 return this->namePackage;
202 const std::string& modelCDMPackage::GetAuthors() const
204 return this->authors;
207 const std::string& modelCDMPackage::GetAuthorsEmail() const
209 return this->authorsEmail;
212 const std::string& modelCDMPackage::GetVersion() const
214 return this->version;
217 const std::string& modelCDMPackage::GetDescription() const
219 return this->description;
222 const std::vector<modelCDMBlackBox*>& modelCDMPackage::GetBlackBoxes() const
224 return this->blackBoxes;
227 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
229 std::vector<std::string> words;
230 CDMUtilities::splitter::split(words, authors, ",\n", CDMUtilities::splitter::no_empties);
231 std::string authorsReal = words[0];
232 for (int i = 1; i < words.size(); i++)
234 authorsReal += "/" + words[i];
238 //opening original cmakelists
239 std::ifstream in((this->path + "/CMakeLists.txt").c_str());
242 result = new std::string("CMakeLists.txt file failed to open.");
245 //opening temporal cmakelists
246 std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str());
249 result = new std::string("CMakeLists.txt.tmp file failed to open.");
252 //copying contents from original to temporal and making changes
253 while (getline(in, line))
255 if(line.find("SET(${BBTK_PACKAGE_NAME}_AUTHOR") != std::string::npos)
256 line = "SET(${BBTK_PACKAGE_NAME}_AUTHOR \"" + authorsReal + "\")";
257 out << line << std::endl;
261 //delete old file and rename new file
262 std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt";
263 if(system(renameCommand.c_str()))
265 result = new std::string("An error occurred while running '" + renameCommand + "'.");
269 this->authors = authorsReal;
273 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
275 //TODO: implement method
279 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
281 std::vector<std::string> vers;
282 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
286 //opening original cmakelists
287 std::ifstream in((this->path + "/CMakeLists.txt").c_str());
290 result = new std::string("CMakeLists.txt file failed to open.");
293 //opening temporal cmakelists
294 std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str());
297 result = new std::string("CMakeLists.txt.tmp file failed to open.");
300 //copying contents from original to temporal and making changes
301 while (getline(in, line))
303 if(line.find("SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION") != std::string::npos)
304 line = "SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION " + vers[0] + ")";
305 else if(line.find("SET(${BBTK_PACKAGE_NAME}_VERSION") != std::string::npos)
306 line = "SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION " + vers[1] + ")";
307 else if(line.find("SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION") != std::string::npos)
308 line = "SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION " + vers[2] + ")";
309 out << line << std::endl;
313 //delete old file and rename new file
314 std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt";
315 if(system(renameCommand.c_str()))
317 result = new std::string("An error occurred while running '" + renameCommand + "'.");
321 this->version = vers[0] + "." + vers[1] + "." + vers[2];
325 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
327 std::vector<std::string> words;
328 CDMUtilities::splitter::split(words, description, " \n", CDMUtilities::splitter::no_empties);
329 std::string descriptionReal = words[0];
330 for (int i = 1; i < words.size(); i++)
332 descriptionReal += " " + words[i];
336 //opening original cmakelists
337 std::ifstream in((this->path + "/CMakeLists.txt").c_str());
340 result = new std::string("CMakeLists.txt file failed to open.");
343 //opening temporal cmakelists
344 std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str());
347 result = new std::string("CMakeLists.txt.tmp file failed to open.");
350 //copying contents from original to temporal and making changes
351 while (getline(in, line))
353 if(line.find("SET(${BBTK_PACKAGE_NAME}_DESCRIPTION") != std::string::npos)
354 line = "SET(${BBTK_PACKAGE_NAME}_DESCRIPTION \"" + descriptionReal + "\")";
355 out << line << std::endl;
359 //delete old file and rename new file
360 std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt";
361 if(system(renameCommand.c_str()))
363 result = new std::string("An error occurred while running '" + renameCommand + "'.");
367 this->description = descriptionReal;
371 bool modelCDMPackage::CreateBlackBox(
372 const std::string& name,
373 const std::string& authors,
374 const std::string& authorsEmail,
375 const std::string& categories,
376 const std::string& description
379 //TODO: implement method
383 const bool modelCDMPackage::Refresh(std::string*& result)
385 //TODO: implement method