]> Creatis software - crea.git/blob - appli/creaNewProject/creaNewProject.cpp
#3243 creaBug New Normal - Size DialgoWindow and size conflicts
[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
88                 //2018-07-06 mingw64
89 //              char *author = (char*) (authorWX.mb_str()) ;
90                 char *author = authorWX.mb_str() ;
91                 
92                 std::string nomDirectory = crea::wx2std(dir) + "\\" + crea::wx2std(name);
93                 std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + crea::wx2std(name) + "_PKG";
94                 std::string bbCreatePackage("bbCreatePackage ");
95                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
96                 system (bbCreatePackage.c_str());               
97                 std::string add;
98                 add = "echo ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG) >> " + nomDirectory + "/CMakeLists.txt";
99                 system(add.c_str());
100
101                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
102                                 wxOK | wxICON_INFORMATION);
103         }       else    {
104                 wxString err(_T("An error occured while running '"));
105                 err +=  crea::std2wx(command) + _T("'");
106                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
107         }
108
109 // ------ LINUX / MacOS
110
111 #else
112         std::string command("creaNewProject.sh ");
113         command += "\"" + crea::wx2std(dir) + "\"" +" " + crea::wx2std(name);
114         
115         if ( ! system ( command.c_str() ) )
116         {
117                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
118                                         wxOK | wxICON_INFORMATION);
119
120                 // Create a Package at the same time.   JPR
121                 
122                 //execGUICreateNewPackage += "/../../../share/bbtk/bbs/toolsbbtk/appli/GUICreatePackage.bbs";
123                 //system(execGUICreateNewPackage.c_str());
124                 
125                 // or, better, new trick :
126                 // bbCreatePackage nomDirectory nomPackage author Description
127    
128 //EED           char *author = getenv("USER");
129 // JPR          char *author = (char*) (authorWX.mb_str());
130                 std::string author(authorWX.mb_str());
131                 std::string nomDirectory = crea::wx2std(dir) + "/" + crea::wx2std(name);
132                 std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + crea::wx2std(name) + "_PKG";
133
134                 std::string bbCreatePackage("bbCreatePackage ");
135                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
136                 system (bbCreatePackage.c_str());
137                 
138                 std::string add;
139                 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
140                 //std::cout << add << std::endl;
141                 system(add.c_str());
142                 
143         }
144         else
145         {       
146                 wxString err(_T("An error occured while running '"));
147                 err +=  crea::std2wx(command) + _T("'");
148                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
149         }
150
151 #endif
152
153    return false;
154 }
155