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