]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Adding export ROOT for partition and mult-translation cgt/opera
authorcg246364 <clarisse.genrault@cea.fr>
Mon, 23 Nov 2020 14:20:23 +0000 (15:20 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Mon, 23 Nov 2020 14:20:23 +0000 (15:20 +0100)
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 ea7f8863d0ca6066516bf8e59a732d04f3af88b1..a1c395d053d2539ed209bb0f35fa799de2e34a5b 100644 (file)
@@ -39,6 +39,7 @@
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_XAOExport.h>
 
+//#include <GeomAPI_Ax1.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_Trsf.h>
@@ -646,19 +647,15 @@ 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);
-        
-        //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);
@@ -688,6 +685,19 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName)
           std::cout<<anObjectName<<" et "<<aName<<std::endl;
           aMapFeatureObject[anObjectName]=aName;
         }
+      } else if (aCurFeature->getKind() == "LinearCopy") {
+        std::vector<std::string> aObjNames;
+        double aStep; 
+        int aNb; 
+        std::string anObjectName = aCurFeature->firstResult()->data()->name();
+        std::vector<std::vector<std::string>> aResulNames;
+        std::shared_ptr<GeomAPI_Ax1> anAxis = ExchangePlugin_ExportRoot::computeMultiTranslation(aCurFeature, aObjNames, aResulNames, aStep, aNb);
+        anAlgo->buildMultiTranslation(aObjNames, aResulNames, aStep, aNb, anAxis);
+        for (int i=0; i<aObjNames.size(); i++) {
+          for (int j=0; j<aResulNames[i].size(); j++) {
+            aMapFeatureObject[aResulNames[i][j]]=aObjNames[i];
+          }
+        }
       } else if (aCurFeature->getKind() == "Partition") {
         std::string anObjectName = aCurFeature->firstResult()->data()->name();
         // ToDo dans computePartition
@@ -703,7 +713,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string& theFileName)
           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++;
index 4e8c5202935f67b67c97aa6a8107116815c29320..aeac567a284f763465f55babcd2e075552a23d1b 100644 (file)
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
+
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 
 #include <CollectionPlugin_Group.h>
 #include <ExchangePlugin_Tools.h>
+
+#include <FeaturesPlugin_MultiTranslation.h>
 #include <FeaturesPlugin_Translation.h>
+
 #include <PrimitivesPlugin_Box.h>
 
 #include <fstream>
@@ -61,8 +69,6 @@ void ExchangePlugin_ExportRoot::readFileMat(const std::string theFileMat,
           aData.push_back(anElem);
         }
       }
-      //std::cout<<"aType :: "<<aName<<std::endl;
-      //std::cout<<"aName :: "<<aData[0]<<std::endl;
       if (aName == "mat") {
         aMat[aData[0]] = aData;
       } else if (aName == "medium") {
@@ -74,8 +80,6 @@ void ExchangePlugin_ExportRoot::readFileMat(const std::string theFileMat,
     
     aFile.close();
   }
-  //std::cout<<"Size of aMat :: "<<aMat.size()<<std::endl;
-  //std::cout<<"Size of aMedias :: "<<aMedias.size()<<std::endl;
 }
 
 void ExchangePlugin_ExportRoot::computeBox(FeaturePtr theCurFeature,
@@ -138,10 +142,77 @@ void ExchangePlugin_ExportRoot::computeTranslation(FeaturePtr theCurFeature,
   }
 }
 
+std::shared_ptr<GeomAPI_Ax1>
+ExchangePlugin_ExportRoot::computeMultiTranslation(FeaturePtr theCurFeature,
+                                                   std::vector<std::string>& theObjNames,
+                                                   std::vector<std::vector<std::string>>& theResulNames,
+                                                   double& theStep, int& theNb)
+{
+  std::list<ResultPtr> aResList = theCurFeature->results();
+  std::list<ResultPtr>::const_iterator aIt;
+  for (aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) {
+    std::cout<<(*aIt)->data()->name()<<std::endl;
+    ResultBodyPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultBody>((*aIt));
+    std::cout<<aCompSolid->numberOfSubs()<<std::endl;
+    std::vector<std::string> aVector;
+    for (int i=0; i< aCompSolid->numberOfSubs();i++) {
+      std::cout<<aCompSolid->subResult(i)->data()->name()<<std::endl;
+      aVector.push_back(aCompSolid->subResult(i)->data()->name());
+    }
+    theResulNames.push_back(aVector);
+  }
+  theStep = theCurFeature->data()->real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value();
+  theNb = theCurFeature->data()->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value();
+  AttributeSelectionPtr anObjRef = theCurFeature->data()->
+    selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
+    
+  GeomShapePtr aShape = anObjRef->value();
+  if (!aShape.get()) {
+    if (anObjRef->context().get()) {
+      aShape = anObjRef->context()->shape();
+    }
+  }
+  if (!aShape.get()) {
+    return;
+  }
+
+  GeomEdgePtr anEdge;
+  if (aShape->isEdge())
+  {
+    anEdge = aShape->edge();
+  }
+  else if (aShape->isCompound())
+  {
+    GeomAPI_ShapeIterator anIt(aShape);
+    anEdge = anIt.current()->edge();
+  }
+
+  if (!anEdge.get())
+  {
+    return;
+  }
+
+  std::shared_ptr<GeomAPI_Ax1> anAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                      anEdge->line()->direction()));
+    
+  AttributeSelectionListPtr anObjectsSelList = theCurFeature->data()->
+    selectionList(FeaturesPlugin_MultiTranslation::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();
+    theObjNames.push_back(aName);
+  }
+  
+  return anAxis;
+}
+
 void ExchangePlugin_ExportRoot::computeGroup(FeaturePtr theCurFeature,
                                              std::vector<std::string>& theListNames)
 {
-  //std::cout<<"COMPUTE GROUP"<<std::endl;
   AttributeSelectionListPtr anObjectsSelList =
       theCurFeature->data()->selectionList(CollectionPlugin_Group::LIST_ID());
       
index 66c3a76a91651a42af9a959b1e611e1273a05fc6..b15905f15545940c32cb89c8788ff108302ae1bf 100644 (file)
 #define EXCHANGEPLUGIN_EXPORTROOT_H_
 
 #include <ExchangePlugin.h>
+#include <GeomAPI_Ax1.h>
 #include <ModelAPI_Feature.h>
 
 #include <map>
+#include <vector>
 
 /**
  * \class ExchangePlugin_Tools
@@ -43,6 +45,12 @@ public:
   /// Compute ....
   static void computeTranslation(FeaturePtr theCurFeature, double& DX, double& DY, double& DZ);
   
+  /// Compute ....
+  static std::shared_ptr<GeomAPI_Ax1> computeMultiTranslation(FeaturePtr theCurFeature,
+                                                              std::vector<std::string>& theObjNames,
+                                                              std::vector<std::vector<std::string>>& theResulNames,
+                                                              double& theStep, int& theNb);
+  
   /// Compute ....
   static void computeGroup(FeaturePtr theCurFeature, std::vector<std::string>& theListNames);
 };
index a7868bd0c0d0c013b93699be42c934c9fe8a3ff0..d86132000ea80817db01a65d71baff888dc05161 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <GeomAlgoAPI_ROOTExport.h>
 
+#include <gp_Ax1.hxx>
+
 #include <OSD_OpenFile.hxx>
 
 #include <fstream>
@@ -72,6 +74,29 @@ void GeomAlgoAPI_ROOTExport::buildTranslation(const std::string& theObjectName,
   myContent += "\n";
 }
 
+//=================================================================================================
+void GeomAlgoAPI_ROOTExport::buildMultiTranslation(const std::vector<std::string>& theObjNames,
+                                                   const std::vector<std::vector<std::string>>& theResulNames,
+                                                   const double theStep,
+                                                   const int theNb, 
+                                                   std::shared_ptr<GeomAPI_Ax1> theAxis)
+{
+  const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
+  
+  for (int i=0; i< theResulNames.size(); i++) {
+    std::vector<std::string> aVector = theResulNames[i];
+    for (int j=0; j<aVector.size();j++) {
+      double aDistance = j*theStep;
+      gp_Vec aVec = gp_Vec(anAxis.Direction()) * aDistance;
+      myContent += "TGeoTranslation *" + aVector[j];
+      myContent += " = new TGeoTranslation(\"" + aVector[j] + "\",";
+      myContent += doubleToString(aVec.X()) + "," + doubleToString(aVec.Y()) + ",";
+      myContent += doubleToString(aVec.Z()) + ");\n";
+      myContent += "\n";
+    }
+  }
+}
+
 //=================================================================================================
 void GeomAlgoAPI_ROOTExport::buildPartition(const std::string& theMainName,
                                             const std::string theObjectName,
index 7adf496d5e24baacbdb5814b43521c42482e2af3..ed0c558ef3ff97750ec3fdb00eb7c212b7ef1c74 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <GeomAlgoAPI.h>
 
+#include <GeomAPI_Ax1.h>
+
 #include <map>
 #include <string>
 #include <vector>
@@ -49,6 +51,13 @@ public:
                                            const double theDX, const double theDY,
                                            const double theDZ);
   
+  /// Build translation
+  GEOMALGOAPI_EXPORT void buildMultiTranslation(const std::vector<std::string>& theObjNames,
+                                                const std::vector<std::vector<std::string>>& theResulNames,
+                                                const double theStep,
+                                                const int theNb, 
+                                                std::shared_ptr<GeomAPI_Ax1> theAxis);
+  
   /// Build partition
   GEOMALGOAPI_EXPORT void buildPartition(const std::string& theMainName,
                                          const std::string theObjectName,