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