]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMPackage.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMPackage.cpp
index 78b6adf6ffdeb85c5c92e8d31094861e516021ad..c6ea443d6d516e0e00b72c65cefe38f3c7f4ef79 100644 (file)
@@ -244,7 +244,12 @@ bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& resul
   in.close();
   out.close();
   //delete old file and rename new file
+#ifdef _WIN32
+  std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+  
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
@@ -296,7 +301,12 @@ bool modelCDMPackage::SetVersion(const std::string& version, std::string*& resul
   in.close();
   out.close();
   //delete old file and rename new file
+#ifdef _WIN32
+  std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+  
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
@@ -342,7 +352,12 @@ bool modelCDMPackage::SetDescription(const std::string& description, std::string
   in.close();
   out.close();
   //delete old file and rename new file
+#ifdef _WIN32
+  std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+  
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
@@ -674,3 +689,169 @@ void modelCDMPackage::CheckStructure(std::map<std::string, bool>& properties)
 
     }
 }
+
+std::map<std::string, bool> modelCDMPackage::Get3rdPartyLibraries()
+{
+  std::map<std::string, std::string> 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<std::string, bool> 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())
+    {
+      CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
+      // look at every syntax element
+      for (int i = 0; i < cmlFile.size(); ++i)
+        {
+          // if the element is a command and is a SET command
+          if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
+            {
+              // search first parameter
+              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] != '(' && cmlFile[i].second[pos][0] != ')')
+                    {
+                      break;
+                    }
+                  pos++;
+                }
+              // if the first parameter is a third party statement
+              if (pos < cmlFile[i].second.size() && correspondence.find(cmlFile[i].second[pos]) != correspondence.end())
+                {
+                  std::string foundLibrary = cmlFile[i].second[pos];
+                  // search for second parameter
+                  pos++;
+                  while (pos < cmlFile[i].second.size())
+                    {
+                      if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
+                        {
+                          break;
+                        }
+                      pos++;
+                    }
+                  // if the second parameter is ON
+                  if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "ON")
+                    {
+                      res[correspondence[foundLibrary]] = true;
+                    }
+                }
+            }
+        }
+    }
+  return res;
+}
+
+bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name,
+    const bool& toInclude)
+{
+  std::map<std::string, std::string> correspondence;
+
+  correspondence["VTK"] = "${BBTK_PACKAGE_NAME}_USE_VTK";
+  correspondence["ITK"] = "${BBTK_PACKAGE_NAME}_USE_ITK";
+  correspondence["GDCM"] = "${BBTK_PACKAGE_NAME}_USE_GDCM";
+  correspondence["GDCM_VTK"] = "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK";
+  correspondence["GSMIS"] = "${BBTK_PACKAGE_NAME}_USE_GSMIS";
+  correspondence["WxWidgets"] = "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS";
+  correspondence["KWWidgets"] = "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS";
+/*
+  if(correspondence.find(library_name) != correspondence.end())
+    {
+      std::string library_command = correspondence[library_name];
+      if (this->HasCMakeLists())
+        {
+          CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
+          bool found = false;
+          // look at every syntax element
+          for (int i = 0; i < cmlFile.size(); ++i)
+            {
+              // if the element is a command and is a SET command
+              if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
+                {
+                  // search first parameter
+                  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] != '(' && cmlFile[i].second[pos][0] != ')')
+                        {
+                          break;
+                        }
+                      pos++;
+                    }
+                  // if the first parameter is a third party statement
+                  if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == library_command)
+                    {
+                      std::string foundLibrary = cmlFile[i].second[pos];
+                      // search for second parameter
+                      pos++;
+                      while (pos < cmlFile[i].second.size())
+                        {
+                          if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
+                            {
+                              break;
+                            }
+                          pos++;
+                        }
+                      // if the second parameter is ON
+                      if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "ON")
+                        {
+                          found = true;
+                          if (toInclude)
+                            {
+                              std::cout << "library already included: " << library_name << std::endl;
+                            }
+                          else
+                            {
+                              cmlFile[i].first = "comment";
+                              cmlFile[i].second[0] = "#" + cmlFile[i].second[0];
+                              std::cout << "library include commented: " << library_name << std::endl;
+                            }
+                        }
+                      else if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == "OFF")
+                        {
+                          found = true;
+                          if (toInclude)
+                            {
+                              cmlFile[i].second[pos] = "ON";
+                              std::cout << "library include activated: " << library_name << std::endl;
+                            }
+                          else
+                            {
+                              std::cout << "library include already disabled: " << library_name << std::endl;
+                            }
+                        }
+                    }
+                } else if (cmlFile[i].first == "comment") {
+                    //TODO: check if it is commented
+                }
+            }
+        }
+    }
+*/
+  return false;
+}
+
+std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
+{
+  std::map<std::string, bool> res;
+  res["Test"] = false;
+  return res;
+}
+
+bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
+    const bool& toInclude)
+{
+  return false;
+}