]> Creatis software - crea.git/commitdiff
Feature #1711 CreaDevManager application implementation
authorDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Mon, 8 Apr 2013 16:13:01 +0000 (18:13 +0200)
committerDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Mon, 8 Apr 2013 16:13:01 +0000 (18:13 +0200)
Feature: Now reading CMakeLists in CDMUtilities as a data structure.
Fix: Dialog Format on Included Libraries section in Applications, Libraries, Packages.

lib/creaDevManagerLib/CDMUtilities.cpp
lib/creaDevManagerLib/CDMUtilities.h
lib/creaDevManagerLib/modelCDMLibrary.cpp
lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp
lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp
lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp

index b4696b1104177d6949398c58a0d5638d631cef95..77f5f52cb7b199ec3efb419551f6b7cea640b80a 100644 (file)
@@ -356,4 +356,154 @@ namespace CDMUtilities
        return res;
   }
 
+  CMLFile readCMLFile(const std::string& file_path)
+  {
+    CMLFile res;
+
+    std::ifstream file(file_path.c_str());
+    if (file.is_open())
+      {
+        char ch = file.get();
+        while (!file.eof())
+          {
+            syntaxElement element;
+            if (isspace(ch))
+              {
+                //std::cout << "space" << std::endl;
+                element.first = "space";
+                element.second.push_back(std::string(1,ch));
+              }
+            else if (ch == '#')
+              {
+                //std::cout << "comment" << std::endl;
+                element.first = "comment";
+                std::string commentValue;
+                while (ch != '\n')
+                  {
+                    commentValue.push_back(ch);
+
+                    ch = file.get();
+                    if (file.eof())
+                      break;
+                  };
+                if (!file.eof())
+                  commentValue.push_back('\n');
+                element.second.push_back(commentValue);
+              }
+            else
+              {
+                //std::cout << "command" << std::endl;
+                element.first = "command";
+                std::string commandValue;
+                while (true)
+                  {
+                    //std::cout << ch;
+                    //std::cout.flush();
+                    while(!isspace(ch) && ch != '(' && ch != ')' && ch != '#')
+                      {
+                        if(ch == '"')
+                          {
+                            if (commandValue.size()) {
+                              element.second.push_back(commandValue);
+                              commandValue.clear();
+                            }
+                            commandValue.push_back(ch);
+                            ch = file.get();
+                            while(!file.eof() && ch != '"')
+                              {
+                                if(ch == '\\')
+                                  {
+                                    commandValue.push_back(ch);
+                                    ch = file.get();
+                                    if(!file.eof())
+                                      commandValue.push_back(ch);
+                                  }
+                                else
+                                  {
+                                    commandValue.push_back(ch);
+                                  }
+                                ch = file.get();
+                              }
+                            if(!file.eof())
+                              commandValue.push_back(ch);
+                            element.second.push_back(commandValue);
+                            commandValue.clear();
+                          }
+                        else
+                          commandValue.push_back(ch);
+
+                        ch = file.get();
+                      }
+
+                    if (!file.eof() && (isspace(ch) || ch == '(' || ch == ')' || ch == '#'))
+                      {
+                        if (commandValue.size()) {
+                          element.second.push_back(commandValue);
+                          commandValue.clear();
+                        }
+                        commandValue.push_back(ch);
+                        if (ch == '#') {
+                          while (ch != '\n') {
+                            ch = file.get();
+                            if (file.eof())
+                              break;
+                            commandValue.push_back(ch);
+                          };
+                        }
+                        element.second.push_back(commandValue);
+                        if (commandValue == ")")
+                          {
+                            commandValue.clear();
+                            break;
+                          }
+                        commandValue.clear();
+                      }
+
+                    ch = file.get();
+                    if (file.eof())
+                      break;
+                  }
+              }
+            res.push_back(element);
+
+            ch = file.get();
+            if (file.eof())
+              break;
+          }
+
+        file.close();
+      }
+
+/*
+    std::cout << "CMakeLists: " << file_path << std::endl;
+    for (int i = 0; i < res.size(); ++i) {
+      if (res[i].first == "command")
+        std::cout << "@";
+      for (int j = 0; j < res[i].second.size(); ++j) {
+        std::cout << "~" << res[i].second[j];
+      }
+      if (res[i].first == "command")
+        std::cout << "@";
+    }
+    std::cout << "End of file" << std::endl;
+*/
+    return res;
+  }
+
+  bool writeCMLFile(const std::string& file_path, const CMLFile& data)
+  {
+    std::ofstream file(file_path.c_str());
+    if(file.is_open())
+      {
+        for (int i = 0; i < data.size(); ++i) {
+          for (int j = 0; j < data[i].second.size(); ++j) {
+            file << data[i].second[j];
+          }
+        }
+        file.close();
+        return true;
+      }
+    return false;
+  }
+
 }
index 5430aea2a9c97d770162aeb1ca398783eccf660c..f807d3262b59df22e837f09a8d71834e28655a02 100644 (file)
@@ -36,6 +36,7 @@
 #define CDMUTILITIES_H_
 
 #include<iostream>
+#include<vector>
 #include<cstddef>
 
 namespace CDMUtilities
@@ -175,6 +176,43 @@ namespace CDMUtilities
    * @return line stringified.
    */
   std::string stringify(const std::string& line);
+
+  //CMakeLists file handling
+  /**
+   * Type definition for the value of a syntax element for CMakeLists files
+   */
+  typedef std::vector<std::string> cmdValue;
+
+  /**
+   * Type definition for the type of a syntax element for CMakeLists files
+   */
+  typedef std::string cmdType;
+
+  /**
+   * Type definition for syntax elements of a CMakeLists file
+   */
+  typedef std::pair<cmdType,cmdValue> syntaxElement;
+
+  /**
+   * Type definition for describing a CMakeLists file content
+   */
+  typedef std::vector<syntaxElement> CMLFile;
+
+  /**
+   * Reads a CMakeLists file and returns the read data.
+   * @param file_path Full path of the CMakeLists file.
+   * @return A CMLFile with the contents of the given file.
+   */
+  CMLFile readCMLFile(const std::string& file_path);
+
+  /**
+   * Writes the given data into specified CMakeLists file.
+   * @param file_path Full path of the CMakeLists file.
+   * @param data CMakeLists data.
+   * @return True if the operation was successful.
+   */
+  bool writeCMLFile(const std::string& file_path, const CMLFile& data);
+
 };
 
 #endif /* CDMUTILITIES_H_ */
index b124c930309cb0300b647c979933774aae50644e..9bac184430df0e36052796f23797df89e84b10da 100644 (file)
@@ -455,6 +455,7 @@ std::map<std::string, bool> modelCDMLibrary::Get3rdPartyLibraries()
 
   if(this->HasCMakeLists())
     {
+      CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
       std::ifstream CMFile(this->CMakeLists->GetPath().c_str());
       if (CMFile.is_open())
         {
index 45d7b7e242b6dae341e612f0281e2bad122a181a..00cf8cc12719f170b0a451c6e67e345bbbe47473 100644 (file)
@@ -153,7 +153,8 @@ void wxCDMApplicationDescriptionPanel::CreateControls()
 
   //Includes
   wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries"));
-  wxPanel* includesPanel = new wxPanel(this);
+  includesBox->SetMinSize(250,250);
+  wxScrolledWindow* includesPanel = new wxScrolledWindow(this);
   wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL);
 
   //Third Party Libraries
@@ -161,7 +162,7 @@ void wxCDMApplicationDescriptionPanel::CreateControls()
   wxFont font = Title1->GetFont();
   font.SetWeight(wxFONTWEIGHT_BOLD);
   Title1->SetFont(font);
-  includesPanelSizer->Add(Title1, 0, wxEXPAND | wxALL, 5);
+  includesPanelSizer->Add(Title1, 0, wxEXPAND);
 
   //inclusion data
   std::map<std::string, bool> inclusions = this->application->Get3rdPartyLibraries();
@@ -203,14 +204,14 @@ void wxCDMApplicationDescriptionPanel::CreateControls()
 
   includesGridSizer->AddGrowableCol(1,1);
 
-  includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND, 0);
+  includesPanelSizer->Add(includesGridSizer, 0, wxEXPAND | wxLEFT, 5);
 
   //Custom Libraries
   wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
   font = Title2->GetFont();
   font.SetWeight(wxFONTWEIGHT_BOLD);
   Title2->SetFont(font);
-  includesPanelSizer->Add(Title2, 0, wxEXPAND | wxALL, 5);
+  includesPanelSizer->Add(Title2, 0, wxEXPAND);
 
   //inclusion data
   std::map<std::string, bool> inclusionsLibs = this->application->GetCustomLibraries();
@@ -252,10 +253,14 @@ void wxCDMApplicationDescriptionPanel::CreateControls()
 
   includesLibGridSizer->AddGrowableCol(1,1);
 
-  includesPanelSizer->Add(includesLibGridSizer, 1, wxEXPAND, 0);
+  includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
 
   includesPanel->SetSizer(includesPanelSizer);
   includesPanelSizer->Fit(includesPanel);
+
+  includesPanel->FitInside();
+  includesPanel->SetScrollRate(5,5);
+
   includesBox->Add(includesPanel, 1, wxEXPAND);
   sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10);
 
index 47efd9c86b95d9621c90dfac33db844034532333..8c767219e27dc74cdffb5c651871b77d8b285d3a 100644 (file)
@@ -153,7 +153,8 @@ void wxCDMLibraryDescriptionPanel::CreateControls()
 
   //Includes
   wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries"));
-  wxPanel* includesPanel = new wxPanel(this);
+  includesBox->SetMinSize(250,250);
+  wxScrolledWindow* includesPanel = new wxScrolledWindow(this);
   wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL);
 
   //Third Party Libraries
@@ -161,7 +162,7 @@ void wxCDMLibraryDescriptionPanel::CreateControls()
   wxFont font = Title1->GetFont();
   font.SetWeight(wxFONTWEIGHT_BOLD);
   Title1->SetFont(font);
-  includesPanelSizer->Add(Title1, 0, wxEXPAND | wxALL, 5);
+  includesPanelSizer->Add(Title1, 0, wxEXPAND);
 
   //inclusion data
   std::map<std::string, bool> inclusions = this->library->Get3rdPartyLibraries();
@@ -203,14 +204,14 @@ void wxCDMLibraryDescriptionPanel::CreateControls()
 
   includesGridSizer->AddGrowableCol(1,1);
 
-  includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND, 0);
+  includesPanelSizer->Add(includesGridSizer, 0, wxEXPAND | wxLEFT, 5);
 
   //Custom Libraries
   wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
   font = Title2->GetFont();
   font.SetWeight(wxFONTWEIGHT_BOLD);
   Title2->SetFont(font);
-  includesPanelSizer->Add(Title2, 0, wxEXPAND | wxALL, 5);
+  includesPanelSizer->Add(Title2, 0, wxEXPAND);
 
   //inclusion data
   std::map<std::string, bool> inclusionsLibs = this->library->GetCustomLibraries();
@@ -252,10 +253,14 @@ void wxCDMLibraryDescriptionPanel::CreateControls()
 
   includesLibGridSizer->AddGrowableCol(1,1);
 
-  includesPanelSizer->Add(includesLibGridSizer, 1, wxEXPAND, 0);
+  includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
 
   includesPanel->SetSizer(includesPanelSizer);
   includesPanelSizer->Fit(includesPanel);
+
+  includesPanel->FitInside();
+  includesPanel->SetScrollRate(5,5);
+
   includesBox->Add(includesPanel, 1, wxEXPAND);
   sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10);
 
index 07a1525b50fb2eed499a3468c3d43860445e807d..7c9c3aaef956af43cbe2057c25fee210072d8c18 100644 (file)
@@ -97,7 +97,7 @@ void wxCDMPackageConfigurationDialog::CreateControls()
     wxFont font = Title1->GetFont();
     font.SetWeight(wxFONTWEIGHT_BOLD);
     Title1->SetFont(font);
-    includesPanelSizer->Add(Title1, 0, wxEXPAND | wxALL, 5);
+    includesPanelSizer->Add(Title1, 0, wxEXPAND);
 
     //inclusion data
     std::map<std::string, bool> inclusions = this->package->Get3rdPartyLibraries();
@@ -139,14 +139,14 @@ void wxCDMPackageConfigurationDialog::CreateControls()
 
     includesGridSizer->AddGrowableCol(1,1);
 
-    includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND, 0);
+    includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND | wxLEFT, 5);
 
     //Custom Libraries
     wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
     font = Title2->GetFont();
     font.SetWeight(wxFONTWEIGHT_BOLD);
     Title2->SetFont(font);
-    includesPanelSizer->Add(Title2, 0, wxEXPAND | wxALL, 5);
+    includesPanelSizer->Add(Title2, 0, wxEXPAND);
 
     //inclusion data
     std::map<std::string, bool> inclusionsLibs = this->package->GetCustomLibraries();
@@ -188,11 +188,11 @@ void wxCDMPackageConfigurationDialog::CreateControls()
 
     includesLibGridSizer->AddGrowableCol(1,1);
 
-    includesPanelSizer->Add(includesLibGridSizer, 1, wxEXPAND, 0);
+    includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
 
     includesPanel->SetSizer(includesPanelSizer);
 
-    v_sizer1->Add(includesPanel, 1, wxEXPAND);
+    v_sizer1->Add(includesPanel, 1, wxEXPAND | wxALL, 10);
 
   v_sizer1->Add(new wxButton(this, wxID_OK, wxT("Close")), 0, wxALIGN_CENTER | wxRIGHT | wxBOTTOM, 30);