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: 13/11/2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMProject.h"
42 #include "CDMUtilities.h"
46 modelCDMProject::modelCDMProject()
48 std::cout << "in constructor1" << std::endl;
51 this->CMakeLists = NULL;
54 modelCDMProject::modelCDMProject(
55 const std::string& path,
56 const std::string& buildPath
59 this->path = CDMUtilities::fixPath(path);
61 std::string pathFixed(CDMUtilities::fixPath(path));
63 //TODO: set pathMakeLists for windows
64 std::string pathMakeLists = pathFixed + "/CMakeLists.txt";
66 std::ifstream confFile;
67 confFile.open((pathMakeLists).c_str());
70 while(confFile.is_open() && !confFile.eof())
72 //std::cout << "leyendo " << word << std::endl;
74 std::getline(confFile,word,'(');
75 std::vector<std::string> wordBits;
76 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
78 if(wordBits[wordBits.size()-1] == "PROJECT")
80 std::getline(confFile,word,')');
81 std::vector<std::string> nameBits;
82 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
84 this->name = this->nameProject = "";
85 for (int i = 0; i < nameBits.size(); i++)
89 this->name += nameBits[i];
91 this->nameProject = this->name;
96 if(wordBits[wordBits.size()-1] == "SET")
99 std::getline(confFile,word,')');
100 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
101 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
103 version = wordBits[1];
105 if(wordBits[0] == "PROJECT_MINOR_VERSION")
107 version += "." + wordBits[1];
109 if(wordBits[0] == "PROJECT_BUILD_VERSION")
111 version += "." + wordBits[1];
114 //get project versionDate
115 if(wordBits[0] == "PROJECT_VERSION_DATE")
117 std::vector<std::string> versionBits;
118 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
119 versionDate = versionBits[0];
121 //get project buildPath
125 this->buildPath = buildPath;
129 this->buildPath = this->path + "Bin";
135 this->type = wxDIR_DIRS;
138 this->children.clear();
141 this->packages.clear();
145 wxDir dir(crea::std2wx((pathFixed).c_str()));
149 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
152 std::string stdfileName = crea::wx2std(fileName);
154 //if appli, create appli
155 if(stdfileName == "appli")
157 this->appli = new modelCDMAppli(pathFixed + "/appli", this->level + 1);
158 this->children.push_back(this->appli);
161 else if(stdfileName == "lib")
163 this->lib = new modelCDMLib(pathFixed + "/lib", this->level + 1);
164 this->children.push_back(this->lib);
166 //if package , create package
167 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
169 modelCDMPackage* package = new modelCDMPackage(pathFixed + "/" + stdfileName, this->level + 1);
170 this->packages.push_back(package);
171 this->children.push_back(package);
173 //if is an unknown folder, create folder
176 this->children.push_back(new modelCDMFolder(pathFixed + "/" + stdfileName, this->level + 1));
179 cont = dir.GetNext(&fileName);
182 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
185 std::string stdfileName = crea::wx2std(fileName);
187 //if CMakeLists, create CMakeLists
188 if(stdfileName == "CMakeLists.txt")
190 this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + "/" + stdfileName, this->level + 1);
191 this->children.push_back(this->CMakeLists);
195 this->children.push_back(new modelCDMFile(pathFixed + "/" + stdfileName, this->level + 1));
197 //if is an unknown file, create file
198 cont = dir.GetNext(&fileName);
202 this->SortChildren();
206 modelCDMProject::~modelCDMProject()
210 const std::string& modelCDMProject::GetNameProject() const
212 return this->nameProject;
215 const std::string& modelCDMProject::GetVersion() const
217 return this->version;
220 const std::string& modelCDMProject::GetVersionDate() const
222 return this->versionDate;
225 const std::string& modelCDMProject::GetBuildPath() const
227 return this->buildPath;
230 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
232 //TODO: implement method
236 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
238 //TODO: implement method
242 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
243 const std::string& name,
244 std::string*& result,
245 const std::string& authors,
246 const std::string& authorsEmail,
247 const std::string& version,
248 const std::string& description
251 //TODO: implement method
255 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
256 const std::string& name,
257 std::string*& result,
258 const std::string& path
261 if(this->lib != NULL)
263 return this->lib->CreateLibrary(name, result);
265 result = new std::string("there is no lib folder in this project.");
269 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
270 const std::string& name,
271 std::string*& result,
272 const std::string& path
275 //TODO: implement method
279 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
280 const std::string& name,
281 const std::string& package,
282 const std::string& authors,
283 const std::string& authorsEmail,
284 const std::string& categories,
285 const std::string& description
288 //TODO: implement method
292 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
294 //TODO: implement method
298 const bool modelCDMProject::Refresh(std::string*& result)
300 std::cout << "refreshing project" << std::endl;
301 //open makelists file
302 //TODO: set pathMakeLists for windows
303 std::string pathMakeLists = this->path + "/CMakeLists.txt";
305 std::ifstream confFile;
306 confFile.open((pathMakeLists).c_str());
309 while(confFile.is_open() && !confFile.eof())
311 //std::cout << "leyendo " << word << std::endl;
313 std::getline(confFile,word,'(');
314 std::vector<std::string> wordBits;
315 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
317 if(wordBits[wordBits.size()-1] == "PROJECT")
319 std::getline(confFile,word,')');
320 std::vector<std::string> nameBits;
321 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
323 this->name = this->nameProject = "";
324 for (int i = 0; i < nameBits.size(); i++)
328 this->name += nameBits[i];
330 this->nameProject = this->name;
335 if(wordBits[wordBits.size()-1] == "SET")
337 //get project version
338 std::getline(confFile,word,')');
339 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
340 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
342 version = wordBits[1];
344 if(wordBits[0] == "PROJECT_MINOR_VERSION")
346 version += "." + wordBits[1];
348 if(wordBits[0] == "PROJECT_BUILD_VERSION")
350 version += "." + wordBits[1];
353 //get project versionDate
354 if(wordBits[0] == "PROJECT_VERSION_DATE")
356 std::vector<std::string> versionBits;
357 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
358 versionDate = versionBits[0];
364 this->type = wxDIR_DIRS;
367 std::vector<bool> checked(this->children.size(), false);
368 std::vector<bool> checkedPackages(this->packages.size(), false);
371 wxDir dir(crea::std2wx((this->path).c_str()));
375 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
378 std::string stdfileName = crea::wx2std(fileName);
380 //if appli, create appli
381 if(stdfileName == "appli")
383 if (this->appli == NULL)
385 this->appli = new modelCDMAppli(this->path + "/appli", this->level + 1);
386 this->children.push_back(this->appli);
390 int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
392 if(!this->appli->Refresh(result))
397 else if(stdfileName == "lib")
399 if (this->lib == NULL)
401 this->lib = new modelCDMLib(this->path + "/lib", this->level + 1);
402 this->children.push_back(this->lib);
406 int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
408 if(!this->lib->Refresh(result))
413 //if package , create package
414 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
416 std::string packageName = stdfileName.substr(5, stdfileName.size()-9);
418 for (int i = 0;!found && i < this->packages.size(); i++)
420 if (this->packages[i]->GetName() == packageName)
423 int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
425 checkedPackages[i] = true;
426 if(!this->packages[i]->Refresh(result))
432 modelCDMPackage* package = new modelCDMPackage(this->path + "/" + stdfileName, this->level + 1);
433 this->packages.push_back(package);
434 this->children.push_back(package);
438 //if is an unknown folder, create folder
442 for (int i = 0; !found && i < this->children.size(); i++)
444 if (this->children[i]->GetName() == stdfileName)
448 if(!this->children[i]->Refresh(result))
455 modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
456 this->children.push_back(folder);
460 cont = dir.GetNext(&fileName);
463 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
466 std::string stdfileName = crea::wx2std(fileName);
468 //if CMakeLists, create CMakeLists
469 if(stdfileName == "CMakeLists.txt")
471 if (this->CMakeLists == NULL)
473 this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
474 this->children.push_back(this->CMakeLists);
478 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
480 if(!this->CMakeLists->Refresh(result))
484 //if is an unknown file, create file
488 for (int i = 0; i <!found && this->children.size(); i++)
490 if (this->children[i]->GetName() == stdfileName)
494 if(!this->children[i]->Refresh(result))
501 modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
502 this->children.push_back(file);
506 cont = dir.GetNext(&fileName);
510 for (int i = 0; i < checkedPackages.size(); i++)
512 if(!checkedPackages[i])
514 this->packages.erase(this->packages.begin()+i);
515 checkedPackages.erase(checkedPackages.begin()+i);
519 for (int i = 0; i < checked.size(); i++)
523 delete this->children[i];
524 this->children.erase(this->children.begin()+i);
525 checked.erase(checked.begin()+i);
529 this->SortChildren();
533 bool modelCDMProject::ConfigureBuild(std::string*& result)
535 //TODO: implement method
539 bool modelCDMProject::Build(std::string*& result)
541 //TODO: implement method
545 bool modelCDMProject::Connect(std::string*& result)
547 //TODO: implement method