]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMIProjectTreeNode.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMIProjectTreeNode.cpp
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  * modelCDMIProjectTreeNode.cpp
30  *
31  *  Created on: Nov 26, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34 #include "modelCDMIProjectTreeNode.h"
35 #include <algorithm>
36
37 bool modelCDMIProjectTreeNode::CompareNodeItem(const modelCDMIProjectTreeNode* x, const modelCDMIProjectTreeNode* y)
38 {
39   bool returnValue;
40   bool noWinner = true;
41   unsigned int i = 0;
42   std::string xName = x->GetName();
43   std::string yName = y->GetName();
44   unsigned char xType = x->GetType();
45   unsigned char yType = y->GetType();
46
47   while ((i < xName.length()) && (i < yName.length()))
48   {
49     if (tolower (xName[i]) < tolower (yName[i]))
50     {
51       noWinner = false;
52       returnValue = true;
53       break;
54     }
55     else if (tolower (xName[i]) > tolower (yName[i]))
56     {
57       noWinner = false;
58       returnValue = false;
59       break;
60     }
61     i++;
62   }
63
64   if(noWinner)
65   {
66     if (xName.length() < yName.length())
67       returnValue = true;
68     else
69       returnValue = false;
70   }
71
72   if(xType != yType)
73   {
74     if(xType == DT_DIR)
75       returnValue = true;
76     else
77       returnValue = false;
78   }
79
80   return returnValue;
81 }
82
83 const wxTreeItemId& modelCDMIProjectTreeNode::GetId() const
84 {
85   return this->id;
86 }
87
88 const std::string& modelCDMIProjectTreeNode::GetPath() const
89 {
90   return this->path;
91 }
92
93 const std::string& modelCDMIProjectTreeNode::GetName() const
94 {
95   return this->name;
96 }
97
98 const unsigned char& modelCDMIProjectTreeNode::GetType() const
99 {
100   return this->type;
101 }
102
103 const int& modelCDMIProjectTreeNode::GetLevel() const
104 {
105   return this->level;
106 }
107
108 const std::vector<modelCDMIProjectTreeNode*>& modelCDMIProjectTreeNode::GetChildren() const
109 {
110   return this->children;
111 }
112
113 void modelCDMIProjectTreeNode::SetId(const wxTreeItemId& id)
114 {
115   this->id = id;
116 }
117
118 void modelCDMIProjectTreeNode::SortChildren()
119 {
120   std::sort(this->children.begin(), this->children.end(), CompareNodeItem);
121 }
122
123 void modelCDMIProjectTreeNode::SetChildren(
124     const std::vector<modelCDMIProjectTreeNode*>& children)
125 {
126   this->children.clear();
127   this->children = children;
128 }
129
130 const bool modelCDMIProjectTreeNode::Refresh(std::string*& result)
131 {
132   //TODO: implement method
133   return false;
134 }
135
136 const bool modelCDMIProjectTreeNode::OpenInFileExplorer(std::string*& result) const
137 {
138   //TODO: implement method
139   return false;
140 }