1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
6 #include "icons/accept.xpm"
7 #include "icons/add.xpm"
8 #include "icons/folder-down.xpm"
9 #include "icons/page-down.xpm"
10 #include "icons/remove.xpm"
11 #include "icons/database-add.xpm"
12 #include "icons/help.xpm"
14 #include <wx/imaglist.h>
18 //======================================================================
19 // The ids of the different tools
25 TOOL_ADDDATABASE_ID = 4,
28 //======================================================================
30 //================================================================
32 const int icon_number = 7;
45 //================================================================
47 //================================================================
49 const icon_id Icon[5] = { Icon_Database,
55 //================================================================
58 //======================================================================
60 WxGimmickView::WxGimmickView(Gimmick* gimmick,
63 const wxPoint& pos, const wxSize& size,
66 int number_of_threads)
67 : wxPanel(parent,id,pos,size),
71 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
73 // Sets the current directory to the home dir
74 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
76 // Connect the AddProgress callback
77 gimmick->ConnectAddProgressObserver
78 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
80 // Create the list of icons (mIcon)
84 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
86 // Create the tool bar
88 sizer->Add( mToolBar ,0, wxGROW ,0);
90 // Split part below toolbar into notebook for views and panel
91 // for preview, messages...
92 mSplitter = new wxSplitterWindow( this , -1);
96 mNotebook = new wxNotebook(mSplitter,
97 -1,wxDefaultPosition, wxDefaultSize, 0);
102 mSelectionMaxDimension=max_dim;
103 mSelectionMinDimension=min_dim;
109 mBottomPanel = new wxPanel(mSplitter,-1);
110 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Status: Welcome to Gimmick!"));
113 int hsize = size.GetHeight();
114 int bottom_minsize = 20;
116 mSplitter->SetMinimumPaneSize( bottom_minsize );
117 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
118 hsize - bottom_minsize);
120 sizer->Add( mSplitter,1,wxGROW ,0);
128 //======================================================================
130 //======================================================================
132 WxGimmickView::~WxGimmickView()
134 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
137 //======================================================================
139 //======================================================================
140 /// Creates the tool bar
141 void WxGimmickView::CreateToolBar()
143 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
144 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
147 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
149 mIcon->GetBitmap(Icon_page_down),
150 _T("Add one or more file to database")
152 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
154 mIcon->GetBitmap(Icon_folder_down),
155 _T("Add the content of a folder to database")
157 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
159 mIcon->GetBitmap(Icon_remove),
160 _T("Remove selected items")
162 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
164 mIcon->GetBitmap(Icon_database_add),
165 _T("Open a local or distant database")
167 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
169 mIcon->GetBitmap(Icon_help),
170 _T("Open help window")
172 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
176 //======================================================================
179 //======================================================================
180 /// Create the tree view for TreeHandler provided
181 void WxGimmickView::CreateTreeView( TreeHandler* h)
183 std::string name(h->GetTree().GetAttribute("Name"));
184 GimmickMessage(2,"Creating the tree view for '"<<
185 name<<"'"<<std::endl);
186 // Create the WxTreeView
187 WxTreeView* view = new WxTreeView(h,mNotebook,-1);
189 view->SetMaxDimension(mSelectionMaxDimension);
190 view->SetMinDimension(mSelectionMinDimension);
192 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
193 // ALREADY IN THE MAP
194 GetTreeViewMap()[name] = view;
197 mNotebook->AddPage( view, crea::std2wx(name) );
200 //======================================================================
201 /// Returns the selected Image so that it complies with the given parameter(<4D)
202 vtkImageData* WxGimmickView::GetSelectedImage(int dim)
204 return GetTreeViewMap()["Local database"]->GetSelectedImage(dim);
207 //======================================================================
208 /// Returns the selected Images so that they comply with the given parameter(4D)
209 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
211 GetTreeViewMap()["Local database"]->GetSelectedImages(s,dim);
214 //=================================================
215 void WxGimmickView::CreateIconList()
217 // Size of the icons;
221 // should correspond to Icon_xxx enum
222 icons[Icon_accept] = wxIcon(accept_xpm);
223 icons[Icon_add] = wxIcon(add_xpm);
224 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
225 icons[Icon_page_down] = wxIcon(page_down_xpm);
226 icons[Icon_remove] = wxIcon(remove_xpm);
227 icons[Icon_database_add] = wxIcon(database_add_xpm);
228 icons[Icon_help] = wxIcon(help_xpm);
230 // unsigned int NbIcons = 8;
231 // Make an image list containing small icons
232 mIcon = new wxImageList(size,size,true);
234 // Make all icons the same size = size of the first one
235 int sizeOrig = icons[0].GetWidth();
236 for ( size_t i = 0; i < icon_number; i++ )
238 if ( size == sizeOrig )
240 mIcon->Add(icons[i]);
244 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
248 //=================================================
251 //=================================================
252 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
254 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
255 std::string wc("*.*");
256 wxFileDialog* FD = new wxFileDialog( 0,
264 if (FD->ShowModal()==wxID_OK)
271 std::vector<std::string> filenames;
272 for (i=0;i<files.GetCount();++i)
274 filenames.push_back(wx2std(files[i]));
275 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
279 new wxProgressDialog(_T("Adding file(s)"),
284 // wxPD_ESTIMATED_TIME |
285 // wxPD_REMAINING_TIME |
288 // TO DO : select the current tree handler
289 mGimmick->AddFiles("Local database",filenames);
291 mProgressDialog->Pulse(_T("Updating view..."));
293 UpdateTreeViewLevel("Local database",1);
294 delete mProgressDialog;
299 //=================================================
301 //=================================================
302 void WxGimmickView::OnAddDir(wxCommandEvent& event)
304 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
307 _T("Select directory"),
311 if (FD->ShowModal()==wxID_OK)
314 bool recurse = false;
315 if (wxMessageBox(_T("Recurse into sub-directories ?"),
316 _T("Scan directory"),
317 wxYES_NO,this ) == wxYES)
323 wxString title(_T("Adding directory"));
325 title = _T("Adding directory (recursive)");
327 new wxProgressDialog(_T("Adding directory"),
332 // wxPD_ESTIMATED_TIME |
333 // wxPD_REMAINING_TIME |
335 std::string dirname = wx2std (FD->GetPath()) ;
336 mCurrentDirectory = FD->GetPath();
338 // TO DO : select the current tree handler
339 mGimmick->AddDir("Local database",dirname,recurse);
341 mProgressDialog->Pulse(_T("Updating view..."));
343 UpdateTreeViewLevel("Local database",1);
344 delete mProgressDialog;
348 //=================================================
350 //=================================================
351 void WxGimmickView::SetMessage(const wxString& mess)
355 mText->SetLabel(_T("Status: ")+mess);
357 //=================================================
359 //=================================================
360 void WxGimmickView::OnRemove(wxCommandEvent& event)
362 //TODO Select current tree handler
364 GetTreeViewMap()["Local database"]->RemoveSelected(1);
366 //=================================================
368 //=================================================
369 /// AddProgress Gimmick callback
370 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
374 sprintf(mess,"%i dirs - %i files - %i handled - %i added",
375 p.GetNumberScannedDirs(),
376 p.GetNumberScannedFiles(),
377 p.GetNumberHandledFiles(),
378 p.GetNumberAddedFiles());
379 // std::cout << "OnAddProgress "<<mess<<std::endl;
380 wxString s(wxString::From8BitData(mess));
381 // std::cout << "Pulse"<<std::endl;
382 if (!mProgressDialog->Pulse(s))
386 // std::cout << "OnAddProgress ok"<<std::endl;
388 //=================================================
390 //=================================================
391 void WxGimmickView::DisplayAddSummary()
393 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
394 std::stringstream mess;
395 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
396 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
397 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
398 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
401 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",
403 (int)( summary.parse_time*100./summary.total_time),
404 summary.file_scan_time,
405 (int)(summary.file_scan_time*100./summary.total_time),
406 summary.update_structs_time,
407 (int)(summary.update_structs_time*100./summary.total_time),
408 summary.update_database_time,
409 (int)(summary.update_database_time*100./summary.total_time),
410 summary.total_time );
414 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
416 //=================================================
418 //=================================================
419 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
420 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
421 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
422 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
424 //=================================================
426 } // EO namespace creaImageIO