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"
45 #include "modelCDMProject.h"
47 modelCDMMain::modelCDMMain()
52 modelCDMMain::~modelCDMMain()
61 modelCDMProject* modelCDMMain::GetProject() const
66 bool modelCDMMain::CreateProject(
67 const std::string& name,
68 const std::string& location,
70 const std::string& author,
71 const std::string& description)
73 std::cout << "Open selection path: "<< location << std::endl;
75 std::string locationFixed = CDMUtilities::fixPath(location);
76 std::cout << "Opening path: "<< locationFixed << std::endl;
78 //creates project in disk
81 std::string command("creaNewProject.bat ");
82 std::string command1("creaSed.exe ");
83 std::string command2("del ");
85 command += "\"" + locationFixed + "\" \"" + name + "\"";
86 command1 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\" " + "PROJECT_NAME " + name + "> \"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
87 command2 += "\"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.in\"";
89 if (system (command.c_str()))
91 result = new std::string("An error occurred while running '" + command + "'.");
95 if (system (command1.c_str()))
97 result = new std::string("An error occurred while running '" + command1 + "'.");
100 if (system (command2.c_str()))
102 result = new std::string("An error occurred while running '" + command2 + "'.");
106 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
107 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
108 std::string bbCreatePackage("bbCreatePackage ");
109 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
110 if (!system (bbCreatePackage.c_str()))
112 result = new std::string("An error occurred while running '" + bbCreatePackage + "'.");
116 add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
117 if (system (add.c_str()))
119 result = new std::string("An error occurred while running '" + add + "'.");
123 this->project = new modelCDMProject(NULL, nomDirectory, name);
126 // ------ LINUX / MacOS
127 std::string command("creaNewProject.sh ");
128 command += "\"" + locationFixed + "\"" +" \"" + name + "\"";
129 //std::cout << "executing " << command << std::endl;
130 if (system ( command.c_str() ) )
132 result = new std::string("An error occured while running '" + command + "'.");
136 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
137 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
139 std::string bbCreatePackage("bbCreatePackage ");
140 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
141 //std::cout << "executing " << bbCreatePackage << std::endl;
142 system (bbCreatePackage.c_str());
145 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
147 //std::cout << "executing " << add << std::endl;
150 if(this->project != NULL)
152 if (!CloseProject(result))
156 this->project = new modelCDMProject(NULL, nomDirectory, name);
163 bool modelCDMMain::OpenProject(
164 const std::string& path,
168 //std::cout << "Open selection path: "<< path << std::endl;
170 std::string pathFixed = CDMUtilities::fixPath(path);
171 std::cout << "Opening path: "<< pathFixed << std::endl;
173 //check if its binaries' folder
174 bool isBinary = false;
175 std::string pathBuild = "";
177 //check if Makefile file exists
178 std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
179 FILE* pFile = fopen(pathMakefile.c_str(), "r");
181 //is the binary folder
185 std::ifstream readFile;
186 readFile.open(pathMakefile.c_str());
189 while(!isBinary && readFile >> word)
191 if(word == "CMAKE_SOURCE_DIR")
195 getline(readFile, word, '\n');
196 pathBuild = pathFixed;
197 pathFixed = CDMUtilities::fixPath(word);
204 //check if its source's folder
205 bool isSource = false;
206 std::string pathSource = "";
207 //check if CMakeLists file exists
208 std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
209 pFile = fopen(pathCMakeLists.c_str(), "r");
211 //is the source folder
215 std::ifstream readFile;
216 readFile.open(pathCMakeLists.c_str());
220 while(!isSource && !readFile.eof())
222 std::getline(readFile,word,'(');
223 std::vector<std::string> wordBits;
224 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
226 if(wordBits[wordBits.size()-1] == "PROJECT")
229 pathSource = pathFixed;
235 //if is source folder
238 if(this->project != NULL)
240 if (!CloseProject(result))
243 std::vector<std::string> words;
244 CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties);
246 std::cout << "Project sources at: " << pathSource << std::endl;
249 std::cout << ", and built in: " << pathBuild << std::endl;
251 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1], pathBuild);
255 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1]);
260 result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
267 bool modelCDMMain::RefreshProject(
271 //recreate the project using the project's path
272 if (this->project != NULL)
274 return this->project->Refresh(result);
278 result = new std::string("There is no open project.");
283 std::map<wxTreeItemId, modelCDMIProjectTreeNode*>& modelCDMMain::GetModelElements()
285 return this->modelElements;
288 bool modelCDMMain::CloseProject(
292 //delete the project tree and leave it as NULL
293 if (this->project != NULL)
295 delete this->project;
296 this->project = NULL;
301 result = new std::string("There is no open project.");