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 + "\"";
236 command = "source ~/.bbtk/profile_creatools ; " + command;
240 // wxMessageBox(crea::std2wx("Command: ->" + command + "<-"),_T("Creating Black Box"),wxOK | wxICON_INFORMATION);
241 if(system(command.c_str()))
243 result = new std::string("Error executing command '" + command + "'");
251 modelCDMFile* header = NULL;
252 modelCDMFile* source = NULL;
253 wxDir dir(crea::std2wx(path));
257 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
260 std::string stdfileName = crea::wx2std(fileName);
261 header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
263 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
266 std::string stdfileName = crea::wx2std(fileName);
267 source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
270 //if source and header exist
273 if (header != NULL && source != NULL)
276 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
278 //associate header and source
279 blackBox->SetHeaderFile(header);
280 blackBox->SetSourceFile(source);
282 this->children.push_back(header);
283 this->children.push_back(source);
285 this->blackBoxes.push_back(blackBox);
288 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
289 this->SortChildren();
295 result = new std::string("The header and source files were not found. Black box not created.");
300 const bool modelCDMPackageSrc::Refresh(std::string*& result)
302 std::cout << "refreshing package src" << std::endl;
304 this->type = wxDIR_DIRS;
307 std::vector<bool> checked(this->children.size(), false);
308 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
311 wxDir dir(crea::std2wx((this->path).c_str()));
315 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
318 std::string stdfileName = crea::wx2std(fileName);
319 std::string folderName = stdfileName;
320 //check if they already exist
322 for (int i = 0; !found && i < (int)(this->children.size()); i++)
324 if (this->children[i]->GetName() == folderName)
328 if(!this->children[i]->Refresh(result))
334 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
335 this->children.push_back(folder);
337 cont = dir.GetNext(&fileName);
340 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
343 std::string stdfileName = crea::wx2std(fileName);
344 std::size_t fileTypePos = stdfileName.find_last_of(".");
345 std::string fileType;
346 if(fileTypePos != std::string::npos)
347 fileType = stdfileName.substr(fileTypePos);
351 //if CMakeLists, create CMakeLists
352 if(stdfileName == "CMakeLists.txt")
354 if (this->CMakeLists == NULL)
356 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
357 this->children.push_back(this->CMakeLists);
361 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
363 if(!this->CMakeLists->Refresh(result))
367 //if is an unknown file, create file
371 for (int i = 0; !found && i < (int)(this->children.size()); i++)
373 if (this->children[i]->GetName() == stdfileName)
377 if(!this->children[i]->Refresh(result))
384 //if is a code file, create modelCDMCodeFile
387 fileType == ".cxx" ||
389 fileType == ".cpp" ||
390 fileType == ".txx" ||
391 fileType == ".cmake" )
393 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
397 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
398 this->children.push_back(file);
403 //if is a Black Box header, check in black boxes
404 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
407 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
409 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
411 checkedBoxes[i] = true;
413 if(!this->blackBoxes[i]->Refresh(result))
421 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
422 this->blackBoxes.push_back(blackBox);
427 cont = dir.GetNext(&fileName);
431 for (int i = 0; i < (int)(checkedBoxes.size()); i++)
435 delete this->blackBoxes[i];
436 this->blackBoxes.erase(this->blackBoxes.begin()+i);
437 checkedBoxes.erase(checkedBoxes.begin()+i);
442 for (int i = 0; i < (int)(checked.size()); i++)
446 delete this->children[i];
447 this->children.erase(this->children.begin()+i);
448 checked.erase(checked.begin()+i);
452 this->SortChildren();
453 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);