]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMProject.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMProject.cpp
index 50f6cc24373699ddd13a1fd8113b4daa23edad6b..2996910dc4711d9f2b40a215b04ac443e561c895 100644 (file)
@@ -87,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 += " ";
@@ -248,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)
 {
 
@@ -255,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;
@@ -331,7 +343,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
 
   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];
     }
@@ -339,7 +351,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
   words.clear();
   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];
     }
@@ -347,13 +359,13 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
   words.clear();
   std::string descriptionFixed;
   CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
-  for (int i = 0; i < words.size(); i++)
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       descriptionFixed += words[i];
     }
   words.clear();
   CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
-  for (int i = 0; i < words.size(); i++)
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       descriptionFixed += "_" + words[i];
     }
@@ -457,7 +469,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 += " ";
@@ -550,7 +562,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
             {
               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() == stdfileName)
                     {
@@ -574,7 +586,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)
                     {
@@ -620,7 +632,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)
                     {
@@ -642,7 +654,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])
         {
@@ -651,7 +663,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])
         {
@@ -706,7 +718,7 @@ bool modelCDMProject::ConfigureBuild(std::string*& result)
   return true;
 }
 
-bool modelCDMProject::Build(std::string*& result)
+bool modelCDMProject::Build(std::string*& result, const std::string& line)
 {
   //TODO: adjust for windows and mac
 #ifdef _WIN32
@@ -725,7 +737,25 @@ bool modelCDMProject::Build(std::string*& result)
       return false;
     }
   //create make command
-  std::string makeComm = "make -C \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";
+  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()))
@@ -741,31 +771,166 @@ bool modelCDMProject::Build(std::string*& result)
 bool modelCDMProject::Connect(std::string*& result)
 {
   //TODO: adjust for windows and mac
-  #ifdef _WIN32
-    // ------ Windows
-  #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 plug command
-    std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1";
-    std::cout << "executing '" << plugComm << "'" << std::endl;
-    //execute plug command
-    if(system(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 \"plugging.log\" file located in the build folder to read more about the problem.");
-        return false;
-      }
-  #endif
-    return true;
+#ifdef _WIN32
+  // ------ Windows
+#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 plug command
+  std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1";
+  std::cout << "executing '" << plugComm << "'" << std::endl;
+  //execute plug command
+  if(system(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;
+    }
+#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);
+    }
 }