]> 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 #include "creaDevManagerIds.h"
38 #include <vector>
39
40 wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl(
41     wxWindow *parent,
42     wxWindowID id,
43     const wxPoint &pos,
44     const wxSize &size,
45     long style,
46     const wxValidator &validator,
47     const wxString &name
48 )
49 {
50   wxCDMProjectsTreeCtrl::Create(parent, id, pos, size, style, validator, name);
51 }
52
53 wxCDMProjectsTreeCtrl::~wxCDMProjectsTreeCtrl()
54 {
55 }
56
57 bool wxCDMProjectsTreeCtrl::Create(
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   wxTreeCtrl::Create (parent, id, pos, size, style, validator, name);
68   wxTreeItemId rootIndex = this-> AddRoot(_("No Open Project"));
69   this->Update();
70   return TRUE;
71 }
72
73 void wxCDMProjectsTreeCtrl::BuildTree(modelCDMProject* projectTree)
74 {
75   this->DeleteAllItems();
76   if(projectTree != NULL)
77     {
78       wxTreeItemId rootIndex;
79       rootIndex= this-> AddRoot(crea::std2wx(projectTree->GetName()));
80       projectTree->SetId(rootIndex);
81
82       std::cout << "Building TreeCtrl for " << projectTree->GetName() << std::endl;
83       this->BuildTree(projectTree->GetChildren(), rootIndex);
84
85       this->Expand(rootIndex);
86
87       this->Update();
88     }
89   else
90     {
91       wxTreeItemId rootIndex = this-> AddRoot(_("No Open Project"));
92     }
93 }
94
95 void wxCDMProjectsTreeCtrl::BuildTree(const std::vector<modelCDMIProjectTreeNode*>& treeNodes, wxTreeItemId parent)
96 {
97   for (int i = 0; i < treeNodes.size(); i++)
98     {
99       //cout << projectsTree[i].GetName() << endl;
100       wxTreeItemId parentNodeIndex;
101       if(treeNodes[i] != NULL)
102         {
103           wxString nodeName((treeNodes[i]->GetName()).c_str(), wxConvUTF8);
104           parentNodeIndex = this->AppendItem(parent, nodeName);
105           treeNodes[i]->SetId(parentNodeIndex);
106
107           std::vector<modelCDMIProjectTreeNode*> innerChildren = treeNodes[i]->GetChildren();
108           if(innerChildren.size() > 0)
109             {
110               this->BuildTree(innerChildren, parentNodeIndex);
111             }
112         }
113
114     }
115 }