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(const std::string& path, const std::string& name, const int& level)
53 this->children.clear();
55 this->CMakeLists = NULL;
58 this->path = CDMUtilities::fixPath(path);
59 this->type = wxDIR_DIRS;
62 wxDir dir(crea::std2wx(path));
66 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
69 std::string stdfileName = crea::wx2std(fileName);
71 //if is an unknown folder, create folder
72 this->children.push_back(new modelCDMFolder(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
74 cont = dir.GetNext(&fileName);
77 cont = dir.GetFirst(&fileName, wxT("CMakeLists.txt"), wxDIR_FILES);
80 std::string stdfileName = crea::wx2std(fileName);
81 this->CMakeLists = new modelCDMCMakeListsFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
82 this->children.push_back(this->CMakeLists);
85 cont = dir.GetFirst(&fileName, wxT("*.h"), wxDIR_FILES);
88 std::string stdfileName = crea::wx2std(fileName);
91 if(stdfileName.substr(0,2) == "bb")
93 file = new modelCDMFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
94 this->children.push_back(file);
95 modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
96 blackBox->SetHeaderFile(file);
97 wxDir dir2(crea::std2wx(path));
98 cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
101 file = new modelCDMFile(path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
102 this->children.push_back(file);
103 blackBox->SetSourceFile(file);
105 this->blackBoxes.push_back(blackBox);
107 cont = dir.GetNext(&fileName);
111 this->SortChildren();
114 modelCDMPackageSrc::~modelCDMPackageSrc()
116 for (int i = 0; i < this->blackBoxes.size(); i++)
118 if(this->blackBoxes[i] != NULL)
120 delete this->blackBoxes[i];
121 this->blackBoxes[i] = NULL;
124 this->blackBoxes.clear();
127 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
129 return this->blackBoxes;
132 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
133 const std::string& name,
134 const std::string& package,
135 const std::string& type,
136 const std::string& format,
137 const std::string& authors,
138 const std::string& authorsEmail,
139 const std::string& categories,
140 const std::string& description)
142 //TODO: implement method
146 const bool modelCDMPackageSrc::Refresh(std::string*& result)
149 this->type = wxDIR_DIRS;
152 std::vector<bool> checked(this->children.size(), false);
153 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
156 wxDir dir(crea::std2wx((this->path).c_str()));
160 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
163 std::string stdfileName = crea::wx2std(fileName);
164 std::string folderName = stdfileName;
165 //check if they already exist
167 for (int i = 0;!found && i < this->children.size(); i++)
169 if (this->children[i]->GetName() == folderName)
173 if(!this->children[i]->Refresh(result))
179 modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
180 this->children.push_back(folder);
182 cont = dir.GetNext(&fileName);
185 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
188 std::string stdfileName = crea::wx2std(fileName);
190 //if CMakeLists, create CMakeLists
191 if(stdfileName == "CMakeLists.txt")
193 if (this->CMakeLists == NULL)
195 this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
196 this->children.push_back(this->CMakeLists);
200 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
202 if(!this->CMakeLists->Refresh(result))
206 //if is an unknown file, create file
210 for (int i = 0; i <!found && this->children.size(); i++)
212 if (this->children[i]->GetName() == stdfileName)
216 if(!this->children[i]->Refresh(result))
223 modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
224 this->children.push_back(file);
228 //if is a Black Box header, check in black boxes
229 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
232 for (int i = 0; i < this->blackBoxes.size(); i++)
234 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
236 checkedBoxes[i] = true;
238 if(!this->blackBoxes[i]->Refresh(result))
246 modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
247 this->blackBoxes.push_back(blackBox);
252 cont = dir.GetNext(&fileName);
256 for (int i = 0; i < checkedBoxes.size(); i++)
260 delete this->blackBoxes[i];
261 this->blackBoxes.erase(this->blackBoxes.begin()+i);
262 checkedBoxes.erase(checkedBoxes.begin()+i);
267 for (int i = 0; i < checked.size(); i++)
271 delete this->children[i];
272 this->children.erase(this->children.begin()+i);
273 checked.erase(checked.begin()+i);
277 this->SortChildren();