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"
43 #include <boost/regex.hpp>
45 #include "CDMUtilities.h"
49 modelCDMProject::modelCDMProject()
51 std::cout << "in constructor1" << std::endl;
54 this->CMakeLists = NULL;
57 modelCDMProject::modelCDMProject(
58 modelCDMIProjectTreeNode* parent,
59 const std::string& path,
60 const std::string& name,
61 const std::string& buildPath
64 std::cout << "creating project: " + name + " in " + path + "\n";
65 this->parent = parent;
66 this->path = CDMUtilities::fixPath(path);
68 std::string pathFixed(CDMUtilities::fixPath(path));
70 std::string pathMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
72 std::ifstream confFile;
73 confFile.open((pathMakeLists).c_str());
76 while(confFile.is_open() && !confFile.eof())
78 //std::cout << "leyendo " << word << std::endl;
80 std::getline(confFile,word,'(');
81 std::vector<std::string> wordBits;
82 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
84 if(wordBits[wordBits.size()-1] == "PROJECT")
86 std::getline(confFile,word,')');
87 std::vector<std::string> nameBits;
88 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
90 this->name = this->nameProject = "";
91 for (int i = 0; i < (int)(nameBits.size()); i++)
95 this->name += nameBits[i];
97 this->nameProject = this->name;
102 if(wordBits[wordBits.size()-1] == "SET")
104 //get project version
105 std::getline(confFile,word,')');
106 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
107 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
109 version = wordBits[1];
111 if(wordBits[0] == "PROJECT_MINOR_VERSION")
113 version += "." + wordBits[1];
115 if(wordBits[0] == "PROJECT_BUILD_VERSION")
117 version += "." + wordBits[1];
120 //get project versionDate
121 if(wordBits[0] == "PROJECT_VERSION_DATE")
123 std::vector<std::string> versionBits;
124 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
125 versionDate = versionBits[0];
127 //get project buildPath
131 this->buildPath = buildPath;
135 this->buildPath = this->path + "Bin";
141 this->type = wxDIR_DIRS;
144 this->children.clear();
147 this->packages.clear();
151 wxDir dir(crea::std2wx((pathFixed).c_str()));
155 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
158 std::string stdfileName = crea::wx2std(fileName);
160 //if appli, create appli
161 if(stdfileName == "appli")
163 this->appli = new modelCDMAppli(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
164 this->children.push_back(this->appli);
167 else if(stdfileName == "lib")
169 this->lib = new modelCDMLib(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
170 this->children.push_back(this->lib);
172 //if package , create package
173 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
175 modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
176 this->packages.push_back(package);
177 this->children.push_back(package);
179 //if is an unknown folder, create folder
182 this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
185 cont = dir.GetNext(&fileName);
188 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
191 std::string stdfileName = crea::wx2std(fileName);
193 //if CMakeLists, create CMakeLists
194 if(stdfileName == "CMakeLists.txt")
196 this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
197 this->children.push_back(this->CMakeLists);
201 this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
203 //if is an unknown file, create file
204 cont = dir.GetNext(&fileName);
208 this->SortChildren();
209 std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
213 modelCDMProject::~modelCDMProject()
217 const std::string& modelCDMProject::GetNameProject() const
219 return this->nameProject;
222 const std::string& modelCDMProject::GetVersion() const
224 return this->version;
227 const std::string& modelCDMProject::GetVersionDate() const
229 return this->versionDate;
232 const std::string& modelCDMProject::GetBuildPath() const
234 return this->buildPath;
237 const std::vector<modelCDMPackage*>& modelCDMProject::GetPackages() const
239 return this->packages;
242 modelCDMAppli* modelCDMProject::GetAppli() const
247 modelCDMLib* modelCDMProject::GetLib() const
252 std::string modelCDMProject::GetBuildInstruction() const
254 std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
258 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
261 std::vector<std::string> vers;
262 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
264 time_t now = time(0);
268 localtime_s(<m, &now);
270 ltm = *(localtime(&now));
273 std::stringstream date;
274 date << ltm.tm_mday << "/" << 1 + ltm.tm_mon << "/" << 1900 + ltm.tm_year;
276 //set name of library in CMakeLists inside copied folder
278 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
281 result = new std::string("CMakeLists.txt file failed to open.");
284 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
287 result = new std::string("CMakeLists.txt.tmp file failed to open.");
290 while (getline(in, line))
292 if(line.find("SET(PROJECT_MAJOR_VERSION") != std::string::npos)
293 line = "SET(PROJECT_MAJOR_VERSION " + vers[0] + ")";
294 else if(line.find("SET(PROJECT_MINOR_VERSION") != std::string::npos)
295 line = "SET(PROJECT_MINOR_VERSION " + vers[1] + ")";
296 else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos)
297 line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")";
298 else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos)
299 line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
300 out << line << std::endl;
304 //delete old file and rename new file
306 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
308 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
310 if(system(renameCommand.c_str()))
312 result = new std::string("An error occurred while running '" + renameCommand + "'.");
316 this->version = vers[0] + "." + vers[1] + "." + vers[2];
317 this->versionDate = date.str();
321 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
325 result = new std::string("The path cannot be empty");
328 if(path == this->path)
330 result = new std::string("The path cannot be same as the project sources");
333 this->buildPath = path;
337 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
338 const std::string& name,
339 std::string*& result,
340 const std::string& authors,
341 const std::string& authorsEmail,
342 const std::string& description,
343 const std::string& version
346 //fixing input parameters
347 std::vector<std::string> words;
349 CDMUtilities::splitter::split(words,name," '/\"\\,.",CDMUtilities::splitter::no_empties);
350 std::string nameFixed = "";
351 for (int i = 0; i < (int)(words.size()); i++)
353 nameFixed += words[i];
357 CDMUtilities::splitter::split(words,authors," '/\"\\,.",CDMUtilities::splitter::no_empties);
358 std::string authorFixed;
359 for (int i = 0; i < (int)(words.size()); i++)
361 authorFixed += words[i];
365 std::string descriptionFixed;
366 CDMUtilities::splitter::split(words,authorsEmail," '/\"\\,",CDMUtilities::splitter::no_empties);
367 for (int i = 0; i < (int)(words.size()); i++)
369 descriptionFixed += words[i] + "/";
372 CDMUtilities::splitter::split(words,description," '\"",CDMUtilities::splitter::no_empties);
373 for (int i = 0; i < (int)(words.size()); i++)
375 descriptionFixed += "_" + words[i];
378 //call project to create package : use bbCreatePackage <path> <name> [author] [description]
379 std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
380 //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
381 bool resultCommand = 0 != system(creationCommand.c_str());
383 resultCommand = false;
387 result = new std::string("An error occurred while running '" + creationCommand + "'.");
391 //add library to project CMakeLists
392 std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
395 out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl;
399 //add library to model
400 modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
401 this->packages.push_back(package);
402 this->children.push_back(package);
404 //TODO: set package version
406 this->SortChildren();
408 result = new std::string(this->path + CDMUtilities::SLASH + name);
412 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
413 const std::string& name,
414 std::string*& result,
415 const std::string& path
418 if(this->lib != NULL)
420 return this->lib->CreateLibrary(name, result);
422 result = new std::string("there is no lib folder in this project.");
426 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
427 const std::string& name,
429 std::string*& result,
430 const std::string& path
433 if(this->appli != NULL)
435 return this->appli->CreateApplication(name, type, result);
437 result = new std::string("there is no appli folder in this project.");
441 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
442 const std::string& name,
443 const std::string& package,
444 const std::string& authors,
445 const std::string& authorsEmail,
446 const std::string& categories,
447 const std::string& description
450 //TODO: implement method
454 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
456 if (!CDMUtilities::openTextEditor(this->CMakeLists->GetPath()))
460 result = new std::string("Couldn't open CMakeLists file.");
465 const bool modelCDMProject::Refresh(std::string*& result)
467 std::cout << "refreshing project" << std::endl;
468 //open makelists file
469 std::string pathMakeLists = this->path + CDMUtilities::SLASH + "CMakeLists.txt";
471 std::ifstream confFile;
472 confFile.open((pathMakeLists).c_str());
475 while(confFile.is_open() && !confFile.eof())
477 //std::cout << "leyendo " << word << std::endl;
479 std::getline(confFile,word,'(');
480 std::vector<std::string> wordBits;
481 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
483 if(wordBits[wordBits.size()-1] == "PROJECT")
485 std::getline(confFile,word,')');
486 std::vector<std::string> nameBits;
487 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
489 this->name = this->nameProject = "";
490 for (int i = 0; i < (int)(nameBits.size()); i++)
494 this->name += nameBits[i];
496 this->nameProject = this->name;
501 if(wordBits[wordBits.size()-1] == "SET")
503 //get project version
504 std::getline(confFile,word,')');
505 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
506 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
508 version = wordBits[1];
510 if(wordBits[0] == "PROJECT_MINOR_VERSION")
512 version += "." + wordBits[1];
514 if(wordBits[0] == "PROJECT_BUILD_VERSION")
516 version += "." + wordBits[1];
519 //get project versionDate
520 if(wordBits[0] == "PROJECT_VERSION_DATE")
522 std::vector<std::string> versionBits;
523 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
524 versionDate = versionBits[0];
530 this->type = wxDIR_DIRS;
533 std::vector<bool> checked(this->children.size(), false);
534 std::vector<bool> checkedPackages(this->packages.size(), false);
537 wxDir dir(crea::std2wx((this->path).c_str()));
541 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
544 std::string stdfileName = crea::wx2std(fileName);
546 //if appli, create appli
547 if(stdfileName == "appli")
549 if (this->appli == NULL)
551 this->appli = new modelCDMAppli(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
552 this->children.push_back(this->appli);
556 int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
558 if(!this->appli->Refresh(result))
563 else if(stdfileName == "lib")
565 if (this->lib == NULL)
567 this->lib = new modelCDMLib(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
568 this->children.push_back(this->lib);
572 int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
574 if(!this->lib->Refresh(result))
579 //if package , create package
580 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
583 for (int i = 0; !found && i < (int)(this->packages.size()); i++)
585 if (this->packages[i]->GetName() == stdfileName)
588 int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
590 checkedPackages[i] = true;
591 if(!this->packages[i]->Refresh(result))
597 modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
598 this->packages.push_back(package);
599 this->children.push_back(package);
603 //if is an unknown folder, create folder
607 for (int i = 0; !found && i < (int)(this->children.size()); i++)
609 if (this->children[i]->GetName() == stdfileName)
613 if(!this->children[i]->Refresh(result))
620 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
621 this->children.push_back(folder);
625 cont = dir.GetNext(&fileName);
628 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
631 std::string stdfileName = crea::wx2std(fileName);
633 //if CMakeLists, create CMakeLists
634 if(stdfileName == "CMakeLists.txt")
636 if (this->CMakeLists == NULL)
638 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
639 this->children.push_back(this->CMakeLists);
643 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
645 if(!this->CMakeLists->Refresh(result))
649 //if is an unknown file, create file
653 for (int i = 0; !found && i < (int)(this->children.size()); i++)
655 if (this->children[i]->GetName() == stdfileName)
659 if(!this->children[i]->Refresh(result))
666 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
667 this->children.push_back(file);
671 cont = dir.GetNext(&fileName);
675 for (int i = 0; i < (int)(checkedPackages.size()); i++)
677 if(!checkedPackages[i])
679 this->packages.erase(this->packages.begin()+i);
680 checkedPackages.erase(checkedPackages.begin()+i);
684 for (int i = 0; i < (int)(checked.size()); i++)
688 delete this->children[i];
689 this->children.erase(this->children.begin()+i);
690 checked.erase(checked.begin()+i);
695 this->SortChildren();
696 std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
700 bool modelCDMProject::ConfigureBuild(std::string*& result)
702 //TODO: adjust for windows and mac
705 if(0 == system("cmake-gui"))
709 result = new std::string("There was an error opening cmake-gui. Please make sure it's installed and that cmake's bin folder is in the system path.");
717 wxDir dir(crea::std2wx((this->buildPath).c_str()));
719 //if folder doesn't exist then create it
722 //create command line to create folder
723 std::string createComm = "mkdir \"" + this->buildPath + "\"";
724 //execute creation command
725 if (system(createComm.c_str()))
727 //if there was an error then report it
728 result = new std::string("There was an error creating the build path: \"" + this->buildPath + "\"");
732 //create command line to execute ccmake
733 //TODO:: adjust for different Linux distributions
734 std::string confComm = "gnome-terminal --tab --working-directory=\"" + this->buildPath + "\" -e \"ccmake '" + this->path + "'\"";
736 if(CDMUtilities::openTerminal(confComm))
738 //if there was an error then report it
739 result = new std::string("There was an error opening the configuration tool in the desired place.");
746 bool modelCDMProject::Build(std::string*& result, const std::string& line)
748 //TODO: adjust for windows and mac
751 std::string command = "start \"\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\"";
752 //wxMessageBox(crea::std2wx(command), wxT("Project Compilation - Check!"));
753 if(0 == system(command.c_str()))
757 result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ installed.");
765 wxDir dir(crea::std2wx((this->buildPath).c_str()));
767 //if binary folder can't be opened then return false
770 result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
773 //create make command
774 std::string makeComm = "gnome-terminal -e \"bash -c \\\"";
775 for (int i = 0; i < line.size(); i++)
779 makeComm+="\\\\\\\"";
781 else if(line[i] == '\\')
783 makeComm+="\\\\\\\\";
787 makeComm.push_back(line[i]);
790 makeComm += "; echo -e '\\a'; bash";
791 makeComm += "\\\"\"";
793 std::cout << "executing '" << makeComm << "'" << std::endl;
794 //execute make command
795 if(system(makeComm.c_str()))
797 //if there was an error then report it
798 result = new std::string("There was an error compiling the project, please check the \"building.log\" file located in the build folder to read more about the problem.");
805 bool modelCDMProject::Connect(std::string*& result, const std::string& folder)
807 //TODO: adjust for mac
811 wxDir dir(crea::std2wx(folder));
813 //if binary folder can't be opened then return false
816 result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
819 //create plug command
820 std::string plugComm = "bbPlugPackage \"" + folder + "\"";
821 std::cout << "executing '" << plugComm << "'" << std::endl;
822 //execute plug command
823 if(system(std::string("start cmd.exe /k \"" + plugComm + "\"").c_str()))
825 //if there was an error then report it
826 result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
834 wxDir dir(crea::std2wx(folder));
836 //if binary folder can't be opened then return false
839 result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
842 //create plug command
843 std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\"";
845 std::string Comm = "gnome-terminal -e \"bash -c \\\"";
846 for (int i = 0; i < plugComm.size(); i++)
848 if(plugComm[i] == '"')
852 else if(plugComm[i] == '\\')
858 Comm.push_back(plugComm[i]);
861 Comm += "; echo -e '\\a'; bash";
865 std::cout << "executing '" << Comm << "'" << std::endl;
866 //execute plug command
867 if(system(Comm.c_str()))
869 //if there was an error then report it
870 result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
877 void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
880 if(this->CMakeLists != NULL)
882 //set properties parameters based on model
883 properties["project add appli"] = this->appli != NULL;
884 properties["project add lib"] = this->lib != NULL;
885 for (int i = 0; i < (int)(this->packages.size()); i++)
886 properties["project add " + packages[i]->GetName()] = false;
889 std::ifstream confFile;
890 confFile.open((this->CMakeLists->GetPath()).c_str());
892 //take everything that is not commented
893 std::string fileContent;
896 std::vector<std::string> words;
897 while(confFile.is_open() && !confFile.eof())
899 std::getline(confFile,word, '\n');
902 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
903 if (words.size() > 0)
906 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
907 for (int i = 0; i < (int)(words.size()); i++)
909 if(words[i].substr(0,2) == "//")
911 fileContent += words[i] + " ";
918 //check every instruction
919 std::stringstream ss(fileContent);
922 std::getline(ss,word, '(');
924 //check instruction name
925 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
928 if (words.size() > 0 && words[words.size()-1] == "SET")
930 std::getline(ss,word, ')');
932 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
933 if (words.size() > 1)
935 if (words[0] == "USE_CREA" && words[1] == "ON")
937 properties["project set USE_CREA"] = true;
939 else if (words[0] == "USE_GDCM" && words[1] == "ON")
941 properties["project set USE_GDCM"] = true;
943 else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
945 properties["project set USE_GDCM_VTK"] = true;
947 else if (words[0] == "USE_GDCM2" && words[1] == "ON")
949 properties["project set USE_GDCM2"] = true;
951 else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
953 properties["project set USE_WXWIDGETS"] = true;
955 else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
957 properties["project set USE_KWWIDGETS"] = true;
959 else if (words[0] == "USE_VTK" && words[1] == "ON")
961 properties["project set USE_VTK"] = true;
963 else if (words[0] == "USE_ITK" && words[1] == "ON")
965 properties["project set USE_ITK"] = true;
967 else if (words[0] == "USE_BOOST" && words[1] == "ON")
969 properties["project set USE_BOOST"] = true;
974 else if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY")
976 std::getline(ss,word, ')');
977 //std::cout << word << std::endl;
978 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
980 if (words.size() > 0)
982 if(words[0] == "appli")
984 properties["project add "+words[0]] = this->appli != NULL;
986 else if(words[0] == "lib")
988 properties["project add "+words[0]] = this->lib != NULL;
992 properties["project add "+words[0]] = true;
1000 //check appli's structure
1001 this->appli->CheckStructure(properties);
1002 //check lib's structure
1003 this->lib->CheckStructure(properties);
1004 //check packages' structure
1005 for (int i = 0; i < (int)(this->packages.size()); i++)
1007 properties["package " + this->packages[i]->GetName()] = true;
1008 this->packages[i]->CheckStructure(properties);
1012 bool modelCDMProject::IsPackageIncluded(const std::string& package_name)
1014 if (this->HasCMakeLists())
1016 CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
1017 for (int i = 0; i < cmlFile.size(); ++i)
1019 if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY")
1022 while (pos < cmlFile[i].second.size())
1024 if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#')
1026 if (package_name == cmlFile[i].second[pos])
1039 bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude)
1041 if (this->HasCMakeLists())
1043 CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
1047 for (int i = 0; i < cmlFile.size(); ++i)
1049 if(toInclude && cmlFile[i].first == "comment")
1051 std::vector<std::string> segments;
1052 std::string line = cmlFile[i].second[0];
1053 while(line[0] == '#')
1056 CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties);
1057 if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == package_name)
1060 while(cmlFile[i].second[0][0] == '#')
1061 cmlFile[i].second[0].erase(0,1);
1064 else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY")
1067 while (pos < cmlFile[i].second.size())
1069 if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#')
1071 if (package_name == cmlFile[i].second[pos])
1076 cmlFile[i].first = "comment";
1077 cmlFile[i].second[0] = "#" + cmlFile[i].second[0];
1078 while (cmlFile[i].second.size() > 1)
1080 cmlFile[i].second[0] += cmlFile[i].second[1];
1081 cmlFile[i].second.erase(cmlFile[i].second.begin()+1);
1092 if (!found && toInclude)
1094 CDMUtilities::syntaxElement element;
1095 element.first = "command";
1096 element.second.push_back("ADD_SUBDIRECTORY(" + package_name + ")");
1097 cmlFile.push_back(element);
1100 return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile);
1105 std::map<std::string, bool> modelCDMProject::Get3rdPartyLibraries()
1107 std::map<std::string, std::string> correspondence;
1108 correspondence["USE_CREA"] = "Crea";
1109 correspondence["USE_GDCM"] = "GDCM";
1110 correspondence["USE_GDCM_VTK"] = "GDCM_VTK";
1111 correspondence["USE_GDCM2"] = "GDCM2";
1112 correspondence["USE_WXWIDGETS"] = "WxWidgets";
1113 correspondence["USE_KWWIDGETS"] = "KWWidgets";
1114 correspondence["USE_VTK"] = "VTK";
1115 correspondence["USE_ITK"] = "ITK";
1116 correspondence["USE_BOOST"] = "Boost";
1118 std::map<std::string, bool> res;
1119 res["Crea"] = false;
1120 res["GDCM"] = false;
1121 res["GDCM_VTK"] = false;
1122 res["GDCM2"] = false;
1123 res["WxWidgets"] = false;
1124 res["KWWidgets"] = false;
1127 res["Boost"] = false;
1129 if (this->HasCMakeLists())
1131 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
1133 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*USE_\\w+\\s+ON");
1134 std::string::const_iterator start, end;
1135 start = CMfile.begin();
1137 boost::match_results<std::string::const_iterator> what;
1138 boost::match_flag_type flags = boost::match_default;
1139 while(boost::regex_search(start, end, what, expression, flags))
1141 std::cout << what[0].str() << std::endl;
1142 boost::regex expression1 = boost::regex("USE_\\w+");
1143 std::string::const_iterator start1, end1;
1144 start1 = what[0].first;
1145 end1 = what[0].second;
1146 boost::match_results<std::string::const_iterator> what1;
1147 if(boost::regex_search(start1, end1, what1, expression1, flags))
1149 std::string dete = what1.str();
1150 CDMUtilities::normalizeStr(dete);
1151 std::cout << dete << std::endl;
1152 if(correspondence.find(dete) != correspondence.end())
1153 res[correspondence[dete]] = true;
1155 start = what[0].second;
1162 bool modelCDMProject::Set3rdPartyLibrary(const std::string& library_name,
1163 const bool& toInclude)
1165 std::map<std::string, std::string> correspondence;
1166 correspondence["Crea"] = "USE_CREA";
1167 correspondence["GDCM"] = "USE_GDCM";
1168 correspondence["GDCM_VTK"] = "USE_GDCM_VTK";
1169 correspondence["GDCM2"] = "USE_GDCM2";
1170 correspondence["WxWidgets"] = "USE_WXWIDGETS";
1171 correspondence["KWWidgets"] = "USE_KWWIDGETS";
1172 correspondence["VTK"] = "USE_VTK";
1173 correspondence["ITK"] = "USE_ITK";
1174 correspondence["Boost"] = "USE_BOOST";
1176 if (correspondence.find(library_name) != correspondence.end())
1178 std::string library_command = correspondence[library_name];
1180 if (this->HasCMakeLists())
1182 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
1183 std::string resCMfile = "";
1185 std::string::const_iterator start, end;
1186 boost::match_results<std::string::const_iterator> what, tmp;
1187 boost::match_flag_type flags = boost::match_default;
1190 start = CMfile.begin();
1193 //search for existing inclusions
1194 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)");
1195 while(boost::regex_search(start, end, what, expression, flags))
1198 resCMfile += what.prefix().str();
1201 std::string dete = what.str();
1202 int pos = dete.find("ON",0);
1203 dete.replace(pos, 2, "OFF");
1207 resCMfile += what.str();
1209 start = what[0].second;
1213 resCMfile += tmp.suffix().str();
1216 start = CMfile.begin();
1219 //search for existing exclusions
1220 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+OFF\\s*\\)");
1221 while(boost::regex_search(start, end, what, expression, flags))
1224 resCMfile += what.prefix().str();
1227 std::string dete = what.str();
1228 int pos = dete.find("OFF",0);
1229 dete.replace(pos, 3, "ON");
1233 resCMfile += what.str();
1235 start = what[0].second;
1239 resCMfile += tmp.suffix().str();
1242 start = CMfile.begin();
1245 //search for existing commented inclusions
1246 expression = boost::regex("^\\h*#+\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)");
1247 while(boost::regex_search(start, end, what, expression, flags))
1250 resCMfile += what.prefix().str();
1253 std::string dete = what.str();
1254 for (int i = 0; i < dete.size(); ++i) {
1264 resCMfile += what.str();
1267 start = what[0].second;
1271 resCMfile += tmp.suffix().str();
1276 start = CMfile.begin();
1279 //search for position to insert
1280 expression = boost::regex("^\\h*#\\h*Libraries\\/tools used\\h*$");
1281 if(boost::regex_search(start, end, what, expression, flags))
1284 resCMfile += what.prefix().str();
1285 resCMfile += what.str();
1286 resCMfile += "\nSET(" + library_command + " ON)";
1287 resCMfile += what.suffix().str();
1301 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);