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