]> Creatis software - bbtk.git/blob - kernel/appli/bbStudio/bbStudio.cxx
25e4612cf6f2fd227a4601f37534e3850519a199
[bbtk.git] / kernel / appli / bbStudio / bbStudio.cxx
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 #ifdef _USE_WXWIDGETS_
29
30 //==========================================================================
31 // WITH WX
32 //==========================================================================
33 #include "bbtkWxGUIScriptingInterface.h"
34
35 #include <wx/cmdline.h> 
36 #include <vector>
37
38 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
39 #if wxMAJOR_VERSION <= 2
40         static const wxCmdLineEntryDesc cmdLineDesc[] =
41         {
42           { wxCMD_LINE_PARAM,  NULL, NULL, _T("file1 [file2 [...]]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
43           { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("Prints this help") },
44           { wxCMD_LINE_SWITCH, _T("d"), _T("debug"),   _T("Message all 9") },
45           { wxCMD_LINE_NONE }
46         };
47 #else
48         static const wxCmdLineEntryDesc cmdLineDesc[] =
49         {
50           { wxCMD_LINE_PARAM,  NULL, NULL, "file1 [file2 [...]]", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
51           { wxCMD_LINE_SWITCH, "h", "help",   "Prints this help" },
52           { wxCMD_LINE_SWITCH, "d", "debug",   "Message all 9" },
53           { wxCMD_LINE_NONE }
54         };
55 #endif
56
57
58
59
60 class wxBBIApp : public wxApp
61 {
62 public:
63   bool OnInit( );
64   int  OnExit() { return true; }
65   void OnInitCmdLine(wxCmdLineParser& parser);
66   bool OnCmdLineParsed(wxCmdLineParser& parser);
67
68   bool usage;
69   std::vector<std::string> input_file;
70 };
71
72 IMPLEMENT_APP(wxBBIApp);
73
74 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
75 {
76   //    std::cout << "OnInitCmdLine"<<std::endl;
77   parser.SetDesc(cmdLineDesc);
78 }
79
80 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
81 {
82   int argc = parser.GetParamCount();
83   for (int i=0; i<argc; ++i) 
84     {
85       std::string s = bbtk::wx2std(parser.GetParam(i));
86       input_file.push_back(s);
87     }
88
89   bool help = ( parser.Found(_T("h")) );
90   usage = (help && (input_file.size()==0));
91   if (usage) {
92     std::cout << "bbStudio (The Black Box Development Studio) - bbtk "
93               << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
94               << std::endl;
95     parser.Usage();
96   }
97   else 
98   {
99         if ( parser.Found(_T("d")) )
100         {
101                 bbtk::MessageManager::SetMessageLevel("all",9);
102         }
103   }
104
105
106   return true;
107 }
108
109
110
111 // ----------------------------------------------------------------------------
112 // The `main program' equivalent, creating the windows and returning the
113 // main frame
114 bool wxBBIApp::OnInit( )
115 {
116   //    std::cout << "OnInit"<<std::endl;
117   wxApp::OnInit();
118 #ifdef __WXGTK__
119   //See http://www.wxwindows.org/faqgtk.htm#locale
120   setlocale(LC_NUMERIC, "C");
121 #endif
122   if (usage) return false;
123   
124   bbtk::WxGUIScriptingInterface *I = 
125     new bbtk::WxGUIScriptingInterface(0);
126   SetTopWindow(I);  
127   I->Show(true);
128
129   std::vector<std::string>::const_iterator i;
130   i=input_file.begin(); 
131   if (i!=input_file.end()) I->Open(*i);
132
133   return true;
134 }
135
136
137 #if defined(_WIN32) 
138
139 //  How to have a Console and wxWidgets
140 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
141 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
142 //  (cout's to the console are visible) and has a wxWidgets GUI, 
143 //  you need to use the linker option "/subsystem:console" and the following code:
144 int main(int argc, char* argv[])
145 {
146         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
147 }
148
149 #endif // defined(_WIN32) 
150
151
152 #else
153 //==========================================================================
154 // WITHOUT WX
155 //==========================================================================
156 #include <iostream>
157 int main(int argc, char* argv[])
158 {  
159   std::cout << "bbStudio was not compiled with wxWidgets : ciao !" <<std::endl;
160   return 0;
161 }
162
163 // EOF
164 #endif //#ifdef _USE_WXWIDGETS_
165
166
167