]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMPackageSrc.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMPackageSrc.cpp
index 06d0c09d2da2c07a48323c63e314cbd1d1490cfb..4654e58cf3a462951eafd26a048c4f4e8c58aa79 100644 (file)
@@ -47,9 +47,10 @@ modelCDMPackageSrc::modelCDMPackageSrc()
   this->CMakeLists = NULL;
 }
 
-modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::string& name, const int& level)
+modelCDMPackageSrc::modelCDMPackageSrc(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
 {
   std::cout << "creating package src: " + path + "\n";
+  this->parent = parent;
   //set attributes
   this->children.clear();
   this->level = level;
@@ -70,7 +71,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin
           std::string stdfileName = crea::wx2std(fileName);
 
           //if is an unknown folder, create folder
-          this->children.push_back(new modelCDMFolder(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+          this->children.push_back(new modelCDMFolder(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
 
           cont = dir.GetNext(&fileName);
         }
@@ -79,7 +80,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin
       if (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          this->CMakeLists = new modelCDMCMakeListsFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+          this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
           this->children.push_back(this->CMakeLists);
         }
 
@@ -87,19 +88,26 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          modelCDMFile* file;
+          std::size_t fileTypePos = stdfileName.find_last_of(".");
+          std::string fileType;
+          if(fileTypePos != std::string::npos)
+            fileType = stdfileName.substr(fileTypePos);
+          else
+            fileType = "";
+
+          modelCDMCodeFile* file;
 
           if(stdfileName.substr(0,2) == "bb")
             {
-              file = new modelCDMFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(file);
-              modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
+              modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
               blackBox->SetHeaderFile(file);
               wxDir dir2(crea::std2wx(path));
               cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES);
               if (cont)
                 {
-                  file = new modelCDMFile(path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
+                  file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1);
                   this->children.push_back(file);
                   blackBox->SetSourceFile(file);
                 }
@@ -115,7 +123,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin
 
 modelCDMPackageSrc::~modelCDMPackageSrc()
 {
-  for (int i = 0; i < this->blackBoxes.size(); i++)
+  for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
     {
       if(this->blackBoxes[i] != NULL)
         {
@@ -144,20 +152,20 @@ modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
 {
   //parse name
   std::vector<std::string> words;
-  CDMUtilities::splitter::split(words, name, " \n\",/\\", CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words, name, " \n\",/\\'", CDMUtilities::splitter::no_empties);
   std::string bbName;
-  for (int i = 0; i < words.size(); i++)
+  for (int i = 0; i < (int)(words.size()); i++)
     {
       bbName += words[i];
     }
 
   //parse categories
-  CDMUtilities::splitter::split(words, categories, " \n\",/\\", CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words, categories, " \n\",/\\'", CDMUtilities::splitter::no_empties);
   std::string bbCategories;
   if(words.size() > 0)
     {
       bbCategories = words[0];
-      for (int i = 1; i < words.size(); i++)
+      for (int i = 1; i < (int)(words.size()); i++)
         {
           bbCategories += "," + words[i];
         }
@@ -166,12 +174,12 @@ modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
     bbCategories = "empty";
 
   //parse authors
-  CDMUtilities::splitter::split(words, authors, "\n\",/\\", CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words, authors, "\n\",/\\'", CDMUtilities::splitter::no_empties);
   std::string bbAuthors;
   if(words.size() > 0)
     {
       bbAuthors = words[0];
-      for (int i = 1; i < words.size(); i++)
+      for (int i = 1; i < (int)(words.size()); i++)
         {
           bbAuthors += "," + words[i];
         }
@@ -180,22 +188,22 @@ modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
     bbAuthors = "Unknown";
 
   //parse description
-  CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\", CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words, authorsEmail, " \n\"/\\'", CDMUtilities::splitter::no_empties);
   std::string bbDescription;
   if(words.size() > 0)
     {
       bbDescription = words[0];
-      for (int i = 1; i < words.size(); i++)
+      for (int i = 1; i < (int)(words.size()); i++)
         {
           bbDescription += "," + words[i];
         }
       bbDescription += " - ";
     }
-  CDMUtilities::splitter::split(words, description, "\n\"/\\", CDMUtilities::splitter::no_empties);
+  CDMUtilities::splitter::split(words, description, "\n\"/\\'", CDMUtilities::splitter::no_empties);
   if(words.size() > 0)
     {
       bbDescription += words[0];
-      for (int i = 1; i < words.size(); i++)
+      for (int i = 1; i < (int)(words.size()); i++)
         {
           bbDescription += words[i];
         }
@@ -208,15 +216,23 @@ modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
   //create command
   std::string command = "bbCreateBlackBox";
   command += " \"" + this->path + "\"";
+#ifdef _WIN32
+  command += " " + package;
+  command += " " + bbName;
+  command += " " + type;
+  command += " " + format;
+#else
   command += " \"" + package + "\"";
   command += " \"" + bbName + "\"";
   command += " \"" + type + "\"";
   command += " \"" + format + "\"";
+#endif
   command += " \"" + bbAuthors + "\"";
   command += " \"" + bbDescription + "\"";
   command += " \"" + bbCategories + "\"";
 
   //excecute command
+  //wxMessageBox(crea::std2wx("Command: ->" + command + "<-"),_T("Creating Black Box"),wxOK | wxICON_INFORMATION);
   if(system(command.c_str()))
     {
       result = new std::string("Error executing command '" + command + "'");
@@ -237,20 +253,20 @@ modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
       if (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          header = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1);
+          header = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
         }
       cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".cxx"), wxDIR_FILES);
       if (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          source = new modelCDMFile(this->path + stdfileName, stdfileName, this->level+1);
+          source = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level+1);
         }
     }
   //if source and header exist
   if (header != NULL && source != NULL)
     {
       //create black box
-      modelCDMBlackBox* blackBox = new modelCDMBlackBox(this->path, package+bbName);
+      modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, this->path, package+bbName);
 
       //associate header and source
       blackBox->SetHeaderFile(header);
@@ -296,7 +312,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
           std::string folderName = stdfileName;
           //check if they 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() == folderName)
                 {
@@ -308,7 +324,7 @@ const bool modelCDMPackageSrc::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);
             }
           cont = dir.GetNext(&fileName);
@@ -318,13 +334,19 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
+          std::size_t fileTypePos = stdfileName.find_last_of(".");
+          std::string fileType;
+          if(fileTypePos != std::string::npos)
+            fileType = stdfileName.substr(fileTypePos);
+          else
+            fileType = "";
 
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
               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
@@ -339,7 +361,7 @@ const bool modelCDMPackageSrc::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)
                     {
@@ -352,8 +374,22 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
-                  this->children.push_back(file);
+                  //if is a code file, create modelCDMCodeFile
+                  if(
+                      fileType == ".c" ||
+                      fileType == ".cxx" ||
+                      fileType == ".h" ||
+                      fileType == ".cpp" ||
+                      fileType == ".txx" ||
+                      fileType == ".cmake" )
+                    {
+                      this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+                    }
+                  else
+                    {
+                      modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                      this->children.push_back(file);
+                    }
                 }
             }
 
@@ -361,7 +397,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
           if(stdfileName.substr(stdfileName.size() - 2, 2) == ".h" && stdfileName.substr(0,2) == "bb")
             {
               bool found = false;
-              for (int i = 0; i < this->blackBoxes.size(); i++)
+              for (int i = 0; i < (int)(this->blackBoxes.size()); i++)
                 {
                   if(this->blackBoxes[i]->GetHeaderFile()->GetName() == stdfileName)
                     {
@@ -375,7 +411,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
 
               if (!found)
                 {
-                  modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
+                  modelCDMBlackBox* blackBox = new modelCDMBlackBox(this, path, stdfileName.substr(2,stdfileName.size()-4), level + 1);
                   this->blackBoxes.push_back(blackBox);
                 }
 
@@ -385,7 +421,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checkedBoxes.size(); i++)
+  for (int i = 0; i < (int)(checkedBoxes.size()); i++)
     {
       if(!checkedBoxes[i])
         {
@@ -396,7 +432,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checked.size(); i++)
+  for (int i = 0; i < (int)(checked.size()); i++)
     {
       if(!checked[i])
         {