]> Creatis software - crea.git/commitdiff
open project fixed for model creation. Model not created yet
authorDaniel Gonzalez <daniel@daniel.creatis>
Mon, 26 Nov 2012 13:41:47 +0000 (14:41 +0100)
committerDaniel Gonzalez <daniel@daniel.creatis>
Mon, 26 Nov 2012 13:47:59 +0000 (14:47 +0100)
lib/creaDevManagerLib/CDMUtilities.cpp
lib/creaDevManagerLib/CDMUtilities.h
lib/creaDevManagerLib/modelCDMMain.cpp
lib/creaDevManagerLib/wxCDMMainFrame.cpp

index a73282f247a68f3ee4e736840ec6b2b277c39421..0149e8dbd5488000f8481549c1570bf5fe3b2070 100644 (file)
@@ -35,6 +35,7 @@
 #include "CDMUtilities.h"
 
 #include<vector>
+#include<string>
 
 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<std::string> 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;
 
   }
index 15031ab3048a9dc08c868c330249eb8711604fe7..2b4f05bfcea9a505864c7969d26ea3964a9cf5df 100644 (file)
@@ -36,6 +36,7 @@
 #define CDMUTILITIES_H_
 
 #include<iostream>
+#include<cstddef>
 
 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_ */
index 307decac4eb4bbcc96bcf191523abf5b7dc0409b..e9df13ed38242c21fced54e9a490bdf032ea6ea5 100644 (file)
 
 #include "modelCDMMain.h"
 
-#include<iostream>
-#include<string>
+
+#include <cstdlib>
+#include <iostream>
+#include <string>
 #include <cstdio>
 #include <fstream>
 
@@ -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;
index e1578f94db44b5f5e95723a688da7b8a0dbcc39d..d60b3173dc21433c11ce50cb26bd9f6e56fec003 100755 (executable)
@@ -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"
 
 
 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();
 }