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 mTreeListCtrl->GetItemData(mItemOfMenu);
282 DicomDatabase* db = data->GetDicomNode()->GetDicomDatabase();
283 DicomDatabase::UpdateSummary summary;
284 wxProgressDialog* progress =
285 new wxProgressDialog(_T("Adding file(s)"),
290 wxPD_ESTIMATED_TIME |
291 wxPD_REMAINING_TIME |
294 db->AddFiles(filenames,progress,summary);
296 progress->Pulse(_T("Updating view..."));
297 UpdateDicomDatabaseView(db);
299 DisplayUpdateSummary(summary,this);
304 //=================================================
306 //=================================================
307 void WxGimmickView::OnAddDir(wxCommandEvent& event)
309 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
312 _T("Select directory"),
316 if (FD->ShowModal()==wxID_OK)
319 bool recurse = false;
320 if (wxMessageBox(_T("Recurse into sub-directories ?"),
321 _T("Scan directory"),
322 wxYES_NO,this ) == wxYES)
328 wxString title(_T("Adding directory"));
330 title = _T("Adding directory (recursive)");
332 new wxProgressDialog(_T("Adding directory"),
337 wxPD_ESTIMATED_TIME |
338 wxPD_REMAINING_TIME |
340 std::string dirname = wx2std (FD->GetPath()) ;
341 mCurrentDirectory = FD->GetPath();
343 // TO DO : select the current tree handler
344 mGimmick->AddDir("Local database",dirname,recurse);
346 mProgressDialog->Pulse(_T("Updating view..."));
348 UpdateTreeViewLevel("Local database",1);
349 delete mProgressDialog;
353 //=================================================
355 //=================================================
356 /// AddProgress Gimmick callback
357 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
361 sprintf(mess,"%i dirs - %i files - %i handled - %i added",
362 p.GetNumberScannedDirs(),
363 p.GetNumberScannedFiles(),
364 p.GetNumberHandledFiles(),
365 p.GetNumberAddedFiles());
366 std::cout << "OnAddProgress "<<mess<<std::endl;
367 wxString s(wxString::From8BitData(mess));
368 // std::cout << "Pulse"<<std::endl;
369 if (!mProgressDialog->Pulse(s))
373 // std::cout << "OnAddProgress ok"<<std::endl;
375 //=================================================
377 //=================================================
378 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
379 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
380 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
382 //=================================================
384 } // EO namespace creaImageIO