From cfa883d25e73975f73c20fefc1ec2c947d827938 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Fri, 28 Dec 2012 12:49:47 +0100 Subject: [PATCH] Feature #1711 CreaDevManager application implementation -Fixed windows path slash -Name of classes passed as parameter in constructor -Creation of New BlackBox Dialog --- lib/creaDevManagerLib/CDMUtilities.cpp | 4 +- lib/creaDevManagerLib/CDMUtilities.h | 11 + lib/creaDevManagerLib/modelCDMAppli.cpp | 38 ++-- lib/creaDevManagerLib/modelCDMAppli.h | 5 +- lib/creaDevManagerLib/modelCDMApplication.cpp | 52 ++--- lib/creaDevManagerLib/modelCDMApplication.h | 4 +- lib/creaDevManagerLib/modelCDMBlackBox.cpp | 167 +++++++++----- lib/creaDevManagerLib/modelCDMBlackBox.h | 2 +- .../modelCDMCMakeListsFile.cpp | 23 +- .../modelCDMCMakeListsFile.h | 2 +- lib/creaDevManagerLib/modelCDMFile.cpp | 16 +- lib/creaDevManagerLib/modelCDMFile.h | 2 +- lib/creaDevManagerLib/modelCDMFolder.cpp | 28 +-- lib/creaDevManagerLib/modelCDMFolder.h | 2 +- lib/creaDevManagerLib/modelCDMLib.cpp | 36 ++- lib/creaDevManagerLib/modelCDMLib.h | 5 +- lib/creaDevManagerLib/modelCDMLibrary.cpp | 36 ++- lib/creaDevManagerLib/modelCDMLibrary.h | 2 +- lib/creaDevManagerLib/modelCDMMain.cpp | 37 ++-- lib/creaDevManagerLib/modelCDMPackage.cpp | 109 +++------ lib/creaDevManagerLib/modelCDMPackage.h | 6 +- lib/creaDevManagerLib/modelCDMPackageSrc.cpp | 39 +++- lib/creaDevManagerLib/modelCDMPackageSrc.h | 13 +- lib/creaDevManagerLib/modelCDMProject.cpp | 46 ++-- lib/creaDevManagerLib/modelCDMProject.h | 2 +- .../wxCDMNewBlackBoxDialog.cpp | 209 ++++++++++++++++++ .../wxCDMNewBlackBoxDialog.h | 91 ++++++++ 27 files changed, 642 insertions(+), 345 deletions(-) create mode 100644 lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp create mode 100644 lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.h diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index 29a277f..f0a538e 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -83,11 +83,11 @@ namespace CDMUtilities //break path into folders std::vector pathSlpit; - splitter::split(pathSlpit, path, "/", splitter::no_empties); + splitter::split(pathSlpit, path, CDMUtilities::SLASH, splitter::no_empties); for (int i = 0; i < pathSlpit.size(); i++) { - pathFixed += "/" + pathSlpit[i]; + pathFixed += CDMUtilities::SLASH + pathSlpit[i]; } #endif return pathFixed; diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index bed8ed9..9bfa1d9 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -40,6 +40,17 @@ namespace CDMUtilities { + //path slash + #ifdef _WIN32 + // ------ Windows + static std::string SLASH = "\\"; + #elif __APPLE__ + // ------ Apple + static std::string SLASH = "/"; + #else + static std::string SLASH = "/"; + #endif + //text editor program #ifdef _WIN32 // ------ Windows diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index e35a9c5..d15bc4f 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -46,10 +46,10 @@ modelCDMAppli::modelCDMAppli() { } -modelCDMAppli::modelCDMAppli(const std::string& path, const int& level) +modelCDMAppli::modelCDMAppli(const std::string& path, const std::string& name, const int& level) { this->type = wxDIR_DIRS; - this->name = "appli"; + this->name = name; this->level = level; this->path = path; @@ -68,7 +68,7 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const int& level) { std::string stdfileName = crea::wx2std(fileName); - modelCDMApplication* application = new modelCDMApplication(pathFixed + "/" + stdfileName, this->level + 1); + modelCDMApplication* application = new modelCDMApplication(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->applications.push_back(application); this->children.push_back(application); @@ -83,13 +83,13 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const int& level) //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); } //if is an unknown file, create file 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)); } cont = dir.GetNext(&fileName); @@ -110,13 +110,11 @@ const std::vector& modelCDMAppli::GetApplications() const modelCDMApplication* modelCDMAppli::CreateApplication( const std::string& name, - std::string*& result, - const std::string& path + std::string*& result ) { //copy template application folder with new name - //TODO: fix for windows - std::string copyCommand = "cp -r " + this->path + "/template_appli " + this->path + "/" + name; + std::string copyCommand = "cp -r \"" + this->path + CDMUtilities::SLASH + "template_appli\" \"" + this->path + CDMUtilities::SLASH + name + "\""; if(system(copyCommand.c_str())) { result = new std::string("An error occurred while running '" + copyCommand + "'."); @@ -124,13 +122,13 @@ modelCDMApplication* modelCDMAppli::CreateApplication( } //set name of library in CMakeLists inside copied folder std::string line; - std::ifstream in((this->path + "/" + name + "/CMakeLists.txt").c_str()); + std::ifstream in((this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt").c_str()); if( !in.is_open()) { result = new std::string("CMakeLists.txt file failed to open."); return NULL; } - std::ofstream out((this->path + "/" + name + "/CMakeLists.txt.tmp").c_str()); + std::ofstream out((this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str()); while (getline(in, line)) { if(line == "SET ( EXE_NAME MyExe )") @@ -140,7 +138,7 @@ modelCDMApplication* modelCDMAppli::CreateApplication( in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/" + name + "/CMakeLists.txt.tmp " + this->path + "/" + name + "/CMakeLists.txt"; + std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -148,14 +146,13 @@ modelCDMApplication* modelCDMAppli::CreateApplication( } //add application to model - //TODO: fix for windows - modelCDMApplication* application = new modelCDMApplication(this->path + "/" + name, this->level + 1); + modelCDMApplication* application = new modelCDMApplication(this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->applications.push_back(application); this->children.push_back(application); this->SortChildren(); - result = new std::string(this->path + "/" + name); + result = new std::string(this->path + CDMUtilities::SLASH + name); return application; } @@ -163,11 +160,6 @@ const bool modelCDMAppli::Refresh(std::string*& result) { std::cout << "refreshing appli" << std::endl; this->type = wxDIR_DIRS; - this->name = "appli"; - this->level = level; - this->path = path; - - std::vector checked(this->children.size(), false); std::vector checkedApplications(this->applications.size(), false); @@ -198,7 +190,7 @@ const bool modelCDMAppli::Refresh(std::string*& result) } if(!found) { - modelCDMApplication* application= new modelCDMApplication(this->path + "/" + stdfileName, this->level + 1); + modelCDMApplication* application= new modelCDMApplication(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->applications.push_back(application); this->children.push_back(application); } @@ -215,7 +207,7 @@ const bool modelCDMAppli::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 @@ -243,7 +235,7 @@ const bool modelCDMAppli::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); } } diff --git a/lib/creaDevManagerLib/modelCDMAppli.h b/lib/creaDevManagerLib/modelCDMAppli.h index c37924d..5d378b9 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.h +++ b/lib/creaDevManagerLib/modelCDMAppli.h @@ -45,15 +45,14 @@ class modelCDMAppli : public modelCDMFolder { public: modelCDMAppli(); - modelCDMAppli(const std::string& path, const int& level = 1); + modelCDMAppli(const std::string& path, const std::string& name = "appli", const int& level = 1); ~modelCDMAppli(); const std::vector& GetApplications() const; modelCDMApplication* CreateApplication( const std::string& name, - std::string*& result, - const std::string& path = "/" + std::string*& result ); virtual const bool Refresh(std::string*& result); diff --git a/lib/creaDevManagerLib/modelCDMApplication.cpp b/lib/creaDevManagerLib/modelCDMApplication.cpp index c39b48d..e8af2cf 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.cpp +++ b/lib/creaDevManagerLib/modelCDMApplication.cpp @@ -45,25 +45,18 @@ modelCDMApplication::modelCDMApplication() { } -modelCDMApplication::modelCDMApplication(const std::string& path, const int& level) +modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level) { //folder name - std::vector words; - std::string delimiters; - //TODO::fix for windows - delimiters = "/"; - CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties); - this->name = words[words.size()-1]; - + this->name = name; //path this->path = CDMUtilities::fixPath(path); //type this->type = wxDIR_DIRS; //level this->level = level; - //open CMakeList - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -89,7 +82,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev word += " " + wordBits[i]; } - this->nameApplication = this->executableName = word; + this->executableName = word; } } } @@ -108,7 +101,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev { std::string stdfileName = crea::wx2std(fileName); - modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1); + modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->folders.push_back(folder); this->children.push_back(folder); @@ -123,13 +116,13 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { - 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); } //if is an unknown file, create file else { - this->children.push_back(new modelCDMFile(this->path + "/" + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } cont = dir.GetNext(&fileName); @@ -142,11 +135,6 @@ modelCDMApplication::~modelCDMApplication() { } -const std::string& modelCDMApplication::GetNameApplication() const -{ - return this->nameApplication; -} - const std::string& modelCDMApplication::GetExecutableName() const { return this->executableName; @@ -164,14 +152,14 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st std::string line; //opening original cmakelists - std::ifstream in((this->path + "/CMakeLists.txt").c_str()); + 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; } //opening temporal cmakelists - std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -187,27 +175,27 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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->executableName = this->nameApplication = fileNameReal; + this->executableName = fileNameReal; return true; } modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result) { //TODO:: mkdir depending on OS - std::string command = "mkdir " + path + "/" + name; + std::string command = "mkdir " + path + CDMUtilities::SLASH + name; if(system(command.c_str())) { result = new std::string("Error executing: " + command + "."); return NULL; } - modelCDMFolder* folder = new modelCDMFolder(path + "/" + name, level + 1); + modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1); this->folders.push_back(folder); this->children.push_back(folder); @@ -220,7 +208,7 @@ const bool modelCDMApplication::Refresh(std::string*& result) this->type = wxDIR_DIRS; //open CMakeList - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -235,10 +223,10 @@ const bool modelCDMApplication::Refresh(std::string*& result) if(wordBits[wordBits.size()-1] == "SET") { - //get library name + //get app name std::getline(confFile,word,')'); CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties); - if(wordBits[0] == "LIBRARY_NAME") + if(wordBits[0] == "EXE_NAME") { word = wordBits[1]; for (int i = 2; i < wordBits.size(); i++) @@ -246,7 +234,7 @@ const bool modelCDMApplication::Refresh(std::string*& result) word += " " + wordBits[i]; } - this->nameApplication = this->executableName = word; + this->executableName = word; } } } @@ -283,7 +271,7 @@ const bool modelCDMApplication::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->folders.push_back(folder); this->children.push_back(folder); } @@ -300,7 +288,7 @@ const bool modelCDMApplication::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 @@ -328,7 +316,7 @@ const bool modelCDMApplication::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); } } diff --git a/lib/creaDevManagerLib/modelCDMApplication.h b/lib/creaDevManagerLib/modelCDMApplication.h index af3cbad..244ec73 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.h +++ b/lib/creaDevManagerLib/modelCDMApplication.h @@ -44,10 +44,9 @@ class modelCDMApplication : public modelCDMFolder { public: modelCDMApplication(); - modelCDMApplication(const std::string& path, const int& level = 2); + modelCDMApplication(const std::string& path, const std::string& name, const int& level = 2); ~modelCDMApplication(); - const std::string& GetNameApplication() const; const std::string& GetExecutableName() const; bool SetExecutableName(const std::string& fileName, std::string*& result); @@ -57,7 +56,6 @@ public: virtual const bool Refresh(std::string*& result); private: - std::string nameApplication; std::string executableName; std::vector folders; }; diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.cpp b/lib/creaDevManagerLib/modelCDMBlackBox.cpp index d177c88..4d83492 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.cpp +++ b/lib/creaDevManagerLib/modelCDMBlackBox.cpp @@ -47,16 +47,16 @@ modelCDMBlackBox::modelCDMBlackBox() this->header = NULL; } -modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level) +modelCDMBlackBox::modelCDMBlackBox(const std::string& path, const std::string& name, const int& level) { - this->name = hName.substr(2, hName.size()-4); + this->name = name; this->path = path; this->level = level; this->type = wxDIR_DIRS; this->source = NULL; this->header = NULL; - std::string pathHeader = path + "/" + "bb" + this->name + ".h"; + std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h"; std::ifstream confFile; confFile.open((pathHeader).c_str()); @@ -101,6 +101,8 @@ modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& modelCDMBlackBox::~modelCDMBlackBox() { + this->header = NULL; + this->source = NULL; } const std::string& modelCDMBlackBox::GetNameBlackBox() const @@ -126,11 +128,11 @@ const std::string& modelCDMBlackBox::GetDescription() const bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& result) { std::vector words; - CDMUtilities::splitter::split(words, authors, ",\"\n", CDMUtilities::splitter::no_empties); + CDMUtilities::splitter::split(words, authors, "/\\\"\n", CDMUtilities::splitter::no_empties); std::string authorsReal = words[0]; for (int i = 1; i < words.size(); i++) { - authorsReal += "/" + words[i]; + authorsReal += "," + words[i]; } //opening original header @@ -168,7 +170,7 @@ bool modelCDMBlackBox::SetAuthors(const std::string& authors, std::string*& resu in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -186,57 +188,57 @@ bool modelCDMBlackBox::SetCategories( ) { std::vector words; - CDMUtilities::splitter::split(words, categories, "\"", CDMUtilities::splitter::no_empties); - std::string catsReal = words[0]; - for (int i = 1; i < words.size(); i++) - { - catsReal += "-" + words[i]; - } - - //opening original header - std::string pathHeader = this->header->GetPath(); - std::ifstream in(pathHeader.c_str()); - if( !in.is_open()) - { - result = new std::string(pathHeader + " file failed to open."); - return false; - } - //opening temporal header - std::ofstream out((pathHeader + ".tmp").c_str()); - if( !out.is_open()) - { - result = new std::string(pathHeader + ".tmp file failed to open."); - return false; - } - //copying contents from original to temporal and making changes - std::string reading; - while (getline(in, reading, '(')) - { - CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties); - if(words[words.size() - 1] == "BBTK_CATEGORY") - { - out << reading << "(\"" << catsReal << "\")"; - getline(in, reading, ')'); - } - else - { - out << reading; - if (!in.eof()) - out << "("; - } - } - in.close(); - out.close(); - //delete old file and rename new file - std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; - if(system(renameCommand.c_str())) - { - result = new std::string("An error occurred while running '" + renameCommand + "'."); - return false; - } - - this->categories = catsReal; - return true; + CDMUtilities::splitter::split(words, categories, "\"\\/", CDMUtilities::splitter::no_empties); + std::string catsReal = words[0]; + for (int i = 1; i < words.size(); i++) + { + catsReal += "," + words[i]; + } + + //opening original header + std::string pathHeader = this->header->GetPath(); + std::ifstream in(pathHeader.c_str()); + if( !in.is_open()) + { + result = new std::string(pathHeader + " file failed to open."); + return false; + } + //opening temporal header + std::ofstream out((pathHeader + ".tmp").c_str()); + if( !out.is_open()) + { + result = new std::string(pathHeader + ".tmp file failed to open."); + return false; + } + //copying contents from original to temporal and making changes + std::string reading; + while (getline(in, reading, '(')) + { + CDMUtilities::splitter::split(words, reading, "\n ", CDMUtilities::splitter::no_empties); + if(words[words.size() - 1] == "BBTK_CATEGORY") + { + out << reading << "(\"" << catsReal << "\")"; + getline(in, reading, ')'); + } + else + { + out << reading; + if (!in.eof()) + out << "("; + } + } + in.close(); + out.close(); + //delete old file and rename new file + std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\""; + if(system(renameCommand.c_str())) + { + result = new std::string("An error occurred while running '" + renameCommand + "'."); + return false; + } + + this->categories = catsReal; + return true; } bool modelCDMBlackBox::SetDescription( @@ -245,11 +247,11 @@ bool modelCDMBlackBox::SetDescription( ) { std::vector words; - CDMUtilities::splitter::split(words, description, "\"", CDMUtilities::splitter::no_empties); + CDMUtilities::splitter::split(words, description, "\"\n\\/", CDMUtilities::splitter::no_empties); std::string descReal = words[0]; for (int i = 1; i < words.size(); i++) { - descReal += "\\\"" + words[i]; + descReal += "-" + words[i]; } //opening original header @@ -287,7 +289,7 @@ bool modelCDMBlackBox::SetDescription( in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + pathHeader + ".tmp " + pathHeader; + std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -330,6 +332,49 @@ modelCDMFile* modelCDMBlackBox::GetSourceFile() const const bool modelCDMBlackBox::Refresh(std::string*& result) { - //TODO: implement method + std::string pathHeader = path + CDMUtilities::SLASH + "bb" + this->name + ".h"; + + std::ifstream confFile; + confFile.open((pathHeader).c_str()); + std::string word; + + if(!confFile.is_open()) + return false; + + while(confFile.is_open() && !confFile.eof()) + { + //get BBTK's + std::getline(confFile,word,'('); + std::vector wordBits; + CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties); + + if(wordBits[wordBits.size()-1] == "BBTK_NAME") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->nameBlackBox = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_AUTHOR") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->authors = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_DESCRIPTION") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->description = word; + } + else if(wordBits[wordBits.size()-1] == "BBTK_CATEGORY") + { + std::getline(confFile,word,'"'); + std::getline(confFile,word,'"'); + this->categories = word; + if (this->categories == "") + this->categories = "empty"; + } + } + confFile.close(); return true; } diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.h b/lib/creaDevManagerLib/modelCDMBlackBox.h index e1021b8..c58b167 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.h +++ b/lib/creaDevManagerLib/modelCDMBlackBox.h @@ -43,7 +43,7 @@ class modelCDMBlackBox : public modelCDMFolder { public: modelCDMBlackBox(); - modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level = 1); + modelCDMBlackBox(const std::string& path, const std::string& name, const int& level = 1); ~modelCDMBlackBox(); const std::string& GetNameBlackBox() const; diff --git a/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp b/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp index 2b9cb2a..dfbb999 100644 --- a/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp +++ b/lib/creaDevManagerLib/modelCDMCMakeListsFile.cpp @@ -34,6 +34,8 @@ #include "modelCDMCMakeListsFile.h" +#include + #include #include @@ -43,14 +45,18 @@ modelCDMCMakeListsFile::modelCDMCMakeListsFile() { } -modelCDMCMakeListsFile::modelCDMCMakeListsFile(const std::string& path, - const int& level) +modelCDMCMakeListsFile::modelCDMCMakeListsFile(const std::string& path, const std::string& name, const int& level) { this->children.clear(); this->level = level; this->type = wxDIR_FILES; - this->name = "CMakeFileLists.txt"; + this->name = name; this->path = path; + + std::ifstream in(path.c_str(), std::ifstream::in | std::ifstream::binary); + in.seekg(0, std::ifstream::end); + this->length = in.tellg(); + in.close(); } modelCDMCMakeListsFile::~modelCDMCMakeListsFile() @@ -71,6 +77,15 @@ bool modelCDMCMakeListsFile::OpenFile(std::string*& result) const bool modelCDMCMakeListsFile::Refresh(std::string*& result) { - //TODO: implement method + std::ifstream in((this->path).c_str()); + if(!in.is_open()) + { + in.close(); + return false; + } + std::ifstream in2(path.c_str(), std::ifstream::in | std::ifstream::binary); + in2.seekg(0, std::ifstream::end); + this->length = in2.tellg(); + in2.close(); return true; } diff --git a/lib/creaDevManagerLib/modelCDMCMakeListsFile.h b/lib/creaDevManagerLib/modelCDMCMakeListsFile.h index ef66a29..65f034f 100644 --- a/lib/creaDevManagerLib/modelCDMCMakeListsFile.h +++ b/lib/creaDevManagerLib/modelCDMCMakeListsFile.h @@ -41,7 +41,7 @@ class modelCDMCMakeListsFile : public modelCDMFile { public: modelCDMCMakeListsFile(); - modelCDMCMakeListsFile(const std::string& path, const int& level = 1); + modelCDMCMakeListsFile(const std::string& path, const std::string& name = "CMakeLists.txt", const int& level = 1); ~modelCDMCMakeListsFile(); bool OpenFile(std::string*& result); diff --git a/lib/creaDevManagerLib/modelCDMFile.cpp b/lib/creaDevManagerLib/modelCDMFile.cpp index 6767b98..039de47 100644 --- a/lib/creaDevManagerLib/modelCDMFile.cpp +++ b/lib/creaDevManagerLib/modelCDMFile.cpp @@ -44,24 +44,18 @@ modelCDMFile::modelCDMFile() { } -modelCDMFile::modelCDMFile(const std::string& path, const int& level) +modelCDMFile::modelCDMFile(const std::string& path, const std::string& name, const int& level) { this->children.clear(); this->level = level; - - std::vector words; - std::string delimiters; - //TODO::fix for windows - delimiters = "/"; - CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties); - this->name = words[words.size()-1]; - + this->name = name; this->path = path; this->type = wxDIR_FILES; std::ifstream in(path.c_str(), std::ifstream::in | std::ifstream::binary); in.seekg(0, std::ifstream::end); this->length = in.tellg(); + in.close(); } @@ -88,6 +82,10 @@ const bool modelCDMFile::Refresh(std::string*& result) in.close(); return false; } + std::ifstream in2(path.c_str(), std::ifstream::in | std::ifstream::binary); + in2.seekg(0, std::ifstream::end); + this->length = in2.tellg(); + in2.close(); return true; } diff --git a/lib/creaDevManagerLib/modelCDMFile.h b/lib/creaDevManagerLib/modelCDMFile.h index 228447f..f521608 100644 --- a/lib/creaDevManagerLib/modelCDMFile.h +++ b/lib/creaDevManagerLib/modelCDMFile.h @@ -44,7 +44,7 @@ class modelCDMFile : public modelCDMIProjectTreeNode { public: modelCDMFile(); - modelCDMFile(const std::string& path, const int& level = 3); + modelCDMFile(const std::string& path, const std::string& name, const int& level = 3); ~modelCDMFile(); bool OpenFile(std::string* & result, const std::string& command = ""); diff --git a/lib/creaDevManagerLib/modelCDMFolder.cpp b/lib/creaDevManagerLib/modelCDMFolder.cpp index 28d7a95..c1ef911 100644 --- a/lib/creaDevManagerLib/modelCDMFolder.cpp +++ b/lib/creaDevManagerLib/modelCDMFolder.cpp @@ -47,21 +47,14 @@ modelCDMFolder::modelCDMFolder() this->CMakeLists = NULL; } -modelCDMFolder::modelCDMFolder(const std::string& path, const int& level) +modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, const int& level) { //set attributes this->children.clear(); this->level = level; this->CMakeLists = NULL; this->length = 0; - - std::vector words; - std::string delimiters; - //TODO::fix for windows - delimiters = "/"; - CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties); - this->name = words[words.size()-1]; - + this->name = name; this->path = path; this->type = wxDIR_DIRS; @@ -77,7 +70,7 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const int& level) std::string stdfileName = crea::wx2std(fileName); //if is an unknown folder, create folder - 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); } @@ -90,12 +83,12 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const int& level) //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); @@ -123,13 +116,13 @@ modelCDMFolder::~modelCDMFolder() modelCDMFolder* modelCDMFolder::CreateFolder(const std::string& name, std::string*& result) { //TODO:: mkdir depending on OS - std::string command = "mkdir " + path + "/" + name; + std::string command = "mkdir \"" + path + CDMUtilities::SLASH + name + "\""; if(system(command.c_str())) { result = new std::string("Error executing: " + command + "."); return NULL; } - modelCDMFolder* folder = new modelCDMFolder(path + "/" + name, level + 1); + modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1); this->folders.push_back(folder); this->children.push_back(folder); @@ -187,7 +180,7 @@ const bool modelCDMFolder::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->folders.push_back(folder); this->children.push_back(folder); } @@ -204,7 +197,7 @@ const bool modelCDMFolder::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 @@ -215,6 +208,7 @@ const bool modelCDMFolder::Refresh(std::string*& result) return false; } } + //if is an unknown file, create file else { @@ -232,7 +226,7 @@ const bool modelCDMFolder::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); } } diff --git a/lib/creaDevManagerLib/modelCDMFolder.h b/lib/creaDevManagerLib/modelCDMFolder.h index 2bda707..a4ea6e7 100644 --- a/lib/creaDevManagerLib/modelCDMFolder.h +++ b/lib/creaDevManagerLib/modelCDMFolder.h @@ -45,7 +45,7 @@ class modelCDMFolder : public modelCDMIProjectTreeNode { public: modelCDMFolder(); - modelCDMFolder(const std::string& path, const int& level = 3); + modelCDMFolder(const std::string& path, const std::string& name, const int& level = 3); ~modelCDMFolder(); modelCDMCMakeListsFile* GetCMakeLists() const; diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index a0ece82..416c1ff 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -45,10 +45,10 @@ modelCDMLib::modelCDMLib() { } -modelCDMLib::modelCDMLib(const std::string& path, const int& level) +modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const int& level) { this->type = wxDIR_DIRS; - this->name = "lib"; + this->name = name; this->level = level; this->path = path; @@ -69,7 +69,7 @@ modelCDMLib::modelCDMLib(const std::string& path, const int& level) { std::string stdfileName = crea::wx2std(fileName); - modelCDMLibrary* library = new modelCDMLibrary(pathFixed + "/" + stdfileName, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); @@ -84,13 +84,13 @@ modelCDMLib::modelCDMLib(const std::string& path, const int& level) //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); } //if is an unknown file, create file 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)); } cont = dir.GetNext(&fileName); @@ -110,13 +110,11 @@ const std::vector& modelCDMLib::GetLibraries() const modelCDMLibrary* modelCDMLib::CreateLibrary( const std::string& name, - std::string*& result, - const std::string& path + std::string*& result ) { //copy template library folder with new name - //TODO: fix for windows - std::string copyCommand = "cp -r " + this->path + "/template_lib " + this->path + "/" + name; + std::string copyCommand = "cp -r \"" + this->path + CDMUtilities::SLASH + "template_lib\" \"" + this->path + CDMUtilities::SLASH + name + "\""; if(system(copyCommand.c_str())) { result = new std::string("An error occurred while running '" + copyCommand + "'."); @@ -124,13 +122,13 @@ modelCDMLibrary* modelCDMLib::CreateLibrary( } //set name of library in CMakeLists inside copied folder std::string line; - std::ifstream in((this->path + "/" + name + "/CMakeLists.txt").c_str()); + std::ifstream in((this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt").c_str()); if( !in.is_open()) { result = new std::string("CMakeLists.txt file failed to open."); return NULL; } - std::ofstream out((this->path + "/" + name + "/CMakeLists.txt.tmp").c_str()); + std::ofstream out((this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str()); while (getline(in, line)) { if(line == "SET ( LIBRARY_NAME MyLib )") @@ -140,7 +138,7 @@ modelCDMLibrary* modelCDMLib::CreateLibrary( in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/" + name + "/CMakeLists.txt.tmp " + this->path + "/" + name + "/CMakeLists.txt"; + std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\""; if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -148,14 +146,13 @@ modelCDMLibrary* modelCDMLib::CreateLibrary( } //add library to model - //TODO: fix for windows - modelCDMLibrary* library = new modelCDMLibrary(this->path + "/" + name, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); this->SortChildren(); - result = new std::string(this->path + "/" + name); + result = new std::string(this->path + CDMUtilities::SLASH + name); return library; } @@ -163,9 +160,6 @@ const bool modelCDMLib::Refresh(std::string*& result) { std::cout << "refreshing lib" << std::endl; this->type = wxDIR_DIRS; - this->name = "lib"; - this->level = level; - this->path = path; @@ -198,7 +192,7 @@ const bool modelCDMLib::Refresh(std::string*& result) } if(!found) { - modelCDMLibrary* library = new modelCDMLibrary(this->path + "/" + stdfileName, this->level + 1); + modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->libraries.push_back(library); this->children.push_back(library); } @@ -215,7 +209,7 @@ const bool modelCDMLib::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 @@ -243,7 +237,7 @@ const bool modelCDMLib::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); } } diff --git a/lib/creaDevManagerLib/modelCDMLib.h b/lib/creaDevManagerLib/modelCDMLib.h index 47de063..59d1196 100644 --- a/lib/creaDevManagerLib/modelCDMLib.h +++ b/lib/creaDevManagerLib/modelCDMLib.h @@ -45,15 +45,14 @@ class modelCDMLib : public modelCDMFolder { public: modelCDMLib(); - modelCDMLib(const std::string& path, const int& level = 1); + modelCDMLib(const std::string& path, const std::string& name = "lib", const int& level = 1); ~modelCDMLib(); const std::vector& GetLibraries() const; modelCDMLibrary* CreateLibrary( const std::string& name, - std::string*& result, - const std::string& path = "/" + std::string*& result ); virtual const bool Refresh(std::string*& result); diff --git a/lib/creaDevManagerLib/modelCDMLibrary.cpp b/lib/creaDevManagerLib/modelCDMLibrary.cpp index 560759e..e16eeae 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.cpp +++ b/lib/creaDevManagerLib/modelCDMLibrary.cpp @@ -45,16 +45,10 @@ modelCDMLibrary::modelCDMLibrary() { } -modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level) +modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& name, const int& level) { //folder name - std::vector words; - std::string delimiters; - //TODO::fix for windows - delimiters = "/"; - CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties); - this->name = words[words.size()-1]; - + this->name = name; //path this->path = CDMUtilities::fixPath(path); //type @@ -63,7 +57,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level) this->level = level; //open CMakeList - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -109,7 +103,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level) { std::string stdfileName = crea::wx2std(fileName); - modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1); + modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->folders.push_back(folder); this->children.push_back(folder); @@ -124,13 +118,13 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const int& level) //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { - 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); } //if is an unknown file, create file else { - this->children.push_back(new modelCDMFile(this->path + "/" + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } cont = dir.GetNext(&fileName); @@ -160,14 +154,14 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& std::string line; //opening original cmakelists - std::ifstream in((this->path + "/CMakeLists.txt").c_str()); + 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; } //opening temporal cmakelists - std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -183,7 +177,7 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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 + "'."); @@ -197,13 +191,13 @@ bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::string*& result) { //TODO:: mkdir depending on OS - std::string command = "mkdir " + path + "/" + name; + std::string command = "mkdir \"" + path + CDMUtilities::SLASH + name + "\""; if(system(command.c_str())) { result = new std::string("Error executing: " + command + "."); return NULL; } - modelCDMFolder* folder = new modelCDMFolder(path + "/" + name, level + 1); + modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1); this->folders.push_back(folder); this->children.push_back(folder); @@ -216,7 +210,7 @@ const bool modelCDMLibrary::Refresh(std::string*& result) this->type = wxDIR_DIRS; //open CMakeList - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -279,7 +273,7 @@ const bool modelCDMLibrary::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->folders.push_back(folder); this->children.push_back(folder); } @@ -296,7 +290,7 @@ const bool modelCDMLibrary::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 @@ -324,7 +318,7 @@ const bool modelCDMLibrary::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); } } diff --git a/lib/creaDevManagerLib/modelCDMLibrary.h b/lib/creaDevManagerLib/modelCDMLibrary.h index 6bcee75..728b5c9 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.h +++ b/lib/creaDevManagerLib/modelCDMLibrary.h @@ -44,7 +44,7 @@ class modelCDMLibrary : public modelCDMFolder { public: modelCDMLibrary(); - modelCDMLibrary(const std::string& path, const int& level=2); + modelCDMLibrary(const std::string& path, const std::string& name, const int& level = 2); ~modelCDMLibrary(); const std::string& GetNameLibrary() const; diff --git a/lib/creaDevManagerLib/modelCDMMain.cpp b/lib/creaDevManagerLib/modelCDMMain.cpp index bb37b3d..7537c46 100644 --- a/lib/creaDevManagerLib/modelCDMMain.cpp +++ b/lib/creaDevManagerLib/modelCDMMain.cpp @@ -83,8 +83,8 @@ bool modelCDMMain::CreateProject( std::string command2("del "); command += "\"" + locationFixed + "\" \"" + name + "\""; - command1 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + locationFixed + "\\" + name + "\\CMakeLists.txt\""; - command2 += "\"" + locationFixed +"\\"+name+"\\CMakeLists.txt.in\""; + command1 += "\"" + locationFixed +CDMUtilities::SLASH+name+CDMUtilities::SLASH+"CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + locationFixed + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\""; + command2 += "\"" + locationFixed +CDMUtilities::SLASH+name+CDMUtilities::SLASH+"CMakeLists.txt.in\""; if (system (command.c_str())) @@ -97,21 +97,21 @@ bool modelCDMMain::CreateProject( system ( command2.c_str() ); char *author = author.c_str(); - std::string nomDirectory = locationFixed + "\\" + name; - std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG"; + std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name; + std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG"; std::string bbCreatePackage("bbCreatePackage "); - bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\""; system (bbCreatePackage.c_str()); std::string add; - add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> " + nomDirectory + "/CMakeLists.txt"; + add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\""; system(add.c_str()); - this->project = new modelCDMProject(nomDirectory); + this->project = new modelCDMProject(nomDirectory, name); #else // ------ LINUX / MacOS std::string command("creaNewProject.sh "); - command += "\"" + locationFixed + "\"" +" " + name; + command += "\"" + locationFixed + "\"" +" \"" + name + "\""; //std::cout << "executing " << command << std::endl; if (system ( command.c_str() ) ) { @@ -119,16 +119,16 @@ bool modelCDMMain::CreateProject( return false; } - std::string nomDirectory = locationFixed + "/" + name; - std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG"; + std::string nomDirectory = locationFixed + CDMUtilities::SLASH + name; + std::string nomPackageDirectory = nomDirectory + CDMUtilities::SLASH + "bbtk_" + name + "_PKG"; std::string bbCreatePackage("bbCreatePackage "); - bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + bbCreatePackage += "\"" + nomDirectory + "\" \"" + name + "\" \"" + author + "\" \"" + description + "\""; //std::cout << "executing " << bbCreatePackage << std::endl; system (bbCreatePackage.c_str()); std::string add; - add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt"; + add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> \"" + nomDirectory + CDMUtilities::SLASH + "CMakeLists.txt\""; //std::cout << "executing " << add << std::endl; system(add.c_str()); @@ -139,7 +139,7 @@ bool modelCDMMain::CreateProject( return false; } - this->project = new modelCDMProject(nomDirectory); + this->project = new modelCDMProject(nomDirectory, name); #endif @@ -161,7 +161,7 @@ bool modelCDMMain::OpenProject( std::string pathBuild = ""; //check if Makefile file exists - std::string pathMakefile = pathFixed + "/Makefile"; + std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile"; FILE* pFile = fopen(pathMakefile.c_str(), "r"); //is the binary folder @@ -191,7 +191,7 @@ bool modelCDMMain::OpenProject( bool isSource = false; std::string pathSource = ""; //check if CMakeLists file exists - std::string pathCMakeLists = pathFixed + "/CMakeLists.txt"; + std::string pathCMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt"; pFile = fopen(pathCMakeLists.c_str(), "r"); //is the source folder @@ -226,16 +226,19 @@ bool modelCDMMain::OpenProject( if (!CloseProject(result)) return false; } + std::vector words; + CDMUtilities::splitter::split(words, pathSource, CDMUtilities::SLASH, CDMUtilities::splitter::no_empties); std::cout << "Project sources at: " << pathSource << std::endl; if(isBinary) { std::cout << ", and built in: " << pathBuild << std::endl; - this->project = new modelCDMProject(pathSource, pathBuild); + + this->project = new modelCDMProject(pathSource, words[words.size()-1], pathBuild); } else { - this->project = new modelCDMProject(pathSource); + this->project = new modelCDMProject(pathSource, words[words.size()-1]); } } else diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index 097c360..a2ee6c8 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -46,13 +46,13 @@ modelCDMPackage::modelCDMPackage() this->src = NULL; } -modelCDMPackage::modelCDMPackage(const std::string& path, const int& level) +modelCDMPackage::modelCDMPackage(const std::string& path, const std::string& name, const int& level) { this->type = wxDIR_DIRS; + this->name = name; //Get Package Name - //TODO: set pathMakeLists for windows - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -121,12 +121,6 @@ modelCDMPackage::modelCDMPackage(const std::string& path, const int& level) } } - std::vector words; - std::string delimiters; - //TODO::fix for windows - delimiters = "/"; - CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties); - this->name = words[words.size()-1]; this->level = level; this->path = path; @@ -144,28 +138,12 @@ modelCDMPackage::modelCDMPackage(const std::string& path, const int& level) //if src, check for black boxes if(stdfileName == "src") { - this->src = new modelCDMPackageSrc(path + delimiters + "src", this->level + 1); + this->src = new modelCDMPackageSrc(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->src); - /*wxDir srcF(crea::std2wx((path + delimiters + "src").c_str())); - if (srcF.IsOpened()) - { - wxString srcName; - bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES); - while (innerCont) - { - if(crea::wx2std(srcName.substr(0,2)) == "bb") - { - modelCDMBlackBox* blackbox = new modelCDMBlackBox(crea::wx2std(srcName), path + delimiters + "src", this->level + 1); - this->blackBoxes.push_back(blackbox); - this->children.push_back(blackbox); - } - innerCont = srcF.GetNext(&srcName); - } - }*/ } else { - this->children.push_back(new modelCDMFolder(path + delimiters + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFolder(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } cont = dir.GetNext(&fileName); @@ -180,12 +158,12 @@ modelCDMPackage::modelCDMPackage(const std::string& path, const int& level) //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { - this->CMakeLists = new modelCDMCMakeListsFile(path + delimiters + stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } else { - this->children.push_back(new modelCDMFile(path + delimiters + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } //if is an unknown file, create file cont = dir.GetNext(&fileName); @@ -240,14 +218,14 @@ bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& resul std::string line; //opening original cmakelists - std::ifstream in((this->path + "/CMakeLists.txt").c_str()); + 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; } //opening temporal cmakelists - std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -263,7 +241,7 @@ bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& resul in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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 + "'."); @@ -288,14 +266,14 @@ bool modelCDMPackage::SetVersion(const std::string& version, std::string*& resul std::string line; //opening original cmakelists - std::ifstream in((this->path + "/CMakeLists.txt").c_str()); + 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; } //opening temporal cmakelists - std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -315,7 +293,7 @@ bool modelCDMPackage::SetVersion(const std::string& version, std::string*& resul in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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 + "'."); @@ -338,14 +316,14 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string std::string line; //opening original cmakelists - std::ifstream in((this->path + "/CMakeLists.txt").c_str()); + 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; } //opening temporal cmakelists - std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -361,7 +339,7 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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 + "'."); @@ -372,8 +350,10 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string return true; } -bool modelCDMPackage::CreateBlackBox( +modelCDMBlackBox* modelCDMPackage::CreateBlackBox( const std::string& name, + const std::string& type, + const std::string& format, const std::string& authors, const std::string& authorsEmail, const std::string& categories, @@ -381,21 +361,17 @@ bool modelCDMPackage::CreateBlackBox( ) { //TODO: implement method - return true; + return NULL; } const bool modelCDMPackage::Refresh(std::string*& result) { std::cout << "refreshing package" << std::endl; this->type = wxDIR_DIRS; - this->name = name; - this->level = level; - this->path = path; //Get Package Name - //TODO: set pathMakeLists for windows - std::string pathMakeLists = path + "/CMakeLists.txt"; + std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt"; std::ifstream confFile; confFile.open((pathMakeLists).c_str()); @@ -496,44 +472,9 @@ const bool modelCDMPackage::Refresh(std::string*& result) } else { - this->src = new modelCDMPackageSrc(path + "/" + "src", this->level +1); + this->src = new modelCDMPackageSrc(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level +1); this->children.push_back(this->src); } - /*wxDir srcF(crea::std2wx((path + "/" + "src").c_str())); - if (srcF.IsOpened()) - { - wxString srcName; - bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES); - while (innerCont) - { - std::string blackBoxName = crea::wx2std(srcName); - if(crea::wx2std(srcName.substr(0,2)) == "bb") - { - //check if box already exist - bool found = false; - for (int i = 0;!found && i < this->blackBoxes.size(); i++) - { - if (this->blackBoxes[i]->GetName() == blackBoxName) - { - found = true; - int pos = std::find(this->children.begin(), this->children.end(), this->blackBoxes[i]) - this->children.begin(); - checked[pos] = true; - checkedBlackBoxes[i] = true; - if(!this->blackBoxes[i]->Refresh(result)) - return false; - } - } - if(!found) - { - modelCDMBlackBox* blackBox = new modelCDMBlackBox(blackBoxName, path + "/" + "src", this->level +1); - this->blackBoxes.push_back(blackBox); - this->children.push_back(blackBox); - } - } - innerCont = srcF.GetNext(&srcName); - } - }*/ - } else { @@ -552,7 +493,7 @@ const bool modelCDMPackage::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); } } @@ -570,7 +511,7 @@ const bool modelCDMPackage::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 @@ -598,7 +539,7 @@ const bool modelCDMPackage::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); } } diff --git a/lib/creaDevManagerLib/modelCDMPackage.h b/lib/creaDevManagerLib/modelCDMPackage.h index d79db95..3745fb2 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.h +++ b/lib/creaDevManagerLib/modelCDMPackage.h @@ -45,7 +45,7 @@ class modelCDMPackage : public modelCDMFolder { public: modelCDMPackage(); - modelCDMPackage(const std::string& path, const int& level = 1); + modelCDMPackage(const std::string& path, const std::string& name, const int& level = 1); ~modelCDMPackage(); const std::string& GetNamePackage() const; @@ -61,8 +61,10 @@ public: bool SetDescription(const std::string& description, std::string*& result); - bool CreateBlackBox( + modelCDMBlackBox* CreateBlackBox( const std::string& name, + const std::string& type = "std", + const std::string& format = "C++", const std::string& authors = "unknown", const std::string& authorsEmail = "", const std::string& categories = "empty", diff --git a/lib/creaDevManagerLib/modelCDMPackageSrc.cpp b/lib/creaDevManagerLib/modelCDMPackageSrc.cpp index b758cc4..16e7e59 100644 --- a/lib/creaDevManagerLib/modelCDMPackageSrc.cpp +++ b/lib/creaDevManagerLib/modelCDMPackageSrc.cpp @@ -47,14 +47,14 @@ modelCDMPackageSrc::modelCDMPackageSrc() this->CMakeLists = NULL; } -modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const int& level) +modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const std::string& name, const int& level) { //set attributes this->children.clear(); this->level = level; this->CMakeLists = NULL; this->length = 0; - this->name = "src"; + this->name = name; this->path = CDMUtilities::fixPath(path); this->type = wxDIR_DIRS; @@ -69,7 +69,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const int& level std::string stdfileName = crea::wx2std(fileName); //if is an unknown folder, create folder - this->children.push_back(new modelCDMFolder(path + "/" + stdfileName, this->level + 1)); + this->children.push_back(new modelCDMFolder(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); cont = dir.GetNext(&fileName); } @@ -78,7 +78,7 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const int& level if (cont) { std::string stdfileName = crea::wx2std(fileName); - this->CMakeLists = new modelCDMCMakeListsFile(path + "/" + stdfileName, this->level + 1); + this->CMakeLists = new modelCDMCMakeListsFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } @@ -90,14 +90,15 @@ modelCDMPackageSrc::modelCDMPackageSrc(const std::string& path, const int& level if(stdfileName.substr(0,2) == "bb") { - file = new modelCDMFile(path + "/" + stdfileName, this->level + 1); + file = new modelCDMFile(path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(file); - modelCDMBlackBox* blackBox = new modelCDMBlackBox(stdfileName, path, level + 1); + modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1); blackBox->SetHeaderFile(file); - cont = dir.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES); + wxDir dir2(crea::std2wx(path)); + cont = dir2.GetFirst(&fileName, crea::std2wx(stdfileName.substr(0,stdfileName.size()-2) + ".cxx"), wxDIR_FILES); if (cont) { - file = new modelCDMFile(path + "/" + crea::wx2std(fileName), this->level + 1); + file = new modelCDMFile(path + CDMUtilities::SLASH + crea::wx2std(fileName), crea::wx2std(fileName), this->level + 1); this->children.push_back(file); blackBox->SetSourceFile(file); } @@ -128,6 +129,20 @@ const std::vector& modelCDMPackageSrc::GetBlackBoxes() const return this->blackBoxes; } +modelCDMBlackBox* modelCDMPackageSrc::CreateBlackBox( + const std::string& name, + const std::string& package, + const std::string& type, + const std::string& format, + const std::string& authors, + const std::string& authorsEmail, + const std::string& categories, + const std::string& description) +{ + //TODO: implement method + return NULL; +} + const bool modelCDMPackageSrc::Refresh(std::string*& result) { //set attributes @@ -161,7 +176,7 @@ const bool modelCDMPackageSrc::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); } cont = dir.GetNext(&fileName); @@ -177,7 +192,7 @@ const bool modelCDMPackageSrc::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 @@ -205,7 +220,7 @@ const bool modelCDMPackageSrc::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); } } @@ -228,7 +243,7 @@ const bool modelCDMPackageSrc::Refresh(std::string*& result) if (!found) { - modelCDMBlackBox* blackBox = new modelCDMBlackBox(stdfileName, path + "/" + stdfileName, level + 1); + modelCDMBlackBox* blackBox = new modelCDMBlackBox(path, stdfileName.substr(2,stdfileName.size()-4), level + 1); this->blackBoxes.push_back(blackBox); } diff --git a/lib/creaDevManagerLib/modelCDMPackageSrc.h b/lib/creaDevManagerLib/modelCDMPackageSrc.h index 14de2d7..d94afbd 100644 --- a/lib/creaDevManagerLib/modelCDMPackageSrc.h +++ b/lib/creaDevManagerLib/modelCDMPackageSrc.h @@ -45,11 +45,22 @@ class modelCDMPackageSrc : public modelCDMFolder { public: modelCDMPackageSrc(); - modelCDMPackageSrc(const std::string& path, const int& level = 3); + modelCDMPackageSrc(const std::string& path, const std::string& name = "src", const int& level = 3); ~modelCDMPackageSrc(); const std::vector& GetBlackBoxes() const; + modelCDMBlackBox* CreateBlackBox( + const std::string& name, + const std::string& package, + const std::string& type = "std", + const std::string& format = "C++", + const std::string& authors = "unknown", + const std::string& authorsEmail = "", + const std::string& categories = "empty", + const std::string& description = "no description" + ); + virtual const bool Refresh(std::string*& result); private: diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index 7ebe67d..8206a75 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -55,6 +55,7 @@ modelCDMProject::modelCDMProject() modelCDMProject::modelCDMProject( const std::string& path, + const std::string& name, const std::string& buildPath ) { @@ -62,8 +63,7 @@ modelCDMProject::modelCDMProject( //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()); @@ -156,26 +156,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); @@ -189,12 +189,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); @@ -254,17 +254,17 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul tm* ltm = localtime(&now); std::stringstream date; - date << ltm->tm_mday << "/" << ltm->tm_mon << "/" << 1900 + ltm->tm_year; + 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 + "/CMakeLists.txt").c_str()); + 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 + "/CMakeLists.txt.tmp").c_str()); + 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."); @@ -285,7 +285,7 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul in.close(); out.close(); //delete old file and rename new file - std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt"; + 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 + "'."); @@ -355,7 +355,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())) { @@ -364,8 +364,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); @@ -373,7 +372,7 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( this->SortChildren(); - result = new std::string(this->path + "/" + name); + result = new std::string(this->path + CDMUtilities::SLASH + name); return package; } @@ -433,8 +432,7 @@ 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()); @@ -516,7 +514,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 @@ -532,7 +530,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 @@ -563,7 +561,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); } @@ -586,7 +584,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); } } @@ -604,7 +602,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 @@ -632,7 +630,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); } } diff --git a/lib/creaDevManagerLib/modelCDMProject.h b/lib/creaDevManagerLib/modelCDMProject.h index e3ba19a..b2a2a11 100644 --- a/lib/creaDevManagerLib/modelCDMProject.h +++ b/lib/creaDevManagerLib/modelCDMProject.h @@ -61,7 +61,7 @@ public: * @param path The source path. * @param buildPath The build path. By default it's an empty string. */ - modelCDMProject(const std::string& path, const std::string& buildPath = ""); + modelCDMProject(const std::string& path, const std::string& name, const std::string& buildPath = ""); /** * Destructor. diff --git a/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp new file mode 100644 index 0000000..166ba83 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp @@ -0,0 +1,209 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ + */ + + +/* + * wxCDMNewBlackBoxDialog.cpp + * + * Created on: 26/12/2012 + * Author: Daniel Felipe Gonzalez Obando + */ + +#include "wxCDMNewBlackBoxDialog.h" + +#include "creaDevManagerIds.h" + +BEGIN_EVENT_TABLE(wxCDMNewBlackBoxDialog, wxDialog) +EVT_BUTTON(ID_BUTTON_NEXT, wxCDMNewBlackBoxDialog::OnCreateBlackBox) +EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMNewBlackBoxDialog::OnCancel) +END_EVENT_TABLE() + +wxCDMNewBlackBoxDialog::wxCDMNewBlackBoxDialog( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + wxCDMNewBlackBoxDialog::Create(parent, id, caption, position, size, style); +} + +wxCDMNewBlackBoxDialog::~wxCDMNewBlackBoxDialog() +{ +} + +bool wxCDMNewBlackBoxDialog::Create( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long int style +) +{ + wxDialog::Create(parent, id, caption, position, size, style); + + this->CreateControls(); + + return TRUE; +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxName() const +{ + return this->blackBoxName->GetValue(); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxAuthor() const +{ + return this->blackBoxAuthor->GetValue(); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxAuthorEmail() const +{ + return this->blackBoxAuthorEmail->GetValue(); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxDescription() const +{ + return this->blackBoxDescription->GetValue(); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxCategories() const +{ + return this->blackBoxCategories->GetValue(); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxType() const +{ + return this->blackBoxType->GetString(this->blackBoxType->GetCurrentSelection()); +} + +const wxString wxCDMNewBlackBoxDialog::GetBlackBoxFormat() const +{ + return this->blackBoxFormat->GetString(this->blackBoxFormat->GetCurrentSelection()); +} + +void wxCDMNewBlackBoxDialog::CreateControls() +{ + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Create a new black box"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxT("Please fill the following details."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15); + + wxStaticText *stxtPrjName = new wxStaticText(this, -1, wxT("Black Box Name")); + wxStaticText *stxtPrjAuth = new wxStaticText(this, -1, wxT("Black Box Authors (separated by ',')")); + wxStaticText *stxtPrjAuthEmail = new wxStaticText(this, -1, wxT("Black Box Authors' Email")); + wxStaticText *stxtPrjDsc = new wxStaticText(this, -1, wxT("Black Box Description")); + wxStaticText *stxtPrjCat = new wxStaticText(this, -1, wxT("Black Box Categories (separated by ',')")); + wxStaticText *stxtPrjTyp = new wxStaticText(this, -1, wxT("Black Box Type")); + wxStaticText *stxtPrjFmt = new wxStaticText(this, -1, wxT("Black Box Format")); + + this->blackBoxName = new wxTextCtrl(this, -1); + this->blackBoxAuthor = new wxTextCtrl(this, -1); + this->blackBoxAuthorEmail = new wxTextCtrl(this, -1); + this->blackBoxDescription = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); + this->blackBoxCategories = new wxTextCtrl(this, -1); + wxString BBTypes[] = + { + wxT("std"), + wxT("VTK-ImageAlgorithm"), + wxT("VTK-PolyAlgorithm"), + wxT("widget") + }; + this->blackBoxType = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, BBTypes); + + wxString BBFormats[] = + { + wxT("C++"), + wxT("XML") + }; + this->blackBoxFormat = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, BBFormats); + + formItems->Add(stxtPrjName, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxName, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjAuth, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxAuthor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjAuthEmail, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxAuthorEmail, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjDsc, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxDescription, 1, wxEXPAND); + formItems->Add(stxtPrjCat,0 , wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxCategories, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjTyp, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxType, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjFmt, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->blackBoxFormat, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL); + + formItems->AddGrowableCol(1,1); + formItems->AddGrowableRow(3,1); + + v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15); + + wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL); + h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxT("Create Black Box")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + + v_sizer1->Add(h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30); + + SetSizer(v_sizer1); +} + +void wxCDMNewBlackBoxDialog::OnCreateBlackBox(wxCommandEvent& event) +{ + bool ready = true; + + if(ready && this->blackBoxName->GetValue() == wxT("")) + { + wxMessageBox(wxT("The black box name cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + if(ready && this->blackBoxAuthor->GetValue() == wxT("")) + { + wxMessageBox(wxT("The black box author has to be specified"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + + if(ready) + { + this->EndModal(wxID_FORWARD); + } + event.Skip(); +} + +void wxCDMNewBlackBoxDialog::OnCancel(wxCommandEvent& event) +{ + this->EndModal(wxID_CANCEL); + event.Skip(); +} diff --git a/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.h b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.h new file mode 100644 index 0000000..9d5a7fc --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.h @@ -0,0 +1,91 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + + +/* + * wxCDMNewBlackBoxDialog.h + * + * Created on: 26/12/2012 + * Author: Daniel Felipe Gonzalez Obando + */ + +#ifndef WXCDMNEWBLACKBOXDIALOG_H_ +#define WXCDMNEWBLACKBOXDIALOG_H_ + +#include +#include +#include + +class wxCDMNewBlackBoxDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() +public: + wxCDMNewBlackBoxDialog( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("New Black Box"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(500,500), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + ~wxCDMNewBlackBoxDialog(); + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("New Black Box"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(500,500), + long style = wxDEFAULT_DIALOG_STYLE + ); + + const wxString GetBlackBoxName() const; + const wxString GetBlackBoxAuthor() const; + const wxString GetBlackBoxAuthorEmail() const; + const wxString GetBlackBoxDescription() const ; + const wxString GetBlackBoxCategories() const ; + const wxString GetBlackBoxType() const; + const wxString GetBlackBoxFormat() const; + +protected: + void CreateControls(); + +private: + wxTextCtrl* blackBoxName; + wxTextCtrl* blackBoxAuthor; + wxTextCtrl* blackBoxAuthorEmail; + wxTextCtrl* blackBoxDescription; + wxTextCtrl* blackBoxCategories; + wxChoice* blackBoxType; + wxChoice* blackBoxFormat; + +//handlers +protected: + void OnCreateBlackBox(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); +}; + +#endif /* WXCDMNEWBLACKBOXDIALOG_H_ */ -- 2.45.1