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