+ //======================================================================
+
+ //======================================================================
+ /// Creates the tool bar
+ void WxGimmickView::CreateToolBar()
+ {
+ long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
+ mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
+ style);
+
+ mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
+ _T("Create database"),
+ mIcon->GetBitmap(Icon_create_database),
+ _T("Create DB from an Attributes Descriptor file")
+ );
+ mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
+ _T("Add file(s)"),
+ mIcon->GetBitmap(Icon_page_down),
+ _T("Add one or more file to database")
+ );
+ mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
+ _T("Add folder"),
+ mIcon->GetBitmap(Icon_folder_down),
+ _T("Add the content of a folder to database")
+ );
+ mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
+ _T("Open database"),
+ mIcon->GetBitmap(Icon_database_add),
+ _T("Open a local or distant database")
+ );
+ mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
+ _T("Remove"),
+ mIcon->GetBitmap(Icon_remove),
+ _T("Remove selected items")
+ );
+ mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
+ _T("Synchronize"),
+ mIcon->GetBitmap(Icon_synchronize),
+ _T("Synchronizes the database with disk")
+ );
+ mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
+ _T("Help"),
+ mIcon->GetBitmap(Icon_help),
+ _T("Open help window")
+ );
+ //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
+
+ mToolBar->Realize();
+ }
+ //======================================================================
+
+
+ //======================================================================
+ /// Create the tree view for TreeHandler provided
+ void WxGimmickView::CreateTreeView( TreeHandler* h)
+ {
+ std::string name(h->GetTree().GetAttribute("Name"));
+ GimmickMessage(2,"Creating the tree view for '"<<
+ name<<"'"<<std::endl);
+ // Create the WxTreeView
+ WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
+
+ // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
+ // ALREADY IN THE MAP
+ GetTreeViewMap()[name] = view;
+
+ // Add Notebook page
+ mNotebook->AddPage( view, crea::std2wx(name) );
+
+ }
+
+ //======================================================================
+ void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
+ {
+ std::vector<std::string> files;
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
+ ReadImagesNotThreaded(s,files,dim);
+ }
+ //======================================================================
+
+ //======================================================================
+ void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
+ {
+ GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
+ }
+ //======================================================================
+
+ //======================================================================
+ void WxGimmickView::GetImages(int dim,
+ const std::vector<std::string>& files,
+ std::vector<vtkImageData*>& s)
+ {
+ ReadImagesNotThreaded(s,files,dim);
+ }
+ //======================================================================
+
+
+ //=================================================
+ void WxGimmickView::CreateIconList()
+ {
+ // Size of the icons;
+ int size = 16;
+
+ wxIcon icons[20];
+ // should correspond to Icon_xxx enum
+ icons[Icon_accept] = wxIcon(accept_xpm);
+ icons[Icon_add] = wxIcon(add_xpm);
+ icons[Icon_folder_down] = wxIcon(folder_down_xpm);
+ icons[Icon_page_down] = wxIcon(page_down_xpm);
+ icons[Icon_remove] = wxIcon(remove_xpm);
+ icons[Icon_database_add] = wxIcon(database_add_xpm);
+ icons[Icon_help] = wxIcon(help_xpm);
+ icons[Icon_synchronize] = wxIcon(synchronize_xpm);
+ icons[Icon_create_database] = wxIcon(create_database_xpm);
+
+ // unsigned int NbIcons = 8;
+ // Make an image list containing small icons
+ mIcon = new wxImageList(size,size,true);
+
+ // Make all icons the same size = size of the first one
+ int sizeOrig = icons[0].GetWidth();
+ for ( size_t i = 0; i < icon_number; i++ )
+ {
+ if ( size == sizeOrig )
+ {
+ mIcon->Add(icons[i]);
+ }
+ else
+ {
+ mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
+ }
+ }
+ }
+ //=================================================
+
+
+ //=================================================
+ void WxGimmickView::OnAddFiles(wxCommandEvent& event)
+ {
+ mViewer->StopPlayer();
+ long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
+ std::string wc("*.*");
+ wxFileDialog* FD = new wxFileDialog( 0,
+ _T("Select file"),
+ _T(""),
+ _T(""),
+ crea::std2wx(wc),
+ style,
+ wxDefaultPosition);
+
+ if (FD->ShowModal()==wxID_OK)
+ {
+ wxBusyCursor busy;
+
+ wxArrayString files;
+ FD->GetPaths(files);
+ unsigned int i;
+ std::vector<std::string> filenames;
+ for (i=0;i<files.GetCount();++i)
+ {
+ filenames.push_back(wx2std(files[i]));
+ GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
+ }
+
+ mProgressDialog =
+ new wxProgressDialog(_T("Adding file(s)"),
+ _T(""),
+ 1000,
+ this,
+ wxPD_ELAPSED_TIME |
+ // wxPD_ESTIMATED_TIME |
+ // wxPD_REMAINING_TIME |
+ wxPD_CAN_ABORT );
+
+ // TO DO : select the current tree handler
+ mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
+
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
+ delete mProgressDialog;
+ DisplayAddSummary();
+
+ }
+ mViewer->StartPlayer();
+ }
+ //=================================================
+
+ //=================================================
+ void WxGimmickView::OnAddDir(wxCommandEvent& event)
+ {
+ mViewer->StopPlayer();
+ std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
+ long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
+ wxDirDialog* FD =
+ new wxDirDialog( 0,
+ _T("Select directory"),
+ mCurrentDirectory,
+ style);
+
+ if (FD->ShowModal()==wxID_OK)
+ {
+
+
+ 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();
+ }