]> Creatis software - crea.git/blob - appli/creaNewProject/creaNewProject.cpp
add previous authors
[crea.git] / appli / creaNewProject / creaNewProject.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 #include <creaWx.h>
29 #include <wx/dirdlg.h>
30 #include <stdlib.h> // for getenv
31
32 class myApp : public wxApp
33 {
34 public:
35   bool OnInit( );
36   int  OnExit() { return true; }
37 };
38
39 IMPLEMENT_APP(myApp);
40 CREA_WXMAIN_WITH_CONSOLE
41
42 bool myApp::OnInit( )
43 {
44   wxApp::OnInit();
45 #ifdef __WXGTK__
46   //See http://www.wxwindows.org/faqgtk.htm#locale
47   setlocale(LC_NUMERIC, "C");
48 #endif
49    wxInitAllImageHandlers();
50
51    wxString dir = wxDirSelector(_T("Select directory in which to create the project"), _T(""), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
52
53    if (dir.IsEmpty()) return false;
54
55    wxString name = wxGetTextFromUser(_T("Enter project name"),
56                                      _T("creaNewProject"),
57                                      _T("New"));
58    if (name.IsEmpty()) return false;
59    
60    wxString description = wxGetTextFromUser(_T("Enter Package Description (html format)"),
61                                      _T("create New Package"),
62                                      _T("NO_DESCRIPTION"));
63    if (description.IsEmpty()) return false;
64
65    wxString authorWX = wxGetTextFromUser(_T("Author (One word)"),
66                                      _T("Author"),
67                                      _T("Author_Name"));
68    if (description.IsEmpty()) return false;
69
70
71
72 #if(_WIN32)
73      
74         std::string command("creaNewProject.bat ");
75         std::string command1("creaSed.exe ");
76         std::string command2("del ");
77
78         command  += "\"" + crea::wx2std(dir) + "\" \"" + crea::wx2std(name) + "\"";
79         command1 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + crea::wx2std(name) + "> \"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt\"";
80         command2 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\"";
81         if ( ! system ( command.c_str() ) )
82         {
83                 system ( command1.c_str() );
84                 system ( command2.c_str() );
85
86         // Create a Package at the same time.   JPR
87                 char *author = (char*) (authorWX.mb_str()) ;
88                 std::string nomDirectory = crea::wx2std(dir) + "\\" + crea::wx2std(name);
89                 std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + crea::wx2std(name) + "_PKG";
90                 std::string bbCreatePackage("bbCreatePackage ");
91                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
92                 system (bbCreatePackage.c_str());               
93                 std::string add;
94                 add = "echo ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG) >> " + nomDirectory + "/CMakeLists.txt";
95                 system(add.c_str());
96
97                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
98                                 wxOK | wxICON_INFORMATION);
99         }       else    {
100                 wxString err(_T("An error occured while running '"));
101                 err +=  crea::std2wx(command) + _T("'");
102                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
103         }
104
105 // ------ LINUX / MacOS
106
107 #else
108         std::string command("creaNewProject.sh ");
109         command += "\"" + crea::wx2std(dir) + "\"" +" " + crea::wx2std(name);
110         
111         if ( ! system ( command.c_str() ) )
112         {
113                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
114                                         wxOK | wxICON_INFORMATION);
115
116                 // Create a Package at the same time.   JPR
117                 
118                 //execGUICreateNewPackage += "/../../../share/bbtk/bbs/toolsbbtk/appli/GUICreatePackage.bbs";
119                 //system(execGUICreateNewPackage.c_str());
120                 
121                 // or, better, new trick :
122                 // bbCreatePackage nomDirectory nomPackage author Description
123    
124 //EED           char *author = getenv("USER");
125 // JPR          char *author = (char*) (authorWX.mb_str());
126                 std::string author(authorWX.mb_str());
127                 std::string nomDirectory = crea::wx2std(dir) + "/" + crea::wx2std(name);
128                 std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + crea::wx2std(name) + "_PKG";
129
130                 std::string bbCreatePackage("bbCreatePackage ");
131                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
132                 system (bbCreatePackage.c_str());
133                 
134                 std::string add;
135                 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
136                 //std::cout << add << std::endl;
137                 system(add.c_str());
138                 
139         }
140         else
141         {       
142                 wxString err(_T("An error occured while running '"));
143                 err +=  crea::std2wx(command) + _T("'");
144                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
145         }
146
147 #endif
148
149    return false;
150 }
151