]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMPackage.cpp
c6ea443d6d516e0e00b72c65cefe38f3c7f4ef79
[crea.git] / lib / creaDevManagerLib / modelCDMPackage.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  * modelCDMPackage.cpp
30  *
31  *  Created on: Nov 23, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "modelCDMPackage.h"
36
37 #include <fstream>
38 #include <sstream>
39 #include <algorithm>
40
41 #include "creaWx.h"
42 #include "wx/dir.h"
43 #include "CDMUtilities.h"
44
45 modelCDMPackage::modelCDMPackage()
46 {
47   this->src = NULL;
48 }
49
50 modelCDMPackage::modelCDMPackage(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
51 {
52   std::cout << "creating package: " + path + "\n";
53   this->parent = parent;
54   this->type = wxDIR_DIRS;
55   this->name = name;
56   //Get Package Name
57
58   std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
59
60   std::ifstream confFile;
61   confFile.open((pathMakeLists).c_str());
62
63   std::string word;
64   while(confFile.is_open() && !confFile.eof())
65     {
66       //get sets
67       std::getline(confFile,word,'(');
68       std::vector<std::string> wordBits;
69       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
70
71       if(wordBits[wordBits.size()-1] == "SET")
72         {
73           //get package name
74           std::getline(confFile,word,')');
75           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
76           if(wordBits[0] == "BBTK_PACKAGE_NAME")
77             {
78               word = wordBits[1];
79               for (int i = 2; i < (int)(wordBits.size()); i++)
80                 {
81                   word += " " + wordBits[i];
82                 }
83               wordBits.clear();
84               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
85
86               this->namePackage = wordBits[0];
87             }
88           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
89             {
90               word = wordBits[1];
91               for (int i = 2; i < (int)(wordBits.size()); i++)
92                 {
93                   word += " " + wordBits[i];
94                 }
95               wordBits.clear();
96               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
97
98               this->authors = wordBits[0];
99             }
100           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
101             {
102               word = wordBits[1];
103               for (int i = 2; i < (int)(wordBits.size()); i++)
104                 {
105                   word += " " + wordBits[i];
106                 }
107               wordBits.clear();
108               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
109
110               this->description = wordBits[0];
111             }
112           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
113             {
114               this->version = wordBits[1];
115             }
116           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
117             {
118               this->version += "." + wordBits[1];
119             }
120           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
121             {
122               this->version += "." + wordBits[1];
123             }
124         }
125     }
126
127   this->level = level;
128   this->path = path;
129
130   //check all folders and files
131   wxDir dir(crea::std2wx((path).c_str()));
132   if (dir.IsOpened())
133     {
134       wxString fileName;
135
136       //folders
137       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
138       while (cont)
139         {
140           std::string stdfileName = crea::wx2std(fileName);
141           //if src, check for black boxes
142           if(stdfileName == "src")
143             {
144               this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
145               this->children.push_back(this->src);
146             }
147           else
148             {
149               this->children.push_back(new modelCDMFolder(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
150             }
151
152           cont = dir.GetNext(&fileName);
153         }
154
155       //files
156       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
157       while (cont)
158         {
159           std::string stdfileName = crea::wx2std(fileName);
160
161           //if CMakeLists, create CMakeLists
162           if(stdfileName == "CMakeLists.txt")
163             {
164               this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
165               this->children.push_back(this->CMakeLists);
166             }
167           else
168             {
169               this->children.push_back(new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
170             }
171           //if is an unknown file, create file
172           cont = dir.GetNext(&fileName);
173         }
174     }
175   this->SortChildren();
176 }
177
178 modelCDMPackage::~modelCDMPackage()
179 {
180 }
181
182 const std::string& modelCDMPackage::GetNamePackage() const
183 {
184   return this->namePackage;
185 }
186
187 const std::string& modelCDMPackage::GetAuthors() const
188 {
189   return this->authors;
190 }
191
192 const std::string& modelCDMPackage::GetAuthorsEmail() const
193 {
194   return this->authorsEmail;
195 }
196
197 const std::string& modelCDMPackage::GetVersion() const
198 {
199   return this->version;
200 }
201
202 const std::string& modelCDMPackage::GetDescription() const
203 {
204   return this->description;
205 }
206
207 modelCDMPackageSrc* modelCDMPackage::GetSrc() const
208 {
209   return this->src;
210 }
211
212 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
213 {
214   std::vector<std::string> words;
215   CDMUtilities::splitter::split(words, authors, ",\n", CDMUtilities::splitter::no_empties);
216   std::string authorsReal = words[0];
217   for (int i = 1; i < (int)(words.size()); i++)
218     {
219       authorsReal += "/" + words[i];
220     }
221
222   std::string line;
223   //opening original cmakelists
224   std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
225   if( !in.is_open())
226     {
227       result = new std::string("CMakeLists.txt file failed to open.");
228       return false;
229     }
230   //opening temporal cmakelists
231   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
232   if( !out.is_open())
233     {
234       result = new std::string("CMakeLists.txt.tmp file failed to open.");
235       return false;
236     }
237   //copying contents from original to temporal and making changes
238   while (getline(in, line))
239     {
240       if(line.find("SET(${BBTK_PACKAGE_NAME}_AUTHOR") != std::string::npos)
241         line = "SET(${BBTK_PACKAGE_NAME}_AUTHOR \"" + authorsReal + "\")";
242       out << line << std::endl;
243     }
244   in.close();
245   out.close();
246   //delete old file and rename new file
247 #ifdef _WIN32
248   std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
249 #else
250   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
251 #endif
252   
253   if(system(renameCommand.c_str()))
254     {
255       result = new std::string("An error occurred while running '" + renameCommand + "'.");
256       return false;
257     }
258
259   this->authors = authorsReal;
260   return true;
261 }
262
263 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
264 {
265   //TODO: implement method
266   return true;
267 }
268
269 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
270 {
271   std::vector<std::string> vers;
272   CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
273
274
275   std::string line;
276   //opening original cmakelists
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   //opening temporal cmakelists
284   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
285   if( !out.is_open())
286     {
287       result = new std::string("CMakeLists.txt.tmp file failed to open.");
288       return false;
289     }
290   //copying contents from original to temporal and making changes
291   while (getline(in, line))
292     {
293       if(line.find("SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION") != std::string::npos)
294         line = "SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION " + vers[0] + ")";
295       else if(line.find("SET(${BBTK_PACKAGE_NAME}_VERSION") != std::string::npos)
296         line = "SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION " + vers[1] + ")";
297       else if(line.find("SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION") != std::string::npos)
298         line = "SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION " + vers[2] + ")";
299       out << line << std::endl;
300     }
301   in.close();
302   out.close();
303   //delete old file and rename new file
304 #ifdef _WIN32
305   std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
306 #else
307   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
308 #endif
309   
310   if(system(renameCommand.c_str()))
311     {
312       result = new std::string("An error occurred while running '" + renameCommand + "'.");
313       return false;
314     }
315
316   this->version = vers[0] + "." + vers[1] + "." + vers[2];
317   return true;
318 }
319
320 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
321 {
322   std::vector<std::string> words;
323   CDMUtilities::splitter::split(words, description, " \n", CDMUtilities::splitter::no_empties);
324   std::string descriptionReal = words[0];
325   for (int i = 1; i < (int)(words.size()); i++)
326     {
327       descriptionReal += " " + words[i];
328     }
329
330   std::string line;
331   //opening original cmakelists
332   std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
333   if( !in.is_open())
334     {
335       result = new std::string("CMakeLists.txt file failed to open.");
336       return false;
337     }
338   //opening temporal cmakelists
339   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
340   if( !out.is_open())
341     {
342       result = new std::string("CMakeLists.txt.tmp file failed to open.");
343       return false;
344     }
345   //copying contents from original to temporal and making changes
346   while (getline(in, line))
347     {
348       if(line.find("SET(${BBTK_PACKAGE_NAME}_DESCRIPTION") != std::string::npos)
349         line = "SET(${BBTK_PACKAGE_NAME}_DESCRIPTION \"" + descriptionReal + "\")";
350       out << line << std::endl;
351     }
352   in.close();
353   out.close();
354   //delete old file and rename new file
355 #ifdef _WIN32
356   std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
357 #else
358   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
359 #endif
360   
361   if(system(renameCommand.c_str()))
362     {
363       result = new std::string("An error occurred while running '" + renameCommand + "'.");
364       return false;
365     }
366
367   this->description = descriptionReal;
368   return true;
369 }
370
371 modelCDMBlackBox* modelCDMPackage::CreateBlackBox(
372     std::string*& result,
373     const std::string& name,
374     const std::string& type,
375     const std::string& format,
376     const std::string& categories,
377     const std::string& authors,
378     const std::string& authorsEmail,
379     const std::string& description
380 )
381 {
382   return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description);
383 }
384
385 const bool modelCDMPackage::Refresh(std::string*& result)
386 {
387   std::cout << "refreshing package " << this->namePackage << std::endl;
388   this->type = wxDIR_DIRS;
389
390   //Get Package Name
391
392   std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
393
394   std::ifstream confFile;
395   confFile.open((pathMakeLists).c_str());
396
397   std::string word;
398   while(confFile.is_open() && !confFile.eof())
399     {
400       //get sets
401       std::getline(confFile,word,'(');
402       std::vector<std::string> wordBits;
403       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
404
405       if(wordBits[wordBits.size()-1] == "SET")
406         {
407           //get package name
408           std::getline(confFile,word,')');
409           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
410           if(wordBits[0] == "BBTK_PACKAGE_NAME")
411             {
412               word = wordBits[1];
413               for (int i = 2; i < (int)(wordBits.size()); i++)
414                 {
415                   word += " " + wordBits[i];
416                 }
417               wordBits.clear();
418               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
419
420               this->namePackage = wordBits[0];
421             }
422           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
423             {
424               word = wordBits[1];
425               for (int i = 2; i < (int)(wordBits.size()); i++)
426                 {
427                   word += " " + wordBits[i];
428                 }
429               wordBits.clear();
430               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
431
432               this->authors = wordBits[0];
433             }
434           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
435             {
436               word = wordBits[1];
437               for (int i = 2; i < (int)(wordBits.size()); i++)
438                 {
439                   word += " " + wordBits[i];
440                 }
441               wordBits.clear();
442               CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
443
444               this->description = wordBits[0];
445             }
446           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
447             {
448               this->version = wordBits[1];
449             }
450           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
451             {
452               this->version += "." + wordBits[1];
453             }
454           else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
455             {
456               this->version += "." + wordBits[1];
457             }
458         }
459     }
460
461
462
463   std::vector<bool> checked(this->children.size(), false);
464   bool checkedSrc = false;
465
466   //check all folders
467   wxDir dir(crea::std2wx((this->path).c_str()));
468   if (dir.IsOpened())
469     {
470       wxString fileName;
471       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
472       while (cont)
473         {
474
475           std::string stdfileName = crea::wx2std(fileName);
476
477           //detect black boxes in src
478           if(stdfileName == "src")
479             {
480               //check if box already exist
481               bool found = false;
482               if (this->src != NULL)
483                 {
484                   found = true;
485                   int pos = std::find(this->children.begin(), this->children.end(), this->src) - this->children.begin();
486                   checked[pos] = true;
487                   checkedSrc = true;
488                   if(!this->src->Refresh(result))
489                     return false;
490                 }
491               else
492                 {
493                   this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level +1);
494                   this->children.push_back(this->src);
495                 }
496             }
497           else
498             {
499
500               //check if folder already exist
501               bool found = false;
502               for (int i = 0; !found && i < (int)(this->children.size()); i++)
503                 {
504                   if (this->children[i]->GetName() == stdfileName)
505                     {
506                       found = true;
507                       checked[i] = true;
508                       if(!this->children[i]->Refresh(result))
509                         return false;
510                     }
511                 }
512               if(!found)
513                 {
514                   modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
515                   this->children.push_back(folder);
516                 }
517             }
518           cont = dir.GetNext(&fileName);
519
520         }
521
522       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
523       while (cont)
524         {
525           std::string stdfileName = crea::wx2std(fileName);
526
527           //if CMakeLists, create CMakeLists
528           if(stdfileName == "CMakeLists.txt")
529             {
530               if (this->CMakeLists == NULL)
531                 {
532                   this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
533                   this->children.push_back(this->CMakeLists);
534                 }
535               else
536                 {
537                   int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
538                   checked[pos] = true;
539                   if(!this->CMakeLists->Refresh(result))
540                     return false;
541                 }
542             }
543           //if is an unknown file, create file
544           else
545             {
546               bool found = false;
547               for (int i = 0; !found && i < (int)(this->children.size()); i++)
548                 {
549                   if (this->children[i]->GetName() == stdfileName)
550                     {
551                       found = true;
552                       checked[i] = true;
553                       if(!this->children[i]->Refresh(result))
554                         return false;
555                     }
556                 }
557
558               if(!found)
559                 {
560                   modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
561                   this->children.push_back(file);
562                 }
563             }
564
565           cont = dir.GetNext(&fileName);
566         }
567     }
568
569   if(!checkedSrc)
570     {
571       this->src = NULL;
572     }
573
574   for (int i = 0; i < (int)(checked.size()); i++)
575     {
576       if(!checked[i])
577         {
578           delete this->children[i];
579           this->children.erase(this->children.begin()+i);
580           checked.erase(checked.begin()+i);
581           i--;
582         }
583     }
584   this->SortChildren();
585   return true;
586 }
587
588 void modelCDMPackage::CheckStructure(std::map<std::string, bool>& properties)
589 {
590   //check cmake exist
591   if(this->CMakeLists != NULL)
592     {
593       //open cmakelists
594       std::ifstream confFile;
595       confFile.open((this->CMakeLists->GetPath()).c_str());
596
597       //take everything that is not commented
598       std::string fileContent;
599
600       std::string word;
601       std::vector<std::string> words;
602       while(confFile.is_open() && !confFile.eof())
603         {
604           std::getline(confFile,word, '\n');
605           if(word[0] != '#')
606             {
607               CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
608               if (words.size() > 0)
609                 {
610                   word = words[0];
611                   CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
612                   for (int i = 0; i < (int)(words.size()); i++)
613                     {
614                       if(words[i].substr(0,2) == "//")
615                         break;
616                       fileContent += words[i] + " ";
617                     }
618                 }
619             }
620         }
621
622       //check every instruction
623       std::stringstream ss(fileContent);
624       while(!ss.eof())
625         {
626           std::getline(ss,word, '(');
627
628           //check instruction name
629           CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
630
631           //set instructions
632           if (words.size() > 0 && words[words.size()-1] == "SET")
633             {
634               std::getline(ss,word, ')');
635
636               CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
637               if (words.size() > 1)
638                 {
639                   if (words[0] == "${BBTK_PACKAGE_NAME}_USE_VTK" && words[1] == "ON")
640                     {
641                       properties["package " + this->name + " set USE_VTK"] = true;
642                     }
643                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_ITK" && words[1] == "ON")
644                     {
645                       properties["package " + this->name + " set USE_ITK"] = true;
646                     }
647                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM" && words[1] == "ON")
648                     {
649                       properties["package " + this->name + " set USE_GDCM"] = true;
650                     }
651                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK" && words[1] == "ON")
652                     {
653                       properties["package " + this->name + " set USE_GDCM_VTK"] = true;
654                     }
655                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GSMIS" && words[1] == "ON")
656                     {
657                       properties["package " + this->name + " set USE_GSMIS"] = true;
658                     }
659                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS" && words[1] == "ON")
660                     {
661                       properties["package " + this->name + " set USE_WXWIDGETS"] = true;
662                     }
663                   else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS" && words[1] == "ON")
664                     {
665                       properties["package " + this->name + " set USE_KWWIDGETS"] = true;
666                     }
667                   else if (words[0] == "USE_BOOST" && words[1] == "ON")
668                     {
669                       properties["package " + this->name + " set USE_BOOST"] = true;
670                     }
671                   else if (words[0] == "${BBTK_PACKAGE_NAME}_INCLUDE_DIRS")
672                     {
673                       for (int i = 1; i < (int)(words.size()); i++)
674                         {
675                           if(words[i].substr(0,2) == "${" || words[i].substr(0,2) == "..")
676                           properties["package " + this->name + " dir " + words[i]] = true;
677                         }
678                     }
679                   else if (words[0] == "${BBTK_PACKAGE_NAME}_LIBS")
680                     {
681                       for (int i = 1; i < (int)(words.size()); i++)
682                         {
683                           properties["package " + this->name + " lib " + words[i]] = true;
684                         }
685                     }
686                 }
687             }
688         }
689
690     }
691 }
692
693 std::map<std::string, bool> modelCDMPackage::Get3rdPartyLibraries()
694 {
695   std::map<std::string, std::string> correspondence;
696   correspondence["${BBTK_PACKAGE_NAME}_USE_VTK"] = "VTK";
697   correspondence["${BBTK_PACKAGE_NAME}_USE_ITK"] = "ITK";
698   correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM"] = "GDCM";
699   correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM_VTK"] = "GDCM_VTK";
700   correspondence["${BBTK_PACKAGE_NAME}_USE_GSMIS"] = "GSMIS";
701   correspondence["${BBTK_PACKAGE_NAME}_USE_WXWIDGETS"] = "WxWidgets";
702   correspondence["${BBTK_PACKAGE_NAME}_USE_KWWIDGETS"] = "KWWidgets";
703   std::map<std::string, bool> res;
704   res["VTK"] = false;
705   res["ITK"] = false;
706   res["GDCM"] = false;
707   res["GDCM_VTK"] = false;
708   res["GSMIS"] = false;
709   res["WxWidgets"] = false;
710   res["KWWidgets"] = false;
711
712   if (this->HasCMakeLists())
713     {
714       CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
715       // look at every syntax element
716       for (int i = 0; i < cmlFile.size(); ++i)
717         {
718           // if the element is a command and is a SET command
719           if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
720             {
721               // search first parameter
722               int pos = 1;
723               while (pos < cmlFile[i].second.size())
724                 {
725                   if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
726                     {
727                       break;
728                     }
729                   pos++;
730                 }
731               // if the first parameter is a third party statement
732               if (pos < cmlFile[i].second.size() && correspondence.find(cmlFile[i].second[pos]) != correspondence.end())
733                 {
734                   std::string foundLibrary = cmlFile[i].second[pos];
735                   // search for second parameter
736                   pos++;
737                   while (pos < cmlFile[i].second.size())
738                     {
739                       if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
740                         {
741                           break;
742                         }
743                       pos++;
744                     }
745                   // if the second parameter is ON
746                   if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "ON")
747                     {
748                       res[correspondence[foundLibrary]] = true;
749                     }
750                 }
751             }
752         }
753     }
754   return res;
755 }
756
757 bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name,
758     const bool& toInclude)
759 {
760   std::map<std::string, std::string> correspondence;
761
762   correspondence["VTK"] = "${BBTK_PACKAGE_NAME}_USE_VTK";
763   correspondence["ITK"] = "${BBTK_PACKAGE_NAME}_USE_ITK";
764   correspondence["GDCM"] = "${BBTK_PACKAGE_NAME}_USE_GDCM";
765   correspondence["GDCM_VTK"] = "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK";
766   correspondence["GSMIS"] = "${BBTK_PACKAGE_NAME}_USE_GSMIS";
767   correspondence["WxWidgets"] = "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS";
768   correspondence["KWWidgets"] = "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS";
769 /*
770   if(correspondence.find(library_name) != correspondence.end())
771     {
772       std::string library_command = correspondence[library_name];
773       if (this->HasCMakeLists())
774         {
775           CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
776           bool found = false;
777           // look at every syntax element
778           for (int i = 0; i < cmlFile.size(); ++i)
779             {
780               // if the element is a command and is a SET command
781               if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
782                 {
783                   // search first parameter
784                   int pos = 1;
785                   while (pos < cmlFile[i].second.size())
786                     {
787                       if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
788                         {
789                           break;
790                         }
791                       pos++;
792                     }
793                   // if the first parameter is a third party statement
794                   if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == library_command)
795                     {
796                       std::string foundLibrary = cmlFile[i].second[pos];
797                       // search for second parameter
798                       pos++;
799                       while (pos < cmlFile[i].second.size())
800                         {
801                           if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
802                             {
803                               break;
804                             }
805                           pos++;
806                         }
807                       // if the second parameter is ON
808                       if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "ON")
809                         {
810                           found = true;
811                           if (toInclude)
812                             {
813                               std::cout << "library already included: " << library_name << std::endl;
814                             }
815                           else
816                             {
817                               cmlFile[i].first = "comment";
818                               cmlFile[i].second[0] = "#" + cmlFile[i].second[0];
819                               std::cout << "library include commented: " << library_name << std::endl;
820                             }
821                         }
822                       else if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "OFF")
823                         {
824                           found = true;
825                           if (toInclude)
826                             {
827                               cmlFile[i].second[pos] = "ON";
828                               std::cout << "library include activated: " << library_name << std::endl;
829                             }
830                           else
831                             {
832                               std::cout << "library include already disabled: " << library_name << std::endl;
833                             }
834                         }
835                     }
836                 } else if (cmlFile[i].first == "comment") {
837                     //TODO: check if it is commented
838                 }
839             }
840         }
841     }
842 */
843   return false;
844 }
845
846 std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
847 {
848   std::map<std::string, bool> res;
849   res["Test"] = false;
850   return res;
851 }
852
853 bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
854     const bool& toInclude)
855 {
856   return false;
857 }