]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx
e05fa97b0711b743550fcbcd1ed2491dd74e272a
[crea.git] / lib / creaDevManagerLib / wxCDMProjectsTreeCtrl.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26  */
27
28
29 /*
30  * wxCreaDevManagerTreeCtrl.cpp
31  *
32  *  Created on: 19/10/2012
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMProjectsTreeCtrl.h"
37
38 #include <vector>
39
40 #include <wx/imaglist.h>
41
42 #include "creaDevManagerIds.h"
43 #include "images/AIcon20.xpm"
44 #include "images/ApIcon20.xpm"
45 #include "images/BBIcon20.xpm"
46 #include "images/CIcon20.xpm"
47 #include "images/CMIcon20.xpm"
48 #include "images/FdIcon20.xpm"
49 #include "images/FlIcon20.xpm"
50 #include "images/LbIcon20.xpm"
51 #include "images/LIcon20.xpm"
52 #include "images/PrIcon20.xpm"
53 #include "images/PkIcon20.xpm"
54
55 wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl(
56     wxWindow *parent,
57     wxWindowID id,
58     const wxPoint &pos,
59     const wxSize &size,
60     long style,
61     const wxValidator &validator,
62     const wxString &name
63 )
64 {
65   wxCDMProjectsTreeCtrl::Create(parent, id, pos, size, style, validator, name);
66 }
67
68 wxCDMProjectsTreeCtrl::~wxCDMProjectsTreeCtrl()
69 {
70 }
71
72 bool wxCDMProjectsTreeCtrl::Create(
73     wxWindow* parent,
74     wxWindowID id,
75     const wxPoint &pos,
76     const wxSize &size,
77     long style,
78     const wxValidator &validator,
79     const wxString &name
80 )
81 {
82   wxTreeCtrl::Create (parent, id, pos, size, style, validator, name);
83
84   this->DeleteAllItems();
85
86   wxImageList* images = new wxImageList(20, 20, true);
87   this->ID_AIcon = images->Add(wxIcon(AIcon20));
88   this->ID_ApIcon = images->Add(wxIcon(ApIcon20));
89   this->ID_BBIcon = images->Add(wxIcon(BBIcon20));
90   this->ID_Cicon = images->Add(wxIcon(CIcon20));
91   this->ID_CMIcon = images->Add(wxIcon(CMIcon20));
92   this->ID_FdIcon = images->Add(wxIcon(FdIcon20));
93   this->ID_FlIcon = images->Add(wxIcon(FlIcon20));
94   this->ID_LbIcon = images->Add(wxIcon(LbIcon20));
95   this->ID_LIcon = images->Add(wxIcon(LIcon20));
96   this->ID_PrIcon = images->Add(wxIcon(PrIcon20));
97   this->ID_PkIcon = images->Add(wxIcon(PkIcon20));
98   this->AssignImageList(images);
99
100   wxTreeItemId rootId = AddRoot(wxT("Root"), 0, 0);
101 /*
102   wxTreeItemId rootIndex = this->AddRoot(wxT("No Open Project"), this->ID_Cicon, this->ID_Cicon);*/
103   this->Update();
104   return TRUE;
105 }
106
107 void wxCDMProjectsTreeCtrl::BuildTree(std::map< wxTreeItemId, modelCDMIProjectTreeNode* >& modelElements, modelCDMProject* projectTree)
108 {
109   std::cout << "building tree" << std::endl;
110   this->DeleteAllItems();
111   modelElements.clear();
112   if(projectTree != NULL)
113     {
114       wxTreeItemId rootIndex;
115       rootIndex= this-> AddRoot(crea::std2wx(projectTree->GetName()), this->ID_PrIcon, this->ID_PrIcon);
116       projectTree->SetId(rootIndex);
117       modelElements[rootIndex] = projectTree;
118
119       std::cout << "Building TreeCtrl for " << projectTree->GetName() << std::endl;
120       this->BuildTree(projectTree->GetChildren(), modelElements, rootIndex);
121
122       this->Expand(rootIndex);
123
124       this->Update();
125     }
126   else
127     {
128       wxTreeItemId rootIndex = this-> AddRoot(_("No Open Project"));
129     }
130 }
131
132 void wxCDMProjectsTreeCtrl::BuildTree(const std::vector<modelCDMIProjectTreeNode*>& treeNodes, std::map< wxTreeItemId, modelCDMIProjectTreeNode* >& modelElements, wxTreeItemId parent)
133 {
134   for (int i = 0; i < treeNodes.size(); i++)
135     {
136       //cout << projectsTree[i].GetName() << endl;
137       wxTreeItemId parentNodeIndex;
138       if(treeNodes[i] != NULL)
139         {
140           int idIcon = GetIconId(treeNodes[i]);
141           wxString nodeName((treeNodes[i]->GetName()).c_str(), wxConvUTF8);
142           parentNodeIndex = this->AppendItem(parent, nodeName, idIcon, idIcon);
143           treeNodes[i]->SetId(parentNodeIndex);
144           modelElements[parentNodeIndex] = treeNodes[i];
145
146           std::vector<modelCDMIProjectTreeNode*> innerChildren = treeNodes[i]->GetChildren();
147           if(innerChildren.size() > 0)
148             {
149               this->BuildTree(innerChildren, modelElements, parentNodeIndex);
150             }
151         }
152
153     }
154 }
155
156 int wxCDMProjectsTreeCtrl::GetIconId(modelCDMIProjectTreeNode* node)
157 {
158   modelCDMIProjectTreeNode* element = dynamic_cast<modelCDMProject*>(node);
159   if(element != NULL)
160     {
161       return this->ID_PrIcon;
162     }
163   else
164     {
165       element = dynamic_cast<modelCDMAppli*>(node);
166       if(element != NULL)
167         {
168           return this->ID_ApIcon;
169         }
170       else
171         {
172           element = dynamic_cast<modelCDMApplication*>(node);
173           if(element != NULL)
174             {
175               return this->ID_AIcon;
176             }
177           else
178             {
179               element = dynamic_cast<modelCDMLib*>(node);
180               if(element != NULL)
181                 {
182                   return this->ID_LbIcon;
183                 }
184               else
185                 {
186                   element = dynamic_cast<modelCDMLibrary*>(node);
187                   if(element != NULL)
188                     {
189                       return this->ID_LIcon;
190                     }
191                   else
192                     {
193                       element = dynamic_cast<modelCDMPackage*>(node);
194                       if(element != NULL)
195                         {
196                           return this->ID_PkIcon;
197                         }
198                       else
199                         {
200                           element = dynamic_cast<modelCDMBlackBox*>(node);
201                           if(element != NULL)
202                             {
203                               return this->ID_BBIcon;
204                             }
205                           else
206                             {
207                               element = dynamic_cast<modelCDMCMakeListsFile*>(node);
208                               if(element != NULL)
209                                 {
210                                   return this->ID_CMIcon;
211                                 }
212                               else
213                                 {
214                                   element = dynamic_cast<modelCDMFolder*>(node);
215                                   if(element != NULL)
216                                     {
217                                       return this->ID_FdIcon;
218                                     }
219                                   else
220                                     {
221                                       element = dynamic_cast<modelCDMFile*>(node);
222                                       if(element != NULL)
223                                         {
224                                           return this->ID_FlIcon;
225                                         }
226                                       else
227                                         {
228                                           return this->ID_Cicon;
229                                         }
230                                     }
231                                 }
232                             }
233                         }
234                     }
235                 }
236             }
237         }
238     }
239 }