From 06ac13bbf6bb5bec138d41f06f83d142eb9b6aeb Mon Sep 17 00:00:00 2001 From: Nicolas RECHATIN Date: Wed, 8 Mar 2023 11:07:46 +0100 Subject: [PATCH] feat : Export ROOT v1.0 --- .../ExchangePlugin_ExportFeature.cpp | 22 +++++++------ .../ExchangePlugin_ExportRoot.cpp | 31 ------------------- src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp | 18 ++++++----- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 4e202d449..a00b1b113 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -678,8 +678,6 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string &theFileName) // LCOV_EXCL_STOP } -#include - void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) { // Get data from feature @@ -697,20 +695,20 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) // Create the head of file anAlgo->buildHead(listNames.front(), aName, aTitle); - // // Materials and mediums + // TODO : Use material files for media list // std::map > aMaterials; // std::map > aMedias; // readFileMat(aFileMat, aMaterials, aMedias); // anAlgo->buildMaterialsMedias(aMaterials, aMedias); // Handling data + std::list aListOfMedias; std::list aListOfVolumes; std::map>> aCopyData; // Add feature in the file std::list aFeatures = document()->allFeatures(); std::list::iterator itFeature = aFeatures.begin(); - std::map aMapFeauturesObject; int aMediumIndex = 0; for (; itFeature != aFeatures.end(); ++itFeature) { @@ -734,7 +732,16 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) std::map aFeatureDimensions; aFeatureDimensions = ExchangePlugin_ExportRoot::computeVolume(aFeature); std::wstring anObjectName = aFeature->firstResult()->data()->name(); - anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex); + + //Filter on already created medias + std::list::iterator anIter = std::find(aListOfMedias.begin(), aListOfMedias.end(), aFeatureDimensions["medium"]); + if (anIter != aListOfMedias.end()) + anAlgo->buildVolume(anObjectName, aFeatureDimensions, -1); + else + { + aListOfMedias.push_back(aFeatureDimensions["medium"]); + anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex); + } // Add volume to known ones aListOfVolumes.push_back(anObjectName); @@ -769,8 +776,7 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) for (int k = 0; k < jt->second.size(); k++ ) if (jt->second[k][0] == it->first) jt->second[k][1] = it->second; - // TODO : Add TR TO ACopyData the AddNode get the TR value - } else {std::cout << "Ignoring translation" << std::endl;} + } else {std::cout << "Ignoring translation" << std::endl;} //Filter translation not on volume or addNode } } @@ -780,9 +786,7 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) aFeature = anObjectAttr->contextFeature(); std::string aNameShape = ""; if (aFeature.get()) - { aNameShape = Locale::Convert::toString(aFeature->firstResult()->data()->name()); - } else { ObjectPtr anObject = anObjectAttr->contextObject(); diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp index 172eaa236..d02c5deaf 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp @@ -33,10 +33,8 @@ #include #include -#include #include #include - #include "math.h" namespace ExchangePlugin_ExportRoot @@ -193,9 +191,6 @@ AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex); ResultPtr aMainResult = aSelection->context(); FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult); - - std::cout << "Copy feature kind is : " << aSelectionFeature->getKind() << std::endl; - std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name(); std::string aSelName(aWSelName.begin(), aWSelName.end()); std::vector> aNewBaseCopies; @@ -231,9 +226,6 @@ AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex); ResultPtr aMainResult = aSelection->context(); FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult); - - std::cout << "Translation feature kind is : " << aSelectionFeature->getKind() << std::endl; - std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name(); std::string aSelName(aWSelName.begin(), aWSelName.end()); //Add it to translated objects @@ -249,29 +241,6 @@ std::map aFeatureDim; return aFeatureDim; } - // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) - // { - // double anAxisOffset; - // AttributeSelectionPtr anAxis; - - // anAxis = theFeature->data()->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); - // anAxisOffset = (theFeature->data()->real(FeaturesPlugin_Translation::DISTANCE_ID())->value()); - - // // Get feature - // ResultPtr aResult = anAxis->context(); - // FeaturePtr anAxisFeature = aResult->document()->feature(aResult); - // std::wstring anAxisName = aResult ? aResult->data()->name() : anAxisFeature->firstResult()->data()->name(); - - // std::map aFeatureDim; - // return aFeatureDim; - // } - // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) - // { - // std::map aFeatureDim; - // return aFeatureDim; - // } } } // namespace ExchangePlugin_ExportRoot - -// std::map>> aCopyData; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp index 154d9dc22..2f18438c8 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp @@ -127,12 +127,15 @@ void GeomAlgoAPI_ROOTExport::buildVolume(const std::wstring &theObjectName, myContent << "\t" << "//Exporting " << anObjectName << std::endl; - myContent << "\t" - << "TGeoMedium *" << theFeatureDim["medium"] << " = new TGeoMedium(\"" - << theFeatureDim["medium"] << "\", " - << theMediumIndex << ", " - << "matDummy);" - << std::endl; + if (theMediumIndex != -1) + { + myContent << "\t" + << "TGeoMedium *" << theFeatureDim["medium"] << " = new TGeoMedium(\"" + << theFeatureDim["medium"] << "\", " + << theMediumIndex << ", " + << "matDummy);" + << std::endl; + } myContent << "\t" << "TGeoVolume *" << anObjectName << " = new TGeoVolume(\"" @@ -157,7 +160,6 @@ void GeomAlgoAPI_ROOTExport::buildAddNode(const std::mapAddNode(" << aToolName << ", " << ++theAddNodeIndex << ");" - << std::endl << std::endl; for (auto const &[key, val] : theCopyData){ @@ -166,11 +168,11 @@ void GeomAlgoAPI_ROOTExport::buildAddNode(const std::mapAddNode(" << aToolName << ", " << ++theAddNodeIndex << ", " << "new TGeoTranslation(" << el[1] <<"));" - << std::endl << std::endl; } } } + myContent << std::endl; } //================================================================================================= -- 2.39.2