+ std::string dirname = wx2std (FD->GetPath());
+ bool recurse = isNeedRecursive(dirname);
+ if (recurse)
+ {
+ recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
+ }
+
+ wxBusyCursor busy;
+ wxString title(_T("Adding directory"));
+ if (recurse)
+ title = _T("Adding directory (recursive)");
+ mProgressDialog =
+ new wxProgressDialog(_T("Adding directory"),
+ _T(""),
+ 1000,
+ this,
+ wxPD_ELAPSED_TIME |
+ // wxPD_ESTIMATED_TIME |
+ // wxPD_REMAINING_TIME |
+ wxPD_CAN_ABORT );
+
+ mCurrentDirectory = FD->GetPath();
+ mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+ delete mProgressDialog;
+ DisplayAddSummary();
+
+ }
+ mViewer->StartPlayer();
+ }
+
+ //=================================================
+ // Test a directory to know if contains sub-directory to analyze
+ bool WxGimmickView::isNeedRecursive(std::string i_name)
+ {
+ boost::filesystem::directory_iterator iter(i_name), end_iter;
+ bool bfindir = false;
+ for(; iter != end_iter; ++iter)
+ {
+ if(boost::filesystem::is_directory(*iter))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ //=================================================
+
+ //=================================================
+ void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
+ {
+ GimmickDebugMessage(5,
+ "WxGimmickView::OnSelectionChange"
+ <<std::endl);
+ wxBusyCursor busy;
+ bool valid=true;
+
+ if(sel.size()==0)
+ {
+ valid= ValidateSelected(NULL,
+ mSelectionMinDimension,
+ mSelectionMaxDimension );
+ }
+ else if(needProcess)
+ {
+ ResetExtent();
+ std::vector<tree::Node*>::const_iterator i;
+ for(i=sel.begin();i!=sel.end()&&valid;++i)
+ {
+ valid= ValidateSelected((*i),
+ mSelectionMinDimension,
+ mSelectionMaxDimension );
+ }
+ }
+ else if(isSelection)
+ {
+ valid= ValidateSelected(sel.front(),
+ mSelectionMinDimension,
+ mSelectionMaxDimension );
+ }
+ else
+ {
+ ResetExtent();
+ std::vector<tree::Node*>::const_iterator i;
+ for(i=sel.begin();i!=sel.end()&&valid;++i)
+ {
+ valid= ValidateSelected((*i),
+ mSelectionMinDimension,
+ mSelectionMaxDimension );
+ }
+ }
+ mText->SetLabel(crea::std2wx(GetMessage()));
+ /*if(valid)
+ {
+ ReadImageThreaded(sel);
+ }
+ else
+ {
+ ClearSelection();
+ }*/
+ ReadImageThreaded(sel);
+
+
+ }
+
+ //==================================================
+
+ //==================================================
+ ///Reads Images (Threaded)
+ void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
+ {
+ GimmickDebugMessage(5,
+ "ReadImageThreaded"
+ <<std::endl);
+ int maxprio = GetMaximalPriority();
+ int prio = maxprio + 2000;
+
+ if(sel.size()>0)
+ {
+ //First load the selected images
+ mCurImageItemToShow = sel.front();
+ pointers.clear();
+ int index = 0;
+ std::vector<tree::Node*>::const_iterator selected;
+ for(selected=sel.begin();selected!=sel.end();++selected)
+ {
+ GimmickDebugMessage(5,
+ "Requesting image from selected "
+ <<(*selected)->GetAttribute("FullFileName")
+ <<std::endl);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ pointers.push_back(ph);
+ RequestReading(*selected,prio,index,ph);
+ // AddEntryToMap(*selected);
+ prio--;
+ index++;
+ }
+ mViewer->SetImageVector(pointers);
+ //Going up
+ prio = maxprio + 20;
+ std::vector<tree::Node*> up;
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
+ std::vector<tree::Node*>::iterator iterUp;
+ for(iterUp=up.begin();iterUp!=up.end();++iterUp)
+ {
+ GimmickDebugMessage(5,
+ "Requesting image from neighbors up "
+ <<(*iterUp)->GetAttribute("FullFileName")
+ <<std::endl);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ RequestReading(*iterUp,prio,-1,ph);
+ // AddEntryToMap(*iterUp);
+ prio--;
+ if (prio == maxprio) break;
+ }
+
+ //Going down
+ prio = maxprio + 19;
+ std::vector<tree::Node*> down;
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
+ std::vector<tree::Node*>::iterator iterDown;
+ for(iterDown=down.begin();iterDown!=down.end();++iterDown)
+ {
+ GimmickDebugMessage(5,
+ "Requesting image from neighbors down "
+ <<(*iterDown)->GetAttribute("FullFileName")
+ <<std::endl);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ RequestReading(*iterDown,prio,-1,ph);
+ // AddEntryToMap(*iterDown);
+ prio--;
+ if (prio == maxprio) break;
+ }
+ }
+ else
+ {
+ pointers.clear();
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ pointers.push_back(ph);
+ mViewer->SetImageVector(pointers);
+ }
+ }
+
+ //==================================================
+
+ //==================================================
+
+ //==================================================
+ void WxGimmickView::OnInternalIdle()
+ {
+ if (!mConstructed) return;
+ static bool first_time = true;
+ if (false)
+ {
+ first_time = false;
+ }
+ // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
+ // mViewer->StartPlayer();
+ if(mViewer)
+ {
+ mViewer->RefreshIfNecessary();
+ }
+ }
+
+ //==================================================
+
+ //==================================================
+ void WxGimmickView::ClearSelection()
+ {
+ pointers.clear();
+ pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
+ mViewer->SetImageVector(pointers);
+ mViewer->RefreshIfNecessary();
+ ResetExtent();
+ }
+
+ //=================================================
+
+ //=================================================
+ void WxGimmickView::OnRemove(wxCommandEvent& event)
+ {
+ //TODO Select current tree handler
+ wxBusyCursor busy;
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
+ ClearSelection();
+ }
+ //=================================================
+
+
+ //=================================================
+ void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
+ {
+ mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
+ }
+
+ //=================================================
+ void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
+ {
+ mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
+ wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
+ }
+
+ //=================================================
+ void WxGimmickView::AddDir(std::string dirName)
+ {
+ mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
+ mCurrentDirectory = crea::std2wx(dirName);
+ mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+ delete mProgressDialog;
+ DisplayAddSummary();
+ }
+
+ //=================================================
+ void WxGimmickView::OnSynchronize(wxCommandEvent& event)
+ {
+ wxBusyCursor busy;
+ const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
+ _T("Check database for files deletion, addition and attributes change. Then give a report."),
+ _T("Repair database (remove deleted files and add new files)."),
+ _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
+
+ wxSingleChoiceDialog dialog(this,
+ _T("Select one of the following synchronization actions:\n")
+ _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
+ _T("Synchronization Settings"),
+ WXSIZEOF(choices), choices);
+
+ //dialog.SetSelection(0);
+
+ if (dialog.ShowModal() == wxID_OK)
+ {
+ int sel=dialog.GetSelection();
+ bool repair=false;
+ bool checkAttributes=false;
+ if(sel==2 || sel==3){repair=true;}
+ if(sel==1 || sel==3){checkAttributes=true;}
+ std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
+ wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
+ if(sel==2 || sel==3){
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
+ }
+
+ }
+ }
+ //=================================================
+
+ //=================================================
+ void WxGimmickView::OnSettings(wxCommandEvent& event)
+ {
+ wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
+ wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
+ // Notebook
+ wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
+
+ siz->Add( nb,1,wxGROW ,0);
+ CreateSettingsDialog(nb,dial);
+ dial->SetSizer(siz);
+ dial->ShowModal();
+ }
+ //=================================================
+
+ //=================================================
+ //AndresDonadio
+ void WxGimmickView::OnTools(wxCommandEvent& event)
+ {
+ mViewer->StopPlayer();
+
+ wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
+
+ wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
+ wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
+
+ wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
+ dialSizer->Add(nb,1,wxGROW,0);
+ dialSizer->Add(buttonsSizer,0,wxGROW);
+
+#if defined(BUILD_BRUKER)
+ //First page: Bruker Image Reader
+ WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
+ nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
+#endif
+
+ dial->SetSizer(dialSizer, true);
+ dial->Layout();
+ dial->ShowModal();
+
+ if (dial->GetReturnCode() == wxID_OK)
+ {
+#if defined(BUILD_BRUKER)
+ if (nb->GetSelection()==0)//Selection: Bruker Image Reader
+ {
+ std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
+ std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
+ bool addToDB = gimmickTools->getCheckBoxValue();
+
+ if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
+ {
+ if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
+ _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
+ {
+ Bruker2Dicom b2d;
+ b2d.SetInputDirectory(inputDir);
+ b2d.SetOutputDirectory(outputDir);
+ b2d.SetConvertModeToDicom();
+ b2d.Execute();
+
+ if (addToDB)
+ {
+ mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
+ mCurrentDirectory = gimmickTools->getOutputDir();
+ mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+ delete mProgressDialog;
+ DisplayAddSummary();
+ }
+ }
+ }
+
+ else
+ {
+ wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
+ }
+ }
+ delete gimmickTools;
+#endif
+ }
+
+ mViewer->StartPlayer();