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>
15 #include "icons/accept.xpm"
16 #include "icons/add.xpm"
17 #include "icons/folder-down.xpm"
18 #include "icons/page-down.xpm"
19 #include "icons/remove.xpm"
20 #include "icons/database-add.xpm"
21 #include "icons/create-database.xpm"
22 #include "icons/help.xpm"
23 #include "icons/synchronize.xpm"
24 #include "icons/settings.xpm"
25 #include "icons/tools.xpm"
26 //#include "icons/import.xpm"
28 #include <wx/imaglist.h>
29 #include <wx/popupwin.h>
30 #include<boost/filesystem/operations.hpp>
31 #if defined(BUILD_BRUKER)
32 #include "bruker2dicom.h"
36 #include <creaImageIOGimmick.h>
44 //======================================================================
45 // The ids of the different tools
50 TOOL_ADDDATABASE_ID = 3,
52 TOOL_SYNCHRONIZE_ID = 5,
59 //======================================================================
61 //================================================================
63 const int icon_number = 11;
80 //================================================================
82 //================================================================
84 const icon_id Icon[5] = { Icon_Database,
90 //================================================================
93 //======================================================================
95 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
102 int number_of_threads)
103 : wxPanel(parent,id,pos,size),
104 GimmickView(gimmick, number_of_threads),
108 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
110 // Sets the current directory to the home dir
111 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
113 // Connect the AddProgress callback
114 gimmick->ConnectAddProgressObserver
115 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
117 // Create the list of icons (mIcon)
121 msizer = new wxBoxSizer(wxVERTICAL);
123 // Create the tool bar
125 msizer->Add( mToolBar, 0, wxGROW, 0);
127 // Split part below toolbar into notebook for views and panel
128 // for preview, messages...
129 mSplitter = new wxSplitterWindow( this , -1);
132 mNotebook = new wxNotebook(mSplitter,
133 -1, wxDefaultPosition, wxDefaultSize, 0);
138 mSelectionMaxDimension = max_dim;
139 mSelectionMinDimension = min_dim;
145 mBottomPanel = new wxPanel(mSplitter,-1);
147 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
151 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
152 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
153 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
155 mViewer->SetImageVector(pointers);
156 mViewer->StartPlayer();
159 mbottom_sizer->Add(mViewer,1,wxGROW,1);
162 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
163 mbottom_sizer->Add(mText,0,wxGROW,0);
167 mBottomPanel->SetSizer(mbottom_sizer);
170 int hsize = size.GetHeight();
172 int top_minsize = 450;
173 int bottom_minsize = 50;
175 mSplitter->SetMinimumPaneSize( bottom_minsize );
176 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
179 msizer->Add( mSplitter, 1, wxGROW, 0);
185 //mListener=new Listener();
186 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
187 //mListener->Create();
189 // mListener->Pause();
193 //======================================================================
195 //======================================================================
197 WxGimmickView::~WxGimmickView()
199 // stop the viewer before application exit.
200 mViewer->StopPlayer();
201 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
205 //if(mListener->IsAlive()) { mListener->Delete(); }
207 //======================================================================
209 //======================================================================
210 /// Creates the tool bar
211 void WxGimmickView::CreateToolBar()
213 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
214 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
217 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
219 mIcon->GetBitmap(Icon_page_down),
220 _T("Add one or more file to database")
222 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
224 mIcon->GetBitmap(Icon_folder_down),
225 _T("Add the content of a folder to database")
227 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
229 mIcon->GetBitmap(Icon_database_add),
230 _T("Open a local or distant database")
232 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
234 mIcon->GetBitmap(Icon_remove),
235 _T("Remove selected items")
237 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
239 mIcon->GetBitmap(Icon_synchronize),
240 _T("Synchronizes the database with disk")
242 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
244 mIcon->GetBitmap(Icon_help),
245 _T("Open help window")
247 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
248 _T("System settings"),
249 mIcon->GetBitmap(Icon_settings),
250 _T("Allows the modification of various system settings")
252 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
254 mIcon->GetBitmap(Icon_tools),
255 _T("Applies tools to images")
257 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
258 _T("Create database"),
259 mIcon->GetBitmap(Icon_create_database),
260 _T("Create DB from an Attributes Descriptor file")
262 #if defined(BUILD_PACS)
263 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
264 _T("PACS Connection,"),
265 mIcon->GetBitmap(Icon_create_database),
266 _T("Echo, Find and Get to a PACS")
269 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
273 //======================================================================
276 //======================================================================
277 /// Create the tree view for TreeHandler provided
278 void WxGimmickView::CreateTreeView( TreeHandler* h)
280 std::string name(h->GetTree().GetAttribute("Name"));
281 GimmickMessage(2,"Creating the tree view for '"<<
282 name<<"'"<<std::endl);
283 // Create the WxTreeView
284 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
286 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
287 // ALREADY IN THE MAP
288 GetTreeViewMap()[name] = view;
291 mNotebook->AddPage( view, crea::std2wx(name) );
295 //======================================================================
296 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
298 std::vector<std::string> files;
299 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
300 ReadImagesNotThreaded(s, files, dim);
303 //======================================================================
304 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
306 std::vector<std::string> files;
307 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
308 ReadImagesNotThreadedInVector(s, files, dim);
310 //======================================================================
312 //======================================================================
313 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
315 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
317 //======================================================================
319 //======================================================================
320 void WxGimmickView::GetImages(int dim,
321 const std::vector<std::string>& files,
322 std::vector<vtkImageData*>& s)
324 ReadImagesNotThreaded(s,files,dim);
326 //======================================================================
329 //=================================================
330 void WxGimmickView::CreateIconList()
332 // Size of the icons;
336 // should correspond to Icon_xxx enum
337 icons[Icon_accept] = wxIcon(accept_xpm);
338 icons[Icon_add] = wxIcon(add_xpm);
339 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
340 icons[Icon_page_down] = wxIcon(page_down_xpm);
341 icons[Icon_remove] = wxIcon(remove_xpm);
342 icons[Icon_database_add] = wxIcon(database_add_xpm);
343 icons[Icon_help] = wxIcon(help_xpm);
344 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
345 icons[Icon_create_database] = wxIcon(create_database_xpm);
346 icons[Icon_settings] = wxIcon(settings_xpm);
347 icons[Icon_tools] = wxIcon(tools_xpm);
349 // unsigned int NbIcons = 8;
350 // Make an image list containing small icons
351 mIcon = new wxImageList(size,size,true);
353 // Make all icons the same size = size of the first one
354 int sizeOrig = icons[0].GetWidth();
355 for ( size_t i = 0; i < icon_number; i++ )
357 if ( size == sizeOrig )
359 mIcon->Add(icons[i]);
363 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
367 //=================================================
370 //=================================================
371 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
373 mViewer->StopPlayer();
374 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
376 wxFileDialog* FD = new wxFileDialog( 0,
384 if (FD->ShowModal()==wxID_OK)
391 std::vector<std::string> filenames;
392 for (i=0;i<files.GetCount();++i)
394 filenames.push_back(wx2std(files[i]));
395 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
399 new wxProgressDialog(_T("Adding file(s)"),
404 // wxPD_ESTIMATED_TIME |
405 // wxPD_REMAINING_TIME |
408 // TO DO : select the current tree handler
409 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
411 mProgressDialog->Pulse(_T("Updating view..."));
413 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
414 delete mProgressDialog;
418 mViewer->StartPlayer();
420 //=================================================
422 //=================================================
423 void WxGimmickView::OnAddDir(wxCommandEvent& event)
425 mViewer->StopPlayer();
426 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
427 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
430 _T("Select directory"),
434 if (FD->ShowModal()==wxID_OK)
436 std::string dirname = wx2std (FD->GetPath());
437 bool recurse = isNeedRecursive(dirname);
440 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
444 wxString title(_T("Adding directory"));
446 title = _T("Adding directory (recursive)");
448 new wxProgressDialog(_T("Adding directory"),
450 NumberFilesToAdd(dirname,recurse),
454 // wxPD_ESTIMATED_TIME |
455 // wxPD_REMAINING_TIME |
458 mCurrentDirectory = FD->GetPath();
459 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
460 mProgressDialog->Pulse(_T("Updating view..."));
462 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
463 delete mProgressDialog;
466 mViewer->StartPlayer();
471 //=================================================
472 // Determines number of files potentially to add to database
473 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
476 if ( !boost::filesystem::exists( dirpath ) ) return nb;
477 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
478 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
480 // If is directory & recurse : do recurse
481 if ( boost::filesystem::is_directory(itr->status()) )
485 nb += NumberFilesToAdd(itr->string(), recursive);
496 //=================================================
497 // Test a directory to know if contains sub-directory to analyze
498 bool WxGimmickView::isNeedRecursive(std::string i_name)
500 boost::filesystem::directory_iterator iter(i_name), end_iter;
501 bool bfindir = false;
502 for(; iter != end_iter; ++iter)
504 if(boost::filesystem::is_directory(*iter))
511 //=================================================
513 //=================================================
514 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
516 GimmickDebugMessage(5,
517 "WxGimmickView::OnSelectionChange"
524 valid= ValidateSelected(NULL,
525 mSelectionMinDimension,
526 mSelectionMaxDimension );
531 std::vector<tree::Node*>::const_iterator i;
532 for(i=sel.begin();i!=sel.end()&&valid;++i)
534 valid= ValidateSelected((*i),
535 mSelectionMinDimension,
536 mSelectionMaxDimension );
541 valid= ValidateSelected(sel.front(),
542 mSelectionMinDimension,
543 mSelectionMaxDimension );
548 std::vector<tree::Node*>::const_iterator i;
549 for(i=sel.begin();i!=sel.end()&&valid;++i)
551 valid= ValidateSelected((*i),
552 mSelectionMinDimension,
553 mSelectionMaxDimension );
556 mText->SetLabel(crea::std2wx(GetMessage()));
559 ReadImageThreaded(sel);
565 ReadImageThreaded(sel);
568 //==================================================
570 //==================================================
571 ///Reads Images (Threaded)
572 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
574 GimmickDebugMessage(5,
577 int maxprio = GetMaximalPriority();
578 int prio = maxprio + 2000;
582 //First load the selected images
583 mCurImageItemToShow = sel.front();
586 std::vector<tree::Node*>::const_iterator selected;
587 for(selected=sel.begin();selected!=sel.end();++selected)
589 GimmickDebugMessage(5,
590 "Requesting image from selected "
591 <<(*selected)->GetAttribute("FullFileName")
593 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
594 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
595 pointers.push_back(ph);
596 RequestReading(*selected,prio,index,ph);
597 // AddEntryToMap(*selected);
601 mViewer->SetImageVector(pointers);
604 std::vector<tree::Node*> up;
605 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
606 std::vector<tree::Node*>::iterator iterUp;
607 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
609 GimmickDebugMessage(5,
610 "Requesting image from neighbors up "
611 <<(*iterUp)->GetAttribute("FullFileName")
613 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
614 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
615 RequestReading(*iterUp,prio,-1,ph);
616 // AddEntryToMap(*iterUp);
618 if (prio == maxprio) break;
623 std::vector<tree::Node*> down;
624 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
625 std::vector<tree::Node*>::iterator iterDown;
626 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
628 GimmickDebugMessage(5,
629 "Requesting image from neighbors down "
630 <<(*iterDown)->GetAttribute("FullFileName")
632 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
633 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
634 RequestReading(*iterDown,prio,-1,ph);
635 // AddEntryToMap(*iterDown);
637 if (prio == maxprio) break;
643 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
644 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
645 pointers.push_back(ph);
646 mViewer->SetImageVector(pointers);
650 //==================================================
652 //==================================================
654 //==================================================
655 void WxGimmickView::OnInternalIdle()
657 if (!mConstructed) return;
658 static bool first_time = true;
663 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
664 // mViewer->StartPlayer();
667 mViewer->RefreshIfNecessary();
671 //==================================================
673 //==================================================
674 void WxGimmickView::ClearSelection()
677 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
678 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
679 mViewer->SetImageVector(pointers);
680 mViewer->RefreshIfNecessary();
684 //=================================================
686 //=================================================
687 void WxGimmickView::OnRemove(wxCommandEvent& event)
689 //TODO Select current tree handler
692 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
693 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
694 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
697 //=================================================
700 //=================================================
701 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
703 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
704 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
707 //=================================================
708 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
710 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
711 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
714 //=================================================
715 void WxGimmickView::AddDir(std::string dirName)
717 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
718 mCurrentDirectory = crea::std2wx(dirName);
719 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
720 mProgressDialog->Pulse(_T("Updating view..."));
722 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
723 delete mProgressDialog;
727 //=================================================
728 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
731 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
732 _T("Check database for files deletion, addition and attributes change. Then give a report."),
733 _T("Repair database (remove deleted files and add new files)."),
734 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
736 wxSingleChoiceDialog dialog(this,
737 _T("Select one of the following synchronization actions:\n")
738 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
739 _T("Synchronization Settings"),
740 WXSIZEOF(choices), choices);
742 //dialog.SetSelection(0);
744 if (dialog.ShowModal() == wxID_OK)
747 int sel=dialog.GetSelection();
749 bool checkAttributes=false;
750 if(sel==2 || sel==3){repair=true;}
751 if(sel==1 || sel==3){checkAttributes=true;}
752 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
753 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
754 if(sel==2 || sel==3){
755 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
760 //=================================================
762 //=================================================
763 void WxGimmickView::OnSettings(wxCommandEvent& event)
765 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
766 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
768 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
770 siz->Add( nb,1,wxGROW ,0);
771 CreateSettingsDialog(nb,dial);
776 //=================================================
777 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
780 // Test if one image is selected => export
782 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
792 void WxGimmickView::ExportImages()
794 //Archive selection: name, emplacement
795 //same process than copy local but to a zip
796 // if settings are yes "always ask for descriptor addition", ask
797 // if settings are yes, adding descriptor
800 void WxGimmickView::ImportImages()
804 // Contain a descriptor.text
805 // create a new database, and add to database
806 // if not, add to current database
810 //=================================================
812 void WxGimmickView::OnTools(wxCommandEvent& event)
814 mViewer->StopPlayer();
816 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
818 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
819 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
820 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
821 dialSizer->Add(nb,1,wxGROW,0);
822 dialSizer->Add(buttonsSizer,0,wxGROW);
824 #if defined(BUILD_BRUKER)
825 //First page: Bruker Image Reader
826 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
827 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
830 dial->SetSizer(dialSizer, true);
834 if (dial->GetReturnCode() == wxID_OK)
836 #if defined(BUILD_BRUKER)
837 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
839 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
840 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
842 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
844 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
846 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
847 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
850 b2d.SetInputDirectory(inputDir);
851 b2d.SetOutputDirectory(outputDir);
852 b2d.SetConvertModeToDicom();
858 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
859 mCurrentDirectory = gimmickTools->getOutputDir();
860 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
861 mProgressDialog->Pulse(_T("Updating view..."));
863 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
864 delete mProgressDialog;
871 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
877 mViewer->StartPlayer();
880 //=================================================
882 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
884 //First page: Customization of configurations
887 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
888 //Database Path String
890 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
891 //Syncronization Event String
893 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
894 //Syncronization Frequency String
896 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
898 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
900 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
902 //Second page: Creation of Databases
903 /*wxPanel* databaseCreation=new wxPanel(nb);
904 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
906 //Second page (temporary): Connection to PACS
907 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
908 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
910 //Third page: CD/DVD Watch
911 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
912 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
914 //Fourth page: Selection of attributes to show
915 std::vector<std::string> shown;
916 std::vector<std::string> nShown;
917 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
918 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
919 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
920 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
923 //===================================================================
924 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
925 std::vector<std::string>& nShown, int level)
927 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
930 //===================================================================
931 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
933 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
934 std::vector<std::string> n=nShown;
935 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
937 //===================================================================
938 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
939 const std::string& dbPath,
940 const std::string& syncEvent,
941 const std::string& syncFreq)
943 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
944 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
945 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
946 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
949 //===================================================================
950 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
952 mListener->SetMonitoredDrive(drive);
953 mListener->SetAddFilesState(addFiles);
954 mListener->SetRemoveFilesState(removeFiles);
957 //========================================================================
959 void WxGimmickView::OnDriveMount(bool mount)
961 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
963 mListener->GetMonitoredDrive(drive);
967 mViewer->StopPlayer();
969 wxString title(_T("Adding drive"));
971 new wxProgressDialog(_T("Adding drive"),
976 // wxPD_ESTIMATED_TIME |
977 // wxPD_REMAINING_TIME |
979 mCurrentDirectory = crea::std2wx(drive);
980 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
981 mProgressDialog->Pulse(_T("Updating view..."));
983 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
984 delete mProgressDialog;
986 mViewer->StartPlayer();
990 mGimmick->DeleteDrive(drive);
991 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
995 //========================================================================
997 void WxGimmickView::StartListeningThread()
1002 //========================================================================
1004 void WxGimmickView::StopListeningThread()
1009 //========================================================================
1010 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1012 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1013 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1014 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1016 siz->Add( ef,1,wxGROW ,0);
1017 dial->SetSizer(siz);
1021 //========================================================================
1022 void WxGimmickView::DumpTags(std::string i_filename)
1024 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1028 //========================================================================
1029 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1031 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1032 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1035 //=================================================
1036 /// AddProgress Gimmick callback
1037 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1040 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1041 p.GetNumberScannedDirs(),
1042 p.GetNumberScannedFiles(),
1043 p.GetNumberHandledFiles(),
1044 p.GetNumberAddedFiles());
1045 // std::cout << "OnAddProgress "<<mess<<std::endl;
1046 wxString s(wxString::From8BitData(mess));
1047 // std::cout << "Pulse"<<std::endl;
1048 if (!mProgressDialog->Pulse(s))
1052 // std::cout << "OnAddProgress ok"<<std::endl;
1054 //=================================================
1056 //=================================================
1057 void WxGimmickView::DisplayAddSummary()
1059 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1060 std::stringstream mess;
1061 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1062 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1063 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1064 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1065 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1068 ////////////////////////////////////////////////
1069 // Add a DB to application //
1070 // @param event : WxEvent //
1072 ////////////////////////////////////////////////
1073 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1076 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1077 std::string wc("*.sqlite3*");
1078 wxFileDialog* FD = new wxFileDialog( 0,
1086 if (FD->ShowModal()==wxID_OK)
1089 wxArrayString files;
1090 FD->GetPaths(files);
1091 std::stringstream st;
1092 for(int i = 0; i< files.size(); i++)
1094 //get name of DB (file name)
1095 size_t pos = files[i].find_last_of(_T("\\"));
1096 std::string name = crea::wx2std(files[i].substr(pos+1));
1097 pos = name.find_last_of(".");
1098 name = name.substr(0,pos);
1099 //create TreeHandler
1100 mGimmick->addDB(name, crea::wx2std(files[i]));
1102 CreateSingleTreeView(name);
1106 ////////////////////////////////////////////////////
1107 // Create a DB from an Attributes Descriptor files //
1108 // @param event : WxEvent //
1110 //////////////////////////////////////////////////
1111 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1113 // PACSConnection("");
1114 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1115 DescriptorPan->Layout();
1116 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1119 std::string file(DescriptorPan->GetDescriptor());
1122 size_t pos = file.find_last_of("\\");
1123 std::string name = file.substr(pos+1);
1124 std::string directory = file.substr(0,pos);
1125 pos = name.find_last_of(".");
1126 name = name.substr(0,pos);
1127 //get directory to store DB
1128 directory += "\\" + name + ".sqlite3";
1130 mGimmick->createDB(name, file,directory);
1131 //create TreeHandler
1132 mGimmick->addDB(name, directory);
1134 CreateSingleTreeView(name);
1139 //=================================================
1141 //=================================================
1142 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1143 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1144 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1145 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1146 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1147 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1148 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1149 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1150 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1152 //=================================================
1154 } // EO namespace creaImageIO