X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMProject.cpp;h=886a3659c4854cf4163be399bfb3b9f5c4c8de36;hb=1c3bc8de4d0e9b492f95c5d8c468881a80f420da;hp=c39463376e247080cecea63f49a45723ac5e4de9;hpb=eadb37661531b59bf98dd976e29c5c5dba682bb7;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index c394633..886a365 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -40,10 +40,12 @@ #include #include #include +#include #include "CDMUtilities.h" #include "creaWx.h" #include "wx/dir.h" +#include modelCDMProject::modelCDMProject() { @@ -168,17 +170,54 @@ modelCDMProject::modelCDMProject( this->lib = new modelCDMLib(this, 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(this, 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(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + bool isPackage = false; + + // check if cmakelists file exist in folder. + std::string tmppath = this->GetPath() + CDMUtilities::SLASH + stdfileName + CDMUtilities::SLASH + "CMakeLists.txt"; + CDMUtilities::CMLFile CMfile = CDMUtilities::readCMLFile(tmppath.c_str()); + if (CMfile.size() > 0) + { + std::cout << "-->" << stdfileName << " ::has cmakelists" << std::endl; + // check if cmakelists file has the SET(BBTK_PACKAGE_NAME [pkgname]) instruction. + for (int i = 0; !isPackage && i < CMfile.size(); ++i) { + if (CMfile[i].first == "command" && CMfile[i].second.size() > 1) + { + std::string cm = CMfile[i].second[0]; + + int pos = 1; + while(pos < CMfile[i].second.size()-1 && !isalpha(CMfile[i].second[pos][0])) + pos++; + + std::string pm1 = CMfile[i].second[pos]; + + std::cout << cm << " " << pm1 << std::endl; + std::transform(cm.begin(), cm.end(), cm.begin(), ::toupper); + std::transform(pm1.begin(), pm1.end(), pm1.begin(), ::toupper); + if(cm == "SET" && pm1 == "BBTK_PACKAGE_NAME") + { + isPackage = true; + } + } + } + } + + // if package, create package + if(isPackage) + { + std::cout << "is Package\n"; + modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + std::cout << "Package created\n"; + this->packages.push_back(package); + this->children.push_back(package); + } + // if is an unknown folder, create folder + else + { + this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + } + } cont = dir.GetNext(&fileName); @@ -188,6 +227,12 @@ modelCDMProject::modelCDMProject( while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType; + if(fileTypePos != std::string::npos) + fileType = stdfileName.substr(fileTypePos); + else + fileType = ""; //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -195,11 +240,23 @@ modelCDMProject::modelCDMProject( this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); this->children.push_back(this->CMakeLists); } + //if is a code file, create modelCDMCodeFile + else if( + fileType == ".c" || + fileType == ".cxx" || + fileType == ".h" || + fileType == ".cpp" || + fileType == ".txx" || + fileType == ".cmake" ) + { + this->children.push_back(new modelCDMCodeFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + } + //if is an unknown file, create file else { this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); } - //if is an unknown file, create file + cont = dir.GetNext(&fileName); } } @@ -250,7 +307,11 @@ modelCDMLib* modelCDMProject::GetLib() const std::string modelCDMProject::GetBuildInstruction() const { - std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/ + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string commandline = crea::wx2std(pConfig->Read(wxT("BUILD_COMMAND"), crea::std2wx(CDMUtilities::BUILD_COMMAND))); + + + std::string makeComm = "cd \"" + this->buildPath + "\";" + commandline;// -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/ return makeComm; } @@ -576,7 +637,7 @@ 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") + /*else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG") { bool found = false; for (int i = 0; !found && i < (int)(this->packages.size()); i++) @@ -598,26 +659,85 @@ const bool modelCDMProject::Refresh(std::string*& result) this->children.push_back(package); } - } - //if is an unknown folder, create folder + }*/ + // package or folder else { - bool found = false; - for (int i = 0; !found && i < (int)(this->children.size()); i++) + bool isPackage = false; + + // check if cmakelists file exist in folder. + std::string tmppath = this->GetPath() + CDMUtilities::SLASH + stdfileName + CDMUtilities::SLASH + "CMakeLists.txt"; + CDMUtilities::CMLFile CMfile = CDMUtilities::readCMLFile(tmppath.c_str()); + if (CMfile.size() > 0) + { - if (this->children[i]->GetName() == stdfileName) + // check if cmakelists file has the SET(BBTK_PACKAGE_NAME [pkgname]) instruction. + for (int i = 0; !isPackage && i < CMfile.size(); ++i) { + if (CMfile[i].first == "command" && CMfile[i].second.size() > 1) + { + std::string cm = CMfile[i].second[0]; + + int pos = 1; + while(pos < CMfile[i].second.size()-1 && !isalpha(CMfile[i].second[pos][0])) + pos++; + + std::string pm1 = CMfile[i].second[pos]; + + std::cout << cm << " " << pm1 << std::endl; + std::transform(cm.begin(), cm.end(), cm.begin(), ::toupper); + std::transform(pm1.begin(), pm1.end(), pm1.begin(), ::toupper); + if(cm == "SET" && pm1 == "BBTK_PACKAGE_NAME") + { + isPackage = true; + } + } + } + } + + // if package, create package + if (isPackage) + { + bool found = false; + for (int i = 0; !found && i < (int)(this->packages.size()); i++) { - found = true; - checked[i] = true; - if(!this->children[i]->Refresh(result)) - return false; + if (this->packages[i]->GetName() == stdfileName) + { + found = true; + int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin(); + checked[pos] = true; + checkedPackages[i] = true; + if(!this->packages[i]->Refresh(result)) + return false; + } } - } - if(!found) + if (!found) + { + modelCDMPackage* package = new modelCDMPackage(this, this->path + 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 { - modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); - this->children.push_back(folder); + bool found = false; + for (int i = 0; !found && i < (int)(this->children.size()); i++) + { + if (this->children[i]->GetName() == stdfileName) + { + found = true; + checked[i] = true; + if(!this->children[i]->Refresh(result)) + return false; + } + } + + if(!found) + { + modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->children.push_back(folder); + } } } @@ -628,6 +748,12 @@ const bool modelCDMProject::Refresh(std::string*& result) while (cont) { std::string stdfileName = crea::wx2std(fileName); + std::size_t fileTypePos = stdfileName.find_last_of("."); + std::string fileType; + if(fileTypePos != std::string::npos) + fileType = stdfileName.substr(fileTypePos); + else + fileType = ""; //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") @@ -645,6 +771,7 @@ const bool modelCDMProject::Refresh(std::string*& result) return false; } } + //if is a code file, create modelCDMCodeFile //if is an unknown file, create file else { @@ -662,8 +789,21 @@ const bool modelCDMProject::Refresh(std::string*& result) if(!found) { - modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); - this->children.push_back(file); + if( + fileType == ".c" || + fileType == ".cxx" || + fileType == ".h" || + fileType == ".cpp" || + fileType == ".txx" || + fileType == ".cmake" ) + { + this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1)); + } + else + { + modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); + this->children.push_back(file); + } } } @@ -1100,3 +1240,206 @@ bool modelCDMProject::SetPackageInclude(const std::string& package_name, const b } return false; } + +std::map modelCDMProject::Get3rdPartyLibraries() +{ + std::map correspondence; + correspondence["USE_CREA"] = "Crea"; + correspondence["USE_GDCM"] = "GDCM"; + correspondence["USE_GDCM_VTK"] = "GDCM_VTK"; + correspondence["USE_GDCM2"] = "GDCM2"; + correspondence["USE_WXWIDGETS"] = "WxWidgets"; + correspondence["USE_KWWIDGETS"] = "KWWidgets"; + correspondence["USE_VTK"] = "VTK"; + correspondence["USE_ITK"] = "ITK"; + correspondence["USE_BOOST"] = "Boost"; + + std::map res; + res["Crea"] = false; + res["GDCM"] = false; + res["GDCM_VTK"] = false; + res["GDCM2"] = false; + res["WxWidgets"] = false; + res["KWWidgets"] = false; + res["VTK"] = false; + res["ITK"] = false; + res["Boost"] = false; + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*USE_\\w+\\s+ON"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + while(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what[0].str() << std::endl; + boost::regex expression1 = boost::regex("USE_\\w+"); + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1; + if(boost::regex_search(start1, end1, what1, expression1, flags)) + { + std::string dete = what1.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << dete << std::endl; + if(correspondence.find(dete) != correspondence.end()) + res[correspondence[dete]] = true; + } + start = what[0].second; + } + } + + return res; +} + +bool modelCDMProject::Set3rdPartyLibrary(const std::string& library_name, + const bool& toInclude) +{ + std::map correspondence; + correspondence["Crea"] = "USE_CREA"; + correspondence["GDCM"] = "USE_GDCM"; + correspondence["GDCM_VTK"] = "USE_GDCM_VTK"; + correspondence["GDCM2"] = "USE_GDCM2"; + correspondence["WxWidgets"] = "USE_WXWIDGETS"; + correspondence["KWWidgets"] = "USE_KWWIDGETS"; + correspondence["VTK"] = "USE_VTK"; + correspondence["ITK"] = "USE_ITK"; + correspondence["Boost"] = "USE_BOOST"; + + if (correspondence.find(library_name) != correspondence.end()) + { + std::string library_command = correspondence[library_name]; + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + std::string resCMfile = ""; + + std::string::const_iterator start, end; + boost::match_results what, tmp; + boost::match_flag_type flags = boost::match_default; + bool found = false; + + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing inclusions + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(!toInclude) + { + std::string dete = what.str(); + int pos = dete.find("ON",0); + dete.replace(pos, 2, "OFF"); + resCMfile += dete; + } + else + resCMfile += what.str(); + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing exclusions + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+OFF\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(toInclude) + { + std::string dete = what.str(); + int pos = dete.find("OFF",0); + dete.replace(pos, 3, "ON"); + resCMfile += dete; + } + else + resCMfile += what.str(); + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for existing commented inclusions + expression = boost::regex("^\\h*#+\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*" + library_command + "\\s+ON\\s*\\)"); + while(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(toInclude) + { + std::string dete = what.str(); + for (int i = 0; i < dete.size(); ++i) { + if(dete[i] == '#') + { + dete.erase(i,1); + i--; + } + } + resCMfile += dete; + } + else + resCMfile += what.str(); + + tmp = what; + start = what[0].second; + } + + if (found) + resCMfile += tmp.suffix().str(); + else + { + if(toInclude) + { + start = CMfile.begin(); + end = CMfile.end(); + + //search for position to insert + expression = boost::regex("^\\h*#\\h*Libraries\\/tools used\\h*$"); + if(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + resCMfile += what.str(); + resCMfile += "\nSET(" + library_command + " ON)"; + resCMfile += what.suffix().str(); + } + } + else + { + found = true; + } + } + } + } + if (!found) { + return false; + } + else + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + + return false; +}