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
176 std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
178 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
181 if(system(renameCommand.c_str()))
183 result = new std::string("An error occurred while running '" + renameCommand + "'.");
187 this->authors = authorsReal;
192 bool modelCDMBlackBox::SetCategories(
193 const std::string& categories,
197 std::vector<std::string> words;
198 CDMUtilities::splitter::split(words, categories, "\"\\/", CDMUtilities::splitter::no_empties);
199 std::string catsReal = words[0];
200 for (int i = 1; i < (int)(words.size()); i++)
202 catsReal += "," + words[i];
205 //opening original header
206 std::string pathHeader = this->header->GetPath();
207 std::ifstream in(pathHeader.c_str());
210 result = new std::string(pathHeader + " file failed to open.");
213 //opening temporal header
214 std::ofstream out((pathHeader + ".tmp").c_str());
217 result = new std::string(pathHeader + ".tmp file failed to open.");
220 //copying contents from original to temporal and making changes
222 while (getline(in, reading, '('))
224 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
225 if(words[words.size() - 1] == "BBTK_CATEGORY")
227 out << reading << "(\"" << catsReal << "\")";
228 getline(in, reading, ')');
239 //delete old file and rename new file
241 std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
243 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
246 if(system(renameCommand.c_str()))
248 result = new std::string("An error occurred while running '" + renameCommand + "'.");
252 this->categories = catsReal;
256 bool modelCDMBlackBox::SetDescription(
257 const std::string& description,
261 std::vector<std::string> words;
262 CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties);
263 std::string descReal = words[0];
264 for (int i = 1; i < (int)(words.size()); i++)
266 descReal += "-" + words[i];
269 //opening original header
270 std::string pathHeader = this->header->GetPath();
271 std::ifstream in(pathHeader.c_str());
274 result = new std::string(pathHeader + " file failed to open.");
277 //opening temporal header
278 std::ofstream out((pathHeader + ".tmp").c_str());
281 result = new std::string(pathHeader + ".tmp file failed to open.");
284 //copying contents from original to temporal and making changes
286 while (getline(in, reading, '('))
288 CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties);
289 if(words[words.size() - 1] == "BBTK_DESCRIPTION")
291 out << reading << "(\"" << descReal << "\")";
292 getline(in, reading, ')');
303 //delete old file and rename new file
305 std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
307 std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
309 if(system(renameCommand.c_str()))
311 result = new std::string("An error occurred while running '" + renameCommand + "'.");
315 this->description = descReal;
319 void modelCDMBlackBox::SetHeaderFile(modelCDMFile* file)
324 void modelCDMBlackBox::SetSourceFile(modelCDMFile* file)
329 bool modelCDMBlackBox::OpenCxx(std::string*& result)
331 return !CDMUtilities::openTextEditor(this->source->GetPath());
334 bool modelCDMBlackBox::OpenHxx(std::string*& result)
336 return !CDMUtilities::openTextEditor(this->header->GetPath());
339 modelCDMFile* modelCDMBlackBox::GetHeaderFile() const
344 modelCDMFile* modelCDMBlackBox::GetSourceFile() const
349 const bool modelCDMBlackBox::Refresh(std::string*& result)
351 std::cout << "refreshing black box: " << this->nameBlackBox << std::endl;
352 std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
354 std::ifstream confFile;
355 confFile.open((pathHeader).c_str());
358 if(!confFile.is_open())
361 while(confFile.is_open() && !confFile.eof())
364 std::getline(confFile,word,'(');
365 std::vector<std::string> wordBits;
366 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
368 if(wordBits[wordBits.size()-1] == "BBTK_NAME")
370 std::getline(confFile,word,'"');
371 std::getline(confFile,word,'"');
372 this->nameBlackBox = word;
374 else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR")
376 std::getline(confFile,word,'"');
377 std::getline(confFile,word,'"');
378 this->authors = word;
380 else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION")
382 std::getline(confFile,word,'"');
383 std::getline(confFile,word,'"');
384 this->description = word;
386 else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY")
388 std::getline(confFile,word,'"');
389 std::getline(confFile,word,'"');
390 this->categories = word;
391 if (this->categories == "")
392 this->categories = "empty";