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