]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMMain.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMMain.cpp
index 25331dc7c1d1403dda1ee3cddbf04ad81a348438..7b47e90035841b8cafb42d19a26113b6246ba121 100644 (file)
@@ -83,35 +83,49 @@ bool modelCDMMain::CreateProject(
   std::string command2("del ");
 
   command  += "\"" + locationFixed + "\" \"" + name + "\"";
-  command1 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + locationFixed + "\\" + name + "\\CMakeLists.txt\"";
-  command2 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\"";
-
+  command1 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\" " + "PROJECT_NAME " + name + "> \"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+  command2 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\"";
 
   if (system (command.c_str()))
     {
-      result = new std::string("An error occured while running '" + command + "'.");
+      result = new std::string("An error occurred while running '" + command + "'.");
       return false;
     }
 
-  system ( command1.c_str() );
-  system ( command2.c_str() );
+  if (system (command1.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + command1 + "'.");
+      return false;
+    }
+  if (system (command2.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + command2 + "'.");
+      return false;
+    }
 
-  char *author = author.c_str();
-  std::string nomDirectory = locationFixed + "\\" + name;
-  std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG";
+  std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
+  std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
   std::string bbCreatePackage("bbCreatePackage ");
-  bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
-  system (bbCreatePackage.c_str());
+  bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
+  if (!system (bbCreatePackage.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + bbCreatePackage + "'.");
+         return false;
+    }
   std::string add;
-  add = "echo ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG) >> " + nomDirectory + "/CMakeLists.txt";
-  system(add.c_str());
+  add = "echo ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG) >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
+  if (system (add.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + add + "'.");
+         return false;
+    }
 
-  this->project = new modelCDMProject(nomDirectory);
+  this->project = new modelCDMProject(NULL, nomDirectory, name);
 
 #else
   // ------ LINUX / MacOS
   std::string command("creaNewProject.sh ");
-  command += "\"" + locationFixed + "\"" +" " + name;
+  command += "\"" + locationFixed + "\"" +" \"" + name + "\"";
   //std::cout << "executing " << command << std::endl;
   if (system ( command.c_str() ) )
     {
@@ -119,22 +133,27 @@ bool modelCDMMain::CreateProject(
       return false;
     }
 
-  std::string nomDirectory = locationFixed + "/" + name;
-  std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG";
+  std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
+  std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
 
   std::string bbCreatePackage("bbCreatePackage ");
-  bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
+  bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
   //std::cout << "executing " << bbCreatePackage << std::endl;
   system (bbCreatePackage.c_str());
 
   std::string add;
-  add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
+  add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG)' >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
 
   //std::cout << "executing " << add << std::endl;
   system(add.c_str());
 
+  if(this->project != NULL)
+    {
+      if (!CloseProject(result))
+        return false;
+    }
 
-  this->project = new modelCDMProject(nomDirectory);
+  this->project = new modelCDMProject(NULL, nomDirectory, name);
 
 #endif
 
@@ -156,7 +175,7 @@ bool modelCDMMain::OpenProject(
   std::string pathBuild = "";
 
   //check if Makefile file exists
-  std::string pathMakefile = pathFixed + "/Makefile";
+  std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
   FILE* pFile = fopen(pathMakefile.c_str(), "r");
 
   //is the binary folder
@@ -186,7 +205,7 @@ bool modelCDMMain::OpenProject(
   bool isSource = false;
   std::string pathSource = "";
   //check if CMakeLists file exists
-  std::string pathCMakeLists = pathFixed + "/CMakeLists.txt";
+  std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
   pFile = fopen(pathCMakeLists.c_str(), "r");
 
   //is the source folder
@@ -216,15 +235,24 @@ bool modelCDMMain::OpenProject(
   //if is source folder
   if(isSource)
     {
+      if(this->project != NULL)
+        {
+          if (!CloseProject(result))
+            return false;
+        }
+      std::vector<std::string> words;
+      CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties);
+
       std::cout << "Project sources at: " << pathSource << std::endl;
       if(isBinary)
         {
           std::cout << ", and built in: " << pathBuild << std::endl;
-          this->project = new modelCDMProject(pathSource, pathBuild);
+
+          this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1], pathBuild);
         }
       else
         {
-          this->project = new modelCDMProject(pathSource);
+          this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1]);
         }
     }
   else
@@ -240,14 +268,37 @@ bool modelCDMMain::RefreshProject(
     std::string*& result
 )
 {
-  //TODO: recreate the project using the project's path
-  return true;
+  //recreate the project using the project's path
+  if (this->project != NULL)
+    {
+      return this->project->Refresh(result);
+    }
+  else
+    {
+      result = new std::string("There is no open project.");
+      return false;
+    }
+}
+
+std::map<wxTreeItemId, modelCDMIProjectTreeNode*>& modelCDMMain::GetModelElements()
+{
+  return this->modelElements;
 }
 
 bool modelCDMMain::CloseProject(
     std::string*& result
 )
 {
-  //TODO: delete the project tree and leave it as NULL
-  return true;
+  //delete the project tree and leave it as NULL
+  if (this->project != NULL)
+    {
+      delete this->project;
+      this->project = NULL;
+      return true;
+    }
+  else
+    {
+      result = new std::string("There is no open project.");
+      return false;
+    }
 }