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 const std::vector<modelCDMPackage*>& modelCDMProject::GetPackages() const
232 return this->packages;
235 modelCDMAppli* modelCDMProject::GetAppli() const
240 modelCDMLib* modelCDMProject::GetLib() const
245 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
247 //TODO: implement method
251 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
253 //TODO: implement method
257 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
258 const std::string& name,
259 std::string*& result,
260 const std::string& authors,
261 const std::string& authorsEmail,
262 const std::string& description,
263 const std::string& version
266 //fixing input parameters
267 std::vector<std::string> words;
269 CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
270 std::string nameFixed = "";
271 for (int i = 0; i < words.size(); i++)
273 nameFixed += words[i];
277 CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
278 std::string authorFixed;
279 for (int i = 0; i < words.size(); i++)
281 authorFixed += words[i];
285 std::string descriptionFixed;
286 CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
287 for (int i = 0; i < words.size(); i++)
289 descriptionFixed += words[i];
292 CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
293 for (int i = 0; i < words.size(); i++)
295 descriptionFixed += "_" + words[i];
298 //call project to create package : use bbCreatePackage <path> <name> [author] [description]
299 std::string creationCommand = "bbCreatePackage \"" + this->path + "\" " + nameFixed + " " + authorFixed + " " + descriptionFixed;
300 //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
301 if(system(creationCommand.c_str()))
303 result = new std::string("An error occurred while running '" + creationCommand + "'.");
307 //add library to model
308 //TODO: fix for windows
309 modelCDMPackage* package = new modelCDMPackage(this->path + "/bbtk_" + nameFixed + "_PKG", this->level + 1);
310 this->packages.push_back(package);
311 this->children.push_back(package);
313 //TODO: set package version
315 this->SortChildren();
317 result = new std::string(this->path + "/" + name);
321 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
322 const std::string& name,
323 std::string*& result,
324 const std::string& path
327 if(this->lib != NULL)
329 return this->lib->CreateLibrary(name, result);
331 result = new std::string("there is no lib folder in this project.");
335 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
336 const std::string& name,
337 std::string*& result,
338 const std::string& path
341 if(this->appli != NULL)
343 return this->appli->CreateApplication(name, result);
345 result = new std::string("there is no appli folder in this project.");
349 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
350 const std::string& name,
351 const std::string& package,
352 const std::string& authors,
353 const std::string& authorsEmail,
354 const std::string& categories,
355 const std::string& description
358 //TODO: implement method
362 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
364 //TODO: implement method
368 const bool modelCDMProject::Refresh(std::string*& result)
370 std::cout << "refreshing project" << std::endl;
371 //open makelists file
372 //TODO: set pathMakeLists for windows
373 std::string pathMakeLists = this->path + "/CMakeLists.txt";
375 std::ifstream confFile;
376 confFile.open((pathMakeLists).c_str());
379 while(confFile.is_open() && !confFile.eof())
381 //std::cout << "leyendo " << word << std::endl;
383 std::getline(confFile,word,'(');
384 std::vector<std::string> wordBits;
385 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
387 if(wordBits[wordBits.size()-1] == "PROJECT")
389 std::getline(confFile,word,')');
390 std::vector<std::string> nameBits;
391 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
393 this->name = this->nameProject = "";
394 for (int i = 0; i < nameBits.size(); i++)
398 this->name += nameBits[i];
400 this->nameProject = this->name;
405 if(wordBits[wordBits.size()-1] == "SET")
407 //get project version
408 std::getline(confFile,word,')');
409 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
410 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
412 version = wordBits[1];
414 if(wordBits[0] == "PROJECT_MINOR_VERSION")
416 version += "." + wordBits[1];
418 if(wordBits[0] == "PROJECT_BUILD_VERSION")
420 version += "." + wordBits[1];
423 //get project versionDate
424 if(wordBits[0] == "PROJECT_VERSION_DATE")
426 std::vector<std::string> versionBits;
427 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
428 versionDate = versionBits[0];
434 this->type = wxDIR_DIRS;
437 std::vector<bool> checked(this->children.size(), false);
438 std::vector<bool> checkedPackages(this->packages.size(), false);
441 wxDir dir(crea::std2wx((this->path).c_str()));
445 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
448 std::string stdfileName = crea::wx2std(fileName);
450 //if appli, create appli
451 if(stdfileName == "appli")
453 if (this->appli == NULL)
455 this->appli = new modelCDMAppli(this->path + "/appli", this->level + 1);
456 this->children.push_back(this->appli);
460 int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
462 if(!this->appli->Refresh(result))
467 else if(stdfileName == "lib")
469 if (this->lib == NULL)
471 this->lib = new modelCDMLib(this->path + "/lib", this->level + 1);
472 this->children.push_back(this->lib);
476 int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
478 if(!this->lib->Refresh(result))
483 //if package , create package
484 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
486 std::string packageName = stdfileName.substr(5, stdfileName.size()-9);
488 for (int i = 0;!found && i < this->packages.size(); i++)
490 if (this->packages[i]->GetName() == packageName)
493 int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
495 checkedPackages[i] = true;
496 if(!this->packages[i]->Refresh(result))
502 modelCDMPackage* package = new modelCDMPackage(this->path + "/" + stdfileName, this->level + 1);
503 this->packages.push_back(package);
504 this->children.push_back(package);
508 //if is an unknown folder, create folder
512 for (int i = 0; !found && i < this->children.size(); i++)
514 if (this->children[i]->GetName() == stdfileName)
518 if(!this->children[i]->Refresh(result))
525 modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
526 this->children.push_back(folder);
530 cont = dir.GetNext(&fileName);
533 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
536 std::string stdfileName = crea::wx2std(fileName);
538 //if CMakeLists, create CMakeLists
539 if(stdfileName == "CMakeLists.txt")
541 if (this->CMakeLists == NULL)
543 this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
544 this->children.push_back(this->CMakeLists);
548 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
550 if(!this->CMakeLists->Refresh(result))
554 //if is an unknown file, create file
558 for (int i = 0; i <!found && this->children.size(); i++)
560 if (this->children[i]->GetName() == stdfileName)
564 if(!this->children[i]->Refresh(result))
571 modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
572 this->children.push_back(file);
576 cont = dir.GetNext(&fileName);
580 for (int i = 0; i < checkedPackages.size(); i++)
582 if(!checkedPackages[i])
584 this->packages.erase(this->packages.begin()+i);
585 checkedPackages.erase(checkedPackages.begin()+i);
589 for (int i = 0; i < checked.size(); i++)
593 delete this->children[i];
594 this->children.erase(this->children.begin()+i);
595 checked.erase(checked.begin()+i);
599 this->SortChildren();
603 bool modelCDMProject::ConfigureBuild(std::string*& result)
605 //TODO: implement method
609 bool modelCDMProject::Build(std::string*& result)
611 //TODO: implement method
615 bool modelCDMProject::Connect(std::string*& result)
617 //TODO: implement method