]> Creatis software - crea.git/commitdiff
Feature #1711
authorDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Fri, 28 Dec 2012 16:53:57 +0000 (17:53 +0100)
committerDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Fri, 28 Dec 2012 16:53:57 +0000 (17:53 +0100)
CreaDevManager application implementation

-Fixed bug with refresh where all elements were being recreated.
-Black box creation implemented

15 files changed:
lib/creaDevManagerLib/modelCDMAppli.cpp
lib/creaDevManagerLib/modelCDMApplication.cpp
lib/creaDevManagerLib/modelCDMBlackBox.cpp
lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp
lib/creaDevManagerLib/modelCDMFile.cpp
lib/creaDevManagerLib/modelCDMFolder.cpp
lib/creaDevManagerLib/modelCDMLib.cpp
lib/creaDevManagerLib/modelCDMLibrary.cpp
lib/creaDevManagerLib/modelCDMPackage.cpp
lib/creaDevManagerLib/modelCDMPackage.h
lib/creaDevManagerLib/modelCDMPackageSrc.cpp
lib/creaDevManagerLib/modelCDMPackageSrc.h
lib/creaDevManagerLib/modelCDMProject.cpp
lib/creaDevManagerLib/wxCDMMainFrame.cpp
lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp

index d15bc4f554bdb5dcc1255824f38b6972e59688ec..c92932a1c5583de3c0a9f6795d926fefe26cc13d 100644 (file)
@@ -48,6 +48,7 @@ modelCDMAppli::modelCDMAppli()
 
 modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating appli\n";
   this->type = wxDIR_DIRS;
   this->name = name;
   this->level = level;
@@ -97,6 +98,7 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, c
 
     }
   this->SortChildren();
+  std::sort(this->applications.begin(), this->applications.end(), CompareNodeItem);
 }
 
 modelCDMAppli::~modelCDMAppli()
@@ -176,7 +178,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
           std::string applicationName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->applications.size(); i++)
+          for (int i = 0; !found && i < this->applications.size(); i++)
             {
               if (this->applications[i]->GetName() == applicationName)
                 {
@@ -222,7 +224,7 @@ const bool modelCDMAppli::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -264,5 +266,6 @@ const bool modelCDMAppli::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->applications.begin(), this->applications.end(), CompareNodeItem);
   return true;
 }
index e8af2cf6649aac6d578c2972aa63146c34aea20e..57770444d31e13ad6df5c98617f5b83ab7a9cb1e 100644 (file)
@@ -47,6 +47,7 @@ modelCDMApplication::modelCDMApplication()
 
 modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating application: " + path + "\n";
   //folder name
   this->name = name;
   //path
@@ -129,6 +130,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const std::str
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMApplication::~modelCDMApplication()
@@ -204,6 +206,7 @@ modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::
 
 const bool modelCDMApplication::Refresh(std::string*& result)
 {
+  std::cout << "refreshing application: " << this->executableName << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -257,7 +260,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
           std::string applicationName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->folders.size(); i++)
+          for (int i = 0; !found && i < this->folders.size(); i++)
             {
               if (this->folders[i]->GetName() == applicationName)
                 {
@@ -303,7 +306,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
index 4d834927d61e08d6e3609d4b889ec595e5c732fe..daec9d4b8bf864997ad72cec4e5df6e2c2813619 100644 (file)
@@ -49,6 +49,7 @@ modelCDMBlackBox::modelCDMBlackBox()
 
 modelCDMBlackBox::modelCDMBlackBox(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating black box: " + name + " in " + path + "\n";
   this->name = name;
   this->path = path;
   this->level = level;
@@ -332,6 +333,7 @@ modelCDMFile* modelCDMBlackBox::GetSourceFile() const
 
 const bool modelCDMBlackBox::Refresh(std::string*& result)
 {
+  std::cout << "refreshing black box: " << this->nameBlackBox << std::endl;
   std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h";
 
   std::ifstream confFile;
index dfbb99958af7655d8cfb22f3c34a8125dd205a00..72b1cdf4378bdc7d379065177cf09811a698e7b6 100644 (file)
@@ -47,6 +47,7 @@ modelCDMCMakeListsFile::modelCDMCMakeListsFile()
 
 modelCDMCMakeListsFile::modelCDMCMakeListsFile(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating cmakelist file: " + path + "\n";
   this->children.clear();
   this->level = level;
   this->type = wxDIR_FILES;
@@ -77,6 +78,7 @@ bool modelCDMCMakeListsFile::OpenFile(std::string*& result)
 
 const bool modelCDMCMakeListsFile::Refresh(std::string*& result)
 {
+  //std::cout << "refreshing cmakelists" << std::endl;
   std::ifstream in((this->path).c_str());
   if(!in.is_open())
     {
index 039de4784d1e55e029e84429a73f7b6ea8a0d98b..3f92ffe9b29a2a81e43b41db285c0860092ff0be 100644 (file)
@@ -46,6 +46,7 @@ modelCDMFile::modelCDMFile()
 
 modelCDMFile::modelCDMFile(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating file: " + path + "\n";
   this->children.clear();
   this->level = level;
   this->name = name;
@@ -76,6 +77,7 @@ bool modelCDMFile::OpenFile(std::string*& result, const std::string& command)
 
 const bool modelCDMFile::Refresh(std::string*& result)
 {
+  //std::cout << "refreshing file " << this->name << std::endl;
   std::ifstream in((this->path).c_str());
   if(!in.is_open())
     {
index c1ef911dfd0b9efce843b402adc4529efd1dea1a..3365c099b9adfd64c246ff7b7f04a92636a6df02 100644 (file)
@@ -49,6 +49,7 @@ modelCDMFolder::modelCDMFolder()
 
 modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating folder: " + path + "\n";
   //set attributes
   this->children.clear();
   this->level = level;
@@ -70,7 +71,9 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
           std::string stdfileName = crea::wx2std(fileName);
 
           //if is an unknown folder, create folder
-          this->children.push_back(new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+          modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+          this->children.push_back(folder);
+          this->folders.push_back(folder);
 
           cont = dir.GetNext(&fileName);
         }
@@ -96,6 +99,7 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
     }
 
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMFolder::~modelCDMFolder()
@@ -147,6 +151,7 @@ bool modelCDMFolder::OpenCMakeListsFile(std::string*& result)
 
 const bool modelCDMFolder::Refresh(std::string*& result)
 {
+  //std::cout << "refreshing folder " << this->name << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -163,12 +168,11 @@ const bool modelCDMFolder::Refresh(std::string*& result)
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          std::string folderName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->folders.size(); i++)
+          for (int i = 0; !found && i < this->folders.size(); i++)
             {
-              if (this->folders[i]->GetName() == folderName)
+              if (this->folders[i]->GetName() == stdfileName)
                 {
                   found = true;
                   int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
@@ -213,7 +217,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0;!found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -255,6 +259,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
   return true;
 }
 
index 416c1ff5230050f9bbf21726e2358c6929db00f9..8ebd9ae100555df4211fdc2149729e3b7081062e 100644 (file)
@@ -47,6 +47,7 @@ modelCDMLib::modelCDMLib()
 
 modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating lib\n";
   this->type = wxDIR_DIRS;
   this->name = name;
   this->level = level;
@@ -97,6 +98,7 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const
         }
     }
   this->SortChildren();
+  std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem);
 }
 
 modelCDMLib::~modelCDMLib()
@@ -178,7 +180,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
           std::string libraryName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->libraries.size(); i++)
+          for (int i = 0; !found && i < this->libraries.size(); i++)
             {
               if (this->libraries[i]->GetName() == libraryName)
                 {
@@ -224,7 +226,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -266,5 +268,6 @@ const bool modelCDMLib::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem);
   return true;
 }
index e16eeae0d0d32e4f1f053dde796ada9f0276abb3..1964e882c02b6ab3192b5978c7c9139403200db6 100644 (file)
@@ -47,6 +47,7 @@ modelCDMLibrary::modelCDMLibrary()
 
 modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating library: " + path + "\n";
   //folder name
   this->name = name;
   //path
@@ -131,6 +132,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& nam
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMLibrary::~modelCDMLibrary()
@@ -206,6 +208,7 @@ modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::stri
 
 const bool modelCDMLibrary::Refresh(std::string*& result)
 {
+  std::cout << "refreshing library: " << this->nameLibrary << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -256,12 +259,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          std::string folderName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->folders.size(); i++)
+          for (int i = 0; !found && i < this->folders.size(); i++)
             {
-              if (this->folders[i]->GetName() == folderName)
+              if (this->folders[i]->GetName() == stdfileName)
                 {
                   found = true;
                   int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
@@ -301,11 +303,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
                     return false;
                 }
             }
-          //if is an unknown file, create file
+          //if is an unknown file, check if exist in children
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -347,5 +349,6 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
   return true;
 }
index a2ee6c8669d8e7b7f1f890e3c33e24990e758b56..cd24c04f04b8df0e69bc3f90c22e9a9dcd1a6b41 100644 (file)
@@ -48,6 +48,7 @@ modelCDMPackage::modelCDMPackage()
 
 modelCDMPackage::modelCDMPackage(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating package: " + path + "\n";
   this->type = wxDIR_DIRS;
   this->name = name;
   //Get Package Name
@@ -351,22 +352,22 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string
 }
 
 modelCDMBlackBox* modelCDMPackage::CreateBlackBox(
+    std::string*& result,
     const std::string& name,
     const std::string& type,
     const std::string& format,
+    const std::string& categories,
     const std::string& authors,
     const std::string& authorsEmail,
-    const std::string& categories,
     const std::string& description
 )
 {
-  //TODO: implement method
-  return NULL;
+  return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description);
 }
 
 const bool modelCDMPackage::Refresh(std::string*& result)
 {
-  std::cout << "refreshing package" << std::endl;
+  std::cout << "refreshing package " << this->namePackage << std::endl;
   this->type = wxDIR_DIRS;
 
   //Get Package Name
@@ -481,7 +482,7 @@ const bool modelCDMPackage::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 < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -526,7 +527,7 @@ const bool modelCDMPackage::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
index 3745fb2154c41227c5cace3c99502350c3a00afc..67e69577ee3ef572f13cf82b74f838b1708cd173 100644 (file)
@@ -62,12 +62,13 @@ public:
 
 
   modelCDMBlackBox* CreateBlackBox(
+      std::string*& result,
       const std::string& name,
       const std::string& type = "std",
       const std::string& format = "C++",
+      const std::string& categories = "empty",
       const std::string& authors = "unknown",
       const std::string& authorsEmail = "",
-      const std::string& categories = "empty",
       const std::string& description = "no description"
   );
   virtual const bool Refresh(std::string*& result);
index 16e7e59b0b65cd67829cec8f41cabbd4eaad3d75..06d0c09d2da2c07a48323c63e314cbd1d1490cfb 100644 (file)
@@ -49,6 +49,7 @@ modelCDMPackageSrc::modelCDMPackageSrc()
 
 modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating package src: " + path + "\n";
   //set attributes
   this->children.clear();
   this->level = level;
@@ -109,6 +110,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::strin
     }
 
   this->SortChildren();
+  std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
 }
 
 modelCDMPackageSrc::~modelCDMPackageSrc()
@@ -130,21 +132,151 @@ const std::vector<modelCDMBlackBox*>& modelCDMPackageSrc::GetBlackBoxes() const
 }
 
 modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox(
+    std::string*& result,
     const std::string& name,
     const std::string& package,
     const std::string& type,
     const std::string& format,
+    const std::string& categories,
     const std::string& authors,
     const std::string& authorsEmail,
-    const std::string& categories,
     const std::string& description)
 {
-  //TODO: implement method
-  return NULL;
+  //parse name
+  std::vector<std::string> words;
+  CDMUtilities::splitter::split(words, name, " \n\",/\\", CDMUtilities::splitter::no_empties);
+  std::string bbName;
+  for (int i = 0; i < words.size(); i++)
+    {
+      bbName += words[i];
+    }
+
+  //parse categories
+  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++)
+        {
+          bbCategories += "," + words[i];
+        }
+    }
+  if(bbCategories == "")
+    bbCategories = "empty";
+
+  //parse authors
+  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++)
+        {
+          bbAuthors += "," + words[i];
+        }
+    }
+  if(bbAuthors == "")
+    bbAuthors = "Unknown";
+
+  //parse description
+  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++)
+        {
+          bbDescription += "," + words[i];
+        }
+      bbDescription += " - ";
+    }
+  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++)
+        {
+          bbDescription += words[i];
+        }
+    }
+
+  if(bbDescription == "")
+    bbDescription = "No Description.";
+
+
+  //create command
+  std::string command = "bbCreateBlackBox";
+  command += " \"" + this->path + "\"";
+  command += " \"" + package + "\"";
+  command += " \"" + bbName + "\"";
+  command += " \"" + type + "\"";
+  command += " \"" + format + "\"";
+  command += " \"" + bbAuthors + "\"";
+  command += " \"" + bbDescription + "\"";
+  command += " \"" + bbCategories + "\"";
+
+  //excecute command
+  if(system(command.c_str()))
+    {
+      result = new std::string("Error executing command '" + command + "'");
+      return NULL;
+    }
+
+  //if command succeed
+
+  //create header
+  //create source
+  modelCDMFile* header = NULL;
+  modelCDMFile* source = NULL;
+  wxDir dir(crea::std2wx(path));
+  if (dir.IsOpened())
+    {
+      wxString fileName;
+      bool cont = dir.GetFirst(&fileName, crea::std2wx("bb"+package+bbName+".h"), wxDIR_FILES);
+      if (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+          header = new modelCDMFile(this->path + 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);
+        }
+    }
+  //if source and header exist
+  if (header != NULL && source != NULL)
+    {
+      //create black box
+      modelCDMBlackBox* blackBox = new modelCDMBlackBox(this->path, package+bbName);
+
+      //associate header and source
+      blackBox->SetHeaderFile(header);
+      blackBox->SetSourceFile(source);
+
+      this->children.push_back(header);
+      this->children.push_back(source);
+
+      this->blackBoxes.push_back(blackBox);
+
+      //sort children
+      std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
+      this->SortChildren();
+
+      return blackBox;
+    }
+  else
+    {
+      result = new std::string("The header and source files were not found. Black box not created.");
+      return NULL;
+    }
 }
 
 const bool modelCDMPackageSrc::Refresh(std::string*& result)
 {
+  std::cout << "refreshing package src" << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -164,7 +296,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 < this->children.size(); i++)
             {
               if (this->children[i]->GetName() == folderName)
                 {
@@ -207,7 +339,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -275,5 +407,6 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->blackBoxes.begin(), this->blackBoxes.end(), CompareNodeItem);
   return true;
 }
index d94afbdd5b0c208788e1286c4d56dfd04c6911db..bb799c394b13909c116e90169412b3b1fdde0d84 100644 (file)
@@ -51,6 +51,7 @@ public:
   const std::vector<modelCDMBlackBox*>& GetBlackBoxes() const;
 
   modelCDMBlackBox* CreateBlackBox(
+      std::string*& result,
       const std::string& name,
       const std::string& package,
       const std::string& type = "std",
index 8206a75bae273f9ed7d20538a73a1ecbbbce0909..c844798f12aca27205df8eea930e35bc6ad02c4d 100644 (file)
@@ -59,6 +59,7 @@ modelCDMProject::modelCDMProject(
     const std::string& buildPath
 )
 {
+  std::cout << "creating project: " + name + " in " + path + "\n";
   this->path = CDMUtilities::fixPath(path);
   //open makelists file
   std::string pathFixed(CDMUtilities::fixPath(path));
@@ -202,6 +203,7 @@ modelCDMProject::modelCDMProject(
     }
 
   this->SortChildren();
+  std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
 
 }
 
@@ -545,11 +547,10 @@ const bool modelCDMProject::Refresh(std::string*& result)
           //if package , create package
           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
             {
-              std::string packageName = stdfileName.substr(5, stdfileName.size()-9);
               bool found = false;
-              for (int i = 0;!found && i < this->packages.size(); i++)
+              for (int i = 0; !found && i < this->packages.size(); i++)
                 {
-                  if (this->packages[i]->GetName() == packageName)
+                  if (this->packages[i]->GetName() == stdfileName)
                     {
                       found = true;
                       int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
@@ -561,7 +562,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
                 }
               if(!found)
                 {
-                  modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName,this->level + 1);
+                  modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->packages.push_back(package);
                   this->children.push_back(package);
                 }
@@ -617,7 +618,7 @@ const bool modelCDMProject::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -658,7 +659,9 @@ const bool modelCDMProject::Refresh(std::string*& result)
           i--;
         }
     }
+
   this->SortChildren();
+  std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
   return true;
 }
 
index ed3b6de98c8dd075705a8255d8b84b3ef2c9e308..7f5fc3afe4b8fda83ee96f92411e9c138b4aa96a 100755 (executable)
@@ -899,6 +899,7 @@ void wxCDMMainFrame::OnCreationComplete(wxCommandEvent& event)
       }
     else if(event.GetString() == wxT("blackbox"))
       {
+        this->tree_Projects->SelectItem(this->model->GetProject()->GetId(), false);
         modelCDMBlackBox* bb = (modelCDMBlackBox*)event.GetClientData();
         description = new wxCDMBlackBoxDescriptionPanel(
             this,
index 4411c9eeb5cc9963864c7c8e4090aa35b64cd413..00858bddbd9ccfb91596a91ac6b132a3bdcbba51 100644 (file)
@@ -39,6 +39,7 @@
 #include "creaDevManagerIds.h"
 #include "images/PkIcon64.xpm"
 
+#include "wxCDMNewBlackBoxDialog.h"
 #include <wx/textdlg.h>
 #include "CDMUtilities.h"
 
@@ -325,9 +326,45 @@ void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
 
 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
-  event.Skip();
+
+  wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
+  long userResponse;
+  userResponse = dialog->ShowModal();
+
+  if(userResponse == wxID_FORWARD)
+    {
+      std::string* result;
+      //create black box
+      modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
+          result,
+          crea::wx2std(dialog->GetBlackBoxName()),
+          crea::wx2std(dialog->GetBlackBoxType()),
+          crea::wx2std(dialog->GetBlackBoxFormat()),
+          crea::wx2std(dialog->GetBlackBoxCategories()),
+          crea::wx2std(dialog->GetBlackBoxAuthor()),
+          crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
+          crea::wx2std(dialog->GetBlackBoxDescription())
+      );
+      //check black box created
+      if(blackBox == NULL)
+        {
+          wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
+          return;
+        }
+      wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
+
+      //refreshing tree and description
+      //send event instead of calling parent to avoid crashing
+
+      ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
+
+      wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+      newEvent->SetId(1);
+      newEvent->SetInt(blackBox->GetId());
+      newEvent->SetString(wxT("blackbox"));
+      newEvent->SetClientData(blackBox);
+      wxPostEvent(this->GetParent(), *newEvent);
+    }
 }
 
 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)