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& description,
248 const std::string& version
251 //fixing input parameters
252 std::vector<std::string> words;
254 CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
255 std::string nameFixed = "";
256 for (int i = 0; i < words.size(); i++)
258 nameFixed += words[i];
262 CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
263 std::string authorFixed;
264 for (int i = 0; i < words.size(); i++)
266 authorFixed += words[i];
270 std::string descriptionFixed;
271 CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
272 for (int i = 0; i < words.size(); i++)
274 descriptionFixed += words[i];
277 CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
278 for (int i = 0; i < words.size(); i++)
280 descriptionFixed += "_" + words[i];
283 //call project to create package : use bbCreatePackage <path> <name> [author] [description]
284 std::string creationCommand = "bbCreatePackage \"" + this->path + "\" " + nameFixed + " " + authorFixed + " " + descriptionFixed;
285 //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
286 if(system(creationCommand.c_str()))
288 result = new std::string("An error occurred while running '" + creationCommand + "'.");
292 //add library to model
293 //TODO: fix for windows
294 modelCDMPackage* package = new modelCDMPackage(this->path + "/bbtk_" + nameFixed + "_PKG", this->level + 1);
295 this->packages.push_back(package);
296 this->children.push_back(package);
298 //TODO: set package version
300 this->SortChildren();
302 result = new std::string(this->path + "/" + name);
306 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
307 const std::string& name,
308 std::string*& result,
309 const std::string& path
312 if(this->lib != NULL)
314 return this->lib->CreateLibrary(name, result);
316 result = new std::string("there is no lib folder in this project.");
320 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
321 const std::string& name,
322 std::string*& result,
323 const std::string& path
326 if(this->appli != NULL)
328 return this->appli->CreateApplication(name, result);
330 result = new std::string("there is no appli folder in this project.");
334 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
335 const std::string& name,
336 const std::string& package,
337 const std::string& authors,
338 const std::string& authorsEmail,
339 const std::string& categories,
340 const std::string& description
343 //TODO: implement method
347 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
349 //TODO: implement method
353 const bool modelCDMProject::Refresh(std::string*& result)
355 std::cout << "refreshing project" << std::endl;
356 //open makelists file
357 //TODO: set pathMakeLists for windows
358 std::string pathMakeLists = this->path + "/CMakeLists.txt";
360 std::ifstream confFile;
361 confFile.open((pathMakeLists).c_str());
364 while(confFile.is_open() && !confFile.eof())
366 //std::cout << "leyendo " << word << std::endl;
368 std::getline(confFile,word,'(');
369 std::vector<std::string> wordBits;
370 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
372 if(wordBits[wordBits.size()-1] == "PROJECT")
374 std::getline(confFile,word,')');
375 std::vector<std::string> nameBits;
376 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
378 this->name = this->nameProject = "";
379 for (int i = 0; i < nameBits.size(); i++)
383 this->name += nameBits[i];
385 this->nameProject = this->name;
390 if(wordBits[wordBits.size()-1] == "SET")
392 //get project version
393 std::getline(confFile,word,')');
394 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
395 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
397 version = wordBits[1];
399 if(wordBits[0] == "PROJECT_MINOR_VERSION")
401 version += "." + wordBits[1];
403 if(wordBits[0] == "PROJECT_BUILD_VERSION")
405 version += "." + wordBits[1];
408 //get project versionDate
409 if(wordBits[0] == "PROJECT_VERSION_DATE")
411 std::vector<std::string> versionBits;
412 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
413 versionDate = versionBits[0];
419 this->type = wxDIR_DIRS;
422 std::vector<bool> checked(this->children.size(), false);
423 std::vector<bool> checkedPackages(this->packages.size(), false);
426 wxDir dir(crea::std2wx((this->path).c_str()));
430 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
433 std::string stdfileName = crea::wx2std(fileName);
435 //if appli, create appli
436 if(stdfileName == "appli")
438 if (this->appli == NULL)
440 this->appli = new modelCDMAppli(this->path + "/appli", this->level + 1);
441 this->children.push_back(this->appli);
445 int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
447 if(!this->appli->Refresh(result))
452 else if(stdfileName == "lib")
454 if (this->lib == NULL)
456 this->lib = new modelCDMLib(this->path + "/lib", this->level + 1);
457 this->children.push_back(this->lib);
461 int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
463 if(!this->lib->Refresh(result))
468 //if package , create package
469 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
471 std::string packageName = stdfileName.substr(5, stdfileName.size()-9);
473 for (int i = 0;!found && i < this->packages.size(); i++)
475 if (this->packages[i]->GetName() == packageName)
478 int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
480 checkedPackages[i] = true;
481 if(!this->packages[i]->Refresh(result))
487 modelCDMPackage* package = new modelCDMPackage(this->path + "/" + stdfileName, this->level + 1);
488 this->packages.push_back(package);
489 this->children.push_back(package);
493 //if is an unknown folder, create folder
497 for (int i = 0; !found && i < this->children.size(); i++)
499 if (this->children[i]->GetName() == stdfileName)
503 if(!this->children[i]->Refresh(result))
510 modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
511 this->children.push_back(folder);
515 cont = dir.GetNext(&fileName);
518 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
521 std::string stdfileName = crea::wx2std(fileName);
523 //if CMakeLists, create CMakeLists
524 if(stdfileName == "CMakeLists.txt")
526 if (this->CMakeLists == NULL)
528 this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
529 this->children.push_back(this->CMakeLists);
533 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
535 if(!this->CMakeLists->Refresh(result))
539 //if is an unknown file, create file
543 for (int i = 0; i <!found && this->children.size(); i++)
545 if (this->children[i]->GetName() == stdfileName)
549 if(!this->children[i]->Refresh(result))
556 modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
557 this->children.push_back(file);
561 cont = dir.GetNext(&fileName);
565 for (int i = 0; i < checkedPackages.size(); i++)
567 if(!checkedPackages[i])
569 this->packages.erase(this->packages.begin()+i);
570 checkedPackages.erase(checkedPackages.begin()+i);
574 for (int i = 0; i < checked.size(); i++)
578 delete this->children[i];
579 this->children.erase(this->children.begin()+i);
580 checked.erase(checked.begin()+i);
584 this->SortChildren();
588 bool modelCDMProject::ConfigureBuild(std::string*& result)
590 //TODO: implement method
594 bool modelCDMProject::Build(std::string*& result)
596 //TODO: implement method
600 bool modelCDMProject::Connect(std::string*& result)
602 //TODO: implement method