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,
65 int number_of_threads)
66 : wxPanel(parent,id,pos,size),
70 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
72 // Sets the current directory to the home dir
73 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
75 // Connect the AddProgress callback
76 gimmick->ConnectAddProgressObserver
77 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
79 // Create the list of icons (mIcon)
83 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
85 // Create the tool bar
87 sizer->Add( mToolBar ,0, wxGROW ,0);
89 // Split part below toolbar into notebook for views and panel
90 // for preview, messages...
91 mSplitter = new wxSplitterWindow( this , -1);
95 mNotebook = new wxNotebook(mSplitter,
96 -1,wxDefaultPosition, wxDefaultSize, 0);
105 mBottomPanel = new wxPanel(mSplitter,-1);
108 int hsize = size.GetHeight();
109 int bottom_minsize = 200;
111 mSplitter->SetMinimumPaneSize( bottom_minsize );
112 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
113 hsize - bottom_minsize);
115 sizer->Add( mSplitter,1,wxGROW ,0);
123 //======================================================================
125 //======================================================================
127 WxGimmickView::~WxGimmickView()
129 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
132 //======================================================================
134 //======================================================================
135 /// Creates the tool bar
136 void WxGimmickView::CreateToolBar()
138 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
139 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
142 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
144 mIcon->GetBitmap(Icon_page_down),
145 _T("Add one or more file to database")
147 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
149 mIcon->GetBitmap(Icon_folder_down),
150 _T("Add the content of a folder to database")
152 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
154 mIcon->GetBitmap(Icon_remove),
155 _T("Remove selected items")
157 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
159 mIcon->GetBitmap(Icon_database_add),
160 _T("Open a local or distant database")
162 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
164 mIcon->GetBitmap(Icon_help),
165 _T("Open help window")
167 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
171 //======================================================================
174 //======================================================================
175 /// Create the tree view for TreeHandler provided
176 void WxGimmickView::CreateTreeView( TreeHandler* h)
178 std::string name(h->GetTree().GetAttribute("Name"));
179 GimmickMessage(2,"Creating the tree view for '"<<
180 name<<"'"<<std::endl);
181 // Create the WxTreeView
182 WxTreeView* view = new WxTreeView(h,mNotebook,-1);
184 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
185 // ALREADY IN THE MAP
186 GetTreeViewMap()[name] = view;
189 mNotebook->AddPage( view, crea::std2wx(name) );
192 //======================================================================
196 //=================================================
197 void WxGimmickView::CreateIconList()
199 // Size of the icons;
203 // should correspond to Icon_xxx enum
204 icons[Icon_accept] = wxIcon(accept_xpm);
205 icons[Icon_add] = wxIcon(add_xpm);
206 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
207 icons[Icon_page_down] = wxIcon(page_down_xpm);
208 icons[Icon_remove] = wxIcon(remove_xpm);
209 icons[Icon_database_add] = wxIcon(database_add_xpm);
210 icons[Icon_help] = wxIcon(help_xpm);
212 // unsigned int NbIcons = 8;
213 // Make an image list containing small icons
214 mIcon = new wxImageList(size,size,true);
216 // Make all icons the same size = size of the first one
217 int sizeOrig = icons[0].GetWidth();
218 for ( size_t i = 0; i < icon_number; i++ )
220 if ( size == sizeOrig )
222 mIcon->Add(icons[i]);
226 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
230 //=================================================
233 //=================================================
234 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
236 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
237 std::string wc("*.*");
238 wxFileDialog* FD = new wxFileDialog( 0,
246 if (FD->ShowModal()==wxID_OK)
253 std::vector<std::string> filenames;
254 for (i=0;i<files.GetCount();++i)
256 filenames.push_back(wx2std(files[i]));
257 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
261 new wxProgressDialog(_T("Adding file(s)"),
266 // wxPD_ESTIMATED_TIME |
267 // wxPD_REMAINING_TIME |
270 // TO DO : select the current tree handler
271 mGimmick->AddFiles("Local database",filenames);
273 mProgressDialog->Pulse(_T("Updating view..."));
275 UpdateTreeViewLevel("Local database",1);
276 delete mProgressDialog;
281 //=================================================
283 //=================================================
284 void WxGimmickView::OnAddDir(wxCommandEvent& event)
286 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
289 _T("Select directory"),
293 if (FD->ShowModal()==wxID_OK)
296 bool recurse = false;
297 if (wxMessageBox(_T("Recurse into sub-directories ?"),
298 _T("Scan directory"),
299 wxYES_NO,this ) == wxYES)
305 wxString title(_T("Adding directory"));
307 title = _T("Adding directory (recursive)");
309 new wxProgressDialog(_T("Adding directory"),
314 // wxPD_ESTIMATED_TIME |
315 // wxPD_REMAINING_TIME |
317 std::string dirname = wx2std (FD->GetPath()) ;
318 mCurrentDirectory = FD->GetPath();
320 // TO DO : select the current tree handler
321 mGimmick->AddDir("Local database",dirname,recurse);
323 mProgressDialog->Pulse(_T("Updating view..."));
325 UpdateTreeViewLevel("Local database",1);
326 delete mProgressDialog;
330 //=================================================
332 //=================================================
333 void WxGimmickView::OnRemove(wxCommandEvent& event)
335 //TODO Select current tree handler
336 GetTreeViewMap()["Local database"]->RemoveSelected(1);
338 //=================================================
340 //=================================================
341 /// AddProgress Gimmick callback
342 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
346 sprintf(mess,"%i dirs - %i files - %i handled - %i added",
347 p.GetNumberScannedDirs(),
348 p.GetNumberScannedFiles(),
349 p.GetNumberHandledFiles(),
350 p.GetNumberAddedFiles());
351 // std::cout << "OnAddProgress "<<mess<<std::endl;
352 wxString s(wxString::From8BitData(mess));
353 // std::cout << "Pulse"<<std::endl;
354 if (!mProgressDialog->Pulse(s))
358 // std::cout << "OnAddProgress ok"<<std::endl;
360 //=================================================
362 //=================================================
363 void WxGimmickView::DisplayAddSummary()
365 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
366 std::stringstream mess;
367 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
368 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
369 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
370 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
373 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",
375 (int)( summary.parse_time*100./summary.total_time),
376 summary.file_scan_time,
377 (int)(summary.file_scan_time*100./summary.total_time),
378 summary.update_structs_time,
379 (int)(summary.update_structs_time*100./summary.total_time),
380 summary.update_database_time,
381 (int)(summary.update_database_time*100./summary.total_time),
382 summary.total_time );
386 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
388 //=================================================
390 //=================================================
391 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
392 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
393 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
394 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
396 //=================================================
398 } // EO namespace creaImageIO