2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
30 * ModelCreaDevManagerTree.cpp
32 * Created on: 22/10/2012
33 * Author: Daniel Felipe Gonzalez Obando
36 #include "modelCDMProjectsTree.h"
44 modelCDMProjectsTree::modelCDMProjectsTree()
48 modelCDMProjectsTree::~modelCDMProjectsTree()
52 bool modelCDMProjectsTree::CompareNodeItem(modelCDMProjectsTreeNode x, modelCDMProjectsTreeNode y)
57 std::string xName = x.GetName();
58 std::string yName = y.GetName();
59 unsigned char xType = x.GetType();
60 unsigned char yType = y.GetType();
62 while ((i < xName.length()) && (i < yName.length()))
64 if (tolower (xName[i]) < tolower (yName[i]))
70 else if (tolower (xName[i]) > tolower (yName[i]))
81 if (xName.length() < yName.length())
89 if(xType == wxDIR_DIRS)
98 void modelCDMProjectsTree::SetRoot(std::string path)
100 std::stringstream p(path);
101 std::vector<std::string> breadcrumbs;
108 breadcrumbs.push_back(name);
112 for (int i = 0; i < (int)(breadcrumbs.size())-1; i++)
114 path += breadcrumbs[i] + "/";
116 name = breadcrumbs[breadcrumbs.size()-1];
118 bool projectFound = false;
119 if(projectRoot.GetName() == name)
124 this->projectRoot = modelCDMProjectsTreeNode(path,name,wxDIR_DIRS ,0);
126 std::cout << "already existing ";
129 std::cout << "project root set: " << name << " in " << path << std::endl;
132 void modelCDMProjectsTree::populateNode(modelCDMProjectsTreeNode& node)
134 //std::cout << "populating " << node.GetName() << " path " << node.GetPath() << "..." << std::endl;
135 std::vector <modelCDMProjectsTreeNode>* nodes = new std::vector <modelCDMProjectsTreeNode>;
137 std::string path = node.GetPath()+node.GetName()+"/";
139 wxDir dir(crea::std2wx(path.c_str()));
142 std::cerr << "Couldn't open the directory" << std::endl;
147 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
150 modelCDMProjectsTreeNode innerNode = modelCDMProjectsTreeNode(path, crea::wx2std(fileName), wxDIR_DIRS, node.GetLevel()+1);
151 this->populateNode(innerNode);
152 nodes->push_back(innerNode);
153 cont = dir.GetNext(&fileName);
156 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
159 modelCDMProjectsTreeNode innerNode = modelCDMProjectsTreeNode(path, crea::wx2std(fileName), wxDIR_FILES, node.GetLevel()+1);
160 nodes->push_back(innerNode);
161 cont = dir.GetNext(&fileName);
164 sort (nodes->begin(), nodes->end(), CompareNodeItem);
165 node.SetChildren(*nodes);
172 std::string path = node.GetPath()+node.GetName()+"/";
174 dp = opendir(path.c_str());
177 while ((ep = readdir (dp)) != NULL)
179 //std::cout << ep->d_name << std::endl;
180 if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 )
182 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, ep->d_name, ep->d_type, node.GetLevel()+1);
183 if (ep->d_type == DT_DIR)
185 this->populateNode(innerNode);
188 nodes->push_back(innerNode);
193 (void) closedir (dp);
195 sort (nodes->begin(), nodes->end(), CompareNodeItem);
197 node.SetChildren(*nodes);
201 std::cerr << "Couldn't open the directory" << std::endl;
205 void modelCDMProjectsTree::populateNode(std::string path)
207 if(path[path.size()-1] != '/')
209 std::cout << "searching " << path << std::endl;
210 if(this->projectRoot.GetPath()+this->projectRoot.GetName()+"/" == path)
212 std::cout << "Populating Project: " << path << "..." << std::endl;
213 this->populateNode(this->projectRoot);