X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMProject.cpp;h=c844798f12aca27205df8eea930e35bc6ad02c4d;hb=311bdcc514f85386f3bbbef9ff6a88bf69fd930f;hp=23dd1666d041bbc0a186c7628e0adebcb00d9914;hpb=9013f401b9f263f755fedc2dc88b21f351abf7da;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index 23dd166..c844798 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -35,9 +35,11 @@ #include "modelCDMProject.h" #include +#include #include #include #include +#include #include "CDMUtilities.h" #include "creaWx.h" @@ -53,15 +55,16 @@ modelCDMProject::modelCDMProject() modelCDMProject::modelCDMProject( const std::string& path, + const std::string& name, const std::string& buildPath ) { + std::cout << "creating project: " + name + " in " + path + "\n"; this->path = CDMUtilities::fixPath(path); //open makelists file std::string pathFixed(CDMUtilities::fixPath(path)); - //TODO: set pathMakeLists for windows - std::string pathMakeLists = pathFixed + "/CMakeLists.txt"; + std::string pathMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -154,26 +157,26 @@ modelCDMProject::modelCDMProject( //if appli, create appli if(stdfileName == "appli") { - this->appli = new modelCDMAppli(pathFixed + "/appli", this->level + 1); + this->appli = new modelCDMAppli(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->appli); } //if lib, create lib else if(stdfileName == "lib") { - this->lib = new modelCDMLib(pathFixed + "/lib", this->level + 1); + this->lib = new modelCDMLib(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->lib); } //if package , create package else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG") { - modelCDMPackage* package = new modelCDMPackage(pathFixed + "/" + stdfileName, this->level + 1); + modelCDMPackage* package = new modelCDMPackage(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->packages.push_back(package); this->children.push_back(package); } //if is an unknown folder, create folder else { - this->children.push_back(new modelCDMFolder(pathFixed + "/" + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } cont = dir.GetNext(&fileName); @@ -187,12 +190,12 @@ modelCDMProject::modelCDMProject( //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { - this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + "/" + stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } else { - this->children.push_back(new modelCDMFile(pathFixed + "/" + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } //if is an unknown file, create file cont = dir.GetNext(&fileName); @@ -200,6 +203,7 @@ modelCDMProject::modelCDMProject( } this->SortChildren(); + std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem); } @@ -227,15 +231,87 @@ const std::string& modelCDMProject::GetBuildPath() const return this->buildPath; } +const std::vector& modelCDMProject::GetPackages() const +{ + return this->packages; +} + +modelCDMAppli* modelCDMProject::GetAppli() const +{ + return this->appli; +} + +modelCDMLib* modelCDMProject::GetLib() const +{ + return this->lib; +} + bool modelCDMProject::SetVersion(const std::string& version, std::string*& result) { - //TODO: implement method + + std::vector vers; + CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties); + + time_t now = time(0); + tm* ltm = localtime(&now); + + std::stringstream date; + date << ltm->tm_mday << "/" << 1 + ltm->tm_mon << "/" << 1900 + ltm->tm_year; + + //set name of library in CMakeLists inside copied folder + std::string line; + std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str()); + if( !in.is_open()) + { + result = new std::string("CMakeLists.txt file failed to open."); + return false; + } + std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str()); + if( !out.is_open()) + { + result = new std::string("CMakeLists.txt.tmp file failed to open."); + return false; + } + while (getline(in, line)) + { + if(line.find("SET(PROJECT_MAJOR_VERSION") != std::string::npos) + line = "SET(PROJECT_MAJOR_VERSION " + vers[0] + ")"; + else if(line.find("SET(PROJECT_MINOR_VERSION") != std::string::npos) + line = "SET(PROJECT_MINOR_VERSION " + vers[1] + ")"; + else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos) + line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")"; + else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos) + line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")"; + out << line << std::endl; + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\""; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return false; + } + + this->version = vers[0] + "." + vers[1] + "." + vers[2]; + this->versionDate = date.str(); return true; } bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result) { - //TODO: implement method + if(path == "") + { + result = new std::string("The path cannot be empty"); + return false; + } + if(path == this->path) + { + result = new std::string("The path cannot be same as the project sources"); + return false; + } + this->buildPath = path; return true; } @@ -281,7 +357,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( } //call project to create package : use bbCreatePackage [author] [description] - std::string creationCommand = "bbCreatePackage \"" + this->path + "\" " + nameFixed + " " + authorFixed + " " + descriptionFixed; + std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\""; //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error if(system(creationCommand.c_str())) { @@ -290,8 +366,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( } //add library to model - //TODO: fix for windows - modelCDMPackage* package = new modelCDMPackage(this->path + "/bbtk_" + nameFixed + "_PKG", this->level + 1); + modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1); this->packages.push_back(package); this->children.push_back(package); @@ -299,7 +374,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( this->SortChildren(); - result = new std::string(this->path + "/" + name); + result = new std::string(this->path + CDMUtilities::SLASH + name); return package; } @@ -324,11 +399,11 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateApplication( ) { if(this->appli != NULL) - { - return this->appli->CreateApplication(name, result); - } - result = new std::string("there is no appli folder in this project."); - return NULL; + { + return this->appli->CreateApplication(name, result); + } + result = new std::string("there is no appli folder in this project."); + return NULL; } modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox( @@ -346,16 +421,20 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox( bool modelCDMProject::OpenCMakeListsFile(std::string*& result) { - //TODO: implement method - return true; + if (!CDMUtilities::openTextEditor(this->CMakeLists->GetPath())) + return true; + else + { + result = new std::string("Couldn't open CMakeLists file."); + return false; + } } const bool modelCDMProject::Refresh(std::string*& result) { std::cout << "refreshing project" << std::endl; //open makelists file - //TODO: set pathMakeLists for windows - std::string pathMakeLists = this->path + "/CMakeLists.txt"; + std::string pathMakeLists = this->path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -437,7 +516,7 @@ const bool modelCDMProject::Refresh(std::string*& result) { if (this->appli == NULL) { - this->appli = new modelCDMAppli(this->path + "/appli", this->level + 1); + this->appli = new modelCDMAppli(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->appli); } else @@ -453,7 +532,7 @@ const bool modelCDMProject::Refresh(std::string*& result) { if (this->lib == NULL) { - this->lib = new modelCDMLib(this->path + "/lib", this->level + 1); + this->lib = new modelCDMLib(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->lib); } else @@ -468,11 +547,10 @@ const bool modelCDMProject::Refresh(std::string*& result) //if package , create package else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG") { - std::string packageName = stdfileName.substr(5, stdfileName.size()-9); bool found = false; - for (int i = 0;!found && i < this->packages.size(); i++) + for (int i = 0; !found && i < this->packages.size(); i++) { - if (this->packages[i]->GetName() == packageName) + if (this->packages[i]->GetName() == stdfileName) { found = true; int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin(); @@ -484,7 +562,7 @@ const bool modelCDMProject::Refresh(std::string*& result) } if(!found) { - modelCDMPackage* package = new modelCDMPackage(this->path + "/" + stdfileName, this->level + 1); + modelCDMPackage* package = new modelCDMPackage(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->packages.push_back(package); this->children.push_back(package); } @@ -507,7 +585,7 @@ const bool modelCDMProject::Refresh(std::string*& result) if(!found) { - modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1); + modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(folder); } } @@ -525,7 +603,7 @@ const bool modelCDMProject::Refresh(std::string*& result) { if (this->CMakeLists == NULL) { - this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } else @@ -540,7 +618,7 @@ const bool modelCDMProject::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; i children.size(); i++) + for (int i = 0; !found && i < this->children.size(); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -553,7 +631,7 @@ const bool modelCDMProject::Refresh(std::string*& result) if(!found) { - modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1); + modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(file); } } @@ -581,7 +659,9 @@ const bool modelCDMProject::Refresh(std::string*& result) i--; } } + this->SortChildren(); + std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem); return true; }