1 /*=========================================================================
4 Module: $RCSfile: wxMaracasDataBrowser.cxx,v $
6 Date: $Date: 2008/10/31 16:32:09 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
18 #include "wxMaracasFrame02.h"
19 #include "wxMaracasDataBrowser.h"
21 #include "marGdcmDicom.h"
24 #include "gdcmDocument.h"
25 #include "gdcmDicomDir.h"
26 #include "gdcmDicomDirPatient.h"
27 #include "gdcmDicomDirStudy.h"
28 #include "gdcmDicomDirSerie.h"
29 #include "gdcmDicomDirImage.h"
34 //-------------------------------------------------------------------------
36 class wxDlgDefineRegionZ : public wxDialog {
38 wxDlgDefineRegionZ(wxWindow *parent,int maxSize, wxString title);
41 void OnIni(wxScrollEvent& event);
42 void OnEnd(wxScrollEvent& event);
49 //-------------------------------------------------------------------------
50 //-------------------------------------------------------------------------
51 //-------------------------------------------------------------------------
53 wxDlgDefineRegionZ::wxDlgDefineRegionZ(wxWindow *parent,int maxSize, wxString title)
54 : wxDialog(parent, -1, title){
56 sldIni = new wxSlider(this, -1, 0 , 0, maxSize, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
57 sldEnd = new wxSlider(this, -1, maxSize, 0, maxSize, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
58 wxStaticText *text1 = new wxStaticText(this, -1, _T("Start : "));
59 wxStaticText *text2 = new wxStaticText(this, -1, _T("End : "));
60 wxButton *btnOk = new wxButton(this, wxID_OK , _T("OK"));
61 wxButton *btnCancel = new wxButton(this, wxID_CANCEL , _T("CANCEL"));
63 sldIni->SetSize(300,20);
64 sldEnd->SetSize(300,20);
66 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
72 sizer->Add(btnCancel);
73 this->SetSizer(sizer);
74 this->SetSize(450,200);
76 this->Connect(sldIni->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxDlgDefineRegionZ::OnIni );
77 this->Connect(sldEnd->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxDlgDefineRegionZ::OnEnd );
80 //-------------------------------------------------------------------------
82 int wxDlgDefineRegionZ::GetIniSlice(){
83 return sldIni->GetValue();
86 //-------------------------------------------------------------------------
88 int wxDlgDefineRegionZ::GetEndSlice(){
89 return sldEnd->GetValue();
92 //-------------------------------------------------------------------------
94 void wxDlgDefineRegionZ::OnIni(wxScrollEvent& event){
95 if (sldIni->GetValue() > sldEnd->GetValue() ){
96 sldEnd->SetValue(sldIni->GetValue() );
100 //-------------------------------------------------------------------------
102 void wxDlgDefineRegionZ::OnEnd(wxScrollEvent& event){
103 if (sldIni->GetValue() > sldEnd->GetValue() ){
104 sldIni->SetValue(sldEnd->GetValue() );
110 //-------------------------------------------------------------------------
111 //-------------------------------------------------------------------------
112 //-------------------------------------------------------------------------
115 BEGIN_EVENT_TABLE( wxMaracasDataBrowser, wxPanel )
116 EVT_BUTTON( ID_BUTTON_CHANGEDIR , wxMaracasDataBrowser::OnChangeDir )
117 EVT_BUTTON( ID_BUTTON_CHANGEDICOMFILE , wxMaracasDataBrowser::OnChangeDicomFile )
118 EVT_BUTTON( ID_BUTTON_CREATEDICOMFILE , wxMaracasDataBrowser::OnCreateDicomFile )
120 EVT_LIST_ITEM_SELECTED( ID_STUDIES_LIST, wxMaracasDataBrowser::OnStudySelected )
121 EVT_LIST_ITEM_SELECTED( ID_SERIES_LIST , wxMaracasDataBrowser::OnSerieSelected )
122 EVT_LIST_ITEM_ACTIVATED( ID_SERIES_LIST , wxMaracasDataBrowser::OnActivated )
125 //-------------------------------------------------------------------------
126 wxMaracasDataBrowser::wxMaracasDataBrowser( wxFrame* parent, marInterface* mar, wxWindowID id )
127 : wxPanel( parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
130 frame_parent = parent;
132 _splitter = new wxSplitterWindow( this, -1, wxDefaultPosition, wxSize( 1200, 800 ), wxSP_3D );
134 _studies = new wxListCtrl( _splitter, ID_STUDIES_LIST, wxDefaultPosition, wxSize(100,100), wxLC_REPORT );
135 _studies->InsertColumn( 0, _T("Patient's name" ));
136 _studies->InsertColumn( 1, _T("Patient's ID" ));
137 _studies->InsertColumn( 2, _T("Study's name" ));
138 _studies->InsertColumn( 3, _T("Study's ID" ));
139 _studies->InsertColumn( 4, _T("Study's date" ));
140 _studies->InsertColumn( 5, _T("Study's time" ));
141 _studies->InsertColumn( 6, _T("Study's description" ));
143 _series = new wxListCtrl( _splitter, ID_SERIES_LIST, wxDefaultPosition, wxSize(100,100), wxLC_REPORT );
144 _series->InsertColumn( 0, _T("Serie's name" ));
145 _series->InsertColumn( 1, _T("Serie's ID" ));
146 _series->InsertColumn( 2, _T("Serie's date" ));
147 _series->InsertColumn( 3, _T("Serie's time" ));
148 _series->InsertColumn( 4, _T("Modality" ));
149 _series->InsertColumn( 5, _T("Body part examined" ));
150 _series->InsertColumn( 6, _T("Serie's description" ));
151 _series->InsertColumn( 7, _T("Serie's diagnostic" ));
152 _series->InsertColumn( 8, _T("Institution name" ));
153 _series->InsertColumn( 9, _T("Number of images" ));
155 _splitter->SplitHorizontally( _studies, _series);
157 wxFlexGridSizer *szTop = new wxFlexGridSizer( 1 );
159 wxButton *btnChangeDir = new wxButton(this,ID_BUTTON_CHANGEDIR,_T("Change Directory")) ;
160 wxButton *btnChangeDicomFile = new wxButton(this,ID_BUTTON_CHANGEDICOMFILE,_T("Change DICOMDIR file")) ;
161 wxButton *btnCreateDicomFile = new wxButton(this,ID_BUTTON_CREATEDICOMFILE,_T("Create DICOMDIR file")) ;
163 btnChangeDir->SetSize(150,25);
164 btnChangeDicomFile->SetSize(150,25);
165 btnCreateDicomFile->SetSize(150,25);
167 szTop->Add( btnChangeDicomFile , 0 , wxALL, 10);
168 szTop->Add( btnCreateDicomFile , 0 , wxALL, 10);
169 szTop->Add( btnChangeDir , 0 , wxALL, 10);
173 wxFlexGridSizer *szVertical = new wxFlexGridSizer( 2 );
174 szVertical->Add( szTop, 1, wxALL|wxEXPAND , 0 );
175 szVertical->Add( _splitter, 1, wxALL|wxEXPAND , 0 );
177 this->SetSizer( szVertical );
178 this->SetAutoLayout( true );
182 szTop->SetSizeHints( this );
183 // _splitter->SetMinimumPaneSize( 50 );
184 _splitter->SetSashPosition(500,true);
189 //----------------------------------------------------------------------------
190 void wxMaracasDataBrowser::CreateDicomFile(){
191 marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
193 gdcmDicom->CreateDicomFile();
195 //-------------------------------------------------------------------------
196 void wxMaracasDataBrowser::LoadData( ){
203 _studies->DeleteAllItems( );
204 _series->DeleteAllItems( );
206 marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
207 gdcmDicom->FillDicomInfo(_parseDir);
208 GDCM_NAME_SPACE::DicomDir *dicomDir = gdcmDicom->getGdcmDicomDir();
209 GDCM_NAME_SPACE::DicomDirPatient *pa;
210 GDCM_NAME_SPACE::DicomDirStudy *st;
212 pa = dicomDir->GetFirstPatient();
213 while (pa){ // on degouline les PATIENT de ce DICOMDIR
214 st = pa->GetFirstStudy();
215 while ( st ) { // on degouline les STUDY de ce patient
216 tmp = _studies->InsertItem( it, wxString(pa->GetEntryString (0x0010, 0x0010).c_str(), wxConvUTF8) , 0 ); // Patient's Name
217 _studies->SetItemData( tmp, it );
218 _studies->SetItem( it, 1, wxString(pa->GetEntryString (0x0010, 0x0020).c_str(), wxConvUTF8) ); // ID_Patient_ID
219 _studies->SetItem( it, 2, wxString(st->GetEntryString (0x0020, 0x000d).c_str(), wxConvUTF8) ); // ID_Study_Instance_UID
220 _studies->SetItem( it, 3, wxString(st->GetEntryString (0x0020, 0x0010).c_str(), wxConvUTF8) ); // ID_Study_ID
221 _studies->SetItem( it, 4, wxString(st->GetEntryString (0x0008, 0x0020).c_str(), wxConvUTF8) ); // ID_Study_Date
222 _studies->SetItem( it, 5, wxString(st->GetEntryString (0x0008, 0x0030).c_str(), wxConvUTF8) ); // ID_Study_Time
223 _studies->SetItem( it, 6, wxString(st->GetEntryString (0x0008, 0x1030).c_str(), wxConvUTF8) ); // ID_Study_Description
225 st = pa->GetNextStudy();
227 pa = dicomDir->GetNextPatient();
230 _studies->Show( ); _series->Show( );
234 //----------------------------------------------------------------------------
235 void wxMaracasDataBrowser::LoadDicomData(int type, wxString msg){
236 wxString dirHome = _mar->_parameters->getStringParam(
237 marParameters::e_dicom_images_directory );
238 wxDirDialog dialog( this, msg,
239 ( !dirHome.IsEmpty( ) )? dirHome: wxGetHomeDir( ) );
241 if( dialog.ShowModal( ) == wxID_OK ){
242 _mar->_parameters->setStringParam(
243 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
244 _mar->saveParameters( );
254 this->CreateDicomFile();
260 //----------------------------------------------------------------------------
261 void wxMaracasDataBrowser::OnChangeDir( wxCommandEvent& event ){
262 this->LoadDicomData(1,_T("Choose a directory..."));
264 //----------------------------------------------------------------------------
265 void wxMaracasDataBrowser::OnChangeDicomFile( wxCommandEvent& event ){
266 this->LoadDicomData(2,_T("Choose a DICOM directory..."));
268 //----------------------------------------------------------------------------
269 void wxMaracasDataBrowser::OnCreateDicomFile( wxCommandEvent& event ){
270 this->LoadDicomData(3,_T("Create a DICOM file. Choose a directory..."));
272 //-------------------------------------------------------------------------
273 void wxMaracasDataBrowser::OnStudySelected( wxListEvent& event ){
275 int maxCount=event.GetIndex();
276 marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
277 GDCM_NAME_SPACE::DicomDir *dicomDir = gdcmDicom->getGdcmDicomDir();
278 GDCM_NAME_SPACE::DicomDirPatient *pa;
279 GDCM_NAME_SPACE::DicomDirStudy *st;
280 GDCM_NAME_SPACE::DicomDirSerie *se;
281 GDCM_NAME_SPACE::DicomDirImage *im;
284 pa = dicomDir->GetFirstPatient();
285 while ((pa) && (ok==true)){ // on degouline les PATIENT de ce DICOMDIR
286 st = pa->GetFirstStudy();
287 while ((st) && (ok==true)) { // on degouline les STUDY de ce patient
289 gdcmDicom->setActualPatient( pa );
290 gdcmDicom->setActualStudy( st );
295 st = pa->GetNextStudy();
298 pa = dicomDir->GetNextPatient();
301 _series->DeleteAllItems( );
305 se = st->GetFirstSerie();
306 while ( se ) { // on degouline les SERIES de cette study
307 tmp = _series->InsertItem( it, wxString(se->GetEntryString(0x0020, 0x000e).c_str(), wxConvUTF8) , 0 ); // ID_Series_Instance_UID
308 _series->SetItemData( tmp, it );
309 _series->SetItem( it, 1, wxString(se->GetEntryString(0x0020, 0x0011).c_str(), wxConvUTF8 )); // ID_Series_Number
310 _series->SetItem( it, 2, wxString(se->GetEntryString(0x0008, 0x0021).c_str(), wxConvUTF8 )); // ID_Series_Date
311 _series->SetItem( it, 3, wxString(se->GetEntryString(0x0008, 0x0031).c_str(), wxConvUTF8 )); // ID_Series_Time
312 _series->SetItem( it, 4, wxString(se->GetEntryString(0x0008, 0x0060).c_str(), wxConvUTF8 )); // ID_Modality
313 _series->SetItem( it, 5, wxString(se->GetEntryString(0x0018, 0x0015).c_str(), wxConvUTF8 )); // ID_Body_Part_Examined
314 _series->SetItem( it, 6, wxString(se->GetEntryString(0x0008, 0x103e).c_str(), wxConvUTF8 )); // ID_Series_Description
315 // _series->SetItem( it, 7, wxString(se->GetEntryString(0x0008, 0x1080).c_str(), wxConvUTF8 )); // ID_Admitting_Diagnoses_Description
316 // _series->SetItem( it, 8, wxString(se->GetEntryString(0x0008, 0x0080).c_str(), wxConvUTF8 )); // ID_Institution_Name
318 im = se->GetFirstImage();
319 while ( im ) { // on degouline les Images de cette serie
321 im = se->GetNextImage();
323 wxString strNumOfImg;
324 strNumOfImg.sprintf(_T("%d"),numOfImg);
325 _series->SetItem( it, 9, strNumOfImg ); // number of images in the serie
328 se = st->GetNextSerie();
332 frame_parent->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, false);
337 //-------------------------------------------------------------------------
338 void wxMaracasDataBrowser::OnSerieSelected( wxListEvent& event ){
339 marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
340 GDCM_NAME_SPACE::DicomDirStudy *st = gdcmDicom->getActualStudy();
341 GDCM_NAME_SPACE::DicomDirSerie *se;
344 int maxCount = event.GetIndex();
345 se = st->GetFirstSerie();
347 while ( (se) && (ok==true) ) { // on degouline les SERIES de cette study
349 gdcmDicom->setActualSerie( se );
353 se = st->GetNextSerie();
355 frame_parent->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, true);
357 //-------------------------------------------------------------------------
358 void wxMaracasDataBrowser::OnActivated( wxListEvent& event )
362 marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
363 GDCM_NAME_SPACE::DicomDirSerie *se;
364 GDCM_NAME_SPACE::DicomDirImage *im;
367 se = gdcmDicom->getActualSerie();
368 im = se->GetFirstImage();
369 while ( im ) { // on degouline les Images de cette serie
371 im = se->GetNextImage();
374 wxDlgDefineRegionZ *wxdlgdefineregionZ = new wxDlgDefineRegionZ(this,numOfImg, _T("Define Z region"));
375 if (wxdlgdefineregionZ->ShowModal() == wxID_OK ){
376 gdcmDicom->setIniSlice( wxdlgdefineregionZ->GetIniSlice() );
377 gdcmDicom->setEndSlice( wxdlgdefineregionZ->GetEndSlice() );
380 wxdlgdefineregionZ->Destroy();
383 wxCommandEvent _evt( wxEVT_COMMAND_MENU_SELECTED ,ID_TOOLBAR_IMAGE_BROWSER );
388 // EOF - wxDataBrowser.cxx