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 /// \TODO fix warning: unused variable hsize
175 int hsize = size.GetHeight();
177 int top_minsize = 450;
178 int bottom_minsize = 50;
180 mSplitter->SetMinimumPaneSize( bottom_minsize );
181 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
184 msizer->Add( mSplitter, 1, wxGROW, 0);
190 //mListener=new Listener();
191 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
192 //mListener->Create();
194 // mListener->Pause();
198 //======================================================================
200 //======================================================================
202 WxGimmickView::~WxGimmickView()
204 // stop the viewer before application exit.
205 mViewer->StopPlayer();
206 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
210 //if(mListener->IsAlive()) { mListener->Delete(); }
212 //======================================================================
214 //======================================================================
215 /// Creates the tool bar
216 void WxGimmickView::CreateToolBar()
218 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
219 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
222 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
224 mIcon->GetBitmap(Icon_page_down),
225 _T("Add one or more file to database")
227 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
229 mIcon->GetBitmap(Icon_folder_down),
230 _T("Add the content of a folder to database")
232 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
234 mIcon->GetBitmap(Icon_database_add),
235 _T("Open a local or distant database")
237 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
239 mIcon->GetBitmap(Icon_remove),
240 _T("Remove selected items")
242 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
244 mIcon->GetBitmap(Icon_synchronize),
245 _T("Synchronizes the database with disk")
247 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
249 mIcon->GetBitmap(Icon_help),
250 _T("Open help window")
252 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
253 _T("System settings"),
254 mIcon->GetBitmap(Icon_settings),
255 _T("Allows the modification of various system settings")
257 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
259 mIcon->GetBitmap(Icon_tools),
260 _T("Applies tools to images")
262 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
263 _T("Create database"),
264 mIcon->GetBitmap(Icon_create_database),
265 _T("Create DB from an Attributes Descriptor file")
267 #if defined(BUILD_PACS)
268 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
269 _T("PACS Connection,"),
270 mIcon->GetBitmap(Icon_create_database),
271 _T("Echo, Find and Get to a PACS")
274 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
278 //======================================================================
281 //======================================================================
282 /// Create the tree view for TreeHandler provided
283 void WxGimmickView::CreateTreeView( TreeHandler* h)
285 std::string name(h->GetTree().GetAttribute("Name"));
286 GimmickMessage(2,"Creating the tree view for '"<<
287 name<<"'"<<std::endl);
288 // Create the WxTreeView
289 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
291 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
292 // ALREADY IN THE MAP
293 GetTreeViewMap()[name] = view;
296 mNotebook->AddPage( view, crea::std2wx(name) );
300 //======================================================================
301 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
303 std::vector<std::string> files;
304 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
305 //ReadImagesNotThreaded(s, files, dim);
308 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
309 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
314 //======================================================================
315 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
317 std::vector<std::string> files;
318 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
319 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
321 ReadImagesNotThreadedInVector(s, files, dim);
325 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
326 /// if out_infos has only one entry "all" we provide all database informations
327 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
328 bool mult, const std::string out_model)
330 // First we select the files
331 std::vector<std::string> files;
332 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
333 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
337 bool bsingle = isSingle(files.front());
339 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
340 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
342 if (asking == "true")
344 // display the output dialog box
347 sscanf(dim.c_str(),"%d",&idim);
348 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
349 if (dlg->ShowModal() == wxID_OK)
352 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
353 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
363 sscanf(dim.c_str(),"%d",&i_dim_out);
366 // Next we create the structure for dicom output infos
368 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
371 // We don't send informations!
373 else if( i_attr.size() == 1 && i_attr.front() == "ALL")
375 // we send all database
376 Oattr.inside.push_back("ALL");
378 else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
379 || (i_attr.size() >1) )
381 mGimmick->fillVectInfos(i_attr, Oattr);
388 // Next we create model and sort files
389 std::vector<std::string> sort_files(files);
391 if( !out_model.empty() )
393 /* OutputModel mod(out_model);
394 mGimmick->isAttributeExist(db_name, mod);
395 mod.sort(files, sort_files);
398 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
400 OutputModel *mod = new OutputModel();
401 zspacing = mod->orderFilesWithZspacing(sort_files);
404 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
405 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
411 //======================================================================
413 //======================================================================
416 //======================================================================
417 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
419 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
421 //======================================================================
423 //======================================================================
424 void WxGimmickView::GetImages(int dim,
425 const std::vector<std::string>& files,
426 std::vector<vtkImageData*>& s)
428 ReadImagesNotThreaded(s,files,dim);
430 //======================================================================
433 //=================================================
434 void WxGimmickView::CreateIconList()
436 // Size of the icons;
440 // should correspond to Icon_xxx enum
441 icons[Icon_accept] = wxIcon(accept_xpm);
442 icons[Icon_add] = wxIcon(add_xpm);
443 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
444 icons[Icon_page_down] = wxIcon(page_down_xpm);
445 icons[Icon_remove] = wxIcon(remove_xpm);
446 icons[Icon_database_add] = wxIcon(database_add_xpm);
447 icons[Icon_help] = wxIcon(help_xpm);
448 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
449 icons[Icon_create_database] = wxIcon(create_database_xpm);
450 icons[Icon_settings] = wxIcon(settings_xpm);
451 icons[Icon_tools] = wxIcon(tools_xpm);
453 // unsigned int NbIcons = 8;
454 // Make an image list containing small icons
455 mIcon = new wxImageList(size,size,true);
457 // Make all icons the same size = size of the first one
458 int sizeOrig = icons[0].GetWidth();
459 for ( size_t i = 0; i < icon_number; i++ )
461 if ( size == sizeOrig )
463 mIcon->Add(icons[i]);
467 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
471 //=================================================
474 //=================================================
475 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
477 mViewer->StopPlayer();
478 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
480 wxFileDialog* FD = new wxFileDialog( 0,
488 if (FD->ShowModal()==wxID_OK)
495 std::vector<std::string> filenames;
496 for (i=0;i<files.GetCount();++i)
498 filenames.push_back(wx2std(files[i]));
499 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
503 new wxProgressDialog(_T("Adding file(s)"),
509 // wxPD_ESTIMATED_TIME |
510 // wxPD_REMAINING_TIME |
513 // TO DO : select the current tree handler
514 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
516 mProgressDialog->Pulse(_T("Updating view..."));
518 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
523 mViewer->StartPlayer();
525 //=================================================
527 //=================================================
528 void WxGimmickView::OnAddDir(wxCommandEvent& event)
530 mViewer->StopPlayer();
531 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
532 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
535 _T("Select directory"),
539 if (FD->ShowModal()==wxID_OK)
542 std::string dirname = wx2std (FD->GetPath());
543 bool recurse = isNeedRecursive(dirname);
546 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
550 wxString title(_T("Adding directory"));
552 title = _T("Adding directory (recursive)");
554 new wxProgressDialog(_T("Adding directory"),
556 NumberFilesToAdd(dirname,recurse),
563 // wxPD_ESTIMATED_TIME |
564 // wxPD_REMAINING_TIME |
567 mCurrentDirectory = FD->GetPath();
568 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
569 mProgressDialog->Pulse(_T("Updating view..."));
571 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
575 mViewer->StartPlayer();
580 //=================================================
581 // Determines number of files potentially to add to database
582 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
585 if ( !boost::filesystem::exists( dirpath ) ) return nb;
586 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
587 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
589 // If is directory & recurse : do recurse
590 if ( boost::filesystem::is_directory(itr->status()) )
594 nb += NumberFilesToAdd(itr->string(), recursive);
605 //=================================================
606 // Test a directory to know if contains sub-directory to analyze
607 bool WxGimmickView::isNeedRecursive(std::string i_name)
609 boost::filesystem::directory_iterator iter(i_name), end_iter;
610 //bool bfindir = false;
611 for(; iter != end_iter; ++iter)
613 if(boost::filesystem::is_directory(*iter))
620 //=================================================
622 //=================================================
623 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
625 GimmickDebugMessage(5,
626 "WxGimmickView::OnSelectionChange"
633 valid= ValidateSelected(NULL,
634 mSelectionMinDimension,
635 mSelectionMaxDimension );
640 std::vector<tree::Node*>::const_iterator i;
641 for(i=sel.begin();i!=sel.end()&&valid;++i)
643 valid= ValidateSelected((*i),
644 mSelectionMinDimension,
645 mSelectionMaxDimension );
650 valid= ValidateSelected(sel.front(),
651 mSelectionMinDimension,
652 mSelectionMaxDimension );
657 std::vector<tree::Node*>::const_iterator i;
658 for(i=sel.begin();i!=sel.end()&&valid;++i)
660 valid= ValidateSelected((*i),
661 mSelectionMinDimension,
662 mSelectionMaxDimension );
665 mText->SetLabel(crea::std2wx(GetMessage()));
668 ReadImageThreaded(sel);
674 ReadImageThreaded(sel);
677 //==================================================
679 //==================================================
680 ///Reads Images (Threaded)
681 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
683 GimmickDebugMessage(5,
686 int maxprio = GetMaximalPriority();
687 int prio = maxprio + 2000;
691 //First load the selected images
692 mCurImageItemToShow = sel.front();
695 std::vector<tree::Node*>::const_iterator selected;
696 for(selected=sel.begin();selected!=sel.end();++selected)
698 GimmickDebugMessage(5,
699 "Requesting image from selected "
700 <<(*selected)->GetAttribute("FullFileName")
702 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
703 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
704 pointers.push_back(ph);
705 RequestReading(*selected,prio,index,ph);
706 // AddEntryToMap(*selected);
710 mViewer->SetImageVector(pointers);
713 std::vector<tree::Node*> up;
714 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
715 std::vector<tree::Node*>::iterator iterUp;
716 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
718 GimmickDebugMessage(5,
719 "Requesting image from neighbors up "
720 <<(*iterUp)->GetAttribute("FullFileName")
722 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
723 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
724 RequestReading(*iterUp,prio,-1,ph);
725 // AddEntryToMap(*iterUp);
727 if (prio == maxprio) break;
732 std::vector<tree::Node*> down;
733 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
734 std::vector<tree::Node*>::iterator iterDown;
735 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
737 GimmickDebugMessage(5,
738 "Requesting image from neighbors down "
739 <<(*iterDown)->GetAttribute("FullFileName")
741 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
742 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
743 RequestReading(*iterDown,prio,-1,ph);
744 // AddEntryToMap(*iterDown);
746 if (prio == maxprio) break;
752 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
753 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
754 pointers.push_back(ph);
755 mViewer->SetImageVector(pointers);
759 //==================================================
761 //==================================================
764 //==================================================
765 void WxGimmickView::OnInternalIdle()
767 if (!mConstructed) return;
768 static bool first_time = true;
773 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
774 // mViewer->StartPlayer();
777 mViewer->RefreshIfNecessary();
781 void WxGimmickView::UpdateWindowUI(long flags)
785 mViewer->RefreshIfNecessary();
789 //==================================================
791 //==================================================
792 void WxGimmickView::ClearSelection()
795 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
796 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
797 mViewer->SetImageVector(pointers);
798 mViewer->RefreshIfNecessary();
802 //=================================================
804 //=================================================
805 void WxGimmickView::OnRemove(wxCommandEvent& event)
807 //TODO Select current tree handler
810 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
811 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
812 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
815 //=================================================
818 //=================================================
819 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
821 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
822 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
825 //=================================================
826 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
828 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
829 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
832 //=================================================
833 void WxGimmickView::AddDir(std::string dirName)
835 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
840 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
841 mCurrentDirectory = crea::std2wx(dirName);
842 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
843 mProgressDialog->Pulse(_T("Updating view..."));
845 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
850 //=================================================
851 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
854 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
855 _T("Check database for files deletion, addition and attributes change. Then give a report."),
856 _T("Repair database (remove deleted files and add new files)."),
857 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
859 wxSingleChoiceDialog dialog(this,
860 _T("Select one of the following synchronization actions:\n")
861 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
862 _T("Synchronization Settings"),
863 WXSIZEOF(choices), choices);
865 //dialog.SetSelection(0);
867 if (dialog.ShowModal() == wxID_OK)
870 int sel=dialog.GetSelection();
872 bool checkAttributes=false;
873 if(sel==2 || sel==3){repair=true;}
874 if(sel==1 || sel==3){checkAttributes=true;}
875 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
876 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
877 if(sel==2 || sel==3){
878 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
883 //=================================================
885 //=================================================
886 void WxGimmickView::OnSettings(wxCommandEvent& event)
888 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
889 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
891 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
893 siz->Add( nb,1,wxGROW ,0);
894 CreateSettingsDialog(nb,dial);
899 //=================================================
900 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
903 // Test if one image is selected => export
905 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
915 void WxGimmickView::ExportImages()
917 //Archive selection: name, emplacement
918 //same process than copy local but to a zip
919 // if settings are yes "always ask for descriptor addition", ask
920 // if settings are yes, adding descriptor
923 void WxGimmickView::ImportImages()
927 // Contain a descriptor.text
928 // create a new database, and add to database
929 // if not, add to current database
933 //=================================================
935 void WxGimmickView::OnTools(wxCommandEvent& event)
937 mViewer->StopPlayer();
939 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
941 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
942 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
943 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
944 dialSizer->Add(nb,1,wxGROW,0);
945 dialSizer->Add(buttonsSizer,0,wxGROW);
947 #if defined(BUILD_BRUKER)
948 //First page: Bruker Image Reader
949 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
950 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
953 dial->SetSizer(dialSizer, true);
957 if (dial->GetReturnCode() == wxID_OK)
959 #if defined(BUILD_BRUKER)
960 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
962 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
963 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
965 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
967 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
969 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
970 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
973 b2d.SetInputDirectory(inputDir);
974 b2d.SetOutputDirectory(outputDir);
975 b2d.SetConvertModeToDicom();
980 std::cout <<"after addToDB" << std::endl;
981 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
986 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
987 std::cout <<"after new wxProgressDialog" << std::endl;
988 mCurrentDirectory = gimmickTools->getOutputDir();
989 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
990 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
991 std::cout <<"after mGimmick->AddDir" << std::endl;
992 mProgressDialog->Pulse(_T("Updating view..."));
993 std::cout <<"after mProgressDialog->Pulse" << std::endl;
994 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
995 std::cout <<"after UpdateTreeViewLevel" << std::endl;
997 std::cout <<"after delete mProgressDialog" << std::endl;
999 std::cout <<"after dDisplayAddSummary" << std::endl;
1005 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1008 delete gimmickTools;
1011 mViewer->StartPlayer();
1014 //=================================================
1016 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1018 //First page: Customization of configurations
1021 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1022 //Database Path String
1024 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1025 //Syncronization Event String
1027 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1028 //Syncronization Frequency String
1030 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1032 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1034 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1036 //Second page: Creation of Databases
1037 /*wxPanel* databaseCreation=new wxPanel(nb);
1038 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1040 //Second page (temporary): Connection to PACS
1041 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1042 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1044 //Third page: CD/DVD Watch
1045 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1046 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1048 //Fourth page: Selection of attributes to show
1049 std::vector<std::string> shown;
1050 std::vector<std::string> nShown;
1051 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1052 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1053 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1054 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1057 //===================================================================
1058 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1059 std::vector<std::string>& nShown, int level)
1061 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1064 //===================================================================
1065 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1067 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1068 std::vector<std::string> n=nShown;
1069 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1071 //===================================================================
1072 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1073 const std::string& dbPath,
1074 const std::string& syncEvent,
1075 const std::string& syncFreq)
1077 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1078 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1079 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1080 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1083 //===================================================================
1084 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1086 mListener->SetMonitoredDrive(drive);
1087 mListener->SetAddFilesState(addFiles);
1088 mListener->SetRemoveFilesState(removeFiles);
1091 //========================================================================
1093 void WxGimmickView::OnDriveMount(bool mount)
1095 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1097 mListener->GetMonitoredDrive(drive);
1101 mViewer->StopPlayer();
1103 wxString title(_T("Adding drive"));
1105 new wxProgressDialog(_T("Adding drive"),
1113 // wxPD_ESTIMATED_TIME |
1114 // wxPD_REMAINING_TIME |
1116 mCurrentDirectory = crea::std2wx(drive);
1117 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1118 mProgressDialog->Pulse(_T("Updating view..."));
1120 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1122 DisplayAddSummary();
1123 mViewer->StartPlayer();
1127 mGimmick->DeleteDrive(drive);
1128 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1132 //========================================================================
1134 void WxGimmickView::StartListeningThread()
1136 mListener->Resume();
1139 //========================================================================
1141 void WxGimmickView::StopListeningThread()
1146 //========================================================================
1147 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1149 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1150 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1151 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1153 siz->Add( ef,1,wxGROW ,0);
1154 dial->SetSizer(siz);
1160 //========================================================================
1161 void WxGimmickView::DumpTags(std::string i_filename)
1163 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1167 //========================================================================
1168 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1170 std::vector<std::string> storages;
1171 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1172 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1174 storages.push_back(it->first);
1177 WxExportDlg* exp= new WxExportDlg(this,storages);
1178 if ( exp->ShowModal() ==ID_EXPORT_OK)
1180 std::string storage = exp->GetStorage();
1182 new wxProgressDialog(_T("Adding file(s)"),
1190 // wxPD_ESTIMATED_TIME |
1191 // wxPD_REMAINING_TIME |
1193 mGimmick->AddFiles(storage,i_filenames);
1194 mProgressDialog->Pulse(_T("Updating view..."));
1195 UpdateTreeViewLevel(storage,1);
1197 DisplayAddSummary();
1203 //========================================================================
1204 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1206 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1207 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1210 //=================================================
1211 /// AddProgress Gimmick callback
1212 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1215 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1216 p.GetNumberScannedDirs(),
1217 p.GetNumberScannedFiles(),
1218 p.GetNumberHandledFiles(),
1219 p.GetNumberAddedFiles());
1220 // std::cout << "OnAddProgress "<<mess<<std::endl;
1221 wxString s(wxString::From8BitData(mess));
1222 // std::cout << "Pulse"<<std::endl;
1224 if(mProgressDialog != 0)
1226 if (!mProgressDialog->Pulse(s))
1231 // std::cout << "OnAddProgress ok"<<std::endl;
1233 //=================================================
1235 //=================================================
1236 void WxGimmickView::DisplayAddSummary()
1238 std::stringstream mess(mGimmick->getSummary());
1241 mess << "time to scan :" << difftime(end,mstart) << "sec";
1242 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1245 ////////////////////////////////////////////////
1246 // Add a DB to application //
1247 // @param event : WxEvent //
1249 ////////////////////////////////////////////////
1250 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1253 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1254 std::string wc("*.sqlite3*");
1255 wxFileDialog* FD = new wxFileDialog( 0,
1263 if (FD->ShowModal()==wxID_OK)
1266 wxArrayString files;
1267 FD->GetPaths(files);
1268 std::stringstream st;
1269 for(int i = 0; i< files.size(); i++)
1271 //get name of DB (file name)
1272 size_t pos = files[i].find_last_of(_T("\\"));
1273 std::string name = crea::wx2std(files[i].substr(pos+1));
1274 pos = name.find_last_of(".");
1275 name = name.substr(0,pos);
1276 //create TreeHandler
1277 mGimmick->addDB(name, crea::wx2std(files[i]));
1279 CreateSingleTreeView(name);
1283 ////////////////////////////////////////////////////
1284 // Create a DB from an Attributes Descriptor files //
1285 // @param event : WxEvent //
1287 //////////////////////////////////////////////////
1288 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1290 // PACSConnection("");
1291 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1292 DescriptorPan->Layout();
1293 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1296 std::string file(DescriptorPan->GetDescriptor());
1299 size_t pos = file.find_last_of("\\");
1300 std::string name = file.substr(pos+1);
1301 std::string directory = file.substr(0,pos);
1302 pos = name.find_last_of(".");
1303 name = name.substr(0,pos);
1304 //get directory to store DB
1305 directory += "\\" + name + ".sqlite3";
1307 mGimmick->createDB(name, file,directory);
1308 //create TreeHandler
1309 mGimmick->addDB(name, directory);
1311 CreateSingleTreeView(name);
1316 void WxGimmickView::killProgress()
1318 mProgressDialog->Resume();
1319 mProgressDialog->Destroy();
1320 mProgressDialog = 0;
1323 //=================================================
1325 //=================================================
1326 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1327 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1328 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1329 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1330 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1331 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1332 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1333 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1334 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1336 //=================================================
1338 } // EO namespace creaImageIO