1 #include <creaImageIOPACSConnection.h>
2 #include <creaImageIOWxPACSConnectionPanel.h>
3 #include <creaImageIOWxGimmickView.h>
4 #include <creaImageIOWxTreeView.h>
5 #include <creaImageIOSystem.h>
6 #include <creaImageIOWxCustomizeConfigPanel.h>
7 #include <creaImageIOWxListenerPanel.h>
8 #include <creaImageIOWxEditFieldsPanel.h>
9 #include <creaImageIOWxAttributeSelectionPanel.h>
10 #include <creaImageIOWxDescriptorPanel.h>
11 #include <creaImageIOWxDumpPanel.h>
12 #include <creaImageIOWxExportDlg.h>
13 #include <creaImageIOWxOutputDlg.h>
14 #include <creaImageIOOutputModel.h>
18 #include "icons/accept.xpm"
19 #include "icons/add.xpm"
20 #include "icons/folder-down.xpm"
21 #include "icons/page-down.xpm"
22 #include "icons/remove.xpm"
23 #include "icons/database-add.xpm"
24 #include "icons/create-database.xpm"
25 #include "icons/help.xpm"
26 #include "icons/synchronize.xpm"
27 #include "icons/settings.xpm"
28 #include "icons/tools.xpm"
29 //#include "icons/import.xpm"
31 #include <wx/imaglist.h>
32 #include <wx/popupwin.h>
33 #include<boost/filesystem/operations.hpp>
34 #if defined(BUILD_BRUKER)
35 #include "bruker2dicom.h"
39 #include <creaImageIOGimmick.h>
47 //======================================================================
48 // The ids of the different tools
53 TOOL_ADDDATABASE_ID = 3,
55 TOOL_SYNCHRONIZE_ID = 5,
62 //======================================================================
64 //================================================================
66 const int icon_number = 11;
83 //================================================================
85 //================================================================
87 const icon_id Icon[5] = { Icon_Database,
93 //================================================================
96 //======================================================================
98 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
105 int number_of_threads)
106 : wxPanel(parent,id,pos,size),
107 GimmickView(gimmick, number_of_threads),
111 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
113 // Sets the current directory to the home dir
114 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
116 // Connect the AddProgress callback
117 gimmick->ConnectAddProgressObserver
118 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
120 // Create the list of icons (mIcon)
124 msizer = new wxBoxSizer(wxVERTICAL);
126 // Create the tool bar
128 msizer->Add( mToolBar, 0, wxGROW, 0);
130 // Split part below toolbar into notebook for views and panel
131 // for preview, messages...
132 mSplitter = new wxSplitterWindow( this , -1);
135 mNotebook = new wxNotebook(mSplitter,
136 -1, wxDefaultPosition, wxDefaultSize, 0);
141 mSelectionMaxDimension = max_dim;
142 mSelectionMinDimension = min_dim;
148 mBottomPanel = new wxPanel(mSplitter,-1);
150 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
154 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
155 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
156 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
158 mViewer->SetImageVector(pointers);
159 mViewer->StartPlayer();
162 mbottom_sizer->Add(mViewer,1,wxGROW,1);
165 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
166 mbottom_sizer->Add(mText,0,wxGROW,0);
170 mBottomPanel->SetSizer(mbottom_sizer);
173 int hsize = size.GetHeight();
175 int top_minsize = 450;
176 int bottom_minsize = 50;
178 mSplitter->SetMinimumPaneSize( bottom_minsize );
179 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
182 msizer->Add( mSplitter, 1, wxGROW, 0);
188 //mListener=new Listener();
189 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
190 //mListener->Create();
192 // mListener->Pause();
196 //======================================================================
198 //======================================================================
200 WxGimmickView::~WxGimmickView()
202 // stop the viewer before application exit.
203 mViewer->StopPlayer();
204 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
208 //if(mListener->IsAlive()) { mListener->Delete(); }
210 //======================================================================
212 //======================================================================
213 /// Creates the tool bar
214 void WxGimmickView::CreateToolBar()
216 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
217 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
220 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
222 mIcon->GetBitmap(Icon_page_down),
223 _T("Add one or more file to database")
225 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
227 mIcon->GetBitmap(Icon_folder_down),
228 _T("Add the content of a folder to database")
230 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
232 mIcon->GetBitmap(Icon_database_add),
233 _T("Open a local or distant database")
235 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
237 mIcon->GetBitmap(Icon_remove),
238 _T("Remove selected items")
240 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
242 mIcon->GetBitmap(Icon_synchronize),
243 _T("Synchronizes the database with disk")
245 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
247 mIcon->GetBitmap(Icon_help),
248 _T("Open help window")
250 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
251 _T("System settings"),
252 mIcon->GetBitmap(Icon_settings),
253 _T("Allows the modification of various system settings")
255 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
257 mIcon->GetBitmap(Icon_tools),
258 _T("Applies tools to images")
260 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
261 _T("Create database"),
262 mIcon->GetBitmap(Icon_create_database),
263 _T("Create DB from an Attributes Descriptor file")
265 #if defined(BUILD_PACS)
266 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
267 _T("PACS Connection,"),
268 mIcon->GetBitmap(Icon_create_database),
269 _T("Echo, Find and Get to a PACS")
272 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
276 //======================================================================
279 //======================================================================
280 /// Create the tree view for TreeHandler provided
281 void WxGimmickView::CreateTreeView( TreeHandler* h)
283 std::string name(h->GetTree().GetAttribute("Name"));
284 GimmickMessage(2,"Creating the tree view for '"<<
285 name<<"'"<<std::endl);
286 // Create the WxTreeView
287 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
289 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
290 // ALREADY IN THE MAP
291 GetTreeViewMap()[name] = view;
294 mNotebook->AddPage( view, crea::std2wx(name) );
298 //======================================================================
299 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
301 std::vector<std::string> files;
302 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
303 //ReadImagesNotThreaded(s, files, dim);
306 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
307 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
312 //======================================================================
313 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
315 std::vector<std::string> files;
316 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
317 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
319 ReadImagesNotThreadedInVector(s, files, dim);
323 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
324 /// if out_infos has only one entry "all" we provide all database informations
325 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
326 bool mult, const std::string out_model)
328 // First we select the files
329 std::vector<std::string> files;
330 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
331 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
335 bool bsingle = isSingle(files.front());
337 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
338 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
340 if (asking == "true")
342 // display the output dialog box
345 sscanf(dim.c_str(),"%d",&idim);
346 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
347 if (dlg->ShowModal() == wxID_OK)
350 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
351 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
361 sscanf(dim.c_str(),"%d",&i_dim_out);
364 // Next we create the structure for dicom output infos
366 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
369 // We don't send informations!
371 else if( i_attr.size() == 1 && i_attr.front() == "ALL")
373 // we send all database
374 Oattr.inside.push_back("ALL");
376 else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
377 || (i_attr.size() >1) )
379 mGimmick->fillVectInfos(i_attr, Oattr);
386 // Next we create model and sort files
387 std::vector<std::string> sort_files(files);
389 if( !out_model.empty() )
391 /* OutputModel mod(out_model);
392 mGimmick->isAttributeExist(db_name, mod);
393 mod.sort(files, sort_files);
396 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
398 OutputModel *mod = new OutputModel();
399 zspacing = mod->orderFilesWithZspacing(sort_files);
402 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
403 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
409 //======================================================================
411 //======================================================================
414 //======================================================================
415 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
417 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
419 //======================================================================
421 //======================================================================
422 void WxGimmickView::GetImages(int dim,
423 const std::vector<std::string>& files,
424 std::vector<vtkImageData*>& s)
426 ReadImagesNotThreaded(s,files,dim);
428 //======================================================================
431 //=================================================
432 void WxGimmickView::CreateIconList()
434 // Size of the icons;
438 // should correspond to Icon_xxx enum
439 icons[Icon_accept] = wxIcon(accept_xpm);
440 icons[Icon_add] = wxIcon(add_xpm);
441 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
442 icons[Icon_page_down] = wxIcon(page_down_xpm);
443 icons[Icon_remove] = wxIcon(remove_xpm);
444 icons[Icon_database_add] = wxIcon(database_add_xpm);
445 icons[Icon_help] = wxIcon(help_xpm);
446 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
447 icons[Icon_create_database] = wxIcon(create_database_xpm);
448 icons[Icon_settings] = wxIcon(settings_xpm);
449 icons[Icon_tools] = wxIcon(tools_xpm);
451 // unsigned int NbIcons = 8;
452 // Make an image list containing small icons
453 mIcon = new wxImageList(size,size,true);
455 // Make all icons the same size = size of the first one
456 int sizeOrig = icons[0].GetWidth();
457 for ( size_t i = 0; i < icon_number; i++ )
459 if ( size == sizeOrig )
461 mIcon->Add(icons[i]);
465 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
469 //=================================================
472 //=================================================
473 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
475 mViewer->StopPlayer();
476 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
478 wxFileDialog* FD = new wxFileDialog( 0,
486 if (FD->ShowModal()==wxID_OK)
493 std::vector<std::string> filenames;
494 for (i=0;i<files.GetCount();++i)
496 filenames.push_back(wx2std(files[i]));
497 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
501 new wxProgressDialog(_T("Adding file(s)"),
506 // wxPD_ESTIMATED_TIME |
507 // wxPD_REMAINING_TIME |
510 // TO DO : select the current tree handler
511 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
513 mProgressDialog->Pulse(_T("Updating view..."));
515 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
516 delete mProgressDialog;
520 mViewer->StartPlayer();
522 //=================================================
524 //=================================================
525 void WxGimmickView::OnAddDir(wxCommandEvent& event)
527 mViewer->StopPlayer();
528 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
529 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
532 _T("Select directory"),
536 if (FD->ShowModal()==wxID_OK)
538 std::string dirname = wx2std (FD->GetPath());
539 bool recurse = isNeedRecursive(dirname);
542 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
546 wxString title(_T("Adding directory"));
548 title = _T("Adding directory (recursive)");
550 new wxProgressDialog(_T("Adding directory"),
552 NumberFilesToAdd(dirname,recurse),
556 // wxPD_ESTIMATED_TIME |
557 // wxPD_REMAINING_TIME |
560 mCurrentDirectory = FD->GetPath();
561 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
562 mProgressDialog->Pulse(_T("Updating view..."));
564 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
565 delete mProgressDialog;
568 mViewer->StartPlayer();
573 //=================================================
574 // Determines number of files potentially to add to database
575 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
578 if ( !boost::filesystem::exists( dirpath ) ) return nb;
579 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
580 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
582 // If is directory & recurse : do recurse
583 if ( boost::filesystem::is_directory(itr->status()) )
587 nb += NumberFilesToAdd(itr->string(), recursive);
598 //=================================================
599 // Test a directory to know if contains sub-directory to analyze
600 bool WxGimmickView::isNeedRecursive(std::string i_name)
602 boost::filesystem::directory_iterator iter(i_name), end_iter;
603 bool bfindir = false;
604 for(; iter != end_iter; ++iter)
606 if(boost::filesystem::is_directory(*iter))
613 //=================================================
615 //=================================================
616 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
618 GimmickDebugMessage(5,
619 "WxGimmickView::OnSelectionChange"
626 valid= ValidateSelected(NULL,
627 mSelectionMinDimension,
628 mSelectionMaxDimension );
633 std::vector<tree::Node*>::const_iterator i;
634 for(i=sel.begin();i!=sel.end()&&valid;++i)
636 valid= ValidateSelected((*i),
637 mSelectionMinDimension,
638 mSelectionMaxDimension );
643 valid= ValidateSelected(sel.front(),
644 mSelectionMinDimension,
645 mSelectionMaxDimension );
650 std::vector<tree::Node*>::const_iterator i;
651 for(i=sel.begin();i!=sel.end()&&valid;++i)
653 valid= ValidateSelected((*i),
654 mSelectionMinDimension,
655 mSelectionMaxDimension );
658 mText->SetLabel(crea::std2wx(GetMessage()));
661 ReadImageThreaded(sel);
667 ReadImageThreaded(sel);
670 //==================================================
672 //==================================================
673 ///Reads Images (Threaded)
674 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
676 GimmickDebugMessage(5,
679 int maxprio = GetMaximalPriority();
680 int prio = maxprio + 2000;
684 //First load the selected images
685 mCurImageItemToShow = sel.front();
688 std::vector<tree::Node*>::const_iterator selected;
689 for(selected=sel.begin();selected!=sel.end();++selected)
691 GimmickDebugMessage(5,
692 "Requesting image from selected "
693 <<(*selected)->GetAttribute("FullFileName")
695 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
696 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
697 pointers.push_back(ph);
698 RequestReading(*selected,prio,index,ph);
699 // AddEntryToMap(*selected);
703 mViewer->SetImageVector(pointers);
706 std::vector<tree::Node*> up;
707 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
708 std::vector<tree::Node*>::iterator iterUp;
709 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
711 GimmickDebugMessage(5,
712 "Requesting image from neighbors up "
713 <<(*iterUp)->GetAttribute("FullFileName")
715 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
716 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
717 RequestReading(*iterUp,prio,-1,ph);
718 // AddEntryToMap(*iterUp);
720 if (prio == maxprio) break;
725 std::vector<tree::Node*> down;
726 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
727 std::vector<tree::Node*>::iterator iterDown;
728 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
730 GimmickDebugMessage(5,
731 "Requesting image from neighbors down "
732 <<(*iterDown)->GetAttribute("FullFileName")
734 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
735 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
736 RequestReading(*iterDown,prio,-1,ph);
737 // AddEntryToMap(*iterDown);
739 if (prio == maxprio) break;
745 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
746 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
747 pointers.push_back(ph);
748 mViewer->SetImageVector(pointers);
752 //==================================================
754 //==================================================
757 //==================================================
758 void WxGimmickView::OnInternalIdle()
760 if (!mConstructed) return;
761 static bool first_time = true;
766 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
767 // mViewer->StartPlayer();
770 mViewer->RefreshIfNecessary();
774 void WxGimmickView::UpdateWindowUI(long flags)
778 mViewer->RefreshIfNecessary();
782 //==================================================
784 //==================================================
785 void WxGimmickView::ClearSelection()
788 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
789 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
790 mViewer->SetImageVector(pointers);
791 mViewer->RefreshIfNecessary();
795 //=================================================
797 //=================================================
798 void WxGimmickView::OnRemove(wxCommandEvent& event)
800 //TODO Select current tree handler
803 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
804 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
805 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
808 //=================================================
811 //=================================================
812 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
814 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
815 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
818 //=================================================
819 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
821 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
822 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
825 //=================================================
826 void WxGimmickView::AddDir(std::string dirName)
828 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
829 mCurrentDirectory = crea::std2wx(dirName);
830 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
831 mProgressDialog->Pulse(_T("Updating view..."));
833 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
834 delete mProgressDialog;
838 //=================================================
839 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
842 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
843 _T("Check database for files deletion, addition and attributes change. Then give a report."),
844 _T("Repair database (remove deleted files and add new files)."),
845 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
847 wxSingleChoiceDialog dialog(this,
848 _T("Select one of the following synchronization actions:\n")
849 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
850 _T("Synchronization Settings"),
851 WXSIZEOF(choices), choices);
853 //dialog.SetSelection(0);
855 if (dialog.ShowModal() == wxID_OK)
858 int sel=dialog.GetSelection();
860 bool checkAttributes=false;
861 if(sel==2 || sel==3){repair=true;}
862 if(sel==1 || sel==3){checkAttributes=true;}
863 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
864 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
865 if(sel==2 || sel==3){
866 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
871 //=================================================
873 //=================================================
874 void WxGimmickView::OnSettings(wxCommandEvent& event)
876 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
877 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
879 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
881 siz->Add( nb,1,wxGROW ,0);
882 CreateSettingsDialog(nb,dial);
887 //=================================================
888 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
891 // Test if one image is selected => export
893 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
903 void WxGimmickView::ExportImages()
905 //Archive selection: name, emplacement
906 //same process than copy local but to a zip
907 // if settings are yes "always ask for descriptor addition", ask
908 // if settings are yes, adding descriptor
911 void WxGimmickView::ImportImages()
915 // Contain a descriptor.text
916 // create a new database, and add to database
917 // if not, add to current database
921 //=================================================
923 void WxGimmickView::OnTools(wxCommandEvent& event)
925 mViewer->StopPlayer();
927 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
929 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
930 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
931 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
932 dialSizer->Add(nb,1,wxGROW,0);
933 dialSizer->Add(buttonsSizer,0,wxGROW);
935 #if defined(BUILD_BRUKER)
936 //First page: Bruker Image Reader
937 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
938 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
941 dial->SetSizer(dialSizer, true);
945 if (dial->GetReturnCode() == wxID_OK)
947 #if defined(BUILD_BRUKER)
948 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
950 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
951 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
953 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
955 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
957 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
958 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
961 b2d.SetInputDirectory(inputDir);
962 b2d.SetOutputDirectory(outputDir);
963 b2d.SetConvertModeToDicom();
969 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
970 mCurrentDirectory = gimmickTools->getOutputDir();
971 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
972 mProgressDialog->Pulse(_T("Updating view..."));
974 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
975 delete mProgressDialog;
982 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
988 mViewer->StartPlayer();
991 //=================================================
993 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
995 //First page: Customization of configurations
998 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
999 //Database Path String
1001 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1002 //Syncronization Event String
1004 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1005 //Syncronization Frequency String
1007 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1009 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1011 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1013 //Second page: Creation of Databases
1014 /*wxPanel* databaseCreation=new wxPanel(nb);
1015 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1017 //Second page (temporary): Connection to PACS
1018 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1019 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1021 //Third page: CD/DVD Watch
1022 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1023 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1025 //Fourth page: Selection of attributes to show
1026 std::vector<std::string> shown;
1027 std::vector<std::string> nShown;
1028 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1029 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1030 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1031 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1034 //===================================================================
1035 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1036 std::vector<std::string>& nShown, int level)
1038 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1041 //===================================================================
1042 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1044 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1045 std::vector<std::string> n=nShown;
1046 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1048 //===================================================================
1049 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1050 const std::string& dbPath,
1051 const std::string& syncEvent,
1052 const std::string& syncFreq)
1054 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1055 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1056 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1057 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1060 //===================================================================
1061 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1063 mListener->SetMonitoredDrive(drive);
1064 mListener->SetAddFilesState(addFiles);
1065 mListener->SetRemoveFilesState(removeFiles);
1068 //========================================================================
1070 void WxGimmickView::OnDriveMount(bool mount)
1072 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1074 mListener->GetMonitoredDrive(drive);
1078 mViewer->StopPlayer();
1080 wxString title(_T("Adding drive"));
1082 new wxProgressDialog(_T("Adding drive"),
1087 // wxPD_ESTIMATED_TIME |
1088 // wxPD_REMAINING_TIME |
1090 mCurrentDirectory = crea::std2wx(drive);
1091 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1092 mProgressDialog->Pulse(_T("Updating view..."));
1094 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1095 delete mProgressDialog;
1096 DisplayAddSummary();
1097 mViewer->StartPlayer();
1101 mGimmick->DeleteDrive(drive);
1102 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1106 //========================================================================
1108 void WxGimmickView::StartListeningThread()
1110 mListener->Resume();
1113 //========================================================================
1115 void WxGimmickView::StopListeningThread()
1120 //========================================================================
1121 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1123 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1124 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1125 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1127 siz->Add( ef,1,wxGROW ,0);
1128 dial->SetSizer(siz);
1134 //========================================================================
1135 void WxGimmickView::DumpTags(std::string i_filename)
1137 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1141 //========================================================================
1142 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1144 std::vector<std::string> storages;
1145 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1146 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1148 storages.push_back(it->first);
1151 WxExportDlg* exp= new WxExportDlg(this,storages);
1152 if ( exp->ShowModal() ==ID_EXPORT_OK)
1154 std::string storage = exp->GetStorage();
1156 new wxProgressDialog(_T("Adding file(s)"),
1161 // wxPD_ESTIMATED_TIME |
1162 // wxPD_REMAINING_TIME |
1164 mGimmick->AddFiles(storage,i_filenames);
1165 mProgressDialog->Pulse(_T("Updating view..."));
1166 UpdateTreeViewLevel(storage,1);
1167 delete mProgressDialog;
1168 DisplayAddSummary();
1174 //========================================================================
1175 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1177 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1178 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1181 //=================================================
1182 /// AddProgress Gimmick callback
1183 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1186 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1187 p.GetNumberScannedDirs(),
1188 p.GetNumberScannedFiles(),
1189 p.GetNumberHandledFiles(),
1190 p.GetNumberAddedFiles());
1191 // std::cout << "OnAddProgress "<<mess<<std::endl;
1192 wxString s(wxString::From8BitData(mess));
1193 // std::cout << "Pulse"<<std::endl;
1194 if (!mProgressDialog->Pulse(s))
1198 // std::cout << "OnAddProgress ok"<<std::endl;
1200 //=================================================
1202 //=================================================
1203 void WxGimmickView::DisplayAddSummary()
1205 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1206 std::stringstream mess;
1207 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1208 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1209 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1210 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1211 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1214 ////////////////////////////////////////////////
1215 // Add a DB to application //
1216 // @param event : WxEvent //
1218 ////////////////////////////////////////////////
1219 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1222 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1223 std::string wc("*.sqlite3*");
1224 wxFileDialog* FD = new wxFileDialog( 0,
1232 if (FD->ShowModal()==wxID_OK)
1235 wxArrayString files;
1236 FD->GetPaths(files);
1237 std::stringstream st;
1238 for(int i = 0; i< files.size(); i++)
1240 //get name of DB (file name)
1241 size_t pos = files[i].find_last_of(_T("\\"));
1242 std::string name = crea::wx2std(files[i].substr(pos+1));
1243 pos = name.find_last_of(".");
1244 name = name.substr(0,pos);
1245 //create TreeHandler
1246 mGimmick->addDB(name, crea::wx2std(files[i]));
1248 CreateSingleTreeView(name);
1252 ////////////////////////////////////////////////////
1253 // Create a DB from an Attributes Descriptor files //
1254 // @param event : WxEvent //
1256 //////////////////////////////////////////////////
1257 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1259 // PACSConnection("");
1260 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1261 DescriptorPan->Layout();
1262 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1265 std::string file(DescriptorPan->GetDescriptor());
1268 size_t pos = file.find_last_of("\\");
1269 std::string name = file.substr(pos+1);
1270 std::string directory = file.substr(0,pos);
1271 pos = name.find_last_of(".");
1272 name = name.substr(0,pos);
1273 //get directory to store DB
1274 directory += "\\" + name + ".sqlite3";
1276 mGimmick->createDB(name, file,directory);
1277 //create TreeHandler
1278 mGimmick->addDB(name, directory);
1280 CreateSingleTreeView(name);
1285 //=================================================
1287 //=================================================
1288 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1289 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1290 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1291 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1292 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1293 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1294 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1295 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1296 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1298 //=================================================
1300 } // EO namespace creaImageIO