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