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);
93 if(stdfileName.substr(0,2) == "bb")
95 file = new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
96 this->children.push_back(file);
97 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
98 blackBox->SetHeaderFile(file);
99 wxDir dir2(crea::std2wx(path));
100 cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
103 file = new modelCDMFile(this, path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
104 this->children.push_back(file);
105 blackBox->SetSourceFile(file);
107 this->blackBoxes.push_back(blackBox);
109 cont = dir.GetNext(&fileName);
113 this->SortChildren();
114 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
117 modelCDMPackageSrc::~modelCDMPackageSrc()
119 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
121 if(this->blackBoxes[i] != NULL)
123 delete this->blackBoxes[i];
124 this->blackBoxes[i] = NULL;
127 this->blackBoxes.clear();
130 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
132 return this->blackBoxes;
135 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
136 std::string*& result,
137 const std::string& name,
138 const std::string& package,
139 const std::string& type,
140 const std::string& format,
141 const std::string& categories,
142 const std::string& authors,
143 const std::string& authorsEmail,
144 const std::string& description)
147 std::vector<std::string> words;
148 CDMUtilities::splitter::split(words, name, " \n\",/\\'", CDMUtilities::splitter::no_empties);
150 for (int i = 0; i < (int)(words.size()); i++)
156 CDMUtilities::splitter::split(words, categories, " \n\",/\\'", CDMUtilities::splitter::no_empties);
157 std::string bbCategories;
160 bbCategories = words[0];
161 for (int i = 1; i < (int)(words.size()); i++)
163 bbCategories += "," + words[i];
166 if(bbCategories == "")
167 bbCategories = "empty";
170 CDMUtilities::splitter::split(words, authors, "\n\",/\\'", CDMUtilities::splitter::no_empties);
171 std::string bbAuthors;
174 bbAuthors = words[0];
175 for (int i = 1; i < (int)(words.size()); i++)
177 bbAuthors += "," + words[i];
181 bbAuthors = "Unknown";
184 CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\'", CDMUtilities::splitter::no_empties);
185 std::string bbDescription;
188 bbDescription = words[0];
189 for (int i = 1; i < (int)(words.size()); i++)
191 bbDescription += "," + words[i];
193 bbDescription += " - ";
195 CDMUtilities::splitter::split(words, description, "\n\"/\\'", CDMUtilities::splitter::no_empties);
198 bbDescription += words[0];
199 for (int i = 1; i < (int)(words.size()); i++)
201 bbDescription += words[i];
205 if(bbDescription == "")
206 bbDescription = "No Description.";
210 std::string command = "bbCreateBlackBox";
211 command += " \"" + this->path + "\"";
213 command += " " + package;
214 command += " " + bbName;
215 command += " " + type;
216 command += " " + format;
218 command += " \"" + package + "\"";
219 command += " \"" + bbName + "\"";
220 command += " \"" + type + "\"";
221 command += " \"" + format + "\"";
223 command += " \"" + bbAuthors + "\"";
224 command += " \"" + bbDescription + "\"";
225 command += " \"" + bbCategories + "\"";
228 if(system(command.c_str()))
230 result = new std::string("Error executing command '" + command + "'");
238 modelCDMFile* header = NULL;
239 modelCDMFile* source = NULL;
240 wxDir dir(crea::std2wx(path));
244 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
247 std::string stdfileName = crea::wx2std(fileName);
248 header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
250 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
253 std::string stdfileName = crea::wx2std(fileName);
254 source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
257 //if source and header exist
258 if (header != NULL && source != NULL)
261 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
263 //associate header and source
264 blackBox->SetHeaderFile(header);
265 blackBox->SetSourceFile(source);
267 this->children.push_back(header);
268 this->children.push_back(source);
270 this->blackBoxes.push_back(blackBox);
273 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
274 this->SortChildren();
280 result = new std::string("The header and source files were not found. Black box not created.");
285 const bool modelCDMPackageSrc::Refresh(std::string*& result)
287 std::cout << "refreshing package src" << std::endl;
289 this->type = wxDIR_DIRS;
292 std::vector<bool> checked(this->children.size(), false);
293 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
296 wxDir dir(crea::std2wx((this->path).c_str()));
300 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
303 std::string stdfileName = crea::wx2std(fileName);
304 std::string folderName = stdfileName;
305 //check if they already exist
307 for (int i = 0; !found && i < (int)(this->children.size()); i++)
309 if (this->children[i]->GetName() == folderName)
313 if(!this->children[i]->Refresh(result))
319 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
320 this->children.push_back(folder);
322 cont = dir.GetNext(&fileName);
325 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
328 std::string stdfileName = crea::wx2std(fileName);
330 //if CMakeLists, create CMakeLists
331 if(stdfileName == "CMakeLists.txt")
333 if (this->CMakeLists == NULL)
335 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
336 this->children.push_back(this->CMakeLists);
340 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
342 if(!this->CMakeLists->Refresh(result))
346 //if is an unknown file, create file
350 for (int i = 0; !found && i < (int)(this->children.size()); i++)
352 if (this->children[i]->GetName() == stdfileName)
356 if(!this->children[i]->Refresh(result))
363 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
364 this->children.push_back(file);
368 //if is a Black Box header, check in black boxes
369 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
372 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
374 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
376 checkedBoxes[i] = true;
378 if(!this->blackBoxes[i]->Refresh(result))
386 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
387 this->blackBoxes.push_back(blackBox);
392 cont = dir.GetNext(&fileName);
396 for (int i = 0; i < (int)(checkedBoxes.size()); i++)
400 delete this->blackBoxes[i];
401 this->blackBoxes.erase(this->blackBoxes.begin()+i);
402 checkedBoxes.erase(checkedBoxes.begin()+i);
407 for (int i = 0; i < (int)(checked.size()); i++)
411 delete this->children[i];
412 this->children.erase(this->children.begin()+i);
413 checked.erase(checked.begin()+i);
417 this->SortChildren();
418 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);