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