]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
fix : Add compounds to export widget
authorNicolas RECHATIN <nicolas.rechatin@cea.fr>
Thu, 26 Jan 2023 11:21:00 +0000 (12:21 +0100)
committerNicolas RECHATIN <nicolas.rechatin@cea.fr>
Wed, 8 Mar 2023 10:09:26 +0000 (11:09 +0100)
src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.h
src/ExchangePlugin/export_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h

index ed21a8928e3b6b8618174867c1b4b0b4ba682643..4ffa1aa412aa5f04c625a8aac6f80ecd3dd417f0 100755 (executable)
@@ -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/FeaturesPlugin
                     ${PROJECT_SOURCE_DIR}/src/OperaPlugin
                     ${OpenCASCADE_INCLUDE_DIR}
 )
index fbfddf29deb565e1546c39dbbfdc45840ef0be25..4e202d44941a6e0dc430d68bb663694ca8357309 100644 (file)
@@ -678,6 +678,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string &theFileName)
     // LCOV_EXCL_STOP
 }
 
+#include <iostream>
+
 void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
 {
     // Get data from feature
@@ -701,10 +703,13 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
     // readFileMat(aFileMat, aMaterials, aMedias);
     // anAlgo->buildMaterialsMedias(aMaterials, aMedias);
 
+    // Handling data
+    std::list<std::wstring> aListOfVolumes;
+    std::map<std::string, std::vector <std::array<std::string, 2>>> aCopyData;
+
     // Add feature in the file
     std::list<FeaturePtr> aFeatures = document()->allFeatures();
     std::list<FeaturePtr>::iterator itFeature = aFeatures.begin();
-    std::vector<std::wstring> aListNamesOfFeatures;
     std::map<std::wstring, std::string> aMapFeauturesObject;
     int aMediumIndex = 0;
     for (; itFeature != aFeatures.end(); ++itFeature)
@@ -716,8 +721,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
             aFeatureDimensions = ExchangePlugin_ExportRoot::computeBox(aFeature);
             std::wstring anObjectName = aFeature->firstResult()->data()->name();
             anAlgo->buildBox(anObjectName, aFeatureDimensions);
-            aListNamesOfFeatures.push_back(anObjectName);
-            aListNamesOfFeatures.push_back(aFeature->data()->name());
         }
         else if (aFeature->getKind() == "Cylinder")
         {
@@ -725,8 +728,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
             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")
         {
@@ -734,17 +735,42 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
             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());
+
+            // Add volume to known ones
+            aListOfVolumes.push_back(anObjectName);
         }
         else if (aFeature->getKind() == "AddNode")
         {
-            std::map<std::string, std::string> aFeatureDimensions;
+            std::map<std::string, std::wstring> aFeatureDimensions;
             aFeatureDimensions = ExchangePlugin_ExportRoot::computeAddNode(aFeature);
             std::wstring anObjectName = aFeature->firstResult()->data()->name();
-            anAlgo->buildAddNode(anObjectName, aFeatureDimensions);
-            aListNamesOfFeatures.push_back(anObjectName);
-            aListNamesOfFeatures.push_back(aFeature->data()->name());
+
+            //Filter copied volumes
+            std::list<std::wstring>::iterator anIter = std::find(aListOfVolumes.begin(), aListOfVolumes.end(), aFeatureDimensions["tool"]);
+            if (anIter != aListOfVolumes.end())
+                anAlgo->buildAddNode(aFeatureDimensions, aCopyData);
+        }
+        else if (aFeature->getKind() == "Copy")
+        {
+            std::map<std::string, std::vector<std::array<std::string, 2>>> aFeatureDimensions;
+            aFeatureDimensions = ExchangePlugin_ExportRoot::computeCopy(aFeature);
+            aCopyData.insert(aFeatureDimensions.begin(), aFeatureDimensions.end());
+        }
+        else if (aFeature->getKind() == "Translation")
+        {
+            std::map<std::string, std::string> aFeatureDimensions;
+            aFeatureDimensions = ExchangePlugin_ExportRoot::computeTranslation(aFeature);
+            if (aFeatureDimensions.size())
+            {
+                std::map<std::string, std::string>::iterator it;
+
+                for (std::map<std::string, std::string>::iterator it = aFeatureDimensions.begin(); it != aFeatureDimensions.end(); it++)
+                    for (auto jt = aCopyData.begin(); jt != aCopyData.end(); jt++)
+                        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;}
         }
     }
 
index 86e762345227223104834e778071924091ff1559..172eaa236148dd3d242ec2fb46e6ab14e0c2da7f 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include <FeaturesPlugin_Copy.h>
+#include <FeaturesPlugin_Translation.h>
+
 #include <PrimitivesPlugin_Box.h>
 #include <PrimitivesPlugin_Cylinder.h>
+
 #include <OperaPlugin_Volume.h>
 #include <OperaPlugin_AddNode.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 
 #include <string>
 #include <iostream>
+#include <iomanip>
+#include <sstream>
 
 #include "math.h"
 
-    namespace ExchangePlugin_ExportRoot
+                                                                                                                   namespace ExchangePlugin_ExportRoot
 {
     //===============================================================================================
     std::map<std::string, double> computeBox(FeaturePtr theFeature)
         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::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name();
         std::map<std::string, std::string> aFeatureDim;
         aFeatureDim["medium"] = aMedium;
 
     }
 
     //===============================================================================================
-    std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature)
+    std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature)
     {
         //Get attributes
         std::string aMedium;
         std::wstring aWToolName = aToolResult ? aToolResult->data()->name() : aToolSelFeature->firstResult()->data()->name();
 
         // Data out
-        std::map<std::string, std::string> aFeatureDim;
+        std::map<std::string, std::wstring> aFeatureDim;
+        aFeatureDim["main"] = aWMainName;
+        aFeatureDim["tool"] = aWToolName;
 
-        std::string aMainName(aWMainName.begin(), aWMainName.end());
-        aFeatureDim["main"] = aMainName;
+        return aFeatureDim;
+    }
 
-        std::string aToolName(aWToolName.begin(), aWToolName.end());
-        aFeatureDim["tool"] = aToolName;
+    //===============================================================================================
+    std::map<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature)
+    {
+        // Initialisation
+        std::map<std::string, std::vector<std::array<std :: string, 2>>> aFeatureDim;
+
+        // Get attributes
+        AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Copy::OBJECTS());
+        int aNumberOfCopies = theFeature->data()->integer(FeaturesPlugin_Copy::NUMBER())->value();
+
+        for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex)
+        {
+            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<std::array<std::string, 2>> aNewBaseCopies;
+            for (int i = 0; i < aNumberOfCopies; i++)
+            {
+                std::array <std::string, 2> aNewCopy = {aSelName + "_" + std::to_string(i+1), "0,0,0"}; //TODO : Get "copy result name"
+                aNewBaseCopies.push_back(aNewCopy);
+            }
+            aFeatureDim[aSelName] = aNewBaseCopies;
+        }
         return aFeatureDim;
     }
 
+    //===============================================================================================
+    std::map<std::string, std::string> computeTranslation(FeaturePtr theFeature)
+    {
+        AttributeStringPtr aMethodTypeAttr = theFeature->data()->string(FeaturesPlugin_Translation::CREATION_METHOD());
+        std::string aMethodType = aMethodTypeAttr->value();
+
+        if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS())
+        {
+            double DX, DY, DZ;
+            std::map<std::string, std::string> aFeatureDim;
+
+            DX = (theFeature->data()->real(FeaturesPlugin_Translation::DX_ID())->value());
+            DY = (theFeature->data()->real(FeaturesPlugin_Translation::DY_ID())->value());
+            DZ = (theFeature->data()->real(FeaturesPlugin_Translation::DZ_ID())->value());
+
+            AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
+            for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex)
+            {
+                //Get new target object name
+                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
+                std::stringstream ss;
+                ss << std::fixed << std::setprecision(3) << DX << "," << DY << "," << DZ;
+                std::string aTrStr = ss.str();
+                aFeatureDim[aSelName] = aTrStr;
+            }
+            return aFeatureDim;
+        }
+        else
+        {
+            std::map<std::string, std::string> 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<std::string, std::string> aFeatureDim;
+            // return aFeatureDim;
+        // }
+        // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS())
+        // {
+        //     std::map<std::string, std::string> aFeatureDim;
+        //     return aFeatureDim;
+        // }
+    }
+
 } // namespace ExchangePlugin_ExportRoot
+
+// std::map<std::string, std::vector<std::array<std : string, 2>>> aCopyData;
index eb77693c4834c342ae2706b748ba3f87ab209a77..705f91a3e9325be6ce118fe48d1beeff1690a5a3 100644 (file)
@@ -29,7 +29,9 @@ namespace ExchangePlugin_ExportRoot
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeBox(FeaturePtr theFeature);
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeCylinder(FeaturePtr theFeature);
   EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeVolume(FeaturePtr theFeature);
-  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeTranslation(FeaturePtr theFeature);
 }
 
 #endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
index b36da145f949db7348467fd5b4f834a2a5b49ba4..097c95556bead70dbebd9f5d6fe21f7fbf41a75a 100644 (file)
                       icon=""
                       label="Main object"
                       tooltip="Select solid object"
-                      shape_types="solids"
+                      shape_types="solids compounds"
                       default=""
                       geometrical_selection="true">
-        <validator id="GeomValidators_ShapeType" parameters="solid"/>
+        <validator id="GeomValidators_ShapeType" parameters="solid compound" />
       </shape_selector>
       <file_selector id="mat_file" title="Materials file" path="">
       </file_selector>
index fef6e62e63e7cbf6f04a0ebe1569651e43f6bb57..154d9dc226ed798c8d6064f8d0c3b8a87ddd1bf5 100644 (file)
@@ -144,18 +144,33 @@ void GeomAlgoAPI_ROOTExport::buildVolume(const std::wstring &theObjectName,
 }
 
 //=================================================================================================
-void GeomAlgoAPI_ROOTExport::buildAddNode(const std::wstring &theObjectName,
-                                          const std::map<std::string, std::string> theFeatureDim)
+void GeomAlgoAPI_ROOTExport::buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
+                                          const std::map<std::string, std::vector<std::array<std::string, 2>>> theCopyData)
 {
-    std::string anObjectName(theObjectName.begin(), theObjectName.end());
+    static int theAddNodeIndex = 0;
+
+    std::string aMainName(theFeatureDim["main"].begin(), theFeatureDim["main"].end());
+    std::string aToolName(theFeatureDim["tool"].begin(), theFeatureDim["tool"].end());
 
     myContent << "\t"
-              << "//Exporting AddNode_" << anObjectName << std::endl;
+              << "//Exporting AddNode " << theAddNodeIndex << std::endl;
 
     myContent << "\t"
-              << theFeatureDim["main"] << "->AddNode(" << theFeatureDim["tool"] << ", 1);"
+              << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ");"
               << std::endl
               << std::endl;
+
+    for (auto const &[key, val] : theCopyData){
+        if (key == aToolName){
+            for (auto& el: val){
+                myContent << "\t"
+                          << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ", "
+                          << "new TGeoTranslation(" << el[1] <<"));"
+                          << std::endl
+                          << std::endl;
+            }
+        }
+    }
 }
 
 //=================================================================================================
index 403f76f5ac3430e4abbbf1c92284ddaa83aeeba9..6851d53d72a16c418f6bcaedbd6d9a4a5bb675e4 100644 (file)
@@ -63,9 +63,8 @@ public:
                                         const int theMediumIndex);
 
     /// Build AddNode
-    GEOMALGOAPI_EXPORT void buildAddNode(const std::wstring &theObjectName,
-                                         const std::map<std::string, std::string> theFeatureDim);
-
+    GEOMALGOAPI_EXPORT void buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
+                                         const std::map<std::string, std::vector<std::array<std::string, 2>>> theCopyData);
     /// Build Medium
     GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName);