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(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
52 std::cout << "creating black box: " + name + " in " + path + "\n";
53 this->parent = parent;
57 this->type = wxDIR_DIRS;
61 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
63 std::ifstream confFile;
64 confFile.open((pathHeader).c_str());
66 while(confFile.is_open() && !confFile.eof())
69 std::getline(confFile,word,'(');
70 std::vector<std::string> wordBits;
71 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
73 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
75 std::getline(confFile,word,'"');
76 std::getline(confFile,word,'"');
77 this->nameBlackBox = word;
79 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
81 std::getline(confFile,word,'"');
82 std::getline(confFile,word,'"');
85 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
87 std::getline(confFile,word,'"');
88 std::getline(confFile,word,'"');
89 this->description = word;
91 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
93 std::getline(confFile,word,'"');
94 std::getline(confFile,word,'"');
95 this->categories = word;
96 if (this->categories == "")
97 this->categories = "empty";
104 modelCDMBlackBox::~modelCDMBlackBox()
110 const std::string& modelCDMBlackBox::GetNameBlackBox() const
112 return this->nameBlackBox;
115 const std::string& modelCDMBlackBox::GetAuthors() const
117 return this->authors;
120 const std::string& modelCDMBlackBox::GetCategories() const
122 return this->categories;
125 const std::string& modelCDMBlackBox::GetDescription() const
127 return this->description;
130 bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result)
132 std::vector<std::string> words;
133 CDMUtilities::splitter::split(words, authors, "/\\\"\n", CDMUtilities::splitter::no_empties);
134 std::string authorsReal = words[0];
135 for (int i = 1; i < (int)(words.size()); i++)
137 authorsReal += "," + words[i];
140 //opening original header
141 std::string pathHeader = this->header->GetPath();
142 std::ifstream in(pathHeader.c_str());
145 result = new std::string(pathHeader + " file failed to open.");
148 //opening temporal header
149 std::ofstream out((pathHeader + ".tmp").c_str());
152 result = new std::string(pathHeader + ".tmp file failed to open.");
155 //copying contents from original to temporal and making changes
157 while (getline(in, reading, '('))
159 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
160 if(words[words.size() - 1] == "BBTK_AUTHOR")
162 out << reading << "(\"" << authorsReal << "\")";
163 getline(in, reading, ')');
174 //delete old file and rename new file
175 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
176 if(system(renameCommand.c_str()))
178 result = new std::string("An error occurred while running '" + renameCommand + "'.");
182 this->authors = authorsReal;
187 bool modelCDMBlackBox::SetCategories(
188 const std::string& categories,
192 std::vector<std::string> words;
193 CDMUtilities::splitter::split(words, categories, "\"\\/", CDMUtilities::splitter::no_empties);
194 std::string catsReal = words[0];
195 for (int i = 1; i < (int)(words.size()); i++)
197 catsReal += "," + words[i];
200 //opening original header
201 std::string pathHeader = this->header->GetPath();
202 std::ifstream in(pathHeader.c_str());
205 result = new std::string(pathHeader + " file failed to open.");
208 //opening temporal header
209 std::ofstream out((pathHeader + ".tmp").c_str());
212 result = new std::string(pathHeader + ".tmp file failed to open.");
215 //copying contents from original to temporal and making changes
217 while (getline(in, reading, '('))
219 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
220 if(words[words.size() - 1] == "BBTK_CATEGORY")
222 out << reading << "(\"" << catsReal << "\")";
223 getline(in, reading, ')');
234 //delete old file and rename new file
235 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
236 if(system(renameCommand.c_str()))
238 result = new std::string("An error occurred while running '" + renameCommand + "'.");
242 this->categories = catsReal;
246 bool modelCDMBlackBox::SetDescription(
247 const std::string& description,
251 std::vector<std::string> words;
252 CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties);
253 std::string descReal = words[0];
254 for (int i = 1; i < (int)(words.size()); i++)
256 descReal += "-" + words[i];
259 //opening original header
260 std::string pathHeader = this->header->GetPath();
261 std::ifstream in(pathHeader.c_str());
264 result = new std::string(pathHeader + " file failed to open.");
267 //opening temporal header
268 std::ofstream out((pathHeader + ".tmp").c_str());
271 result = new std::string(pathHeader + ".tmp file failed to open.");
274 //copying contents from original to temporal and making changes
276 while (getline(in, reading, '('))
278 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
279 if(words[words.size() - 1] == "BBTK_DESCRIPTION")
281 out << reading << "(\"" << descReal << "\")";
282 getline(in, reading, ')');
293 //delete old file and rename new file
294 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
295 if(system(renameCommand.c_str()))
297 result = new std::string("An error occurred while running '" + renameCommand + "'.");
301 this->description = descReal;
305 void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file)
310 void modelCDMBlackBox::SetSourceFile(modelCDMFile* file)
315 bool modelCDMBlackBox::OpenCxx(std::string*& result)
317 return !CDMUtilities::openTextEditor(this->source->GetPath());
320 bool modelCDMBlackBox::OpenHxx(std::string*& result)
322 return !CDMUtilities::openTextEditor(this->header->GetPath());
325 modelCDMFile* modelCDMBlackBox::GetHeaderFile() const
330 modelCDMFile* modelCDMBlackBox::GetSourceFile() const
335 const bool modelCDMBlackBox::Refresh(std::string*& result)
337 std::cout << "refreshing black box: " << this->nameBlackBox << std::endl;
338 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
340 std::ifstream confFile;
341 confFile.open((pathHeader).c_str());
344 if(!confFile.is_open())
347 while(confFile.is_open() && !confFile.eof())
350 std::getline(confFile,word,'(');
351 std::vector<std::string> wordBits;
352 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
354 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
356 std::getline(confFile,word,'"');
357 std::getline(confFile,word,'"');
358 this->nameBlackBox = word;
360 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
362 std::getline(confFile,word,'"');
363 std::getline(confFile,word,'"');
364 this->authors = word;
366 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
368 std::getline(confFile,word,'"');
369 std::getline(confFile,word,'"');
370 this->description = word;
372 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
374 std::getline(confFile,word,'"');
375 std::getline(confFile,word,'"');
376 this->categories = word;
377 if (this->categories == "")
378 this->categories = "empty";