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 //wxMessageBox(crea::std2wx("Command: ->" + command + "<-"),_T("Creating Black Box"),wxOK | wxICON_INFORMATION);
229 if(system(command.c_str()))
231 result = new std::string("Error executing command '" + command + "'");
239 modelCDMFile* header = NULL;
240 modelCDMFile* source = NULL;
241 wxDir dir(crea::std2wx(path));
245 bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
248 std::string stdfileName = crea::wx2std(fileName);
249 header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
251 cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
254 std::string stdfileName = crea::wx2std(fileName);
255 source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
258 //if source and header exist
259 if (header != NULL && source != NULL)
262 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
264 //associate header and source
265 blackBox->SetHeaderFile(header);
266 blackBox->SetSourceFile(source);
268 this->children.push_back(header);
269 this->children.push_back(source);
271 this->blackBoxes.push_back(blackBox);
274 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
275 this->SortChildren();
281 result = new std::string("The header and source files were not found. Black box not created.");
286 const bool modelCDMPackageSrc::Refresh(std::string*& result)
288 std::cout << "refreshing package src" << std::endl;
290 this->type = wxDIR_DIRS;
293 std::vector<bool> checked(this->children.size(), false);
294 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
297 wxDir dir(crea::std2wx((this->path).c_str()));
301 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
304 std::string stdfileName = crea::wx2std(fileName);
305 std::string folderName = stdfileName;
306 //check if they already exist
308 for (int i = 0; !found && i < (int)(this->children.size()); i++)
310 if (this->children[i]->GetName() == folderName)
314 if(!this->children[i]->Refresh(result))
320 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
321 this->children.push_back(folder);
323 cont = dir.GetNext(&fileName);
326 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
329 std::string stdfileName = crea::wx2std(fileName);
331 //if CMakeLists, create CMakeLists
332 if(stdfileName == "CMakeLists.txt")
334 if (this->CMakeLists == NULL)
336 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
337 this->children.push_back(this->CMakeLists);
341 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
343 if(!this->CMakeLists->Refresh(result))
347 //if is an unknown file, create file
351 for (int i = 0; !found && i < (int)(this->children.size()); i++)
353 if (this->children[i]->GetName() == stdfileName)
357 if(!this->children[i]->Refresh(result))
364 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
365 this->children.push_back(file);
369 //if is a Black Box header, check in black boxes
370 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
373 for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
375 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
377 checkedBoxes[i] = true;
379 if(!this->blackBoxes[i]->Refresh(result))
387 modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
388 this->blackBoxes.push_back(blackBox);
393 cont = dir.GetNext(&fileName);
397 for (int i = 0; i < (int)(checkedBoxes.size()); i++)
401 delete this->blackBoxes[i];
402 this->blackBoxes.erase(this->blackBoxes.begin()+i);
403 checkedBoxes.erase(checkedBoxes.begin()+i);
408 for (int i = 0; i < (int)(checked.size()); i++)
412 delete this->children[i];
413 this->children.erase(this->children.begin()+i);
414 checked.erase(checked.begin()+i);
418 this->SortChildren();
419 std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);