Neature: Now detecting included 3rd party libraries in Projects using Regular Expressions. Also including and excluding them with regex.
#include <algorithm>
#include <fstream>
#include <ctime>
+#include <boost/regex.hpp>
#include "CDMUtilities.h"
#include "creaWx.h"
}
return false;
}
+
+std::map<std::string, bool> modelCDMProject::Get3rdPartyLibraries()
+{
+ std::map<std::string, std::string> 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<std::string, bool> 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<std::string::const_iterator> 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<std::string::const_iterator> 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<std::string, std::string> 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<std::string::const_iterator> 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;
+}
*/
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<std::string, bool> 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:
--- /dev/null
+/*
+# ---------------------------------------------------------------------
+#
+# 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<std::string, bool> 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<std::string, bool>::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());
+}
--- /dev/null
+/*
+# ---------------------------------------------------------------------
+#
+# 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 <creaWx.h>
+#include <wx/dialog.h>
+
+#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_ */
#include "wxCDMMainFrame.h"
#include "wxCDMNewPackageDialog.h"
+#include "wxCDMProjectConfigurationDialog.h"
#include "wxCDMProjectHelpDialog.h"
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)
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
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."));
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;
* 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.
*/