]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/include/wxMaracasApp02.cxx
#3207 creaMaracasVisu Feature New Normal branch vtk7itk4wx3-mingw
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / include / wxMaracasApp02.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28  Program:   wxMaracas
29  Module:    $RCSfile: wxMaracasApp02.cxx,v $
30  Language:  C++
31  Date:      $Date: 2012/11/15 14:14:56 $
32  Version:   $Revision: 1.2 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37    This software is distributed WITHOUT ANY WARRANTY; without even
38    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39    PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43 /**
44 * \mainpage wxMaracas version wxWindows
45 *
46 * \section intro Introduction
47 *
48 * This is the introduction.
49 *
50 * \section install Installation
51 *
52 * \subsection step1 Step 1: Opening the box
53 *
54 * etc...
55 */
56
57 // ----------------------------------------------------------------------------
58 // wx headers
59 // ----------------------------------------------------------------------------
60 #include "wx/wxprec.h"
61 #include <wx/datetime.h>
62 #ifndef WX_PRECOMP
63 #   include <wx/wx.h>
64 #endif
65
66 #include <wx/log.h>
67
68
69 // ----------------------------------------------------------------------------
70 // Local headers
71 // ----------------------------------------------------------------------------
72
73 #include <vtkDebugLeaks.h> 
74
75
76 #include "wxMaracasFrame02.h"
77 #include "wxMaracasApp02.h"
78 #include "marGdcmDicom.h"
79
80
81 #ifdef __WXGTK__
82 # include <locale.h>
83 #endif
84
85
86
87
88 //EED
89 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
90 wxString getExecutablePath()
91 {
92     char buf[512];
93     char* slash;
94
95 #if defined(WIN32)
96
97     wchar_t buf2[512];
98     long result = GetModuleFileName(NULL, buf2, 511);
99         int ret = wcstombs ( buf, buf2, sizeof(pname) );        
100 //    GetModuleFileName(NULL, buf, 511);
101
102     slash = strrchr(buf, '\\');
103     if (slash)
104     {
105         *slash = 0;
106     }
107 #elif defined(__LINUX__)
108     int res;
109     res = readlink("/proc/self/exe", buf, 512);
110     if (res == -1)
111         return _T("");
112     buf[res] = 0;
113     slash = strrchr(buf, '/');
114     if (slash)
115     {
116         *slash = 0;
117     }
118 #else
119     return "";
120 #endif
121
122     return wxString(buf, wxConvUTF8 );
123 }
124
125
126
127
128
129 // ----------------------------------------------------------------------------
130 // This macro implements the entry point (main function) for the application
131 // ----------------------------------------------------------------------------
132 IMPLEMENT_APP( wxMaracasApp02 );
133
134
135 // ----------------------------------------------------------------------------
136 // The `main program' equivalent, creating the windows and returning the
137 // main frame
138 bool wxMaracasApp02::OnInit( )
139 {
140 #ifdef __WXGTK__
141         //See http://www.wxwindows.org/faqgtk.htm#locale
142         setlocale(LC_NUMERIC, "C");
143 #endif
144 /*
145 #ifdef __WXDEBUG__
146         //static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",false,false);
147         static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",true,false);
148         wxLog::SetActiveTarget(myLogWindow);
149         myLogWindow->ClearTraceMasks();
150 #endif
151         wxLogDebug("---------------------------------------------------");
152         wxLogDebug("----------- Initialising application");
153 */
154 //      int nSize=_MAX_PATH;
155 //      LPTSTR lpFilename=(LPTSTR) (new char[nSize]);
156 //      GetModuleFileName(NULL,lpFilename,nSize);
157 //      wxString moduleFileName( lpFilename );
158
159         wxString moduleFileName = getExecutablePath();
160
161         wxString paramFileName=moduleFileName.BeforeLast( wxChar(92) )   // caracter '\'
162                 +wxString( wxChar(92) )
163                 +wxString( MAR_DEFAULT_FILE_PARAMETERS , wxConvUTF8 );
164         wxString dictionaryFileName=moduleFileName.BeforeLast( wxChar(92) )
165                 +wxString( wxChar(92) )
166                 +wxString( MAR_DEFAULT_FILE_DICTIONARY, wxConvUTF8 );
167
168         // Initialize MARACAS
169         _mar = new marInterface();
170
171         _mar->SetParamFileName( (const char*)(paramFileName.mb_str()) );
172         _mar->loadParameters();
173
174 /*
175         // Initialize MARACASCT
176         _marCT = new marInterfaceCT();
177         _marCT->SetParamFileName(paramFileName.c_str());
178         _marCT->loadParameters();
179 */
180
181 // EED ILPD
182
183 //EED 4 oct 2006
184 //      _mar->SetDicom( new marGdcmDicomILPD( _mar->_parameters ) );
185
186         //      _marCT->SetDicom( new marGdcmDicomILPD( _marCT->getParameters() ) );
187 //      _mar->SetDicom( new marGdcmDicom( _mar->_parameters ) );
188
189 /*
190 //--
191         // Create the main frame window 
192         wxMaracasFrame02* frame = new wxMaracasFrame02( ( wxFrame* )NULL,  -1 , _mar, _marCT, (const char*)dictionaryFileName.mb_str());
193         frame->Show( true );
194         frame->Maximize( );
195         this->SetTopWindow( frame );
196
197
198         //If no dir was set for DICOM force user to set it !
199         wxString dirHome = _mar->_parameters->getStringParam(
200                 marParameters::e_dicom_images_directory );
201         if( dirHome == "NO_DIRECTORY" || dirHome == "")
202         {
203 //              _mar->_parameters->setStringParam(
204 //                      marParameters::e_dicom_images_directory, "c:\\temp" );
205                 
206                 wxDirDialog dialog( frame, "Choose a DICOM directory...",
207                         ( !dirHome.IsEmpty( ) )? dirHome: wxGetHomeDir( ) );
208
209                 if( dialog.ShowModal( ) == wxID_OK )
210                 {
211                         _mar->_parameters->setStringParam(
212                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
213                         _marCT->getParameters()->setStringParam(
214                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
215
216                         
217                 }
218                 
219         }
220         else
221         {
222                 _marCT->getParameters()->setStringParam(
223                         marParameters::e_dicom_images_directory, dirHome );
224
225         }
226
227
228         wxCommandEvent cmd;
229         frame->OnLoadPatientData( cmd );
230         _mar->saveParameters( );
231         _marCT->saveParameters( );
232 //EED   initialized=true;
233
234
235 // PS -> #ifndef DXMM
236 // PS ->        // GO !
237 // PS ->        SetExitOnFrameDelete(true);
238 // PS ->        m_pFrame->Show( true );
239 // PS -> #else
240 //      SetExitOnFrameDelete(true);
241 // PS -> #endif
242 //--
243 */
244
245 //--    
246
247         string tmpstring = (const char*) (dictionaryFileName.mb_str());
248         wxMaracasFrame03 *frame03 = new wxMaracasFrame03( (wxFrame*) NULL,  -1 , _mar, (char*)tmpstring.c_str() );
249         frame03->SetTitle(_T("Maracas - Evaluation version 1 July 2008 - Use limited to the research team - (Creatis-LRMN,Uniandes)"));
250
251         frame03->Show( true );
252         frame03->Maximize( );
253         this->SetTopWindow( frame03 );
254 //--
255
256 /*
257         wxDateTime date;
258         int year=date.GetCurrentYear();
259         int month=date.GetCurrentMonth()+1;
260         if (!((year==2006) && (month==01)))     
261         {
262                 wxMessageDialog msg(frame03, "ERROR EED:1010", "Message box", wxOK );
263                 msg.ShowModal();
264                 return  false;
265         }
266 */
267
268         return( true );
269 }
270 // ----------------------------------------------------------------------------
271 int wxMaracasApp02::OnExit(){
272
273
274         if (_mar!=NULL) { delete _mar; }
275
276
277 //EED   vtkDebugLeaks::PrintCurrentLeaks  (    ) ;
278
279         return true;
280
281 }
282
283 // EOF - wxMaracasApp02.cxx