]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMProject.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMProject.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  * modelCDMProject.cpp
30  *
31  *  Created on: 13/11/2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "modelCDMProject.h"
36
37 #include <iostream>
38 #include <vector>
39 #include <fstream>
40
41 #include "CDMUtilities.h"
42 #include "creaWx.h"
43 #include "wx/dir.h"
44
45 modelCDMProject::modelCDMProject()
46 {
47   std::cout << "in constructor1" << std::endl;
48   this->appli = NULL;
49   this->lib = NULL;
50   this->CMakeLists = NULL;
51 }
52
53 modelCDMProject::modelCDMProject(
54     const std::string& path,
55     const std::string& buildPath
56 )
57 {
58   this->path = CDMUtilities::fixPath(path);
59   //open makelists file
60   std::string pathFixed(CDMUtilities::fixPath(path));
61
62   //TODO: set pathMakeLists for windows
63   std::string pathMakeLists = pathFixed + "/CMakeLists.txt";
64
65   std::ifstream confFile;
66   confFile.open((pathMakeLists).c_str());
67
68   std::string word;
69   while(confFile.is_open() && !confFile.eof())
70     {
71       //std::cout << "leyendo " << word << std::endl;
72       //get project name
73       std::getline(confFile,word,'(');
74       std::vector<std::string> wordBits;
75       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
76
77       if(wordBits[wordBits.size()-1] == "PROJECT")
78         {
79           std::getline(confFile,word,')');
80           std::vector<std::string> nameBits;
81           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
82
83           this->name = this->nameProject = "";
84           for (int i = 0; i < nameBits.size(); i++)
85             {
86               if(i != 0)
87                 this->name += " ";
88               this->name += nameBits[i];
89             }
90           this->nameProject = this->name;
91
92         }
93
94
95       if(wordBits[wordBits.size()-1] == "SET")
96         {
97           //get project version
98           std::getline(confFile,word,')');
99           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
100           if(wordBits[0] == "PROJECT_MAJOR_VERSION")
101             {
102               version = wordBits[1];
103             }
104           if(wordBits[0] == "PROJECT_MINOR_VERSION")
105             {
106               version += "." + wordBits[1];
107             }
108           if(wordBits[0] == "PROJECT_BUILD_VERSION")
109             {
110               version += "." + wordBits[1];
111             }
112
113           //get project versionDate
114           if(wordBits[0] == "PROJECT_VERSION_DATE")
115             {
116               std::vector<std::string> versionBits;
117               CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
118               versionDate = versionBits[0];
119             }
120           //get project buildPath
121
122           if (buildPath != "")
123             {
124               this->buildPath = buildPath;
125             }
126           else
127             {
128               this->buildPath = this->path + "Bin";
129             }
130         }
131     }
132   confFile.close();
133
134   this->type = wxDIR_DIRS;
135   this->level = 0;
136
137   this->children.clear();
138   this->appli = NULL;
139   this->lib = NULL;
140   this->packages.clear();
141
142
143   //check all folders
144   wxDir dir(crea::std2wx((pathFixed).c_str()));
145   if (dir.IsOpened())
146     {
147       wxString fileName;
148       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
149       while (cont)
150         {
151           std::string stdfileName = crea::wx2std(fileName);
152
153           //if appli, create appli
154           if(stdfileName == "appli")
155             {
156               this->appli = new modelCDMAppli(pathFixed + "/appli", this->level + 1);
157               this->children.push_back(this->appli);
158             }
159           //if lib, create lib
160           else if(stdfileName == "lib")
161             {
162               this->lib = new modelCDMLib(pathFixed + "/lib", this->level + 1);
163               this->children.push_back(this->lib);
164             }
165           //if package , create package
166           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
167             {
168               modelCDMPackage* package = new modelCDMPackage(pathFixed + "/" + stdfileName, this->level + 1);
169               this->packages.push_back(package);
170               this->children.push_back(package);
171             }
172           //if is an unknown folder, create folder
173           else
174             {
175               this->children.push_back(new modelCDMFolder(pathFixed + "/" + stdfileName, this->level + 1));
176             }
177
178           cont = dir.GetNext(&fileName);
179         }
180
181       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
182       while (cont)
183         {
184           std::string stdfileName = crea::wx2std(fileName);
185
186           //if CMakeLists, create CMakeLists
187           if(stdfileName == "CMakeLists.txt")
188             {
189               this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + "/" + stdfileName, this->level + 1);
190               this->children.push_back(this->CMakeLists);
191             }
192           else
193             {
194               this->children.push_back(new modelCDMFile(pathFixed + "/" + stdfileName, this->level + 1));
195             }
196           //if is an unknown file, create file
197           cont = dir.GetNext(&fileName);
198         }
199     }
200
201   this->SortChildren();
202
203 }
204
205 modelCDMProject::~modelCDMProject()
206 {
207   for (int i = 0; i < this->children.size(); i++)
208     {
209       if(this->children[i] != NULL)
210         {
211           delete this->children[i];
212           this->children[i] = NULL;
213         }
214     }
215 }
216
217 const std::string& modelCDMProject::GetNameProject() const
218 {
219   return this->nameProject;
220 }
221
222 const std::string& modelCDMProject::GetVersion() const
223 {
224   return this->version;
225 }
226
227 const std::string& modelCDMProject::GetVersionDate() const
228 {
229   return this->versionDate;
230 }
231
232 const std::string& modelCDMProject::GetBuildPath() const
233 {
234   return this->buildPath;
235 }
236
237 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
238 {
239   //TODO: implement method
240   return true;
241 }
242
243 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
244 {
245   //TODO: implement method
246   return true;
247 }
248
249 bool modelCDMProject::CreatePackage(
250     const std::string& name,
251     std::string*& result,
252     const std::string& authors,
253     const std::string& authorsEmail,
254     const std::string& version,
255     const std::string& description
256 )
257 {
258   //TODO: implement method
259   return true;
260 }
261
262 bool modelCDMProject::CreateLibrary(
263     const std::string& name,
264     std::string*& result,
265     const std::string& path
266 )
267 {
268   //TODO: implement method
269   return true;
270 }
271
272 bool modelCDMProject::CreateApplication(
273     const std::string& name,
274     std::string*& result,
275     const std::string& path
276 )
277 {
278   //TODO: implement method
279   return true;
280 }
281
282 bool modelCDMProject::CreateBlackBox(
283     const std::string& name,
284     const std::string& package,
285     const std::string& authors,
286     const std::string& authorsEmail,
287     const std::string& categories,
288     const std::string& description
289 )
290 {
291   //TODO: implement method
292   return true;
293 }
294
295 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
296 {
297   //TODO: implement method
298   return true;
299 }
300
301 const bool modelCDMProject::Refresh(std::string*& result)
302 {
303   //TODO: implement method
304   return true;
305 }
306
307 bool modelCDMProject::ConfigureBuild(std::string*& result)
308 {
309   //TODO: implement method
310   return true;
311 }
312
313 bool modelCDMProject::Build(std::string*& result)
314 {
315   //TODO: implement method
316   return true;
317 }
318
319 bool modelCDMProject::Connect(std::string*& result)
320 {
321   //TODO: implement method
322   return true;
323 }