]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/include/marInterface.cpp
7d180f061f881f38bbd7cdb5256821229e002145
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / include / marInterface.cpp
1 /*=========================================================================
2
3  Program:   wxMaracas
4  Module:    $RCSfile: marInterface.cpp,v $
5  Language:  C++
6  Date:      $Date: 2009/05/14 13:55:07 $
7  Version:   $Revision: 1.1 $
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 #ifdef _MSC_VER
18 #pragma warning ( disable : 4786 )
19 #pragma warning ( disable : 4251 )
20 #endif //_MSC_VER
21
22 #include "marInterface.h"
23 #include <wx/file.h>
24 #include <wx/log.h>
25
26
27
28
29 // ----------------------------------------------------------------------------
30 marInterface::marInterface( )
31 : _parameters( NULL ), _dicom( NULL ),
32 _experiment( NULL )
33 {
34         m_paramFileName=MAR_DEFAULT_FILE_PARAMETERS;
35     _parameters = new marParameters( );
36 //EED    _dicom = new marGdcmDicom( _parameters );
37     _experiment = new marExperiment( _parameters );
38         
39     // loadParameters( ); //PS !!! dangereux de faire des opĂ©rations d'E/S 
40         // dans des constructeurs
41 }
42
43 // ----------------------------------------------------------------------------
44 marInterface::~marInterface( ){
45     reset( );
46 }
47
48 // ----------------------------------------------------------------------------
49 bool marInterface::loadParameters( std::string pFile )
50 {
51         std::ifstream is( pFile.c_str( ),std::ios::binary|std::ios::in);
52
53 //EEDxx2.4 DEBuG
54 //      wxLogDebug(wxString("Loading parameters from file ") 
55 //              + wxString(pFile.c_str()));
56         
57         if( is==NULL )
58         {
59                 wxString errorMsg;
60                 errorMsg= wxString(_T("Error : Cannot open file "))
61                                 + wxString( pFile.c_str(), wxConvUTF8 )
62                                 + wxString(_T(" to load parameters"));
63 //EEDxx2.4 DEBuG
64 //              wxLogDebug(errorMsg);
65                 return (false);
66         }
67         _parameters->reset( );
68         if (_parameters->load( is ))
69         {
70                 is.close( );
71                 return( true );
72         }
73         else
74         {
75                 is.close();
76 //EEDxx2.4 DEBuG
77 //              wxLogDebug(wxString("Error : Cannot load parameters from file ")
78 //                              + wxString(pFile.c_str())
79 //                              + wxString(": file may be corrupted"));
80                 return (false);
81         }
82 }
83
84 // ----------------------------------------------------------------------------
85 bool marInterface::saveParameters( std::string pFile )
86 {
87         std::ofstream os(pFile.c_str( ),std::ios::binary | std::ios::out);
88         
89 //EEDxx2.4 DEBuG
90 //      wxLogDebug(wxString("Saving parameters to file ") 
91 //                      + wxString(pFile.c_str()));
92         
93         
94         if( os==NULL )
95         {
96                 wxString errorMsg;
97                 errorMsg= wxString(_T("Error : Cannot open file "))
98                                 + wxString(pFile.c_str(), wxConvUTF8)
99                                 + wxString(_T(" to save parameters"));
100 //EEDxx2.4 DEBuG
101 //              wxLogDebug(errorMsg);
102                 return( false );
103         }
104         if(_parameters->save( os ))
105         {
106                 os.close( );
107                 return( true );
108         }
109         else
110         {
111                 os.close();
112 //EEDxx2.4 DEBuG
113 //              wxLogDebug(wxString("Error : Cannot save parameters to file ")
114 //                              + wxString(pFile.c_str()));
115                 return (false);
116         }
117
118 }
119
120 // ----------------------------------------------------------------------------
121 bool marInterface::initExperiment( )
122 {
123     _experiment->reset( );
124     _experiment->initExperiment( _dicom->getVolume( ) );
125     return( true );
126         
127 }
128 // ----------------------------------------------------------------------------
129 bool marInterface::saveExperiment( std::string nFile )
130 {
131         std::ofstream os( nFile.c_str( ),std::ios::binary | std::ios::out );
132         
133 //EEDxx2.4 DEBuG
134 //      wxLogDebug(wxString("Saving experiment to file ") 
135 //                      + wxString(nFile.c_str()));
136         
137         wxString errorMsg;
138         errorMsg= wxString(_T("Cannot open file "))
139                         + wxString(nFile.c_str(), wxConvUTF8)
140                         + wxString(_T(" to save experiment"));
141
142         
143     if( os !=NULL ) {
144                 
145         _parameters->save( os );
146         _dicom->save( os );
147         _experiment->save( os );
148                 os.close( );
149                 return( true );
150                 
151     } // fi
152 //EEDxx2.4 DEBuG
153 //      wxLogDebug(errorMsg);
154     return( false );
155 }
156
157 // ----------------------------------------------------------------------------
158 bool marInterface::loadExperiment( std::string nFile )
159 {
160         std::ifstream is( nFile.c_str( ) ,std::ios::binary|std::ios::in );
161         
162 //EEDxx2.4 DEBuG
163 //      wxLogDebug(wxString("Loading experiment from file ") 
164 //                      + wxString(nFile.c_str()));
165         
166         wxString errorMsg;
167         errorMsg= wxString(_T("Cannot open file "))
168                         + wxString(nFile.c_str(), wxConvUTF8)
169                         + wxString(_T(" to load experiment"));
170         
171     if( is !=NULL) {
172                 
173         _parameters->reset( );
174         _dicom->reset( );
175         _experiment->reset( );
176                 
177         _parameters->load( is );
178         _dicom->load( is );
179         _experiment->load( is );
180                 is.close( );
181                 return( true );
182                 
183     } // fi
184 //EEDxx2.4 DEBuG
185 //      wxLogDebug(errorMsg);
186     return( false );
187 }
188
189 // ----------------------------------------------------------------------------
190 void marInterface::reset( )
191 {
192     if( _dicom          != NULL ) delete _dicom;
193     if( _experiment != NULL ) delete _experiment;
194     if( _parameters != NULL ) delete _parameters;
195
196     _dicom              = NULL;
197     _experiment = NULL;
198     _parameters = NULL;
199 }
200 // ----------------------------------------------------------------------------
201 void marInterface::SetParamFileName(std::string pFileName) 
202
203         m_paramFileName=pFileName; 
204 }
205 // ----------------------------------------------------------------------------
206 std::string  marInterface::GetParamFileName() 
207
208         return m_paramFileName;  
209 }
210 // ----------------------------------------------------------------------------
211 void marInterface::SetDicom(marFilesBase *dicom) 
212 {
213         _dicom=dicom;                            
214 }
215
216
217 // eof - interface.cxx
218
219
220 /* EED
221 void marInterface::SetVolumeData(int dimX,int dimY,int dimZ, float spacingX, float spacingY, float spacingZ, unsigned short * pixels)
222 {
223         if (_dicom!=NULL)
224                 _dicom->SetVolumeData(dimX,dimY,dimZ,spacingX,spacingY,spacingZ,pixels);
225 }
226 */
227