]> Creatis software - crea.git/commitdiff
Feature #1711
authorDaniel Gonzalez <daniel@daniel.creatis>
Wed, 5 Dec 2012 10:10:29 +0000 (11:10 +0100)
committerDaniel Gonzalez <daniel@daniel.creatis>
Wed, 5 Dec 2012 10:10:29 +0000 (11:10 +0100)
CreaDevManager application implementation

Package creation implemented
Application creation implemented

missing adjustments for windows
other scripts from bbtk don't return error codes

12 files changed:
lib/creaDevManagerLib/modelCDMAppli.cpp
lib/creaDevManagerLib/modelCDMAppli.h
lib/creaDevManagerLib/modelCDMLib.cpp
lib/creaDevManagerLib/modelCDMLib.h
lib/creaDevManagerLib/modelCDMProject.cpp
lib/creaDevManagerLib/modelCDMProject.h
lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp
lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp
lib/creaDevManagerLib/wxCDMMainFrame.cpp
lib/creaDevManagerLib/wxCDMNewPackageDialog.cpp [new file with mode: 0644]
lib/creaDevManagerLib/wxCDMNewPackageDialog.h [new file with mode: 0644]
lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp

index 2bba913c0f7b98255fe3b77ff0a3a29915d22937..1f08f3b9b8dc5b4a2b2e429c85add024185193fb 100644 (file)
@@ -34,6 +34,9 @@
 
 #include "modelCDMAppli.h"
 
+#include <iostream>
+#include <fstream>
+
 #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)
index c8d6003f5596da740ed33fd1001f2cc975fe0e65..8b8ecbe355cc884de0c44ac51d3ffeb3026913cb 100644 (file)
@@ -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 = "/"
index 9ecaea45f3a39c495dd863f29bceba4ba4a3c8ca..236f7a311e6d57035ba7f4ebcfe85380be020d2b 100644 (file)
@@ -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);
index 3991384cc589c98dd326fad452b253c0ae13c7d4..71ed033237785aa705ae51ef15a266a565de11b9 100644 (file)
@@ -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 = "/"
index 7cadb24241c62d308236cfbf0bfe020b406b68af..23dd1666d041bbc0a186c7628e0adebcb00d9914 100644 (file)
@@ -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<std::string> 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 <path> <name> [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++)
index 2cb35b25e8559be5218d2bddb19f0a36d74e22db..c6f5830a7281fad11e3eeeabf85334a362c575b6 100644 (file)
@@ -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,
index 617f39fbb4e725aa59b35da0fd10207777122f3f..9d815d224db30a7d351e20426e27317f3529a00b 100644 (file)
 #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)
index 878d51da92f39ec6203c7b56a06e8a9492a7c796..f19dbcfb4d23fdcf76d8e087d216c624006236a9 100644 (file)
@@ -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);
index 74999d621a17a74e69468caedd1b6ca8c26eacae..94a7a38cd77f1569e217b4fb9160e9ec21d6d0f7 100755 (executable)
@@ -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 (file)
index 0000000..8b0efff
--- /dev/null
@@ -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 (file)
index 0000000..1c76552
--- /dev/null
@@ -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 <creaWx.h>
+#include <wx/dialog.h>
+
+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_ */
index 5093d7173a7855b6141c09b26d8147488f418bb3..a624244ff57c66a256dc307981509bd87e1da13b 100644 (file)
@@ -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 <path> <name> [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)