]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add export root for a box with material et media
authorClarisse Genrault <cgenrault@is231796.intra.cea.fr>
Fri, 7 Aug 2020 12:25:13 +0000 (14:25 +0200)
committerClarisse Genrault <cgenrault@is231796.intra.cea.fr>
Fri, 7 Aug 2020 12:25:13 +0000 (14:25 +0200)
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_ExportRoot.h [new file with mode: 0644]
src/ExchangePlugin/export_widget.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h [new file with mode: 0644]

index 222f2e6eaea1ac3bea1cbbb0aa44e8d0b8465cd8..cc82d7da6efdcc25743127d50d6b7f364b68c884 100644 (file)
@@ -27,6 +27,8 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/GeomAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
                     ${PROJECT_SOURCE_DIR}/src/XAO
+                    ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
+                    ${PROJECT_SOURCE_DIR}/src/CollectionPlugin
 )
 
 SET(PROJECT_HEADERS
@@ -37,6 +39,7 @@ SET(PROJECT_HEADERS
     ExchangePlugin_Validators.h
     ExchangePlugin_Tools.h
     ExchangePlugin_Dump.h
+    ExchangePlugin_ExportRoot.h
 )
 
 SET(PROJECT_SOURCES
@@ -46,6 +49,7 @@ SET(PROJECT_SOURCES
     ExchangePlugin_Validators.cpp
     ExchangePlugin_Tools.cpp
     ExchangePlugin_Dump.cpp
+    ExchangePlugin_ExportRoot.cpp
 )
 
 SET(XML_RESOURCES
index 4eedccc2604e1078446fe24cbd99dbde9ea37b5a..c876948701a00974f11318ad53bb5641090c539c 100644 (file)
@@ -26,6 +26,7 @@
 #include <iostream>
 #include <ostream>
 #endif
+#include <iostream>
 
 #include <Config_Common.h>
 #include <Config_PropManager.h>
@@ -33,6 +34,7 @@
 #include <GeomAlgoAPI_BREPExport.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_IGESExport.h>
+#include <GeomAlgoAPI_ROOTExport.h>
 #include <GeomAlgoAPI_STEPExport.h>
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_XAOExport.h>
@@ -41,6 +43,7 @@
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_Trsf.h>
 
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeStringArray.h>
 #include <XAO_Xao.hxx>
 #include <XAO_Geometry.hxx>
 
+#include <ExchangePlugin_ExportRoot.h>
 #include <ExchangePlugin_Tools.h>
 
+#include <PrimitivesPlugin_Box.h>
+
+#ifdef WIN32
+# define _separator_ '\\'
+#else
+# define _separator_ '/'
+#endif
+
 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
 {
 }
@@ -86,6 +98,8 @@ void ExchangePlugin_ExportFeature::initAttributes()
     ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
     ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::ROOT_FILE_PATH_ID(),
+    ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
     ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
@@ -94,6 +108,12 @@ void ExchangePlugin_ExportFeature::initAttributes()
     ModelAPI_AttributeString::typeId());
   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
     ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::ROOT_MANAGER_NAME_ID(),
+    ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::ROOT_MANAGER_TITLE_ID(),
+    ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::MAT_FILE_ID(),
+    ModelAPI_AttributeString::typeId());
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
@@ -108,6 +128,9 @@ void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
   if (theID == XAO_FILE_PATH_ID()) {
     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
+  } else if (theID == ROOT_FILE_PATH_ID()) {
+    string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
+      string(ExchangePlugin_ExportFeature::ROOT_FILE_PATH_ID())->value());
   }
 }
 
@@ -119,10 +142,14 @@ void ExchangePlugin_ExportFeature::execute()
   AttributeStringPtr aFormatAttr =
       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
   std::string aFormat = aFormatAttr->value();
+  std::cout<<"FORMAT"<<std::endl;
+  std::cout<<aFormat<<std::endl;
 
   AttributeStringPtr aFilePathAttr =
       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
   std::string aFilePath = aFilePathAttr->value();
+  std::cout<<"FILE"<<std::endl;
+  std::cout<<aFilePath<<std::endl;
   if (aFilePath.empty())
     return;
 
@@ -143,16 +170,27 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
       aFormatName = "STEP";
     } else if (anExtension == "IGES" || anExtension == "IGS") {
       aFormatName = "IGES-5.1";
+    } else if (anExtension == "C") {
+      aFormatName = "ROOT";
     } else {
       aFormatName = anExtension;
     }
   }
 
+  std::cout<<"PASSAGE1"<<std::endl;
+  std::cout<<aFormatName<<std::endl;
+
   if (aFormatName == "XAO") {
     exportXAO(theFileName);
     return;
   }
 
+  
+  if (aFormatName == "ROOT") {
+    exportROOT(theFileName);
+    return;
+  }
+
   // make shape for export from selected shapes
   AttributeSelectionListPtr aSelectionListAttr =
       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
@@ -558,6 +596,76 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 // LCOV_EXCL_STOP
 }
 
+
+void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName)
+{
+  std::cout<<"EXPORT ROOT ==> debut"<<std::endl;
+  std::string aName = string(ExchangePlugin_ExportFeature::ROOT_MANAGER_NAME_ID())->value();
+  std::string aTitle = string(ExchangePlugin_ExportFeature::ROOT_MANAGER_TITLE_ID())->value();
+  std::string aFileMat = string(ExchangePlugin_ExportFeature::MAT_FILE_ID())->value();
+
+  std::shared_ptr<GeomAlgoAPI_ROOTExport> anAlgo(new GeomAlgoAPI_ROOTExport(theFileName));
+
+  std::list<std::string> listNames = ExchangePlugin_Tools::split(theFileName, _separator_);
+  listNames = ExchangePlugin_Tools::split(listNames.back(), '.');
+
+  // Create the head of file
+  anAlgo->buildHead(listNames.front(), aName, aTitle);
+  
+  // Materials and medias
+  std::map<std::string, std::vector<std::string> > aMat;
+  std::map<std::string, std::vector<std::string> > aMedium;
+  ExchangePlugin_ExportRoot::readFileMat(aFileMat, aMat, aMedium);
+  std::cout<<"Size  "<<aMat.size()<<std::endl;
+  std::cout<<"Size  "<<aMedium.size()<<std::endl;
+  
+  anAlgo->buildMatAndMedium(aMat, aMedium);
+
+  // Add feature in the file 
+  std::list<FeaturePtr> theExport = document()->allFeatures();
+  std::list<FeaturePtr>::iterator itExport = theExport.begin();
+  std::vector<std::string> aListNamesOfFeatures;
+  for (; itExport != theExport.end(); ++itExport)
+  {
+      FeaturePtr aCurFeature = *itExport;
+      if (aCurFeature->getKind() == "Box") {
+        double anOx, anOy, anOz, aDx, aDy, aDz;
+        ExchangePlugin_ExportRoot::computeBox(aCurFeature, anOx, anOy, anOz, aDx, aDy, aDz);
+        //std::cout<<"BOX EN COURS (Feature) :: "<<aCurFeature->data()->name()<<std::endl;
+        //std::cout<<"BOX EN COURS (Result) :: "<<aCurFeature->firstResult()->data()->name()<<std::endl;
+        std::string anObjectName = aCurFeature->firstResult()->data()->name();
+        anAlgo->buildBox(anObjectName, anOx, anOy, anOz, aDx, aDy, aDz);
+        aListNamesOfFeatures.push_back(anObjectName);
+        aListNamesOfFeatures.push_back(aCurFeature->data()->name());
+      }
+  }
+  
+  std::cout<<"Nb of elements :: " << aListNamesOfFeatures.size() << std::endl;
+  
+  // Add all groups in the file
+  itExport = theExport.begin();
+  for (; itExport != theExport.end(); ++itExport)
+  {
+      FeaturePtr aCurFeature = *itExport;
+      if (aCurFeature->getKind() == "Group") {
+        std::vector<std::string> aListNames;
+        std::string anObjectName = aCurFeature->firstResult()->data()->name();
+        ExchangePlugin_ExportRoot::computeGroup(aCurFeature, aListNames);
+        
+        //for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
+        for (std::vector<std::string>::iterator it = aListNames.begin(); it != aListNames.end(); it++) {
+          std::string aName = anObjectName + "_" + *it;
+          anAlgo->BuildVolume(aName, *it, anObjectName);
+        }
+      }
+  }
+
+  anAlgo->buildEnd();
+
+  // Create the file with the content
+  anAlgo->write();
+}
+
 bool ExchangePlugin_ExportFeature::isMacro() const
 {
   if (!data().get() || !data()->isValid())
index c0a79a8c5ea092bcbbba0d7fff00d3a97f0d6d7a..5d5060cbcf42f2cf16946ff3b71dfd78fa6c4d3f 100644 (file)
@@ -84,6 +84,32 @@ public:
     static const std::string MY_XAO_GEOMETRY_NAME_ID("xao_geometry_name");
     return MY_XAO_GEOMETRY_NAME_ID;
   }
+
+  /// attribute name of root file path
+  inline static const std::string& ROOT_FILE_PATH_ID()
+  {
+    static const std::string MY_ROOT_FILE_PATH_ID("root_file_path");
+    return MY_ROOT_FILE_PATH_ID;
+  }
+  /// attribute name of author for XAO format
+  inline static const std::string& ROOT_MANAGER_NAME_ID()
+  {
+    static const std::string MY_ROOT_MANAGER_NAME_ID("root_manager_name");
+    return MY_ROOT_MANAGER_NAME_ID;
+  }
+  /// attribute name of geometry name for XAO format
+  inline static const std::string& ROOT_MANAGER_TITLE_ID()
+  {
+    static const std::string MY_ROOT_MANAGER_TITLE_ID("root_manager_title");
+    return MY_ROOT_MANAGER_TITLE_ID;
+  }
+  /// attribute name of materials file
+  inline static const std::string& MAT_FILE_ID()
+  {
+    static const std::string MY_MAT_FILE_ID("mat_file");
+    return MY_MAT_FILE_ID;
+  }
+
   /// Default constructor
   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
   /// Default destructor
@@ -123,6 +149,9 @@ protected:
 
   /// Performs export to XAO file
   EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName);
+
+  /// Performs export to XAO file
+  EXCHANGEPLUGIN_EXPORT void exportROOT(const std::string& theFileName);
 };
 
 #endif /* EXPORT_EXPORTFEATURE_H_ */
diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp
new file mode 100644 (file)
index 0000000..61aabc2
--- /dev/null
@@ -0,0 +1,115 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <ExchangePlugin_ExportRoot.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <CollectionPlugin_Group.h>
+#include <ExchangePlugin_Tools.h>
+#include <PrimitivesPlugin_Box.h>
+
+#include <fstream>
+#include <iostream>
+
+void ExchangePlugin_ExportRoot::readFileMat(const std::string theFileMat,
+                                std::map<std::string, std::vector<std::string> >& aMat,
+                                std::map<std::string, std::vector<std::string> >& aMedias)
+{
+  std::string aLine;
+  std::ifstream aFile (theFileMat);
+  if (aFile.is_open())
+  {
+    while ( getline (aFile,aLine) )
+    {
+      std::list<std::string> aList = ExchangePlugin_Tools::split(aLine, ' '); 
+      std::list<std::string>::iterator itList = aList.begin();
+      
+      bool isFirst = true;
+      std::string aName;
+      std::vector<std::string> aData;
+      for (; itList != aList.end(); ++itList)
+      {
+        std::string anElem = *itList;
+        if (isFirst) {
+          aName = anElem;
+          isFirst = false;
+        } else {
+          aData.push_back(anElem);
+        }
+      }
+      std::cout<<"aType :: "<<aName<<std::endl;
+      std::cout<<"aName :: "<<aData[0]<<std::endl;
+      if (aName == "mat") {
+        aMat[aData[0]] = aData;
+      } else if (aName == "medium") {
+        aMedias[aData[0]] = aData;
+      } else {
+        std::cout<<"ERROR : ToDo"<<std::endl;
+      }
+    }
+    
+    aFile.close();
+  }
+  std::cout<<"Size of aMat :: "<<aMat.size()<<std::endl;
+  std::cout<<"Size of aMedias :: "<<aMedias.size()<<std::endl;
+}
+
+void ExchangePlugin_ExportRoot::computeBox(FeaturePtr theCurFeature,
+                                           double& OX, double& OY, double& OZ,
+                                           double& DX, double& DY, double& DZ)
+{
+  std::string aMethodName = theCurFeature->data()->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
+  if (aMethodName == "BoxByDimensions") {
+    DX = (theCurFeature->data()->real(PrimitivesPlugin_Box::DX_ID())->value())/2;
+    DY = (theCurFeature->data()->real(PrimitivesPlugin_Box::DY_ID())->value())/2;
+    DZ = (theCurFeature->data()->real(PrimitivesPlugin_Box::DZ_ID())->value())/2;
+    OX = DX;
+    OY = DY;
+    OZ = DZ;
+  } else if (aMethodName == "BoxByTwoPoints") {
+    // A completer
+  } else if (aMethodName == "BoxByOnePointAndDims") {
+    DX = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DX_ID())->value();
+    DY = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DY_ID())->value();
+    DY = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DZ_ID())->value();
+    OX = theCurFeature->data()->real(PrimitivesPlugin_Box::OX_ID())->value();
+    OY = theCurFeature->data()->real(PrimitivesPlugin_Box::OY_ID())->value();
+    OZ = theCurFeature->data()->real(PrimitivesPlugin_Box::OZ_ID())->value();
+  }
+}
+
+void ExchangePlugin_ExportRoot::computeGroup(FeaturePtr theCurFeature,
+                                             std::vector<std::string>& theListNames)
+{
+  std::cout<<"COMPUTE GROUP"<<std::endl;
+  AttributeSelectionListPtr anObjectsSelList =
+      theCurFeature->data()->selectionList(CollectionPlugin_Group::LIST_ID());
+      
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
+      anObjectsSelList->value(anObjectsIndex);
+    ObjectPtr anObject = anObjectAttr->contextObject();
+    std::string aName = anObject->data()->name();
+    std::cout<<"NAME :: "<<aName<<std::endl;
+    theListNames.push_back(aName);
+  }
+}
diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h
new file mode 100644 (file)
index 0000000..b82bf09
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef EXCHANGEPLUGIN_EXPORTROOT_H_
+#define EXCHANGEPLUGIN_EXPORTROOT_H_
+
+#include <ExchangePlugin.h>
+#include <ModelAPI_Feature.h>
+
+#include <map>
+
+/**
+ * \class ExchangePlugin_Tools
+ * \brief Internal tools for the ExchangePlugin.
+ */
+class EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportRoot {
+public:
+  /// Compute the list of materials and medias
+  static void readFileMat(const std::string theFileMat,
+                          std::map<std::string, std::vector<std::string> >& aMat,
+                          std::map<std::string, std::vector<std::string> >& aMedias);
+  
+  /// Compute ....
+  static void computeBox(FeaturePtr theCurFeature,
+                         double& OX, double& OY, double& OZ, double& DX, double& DY, double& DZ);
+  
+  /// Compute ....
+  static void computeGroup(FeaturePtr theCurFeature, std::vector<std::string>& theListNames);
+};
+
+#endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
index 9e134b805c32601d268fc1ce6e73a25e165e2a50..c413805641d8ab08c76551e0e09184c81eca8c81 100644 (file)
                    placeholder="Please input the geometry name">
       </stringvalue>
     </case>
+    <case id="ROOT" title="ROOT">
+      <export_file_selector id="root_file_path"
+                            type="save"
+                            title="Export file"
+                            path="">
+        <validator id="ExchangePlugin_ExportFormat"
+                   parameters="C:root" />
+      </export_file_selector>
+      <stringvalue id="root_manager_name"
+                   label="Manager name"
+                   placeholder="Please input the name of the manager">
+      </stringvalue>
+      <stringvalue id="root_manager_title"
+                   label="Manager title"
+                   placeholder="Please input the title of the manager">
+      </stringvalue>
+      <file_selector id="mat_file" title="Materials file" path="">
+      </file_selector>
+    </case>
   </switch>
 </source>
index 235851975d320db4ffd4596b5215e1af2ee011b9..3349b7968e4a1f936797fb2532d059c170dcba94 100644 (file)
@@ -82,6 +82,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_SolidClassifier.h
     GeomAlgoAPI_MapShapesAndAncestors.h
     GeomAlgoAPI_Chamfer.h
+    GeomAlgoAPI_ROOTExport.h
 )
 
 SET(PROJECT_SOURCES
@@ -144,6 +145,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_MapShapesAndAncestors.cpp
     GeomAlgoAPI_Projection.cpp
     GeomAlgoAPI_Chamfer.cpp
+    GeomAlgoAPI_ROOTExport.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp
new file mode 100644 (file)
index 0000000..476b075
--- /dev/null
@@ -0,0 +1,116 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <GeomAlgoAPI_ROOTExport.h>
+
+#include <OSD_OpenFile.hxx>
+
+#include <fstream>
+
+//=================================================================================================
+GeomAlgoAPI_ROOTExport::GeomAlgoAPI_ROOTExport(const std::string& theFileName)
+{
+  myFileName = theFileName;
+  myContent = "";
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildHead(const std::string& theMethodName,
+                                       const std::string& theName,
+                                       const std::string& theTitle)
+{
+  std::string tmp = "void " + theMethodName + "() {\n";
+  myContent += tmp;
+  tmp = "gSystem->Load(\"libGeom\");\n";
+  myContent += tmp;
+  tmp = "TGeoManager *geom = new TGeoManager(\"" + theName + "\",\"" + theTitle +"\");\n";
+  myContent += tmp;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildBox(const std::string& theObjectName,
+                                      const double theOX, const double theOY, const double theOZ,
+                                      const double theDX, const double theDY, const double theDZ)
+{
+  std::cout<<"buildBox"<<std::endl;
+  char anOX[50], anOY[50], anOZ[50], aDX[50], aDY[50], aDZ[50];
+  sprintf(anOX, "%.f", theOX);
+  sprintf(anOY, "%.f", theOY);
+  sprintf(anOZ, "%.f", theOZ);
+  sprintf(aDX, "%.f", theDX);
+  sprintf(aDY, "%.f", theDY);
+  sprintf(aDZ, "%.f", theDZ);
+  myContent += "Double_t point_"+theObjectName+"[3] = {"+std::string(anOX)+",";
+  myContent += std::string(anOY)+","+std::string(anOZ)+"};\n";
+  myContent += "TGeoBBox* " + theObjectName + "= new TGeoBBox(\"" +theObjectName + "\",";
+  myContent += std::string(aDX)+","+std::string(aDY)+","+std::string(aDZ)+",point_";
+  myContent += theObjectName + ");\n";
+}
+
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildMatAndMedium(
+    const std::map<std::string,std::vector<std::string> > theMat,
+    const std::map<std::string, std::vector<std::string> > theMedium)
+{
+  std::map<std::string, std::vector<std::string> >::const_iterator anIt = theMat.begin(),
+                                                                   aLast = theMat.end();
+  for (; anIt != aLast; anIt++) {
+    std::vector<std::string> aValues = anIt->second;
+    myContent += "TGeoMaterial *" + anIt->first + " = new TGeoMaterial(\"";
+    myContent += aValues[1] + "\"," + aValues[2] + "," + aValues[3] + "," + aValues[4] + ") ;\n";
+  }
+  
+  std::map<std::string, std::vector<std::string> >::const_iterator anIt2 = theMedium.begin(),
+                                                                   aLast2 = theMedium.end();
+  for (; anIt2 != aLast2; anIt2++) {
+    std::vector<std::string> aValues = anIt2->second;
+    myContent += "TGeoMedium *" + anIt2->first + " = new TGeoMedium(\"";
+    myContent += aValues[1] + "\"," + aValues[2] + "," + aValues[3] + ") ;\n";
+  }
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::BuildVolume(const std::string theName,
+                                         const std::string theGeometryName,
+                                         const std::string theMediumName)
+{
+  myContent += "TGeoVolume *" + theName + " = new TGeoVolume(\"" + theName;
+  myContent += "\"," + theGeometryName + "," + theMediumName + ");\n";
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildEnd()
+{
+  myContent += "}";
+}
+
+//=================================================================================================
+bool GeomAlgoAPI_ROOTExport::write()
+{
+  std::ofstream aFile;
+  std::cout<<myFileName.c_str()<<std::endl;
+  OSD_OpenStream(aFile, myFileName.c_str(), std::ofstream::out);
+  if (!aFile.is_open())
+    return false;
+    
+  aFile << myContent << std::endl;
+  aFile.close();
+  return true;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h
new file mode 100644 (file)
index 0000000..df64310
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GEOMALGOAPI_ROOTEXPORT_H_
+#define GEOMALGOAPI_ROOTEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+/**\class GeomAlgoAPI_ROOTExport
+ * \ingroup DataAlgo
+ * \brief Allows to export results to a root file
+ */
+class GeomAlgoAPI_ROOTExport
+{
+public:
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_ROOTExport(const std::string& theFileName);
+
+  /// Build the head of file
+  GEOMALGOAPI_EXPORT void buildHead(const std::string& theMethodName, const std::string& theName,
+                                    const std::string& theTitle);
+
+  /// Build box
+  GEOMALGOAPI_EXPORT void buildBox(const std::string& theObjectName,
+                                   const double theOX, const double theOY, const double theOZ,
+                                   const double theDX, const double theDY, const double theDZ);
+
+  /// Build mat and medium
+  GEOMALGOAPI_EXPORT void buildMatAndMedium(
+      const std::map<std::string,std::vector<std::string> > theMat,
+      const std::map<std::string, std::vector<std::string> > theMedium);
+  
+  ///
+  GEOMALGOAPI_EXPORT void BuildVolume(const std::string theName, 
+                                      const std::string theGeometryName,
+                                      const std::string theMediumName);
+  
+  /// Build the end of file
+  GEOMALGOAPI_EXPORT void buildEnd();
+
+  /// Write the file
+  GEOMALGOAPI_EXPORT bool write();
+
+private:
+  std::string myFileName;
+  std::string myContent;
+};
+
+#endif /* GEOMALGOAPI_ROOTEXPORT_H_ */