From: unknown Date: Tue, 23 Apr 2013 12:26:00 +0000 (+0200) Subject: Merge remote-tracking branch 'refs/remotes/origin/master' into creaDevManagerCMake X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e5db5721e091541b11e8cff659e5832fa0b5c563;hp=e308b316bca88bedb8fb0aa3f4fabc33bc070b78;p=crea.git Merge remote-tracking branch 'refs/remotes/origin/master' into creaDevManagerCMake --- diff --git a/appli/creaDevManager/creaDevManager.cpp b/appli/creaDevManager/creaDevManager.cpp index fd922da..a57d7b2 100644 --- a/appli/creaDevManager/creaDevManager.cpp +++ b/appli/creaDevManager/creaDevManager.cpp @@ -49,7 +49,7 @@ bool wxCreaDevManagerApp::OnInit() mainWindow = new wxCDMMainFrame(NULL); SetTopWindow(mainWindow); - mainWindow->SetSize(750, 700); + mainWindow->SetSize(850, 700); wxToolTip::SetDelay(700); mainWindow->Show(true); std::cout << "Crea DevManager opened." << std::endl; diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index b4696b1..cc64ee3 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -356,4 +356,196 @@ namespace CDMUtilities return res; } + std::string readFile(const std::string& file_path) + { + std::string res; + std::ifstream file(file_path.c_str()); + if (file.is_open()) + { + char ch = file.get(); + while (!file.eof()) + { + res.push_back(ch); + ch = file.get(); + } + file.close(); + } + return res; + } + + bool writeFile(const std::string& file_path, const std::string& st) + { + std::ofstream file(file_path.c_str()); + if (file.is_open()) + { + file << st; + file.close(); + return true; + } + return false; + + } + + CMLFile readCMLFile(const std::string& file_path) + { + CMLFile res; + + std::ifstream file(file_path.c_str()); + if (file.is_open()) + { + char ch = file.get(); + while (!file.eof()) + { + syntaxElement element; + if (isspace(ch)) + { + //std::cout << "space" << std::endl; + element.first = "space"; + element.second.push_back(std::string(1,ch)); + } + else if (ch == '#') + { + //std::cout << "comment" << std::endl; + element.first = "comment"; + std::string commentValue; + while (ch != '\n') + { + commentValue.push_back(ch); + + ch = file.get(); + if (file.eof()) + break; + }; + if (!file.eof()) + commentValue.push_back('\n'); + element.second.push_back(commentValue); + } + else + { + //std::cout << "command" << std::endl; + element.first = "command"; + std::string commandValue; + while (true) + { + //std::cout << ch; + //std::cout.flush(); + while(!isspace(ch) && ch != '(' && ch != ')' && ch != '#') + { + if(ch == '"') + { + if (commandValue.size()) { + element.second.push_back(commandValue); + commandValue.clear(); + } + commandValue.push_back(ch); + ch = file.get(); + while(!file.eof() && ch != '"') + { + if(ch == '\\') + { + commandValue.push_back(ch); + ch = file.get(); + if(!file.eof()) + commandValue.push_back(ch); + } + else + { + commandValue.push_back(ch); + } + ch = file.get(); + } + if(!file.eof()) + commandValue.push_back(ch); + element.second.push_back(commandValue); + commandValue.clear(); + } + else + commandValue.push_back(ch); + + ch = file.get(); + } + + if (!file.eof() && (isspace(ch) || ch == '(' || ch == ')' || ch == '#')) + { + if (commandValue.size()) { + element.second.push_back(commandValue); + commandValue.clear(); + } + commandValue.push_back(ch); + if (ch == '#') { + while (ch != '\n') { + ch = file.get(); + if (file.eof()) + break; + commandValue.push_back(ch); + }; + } + element.second.push_back(commandValue); + if (commandValue == ")") + { + commandValue.clear(); + break; + } + commandValue.clear(); + } + + ch = file.get(); + if (file.eof()) + break; + } + } + res.push_back(element); + + ch = file.get(); + if (file.eof()) + break; + } + + file.close(); + } + +/* + std::cout << "CMakeLists: " << file_path << std::endl; + for (int i = 0; i < res.size(); ++i) { + if (res[i].first == "command") + std::cout << "@"; + for (int j = 0; j < res[i].second.size(); ++j) { + std::cout << "~" << res[i].second[j]; + } + if (res[i].first == "command") + std::cout << "@"; + } + std::cout << "End of file" << std::endl; +*/ + return res; + } + + bool writeCMLFile(const std::string& file_path, const CMLFile& data) + { + std::ofstream file(file_path.c_str()); + if(file.is_open()) + { + for (int i = 0; i < data.size(); ++i) { + for (int j = 0; j < data[i].second.size(); ++j) { + file << data[i].second[j]; + } + } + file.close(); + return true; + } + return false; + } + + + + void + normalizeStr(std::string& st) + { + while(st.size() && isspace(st[0])) + st.erase(0,1); + while(st.size() && isspace(st[st.size()-1])) + st.erase(st.size()-1,1); + return; + } + } diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index 5430aea..92fe3d0 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -36,6 +36,7 @@ #define CDMUTILITIES_H_ #include +#include #include namespace CDMUtilities @@ -175,6 +176,62 @@ namespace CDMUtilities * @return line stringified. */ std::string stringify(const std::string& line); + + //CMakeLists file handling + /** + * Type definition for the value of a syntax element for CMakeLists files + */ + typedef std::vector cmdValue; + + /** + * Type definition for the type of a syntax element for CMakeLists files + */ + typedef std::string cmdType; + + /** + * Type definition for syntax elements of a CMakeLists file + */ + typedef std::pair syntaxElement; + + /** + * Type definition for describing a CMakeLists file content + */ + typedef std::vector CMLFile; + + /** + * Reads a file as string and returns the read data. + * @param file_path Full path of the CMakeLists file. + * @return A string with the contents of the given file. + */ + std::string readFile(const std::string& file_path); + /** + * Writes the given string into a file and returns whether the operation is successful. + * @param file_path Full path of the CMakeLists file. + * @param st string to write. + * @return True if the operation was successful. + */ + bool writeFile(const std::string& file_path, const std::string& st); + + /** + * Reads a CMakeLists file and returns the read data. + * @param file_path Full path of the CMakeLists file. + * @return A CMLFile with the contents of the given file. + */ + CMLFile readCMLFile(const std::string& file_path); + + /** + * Writes the given data into specified CMakeLists file. + * @param file_path Full path of the CMakeLists file. + * @param data CMakeLists data. + * @return True if the operation was successful. + */ + bool writeCMLFile(const std::string& file_path, const CMLFile& data); + + /** + * @param st Strips all space character at the beginning and at the end of the string. + */ + void normalizeStr(std::string& st); + }; #endif /* CDMUTILITIES_H_ */ diff --git a/lib/creaDevManagerLib/CMakeLists.txt b/lib/creaDevManagerLib/CMakeLists.txt index 37aa14e..bb1dbea 100644 --- a/lib/creaDevManagerLib/CMakeLists.txt +++ b/lib/creaDevManagerLib/CMakeLists.txt @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image -# pour la Santé) +# 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 @@ -83,7 +83,7 @@ IF ( BUILD_${LIBRARY_NAME} ) # ${VTK_LIBRARIES} # ${ITK_LIBRARIES} # ${GDCM_LIBRARIES} - # ${BOOST_LIBRARIES} + ${BOOST_LIBRARIES} # If this library must link against other libraries # USER! : Add here any extra Library you need diff --git a/lib/creaDevManagerLib/creaDevManagerIds.h b/lib/creaDevManagerLib/creaDevManagerIds.h index a73f569..2ac3960 100644 --- a/lib/creaDevManagerLib/creaDevManagerIds.h +++ b/lib/creaDevManagerLib/creaDevManagerIds.h @@ -92,29 +92,41 @@ #define ID_BUTTON_OPEN_COMMAND 10317 #define ID_BUTTON_SET_VERSION 10318 #define ID_BUTTON_SET_BUILD_PATH 10319 -#define ID_BUTTON_SET_AUTHOR 10320 -#define ID_BUTTON_SET_DESCRIPTION 10321 -#define ID_BUTTON_SET_NAME 10322 -#define ID_BUTTON_SET_CATEGORY 10323 - - -#define ID_BUTTON_BUILD_PROJECT 10324 -#define ID_BUTTON_CONFIGURE_BUILD 10325 -#define ID_BUTTON_CONNECT_PROJECT 10326 - -#define ID_BUTTON_GOTO_PACKAGE_MANAGER 10327 -#define ID_BUTTON_GOTO_APPLI_MANAGER 10328 -#define ID_BUTTON_GOTO_LIB_MANAGER 10329 - -#define ID_LINK_SELECT_PACKAGE 10330 -#define ID_LINK_SELECT_LIBRARY 10331 -#define ID_LINK_SELECT_APPLICATION 10332 -#define ID_LINK_SELECT_BLACKBOX 10333 - -#define ID_CHECKBOX_ENABLE_HELP 10334 -#define ID_CHECKBOX_DISABLE_HELP 10335 -#define ID_CHECKBOX_TOGGLE_HELP 10335 - -#define ID_BUTTON_CHECK_PROJECT 10336 +#define ID_BUTTON_OPEN_BUILD_PATH 10320 +#define ID_BUTTON_SET_AUTHOR 10321 +#define ID_BUTTON_SET_DESCRIPTION 10322 +#define ID_BUTTON_SET_NAME 10323 +#define ID_BUTTON_SET_CATEGORY 10324 + + +#define ID_BUTTON_BUILD_PROJECT 10325 +#define ID_BUTTON_CONFIGURE_BUILD 10326 +#define ID_BUTTON_CONNECT_PROJECT 10327 + +#define ID_BUTTON_GOTO_PACKAGE_MANAGER 10328 +#define ID_BUTTON_GOTO_APPLI_MANAGER 10329 +#define ID_BUTTON_GOTO_LIB_MANAGER 10330 + +#define ID_LINK_SELECT_PACKAGE 10331 +#define ID_LINK_SELECT_LIBRARY 10332 +#define ID_LINK_SELECT_APPLICATION 10333 +#define ID_LINK_SELECT_BLACKBOX 10334 + +#define ID_CHECK_INCLUDE_LIBRARY 10335 +#define ID_CHECK_INCLUDE_3RDLIBRARY 10336 +#define ID_CHECK_INCLUDE_PACKAGE 10337 +#define ID_CHECK_INCLUDE_APPLICATION 10338 + +#define ID_CHECKBOX_ENABLE_HELP 10339 +#define ID_CHECKBOX_DISABLE_HELP 10340 +#define ID_CHECKBOX_TOGGLE_HELP 10341 + +#define ID_BUTTON_CHECK_PROJECT 10342 + +#define ID_MENU_OPEN_RECENT1 10343 +#define ID_MENU_OPEN_RECENT2 10344 +#define ID_MENU_OPEN_RECENT3 10345 +#define ID_MENU_OPEN_RECENT4 10346 +#define ID_MENU_OPEN_RECENT5 10347 #endif /* CREADEVMANAGERIDS_H_ */ diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index bcb0876..c66cbb8 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -183,6 +183,14 @@ modelCDMApplication* modelCDMAppli::CreateApplication( return NULL; } + //add application to appli CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(" << name << ")" << std::endl; + out1.close(); + } + //add application to model modelCDMApplication* application = new modelCDMApplication(this, this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->applications.push_back(application); @@ -237,6 +245,14 @@ modelCDMApplication* modelCDMAppli::CreateApplication( return NULL; } + //add application to appli CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(" << name << ")" << std::endl; + out1.close(); + } + //add application to model modelCDMApplication* application = new modelCDMApplication(this, this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->applications.push_back(application); @@ -467,3 +483,95 @@ void modelCDMAppli::CheckStructure(std::map& properties) this->applications[i]->CheckStructure(properties); } } + +bool modelCDMAppli::IsApplicationIncluded(const std::string& application_name) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + for (int i = 0; i < cmlFile.size(); ++i) + { + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (application_name == cmlFile[i].second[pos]) + return true; + break; + } + pos++; + } + } + } + } + return false; +} + +bool modelCDMAppli::SetApplicationInclude(const std::string& application_name, const bool& toInclude) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + + bool found = false; + + for (int i = 0; i < cmlFile.size(); ++i) + { + if(toInclude && cmlFile[i].first == "comment") + { + std::vector segments; + std::string line = cmlFile[i].second[0]; + while(line[0] == '#') + line.erase(0,1); + + CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties); + if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == application_name) + { + found = true; + while(cmlFile[i].second[0][0] == '#') + cmlFile[i].second[0].erase(0,1); + } + } + else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (application_name == cmlFile[i].second[pos]) + { + found = true; + if (!toInclude) + { + cmlFile[i].first = "comment"; + cmlFile[i].second[0] = "#" + cmlFile[i].second[0]; + while (cmlFile[i].second.size() > 1) + { + cmlFile[i].second[0] += cmlFile[i].second[1]; + cmlFile[i].second.erase(cmlFile[i].second.begin()+1); + } + + } + } + break; + } + pos++; + } + } + } + if (!found && toInclude) + { + CDMUtilities::syntaxElement element; + element.first = "command"; + element.second.push_back("ADD_SUBDIRECTORY(" + application_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); + } + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMAppli.h b/lib/creaDevManagerLib/modelCDMAppli.h index 579f12a..c3bce22 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.h +++ b/lib/creaDevManagerLib/modelCDMAppli.h @@ -72,7 +72,7 @@ public: const std::vector& GetApplications() const; /** - * Creates a new application in the system and creates an application node. This node is stored in the applications attribute and returned. + * Creates a new application in the system and creates an application node. This node is stored in the applications attribute and returned. The created application is included in the appli's CMakeLists file. * @param name Name of the new application. * @param type 0=console application, 1=GUI Application (wxWidgets). * @param result Result message of the operation. @@ -96,6 +96,21 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks if the given application is included in the CMakeLists file. + * @param application_name Name of the library to check. + * @return True if the library is included, otherwise returns False. + */ + bool IsApplicationIncluded(const std::string& application_name); + + /** + * Sets the inclusion of the application in the lib's CMakeLists file. If the application inclusion already exist in file, then the line is uncommented/commented depending on the requested action. If the application inclusion doesn't exist yet, then it is included if the request is an inclusion. + * @param application_name Name of the application to include/exclude. + * @param toInclude True if the request is an inclusion, False otherwise. + * @return True if the request was processed successfully. + */ + bool SetApplicationInclude(const std::string& application_name, const bool& toInclude); + private: /** * application in the appli folder node. diff --git a/lib/creaDevManagerLib/modelCDMApplication.cpp b/lib/creaDevManagerLib/modelCDMApplication.cpp index 7083c47..5d0f597 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.cpp +++ b/lib/creaDevManagerLib/modelCDMApplication.cpp @@ -34,9 +34,14 @@ #include "modelCDMApplication.h" +#include "modelCDMProject.h" +#include "modelCDMLib.h" +#include "modelCDMLibrary.h" + #include #include #include +#include #include "CDMUtilities.h" #include "creaWx.h" @@ -117,7 +122,6 @@ modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const while (cont) { std::string stdfileName = crea::wx2std(fileName); - //if CMakeLists, create CMakeLists if(stdfileName == "CMakeLists.txt") { @@ -129,23 +133,46 @@ modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const { modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1); std::string extension = stdfileName.substr(stdfileName.size()-4); + //if is cxx or cpp check if is the main file. if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp")) { - std::ifstream fileStream; - std::string word; - fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str()); - while (fileStream.is_open() && !fileStream.eof()) + std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str()); + + if (fileStream.is_open()) { - //get sets - std::getline(fileStream,word,'('); - std::vector wordBits; - CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties); - if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP") + std::string fileContent = ""; + char ch = fileStream.get(); + while(!fileStream.eof()) + { + fileContent.push_back(ch); + ch = fileStream.get(); + } + fileStream.close(); + + boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]"); + std::string::const_iterator start, end; + start = fileContent.begin(); + end = fileContent.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) { + std::cout << "found main wxwidgets file: " << stdfileName << std::endl; this->mainFile = file; } + else + { + expression = boost::regex("^\\h*int\\h+main[#\\s\\(]"); + start = fileContent.begin(); + end = fileContent.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + std::cout << "found main console file: " << stdfileName << std::endl; + this->mainFile = file; + } + } } - fileStream.close(); + } this->children.push_back(file); } @@ -514,3 +541,456 @@ void modelCDMApplication::CheckStructure(std::map& properties } } + +std::map modelCDMApplication::Get3rdPartyLibraries() +{ + std::map correspondence; + correspondence["${crea_LIBRARIES}"] = "Crea"; + correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets"; + correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets"; + correspondence["${VTK_LIBRARIES}"] = "VTK"; + correspondence["${ITK_LIBRARIES}"] = "ITK"; + correspondence["${GDCM_LIBRARIES}"] = "GDCM"; + correspondence["${BOOST_LIBRARIES}"] = "Boost"; + std::map res; + res["Crea"] = false; + res["WxWidgets"] = false; + res["KWWidgets"] = false; + res["VTK"] = false; + res["ITK"] = false; + res["GDCM"] = 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)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + if(what2.str()[0] != '#') + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + if(correspondence.find(dete) != correspondence.end()) + res[correspondence[dete]] = true; + } + start2 = what2[0].second; + } + } + } + } + return res; +} + +bool modelCDMApplication::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude) +{ + std::map correspondence; + + correspondence["Crea"] = "${crea_LIBRARIES}"; + correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}"; + correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}"; + correspondence["VTK"] = "${VTK_LIBRARIES}"; + correspondence["ITK"] = "${ITK_LIBRARIES}"; + correspondence["GDCM"] = "${GDCM_LIBRARIES}"; + correspondence["Boost"] = "${BOOST_LIBRARIES}"; + + std::map regexCorrespondence; + + regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}"; + regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}"; + regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}"; + regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}"; + regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}"; + regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}"; + regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}"; + + if (correspondence.find(library_name) != correspondence.end()) + { + std::string library_command = correspondence[library_name]; + std::string regex_command = regexCorrespondence[library_name]; + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + std::string resCMfile = ""; + + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + bool found = false; + if (toInclude) { + expression = "^\\h*#+\\h*" + regex_command; + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1, what2; + while(boost::regex_search(start1, end1, what1, expression, flags)) + { + found = true; + resCMfile += what1.prefix().str(); + std::string dete = what1[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + what2 = what1; + start1 = what1[0].second; + } + if (found) + resCMfile += what2.suffix().str(); + else + { + expression = "^\\h*" + regex_command; + if(boost::regex_search(start1, end1, what1, expression, flags)) + found = true; + + expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES"; + boost::regex_search(start1, end1, what1, expression, flags); + + resCMfile += what1.prefix().str() + what1.str(); + if(!found) + resCMfile += "\n" + library_command + "\n"; + resCMfile += what1.suffix().str(); + } + + }else{ + expression = "^\\h*" + regex_command; + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1, what2; + while(boost::regex_search(start1, end1, what1, expression, flags)) + { + found = true; + resCMfile += what1.prefix().str(); + resCMfile += "#" + what1.str(); + what2 = what1; + start1 = what1[0].second; + } + if (found) + resCMfile += what2.suffix().str(); + else + { + expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES"; + boost::regex_search(start1, end1, what1, expression, flags); + + resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str(); + } + } + resCMfile += what.suffix().str(); + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + } + return false; + +} + +std::map modelCDMApplication::GetCustomLibraries() +{ + std::map res; + std::map res1; + + std::map correspondence; + std::vector libraries; + if(this->GetParent() != NULL && this->GetParent()->GetParent() != NULL) + if(dynamic_cast(this->GetParent()->GetParent()) != NULL && dynamic_cast(this->GetParent()->GetParent())->GetLib() != NULL) + libraries = (dynamic_cast(this->GetParent()->GetParent()))->GetLib()->GetLibraries(); + for (int i = 0; i < libraries.size(); ++i) + { + correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary(); + res[libraries[i]->GetNameLibrary()] = false; + res1[libraries[i]->GetNameLibrary()] = false; + } + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + + //find included libraries + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + expression = boost::regex("^\\h*[\\w\\d]+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado lib: " << dete << std::endl; + if(res1.find(dete) != res1.end()) + res1[dete] = true; + + start2 = what2[0].second; + } + } + } + + //find included folders + //std::cout << "searching..." << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\")(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\("); + 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, expression, flags)) + { + //std::cout << what1.str() << std::endl; + expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/([\\w\\d])+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado dir: " << dete.substr(10) << std::endl; + if(correspondence.find(dete.substr(10)) != correspondence.end()) + res[correspondence[dete.substr(10)]] = res1[correspondence[dete.substr(10)]]; + + start2 = what2[0].second; + } + } + } + } + + return res; +} + +bool modelCDMApplication::SetCustomLibrary(const std::string& library_name, const bool& toInclude) +{ + std::map correspondence; + + std::vector libraries; + modelCDMIProjectTreeNode* p = this; + while(p != NULL && dynamic_cast(p) == NULL) + p = p->GetParent(); + + if(p != NULL && dynamic_cast(p)->GetLib() != NULL) + libraries = dynamic_cast(p)->GetLib()->GetLibraries(); + + for (int i = 0; i < libraries.size(); ++i) + { + correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName(); + } + + if (correspondence.find(library_name) != correspondence.end()) + { + if (this->HasCMakeLists()) + { + std::string resCMfile = ""; + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + bool found = false; + + //find included libraries + //std::cout << "searching..." << CMfile << std::endl; + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what.str() << std::endl; + resCMfile += what.prefix().str(); + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + //check if already exists + expression = boost::regex("^\\h*"+library_name); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + resCMfile += what2.prefix().str(); + found = true; + if (!toInclude) + { + resCMfile += "#"; + } + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //check if is commented + else + { + expression = boost::regex("^\\h*#+\\h*"+library_name); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n" + library_name; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + //find included folders + CMfile = resCMfile; + resCMfile = ""; + + + found = false; + //std::cout << "searching..." << CMfile << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + //std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\("); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + //std::cout << what1.str() << std::endl; + //search if dir is already included + expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(!toInclude) + resCMfile += "#"; + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //search if dir is commented + else + { + expression = boost::regex("^\\h*#+\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n../../lib/" + correspondence[library_name]; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMApplication.h b/lib/creaDevManagerLib/modelCDMApplication.h index e471ec9..18cb7c5 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.h +++ b/lib/creaDevManagerLib/modelCDMApplication.h @@ -105,6 +105,30 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks the application's CMakeLists file to check which third party libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map Get3rdPartyLibraries(); + + /** + * Sets the 3rd party library inclusion in the application's CMakeLists file. + * @return if the operation was successful. + */ + bool Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude); + + /** + * Checks the application's CMakeLists file to check which custom libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map GetCustomLibraries(); + + /** + * Sets the custom library inclusion in the application's CMakeLists file. + * @return if the operation was successful. + */ + bool SetCustomLibrary(const std::string& library_name, const bool& toInclude); + private: /** * Name of the application executable file. diff --git a/lib/creaDevManagerLib/modelCDMLib.cpp b/lib/creaDevManagerLib/modelCDMLib.cpp index e3c2902..3dcf9b8 100644 --- a/lib/creaDevManagerLib/modelCDMLib.cpp +++ b/lib/creaDevManagerLib/modelCDMLib.cpp @@ -177,6 +177,15 @@ modelCDMLibrary* modelCDMLib::CreateLibrary( return NULL; } + //add library to lib CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(" << name << ")" << std::endl; + out1.close(); + } + + //add library to model modelCDMLibrary* library = new modelCDMLibrary(this, this->path + CDMUtilities::SLASH + name, name, this->level + 1); this->libraries.push_back(library); @@ -398,3 +407,95 @@ void modelCDMLib::CheckStructure(std::map& properties) this->libraries[i]->CheckStructure(properties); } } + +bool modelCDMLib::IsLibraryIncluded(const std::string& library_name) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + for (int i = 0; i < cmlFile.size(); ++i) + { + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (library_name == cmlFile[i].second[pos]) + return true; + break; + } + pos++; + } + } + } + } + return false; +} + +bool modelCDMLib::SetLibraryInclude(const std::string& library_name, const bool& toInclude) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + + bool found = false; + + for (int i = 0; i < cmlFile.size(); ++i) + { + if(toInclude && cmlFile[i].first == "comment") + { + std::vector segments; + std::string line = cmlFile[i].second[0]; + while(line[0] == '#') + line.erase(0,1); + + CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties); + if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == library_name) + { + found = true; + while(cmlFile[i].second[0][0] == '#') + cmlFile[i].second[0].erase(0,1); + } + } + else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (library_name == cmlFile[i].second[pos]) + { + found = true; + if (!toInclude) + { + cmlFile[i].first = "comment"; + cmlFile[i].second[0] = "#" + cmlFile[i].second[0]; + while (cmlFile[i].second.size() > 1) + { + cmlFile[i].second[0] += cmlFile[i].second[1]; + cmlFile[i].second.erase(cmlFile[i].second.begin()+1); + } + + } + } + break; + } + pos++; + } + } + } + if (!found && toInclude) + { + CDMUtilities::syntaxElement element; + element.first = "command"; + element.second.push_back("ADD_SUBDIRECTORY(" + library_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); + } + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMLib.h b/lib/creaDevManagerLib/modelCDMLib.h index e372e5f..d8b8c27 100644 --- a/lib/creaDevManagerLib/modelCDMLib.h +++ b/lib/creaDevManagerLib/modelCDMLib.h @@ -72,7 +72,7 @@ public: const std::vector& GetLibraries() const; /** - * Creates a new library node for the actual project and registers it. It modifies the project model as well as the system. + * Creates a new library node for the actual project and registers it. It modifies the project model as well as the system. The created library is included in the lib's CMakeLists file. * @param name Name of the new library. * @param result Result message. * @return New library reference. @@ -95,6 +95,21 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks if the given library is included in the CMakeLists file. + * @param library_name Name of the library to check. + * @return True if the library is included, otherwise returns False. + */ + bool IsLibraryIncluded(const std::string& library_name); + + /** + * Sets the inclusion of the library in the lib's CMakeLists file. If the library inclusion already exist in file, then the line is uncommented/commented depending on the requested action. If the library inclusion doesn't exist yet, then it is included if the request is an inclusion. + * @param library_name Name of the library to include/exclude. + * @param toInclude True if the request is an inclusion, False otherwise. + * @return True if the request was processed successfully. + */ + bool SetLibraryInclude(const std::string& library_name, const bool& toInclude); + private: /** * Libraries references. diff --git a/lib/creaDevManagerLib/modelCDMLibrary.cpp b/lib/creaDevManagerLib/modelCDMLibrary.cpp index 7b99318..72310c7 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.cpp +++ b/lib/creaDevManagerLib/modelCDMLibrary.cpp @@ -34,9 +34,12 @@ #include "modelCDMLibrary.h" +#include "modelCDMLib.h" + #include #include #include +#include #include "CDMUtilities.h" #include "creaWx.h" @@ -433,3 +436,445 @@ void modelCDMLibrary::CheckStructure(std::map& properties) } } + +std::map modelCDMLibrary::Get3rdPartyLibraries() +{ + std::map correspondence; + correspondence["${crea_LIBRARIES}"] = "Crea"; + correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets"; + correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets"; + correspondence["${VTK_LIBRARIES}"] = "VTK"; + correspondence["${ITK_LIBRARIES}"] = "ITK"; + correspondence["${GDCM_LIBRARIES}"] = "GDCM"; + correspondence["${BOOST_LIBRARIES}"] = "Boost"; + std::map res; + res["Crea"] = false; + res["WxWidgets"] = false; + res["KWWidgets"] = false; + res["VTK"] = false; + res["ITK"] = false; + res["GDCM"] = 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)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + if(what2.str()[0] != '#') + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + if(correspondence.find(dete) != correspondence.end()) + res[correspondence[dete]] = true; + } + start2 = what2[0].second; + } + } + } + } + return res; +} + +bool modelCDMLibrary::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude) +{ + std::map correspondence; + + correspondence["Crea"] = "${crea_LIBRARIES}"; + correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}"; + correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}"; + correspondence["VTK"] = "${VTK_LIBRARIES}"; + correspondence["ITK"] = "${ITK_LIBRARIES}"; + correspondence["GDCM"] = "${GDCM_LIBRARIES}"; + correspondence["Boost"] = "${BOOST_LIBRARIES}"; + + std::map regexCorrespondence; + + regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}"; + regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}"; + regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}"; + regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}"; + regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}"; + regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}"; + regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}"; + + if (correspondence.find(library_name) != correspondence.end()) + { + std::string library_command = correspondence[library_name]; + std::string regex_command = regexCorrespondence[library_name]; + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + std::string resCMfile = ""; + + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + bool found = false; + if (toInclude) { + expression = "^\\h*#+\\h*" + regex_command; + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1, what2; + while(boost::regex_search(start1, end1, what1, expression, flags)) + { + found = true; + resCMfile += what1.prefix().str(); + std::string dete = what1[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + what2 = what1; + start1 = what1[0].second; + } + if (found) + resCMfile += what2.suffix().str(); + else + { + expression = "^\\h*" + regex_command; + if(boost::regex_search(start1, end1, what1, expression, flags)) + found = true; + + expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES"; + boost::regex_search(start1, end1, what1, expression, flags); + + resCMfile += what1.prefix().str() + what1.str(); + if(!found) + resCMfile += "\n" + library_command + "\n"; + resCMfile += what1.suffix().str(); + } + + }else{ + expression = "^\\h*" + regex_command; + std::string::const_iterator start1, end1; + start1 = what[0].first; + end1 = what[0].second; + boost::match_results what1, what2; + while(boost::regex_search(start1, end1, what1, expression, flags)) + { + found = true; + resCMfile += what1.prefix().str(); + resCMfile += "#" + what1.str(); + what2 = what1; + start1 = what1[0].second; + } + if (found) + resCMfile += what2.suffix().str(); + else + { + expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES"; + boost::regex_search(start1, end1, what1, expression, flags); + + resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str(); + } + } + resCMfile += what.suffix().str(); + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + } + return false; +} + +std::map modelCDMLibrary::GetCustomLibraries() +{ + std::map res; + std::map res1; + + std::map correspondence; + std::vector libraries = ((modelCDMLib*)this->parent)->GetLibraries(); + for (int i = 0; i < libraries.size(); ++i) + { + if(libraries[i]->GetNameLibrary() == this->nameLibrary) + continue; + correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary(); + res[libraries[i]->GetNameLibrary()] = false; + res1[libraries[i]->GetNameLibrary()] = false; + } + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + + //find included libraries + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + expression = boost::regex("^\\h*[\\w\\d]+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado lib: " << dete << std::endl; + if(res1.find(dete) != res1.end()) + res1[dete] = true; + + start2 = what2[0].second; + } + } + } + + //find included folders + //std::cout << "searching..." << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\("); + 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, expression, flags)) + { + //std::cout << what1.str() << std::endl; + expression = boost::regex("^\\h*\\.\\.\\/([\\w\\d])+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado dir: " << dete.substr(3) << std::endl; + if(correspondence.find(dete.substr(3)) != correspondence.end()) + res[correspondence[dete.substr(3)]] = res1[correspondence[dete.substr(3)]]; + + start2 = what2[0].second; + } + } + } + } + + return res; +} + +bool modelCDMLibrary::SetCustomLibrary(const std::string& library_name, const bool& toInclude) +{ + std::map correspondence; + std::vector libraries = ((modelCDMLib*)this->parent)->GetLibraries(); + for (int i = 0; i < libraries.size(); ++i) + { + if(libraries[i]->GetNameLibrary() == this->nameLibrary) + continue; + correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName(); + } + + if (correspondence.find(library_name) != correspondence.end()) + { + if (this->HasCMakeLists()) + { + std::string resCMfile = ""; + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + bool found = false; + + //find included libraries + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES"); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + //check if already exists + expression = boost::regex("^\\h*"+library_name); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + resCMfile += what2.prefix().str(); + found = true; + if (!toInclude) + { + resCMfile += "#"; + } + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //check if is commented + else + { + expression = boost::regex("^\\h*#+\\h*"+library_name); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n" + library_name; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + //find included folders + CMfile = resCMfile; + resCMfile = ""; + + + found = false; + std::cout << "searching..." << CMfile << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\("); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + std::cout << what1.str() << std::endl; + //search if dir is already included + expression = boost::regex("^\\h*\\.\\.\\/"+correspondence[library_name]); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(!toInclude) + resCMfile += "#"; + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //search if dir is commented + else + { + expression = boost::regex("^\\h*#+\\h*\\.\\.\\/"+correspondence[library_name]); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n../" + correspondence[library_name]; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMLibrary.h b/lib/creaDevManagerLib/modelCDMLibrary.h index ae37ec9..bec1278 100644 --- a/lib/creaDevManagerLib/modelCDMLibrary.h +++ b/lib/creaDevManagerLib/modelCDMLibrary.h @@ -98,6 +98,30 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks the library CMakeLists file to check which third party libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map Get3rdPartyLibraries(); + + /** + * Sets the 3rd party library inclusion in the CMakeLists file. + * @return if the operation was successful. + */ + bool Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude); + + /** + * Checks the library CMakeLists file to check which custom libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map GetCustomLibraries(); + + /** + * Sets the custom library inclusion in the CMakeLists file. + * @return if the operation was successful. + */ + bool SetCustomLibrary(const std::string& library_name, const bool& toInclude); + private: /** * Name of the library node. The name of a library can be different than the library folder name. diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index 66c5e22..e565dec 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -34,9 +34,15 @@ #include "modelCDMPackage.h" +#include "modelCDMProject.h" +#include "modelCDMLib.h" +#include "modelCDMLibrary.h" + + #include #include #include +#include #include "creaWx.h" #include "wx/dir.h" @@ -689,3 +695,447 @@ void modelCDMPackage::CheckStructure(std::map& properties) } } + +std::map modelCDMPackage::Get3rdPartyLibraries() +{ + std::map correspondence; + correspondence["${BBTK_PACKAGE_NAME}_USE_VTK"] = "VTK"; + correspondence["${BBTK_PACKAGE_NAME}_USE_ITK"] = "ITK"; + correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM"] = "GDCM"; + correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM_VTK"] = "GDCM_VTK"; + correspondence["${BBTK_PACKAGE_NAME}_USE_GSMIS"] = "GSMIS"; + correspondence["${BBTK_PACKAGE_NAME}_USE_WXWIDGETS"] = "WxWidgets"; + correspondence["${BBTK_PACKAGE_NAME}_USE_KWWIDGETS"] = "KWWidgets"; + std::map res; + res["VTK"] = false; + res["ITK"] = false; + res["GDCM"] = false; + res["GDCM_VTK"] = false; + res["GSMIS"] = false; + res["WxWidgets"] = false; + res["KWWidgets"] = 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)*\\$\\{BBTK_PACKAGE_NAME\\}_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("\\$\\{BBTK_PACKAGE_NAME\\}_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 modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name, + const bool& toInclude) +{ + std::map correspondence; + + correspondence["VTK"] = "_USE_VTK"; + correspondence["ITK"] = "_USE_ITK"; + correspondence["GDCM"] = "_USE_GDCM"; + correspondence["GDCM_VTK"] = "_USE_GDCM_VTK"; + correspondence["GSMIS"] = "_USE_GSMIS"; + correspondence["WxWidgets"] = "_USE_WXWIDGETS"; + correspondence["KWWidgets"] = "_USE_KWWIDGETS"; + + if (correspondence.find(library_name) != correspondence.end()) + { + std::string library_command = correspondence[library_name]; +// std::cout << "found correspondence " << library_command << std::endl; +// std::cout.flush(); + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + std::string resCMfile = ""; + bool found = false; + +// std::cout << "found cmakefile: " << CMfile << std::endl; +// std::cout.flush(); + + try { +// std::cout << "first regex" << std::endl; +// std::cout.flush(); + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)"); + + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { +// std::cout << "found " << what.str() << std::endl; +// std::cout.flush(); + found = true; + resCMfile += what.prefix().str(); + if (toInclude) + resCMfile += what.str(); + else + resCMfile += "#" + what.str(); + resCMfile += what.suffix().str(); + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + else + { +// std::cout << "second regex" << std::endl; +// std::cout.flush(); + boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)"); + if(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + if(toInclude) + { + std::string dete = what[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + if (dete[i] == 'S') + { + resCMfile += dete.substr(i+1); + break; + } + } + } + else + resCMfile += what.str(); + + resCMfile += what.suffix().str(); + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + else + { +// std::cout << "third regex" << std::endl; +// std::cout.flush(); + boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n"); + if(boost::regex_search(start, end, what, expression, flags)) + { + found = true; + resCMfile += what.prefix().str(); + resCMfile += what.str(); + if(toInclude) + { + resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n"; + } + resCMfile += what.suffix().str(); + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + } + } catch (boost::bad_expression& e) { + std::cout << "bad regex: " << e.what() << std::endl; + std::cout.flush(); + } + } + } + return false; +} + +std::map modelCDMPackage::GetCustomLibraries() +{ + std::map res; + std::map res1; + + std::map correspondence; + std::vector libraries; + modelCDMIProjectTreeNode* p = this; + while(p != NULL && dynamic_cast(p) == NULL) + p = p->GetParent(); + + if(p != NULL && dynamic_cast(p)->GetLib() != NULL) + libraries = dynamic_cast(p)->GetLib()->GetLibraries(); + + for (int i = 0; i < libraries.size(); ++i) + { + correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary(); + res[libraries[i]->GetNameLibrary()] = false; + res1[libraries[i]->GetNameLibrary()] = false; + } + + if (this->HasCMakeLists()) + { + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + + //find included libraries + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS"); + 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, expression, flags)) + { + expression = boost::regex("^\\h*[\\w\\d]+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado lib: " << dete << std::endl; + if(res1.find(dete) != res1.end()) + res1[dete] = true; + + start2 = what2[0].second; + } + } + } + + //find included folders + //std::cout << "searching..." << std::endl; + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n|////[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS"); + 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, expression, flags)) + { + //std::cout << what1.str() << std::endl; + expression = boost::regex("^\\h*\\.\\.\\/lib\\/([\\w\\d])+"); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + std::string dete = what2.str(); + CDMUtilities::normalizeStr(dete); + //std::cout << "detectado dir: " << dete.substr(7) << std::endl; + if(correspondence.find(dete.substr(7)) != correspondence.end()) + res[correspondence[dete.substr(7)]] = res1[correspondence[dete.substr(7)]]; + + start2 = what2[0].second; + } + } + } + } + + return res; +} + +bool modelCDMPackage::SetCustomLibrary(const std::string& library_name, + const bool& toInclude) +{ + std::map correspondence; + + std::vector libraries; + modelCDMIProjectTreeNode* p = this; + while(p != NULL && dynamic_cast(p) == NULL) + p = p->GetParent(); + + if(p != NULL && dynamic_cast(p)->GetLib() != NULL) + libraries = dynamic_cast(p)->GetLib()->GetLibraries(); + + for (int i = 0; i < libraries.size(); ++i) + { + correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName(); + } + + if (correspondence.find(library_name) != correspondence.end()) + { + if (this->HasCMakeLists()) + { + std::string resCMfile = ""; + std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str()); + bool found = false; + + //find included libraries + //std::cout << "searching..." << CMfile << std::endl; + boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + std::string::const_iterator start, end; + start = CMfile.begin(); + end = CMfile.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + if(boost::regex_search(start, end, what, expression, flags)) + { + //std::cout << what.str() << std::endl; + resCMfile += what.prefix().str(); + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS"); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + //check if already exists + expression = boost::regex("^\\h*"+library_name); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + resCMfile += what2.prefix().str(); + found = true; + if (!toInclude) + { + resCMfile += "#"; + } + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //check if is commented + else + { + expression = boost::regex("^\\h*#+\\h*"+library_name); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n" + library_name; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + //find included folders + CMfile = resCMfile; + resCMfile = ""; + + + found = false; + //std::cout << "searching..." << CMfile << std::endl; + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)"); + start = CMfile.begin(); + end = CMfile.end(); + if(boost::regex_search(start, end, what, expression, flags)) + { + resCMfile += what.prefix().str(); + //std::cout << what.str() << std::endl; + expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS"); + 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, expression, flags)) + { + resCMfile += what1.prefix().str() + what1.str(); + //std::cout << what1.str() << std::endl; + //search if dir is already included + expression = boost::regex("^\\h*\\.\\.\\/lib\\/"+correspondence[library_name]); + std::string::const_iterator start2, end2; + start2 = what1[0].second; + end2 = what[0].second; + boost::match_results what2, temp2; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(!toInclude) + resCMfile += "#"; + resCMfile += what2.str(); + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //search if dir is commented + else + { + expression = boost::regex("^\\h*#+\\h*\\.\\.\\/lib\\/"+correspondence[library_name]); + start2 = what1[0].second; + end2 = what[0].second; + while(boost::regex_search(start2, end2, what2, expression, flags)) + { + found = true; + resCMfile += what2.prefix().str(); + if(toInclude) + { + std::string dete = what2[0].str(); + for (int i = 0; i < dete.size(); ++i) { + if (dete[i] != '#') + resCMfile.push_back(dete[i]); + } + } + temp2 = what2; + start2 = what2[0].second; + } + if(found) + resCMfile += temp2.suffix().str(); + //add at the beggining of instruction + else + { + if(toInclude) + resCMfile += "\n../lib/" + correspondence[library_name]; + resCMfile += what1.suffix().str(); + } + } + } + resCMfile += what.suffix().str(); + } + else + return false; + + return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile); + } + } + + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMPackage.h b/lib/creaDevManagerLib/modelCDMPackage.h index 05e2473..198e68b 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.h +++ b/lib/creaDevManagerLib/modelCDMPackage.h @@ -161,6 +161,30 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks the package's CMakeLists file to check which third party libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map Get3rdPartyLibraries(); + + /** + * Sets the 3rd party library inclusion in the CMakeLists file. + * @return if the operation was successful. + */ + bool Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude); + + /** + * Checks the package CMakeLists file to check which custom libraries are enabled. + * @return A map with the name of the library and if it's included in the CMakeLists file. + */ + std::map GetCustomLibraries(); + + /** + * Sets the custom library inclusion in the CMakeLists file. + * @return if the operation was successful. + */ + bool SetCustomLibrary(const std::string& library_name, const bool& toInclude); + private: /** * Package name. diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index aa6fdeb..c394633 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -387,6 +387,14 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( return NULL; } + //add library to project CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl; + out1.close(); + } + //add library to model modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1); this->packages.push_back(package); @@ -739,15 +747,13 @@ bool modelCDMProject::Build(std::string*& result, const std::string& line) //TODO: adjust for windows and mac #ifdef _WIN32 // ------ Windows - //\\..\\IDE\\VCExpress.exe \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" -// std::string command = "\"" + std::string(getenv("VS90COMNTOOLS")) + "..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &"; - std::string command = "\"\"%VS90COMNTOOLS%..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &\""; - command = "start cmd.exe /k " + command + " &"; - if(0 == system(command.c_str())) + std::string command = "start \"\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\""; + //wxMessageBox(crea::std2wx(command), wxT("Project Compilation - Check!")); + if(0 == system(command.c_str())) return true; else { - result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ express installed and to have the VS90COMNTOOLS environment variable set."); + result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ installed."); return false; } #elif __APPLE__ @@ -1001,3 +1007,96 @@ void modelCDMProject::CheckStructure(std::map& properties) this->packages[i]->CheckStructure(properties); } } + +bool modelCDMProject::IsPackageIncluded(const std::string& package_name) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + for (int i = 0; i < cmlFile.size(); ++i) + { + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (package_name == cmlFile[i].second[pos]) + return true; + break; + } + pos++; + } + } + } + } + return false; + +} + +bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + + bool found = false; + + for (int i = 0; i < cmlFile.size(); ++i) + { + if(toInclude && cmlFile[i].first == "comment") + { + std::vector segments; + std::string line = cmlFile[i].second[0]; + while(line[0] == '#') + line.erase(0,1); + + CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties); + if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == package_name) + { + found = true; + while(cmlFile[i].second[0][0] == '#') + cmlFile[i].second[0].erase(0,1); + } + } + else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (package_name == cmlFile[i].second[pos]) + { + found = true; + if (!toInclude) + { + cmlFile[i].first = "comment"; + cmlFile[i].second[0] = "#" + cmlFile[i].second[0]; + while (cmlFile[i].second.size() > 1) + { + cmlFile[i].second[0] += cmlFile[i].second[1]; + cmlFile[i].second.erase(cmlFile[i].second.begin()+1); + } + + } + } + break; + } + pos++; + } + } + } + if (!found && toInclude) + { + CDMUtilities::syntaxElement element; + element.first = "command"; + element.second.push_back("ADD_SUBDIRECTORY(" + package_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); + } + return false; +} diff --git a/lib/creaDevManagerLib/modelCDMProject.h b/lib/creaDevManagerLib/modelCDMProject.h index 5df1550..f354db9 100644 --- a/lib/creaDevManagerLib/modelCDMProject.h +++ b/lib/creaDevManagerLib/modelCDMProject.h @@ -142,7 +142,7 @@ public: //Creations /** - * Creates a package and sets it as a children of the project. This method creates the package in the hard drive and also in the model. + * Creates a package and sets it as a children of the project. This method creates the package in the hard drive and also in the model. The created package is included in the project's CMakeLists file. * @param name Name of the package. * @param result Result of the operation. * @param authors Authors of the operation. If any space is found, it will be replaced by '_'. @@ -252,6 +252,21 @@ public: */ void CheckStructure(std::map& properties); + /** + * Checks if the given package is included in the CMakeLists file. + * @param package_name Name of the package to check. + * @return True if the package is included, otherwise returns False. + */ + bool IsPackageIncluded(const std::string& package_name); + + /** + * Sets the inclusion of the package in the project's CMakeLists file. If the package inclusion already exist in file, then the line is uncommented/commented depending on the requested action. If the package inclusion doesn't exist yet, then it is included if the request is an inclusion. + * @param package_name Name of the package to include/exclude. + * @param toInclude True if the request is an inclusion, False otherwise. + * @return True if the request was processed successfully. + */ + bool SetPackageInclude(const std::string& package_name, const bool& toInclude); + private: diff --git a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp index 49904c2..9f81851 100644 --- a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp @@ -49,6 +49,7 @@ EVT_HYPERLINK(ID_LINK_SELECT_APPLICATION, wxCDMAppliDescriptionPanel::OnLnkAppli EVT_BUTTON(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMAppliDescriptionPanel::OnBtnOpenFolder) +EVT_CHECKBOX(ID_CHECK_INCLUDE_APPLICATION, wxCDMAppliDescriptionPanel::OnChBApplicationChange) END_EVENT_TABLE() wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel( @@ -81,6 +82,9 @@ bool wxCDMAppliDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->appli = appli; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -120,23 +124,53 @@ void wxCDMAppliDescriptionPanel::CreateControls() wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications")); propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them.")); wxPanel* propertiesPanel = new wxPanel(this); - wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL); std::vector applications = this->appli->GetApplications(); + wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(applications.size()+1, 3, 9, 5); + + wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Application Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + + propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5); + for (int i = 0; i < (int)(applications.size()); i++) { - wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); + //checkbox for cmake inclusion + wxCheckBox* pApplicationChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_APPLICATION, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + pApplicationChB->SetName(crea::std2wx(applications[i]->GetName())); + std::string tt = "if this box is checked the the " + applications[i]->GetName() + " application is included in the project compilation."; + pApplicationChB->SetToolTip(crea::std2wx(tt)); + pApplicationChB->SetValue(this->appli->IsApplicationIncluded(applications[i]->GetName())); + propertiesGridSizer -> Add(pApplicationChB, 0, wxEXPAND | wxALIGN_CENTER); + + //link to library with description + wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); pApplicationlk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER); - std::string tt = "Name: " + applications[i]->GetName() + "\n"; + tt = "Name: " + applications[i]->GetName() + "\n"; tt += "Location: " + applications[i]->GetPath(); - pApplicationlk->SetToolTip(crea::std2wx(tt.c_str())); + pApplicationlk->SetToolTip(crea::std2wx(tt)); pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this); pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this); - propertiesPanelSizer -> Add(pApplicationlk, 1, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(pApplicationlk, 0, wxEXPAND); + + //help icon + wxButton* pApplicationHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); + pApplicationHlp->Enable(false); + tt = "When this application is included in the CMakeLists file, the\nfollowing line is included in the CMakeList.txt file in the\nappli folder:\n" + "ADD_SUBDIRECTORY(" + applications[i]->GetName() + ")"; + pApplicationHlp->SetToolTip(crea::std2wx(tt)); + + propertiesGridSizer -> Add(pApplicationHlp, 0, wxEXPAND | wxALIGN_CENTER); } - propertiesPanel->SetSizer(propertiesPanelSizer); - propertiesPanelSizer->Fit(propertiesPanel); + propertiesGridSizer->AddGrowableCol(1,1); + + propertiesPanel->SetSizer(propertiesGridSizer); + propertiesGridSizer->Fit(propertiesPanel); + propertiesBox->Add(propertiesPanel, 1, wxEXPAND | wxALL, 5); sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10); @@ -151,12 +185,12 @@ void wxCDMAppliDescriptionPanel::CreateControls() wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application")); createApplicationbt->SetToolTip(wxT("Create a new application for this project.")); actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this); actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Applications Folder")); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Applications Folder")); openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer.")); actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); @@ -254,6 +288,14 @@ void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) } } +void wxCDMAppliDescriptionPanel::OnChBApplicationChange(wxCommandEvent& event) +{ + this->appli->SetApplicationInclude( + crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), + ((wxCheckBox*)event.GetEventObject())->GetValue() + ); +} + void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event) { modelCDMApplication* applicationFound = NULL; diff --git a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.h index 88c2cf9..a12c31f 100644 --- a/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMAPPLIDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMAppli.h" @@ -44,7 +43,7 @@ /** * Application manager description panel. Shows the available applications in the project and the actions corresponding to application management. */ -class wxCDMAppliDescriptionPanel : public wxPanel +class wxCDMAppliDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -112,6 +111,11 @@ protected: * Handles when the open package cmakelists file button is pressed. */ void OnBtnEditCMakeLists(wxCommandEvent& event); + /** + * Handles when a application checkbox is (un)checked. + * @param event Has the link reference to know which application was selected. + */ + void OnChBApplicationChange(wxCommandEvent& event); /** * Handles when an application link is pressed. * @param event Has the link reference to know which application was selected. diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp index 26c6ce0..5b63f23 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp @@ -50,6 +50,8 @@ EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnCreat EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnOpenFolder) EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMApplicationDescriptionPanel::OnBtnOpenMain) +EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMApplicationDescriptionPanel::On3rdLibraryChBChange) +EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMApplicationDescriptionPanel::OnLibraryChBChange) END_EVENT_TABLE() wxCDMApplicationDescriptionPanel::wxCDMApplicationDescriptionPanel( @@ -82,6 +84,9 @@ bool wxCDMApplicationDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->application = application; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -143,6 +148,138 @@ void wxCDMApplicationDescriptionPanel::CreateControls() propertiesBox->Add(propertiesPanel, 0, wxEXPAND); sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10); */ + + //Includes + wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries")); + includesBox->SetMinSize(200,250); + wxScrolledWindow* includesPanel = new wxScrolledWindow(this); + wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL); + + //Third Party Libraries + wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:")); + wxFont font = Title1->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title1->SetFont(font); + includesPanelSizer->Add(Title1, 0, wxEXPAND); + + //inclusion data + std::map inclusions = this->application->Get3rdPartyLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesGridSizer->Add(ChBTitle, 1, wxEXPAND); + includesGridSizer->Add(LNmTitle, 1, wxEXPAND); + + for (std::map::iterator it = inclusions.begin(); it != inclusions.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " library\n" + "is included in the project configuration for\n" + "this application including the following instruction\n" + "in the application's folder CMakeLists.txt file:\n" + "SET ( ${LIBRARY_NAME}_LINK_LIBRARIES\n" + " ${" + it->first+ "_LIBRARIES}\n" + ")")); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesGridSizer->Add(ChBIncl, 1, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesGridSizer, 0, wxEXPAND | wxLEFT, 5); + + //Custom Libraries + wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:")); + font = Title2->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title2->SetFont(font); + includesPanelSizer->Add(Title2, 0, wxEXPAND); + + //inclusion data + std::map inclusionsLibs = this->application->GetCustomLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND); + includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND); + + for (std::map::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " custom\n" + "library is included in the project configuration for\n" + "this application including the following code in the\n" + "application's folder CMakeLists.txt file:\n" + "INCLUDE_DIRECTORIES (\n" + " ../../lib/"+ it->first + "\n" + ")\n" + "SET ( ${EXE_NAME}_LINK_LIBRARIES\n" + " " + it->first+ "\n" + ")")); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesLibGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5); + + includesPanel->SetSizer(includesPanelSizer); + includesPanelSizer->Fit(includesPanel); + + includesPanel->FitInside(); + includesPanel->SetScrollRate(5,5); + + includesBox->Add(includesPanel, 1, wxEXPAND); + sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10); + + //Actions //actions StaticBoxSizer wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions")); @@ -154,19 +291,19 @@ void wxCDMApplicationDescriptionPanel::CreateControls() //actionsGrid Sizer wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(3, 2, 9, 15); - wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class (Optional)")); + wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class")); createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files).")); - wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)")); + wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder")); createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder.")); wxButton* openMainbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("A. Open Main File")); openMainbt->SetToolTip(wxT("Open the main file in the application folder with the default code editor.")); openMainbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseEnter,NULL,this); openMainbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseExit,NULL,this); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("C. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file inside this application.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseExit,NULL,this); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("B. Open Application Folder")); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Application Folder")); openFolderbt->SetToolTip(wxT("Open the application folder in the file explorer.")); @@ -239,6 +376,22 @@ void wxCDMApplicationDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event) this->executableNametc->SetLabel(crea::std2wx(this->application->GetExecutableName())); } +void wxCDMApplicationDescriptionPanel::On3rdLibraryChBChange(wxCommandEvent& event) +{ + if(this->application->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} + +void wxCDMApplicationDescriptionPanel::OnLibraryChBChange(wxCommandEvent& event) +{ + if(this->application->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} + void wxCDMApplicationDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event) { //get class name from user diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h index 741eb44..d3117f8 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMAPPLICATIONDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMApplication.h" @@ -44,7 +43,7 @@ /** * Application description panel. Shows the properties and actions available for the described application. */ -class wxCDMApplicationDescriptionPanel : public wxPanel +class wxCDMApplicationDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -118,8 +117,19 @@ protected: /** * Handles when the set executable name button is pressed. + * @param event Unused */ void OnBtnSetExeName(wxCommandEvent& event); + /** + * Handles when a 3rd Party Library checkbox state is changed. It calls to include/exclude the selected application. + * @param event CheckBox event. + */ + void On3rdLibraryChBChange(wxCommandEvent& event); + /** + * Handles when a Custom Library checkbox state is changed. It calls to include/exclude the selected application. + * @param event CheckBox event. + */ + void OnLibraryChBChange(wxCommandEvent& event); /** * Handles when the create class button is pressed. */ diff --git a/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp index 959d27a..b694aee 100644 --- a/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp @@ -78,9 +78,12 @@ bool wxCDMBlackBoxDescriptionPanel::Create( long style ) { - wxPanel::Create(parent, id, pos, size, style); this->blackBox = blackBox; + wxPanel::Create(parent, id, pos, size, style); CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -186,7 +189,7 @@ void wxCDMBlackBoxDescriptionPanel::CreateControls() openCxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit,NULL,this); openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor.")); actionsGridSizer->Add(openCxxbt, 1, wxALL | wxEXPAND, 5); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Source Folder")); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Source Folder")); openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer.")); actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); diff --git a/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.h index 94d3071..fb0291b 100644 --- a/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMBLACKBOXDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMBlackBox.h" @@ -44,7 +43,7 @@ /** * Black box description panel. Shows the properties and available actions for the described black box. */ -class wxCDMBlackBoxDescriptionPanel : public wxPanel +class wxCDMBlackBoxDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: diff --git a/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.cpp index 0731624..ea0d465 100644 --- a/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.cpp @@ -75,6 +75,9 @@ bool wxCDMCMakeListsDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->cMakeLists = makefile; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } diff --git a/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.h index ac6f73f..e2ca842 100644 --- a/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMCMAKELISTSDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMCMakeListsFile.h" @@ -44,7 +43,7 @@ /** * CMakeLists File description panel. Shows the file properties and the available actions for it. */ -class wxCDMCMakeListsDescriptionPanel : public wxPanel +class wxCDMCMakeListsDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: diff --git a/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp index fac03fa..e99603a 100644 --- a/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp @@ -77,6 +77,9 @@ bool wxCDMFileDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->file = file; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -124,16 +127,16 @@ void wxCDMFileDescriptionPanel::CreateControls() wxStaticText *pLength = new wxStaticText(propertiesPanel, -1, wxT("File Size")); wxStaticText* pLocationtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->file->GetPath())); - pLocationtc->SetMaxSize(wxSize(350,-1)); + pLocationtc->SetMaxSize(wxSize(300,-1)); int lgth = this->file->GetLength(); std::stringstream ss; ss << lgth / 1024; std::string lgths = ss.str() + " KB"; wxStaticText* pLengthtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(lgths)); - propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_TOP); propertiesGridSizer->Add(pLocationtc, 1, wxEXPAND); - propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_TOP); propertiesGridSizer->Add(pLengthtc, 1, wxEXPAND); propertiesGridSizer->AddGrowableCol(1,1); diff --git a/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.h index 09cc104..8eee2ee 100644 --- a/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMFileDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMFILEDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMFile.h" @@ -44,7 +43,7 @@ /** * File description panel. Shows the File properties and the available options for it. */ -class wxCDMFileDescriptionPanel : public wxPanel +class wxCDMFileDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: diff --git a/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.cpp index 7acc023..2f1c181 100644 --- a/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.cpp @@ -78,6 +78,9 @@ bool wxCDMFolderDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->folder = folder; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } diff --git a/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.h index fafe66e..f06f0ce 100644 --- a/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMFOLDERDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMFolder.h" @@ -44,7 +43,7 @@ /** * Folder description panel. Shows the properties of the referenced folder and the available actions. */ -class wxCDMFolderDescriptionPanel : public wxPanel +class wxCDMFolderDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: diff --git a/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.cpp index d31dd06..4dec780 100644 --- a/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.cpp @@ -47,6 +47,7 @@ EVT_HYPERLINK(ID_LINK_SELECT_LIBRARY, wxCDMLibDescriptionPanel::OnLnkLibrarySele EVT_BUTTON(ID_BUTTON_CREATE_LIBRARY, wxCDMLibDescriptionPanel::OnBtnCreateLibrary) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibDescriptionPanel::OnBtnOpenFolder) +EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMLibDescriptionPanel::OnChBLibraryChange) END_EVENT_TABLE() wxCDMLibDescriptionPanel::wxCDMLibDescriptionPanel( @@ -79,6 +80,9 @@ bool wxCDMLibDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->lib = lib; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -118,23 +122,52 @@ void wxCDMLibDescriptionPanel::CreateControls() wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Libraries")); propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available libraries to see its details or modify them.")); wxPanel* propertiesPanel = new wxPanel(this); - wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL); std::vector libraries = this->lib->GetLibraries(); + wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(libraries.size()+1, 3, 9, 5); + + wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Library Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + + propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5); + for (int i = 0; i < (int)(libraries.size()); i++) { - wxHyperlinkCtrl* pLibrarylk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_LIBRARY, crea::std2wx(libraries[i]->GetName().c_str()), crea::std2wx(libraries[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); + //checkbox for cmake inclusion + wxCheckBox* pLibraryChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + pLibraryChB->SetName(crea::std2wx(libraries[i]->GetName())); + std::string tt = "if this box is checked the the " + libraries[i]->GetName() + " library is included in the project compilation."; + pLibraryChB->SetToolTip(crea::std2wx(tt)); + pLibraryChB->SetValue(this->lib->IsLibraryIncluded(libraries[i]->GetName())); + propertiesGridSizer -> Add(pLibraryChB, 0, wxEXPAND | wxALIGN_CENTER); + + //link to library with description + wxHyperlinkCtrl* pLibrarylk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_LIBRARY, crea::std2wx(libraries[i]->GetName().c_str()), crea::std2wx(libraries[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); pLibrarylk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER); - std::string tt = "Name: " + libraries[i]->GetName() + "\n"; + tt = "Name: " + libraries[i]->GetName() + "\n"; tt += "Location: " + libraries[i]->GetPath(); - pLibrarylk->SetToolTip(crea::std2wx(tt.c_str())); + pLibrarylk->SetToolTip(crea::std2wx(tt)); pLibrarylk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseEnter,NULL,this); pLibrarylk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseExit,NULL,this); - propertiesPanelSizer -> Add(pLibrarylk, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(pLibrarylk, 0, wxEXPAND); + + //help icon + wxButton* pLibraryHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); + pLibraryHlp->Enable(false); + tt = "When this library is included in the CMakeLists file, the\nfollowing line is included in the CMakeList.txt file in the lib\nfolder:\n" + "ADD_SUBDIRECTORY(" + libraries[i]->GetName() + ")"; + pLibraryHlp->SetToolTip(crea::std2wx(tt)); + + propertiesGridSizer -> Add(pLibraryHlp, 0, wxEXPAND | wxALIGN_CENTER); } - propertiesPanel->SetSizer(propertiesPanelSizer); - propertiesPanelSizer->Fit(propertiesPanel); + propertiesGridSizer->AddGrowableCol(1,1); + + propertiesPanel->SetSizer(propertiesGridSizer); + propertiesGridSizer->Fit(propertiesPanel); propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5); sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10); @@ -150,12 +183,12 @@ void wxCDMLibDescriptionPanel::CreateControls() wxButton* createLibrarybt = new wxButton(actionsPanel, ID_BUTTON_CREATE_LIBRARY, _T("A. Create Library")); createLibrarybt->SetToolTip(wxT("Create a new library for this project.")); actionsGridSizer->Add(createLibrarybt, 1, wxALL | wxEXPAND, 5); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the Lib's CMakeLists.txt file.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseExit,NULL,this); actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Libraries Folder")); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Libraries Folder")); openFolderbt->SetToolTip(wxT("Open the lib folder in the file explorer.")); actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); @@ -229,6 +262,14 @@ void wxCDMLibDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) } } +void wxCDMLibDescriptionPanel::OnChBLibraryChange(wxCommandEvent& event) +{ + this->lib->SetLibraryInclude( + crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), + ((wxCheckBox*)event.GetEventObject())->GetValue() + ); +} + void wxCDMLibDescriptionPanel::OnLnkLibrarySelect(wxHyperlinkEvent& event) { modelCDMLibrary* theLibrary = NULL; diff --git a/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.h index 2483c9a..15c9ec4 100644 --- a/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMLibDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMLIBDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMLib.h" @@ -44,7 +43,7 @@ /** * Library manager description panel. Shows the available libraries in the project and the actions corresponding to library management. */ -class wxCDMLibDescriptionPanel : public wxPanel +class wxCDMLibDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -115,6 +114,11 @@ protected: * Handles when the open package cmakelists file button is pressed. */ void OnBtnEditCMakeLists(wxCommandEvent& event); + /** + * Handles when a library checkbox is (un)checked. + * @param event Has the link reference to know which library was selected. + */ + void OnChBLibraryChange(wxCommandEvent& event); /** * Handles when a library link is pressed. * @param event Has the link reference to know which library was selected. diff --git a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp index 4892b64..71f6d69 100644 --- a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp @@ -49,6 +49,8 @@ EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMLibraryDescriptionPanel::OnBtnCreateClas EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnCreateFolder) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnOpenFolder) +EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMLibraryDescriptionPanel::On3rdLibraryChBChange) +EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMLibraryDescriptionPanel::OnLibraryChBChange) END_EVENT_TABLE() wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel( @@ -81,6 +83,9 @@ bool wxCDMLibraryDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->library = library; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -144,6 +149,139 @@ void wxCDMLibraryDescriptionPanel::CreateControls() propertiesBox->Add(propertiesPanel, 0, wxEXPAND); sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10); */ + + //Includes + wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries")); + includesBox->SetMinSize(200,250); + wxScrolledWindow* includesPanel = new wxScrolledWindow(this); + wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL); + + //Third Party Libraries + wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:")); + wxFont font = Title1->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title1->SetFont(font); + includesPanelSizer->Add(Title1, 0, wxEXPAND); + + //inclusion data + std::map inclusions = this->library->Get3rdPartyLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesGridSizer->Add(ChBTitle, 1, wxEXPAND); + includesGridSizer->Add(LNmTitle, 1, wxEXPAND); + + for (std::map::iterator it = inclusions.begin(); it != inclusions.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " library\n" + "is included in the project configuration for\n" + "this library including the following instruction\n" + "in the library's folder CMakeLists.txt file:\n" + "SET ( ${LIBRARY_NAME}_LINK_LIBRARIES\n" + " ${" + it->first+ "_LIBRARIES}\n" + ")")); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesGridSizer->Add(ChBIncl, 1, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesGridSizer, 0, wxEXPAND | wxLEFT, 5); + + //Custom Libraries + wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:")); + font = Title2->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title2->SetFont(font); + includesPanelSizer->Add(Title2, 0, wxEXPAND); + + //inclusion data + std::map inclusionsLibs = this->library->GetCustomLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND); + includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND); + + for (std::map::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " custom\n" + "library is included in the project configuration for\n" + "this library including the following code in the\n" + "library's CMakeLists.txt file:\n" + "INCLUDE_DIRECTORIES (\n" + " ../"+ it->first + "\n" + ")\n" + "SET ( ${LIBRARY_NAME}_LINK_LIBRARIES\n" + " " + it->first+ "\n" + ")")); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesLibGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5); + + includesPanel->SetSizer(includesPanelSizer); + includesPanelSizer->Fit(includesPanel); + + includesPanel->FitInside(); + includesPanel->SetScrollRate(5,5); + + includesBox->Add(includesPanel, 1, wxEXPAND); + sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10); + + + //Actions wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions")); wxPanel* actionsPanel = new wxPanel(this); @@ -158,12 +296,12 @@ void wxCDMLibraryDescriptionPanel::CreateControls() wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("B. Open Library Folder")); openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer.")); actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("C. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this); actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5); - wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)")); + wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder")); createFolderbt->SetToolTip(wxT("Create a new folder for this library.")); actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5); @@ -228,6 +366,22 @@ void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event) this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary())); } +void wxCDMLibraryDescriptionPanel::On3rdLibraryChBChange(wxCommandEvent& event) +{ + if(this->library->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} + +void wxCDMLibraryDescriptionPanel::OnLibraryChBChange(wxCommandEvent& event) +{ + if(this->library->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} + void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event) { //get class name from user diff --git a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.h index 724e485..0fcc262 100644 --- a/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMLIBRARYDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMLibrary.h" @@ -44,7 +43,7 @@ /** * Library description panel. Shows the available actions on the described library. */ -class wxCDMLibraryDescriptionPanel : public wxPanel +class wxCDMLibraryDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -122,6 +121,16 @@ protected: * @param event Unused. */ void OnBtnSetExeName(wxCommandEvent& event); + /** + * Handles when a 3rd Party Library checkbox state is changed. It calls to include/exclude the selected library. + * @param event CheckBox event. + */ + void On3rdLibraryChBChange(wxCommandEvent& event); + /** + * Handles when a Custom Library checkbox state is changed. It calls to include/exclude the selected library. + * @param event CheckBox event. + */ + void OnLibraryChBChange(wxCommandEvent& event); /** * Handles when the create class button is pressed. * @param event Unused. diff --git a/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.cpp index d7f10ae..dbe66c1 100644 --- a/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.cpp @@ -75,6 +75,11 @@ bool wxCDMMainDescriptionPanel::Create( { wxPanel::Create(parent, id, pos, size, style); CreateControls(); + //to scroll + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); + + return TRUE; } @@ -97,27 +102,28 @@ void wxCDMMainDescriptionPanel::CreateControls() sizer->Add(headerSizer, 0, wxALIGN_CENTER | wxUP, 10); //Actions - wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions")); + wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions")); actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new crea project or open an existing one selection any of the available actions.")); - wxPanel* actionsPanel = new wxPanel(this); - wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL); + //wxPanel* actionsPanel = new wxPanel(this); + //wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL); - wxButton* newProjectbt = new wxButton(actionsPanel, ID_BUTTON_NEWPROJECT, _T("New Project")); + wxButton* newProjectbt = new wxButton(this, ID_BUTTON_NEWPROJECT, _T("New Project")); newProjectbt->SetToolTip(wxT("Create a new crea project.")); - actionsPanelSizer->Add(newProjectbt, 0, wxRIGHT | wxLEFT, 20); - wxButton* openProjectbt = new wxButton(actionsPanel, ID_BUTTON_OPENPROJECT, _T("Open Project (source/binaries)")); + actionsBox->Add(newProjectbt, 0, wxALL, 20); + wxButton* openProjectbt = new wxButton(this, ID_BUTTON_OPENPROJECT, _T("Open Project (source/binaries)")); openProjectbt->SetToolTip(wxT("Open an existing crea project from its binaries or its sources.")); - actionsPanelSizer->Add(openProjectbt, 0, wxRIGHT | wxLEFT, 20); + actionsBox->Add(openProjectbt, 0, wxALL, 20); + + //actionsPanel->SetSizer(actionsPanelSizer); + //actionsPanelSizer->Fit(actionsPanel); - actionsPanel->SetSizer(actionsPanelSizer); - actionsPanelSizer->Fit(actionsPanel); - actionsBox->Add(actionsPanel, 0, wxALIGN_CENTER | wxALL, 10); - sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 20); + //actionsBox->Add(actionsPanel, 0,wxEXPAND | wxALIGN_CENTER | wxALL, 10); + sizer -> Add(actionsBox, 0, wxALIGN_CENTER | wxALL, 20); //Asign sizer sizer->SetSizeHints(this); SetSizer(sizer); - + sizer->Fit(this); if(((wxCDMMainFrame*)this->GetParent())->isHelp()) { wxDialog* helpDialog = new wxCDMMainHelpDialog(this->GetParent(), this, wxID_ANY); diff --git a/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.h index fb0defa..08490f7 100644 --- a/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMMainDescriptionPanel.h @@ -37,11 +37,10 @@ #define WXCDMMAINDESCRIPTIONPANEL_H_ #include -#include /** * Main View description panel. Shows the welcome message and allows to open or create Crea projects. */ -class wxCDMMainDescriptionPanel : public wxPanel +class wxCDMMainDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index 8aca7ba..761a4f9 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -64,8 +64,14 @@ BEGIN_EVENT_TABLE(wxCDMMainFrame, wxFrame) +EVT_MENU_OPEN(wxCDMMainFrame::OnMenuBarOpen) EVT_MENU(ID_MENU_NEW_PROJECT, wxCDMMainFrame::OnMenuNewProject) EVT_MENU(ID_MENU_OPEN_PROJECT, wxCDMMainFrame::OnMenuOpenProject) +EVT_MENU(ID_MENU_OPEN_RECENT1, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT2, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT3, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT4, wxCDMMainFrame::OnMenuOpenRecent) +EVT_MENU(ID_MENU_OPEN_RECENT5, wxCDMMainFrame::OnMenuOpenRecent) EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject) EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy) EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit) @@ -174,10 +180,40 @@ void wxCDMMainFrame::CreateMenus() { wxMenuBar* menuBar = new wxMenuBar; + //Recently opened projects + menu_Recent = new wxMenu(); + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string rp = crea::wx2std(pConfig->Read(wxT("RECENT1"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT1, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT2"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT2, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT3"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT3, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT4"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT4, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT5"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT5, crea::std2wx(rp)); + } + } + } + } + } + //FileMenu menu_File = new wxMenu(); menu_File->Append(ID_MENU_NEW_PROJECT, wxT("&New Project...")); menu_File->Append(ID_MENU_OPEN_PROJECT, wxT("&Open Project...")); + menu_File->AppendSubMenu(menu_Recent,wxT("Open &Recent"),wxT("Open a recently opened project.")); menu_File->AppendSeparator(); menu_File->Append(ID_MENU_CLOSE_PROJECT, wxT("&Close Project")); menu_File->AppendSeparator(); @@ -248,7 +284,7 @@ void wxCDMMainFrame::CreateControls() ); auiManager.AddPane(panel_Properties, wxAuiPaneInfo().BestSize(600,400).CenterPane().Name(wxT("panel_Properties")).Caption(wxT("")).CloseButton(false)); - auiManager.AddPane(tree_Projects, wxAuiPaneInfo().Right().MinSize(300,300).BestSize(300,400).CloseButton(false).Name(wxT("tree_Projects")).Caption(wxT("Project Tree")).CloseButton(false)); + auiManager.AddPane(tree_Projects, wxAuiPaneInfo().Left().MinSize(250,300).BestSize(250,400).CloseButton(false).Name(wxT("tree_Projects")).Caption(wxT("Project Tree")).CloseButton(false)); auiManager.Update(); //auiManager.LoadPerspective(pers,true); wxToolTip::Enable(true); @@ -256,6 +292,43 @@ void wxCDMMainFrame::CreateControls() } //Event Handlers + +void wxCDMMainFrame::OnMenuBarOpen(wxMenuEvent& event) +{ + //clean recent menu + int tam = menu_Recent->GetMenuItemCount(); + for (int i = 0; i < tam; ++i) { + menu_Recent->Delete(menu_Recent->FindItemByPosition(0)); + } + //populate recent menu + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string rp = crea::wx2std(pConfig->Read(wxT("RECENT1"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT1, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT2"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT2, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT3"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT3, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT4"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT4, crea::std2wx(rp)); + rp = crea::wx2std(pConfig->Read(wxT("RECENT5"), wxT(""))); + if(rp != "") + { + menu_Recent->Append(ID_MENU_OPEN_RECENT5, crea::std2wx(rp)); + } + } + } + } + } +} + //File menu void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) { @@ -267,7 +340,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) if(userResponse == wxID_FORWARD) { - //create project + //close open project if(this->model->GetProject() != NULL) { if(!this->model->CloseProject(result)) @@ -277,6 +350,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) event.Skip(); return; } + if(this->panel_Properties != NULL) { auiManager.DetachPane(this->panel_Properties); @@ -290,7 +364,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) } - + //create project if(!this->model->CreateProject( crea::wx2std(dialog->GetProjectName()), crea::wx2std(dialog->GetProjectLocation()), @@ -305,6 +379,18 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) return; } + //update recently open projects + wxConfigBase* pConfig = wxConfigBase::Get(); + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + + //show project actions panel if(this->panel_ProjectActions != NULL) { @@ -334,6 +420,104 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event) //wxMessageBox(wxT("ProjectSelected") ,_T("New Project - Success!"),wxOK | wxICON_ERROR); } } +void wxCDMMainFrame::OnMenuOpenRecent(wxCommandEvent& event) +{ + std::string* result; + + //((wxMenuItem*)(event.GetEventObject()))->GetItemLabel(); + + std::string path = ""; + wxConfigBase* pConfig = wxConfigBase::Get(); + if(event.GetId() == ID_MENU_OPEN_RECENT1) + path = crea::wx2std (pConfig->Read(wxT("RECENT1"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT2) + path = crea::wx2std (pConfig->Read(wxT("RECENT2"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT3) + path = crea::wx2std (pConfig->Read(wxT("RECENT3"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT4) + path = crea::wx2std (pConfig->Read(wxT("RECENT4"),wxT(""))); + else if(event.GetId() == ID_MENU_OPEN_RECENT5) + path = crea::wx2std (pConfig->Read(wxT("RECENT5"),wxT(""))); + + std::cout << "Selection to open: " << path << std::endl; + std::cout.flush(); + + + //populate model + if(this->model->GetProject() != NULL) + { + std::cout << "Project not null, closing it" << std::endl; + if(!this->model->CloseProject(result)) + { + std::cout << "error closing project: " << *result << std::endl; + wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR); + event.Skip(); + return; + } + + if(this->panel_Properties != NULL) + { + auiManager.DetachPane(this->panel_Properties); + this->panel_Properties->Hide(); + } + if(this->panel_ProjectActions != NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Hide(); + } + } + + if (!this->model->OpenProject(path, result)) + { + std::cout << "error opening project: " << *result << std::endl; + wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR); + event.Skip(); + return; + }; + + //update recently open projects + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + + std::cout << "building ui" << std::endl; + + //populate tree control + tree_Projects->BuildTree(this->model->GetModelElements(), this->model->GetProject()); + tree_Projects->Unselect(); + this->actualTreeItem.Unset(); + tree_Projects->SelectItem(this->model->GetProject()->GetId().GetWxId(), true); + + + //change project's actions panel + if(this->panel_ProjectActions!= NULL) + { + auiManager.DetachPane(this->panel_ProjectActions); + this->panel_ProjectActions->Destroy(); + this->panel_ProjectActions = NULL; + } + panel_ProjectActions = new wxCDMProjectActionsPanel( + this, + this->model->GetProject(), + ID_WINDOW_PROJ_ACTIONS, + wxT("Project Actions Panel"), + wxDefaultPosition, + wxSize(800,200), + 0 + ); + panel_ProjectActions->SetMinSize(wxSize(500, 100)); + + + auiManager.AddPane(panel_ProjectActions, wxAuiPaneInfo().Bottom().MinSize(800,50).Name(wxT("panel_ProjectActions")).Caption(wxT("General Project Actions")).BestSize(800,70).CloseButton(false)); + + auiManager.Update(); + +} void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) { std::string* result; @@ -361,6 +545,7 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) event.Skip(); return; } + if(this->panel_Properties != NULL) { auiManager.DetachPane(this->panel_Properties); @@ -381,6 +566,17 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event) return; }; + //update recently open projects + wxConfigBase* pConfig = wxConfigBase::Get(); + if(pConfig->Read(wxT("RECENT1"),wxT("")) != crea::std2wx(this->model->GetProject()->GetPath())) + { + pConfig->Write(wxT("RECENT5"), pConfig->Read(wxT("RECENT4"),wxT(""))); + pConfig->Write(wxT("RECENT4"), pConfig->Read(wxT("RECENT3"),wxT(""))); + pConfig->Write(wxT("RECENT3"), pConfig->Read(wxT("RECENT2"),wxT(""))); + pConfig->Write(wxT("RECENT2"), pConfig->Read(wxT("RECENT1"),wxT(""))); + pConfig->Write(wxT("RECENT1"), crea::std2wx(this->model->GetProject()->GetPath())); + } + std::cout << "building ui" << std::endl; //populate tree control diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.h b/lib/creaDevManagerLib/wxCDMMainFrame.h index b5180f1..3cacf8a 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.h +++ b/lib/creaDevManagerLib/wxCDMMainFrame.h @@ -125,6 +125,10 @@ protected: private: //Menus + /** + * Recently opened projects menu + */ + wxMenu* menu_Recent; /** * File menu */ @@ -177,6 +181,13 @@ private: //events protected: + + /** + * Starts when the menu bar is opened. + * @param event The event object that triggers the handler. + */ + void OnMenuBarOpen(wxMenuEvent& event); + //File /** * New project handler. Launches a new project dialog and creates a project model if the project is correctly created. @@ -188,6 +199,11 @@ protected: * @param event The event object that triggers the handler. */ void OnMenuOpenProject(wxCommandEvent& event); + /** + * Open recent project handler. Creates a project model if the project is correctly opened given its path. + * @param event The event object that triggers the handler. + */ + void OnMenuOpenRecent(wxCommandEvent& event); /** * Close project handler. Remove the project from the model and restarts the user interface. * @param event The event object that triggers the handler. diff --git a/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp new file mode 100644 index 0000000..2ab63a6 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.cpp @@ -0,0 +1,239 @@ +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ + */ + + +/* + * wxCDMPackageConfigurationDialog.cpp + * + * Created on: 6/4/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#include "wxCDMPackageConfigurationDialog.h" + +#include "creaDevManagerIds.h" + +BEGIN_EVENT_TABLE(wxCDMPackageConfigurationDialog, wxDialog) +EVT_BUTTON(wxID_OK, wxCDMPackageConfigurationDialog::OnFinish) +EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMPackageConfigurationDialog::On3rdLibraryIncludeChange) +EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMPackageConfigurationDialog::OnCustomLibraryIncludeChange) +END_EVENT_TABLE() + +wxCDMPackageConfigurationDialog::wxCDMPackageConfigurationDialog( + wxWindow* parent, + modelCDMPackage* package, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + this->package = package; + wxCDMPackageConfigurationDialog::Create(parent, id, caption, position, size, style); +} + +wxCDMPackageConfigurationDialog::~wxCDMPackageConfigurationDialog() +{ +} + +bool wxCDMPackageConfigurationDialog::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; +} + +void wxCDMPackageConfigurationDialog::CreateControls() +{ + + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Please select the libraries that are used in this package."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY); + v_sizer1->Add(title, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 5); + + wxScrolledWindow* includesPanel = new wxScrolledWindow(this); + includesPanel->FitInside(); + includesPanel->SetScrollRate(5,5); + + wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL); + + //Third Party Libraries + wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:")); + wxFont font = Title1->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title1->SetFont(font); + includesPanelSizer->Add(Title1, 0, wxEXPAND); + + //inclusion data + std::map inclusions = this->package->Get3rdPartyLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesGridSizer->Add(ChBTitle, 1, wxEXPAND); + includesGridSizer->Add(LNmTitle, 1, wxEXPAND); + + for (std::map::iterator it = inclusions.begin(); it != inclusions.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " library\n" + "is included in the project configuration for\n" + "this package including the following instruction\n" + "in the package's folder CMakeLists.txt file:\n" + "SET(${BBTK_PACKAGE_NAME}_USE_" + it->first+ " ON)\n" + )); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesGridSizer->Add(ChBIncl, 0, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND | wxLEFT, 5); + + //Custom Libraries + wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:")); + font = Title2->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + Title2->SetFont(font); + includesPanelSizer->Add(Title2, 0, wxEXPAND); + + //inclusion data + std::map inclusionsLibs = this->package->GetCustomLibraries(); + //includesGrid Sizer + wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5); + + wxStaticText* ChBTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Included"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_CENTER + ); + wxStaticText* LNmTitle1 = new wxStaticText( + includesPanel, + wxID_ANY, + wxT("Library Name"), + wxDefaultPosition, + wxDefaultSize, + wxALIGN_LEFT + ); + + includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND); + includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND); + + for (std::map::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) { + wxCheckBox* ChBIncl = new wxCheckBox( + includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT + ); + ChBIncl->SetToolTip(crea::std2wx( + "When this box is checked the " + it->first + " custom\n" + "library is included in the project configuration for\n" + "this packages including the following code in the\n" + "package's folder CMakeLists.txt file:\n" + "SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS\n" + " ../lib/"+ it->first + "\n" + ")\n" + "SET(${BBTK_PACKAGE_NAME}_LIBS\n" + " " + it->first+ "\n" + ")")); + ChBIncl->SetName(crea::std2wx(it->first)); + ChBIncl->SetValue(it->second); + includesLibGridSizer->Add(ChBIncl, 0, wxEXPAND); + + wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first)); + includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND); + } + + includesLibGridSizer->AddGrowableCol(1,1); + + includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5); + + includesPanel->SetSizer(includesPanelSizer); + + v_sizer1->Add(includesPanel, 1, wxEXPAND | wxALL, 10); + + v_sizer1->Add(new wxButton(this, wxID_OK, wxT("Close")), 0, wxALIGN_CENTER | wxRIGHT | wxBOTTOM, 30); + + SetSizer(v_sizer1); +} + +void wxCDMPackageConfigurationDialog::OnFinish(wxCommandEvent& event) +{ + this->EndModal(wxID_OK); +} + +void wxCDMPackageConfigurationDialog::On3rdLibraryIncludeChange( + wxCommandEvent& event) +{ + if(this->package->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} + +void wxCDMPackageConfigurationDialog::OnCustomLibraryIncludeChange( + wxCommandEvent& event) +{ + if(this->package->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue())) + ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue()); + else + ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue()); +} diff --git a/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.h b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.h new file mode 100644 index 0000000..a839430 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMPackageConfigurationDialog.h @@ -0,0 +1,127 @@ +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ +*/ + + +/* + * wxCDMPackageConfigurationDialog.h + * + * Created on: 6/4/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#ifndef WXCDMPACKAGECONFIGURATIONDIALOG_H_ +#define WXCDMPACKAGECONFIGURATIONDIALOG_H_ + +#include +#include + +#include "modelCDMPackage.h" + +/** + * Package Configuration Dialog + */ +class wxCDMPackageConfigurationDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() +public: + /** + * Package Configuration Dialog Constructor. + * @param parent Parent window. + * @param package Package Description reference. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Package Library Configuration". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE. + */ + wxCDMPackageConfigurationDialog( + wxWindow* parent, + modelCDMPackage * package, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Package Library Configuration"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,370), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + /** + * Destructor. + */ + ~wxCDMPackageConfigurationDialog(); + /** + * Package Configuration Dialog Creator. + * @param parent Parent window. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Package Library Configuration". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE. + * @return if the creation was successful. + */ + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Package Library Configuration"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,370), + long style = wxDEFAULT_DIALOG_STYLE + ); + +protected: + /** + * Creates the help controls (text and buttons). + */ + void CreateControls(); + +//attributes +private: + /** + * Main panel reference. + */ + modelCDMPackage* package; + +//handlers +protected: + /** + * Handler to close configuration dialog. + * @param event Unused. + */ + void OnFinish(wxCommandEvent& event); + + /** + * Handler when a third party library include is pressed. + * @param event checkbox event. + */ + void On3rdLibraryIncludeChange(wxCommandEvent& event); + + /** + * Handler when a custom library include is pressed. + * @param event checkbox event. + */ + void OnCustomLibraryIncludeChange(wxCommandEvent& event); +}; + +#endif /* WXCDMPACKAGECONFIGURATIONDIALOG_H_ */ diff --git a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp index e2e452c..c736270 100644 --- a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp @@ -40,6 +40,7 @@ #include "images/PkIcon64.xpm" #include "wxCDMNewBlackBoxDialog.h" +#include "wxCDMPackageConfigurationDialog.h" #include #include "CDMUtilities.h" @@ -57,6 +58,7 @@ EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackB EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder) +EVT_BUTTON(ID_BUTTON_CHOOSE, wxCDMPackageDescriptionPanel::OnBtnConfigurePackage) END_EVENT_TABLE() wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel( @@ -86,9 +88,12 @@ bool wxCDMPackageDescriptionPanel::Create( long style ) { - wxPanel::Create(parent, id, pos, size, style); this->package = package; + wxPanel::Create(parent, id, pos, size, style); CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -215,12 +220,15 @@ void wxCDMPackageDescriptionPanel::CreateControls() wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("A. Create Black Box")); createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package.")); actionsGridSizer->Add(createBBbt, 1, wxALL | wxEXPAND, 5); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File")); + wxButton* editConfbt = new wxButton(actionsPanel, ID_BUTTON_CHOOSE, _T("B. Configure Package")); + editConfbt->SetToolTip(wxT("Select the libraries your package is going to use. This procedure changes the package's CMakeLists file.")); + actionsGridSizer->Add(editConfbt, 1, wxALL | wxEXPAND, 5); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this); actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Package Folder")); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder")); openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer.")); actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); @@ -407,6 +415,14 @@ void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event) } } +void +wxCDMPackageDescriptionPanel::OnBtnConfigurePackage(wxCommandEvent& event) +{ + wxCDMPackageConfigurationDialog* dialog = new wxCDMPackageConfigurationDialog(this,this->package); + long userResponse; + userResponse = dialog->ShowModal(); +} + void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) { std::string* result; diff --git a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.h index 8e88f9a..6e992bd 100644 --- a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.h @@ -36,7 +36,6 @@ #define WXCDMPACKAGEDESCRIPTIONPANEL_H_ #include -#include #include #include "modelCDMPackage.h" @@ -44,7 +43,7 @@ /** * Package description panel. Shows the package's properties and the available actions for a package. */ -class wxCDMPackageDescriptionPanel : public wxPanel +class wxCDMPackageDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -146,6 +145,10 @@ protected: * Handles when the create black box button is pressed. */ void OnBtnCreateBlackBox(wxCommandEvent& event); + /** + * Handles when the configure package button is pressed. + */ + void OnBtnConfigurePackage(wxCommandEvent& event); /** * Handles when the edit cmakelists file button is pressed. */ diff --git a/lib/creaDevManagerLib/wxCDMPackageManagerPanel.cpp b/lib/creaDevManagerLib/wxCDMPackageManagerPanel.cpp index 543ac59..d7a28be 100644 --- a/lib/creaDevManagerLib/wxCDMPackageManagerPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMPackageManagerPanel.cpp @@ -49,6 +49,7 @@ EVT_BUTTON(ID_BUTTON_CREATE_PACKAGE, wxCDMPackageManagerPanel::OnBtnCreatePackag EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, wxCDMPackageManagerPanel::OnBtnCreatePackage) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageManagerPanel::OnBtnEditCMakeLists) EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_TOOL_ENTER, wxCDMPackageManagerPanel::OnBtnEditCMakeLists) +EVT_CHECKBOX(ID_CHECK_INCLUDE_PACKAGE, wxCDMPackageManagerPanel::OnChBPackageChange) END_EVENT_TABLE() wxCDMPackageManagerPanel::wxCDMPackageManagerPanel( @@ -81,6 +82,9 @@ bool wxCDMPackageManagerPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->project = project; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -111,22 +115,54 @@ void wxCDMPackageManagerPanel::CreateControls() wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages")); propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available packages to see its details or modify them. Remember that black boxes are created inside packages, any of these packages is available.")); wxPanel* propertiesPanel = new wxPanel(this); - wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL); std::vector packages = this->project->GetPackages(); + wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(packages.size()+1, 3, 9, 5); + + wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Package Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL); + + propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5); + propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5); + for (int i = 0; i < (int)(packages.size()); i++) { - wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); - pPackagelk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER); - std::string tt = "Author: " + packages[i]->GetAuthors() + "\nDescription: " + packages[i]->GetDescription(); + //checkbox for cmake inclusion + wxCheckBox* pPackageChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_PACKAGE, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); + pPackageChB->SetName(crea::std2wx(packages[i]->GetName())); + std::string tt = "if this box is checked the the " + packages[i]->GetName() + " package is included in the project compilation."; + pPackageChB->SetToolTip(crea::std2wx(tt)); + pPackageChB->SetValue(this->project->IsPackageIncluded(packages[i]->GetName())); + propertiesGridSizer -> Add(pPackageChB, 0, wxEXPAND | wxALIGN_CENTER); + + //link to package with description + wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE); + pPackagelk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER); + tt = "Name: " + packages[i]->GetName() + "\n"; + tt += "Location: " + packages[i]->GetPath(); pPackagelk->SetToolTip(crea::std2wx(tt)); - propertiesPanelSizer -> Add(pPackagelk, 0, wxEXPAND | wxALL, 5); pPackagelk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseEnter,NULL,this); pPackagelk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseExit,NULL,this); + propertiesGridSizer -> Add(pPackagelk, 0, wxEXPAND); + + //help icon + wxButton* pPackageHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); + pPackageHlp->Enable(false); + tt = "When this package is included in the CMakeLists file, the\nfollowing line is included in the CMakeList.txt file in the\nproject folder:\n" + "ADD_SUBDIRECTORY(" + packages[i]->GetName() + ")"; + pPackageHlp->SetToolTip(crea::std2wx(tt)); + + propertiesGridSizer -> Add(pPackageHlp, 0, wxEXPAND | wxALIGN_CENTER); } - propertiesPanel->SetSizer(propertiesPanelSizer); - propertiesPanelSizer->Fit(propertiesPanel); + propertiesGridSizer->AddGrowableCol(1,1); + + propertiesPanel->SetSizer(propertiesGridSizer); + propertiesGridSizer->Fit(propertiesPanel); + + propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5); sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10); @@ -142,7 +178,7 @@ void wxCDMPackageManagerPanel::CreateControls() wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("A. Create Package")); createPkgbt->SetToolTip(wxT("Create a new package for this project.")); actionsGridSizer->Add(createPkgbt, 1, wxALL | wxEXPAND, 5); - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseExit,NULL,this); @@ -181,6 +217,14 @@ void wxCDMPackageManagerPanel::OnBtnReturn(wxHyperlinkEvent& event) wxPostEvent(this->GetParent(), *newEvent); } +void wxCDMPackageManagerPanel::OnChBPackageChange(wxCommandEvent& event) +{ + this->project->SetPackageInclude( + crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), + ((wxCheckBox*)event.GetEventObject())->GetValue() + ); +} + void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event) { modelCDMPackage* thePackage = NULL; diff --git a/lib/creaDevManagerLib/wxCDMPackageManagerPanel.h b/lib/creaDevManagerLib/wxCDMPackageManagerPanel.h index 66a1d1c..245ebf9 100644 --- a/lib/creaDevManagerLib/wxCDMPackageManagerPanel.h +++ b/lib/creaDevManagerLib/wxCDMPackageManagerPanel.h @@ -36,7 +36,6 @@ #define WXCDMPACKAGEMANAGERPANEL_H_ #include -#include #include #include @@ -45,7 +44,7 @@ /** * Package manager description panel. Shows the available packages in the project and the actions corresponding to package management. */ -class wxCDMPackageManagerPanel : public wxPanel +class wxCDMPackageManagerPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -119,6 +118,11 @@ protected: * @param event Has the link reference to know where to return */ void OnBtnReturn(wxHyperlinkEvent& event); + /** + * Handles when a package checkbox is (un)checked. + * @param event Has the link reference to know which package was selected. + */ + void OnChBPackageChange(wxCommandEvent& event); /** * Handles when a packages link is pressed. * @param event Has the link reference to know which package was selected. diff --git a/lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp b/lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp index 0b33c8c..35a98be 100755 --- a/lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMProjectActionsPanel.cpp @@ -77,8 +77,10 @@ bool wxCDMProjectActionsPanel::Create( wxPanel::Create(parent,id,pos,size,style); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); this->SetSizer(sizer); - CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } diff --git a/lib/creaDevManagerLib/wxCDMProjectActionsPanel.h b/lib/creaDevManagerLib/wxCDMProjectActionsPanel.h index 93850e2..cd60d75 100755 --- a/lib/creaDevManagerLib/wxCDMProjectActionsPanel.h +++ b/lib/creaDevManagerLib/wxCDMProjectActionsPanel.h @@ -37,14 +37,13 @@ #define WXCDMPROJECTACTIONSPANEL_H_ #include -#include #include "modelCDMProject.h" /** * Panel with common actions for an open Crea project. */ -class wxCDMProjectActionsPanel : public wxPanel +class wxCDMProjectActionsPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: diff --git a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp index 76aa9bb..a6f121b 100644 --- a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp @@ -49,6 +49,7 @@ EVT_BUTTON(ID_BUTTON_GOTO_LIB_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManage EVT_BUTTON(ID_BUTTON_GOTO_APPLI_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageApplications) EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists) EVT_BUTTON(ID_BUTTON_SET_BUILD_PATH, wxCDMProjectDescriptionPanel::OnBtnSetBuildPath) +EVT_BUTTON(ID_BUTTON_OPEN_BUILD_PATH, wxCDMProjectDescriptionPanel::OnBtnOpenBuild) EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMProjectDescriptionPanel::OnBtnOpenFolder) EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMProjectDescriptionPanel::OnBtnSetVersion) END_EVENT_TABLE() @@ -83,6 +84,9 @@ bool wxCDMProjectDescriptionPanel::Create( wxPanel::Create(parent, id, pos, size, style); this->project = project; CreateControls(); + // this part makes the scrollbars show up + this->FitInside(); // ask the sizer about the needed size + this->SetScrollRate(5, 5); return TRUE; } @@ -135,7 +139,7 @@ void wxCDMProjectDescriptionPanel::CreateControls() // sourceLocation wxBoxSizer* pSourceLocationsz = new wxBoxSizer(wxHORIZONTAL); wxStaticText* pSourceLocationtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetPath())); - //pSourceLocationtc->SetMaxSize(wxSize(350,-1)); + pSourceLocationtc->SetMaxSize(wxSize(200,-1)); wxButton* pSourceLocationbt = new wxButton(propertiesPanel, ID_BUTTON_OPEN_FOLDER, wxT("Open")); pSourceLocationbt->SetToolTip(wxT("Open the source folder in the file explorer.")); pSourceLocationsz->Add(pSourceLocationtc, 1, wxALIGN_CENTER, 1); @@ -143,11 +147,17 @@ void wxCDMProjectDescriptionPanel::CreateControls() // buildLocation wxBoxSizer* pBuildLocationsz = new wxBoxSizer(wxHORIZONTAL); this->buildPathtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetBuildPath())); - //this->buildPathtc->SetMaxSize(wxSize(350,-1)); - wxButton* pBuildLocationbt = new wxButton(propertiesPanel, ID_BUTTON_SET_BUILD_PATH, wxT("Choose")); + this->buildPathtc->SetMaxSize(wxSize(200,-1)); + + wxButton* pBuildLocationbt = new wxButton(propertiesPanel, ID_BUTTON_SET_BUILD_PATH, wxT("Choose...")); pBuildLocationbt->SetToolTip(wxT("Select a new location for compiling the project.")); + + wxButton* pBuildOpenbt = new wxButton(propertiesPanel, ID_BUTTON_OPEN_BUILD_PATH, wxT("Open")); + pBuildOpenbt->SetToolTip(wxT("Open the binaries folder in the file explorer.")); + pBuildLocationsz->Add(this->buildPathtc, 1, wxALIGN_CENTER, 1); pBuildLocationsz->Add(pBuildLocationbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10); + pBuildLocationsz->Add(pBuildOpenbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10); propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND); @@ -206,7 +216,7 @@ void wxCDMProjectDescriptionPanel::CreateControls() actionsGridSizer->Add(appliMgrbt, 1, wxALL | wxEXPAND, 5); } // edit CMakeLists file - wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("D. Edit CMakeLists File")); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseExit,NULL,this); @@ -303,8 +313,7 @@ void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event) } } -void -wxCDMProjectDescriptionPanel::OnBtnSetBuildPath(wxCommandEvent& event) +void wxCDMProjectDescriptionPanel::OnBtnSetBuildPath(wxCommandEvent& event) { wxDirDialog* dialog = new wxDirDialog(this, wxT("Choose the new build location for the project")); if(dialog->ShowModal()) @@ -316,8 +325,13 @@ wxCDMProjectDescriptionPanel::OnBtnSetBuildPath(wxCommandEvent& event) this->buildPathtc->SetLabel(crea::std2wx(this->project->GetBuildPath())); } -void -wxCDMProjectDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event) +void wxCDMProjectDescriptionPanel::OnBtnOpenBuild(wxCommandEvent& event) +{ + if(CDMUtilities::openFileExplorer(this->project->GetBuildPath())) + wxMessageBox(crea::std2wx("The folder doesn't exist or hasn't yet been created."),_T("Open Folder - Error!"),wxOK | wxICON_ERROR); +} + +void wxCDMProjectDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event) { std::string* result; if(!this->project->OpenInFileExplorer(result)) diff --git a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h index 86726c5..d210e32 100644 --- a/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.h @@ -36,14 +36,13 @@ #define WXCDMPROJECTDESCRIPTIONPANEL_H_ #include -#include #include "modelCDMProject.h" /** * Project Description Panel. Shows the project properties and the principal actions for the project. */ -class wxCDMProjectDescriptionPanel : public wxPanel +class wxCDMProjectDescriptionPanel : public wxScrolledWindow { DECLARE_EVENT_TABLE() public: @@ -145,6 +144,10 @@ protected: * Handles when the choose build path button is pressed. */ void OnBtnSetBuildPath(wxCommandEvent& event); + /** + * Handles when the open build folder button is pressed. + */ + void OnBtnOpenBuild(wxCommandEvent& event); /** * Handles when the open containing folder button is pressed. */