From d63809f12ef02087c94159a16a83ec0f31ae0d74 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Mon, 26 Nov 2012 14:41:47 +0100 Subject: [PATCH] open project fixed for model creation. Model not created yet --- lib/creaDevManagerLib/CDMUtilities.cpp | 25 ++-- lib/creaDevManagerLib/CDMUtilities.h | 3 +- lib/creaDevManagerLib/modelCDMMain.cpp | 82 ++++++++++- lib/creaDevManagerLib/wxCDMMainFrame.cpp | 165 +++++++++++++---------- 4 files changed, 183 insertions(+), 92 deletions(-) diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index a73282f..0149e8d 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -35,6 +35,7 @@ #include "CDMUtilities.h" #include +#include namespace CDMUtilities { @@ -54,36 +55,40 @@ namespace CDMUtilities { if (empties == no_empties) { - next = s.find_first_not_of( delimiters, next + 1 ); - if (next == Container::value_type::npos) break; + next = s.find_first_not_of(delimiters, next + 1); + if (next == Container::value_type::npos) + { + break; + } next -= 1; } current = next + 1; - next = s.find_first_of( delimiters, current ); - result.push_back( s.substr( current, next - current ) ); + next = s.find_first_of(delimiters, current); + result.push_back(s.substr(current, next - current)); } while (next != Container::value_type::npos); return result; } - const std::string& fixPath(const std::string& path) + const std::string fixPath(const std::string& path) { std::string pathFixed = ""; - #if(_WIN32) +#if(_WIN32) // ------ Windows //TODO: implementation for windows - #else +#else // ------ LINUX / MacOS //break path into folders std::vector pathSlpit; - splitter::split(pathSlpit, path, "\"/", splitter::no_empties); + + splitter::split(pathSlpit, path, "/", splitter::no_empties); + for (int i = 0; i < pathSlpit.size(); i++) { - std::cout << pathSlpit[i]; pathFixed += "/" + pathSlpit[i]; } - #endif +#endif return pathFixed; } diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index 15031ab..2b4f05b 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -36,6 +36,7 @@ #define CDMUTILITIES_H_ #include +#include namespace CDMUtilities { @@ -52,7 +53,7 @@ namespace CDMUtilities ); }; - const std::string& fixPath(const std::string& path); + const std::string fixPath(const std::string& path); }; #endif /* CDMUTILITIES_H_ */ diff --git a/lib/creaDevManagerLib/modelCDMMain.cpp b/lib/creaDevManagerLib/modelCDMMain.cpp index 307deca..e9df13e 100644 --- a/lib/creaDevManagerLib/modelCDMMain.cpp +++ b/lib/creaDevManagerLib/modelCDMMain.cpp @@ -34,8 +34,10 @@ #include "modelCDMMain.h" -#include -#include + +#include +#include +#include #include #include @@ -64,7 +66,75 @@ bool modelCDMMain::CreateProject( const std::string& author, const std::string& description) { - //TODO: implement method + std::cout << "Open selection path: "<< location << std::endl; + //get fixed location + std::string locationFixed = CDMUtilities::fixPath(location); + std::cout << "Opening path: "<< locationFixed << std::endl; + + //TODO: create Project given the source folder + +#if(_WIN32) + + std::string command("creaNewProject.bat "); + std::string command1("creaSed.exe "); + std::string command2("del "); + + command += "\"" + locationFixed + "\" \"" + name + "\""; + command1 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + locationFixed + "\\" + name + "\\CMakeLists.txt\""; + command2 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\""; + if ( ! system ( command.c_str() ) ) + { + system ( command1.c_str() ); + system ( command2.c_str() ); + + // Create a Package at the same time. JPR + char *author = author.c_str(); + std::string nomDirectory = locationFixed + "\\" + name; + std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG"; + std::string bbCreatePackage("bbCreatePackage "); + bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + system (bbCreatePackage.c_str()); + std::string add; + add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> " + nomDirectory + "/CMakeLists.txt"; + system(add.c_str()); + } + else + { + result = new std::string("An error occured while running '" + command + "'."); + return false; + } + +#else + // ------ LINUX / MacOS + std::string command("creaNewProject.sh "); + command += "\"" + locationFixed + "\"" +" " + name; + std::cout << "executing " << command << std::endl; + if ( ! system ( command.c_str() ) ) + { + std::string nomDirectory = locationFixed + "/" + name; + std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG"; + + std::string bbCreatePackage("bbCreatePackage "); + bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + std::cout << "executing " << bbCreatePackage << std::endl; + system (bbCreatePackage.c_str()); + + std::string add; + add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt"; + //std::cout << add << std::endl; + std::cout << "executing " << add << std::endl; + system(add.c_str()); + } + else + { + result = new std::string("An error occured while running '" + command + "'."); + return false; + } + +#endif + + + return true; } @@ -73,11 +143,10 @@ bool modelCDMMain::OpenProject( std::string*& result ) { - std::cout << "Selection path: "<< path << std::endl; - + std::cout << "Open selection path: "<< path << std::endl; //get fixed path std::string pathFixed = CDMUtilities::fixPath(path); - std::cout << "Fixed selection path: "<< pathFixed << std::endl; + std::cout << "Opening path: "<< pathFixed << std::endl; //check if its binaries' folder bool isBinary = false; @@ -97,7 +166,6 @@ bool modelCDMMain::OpenProject( while(!isBinary && readFile >> word) { - //cout << word << endl; if(word == "CMAKE_SOURCE_DIR") { readFile >> word; diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index e1578f9..d60b317 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -23,7 +23,7 @@ # 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. # ------------------------------------------------------------------------ -*/ + */ #include "wxCDMMainFrame.h" @@ -40,40 +40,40 @@ BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame) - EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject) - EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject) - EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent) - EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject) - EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects) - EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy) - EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit) - EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject) - EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut) - EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy) - EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste) - EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete) - EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll) - EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone) - EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog) - EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor) - EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools) - EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor) - EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine) - EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp) - EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug) - 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_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject) +EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject) +EVT_MENU(ID_MENU_OPEN_RECENT, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject) +EVT_MENU(ID_MENU_CLOSE_ALL_PROJECTS, wxCDMMainFrame::OnMenuCloseAllProjects) +EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy) +EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit) +EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject) +EVT_MENU(ID_MENU_CUT, wxCDMMainFrame::OnMenuMenuCut) +EVT_MENU(ID_MENU_COPY, wxCDMMainFrame::OnMenuMenuCopy) +EVT_MENU(ID_MENU_PASTE, wxCDMMainFrame::OnMenuMenuPaste) +EVT_MENU(ID_MENU_DELETE, wxCDMMainFrame::OnMenuMenuDelete) +EVT_MENU(ID_MENU_SELECT_ALL, wxCDMMainFrame::OnMenuSelectAll) +EVT_MENU(ID_MENU_SELECT_NONE, wxCDMMainFrame::OnMenuSelectNone) +EVT_MENU(ID_MENU_EVENT_LOG, wxCDMMainFrame::OnMenuEventLog) +EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor) +EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools) +EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor) +EVT_MENU(ID_MENU_COMMAND_LINE, wxCDMMainFrame::OnMenuCommandLine) +EVT_MENU(ID_MENU_HELP, wxCDMMainFrame::OnMenuHelp) +EVT_MENU(ID_MENU_REPORT_BUG, wxCDMMainFrame::OnMenuReportBug) +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) END_EVENT_TABLE() wxCDMMainFrame::wxCDMMainFrame( - wxWindow* parent, - wxWindowID id, - const wxString& caption, - const wxPoint& pos, - const wxSize& size, - long style + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& pos, + const wxSize& size, + long style ) { Create(parent, id, caption, pos, size, style); @@ -85,12 +85,12 @@ wxCDMMainFrame::~wxCDMMainFrame() } bool wxCDMMainFrame::Create( - wxWindow* parent, - wxWindowID id, - const wxString& caption, - const wxPoint& pos, - const wxSize& size, - long style + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& pos, + const wxSize& size, + long style ) { wxFrame::Create(parent, id, caption, pos, size, style); @@ -168,32 +168,32 @@ void wxCDMMainFrame::CreateControls() tree_Projects = new wxCDMProjectsTreeCtrl( - this, - ID_TREE_PROJECTS, - wxDefaultPosition, - wxSize(300,400), - wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS + this, + ID_TREE_PROJECTS, + wxDefaultPosition, + wxSize(300,400), + wxTR_HAS_BUTTONS | wxTR_AQUA_BUTTONS ); tree_Projects->SetMinSize(wxSize(200,200)); panel_Properties = new wxCDMMainDescriptionPanel( - this, - ID_WINDOW_PROPERTIES, - wxT("Description Panel"), - wxDefaultPosition, - wxSize(300, 400), - 0 + this, + ID_WINDOW_PROPERTIES, + wxT("Description Panel"), + wxDefaultPosition, + wxSize(300, 400), + 0 ); panel_ProjectActions = new wxCDMProjectActionsPanel( - this, - ID_WINDOW_PROJ_ACTIONS, - wxT("Project Actions Panel"), - wxDefaultPosition, - wxSize(600,200), - 0 + this, + ID_WINDOW_PROJ_ACTIONS, + wxT("Project Actions Panel"), + wxDefaultPosition, + wxSize(600,200), + 0 ); panel_ProjectActions->SetMinSize(wxSize(500, 100)); @@ -215,11 +215,26 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) userResponse = dialog->ShowModal(); if(userResponse == wxID_FORWARD) - { - //TODO createProject - std::cerr << "should create Project here" << std::endl; - //tree_Projects->BuildTree(this->model->GetActiveProjects()); - } + { + std::string* result; + if(!this->model->CreateProject( + crea::wx2std(dialog->GetProjectName()), + crea::wx2std(dialog->GetProjectLocation()), + result, + crea::wx2std(dialog->GetPackageAuthor()), + crea::wx2std(dialog->GetPackageDescription()) + )) + { + wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR); + } + wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION); + + //TODO: populate model + //TODO: populate tree control + + //tree_Projects->BuildTree(this->model->GetActiveProjects()); + auiManager.Update(); + } event.Skip(); } @@ -230,21 +245,23 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) long userResponse; userResponse = FD->ShowModal(); if(userResponse == wxID_OK) - { - std::cout << "selection: " << crea::wx2std (FD->GetPath()) << std::endl; - std::string path = CDMUtilities::fixPath(crea::wx2std (FD->GetPath())); - std::cout << "fixed selection: " << path << std::endl; - std::string* result; - if (!this->model->OpenProject(path, result)) { - wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR); - event.Skip(); - }; - //TODO: Create tree control - //((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(controller->GetActiveProjects()); - - auiManager.Update(); - } + std::cout << "Selection to open: " << crea::wx2std (FD->GetPath()) << std::endl; + std::string path = crea::wx2std (FD->GetPath()); + + std::string* result; + if (!this->model->OpenProject(path, result)) + { + wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR); + event.Skip(); + }; + + //TODO: populate model + //TODO: populate tree control + + //((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(controller->GetActiveProjects()); + auiManager.Update(); + } event.Skip(); } -- 2.45.1