From 568ae730865efa12b53def3779d38067afd8963a Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Wed, 24 Apr 2013 13:41:26 +0200 Subject: [PATCH] Feature #1711 CreaDevManager application implementation Neature: Now detecting included 3rd party libraries in Projects using Regular Expressions. Also including and excluding them with regex. --- lib/creaDevManagerLib/modelCDMProject.cpp | 204 ++++++++++++++++++ lib/creaDevManagerLib/modelCDMProject.h | 12 ++ .../wxCDMProjectConfigurationDialog.cpp | 170 +++++++++++++++ .../wxCDMProjectConfigurationDialog.h | 122 +++++++++++ .../wxCDMProjectDescriptionPanel.cpp | 16 +- .../wxCDMProjectDescriptionPanel.h | 4 + 6 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.cpp create mode 100644 lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.h diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index c394633..dff1b63 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "CDMUtilities.h" #include "creaWx.h" @@ -1100,3 +1101,206 @@ bool modelCDMProject::SetPackageInclude(const std::string& package_name, const b } return false; } + +std::map modelCDMProject::Get3rdPartyLibraries() +{ + std::map correspondence; + correspondence["USE_CREA"] = "Crea"; + correspondence["USE_GDCM"] = "GDCM"; + correspondence["USE_GDCM_VTK"] = "GDCM_VTK"; + correspondence["USE_GDCM2"] = "GDCM2"; + correspondence["USE_WXWIDGETS"] = "WxWidgets"; + correspondence["USE_KWWIDGETS"] = "KWWidgets"; + correspondence["USE_VTK"] = "VTK"; + correspondence["USE_ITK"] = "ITK"; + correspondence["USE_BOOST"] = "Boost"; + + std::map res; + res["Crea"] = false; + res["GDCM"] = false; + res["GDCM_VTK"] = false; + res["GDCM2"] = false; + res["WxWidgets"] = false; + res["KWWidgets"] = false; + res["VTK"] = false; + res["ITK"] = false; + res["Boost"] = false; + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*USE_\\w+\\s+ON"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + while(boost::regex_search(start, end, what, expression, flags)) + { + std::cout << what[0].str() << std::endl; + boost::regex expression1 = boost::regex("USE_\\w+"); + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1; + if(boost::regex_search(start1, end1, what1, expression1, flags)) + { + std::string dete = what1.str(); + CDMUtilities::normalizeStr(dete); + std::cout << dete << std::endl; + if(correspondence.find(dete) != correspondence.end()) + res[correspondence[dete]] = true; + } + start = what[0].second; + } + } + + return res; +} + +bool modelCDMProject::Set3rdPartyLibrary(const std::string& library_name, + const bool& toInclude) +{ + std::map correspondence; + correspondence["Crea"] = "USE_CREA"; + correspondence["GDCM"] = "USE_GDCM"; + correspondence["GDCM_VTK"] = "USE_GDCM_VTK"; + correspondence["GDCM2"] = "USE_GDCM2"; + correspondence["WxWidgets"] = "USE_WXWIDGETS"; + correspondence["KWWidgets"] = "USE_KWWIDGETS"; + correspondence["VTK"] = "USE_VTK"; + correspondence["ITK"] = "USE_ITK"; + correspondence["Boost"] = "USE_BOOST"; + + if (correspondence.find(library_name) != correspondence.end()) + { + std::string library_command = correspondence[library_name]; + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + std::string resCMfile = ""; + + std::string::const_iterator start, end; + boost::match_results what, tmp; + boost::match_flag_type flags = boost::match_default; + bool found = false; + + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing inclusions + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(!toInclude) + { + std::string dete = what.str(); + int pos = dete.find("ON",0); + dete.replace(pos, 2, "OFF"); + resCMfile += dete; + } + else + resCMfile += what.str(); + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing exclusions + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+OFF\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(toInclude) + { + std::string dete = what.str(); + int pos = dete.find("OFF",0); + dete.replace(pos, 3, "ON"); + resCMfile += dete; + } + else + resCMfile += what.str(); + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing commented inclusions + expression = boost::regex("^\\h*#+\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(toInclude) + { + std::string dete = what.str(); + for (int i = 0; i < dete.size(); ++i) { + if(dete[i] == '#') + { + dete.erase(i,1); + i--; + } + } + resCMfile += dete; + } + else + resCMfile += what.str(); + + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + if(toInclude) + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for position to insert + expression = boost::regex("^\\h*#\\h*Libraries\\/tools used\\h*$"); + if(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + resCMfile += what.str(); + resCMfile += "\nSET(" + library_command + " ON)"; + resCMfile += what.suffix().str(); + } + } + else + { + found = true; + } + } + } + } + if (!found) { + return false; + } + else + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMProject.h b/lib/creaDevManagerLib/modelCDMProject.h index f354db9..a3459d7 100644 --- a/lib/creaDevManagerLib/modelCDMProject.h +++ b/lib/creaDevManagerLib/modelCDMProject.h @@ -267,6 +267,18 @@ public: */ bool SetPackageInclude(const std::string& package_name, const bool& toInclude); + /** + * Checks the project folder's CMakeLists file to check which third party libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map Get3rdPartyLibraries(); + + /** + * Sets the 3rd party library inclusion in the CMakeLists file. + * @return if the operation was successful. + */ + bool Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude); + private: diff --git a/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.cpp b/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.cpp new file mode 100644 index 0000000..d26fbb3 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.cpp @@ -0,0 +1,170 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ + */ + + +/* + * wxCDMProjectConfigurationDialog.cpp + * + * Created on: 6/4/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#include "wxCDMProjectConfigurationDialog.h" + +#include "creaDevManagerIds.h" + +BEGIN_EVENT_TABLE(wxCDMProjectConfigurationDialog, wxDialog) +EVT_BUTTON(wxID_OK, wxCDMProjectConfigurationDialog::OnFinish) +EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMProjectConfigurationDialog::On3rdLibraryIncludeChange) +END_EVENT_TABLE() + +wxCDMProjectConfigurationDialog::wxCDMProjectConfigurationDialog( + wxWindow* parent, + modelCDMProject* project, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + this->project = project; + wxCDMProjectConfigurationDialog::Create(parent, id, caption, position, size, style); +} + +wxCDMProjectConfigurationDialog::~wxCDMProjectConfigurationDialog() +{ +} + +bool wxCDMProjectConfigurationDialog::Create( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long int style +) +{ + wxDialog::Create(parent, id, caption, position, size, style); + + this->CreateControls(); + + return TRUE; +} + +void wxCDMProjectConfigurationDialog::CreateControls() +{ + + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Please select the libraries that are used in this project."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY); + v_sizer1->Add(title, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 5); + + wxScrolledWindow* includesPanel = new wxScrolledWindow(this); + includesPanel->FitInside(); + includesPanel->SetScrollRate(5,5); + + wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL); + + //Third Party Libraries + wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:")); + wxFont font = Title1->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title1->SetFont(font); + includesPanelSizer->Add(Title1, 0, wxEXPAND); + + //inclusion data + std::map inclusions = this->project->Get3rdPartyLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesGridSizer->Add(ChBTitle, 1, wxEXPAND); + includesGridSizer->Add(LNmTitle, 1, wxEXPAND); + + for (std::map::iterator it = inclusions.begin(); it != inclusions.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " library\n" + "is included in the project configuration for\n" + "this package including the following instruction\n" + "in the package's folder CMakeLists.txt file:\n" + "SET(${BBTK_PACKAGE_NAME}_USE_" + it->first+ " ON)\n" + )); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesGridSizer->Add(ChBIncl, 0, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND | wxLEFT, 5); + + includesPanel->SetSizer(includesPanelSizer); + + v_sizer1->Add(includesPanel, 1, wxEXPAND | wxALL, 10); + + v_sizer1->Add(new wxButton(this, wxID_OK, wxT("Close")), 0, wxALIGN_CENTER | wxRIGHT | wxBOTTOM, 30); + + SetSizer(v_sizer1); +} + +void wxCDMProjectConfigurationDialog::OnFinish(wxCommandEvent& event) +{ + this->EndModal(wxID_OK); +} + +void wxCDMProjectConfigurationDialog::On3rdLibraryIncludeChange( + wxCommandEvent& event) +{ + if(this->project->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} diff --git a/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.h b/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.h new file mode 100644 index 0000000..b500412 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMProjectConfigurationDialog.h @@ -0,0 +1,122 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + + +/* + * wxCDMProjectConfigurationDialog.h + * + * Created on: 24/4/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#ifndef WXCDMPROJECTCONFIGURATIONDIALOG_H_ +#define WXCDMPROJECTCONFIGURATIONDIALOG_H_ + +#include +#include + +#include "modelCDMProject.h" + +/** + * Project Configuration Dialog + */ +class wxCDMProjectConfigurationDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() +public: + /** + * Project Configuration Dialog Constructor. + * @param parent Parent window. + * @param project Project Description reference. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Project Library Configuration". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE. + */ + wxCDMProjectConfigurationDialog( + wxWindow* parent, + modelCDMProject * project, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Project Library Configuration"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,370), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + /** + * Destructor. + */ + ~wxCDMProjectConfigurationDialog(); + /** + * Project Configuration Dialog Creator. + * @param parent Parent window. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Project Library Configuration". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE. + * @return if the creation was successful. + */ + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Project Library Configuration"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,370), + long style = wxDEFAULT_DIALOG_STYLE + ); + +protected: + /** + * Creates the help controls (text and buttons). + */ + void CreateControls(); + +//attributes +private: + /** + * Project model reference. + */ + modelCDMProject* project; + +//handlers +protected: + /** + * Handler to close configuration dialog. + * @param event Unused. + */ + void OnFinish(wxCommandEvent& event); + + /** + * Handler when a third party library include is pressed. + * @param event checkbox event. + */ + void On3rdLibraryIncludeChange(wxCommandEvent& event); + +}; + +#endif /* WXCDMPROJECTCONFIGURATIONDIALOG_H_ */ diff --git a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp index a6f121b..ac170e0 100644 --- a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp @@ -36,6 +36,7 @@ #include "wxCDMMainFrame.h" #include "wxCDMNewPackageDialog.h" +#include "wxCDMProjectConfigurationDialog.h" #include "wxCDMProjectHelpDialog.h" @@ -47,6 +48,7 @@ BEGIN_EVENT_TABLE(wxCDMProjectDescriptionPanel, wxPanel) EVT_BUTTON(ID_BUTTON_GOTO_PACKAGE_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManagePackages) EVT_BUTTON(ID_BUTTON_GOTO_LIB_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageLibraries) EVT_BUTTON(ID_BUTTON_GOTO_APPLI_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageApplications) +EVT_BUTTON(ID_BUTTON_CHOOSE, wxCDMProjectDescriptionPanel::OnBtnConfigProject) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_SET_BUILD_PATH, wxCDMProjectDescriptionPanel::OnBtnSetBuildPath) EVT_BUTTON(ID_BUTTON_OPEN_BUILD_PATH, wxCDMProjectDescriptionPanel::OnBtnOpenBuild) @@ -188,7 +190,7 @@ void wxCDMProjectDescriptionPanel::CreateControls() wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL); //actionsGrid Sizer - wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15); + wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(3, 2, 9, 15); //buttons // lib manager // show only if there is a lib folder @@ -215,6 +217,11 @@ void wxCDMProjectDescriptionPanel::CreateControls() appliMgrbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnAppliMouseExit,NULL,this); actionsGridSizer->Add(appliMgrbt, 1, wxALL | wxEXPAND, 5); } + // edit 3rd Party libraries + wxButton* configPrjbt = new wxButton(actionsPanel, ID_BUTTON_CHOOSE, _T("D. 3rd Party Libraries Manager")); + configPrjbt->SetToolTip(wxT("Select which third party libraries will be used in this project.")); + actionsGridSizer->Add(configPrjbt, 1, wxALL | wxEXPAND, 5); + // edit CMakeLists file wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project.")); @@ -297,6 +304,13 @@ void wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event event.Skip(); } +void wxCDMProjectDescriptionPanel::OnBtnConfigProject(wxCommandEvent& event) +{ + wxCDMProjectConfigurationDialog* dialog = new wxCDMProjectConfigurationDialog(this,this->project); + long userResponse; + userResponse = dialog->ShowModal(); +} + void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) { std::string* result; diff --git a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h index d210e32..1b79726 100644 --- a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h @@ -136,6 +136,10 @@ protected: * Handles when the manage applications button is pressed. */ void OnBtnManageApplications(wxCommandEvent& event); + /** + * Handles when the 3rd party libraries manager button is pressed. + */ + void OnBtnConfigProject(wxCommandEvent& event); /** * Handles when the open cmakelists file button is pressed. */ -- 2.47.1