]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMProject.cpp
51f642a0b097068da7d779cccbb84a6e561620dc
[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 <sstream>
39 #include <vector>
40 #include <algorithm>
41 #include <fstream>
42 #include <ctime>
43
44 #include "CDMUtilities.h"
45 #include "creaWx.h"
46 #include "wx/dir.h"
47
48 modelCDMProject::modelCDMProject()
49 {
50   std::cout << "in constructor1" << std::endl;
51   this->appli = NULL;
52   this->lib = NULL;
53   this->CMakeLists = NULL;
54 }
55
56 modelCDMProject::modelCDMProject(
57     modelCDMIProjectTreeNode* parent,
58     const std::string& path,
59     const std::string& name,
60     const std::string& buildPath
61 )
62 {
63   std::cout << "creating project: " + name + " in " + path + "\n";
64   this->parent = parent;
65   this->path = CDMUtilities::fixPath(path);
66   //open makelists file
67   std::string pathFixed(CDMUtilities::fixPath(path));
68
69   std::string pathMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
70
71   std::ifstream confFile;
72   confFile.open((pathMakeLists).c_str());
73
74   std::string word;
75   while(confFile.is_open() && !confFile.eof())
76     {
77       //std::cout << "leyendo " << word << std::endl;
78       //get project name
79       std::getline(confFile,word,'(');
80       std::vector<std::string> wordBits;
81       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
82
83       if(wordBits[wordBits.size()-1] == "PROJECT")
84         {
85           std::getline(confFile,word,')');
86           std::vector<std::string> nameBits;
87           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
88
89           this->name = this->nameProject = "";
90           for (int i = 0; i < nameBits.size(); i++)
91             {
92               if(i != 0)
93                 this->name += " ";
94               this->name += nameBits[i];
95             }
96           this->nameProject = this->name;
97
98         }
99
100
101       if(wordBits[wordBits.size()-1] == "SET")
102         {
103           //get project version
104           std::getline(confFile,word,')');
105           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
106           if(wordBits[0] == "PROJECT_MAJOR_VERSION")
107             {
108               version = wordBits[1];
109             }
110           if(wordBits[0] == "PROJECT_MINOR_VERSION")
111             {
112               version += "." + wordBits[1];
113             }
114           if(wordBits[0] == "PROJECT_BUILD_VERSION")
115             {
116               version += "." + wordBits[1];
117             }
118
119           //get project versionDate
120           if(wordBits[0] == "PROJECT_VERSION_DATE")
121             {
122               std::vector<std::string> versionBits;
123               CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
124               versionDate = versionBits[0];
125             }
126           //get project buildPath
127
128           if (buildPath != "")
129             {
130               this->buildPath = buildPath;
131             }
132           else
133             {
134               this->buildPath = this->path + "Bin";
135             }
136         }
137     }
138   confFile.close();
139
140   this->type = wxDIR_DIRS;
141   this->level = 0;
142
143   this->children.clear();
144   this->appli = NULL;
145   this->lib = NULL;
146   this->packages.clear();
147
148
149   //check all folders
150   wxDir dir(crea::std2wx((pathFixed).c_str()));
151   if (dir.IsOpened())
152     {
153       wxString fileName;
154       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
155       while (cont)
156         {
157           std::string stdfileName = crea::wx2std(fileName);
158
159           //if appli, create appli
160           if(stdfileName == "appli")
161             {
162               this->appli = new modelCDMAppli(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
163               this->children.push_back(this->appli);
164             }
165           //if lib, create lib
166           else if(stdfileName == "lib")
167             {
168               this->lib = new modelCDMLib(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
169               this->children.push_back(this->lib);
170             }
171           //if package , create package
172           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
173             {
174               modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
175               this->packages.push_back(package);
176               this->children.push_back(package);
177             }
178           //if is an unknown folder, create folder
179           else
180             {
181               this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
182             }
183
184           cont = dir.GetNext(&fileName);
185         }
186
187       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
188       while (cont)
189         {
190           std::string stdfileName = crea::wx2std(fileName);
191
192           //if CMakeLists, create CMakeLists
193           if(stdfileName == "CMakeLists.txt")
194             {
195               this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
196               this->children.push_back(this->CMakeLists);
197             }
198           else
199             {
200               this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
201             }
202           //if is an unknown file, create file
203           cont = dir.GetNext(&fileName);
204         }
205     }
206
207   this->SortChildren();
208   std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
209
210 }
211
212 modelCDMProject::~modelCDMProject()
213 {
214 }
215
216 const std::string& modelCDMProject::GetNameProject() const
217 {
218   return this->nameProject;
219 }
220
221 const std::string& modelCDMProject::GetVersion() const
222 {
223   return this->version;
224 }
225
226 const std::string& modelCDMProject::GetVersionDate() const
227 {
228   return this->versionDate;
229 }
230
231 const std::string& modelCDMProject::GetBuildPath() const
232 {
233   return this->buildPath;
234 }
235
236 const std::vector<modelCDMPackage*>& modelCDMProject::GetPackages() const
237 {
238   return this->packages;
239 }
240
241 modelCDMAppli* modelCDMProject::GetAppli() const
242 {
243   return this->appli;
244 }
245
246 modelCDMLib* modelCDMProject::GetLib() const
247 {
248   return this->lib;
249 }
250
251 std::string modelCDMProject::GetBuildInstruction() const
252 {
253   std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
254   return makeComm;
255 }
256
257 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
258 {
259
260   std::vector<std::string> vers;
261   CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
262
263   time_t now = time(0);
264   tm* ltm = localtime(&now);
265
266   std::stringstream date;
267   date << ltm->tm_mday << "/" << 1 + ltm->tm_mon << "/" << 1900 + ltm->tm_year;
268
269   //set name of library in CMakeLists inside copied folder
270   std::string line;
271   std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
272   if( !in.is_open())
273     {
274       result = new std::string("CMakeLists.txt file failed to open.");
275       return false;
276     }
277   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
278   if( !out.is_open())
279     {
280       result = new std::string("CMakeLists.txt.tmp file failed to open.");
281       return false;
282     }
283   while (getline(in, line))
284     {
285       if(line.find("SET(PROJECT_MAJOR_VERSION") != std::string::npos)
286         line = "SET(PROJECT_MAJOR_VERSION " + vers[0] + ")";
287       else if(line.find("SET(PROJECT_MINOR_VERSION") != std::string::npos)
288         line = "SET(PROJECT_MINOR_VERSION " + vers[1] + ")";
289       else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos)
290         line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")";
291       else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos)
292         line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
293       out << line << std::endl;
294     }
295   in.close();
296   out.close();
297   //delete old file and rename new file
298   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
299   if(system(renameCommand.c_str()))
300     {
301       result = new std::string("An error occurred while running '" + renameCommand + "'.");
302       return false;
303     }
304
305   this->version = vers[0] + "." + vers[1] + "." + vers[2];
306   this->versionDate = date.str();
307   return true;
308 }
309
310 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
311 {
312   if(path == "")
313     {
314       result = new std::string("The path cannot be empty");
315       return false;
316     }
317   if(path == this->path)
318     {
319       result = new std::string("The path cannot be same as the project sources");
320       return false;
321     }
322   this->buildPath = path;
323   return true;
324 }
325
326 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
327     const std::string& name,
328     std::string*& result,
329     const std::string& authors,
330     const std::string& authorsEmail,
331     const std::string& description,
332     const std::string& version
333 )
334 {
335   //fixing input parameters
336   std::vector<std::string> words;
337
338   CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
339   std::string nameFixed = "";
340   for (int i = 0; i < words.size(); i++)
341     {
342       nameFixed += words[i];
343     }
344
345   words.clear();
346   CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
347   std::string authorFixed;
348   for (int i = 0; i < words.size(); i++)
349     {
350       authorFixed += words[i];
351     }
352
353   words.clear();
354   std::string descriptionFixed;
355   CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
356   for (int i = 0; i < words.size(); i++)
357     {
358       descriptionFixed += words[i];
359     }
360   words.clear();
361   CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
362   for (int i = 0; i < words.size(); i++)
363     {
364       descriptionFixed += "_" + words[i];
365     }
366
367   //call project to create package : use bbCreatePackage <path> <name> [author] [description]
368   std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
369   //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
370   if(system(creationCommand.c_str()))
371     {
372       result = new std::string("An error occurred while running '" + creationCommand + "'.");
373       return NULL;
374     }
375
376   //add library to model
377   modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
378   this->packages.push_back(package);
379   this->children.push_back(package);
380
381   //TODO: set package version
382
383   this->SortChildren();
384
385   result = new std::string(this->path + CDMUtilities::SLASH + name);
386   return package;
387 }
388
389 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
390     const std::string& name,
391     std::string*& result,
392     const std::string& path
393 )
394 {
395   if(this->lib != NULL)
396     {
397       return this->lib->CreateLibrary(name, result);
398     }
399   result = new std::string("there is no lib folder in this project.");
400   return NULL;
401 }
402
403 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
404     const std::string& name,
405     std::string*& result,
406     const std::string& path
407 )
408 {
409   if(this->appli != NULL)
410     {
411       return this->appli->CreateApplication(name, result);
412     }
413   result = new std::string("there is no appli folder in this project.");
414   return NULL;
415 }
416
417 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
418     const std::string& name,
419     const std::string& package,
420     const std::string& authors,
421     const std::string& authorsEmail,
422     const std::string& categories,
423     const std::string& description
424 )
425 {
426   //TODO: implement method
427   return NULL;
428 }
429
430 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
431 {
432   if (!CDMUtilities::openTextEditor(this->CMakeLists->GetPath()))
433     return true;
434   else
435     {
436       result = new std::string("Couldn't open CMakeLists file.");
437       return false;
438     }
439 }
440
441 const bool modelCDMProject::Refresh(std::string*& result)
442 {
443   std::cout << "refreshing project" << std::endl;
444   //open makelists file
445   std::string pathMakeLists = this->path + CDMUtilities::SLASH + "CMakeLists.txt";
446
447   std::ifstream confFile;
448   confFile.open((pathMakeLists).c_str());
449
450   std::string word;
451   while(confFile.is_open() && !confFile.eof())
452     {
453       //std::cout << "leyendo " << word << std::endl;
454       //get project name
455       std::getline(confFile,word,'(');
456       std::vector<std::string> wordBits;
457       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
458
459       if(wordBits[wordBits.size()-1] == "PROJECT")
460         {
461           std::getline(confFile,word,')');
462           std::vector<std::string> nameBits;
463           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
464
465           this->name = this->nameProject = "";
466           for (int i = 0; i < nameBits.size(); i++)
467             {
468               if(i != 0)
469                 this->name += " ";
470               this->name += nameBits[i];
471             }
472           this->nameProject = this->name;
473
474         }
475
476
477       if(wordBits[wordBits.size()-1] == "SET")
478         {
479           //get project version
480           std::getline(confFile,word,')');
481           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
482           if(wordBits[0] == "PROJECT_MAJOR_VERSION")
483             {
484               version = wordBits[1];
485             }
486           if(wordBits[0] == "PROJECT_MINOR_VERSION")
487             {
488               version += "." + wordBits[1];
489             }
490           if(wordBits[0] == "PROJECT_BUILD_VERSION")
491             {
492               version += "." + wordBits[1];
493             }
494
495           //get project versionDate
496           if(wordBits[0] == "PROJECT_VERSION_DATE")
497             {
498               std::vector<std::string> versionBits;
499               CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
500               versionDate = versionBits[0];
501             }
502         }
503     }
504   confFile.close();
505
506   this->type = wxDIR_DIRS;
507   this->level = 0;
508
509   std::vector<bool> checked(this->children.size(), false);
510   std::vector<bool> checkedPackages(this->packages.size(), false);
511
512   //check all folders
513   wxDir dir(crea::std2wx((this->path).c_str()));
514   if (dir.IsOpened())
515     {
516       wxString fileName;
517       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
518       while (cont)
519         {
520           std::string stdfileName = crea::wx2std(fileName);
521
522           //if appli, create appli
523           if(stdfileName == "appli")
524             {
525               if (this->appli == NULL)
526                 {
527                   this->appli = new modelCDMAppli(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
528                   this->children.push_back(this->appli);
529                 }
530               else
531                 {
532                   int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
533                   checked[pos] = true;
534                   if(!this->appli->Refresh(result))
535                     return false;
536                 }
537             }
538           //if lib, create lib
539           else if(stdfileName == "lib")
540             {
541               if (this->lib == NULL)
542                 {
543                   this->lib = new modelCDMLib(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
544                   this->children.push_back(this->lib);
545                 }
546               else
547                 {
548                   int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
549                   checked[pos] = true;
550                   if(!this->lib->Refresh(result))
551                     return false;
552                 }
553
554             }
555           //if package , create package
556           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
557             {
558               bool found = false;
559               for (int i = 0; !found && i < this->packages.size(); i++)
560                 {
561                   if (this->packages[i]->GetName() == stdfileName)
562                     {
563                       found = true;
564                       int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
565                       checked[pos] = true;
566                       checkedPackages[i] = true;
567                       if(!this->packages[i]->Refresh(result))
568                         return false;
569                     }
570                 }
571               if(!found)
572                 {
573                   modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
574                   this->packages.push_back(package);
575                   this->children.push_back(package);
576                 }
577
578             }
579           //if is an unknown folder, create folder
580           else
581             {
582               bool found = false;
583               for (int i = 0; !found && i < this->children.size(); i++)
584                 {
585                   if (this->children[i]->GetName() == stdfileName)
586                     {
587                       found = true;
588                       checked[i] = true;
589                       if(!this->children[i]->Refresh(result))
590                         return false;
591                     }
592                 }
593
594               if(!found)
595                 {
596                   modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
597                   this->children.push_back(folder);
598                 }
599             }
600
601           cont = dir.GetNext(&fileName);
602         }
603
604       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
605       while (cont)
606         {
607           std::string stdfileName = crea::wx2std(fileName);
608
609           //if CMakeLists, create CMakeLists
610           if(stdfileName == "CMakeLists.txt")
611             {
612               if (this->CMakeLists == NULL)
613                 {
614                   this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
615                   this->children.push_back(this->CMakeLists);
616                 }
617               else
618                 {
619                   int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
620                   checked[pos] = true;
621                   if(!this->CMakeLists->Refresh(result))
622                     return false;
623                 }
624             }
625           //if is an unknown file, create file
626           else
627             {
628               bool found = false;
629               for (int i = 0; !found && i < this->children.size(); i++)
630                 {
631                   if (this->children[i]->GetName() == stdfileName)
632                     {
633                       found = true;
634                       checked[i] = true;
635                       if(!this->children[i]->Refresh(result))
636                         return false;
637                     }
638                 }
639
640               if(!found)
641                 {
642                   modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
643                   this->children.push_back(file);
644                 }
645             }
646
647           cont = dir.GetNext(&fileName);
648         }
649     }
650
651   for (int i = 0; i < checkedPackages.size(); i++)
652     {
653       if(!checkedPackages[i])
654         {
655           this->packages.erase(this->packages.begin()+i);
656           checkedPackages.erase(checkedPackages.begin()+i);
657           i--;
658         }
659     }
660   for (int i = 0; i < checked.size(); i++)
661     {
662       if(!checked[i])
663         {
664           delete this->children[i];
665           this->children.erase(this->children.begin()+i);
666           checked.erase(checked.begin()+i);
667           i--;
668         }
669     }
670
671   this->SortChildren();
672   std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
673   return true;
674 }
675
676 bool modelCDMProject::ConfigureBuild(std::string*& result)
677 {
678   //TODO: adjust for windows and mac
679 #ifdef _WIN32
680   // ------ Windows
681 #elif __APPLE__
682   // ------ Apple
683 #else
684   // ------ Linux
685   //open binary folder
686   wxDir dir(crea::std2wx((this->buildPath).c_str()));
687
688   //if folder doesn't exist then create it
689   if (!dir.IsOpened())
690     {
691       //create command line to create folder
692       std::string createComm = "mkdir \"" + this->buildPath + "\"";
693       //execute creation command
694       if (system(createComm.c_str()))
695         {
696           //if there was an error then report it
697           result = new std::string("There was an error creating the build path: \"" + this->buildPath + "\"");
698           return false;
699         }
700     }
701   //create command line to execute ccmake
702   //TODO:: adjust for different Linux distributions
703   std::string confComm = "gnome-terminal --tab --working-directory=\"" + this->buildPath + "\" -e \"ccmake '" + this->path + "'\"";
704   //execute command
705   if(CDMUtilities::openTerminal(confComm))
706     {
707       //if there was an error then report it
708       result = new std::string("There was an error opening the configuration tool in the desired place.");
709       return false;
710     }
711 #endif
712   return true;
713 }
714
715 bool modelCDMProject::Build(std::string*& result, const std::string& line)
716 {
717   //TODO: adjust for windows and mac
718 #ifdef _WIN32
719   // ------ Windows
720 #elif __APPLE__
721   // ------ Apple
722 #else
723   // ------ Linux
724   //open binary folder
725   wxDir dir(crea::std2wx((this->buildPath).c_str()));
726
727   //if binary folder can't be opened then return false
728   if (!dir.IsOpened())
729     {
730       result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
731       return false;
732     }
733   //create make command
734   std::string makeComm = "gnome-terminal -e \"bash -c \\\"";
735   for (int i = 0; i < line.size(); i++)
736     {
737       if(line[i] == '"')
738         {
739           makeComm+="\\\\\\\"";
740         }
741       else if(line[i] == '\\')
742         {
743           makeComm+="\\\\\\\\";
744         }
745       else
746         {
747           makeComm.push_back(line[i]);
748         }
749     }
750   makeComm += "; echo -e '\\a'; bash";
751   makeComm += "\\\"\"";
752
753   std::cout << "executing '" << makeComm << "'" << std::endl;
754   //execute make command
755   if(system(makeComm.c_str()))
756     {
757       //if there was an error then report it
758       result = new std::string("There was an error compiling the project, please check the \"building.log\" file located in the build folder to read more about the problem.");
759       return false;
760     }
761 #endif
762   return true;
763 }
764
765 bool modelCDMProject::Connect(std::string*& result)
766 {
767   //TODO: adjust for windows and mac
768 #ifdef _WIN32
769   // ------ Windows
770 #elif __APPLE__
771   // ------ Apple
772 #else
773   // ------ Linux
774   //open binary folder
775   wxDir dir(crea::std2wx((this->buildPath).c_str()));
776
777   //if binary folder can't be opened then return false
778   if (!dir.IsOpened())
779     {
780       result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
781       return false;
782     }
783   //create plug command
784   std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1";
785   std::cout << "executing '" << plugComm << "'" << std::endl;
786   //execute plug command
787   if(system(plugComm.c_str()))
788     {
789       //if there was an error then report it
790       result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
791       return false;
792     }
793 #endif
794   return true;
795 }
796
797 void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
798 {
799   //check cmake exist
800   if(this->CMakeLists != NULL)
801     {
802       //set properties parameters based on model
803       properties["project add appli"] = this->appli != NULL;
804       properties["project add lib"] = this->lib != NULL;
805       for (int i = 0; i < this->packages.size(); i++)
806         properties["project add " + packages[i]->GetName()] = false;
807
808       //open cmakelists
809       std::ifstream confFile;
810       confFile.open((this->CMakeLists->GetPath()).c_str());
811
812       //take everything that is not commented
813       std::string fileContent;
814
815       std::string word;
816       std::vector<std::string> words;
817       while(confFile.is_open() && !confFile.eof())
818         {
819           std::getline(confFile,word, '\n');
820           if(word[0] != '#')
821             {
822               CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
823               if (words.size() > 0)
824                 {
825                   word = words[0];
826                   CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
827                   for (int i = 0; i < words.size(); i++)
828                     {
829                       if(words[i].substr(0,2) == "//")
830                         break;
831                       fileContent += words[i] + " ";
832                     }
833                 }
834
835             }
836         }
837
838       //check every instruction
839       std::stringstream ss(fileContent);
840       while(!ss.eof())
841         {
842           std::getline(ss,word, '(');
843
844           //check instruction name
845           CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
846
847           //set instructions
848           if (words.size() > 0 && words[words.size()-1] == "SET")
849             {
850               std::getline(ss,word, ')');
851
852               CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
853               if (words.size() > 1)
854                 {
855                   if (words[0] == "USE_CREA" && words[1] == "ON")
856                     {
857                       properties["project set USE_CREA"] = true;
858                     }
859                   else if (words[0] == "USE_GDCM" && words[1] == "ON")
860                     {
861                       properties["project set USE_GDCM"] = true;
862                     }
863                   else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
864                     {
865                       properties["project set USE_GDCM_VTK"] = true;
866                     }
867                   else if (words[0] == "USE_GDCM2" && words[1] == "ON")
868                     {
869                       properties["project set USE_GDCM2"] = true;
870                     }
871                   else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
872                     {
873                       properties["project set USE_WXWIDGETS"] = true;
874                     }
875                   else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
876                     {
877                       properties["project set USE_KWWIDGETS"] = true;
878                     }
879                   else if (words[0] == "USE_VTK" && words[1] == "ON")
880                     {
881                       properties["project set USE_VTK"] = true;
882                     }
883                   else if (words[0] == "USE_ITK" && words[1] == "ON")
884                     {
885                       properties["project set USE_ITK"] = true;
886                     }
887                   else if (words[0] == "USE_BOOST" && words[1] == "ON")
888                     {
889                       properties["project set USE_BOOST"] = true;
890                     }
891                 }
892             }
893           //add instructions
894           else if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY")
895             {
896               std::getline(ss,word, ')');
897               //std::cout << word << std::endl;
898               CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
899
900               if (words.size() > 0)
901                 {
902                   if(words[0] == "appli")
903                     {
904                       properties["project add "+words[0]] = this->appli != NULL;
905                     }
906                   else if(words[0] == "lib")
907                     {
908                       properties["project add "+words[0]] = this->lib != NULL;
909                     }
910                   else
911                     {
912                       properties["project add "+words[0]] = true;
913                     }
914                 }
915             }
916         }
917
918     }
919
920   //check appli's structure
921   this->appli->CheckStructure(properties);
922   //check lib's structure
923   this->lib->CheckStructure(properties);
924   //check packages' structure
925   for (int i = 0; i < this->packages.size(); i++)
926     {
927       properties["package " + this->packages[i]->GetName()] = true;
928       this->packages[i]->CheckStructure(properties);
929     }
930 }