]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOWxGimmickView.cpp
1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4
5 // Icons
6 #include "../src/icons/database.xpm"
7 #include "../src/icons/folder.xpm"
8 #include "../src/icons/dicomdir.xpm"
9 #include "../src/icons/patient.xpm"
10 #include "../src/icons/study.xpm"
11 #include "../src/icons/series.xpm"
12 #include "../src/icons/image.xpm"
13 #include "../src/icons/root.xpm"
14
15 #include <wx/imaglist.h>
16
17 namespace creaImageIO
18 {
19   //======================================================================
20   // The ids of the different tools
21   enum
22     {
23       TOOL_ADDFILE_ID = 1
24     };
25   //======================================================================
26
27   //================================================================
28   // 
29   const int icon_number = 8;
30   // Icon ids
31   typedef enum
32     {
33       Icon_Root,
34       Icon_Database,
35       Icon_Folder,
36       Icon_DicomDir,
37       Icon_Patient,
38       Icon_Study,
39       Icon_Series,
40       Icon_Image
41     }
42     icon_id;
43   //================================================================
44
45   //================================================================
46   /*
47   const icon_id Icon[5] = { Icon_Database,  
48                             Icon_Patient,
49                             Icon_Study,
50                             Icon_Series,
51                             Icon_Image };
52   */
53   //================================================================
54
55
56   //======================================================================
57   // CTor
58   WxGimmickView::WxGimmickView(Gimmick* gimmick,
59                                wxWindow *parent, 
60                                const wxWindowID id,
61                                const wxPoint& pos, const wxSize& size,
62                                int image_type,
63                                int number_of_threads)
64     : wxPanel(parent,id,pos,size),
65       GimmickView(gimmick)
66   {
67     GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
68                         <<std::endl);
69     // Create the list of icons (mIcon)
70     CreateIconList();
71
72     // Global sizer
73     wxBoxSizer  *sizer = new wxBoxSizer(wxVERTICAL);
74
75     // Create the tool bar
76     CreateToolBar(); 
77     sizer->Add( mToolBar ,0, wxGROW  ,0);
78
79     // Split part below toolbar into notebook for views and panel
80     // for preview, messages...
81     mSplitter = new wxSplitterWindow( this , -1);
82  
83    
84     // Notebook
85     mNotebook = new wxNotebook(mSplitter,
86                                -1,wxDefaultPosition, wxDefaultSize, 0);
87
88     // Create the views
89     CreateTreeViews();
90
91     // Bottom panel 
92     mBottomPanel = new wxPanel(mSplitter,-1);
93
94     // Splitting
95     int hsize = size.GetHeight();
96     int bottom_minsize = 200;
97
98     mSplitter->SetMinimumPaneSize( viewsminsize );
99     mSplitter->SplitHorizontally( mNotebook, mBottomPanel, 
100                                    hsize - bottom_minsize);
101   
102     sizer->Add( mSplitter,1,wxGROW  ,0);
103
104
105     SetSizer( sizer );     
106     SetAutoLayout(true);
107     Layout();
108
109   }
110   //======================================================================
111
112   //======================================================================
113   /// Destructor
114   WxGimmickView::~WxGimmickView()
115   {
116     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
117                         <<std::endl);
118   }
119   //======================================================================
120   
121   //======================================================================
122   /// Creates the tool bar
123   void WxGimmickView::CreateToolBar()
124   {
125     long style = wxTB_HORIZONTAL | wxNO_BORDER;
126     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
127                              style);
128
129     mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID, 
130                                       _T("Add file"),
131                                       mIcon->GetBitmap(Icon_Database),
132                                       _T("Add file")
133                                       );
134     //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
135
136     mToolBar->Realize();
137   }
138   //======================================================================
139
140  
141   //======================================================================
142   /// Create the tree view for TreeHandler provided
143   void WxGimmickView::CreateTreeView( TreeHandler* h)
144   {
145     std::string name(h->GetTree().GetAttribute("Name"));
146     GimmickMessage(2,"Creating the tree view for '"<<
147                    name<<"'"<<std::endl);
148     // Create the WxTreeView
149     WxTreeView* view = new WxTreeView(h,mNotebook,-1);
150
151     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
152     // ALREADY IN THE MAP
153     GetTreeViewMap()[name] = view;
154
155     // Add Notebook page
156     mNotebook->AddPage( view, crea::std2wx(name) );
157
158   }
159   //======================================================================
160
161
162
163   //=================================================
164   void WxGimmickView::CreateIconList()
165   {
166     // Size of the icons;
167     int size = 32;
168
169     wxIcon icons[20];
170     // should correspond to Icon_xxx enum
171     icons[Icon_Patient] = wxIcon(patient_xpm);
172     icons[Icon_Study] = wxIcon(study_xpm);
173     icons[Icon_Series] = wxIcon(series_xpm);
174     icons[Icon_Image] = wxIcon(image_xpm);
175     icons[Icon_Database] = wxIcon(database_xpm);
176     icons[Icon_Folder] = wxIcon(folder_xpm);
177     icons[Icon_DicomDir] = wxIcon(dicomdir_xpm);
178     icons[Icon_Root] = wxIcon(root_xpm);
179
180     unsigned int NbIcons = 8;
181     // Make an image list containing small icons
182     mIcon = new wxImageList(size,size,true);
183     
184     // Make all icons the same size = size of the first one
185     int sizeOrig = icons[0].GetWidth();
186     for ( size_t i = 0; i < NbIcons; i++ )
187       {
188         if ( size == sizeOrig )
189           {
190             mIcon->Add(icons[i]);
191           }
192         else
193           {
194             mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
195           }
196       }
197   }
198   //=================================================
199
200
201
202 } // EO namespace creaImageIO
203
204