From 5a17d994576296f2a5a85f3a01ad5631786a0c56 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Mon, 8 Apr 2013 18:13:01 +0200 Subject: [PATCH] Feature #1711 CreaDevManager application implementation 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 | 150 ++++++++++++++++++ lib/creaDevManagerLib/CDMUtilities.h | 38 +++++ lib/creaDevManagerLib/modelCDMLibrary.cpp | 1 + .../wxCDMApplicationDescriptionPanel.cpp | 15 +- .../wxCDMLibraryDescriptionPanel.cpp | 15 +- .../wxCDMPackageConfigurationDialog.cpp | 10 +- 6 files changed, 214 insertions(+), 15 deletions(-) diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index b4696b1..77f5f52 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -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; + } + } diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index 5430aea..f807d32 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -36,6 +36,7 @@ #define CDMUTILITIES_H_ #include +#include #include 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 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 syntaxElement; + + /** + * Type definition for describing a CMakeLists file content + */ + typedef std::vector 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_ */ diff --git a/lib/creaDevManagerLib/modelCDMLibrary.cpp b/lib/creaDevManagerLib/modelCDMLibrary.cpp index b124c93..9bac184 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.cpp +++ b/lib/creaDevManagerLib/modelCDMLibrary.cpp @@ -455,6 +455,7 @@ std::map modelCDMLibrary::Get3rdPartyLibraries() if(this->HasCMakeLists()) { + CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); std::ifstream CMFile(this->CMakeLists->GetPath().c_str()); if (CMFile.is_open()) { diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp index 45d7b7e..00cf8cc 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp @@ -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 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 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); diff --git a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp index 47efd9c..8c76721 100644 --- a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp @@ -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 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 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); diff --git a/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp index 07a1525..7c9c3aa 100644 --- a/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp +++ b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp @@ -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 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 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); -- 2.45.0