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 # ------------------------------------------------------------------------
29 * modelCDMBlackBox.cpp
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMBlackBox.h"
39 #include "CDMUtilities.h"
44 modelCDMBlackBox::modelCDMBlackBox()
50 modelCDMBlackBox::modelCDMBlackBox(const std::string& path, const std::string& name, const int& level)
52 std::cout << "creating black box: " + name + " in " + path + "\n";
56 this->type = wxDIR_DIRS;
60 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
62 std::ifstream confFile;
63 confFile.open((pathHeader).c_str());
65 while(confFile.is_open() && !confFile.eof())
68 std::getline(confFile,word,'(');
69 std::vector<std::string> wordBits;
70 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
72 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
74 std::getline(confFile,word,'"');
75 std::getline(confFile,word,'"');
76 this->nameBlackBox = word;
78 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
80 std::getline(confFile,word,'"');
81 std::getline(confFile,word,'"');
84 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
86 std::getline(confFile,word,'"');
87 std::getline(confFile,word,'"');
88 this->description = word;
90 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
92 std::getline(confFile,word,'"');
93 std::getline(confFile,word,'"');
94 this->categories = word;
95 if (this->categories == "")
96 this->categories = "empty";
103 modelCDMBlackBox::~modelCDMBlackBox()
109 const std::string& modelCDMBlackBox::GetNameBlackBox() const
111 return this->nameBlackBox;
114 const std::string& modelCDMBlackBox::GetAuthors() const
116 return this->authors;
119 const std::string& modelCDMBlackBox::GetCategories() const
121 return this->categories;
124 const std::string& modelCDMBlackBox::GetDescription() const
126 return this->description;
129 bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result)
131 std::vector<std::string> words;
132 CDMUtilities::splitter::split(words, authors, "/\\\"\n", CDMUtilities::splitter::no_empties);
133 std::string authorsReal = words[0];
134 for (int i = 1; i < words.size(); i++)
136 authorsReal += "," + words[i];
139 //opening original header
140 std::string pathHeader = this->header->GetPath();
141 std::ifstream in(pathHeader.c_str());
144 result = new std::string(pathHeader + " file failed to open.");
147 //opening temporal header
148 std::ofstream out((pathHeader + ".tmp").c_str());
151 result = new std::string(pathHeader + ".tmp file failed to open.");
154 //copying contents from original to temporal and making changes
156 while (getline(in, reading, '('))
158 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
159 if(words[words.size() - 1] == "BBTK_AUTHOR")
161 out << reading << "(\"" << authorsReal << "\")";
162 getline(in, reading, ')');
173 //delete old file and rename new file
174 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
175 if(system(renameCommand.c_str()))
177 result = new std::string("An error occurred while running '" + renameCommand + "'.");
181 this->authors = authorsReal;
186 bool modelCDMBlackBox::SetCategories(
187 const std::string& categories,
191 std::vector<std::string> words;
192 CDMUtilities::splitter::split(words, categories, "\"\\/", CDMUtilities::splitter::no_empties);
193 std::string catsReal = words[0];
194 for (int i = 1; i < words.size(); i++)
196 catsReal += "," + words[i];
199 //opening original header
200 std::string pathHeader = this->header->GetPath();
201 std::ifstream in(pathHeader.c_str());
204 result = new std::string(pathHeader + " file failed to open.");
207 //opening temporal header
208 std::ofstream out((pathHeader + ".tmp").c_str());
211 result = new std::string(pathHeader + ".tmp file failed to open.");
214 //copying contents from original to temporal and making changes
216 while (getline(in, reading, '('))
218 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
219 if(words[words.size() - 1] == "BBTK_CATEGORY")
221 out << reading << "(\"" << catsReal << "\")";
222 getline(in, reading, ')');
233 //delete old file and rename new file
234 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
235 if(system(renameCommand.c_str()))
237 result = new std::string("An error occurred while running '" + renameCommand + "'.");
241 this->categories = catsReal;
245 bool modelCDMBlackBox::SetDescription(
246 const std::string& description,
250 std::vector<std::string> words;
251 CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties);
252 std::string descReal = words[0];
253 for (int i = 1; i < words.size(); i++)
255 descReal += "-" + words[i];
258 //opening original header
259 std::string pathHeader = this->header->GetPath();
260 std::ifstream in(pathHeader.c_str());
263 result = new std::string(pathHeader + " file failed to open.");
266 //opening temporal header
267 std::ofstream out((pathHeader + ".tmp").c_str());
270 result = new std::string(pathHeader + ".tmp file failed to open.");
273 //copying contents from original to temporal and making changes
275 while (getline(in, reading, '('))
277 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
278 if(words[words.size() - 1] == "BBTK_DESCRIPTION")
280 out << reading << "(\"" << descReal << "\")";
281 getline(in, reading, ')');
292 //delete old file and rename new file
293 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
294 if(system(renameCommand.c_str()))
296 result = new std::string("An error occurred while running '" + renameCommand + "'.");
300 this->description = descReal;
304 void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file)
309 void modelCDMBlackBox::SetSourceFile(modelCDMFile* file)
314 bool modelCDMBlackBox::OpenCxx(std::string*& result)
316 return !CDMUtilities::openTextEditor(this->source->GetPath());
319 bool modelCDMBlackBox::OpenHxx(std::string*& result)
321 return !CDMUtilities::openTextEditor(this->header->GetPath());
324 modelCDMFile* modelCDMBlackBox::GetHeaderFile() const
329 modelCDMFile* modelCDMBlackBox::GetSourceFile() const
334 const bool modelCDMBlackBox::Refresh(std::string*& result)
336 std::cout << "refreshing black box: " << this->nameBlackBox << std::endl;
337 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
339 std::ifstream confFile;
340 confFile.open((pathHeader).c_str());
343 if(!confFile.is_open())
346 while(confFile.is_open() && !confFile.eof())
349 std::getline(confFile,word,'(');
350 std::vector<std::string> wordBits;
351 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
353 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
355 std::getline(confFile,word,'"');
356 std::getline(confFile,word,'"');
357 this->nameBlackBox = word;
359 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
361 std::getline(confFile,word,'"');
362 std::getline(confFile,word,'"');
363 this->authors = word;
365 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
367 std::getline(confFile,word,'"');
368 std::getline(confFile,word,'"');
369 this->description = word;
371 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
373 std::getline(confFile,word,'"');
374 std::getline(confFile,word,'"');
375 this->categories = word;
376 if (this->categories == "")
377 this->categories = "empty";