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