2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */
27 * ModelCreaDevManagerTree.cpp
29 * Created on: 22/10/2012
33 #include "modelCDMProjectsTree.h"
41 modelCDMProjectsTree::modelCDMProjectsTree()
45 modelCDMProjectsTree::~modelCDMProjectsTree()
49 bool modelCDMProjectsTree::CompareNodeItem(modelCDMProjectsTreeNode x, modelCDMProjectsTreeNode y)
54 std::string xName = x.GetName();
55 std::string yName = y.GetName();
56 unsigned char xType = x.GetType();
57 unsigned char yType = y.GetType();
59 while ((i < xName.length()) && (i < yName.length()))
61 if (tolower (xName[i]) < tolower (yName[i]))
67 else if (tolower (xName[i]) > tolower (yName[i]))
78 if (xName.length() < yName.length())
95 void modelCDMProjectsTree::SetRoot(std::string path)
97 std::stringstream p(path);
98 std::vector<std::string> breadcrumbs;
105 breadcrumbs.push_back(name);
109 for (int i = 0; i < breadcrumbs.size()-1; i++)
111 path += breadcrumbs[i] + "/";
113 name = breadcrumbs[breadcrumbs.size()-1];
115 bool projectFound = false;
116 if(projectRoot.GetName() == name)
121 this->projectRoot = modelCDMProjectsTreeNode(path,name,DT_DIR,0);
123 std::cout << "already existing ";
126 std::cout << "project root set: " << name << " in " << path << std::endl;
129 void modelCDMProjectsTree::populateNode(modelCDMProjectsTreeNode& node)
131 //std::cout << "populating " << node.GetName() << " path " << node.GetPath() << "..." << std::endl;
132 std::vector <modelCDMProjectsTreeNode>* nodes = new std::vector <modelCDMProjectsTreeNode>;
134 std::string path = node.GetPath()+node.GetName()+"/";
136 wxDir dir(wxString(path.c_str()));
139 std::cerr << "Couldn't open the directory" << std::endl;
144 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
147 modelCDMProjectsTreeNode innerNode = modelCDMProjectsTreeNode(path, crea::wx2std(fileName), wxDIR_DIRS, node.GetLevel()+1);
148 this->populateNode(innerNode);
149 nodes->push_back(innerNode);
150 cont = dir.GetNext(&fileName);
153 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
156 modelCDMProjectsTreeNode innerNode = modelCDMProjectsTreeNode(path, crea::wx2std(fileName), wxDIR_FILES, node.GetLevel()+1);
157 nodes->push_back(innerNode);
158 cont = dir.GetNext(&fileName);
161 sort (nodes->begin(), nodes->end(), CompareNodeItem);
162 node.SetChildren(*nodes);
169 std::string path = node.GetPath()+node.GetName()+"/";
171 dp = opendir(path.c_str());
174 while ((ep = readdir (dp)) != NULL)
176 //std::cout << ep->d_name << std::endl;
177 if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 )
179 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, ep->d_name, ep->d_type, node.GetLevel()+1);
180 if (ep->d_type == DT_DIR)
182 this->populateNode(innerNode);
185 nodes->push_back(innerNode);
190 (void) closedir (dp);
192 sort (nodes->begin(), nodes->end(), CompareNodeItem);
194 node.SetChildren(*nodes);
198 std::cerr << "Couldn't open the directory" << std::endl;
202 void modelCDMProjectsTree::populateNode(std::string path)
204 if(path[path.size()-1] != '/')
206 std::cout << "searching " << path << std::endl;
207 if(this->projectRoot.GetPath()+this->projectRoot.GetName()+"/" == path)
209 std::cout << "Populating Project: " << path << "..." << std::endl;
210 this->populateNode(this->projectRoot);