]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMProject.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMProject.cpp
index 7cadb24241c62d308236cfbf0bfe020b406b68af..23dd1666d041bbc0a186c7628e0adebcb00d9914 100644 (file)
@@ -244,12 +244,63 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
     std::string*& result,
     const std::string& authors,
     const std::string& authorsEmail,
-    const std::string& version,
-    const std::string& description
+    const std::string& description,
+    const std::string& version
 )
 {
-  //TODO: implement method
-  return NULL;
+  //fixing input parameters
+  std::vector<std::string> words;
+
+  CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
+  std::string nameFixed = "";
+  for (int i = 0; i < words.size(); i++)
+    {
+      nameFixed += words[i];
+    }
+
+  words.clear();
+  CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
+  std::string authorFixed;
+  for (int i = 0; i < 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++)
+    {
+      descriptionFixed += words[i];
+    }
+  words.clear();
+  CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
+  for (int i = 0; i < words.size(); i++)
+    {
+      descriptionFixed += "_" + words[i];
+    }
+
+  //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()))
+    {
+      result = new std::string("An error occurred while running '" + creationCommand + "'.");
+      return NULL;
+    }
+
+  //add library to model
+  //TODO: fix for windows
+  modelCDMPackage* package = new modelCDMPackage(this->path + "/bbtk_" + nameFixed + "_PKG", this->level + 1);
+  this->packages.push_back(package);
+  this->children.push_back(package);
+
+  //TODO: set package version
+
+  this->SortChildren();
+
+  result = new std::string(this->path + "/" + name);
+  return package;
 }
 
 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
@@ -272,8 +323,12 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
     const std::string& path
 )
 {
-  //TODO: implement method
-  return NULL;
+  if(this->appli != NULL)
+      {
+        return this->appli->CreateApplication(name, result);
+      }
+    result = new std::string("there is no appli folder in this project.");
+    return NULL;
 }
 
 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
@@ -512,8 +567,8 @@ const bool modelCDMProject::Refresh(std::string*& result)
       if(!checkedPackages[i])
         {
           this->packages.erase(this->packages.begin()+i);
-                    checkedPackages.erase(checkedPackages.begin()+i);
-                    i--;
+          checkedPackages.erase(checkedPackages.begin()+i);
+          i--;
         }
     }
   for (int i = 0; i < checked.size(); i++)