]> Creatis software - bbtkGEditor.git/blob - appli/bbEditor/bbEditor.cxx
#3251 Bug with segmentation fault with VTK 9.2 ( SupportsOpenGL )
[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 #include "vtkOutputWindow.h"
39 #include "vtkRenderWindow.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
58 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
59 #if wxMAJOR_VERSION <= 2
60         static const wxCmdLineEntryDesc cmdLineDesc[] =
61         {
62         { wxCMD_LINE_PARAM,  NULL, NULL, _T("file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
63         { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("Prints this help") },
64         //{ wxCMD_LINE_SWITCH, _T("d"), _T("debug"),   _T("Message all 9") },
65         { wxCMD_LINE_NONE }
66         };
67 #else
68         static const wxCmdLineEntryDesc cmdLineDesc[] =
69         {
70         { wxCMD_LINE_PARAM,  NULL, NULL, "file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
71         { wxCMD_LINE_SWITCH, "h", "help",   "Prints this help" },
72         //{ wxCMD_LINE_SWITCH, _T("d"), _T("debug"),   _T("Message all 9") },
73         { wxCMD_LINE_NONE }
74         };
75 #endif
76
77
78
79
80 class wxBBEditorApp : public wxApp
81 {
82 public:
83   bool OnInit( );
84   int  OnExit() { return true; }
85
86          bool usage;
87         bool OnCmdLineParsed(wxCmdLineParser& parser);
88         void OnInitCmdLine(wxCmdLineParser& parser);
89 private:
90          std::vector<std::string> input_file;
91
92 };
93
94 IMPLEMENT_APP(wxBBEditorApp);
95
96
97
98 void wxBBEditorApp::OnInitCmdLine(wxCmdLineParser& parser)
99 {
100         //    std::cout << "wxBBEditorApp::OnInitCmdLine"<<std::endl;
101         parser.SetDesc(cmdLineDesc);
102 }
103
104
105 bool wxBBEditorApp::OnCmdLineParsed(wxCmdLineParser& parser)
106 {
107         int argc = parser.GetParamCount();
108         for (int i=0; i<argc; ++i) 
109     {
110                 std::string s = bbtk::wx2std(parser.GetParam(i));
111                 input_file.push_back(s);
112     }
113         
114         bool help = ( parser.Found(_T("h")) );
115         usage = (help && (input_file.size()==0));
116         if (usage) {
117                 std::cout << "bbEditor (The Black Box Development Graphic Editor) - bbtk "
118                 << bbtk::GetVersion() << " - (c) Creatis 2013"
119                 << std::endl;
120                 parser.Usage();
121         }
122         return true;
123 }
124
125
126 // ----------------------------------------------------------------------------
127 // The `main program' equivalent, creating the windows and returning the
128 // main frame
129
130 #define GL_MAJOR_VERSION 0x821B
131 #define GL_MINOR_VERSION 0x821C
132
133 bool wxBBEditorApp::OnInit( )
134 {       
135         vtkRenderWindow *renWin = vtkRenderWindow::New();
136     
137     printf("EED wxBBEditorApp::OnInit >>>>> vtkRenderWindow IsDirect       %d\n", renWin->IsDirect() );
138
139 /* EED  2022-07-26 Segmentation fault with VTK9.2 in MacOs
140         int supportopengl=renWin->SupportsOpenGL();
141         printf("EED wxBBEditorApp::OnInit >>>>> vtkRenderWindow SupportsOpenGL %d\n", supportopengl );
142         renWin->Delete();
143         if (supportopengl==0)
144         {
145 #if defined(_WIN32)
146                 wxString message=wxT("OpenGL 3>= not detected.\n Try to install opengl drivers or use de opengl-mesa version.\n Copy from: <ProgramsFiles>\\CreaTools\\crea_TPdlls-4.0.0\\bin\\opengl-mesa the file: opengl32.dll\n to\n <ProgramsFiles>\\CreaTools\\CreaTools-3.0.0\\bin ");
147 #else
148                 wxString message=wxT("OpenGL 3>= not detected.\n Try to install opengl drivers or use de opengl-mesa version.\n ");     
149 #endif
150                 wxMessageBox(message);
151                 exit(0);
152         }
153 */
154         
155         vtkOutputWindowbbGEditor *vtkoutputwindowbbgeditor= vtkOutputWindowbbGEditor::New();
156         vtkOutputWindow::SetInstance( vtkoutputwindowbbgeditor );
157         vtkoutputwindowbbgeditor->Delete();
158
159 #ifdef MACOSX
160         /* assume this is OSX */
161         wxSystemOptions::SetOption("mac.listctrl.always_use_generic", 1);
162 #endif
163
164         wxApp::OnInit();
165 #ifdef __WXGTK__
166   //See http://www.wxwindows.org/faqgtk.htm#locale
167   setlocale(LC_NUMERIC, "C");
168 #endif
169
170         bbtk::wxGUIEditorGraphicBBS *iegbbs;
171
172         iegbbs = new bbtk::wxGUIEditorGraphicBBS(NULL);
173         SetTopWindow(iegbbs);
174         iegbbs->Show(true);
175
176
177         // EED  ..To Do..
178         // 1. This block have to be mooved to the library
179         // 2. We have to verifiy if the file is a good bbg  or a good bbs
180         // 3. Clean the path to pout just the name of the file in the second parameter (information of the tabPanel)
181         //      OpenDiagram(<PATH+Filename>, <Filena>); 
182         for(int i=0;i<input_file.size();i++)
183         {
184                 int strsize=input_file[i].size()-1;
185                 if ((input_file[i])[strsize]=='g')
186                 {
187                         iegbbs->OpenDiagram(input_file[i], input_file[i]); 
188                 } 
189                 if ((input_file[i])[strsize]=='s')
190                 {
191                         iegbbs->OpenBBS(input_file[i], input_file[i]); 
192                 } 
193         }
194         return true;
195 }
196
197
198 #if defined(_WIN32)
199
200 //  How to have a Console and wxWidgets
201 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
202 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application
203 //  (cout's to the console are visible) and has a wxWidgets GUI,
204 //  you need to use the linker option "/subsystem:console" and the following code:
205 int main(int argc, char* argv[])
206 {
207         char buffer[500];
208         wcstombs(buffer, ::GetCommandLine(), 500);
209         return WinMain(::GetModuleHandle(NULL), NULL, buffer, SW_SHOWNORMAL);
210 //      return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
211 }
212
213 #endif // defined(_WIN32)
214
215
216 #else
217 //==========================================================================
218 // WITHOUT WX
219 //==========================================================================
220 #include <iostream>
221 int main(int argc, char* argv[])
222 {
223   std::cout << "bbStudio was not compiled with wxWidgets : ciao !" <<std::endl;
224   return 0;
225 }
226
227 // EOF
228 #endif //#ifdef _USE_WXWIDGETS_
229
230
231