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"
45 #include "CDMUtilities.h"
46 #include "modelCDMProject.h"
48 modelCDMMain::modelCDMMain()
53 modelCDMMain::~modelCDMMain()
62 modelCDMProject* modelCDMMain::GetProject() const
67 bool modelCDMMain::CreateProject(
68 const std::string& name,
69 const std::string& location,
71 const std::string& author,
72 const std::string& description)
74 std::cout << "Open selection path: "<< location << std::endl;
76 std::string locationFixed = CDMUtilities::fixPath(location);
77 std::cout << "Opening path: "<< locationFixed << std::endl;
79 //creates project in disk
82 std::string command("creaNewProject.bat ");
83 std::string command1("creaSed.exe ");
84 std::string command2("del ");
86 command += "\"" + locationFixed + "\" \"" + name + "\"";
87 command1 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\" " + "PROJECT_NAME " + name + "> \"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
88 command2 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\"";
90 if (system (command.c_str()))
92 result = new std::string("An error occurred while running '" + command + "'.");
96 if (system (command1.c_str()))
98 result = new std::string("An error occurred while running '" + command1 + "'.");
101 if (system (command2.c_str()))
103 result = new std::string("An error occurred while running '" + command2 + "'.");
107 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
108 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
109 std::string bbCreatePackage("bbCreatePackage ");
110 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
111 if (!system (bbCreatePackage.c_str()))
113 result = new std::string("An error occurred while running '" + bbCreatePackage + "'.");
117 add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
118 if (system (add.c_str()))
120 result = new std::string("An error occurred while running '" + add + "'.");
124 this->project = new modelCDMProject(NULL, nomDirectory, name);
127 // ------ LINUX / MacOS
128 std::string command("creaNewProject.sh ");
129 command += "\"" + locationFixed + "\"" +" \"" + name + "\"";
130 //std::cout << "executing " << command << std::endl;
131 if (system ( command.c_str() ) )
133 result = new std::string("An error occured while running '" + command + "'.");
137 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
138 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
140 std::string bbCreatePackage("bbCreatePackage ");
141 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
142 //std::cout << "executing " << bbCreatePackage << std::endl;
143 system (bbCreatePackage.c_str());
146 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
148 //std::cout << "executing " << add << std::endl;
151 if(this->project != NULL)
153 if (!CloseProject(result))
157 this->project = new modelCDMProject(NULL, nomDirectory, name);
164 bool modelCDMMain::OpenProject(
165 const std::string& path,
169 //std::cout << "Open selection path: "<< path << std::endl;
171 std::string pathFixed = CDMUtilities::fixPath(path);
172 std::cout << "Opening path: "<< pathFixed << std::endl;
174 //check if its binaries' folder
175 bool isBinary = false;
176 std::string pathBuild = "";
178 //check if Makefile file exists
180 std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "CMakeCache.txt";
182 errno_t errorOpen = fopen_s(&pFile, pathMakefile.c_str(), "r");
184 std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
186 pFile = fopen(pathMakefile.c_str(), "r");
187 bool errorOpen = (pFile == NULL);
189 //is the binary folder
190 if (!errorOpen && pFile)
193 std::ifstream readFile;
194 readFile.open(pathMakefile.c_str());
199 while(!isBinary && !readFile.eof())
201 getline(readFile, word, '\n');
202 std::vector<std::string> words;
203 CDMUtilities::splitter::split(words,word,"=",CDMUtilities::splitter::no_empties);
204 if(words.size() && words[0] == "CMAKE_HOME_DIRECTORY:INTERNAL")
206 pathBuild = pathFixed;
207 pathFixed = CDMUtilities::fixPath(words[1]);
208 for (int i = 0; i < (int)(pathFixed.size()); i++)
210 if (pathFixed[i]=='/')
217 while(!isBinary && readFile >> word)
219 if(word == "CMAKE_SOURCE_DIR")
223 getline(readFile, word, '\n');
224 pathBuild = pathFixed;
225 pathFixed = CDMUtilities::fixPath(word);
233 //check if its source's folder
234 bool isSource = false;
235 std::string pathSource = "";
236 //check if CMakeLists file exists
237 std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
239 errorOpen = fopen_s(&pFile, pathCMakeLists.c_str(), "r");
241 pFile = fopen(pathCMakeLists.c_str(), "r");
242 errorOpen = (pFile == NULL);
245 //is the source folder
246 if (!errorOpen && pFile)
249 std::ifstream readFile;
250 readFile.open(pathCMakeLists.c_str());
254 while(!isSource && !readFile.eof())
256 std::getline(readFile,word,'(');
257 std::vector<std::string> wordBits;
258 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
260 if(wordBits[wordBits.size()-1] == "PROJECT")
263 pathSource = pathFixed;
269 //if is source folder
272 if(this->project != NULL)
274 if (!CloseProject(result))
277 std::vector<std::string> words;
278 CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties);
280 std::cout << "Project sources at: " << pathSource << std::endl;
283 std::cout << ", and built in: " << pathBuild << std::endl;
285 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1], pathBuild);
289 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1]);
294 result = new std::string("No source folder found. Please make sure to select either the project's build or source folder. " + pathBuild + pathFixed);
301 bool modelCDMMain::RefreshProject(
305 //recreate the project using the project's path
306 if (this->project != NULL)
308 return this->project->Refresh(result);
312 result = new std::string("There is no open project.");
317 std::map<wxCDMTreeItemId, modelCDMIProjectTreeNode*>& modelCDMMain::GetModelElements()
319 return this->modelElements;
322 bool modelCDMMain::CloseProject(
326 //delete the project tree and leave it as NULL
327 if (this->project != NULL)
329 delete this->project;
330 this->project = NULL;
335 result = new std::string("There is no open project.");