]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.cpp
aee84ab259825fb6e95ad153b274d6f5c39ca157
[creaImageIO.git] / src2 / creaImageIOWxGimmickView.cpp
1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4
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     // Create the views
91     CreateTreeViews();
92
93     // Bottom panel 
94     mBottomPanel = new wxPanel(mSplitter,-1);
95
96     // Splitting
97     int hsize = size.GetHeight();
98     int bottom_minsize = 200;
99
100     mSplitter->SetMinimumPaneSize( bottom_minsize );
101     mSplitter->SplitHorizontally( mNotebook, mBottomPanel, 
102                                    hsize - bottom_minsize);
103   
104     sizer->Add( mSplitter,1,wxGROW  ,0);
105
106
107     SetSizer( sizer );     
108     SetAutoLayout(true);
109     Layout();
110
111   }
112   //======================================================================
113
114   //======================================================================
115   /// Destructor
116   WxGimmickView::~WxGimmickView()
117   {
118     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
119                         <<std::endl);
120   }
121   //======================================================================
122   
123   //======================================================================
124   /// Creates the tool bar
125   void WxGimmickView::CreateToolBar()
126   {
127     long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
128     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
129                              style);
130
131     mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID, 
132                                       _T("Add file(s)"),
133                                       mIcon->GetBitmap(Icon_page_down),
134                                       _T("Add some file(s) to database")
135                                       );
136     mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, 
137                                       _T("Add folder"),
138                                       mIcon->GetBitmap(Icon_folder_down),
139                                       _T("Add the content of a folder to database")
140                                       );
141     mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID, 
142                                       _T("Remove"),
143                                       mIcon->GetBitmap(Icon_remove),
144                                       _T("Remove selected items")
145                                       );
146     mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID, 
147                                       _T("Open database"),
148                                       mIcon->GetBitmap(Icon_database_add),
149                                       _T("Open a local or distant database")
150                                       );
151     mToolHelp = mToolBar->AddTool( TOOL_HELP_ID, 
152                                       _T("Help"),
153                                       mIcon->GetBitmap(Icon_help),
154                                       _T("Open help window")
155                                       );
156     //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
157
158     mToolBar->Realize();
159   }
160   //======================================================================
161
162  
163   //======================================================================
164   /// Create the tree view for TreeHandler provided
165   void WxGimmickView::CreateTreeView( TreeHandler* h)
166   {
167     std::string name(h->GetTree().GetAttribute("Name"));
168     GimmickMessage(2,"Creating the tree view for '"<<
169                    name<<"'"<<std::endl);
170     // Create the WxTreeView
171     WxTreeView* view = new WxTreeView(h,mNotebook,-1);
172
173     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
174     // ALREADY IN THE MAP
175     GetTreeViewMap()[name] = view;
176
177     // Add Notebook page
178     mNotebook->AddPage( view, crea::std2wx(name) );
179
180   }
181   //======================================================================
182
183
184
185   //=================================================
186   void WxGimmickView::CreateIconList()
187   {
188     // Size of the icons;
189     int size = 24;
190
191     wxIcon icons[20];
192     // should correspond to Icon_xxx enum
193     icons[Icon_accept] = wxIcon(accept_xpm);
194     icons[Icon_add] = wxIcon(add_xpm);
195     icons[Icon_folder_down] = wxIcon(folder_down_xpm);
196     icons[Icon_page_down] = wxIcon(page_down_xpm);
197     icons[Icon_remove] = wxIcon(remove_xpm);
198     icons[Icon_database_add] = wxIcon(database_add_xpm);
199     icons[Icon_help] = wxIcon(help_xpm);
200
201     //   unsigned int NbIcons = 8;
202     // Make an image list containing small icons
203     mIcon = new wxImageList(size,size,true);
204     
205     // Make all icons the same size = size of the first one
206     int sizeOrig = icons[0].GetWidth();
207     for ( size_t i = 0; i < icon_number; i++ )
208       {
209         if ( size == sizeOrig )
210           {
211             mIcon->Add(icons[i]);
212           }
213         else
214           {
215             mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
216           }
217       }
218   }
219   //=================================================
220
221
222
223 } // EO namespace creaImageIO
224
225