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)
55 this->type = wxDIR_DIRS;
59 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
61 std::ifstream confFile;
62 confFile.open((pathHeader).c_str());
64 while(confFile.is_open() && !confFile.eof())
67 std::getline(confFile,word,'(');
68 std::vector<std::string> wordBits;
69 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
71 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
73 std::getline(confFile,word,'"');
74 std::getline(confFile,word,'"');
75 this->nameBlackBox = word;
77 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
79 std::getline(confFile,word,'"');
80 std::getline(confFile,word,'"');
83 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
85 std::getline(confFile,word,'"');
86 std::getline(confFile,word,'"');
87 this->description = word;
89 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
91 std::getline(confFile,word,'"');
92 std::getline(confFile,word,'"');
93 this->categories = word;
94 if (this->categories == "")
95 this->categories = "empty";
102 modelCDMBlackBox::~modelCDMBlackBox()
108 const std::string& modelCDMBlackBox::GetNameBlackBox() const
110 return this->nameBlackBox;
113 const std::string& modelCDMBlackBox::GetAuthors() const
115 return this->authors;
118 const std::string& modelCDMBlackBox::GetCategories() const
120 return this->categories;
123 const std::string& modelCDMBlackBox::GetDescription() const
125 return this->description;
128 bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result)
130 std::vector<std::string> words;
131 CDMUtilities::splitter::split(words, authors, "/\\\"\n", CDMUtilities::splitter::no_empties);
132 std::string authorsReal = words[0];
133 for (int i = 1; i < words.size(); i++)
135 authorsReal += "," + words[i];
138 //opening original header
139 std::string pathHeader = this->header->GetPath();
140 std::ifstream in(pathHeader.c_str());
143 result = new std::string(pathHeader + " file failed to open.");
146 //opening temporal header
147 std::ofstream out((pathHeader + ".tmp").c_str());
150 result = new std::string(pathHeader + ".tmp file failed to open.");
153 //copying contents from original to temporal and making changes
155 while (getline(in, reading, '('))
157 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
158 if(words[words.size() - 1] == "BBTK_AUTHOR")
160 out << reading << "(\"" << authorsReal << "\")";
161 getline(in, reading, ')');
172 //delete old file and rename new file
173 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
174 if(system(renameCommand.c_str()))
176 result = new std::string("An error occurred while running '" + renameCommand + "'.");
180 this->authors = authorsReal;
185 bool modelCDMBlackBox::SetCategories(
186 const std::string& categories,
190 std::vector<std::string> words;
191 CDMUtilities::splitter::split(words, categories, "\"\\/", CDMUtilities::splitter::no_empties);
192 std::string catsReal = words[0];
193 for (int i = 1; i < words.size(); i++)
195 catsReal += "," + words[i];
198 //opening original header
199 std::string pathHeader = this->header->GetPath();
200 std::ifstream in(pathHeader.c_str());
203 result = new std::string(pathHeader + " file failed to open.");
206 //opening temporal header
207 std::ofstream out((pathHeader + ".tmp").c_str());
210 result = new std::string(pathHeader + ".tmp file failed to open.");
213 //copying contents from original to temporal and making changes
215 while (getline(in, reading, '('))
217 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
218 if(words[words.size() - 1] == "BBTK_CATEGORY")
220 out << reading << "(\"" << catsReal << "\")";
221 getline(in, reading, ')');
232 //delete old file and rename new file
233 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
234 if(system(renameCommand.c_str()))
236 result = new std::string("An error occurred while running '" + renameCommand + "'.");
240 this->categories = catsReal;
244 bool modelCDMBlackBox::SetDescription(
245 const std::string& description,
249 std::vector<std::string> words;
250 CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties);
251 std::string descReal = words[0];
252 for (int i = 1; i < words.size(); i++)
254 descReal += "-" + words[i];
257 //opening original header
258 std::string pathHeader = this->header->GetPath();
259 std::ifstream in(pathHeader.c_str());
262 result = new std::string(pathHeader + " file failed to open.");
265 //opening temporal header
266 std::ofstream out((pathHeader + ".tmp").c_str());
269 result = new std::string(pathHeader + ".tmp file failed to open.");
272 //copying contents from original to temporal and making changes
274 while (getline(in, reading, '('))
276 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
277 if(words[words.size() - 1] == "BBTK_DESCRIPTION")
279 out << reading << "(\"" << descReal << "\")";
280 getline(in, reading, ')');
291 //delete old file and rename new file
292 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
293 if(system(renameCommand.c_str()))
295 result = new std::string("An error occurred while running '" + renameCommand + "'.");
299 this->description = descReal;
303 void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file)
308 void modelCDMBlackBox::SetSourceFile(modelCDMFile* file)
313 bool modelCDMBlackBox::OpenCxx(std::string*& result)
315 return !CDMUtilities::openTextEditor(this->source->GetPath());
318 bool modelCDMBlackBox::OpenHxx(std::string*& result)
320 return !CDMUtilities::openTextEditor(this->header->GetPath());
323 modelCDMFile* modelCDMBlackBox::GetHeaderFile() const
328 modelCDMFile* modelCDMBlackBox::GetSourceFile() const
333 const bool modelCDMBlackBox::Refresh(std::string*& result)
335 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
337 std::ifstream confFile;
338 confFile.open((pathHeader).c_str());
341 if(!confFile.is_open())
344 while(confFile.is_open() && !confFile.eof())
347 std::getline(confFile,word,'(');
348 std::vector<std::string> wordBits;
349 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
351 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
353 std::getline(confFile,word,'"');
354 std::getline(confFile,word,'"');
355 this->nameBlackBox = word;
357 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
359 std::getline(confFile,word,'"');
360 std::getline(confFile,word,'"');
361 this->authors = word;
363 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
365 std::getline(confFile,word,'"');
366 std::getline(confFile,word,'"');
367 this->description = word;
369 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
371 std::getline(confFile,word,'"');
372 std::getline(confFile,word,'"');
373 this->categories = word;
374 if (this->categories == "")
375 this->categories = "empty";