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\" " + "NameOfTheProject " + name + "> \"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
87 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 system ( command1.c_str() );
97 system ( command2.c_str() );
99 char *author = author.c_str();
100 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
101 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
102 std::string bbCreatePackage("bbCreatePackage ");
103 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
104 system (bbCreatePackage.c_str());
106 add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
109 this->project = new modelCDMProject(nomDirectory, name);
112 // ------ LINUX / MacOS
113 std::string command("creaNewProject.sh ");
114 command += "\"" + locationFixed + "\"" +" \"" + name + "\"";
115 //std::cout << "executing " << command << std::endl;
116 if (system ( command.c_str() ) )
118 result = new std::string("An error occured while running '" + command + "'.");
122 std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name;
123 std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG";
125 std::string bbCreatePackage("bbCreatePackage ");
126 bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\"";
127 //std::cout << "executing " << bbCreatePackage << std::endl;
128 system (bbCreatePackage.c_str());
131 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\"";
133 //std::cout << "executing " << add << std::endl;
136 if(this->project != NULL)
138 if (!CloseProject(result))
142 this->project = new modelCDMProject(NULL, nomDirectory, name);
149 bool modelCDMMain::OpenProject(
150 const std::string& path,
154 //std::cout << "Open selection path: "<< path << std::endl;
156 std::string pathFixed = CDMUtilities::fixPath(path);
157 std::cout << "Opening path: "<< pathFixed << std::endl;
159 //check if its binaries' folder
160 bool isBinary = false;
161 std::string pathBuild = "";
163 //check if Makefile file exists
164 std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
165 FILE* pFile = fopen(pathMakefile.c_str(), "r");
167 //is the binary folder
171 std::ifstream readFile;
172 readFile.open(pathMakefile.c_str());
175 while(!isBinary && readFile >> word)
177 if(word == "CMAKE_SOURCE_DIR")
181 getline(readFile, word, '\n');
182 pathBuild = pathFixed;
183 pathFixed = CDMUtilities::fixPath(word);
190 //check if its source's folder
191 bool isSource = false;
192 std::string pathSource = "";
193 //check if CMakeLists file exists
194 std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
195 pFile = fopen(pathCMakeLists.c_str(), "r");
197 //is the source folder
201 std::ifstream readFile;
202 readFile.open(pathCMakeLists.c_str());
206 while(!isSource && !readFile.eof())
208 std::getline(readFile,word,'(');
209 std::vector<std::string> wordBits;
210 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
212 if(wordBits[wordBits.size()-1] == "PROJECT")
215 pathSource = pathFixed;
221 //if is source folder
224 if(this->project != NULL)
226 if (!CloseProject(result))
229 std::vector<std::string> words;
230 CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties);
232 std::cout << "Project sources at: " << pathSource << std::endl;
235 std::cout << ", and built in: " << pathBuild << std::endl;
237 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1], pathBuild);
241 this->project = new modelCDMProject(NULL, pathSource, words[words.size()-1]);
246 result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
253 bool modelCDMMain::RefreshProject(
257 //recreate the project using the project's path
258 if (this->project != NULL)
260 return this->project->Refresh(result);
264 result = new std::string("There is no open project.");
269 std::map<wxTreeItemId, modelCDMIProjectTreeNode*>& modelCDMMain::GetModelElements()
271 return this->modelElements;
274 bool modelCDMMain::CloseProject(
278 //delete the project tree and leave it as NULL
279 if (this->project != NULL)
281 delete this->project;
282 this->project = NULL;
287 result = new std::string("There is no open project.");