]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMProject.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMProject.cpp
index 8206a75bae273f9ed7d20538a73a1ecbbbce0909..c39463376e247080cecea63f49a45723ac5e4de9 100644 (file)
@@ -54,11 +54,14 @@ modelCDMProject::modelCDMProject()
 }
 
 modelCDMProject::modelCDMProject(
+    modelCDMIProjectTreeNode* parent,
     const std::string& path,
     const std::string& name,
     const std::string& buildPath
 )
 {
+  std::cout << "creating project: " + name + " in " + path + "\n";
+  this->parent = parent;
   this->path = CDMUtilities::fixPath(path);
   //open makelists file
   std::string pathFixed(CDMUtilities::fixPath(path));
@@ -84,7 +87,7 @@ modelCDMProject::modelCDMProject(
           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
 
           this->name = this->nameProject = "";
-          for (int i = 0; i < nameBits.size(); i++)
+          for (int i = 0; i < (int)(nameBits.size()); i++)
             {
               if(i != 0)
                 this->name += " ";
@@ -156,26 +159,26 @@ modelCDMProject::modelCDMProject(
           //if appli, create appli
           if(stdfileName == "appli")
             {
-              this->appli = new modelCDMAppli(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->appli = new modelCDMAppli(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->appli);
             }
           //if lib, create lib
           else if(stdfileName == "lib")
             {
-              this->lib = new modelCDMLib(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->lib = new modelCDMLib(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->lib);
             }
           //if package , create package
           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
             {
-              modelCDMPackage* package = new modelCDMPackage(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->packages.push_back(package);
               this->children.push_back(package);
             }
           //if is an unknown folder, create folder
           else
             {
-              this->children.push_back(new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+              this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
             }
 
           cont = dir.GetNext(&fileName);
@@ -189,12 +192,12 @@ modelCDMProject::modelCDMProject(
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
-              this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->CMakeLists);
             }
           else
             {
-              this->children.push_back(new modelCDMFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+              this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
             }
           //if is an unknown file, create file
           cont = dir.GetNext(&fileName);
@@ -202,6 +205,7 @@ modelCDMProject::modelCDMProject(
     }
 
   this->SortChildren();
+  std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
 
 }
 
@@ -244,6 +248,12 @@ modelCDMLib* modelCDMProject::GetLib() const
   return this->lib;
 }
 
+std::string modelCDMProject::GetBuildInstruction() const
+{
+  std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
+  return makeComm;
+}
+
 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
 {
 
@@ -251,10 +261,16 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul
   CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
 
   time_t now = time(0);
-  tm* ltm = localtime(&now);
+
+  tm ltm;
+#ifdef _WIN32
+  localtime_s(&ltm, &now);
+#else
+  ltm = *(localtime(&now));
+#endif
 
   std::stringstream date;
-  date << ltm->tm_mday << "/" << 1 + ltm->tm_mon << "/" << 1900 + ltm->tm_year;
+  date << ltm.tm_mday << "/" << 1 + ltm.tm_mon << "/" << 1900 + ltm.tm_year;
 
   //set name of library in CMakeLists inside copied folder
   std::string line;
@@ -279,13 +295,17 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul
       else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos)
         line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")";
       else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos)
-              line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
+        line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
       out << line << std::endl;
     }
   in.close();
   out.close();
   //delete old file and rename new file
+#ifdef _WIN32
+  std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
@@ -325,31 +345,31 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
   //fixing input parameters
   std::vector<std::string> words;
 
-  CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words,name," '/\"\\,.",CDMUtilities::splitter::no_empties);
   std::string nameFixed = "";
-  for (int i = 0; i < words.size(); i++)
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       nameFixed += words[i];
     }
 
   words.clear();
-  CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words,authors," '/\"\\,.",CDMUtilities::splitter::no_empties);
   std::string authorFixed;
-  for (int i = 0; i < words.size(); i++)
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       authorFixed += words[i];
     }
 
   words.clear();
   std::string descriptionFixed;
-  CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
-  for (int i = 0; i < words.size(); i++)
+  CDMUtilities::splitter::split(words,authorsEmail," '/\"\\,",CDMUtilities::splitter::no_empties);
+  for (int i = 0; i < (int)(words.size()); i++)
     {
-      descriptionFixed += words[i];
+      descriptionFixed += words[i] + "/";
     }
   words.clear();
-  CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
-  for (int i = 0; i < words.size(); i++)
+  CDMUtilities::splitter::split(words,description," '\"",CDMUtilities::splitter::no_empties);
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       descriptionFixed += "_" + words[i];
     }
@@ -357,14 +377,26 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
   //call project to create package : use bbCreatePackage <path> <name> [author] [description]
   std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
   //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
-  if(system(creationCommand.c_str()))
+  bool resultCommand = 0 != system(creationCommand.c_str());
+#ifdef _WIN32
+  resultCommand = false;
+#endif
+  if(resultCommand)
     {
       result = new std::string("An error occurred while running '" + creationCommand + "'.");
       return NULL;
     }
 
+  //add library to project CMakeLists
+  std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
+  if (out1.is_open())
+    {
+      out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl;
+      out1.close();
+    }
+
   //add library to model
-  modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
+  modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
   this->packages.push_back(package);
   this->children.push_back(package);
 
@@ -392,13 +424,14 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
 
 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
     const std::string& name,
+    const int& type,
     std::string*& result,
     const std::string& path
 )
 {
   if(this->appli != NULL)
     {
-      return this->appli->CreateApplication(name, result);
+      return this->appli->CreateApplication(name, type, result);
     }
   result = new std::string("there is no appli folder in this project.");
   return NULL;
@@ -453,7 +486,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
 
           this->name = this->nameProject = "";
-          for (int i = 0; i < nameBits.size(); i++)
+          for (int i = 0; i < (int)(nameBits.size()); i++)
             {
               if(i != 0)
                 this->name += " ";
@@ -514,7 +547,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
             {
               if (this->appli == NULL)
                 {
-                  this->appli = new modelCDMAppli(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->appli = new modelCDMAppli(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->appli);
                 }
               else
@@ -530,7 +563,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
             {
               if (this->lib == NULL)
                 {
-                  this->lib = new modelCDMLib(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->lib = new modelCDMLib(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->lib);
                 }
               else
@@ -545,11 +578,10 @@ const bool modelCDMProject::Refresh(std::string*& result)
           //if package , create package
           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
             {
-              std::string packageName = stdfileName.substr(5, stdfileName.size()-9);
               bool found = false;
-              for (int i = 0;!found && i < this->packages.size(); i++)
+              for (int i = 0; !found && i < (int)(this->packages.size()); i++)
                 {
-                  if (this->packages[i]->GetName() == packageName)
+                  if (this->packages[i]->GetName() == stdfileName)
                     {
                       found = true;
                       int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
@@ -561,7 +593,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
                 }
               if(!found)
                 {
-                  modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName,this->level + 1);
+                  modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->packages.push_back(package);
                   this->children.push_back(package);
                 }
@@ -571,7 +603,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; !found && i < this->children.size(); i++)
+              for (int i = 0; !found && i < (int)(this->children.size()); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -584,7 +616,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(folder);
                 }
             }
@@ -602,7 +634,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
             {
               if (this->CMakeLists == NULL)
                 {
-                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->CMakeLists);
                 }
               else
@@ -617,7 +649,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < (int)(this->children.size()); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -630,7 +662,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(file);
                 }
             }
@@ -639,7 +671,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checkedPackages.size(); i++)
+  for (int i = 0; i < (int)(checkedPackages.size()); i++)
     {
       if(!checkedPackages[i])
         {
@@ -648,7 +680,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           i--;
         }
     }
-  for (int i = 0; i < checked.size(); i++)
+  for (int i = 0; i < (int)(checked.size()); i++)
     {
       if(!checked[i])
         {
@@ -658,24 +690,413 @@ const bool modelCDMProject::Refresh(std::string*& result)
           i--;
         }
     }
+
   this->SortChildren();
+  std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
   return true;
 }
 
 bool modelCDMProject::ConfigureBuild(std::string*& result)
 {
-  //TODO: implement method
+  //TODO: adjust for windows and mac
+#ifdef _WIN32
+  // ------ Windows
+  if(0 == system("cmake-gui"))
+    return true;
+  else
+    {
+         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.");
+      return false;
+    }
+#elif __APPLE__
+  // ------ Apple
+#else
+  // ------ Linux
+  //open binary folder
+  wxDir dir(crea::std2wx((this->buildPath).c_str()));
+
+  //if folder doesn't exist then create it
+  if (!dir.IsOpened())
+    {
+      //create command line to create folder
+      std::string createComm = "mkdir \"" + this->buildPath + "\"";
+      //execute creation command
+      if (system(createComm.c_str()))
+        {
+          //if there was an error then report it
+          result = new std::string("There was an error creating the build path: \"" + this->buildPath + "\"");
+          return false;
+        }
+    }
+  //create command line to execute ccmake
+  //TODO:: adjust for different Linux distributions
+  std::string confComm = "gnome-terminal --tab --working-directory=\"" + this->buildPath + "\" -e \"ccmake '" + this->path + "'\"";
+  //execute command
+  if(CDMUtilities::openTerminal(confComm))
+    {
+      //if there was an error then report it
+      result = new std::string("There was an error opening the configuration tool in the desired place.");
+      return false;
+    }
+#endif
   return true;
 }
 
-bool modelCDMProject::Build(std::string*& result)
+bool modelCDMProject::Build(std::string*& result, const std::string& line)
 {
-  //TODO: implement method
+  //TODO: adjust for windows and mac
+#ifdef _WIN32
+  // ------ Windows
+       std::string command = "start \"\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\"";
+  //wxMessageBox(crea::std2wx(command), wxT("Project Compilation - Check!"));
+       if(0 == system(command.c_str()))
+    return true;
+  else
+    {
+      result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ installed.");
+         return false;
+    }
+#elif __APPLE__
+  // ------ Apple
+#else
+  // ------ Linux
+  //open binary folder
+  wxDir dir(crea::std2wx((this->buildPath).c_str()));
+
+  //if binary folder can't be opened then return false
+  if (!dir.IsOpened())
+    {
+      result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
+      return false;
+    }
+  //create make command
+  std::string makeComm = "gnome-terminal -e \"bash -c \\\"";
+  for (int i = 0; i < line.size(); i++)
+    {
+      if(line[i] == '"')
+        {
+          makeComm+="\\\\\\\"";
+        }
+      else if(line[i] == '\\')
+        {
+          makeComm+="\\\\\\\\";
+        }
+      else
+        {
+          makeComm.push_back(line[i]);
+        }
+    }
+  makeComm += "; echo -e '\\a'; bash";
+  makeComm += "\\\"\"";
+
+  std::cout << "executing '" << makeComm << "'" << std::endl;
+  //execute make command
+  if(system(makeComm.c_str()))
+    {
+      //if there was an error then report it
+      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.");
+      return false;
+    }
+#endif
   return true;
 }
 
-bool modelCDMProject::Connect(std::string*& result)
+bool modelCDMProject::Connect(std::string*& result, const std::string& folder)
 {
-  //TODO: implement method
+  //TODO: adjust for mac
+#ifdef _WIN32
+  // ------ Windows
+  //open binary folder
+  wxDir dir(crea::std2wx(folder));
+
+  //if binary folder can't be opened then return false
+  if (!dir.IsOpened())
+    {
+      result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
+      return false;
+    }
+  //create plug command
+  std::string plugComm = "bbPlugPackage \"" + folder + "\"";
+  std::cout << "executing '" << plugComm << "'" << std::endl;
+  //execute plug command
+  if(system(std::string("start cmd.exe /k \"" + plugComm + "\"").c_str()))
+    {
+      //if there was an error then report it
+      result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
+      return false;
+    }
+#elif __APPLE__
+  // ------ Apple
+#else
+  // ------ Linux
+  //open binary folder
+  wxDir dir(crea::std2wx(folder));
+
+  //if binary folder can't be opened then return false
+  if (!dir.IsOpened())
+    {
+      result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
+      return false;
+    }
+  //create plug command
+  std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\"";
+
+  std::string Comm = "gnome-terminal -e \"bash -c \\\"";
+    for (int i = 0; i < plugComm.size(); i++)
+      {
+        if(plugComm[i] == '"')
+          {
+            Comm+="\\\\\\\"";
+          }
+        else if(plugComm[i] == '\\')
+          {
+            Comm+="\\\\\\\\";
+          }
+        else
+          {
+            Comm.push_back(plugComm[i]);
+          }
+      }
+    Comm += "; echo -e '\\a'; bash";
+    Comm += "\\\"\"";
+
+
+  std::cout << "executing '" << Comm << "'" << std::endl;
+  //execute plug command
+  if(system(Comm.c_str()))
+    {
+      //if there was an error then report it
+      result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
+      return false;
+    }
+#endif
   return true;
 }
+
+void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
+{
+  //check cmake exist
+  if(this->CMakeLists != NULL)
+    {
+      //set properties parameters based on model
+      properties["project add appli"] = this->appli != NULL;
+      properties["project add lib"] = this->lib != NULL;
+      for (int i = 0; i < (int)(this->packages.size()); i++)
+        properties["project add " + packages[i]->GetName()] = false;
+
+      //open cmakelists
+      std::ifstream confFile;
+      confFile.open((this->CMakeLists->GetPath()).c_str());
+
+      //take everything that is not commented
+      std::string fileContent;
+
+      std::string word;
+      std::vector<std::string> words;
+      while(confFile.is_open() && !confFile.eof())
+        {
+          std::getline(confFile,word, '\n');
+          if(word[0] != '#')
+            {
+              CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
+              if (words.size() > 0)
+                {
+                  word = words[0];
+                  CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
+                  for (int i = 0; i < (int)(words.size()); i++)
+                    {
+                      if(words[i].substr(0,2) == "//")
+                        break;
+                      fileContent += words[i] + " ";
+                    }
+                }
+
+            }
+        }
+
+      //check every instruction
+      std::stringstream ss(fileContent);
+      while(!ss.eof())
+        {
+          std::getline(ss,word, '(');
+
+          //check instruction name
+          CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
+
+          //set instructions
+          if (words.size() > 0 && words[words.size()-1] == "SET")
+            {
+              std::getline(ss,word, ')');
+
+              CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
+              if (words.size() > 1)
+                {
+                  if (words[0] == "USE_CREA" && words[1] == "ON")
+                    {
+                      properties["project set USE_CREA"] = true;
+                    }
+                  else if (words[0] == "USE_GDCM" && words[1] == "ON")
+                    {
+                      properties["project set USE_GDCM"] = true;
+                    }
+                  else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
+                    {
+                      properties["project set USE_GDCM_VTK"] = true;
+                    }
+                  else if (words[0] == "USE_GDCM2" && words[1] == "ON")
+                    {
+                      properties["project set USE_GDCM2"] = true;
+                    }
+                  else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
+                    {
+                      properties["project set USE_WXWIDGETS"] = true;
+                    }
+                  else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
+                    {
+                      properties["project set USE_KWWIDGETS"] = true;
+                    }
+                  else if (words[0] == "USE_VTK" && words[1] == "ON")
+                    {
+                      properties["project set USE_VTK"] = true;
+                    }
+                  else if (words[0] == "USE_ITK" && words[1] == "ON")
+                    {
+                      properties["project set USE_ITK"] = true;
+                    }
+                  else if (words[0] == "USE_BOOST" && words[1] == "ON")
+                    {
+                      properties["project set USE_BOOST"] = true;
+                    }
+                }
+            }
+          //add instructions
+          else if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY")
+            {
+              std::getline(ss,word, ')');
+              //std::cout << word << std::endl;
+              CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
+
+              if (words.size() > 0)
+                {
+                  if(words[0] == "appli")
+                    {
+                      properties["project add "+words[0]] = this->appli != NULL;
+                    }
+                  else if(words[0] == "lib")
+                    {
+                      properties["project add "+words[0]] = this->lib != NULL;
+                    }
+                  else
+                    {
+                      properties["project add "+words[0]] = true;
+                    }
+                }
+            }
+        }
+
+    }
+
+  //check appli's structure
+  this->appli->CheckStructure(properties);
+  //check lib's structure
+  this->lib->CheckStructure(properties);
+  //check packages' structure
+  for (int i = 0; i < (int)(this->packages.size()); i++)
+    {
+      properties["package " + this->packages[i]->GetName()] = true;
+      this->packages[i]->CheckStructure(properties);
+    }
+}
+
+bool modelCDMProject::IsPackageIncluded(const std::string& package_name)
+{
+  if (this->HasCMakeLists())
+    {
+      CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
+      for (int i = 0; i < cmlFile.size(); ++i)
+        {
+          if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY")
+            {
+              int pos = 1;
+              while (pos < cmlFile[i].second.size())
+                {
+                  if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#')
+                    {
+                      if (package_name == cmlFile[i].second[pos])
+                        return true;
+                      break;
+                    }
+                  pos++;
+                }
+            }
+        }
+    }
+  return false;
+
+}
+
+bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude)
+{
+  if (this->HasCMakeLists())
+    {
+      CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
+
+      bool found = false;
+
+      for (int i = 0; i < cmlFile.size(); ++i)
+        {
+          if(toInclude && cmlFile[i].first == "comment")
+            {
+              std::vector<std::string> segments;
+              std::string line = cmlFile[i].second[0];
+              while(line[0] == '#')
+                line.erase(0,1);
+
+              CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties);
+              if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == package_name)
+                {
+                  found = true;
+                  while(cmlFile[i].second[0][0] == '#')
+                    cmlFile[i].second[0].erase(0,1);
+                }
+            }
+          else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY")
+            {
+              int pos = 1;
+              while (pos < cmlFile[i].second.size())
+                {
+                  if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#')
+                    {
+                      if (package_name == cmlFile[i].second[pos])
+                        {
+                          found = true;
+                          if (!toInclude)
+                            {
+                              cmlFile[i].first = "comment";
+                              cmlFile[i].second[0] = "#" + cmlFile[i].second[0];
+                              while (cmlFile[i].second.size() > 1)
+                                {
+                                  cmlFile[i].second[0] += cmlFile[i].second[1];
+                                  cmlFile[i].second.erase(cmlFile[i].second.begin()+1);
+                                }
+
+                            }
+                        }
+                      break;
+                    }
+                  pos++;
+                }
+            }
+        }
+      if (!found && toInclude)
+        {
+          CDMUtilities::syntaxElement element;
+          element.first = "command";
+          element.second.push_back("ADD_SUBDIRECTORY(" + package_name + ")");
+          cmlFile.push_back(element);
+        }
+
+      return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile);
+    }
+  return false;
+}