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