]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
feat : ROOT export API working, missing attr
authorNicolas RECHATIN <nicolas.rechatin@cea.fr>
Mon, 9 Oct 2023 08:21:30 +0000 (10:21 +0200)
committerNicolas RECHATIN <nicolas.rechatin@cea.fr>
Mon, 9 Oct 2023 08:21:30 +0000 (10:21 +0200)
src/ExchangeAPI/ExchangeAPI_Export.cpp
src/ExchangeAPI/ExchangeAPI_Export.h
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportFeature.h
src/PythonAPI/model/exchange/__init__.py

index cd38376422766cd8e378a15fcc99f696c2c027f5..b1a276bf334618888198d8ceaeb27ce4cc8427d7 100644 (file)
@@ -53,6 +53,24 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
   apply(); // finish operation to make sure the export is done on the current state of the history
 }
 
+/// Constructor with values for ROOT export.
+ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                              const std::string & theFilePath,
+                              const ModelHighAPI_Selection & theSelectedShape)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+  fillAttribute("ROOT", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID()));
+  fillAttribute("ROOT", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID()));
+  fillAttribute("manager_name", theFeature->string(ExchangePlugin_ExportFeature::ROOT_MANAGER_NAME_ID()));
+  fillAttribute("manager_title", theFeature->string(ExchangePlugin_ExportFeature::ROOT_MANAGER_TITLE_ID()));
+  fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID()));
+  fillAttribute(theSelectedShape, theFeature->selection(ExchangePlugin_ExportFeature::MAIN_OBJECT_ID()));
+  fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::ROOT_FILE_PATH_ID()));
+  theFeature->execute();
+  apply(); // finish operation to make sure the export is done on the current state of the history
+}
+
 // Constructor with values for STL of selected result export.
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                        const std::string & theFilePath,
@@ -254,6 +272,19 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
 }
 
+ExportPtr exportToROOT(const std::shared_ptr<ModelAPI_Document> &thePart,
+                       const std::string &theFilePath,
+                       const ModelHighAPI_Selection &theSelectedShape)
+{
+  apply(); // finish previous operation to make sure all previous operations are done
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    thePart->addFeature(ExchangePlugin_ExportFeature::ID());
+  if (theFilePath.substr(theFilePath.size() - 2) != ".C")
+    aFeature->setError(std::string("Error: the file seems to not have a .C extension file for ROOT. Aborting"));
+  return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape));
+}
+
+
 ExportPtr exportToSTL(const std::shared_ptr<ModelAPI_Document> & thePart,
       const std::string & theFilePath,
       const ModelHighAPI_Selection& theSelectedShape,
index 42b16d12b1af09bf9070d8c9ab45978e95e2c271..0c5f68aa8fac3a9e408efa5927f0d23279d3cd8e 100644 (file)
@@ -53,6 +53,12 @@ public:
                               const std::string & theAuthor = std::string(),
                               const std::string & theGeometryName = std::string());
 
+  /// Constructor with values for ROOT export.
+  EXCHANGEAPI_EXPORT
+  explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature> &theFeature,
+                              const std::string &theFilePath,
+                              const ModelHighAPI_Selection &theSelectedShape);
+
   /// Constructor with values for STL of selected result export.
   EXCHANGEAPI_EXPORT
     explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
@@ -82,39 +88,50 @@ public:
   EXCHANGEAPI_EXPORT
   virtual ~ExchangeAPI_Export();
 
-  INTERFACE_15(ExchangePlugin_ExportFeature::ID(),
-             exportType, ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
-             ModelAPI_AttributeString, /** ExportType */,
-             filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(),
-             ModelAPI_AttributeString, /** file path */,
-             xaoFilePath, ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
-             ModelAPI_AttributeString, /** xao_file_path */,
-             fileFormat, ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
-             ModelAPI_AttributeString, /** file format */,
-             selectionList, ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
-             ModelAPI_AttributeString, /** selection list */,
-             xaoAuthor, ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
-             ModelAPI_AttributeString, /** xao author */,
-             xaoGeometryName, ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
-             ModelAPI_AttributeString, /** xao geometry name */,
-             stlFilePath, ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
-             ModelAPI_AttributeString, /** stl_file_path */,
-             stlobjectselected, ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
-             ModelAPI_AttributeSelection, /** Object selected to export in stl file*/,
-             stldeflectionType, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
-             ModelAPI_AttributeString, /** Type of the defelection */,
-             stlrelative, ExchangePlugin_ExportFeature::STL_RELATIVE(),
-             ModelAPI_AttributeDouble, /** Relative*/,
-             stlabsolute, ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
-             ModelAPI_AttributeDouble, /** Absolute */,
-             stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
-             ModelAPI_AttributeString, /** Type of the stl file*/,
-             stldeflectionTypeabsolute,
-                      ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(),
-             ModelAPI_AttributeString, /** Type of the defelection */,
-             stldeflectionTyperelative,
-                      ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(),
-             ModelAPI_AttributeString, /** Type of the defelection */)
+  INTERFACE_20(ExchangePlugin_ExportFeature::ID(),
+               exportType, ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
+               ModelAPI_AttributeString, /** ExportType */,
+               filePath, ExchangePlugin_ExportFeature::FILE_PATH_ID(),
+               ModelAPI_AttributeString, /** file path */,
+               xaoFilePath, ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
+               ModelAPI_AttributeString, /** xao_file_path */,
+               fileFormat, ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
+               ModelAPI_AttributeString, /** file format */,
+               selectionList, ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
+               ModelAPI_AttributeString, /** selection list */,
+               xaoAuthor, ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
+               ModelAPI_AttributeString, /** xao author */,
+               xaoGeometryName, ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
+               ModelAPI_AttributeString, /** xao geometry name */,
+               rootFilePath, ExchangePlugin_ExportFeature::ROOT_FILE_PATH_ID(),
+               ModelAPI_AttributeString, /** root_file_path */,
+               rootManagerName, ExchangePlugin_ExportFeature::ROOT_MANAGER_NAME_ID(),
+               ModelAPI_AttributeString, /** root manager name */,
+               rootManagerTitle, ExchangePlugin_ExportFeature::ROOT_MANAGER_TITLE_ID(),
+               ModelAPI_AttributeString, /** root manager title */,
+               rootNameFile, ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID(),
+               ModelAPI_AttributeString, /** root name file */,
+               rootMainObject, ExchangePlugin_ExportFeature::MAIN_OBJECT_ID(),
+               ModelAPI_AttributeSelection, /** root main object */,
+               stlFilePath, ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
+               ModelAPI_AttributeString, /** stl_file_path */,
+               stlobjectselected, ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
+               ModelAPI_AttributeSelection, /** Object selected to export in stl file*/,
+               stldeflectionType, ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
+               ModelAPI_AttributeString, /** Type of the defelection */,
+               stlrelative, ExchangePlugin_ExportFeature::STL_RELATIVE(),
+               ModelAPI_AttributeDouble, /** Relative*/,
+               stlabsolute, ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
+               ModelAPI_AttributeDouble, /** Absolute */,
+               stlfileType, ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
+               ModelAPI_AttributeString, /** Type of the stl file*/,
+               stldeflectionTypeabsolute,
+               ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_ABSOLUTE(),
+               ModelAPI_AttributeString, /** Type of the defelection */,
+               stldeflectionTyperelative,
+               ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE_RELATIVE(),
+               ModelAPI_AttributeString,
+               /** Type of the defelection */)
 
   /// Dump wrapped feature
   EXCHANGEAPI_EXPORT
@@ -164,6 +181,13 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
   const std::string & theAuthor = std::string(),
   const std::string & theGeometryName = std::string());
 
+/**\ingroup CPPHighAPI
+ * \brief Exports to XAO file all results of the current document
+ */
+EXCHANGEAPI_EXPORT
+ExportPtr exportToROOT(const std::shared_ptr<ModelAPI_Document> &thePart,
+                       const std::string &theFilePath,
+                       const ModelHighAPI_Selection &theSelectedShape);
 
 /** \ingroup CPPHighAPI
  *  \brief Export selected features or the whole part to the binary file.
index 52cb79909c74afca961d392c06536589b1f83a6f..685d3f96f4c59116da3c1b55c55963211333d0c1 100644 (file)
@@ -683,7 +683,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     // Get data from feature
     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;
 
@@ -695,12 +694,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     // Create the head of file
     anAlgo->buildHead(listNames.front(), aName, aTitle);
 
-    // TODO : Use material files for media list
-    // 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);
-
     // Handling data
     std::list<std::string> aListOfMedias;
 
@@ -760,9 +753,9 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     }
 
     // Create the end of files
-    std::string aExportFileName = string(ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID())->value();
-    AttributeSelectionPtr anObjectAttr = selection(MAIN_OBJECT_ID());
+    AttributeSelectionPtr anObjectAttr = selection(ExchangePlugin_ExportFeature::MAIN_OBJECT_ID());
     aFeature = anObjectAttr->contextFeature();
+
     std::string aNameShape = "";
     if (aFeature.get())
         aNameShape = Locale::Convert::toString(aFeature->firstResult()->data()->name());
@@ -773,6 +766,7 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     }
 
     // Create the end of file
+    std::string aExportFileName = string(ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID())->value();
     anAlgo->buildEnd(aNameShape, aExportFileName);
 
     // Create the file with the content
index 4f2a141b1c887e12657b8312058d667d2c0843b9..2804f68c0fb56c8bfcfd925760cf8cd90aa01320 100644 (file)
@@ -156,13 +156,13 @@ public:
     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
+  /// attribute name of author for ROOT 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
+  /// attribute name of geometry name for ROOT format
   inline static const std::string& ROOT_MANAGER_TITLE_ID()
   {
     static const std::string MY_ROOT_MANAGER_TITLE_ID("root_manager_title");
index 4ca8d345a2ab7e466014b08976c869dd048d8d77..93bfa74860352b57b52c06c44d57cd752561a8d1 100644 (file)
@@ -19,7 +19,7 @@
 """Package for Exchange plugin for the Parametric Geometry API of the Modeler.
 """
 
-from ExchangeAPI import addImport, addImportSTEP, exportToFile, exportToXAO, exportToSTL
+from ExchangeAPI import addImport, addImportSTEP, exportToFile, exportToXAO, exportToSTL, exportToROOT
 from ExchangeAPI import exportPart, importPart, addImportImage
 
 from .tools import *