From 4aa565855cc817ff124ca012e786da1413f645c9 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Thu, 6 Dec 2012 12:00:58 +0100 Subject: [PATCH] Feature #1711 CreaDevManager application implementation Package detecting and creating black boxes. Black box constructor set. modelCDMProject documented. --- lib/creaDevManagerLib/modelCDMAppli.cpp | 1 - lib/creaDevManagerLib/modelCDMBlackBox.cpp | 11 ++ lib/creaDevManagerLib/modelCDMBlackBox.h | 1 + lib/creaDevManagerLib/modelCDMPackage.cpp | 63 +++++++++- lib/creaDevManagerLib/modelCDMProject.h | 128 +++++++++++++++++++++ 5 files changed, 202 insertions(+), 2 deletions(-) diff --git a/lib/creaDevManagerLib/modelCDMAppli.cpp b/lib/creaDevManagerLib/modelCDMAppli.cpp index 1f08f3b..9740917 100644 --- a/lib/creaDevManagerLib/modelCDMAppli.cpp +++ b/lib/creaDevManagerLib/modelCDMAppli.cpp @@ -55,7 +55,6 @@ modelCDMAppli::modelCDMAppli(const std::string& path, const int& level) this->path = CDMUtilities::fixPath(path); - //open makelists file std::string pathFixed(CDMUtilities::fixPath(path)); this->applications.clear(); diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.cpp b/lib/creaDevManagerLib/modelCDMBlackBox.cpp index db8b11c..d326e00 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.cpp +++ b/lib/creaDevManagerLib/modelCDMBlackBox.cpp @@ -34,10 +34,21 @@ #include "modelCDMBlackBox.h" +#include +#include"wx/dir.h" + modelCDMBlackBox::modelCDMBlackBox() { } +modelCDMBlackBox::modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level) +{ + this->name = hName.substr(2, hName.size()-4); + this->path = path; + this->level = level; + this->type = wxDIR_DIRS; +} + modelCDMBlackBox::~modelCDMBlackBox() { } diff --git a/lib/creaDevManagerLib/modelCDMBlackBox.h b/lib/creaDevManagerLib/modelCDMBlackBox.h index 7c0bb08..127a4d5 100644 --- a/lib/creaDevManagerLib/modelCDMBlackBox.h +++ b/lib/creaDevManagerLib/modelCDMBlackBox.h @@ -43,6 +43,7 @@ class modelCDMBlackBox : public modelCDMFolder { public: modelCDMBlackBox(); + modelCDMBlackBox(const std::string& hName, const std::string& path, const int& level = 1); ~modelCDMBlackBox(); const std::string& GetNameBlackBox() const; diff --git a/lib/creaDevManagerLib/modelCDMPackage.cpp b/lib/creaDevManagerLib/modelCDMPackage.cpp index b201b50..044171b 100644 --- a/lib/creaDevManagerLib/modelCDMPackage.cpp +++ b/lib/creaDevManagerLib/modelCDMPackage.cpp @@ -55,6 +55,67 @@ modelCDMPackage::modelCDMPackage(const std::string& path, const int& level) this->namePackage = this->name; this->level = level; this->path = path; + + //check all folders and files + wxDir dir(crea::std2wx((path).c_str())); + if (dir.IsOpened()) + { + wxString fileName; + + //folders + bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS); + while (cont) + { + std::string stdfileName = crea::wx2std(fileName); + //if src, check for black boxes + if(stdfileName == "src") + { + wxDir srcF(crea::std2wx((path + delimiters + "src").c_str())); + if (srcF.IsOpened()) + { + wxString srcName; + bool innerCont = srcF.GetFirst(&srcName, wxT("*.h"), wxDIR_FILES); + while (innerCont) + { + if(crea::wx2std(srcName.substr(0,2)) == "bb") + { + modelCDMBlackBox* blackbox = new modelCDMBlackBox(crea::wx2std(srcName), path + delimiters + "src", this->level + 1); + this->blackBoxes.push_back(blackbox); + this->children.push_back(blackbox); + } + innerCont = srcF.GetNext(&srcName); + } + } + } + //if is an unknown folder, create folder + else + { + this->children.push_back(new modelCDMFolder(path + delimiters + stdfileName, this->level + 1)); + } + cont = dir.GetNext(&fileName); + } + + //files + cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES); + while (cont) + { + std::string stdfileName = crea::wx2std(fileName); + + //if CMakeLists, create CMakeLists + if(stdfileName == "CMakeLists.txt") + { + this->CMakeLists = new modelCDMCMakeListsFile(path + delimiters + stdfileName, this->level + 1); + this->children.push_back(this->CMakeLists); + } + else + { + this->children.push_back(new modelCDMFile(path + delimiters + stdfileName, this->level + 1)); + } + //if is an unknown file, create file + cont = dir.GetNext(&fileName); + } + } + this->SortChildren(); } modelCDMPackage::~modelCDMPackage() @@ -101,7 +162,7 @@ bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& re bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result) { //TODO: implement method - return true; + return true; } bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result) diff --git a/lib/creaDevManagerLib/modelCDMProject.h b/lib/creaDevManagerLib/modelCDMProject.h index c6f5830..fe10702 100644 --- a/lib/creaDevManagerLib/modelCDMProject.h +++ b/lib/creaDevManagerLib/modelCDMProject.h @@ -44,23 +44,91 @@ #include "modelCDMPackage.h" #include "modelCDMCMakeListsFile.h" +/** + * Project model class. + * This class represents a project stored in a hard drive. It can perform some of the most relevant operations for a crea project. + */ class modelCDMProject : public modelCDMFolder { public: + /** + * Default constructor. + */ modelCDMProject(); + + /** + * Constructor receiving the source path and the build path. + * @param path The source path. + * @param buildPath The build path. By default it's an empty string. + */ modelCDMProject(const std::string& path, const std::string& buildPath = ""); + + /** + * Destructor. + */ ~modelCDMProject(); + /** + * Unimplemented. + */ void PopulateProject(); + + //Getters + /** + * Retrieves the name of the project. + * @return The name of the project. + */ const std::string& GetNameProject() const; + + /** + * Retrieves the version of the project. + * @return The version of the project in the format X.Y.Z where X is the major version of the project, Y is the minor version of the project, and Z is the build version. + */ const std::string& GetVersion() const; + + /** + * Retrieves the last version modification date of the project + * @return The date of the last version modification in the format DD/MM/YYYY + */ const std::string& GetVersionDate() const; + + /** + * Retrieves the build path of the project. + * @return The build path of the project. By default .../ProjectNameBin. + */ const std::string& GetBuildPath() const; + + //Setters + /** + * Sets the version of the project. It also modifies the build date of the project. + * @param version New version of the project. + * @param result returns the result of the operation. + * @return If the version configuration was successful it returns true. If not, it returns false and the error description returns in the parameter result. + */ bool SetVersion(const std::string& version, std::string*& result); + + /** + * Sets the build path of the project. + * @param path Path for builing the project. + * @param result Result of the operation. + * @return If the build path configuration was successful it returns true. If not, it returns false and the error description returns in the parameter result. + */ bool SetBuildPath(const std::string& path, std::string*& result); + + //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. + * @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 '_'. + * @param authorsEmail Authors' E-mails. This is appended to the package description. + * @param description Package description. + * @param version Package version in the format X.Y.Z where X is the major version, Y the minor version, and Z the build version. + * @return The result of the creation. If everything goes well it returns true, else it returns false. + */ modelCDMIProjectTreeNode* CreatePackage( const std::string& name, std::string*& result, @@ -69,16 +137,43 @@ public: const std::string& description = "no description", const std::string& version = "1.0.0" ); + + /** + * Creates a library and sets it as a children of the lib folder in the project. This method creates the library in the hard drive and also in the model. + * @param name Library name. + * @param result Result of the operation. + * @param path Path of the library if not in the lib folder. This parameter is not used (for now). + * @return The result of the creation. If everything goes well it returns true, else it returns false. + */ modelCDMIProjectTreeNode* CreateLibrary( const std::string& name, std::string*& result, const std::string& path = "/lib" ); + + /** + * Creates an application and sets it as a children of the appli folder in the project. This method creates the library in the hard drive and also in the model. + * @param name Application name. + * @param result Result of the operation. + * @param path Path of the application if not in the application folder. This parameter is not used (for now). + * @return The result of the creation. If everything goes well it returns true, else it returns false. + */ modelCDMIProjectTreeNode* CreateApplication( const std::string& name, std::string*& result, const std::string& path = "/appli" ); + + /** + * Creates a black box and sets it as a children of the specified package folder in the project. This method creates the black box in the hard drive and also in the model. + * @param name Black box name. + * @param package The name of the package where the black box is created. The name should not contain neither the "bbtk_" , nor the "_PKG" parts of the folder name. If empty converts into "/bbtk_*projectName*_PKG" + * @param authors The authors of the black box. This string should not contain commas or spaces, they will be replaced by '_'. + * @param authorsEmail The authors e-mails. This string should not contain spaces, they will be replaced by '/'. This field is appended to the black box description. + * @param categories The categories of concerning for the created black box. + * @param description Description of the black box. It should not contain spaces, they will be replaced by '_'. + * @return The result of the creation. If everything goes well it returns true, else it returns false. + */ modelCDMIProjectTreeNode* CreateBlackBox( const std::string& name, const std::string& package = "", //if empty converts into "/bbtk_*projectName*_PKG" @@ -87,12 +182,45 @@ public: const std::string& categories = "empty", const std::string& description = "no description" ); + + + //Operations + /** + * Opens the CMakeLists.txt file in the system's default text editor. + * @param result Result of the operation. + * @return Success of the operation. If the file doesn't exist or can't be opened it returns false. + */ bool OpenCMakeListsFile(std::string*& result); + + /** + * Refresh the model with the file hierarchy in the hard drive. + * @param result Result of the operation. + * @return if there's an error refreshing the project it returns false. + */ virtual const bool Refresh(std::string*& result); + + /** + * Launches in console the ccmake tool in the build path to configure the building of the project. + * @param result The result message of the operation. + * @return if the ccmake tool doesn't launches it returns false. + */ bool ConfigureBuild(std::string*& result); + + /** + * Launches in console the make -clean and make commands to build the project. + * @param result Result message for building the project. + * @return if any of the commands cannot be executed it return false. + */ bool Build(std::string*& result); + + /** + * Launches in console the bbPlugPackage command to connect the project to the .bbtk folder in the hard drive. + * @param result Result message for connecting the project. + * @return if the command cannot be executed it return false. + */ bool Connect(std::string*& result); + private: std::string nameProject; -- 2.45.1