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(".");
92 std::string fileType = stdfileName.substr(fileTypePos);
93 modelCDMCodeFile* file;
95 if(stdfileName.substr(0,2) == "bb")
97 file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
98 this->children.push_back(file);
99 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
100 blackBox->SetHeaderFile(file);
101 wxDir dir2(crea::std2wx(path));
102 cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
105 file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
106 this->children.push_back(file);
107 blackBox->SetSourceFile(file);
109 this->blackBoxes.push_back(blackBox);
111 cont = dir.GetNext(&fileName);
115 this->SortChildren();
116 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
119 modelCDMPackageSrc::~modelCDMPackageSrc()
121 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
123 if(this->blackBoxes[i] != NULL)
125 delete this->blackBoxes[i];
126 this->blackBoxes[i] = NULL;
129 this->blackBoxes.clear();
132 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
134 return this->blackBoxes;
137 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
138 std::string*& result,
139 const std::string& name,
140 const std::string& package,
141 const std::string& type,
142 const std::string& format,
143 const std::string& categories,
144 const std::string& authors,
145 const std::string& authorsEmail,
146 const std::string& description)
149 std::vector<std::string> words;
150 CDMUtilities::splitter::split(words, name, " \n\",/\\'", CDMUtilities::splitter::no_empties);
152 for (int i = 0; i < (int)(words.size()); i++)
158 CDMUtilities::splitter::split(words, categories, " \n\",/\\'", CDMUtilities::splitter::no_empties);
159 std::string bbCategories;
162 bbCategories = words[0];
163 for (int i = 1; i < (int)(words.size()); i++)
165 bbCategories += "," + words[i];
168 if(bbCategories == "")
169 bbCategories = "empty";
172 CDMUtilities::splitter::split(words, authors, "\n\",/\\'", CDMUtilities::splitter::no_empties);
173 std::string bbAuthors;
176 bbAuthors = words[0];
177 for (int i = 1; i < (int)(words.size()); i++)
179 bbAuthors += "," + words[i];
183 bbAuthors = "Unknown";
186 CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\'", CDMUtilities::splitter::no_empties);
187 std::string bbDescription;
190 bbDescription = words[0];
191 for (int i = 1; i < (int)(words.size()); i++)
193 bbDescription += "," + words[i];
195 bbDescription += " - ";
197 CDMUtilities::splitter::split(words, description, "\n\"/\\'", CDMUtilities::splitter::no_empties);
200 bbDescription += words[0];
201 for (int i = 1; i < (int)(words.size()); i++)
203 bbDescription += words[i];
207 if(bbDescription == "")
208 bbDescription = "No Description.";
212 std::string command = "bbCreateBlackBox";
213 command += " \"" + this->path + "\"";
215 command += " " + package;
216 command += " " + bbName;
217 command += " " + type;
218 command += " " + format;
220 command += " \"" + package + "\"";
221 command += " \"" + bbName + "\"";
222 command += " \"" + type + "\"";
223 command += " \"" + format + "\"";
225 command += " \"" + bbAuthors + "\"";
226 command += " \"" + bbDescription + "\"";
227 command += " \"" + bbCategories + "\"";
230 //wxMessageBox(crea::std2wx("Command: ->" + command + "<-"),_T("Creating Black Box"),wxOK | wxICON_INFORMATION);
231 if(system(command.c_str()))
233 result = new std::string("Error executing command '" + command + "'");
241 modelCDMFile* header = NULL;
242 modelCDMFile* source = NULL;
243 wxDir dir(crea::std2wx(path));
247 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
250 std::string stdfileName = crea::wx2std(fileName);
251 header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
253 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
256 std::string stdfileName = crea::wx2std(fileName);
257 source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
260 //if source and header exist
261 if (header != NULL && source != NULL)
264 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
266 //associate header and source
267 blackBox->SetHeaderFile(header);
268 blackBox->SetSourceFile(source);
270 this->children.push_back(header);
271 this->children.push_back(source);
273 this->blackBoxes.push_back(blackBox);
276 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
277 this->SortChildren();
283 result = new std::string("The header and source files were not found. Black box not created.");
288 const bool modelCDMPackageSrc::Refresh(std::string*& result)
290 std::cout << "refreshing package src" << std::endl;
292 this->type = wxDIR_DIRS;
295 std::vector<bool> checked(this->children.size(), false);
296 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
299 wxDir dir(crea::std2wx((this->path).c_str()));
303 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
306 std::string stdfileName = crea::wx2std(fileName);
307 std::string folderName = stdfileName;
308 //check if they already exist
310 for (int i = 0; !found && i < (int)(this->children.size()); i++)
312 if (this->children[i]->GetName() == folderName)
316 if(!this->children[i]->Refresh(result))
322 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
323 this->children.push_back(folder);
325 cont = dir.GetNext(&fileName);
328 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
331 std::string stdfileName = crea::wx2std(fileName);
332 std::size_t fileTypePos = stdfileName.find_last_of(".");
333 std::string fileType = stdfileName.substr(fileTypePos);
335 //if CMakeLists, create CMakeLists
336 if(stdfileName == "CMakeLists.txt")
338 if (this->CMakeLists == NULL)
340 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
341 this->children.push_back(this->CMakeLists);
345 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
347 if(!this->CMakeLists->Refresh(result))
351 //if is an unknown file, create file
355 for (int i = 0; !found && i < (int)(this->children.size()); i++)
357 if (this->children[i]->GetName() == stdfileName)
361 if(!this->children[i]->Refresh(result))
368 //if is a code file, create modelCDMCodeFile
371 fileType == ".cxx" ||
373 fileType == ".cpp" ||
374 fileType == ".txx" ||
375 fileType == ".cmake" )
377 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
381 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
382 this->children.push_back(file);
387 //if is a Black Box header, check in black boxes
388 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
391 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
393 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
395 checkedBoxes[i] = true;
397 if(!this->blackBoxes[i]->Refresh(result))
405 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
406 this->blackBoxes.push_back(blackBox);
411 cont = dir.GetNext(&fileName);
415 for (int i = 0; i < (int)(checkedBoxes.size()); i++)
419 delete this->blackBoxes[i];
420 this->blackBoxes.erase(this->blackBoxes.begin()+i);
421 checkedBoxes.erase(checkedBoxes.begin()+i);
426 for (int i = 0; i < (int)(checked.size()); i++)
430 delete this->children[i];
431 this->children.erase(this->children.begin()+i);
432 checked.erase(checked.begin()+i);
436 this->SortChildren();
437 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);