From: Nicolas RECHATIN Date: Tue, 10 Jan 2023 15:01:51 +0000 (+0100) Subject: WIP : Export for Volume of Box and Cylinder X-Git-Tag: OPERA_v0.6-s990~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=defa2310ce4d881376fb7c3a29a5f63d4b65f5df;p=modules%2Fshaper.git WIP : Export for Volume of Box and Cylinder --- diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index 3dc9bd5f5..ed21a8928 100755 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -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} ) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 95ac37d45..51f63021d 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -706,12 +706,13 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) std::list::iterator itFeature = aFeatures.begin(); std::vector aListNamesOfFeatures; std::map aMapFeauturesObject; + int aMediumIndex = 0; for (; itFeature != aFeatures.end(); ++itFeature) { aFeature = *itFeature; - std::map aFeatureDimensions; if (aFeature->getKind() == "Box") { + std::map 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 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 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 diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp index 65f7b3010..9066ee8cd 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp @@ -19,19 +19,21 @@ #include #include +#include + #include #include -#include #include +#include #include #include #include "math.h" -namespace ExchangePlugin_ExportRoot + namespace ExchangePlugin_ExportRoot { //=============================================================================================== std::map computeBox(FeaturePtr theFeature) @@ -105,9 +107,6 @@ namespace ExchangePlugin_ExportRoot //=============================================================================================== std::map 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 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 aFeatureDim; + aFeatureDim["medium"] = aMedium; + + std::string aShapeName(aWShapeName.begin(), aWShapeName.end()); + aFeatureDim["shape"] = aShapeName; + + return aFeatureDim; + } + } // namespace ExchangePlugin_ExportRoot diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h index c35a2d9ff..40c0b02d1 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h @@ -28,6 +28,7 @@ namespace ExchangePlugin_ExportRoot /// \param[out] theDimensions dimensions of the box EXCHANGEPLUGIN_EXPORT std::map computeBox(FeaturePtr theFeature); EXCHANGEPLUGIN_EXPORT std::map computeCylinder(FeaturePtr theFeature); + EXCHANGEPLUGIN_EXPORT std::map computeVolume(FeaturePtr theFeature); } #endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp index 7b670bb8d..e3bc1d294 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp @@ -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 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 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 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" diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h index 1e3d8bf39..c4751517e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h @@ -57,6 +57,14 @@ public: GEOMALGOAPI_EXPORT void buildTube(const std::wstring &theObjectName, const std::map theFeatureDim); + /// Build Volume + GEOMALGOAPI_EXPORT void buildVolume(const std::wstring &theObjectName, + const std::map theFeatureDim, + const int theMediumIndex); + + /// Build Medium + GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName); + /// Write the file GEOMALGOAPI_EXPORT bool write();