From 9013f401b9f263f755fedc2dc88b21f351abf7da Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Wed, 5 Dec 2012 11:10:29 +0100 Subject: [PATCH] Feature #1711 CreaDevManager application implementation Package creation implemented Application creation implemented missing adjustments for windows other scripts from bbtk don't return error codes --- lib/creaDevManagerLib/modelCDMAppli.cpp | 50 +++++- lib/creaDevManagerLib/modelCDMAppli.h | 2 +- lib/creaDevManagerLib/modelCDMLib.cpp | 4 +- lib/creaDevManagerLib/modelCDMLib.h | 2 +- lib/creaDevManagerLib/modelCDMProject.cpp | 71 +++++++- lib/creaDevManagerLib/modelCDMProject.h | 4 +- .../wxCDMAppliDescriptionPanel.cpp | 40 ++++- .../wxCDMApplicationDescriptionPanel.cpp | 2 +- lib/creaDevManagerLib/wxCDMMainFrame.cpp | 15 +- .../wxCDMNewPackageDialog.cpp | 168 ++++++++++++++++++ lib/creaDevManagerLib/wxCDMNewPackageDialog.h | 84 +++++++++ .../wxCDMProjectDescriptionPanel.cpp | 73 +++++++- 12 files changed, 481 insertions(+), 34 deletions(-) create mode 100644 lib/creaDevManagerLib/wxCDMNewPackageDialog.cpp create mode 100644 lib/creaDevManagerLib/wxCDMNewPackageDialog.h diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index 2bba913..1f08f3b 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -34,6 +34,9 @@ #include "modelCDMAppli.h" +#include +#include + #include "CDMUtilities.h" #include "creaWx.h" #include "wx/dir.h" @@ -80,14 +83,55 @@ modelCDMAppli::~modelCDMAppli() { } -bool modelCDMAppli::CreateApplication( +modelCDMApplication* modelCDMAppli::CreateApplication( const std::string& name, std::string*& result, const std::string& path ) { - //TODO: implement method - return true; + //copy template library folder with new name + //TODO: fix for windows + std::string copyCommand = "cp -r " + this->path + "/template_appli " + this->path + "/" + name; + if(system(copyCommand.c_str())) + { + result = new std::string("An error occurred while running '" + copyCommand + "'."); + return NULL; + } + //set name of library in CMakeLists inside copied folder + std::string line; + std::ifstream in((this->path + "/" + name + "/CMakeLists.txt").c_str()); + if( !in.is_open()) + { + result = new std::string("CMakeLists.txt file failed to open."); + return NULL; + } + std::ofstream out((this->path + "/" + name + "/CMakeLists.txt.tmp").c_str()); + while (getline(in, line)) + { + if(line == "SET ( EXE_NAME MyExe )") + line = "SET ( EXE_NAME " + name + " )"; + out << line << std::endl; + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv " + this->path + "/" + name + "/CMakeLists.txt.tmp " + this->path + "/" + name + "/CMakeLists.txt"; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return NULL; + } + + //add application to model + //TODO: fix for windows + modelCDMApplication* application = new modelCDMApplication(this->path + "/" + name, this->level + 1); + this->applications.push_back(application); + this->children.push_back(application); + + this->SortChildren(); + + result = new std::string(this->path + "/" + name); + return application; } bool modelCDMAppli::OpenCMakeListsFile(std::string*& result) diff --git a/lib/creaDevManagerLib/modelCDMAppli.h b/lib/creaDevManagerLib/modelCDMAppli.h index c8d6003..8b8ecbe 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.h +++ b/lib/creaDevManagerLib/modelCDMAppli.h @@ -48,7 +48,7 @@ public: modelCDMAppli(const std::string& path, const int& level = 1); ~modelCDMAppli(); - bool CreateApplication( + modelCDMApplication* CreateApplication( const std::string& name, std::string*& result, const std::string& path = "/" diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index 9ecaea4..236f7a3 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -103,13 +103,14 @@ modelCDMLib::~modelCDMLib() { } -modelCDMIProjectTreeNode* modelCDMLib::CreateLibrary( +modelCDMLibrary* modelCDMLib::CreateLibrary( const std::string& name, std::string*& result, const std::string& path ) { //copy template library folder with new name + //TODO: fix for windows std::string copyCommand = "cp -r " + this->path + "/template_lib " + this->path + "/" + name; if(system(copyCommand.c_str())) { @@ -142,6 +143,7 @@ modelCDMIProjectTreeNode* modelCDMLib::CreateLibrary( } //add library to model + //TODO: fix for windows modelCDMLibrary* library = new modelCDMLibrary(this->path + "/" + name, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); diff --git a/lib/creaDevManagerLib/modelCDMLib.h b/lib/creaDevManagerLib/modelCDMLib.h index 3991384..71ed033 100644 --- a/lib/creaDevManagerLib/modelCDMLib.h +++ b/lib/creaDevManagerLib/modelCDMLib.h @@ -48,7 +48,7 @@ public: modelCDMLib(const std::string& path, const int& level = 1); ~modelCDMLib(); - modelCDMIProjectTreeNode* CreateLibrary( + modelCDMLibrary* CreateLibrary( const std::string& name, std::string*& result, const std::string& path = "/" diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index 7cadb24..23dd166 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -244,12 +244,63 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( std::string*& result, const std::string& authors, const std::string& authorsEmail, - const std::string& version, - const std::string& description + const std::string& description, + const std::string& version ) { - //TODO: implement method - return NULL; + //fixing input parameters + std::vector words; + + CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties); + std::string nameFixed = ""; + for (int i = 0; i < words.size(); i++) + { + nameFixed += words[i]; + } + + words.clear(); + CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties); + std::string authorFixed; + for (int i = 0; i < words.size(); i++) + { + authorFixed += words[i]; + } + + words.clear(); + std::string descriptionFixed; + CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties); + for (int i = 0; i < words.size(); i++) + { + descriptionFixed += words[i]; + } + words.clear(); + CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties); + for (int i = 0; i < words.size(); i++) + { + descriptionFixed += "_" + words[i]; + } + + //call project to create package : use bbCreatePackage [author] [description] + std::string creationCommand = "bbCreatePackage \"" + this->path + "\" " + nameFixed + " " + authorFixed + " " + descriptionFixed; + //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error + if(system(creationCommand.c_str())) + { + result = new std::string("An error occurred while running '" + creationCommand + "'."); + return NULL; + } + + //add library to model + //TODO: fix for windows + modelCDMPackage* package = new modelCDMPackage(this->path + "/bbtk_" + nameFixed + "_PKG", this->level + 1); + this->packages.push_back(package); + this->children.push_back(package); + + //TODO: set package version + + this->SortChildren(); + + result = new std::string(this->path + "/" + name); + return package; } modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary( @@ -272,8 +323,12 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateApplication( const std::string& path ) { - //TODO: implement method - return NULL; + if(this->appli != NULL) + { + return this->appli->CreateApplication(name, result); + } + result = new std::string("there is no appli folder in this project."); + return NULL; } modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox( @@ -512,8 +567,8 @@ const bool modelCDMProject::Refresh(std::string*& result) if(!checkedPackages[i]) { this->packages.erase(this->packages.begin()+i); - checkedPackages.erase(checkedPackages.begin()+i); - i--; + checkedPackages.erase(checkedPackages.begin()+i); + i--; } } for (int i = 0; i < checked.size(); i++) diff --git a/lib/creaDevManagerLib/modelCDMProject.h b/lib/creaDevManagerLib/modelCDMProject.h index 2cb35b2..c6f5830 100644 --- a/lib/creaDevManagerLib/modelCDMProject.h +++ b/lib/creaDevManagerLib/modelCDMProject.h @@ -66,8 +66,8 @@ public: std::string*& result, const std::string& authors = "info-dev", const std::string& authorsEmail = "info-dev@creatis.insa-lyon.fr", - const std::string& version = "1.0.0", - const std::string& description = "no description" + const std::string& description = "no description", + const std::string& version = "1.0.0" ); modelCDMIProjectTreeNode* CreateLibrary( const std::string& name, diff --git a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp index 617f39f..9d815d2 100644 --- a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp @@ -35,11 +35,13 @@ #include "wxCDMAppliDescriptionPanel.h" #include "creaDevManagerIds.h" + +#include "wxCDMMainFrame.h" #include "images/ApIcon64.xpm" BEGIN_EVENT_TABLE(wxCDMAppliDescriptionPanel, wxPanel) -EVT_MENU(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication) -EVT_MENU(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists) +EVT_BUTTON(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication) +EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists) END_EVENT_TABLE() wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel( @@ -102,9 +104,37 @@ void wxCDMAppliDescriptionPanel::CreateControls() void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event) { - //TODO: implement method - std::cerr << "Event OnBtnCreateApplication not implemented" << std::endl; - event.Skip(); + //get name + wxString applicationName = wxGetTextFromUser( + _T("Enter the new application name"), + _T("New Application - creaDevManager"), + _T("") + ); + //check name + if(applicationName.Len() > 0) + { + std::string* result; + //create library + modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result); + //check library created + if(application == NULL) + { + wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - 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->SetInt(application->GetId()); + wxPostEvent(this->GetParent(), *newEvent); + event.Skip(); + } } void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp index 878d51d..f19dbcf 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp @@ -80,7 +80,7 @@ void wxCDMApplicationDescriptionPanel::CreateControls() wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); //Welcome - sizer->Add(new wxStaticText(this, -1, _("Project")),0, wxALIGN_CENTER, 0); + sizer->Add(new wxStaticText(this, -1, _("Application")),0, wxALIGN_CENTER, 0); //Image sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(AIcon64)),0, wxALIGN_CENTER, 0); diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index 74999d6..94a7a38 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -78,7 +78,7 @@ EVT_MENU(ID_MENU_ABOUT_CREADEVMANAGER, wxCDMMainFrame::OnMenuAboutCreaDevManager EVT_MENU(ID_MENU_ABOUT_CREATIS, wxCDMMainFrame::OnMenuAboutCreatis) EVT_BUTTON(ID_BUTTON_NEWPROJECT, wxCDMMainFrame::OnMenuNewProject) EVT_BUTTON(ID_BUTTON_OPENPROJECT, wxCDMMainFrame::OnMenuOpenProject) -EVT_TREE_SEL_CHANGED(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged) +EVT_TREE_SEL_CHANGING(ID_TREE_PROJECTS, wxCDMMainFrame::OnTreeSelectionChanged) EVT_COMMAND(wxID_ANY, wxEVT_DISPLAY_CHANGED, wxCDMMainFrame::OnCreationComplete) END_EVENT_TABLE() @@ -808,21 +808,24 @@ void wxCDMMainFrame::OnTreeSelectionChanged(wxTreeEvent& event) } } } - description->Hide(); + + if(this->panel_Properties!= NULL) + this->panel_Properties->Hide(); + + auiManager.AddPane(description, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400)); + auiManager.Update(); + //delete old view if(this->panel_Properties!= NULL) { - this->panel_Properties->Hide(); this->panel_Properties->Destroy(); auiManager.DetachPane(this->panel_Properties); - } //set new view this->panel_Properties = description; - auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400)); + //auiManager.AddPane(panel_Properties, wxAuiPaneInfo().Center().Name(wxT("panel_Properties")).Caption(wxT("Properties")).BestSize(600,400)); auiManager.Update(); - this->panel_Properties->Show(true); event.Skip(); return; diff --git a/lib/creaDevManagerLib/wxCDMNewPackageDialog.cpp b/lib/creaDevManagerLib/wxCDMNewPackageDialog.cpp new file mode 100644 index 0000000..8b0efff --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMNewPackageDialog.cpp @@ -0,0 +1,168 @@ +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ +*/ + + +/* + * wxCDMNewPackageDialog.cpp + * + * Created on: 05/12/2012 + * Author: Daniel Felipe Gonzalez Obando + */ + +#include "wxCDMNewPackageDialog.h" + +#include "creaDevManagerIds.h" + +BEGIN_EVENT_TABLE(wxCDMNewPackageDialog, wxDialog) + EVT_BUTTON(ID_BUTTON_NEXT, wxCDMNewPackageDialog::OnCreatePackage) + EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMNewPackageDialog::OnCancel) +END_EVENT_TABLE() + +wxCDMNewPackageDialog::wxCDMNewPackageDialog( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + wxCDMNewPackageDialog::Create(parent, id, caption, position, size, style); +} + +wxCDMNewPackageDialog::~wxCDMNewPackageDialog() +{ +} + +bool wxCDMNewPackageDialog::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; +} + +const wxString wxCDMNewPackageDialog::GetPackageName() +{ + return this->packageName->GetValue(); +} +const wxString wxCDMNewPackageDialog::GetPackageAuthor() +{ + return this->packageAuthor->GetValue(); +} +const wxString wxCDMNewPackageDialog::GetPackageAuthorEmail() +{ + return this->packageAuthorEmail->GetValue(); +} +const wxString wxCDMNewPackageDialog::GetPackageDescription() +{ + return this->packageDescription->GetValue(); +} + +void wxCDMNewPackageDialog::CreateControls() +{ + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Create a new package"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxT("Please fill the following details."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15); + + wxStaticText *stxtPrjName = new wxStaticText(this, -1, wxT("Package Name")); + wxStaticText *stxtPrjAuth = new wxStaticText(this, -1, wxT("Package's Author (1 word)")); + wxStaticText *stxtPrjAuthEmail = new wxStaticText(this, -1, wxT("Package's Author Email")); + wxStaticText *stxtPrjPkg = new wxStaticText(this, -1, wxT("Package's Description (HTML)")); + + this->packageName = new wxTextCtrl(this, -1); + this->packageAuthor = new wxTextCtrl(this, -1); + this->packageAuthorEmail = new wxTextCtrl(this, -1); + this->packageDescription = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); + + formItems->Add(stxtPrjName, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->packageName, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjAuth, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->packageAuthor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjAuthEmail, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->packageAuthorEmail, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjPkg); + formItems->Add(this->packageDescription, 1, wxEXPAND); + + formItems->AddGrowableCol(1,1); + formItems->AddGrowableRow(3,1); + + v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15); + + wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL); + h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxT("Create Package")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + + v_sizer1->Add(h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30); + + SetSizer(v_sizer1); + v_sizer1->SetSizeHints(this); +} + +void wxCDMNewPackageDialog::OnCreatePackage(wxCommandEvent& event) +{ + bool ready = true; + + if(ready && this->packageName->GetValue() == wxT("")) + { + wxMessageBox(wxT("The package name cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + if(ready && this->packageAuthor->GetValue() == wxT("")) + { + wxMessageBox(wxT("The package's author cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + + if(ready) + { + this->EndModal(wxID_FORWARD); + } + + event.Skip(); +} + +void wxCDMNewPackageDialog::OnCancel(wxCommandEvent& event) +{ + this->EndModal(wxID_CANCEL); + event.Skip(); +} diff --git a/lib/creaDevManagerLib/wxCDMNewPackageDialog.h b/lib/creaDevManagerLib/wxCDMNewPackageDialog.h new file mode 100644 index 0000000..1c76552 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMNewPackageDialog.h @@ -0,0 +1,84 @@ +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ +*/ + + +/* + * wxCDMNewPackageDialog.h + * + * Created on: 05/12/2012 + * Author: Daniel Felipe Gonzalez Obando + */ + +#ifndef WXCDMNEWPACKAGEDIALOG_H_ +#define WXCDMNEWPACKAGEDIALOG_H_ + +#include +#include + +class wxCDMNewPackageDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() +public: + wxCDMNewPackageDialog( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("New Package"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(400,300), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + ~wxCDMNewPackageDialog(); + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("New Package"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(400,300), + long style = wxDEFAULT_DIALOG_STYLE + ); + + const wxString GetPackageName(); + const wxString GetPackageAuthor(); + const wxString GetPackageAuthorEmail(); + const wxString GetPackageDescription(); + +protected: + void CreateControls(); + +private: + wxTextCtrl* packageName; + wxTextCtrl* packageAuthor; + wxTextCtrl* packageAuthorEmail; + wxTextCtrl* packageDescription; + +//handlers +protected: + void OnCreatePackage(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); +}; + +#endif /* WXCDMNEWPACKAGEDIALOG_H_ */ diff --git a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp index 5093d71..a624244 100644 --- a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp @@ -35,6 +35,7 @@ #include "wxCDMProjectDescriptionPanel.h" #include "wxCDMMainFrame.h" +#include "wxCDMNewPackageDialog.h" #include "creaDevManagerIds.h" #include "images/PrIcon64.xpm" @@ -143,9 +144,41 @@ void wxCDMProjectDescriptionPanel::CreateControls() void wxCDMProjectDescriptionPanel::OnBtnCreatePackage(wxCommandEvent& event) { - //TODO: implement method - //TODO: call project to create package : use bbCreatePackage [author] [description] - std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl; + std::string* result; + + wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this); + long userResponse; + userResponse = dialog->ShowModal(); + + if(userResponse == wxID_FORWARD) + { + modelCDMIProjectTreeNode* package = this->project->CreatePackage( + crea::wx2std(dialog->GetPackageName()), + result, + crea::wx2std(dialog->GetPackageAuthor()), + crea::wx2std(dialog->GetPackageAuthorEmail()), + crea::wx2std(dialog->GetPackageDescription()) + ); + if(package == NULL) + { + std::cout << "error creating package: " << *result << std::endl; + wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - 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->SetInt(package->GetId()); + wxPostEvent(this->GetParent(), *newEvent); + event.Skip(); + } + event.Skip(); } @@ -193,9 +226,37 @@ void wxCDMProjectDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event) void wxCDMProjectDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event) { - //TODO: implement method - std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl; - event.Skip(); + //get name + wxString applicationName = wxGetTextFromUser( + _T("Enter the new application name"), + _T("New Application - creaDevManager"), + _T("") + ); + //check name + if(applicationName.Len() > 0) + { + std::string* result; + //create library + modelCDMIProjectTreeNode* application = this->project->CreateApplication(crea::wx2std(applicationName),result); + //check library created + if(application == NULL) + { + wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - 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->SetInt(application->GetId()); + wxPostEvent(this->GetParent(), *newEvent); + event.Skip(); + } } void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) -- 2.45.1