]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/include/wxMaracasApp02.cxx
Support #1768 CREATIS Licence insertion
[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     GetModuleFileName(NULL, buf, 511);
97     slash = strrchr(buf, '\\');
98     if (slash)
99     {
100         *slash = 0;
101     }
102 #elif defined(__LINUX__)
103     int res;
104     res = readlink("/proc/self/exe", buf, 512);
105     if (res == -1)
106         return _T("");
107     buf[res] = 0;
108     slash = strrchr(buf, '/');
109     if (slash)
110     {
111         *slash = 0;
112     }
113 #else
114     return "";
115 #endif
116
117     return wxString(buf, wxConvUTF8 );
118 }
119
120
121
122
123
124 // ----------------------------------------------------------------------------
125 // This macro implements the entry point (main function) for the application
126 // ----------------------------------------------------------------------------
127 IMPLEMENT_APP( wxMaracasApp02 );
128
129
130 // ----------------------------------------------------------------------------
131 // The `main program' equivalent, creating the windows and returning the
132 // main frame
133 bool wxMaracasApp02::OnInit( )
134 {
135 #ifdef __WXGTK__
136         //See http://www.wxwindows.org/faqgtk.htm#locale
137         setlocale(LC_NUMERIC, "C");
138 #endif
139 /*
140 #ifdef __WXDEBUG__
141         //static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",false,false);
142         static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",true,false);
143         wxLog::SetActiveTarget(myLogWindow);
144         myLogWindow->ClearTraceMasks();
145 #endif
146         wxLogDebug("---------------------------------------------------");
147         wxLogDebug("----------- Initialising application");
148 */
149 //      int nSize=_MAX_PATH;
150 //      LPTSTR lpFilename=(LPTSTR) (new char[nSize]);
151 //      GetModuleFileName(NULL,lpFilename,nSize);
152 //      wxString moduleFileName( lpFilename );
153
154         wxString moduleFileName = getExecutablePath();
155
156         wxString paramFileName=moduleFileName.BeforeLast( wxChar(92) )   // caracter '\'
157                 +wxString( wxChar(92) )
158                 +wxString( MAR_DEFAULT_FILE_PARAMETERS , wxConvUTF8 );
159         wxString dictionaryFileName=moduleFileName.BeforeLast( wxChar(92) )
160                 +wxString( wxChar(92) )
161                 +wxString( MAR_DEFAULT_FILE_DICTIONARY, wxConvUTF8 );
162
163         // Initialize MARACAS
164         _mar = new marInterface();
165
166         _mar->SetParamFileName( (const char*)(paramFileName.mb_str()) );
167         _mar->loadParameters();
168
169 /*
170         // Initialize MARACASCT
171         _marCT = new marInterfaceCT();
172         _marCT->SetParamFileName(paramFileName.c_str());
173         _marCT->loadParameters();
174 */
175
176 // EED ILPD
177
178 //EED 4 oct 2006
179 //      _mar->SetDicom( new marGdcmDicomILPD( _mar->_parameters ) );
180
181         //      _marCT->SetDicom( new marGdcmDicomILPD( _marCT->getParameters() ) );
182 //      _mar->SetDicom( new marGdcmDicom( _mar->_parameters ) );
183
184 /*
185 //--
186         // Create the main frame window 
187         wxMaracasFrame02* frame = new wxMaracasFrame02( ( wxFrame* )NULL,  -1 , _mar, _marCT, (const char*)dictionaryFileName.mb_str());
188         frame->Show( true );
189         frame->Maximize( );
190         this->SetTopWindow( frame );
191
192
193         //If no dir was set for DICOM force user to set it !
194         wxString dirHome = _mar->_parameters->getStringParam(
195                 marParameters::e_dicom_images_directory );
196         if( dirHome == "NO_DIRECTORY" || dirHome == "")
197         {
198 //              _mar->_parameters->setStringParam(
199 //                      marParameters::e_dicom_images_directory, "c:\\temp" );
200                 
201                 wxDirDialog dialog( frame, "Choose a DICOM directory...",
202                         ( !dirHome.IsEmpty( ) )? dirHome: wxGetHomeDir( ) );
203
204                 if( dialog.ShowModal( ) == wxID_OK )
205                 {
206                         _mar->_parameters->setStringParam(
207                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
208                         _marCT->getParameters()->setStringParam(
209                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
210
211                         
212                 }
213                 
214         }
215         else
216         {
217                 _marCT->getParameters()->setStringParam(
218                         marParameters::e_dicom_images_directory, dirHome );
219
220         }
221
222
223         wxCommandEvent cmd;
224         frame->OnLoadPatientData( cmd );
225         _mar->saveParameters( );
226         _marCT->saveParameters( );
227 //EED   initialized=true;
228
229
230 // PS -> #ifndef DXMM
231 // PS ->        // GO !
232 // PS ->        SetExitOnFrameDelete(true);
233 // PS ->        m_pFrame->Show( true );
234 // PS -> #else
235 //      SetExitOnFrameDelete(true);
236 // PS -> #endif
237 //--
238 */
239
240 //--    
241
242         string tmpstring = (const char*) (dictionaryFileName.mb_str());
243         wxMaracasFrame03 *frame03 = new wxMaracasFrame03( (wxFrame*) NULL,  -1 , _mar, (char*)tmpstring.c_str() );
244         frame03->SetTitle(_T("Maracas - Evaluation version 1 July 2008 - Use limited to the research team - (Creatis-LRMN,Uniandes)"));
245
246         frame03->Show( true );
247         frame03->Maximize( );
248         this->SetTopWindow( frame03 );
249 //--
250
251 /*
252         wxDateTime date;
253         int year=date.GetCurrentYear();
254         int month=date.GetCurrentMonth()+1;
255         if (!((year==2006) && (month==01)))     
256         {
257                 wxMessageDialog msg(frame03, "ERROR EED:1010", "Message box", wxOK );
258                 msg.ShowModal();
259                 return  false;
260         }
261 */
262
263         return( true );
264 }
265 // ----------------------------------------------------------------------------
266 int wxMaracasApp02::OnExit(){
267
268
269         if (_mar!=NULL) { delete _mar; }
270
271
272 //EED   vtkDebugLeaks::PrintCurrentLeaks  (    ) ;
273
274         return true;
275
276 }
277
278 // EOF - wxMaracasApp02.cxx