]> Creatis software - bbtkGEditor.git/blob - appli/bbEditor/bbEditor.cxx
2114 bbGEditor Feature New Normal Open bbg/bbs with command line
[bbtkGEditor.git] / appli / bbEditor / bbEditor.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 #
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
26 #ifdef _USE_WXWIDGETS_
27
28 //==========================================================================
29 // WITH WX
30 //==========================================================================
31
32 #include "bbtkwxGUIEditorGraphicBBS.h"
33
34 #include <wx/cmdline.h>
35 #include <wx/app.h>
36 #include <wx/sysopt.h>
37
38
39 static const wxCmdLineEntryDesc cmdLineDesc[] =
40 {
41 { wxCMD_LINE_PARAM,  NULL, NULL, _T("file"), 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 class wxBBEditorApp : public wxApp
49 {
50 public:
51   bool OnInit( );
52   int  OnExit() { return true; }
53
54          bool usage;
55         bool OnCmdLineParsed(wxCmdLineParser& parser);
56         void OnInitCmdLine(wxCmdLineParser& parser);
57 private:
58          std::vector<std::string> input_file;
59
60 };
61
62 IMPLEMENT_APP(wxBBEditorApp);
63
64
65
66 void wxBBEditorApp::OnInitCmdLine(wxCmdLineParser& parser)
67 {
68         //    std::cout << "wxBBEditorApp::OnInitCmdLine"<<std::endl;
69         parser.SetDesc(cmdLineDesc);
70 }
71
72
73 bool wxBBEditorApp::OnCmdLineParsed(wxCmdLineParser& parser)
74 {
75         int argc = parser.GetParamCount();
76         for (int i=0; i<argc; ++i) 
77     {
78                 std::string s = bbtk::wx2std(parser.GetParam(i));
79                 input_file.push_back(s);
80     }
81         
82         bool help = ( parser.Found(_T("h")) );
83         usage = (help && (input_file.size()==0));
84         if (usage) {
85                 std::cout << "bbEditor (The Black Box Development Graphic Editor) - bbtk "
86                 << bbtk::GetVersion() << " - (c) Creatis 2013"
87                 << std::endl;
88                 parser.Usage();
89         }
90         return true;
91 }
92
93
94
95
96 // ----------------------------------------------------------------------------
97 // The `main program' equivalent, creating the windows and returning the
98 // main frame
99 bool wxBBEditorApp::OnInit( )
100 {
101 #ifdef MACOSX
102         /* assume this is OSX */
103         wxSystemOptions::SetOption("mac.listctrl.always_use_generic", 1);
104 #endif
105
106         wxApp::OnInit();
107 #ifdef __WXGTK__
108   //See http://www.wxwindows.org/faqgtk.htm#locale
109   setlocale(LC_NUMERIC, "C");
110 #endif
111
112         bbtk::wxGUIEditorGraphicBBS *iegbbs;
113         iegbbs = new bbtk::wxGUIEditorGraphicBBS(NULL);
114         SetTopWindow(iegbbs);
115         iegbbs->Show(true);
116
117
118         // EED  ..To Do..
119         // 1. This block have to be mooved to the library
120         // 2. We have to verifiy if the file is a good bbg  or a good bbs
121         // 3. Clean the path to pout just the name of the file in the second parameter (information of the tabPanel)
122         //      OpenDiagram(<PATH+Filename>, <Filena>); 
123         for(int i=0;i<input_file.size();i++)
124         {
125                 int strsize=input_file[i].size()-1;
126                 if ((input_file[i])[strsize]=='g')
127                 {
128                         iegbbs->OpenDiagram(input_file[i], input_file[i]); 
129                 } 
130                 if ((input_file[i])[strsize]=='s')
131                 {
132                         iegbbs->OpenBBS(input_file[i], input_file[i]); 
133                 } 
134         }
135
136
137         return true;
138 }
139
140
141 #if defined(_WIN32)
142
143 //  How to have a Console and wxWidgets
144 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
145 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application
146 //  (cout's to the console are visible) and has a wxWidgets GUI,
147 //  you need to use the linker option "/subsystem:console" and the following code:
148 int main(int argc, char* argv[])
149 {
150         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
151 }
152
153 #endif // defined(_WIN32)
154
155
156 #else
157 //==========================================================================
158 // WITHOUT WX
159 //==========================================================================
160 #include <iostream>
161 int main(int argc, char* argv[])
162 {
163   std::cout << "bbStudio was not compiled with wxWidgets : ciao !" <<std::endl;
164   return 0;
165 }
166
167 // EOF
168 #endif //#ifdef _USE_WXWIDGETS_
169
170
171