]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add export ROOT to Partition (AddNode)
authorcg246364 <clarisse.genrault@cea.fr>
Fri, 13 Nov 2020 14:15:35 +0000 (15:15 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Fri, 13 Nov 2020 14:15:35 +0000 (15:15 +0100)
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h

index ee5cf6be4cabd53608a77e99a736c39f69b33e45..ea7f8863d0ca6066516bf8e59a732d04f3af88b1 100644 (file)
@@ -71,6 +71,9 @@
 #include <ExchangePlugin_Tools.h>
 
 #include <PrimitivesPlugin_Box.h>
+// ToDo : a supprimer
+#include <FeaturesPlugin_Partition.h>
+#include <FeaturesPlugin_Translation.h>
 
 #ifdef WIN32
 # define _separator_ '\\'
@@ -619,6 +622,7 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName)
   std::list<FeaturePtr> theExport = document()->allFeatures();
   std::list<FeaturePtr>::iterator itExport = theExport.begin();
   std::vector<std::string> aListNamesOfFeatures;
+  std::map<std::string,std::string> 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"<<std::endl;
-        std::string anObjectName = aCurFeature->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"<<std::endl;
   itExport = theExport.begin();
   for (; itExport != theExport.end(); ++itExport)
   {
+      std::cout<<"ETRANGE une fois"<<std::endl;
       FeaturePtr aCurFeature = *itExport;
       if (aCurFeature->getKind() == "Group") {
+        std::cout<<"ETRANGE deux fois"<<std::endl;
         std::vector<std::string> 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<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
         for (std::vector<std::string>::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<ModelAPI_AttributeSelection> anObjectAttr =
+            anObjectsSelList->value(anObjectsIndex);
+          ObjectPtr anObject = anObjectAttr->contextObject();
+          std::string aName = anObject->data()->name();
+          std::cout<<anObjectName<<" et "<<aName<<std::endl;
+          aMapFeatureObject[anObjectName]=aName;
+        }
+      } else if (aCurFeature->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<ModelAPI_AttributeSelection> anObjectAttr =
+            anObjectsSelList->value(anObjectsIndex);
+          ObjectPtr anObject = anObjectAttr->contextObject();
+          std::string aName = anObject->data()->name();
+          if (index == 0) {
+            aMainName = aName;
+          } else {
+            std::cout<<aMainName<<"AA  AA "<<aMapFeatureObject[aName]<<" BB  BB "<<aName<<std::endl;
+            anAlgo->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());
index ebab302ddcf94f362bae22eeff10e80d53475535..4e8c5202935f67b67c97aa6a8107116815c29320 100644 (file)
@@ -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();
index 15f8bc79ceef567d8ce2a31ba53b5c20c5194b01..a7868bd0c0d0c013b93699be42c934c9fe8a3ff0 100644 (file)
@@ -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<std::string> 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)
 {
index 3f0f66be6aaece8ff5593f9f72772119da387a14..7adf496d5e24baacbdb5814b43521c42482e2af3 100644 (file)
@@ -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<std::string, std::vector<std::string> > 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<std::string> 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: