]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/wxMaracasApp02.cxx
BUG interaction ROI-creation line, rectangle, circle,
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / wxMaracasApp02.cxx
1 /*=========================================================================
2
3  Program:   wxMaracas
4  Module:    $RCSfile: wxMaracasApp02.cxx,v $
5  Language:  C++
6  Date:      $Date: 2008/11/21 17:24:42 $
7  Version:   $Revision: 1.2 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12    This software is distributed WITHOUT ANY WARRANTY; without even
13    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14    PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18 /**
19 * \mainpage wxMaracas version wxWindows
20 *
21 * \section intro Introduction
22 *
23 * This is the introduction.
24 *
25 * \section install Installation
26 *
27 * \subsection step1 Step 1: Opening the box
28 *
29 * etc...
30 */
31
32 // ----------------------------------------------------------------------------
33 // wx headers
34 // ----------------------------------------------------------------------------
35 #include "wx/wxprec.h"
36 #include <wx/datetime.h>
37 #ifndef WX_PRECOMP
38 #   include <wx/wx.h>
39 #endif
40
41 #include <wx/log.h>
42
43
44 // ----------------------------------------------------------------------------
45 // Local headers
46 // ----------------------------------------------------------------------------
47
48 #include <vtkDebugLeaks.h> 
49
50
51 #include "wxMaracasFrame02.h"
52 #include "wxMaracasApp02.h"
53 #include "marGdcmDicom.h"
54
55
56 #ifdef __WXGTK__
57 # include <locale.h>
58 #endif
59
60
61
62
63 //EED
64 // http://lists.wxwidgets.org/archive/wx-dev/msg30449.html
65 wxString getExecutablePath()
66 {
67     char buf[512];
68     char* slash;
69
70 #if defined(WIN32)
71     GetModuleFileName(NULL, buf, 511);
72     slash = strrchr(buf, '\\');
73     if (slash)
74     {
75         *slash = 0;
76     }
77 #elif defined(__LINUX__)
78     int res;
79     res = readlink("/proc/self/exe", buf, 512);
80     if (res == -1)
81         return _T("");
82     buf[res] = 0;
83     slash = strrchr(buf, '/');
84     if (slash)
85     {
86         *slash = 0;
87     }
88 #else
89     return "";
90 #endif
91
92     return wxString(buf, wxConvUTF8 );
93 }
94
95
96
97
98
99 // ----------------------------------------------------------------------------
100 // This macro implements the entry point (main function) for the application
101 // ----------------------------------------------------------------------------
102 IMPLEMENT_APP( wxMaracasApp02 );
103
104
105 // ----------------------------------------------------------------------------
106 // The `main program' equivalent, creating the windows and returning the
107 // main frame
108 bool wxMaracasApp02::OnInit( )
109 {
110 #ifdef __WXGTK__
111         //See http://www.wxwindows.org/faqgtk.htm#locale
112         setlocale(LC_NUMERIC, "C");
113 #endif
114 /*
115 #ifdef __WXDEBUG__
116         //static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",false,false);
117         static wxLogWindow * myLogWindow=new wxLogWindow(NULL,"Log Window",true,false);
118         wxLog::SetActiveTarget(myLogWindow);
119         myLogWindow->ClearTraceMasks();
120 #endif
121         wxLogDebug("---------------------------------------------------");
122         wxLogDebug("----------- Initialising application");
123 */
124 //      int nSize=_MAX_PATH;
125 //      LPTSTR lpFilename=(LPTSTR) (new char[nSize]);
126 //      GetModuleFileName(NULL,lpFilename,nSize);
127 //      wxString moduleFileName( lpFilename );
128
129         wxString moduleFileName = getExecutablePath();
130
131         wxString paramFileName=moduleFileName.BeforeLast( wxChar(92) )   // caracter '\'
132                 +wxString( wxChar(92) )
133                 +wxString( MAR_DEFAULT_FILE_PARAMETERS , wxConvUTF8 );
134         wxString dictionaryFileName=moduleFileName.BeforeLast( wxChar(92) )
135                 +wxString( wxChar(92) )
136                 +wxString( MAR_DEFAULT_FILE_DICTIONARY, wxConvUTF8 );
137
138         // Initialize MARACAS
139         _mar = new marInterface();
140
141         _mar->SetParamFileName( (const char*)(paramFileName.mb_str()) );
142         _mar->loadParameters();
143
144 /*
145         // Initialize MARACASCT
146         _marCT = new marInterfaceCT();
147         _marCT->SetParamFileName(paramFileName.c_str());
148         _marCT->loadParameters();
149 */
150
151 // EED ILPD
152
153 //EED 4 oct 2006
154 //      _mar->SetDicom( new marGdcmDicomILPD( _mar->_parameters ) );
155
156         //      _marCT->SetDicom( new marGdcmDicomILPD( _marCT->getParameters() ) );
157 //      _mar->SetDicom( new marGdcmDicom( _mar->_parameters ) );
158
159 /*
160 //--
161         // Create the main frame window 
162         wxMaracasFrame02* frame = new wxMaracasFrame02( ( wxFrame* )NULL,  -1 , _mar, _marCT, (const char*)dictionaryFileName.mb_str());
163         frame->Show( true );
164         frame->Maximize( );
165         this->SetTopWindow( frame );
166
167
168         //If no dir was set for DICOM force user to set it !
169         wxString dirHome = _mar->_parameters->getStringParam(
170                 marParameters::e_dicom_images_directory );
171         if( dirHome == "NO_DIRECTORY" || dirHome == "")
172         {
173 //              _mar->_parameters->setStringParam(
174 //                      marParameters::e_dicom_images_directory, "c:\\temp" );
175                 
176                 wxDirDialog dialog( frame, "Choose a DICOM directory...",
177                         ( !dirHome.IsEmpty( ) )? dirHome: wxGetHomeDir( ) );
178
179                 if( dialog.ShowModal( ) == wxID_OK )
180                 {
181                         _mar->_parameters->setStringParam(
182                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
183                         _marCT->getParameters()->setStringParam(
184                                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
185
186                         
187                 }
188                 
189         }
190         else
191         {
192                 _marCT->getParameters()->setStringParam(
193                         marParameters::e_dicom_images_directory, dirHome );
194
195         }
196
197
198         wxCommandEvent cmd;
199         frame->OnLoadPatientData( cmd );
200         _mar->saveParameters( );
201         _marCT->saveParameters( );
202 //EED   initialized=true;
203
204
205 // PS -> #ifndef DXMM
206 // PS ->        // GO !
207 // PS ->        SetExitOnFrameDelete(true);
208 // PS ->        m_pFrame->Show( true );
209 // PS -> #else
210 //      SetExitOnFrameDelete(true);
211 // PS -> #endif
212 //--
213 */
214
215 //--    
216
217         string tmpstring = (const char*) (dictionaryFileName.mb_str());
218         wxMaracasFrame03 *frame03 = new wxMaracasFrame03( (wxFrame*) NULL,  -1 , _mar, (char*)tmpstring.c_str() );
219         frame03->SetTitle(_T("Maracas - Evaluation version 1 July 2008 - Use limited to the research team - (Creatis-LRMN,Uniandes)"));
220
221         frame03->Show( true );
222         frame03->Maximize( );
223         this->SetTopWindow( frame03 );
224 //--
225
226 /*
227         wxDateTime date;
228         int year=date.GetCurrentYear();
229         int month=date.GetCurrentMonth()+1;
230         if (!((year==2006) && (month==01)))     
231         {
232                 wxMessageDialog msg(frame03, "ERROR EED:1010", "Message box", wxOK );
233                 msg.ShowModal();
234                 return  false;
235         }
236 */
237
238         return( true );
239 }
240 // ----------------------------------------------------------------------------
241 int wxMaracasApp02::OnExit(){
242
243
244         if (_mar!=NULL) { delete _mar; }
245
246
247 //EED   vtkDebugLeaks::PrintCurrentLeaks  (    ) ;
248
249         return true;
250
251 }
252
253 // EOF - wxMaracasApp02.cxx