1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4 #include <creaImageIOWxCustomizeConfigPanel.h>
5 #include <creaImageIOWxListenerPanel.h>
6 #include <creaImageIOWxEditFieldsPanel.h>
7 #include <creaImageIOWxAttributeSelectionPanel.h>
8 #include <creaImageIOWxPACSConnectionPanel.h>
12 #include "icons/accept.xpm"
13 #include "icons/add.xpm"
14 #include "icons/folder-down.xpm"
15 #include "icons/page-down.xpm"
16 #include "icons/remove.xpm"
17 #include "icons/database-add.xpm"
18 #include "icons/create-database.xpm"
19 #include "icons/help.xpm"
20 #include "icons/synchronize.xpm"
21 #include "icons/settings.xpm"
22 #include "icons/tools.xpm"
23 //#include "icons/import.xpm"
25 #include <wx/imaglist.h>
26 #include <wx/popupwin.h>
27 #include<boost/filesystem/operations.hpp>
28 #if defined(BUILD_BRUKER)
29 #include "bruker2dicom.h"
35 //======================================================================
36 // The ids of the different tools
42 TOOL_ADDDATABASE_ID = 4,
44 TOOL_SYNCHRONIZE_ID = 6,
49 //======================================================================
51 //================================================================
53 const int icon_number = 11;
70 //================================================================
72 //================================================================
74 const icon_id Icon[5] = { Icon_Database,
80 //================================================================
83 //======================================================================
85 WxGimmickView::WxGimmickView(Gimmick* gimmick,
88 const wxPoint& pos, const wxSize& size,
91 int number_of_threads)
92 : wxPanel(parent,id,pos,size),
93 GimmickView(gimmick, number_of_threads),
97 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
99 // Sets the current directory to the home dir
100 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
102 // Connect the AddProgress callback
103 gimmick->ConnectAddProgressObserver
104 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
106 // Create the list of icons (mIcon)
110 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
112 // Create the tool bar
114 sizer->Add( mToolBar ,0, wxGROW ,0);
116 // Split part below toolbar into notebook for views and panel
117 // for preview, messages...
118 mSplitter = new wxSplitterWindow( this , -1);
122 mNotebook = new wxNotebook(mSplitter,
123 -1,wxDefaultPosition, wxDefaultSize, 0);
129 mSelectionMaxDimension= max_dim;
130 mSelectionMinDimension= min_dim;
136 mBottomPanel = new wxPanel(mSplitter,-1);
138 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
142 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
143 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
144 mViewer->SetImageVector(pointers);
145 mViewer->StartPlayer();
148 bottom_sizer->Add(mViewer,1,wxGROW,1);
151 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
152 bottom_sizer->Add(mText,0,wxGROW,0);
156 mBottomPanel->SetSizer(bottom_sizer);
159 int hsize = size.GetHeight();
161 int top_minsize = 450;
162 int bottom_minsize = 50;
164 mSplitter->SetMinimumPaneSize( bottom_minsize );
165 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
168 sizer->Add( mSplitter,1,wxGROW ,0);
174 mListener=new Listener();
175 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
182 //======================================================================
184 //======================================================================
186 WxGimmickView::~WxGimmickView()
188 // stop the viewer before application exit.
189 mViewer->StopPlayer();
190 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
192 if(mListener->IsAlive())
197 //======================================================================
199 //======================================================================
200 /// Creates the tool bar
201 void WxGimmickView::CreateToolBar()
203 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
204 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
207 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
208 _T("Create database"),
209 mIcon->GetBitmap(Icon_create_database),
210 _T("Create DB from an Attributes Descriptor file")
212 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
214 mIcon->GetBitmap(Icon_page_down),
215 _T("Add one or more file to database")
217 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
219 mIcon->GetBitmap(Icon_folder_down),
220 _T("Add the content of a folder to database")
222 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
224 mIcon->GetBitmap(Icon_database_add),
225 _T("Open a local or distant database")
227 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
229 mIcon->GetBitmap(Icon_remove),
230 _T("Remove selected items")
232 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
234 mIcon->GetBitmap(Icon_synchronize),
235 _T("Synchronizes the database with disk")
237 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
239 mIcon->GetBitmap(Icon_help),
240 _T("Open help window")
242 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
243 _T("System settings"),
244 mIcon->GetBitmap(Icon_settings),
245 _T("Allows the modification of various system settings")
247 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
249 mIcon->GetBitmap(Icon_tools),
250 _T("Applies tools to images")
252 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
256 //======================================================================
259 //======================================================================
260 /// Create the tree view for TreeHandler provided
261 void WxGimmickView::CreateTreeView( TreeHandler* h)
263 std::string name(h->GetTree().GetAttribute("Name"));
264 GimmickMessage(2,"Creating the tree view for '"<<
265 name<<"'"<<std::endl);
266 // Create the WxTreeView
267 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
269 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
270 // ALREADY IN THE MAP
271 GetTreeViewMap()[name] = view;
274 mNotebook->AddPage( view, crea::std2wx(name) );
278 //======================================================================
279 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
281 std::vector<std::string> files;
282 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
283 ReadImagesNotThreaded(s,files,dim);
285 //======================================================================
287 //======================================================================
288 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
290 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
292 //======================================================================
294 //======================================================================
295 void WxGimmickView::GetImages(int dim,
296 const std::vector<std::string>& files,
297 std::vector<vtkImageData*>& s)
299 ReadImagesNotThreaded(s,files,dim);
301 //======================================================================
304 //=================================================
305 void WxGimmickView::CreateIconList()
307 // Size of the icons;
311 // should correspond to Icon_xxx enum
312 icons[Icon_accept] = wxIcon(accept_xpm);
313 icons[Icon_add] = wxIcon(add_xpm);
314 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
315 icons[Icon_page_down] = wxIcon(page_down_xpm);
316 icons[Icon_remove] = wxIcon(remove_xpm);
317 icons[Icon_database_add] = wxIcon(database_add_xpm);
318 icons[Icon_help] = wxIcon(help_xpm);
319 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
320 icons[Icon_create_database] = wxIcon(create_database_xpm);
321 icons[Icon_settings] = wxIcon(settings_xpm);
322 icons[Icon_tools] = wxIcon(tools_xpm);
324 // unsigned int NbIcons = 8;
325 // Make an image list containing small icons
326 mIcon = new wxImageList(size,size,true);
328 // Make all icons the same size = size of the first one
329 int sizeOrig = icons[0].GetWidth();
330 for ( size_t i = 0; i < icon_number; i++ )
332 if ( size == sizeOrig )
334 mIcon->Add(icons[i]);
338 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
342 //=================================================
345 //=================================================
346 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
348 mViewer->StopPlayer();
349 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
350 std::string wc("*.*");
351 wxFileDialog* FD = new wxFileDialog( 0,
359 if (FD->ShowModal()==wxID_OK)
366 std::vector<std::string> filenames;
367 for (i=0;i<files.GetCount();++i)
369 filenames.push_back(wx2std(files[i]));
370 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
374 new wxProgressDialog(_T("Adding file(s)"),
379 // wxPD_ESTIMATED_TIME |
380 // wxPD_REMAINING_TIME |
383 // TO DO : select the current tree handler
384 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
386 mProgressDialog->Pulse(_T("Updating view..."));
388 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
389 delete mProgressDialog;
393 mViewer->StartPlayer();
395 //=================================================
397 //=================================================
398 void WxGimmickView::OnAddDir(wxCommandEvent& event)
400 mViewer->StopPlayer();
401 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
402 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
405 _T("Select directory"),
409 if (FD->ShowModal()==wxID_OK)
413 std::string dirname = wx2std (FD->GetPath());
414 bool recurse = isNeedRecursive(dirname);
417 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
421 wxString title(_T("Adding directory"));
423 title = _T("Adding directory (recursive)");
425 new wxProgressDialog(_T("Adding directory"),
427 NumberFilesToAdd(dirname,recurse),
431 // wxPD_ESTIMATED_TIME |
432 // wxPD_REMAINING_TIME |
435 mCurrentDirectory = FD->GetPath();
436 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
437 mProgressDialog->Pulse(_T("Updating view..."));
439 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
440 delete mProgressDialog;
444 mViewer->StartPlayer();
448 //=================================================
449 // Determines number of files potentially to add to database
450 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
453 if ( !boost::filesystem::exists( dirpath ) ) return nb;
454 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
455 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
457 // If is directory & recurse : do recurse
458 if ( boost::filesystem::is_directory(itr->status()) )
462 nb += NumberFilesToAdd(itr->string(), recursive);
474 //=================================================
475 // Test a directory to know if contains sub-directory to analyze
476 bool WxGimmickView::isNeedRecursive(std::string i_name)
478 boost::filesystem::directory_iterator iter(i_name), end_iter;
479 bool bfindir = false;
480 for(; iter != end_iter; ++iter)
482 if(boost::filesystem::is_directory(*iter))
489 //=================================================
491 //=================================================
492 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
494 GimmickDebugMessage(5,
495 "WxGimmickView::OnSelectionChange"
502 valid= ValidateSelected(NULL,
503 mSelectionMinDimension,
504 mSelectionMaxDimension );
509 std::vector<tree::Node*>::const_iterator i;
510 for(i=sel.begin();i!=sel.end()&&valid;++i)
512 valid= ValidateSelected((*i),
513 mSelectionMinDimension,
514 mSelectionMaxDimension );
519 valid= ValidateSelected(sel.front(),
520 mSelectionMinDimension,
521 mSelectionMaxDimension );
526 std::vector<tree::Node*>::const_iterator i;
527 for(i=sel.begin();i!=sel.end()&&valid;++i)
529 valid= ValidateSelected((*i),
530 mSelectionMinDimension,
531 mSelectionMaxDimension );
534 mText->SetLabel(crea::std2wx(GetMessage()));
537 ReadImageThreaded(sel);
543 ReadImageThreaded(sel);
548 //==================================================
550 //==================================================
551 ///Reads Images (Threaded)
552 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
554 GimmickDebugMessage(5,
557 int maxprio = GetMaximalPriority();
558 int prio = maxprio + 2000;
562 //First load the selected images
563 mCurImageItemToShow = sel.front();
566 std::vector<tree::Node*>::const_iterator selected;
567 for(selected=sel.begin();selected!=sel.end();++selected)
569 GimmickDebugMessage(5,
570 "Requesting image from selected "
571 <<(*selected)->GetAttribute("FullFileName")
573 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
574 pointers.push_back(ph);
575 RequestReading(*selected,prio,index,ph);
576 // AddEntryToMap(*selected);
580 mViewer->SetImageVector(pointers);
583 std::vector<tree::Node*> up;
584 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
585 std::vector<tree::Node*>::iterator iterUp;
586 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
588 GimmickDebugMessage(5,
589 "Requesting image from neighbors up "
590 <<(*iterUp)->GetAttribute("FullFileName")
592 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
593 RequestReading(*iterUp,prio,-1,ph);
594 // AddEntryToMap(*iterUp);
596 if (prio == maxprio) break;
601 std::vector<tree::Node*> down;
602 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
603 std::vector<tree::Node*>::iterator iterDown;
604 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
606 GimmickDebugMessage(5,
607 "Requesting image from neighbors down "
608 <<(*iterDown)->GetAttribute("FullFileName")
610 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
611 RequestReading(*iterDown,prio,-1,ph);
612 // AddEntryToMap(*iterDown);
614 if (prio == maxprio) break;
620 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
621 pointers.push_back(ph);
622 mViewer->SetImageVector(pointers);
626 //==================================================
628 //==================================================
630 //==================================================
631 void WxGimmickView::OnInternalIdle()
633 if (!mConstructed) return;
634 static bool first_time = true;
639 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
640 // mViewer->StartPlayer();
643 mViewer->RefreshIfNecessary();
647 //==================================================
649 //==================================================
650 void WxGimmickView::ClearSelection()
653 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
654 mViewer->SetImageVector(pointers);
655 mViewer->RefreshIfNecessary();
659 //=================================================
661 //=================================================
662 void WxGimmickView::OnRemove(wxCommandEvent& event)
664 //TODO Select current tree handler
666 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
669 //=================================================
672 //=================================================
673 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
675 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
676 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
679 //=================================================
680 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
682 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
683 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
686 //=================================================
687 void WxGimmickView::AddDir(std::string dirName)
689 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
690 mCurrentDirectory = crea::std2wx(dirName);
691 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
692 mProgressDialog->Pulse(_T("Updating view..."));
694 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
695 delete mProgressDialog;
699 //=================================================
700 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
703 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
704 _T("Check database for files deletion, addition and attributes change. Then give a report."),
705 _T("Repair database (remove deleted files and add new files)."),
706 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
708 wxSingleChoiceDialog dialog(this,
709 _T("Select one of the following synchronization actions:\n")
710 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
711 _T("Synchronization Settings"),
712 WXSIZEOF(choices), choices);
714 //dialog.SetSelection(0);
716 if (dialog.ShowModal() == wxID_OK)
718 int sel=dialog.GetSelection();
720 bool checkAttributes=false;
721 if(sel==2 || sel==3){repair=true;}
722 if(sel==1 || sel==3){checkAttributes=true;}
723 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
724 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
725 if(sel==2 || sel==3){
726 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
731 //=================================================
733 //=================================================
734 void WxGimmickView::OnSettings(wxCommandEvent& event)
736 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
737 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
739 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
741 siz->Add( nb,1,wxGROW ,0);
742 CreateSettingsDialog(nb,dial);
746 //=================================================
747 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
750 // Test if one image is selected => export
752 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
762 void WxGimmickView::ExportImages()
764 //Archive selection: name, emplacement
765 //same process than copy local but to a zip
766 // if settings are yes "always ask for descriptor addition", ask
767 // if settings are yes, adding descriptor
770 void WxGimmickView::ImportImages()
774 // Contain a descriptor.text
775 // create a new database, and add to database
776 // if not, add to current database
780 //=================================================
782 void WxGimmickView::OnTools(wxCommandEvent& event)
784 mViewer->StopPlayer();
786 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
788 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
789 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
791 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
792 dialSizer->Add(nb,1,wxGROW,0);
793 dialSizer->Add(buttonsSizer,0,wxGROW);
795 #if defined(BUILD_BRUKER)
796 //First page: Bruker Image Reader
797 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
798 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
801 dial->SetSizer(dialSizer, true);
805 if (dial->GetReturnCode() == wxID_OK)
807 #if defined(BUILD_BRUKER)
808 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
810 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
811 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
812 bool addToDB = gimmickTools->getCheckBoxValue();
814 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
816 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
817 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
820 b2d.SetInputDirectory(inputDir);
821 b2d.SetOutputDirectory(outputDir);
822 b2d.SetConvertModeToDicom();
827 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
828 mCurrentDirectory = gimmickTools->getOutputDir();
829 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
830 mProgressDialog->Pulse(_T("Updating view..."));
832 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
833 delete mProgressDialog;
841 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
848 mViewer->StartPlayer();
850 //=================================================
852 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
854 //First page: Customization of configurations
857 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
858 //Database Path String
860 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
861 //Syncronization Event String
863 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
864 //Syncronization Frequency String
866 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
868 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
870 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
872 //Second page: Creation of Databases
873 /*wxPanel* databaseCreation=new wxPanel(nb);
874 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
876 //Second page (temporary): Connection to PACS
877 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
878 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
880 //Third page: CD/DVD Watch
881 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
882 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
884 //Fourth page: Selection of attributes to show
885 std::vector<std::string> shown;
886 std::vector<std::string> nShown;
887 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
888 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
889 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
890 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
893 //===================================================================
894 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
895 std::vector<std::string>& nShown, int level)
897 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
900 //===================================================================
901 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
903 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
904 std::vector<std::string> n=nShown;
905 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
907 //===================================================================
908 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
909 const std::string& dbPath,
910 const std::string& syncEvent,
911 const std::string& syncFreq)
913 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
914 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
915 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
916 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
919 //===================================================================
920 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
922 mListener->SetMonitoredDrive(drive);
923 mListener->SetAddFilesState(addFiles);
924 mListener->SetRemoveFilesState(removeFiles);
927 //========================================================================
929 void WxGimmickView::OnDriveMount(bool mount)
931 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
933 mListener->GetMonitoredDrive(drive);
937 mViewer->StopPlayer();
939 wxString title(_T("Adding drive"));
941 new wxProgressDialog(_T("Adding drive"),
946 // wxPD_ESTIMATED_TIME |
947 // wxPD_REMAINING_TIME |
949 mCurrentDirectory = crea::std2wx(drive);
950 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
951 mProgressDialog->Pulse(_T("Updating view..."));
953 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
954 delete mProgressDialog;
956 mViewer->StartPlayer();
961 mGimmick->DeleteDrive(drive);
962 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
967 //========================================================================
969 void WxGimmickView::StartListeningThread()
974 //========================================================================
976 void WxGimmickView::StopListeningThread()
981 //========================================================================
982 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
984 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
985 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
986 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
988 siz->Add( ef,1,wxGROW ,0);
993 //========================================================================
994 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
996 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
997 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1000 //=================================================
1001 /// AddProgress Gimmick callback
1002 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1005 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1006 p.GetNumberScannedDirs(),
1007 p.GetNumberScannedFiles(),
1008 p.GetNumberHandledFiles(),
1009 p.GetNumberAddedFiles());
1010 // std::cout << "OnAddProgress "<<mess<<std::endl;
1011 wxString s(wxString::From8BitData(mess));
1012 // std::cout << "Pulse"<<std::endl;
1013 if (!mProgressDialog->Pulse(s))
1017 // std::cout << "OnAddProgress ok"<<std::endl;
1019 //=================================================
1021 //=================================================
1022 void WxGimmickView::DisplayAddSummary()
1024 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1025 std::stringstream mess;
1026 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1027 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1028 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1029 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1032 sprintf(times,"Time to parse dir \t\t: %ld ms \t%d°/o\nTime to read files info \t: %ld ms \t%d°/o\nTime to update structs \t: %ld ms \t%d°/o\nTime to update database \t: %ld ms \t%d°/o\nTotal time \t\t\t: %ld ms",
1034 (int)( summary.parse_time*100./summary.total_time),
1035 summary.file_scan_time,
1036 (int)(summary.file_scan_time*100./summary.total_time),
1037 summary.update_structs_time,
1038 (int)(summary.update_structs_time*100./summary.total_time),
1039 summary.update_database_time,
1040 (int)(summary.update_database_time*100./summary.total_time),
1041 summary.total_time );
1045 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1048 //////////////////////////////////////////////////
1049 // Add a DB to application //
1050 // @param event : WxEvent //
1052 //////////////////////////////////////////////////
1053 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1057 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1058 std::string wc("*.sqlite3*");
1059 wxFileDialog* FD = new wxFileDialog( 0,
1067 if (FD->ShowModal()==wxID_OK)
1070 wxArrayString files;
1071 FD->GetPaths(files);
1072 std::stringstream st;
1073 for(int i = 0; i< files.size(); i++)
1075 //get name of DB (file name)
1076 size_t pos = files[i].find_last_of(_T("\\"));
1077 std::string name = crea::wx2std(files[i].substr(pos+1));
1078 pos = name.find_last_of(".");
1079 name = name.substr(0,pos);
1080 //create TreeHandler
1081 mGimmick->addDB(name, crea::wx2std(files[i]));
1083 CreateSingleTreeView(name);
1087 ////////////////////////////////////////////////////
1088 // Create a DB from an Attributes Descriptor files //
1089 // @param event : WxEvent //
1091 //////////////////////////////////////////////////
1092 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1096 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1097 std::string wc("*.txt");
1098 wxFileDialog* FD = new wxFileDialog( 0,
1106 if (FD->ShowModal()==wxID_OK)
1109 wxArrayString afile;
1110 FD->GetPaths(afile);
1111 //get name of DB (file name)
1112 std::string file = crea::wx2std(afile[0]);
1113 size_t pos = file.find_last_of("\\");
1114 std::string name = file.substr(pos+1);
1115 std::string directory = file.substr(0,pos);
1116 pos = name.find_last_of(".");
1117 name = name.substr(0,pos);
1118 //get directory to store DB
1119 directory += "\\" + name + ".sqlite3";
1121 mGimmick->createDB(name, file,directory);
1122 //create TreeHandler
1123 mGimmick->addDB(name, directory);
1125 CreateSingleTreeView(name);
1129 //=================================================
1131 //=================================================
1132 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1133 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1134 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1135 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1136 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1137 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1138 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1139 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1140 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1142 //=================================================
1144 } // EO namespace creaImageIO