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());
117 // Connect the AddProgress callback
118 gimmick->ConnectAddProgressObserver
119 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
121 // Create the list of icons (mIcon)
125 msizer = new wxBoxSizer(wxVERTICAL);
127 // Create the tool bar
129 msizer->Add( mToolBar, 0, wxGROW, 0);
131 // Split part below toolbar into notebook for views and panel
132 // for preview, messages...
133 mSplitter = new wxSplitterWindow( this , -1);
136 mNotebook = new wxNotebook(mSplitter,
137 -1, wxDefaultPosition, wxDefaultSize, 0);
142 mSelectionMaxDimension = max_dim;
143 mSelectionMinDimension = min_dim;
149 mBottomPanel = new wxPanel(mSplitter,-1);
151 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
155 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
156 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
157 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
159 mViewer->SetImageVector(pointers);
160 mViewer->StartPlayer();
163 mbottom_sizer->Add(mViewer,1,wxGROW,1);
166 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
167 mbottom_sizer->Add(mText,0,wxGROW,0);
171 mBottomPanel->SetSizer(mbottom_sizer);
174 int hsize = size.GetHeight();
176 int top_minsize = 450;
177 int bottom_minsize = 50;
179 mSplitter->SetMinimumPaneSize( bottom_minsize );
180 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
183 msizer->Add( mSplitter, 1, wxGROW, 0);
189 //mListener=new Listener();
190 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
191 //mListener->Create();
193 // mListener->Pause();
197 //======================================================================
199 //======================================================================
201 WxGimmickView::~WxGimmickView()
203 // stop the viewer before application exit.
204 mViewer->StopPlayer();
205 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
209 //if(mListener->IsAlive()) { mListener->Delete(); }
211 //======================================================================
213 //======================================================================
214 /// Creates the tool bar
215 void WxGimmickView::CreateToolBar()
217 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
218 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
221 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
223 mIcon->GetBitmap(Icon_page_down),
224 _T("Add one or more file to database")
226 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
228 mIcon->GetBitmap(Icon_folder_down),
229 _T("Add the content of a folder to database")
231 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
233 mIcon->GetBitmap(Icon_database_add),
234 _T("Open a local or distant database")
236 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
238 mIcon->GetBitmap(Icon_remove),
239 _T("Remove selected items")
241 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
243 mIcon->GetBitmap(Icon_synchronize),
244 _T("Synchronizes the database with disk")
246 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
248 mIcon->GetBitmap(Icon_help),
249 _T("Open help window")
251 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
252 _T("System settings"),
253 mIcon->GetBitmap(Icon_settings),
254 _T("Allows the modification of various system settings")
256 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
258 mIcon->GetBitmap(Icon_tools),
259 _T("Applies tools to images")
261 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
262 _T("Create database"),
263 mIcon->GetBitmap(Icon_create_database),
264 _T("Create DB from an Attributes Descriptor file")
266 #if defined(BUILD_PACS)
267 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
268 _T("PACS Connection,"),
269 mIcon->GetBitmap(Icon_create_database),
270 _T("Echo, Find and Get to a PACS")
273 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
277 //======================================================================
280 //======================================================================
281 /// Create the tree view for TreeHandler provided
282 void WxGimmickView::CreateTreeView( TreeHandler* h)
284 std::string name(h->GetTree().GetAttribute("Name"));
285 GimmickMessage(2,"Creating the tree view for '"<<
286 name<<"'"<<std::endl);
287 // Create the WxTreeView
288 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
290 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
291 // ALREADY IN THE MAP
292 GetTreeViewMap()[name] = view;
295 mNotebook->AddPage( view, crea::std2wx(name) );
299 //======================================================================
300 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
302 std::vector<std::string> files;
303 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
304 //ReadImagesNotThreaded(s, files, dim);
307 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
308 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
313 //======================================================================
314 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
316 std::vector<std::string> files;
317 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
318 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
320 ReadImagesNotThreadedInVector(s, files, dim);
324 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
325 /// if out_infos has only one entry "all" we provide all database informations
326 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
327 bool mult, const std::string out_model)
329 // First we select the files
330 std::vector<std::string> files;
331 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
332 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
336 bool bsingle = isSingle(files.front());
338 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
339 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
341 if (asking == "true")
343 // display the output dialog box
346 sscanf(dim.c_str(),"%d",&idim);
347 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
348 if (dlg->ShowModal() == wxID_OK)
351 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
352 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
362 sscanf(dim.c_str(),"%d",&i_dim_out);
365 // Next we create the structure for dicom output infos
367 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
370 // We don't send informations!
372 else if( i_attr.size() == 1 && i_attr.front() == "ALL")
374 // we send all database
375 Oattr.inside.push_back("ALL");
377 else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
378 || (i_attr.size() >1) )
380 mGimmick->fillVectInfos(i_attr, Oattr);
387 // Next we create model and sort files
388 std::vector<std::string> sort_files(files);
390 if( !out_model.empty() )
392 /* OutputModel mod(out_model);
393 mGimmick->isAttributeExist(db_name, mod);
394 mod.sort(files, sort_files);
397 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
399 OutputModel *mod = new OutputModel();
400 zspacing = mod->orderFilesWithZspacing(sort_files);
403 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
404 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
410 //======================================================================
412 //======================================================================
415 //======================================================================
416 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
418 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
420 //======================================================================
422 //======================================================================
423 void WxGimmickView::GetImages(int dim,
424 const std::vector<std::string>& files,
425 std::vector<vtkImageData*>& s)
427 ReadImagesNotThreaded(s,files,dim);
429 //======================================================================
432 //=================================================
433 void WxGimmickView::CreateIconList()
435 // Size of the icons;
439 // should correspond to Icon_xxx enum
440 icons[Icon_accept] = wxIcon(accept_xpm);
441 icons[Icon_add] = wxIcon(add_xpm);
442 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
443 icons[Icon_page_down] = wxIcon(page_down_xpm);
444 icons[Icon_remove] = wxIcon(remove_xpm);
445 icons[Icon_database_add] = wxIcon(database_add_xpm);
446 icons[Icon_help] = wxIcon(help_xpm);
447 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
448 icons[Icon_create_database] = wxIcon(create_database_xpm);
449 icons[Icon_settings] = wxIcon(settings_xpm);
450 icons[Icon_tools] = wxIcon(tools_xpm);
452 // unsigned int NbIcons = 8;
453 // Make an image list containing small icons
454 mIcon = new wxImageList(size,size,true);
456 // Make all icons the same size = size of the first one
457 int sizeOrig = icons[0].GetWidth();
458 for ( size_t i = 0; i < icon_number; i++ )
460 if ( size == sizeOrig )
462 mIcon->Add(icons[i]);
466 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
470 //=================================================
473 //=================================================
474 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
476 mViewer->StopPlayer();
477 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
479 wxFileDialog* FD = new wxFileDialog( 0,
487 if (FD->ShowModal()==wxID_OK)
494 std::vector<std::string> filenames;
495 for (i=0;i<files.GetCount();++i)
497 filenames.push_back(wx2std(files[i]));
498 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
502 new wxProgressDialog(_T("Adding file(s)"),
508 // wxPD_ESTIMATED_TIME |
509 // wxPD_REMAINING_TIME |
512 // TO DO : select the current tree handler
513 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
515 mProgressDialog->Pulse(_T("Updating view..."));
517 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
522 mViewer->StartPlayer();
524 //=================================================
526 //=================================================
527 void WxGimmickView::OnAddDir(wxCommandEvent& event)
529 mViewer->StopPlayer();
530 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
531 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
534 _T("Select directory"),
538 if (FD->ShowModal()==wxID_OK)
541 std::string dirname = wx2std (FD->GetPath());
542 bool recurse = isNeedRecursive(dirname);
545 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
549 wxString title(_T("Adding directory"));
551 title = _T("Adding directory (recursive)");
553 new wxProgressDialog(_T("Adding directory"),
555 NumberFilesToAdd(dirname,recurse),
559 // wxPD_ESTIMATED_TIME |
560 // wxPD_REMAINING_TIME |
563 mCurrentDirectory = FD->GetPath();
564 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
565 mProgressDialog->Pulse(_T("Updating view..."));
567 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
571 mViewer->StartPlayer();
576 //=================================================
577 // Determines number of files potentially to add to database
578 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
581 if ( !boost::filesystem::exists( dirpath ) ) return nb;
582 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
583 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
585 // If is directory & recurse : do recurse
586 if ( boost::filesystem::is_directory(itr->status()) )
590 nb += NumberFilesToAdd(itr->string(), recursive);
601 //=================================================
602 // Test a directory to know if contains sub-directory to analyze
603 bool WxGimmickView::isNeedRecursive(std::string i_name)
605 boost::filesystem::directory_iterator iter(i_name), end_iter;
606 bool bfindir = false;
607 for(; iter != end_iter; ++iter)
609 if(boost::filesystem::is_directory(*iter))
616 //=================================================
618 //=================================================
619 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
621 GimmickDebugMessage(5,
622 "WxGimmickView::OnSelectionChange"
629 valid= ValidateSelected(NULL,
630 mSelectionMinDimension,
631 mSelectionMaxDimension );
636 std::vector<tree::Node*>::const_iterator i;
637 for(i=sel.begin();i!=sel.end()&&valid;++i)
639 valid= ValidateSelected((*i),
640 mSelectionMinDimension,
641 mSelectionMaxDimension );
646 valid= ValidateSelected(sel.front(),
647 mSelectionMinDimension,
648 mSelectionMaxDimension );
653 std::vector<tree::Node*>::const_iterator i;
654 for(i=sel.begin();i!=sel.end()&&valid;++i)
656 valid= ValidateSelected((*i),
657 mSelectionMinDimension,
658 mSelectionMaxDimension );
661 mText->SetLabel(crea::std2wx(GetMessage()));
664 ReadImageThreaded(sel);
670 ReadImageThreaded(sel);
673 //==================================================
675 //==================================================
676 ///Reads Images (Threaded)
677 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
679 GimmickDebugMessage(5,
682 int maxprio = GetMaximalPriority();
683 int prio = maxprio + 2000;
687 //First load the selected images
688 mCurImageItemToShow = sel.front();
691 std::vector<tree::Node*>::const_iterator selected;
692 for(selected=sel.begin();selected!=sel.end();++selected)
694 GimmickDebugMessage(5,
695 "Requesting image from selected "
696 <<(*selected)->GetAttribute("FullFileName")
698 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
699 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
700 pointers.push_back(ph);
701 RequestReading(*selected,prio,index,ph);
702 // AddEntryToMap(*selected);
706 mViewer->SetImageVector(pointers);
709 std::vector<tree::Node*> up;
710 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
711 std::vector<tree::Node*>::iterator iterUp;
712 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
714 GimmickDebugMessage(5,
715 "Requesting image from neighbors up "
716 <<(*iterUp)->GetAttribute("FullFileName")
718 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
719 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
720 RequestReading(*iterUp,prio,-1,ph);
721 // AddEntryToMap(*iterUp);
723 if (prio == maxprio) break;
728 std::vector<tree::Node*> down;
729 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
730 std::vector<tree::Node*>::iterator iterDown;
731 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
733 GimmickDebugMessage(5,
734 "Requesting image from neighbors down "
735 <<(*iterDown)->GetAttribute("FullFileName")
737 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
738 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
739 RequestReading(*iterDown,prio,-1,ph);
740 // AddEntryToMap(*iterDown);
742 if (prio == maxprio) break;
748 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
749 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
750 pointers.push_back(ph);
751 mViewer->SetImageVector(pointers);
755 //==================================================
757 //==================================================
760 //==================================================
761 void WxGimmickView::OnInternalIdle()
763 if (!mConstructed) return;
764 static bool first_time = true;
769 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
770 // mViewer->StartPlayer();
773 mViewer->RefreshIfNecessary();
777 void WxGimmickView::UpdateWindowUI(long flags)
781 mViewer->RefreshIfNecessary();
785 //==================================================
787 //==================================================
788 void WxGimmickView::ClearSelection()
791 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
792 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
793 mViewer->SetImageVector(pointers);
794 mViewer->RefreshIfNecessary();
798 //=================================================
800 //=================================================
801 void WxGimmickView::OnRemove(wxCommandEvent& event)
803 //TODO Select current tree handler
806 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
807 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
808 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
811 //=================================================
814 //=================================================
815 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
817 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
818 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
821 //=================================================
822 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
824 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
825 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
828 //=================================================
829 void WxGimmickView::AddDir(std::string dirName)
831 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
832 mCurrentDirectory = crea::std2wx(dirName);
833 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
834 mProgressDialog->Pulse(_T("Updating view..."));
836 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
841 //=================================================
842 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
845 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
846 _T("Check database for files deletion, addition and attributes change. Then give a report."),
847 _T("Repair database (remove deleted files and add new files)."),
848 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
850 wxSingleChoiceDialog dialog(this,
851 _T("Select one of the following synchronization actions:\n")
852 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
853 _T("Synchronization Settings"),
854 WXSIZEOF(choices), choices);
856 //dialog.SetSelection(0);
858 if (dialog.ShowModal() == wxID_OK)
861 int sel=dialog.GetSelection();
863 bool checkAttributes=false;
864 if(sel==2 || sel==3){repair=true;}
865 if(sel==1 || sel==3){checkAttributes=true;}
866 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
867 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
868 if(sel==2 || sel==3){
869 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
874 //=================================================
876 //=================================================
877 void WxGimmickView::OnSettings(wxCommandEvent& event)
879 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
880 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
882 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
884 siz->Add( nb,1,wxGROW ,0);
885 CreateSettingsDialog(nb,dial);
890 //=================================================
891 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
894 // Test if one image is selected => export
896 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
906 void WxGimmickView::ExportImages()
908 //Archive selection: name, emplacement
909 //same process than copy local but to a zip
910 // if settings are yes "always ask for descriptor addition", ask
911 // if settings are yes, adding descriptor
914 void WxGimmickView::ImportImages()
918 // Contain a descriptor.text
919 // create a new database, and add to database
920 // if not, add to current database
924 //=================================================
926 void WxGimmickView::OnTools(wxCommandEvent& event)
928 mViewer->StopPlayer();
930 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
932 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
933 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
934 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
935 dialSizer->Add(nb,1,wxGROW,0);
936 dialSizer->Add(buttonsSizer,0,wxGROW);
938 #if defined(BUILD_BRUKER)
939 //First page: Bruker Image Reader
940 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
941 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
944 dial->SetSizer(dialSizer, true);
948 if (dial->GetReturnCode() == wxID_OK)
950 #if defined(BUILD_BRUKER)
951 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
953 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
954 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
956 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
958 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
960 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
961 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
964 b2d.SetInputDirectory(inputDir);
965 b2d.SetOutputDirectory(outputDir);
966 b2d.SetConvertModeToDicom();
971 std::cout <<"after addToDB" << std::endl;
972 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
973 std::cout <<"after new wxProgressDialog" << std::endl;
974 mCurrentDirectory = gimmickTools->getOutputDir();
975 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
976 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
977 std::cout <<"after mGimmick->AddDir" << std::endl;
978 mProgressDialog->Pulse(_T("Updating view..."));
979 std::cout <<"after mProgressDialog->Pulse" << std::endl;
980 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
981 std::cout <<"after UpdateTreeViewLevel" << std::endl;
983 std::cout <<"after delete mProgressDialog" << std::endl;
985 std::cout <<"after dDisplayAddSummary" << std::endl;
991 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
997 mViewer->StartPlayer();
1000 //=================================================
1002 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1004 //First page: Customization of configurations
1007 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1008 //Database Path String
1010 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1011 //Syncronization Event String
1013 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1014 //Syncronization Frequency String
1016 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1018 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1020 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1022 //Second page: Creation of Databases
1023 /*wxPanel* databaseCreation=new wxPanel(nb);
1024 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1026 //Second page (temporary): Connection to PACS
1027 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1028 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1030 //Third page: CD/DVD Watch
1031 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1032 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1034 //Fourth page: Selection of attributes to show
1035 std::vector<std::string> shown;
1036 std::vector<std::string> nShown;
1037 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1038 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1039 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1040 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1043 //===================================================================
1044 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1045 std::vector<std::string>& nShown, int level)
1047 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1050 //===================================================================
1051 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1053 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1054 std::vector<std::string> n=nShown;
1055 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1057 //===================================================================
1058 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1059 const std::string& dbPath,
1060 const std::string& syncEvent,
1061 const std::string& syncFreq)
1063 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1064 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1065 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1066 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1069 //===================================================================
1070 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1072 mListener->SetMonitoredDrive(drive);
1073 mListener->SetAddFilesState(addFiles);
1074 mListener->SetRemoveFilesState(removeFiles);
1077 //========================================================================
1079 void WxGimmickView::OnDriveMount(bool mount)
1081 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1083 mListener->GetMonitoredDrive(drive);
1087 mViewer->StopPlayer();
1089 wxString title(_T("Adding drive"));
1091 new wxProgressDialog(_T("Adding drive"),
1096 // wxPD_ESTIMATED_TIME |
1097 // wxPD_REMAINING_TIME |
1099 mCurrentDirectory = crea::std2wx(drive);
1100 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1101 mProgressDialog->Pulse(_T("Updating view..."));
1103 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1105 DisplayAddSummary();
1106 mViewer->StartPlayer();
1110 mGimmick->DeleteDrive(drive);
1111 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1115 //========================================================================
1117 void WxGimmickView::StartListeningThread()
1119 mListener->Resume();
1122 //========================================================================
1124 void WxGimmickView::StopListeningThread()
1129 //========================================================================
1130 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1132 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1133 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1134 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1136 siz->Add( ef,1,wxGROW ,0);
1137 dial->SetSizer(siz);
1143 //========================================================================
1144 void WxGimmickView::DumpTags(std::string i_filename)
1146 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1150 //========================================================================
1151 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1153 std::vector<std::string> storages;
1154 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1155 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1157 storages.push_back(it->first);
1160 WxExportDlg* exp= new WxExportDlg(this,storages);
1161 if ( exp->ShowModal() ==ID_EXPORT_OK)
1163 std::string storage = exp->GetStorage();
1165 new wxProgressDialog(_T("Adding file(s)"),
1170 // wxPD_ESTIMATED_TIME |
1171 // wxPD_REMAINING_TIME |
1173 mGimmick->AddFiles(storage,i_filenames);
1174 mProgressDialog->Pulse(_T("Updating view..."));
1175 UpdateTreeViewLevel(storage,1);
1177 DisplayAddSummary();
1183 //========================================================================
1184 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1186 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1187 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1190 //=================================================
1191 /// AddProgress Gimmick callback
1192 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1195 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1196 p.GetNumberScannedDirs(),
1197 p.GetNumberScannedFiles(),
1198 p.GetNumberHandledFiles(),
1199 p.GetNumberAddedFiles());
1200 // std::cout << "OnAddProgress "<<mess<<std::endl;
1201 wxString s(wxString::From8BitData(mess));
1202 // std::cout << "Pulse"<<std::endl;
1203 if (mProgressDialog!=0)
1205 if (!mProgressDialog->Pulse(s))
1211 if(mProgressDialog != 0)
1213 if (!mProgressDialog->Pulse(s))
1218 // std::cout << "OnAddProgress ok"<<std::endl;
1220 //=================================================
1222 //=================================================
1223 void WxGimmickView::DisplayAddSummary()
1225 std::stringstream mess(mGimmick->getSummary());
1228 mess << "time to scan :" << difftime(end,mstart) << "sec";
1229 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1232 ////////////////////////////////////////////////
1233 // Add a DB to application //
1234 // @param event : WxEvent //
1236 ////////////////////////////////////////////////
1237 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1240 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1241 std::string wc("*.sqlite3*");
1242 wxFileDialog* FD = new wxFileDialog( 0,
1250 if (FD->ShowModal()==wxID_OK)
1253 wxArrayString files;
1254 FD->GetPaths(files);
1255 std::stringstream st;
1256 for(int i = 0; i< files.size(); i++)
1258 //get name of DB (file name)
1259 size_t pos = files[i].find_last_of(_T("\\"));
1260 std::string name = crea::wx2std(files[i].substr(pos+1));
1261 pos = name.find_last_of(".");
1262 name = name.substr(0,pos);
1263 //create TreeHandler
1264 mGimmick->addDB(name, crea::wx2std(files[i]));
1266 CreateSingleTreeView(name);
1270 ////////////////////////////////////////////////////
1271 // Create a DB from an Attributes Descriptor files //
1272 // @param event : WxEvent //
1274 //////////////////////////////////////////////////
1275 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1277 // PACSConnection("");
1278 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1279 DescriptorPan->Layout();
1280 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1283 std::string file(DescriptorPan->GetDescriptor());
1286 size_t pos = file.find_last_of("\\");
1287 std::string name = file.substr(pos+1);
1288 std::string directory = file.substr(0,pos);
1289 pos = name.find_last_of(".");
1290 name = name.substr(0,pos);
1291 //get directory to store DB
1292 directory += "\\" + name + ".sqlite3";
1294 mGimmick->createDB(name, file,directory);
1295 //create TreeHandler
1296 mGimmick->addDB(name, directory);
1298 CreateSingleTreeView(name);
1303 void WxGimmickView::killProgress()
1305 mProgressDialog->Resume();
1306 mProgressDialog->Destroy();
1307 mProgressDialog = 0;
1310 //=================================================
1312 //=================================================
1313 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1314 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1315 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1316 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1317 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1318 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1319 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1320 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1321 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1323 //=================================================
1325 } // EO namespace creaImageIO