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 28, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMPackageSrc.h"
43 #include "CDMUtilities.h"
45 modelCDMPackageSrc::modelCDMPackageSrc()
47 this->CMakeLists = NULL;
50 modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::string& name, const int& level)
52 std::cout << "creating package src: " + path + "\n";
54 this->children.clear();
56 this->CMakeLists = NULL;
59 this->path = CDMUtilities::fixPath(path);
60 this->type = wxDIR_DIRS;
63 wxDir dir(crea::std2wx(path));
67 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
70 std::string stdfileName = crea::wx2std(fileName);
72 //if is an unknown folder, create folder
73 this->children.push_back(new modelCDMFolder(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
75 cont = dir.GetNext(&fileName);
78 cont = dir.GetFirst(&fileName, wxT("CMakeLists.txt"), wxDIR_FILES);
81 std::string stdfileName = crea::wx2std(fileName);
82 this->CMakeLists = new modelCDMCMakeListsFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
83 this->children.push_back(this->CMakeLists);
86 cont = dir.GetFirst(&fileName, wxT("*.h"), wxDIR_FILES);
89 std::string stdfileName = crea::wx2std(fileName);
92 if(stdfileName.substr(0,2) == "bb")
94 file = new modelCDMFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
95 this->children.push_back(file);
96 modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
97 blackBox->SetHeaderFile(file);
98 wxDir dir2(crea::std2wx(path));
99 cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
102 file = new modelCDMFile(path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
103 this->children.push_back(file);
104 blackBox->SetSourceFile(file);
106 this->blackBoxes.push_back(blackBox);
108 cont = dir.GetNext(&fileName);
112 this->SortChildren();
113 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
116 modelCDMPackageSrc::~modelCDMPackageSrc()
118 for (int i = 0; i < this->blackBoxes.size(); i++)
120 if(this->blackBoxes[i] != NULL)
122 delete this->blackBoxes[i];
123 this->blackBoxes[i] = NULL;
126 this->blackBoxes.clear();
129 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
131 return this->blackBoxes;
134 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
135 std::string*& result,
136 const std::string& name,
137 const std::string& package,
138 const std::string& type,
139 const std::string& format,
140 const std::string& categories,
141 const std::string& authors,
142 const std::string& authorsEmail,
143 const std::string& description)
146 std::vector<std::string> words;
147 CDMUtilities::splitter::split(words, name, " \n\",/\\'", CDMUtilities::splitter::no_empties);
149 for (int i = 0; i < words.size(); i++)
155 CDMUtilities::splitter::split(words, categories, " \n\",/\\'", CDMUtilities::splitter::no_empties);
156 std::string bbCategories;
159 bbCategories = words[0];
160 for (int i = 1; i < words.size(); i++)
162 bbCategories += "," + words[i];
165 if(bbCategories == "")
166 bbCategories = "empty";
169 CDMUtilities::splitter::split(words, authors, "\n\",/\\'", CDMUtilities::splitter::no_empties);
170 std::string bbAuthors;
173 bbAuthors = words[0];
174 for (int i = 1; i < words.size(); i++)
176 bbAuthors += "," + words[i];
180 bbAuthors = "Unknown";
183 CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\'", CDMUtilities::splitter::no_empties);
184 std::string bbDescription;
187 bbDescription = words[0];
188 for (int i = 1; i < words.size(); i++)
190 bbDescription += "," + words[i];
192 bbDescription += " - ";
194 CDMUtilities::splitter::split(words, description, "\n\"/\\'", CDMUtilities::splitter::no_empties);
197 bbDescription += words[0];
198 for (int i = 1; i < words.size(); i++)
200 bbDescription += words[i];
204 if(bbDescription == "")
205 bbDescription = "No Description.";
209 std::string command = "bbCreateBlackBox";
210 command += " \"" + this->path + "\"";
211 command += " \"" + package + "\"";
212 command += " \"" + bbName + "\"";
213 command += " \"" + type + "\"";
214 command += " \"" + format + "\"";
215 command += " \"" + bbAuthors + "\"";
216 command += " \"" + bbDescription + "\"";
217 command += " \"" + bbCategories + "\"";
220 if(system(command.c_str()))
222 result = new std::string("Error executing command '" + command + "'");
230 modelCDMFile* header = NULL;
231 modelCDMFile* source = NULL;
232 wxDir dir(crea::std2wx(path));
236 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
239 std::string stdfileName = crea::wx2std(fileName);
240 header = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1);
242 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
245 std::string stdfileName = crea::wx2std(fileName);
246 source = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1);
249 //if source and header exist
250 if (header != NULL && source != NULL)
253 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this->path, package+bbName);
255 //associate header and source
256 blackBox->SetHeaderFile(header);
257 blackBox->SetSourceFile(source);
259 this->children.push_back(header);
260 this->children.push_back(source);
262 this->blackBoxes.push_back(blackBox);
265 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
266 this->SortChildren();
272 result = new std::string("The header and source files were not found. Black box not created.");
277 const bool modelCDMPackageSrc::Refresh(std::string*& result)
279 std::cout << "refreshing package src" << std::endl;
281 this->type = wxDIR_DIRS;
284 std::vector<bool> checked(this->children.size(), false);
285 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
288 wxDir dir(crea::std2wx((this->path).c_str()));
292 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
295 std::string stdfileName = crea::wx2std(fileName);
296 std::string folderName = stdfileName;
297 //check if they already exist
299 for (int i = 0; !found && i < this->children.size(); i++)
301 if (this->children[i]->GetName() == folderName)
305 if(!this->children[i]->Refresh(result))
311 modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
312 this->children.push_back(folder);
314 cont = dir.GetNext(&fileName);
317 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
320 std::string stdfileName = crea::wx2std(fileName);
322 //if CMakeLists, create CMakeLists
323 if(stdfileName == "CMakeLists.txt")
325 if (this->CMakeLists == NULL)
327 this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
328 this->children.push_back(this->CMakeLists);
332 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
334 if(!this->CMakeLists->Refresh(result))
338 //if is an unknown file, create file
342 for (int i = 0; !found && i < this->children.size(); i++)
344 if (this->children[i]->GetName() == stdfileName)
348 if(!this->children[i]->Refresh(result))
355 modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
356 this->children.push_back(file);
360 //if is a Black Box header, check in black boxes
361 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
364 for (int i = 0; i < this->blackBoxes.size(); i++)
366 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
368 checkedBoxes[i] = true;
370 if(!this->blackBoxes[i]->Refresh(result))
378 modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
379 this->blackBoxes.push_back(blackBox);
384 cont = dir.GetNext(&fileName);
388 for (int i = 0; i < checkedBoxes.size(); i++)
392 delete this->blackBoxes[i];
393 this->blackBoxes.erase(this->blackBoxes.begin()+i);
394 checkedBoxes.erase(checkedBoxes.begin()+i);
399 for (int i = 0; i < checked.size(); i++)
403 delete this->children[i];
404 this->children.erase(this->children.begin()+i);
405 checked.erase(checked.begin()+i);
409 this->SortChildren();
410 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);