]> 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 <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 < (int)(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
265   tm ltm;
266 #ifdef _WIN32
267   localtime_s(&ltm, &now);
268 #else
269   ltm = *(localtime(&now));
270 #endif
271
272   std::stringstream date;
273   date << ltm.tm_mday << "/" << 1 + ltm.tm_mon << "/" << 1900 + ltm.tm_year;
274
275   //set name of library in CMakeLists inside copied folder
276   std::string line;
277   std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
278   if( !in.is_open())
279     {
280       result = new std::string("CMakeLists.txt file failed to open.");
281       return false;
282     }
283   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
284   if( !out.is_open())
285     {
286       result = new std::string("CMakeLists.txt.tmp file failed to open.");
287       return false;
288     }
289   while (getline(in, line))
290     {
291       if(line.find("SET(PROJECT_MAJOR_VERSION") != std::string::npos)
292         line = "SET(PROJECT_MAJOR_VERSION " + vers[0] + ")";
293       else if(line.find("SET(PROJECT_MINOR_VERSION") != std::string::npos)
294         line = "SET(PROJECT_MINOR_VERSION " + vers[1] + ")";
295       else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos)
296         line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")";
297       else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos)
298         line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
299       out << line << std::endl;
300     }
301   in.close();
302   out.close();
303   //delete old file and rename new file
304   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
305   if(system(renameCommand.c_str()))
306     {
307       result = new std::string("An error occurred while running '" + renameCommand + "'.");
308       return false;
309     }
310
311   this->version = vers[0] + "." + vers[1] + "." + vers[2];
312   this->versionDate = date.str();
313   return true;
314 }
315
316 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
317 {
318   if(path == "")
319     {
320       result = new std::string("The path cannot be empty");
321       return false;
322     }
323   if(path == this->path)
324     {
325       result = new std::string("The path cannot be same as the project sources");
326       return false;
327     }
328   this->buildPath = path;
329   return true;
330 }
331
332 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
333     const std::string& name,
334     std::string*& result,
335     const std::string& authors,
336     const std::string& authorsEmail,
337     const std::string& description,
338     const std::string& version
339 )
340 {
341   //fixing input parameters
342   std::vector<std::string> words;
343
344   CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties);
345   std::string nameFixed = "";
346   for (int i = 0; i < (int)(words.size()); i++)
347     {
348       nameFixed += words[i];
349     }
350
351   words.clear();
352   CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties);
353   std::string authorFixed;
354   for (int i = 0; i < (int)(words.size()); i++)
355     {
356       authorFixed += words[i];
357     }
358
359   words.clear();
360   std::string descriptionFixed;
361   CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties);
362   for (int i = 0; i < (int)(words.size()); i++)
363     {
364       descriptionFixed += words[i];
365     }
366   words.clear();
367   CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties);
368   for (int i = 0; i < (int)(words.size()); i++)
369     {
370       descriptionFixed += "_" + words[i];
371     }
372
373   //call project to create package : use bbCreatePackage <path> <name> [author] [description]
374   std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
375   //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
376   if(system(creationCommand.c_str()))
377     {
378       result = new std::string("An error occurred while running '" + creationCommand + "'.");
379       return NULL;
380     }
381
382   //add library to model
383   modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
384   this->packages.push_back(package);
385   this->children.push_back(package);
386
387   //TODO: set package version
388
389   this->SortChildren();
390
391   result = new std::string(this->path + CDMUtilities::SLASH + name);
392   return package;
393 }
394
395 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
396     const std::string& name,
397     std::string*& result,
398     const std::string& path
399 )
400 {
401   if(this->lib != NULL)
402     {
403       return this->lib->CreateLibrary(name, result);
404     }
405   result = new std::string("there is no lib folder in this project.");
406   return NULL;
407 }
408
409 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
410     const std::string& name,
411     std::string*& result,
412     const std::string& path
413 )
414 {
415   if(this->appli != NULL)
416     {
417       return this->appli->CreateApplication(name, result);
418     }
419   result = new std::string("there is no appli folder in this project.");
420   return NULL;
421 }
422
423 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
424     const std::string& name,
425     const std::string& package,
426     const std::string& authors,
427     const std::string& authorsEmail,
428     const std::string& categories,
429     const std::string& description
430 )
431 {
432   //TODO: implement method
433   return NULL;
434 }
435
436 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
437 {
438   if (!CDMUtilities::openTextEditor(this->CMakeLists->GetPath()))
439     return true;
440   else
441     {
442       result = new std::string("Couldn't open CMakeLists file.");
443       return false;
444     }
445 }
446
447 const bool modelCDMProject::Refresh(std::string*& result)
448 {
449   std::cout << "refreshing project" << std::endl;
450   //open makelists file
451   std::string pathMakeLists = this->path + CDMUtilities::SLASH + "CMakeLists.txt";
452
453   std::ifstream confFile;
454   confFile.open((pathMakeLists).c_str());
455
456   std::string word;
457   while(confFile.is_open() && !confFile.eof())
458     {
459       //std::cout << "leyendo " << word << std::endl;
460       //get project name
461       std::getline(confFile,word,'(');
462       std::vector<std::string> wordBits;
463       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
464
465       if(wordBits[wordBits.size()-1] == "PROJECT")
466         {
467           std::getline(confFile,word,')');
468           std::vector<std::string> nameBits;
469           CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
470
471           this->name = this->nameProject = "";
472           for (int i = 0; i < (int)(nameBits.size()); i++)
473             {
474               if(i != 0)
475                 this->name += " ";
476               this->name += nameBits[i];
477             }
478           this->nameProject = this->name;
479
480         }
481
482
483       if(wordBits[wordBits.size()-1] == "SET")
484         {
485           //get project version
486           std::getline(confFile,word,')');
487           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
488           if(wordBits[0] == "PROJECT_MAJOR_VERSION")
489             {
490               version = wordBits[1];
491             }
492           if(wordBits[0] == "PROJECT_MINOR_VERSION")
493             {
494               version += "." + wordBits[1];
495             }
496           if(wordBits[0] == "PROJECT_BUILD_VERSION")
497             {
498               version += "." + wordBits[1];
499             }
500
501           //get project versionDate
502           if(wordBits[0] == "PROJECT_VERSION_DATE")
503             {
504               std::vector<std::string> versionBits;
505               CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
506               versionDate = versionBits[0];
507             }
508         }
509     }
510   confFile.close();
511
512   this->type = wxDIR_DIRS;
513   this->level = 0;
514
515   std::vector<bool> checked(this->children.size(), false);
516   std::vector<bool> checkedPackages(this->packages.size(), false);
517
518   //check all folders
519   wxDir dir(crea::std2wx((this->path).c_str()));
520   if (dir.IsOpened())
521     {
522       wxString fileName;
523       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
524       while (cont)
525         {
526           std::string stdfileName = crea::wx2std(fileName);
527
528           //if appli, create appli
529           if(stdfileName == "appli")
530             {
531               if (this->appli == NULL)
532                 {
533                   this->appli = new modelCDMAppli(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
534                   this->children.push_back(this->appli);
535                 }
536               else
537                 {
538                   int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
539                   checked[pos] = true;
540                   if(!this->appli->Refresh(result))
541                     return false;
542                 }
543             }
544           //if lib, create lib
545           else if(stdfileName == "lib")
546             {
547               if (this->lib == NULL)
548                 {
549                   this->lib = new modelCDMLib(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
550                   this->children.push_back(this->lib);
551                 }
552               else
553                 {
554                   int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
555                   checked[pos] = true;
556                   if(!this->lib->Refresh(result))
557                     return false;
558                 }
559
560             }
561           //if package , create package
562           else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
563             {
564               bool found = false;
565               for (int i = 0; !found && i < (int)(this->packages.size()); i++)
566                 {
567                   if (this->packages[i]->GetName() == stdfileName)
568                     {
569                       found = true;
570                       int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
571                       checked[pos] = true;
572                       checkedPackages[i] = true;
573                       if(!this->packages[i]->Refresh(result))
574                         return false;
575                     }
576                 }
577               if(!found)
578                 {
579                   modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
580                   this->packages.push_back(package);
581                   this->children.push_back(package);
582                 }
583
584             }
585           //if is an unknown folder, create folder
586           else
587             {
588               bool found = false;
589               for (int i = 0; !found && i < (int)(this->children.size()); i++)
590                 {
591                   if (this->children[i]->GetName() == stdfileName)
592                     {
593                       found = true;
594                       checked[i] = true;
595                       if(!this->children[i]->Refresh(result))
596                         return false;
597                     }
598                 }
599
600               if(!found)
601                 {
602                   modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
603                   this->children.push_back(folder);
604                 }
605             }
606
607           cont = dir.GetNext(&fileName);
608         }
609
610       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
611       while (cont)
612         {
613           std::string stdfileName = crea::wx2std(fileName);
614
615           //if CMakeLists, create CMakeLists
616           if(stdfileName == "CMakeLists.txt")
617             {
618               if (this->CMakeLists == NULL)
619                 {
620                   this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
621                   this->children.push_back(this->CMakeLists);
622                 }
623               else
624                 {
625                   int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
626                   checked[pos] = true;
627                   if(!this->CMakeLists->Refresh(result))
628                     return false;
629                 }
630             }
631           //if is an unknown file, create file
632           else
633             {
634               bool found = false;
635               for (int i = 0; !found && i < (int)(this->children.size()); i++)
636                 {
637                   if (this->children[i]->GetName() == stdfileName)
638                     {
639                       found = true;
640                       checked[i] = true;
641                       if(!this->children[i]->Refresh(result))
642                         return false;
643                     }
644                 }
645
646               if(!found)
647                 {
648                   modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
649                   this->children.push_back(file);
650                 }
651             }
652
653           cont = dir.GetNext(&fileName);
654         }
655     }
656
657   for (int i = 0; i < (int)(checkedPackages.size()); i++)
658     {
659       if(!checkedPackages[i])
660         {
661           this->packages.erase(this->packages.begin()+i);
662           checkedPackages.erase(checkedPackages.begin()+i);
663           i--;
664         }
665     }
666   for (int i = 0; i < (int)(checked.size()); i++)
667     {
668       if(!checked[i])
669         {
670           delete this->children[i];
671           this->children.erase(this->children.begin()+i);
672           checked.erase(checked.begin()+i);
673           i--;
674         }
675     }
676
677   this->SortChildren();
678   std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
679   return true;
680 }
681
682 bool modelCDMProject::ConfigureBuild(std::string*& result)
683 {
684   //TODO: adjust for windows and mac
685 #ifdef _WIN32
686   // ------ Windows
687 #elif __APPLE__
688   // ------ Apple
689 #else
690   // ------ Linux
691   //open binary folder
692   wxDir dir(crea::std2wx((this->buildPath).c_str()));
693
694   //if folder doesn't exist then create it
695   if (!dir.IsOpened())
696     {
697       //create command line to create folder
698       std::string createComm = "mkdir \"" + this->buildPath + "\"";
699       //execute creation command
700       if (system(createComm.c_str()))
701         {
702           //if there was an error then report it
703           result = new std::string("There was an error creating the build path: \"" + this->buildPath + "\"");
704           return false;
705         }
706     }
707   //create command line to execute ccmake
708   //TODO:: adjust for different Linux distributions
709   std::string confComm = "gnome-terminal --tab --working-directory=\"" + this->buildPath + "\" -e \"ccmake '" + this->path + "'\"";
710   //execute command
711   if(CDMUtilities::openTerminal(confComm))
712     {
713       //if there was an error then report it
714       result = new std::string("There was an error opening the configuration tool in the desired place.");
715       return false;
716     }
717 #endif
718   return true;
719 }
720
721 bool modelCDMProject::Build(std::string*& result, const std::string& line)
722 {
723   //TODO: adjust for windows and mac
724 #ifdef _WIN32
725   // ------ Windows
726 #elif __APPLE__
727   // ------ Apple
728 #else
729   // ------ Linux
730   //open binary folder
731   wxDir dir(crea::std2wx((this->buildPath).c_str()));
732
733   //if binary folder can't be opened then return false
734   if (!dir.IsOpened())
735     {
736       result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
737       return false;
738     }
739   //create make command
740   std::string makeComm = "gnome-terminal -e \"bash -c \\\"";
741   for (int i = 0; i < line.size(); i++)
742     {
743       if(line[i] == '"')
744         {
745           makeComm+="\\\\\\\"";
746         }
747       else if(line[i] == '\\')
748         {
749           makeComm+="\\\\\\\\";
750         }
751       else
752         {
753           makeComm.push_back(line[i]);
754         }
755     }
756   makeComm += "; echo -e '\\a'; bash";
757   makeComm += "\\\"\"";
758
759   std::cout << "executing '" << makeComm << "'" << std::endl;
760   //execute make command
761   if(system(makeComm.c_str()))
762     {
763       //if there was an error then report it
764       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.");
765       return false;
766     }
767 #endif
768   return true;
769 }
770
771 bool modelCDMProject::Connect(std::string*& result)
772 {
773   //TODO: adjust for windows and mac
774 #ifdef _WIN32
775   // ------ Windows
776 #elif __APPLE__
777   // ------ Apple
778 #else
779   // ------ Linux
780   //open binary folder
781   wxDir dir(crea::std2wx((this->buildPath).c_str()));
782
783   //if binary folder can't be opened then return false
784   if (!dir.IsOpened())
785     {
786       result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
787       return false;
788     }
789   //create plug command
790   std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1";
791   std::cout << "executing '" << plugComm << "'" << std::endl;
792   //execute plug command
793   if(system(plugComm.c_str()))
794     {
795       //if there was an error then report it
796       result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
797       return false;
798     }
799 #endif
800   return true;
801 }
802
803 void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
804 {
805   //check cmake exist
806   if(this->CMakeLists != NULL)
807     {
808       //set properties parameters based on model
809       properties["project add appli"] = this->appli != NULL;
810       properties["project add lib"] = this->lib != NULL;
811       for (int i = 0; i < (int)(this->packages.size()); i++)
812         properties["project add " + packages[i]->GetName()] = false;
813
814       //open cmakelists
815       std::ifstream confFile;
816       confFile.open((this->CMakeLists->GetPath()).c_str());
817
818       //take everything that is not commented
819       std::string fileContent;
820
821       std::string word;
822       std::vector<std::string> words;
823       while(confFile.is_open() && !confFile.eof())
824         {
825           std::getline(confFile,word, '\n');
826           if(word[0] != '#')
827             {
828               CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
829               if (words.size() > 0)
830                 {
831                   word = words[0];
832                   CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
833                   for (int i = 0; i < (int)(words.size()); i++)
834                     {
835                       if(words[i].substr(0,2) == "//")
836                         break;
837                       fileContent += words[i] + " ";
838                     }
839                 }
840
841             }
842         }
843
844       //check every instruction
845       std::stringstream ss(fileContent);
846       while(!ss.eof())
847         {
848           std::getline(ss,word, '(');
849
850           //check instruction name
851           CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
852
853           //set instructions
854           if (words.size() > 0 && words[words.size()-1] == "SET")
855             {
856               std::getline(ss,word, ')');
857
858               CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
859               if (words.size() > 1)
860                 {
861                   if (words[0] == "USE_CREA" && words[1] == "ON")
862                     {
863                       properties["project set USE_CREA"] = true;
864                     }
865                   else if (words[0] == "USE_GDCM" && words[1] == "ON")
866                     {
867                       properties["project set USE_GDCM"] = true;
868                     }
869                   else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
870                     {
871                       properties["project set USE_GDCM_VTK"] = true;
872                     }
873                   else if (words[0] == "USE_GDCM2" && words[1] == "ON")
874                     {
875                       properties["project set USE_GDCM2"] = true;
876                     }
877                   else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
878                     {
879                       properties["project set USE_WXWIDGETS"] = true;
880                     }
881                   else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
882                     {
883                       properties["project set USE_KWWIDGETS"] = true;
884                     }
885                   else if (words[0] == "USE_VTK" && words[1] == "ON")
886                     {
887                       properties["project set USE_VTK"] = true;
888                     }
889                   else if (words[0] == "USE_ITK" && words[1] == "ON")
890                     {
891                       properties["project set USE_ITK"] = true;
892                     }
893                   else if (words[0] == "USE_BOOST" && words[1] == "ON")
894                     {
895                       properties["project set USE_BOOST"] = true;
896                     }
897                 }
898             }
899           //add instructions
900           else if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY")
901             {
902               std::getline(ss,word, ')');
903               //std::cout << word << std::endl;
904               CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
905
906               if (words.size() > 0)
907                 {
908                   if(words[0] == "appli")
909                     {
910                       properties["project add "+words[0]] = this->appli != NULL;
911                     }
912                   else if(words[0] == "lib")
913                     {
914                       properties["project add "+words[0]] = this->lib != NULL;
915                     }
916                   else
917                     {
918                       properties["project add "+words[0]] = true;
919                     }
920                 }
921             }
922         }
923
924     }
925
926   //check appli's structure
927   this->appli->CheckStructure(properties);
928   //check lib's structure
929   this->lib->CheckStructure(properties);
930   //check packages' structure
931   for (int i = 0; i < (int)(this->packages.size()); i++)
932     {
933       properties["package " + this->packages[i]->GetName()] = true;
934       this->packages[i]->CheckStructure(properties);
935     }
936 }