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),
69 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
71 // Create the list of icons (mIcon)
75 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
77 // Create the tool bar
79 sizer->Add( mToolBar ,0, wxGROW ,0);
81 // Split part below toolbar into notebook for views and panel
82 // for preview, messages...
83 mSplitter = new wxSplitterWindow( this , -1);
87 mNotebook = new wxNotebook(mSplitter,
88 -1,wxDefaultPosition, wxDefaultSize, 0);
97 mBottomPanel = new wxPanel(mSplitter,-1);
100 int hsize = size.GetHeight();
101 int bottom_minsize = 200;
103 mSplitter->SetMinimumPaneSize( bottom_minsize );
104 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
105 hsize - bottom_minsize);
107 sizer->Add( mSplitter,1,wxGROW ,0);
115 //======================================================================
117 //======================================================================
119 WxGimmickView::~WxGimmickView()
121 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
124 //======================================================================
126 //======================================================================
127 /// Creates the tool bar
128 void WxGimmickView::CreateToolBar()
130 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
131 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
134 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID,
136 mIcon->GetBitmap(Icon_page_down),
137 _T("Add some file(s) to database")
139 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
141 mIcon->GetBitmap(Icon_folder_down),
142 _T("Add the content of a folder to database")
144 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
146 mIcon->GetBitmap(Icon_remove),
147 _T("Remove selected items")
149 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
151 mIcon->GetBitmap(Icon_database_add),
152 _T("Open a local or distant database")
154 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
156 mIcon->GetBitmap(Icon_help),
157 _T("Open help window")
159 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
163 //======================================================================
166 //======================================================================
167 /// Create the tree view for TreeHandler provided
168 void WxGimmickView::CreateTreeView( TreeHandler* h)
170 std::string name(h->GetTree().GetAttribute("Name"));
171 GimmickMessage(2,"Creating the tree view for '"<<
172 name<<"'"<<std::endl);
173 // Create the WxTreeView
174 WxTreeView* view = new WxTreeView(h,mNotebook,-1);
176 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
177 // ALREADY IN THE MAP
178 GetTreeViewMap()[name] = view;
181 mNotebook->AddPage( view, crea::std2wx(name) );
184 //======================================================================
188 //=================================================
189 void WxGimmickView::CreateIconList()
191 // Size of the icons;
195 // should correspond to Icon_xxx enum
196 icons[Icon_accept] = wxIcon(accept_xpm);
197 icons[Icon_add] = wxIcon(add_xpm);
198 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
199 icons[Icon_page_down] = wxIcon(page_down_xpm);
200 icons[Icon_remove] = wxIcon(remove_xpm);
201 icons[Icon_database_add] = wxIcon(database_add_xpm);
202 icons[Icon_help] = wxIcon(help_xpm);
204 // unsigned int NbIcons = 8;
205 // Make an image list containing small icons
206 mIcon = new wxImageList(size,size,true);
208 // Make all icons the same size = size of the first one
209 int sizeOrig = icons[0].GetWidth();
210 for ( size_t i = 0; i < icon_number; i++ )
212 if ( size == sizeOrig )
214 mIcon->Add(icons[i]);
218 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
224 //=================================================
225 void WxGimmickView::OnAddFile(wxCommandEvent& event)
227 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
228 std::string wc("*.*");
229 wxFileDialog* FD = new wxFileDialog( 0,
237 if (FD->ShowModal()==wxID_OK)
243 std::vector<std::string> filenames;
244 for (i=0;i<files.GetCount();++i)
246 filenames.push_back(wx2std(files[i]));
247 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
254 mTreeListCtrl->GetItemData(mItemOfMenu);
255 DicomDatabase* db = data->GetDicomNode()->GetDicomDatabase();
256 DicomDatabase::UpdateSummary summary;
257 wxProgressDialog* progress =
258 new wxProgressDialog(_T("Adding file(s)"),
263 wxPD_ESTIMATED_TIME |
264 wxPD_REMAINING_TIME |
267 db->AddFiles(filenames,progress,summary);
269 progress->Pulse(_T("Updating view..."));
270 UpdateDicomDatabaseView(db);
272 DisplayUpdateSummary(summary,this);
277 //=================================================
279 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
280 EVT_TOOL(TOOL_ADDFILE_ID, WxGimmickView::OnAddFile)
283 } // EO namespace creaImageIO