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)"),
507 // wxPD_ESTIMATED_TIME |
508 // wxPD_REMAINING_TIME |
511 // TO DO : select the current tree handler
512 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
514 mProgressDialog->Pulse(_T("Updating view..."));
516 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
517 delete mProgressDialog;
521 mViewer->StartPlayer();
523 //=================================================
525 //=================================================
526 void WxGimmickView::OnAddDir(wxCommandEvent& event)
528 mViewer->StopPlayer();
529 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
530 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
533 _T("Select directory"),
537 if (FD->ShowModal()==wxID_OK)
540 std::string dirname = wx2std (FD->GetPath());
541 bool recurse = isNeedRecursive(dirname);
544 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
548 wxString title(_T("Adding directory"));
550 title = _T("Adding directory (recursive)");
552 new wxProgressDialog(_T("Adding directory"),
554 NumberFilesToAdd(dirname,recurse),
558 // wxPD_ESTIMATED_TIME |
559 // wxPD_REMAINING_TIME |
562 mCurrentDirectory = FD->GetPath();
563 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
564 mProgressDialog->Pulse(_T("Updating view..."));
566 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
567 delete mProgressDialog;
570 mViewer->StartPlayer();
575 //=================================================
576 // Determines number of files potentially to add to database
577 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
580 if ( !boost::filesystem::exists( dirpath ) ) return nb;
581 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
582 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
584 // If is directory & recurse : do recurse
585 if ( boost::filesystem::is_directory(itr->status()) )
589 nb += NumberFilesToAdd(itr->string(), recursive);
600 //=================================================
601 // Test a directory to know if contains sub-directory to analyze
602 bool WxGimmickView::isNeedRecursive(std::string i_name)
604 boost::filesystem::directory_iterator iter(i_name), end_iter;
605 bool bfindir = false;
606 for(; iter != end_iter; ++iter)
608 if(boost::filesystem::is_directory(*iter))
615 //=================================================
617 //=================================================
618 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
620 GimmickDebugMessage(5,
621 "WxGimmickView::OnSelectionChange"
628 valid= ValidateSelected(NULL,
629 mSelectionMinDimension,
630 mSelectionMaxDimension );
635 std::vector<tree::Node*>::const_iterator i;
636 for(i=sel.begin();i!=sel.end()&&valid;++i)
638 valid= ValidateSelected((*i),
639 mSelectionMinDimension,
640 mSelectionMaxDimension );
645 valid= ValidateSelected(sel.front(),
646 mSelectionMinDimension,
647 mSelectionMaxDimension );
652 std::vector<tree::Node*>::const_iterator i;
653 for(i=sel.begin();i!=sel.end()&&valid;++i)
655 valid= ValidateSelected((*i),
656 mSelectionMinDimension,
657 mSelectionMaxDimension );
660 mText->SetLabel(crea::std2wx(GetMessage()));
663 ReadImageThreaded(sel);
669 ReadImageThreaded(sel);
672 //==================================================
674 //==================================================
675 ///Reads Images (Threaded)
676 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
678 GimmickDebugMessage(5,
681 int maxprio = GetMaximalPriority();
682 int prio = maxprio + 2000;
686 //First load the selected images
687 mCurImageItemToShow = sel.front();
690 std::vector<tree::Node*>::const_iterator selected;
691 for(selected=sel.begin();selected!=sel.end();++selected)
693 GimmickDebugMessage(5,
694 "Requesting image from selected "
695 <<(*selected)->GetAttribute("FullFileName")
697 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
698 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
699 pointers.push_back(ph);
700 RequestReading(*selected,prio,index,ph);
701 // AddEntryToMap(*selected);
705 mViewer->SetImageVector(pointers);
708 std::vector<tree::Node*> up;
709 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
710 std::vector<tree::Node*>::iterator iterUp;
711 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
713 GimmickDebugMessage(5,
714 "Requesting image from neighbors up "
715 <<(*iterUp)->GetAttribute("FullFileName")
717 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
718 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
719 RequestReading(*iterUp,prio,-1,ph);
720 // AddEntryToMap(*iterUp);
722 if (prio == maxprio) break;
727 std::vector<tree::Node*> down;
728 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
729 std::vector<tree::Node*>::iterator iterDown;
730 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
732 GimmickDebugMessage(5,
733 "Requesting image from neighbors down "
734 <<(*iterDown)->GetAttribute("FullFileName")
736 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
737 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
738 RequestReading(*iterDown,prio,-1,ph);
739 // AddEntryToMap(*iterDown);
741 if (prio == maxprio) break;
747 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
748 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
749 pointers.push_back(ph);
750 mViewer->SetImageVector(pointers);
754 //==================================================
756 //==================================================
759 //==================================================
760 void WxGimmickView::OnInternalIdle()
762 if (!mConstructed) return;
763 static bool first_time = true;
768 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
769 // mViewer->StartPlayer();
772 mViewer->RefreshIfNecessary();
776 void WxGimmickView::UpdateWindowUI(long flags)
780 // mViewer->RefreshIfNecessary();
784 //==================================================
786 //==================================================
787 void WxGimmickView::ClearSelection()
790 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
791 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
792 mViewer->SetImageVector(pointers);
793 mViewer->RefreshIfNecessary();
797 //=================================================
799 //=================================================
800 void WxGimmickView::OnRemove(wxCommandEvent& event)
802 //TODO Select current tree handler
805 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
806 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
807 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
810 //=================================================
813 //=================================================
814 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
816 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
817 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
820 //=================================================
821 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
823 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
824 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
827 //=================================================
828 void WxGimmickView::AddDir(std::string dirName)
830 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
831 mCurrentDirectory = crea::std2wx(dirName);
832 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
833 mProgressDialog->Pulse(_T("Updating view..."));
835 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
836 delete mProgressDialog;
840 //=================================================
841 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
844 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
845 _T("Check database for files deletion, addition and attributes change. Then give a report."),
846 _T("Repair database (remove deleted files and add new files)."),
847 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
849 wxSingleChoiceDialog dialog(this,
850 _T("Select one of the following synchronization actions:\n")
851 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
852 _T("Synchronization Settings"),
853 WXSIZEOF(choices), choices);
855 //dialog.SetSelection(0);
857 if (dialog.ShowModal() == wxID_OK)
860 int sel=dialog.GetSelection();
862 bool checkAttributes=false;
863 if(sel==2 || sel==3){repair=true;}
864 if(sel==1 || sel==3){checkAttributes=true;}
865 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
866 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
867 if(sel==2 || sel==3){
868 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
873 //=================================================
875 //=================================================
876 void WxGimmickView::OnSettings(wxCommandEvent& event)
878 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
879 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
881 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
883 siz->Add( nb,1,wxGROW ,0);
884 CreateSettingsDialog(nb,dial);
889 //=================================================
890 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
893 // Test if one image is selected => export
895 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
905 void WxGimmickView::ExportImages()
907 //Archive selection: name, emplacement
908 //same process than copy local but to a zip
909 // if settings are yes "always ask for descriptor addition", ask
910 // if settings are yes, adding descriptor
913 void WxGimmickView::ImportImages()
917 // Contain a descriptor.text
918 // create a new database, and add to database
919 // if not, add to current database
923 //=================================================
925 void WxGimmickView::OnTools(wxCommandEvent& event)
927 mViewer->StopPlayer();
929 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
931 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
932 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
933 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
934 dialSizer->Add(nb,1,wxGROW,0);
935 dialSizer->Add(buttonsSizer,0,wxGROW);
937 #if defined(BUILD_BRUKER)
938 //First page: Bruker Image Reader
939 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
940 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
943 dial->SetSizer(dialSizer, true);
947 if (dial->GetReturnCode() == wxID_OK)
949 #if defined(BUILD_BRUKER)
950 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
952 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
953 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
955 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
957 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
959 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
960 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
963 b2d.SetInputDirectory(inputDir);
964 b2d.SetOutputDirectory(outputDir);
965 b2d.SetConvertModeToDicom();
970 std::cout <<"after addToDB" << std::endl;
971 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
972 std::cout <<"after new wxProgressDialog" << std::endl;
973 mCurrentDirectory = gimmickTools->getOutputDir();
974 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
975 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
976 std::cout <<"after mGimmick->AddDir" << std::endl;
977 mProgressDialog->Pulse(_T("Updating view..."));
978 std::cout <<"after mProgressDialog->Pulse" << std::endl;
979 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
980 std::cout <<"after UpdateTreeViewLevel" << std::endl;
981 delete mProgressDialog;
982 std::cout <<"after delete mProgressDialog" << std::endl;
984 std::cout <<"after dDisplayAddSummary" << std::endl;
990 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
996 mViewer->StartPlayer();
999 //=================================================
1001 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1003 //First page: Customization of configurations
1006 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1007 //Database Path String
1009 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1010 //Syncronization Event String
1012 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1013 //Syncronization Frequency String
1015 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1017 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1019 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1021 //Second page: Creation of Databases
1022 /*wxPanel* databaseCreation=new wxPanel(nb);
1023 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1025 //Second page (temporary): Connection to PACS
1026 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1027 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1029 //Third page: CD/DVD Watch
1030 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1031 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1033 //Fourth page: Selection of attributes to show
1034 std::vector<std::string> shown;
1035 std::vector<std::string> nShown;
1036 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1037 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1038 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1039 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1042 //===================================================================
1043 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1044 std::vector<std::string>& nShown, int level)
1046 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1049 //===================================================================
1050 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1052 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1053 std::vector<std::string> n=nShown;
1054 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1056 //===================================================================
1057 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1058 const std::string& dbPath,
1059 const std::string& syncEvent,
1060 const std::string& syncFreq)
1062 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1063 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1064 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1065 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1068 //===================================================================
1069 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1071 mListener->SetMonitoredDrive(drive);
1072 mListener->SetAddFilesState(addFiles);
1073 mListener->SetRemoveFilesState(removeFiles);
1076 //========================================================================
1078 void WxGimmickView::OnDriveMount(bool mount)
1080 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1082 mListener->GetMonitoredDrive(drive);
1086 mViewer->StopPlayer();
1088 wxString title(_T("Adding drive"));
1090 new wxProgressDialog(_T("Adding drive"),
1095 // wxPD_ESTIMATED_TIME |
1096 // wxPD_REMAINING_TIME |
1098 mCurrentDirectory = crea::std2wx(drive);
1099 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1100 mProgressDialog->Pulse(_T("Updating view..."));
1102 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1103 delete mProgressDialog;
1104 DisplayAddSummary();
1105 mViewer->StartPlayer();
1109 mGimmick->DeleteDrive(drive);
1110 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1114 //========================================================================
1116 void WxGimmickView::StartListeningThread()
1118 mListener->Resume();
1121 //========================================================================
1123 void WxGimmickView::StopListeningThread()
1128 //========================================================================
1129 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1131 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1132 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1133 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1135 siz->Add( ef,1,wxGROW ,0);
1136 dial->SetSizer(siz);
1142 //========================================================================
1143 void WxGimmickView::DumpTags(std::string i_filename)
1145 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1149 //========================================================================
1150 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1152 std::vector<std::string> storages;
1153 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1154 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1156 storages.push_back(it->first);
1159 WxExportDlg* exp= new WxExportDlg(this,storages);
1160 if ( exp->ShowModal() ==ID_EXPORT_OK)
1162 std::string storage = exp->GetStorage();
1164 new wxProgressDialog(_T("Adding file(s)"),
1169 // wxPD_ESTIMATED_TIME |
1170 // wxPD_REMAINING_TIME |
1172 mGimmick->AddFiles(storage,i_filenames);
1173 mProgressDialog->Pulse(_T("Updating view..."));
1174 UpdateTreeViewLevel(storage,1);
1175 delete mProgressDialog;
1176 DisplayAddSummary();
1182 //========================================================================
1183 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1185 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1186 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1189 //=================================================
1190 /// AddProgress Gimmick callback
1191 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1194 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1195 p.GetNumberScannedDirs(),
1196 p.GetNumberScannedFiles(),
1197 p.GetNumberHandledFiles(),
1198 p.GetNumberAddedFiles());
1199 // std::cout << "OnAddProgress "<<mess<<std::endl;
1200 wxString s(wxString::From8BitData(mess));
1201 // std::cout << "Pulse"<<std::endl;
1202 if (!mProgressDialog->Pulse(s))
1206 // std::cout << "OnAddProgress ok"<<std::endl;
1208 //=================================================
1210 //=================================================
1211 void WxGimmickView::DisplayAddSummary()
1213 std::stringstream mess(mGimmick->getSummary());
1216 mess << "time to scan :" << difftime(end,mstart) << "sec";
1217 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1220 ////////////////////////////////////////////////
1221 // Add a DB to application //
1222 // @param event : WxEvent //
1224 ////////////////////////////////////////////////
1225 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1228 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1229 std::string wc("*.sqlite3*");
1230 wxFileDialog* FD = new wxFileDialog( 0,
1238 if (FD->ShowModal()==wxID_OK)
1241 wxArrayString files;
1242 FD->GetPaths(files);
1243 std::stringstream st;
1244 for(int i = 0; i< files.size(); i++)
1246 //get name of DB (file name)
1247 size_t pos = files[i].find_last_of(_T("\\"));
1248 std::string name = crea::wx2std(files[i].substr(pos+1));
1249 pos = name.find_last_of(".");
1250 name = name.substr(0,pos);
1251 //create TreeHandler
1252 mGimmick->addDB(name, crea::wx2std(files[i]));
1254 CreateSingleTreeView(name);
1258 ////////////////////////////////////////////////////
1259 // Create a DB from an Attributes Descriptor files //
1260 // @param event : WxEvent //
1262 //////////////////////////////////////////////////
1263 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1265 // PACSConnection("");
1266 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1267 DescriptorPan->Layout();
1268 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1271 std::string file(DescriptorPan->GetDescriptor());
1274 size_t pos = file.find_last_of("\\");
1275 std::string name = file.substr(pos+1);
1276 std::string directory = file.substr(0,pos);
1277 pos = name.find_last_of(".");
1278 name = name.substr(0,pos);
1279 //get directory to store DB
1280 directory += "\\" + name + ".sqlite3";
1282 mGimmick->createDB(name, file,directory);
1283 //create TreeHandler
1284 mGimmick->addDB(name, directory);
1286 CreateSingleTreeView(name);
1291 //=================================================
1293 //=================================================
1294 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1295 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1296 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1297 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1298 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1299 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1300 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1301 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1302 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1304 //=================================================
1306 } // EO namespace creaImageIO