]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.cpp
Corrected ggo to work in win32.
[creaImageIO.git] / src2 / creaImageIOWxGimmickView.cpp
1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4 using namespace crea;
5 // Icons
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"
13
14 #include <wx/imaglist.h>
15
16 namespace creaImageIO
17 {
18   //======================================================================
19   // The ids of the different tools
20   enum
21     {
22       TOOL_ADDFILE_ID = 1,
23       TOOL_ADDDIR_ID = 2,
24       TOOL_REMOVE_ID = 3,
25       TOOL_ADDDATABASE_ID = 4,
26       TOOL_HELP_ID = 5
27     };
28   //======================================================================
29
30   //================================================================
31   // 
32   const int icon_number = 7;
33   // Icon ids
34   typedef enum
35     {
36       Icon_accept,
37       Icon_add,
38       Icon_folder_down,
39       Icon_page_down,
40       Icon_remove,
41       Icon_database_add,
42       Icon_help
43     }
44     icon_id;
45   //================================================================
46
47   //================================================================
48   /*
49   const icon_id Icon[5] = { Icon_Database,  
50                             Icon_Patient,
51                             Icon_Study,
52                             Icon_Series,
53                             Icon_Image };
54   */
55   //================================================================
56
57
58   //======================================================================
59   // CTor
60   WxGimmickView::WxGimmickView(Gimmick* gimmick,
61                                wxWindow *parent, 
62                                const wxWindowID id,
63                                const wxPoint& pos, const wxSize& size,
64                                int image_type,
65                                int number_of_threads)
66     : wxPanel(parent,id,pos,size),
67       GimmickView(gimmick)
68   {
69     GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
70                         <<std::endl);
71     // Create the list of icons (mIcon)
72     CreateIconList();
73
74     // Global sizer
75     wxBoxSizer  *sizer = new wxBoxSizer(wxVERTICAL);
76
77     // Create the tool bar
78     CreateToolBar(); 
79     sizer->Add( mToolBar ,0, wxGROW  ,0);
80
81     // Split part below toolbar into notebook for views and panel
82     // for preview, messages...
83     mSplitter = new wxSplitterWindow( this , -1);
84  
85    
86     // Notebook
87     mNotebook = new wxNotebook(mSplitter,
88                                -1,wxDefaultPosition, wxDefaultSize, 0);
89
90         //Gimmick
91         mGimmick=gimmick;
92
93     // Create the views
94     CreateTreeViews();
95
96     // Bottom panel 
97     mBottomPanel = new wxPanel(mSplitter,-1);
98
99     // Splitting
100     int hsize = size.GetHeight();
101     int bottom_minsize = 200;
102
103     mSplitter->SetMinimumPaneSize( bottom_minsize );
104     mSplitter->SplitHorizontally( mNotebook, mBottomPanel, 
105                                    hsize - bottom_minsize);
106   
107     sizer->Add( mSplitter,1,wxGROW  ,0);
108
109
110     SetSizer( sizer );     
111     SetAutoLayout(true);
112     Layout();
113
114   }
115   //======================================================================
116
117   //======================================================================
118   /// Destructor
119   WxGimmickView::~WxGimmickView()
120   {
121     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
122                         <<std::endl);
123   }
124   //======================================================================
125   
126   //======================================================================
127   /// Creates the tool bar
128   void WxGimmickView::CreateToolBar()
129   {
130     long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
131     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
132                              style);
133
134     mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID, 
135                                       _T("Add file(s)"),
136                                       mIcon->GetBitmap(Icon_page_down),
137                                       _T("Add some file(s) to database")
138                                       );
139     mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, 
140                                       _T("Add folder"),
141                                       mIcon->GetBitmap(Icon_folder_down),
142                                       _T("Add the content of a folder to database")
143                                       );
144     mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID, 
145                                       _T("Remove"),
146                                       mIcon->GetBitmap(Icon_remove),
147                                       _T("Remove selected items")
148                                       );
149     mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID, 
150                                       _T("Open database"),
151                                       mIcon->GetBitmap(Icon_database_add),
152                                       _T("Open a local or distant database")
153                                       );
154     mToolHelp = mToolBar->AddTool( TOOL_HELP_ID, 
155                                       _T("Help"),
156                                       mIcon->GetBitmap(Icon_help),
157                                       _T("Open help window")
158                                       );
159     //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
160
161     mToolBar->Realize();
162   }
163   //======================================================================
164
165  
166   //======================================================================
167   /// Create the tree view for TreeHandler provided
168   void WxGimmickView::CreateTreeView( TreeHandler* h)
169   {
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);
175
176     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
177     // ALREADY IN THE MAP
178     GetTreeViewMap()[name] = view;
179
180     // Add Notebook page
181     mNotebook->AddPage( view, crea::std2wx(name) );
182
183   }
184   //======================================================================
185
186
187
188   //=================================================
189   void WxGimmickView::CreateIconList()
190   {
191     // Size of the icons;
192     int size = 24;
193
194     wxIcon icons[20];
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);
203
204     //   unsigned int NbIcons = 8;
205     // Make an image list containing small icons
206     mIcon = new wxImageList(size,size,true);
207     
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++ )
211       {
212         if ( size == sizeOrig )
213           {
214             mIcon->Add(icons[i]);
215           }
216         else
217           {
218             mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
219           }
220       }
221   }
222
223
224   //=================================================
225   void WxGimmickView::OnAddFile(wxCommandEvent& event)
226   {
227    long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
228     std::string wc("*.*");
229     wxFileDialog* FD = new wxFileDialog( 0, 
230                                          _T("Select file"),
231                                          "",
232                                          _T(""),
233                                          std2wx(wc),
234                                          style,
235                                          wxDefaultPosition);
236     
237     if (FD->ShowModal()==wxID_OK)
238       {
239
240         wxArrayString files;
241         FD->GetPaths(files);
242         unsigned int i;
243         std::vector<std::string> filenames;
244         for (i=0;i<files.GetCount();++i)
245         {
246           filenames.push_back(wx2std(files[i]));
247           GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
248         }
249
250         
251     /*   
252         TreeItemData *data = 
253           (TreeItemData *)
254           mTreeListCtrl->GetItemData(mItemOfMenu);
255         DicomDatabase* db = data->GetDicomNode()->GetDicomDatabase();
256         DicomDatabase::UpdateSummary summary;
257         wxProgressDialog* progress = 
258           new wxProgressDialog(_T("Adding file(s)"),
259                                _T(""),
260                                1000,
261                                this,
262                                wxPD_ELAPSED_TIME |
263                                wxPD_ESTIMATED_TIME | 
264                                wxPD_REMAINING_TIME |
265                                wxPD_CAN_ABORT );
266        
267         db->AddFiles(filenames,progress,summary);
268         
269         progress->Pulse(_T("Updating view..."));
270         UpdateDicomDatabaseView(db);
271         delete progress;
272         DisplayUpdateSummary(summary,this);
273         */
274       }
275         
276   }
277   //=================================================
278
279   BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
280   EVT_TOOL(TOOL_ADDFILE_ID, WxGimmickView::OnAddFile)
281   END_EVENT_TABLE()
282
283 } // EO namespace creaImageIO
284
285