#include "CDMUtilities.h"
#include "creaWx.h"
#include "wx/dir.h"
+#include <wx/config.h>
modelCDMProject::modelCDMProject()
{
this->lib = new modelCDMLib(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
this->children.push_back(this->lib);
}
- //if package , create package
- else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
- {
- modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
- this->packages.push_back(package);
- this->children.push_back(package);
- }
- //if is an unknown folder, create folder
else
{
- this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+ bool isPackage = false;
+
+ // check if cmakelists file exist in folder.
+ std::string tmppath = this->GetPath() + CDMUtilities::SLASH + stdfileName + CDMUtilities::SLASH + "CMakeLists.txt";
+ CDMUtilities::CMLFile CMfile = CDMUtilities::readCMLFile(tmppath.c_str());
+ if (CMfile.size() > 0)
+ {
+ std::cout << "-->" << stdfileName << " ::has cmakelists" << std::endl;
+ // check if cmakelists file has the SET(BBTK_PACKAGE_NAME [pkgname]) instruction.
+ for (int i = 0; !isPackage && i < CMfile.size(); ++i) {
+ if (CMfile[i].first == "command" && CMfile[i].second.size() > 1)
+ {
+ std::string cm = CMfile[i].second[0];
+
+ int pos = 1;
+ while(pos < CMfile[i].second.size()-1 && !isalpha(CMfile[i].second[pos][0]))
+ pos++;
+
+ std::string pm1 = CMfile[i].second[pos];
+
+ std::cout << cm << " " << pm1 << std::endl;
+ std::transform(cm.begin(), cm.end(), cm.begin(), ::toupper);
+ std::transform(pm1.begin(), pm1.end(), pm1.begin(), ::toupper);
+ if(cm == "SET" && pm1 == "BBTK_PACKAGE_NAME")
+ {
+ isPackage = true;
+ }
+ }
+ }
+ }
+
+ // if package, create package
+ if(isPackage)
+ {
+ std::cout << "is Package\n";
+ modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+ std::cout << "Package created\n";
+ this->packages.push_back(package);
+ this->children.push_back(package);
+ }
+ // if is an unknown folder, create folder
+ else
+ {
+ this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+ }
+
}
cont = dir.GetNext(&fileName);
while (cont)
{
std::string stdfileName = crea::wx2std(fileName);
+ std::size_t fileTypePos = stdfileName.find_last_of(".");
+ std::string fileType;
+ if(fileTypePos != std::string::npos)
+ fileType = stdfileName.substr(fileTypePos);
+ else
+ fileType = "";
//if CMakeLists, create CMakeLists
if(stdfileName == "CMakeLists.txt")
this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
this->children.push_back(this->CMakeLists);
}
+ //if is a code file, create modelCDMCodeFile
+ else if(
+ fileType == ".c" ||
+ fileType == ".cxx" ||
+ fileType == ".h" ||
+ fileType == ".cpp" ||
+ fileType == ".txx" ||
+ fileType == ".cmake" )
+ {
+ this->children.push_back(new modelCDMCodeFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+ }
+ //if is an unknown file, create file
else
{
this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
}
- //if is an unknown file, create file
+
cont = dir.GetNext(&fileName);
}
}
std::string modelCDMProject::GetBuildInstruction() const
{
- std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
+ wxConfigBase* pConfig = wxConfigBase::Get();
+ std::string commandline = crea::wx2std(pConfig->Read(wxT("BUILD_COMMAND"), crea::std2wx(CDMUtilities::BUILD_COMMAND)));
+
+
+ std::string makeComm = "cd \"" + this->buildPath + "\";" + commandline;// -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
return makeComm;
}
}
//if package , create package
- else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
+ /*else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
{
bool found = false;
for (int i = 0; !found && i < (int)(this->packages.size()); i++)
this->children.push_back(package);
}
- }
- //if is an unknown folder, create folder
+ }*/
+ // package or folder
else
{
- bool found = false;
- for (int i = 0; !found && i < (int)(this->children.size()); i++)
+ bool isPackage = false;
+
+ // check if cmakelists file exist in folder.
+ std::string tmppath = this->GetPath() + CDMUtilities::SLASH + stdfileName + CDMUtilities::SLASH + "CMakeLists.txt";
+ CDMUtilities::CMLFile CMfile = CDMUtilities::readCMLFile(tmppath.c_str());
+ if (CMfile.size() > 0)
+
{
- if (this->children[i]->GetName() == stdfileName)
+ // check if cmakelists file has the SET(BBTK_PACKAGE_NAME [pkgname]) instruction.
+ for (int i = 0; !isPackage && i < CMfile.size(); ++i) {
+ if (CMfile[i].first == "command" && CMfile[i].second.size() > 1)
+ {
+ std::string cm = CMfile[i].second[0];
+
+ int pos = 1;
+ while(pos < CMfile[i].second.size()-1 && !isalpha(CMfile[i].second[pos][0]))
+ pos++;
+
+ std::string pm1 = CMfile[i].second[pos];
+
+ std::cout << cm << " " << pm1 << std::endl;
+ std::transform(cm.begin(), cm.end(), cm.begin(), ::toupper);
+ std::transform(pm1.begin(), pm1.end(), pm1.begin(), ::toupper);
+ if(cm == "SET" && pm1 == "BBTK_PACKAGE_NAME")
+ {
+ isPackage = true;
+ }
+ }
+ }
+ }
+
+ // if package, create package
+ if (isPackage)
+ {
+ bool found = false;
+ for (int i = 0; !found && i < (int)(this->packages.size()); i++)
{
- found = true;
- checked[i] = true;
- if(!this->children[i]->Refresh(result))
- return false;
+ if (this->packages[i]->GetName() == stdfileName)
+ {
+ found = true;
+ int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
+ checked[pos] = true;
+ checkedPackages[i] = true;
+ if(!this->packages[i]->Refresh(result))
+ return false;
+ }
}
- }
- if(!found)
+ if (!found)
+ {
+ modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+ this->packages.push_back(package);
+ this->children.push_back(package);
+ }
+ }
+ //if is an unknown folder, create folder
+ else
{
- modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
- this->children.push_back(folder);
+ bool found = false;
+ for (int i = 0; !found && i < (int)(this->children.size()); i++)
+ {
+ if (this->children[i]->GetName() == stdfileName)
+ {
+ found = true;
+ checked[i] = true;
+ if(!this->children[i]->Refresh(result))
+ return false;
+ }
+ }
+
+ if(!found)
+ {
+ modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+ this->children.push_back(folder);
+ }
}
}
while (cont)
{
std::string stdfileName = crea::wx2std(fileName);
+ std::size_t fileTypePos = stdfileName.find_last_of(".");
+ std::string fileType;
+ if(fileTypePos != std::string::npos)
+ fileType = stdfileName.substr(fileTypePos);
+ else
+ fileType = "";
//if CMakeLists, create CMakeLists
if(stdfileName == "CMakeLists.txt")
return false;
}
}
+ //if is a code file, create modelCDMCodeFile
//if is an unknown file, create file
else
{
if(!found)
{
- modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
- this->children.push_back(file);
+ if(
+ fileType == ".c" ||
+ fileType == ".cxx" ||
+ fileType == ".h" ||
+ fileType == ".cpp" ||
+ fileType == ".txx" ||
+ fileType == ".cmake" )
+ {
+ this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+ }
+ else
+ {
+ modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+ this->children.push_back(file);
+ }
}
}