2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
31 * Created on: 13/11/2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMMain.h"
44 #include "CDMUtilities.h"
46 modelCDMMain::modelCDMMain()
48 //TODO: implement method
51 modelCDMMain::~modelCDMMain()
53 //TODO: implement method
56 const modelCDMProject* modelCDMMain::GetProject() const
58 //TODO: implement method
62 bool modelCDMMain::CreateProject(
63 const std::string& name,
64 const std::string& location,
66 const std::string& author,
67 const std::string& description)
69 std::cout << "Open selection path: "<< location << std::endl;
71 std::string locationFixed = CDMUtilities::fixPath(location);
72 std::cout << "Opening path: "<< locationFixed << std::endl;
74 //TODO: create Project given the source folder
78 std::string command("creaNewProject.bat ");
79 std::string command1("creaSed.exe ");
80 std::string command2("del ");
82 command += "\"" + locationFixed + "\" \"" + name + "\"";
83 command1 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + locationFixed + "\\" + name + "\\CMakeLists.txt\"";
84 command2 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\"";
85 if ( ! system ( command.c_str() ) )
87 system ( command1.c_str() );
88 system ( command2.c_str() );
90 // Create a Package at the same time. JPR
91 char *author = author.c_str();
92 std::string nomDirectory = locationFixed + "\\" + name;
93 std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG";
94 std::string bbCreatePackage("bbCreatePackage ");
95 bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
96 system (bbCreatePackage.c_str());
98 add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> " + nomDirectory + "/CMakeLists.txt";
103 result = new std::string("An error occured while running '" + command + "'.");
108 // ------ LINUX / MacOS
109 std::string command("creaNewProject.sh ");
110 command += "\"" + locationFixed + "\"" +" " + name;
111 std::cout << "executing " << command << std::endl;
112 if ( ! system ( command.c_str() ) )
114 std::string nomDirectory = locationFixed + "/" + name;
115 std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG";
117 std::string bbCreatePackage("bbCreatePackage ");
118 bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description;
119 std::cout << "executing " << bbCreatePackage << std::endl;
120 system (bbCreatePackage.c_str());
123 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
124 //std::cout << add << std::endl;
125 std::cout << "executing " << add << std::endl;
130 result = new std::string("An error occured while running '" + command + "'.");
141 bool modelCDMMain::OpenProject(
142 const std::string& path,
146 std::cout << "Open selection path: "<< path << std::endl;
148 std::string pathFixed = CDMUtilities::fixPath(path);
149 std::cout << "Opening path: "<< pathFixed << std::endl;
151 //check if its binaries' folder
152 bool isBinary = false;
153 std::string pathBuild = "";
155 //check if Makefile file exists
156 std::string pathMakefile = pathFixed + "/Makefile";
157 FILE* pFile = fopen(pathMakefile.c_str(), "r");
159 //is the binary folder
163 std::ifstream readFile;
164 readFile.open(pathMakefile.c_str());
167 while(!isBinary && readFile >> word)
169 if(word == "CMAKE_SOURCE_DIR")
173 getline(readFile, word, '\n');
174 pathBuild = pathFixed;
182 //check if its source's folder
183 bool isSource = false;
184 std::string pathSource = "";
185 //check if CMakeLists file exists
186 std::string pathCMakeLists = pathFixed + "/CMakeLists.txt";
187 pFile = fopen(pathCMakeLists.c_str(), "r");
189 //is the source folder
193 std::ifstream readFile;
194 readFile.open(pathCMakeLists.c_str());
198 while(!isSource && !readFile.eof())
200 std::getline(readFile,word,'\n');
201 int pos = word.find("PROJECT");
202 if(pos != std::string::npos)
204 pathSource = pathFixed;
211 //if is source folder
214 std::cout << "Project sources at: " << pathSource;
217 std::cout << ", and built in: " << pathBuild;
219 std::cout << std::endl;
223 result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
227 //TODO: create Project given the source folder
231 bool modelCDMMain::RefreshProject(
235 //TODO: recreate the project using the project's path
239 bool modelCDMMain::CloseProject(
243 //TODO: delete the project tree and leave it as NULL