]> Creatis software - crea.git/blob - lib/creaDevManagerLib/ControlCreaDevManagerProject.cpp
Bug #1912
[crea.git] / lib / creaDevManagerLib / ControlCreaDevManagerProject.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26 */ 
27
28
29 /*
30  * ControlCreaDevManagerProject.cpp
31  *
32  *  Created on: 5/11/2012
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "ControlCreaDevManagerProject.h"
37
38 #include <creaWx.h>
39 #include <wx/dirdlg.h>
40 #include <stdlib.h> // for getenv
41
42 ControlCreaDevManagerProject::ControlCreaDevManagerProject()
43 {
44   // TODO Auto-generated constructor stub
45
46 }
47
48 ControlCreaDevManagerProject::~ControlCreaDevManagerProject()
49 {
50   // TODO Auto-generated destructor stub
51 }
52
53 bool ControlCreaDevManagerProject::CreateProject(const std::string& name, const std::string& dir, const std::string& author, const std::string& description)
54 {
55   // ------ Windows
56 #if(_WIN32)
57
58   std::string command("creaNewProject.bat ");
59   std::string command1("creaSed.exe ");
60   std::string command2("del ");
61
62   command  += "\"" + dir + "\" \"" + name + "\"";
63   command1 += "\"" + dir+"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + dir + "\\" + name + "\\CMakeLists.txt\"";
64   command2 += "\"" + dir+"\\"+name+"\\CMakeLists.txt.in\"";
65   if ( ! system ( command.c_str() ) )
66   {
67     system ( command1.c_str() );
68     system ( command2.c_str() );
69
70   // Create a Package at the same time.   JPR
71     char *author = author.c_str();
72     std::string nomDirectory = dir + "\\" + name;
73     std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG";
74     std::string bbCreatePackage("bbCreatePackage ");
75     bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
76     system (bbCreatePackage.c_str());
77     std::string add;
78     add = "echo ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG) >> " + nomDirectory + "/CMakeLists.txt";
79     system(add.c_str());
80
81     wxMessageBox(_T("New Project created !"),_T("creaNewProject"), wxOK | wxICON_INFORMATION);
82   }
83   else
84   {
85     wxString err(_T("An error occured while running '"));
86     err +=  crea::std2wx(command) + _T("'");
87     wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
88     return false;
89   }
90
91 #else
92   // ------ LINUX / MacOS
93   std::string command("creaNewProject.sh ");
94   command += "\"" + dir + "\"" +" " + name;
95   std::cout << "executing " << command << std::endl;
96   if ( ! system ( command.c_str() ) )
97   {
98     //wxMessageBox(_T("New Project created !"),_T("creaNewProject"), wxOK | wxICON_INFORMATION);
99
100     std::string nomDirectory = dir + "/" + name;
101     std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG";
102
103     std::string bbCreatePackage("bbCreatePackage ");
104     bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
105     std::cout << "executing " << bbCreatePackage << std::endl;
106     system (bbCreatePackage.c_str());
107
108     std::string add;
109     add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
110     //std::cout << add << std::endl;
111     std::cout << "executing " << add << std::endl;
112     system(add.c_str());
113
114   }
115   else
116   {
117     wxString err(_T("An error occured while running '"));
118     err +=  crea::std2wx(command) + _T("'");
119     wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
120     return false;
121   }
122
123 #endif
124
125    return true;
126 }