]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMAppli.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMAppli.cpp
index 417392792399e8024b7eed70ae5b7101c762f655..4f61e13de3c84c765474ec4d709b798e46a5a265 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <iostream>
 #include <fstream>
+#include <sstream>
 #include <algorithm>
 
 #include "CDMUtilities.h"
@@ -46,9 +47,10 @@ modelCDMAppli::modelCDMAppli()
 {
 }
 
-modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, const int& level)
+modelCDMAppli::modelCDMAppli(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
 {
   std::cout << "creating appli\n";
+  this->parent = parent;
   this->type = wxDIR_DIRS;
   this->name = name;
   this->level = level;
@@ -71,13 +73,13 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, c
 
           if(stdfileName != "template_appli" && stdfileName != "template_wx_appli")
             {
-              modelCDMApplication* application = new modelCDMApplication(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              modelCDMApplication* application = new modelCDMApplication(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->applications.push_back(application);
               this->children.push_back(application);
             }
           else
             {
-              modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              modelCDMFolder* folder = new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(folder);
             }
 
@@ -92,13 +94,13 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, c
           //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);
             }
           //if is an unknown file, create file
           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));
             }
 
           cont = dir.GetNext(&fileName);
@@ -156,7 +158,7 @@ modelCDMApplication* modelCDMAppli::CreateApplication(
     }
 
   //add application to model
-  modelCDMApplication* application = new modelCDMApplication(this->path + CDMUtilities::SLASH + name, name, this->level + 1);
+  modelCDMApplication* application = new modelCDMApplication(this, this->path + CDMUtilities::SLASH + name, name, this->level + 1);
   this->applications.push_back(application);
   this->children.push_back(application);
 
@@ -189,7 +191,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
               std::string applicationName = stdfileName;
               //check if application already exist
               bool found = false;
-              for (int i = 0; !found && i < this->applications.size(); i++)
+              for (int i = 0; !found && i < (int)(this->applications.size()); i++)
                 {
                   if (this->applications[i]->GetName() == applicationName)
                     {
@@ -203,7 +205,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
                 }
               if(!found)
                 {
-                  modelCDMApplication* application= new modelCDMApplication(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  modelCDMApplication* application= new modelCDMApplication(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->applications.push_back(application);
                   this->children.push_back(application);
                 }
@@ -212,7 +214,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
             {
               //check if folder already exist
               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)
                     {
@@ -225,7 +227,7 @@ const bool modelCDMAppli::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);
                 }
             }
@@ -242,7 +244,7 @@ const bool modelCDMAppli::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
@@ -257,7 +259,7 @@ const bool modelCDMAppli::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)
                     {
@@ -270,7 +272,7 @@ const bool modelCDMAppli::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);
                 }
             }
@@ -279,7 +281,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checkedApplications.size(); i++)
+  for (int i = 0; i < (int)(checkedApplications.size()); i++)
     {
       if(!checkedApplications[i])
         {
@@ -288,7 +290,7 @@ const bool modelCDMAppli::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])
         {
@@ -302,3 +304,76 @@ const bool modelCDMAppli::Refresh(std::string*& result)
   std::sort(this->applications.begin(), this->applications.end(), CompareNodeItem);
   return true;
 }
+
+void modelCDMAppli::CheckStructure(std::map<std::string, bool>& properties)
+{
+  //check cmake exist
+  if(this->CMakeLists != NULL)
+    {
+      //set properties parameters based on model
+      for (int i = 0; i < (int)(this->applications.size()); i++)
+        properties["appli add " + this->applications[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);
+
+          //add instructions
+          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)
+                {
+                  {
+                    properties["appli add " + words[0]] = true;
+                  }
+                }
+            }
+        }
+
+    }
+
+  //check libraries' structure
+  for (int i = 0; i < (int)(this->applications.size()); i++)
+    {
+      properties["application " + this->applications[i]->GetName()] = true;
+      this->applications[i]->CheckStructure(properties);
+    }
+}