]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add export boxes in ROOT format
authorcg246364 <clarisse.genrault@cea.fr>
Thu, 30 Sep 2021 05:09:55 +0000 (07:09 +0200)
committercg246364 <clarisse.genrault@cea.fr>
Thu, 30 Sep 2021 05:09:55 +0000 (07:09 +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]
src/PrimitivesPlugin/doc/images/Tube_button.png
src/PrimitivesPlugin/icons/tube.png

index a155317e903410136646565e20cc272f09c75a19..36f0a39dfe42e19410ace85c3f7b9715756ad39e 100644 (file)
@@ -31,6 +31,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/XAO
                     ${PROJECT_SOURCE_DIR}/src/ConstructionPlugin
                     ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+                    ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
                     ${OpenCASCADE_INCLUDE_DIR}
 )
 
@@ -45,6 +46,7 @@ SET(PROJECT_HEADERS
     ExchangePlugin_ImportPart.h
     ExchangePlugin_ExportPart.h
     ExchangePlugin_Import.h
+    ExchangePlugin_ExportRoot.h
 )
 
 SET(PROJECT_SOURCES
@@ -57,6 +59,7 @@ SET(PROJECT_SOURCES
     ExchangePlugin_ImportPart.cpp
     ExchangePlugin_ExportPart.cpp
     ExchangePlugin_Import.cpp
+    ExchangePlugin_ExportRoot.cpp
 )
 
 SET(XML_RESOURCES
index 6ae4199ec4da72ef2a973b569165cd84c4181210..cd57a9d6fb63e7ec3be97a52082cc41ce6290e64 100644 (file)
 #include <ExchangePlugin_ExportFeature.h>
 
 #include <algorithm>
+#include <fstream>
 #include <iterator>
 #include <string>
+#include <iostream>
 #ifdef _DEBUG
 #include <iostream>
 #include <ostream>
@@ -34,6 +36,7 @@
 #include <GeomAlgoAPI_BREPExport.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_IGESExport.h>
+#include <GeomAlgoAPI_ROOTExport.h>
 #include <GeomAlgoAPI_STEPExport.h>
 #include <GeomAlgoAPI_STLExport.h>
 #include <GeomAlgoAPI_Tools.h>
@@ -43,6 +46,8 @@
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_Trsf.h>
 
+#include <ExchangePlugin_ExportRoot.h>
+
 #include <Locale_Convert.h>
 
 #include <ModelAPI_AttributeSelectionList.h>
 
 #include <ExchangePlugin_Tools.h>
 
+#ifdef WIN32
+# define _separator_ '\\'
+#else
+# define _separator_ '/'
+#endif
+
 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
 {
 }
@@ -129,6 +140,19 @@ void ExchangePlugin_ExportFeature::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
     ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
 
+  data()->addAttribute(ExchangePlugin_ExportFeature::ROOT_FILE_PATH_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::EXP_NAME_FILE_ID(),
+    ModelAPI_AttributeString::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::MAIN_OBJECT_ID(),
+    ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(ExchangePlugin_ExportFeature::MAT_FILE_ID(),
+    ModelAPI_AttributeString::typeId());
+
   // to support previous version of document, move the selection list
   // if the type of export operation is XAO
   AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
@@ -153,7 +177,10 @@ void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
       string(ExchangePlugin_ExportFeature::STL_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());
+  }
 }
 
 /*
@@ -167,6 +194,7 @@ void ExchangePlugin_ExportFeature::execute()
 
   AttributeStringPtr aFilePathAttr =
       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
+
   std::string aFilePath = aFilePathAttr->value();
   if (aFilePath.empty())
     return;
@@ -188,6 +216,8 @@ 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;
     }
@@ -196,9 +226,12 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
   if (aFormatName == "XAO") {
     exportXAO(theFileName);
     return;
-  }else if (aFormatName == "STL") {
+  } else if (aFormatName == "STL") {
     exportSTL(theFileName);
     return;
+  } else if (aFormatName == "ROOT") {
+    exportROOT(theFileName);
+    return;
   }
 
   // make shape for export from selected shapes
@@ -661,6 +694,66 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 // LCOV_EXCL_STOP
 }
 
+void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName)
+{
+  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();
+
+  FeaturePtr aFeature;
+
+  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 mediums
+  std::map<std::string, std::vector<std::string> > aMaterials;
+  std::map<std::string, std::vector<std::string> > aMedias;
+  readFileMat(aFileMat, aMaterials, aMedias);
+  anAlgo->buildMaterialsMedias(aMaterials, aMedias);
+
+  // Create the end of files
+  std::string aExportFileName = string(ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID())->value();
+  AttributeSelectionPtr anObjectAttr = selection(MAIN_OBJECT_ID());
+  aFeature = anObjectAttr->contextFeature();
+  std::string aNameShape ="";
+  if (aFeature.get()) {
+    aNameShape = Locale::Convert::toString(aFeature->firstResult()->data()->name());
+  } else {
+    ObjectPtr anObject = anObjectAttr->contextObject();
+    aNameShape = Locale::Convert::toString(anObject->data()->name());
+  }
+
+  // Add feature in the file
+  std::list<FeaturePtr> aFeatures = document()->allFeatures();
+  std::list<FeaturePtr>::iterator itFeature = aFeatures.begin();
+  std::vector<std::wstring> aListNamesOfFeatures;
+  std::map<std::wstring, std::string> aMapFeauturesObject;
+  for(; itFeature != aFeatures.end(); ++itFeature)
+  {
+    aFeature = *itFeature;
+    if (aFeature->getKind() == "Box")
+    {
+      std::vector<double> aCenterDims;
+      aCenterDims = ExchangePlugin_ExportRoot::computeBox(aFeature);
+      std::wstring anObjectName = aFeature->firstResult()->data()->name();
+      anAlgo->buildBox(anObjectName, aCenterDims);
+      aListNamesOfFeatures.push_back(anObjectName);
+      aListNamesOfFeatures.push_back(aFeature->data()->name());
+    }
+  }
+
+  // Create the end of file
+  anAlgo->buildEnd(aNameShape, aExportFileName);
+
+  // Create the file with the content
+  anAlgo->write();
+}
+
 bool ExchangePlugin_ExportFeature::isMacro() const
 {
   if (!data().get() || !data()->isValid())
@@ -685,3 +778,41 @@ bool ExchangePlugin_ExportFeature::isMacro() const
   }
   return true;
 }
+
+
+//=================================================================================================
+void ExchangePlugin_ExportFeature::readFileMat(const std::string theFileMat,
+                   std::map<std::string, std::vector<std::string> >& theMaterials,
+                   std::map<std::string, std::vector<std::string> >& theMedias)
+{
+  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);
+        }
+      }
+      if (aName == "mat")
+        theMaterials[aData[0]] = aData;
+      else if (aName == "medium")
+        theMedias[aData[0]] = aData;
+    }
+    aFile.close();
+  }
+}
index ffd9deab8e755fae43668a5fe2620b4ebc8b93b1..a059b5b8c96b411242b4c71bb399ce4d99c41a15 100644 (file)
@@ -150,6 +150,43 @@ 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 file export
+  inline static const std::string& EXP_NAME_FILE_ID()
+  {
+    static const std::string MY_EXP_NAME_FILE_ID("root_name_file");
+    return MY_EXP_NAME_FILE_ID;
+  }
+  /// Attribute name of the main solid.
+  inline static const std::string& MAIN_OBJECT_ID()
+  {
+    static const std::string MY_MAIN_OBJECT_ID("root_main_object");
+    return MY_MAIN_OBJECT_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
@@ -192,6 +229,15 @@ protected:
 
   /// Performs export to STL file
   EXCHANGEPLUGIN_EXPORT void exportSTL(const std::string& theFileName);
+
+  /// Performs export to ROOT file
+  EXCHANGEPLUGIN_EXPORT void exportROOT(const std::string& theFileName);
+
+private:
+  /// Read materials and mediums in a file
+  void readFileMat(const std::string theFileMat,
+                   std::map<std::string, std::vector<std::string> >& theMaterials,
+                   std::map<std::string, std::vector<std::string> >& theMediums);
 };
 
 #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..721f363
--- /dev/null
@@ -0,0 +1,98 @@
+// Copyright (C) 2014-2021  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 <PrimitivesPlugin_Box.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <string>
+#include <iostream>
+
+#include "math.h"
+
+namespace ExchangePlugin_ExportRoot
+{
+  //===============================================================================================
+  std::vector<double> computeBox(FeaturePtr theFeature)
+  {
+    std::string aMethodName =
+      theFeature->data()->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
+
+    double OX, OY, OZ;
+    double DX, DY, DZ;
+
+    if (aMethodName == "BoxByDimensions") {
+      DX = (theFeature->data()->real(PrimitivesPlugin_Box::DX_ID())->value())/2;
+      DY = (theFeature->data()->real(PrimitivesPlugin_Box::DY_ID())->value())/2;
+      DZ = (theFeature->data()->real(PrimitivesPlugin_Box::DZ_ID())->value())/2;
+      OX = DX;
+      OY = DY;
+      OZ = DZ;
+    } else if (aMethodName == "BoxByTwoPoints") {
+      // Get the first point
+      AttributeSelectionPtr aRef1 =
+        theFeature->data()->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
+      GeomShapePtr aShape1 = aRef1->value();
+      if (!aShape1.get())
+        aShape1 = aRef1->context()->shape();
+      std::shared_ptr<GeomAPI_Pnt> aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
+      // Get the second point
+      AttributeSelectionPtr aRef2 =
+        theFeature->data()->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
+      GeomShapePtr aShape2 = aRef2->value();
+      if (!aShape2.get())
+        aShape2 = aRef2->context()->shape();
+      std::shared_ptr<GeomAPI_Pnt> aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2);
+      DX = fabs(aSecondPoint->x() - aFirstPoint->x())/2;
+      DY = fabs(aSecondPoint->y() - aFirstPoint->y())/2;
+      DZ = fabs(aSecondPoint->z() - aFirstPoint->z())/2;
+      OX = fmin(aFirstPoint->x(), aSecondPoint->x()) + DX;
+      OY = fmin(aFirstPoint->y(), aSecondPoint->y()) + DY;
+      OZ = fmin(aFirstPoint->z(), aSecondPoint->z()) + DZ;
+    } else if (aMethodName == "BoxByOnePointAndDims") {
+      OX = theFeature->data()->real(PrimitivesPlugin_Box::OX_ID())->value();
+      OY = theFeature->data()->real(PrimitivesPlugin_Box::OY_ID())->value();
+      OZ = theFeature->data()->real(PrimitivesPlugin_Box::OZ_ID())->value();
+      DX = theFeature->data()->real(PrimitivesPlugin_Box::HALF_DX_ID())->value();
+      DY = theFeature->data()->real(PrimitivesPlugin_Box::HALF_DY_ID())->value();
+      DZ = theFeature->data()->real(PrimitivesPlugin_Box::HALF_DZ_ID())->value();
+    } else {
+      // ToDo error
+     return;
+    }
+
+    std::vector<double> aCenterDims;
+    // Put the center
+    aCenterDims.push_back(OX);
+    aCenterDims.push_back(OY);
+    aCenterDims.push_back(OZ);
+
+    // Put the dimensions
+    aCenterDims.push_back(DX);
+    aCenterDims.push_back(DY);
+    aCenterDims.push_back(DZ);
+
+    return aCenterDims;
+
+  }
+} // namespace ExchangePlugin_ExportRoot
diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h
new file mode 100644 (file)
index 0000000..73b6b7d
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2014-2021  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_
+
+namespace ExchangePlugin_ExportRoot
+{
+  /// Returns the coordinates of the center and the dimensions of a box
+  /// \param[in] theFeature a feature to obtain AttributeRefAttr
+  /// \param[out] theCenter coordinates of the center of the box
+  /// \param[out] theDimensions dimensions of the box
+  EXCHANGEPLUGIN_EXPORT std::vector<double> computeBox(FeaturePtr theFeature);
+}
+
+#endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
index 83b9aba4d627ce67e2b655512c2131e9fb49763e..b36da145f949db7348467fd5b4f834a2a5b49ba4 100644 (file)
         </radiobox>
       </groupbox >
     </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 title">
+      </stringvalue>
+      <stringvalue id="root_name_file"
+                   label="Name file export"
+                   placeholder="Please input the name of file export">
+      </stringvalue>
+      <shape_selector id="root_main_object"
+                      icon=""
+                      label="Main object"
+                      tooltip="Select solid object"
+                      shape_types="solids"
+                      default=""
+                      geometrical_selection="true">
+        <validator id="GeomValidators_ShapeType" parameters="solid"/>
+      </shape_selector>
+      <file_selector id="mat_file" title="Materials file" path="">
+      </file_selector>
+    </case>
   </switch>
 </source>
index 4073754d517e261a0e3c563ebaa8e00759461851..de027193c591a36daf7cb85c8ba065b23197ee74 100644 (file)
@@ -92,6 +92,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_Defeaturing.h
     GeomAlgoAPI_BoundingBox.h
     GeomAlgoAPI_Tube.h
+    GeomAlgoAPI_ROOTExport.h
 )
 
 SET(PROJECT_SOURCES
@@ -163,6 +164,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_Defeaturing.cpp
     GeomAlgoAPI_BoundingBox.cpp
     GeomAlgoAPI_Tube.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..de4214a
--- /dev/null
@@ -0,0 +1,122 @@
+// Copyright (C) 2014-2021  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>
+#include <iostream>
+
+#include <map>
+#include <vector>
+
+//=================================================================================================
+static std::string doubleToString(const double& theValue)
+{
+  std::ostringstream str;
+  str << theValue;
+  return str.str();
+}
+
+//=================================================================================================
+GeomAlgoAPI_ROOTExport::GeomAlgoAPI_ROOTExport(const std::string& theFileName)
+{
+  myFileName = theFileName;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildHead(const std::string& theMethodName, const std::string& theName,
+                                       const std::string& theTitle)
+{
+  myContent << "void " << theMethodName << "() {" << std::endl;
+  myContent << "gSystem->Load(\"libGeom\");" << std::endl;
+  myContent << "TGeoManager *geom = new TGeoManager(\"" << theName;
+  myContent << "\",\"" << theTitle  << "\");" << std::endl;
+  myContent << std::endl;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildEnd(const std::string theSolidName,
+                                      const std::string theExportName)
+{
+  myContent << "// ####################################" << std::endl;
+  myContent << "geom->SetTopVolume("  << theSolidName << ");" << std::endl;
+  myContent << "geom->CloseGeometry();" << std::endl;
+  myContent << theSolidName + "->SetVisContainers(kTRUE);" << std::endl;
+  myContent << "geom->SetTopVisible(kTRUE);" << std::endl;
+  myContent << "geom->Export(\"" + theExportName + "\");" << std::endl;
+  myContent << "geom->CheckOverlaps(0.0001);" << std::endl;
+  myContent << "geom->PrintOverlaps();" << std::endl;
+  myContent << theSolidName + "->Draw();" << std::endl;
+  myContent << "}" << std::endl;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildMaterialsMedias(
+    const std::map<std::string, std::vector<std::string> > theMaterials,
+    const std::map<std::string, std::vector<std::string> > theMedias)
+{
+  const std::map<std::string, std::vector<std::string> >::const_iterator
+     anItMat = theMaterials.begin(), aLastMat = theMaterials.end();
+  for(; anItMat != aLastMat; anItMat++) {
+    std::vector<std::string> aValues = anItMat->second;
+    myContent << "TGeoMaterial *" << anItMat->first << " = new TGeoMaterial(\"" << aValues[1] <<
+              "\"," << aValues[2] << "," << aValues[3] << "," << aValues[4] << ");" << std::endl;
+  }
+
+  const std::map<std::string, std::vector<std::string> >::const_iterator
+     anItMed = theMedias.begin(), aLastMed = theMedias.end();
+  for(; anItMed != aLastMed; anItMed++) {
+    std::vector<std::string> aValues = anItMed->second;
+    myContent << "TGeoMedium *" << anItMed->first << " = new TGeoMedium(\"" << aValues[1] <<
+              "\"," << aValues[2] << "," << aValues[3] << ");" << std::endl;
+  }
+  myContent << std::endl;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildBox(const std::wstring& theObjectName,
+                                      const std::vector<double> theCenterDims)
+{
+  std::string anObjectName(theObjectName.begin(), theObjectName.end());
+
+  myContent << "Double_t point_" << anObjectName << "[3] = {";
+  myContent << doubleToString(theCenterDims[0]) << "," << doubleToString(theCenterDims[1]) << ",";
+  myContent << (theCenterDims[2]) << "};" << std::endl;
+
+  myContent << "TGeoBBox *" << anObjectName << " = new TGeoBBox(\"";
+  myContent << anObjectName << "\",";
+  myContent << doubleToString(theCenterDims[3]) << "," << doubleToString(theCenterDims[4]) << ",";
+  myContent << doubleToString(theCenterDims[5]) << ",point_";
+  myContent << anObjectName << ");" << std::endl << std::endl;
+}
+
+//=================================================================================================
+bool GeomAlgoAPI_ROOTExport::write()
+{
+  std::ofstream aFile;
+  OSD_OpenStream(aFile, myFileName.c_str(), std::ofstream::out);
+  if (!aFile.is_open())
+    return false;
+
+  aFile << myContent.str() << 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..f300e9e
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2014-2021  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 <sstream>
+#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 the end of file
+  GEOMALGOAPI_EXPORT void buildEnd(const std::string theSolidName,
+                                   const std::string theExportName);
+
+  /// Build the materials ans mediums
+  GEOMALGOAPI_EXPORT void buildMaterialsMedias(
+    const std::map<std::string, std::vector<std::string> > theMaterials,
+    const std::map<std::string, std::vector<std::string> > theMedias);
+
+  /// Build box
+  GEOMALGOAPI_EXPORT void buildBox(const std::wstring& theObjectName,
+                                   const std::vector<double> theCenterDims);
+
+  /// Write the file
+  GEOMALGOAPI_EXPORT bool write();
+
+ private:
+  std::string myFileName; /// File name for materials and medias
+  std::ostringstream myContent; /// X coordinate of the center to create a box.
+};
+
+#endif // GEOMALGOAPI_ROOTEXPORT_H_
index 3e274917c286cfa01b0cfcbac596565dba4e1b5e..26db05d57efa2fbbf5f3d47e1229fd6621ca7c7b 100755 (executable)
Binary files a/src/PrimitivesPlugin/doc/images/Tube_button.png and b/src/PrimitivesPlugin/doc/images/Tube_button.png differ
index 3e274917c286cfa01b0cfcbac596565dba4e1b5e..26db05d57efa2fbbf5f3d47e1229fd6621ca7c7b 100755 (executable)
Binary files a/src/PrimitivesPlugin/icons/tube.png and b/src/PrimitivesPlugin/icons/tube.png differ