From: cg246364 Date: Fri, 13 Nov 2020 14:15:35 +0000 (+0100) Subject: Add export ROOT to Partition (AddNode) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0e8cb13968ed0ceac90e354e487210222394541f;p=modules%2Fshaper.git Add export ROOT to Partition (AddNode) --- diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index ee5cf6be4..ea7f8863d 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -71,6 +71,9 @@ #include #include +// ToDo : a supprimer +#include +#include #ifdef WIN32 # define _separator_ '\\' @@ -619,6 +622,7 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName) std::list theExport = document()->allFeatures(); std::list::iterator itExport = theExport.begin(); std::vector aListNamesOfFeatures; + std::map aMapFeatureObject; for (; itExport != theExport.end(); ++itExport) { FeaturePtr aCurFeature = *itExport; @@ -631,18 +635,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName) anAlgo->buildBox(anObjectName, anOx, anOy, anOz, aDx, aDy, aDz); aListNamesOfFeatures.push_back(anObjectName); aListNamesOfFeatures.push_back(aCurFeature->data()->name()); - } else if (aCurFeature->getKind() == "Translation") { - double aDx, aDy, aDz; - std::string anObjectName = aCurFeature->firstResult()->data()->name(); - ExchangePlugin_ExportRoot::computeTranslation(aCurFeature, aDx, aDy, aDz); - anAlgo->buildTranslation(anObjectName, aDx, aDy, aDz); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aCurFeature->data()->name()); - } else if (aCurFeature->getKind() == "Partition") { - //std::cout<<"ToDo PARTITION"<firstResult()->data()->name(); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aCurFeature->data()->name()); } } @@ -654,11 +646,14 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName) aListMedium.push_back(anIt->first); } + std::cout<<"ETRANGE"<getKind() == "Group") { + std::cout<<"ETRANGE deux fois"< aListNames; std::string anObjectName = aCurFeature->firstResult()->data()->name(); ExchangePlugin_ExportRoot::computeGroup(aCurFeature, aListNames); @@ -666,10 +661,57 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName) //for (std::vector::iterator it = myvector.begin() ; it != myvector.end(); ++it) for (std::vector::iterator it = aListNames.begin(); it != aListNames.end(); it++) { std::string aName = anObjectName + "_" + *it; - anAlgo->BuildVolume(aName, *it, anObjectName, aListMedium); + anAlgo->buildVolume(aName, *it, anObjectName, aListMedium); } } } + + itExport = theExport.begin(); + for (; itExport != theExport.end(); ++itExport) + { + FeaturePtr aCurFeature = *itExport; + if (aCurFeature->getKind() == "Translation") { + double aDx, aDy, aDz; + std::string anObjectName = aCurFeature->firstResult()->data()->name(); + ExchangePlugin_ExportRoot::computeTranslation(aCurFeature, aDx, aDy, aDz); + anAlgo->buildTranslation(anObjectName, aDx, aDy, aDz); + aListNamesOfFeatures.push_back(anObjectName); + aListNamesOfFeatures.push_back(aCurFeature->data()->name()); + // ToDo dans computeTranslation + AttributeSelectionListPtr anObjectsSelList = aCurFeature->data()-> + selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); + for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { + std::shared_ptr anObjectAttr = + anObjectsSelList->value(anObjectsIndex); + ObjectPtr anObject = anObjectAttr->contextObject(); + std::string aName = anObject->data()->name(); + std::cout<getKind() == "Partition") { + std::string anObjectName = aCurFeature->firstResult()->data()->name(); + // ToDo dans computePartition + int index = 0; + std::string aMainName = ""; + AttributeSelectionListPtr anObjectsSelList = aCurFeature->data()-> + selectionList(FeaturesPlugin_Partition::BASE_OBJECTS_ID()); + for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { + std::shared_ptr anObjectAttr = + anObjectsSelList->value(anObjectsIndex); + ObjectPtr anObject = anObjectAttr->contextObject(); + std::string aName = anObject->data()->name(); + if (index == 0) { + aMainName = aName; + } else { + std::cout<buildPartition(aMainName, aMapFeatureObject[aName], aName, index); + } + index++; + } + aListNamesOfFeatures.push_back(anObjectName); + aListNamesOfFeatures.push_back(aCurFeature->data()->name()); + } + } std::string aExportFileName = string(ExchangePlugin_ExportFeature::EXP_NAME_FILE_ID())->value(); AttributeSelectionPtr anObjectAttr = selection(MAIN_OBJECT_ID()); diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp index ebab302dd..4e8c52029 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp @@ -119,7 +119,7 @@ void ExchangePlugin_ExportRoot::computeBox(FeaturePtr theCurFeature, } else if (aMethodName == "BoxByOnePointAndDims") { DX = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DX_ID())->value(); DY = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DY_ID())->value(); - DY = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DZ_ID())->value(); + DZ = theCurFeature->data()->real(PrimitivesPlugin_Box::HALF_DZ_ID())->value(); OX = theCurFeature->data()->real(PrimitivesPlugin_Box::OX_ID())->value(); OY = theCurFeature->data()->real(PrimitivesPlugin_Box::OY_ID())->value(); OZ = theCurFeature->data()->real(PrimitivesPlugin_Box::OZ_ID())->value(); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp index 15f8bc79c..a7868bd0c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp @@ -44,6 +44,7 @@ void GeomAlgoAPI_ROOTExport::buildHead(const std::string& theMethodName, myContent += tmp; tmp = "TGeoManager *geom = new TGeoManager(\"" + theName + "\",\"" + theTitle +"\");\n"; myContent += tmp; + myContent += "\n"; } //================================================================================================= @@ -56,6 +57,7 @@ void GeomAlgoAPI_ROOTExport::buildBox(const std::string& theObjectName, myContent += "TGeoBBox *" + theObjectName + "_tmp = new TGeoBBox(\"" +theObjectName + "_tmp\","; myContent += doubleToString(theDX)+","+doubleToString(theDY)+","+doubleToString(theDZ)+",point_"; myContent += theObjectName + ");\n"; + myContent += "\n"; } //================================================================================================= @@ -64,9 +66,22 @@ void GeomAlgoAPI_ROOTExport::buildTranslation(const std::string& theObjectName, const double theDZ) { myContent += "TGeoTranslation *" + theObjectName; - myContent += "_tmp = new TGeoTranslation(\"" + theObjectName + "_tmp\","; + myContent += " = new TGeoTranslation(\"" + theObjectName + "\","; myContent += doubleToString(theDX) + "," + doubleToString(theDY) + ","; myContent += doubleToString(theDZ) + ");\n"; + myContent += "\n"; +} + +//================================================================================================= +void GeomAlgoAPI_ROOTExport::buildPartition(const std::string& theMainName, + const std::string theObjectName, + const std::string theOperationName, + const int theIndex) +{ + myContent += theMainName + "->AddNode("; + myContent += theObjectName + ", " + intToString(theIndex) + ", "; + myContent += theOperationName + ");\n"; + myContent += "\n"; } //================================================================================================= @@ -89,10 +104,11 @@ void GeomAlgoAPI_ROOTExport::buildMatAndMedium( myContent += "TGeoMedium *" + anIt2->first + " = new TGeoMedium(\""; myContent += aValues[1] + "\"," + aValues[2] + "," + aValues[3] + ") ;\n"; } + myContent += "\n"; } //================================================================================================= -void GeomAlgoAPI_ROOTExport::BuildVolume(const std::string theName, +void GeomAlgoAPI_ROOTExport::buildVolume(const std::string theName, const std::string theGeometryName, const std::string theMediumName, std::vector theListMedium) @@ -102,6 +118,7 @@ void GeomAlgoAPI_ROOTExport::BuildVolume(const std::string theName, if (aFound) { myContent += "TGeoVolume *" + theGeometryName + " = new TGeoVolume(\"" + theName; myContent += "\"," + theGeometryName + "_tmp," + theMediumName + ");\n"; + myContent += "\n"; } } @@ -134,6 +151,14 @@ bool GeomAlgoAPI_ROOTExport::write() return true; } +//================================================================================================= +const std::string GeomAlgoAPI_ROOTExport::intToString(const int& value) +{ + std::ostringstream str; + str << value; + return str.str(); +} + //================================================================================================= const std::string GeomAlgoAPI_ROOTExport::doubleToString(const double& value) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h index 3f0f66be6..7adf496d5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h @@ -48,6 +48,12 @@ public: GEOMALGOAPI_EXPORT void buildTranslation(const std::string& theObjectName, const double theDX, const double theDY, const double theDZ); + + /// Build partition + GEOMALGOAPI_EXPORT void buildPartition(const std::string& theMainName, + const std::string theObjectName, + const std::string theOperationName, + const int theIndex); /// Build mat and medium GEOMALGOAPI_EXPORT void buildMatAndMedium( @@ -55,7 +61,7 @@ public: const std::map > theMedium); /// - GEOMALGOAPI_EXPORT void BuildVolume(const std::string theName, + GEOMALGOAPI_EXPORT void buildVolume(const std::string theName, const std::string theGeometryName, const std::string theMediumName, std::vector theListMedium); @@ -66,6 +72,10 @@ public: /// Write the file GEOMALGOAPI_EXPORT bool write(); + /// + GEOMALGOAPI_EXPORT const std::string intToString(const int& value); + + /// GEOMALGOAPI_EXPORT const std::string doubleToString(const double& value); private: