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>
14 #include "icons/accept.xpm"
15 #include "icons/add.xpm"
16 #include "icons/folder-down.xpm"
17 #include "icons/page-down.xpm"
18 #include "icons/remove.xpm"
19 #include "icons/database-add.xpm"
20 #include "icons/create-database.xpm"
21 #include "icons/help.xpm"
22 #include "icons/synchronize.xpm"
23 #include "icons/settings.xpm"
24 #include "icons/tools.xpm"
25 //#include "icons/import.xpm"
27 #include <wx/imaglist.h>
28 #include <wx/popupwin.h>
29 #include<boost/filesystem/operations.hpp>
30 #if defined(BUILD_BRUKER)
31 #include "bruker2dicom.h"
39 //======================================================================
40 // The ids of the different tools
45 TOOL_ADDDATABASE_ID = 3,
47 TOOL_SYNCHRONIZE_ID = 5,
53 //======================================================================
55 //================================================================
57 const int icon_number = 11;
74 //================================================================
76 //================================================================
78 const icon_id Icon[5] = { Icon_Database,
84 //================================================================
87 //======================================================================
89 WxGimmickView::WxGimmickView(Gimmick* gimmick,
96 int number_of_threads)
97 : wxPanel(parent,id,pos,size),
98 GimmickView(gimmick, number_of_threads),
102 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
104 // Sets the current directory to the home dir
105 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
107 // Connect the AddProgress callback
108 gimmick->ConnectAddProgressObserver
109 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
111 // Create the list of icons (mIcon)
115 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
117 // Create the tool bar
119 sizer->Add( mToolBar ,0, wxGROW ,0);
121 // Split part below toolbar into notebook for views and panel
122 // for preview, messages...
123 mSplitter = new wxSplitterWindow( this , -1);
127 mNotebook = new wxNotebook(mSplitter,
128 -1,wxDefaultPosition, wxDefaultSize, 0);
134 mSelectionMaxDimension= max_dim;
135 mSelectionMinDimension= min_dim;
141 mBottomPanel = new wxPanel(mSplitter,-1);
143 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
147 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
148 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
149 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
151 mViewer->SetImageVector(pointers);
152 mViewer->StartPlayer();
155 bottom_sizer->Add(mViewer,1,wxGROW,1);
158 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
159 bottom_sizer->Add(mText,0,wxGROW,0);
163 mBottomPanel->SetSizer(bottom_sizer);
166 int hsize = size.GetHeight();
168 int top_minsize = 450;
169 int bottom_minsize = 50;
171 mSplitter->SetMinimumPaneSize( bottom_minsize );
172 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
175 sizer->Add( mSplitter,1,wxGROW ,0);
181 mListener=new Listener();
182 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
189 //======================================================================
191 //======================================================================
193 WxGimmickView::~WxGimmickView()
195 // stop the viewer before application exit.
196 mViewer->StopPlayer();
197 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
199 if(mListener->IsAlive())
204 //======================================================================
206 //======================================================================
207 /// Creates the tool bar
208 void WxGimmickView::CreateToolBar()
210 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
211 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
214 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
216 mIcon->GetBitmap(Icon_page_down),
217 _T("Add one or more file to database")
219 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
221 mIcon->GetBitmap(Icon_folder_down),
222 _T("Add the content of a folder to database")
224 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
226 mIcon->GetBitmap(Icon_database_add),
227 _T("Open a local or distant database")
229 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
231 mIcon->GetBitmap(Icon_remove),
232 _T("Remove selected items")
234 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
236 mIcon->GetBitmap(Icon_synchronize),
237 _T("Synchronizes the database with disk")
239 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
241 mIcon->GetBitmap(Icon_help),
242 _T("Open help window")
244 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
245 _T("System settings"),
246 mIcon->GetBitmap(Icon_settings),
247 _T("Allows the modification of various system settings")
249 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
251 mIcon->GetBitmap(Icon_tools),
252 _T("Applies tools to images")
254 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
255 _T("Create database"),
256 mIcon->GetBitmap(Icon_create_database),
257 _T("Create DB from an Attributes Descriptor file")
260 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
264 //======================================================================
267 //======================================================================
268 /// Create the tree view for TreeHandler provided
269 void WxGimmickView::CreateTreeView( TreeHandler* h)
271 std::string name(h->GetTree().GetAttribute("Name"));
272 GimmickMessage(2,"Creating the tree view for '"<<
273 name<<"'"<<std::endl);
274 // Create the WxTreeView
275 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
277 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
278 // ALREADY IN THE MAP
279 GetTreeViewMap()[name] = view;
282 mNotebook->AddPage( view, crea::std2wx(name) );
286 //======================================================================
287 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
289 std::vector<std::string> files;
290 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
291 ReadImagesNotThreaded(s,files,dim);
293 //======================================================================
295 //======================================================================
296 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
298 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
300 //======================================================================
302 //======================================================================
303 void WxGimmickView::GetImages(int dim,
304 const std::vector<std::string>& files,
305 std::vector<vtkImageData*>& s)
307 ReadImagesNotThreaded(s,files,dim);
309 //======================================================================
312 //=================================================
313 void WxGimmickView::CreateIconList()
315 // Size of the icons;
319 // should correspond to Icon_xxx enum
320 icons[Icon_accept] = wxIcon(accept_xpm);
321 icons[Icon_add] = wxIcon(add_xpm);
322 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
323 icons[Icon_page_down] = wxIcon(page_down_xpm);
324 icons[Icon_remove] = wxIcon(remove_xpm);
325 icons[Icon_database_add] = wxIcon(database_add_xpm);
326 icons[Icon_help] = wxIcon(help_xpm);
327 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
328 icons[Icon_create_database] = wxIcon(create_database_xpm);
329 icons[Icon_settings] = wxIcon(settings_xpm);
330 icons[Icon_tools] = wxIcon(tools_xpm);
332 // unsigned int NbIcons = 8;
333 // Make an image list containing small icons
334 mIcon = new wxImageList(size,size,true);
336 // Make all icons the same size = size of the first one
337 int sizeOrig = icons[0].GetWidth();
338 for ( size_t i = 0; i < icon_number; i++ )
340 if ( size == sizeOrig )
342 mIcon->Add(icons[i]);
346 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
350 //=================================================
353 //=================================================
354 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
356 mViewer->StopPlayer();
357 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
359 wxFileDialog* FD = new wxFileDialog( 0,
367 if (FD->ShowModal()==wxID_OK)
374 std::vector<std::string> filenames;
375 for (i=0;i<files.GetCount();++i)
377 filenames.push_back(wx2std(files[i]));
378 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
382 new wxProgressDialog(_T("Adding file(s)"),
387 // wxPD_ESTIMATED_TIME |
388 // wxPD_REMAINING_TIME |
391 // TO DO : select the current tree handler
392 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
394 mProgressDialog->Pulse(_T("Updating view..."));
396 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
397 delete mProgressDialog;
401 mViewer->StartPlayer();
403 //=================================================
405 //=================================================
406 void WxGimmickView::OnAddDir(wxCommandEvent& event)
408 mViewer->StopPlayer();
409 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
410 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
413 _T("Select directory"),
417 if (FD->ShowModal()==wxID_OK)
421 std::string dirname = wx2std (FD->GetPath());
422 bool recurse = isNeedRecursive(dirname);
425 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
429 wxString title(_T("Adding directory"));
431 title = _T("Adding directory (recursive)");
433 new wxProgressDialog(_T("Adding directory"),
435 NumberFilesToAdd(dirname,recurse),
439 // wxPD_ESTIMATED_TIME |
440 // wxPD_REMAINING_TIME |
443 mCurrentDirectory = FD->GetPath();
444 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
445 mProgressDialog->Pulse(_T("Updating view..."));
447 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
448 delete mProgressDialog;
452 mViewer->StartPlayer();
456 //=================================================
457 // Determines number of files potentially to add to database
458 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
461 if ( !boost::filesystem::exists( dirpath ) ) return nb;
462 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
463 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
465 // If is directory & recurse : do recurse
466 if ( boost::filesystem::is_directory(itr->status()) )
470 nb += NumberFilesToAdd(itr->string(), recursive);
482 //=================================================
483 // Test a directory to know if contains sub-directory to analyze
484 bool WxGimmickView::isNeedRecursive(std::string i_name)
486 boost::filesystem::directory_iterator iter(i_name), end_iter;
487 bool bfindir = false;
488 for(; iter != end_iter; ++iter)
490 if(boost::filesystem::is_directory(*iter))
497 //=================================================
499 //=================================================
500 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
502 GimmickDebugMessage(5,
503 "WxGimmickView::OnSelectionChange"
510 valid= ValidateSelected(NULL,
511 mSelectionMinDimension,
512 mSelectionMaxDimension );
517 std::vector<tree::Node*>::const_iterator i;
518 for(i=sel.begin();i!=sel.end()&&valid;++i)
520 valid= ValidateSelected((*i),
521 mSelectionMinDimension,
522 mSelectionMaxDimension );
527 valid= ValidateSelected(sel.front(),
528 mSelectionMinDimension,
529 mSelectionMaxDimension );
534 std::vector<tree::Node*>::const_iterator i;
535 for(i=sel.begin();i!=sel.end()&&valid;++i)
537 valid= ValidateSelected((*i),
538 mSelectionMinDimension,
539 mSelectionMaxDimension );
542 mText->SetLabel(crea::std2wx(GetMessage()));
545 ReadImageThreaded(sel);
551 ReadImageThreaded(sel);
556 //==================================================
558 //==================================================
559 ///Reads Images (Threaded)
560 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
562 GimmickDebugMessage(5,
565 int maxprio = GetMaximalPriority();
566 int prio = maxprio + 2000;
570 //First load the selected images
571 mCurImageItemToShow = sel.front();
574 std::vector<tree::Node*>::const_iterator selected;
575 for(selected=sel.begin();selected!=sel.end();++selected)
577 GimmickDebugMessage(5,
578 "Requesting image from selected "
579 <<(*selected)->GetAttribute("FullFileName")
581 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
582 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
583 pointers.push_back(ph);
584 RequestReading(*selected,prio,index,ph);
585 // AddEntryToMap(*selected);
589 mViewer->SetImageVector(pointers);
592 std::vector<tree::Node*> up;
593 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
594 std::vector<tree::Node*>::iterator iterUp;
595 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
597 GimmickDebugMessage(5,
598 "Requesting image from neighbors up "
599 <<(*iterUp)->GetAttribute("FullFileName")
601 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
602 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
603 RequestReading(*iterUp,prio,-1,ph);
604 // AddEntryToMap(*iterUp);
606 if (prio == maxprio) break;
611 std::vector<tree::Node*> down;
612 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
613 std::vector<tree::Node*>::iterator iterDown;
614 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
616 GimmickDebugMessage(5,
617 "Requesting image from neighbors down "
618 <<(*iterDown)->GetAttribute("FullFileName")
620 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
621 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
622 RequestReading(*iterDown,prio,-1,ph);
623 // AddEntryToMap(*iterDown);
625 if (prio == maxprio) break;
631 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
632 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
633 pointers.push_back(ph);
634 mViewer->SetImageVector(pointers);
638 //==================================================
640 //==================================================
642 //==================================================
643 void WxGimmickView::OnInternalIdle()
645 if (!mConstructed) return;
646 static bool first_time = true;
651 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
652 // mViewer->StartPlayer();
655 mViewer->RefreshIfNecessary();
659 //==================================================
661 //==================================================
662 void WxGimmickView::ClearSelection()
665 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
666 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
667 mViewer->SetImageVector(pointers);
668 mViewer->RefreshIfNecessary();
672 //=================================================
674 //=================================================
675 void WxGimmickView::OnRemove(wxCommandEvent& event)
677 //TODO Select current tree handler
679 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
682 //=================================================
685 //=================================================
686 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
688 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
689 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
692 //=================================================
693 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
695 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
696 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
699 //=================================================
700 void WxGimmickView::AddDir(std::string dirName)
702 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
703 mCurrentDirectory = crea::std2wx(dirName);
704 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
705 mProgressDialog->Pulse(_T("Updating view..."));
707 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
708 delete mProgressDialog;
712 //=================================================
713 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
716 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
717 _T("Check database for files deletion, addition and attributes change. Then give a report."),
718 _T("Repair database (remove deleted files and add new files)."),
719 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
721 wxSingleChoiceDialog dialog(this,
722 _T("Select one of the following synchronization actions:\n")
723 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
724 _T("Synchronization Settings"),
725 WXSIZEOF(choices), choices);
727 //dialog.SetSelection(0);
729 if (dialog.ShowModal() == wxID_OK)
731 int sel=dialog.GetSelection();
733 bool checkAttributes=false;
734 if(sel==2 || sel==3){repair=true;}
735 if(sel==1 || sel==3){checkAttributes=true;}
736 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
737 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
738 if(sel==2 || sel==3){
739 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
744 //=================================================
746 //=================================================
747 void WxGimmickView::OnSettings(wxCommandEvent& event)
749 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
750 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
752 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
754 siz->Add( nb,1,wxGROW ,0);
755 CreateSettingsDialog(nb,dial);
759 //=================================================
760 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
763 // Test if one image is selected => export
765 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
775 void WxGimmickView::ExportImages()
777 //Archive selection: name, emplacement
778 //same process than copy local but to a zip
779 // if settings are yes "always ask for descriptor addition", ask
780 // if settings are yes, adding descriptor
783 void WxGimmickView::ImportImages()
787 // Contain a descriptor.text
788 // create a new database, and add to database
789 // if not, add to current database
793 //=================================================
795 void WxGimmickView::OnTools(wxCommandEvent& event)
797 mViewer->StopPlayer();
799 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
801 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
802 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
803 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
804 dialSizer->Add(nb,1,wxGROW,0);
805 dialSizer->Add(buttonsSizer,0,wxGROW);
807 #if defined(BUILD_BRUKER)
808 //First page: Bruker Image Reader
809 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
810 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
813 dial->SetSizer(dialSizer, true);
817 if (dial->GetReturnCode() == wxID_OK)
819 #if defined(BUILD_BRUKER)
820 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
822 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
823 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
825 bool addToDB = gimmickTools->getCheckBoxValue();
827 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
829 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
830 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
833 b2d.SetInputDirectory(inputDir);
834 b2d.SetOutputDirectory(outputDir);
835 b2d.SetConvertModeToDicom();
841 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
842 mCurrentDirectory = gimmickTools->getOutputDir();
843 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
844 mProgressDialog->Pulse(_T("Updating view..."));
846 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
847 delete mProgressDialog;
855 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
862 mViewer->StartPlayer();
864 //=================================================
866 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
868 //First page: Customization of configurations
871 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
872 //Database Path String
874 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
875 //Syncronization Event String
877 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
878 //Syncronization Frequency String
880 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
882 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
884 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
886 //Second page: Creation of Databases
887 /*wxPanel* databaseCreation=new wxPanel(nb);
888 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
890 //Second page (temporary): Connection to PACS
891 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
892 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
894 //Third page: CD/DVD Watch
895 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
896 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
898 //Fourth page: Selection of attributes to show
899 std::vector<std::string> shown;
900 std::vector<std::string> nShown;
901 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
902 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
903 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
904 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
907 //===================================================================
908 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
909 std::vector<std::string>& nShown, int level)
911 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
914 //===================================================================
915 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
917 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
918 std::vector<std::string> n=nShown;
919 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
921 //===================================================================
922 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
923 const std::string& dbPath,
924 const std::string& syncEvent,
925 const std::string& syncFreq)
927 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
928 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
929 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
930 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
933 //===================================================================
934 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
936 mListener->SetMonitoredDrive(drive);
937 mListener->SetAddFilesState(addFiles);
938 mListener->SetRemoveFilesState(removeFiles);
941 //========================================================================
943 void WxGimmickView::OnDriveMount(bool mount)
945 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
947 mListener->GetMonitoredDrive(drive);
951 mViewer->StopPlayer();
953 wxString title(_T("Adding drive"));
955 new wxProgressDialog(_T("Adding drive"),
960 // wxPD_ESTIMATED_TIME |
961 // wxPD_REMAINING_TIME |
963 mCurrentDirectory = crea::std2wx(drive);
964 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
965 mProgressDialog->Pulse(_T("Updating view..."));
967 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
968 delete mProgressDialog;
970 mViewer->StartPlayer();
974 mGimmick->DeleteDrive(drive);
975 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
979 //========================================================================
981 void WxGimmickView::StartListeningThread()
986 //========================================================================
988 void WxGimmickView::StopListeningThread()
993 //========================================================================
994 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
996 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
997 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
998 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1000 siz->Add( ef,1,wxGROW ,0);
1001 dial->SetSizer(siz);
1005 //========================================================================
1006 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1008 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1009 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1012 //=================================================
1013 /// AddProgress Gimmick callback
1014 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1017 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1018 p.GetNumberScannedDirs(),
1019 p.GetNumberScannedFiles(),
1020 p.GetNumberHandledFiles(),
1021 p.GetNumberAddedFiles());
1022 // std::cout << "OnAddProgress "<<mess<<std::endl;
1023 wxString s(wxString::From8BitData(mess));
1024 // std::cout << "Pulse"<<std::endl;
1025 if (!mProgressDialog->Pulse(s))
1029 // std::cout << "OnAddProgress ok"<<std::endl;
1031 //=================================================
1033 //=================================================
1034 void WxGimmickView::DisplayAddSummary()
1036 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1037 std::stringstream mess;
1038 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1039 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1040 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1041 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1042 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1045 ////////////////////////////////////////////////
1046 // Add a DB to application //
1047 // @param event : WxEvent //
1049 ////////////////////////////////////////////////
1050 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1053 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1054 std::string wc("*.sqlite3*");
1055 wxFileDialog* FD = new wxFileDialog( 0,
1063 if (FD->ShowModal()==wxID_OK)
1066 wxArrayString files;
1067 FD->GetPaths(files);
1068 std::stringstream st;
1069 for(int i = 0; i< files.size(); i++)
1071 //get name of DB (file name)
1072 size_t pos = files[i].find_last_of(_T("\\"));
1073 std::string name = crea::wx2std(files[i].substr(pos+1));
1074 pos = name.find_last_of(".");
1075 name = name.substr(0,pos);
1076 //create TreeHandler
1077 mGimmick->addDB(name, crea::wx2std(files[i]));
1079 CreateSingleTreeView(name);
1083 ////////////////////////////////////////////////////
1084 // Create a DB from an Attributes Descriptor files //
1085 // @param event : WxEvent //
1087 //////////////////////////////////////////////////
1088 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1090 // PACSConnection("");
1091 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1092 DescriptorPan->Layout();
1093 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1096 std::string file(DescriptorPan->GetDescriptor());
1099 size_t pos = file.find_last_of("\\");
1100 std::string name = file.substr(pos+1);
1101 std::string directory = file.substr(0,pos);
1102 pos = name.find_last_of(".");
1103 name = name.substr(0,pos);
1104 //get directory to store DB
1105 directory += "\\" + name + ".sqlite3";
1107 mGimmick->createDB(name, file,directory);
1108 //create TreeHandler
1109 mGimmick->addDB(name, directory);
1111 CreateSingleTreeView(name);
1116 //=================================================
1118 //=================================================
1119 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1120 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1121 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1122 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1123 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1124 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1125 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1126 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1127 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1129 //=================================================
1131 } // EO namespace creaImageIO