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 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 + "/" + 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 + "/" + 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 + "/" + stdfileName, this->level + 1);
94 this->children.push_back(file);
95 modelCDMBlackBox* blackBox = new modelCDMBlackBox(stdfileName, path, level + 1);
96 blackBox->SetHeaderFile(file);
97 cont = dir.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
100 file = new modelCDMFile(path + "/" + crea::wx2std(fileName), this->level + 1);
101 this->children.push_back(file);
102 blackBox->SetSourceFile(file);
104 this->blackBoxes.push_back(blackBox);
106 cont = dir.GetNext(&fileName);
110 this->SortChildren();
113 modelCDMPackageSrc::~modelCDMPackageSrc()
115 for (int i = 0; i < this->blackBoxes.size(); i++)
117 if(this->blackBoxes[i] != NULL)
119 delete this->blackBoxes[i];
120 this->blackBoxes[i] = NULL;
123 this->blackBoxes.clear();
126 const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
128 return this->blackBoxes;
131 const bool modelCDMPackageSrc::Refresh(std::string*& result)
134 this->type = wxDIR_DIRS;
137 std::vector<bool> checked(this->children.size(), false);
138 std::vector<bool> checkedBoxes(this->blackBoxes.size(), false);
141 wxDir dir(crea::std2wx((this->path).c_str()));
145 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
148 std::string stdfileName = crea::wx2std(fileName);
149 std::string folderName = stdfileName;
150 //check if they already exist
152 for (int i = 0;!found && i < this->children.size(); i++)
154 if (this->children[i]->GetName() == folderName)
158 if(!this->children[i]->Refresh(result))
164 modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
165 this->children.push_back(folder);
167 cont = dir.GetNext(&fileName);
170 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
173 std::string stdfileName = crea::wx2std(fileName);
175 //if CMakeLists, create CMakeLists
176 if(stdfileName == "CMakeLists.txt")
178 if (this->CMakeLists == NULL)
180 this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
181 this->children.push_back(this->CMakeLists);
185 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
187 if(!this->CMakeLists->Refresh(result))
191 //if is an unknown file, create file
195 for (int i = 0; i <!found && this->children.size(); i++)
197 if (this->children[i]->GetName() == stdfileName)
201 if(!this->children[i]->Refresh(result))
208 modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
209 this->children.push_back(file);
213 //if is a Black Box header, check in black boxes
214 if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
217 for (int i = 0; i < this->blackBoxes.size(); i++)
219 if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
221 checkedBoxes[i] = true;
223 if(!this->blackBoxes[i]->Refresh(result))
231 modelCDMBlackBox* blackBox = new modelCDMBlackBox(stdfileName, path + "/" + stdfileName, level + 1);
232 this->blackBoxes.push_back(blackBox);
237 cont = dir.GetNext(&fileName);
241 for (int i = 0; i < checkedBoxes.size(); i++)
245 delete this->blackBoxes[i];
246 this->blackBoxes.erase(this->blackBoxes.begin()+i);
247 checkedBoxes.erase(checkedBoxes.begin()+i);
252 for (int i = 0; i < checked.size(); i++)
256 delete this->children[i];
257 this->children.erase(this->children.begin()+i);
258 checked.erase(checked.begin()+i);
262 this->SortChildren();