]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMPackage.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMPackage.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  * modelCDMPackage.cpp
30  *
31  *  Created on: Nov 23, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "modelCDMPackage.h"
36
37 #include "creaWx.h"
38 #include "wx/dir.h"
39 #include "CDMUtilities.h"
40
41 modelCDMPackage::modelCDMPackage()
42 {
43 }
44
45 modelCDMPackage::modelCDMPackage(const std::string& path, const int& level)
46 {
47   this->type = wxDIR_DIRS;
48   //Get Package Name
49   std::vector<std::string> words;
50   std::string delimiters;
51   //TODO::fix for windows
52   delimiters = "/";
53   CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
54   this->name = words[words.size()-1];
55   this->namePackage = this->name;
56   this->level = level;
57   this->path = path;
58
59   //check all folders and files
60   wxDir dir(crea::std2wx((path).c_str()));
61   if (dir.IsOpened())
62     {
63       wxString fileName;
64
65       //folders
66       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
67       while (cont)
68         {
69           std::string stdfileName = crea::wx2std(fileName);
70           //if src, check for black boxes
71           if(stdfileName == "src")
72             {
73               wxDir srcF(crea::std2wx((path + delimiters + "src").c_str()));
74               if (srcF.IsOpened())
75                 {
76                   wxString srcName;
77                   bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES);
78                   while (innerCont)
79                     {
80                       if(crea::wx2std(srcName.substr(0,2)) == "bb")
81                         {
82                           modelCDMBlackBox* blackbox = new modelCDMBlackBox(crea::wx2std(srcName), path + delimiters + "src", this->level + 1);
83                           this->blackBoxes.push_back(blackbox);
84                           this->children.push_back(blackbox);
85                         }
86                       innerCont = srcF.GetNext(&srcName);
87                     }
88                 }
89             }
90           //if is an unknown folder, create folder
91           else
92             {
93               this->children.push_back(new modelCDMFolder(path + delimiters + stdfileName, this->level + 1));
94             }
95           cont = dir.GetNext(&fileName);
96         }
97
98       //files
99       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
100       while (cont)
101         {
102           std::string stdfileName = crea::wx2std(fileName);
103
104           //if CMakeLists, create CMakeLists
105           if(stdfileName == "CMakeLists.txt")
106             {
107               this->CMakeLists = new modelCDMCMakeListsFile(path + delimiters + stdfileName, this->level + 1);
108               this->children.push_back(this->CMakeLists);
109             }
110           else
111             {
112               this->children.push_back(new modelCDMFile(path + delimiters + stdfileName, this->level + 1));
113             }
114           //if is an unknown file, create file
115           cont = dir.GetNext(&fileName);
116         }
117     }
118   this->SortChildren();
119 }
120
121 modelCDMPackage::~modelCDMPackage()
122 {
123 }
124
125 const std::string& modelCDMPackage::GetNamePackage() const
126 {
127   return this->namePackage;
128 }
129
130 const std::string& modelCDMPackage::GetAuthors() const
131 {
132   return this->authors;
133 }
134
135 const std::string& modelCDMPackage::GetAuthorsEmail() const
136 {
137   return this->authorsEmail;
138 }
139
140 const std::string& modelCDMPackage::GetVersion() const
141 {
142   return this->version;
143 }
144
145 const std::string& modelCDMPackage::GetDescription() const
146 {
147   return this->description;
148 }
149
150 const std::vector<modelCDMBlackBox*>& modelCDMPackage::GetBlackBoxes() const
151 {
152   return this->blackBoxes;
153 }
154
155 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
156 {
157   //TODO: implement method
158   return true;
159 }
160
161 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
162 {
163   //TODO: implement method
164   return true;
165 }
166
167 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
168 {
169   //TODO: implement method
170   return true;
171 }
172
173 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
174 {
175   //TODO: implement method
176   return true;
177 }
178
179 bool modelCDMPackage::CreateBlackBox(
180     const std::string& name,
181     const std::string& authors,
182     const std::string& authorsEmail,
183     const std::string& categories,
184     const std::string& description
185 )
186 {
187   //TODO: implement method
188   return true;
189 }
190
191 bool modelCDMPackage::OpenCMakeListsFile(std::string*& result)
192 {
193   //TODO: implement method
194   return true;
195 }
196
197 const bool modelCDMPackage::Refresh(std::string*& result)
198 {
199   //TODO: implement method
200   return true;
201 }