]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickFieldsView.cpp
start!
[creaImageIO.git] / src / creaImageIOWxGimmickFieldsView.cpp
1 #include <creaImageIOWxGimmickFieldsView.h>
2
3 #include <gdcm.h> 
4
5 namespace creaImageIO
6 {
7
8 #define TreeListCtrlId -1
9
10
11
12  //================================================================
13   class WxGimmickFieldsViewItemData : public wxTreeItemData
14   {
15   public:
16     WxGimmickFieldsViewItemData(const std::string& key) : 
17       mKey(key)
18     { }
19     const std::string& GetKey() const { return mKey; }
20
21   private:
22     std::string mKey;
23   };
24   //================================================================
25
26  //================================================================
27   WxGimmickFieldsView::WxGimmickFieldsView(wxWindow *parent, 
28                                                    wxWindowID id,
29                                                    const wxPoint& pos,
30                                                    const wxSize& size,
31                                                    long style)
32     : wxPanel(parent,id,pos,size)
33    {
34     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
35
36     style = //wxTR_DEFAULT_STYLE
37       wxTR_HIDE_ROOT 
38       | wxTR_HAS_BUTTONS 
39       //      | wxTR_NO_LINES
40       | wxTR_FULL_ROW_HIGHLIGHT
41       //| wxTR_SINGLE 
42       //      | wxTR_LINES_AT_ROOT 
43       ;
44
45    /*
46     style = style 
47       //      | wxTR_EDIT_LABELS        //Use this style if you wish the user to be able to edit labels in the tree list control.
48       //wxTR_NO_BUTTONS         For convenience to document that no buttons are to be drawn.
49       | wxTR_HAS_BUTTONS        //Use this style to show + and - buttons to the left of parent items.
50       | wxTR_TWIST_BUTTONS      //Use this style to show Mac-style twister buttons to the left of parent items. If both wxTR_HAS_BUTTONS and wxTR_TWIST_BUTTONS are given, twister buttons are generated.
51       //wxTR_NO_LINES   Use this style to hide vertical level connectors.
52       | wxTR_FULL_ROW_HIGHLIGHT         //Use this style to have the background colour and the selection highlight extend over the entire horizontal row of the tree list control window. (This flag is ignored under Windows unless you specify wxTR_NO_LINES as well.)
53       | wxTR_LINES_AT_ROOT      //Use this style to show lines between root nodes. Only applicable if wxTR_HIDE_ROOT is set and wxTR_NO_LINES is not set.
54       | wxTR_HIDE_ROOT  //Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes.
55       //   wxTR_ROW_LINES //    Use this style to draw a contrasting border between displayed rows.
56       //      xTR_HAS_VARIABLE_ROW_HEIGHT//     Use this style to cause row heights to be just big enough to fit the content. If not set, all rows use the largest row height. The default is that this flag is unset.
57       &  !wxTR_SINGLE //        For convenience to document that only one item may be selected at a time. Selecting another item causes the current selection, if any, to be deselected. This is the default.
58       & !wxTR_MULTIPLE //       Use this style to allow a range of items to be selected. If a second range is selected, the current range, if any, is deselected.
59       &   ! wxTR_EXTENDED //    Use this style to allow disjoint items to be selected. (Only partially implemented; may not work in all cases.)
60       //wxTR_DEFAULT_STYLE      The set of flags that are closest to the defaults for the native control for a particular toolkit.
61       //| wxTR_VIRTUAL //The application provides items text on demand.
62       */
63       /*
64      | wxTR_HIDE_ROOT
65       | wxTR_HAS_BUTTONS
66       | wxTR_TWIST_BUTTONS
67       //      | wxTR_NO_LINES
68       | wxTR_LINES_AT_ROOT
69       | wxTR_EDIT_LABELS
70       //      | wxTR_ROW_LINES
71       | wxTR_FULL_ROW_HIGHLIGHT  
72       | wxTR_MULTIPLE
73       | wxTR_EXTENDED
74       */
75       ;
76     mTreeListCtrl = new wxTreeListCtrl(this,
77                                        TreeListCtrlId,
78                                        wxDefaultPosition,
79                                        wxDefaultSize,style);
80
81     mTreeListCtrl->AddColumn (_T("Field"),200,wxALIGN_LEFT,-1,true,false);
82     mTreeListCtrl->AddColumn (_T("Value"),400,wxALIGN_LEFT,-1,true,false);
83     mTreeListCtrl->AddColumn (_T("Tag"),100,wxALIGN_LEFT,-1,true,false);
84     mTreeListCtrl->AddColumn (_T("VR"),40,wxALIGN_LEFT,-1,true,false);
85
86     mTreeListCtrl->SetMainColumn (0);
87     
88     mRootId = mTreeListCtrl->AddRoot( _T(""));
89     
90     mItemId[DicomNode::Database] = mTreeListCtrl->AppendItem( mRootId,
91                                                               _T("Collection"));
92     mItemId[DicomNode::Patient] = mTreeListCtrl->AppendItem( mRootId,
93                                                              _T("Patient"));
94     mItemId[DicomNode::Study] = mTreeListCtrl->AppendItem( mRootId,
95                                                            _T("Study"));
96     mItemId[DicomNode::Series] = mTreeListCtrl->AppendItem( mRootId,
97                                                             _T("Series"));
98     mItemId[DicomNode::Image] = mTreeListCtrl->AppendItem(mRootId,
99                                                           _T("Image"));
100     
101     
102     //    CreateImageList();
103     //    CreateButtonsImageList();
104    //    mTreeListCtrl->SetBackgroundColour(*wxWHITE);
105     //    mTreeListCtrl->SetSpacingY(0);
106  
107     sizer->Add(mTreeListCtrl,1,wxGROW);
108     
109     SetSizer(sizer);
110     SetAutoLayout(true);
111     Layout();
112
113   }
114  //================================================================
115     
116  //================================================================
117   WxGimmickFieldsView::~WxGimmickFieldsView()
118   {
119   }
120  //================================================================
121
122
123  //================================================================
124   void WxGimmickFieldsView::UpdateFields(DicomDatabase* db)
125   {
126
127     for (int i=DicomNode::Database; 
128          i<DicomNode::Image+1;i++)
129       {
130         DicomNodeTypeDescription::FieldDescriptionMapType::iterator j;
131         for (j  = db->GetDicomNodeTypeDescription(i).GetFieldDescriptionMap().begin();
132              j != db->GetDicomNodeTypeDescription(i).GetFieldDescriptionMap().end();
133              j++)
134           {
135             
136             Field::Description& desc = j->second;
137             // Skip DB fields
138             if (desc.GetFlags() & 1) continue;
139             
140             WxGimmickFieldsViewItemData* data = 
141               new WxGimmickFieldsViewItemData(desc.GetKey());
142             wxTreeItemId item = mTreeListCtrl->AppendItem
143               ( mItemId[i], crea::std2wx( desc.GetName() ), 0, 0, data );
144             //      mTreeListCtrl->SetItemFont(item,0,*wxITALIC_FONT);
145     
146             
147             if ( ( desc.GetGroup()!=0 ) || ( desc.GetElement()!=0) ) 
148               {
149                 std::string groupelem = 
150                   GDCM_NAME_SPACE::Util::Format("%04x | %04x" , 
151                                                 desc.GetGroup() , 
152                                                 desc.GetElement());
153                 mTreeListCtrl->SetItemText(item,2,crea::std2wx(groupelem));
154               }
155             
156           }  
157       }  
158     /*
159       mTreeListCtrl->SetItemTextColour(mTreeRootId,
160                                      mSettings.RootColour());
161                                      mTreeListCtrl->SetItemBackgroundColour(mTreeRootId,
162                                      mSettings.RootBgColour());
163     */
164     mTreeListCtrl->ExpandAll(mRootId);
165     //    mTreeListCtrl->CollapseAll();
166   }
167   //================================================================
168
169   //================================================================
170    void WxGimmickFieldsView::UpdateValues(DicomNode* node)
171    {
172      //     std::cout << "WxGimmickFieldsView::UpdateValues "<<node->GetLabel()<<std::endl;
173      // Fill the values for each level until top of the node hierarchy
174      DicomNode* n = node;
175      do
176        {
177          wxTreeItemIdValue cookie;
178          wxTreeItemId i;
179          for (i = mTreeListCtrl->GetFirstChild(mItemId[n->GetType()],cookie);
180               i.IsOk();
181               i = mTreeListCtrl->GetNextChild(mItemId[n->GetType()],cookie))
182            {
183              const std::string& key = 
184                ((WxGimmickFieldsViewItemData *)(mTreeListCtrl->GetItemData(i)))->GetKey();;
185              wxString v(crea::std2wx(n->GetFieldValueMap()[key]));
186              mTreeListCtrl->SetItemText(i,1,v);
187            }
188          n = n->GetParent();
189        }
190      while (n != 0);
191      
192      // Reset N/A items (below the node level)
193      for (int t=node->GetType()+1;
194           t<DicomNode::Image+1;t++)
195        {
196          wxTreeItemIdValue cookie;
197          wxTreeItemId i;
198          for (i = mTreeListCtrl->GetFirstChild(mItemId[t],cookie);
199               i.IsOk();
200               i = mTreeListCtrl->GetNextChild(mItemId[t],cookie))
201            {
202              mTreeListCtrl->SetItemText(i,1,_T(""));
203            } 
204        }
205      //
206
207    }
208   //================================================================
209
210   //================================================================
211    void WxGimmickFieldsView::SetColors( const wxColour& DatabaseColour,
212                                           const wxColour& DatabaseBgColour,
213                                           const wxColour& PatientColour,
214                                           const wxColour& PatientBgColour,
215                                           const wxColour& StudyColour,
216                                           const wxColour& StudyBgColour,
217                                           const wxColour& SeriesColour,
218                                           const wxColour& SeriesBgColour,
219                                           const wxColour& ImageColour,
220                                           const wxColour& ImageBgColour)
221    {
222      mTreeListCtrl->SetItemTextColour(mItemId[DicomNode::Database],
223                                       DatabaseColour);
224      mTreeListCtrl->SetItemBackgroundColour(mItemId[DicomNode::Database],
225                                             DatabaseBgColour);
226      mTreeListCtrl->SetItemTextColour(mItemId[DicomNode::Patient],
227                                       PatientColour);
228      mTreeListCtrl->SetItemBackgroundColour(mItemId[DicomNode::Patient],
229                                             PatientBgColour);
230      mTreeListCtrl->SetItemTextColour(mItemId[DicomNode::Study],
231                                       StudyColour);
232      mTreeListCtrl->SetItemBackgroundColour(mItemId[DicomNode::Study],
233                                             StudyBgColour);
234      mTreeListCtrl->SetItemTextColour(mItemId[DicomNode::Series],
235                                       SeriesColour);
236      mTreeListCtrl->SetItemBackgroundColour(mItemId[DicomNode::Series],
237                                             SeriesBgColour);
238      mTreeListCtrl->SetItemTextColour(mItemId[DicomNode::Image],
239                                       ImageColour);
240      mTreeListCtrl->SetItemBackgroundColour(mItemId[DicomNode::Image],
241                                             ImageBgColour);
242    }
243  //================================================================
244
245
246
247
248 }