]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMMain.cpp
new model classes
[crea.git] / lib / creaDevManagerLib / modelCDMMain.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  * modelCDMMain.cpp
30  *
31  *  Created on: 13/11/2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "modelCDMMain.h"
36
37 #include<iostream>
38 #include<string>
39 #include <cstdio>
40 #include <fstream>
41
42 #include "CDMUtilities.h"
43
44 modelCDMMain::modelCDMMain()
45 {
46   //TODO: implement method
47 }
48
49 modelCDMMain::~modelCDMMain()
50 {
51   //TODO: implement method
52 }
53
54 const modelCDMProject* modelCDMMain::GetProject() const
55 {
56   //TODO: implement method
57   return this->project;
58 }
59
60 bool modelCDMMain::CreateProject(
61     const std::string& name,
62     const std::string& location,
63     std::string*& result,
64     const std::string& author,
65     const std::string& description)
66 {
67   //TODO: implement method
68   return true;
69 }
70
71 bool modelCDMMain::OpenProject(
72     const std::string& path,
73     std::string*& result
74 )
75 {
76   std::cout << "Selection path: "<< path << std::endl;
77
78   //get fixed path
79   std::string pathFixed = CDMUtilities::fixPath(path);
80   std::cout << "Fixed selection path: "<< pathFixed << std::endl;
81
82   //check if its binaries' folder
83   bool isBinary = false;
84   std::string pathBuild = "";
85
86   //check if Makefile file exists
87   std::string pathMakefile = pathFixed + "/Makefile";
88   FILE* pFile = fopen(pathMakefile.c_str(), "r");
89
90   //is the binary folder
91   if (pFile != NULL)
92     {
93       fclose(pFile);
94       std::ifstream readFile;
95       readFile.open(pathMakefile.c_str());
96       std::string word;
97
98       while(!isBinary && readFile >> word)
99         {
100           //cout << word << endl;
101           if(word == "CMAKE_SOURCE_DIR")
102             {
103               readFile >> word;
104               readFile.ignore();
105               getline(readFile, word, '\n');
106               pathBuild = pathFixed;
107               pathFixed = word;
108               isBinary = true;
109             }
110         }
111       readFile.close();
112     }
113
114   //check if its source's folder
115   bool isSource = false;
116   std::string pathSource = "";
117   //check if CMakeLists file exists
118   std::string pathCMakeLists = pathFixed + "/CMakeLists.txt";
119   pFile = fopen(pathCMakeLists.c_str(), "r");
120
121   //is the source folder
122   if (pFile != NULL)
123     {
124       fclose(pFile);
125       std::ifstream readFile;
126       readFile.open(pathCMakeLists.c_str());
127       std::string word;
128
129
130       while(!isSource && !readFile.eof())
131         {
132           std::getline(readFile,word,'\n');
133           int pos = word.find("PROJECT");
134           if(pos != std::string::npos)
135             {
136               pathSource = pathFixed;
137               isSource = true;
138             }
139         }
140       readFile.close();
141     }
142
143   //if is source folder
144   if(isSource)
145     {
146       std::cout << "Project sources at: " << pathSource;
147       if(isBinary)
148         {
149           std::cout << ", and built in: " << pathBuild;
150         }
151       std::cout << std::endl;
152     }
153   else
154     {
155       result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
156       return false;
157     }
158
159   //TODO: create Project given the source folder
160   return true;
161 }
162
163 bool modelCDMMain::RefreshProject(
164     std::string*& result
165 )
166 {
167   //TODO: recreate the project using the project's path
168   return true;
169 }
170
171 bool modelCDMMain::CloseProject(
172     std::string*& result
173 )
174 {
175   //TODO: delete the project tree and leave it as NULL
176   return true;
177 }