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),
562 // wxPD_ESTIMATED_TIME |
563 // wxPD_REMAINING_TIME |
566 mCurrentDirectory = FD->GetPath();
567 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
568 mProgressDialog->Pulse(_T("Updating view..."));
570 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
574 mViewer->StartPlayer();
579 //=================================================
580 // Determines number of files potentially to add to database
581 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
584 if ( !boost::filesystem::exists( dirpath ) ) return nb;
585 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
586 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
588 // If is directory & recurse : do recurse
589 if ( boost::filesystem::is_directory(itr->status()) )
593 nb += NumberFilesToAdd(itr->string(), recursive);
604 //=================================================
605 // Test a directory to know if contains sub-directory to analyze
606 bool WxGimmickView::isNeedRecursive(std::string i_name)
608 boost::filesystem::directory_iterator iter(i_name), end_iter;
609 bool bfindir = false;
610 for(; iter != end_iter; ++iter)
612 if(boost::filesystem::is_directory(*iter))
619 //=================================================
621 //=================================================
622 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
624 GimmickDebugMessage(5,
625 "WxGimmickView::OnSelectionChange"
632 valid= ValidateSelected(NULL,
633 mSelectionMinDimension,
634 mSelectionMaxDimension );
639 std::vector<tree::Node*>::const_iterator i;
640 for(i=sel.begin();i!=sel.end()&&valid;++i)
642 valid= ValidateSelected((*i),
643 mSelectionMinDimension,
644 mSelectionMaxDimension );
649 valid= ValidateSelected(sel.front(),
650 mSelectionMinDimension,
651 mSelectionMaxDimension );
656 std::vector<tree::Node*>::const_iterator i;
657 for(i=sel.begin();i!=sel.end()&&valid;++i)
659 valid= ValidateSelected((*i),
660 mSelectionMinDimension,
661 mSelectionMaxDimension );
664 mText->SetLabel(crea::std2wx(GetMessage()));
667 ReadImageThreaded(sel);
673 ReadImageThreaded(sel);
676 //==================================================
678 //==================================================
679 ///Reads Images (Threaded)
680 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
682 GimmickDebugMessage(5,
685 int maxprio = GetMaximalPriority();
686 int prio = maxprio + 2000;
690 //First load the selected images
691 mCurImageItemToShow = sel.front();
694 std::vector<tree::Node*>::const_iterator selected;
695 for(selected=sel.begin();selected!=sel.end();++selected)
697 GimmickDebugMessage(5,
698 "Requesting image from selected "
699 <<(*selected)->GetAttribute("FullFileName")
701 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
702 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
703 pointers.push_back(ph);
704 RequestReading(*selected,prio,index,ph);
705 // AddEntryToMap(*selected);
709 mViewer->SetImageVector(pointers);
712 std::vector<tree::Node*> up;
713 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
714 std::vector<tree::Node*>::iterator iterUp;
715 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
717 GimmickDebugMessage(5,
718 "Requesting image from neighbors up "
719 <<(*iterUp)->GetAttribute("FullFileName")
721 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
722 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
723 RequestReading(*iterUp,prio,-1,ph);
724 // AddEntryToMap(*iterUp);
726 if (prio == maxprio) break;
731 std::vector<tree::Node*> down;
732 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
733 std::vector<tree::Node*>::iterator iterDown;
734 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
736 GimmickDebugMessage(5,
737 "Requesting image from neighbors down "
738 <<(*iterDown)->GetAttribute("FullFileName")
740 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
741 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
742 RequestReading(*iterDown,prio,-1,ph);
743 // AddEntryToMap(*iterDown);
745 if (prio == maxprio) break;
751 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
752 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
753 pointers.push_back(ph);
754 mViewer->SetImageVector(pointers);
758 //==================================================
760 //==================================================
763 //==================================================
764 void WxGimmickView::OnInternalIdle()
766 if (!mConstructed) return;
767 static bool first_time = true;
772 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
773 // mViewer->StartPlayer();
776 mViewer->RefreshIfNecessary();
780 void WxGimmickView::UpdateWindowUI(long flags)
784 mViewer->RefreshIfNecessary();
788 //==================================================
790 //==================================================
791 void WxGimmickView::ClearSelection()
794 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
795 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
796 mViewer->SetImageVector(pointers);
797 mViewer->RefreshIfNecessary();
801 //=================================================
803 //=================================================
804 void WxGimmickView::OnRemove(wxCommandEvent& event)
806 //TODO Select current tree handler
809 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
810 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
811 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
814 //=================================================
817 //=================================================
818 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
820 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
821 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
824 //=================================================
825 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
827 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
828 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
831 //=================================================
832 void WxGimmickView::AddDir(std::string dirName)
834 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
839 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
840 mCurrentDirectory = crea::std2wx(dirName);
841 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
842 mProgressDialog->Pulse(_T("Updating view..."));
844 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
849 //=================================================
850 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
853 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
854 _T("Check database for files deletion, addition and attributes change. Then give a report."),
855 _T("Repair database (remove deleted files and add new files)."),
856 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
858 wxSingleChoiceDialog dialog(this,
859 _T("Select one of the following synchronization actions:\n")
860 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
861 _T("Synchronization Settings"),
862 WXSIZEOF(choices), choices);
864 //dialog.SetSelection(0);
866 if (dialog.ShowModal() == wxID_OK)
869 int sel=dialog.GetSelection();
871 bool checkAttributes=false;
872 if(sel==2 || sel==3){repair=true;}
873 if(sel==1 || sel==3){checkAttributes=true;}
874 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
875 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
876 if(sel==2 || sel==3){
877 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
882 //=================================================
884 //=================================================
885 void WxGimmickView::OnSettings(wxCommandEvent& event)
887 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
888 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
890 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
892 siz->Add( nb,1,wxGROW ,0);
893 CreateSettingsDialog(nb,dial);
898 //=================================================
899 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
902 // Test if one image is selected => export
904 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
914 void WxGimmickView::ExportImages()
916 //Archive selection: name, emplacement
917 //same process than copy local but to a zip
918 // if settings are yes "always ask for descriptor addition", ask
919 // if settings are yes, adding descriptor
922 void WxGimmickView::ImportImages()
926 // Contain a descriptor.text
927 // create a new database, and add to database
928 // if not, add to current database
932 //=================================================
934 void WxGimmickView::OnTools(wxCommandEvent& event)
936 mViewer->StopPlayer();
938 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
940 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
941 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
942 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
943 dialSizer->Add(nb,1,wxGROW,0);
944 dialSizer->Add(buttonsSizer,0,wxGROW);
946 #if defined(BUILD_BRUKER)
947 //First page: Bruker Image Reader
948 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
949 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
952 dial->SetSizer(dialSizer, true);
956 if (dial->GetReturnCode() == wxID_OK)
958 #if defined(BUILD_BRUKER)
959 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
961 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
962 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
964 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
966 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
968 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
969 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
972 b2d.SetInputDirectory(inputDir);
973 b2d.SetOutputDirectory(outputDir);
974 b2d.SetConvertModeToDicom();
979 std::cout <<"after addToDB" << std::endl;
980 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
985 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
986 std::cout <<"after new wxProgressDialog" << std::endl;
987 mCurrentDirectory = gimmickTools->getOutputDir();
988 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
989 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
990 std::cout <<"after mGimmick->AddDir" << std::endl;
991 mProgressDialog->Pulse(_T("Updating view..."));
992 std::cout <<"after mProgressDialog->Pulse" << std::endl;
993 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
994 std::cout <<"after UpdateTreeViewLevel" << std::endl;
996 std::cout <<"after delete mProgressDialog" << std::endl;
998 std::cout <<"after dDisplayAddSummary" << std::endl;
1004 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1007 delete gimmickTools;
1010 mViewer->StartPlayer();
1013 //=================================================
1015 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1017 //First page: Customization of configurations
1020 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1021 //Database Path String
1023 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1024 //Syncronization Event String
1026 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1027 //Syncronization Frequency String
1029 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1031 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1033 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1035 //Second page: Creation of Databases
1036 /*wxPanel* databaseCreation=new wxPanel(nb);
1037 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1039 //Second page (temporary): Connection to PACS
1040 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1041 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1043 //Third page: CD/DVD Watch
1044 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1045 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1047 //Fourth page: Selection of attributes to show
1048 std::vector<std::string> shown;
1049 std::vector<std::string> nShown;
1050 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1051 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1052 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1053 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1056 //===================================================================
1057 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1058 std::vector<std::string>& nShown, int level)
1060 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1063 //===================================================================
1064 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1066 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1067 std::vector<std::string> n=nShown;
1068 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1070 //===================================================================
1071 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1072 const std::string& dbPath,
1073 const std::string& syncEvent,
1074 const std::string& syncFreq)
1076 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1077 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1078 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1079 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1082 //===================================================================
1083 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1085 mListener->SetMonitoredDrive(drive);
1086 mListener->SetAddFilesState(addFiles);
1087 mListener->SetRemoveFilesState(removeFiles);
1090 //========================================================================
1092 void WxGimmickView::OnDriveMount(bool mount)
1094 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1096 mListener->GetMonitoredDrive(drive);
1100 mViewer->StopPlayer();
1102 wxString title(_T("Adding drive"));
1104 new wxProgressDialog(_T("Adding drive"),
1112 // wxPD_ESTIMATED_TIME |
1113 // wxPD_REMAINING_TIME |
1115 mCurrentDirectory = crea::std2wx(drive);
1116 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1117 mProgressDialog->Pulse(_T("Updating view..."));
1119 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1121 DisplayAddSummary();
1122 mViewer->StartPlayer();
1126 mGimmick->DeleteDrive(drive);
1127 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1131 //========================================================================
1133 void WxGimmickView::StartListeningThread()
1135 mListener->Resume();
1138 //========================================================================
1140 void WxGimmickView::StopListeningThread()
1145 //========================================================================
1146 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1148 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1149 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1150 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1152 siz->Add( ef,1,wxGROW ,0);
1153 dial->SetSizer(siz);
1159 //========================================================================
1160 void WxGimmickView::DumpTags(std::string i_filename)
1162 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1166 //========================================================================
1167 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1169 std::vector<std::string> storages;
1170 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1171 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1173 storages.push_back(it->first);
1176 WxExportDlg* exp= new WxExportDlg(this,storages);
1177 if ( exp->ShowModal() ==ID_EXPORT_OK)
1179 std::string storage = exp->GetStorage();
1181 new wxProgressDialog(_T("Adding file(s)"),
1189 // wxPD_ESTIMATED_TIME |
1190 // wxPD_REMAINING_TIME |
1192 mGimmick->AddFiles(storage,i_filenames);
1193 mProgressDialog->Pulse(_T("Updating view..."));
1194 UpdateTreeViewLevel(storage,1);
1196 DisplayAddSummary();
1202 //========================================================================
1203 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1205 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1206 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1209 //=================================================
1210 /// AddProgress Gimmick callback
1211 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1214 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1215 p.GetNumberScannedDirs(),
1216 p.GetNumberScannedFiles(),
1217 p.GetNumberHandledFiles(),
1218 p.GetNumberAddedFiles());
1219 // std::cout << "OnAddProgress "<<mess<<std::endl;
1220 wxString s(wxString::From8BitData(mess));
1221 // std::cout << "Pulse"<<std::endl;
1223 if(mProgressDialog != 0)
1225 if (!mProgressDialog->Pulse(s))
1230 // std::cout << "OnAddProgress ok"<<std::endl;
1232 //=================================================
1234 //=================================================
1235 void WxGimmickView::DisplayAddSummary()
1237 std::stringstream mess(mGimmick->getSummary());
1240 mess << "time to scan :" << difftime(end,mstart) << "sec";
1241 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1244 ////////////////////////////////////////////////
1245 // Add a DB to application //
1246 // @param event : WxEvent //
1248 ////////////////////////////////////////////////
1249 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1252 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1253 std::string wc("*.sqlite3*");
1254 wxFileDialog* FD = new wxFileDialog( 0,
1262 if (FD->ShowModal()==wxID_OK)
1265 wxArrayString files;
1266 FD->GetPaths(files);
1267 std::stringstream st;
1268 for(int i = 0; i< files.size(); i++)
1270 //get name of DB (file name)
1271 size_t pos = files[i].find_last_of(_T("\\"));
1272 std::string name = crea::wx2std(files[i].substr(pos+1));
1273 pos = name.find_last_of(".");
1274 name = name.substr(0,pos);
1275 //create TreeHandler
1276 mGimmick->addDB(name, crea::wx2std(files[i]));
1278 CreateSingleTreeView(name);
1282 ////////////////////////////////////////////////////
1283 // Create a DB from an Attributes Descriptor files //
1284 // @param event : WxEvent //
1286 //////////////////////////////////////////////////
1287 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1289 // PACSConnection("");
1290 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1291 DescriptorPan->Layout();
1292 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1295 std::string file(DescriptorPan->GetDescriptor());
1298 size_t pos = file.find_last_of("\\");
1299 std::string name = file.substr(pos+1);
1300 std::string directory = file.substr(0,pos);
1301 pos = name.find_last_of(".");
1302 name = name.substr(0,pos);
1303 //get directory to store DB
1304 directory += "\\" + name + ".sqlite3";
1306 mGimmick->createDB(name, file,directory);
1307 //create TreeHandler
1308 mGimmick->addDB(name, directory);
1310 CreateSingleTreeView(name);
1315 void WxGimmickView::killProgress()
1317 mProgressDialog->Resume();
1318 mProgressDialog->Destroy();
1319 mProgressDialog = 0;
1322 //=================================================
1324 //=================================================
1325 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1326 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1327 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1328 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1329 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1330 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1331 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1332 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1333 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1335 //=================================================
1337 } // EO namespace creaImageIO