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(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
52 std::cout << "creating package src: " + path + "\n";
53 this->parent = parent;
55 this->children.clear();
57 this->CMakeLists = NULL;
60 this->path = CDMUtilities::fixPath(path);
61 this->type = wxDIR_DIRS;
64 wxDir dir(crea::std2wx(path));
68 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
71 std::string stdfileName = crea::wx2std(fileName);
73 //if is an unknown folder, create folder
74 this->children.push_back(new modelCDMFolder(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
76 cont = dir.GetNext(&fileName);
79 cont = dir.GetFirst(&fileName, wxT("CMakeLists.txt"), wxDIR_FILES);
82 std::string stdfileName = crea::wx2std(fileName);
83 this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
84 this->children.push_back(this->CMakeLists);
87 cont = dir.GetFirst(&fileName, wxT("*.h"), wxDIR_FILES);
90 std::string stdfileName = crea::wx2std(fileName);
91 std::size_t fileTypePos = stdfileName.find_last_of(".");
93 if(fileTypePos != std::string::npos)
94 fileType = stdfileName.substr(fileTypePos);
98 modelCDMCodeFile* file;
100 if(stdfileName.substr(0,2) == "bb")
102 file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
103 this->children.push_back(file);
104 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
105 blackBox->SetHeaderFile(file);
106 wxDir dir2(crea::std2wx(path));
107 cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
110 file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
111 this->children.push_back(file);
112 blackBox->SetSourceFile(file);
114 this->blackBoxes.push_back(blackBox);
116 cont = dir.GetNext(&fileName);
120 this->SortChildren();
121 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
124 modelCDMPackageSrc::~modelCDMPackageSrc()
126 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
128 if(this->blackBoxes[i] != NULL)
130 delete this->blackBoxes[i];
131 this->blackBoxes[i] = NULL;
134 this->blackBoxes.clear();
137 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
139 return this->blackBoxes;
142 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
143 std::string*& result,
144 const std::string& name,
145 const std::string& package,
146 const std::string& type,
147 const std::string& format,
148 const std::string& categories,
149 const std::string& authors,
150 const std::string& authorsEmail,
151 const std::string& description)
154 std::vector<std::string> words;
155 CDMUtilities::splitter::split(words, name, " \n\",/\\'", CDMUtilities::splitter::no_empties);
157 for (int i = 0; i < (int)(words.size()); i++)
163 CDMUtilities::splitter::split(words, categories, " \n\",/\\'", CDMUtilities::splitter::no_empties);
164 std::string bbCategories;
167 bbCategories = words[0];
168 for (int i = 1; i < (int)(words.size()); i++)
170 bbCategories += "," + words[i];
173 if(bbCategories == "")
174 bbCategories = "empty";
177 CDMUtilities::splitter::split(words, authors, "\n\",/\\'", CDMUtilities::splitter::no_empties);
178 std::string bbAuthors;
181 bbAuthors = words[0];
182 for (int i = 1; i < (int)(words.size()); i++)
184 bbAuthors += "," + words[i];
188 bbAuthors = "Unknown";
191 CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\'", CDMUtilities::splitter::no_empties);
192 std::string bbDescription;
195 bbDescription = words[0];
196 for (int i = 1; i < (int)(words.size()); i++)
198 bbDescription += "," + words[i];
200 bbDescription += " - ";
202 CDMUtilities::splitter::split(words, description, "\n\"/\\'", CDMUtilities::splitter::no_empties);
205 bbDescription += words[0];
206 for (int i = 1; i < (int)(words.size()); i++)
208 bbDescription += words[i];
212 if(bbDescription == "")
213 bbDescription = "No Description.";
217 std::string command = "bbCreateBlackBox";
218 command += " \"" + this->path + "\"";
220 command += " " + package;
221 command += " " + bbName;
222 command += " " + type;
223 command += " " + format;
225 command += " \"" + package + "\"";
226 command += " \"" + bbName + "\"";
227 command += " \"" + type + "\"";
228 command += " \"" + format + "\"";
230 command += " \"" + bbAuthors + "\"";
231 command += " \"" + bbDescription + "\"";
232 command += " \"" + bbCategories + "\"";
235 //wxMessageBox(crea::std2wx("Command: ->" + command + "<-"),_T("Creating Black Box"),wxOK | wxICON_INFORMATION);
236 if(system(command.c_str()))
238 result = new std::string("Error executing command '" + command + "'");
246 modelCDMFile* header = NULL;
247 modelCDMFile* source = NULL;
248 wxDir dir(crea::std2wx(path));
252 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
255 std::string stdfileName = crea::wx2std(fileName);
256 header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
258 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
261 std::string stdfileName = crea::wx2std(fileName);
262 source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
265 //if source and header exist
266 if (header != NULL && source != NULL)
269 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
271 //associate header and source
272 blackBox->SetHeaderFile(header);
273 blackBox->SetSourceFile(source);
275 this->children.push_back(header);
276 this->children.push_back(source);
278 this->blackBoxes.push_back(blackBox);
281 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
282 this->SortChildren();
288 result = new std::string("The header and source files were not found. Black box not created.");
293 const bool modelCDMPackageSrc::Refresh(std::string*& result)
295 std::cout << "refreshing package src" << std::endl;
297 this->type = wxDIR_DIRS;
300 std::vector<bool> checked(this->children.size(), false);
301 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
304 wxDir dir(crea::std2wx((this->path).c_str()));
308 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
311 std::string stdfileName = crea::wx2std(fileName);
312 std::string folderName = stdfileName;
313 //check if they already exist
315 for (int i = 0; !found && i < (int)(this->children.size()); i++)
317 if (this->children[i]->GetName() == folderName)
321 if(!this->children[i]->Refresh(result))
327 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
328 this->children.push_back(folder);
330 cont = dir.GetNext(&fileName);
333 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
336 std::string stdfileName = crea::wx2std(fileName);
337 std::size_t fileTypePos = stdfileName.find_last_of(".");
338 std::string fileType;
339 if(fileTypePos != std::string::npos)
340 fileType = stdfileName.substr(fileTypePos);
344 //if CMakeLists, create CMakeLists
345 if(stdfileName == "CMakeLists.txt")
347 if (this->CMakeLists == NULL)
349 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
350 this->children.push_back(this->CMakeLists);
354 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
356 if(!this->CMakeLists->Refresh(result))
360 //if is an unknown file, create file
364 for (int i = 0; !found && i < (int)(this->children.size()); i++)
366 if (this->children[i]->GetName() == stdfileName)
370 if(!this->children[i]->Refresh(result))
377 //if is a code file, create modelCDMCodeFile
380 fileType == ".cxx" ||
382 fileType == ".cpp" ||
383 fileType == ".txx" ||
384 fileType == ".cmake" )
386 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
390 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
391 this->children.push_back(file);
396 //if is a Black Box header, check in black boxes
397 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
400 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
402 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
404 checkedBoxes[i] = true;
406 if(!this->blackBoxes[i]->Refresh(result))
414 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
415 this->blackBoxes.push_back(blackBox);
420 cont = dir.GetNext(&fileName);
424 for (int i = 0; i < (int)(checkedBoxes.size()); i++)
428 delete this->blackBoxes[i];
429 this->blackBoxes.erase(this->blackBoxes.begin()+i);
430 checkedBoxes.erase(checkedBoxes.begin()+i);
435 for (int i = 0; i < (int)(checked.size()); i++)
439 delete this->children[i];
440 this->children.erase(this->children.begin()+i);
441 checked.erase(checked.begin()+i);
445 this->SortChildren();
446 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);