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 < 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 < 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 < 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 < 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 < 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 < words.size(); i++)
201 bbDescription += words[i];
205 if(bbDescription == "")
206 bbDescription = "No Description.";
210 std::string command = "bbCreateBlackBox";
211 command += " \"" + this->path + "\"";
212 command += " \"" + package + "\"";
213 command += " \"" + bbName + "\"";
214 command += " \"" + type + "\"";
215 command += " \"" + format + "\"";
216 command += " \"" + bbAuthors + "\"";
217 command += " \"" + bbDescription + "\"";
218 command += " \"" + bbCategories + "\"";
221 if(system(command.c_str()))
223 result = new std::string("Error executing command '" + command + "'");
231 modelCDMFile* header = NULL;
232 modelCDMFile* source = NULL;
233 wxDir dir(crea::std2wx(path));
237 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
240 std::string stdfileName = crea::wx2std(fileName);
241 header = new modelCDMFile(this, this->path + stdfileName, stdfileName, this->level+1);
243 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
246 std::string stdfileName = crea::wx2std(fileName);
247 source = new modelCDMFile(this, this->path + stdfileName, stdfileName, this->level+1);
250 //if source and header exist
251 if (header != NULL && source != NULL)
254 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
256 //associate header and source
257 blackBox->SetHeaderFile(header);
258 blackBox->SetSourceFile(source);
260 this->children.push_back(header);
261 this->children.push_back(source);
263 this->blackBoxes.push_back(blackBox);
266 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
267 this->SortChildren();
273 result = new std::string("The header and source files were not found. Black box not created.");
278 const bool modelCDMPackageSrc::Refresh(std::string*& result)
280 std::cout << "refreshing package src" << std::endl;
282 this->type = wxDIR_DIRS;
285 std::vector<bool> checked(this->children.size(), false);
286 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
289 wxDir dir(crea::std2wx((this->path).c_str()));
293 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
296 std::string stdfileName = crea::wx2std(fileName);
297 std::string folderName = stdfileName;
298 //check if they already exist
300 for (int i = 0; !found && i < this->children.size(); i++)
302 if (this->children[i]->GetName() == folderName)
306 if(!this->children[i]->Refresh(result))
312 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
313 this->children.push_back(folder);
315 cont = dir.GetNext(&fileName);
318 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
321 std::string stdfileName = crea::wx2std(fileName);
323 //if CMakeLists, create CMakeLists
324 if(stdfileName == "CMakeLists.txt")
326 if (this->CMakeLists == NULL)
328 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
329 this->children.push_back(this->CMakeLists);
333 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
335 if(!this->CMakeLists->Refresh(result))
339 //if is an unknown file, create file
343 for (int i = 0; !found && i < this->children.size(); i++)
345 if (this->children[i]->GetName() == stdfileName)
349 if(!this->children[i]->Refresh(result))
356 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
357 this->children.push_back(file);
361 //if is a Black Box header, check in black boxes
362 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
365 for (int i = 0; i < this->blackBoxes.size(); i++)
367 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
369 checkedBoxes[i] = true;
371 if(!this->blackBoxes[i]->Refresh(result))
379 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
380 this->blackBoxes.push_back(blackBox);
385 cont = dir.GetNext(&fileName);
389 for (int i = 0; i < checkedBoxes.size(); i++)
393 delete this->blackBoxes[i];
394 this->blackBoxes.erase(this->blackBoxes.begin()+i);
395 checkedBoxes.erase(checkedBoxes.begin()+i);
400 for (int i = 0; i < checked.size(); i++)
404 delete this->children[i];
405 this->children.erase(this->children.begin()+i);
406 checked.erase(checked.begin()+i);
410 this->SortChildren();
411 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);