]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx
6007d9434e23ecb5fdaed1a530c366e0338bdabd
[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 #include <sstream>
40
41 #include <wx/imaglist.h>
42
43 #include "creaDevManagerIds.h"
44 #include "images/AIcon20.xpm"
45 #include "images/ApIcon20.xpm"
46 #include "images/BBIcon20.xpm"
47 #include "images/BBSIcon20.xpm"
48 #include "images/CIcon20.xpm"
49 #include "images/CFIcon20.xpm"
50 #include "images/CMIcon20.xpm"
51 #include "images/FdIcon20.xpm"
52 #include "images/FlIcon20.xpm"
53 #include "images/LbIcon20.xpm"
54 #include "images/LIcon20.xpm"
55 #include "images/PrIcon20.xpm"
56 #include "images/PkIcon20.xpm"
57
58 wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl(
59     wxWindow *parent,
60     wxWindowID id,
61     const wxPoint &pos,
62     const wxSize &size,
63     long style,
64     const wxValidator &validator,
65     const wxString &name
66 )
67 {
68   wxCDMProjectsTreeCtrl::Create(parent, id, pos, size, style, validator, name);
69 }
70
71 wxCDMProjectsTreeCtrl::~wxCDMProjectsTreeCtrl()
72 {
73 }
74
75 bool wxCDMProjectsTreeCtrl::Create(
76     wxWindow* parent,
77     wxWindowID id,
78     const wxPoint &pos,
79     const wxSize &size,
80     long style,
81     const wxValidator &validator,
82     const wxString &name
83 )
84 {
85   wxTreeCtrl::Create (parent, id, pos, size, style, validator, name);
86
87   this->DeleteAllItems();
88
89   wxImageList* images = new wxImageList(20, 20, true);
90   this->ID_AIcon = images->Add(wxIcon(AIcon20));
91   this->ID_ApIcon = images->Add(wxIcon(ApIcon20));
92   this->ID_BBIcon = images->Add(wxIcon(BBIcon20));
93   this->ID_BBSIcon = images->Add(wxIcon(BBSIcon20));
94   this->ID_Cicon = images->Add(wxIcon(CIcon20));
95   this->ID_CMIcon = images->Add(wxIcon(CMIcon20));
96   this->ID_FdIcon = images->Add(wxIcon(FdIcon20));
97   this->ID_FlIcon = images->Add(wxIcon(FlIcon20));
98   this->ID_CFIcon = images->Add(wxIcon(CFIcon20));
99   this->ID_LbIcon = images->Add(wxIcon(LbIcon20));
100   this->ID_LIcon = images->Add(wxIcon(LIcon20));
101   this->ID_PrIcon = images->Add(wxIcon(PrIcon20));
102   this->ID_PkIcon = images->Add(wxIcon(PkIcon20));
103   this->AssignImageList(images);
104
105   wxTreeItemId rootIndex = this->AddRoot(wxT("No Open Project"), this->ID_Cicon, this->ID_Cicon);
106
107   this->Update();
108   return TRUE;
109 }
110
111 void wxCDMProjectsTreeCtrl::BuildTree(std::map< wxCDMTreeItemId, modelCDMIProjectTreeNode* >& modelElements, modelCDMProject* projectTree)
112 {
113   this->Unselect();
114   std::cout << "building tree" << std::endl;
115   this->DeleteAllItems();
116   modelElements.clear();
117   if(projectTree != NULL)
118     {
119       projectTree->SetId(this->AddRoot(crea::std2wx(projectTree->GetName()), this->ID_PrIcon));
120           
121           modelElements[projectTree->GetId()] = projectTree;
122
123       std::cout << "Building TreeCtrl for " << projectTree->GetName() << std::endl;
124       this->BuildTree(projectTree->GetChildren(), modelElements, projectTree->GetId());
125
126       this->Expand(projectTree->GetId().GetWxId());
127
128       this->Update();
129     }
130   else
131     {
132       wxTreeItemId rootIndex = this-> AddRoot(_("No Open Project"), this->ID_Cicon);
133     }
134 }
135
136 void wxCDMProjectsTreeCtrl::BuildTree(const std::vector<modelCDMIProjectTreeNode*>& treeNodes, std::map< wxCDMTreeItemId, modelCDMIProjectTreeNode* >& modelElements, const wxCDMTreeItemId& parent)
137 {
138   for (int i = 0; i < (int)(treeNodes.size()); i++)
139     {
140       //cout << projectsTree[i].GetName() << endl;
141       if(treeNodes[i] != NULL)
142         {
143           int idIcon = GetIconId(treeNodes[i]);
144           wxString nodeName((treeNodes[i]->GetName()).c_str(), wxConvUTF8);
145           treeNodes[i]->SetId(wxCDMTreeItemId(this->AppendItem(parent.GetWxId(), nodeName, idIcon)));
146           
147                   modelElements[treeNodes[i]->GetId()] = treeNodes[i];
148
149           std::vector<modelCDMIProjectTreeNode*> innerChildren = treeNodes[i]->GetChildren();
150           if(innerChildren.size() > 0)
151             {
152               this->BuildTree(innerChildren, modelElements, treeNodes[i]->GetId());
153             }
154         }
155
156     }
157 }
158
159 int wxCDMProjectsTreeCtrl::GetIconId(modelCDMIProjectTreeNode* node)
160 {
161   modelCDMIProjectTreeNode* element = dynamic_cast<modelCDMProject*>(node);
162   if(element != NULL)
163     {
164       return this->ID_PrIcon;
165     }
166   else
167     {
168       element = dynamic_cast<modelCDMAppli*>(node);
169       if(element != NULL)
170         {
171           return this->ID_ApIcon;
172         }
173       else
174         {
175           element = dynamic_cast<modelCDMApplication*>(node);
176           if(element != NULL)
177             {
178               return this->ID_AIcon;
179             }
180           else
181             {
182               element = dynamic_cast<modelCDMLib*>(node);
183               if(element != NULL)
184                 {
185                   return this->ID_LbIcon;
186                 }
187               else
188                 {
189                   element = dynamic_cast<modelCDMLibrary*>(node);
190                   if(element != NULL)
191                     {
192                       return this->ID_LIcon;
193                     }
194                   else
195                     {
196                       element = dynamic_cast<modelCDMPackage*>(node);
197                       if(element != NULL)
198                         {
199                           return this->ID_PkIcon;
200                         }
201                       else
202                         {
203                           element = dynamic_cast<modelCDMBlackBox*>(node);
204                           if(element != NULL)
205                             {
206                               return this->ID_BBIcon;
207                             }
208                           else
209                             {
210                               element = dynamic_cast<modelCDMCMakeListsFile*>(node);
211                               if(element != NULL)
212                                 {
213                                   return this->ID_CMIcon;
214                                 }
215                               else
216                                 {
217                                   element = dynamic_cast<modelCDMCodeFile*>(node);
218                                   if(element != NULL)
219                                     {
220                                       return this->ID_CFIcon;
221                                     }
222                                   else
223                                     {
224                                       element = dynamic_cast<modelCDMBBSFile*>(node);
225                                       if(element != NULL)
226                                         {
227                                           return this->ID_BBSIcon;
228                                         }
229                                       else
230                                         {
231                                           element = dynamic_cast<modelCDMFolder*>(node);
232                                           if(element != NULL)
233                                             {
234                                               return this->ID_FdIcon;
235                                             }
236                                           else
237                                             {
238                                               element = dynamic_cast<modelCDMFile*>(node);
239                                               if(element != NULL)
240                                                 {
241                                                   return this->ID_FlIcon;
242                                                 }
243                                               else
244                                                 {
245                                                   return this->ID_Cicon;
246                                                 }
247                                             }
248                                         }
249                                     }
250                                 }
251                             }
252                         }
253                     }
254                 }
255             }
256         }
257     }
258 }