]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMIProjectTreeNode.h
d1688de5a8715da49defcd82ec8c46aa3efd0aa0
[crea.git] / lib / creaDevManagerLib / modelCDMIProjectTreeNode.h
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.h
30  *
31  *  Created on: 13/11/2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #ifndef MODELCDMIPROJECTTREENODE_H_
36 #define MODELCDMIPROJECTTREENODE_H_
37
38 #include <iostream>
39 #include <vector>
40 #include <creaWx.h>
41 #include "wx/treectrl.h"
42
43 /**
44  * Class that represents an element of a Crea Project.
45  */
46 class modelCDMIProjectTreeNode
47 {
48 public:
49   /**
50    * Destructor that doesn't do anything.
51    */
52   virtual ~modelCDMIProjectTreeNode() {};
53
54   /**
55    * Compares the precedence of an modelCDMIProjectTreeNode object with another by the node's name and its type (first folder then file).
56    * @return Either if the node x goes before (true) or after (false) y.
57    */
58   static bool CompareNodeItem(const modelCDMIProjectTreeNode* x, const modelCDMIProjectTreeNode* y);
59
60   /**
61    * Returns the id of the node in the tree of the project.
62    * @return Id of the node in the tree project.
63    */
64   const wxTreeItemId& GetId() const;
65   /**
66    * Returns the full path to the node, including the name of the node.
67    * @return Node's full path.
68    */
69   const std::string& GetPath() const;
70   /**
71    * Return the name of the node, either the file name or the folder name.
72    * @return Name of the node.
73    */
74   const std::string& GetName() const;
75   /**
76    * Returns the type of node.
77    * @return Either wxDIR_FILES for files or wxDIR_DIRS for folders.
78    */
79   const unsigned char& GetType() const;
80   /**
81    * Returns the level of the node in the project tree.
82    * @return Level of the node in the project tree.
83    */
84   const int& GetLevel() const;
85   /**
86    * Returns a reference to the parent node of the actual node.
87    * @return The reference of the parent node or NULL.
88    */
89   modelCDMIProjectTreeNode* GetParent() const;
90   /**
91    * Returns an array with the hierarchy route between the node and the project root
92    * @return Hierarchy array ordered from higher to lower node level down to the project root.
93    */
94   std::vector<modelCDMIProjectTreeNode*> GetParents() const;
95   /**
96    * Returns the children nodes of the actual node.
97    * @return An array with the children nodes.
98    */
99   const std::vector<modelCDMIProjectTreeNode*>& GetChildren() const;
100   /**
101    * Returns the file size of the node.
102    * @return File size.
103    */
104   const int& GetLength();
105   /**
106    * Sets the id of the node in the project tree.
107    * @param id Id of the node.
108    */
109   void SetId(const wxTreeItemId& id);
110   /**
111    * Sorts the children using the compareNodeItem function.
112    */
113   void SortChildren();
114   /**
115    * Sets the children array of the node. Warning: it discards the older children.
116    * @param children Array of children nodes.
117    */
118   void SetChildren(const std::vector<modelCDMIProjectTreeNode*>& children);
119
120   /**
121    * Refreshes the structure of the node and its children.
122    * @param result Result of the procedure.
123    * @return True if the procedure was successful.
124    */
125   virtual const bool Refresh(std::string*& result);
126   /**
127    * Opens the file explorer in the containing folder of the file or in the folder itself.
128    * @param result Result of the procedure.
129    * @return True if the procedure was successful.
130    */
131   const bool OpenInFileExplorer(std::string*& result) const;
132
133   protected:
134   /**
135    * Id of the node in the project tree.
136    */
137   wxTreeItemId id;
138   /**
139    * path of the node in the computer.
140    */
141   std::string path;
142   /**
143    * Name of the folder or file.
144    */
145   std::string name;
146   /**
147    * Type of the node. Either wxDIR_FILES for files or wxDIR_DIRS for folders.
148    */
149   unsigned char type;
150   /**
151    * Level of the node in the file hierarchy.
152    */
153   int level;
154   /**
155    * Length of the file in the system.
156    */
157   int length;
158   /**
159    * Reference to the parent node.
160    */
161   modelCDMIProjectTreeNode* parent;
162   /**
163    * Array of references to the children nodes.
164    */
165   std::vector<modelCDMIProjectTreeNode*> children;
166
167 };
168
169
170 #endif /* MODELCDMIPROJECTTREENODE_H_ */