]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMPackage.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMPackage.cpp
index 43d169abb13bfbbefb5b209424cc84f268447959..c6ea443d6d516e0e00b72c65cefe38f3c7f4ef79 100644 (file)
@@ -692,14 +692,154 @@ 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["Test"] = false;
+  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;
 }