]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
WIP : Export for Volume of Box and Cylinder
authorNicolas RECHATIN <nicolas.rechatin@cea.fr>
Tue, 10 Jan 2023 15:01:51 +0000 (16:01 +0100)
committerNicolas RECHATIN <nicolas.rechatin@cea.fr>
Tue, 10 Jan 2023 15:01:51 +0000 (16:01 +0100)
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.h
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h

index 3dc9bd5f5c7277e4aaca9be2032f9a0b7e186614..ed21a8928e3b6b8618174867c1b4b0b4ba682643 100755 (executable)
@@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
                     ${QT_INCLUDES}
                     ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
+                    ${PROJECT_SOURCE_DIR}/src/OperaPlugin
                     ${OpenCASCADE_INCLUDE_DIR}
 )
 
index 95ac37d45d9965c47f0c13151ba3e5494a8441eb..51f63021d004caebbcca361bb58afd45c7943611 100644 (file)
@@ -706,12 +706,13 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     std::list<FeaturePtr>::iterator itFeature = aFeatures.begin();
     std::vector<std::wstring> aListNamesOfFeatures;
     std::map<std::wstring, std::string> aMapFeauturesObject;
+    int aMediumIndex = 0;
     for (; itFeature != aFeatures.end(); ++itFeature)
     {
         aFeature = *itFeature;
-        std::map<std::string, double> aFeatureDimensions;
         if (aFeature->getKind() == "Box")
         {
+            std::map<std::string, double> aFeatureDimensions;
             aFeatureDimensions = ExchangePlugin_ExportRoot::computeBox(aFeature);
             std::wstring anObjectName = aFeature->firstResult()->data()->name();
             anAlgo->buildBox(anObjectName, aFeatureDimensions);
@@ -720,12 +721,22 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
         }
         else if (aFeature->getKind() == "Cylinder")
         {
+            std::map<std::string, double> aFeatureDimensions;
             aFeatureDimensions = ExchangePlugin_ExportRoot::computeCylinder(aFeature);
             std::wstring anObjectName = aFeature->firstResult()->data()->name();
             anAlgo->buildTube(anObjectName, aFeatureDimensions);
             aListNamesOfFeatures.push_back(anObjectName);
             aListNamesOfFeatures.push_back(aFeature->data()->name());
         }
+        else if (aFeature->getKind() == "Volume")
+        {
+            std::map<std::string, std::string> aFeatureDimensions;
+            aFeatureDimensions = ExchangePlugin_ExportRoot::computeVolume(aFeature);
+            std::wstring anObjectName = aFeature->firstResult()->data()->name();
+            anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex);
+            aListNamesOfFeatures.push_back(anObjectName);
+            aListNamesOfFeatures.push_back(aFeature->data()->name());
+        }
     }
 
     // Create the end of files
index 65f7b301024b114b9600593fff1d480f965d6cd2..9066ee8cd495fb665ae856039bb137c25b00827d 100644 (file)
 
 #include <PrimitivesPlugin_Box.h>
 #include <PrimitivesPlugin_Cylinder.h>
+#include <OperaPlugin_Volume.h>
+
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
 #include <string>
 #include <iostream>
 
 #include "math.h"
 
-namespace ExchangePlugin_ExportRoot
+    namespace ExchangePlugin_ExportRoot
 {
     //===============================================================================================
     std::map<std::string, double> computeBox(FeaturePtr theFeature)
@@ -105,9 +107,6 @@ namespace ExchangePlugin_ExportRoot
     //===============================================================================================
     std::map<std::string, double> computeCylinder(FeaturePtr theFeature)
     {
-        std::string aMethodName =
-            theFeature->data()->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value();
-
         double radius, halfdz;
         radius = (theFeature->data()->real(PrimitivesPlugin_Cylinder::RADIUS_ID())->value());
         halfdz = (theFeature->data()->real(PrimitivesPlugin_Cylinder::HEIGHT_ID())->value()) / 2;
@@ -120,4 +119,34 @@ namespace ExchangePlugin_ExportRoot
         return aFeatureDim;
     }
 
+    //===============================================================================================
+    std::map<std::string, std::string> computeVolume(FeaturePtr theFeature)
+    {
+        std::string aMedium;
+
+        //Get attributes
+        aMedium = (theFeature->data()->string(OperaPlugin_Volume::MEDIUM_ID())->value());
+        AttributeSelectionPtr aSel = theFeature->data()->selectionList(OperaPlugin_Volume::OBJECTS_LIST_ID())->value(0);
+
+        //Get feature
+        ResultPtr aResult = aSel->context();
+        FeaturePtr aSelFeature = aResult->document()->feature(aResult);
+        std::string aKind = aSelFeature->getKind();
+
+        // Debug data
+        std::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name();
+        std::cout << "The volume medium is : " << aMedium << std::endl;
+        std::cout << "Feature kind is : " << aKind << std::endl;
+        std::wcout << "Feature result name is : " << aWShapeName << std::endl;
+
+        //Data out
+        std::map<std::string, std::string> aFeatureDim;
+        aFeatureDim["medium"] = aMedium;
+
+        std::string aShapeName(aWShapeName.begin(), aWShapeName.end());
+        aFeatureDim["shape"] = aShapeName;
+
+        return aFeatureDim;
+    }
+
 } // namespace ExchangePlugin_ExportRoot
index c35a2d9ffcccbc4b14d82c417ab2fe003191f52f..40c0b02d1b0458811ff1b8b98044671db0b48e7a 100644 (file)
@@ -28,6 +28,7 @@ namespace ExchangePlugin_ExportRoot
   /// \param[out] theDimensions dimensions of the box
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeBox(FeaturePtr theFeature);
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeCylinder(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeVolume(FeaturePtr theFeature);
 }
 
 #endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
index 7b670bb8de126b44a65b5c4905d996458c3707a3..e3bc1d2943fa62cc05426b9b207846e6061f188d 100644 (file)
@@ -49,15 +49,29 @@ void GeomAlgoAPI_ROOTExport::buildHead(const std::string &theMethodName, const s
               << "{" << std::endl
               << std::endl;
 
+    myContent << "\t// ############## HEADER ##############" << std::endl;
     myContent << "\t"
               << "TGeoManager *geom = new TGeoManager(\""
               << theName << "\",\""
               << theTitle << "\");" << std::endl;
 
+    // TGeoMaterial *matDummy = new TGeoMaterial("Dummy", 0, 0, 0);
+    myContent << "\t"
+              << "TGeoMaterial *matDummy = new TGeoMaterial(\" Dummy\", 0, 0, 0);"
+              << std::endl;
+
     myContent << "\t"
               << "// ####################################" << std::endl;
 }
 
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::addMedium(const std::string theMediumName)
+{
+    myContent << "\t"
+              << "TGeoMedium *" << theMediumName
+              << " = new TGeoMedium(\"" << theMediumName
+              << "\", 1, matDummy);" << std::endl;
+}
 //=================================================================================================
 void GeomAlgoAPI_ROOTExport::buildBox(const std::wstring &theObjectName,
                                       const std::map<std::string, double> theFeatureDim)
@@ -68,18 +82,18 @@ void GeomAlgoAPI_ROOTExport::buildBox(const std::wstring &theObjectName,
               << "//Exporting " << anObjectName << std::endl;
 
     myContent << "\t"
-              << "Double_t point_" << anObjectName << "[3] = {"
-              << doubleToString(theFeatureDim["OX"]) << ","
-              << doubleToString(theFeatureDim["OY"]) << ","
-              << doubleToString(theFeatureDim["OZ"]) << "}" << std::endl;
+              << "Double_t origin_" << anObjectName << "[3] = {"
+              << doubleToString(theFeatureDim["OX"]) << ", "
+              << doubleToString(theFeatureDim["OY"]) << ", "
+              << doubleToString(theFeatureDim["OZ"]) << "};" << std::endl;
 
     myContent << "\t"
               << "TGeoBBox *" << anObjectName << " = new TGeoBBox(\""
-              << anObjectName << "\","
-              << doubleToString(theFeatureDim["DX"]) << ","
-              << doubleToString(theFeatureDim["DY"]) << ","
-              << doubleToString(theFeatureDim["DZ"]) << ","
-              << "point_" << anObjectName << ");" << std::endl
+              << anObjectName << "\", "
+              << doubleToString(theFeatureDim["DX"]) << ", "
+              << doubleToString(theFeatureDim["DY"]) << ", "
+              << doubleToString(theFeatureDim["DZ"]) << ", "
+              << "origin_" << anObjectName << ");" << std::endl
               << std::endl;
 }
 
@@ -87,7 +101,6 @@ void GeomAlgoAPI_ROOTExport::buildBox(const std::wstring &theObjectName,
 void GeomAlgoAPI_ROOTExport::buildTube(const std::wstring &theObjectName,
                                        const std::map<std::string, double> theFeatureDim)
 {
-    // TGeoTube * fuelShape = new TGeoTube("fuelShape",0.,fuelRadius,halfdz);
     std::string anObjectName(theObjectName.begin(), theObjectName.end());
 
     myContent << "\t"
@@ -95,21 +108,49 @@ void GeomAlgoAPI_ROOTExport::buildTube(const std::wstring &theObjectName,
 
     myContent << "\t"
               << "TGeoTube *" << anObjectName << " = new TGeoTube(\""
-              << anObjectName << "\","
+              << anObjectName << "\", "
               << "0."
-              << ","
-              << doubleToString(theFeatureDim["radius"]) << ","
+              << ", "
+              << doubleToString(theFeatureDim["radius"]) << ", "
               << doubleToString(theFeatureDim["halfdz"]) << ");"
               << std::endl
               << std::endl;
 }
 
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildVolume(const std::wstring &theObjectName,
+                                         const std::map<std::string, std::string> theFeatureDim,
+                                         const int theMediumIndex)
+{
+    std::string anObjectName(theObjectName.begin(), theObjectName.end());
+
+    myContent << "\t"
+              << "//Exporting " << anObjectName << std::endl;
+
+    myContent << "\t"
+              << "TGeoMedium *" << theFeatureDim["medium"] << " = new TGeoMedium(\""
+              << theFeatureDim["medium"] << "\", "
+              << theMediumIndex << ", "
+              << "matDummy);"
+              << std::endl;
+
+    myContent << "\t"
+              << "TGeoVolume *" << anObjectName << " = new TGeoVolume(\""
+              << anObjectName << "\", "
+              << theFeatureDim["shape"] << ", "
+              << theFeatureDim["medium"] << ");"
+              << std::endl
+              << std::endl;
+}
+
 //=================================================================================================
 void GeomAlgoAPI_ROOTExport::buildEnd(const std::string theSolidName,
                                       const std::string theExportName)
 {
     myContent << "\t"
-              << "// ####################################" << std::endl;
+              << "// ####################################" << std::endl
+              << "\t// ############## FOOTER ##############" << std::endl;
+
     myContent << "\t"
               << "geom->SetTopVolume(" << theSolidName << ");" << std::endl;
     myContent << "\t"
index 1e3d8bf393070de747b4afd4277917f46a9375bf..c4751517ea763a70d582fd490960402ef021306b 100644 (file)
@@ -57,6 +57,14 @@ public:
     GEOMALGOAPI_EXPORT void buildTube(const std::wstring &theObjectName,
                                       const std::map<std::string, double> theFeatureDim);
 
+    /// Build Volume
+    GEOMALGOAPI_EXPORT void buildVolume(const std::wstring &theObjectName,
+                                        const std::map<std::string, std::string> theFeatureDim,
+                                        const int theMediumIndex);
+
+    /// Build Medium
+    GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName);
+
     /// Write the file
     GEOMALGOAPI_EXPORT bool write();