]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of proposal 3 in the issue #2882 : Groups are not exported to GEOM...
authormpv <mpv@opencascade.com>
Tue, 26 Mar 2019 14:22:14 +0000 (17:22 +0300)
committermpv <mpv@opencascade.com>
Tue, 26 Mar 2019 14:22:14 +0000 (17:22 +0300)
To export results without joining them into compound. In this case group that contains selection on several results must be splitted into several groups (with same name), located under the corresponding results.

salomeRun_rel.bat
src/CollectionPlugin/CollectionPlugin_Validators.cpp
src/ConnectorAPI/Test/TestExportToGEOM.py
src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py
src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py
src/ExchangeAPI/ExchangeAPI_Export.cpp
src/ExchangeAPI/ExchangeAPI_Export.h
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/Model/Model_ResultBody.cpp
src/ModelAPI/ModelAPI_ResultBody.h

index 03ab278f6090eb6c22791e4073c9d70cc18c8262..2cfabdae9b283e2d0da722f4532eb33ff314cb79 100644 (file)
@@ -12,4 +12,4 @@ call env_Salome.bat
 @SET SHAPER_ROOT_DIR=%ROOT_DIR%\install
 @SET SalomeAppConfig=%SHAPER_ROOT_DIR%\share\salome\resources\shaper;%GUI_ROOT_DIR%\share\salome\resources\gui
 
-start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %*
+start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" --modules=SHAPER,GEOM,SMESH %*
index 0c765092eebd034c7e34b5bf713508c0f61f7b6d..d644c13f64817c4bc9f0da5fa700e3ddaea72fe1 100644 (file)
@@ -29,17 +29,15 @@ bool CollectionPlugin_FieldValidator::isValid(const FeaturePtr& theFeature,
 {
   AttributeSelectionListPtr aSelList =
     theFeature->selectionList(CollectionPlugin_Field::SELECTED_ID());
+  std::string aTypeStr = aSelList->selectionType();
+  if (aTypeStr == "part")
+    return true;
   if (aSelList->isInitialized()) {
     int aSize = aSelList->size();
-    std::string aTypeStr = aSelList->selectionType();
-    if (aTypeStr == "part")
-      return true;
-    else {
-      bool aIsDefined = aSize > 0;
-      if (!aIsDefined)
-        theError = "Selection list is not initialized";
-      return aIsDefined;
-    }
+    bool aIsDefined = aSize > 0;
+    if (!aIsDefined)
+      theError = "Selection list is not initialized";
+    return aIsDefined;
   }
   theError = "Selection list is not initialized";
   return false;
index 0c861488789319ee50c85366fec7de3ce75cf282..9efb1bba0a526c85d90f73b3132ba9a7a79c792d 100644 (file)
@@ -90,10 +90,10 @@ def testSeveralExportsToGEOM():
   Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Box_2_1")])
   Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Box_2_1/Top")])
   model.do()
-  model.end()
 
   # First export to GEOM
   model.exportToGEOM(Part_1_doc)
+  model.end()
 
   # Check that the GEOM object has 1 compsolid and 2 solids
   geomObject_1 = getLastGEOMShape()
@@ -105,15 +105,18 @@ def testSeveralExportsToGEOM():
   assert geompy.NumberOfFaces(geomGroup_1) == 2
 
   # Add a third box
+  model.begin()
   Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
   Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 20)
+  model.do()
 
   # Second export to GEOM
   model.exportToGEOM(Part_1_doc)
+  model.end()
 
-  # Check that the GEOM object has 3 solids
+  # Check that the last exported GEOM object is 1 solids
   geomObject_2 = getLastGEOMShape()
-  assert geompy.NumberOfSolids(geomObject_2) == 3
+  assert geompy.NumberOfSolids(geomObject_2) == 1
 
   # Dump the salome study (only CORBA modules, SHAPER dump is not in it)
   tempdir = tempfile.gettempdir()
index 416d2ad5f1881c8c6efc008b6bb8785de948a4f0..0048ebc6b32e6b3b78a86f4cec2846a886155ed2 100644 (file)
@@ -117,8 +117,8 @@ def testGroupsAndFieldsExportToGEOM():
   Field_4 = model.addField(Part_1_doc, 1, "DOUBLE", 1, ["Comp 1"], Field_4_objects)
   Field_4.result().setName("Field_vertices")
   Field_4.addStep(0, 0, [[0], [1], [1], [1], [1], [1], [1], [1], [1], [2], [2], [2], [2], [3], [3], [3], [3]])
-  model.exportToGEOM(Part_1_doc)
   model.do()
+  model.exportToGEOM(Part_1_doc)
   model.end()
 
 # check the groups content by the coordinates of a point on its sub-shapes
@@ -130,55 +130,55 @@ def checkGroupByCoords(group, coords, tolerance=1e-7):
 
 ## Check the result imported in GEOM
 def checkResultInGEOM():
-  geomObject_1 = getLastGEOMShape()
+  geomObject_1 = getLastGEOMShape() # the second, translation result
 
   group_1_GEOM = getSubObject(geomObject_1, 1)
   assert group_1_GEOM.GetName() == 'faces_top'
-  assert geompy.NumberOfFaces(group_1_GEOM) == 3
+  assert geompy.NumberOfFaces(group_1_GEOM) == 1 # 2 faces are in the first result, only one here
 
   # coordinates of the barycenters of the faces of Group_1
-  coords_1 = [[-5, 5, 10], [10, 10, 20], [25, 5, 10]]
+  coords_1 = [[25, 5, 10]]
   checkGroupByCoords(group_1_GEOM, coords_1)
 
   group_2_GEOM = getSubObject(geomObject_1, 2)
   assert group_2_GEOM.GetName() == 'edges_x'
-  assert geompy.NumberOfEdges(group_2_GEOM) == 3
+  assert geompy.NumberOfEdges(group_2_GEOM) == 1 # 2 edges are in the first result, only one here
 
   # coordinates of the barycenters of the edges of Group_2
-  coords_2 = [[-5, 0, 0], [10, 0, 0], [25, 0, 0]]
+  coords_2 = [[25, 0, 0]]
   checkGroupByCoords(group_2_GEOM, coords_2)
 
   group_3_GEOM = getSubObject(geomObject_1, 3)
   assert group_3_GEOM.GetName() == 'vertices_bottom'
-  assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 8
+  assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 3 # 3 of 8
 
   # coordinates of the points of of Group_3
-  coords_3 = [[-10, 0, 0], [-10, 10, 0], [0, 10, 0], [0, 20, 0], [20, 20, 0], [20, 10, 0], [30, 10, 0], [30, 0, 0]]
+  coords_3 = [[20, 10, 0], [30, 10, 0], [30, 0, 0]]
   checkGroupByCoords(group_3_GEOM, coords_3)
 
   group_4_GEOM = getSubObject(geomObject_1, 4)
   assert group_4_GEOM.GetName() == 'solids_small'
-  assert geompy.NumberOfSolids(group_4_GEOM) == 2
+  assert geompy.NumberOfSolids(group_4_GEOM) == 1 # 1 of 2
 
   # coordinates of the barycenters of the solids of Group_4
-  coords_4 = [[-5, 5, 5], [25, 5, 5]]
+  coords_4 = [[25, 5, 5]]
   checkGroupByCoords(group_4_GEOM, coords_4)
 
   field_1_GEOM = getSubObject(geomObject_1, 5)
   assert field_1_GEOM.GetName() == 'Field_solids'
-  assert field_1_GEOM.GetStep(0).GetValues() == [1.0, 2.0, 3.0]
+  assert field_1_GEOM.GetStep(0).GetValues() == [3.0]
 
   field_2_GEOM = getSubObject(geomObject_1, 6)
   assert field_2_GEOM.GetName() == 'Field_faces'
-  assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
+  assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0]
 
   field_3_GEOM = getSubObject(geomObject_1, 7)
   assert field_3_GEOM.GetName() == 'Field_edges'
-  assert field_3_GEOM.GetStep(0).GetValues() == [2.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
+  assert field_3_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0]
 
   field_4_GEOM = getSubObject(geomObject_1, 8)
   assert field_4_GEOM.GetName() == 'Field_vertices'
-  assert field_4_GEOM.GetStep(0).GetValues() == [2.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
+  assert field_4_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0]
 
   pass
 
index 8bde3eec7a83f52e6f48062d41e7f22df045d175..338161d4ae6bd77ee70a33858edd0be600eeeb0e 100644 (file)
@@ -57,7 +57,7 @@ class ExportFeature(ModelAPI.ModelAPI_Feature):
     def getKind(self):
         return ExportFeature.ID()
 
-    ## This feature is action: has no property pannel and executes immediately.
+    ## This feature is action: has no property panel and executes immediately.
     def isAction(self):
         return True
 
@@ -67,32 +67,38 @@ class ExportFeature(ModelAPI.ModelAPI_Feature):
 
     ## Export the results, groups and fields via XAO
     def exportViaXAO(self):
-        tmpXAOFile = getTmpFileName("xao")
-        self.tmpXAOFile = tmpXAOFile
-        #print "Export to %s"%tmpXAOFile
-        exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, "automatic_shaper_export_to_XAO")
-        if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0:
-            exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.")
-            return
-        imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile)
-        self.geompy.addToStudy( shape, shape.GetName() )
-        # add sub-shapes and groups to the object browser
-        for obj in subShapes + groups:
-            name = obj.GetName()
-            self.geompy.addToStudyInFather(shape, obj, name)
-        # add fields to the object browser
-        for field in fields:
-            name = field.GetName()
-            self.geompy.addToStudyInFather(shape, field, name)
-            # add steps to the object browser
-            steps = field.getSteps()
-            for i_step in steps:
-                step = field.getStep(i_step)
-                i_stamp = step.GetStamp()
-                step_name = "Step %i %i"%(i_step, i_stamp)
-                self.geompy.addToStudyInFather( field, step, step_name )
-        # Remove the temporary file
-        os.remove(tmpXAOFile)
+        # iterate all results of Part, export one by one due to issue 2882
+        for aResIndex in range(self.Part.size(model.ModelAPI_ResultBody_group())):
+          anObject = self.Part.object(model.ModelAPI_ResultBody_group(), aResIndex)
+          aResult = model.objectToResult(anObject)
+          if not aResult is None:
+            tmpXAOFile = getTmpFileName("xao")
+            self.tmpXAOFile = tmpXAOFile
+            #print "Export to %s"%tmpXAOFile
+            exportXAO = ExchangeAPI.exportToXAO(self.Part, tmpXAOFile, model.selection(aResult), "automatic_shaper_export_to_XAO")
+            if not os.path.exists(tmpXAOFile) or os.stat(tmpXAOFile).st_size == 0:
+                exportXAO.feature().setError("Error in exportToXAO. No XAO file has been created.")
+                return
+            imported, shape, subShapes, groups, fields = self.geompy.ImportXAO(tmpXAOFile)
+            self.geompy.addToStudy( shape, shape.GetName() )
+            # add sub-shapes and groups to the object browser
+            for obj in subShapes + groups:
+                name = obj.GetName()
+                self.geompy.addToStudyInFather(shape, obj, name)
+            # add fields to the object browser
+            for field in fields:
+                name = field.GetName()
+                self.geompy.addToStudyInFather(shape, field, name)
+                # add steps to the object browser
+                steps = field.getSteps()
+                for i_step in steps:
+                    step = field.getStep(i_step)
+                    i_stamp = step.GetStamp()
+                    step_name = "Step %i %i"%(i_step, i_stamp)
+                    self.geompy.addToStudyInFather( field, step, step_name )
+            # Remove the temporary file
+            os.remove(tmpXAOFile)
+          pass
         pass
 
     ## Exports all shapes and groups into the GEOM module.
index 10ea384268c4e8ca0c1cefe2219c89290934a99c..1e7e54aa88fbbf21ce57301ad56be3d6cee85576 100644 (file)
@@ -24,6 +24,7 @@
 #include <ModelHighAPI_Tools.h>
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Services.h>
+#include <ModelHighAPI_Selection.h>
 //--------------------------------------------------------------------------------------
 
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature)
@@ -50,6 +51,27 @@ ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>&
   apply(); // finish operation to make sure the export is done on the current state of the history
 }
 
+ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::string & theFilePath, const ModelHighAPI_Selection& theResult,
+  const std::string & theAuthor, const std::string & theGeometryName)
+  : ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+  fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID()));
+  fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID()));
+  fillAttribute(theAuthor, theFeature->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID()));
+  fillAttribute(theGeometryName,
+    theFeature->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID()));
+  fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID()));
+  std::list<ModelHighAPI_Selection> aListOfOneSel;
+  aListOfOneSel.push_back(theResult);
+  fillAttribute(aListOfOneSel,
+    theFeature->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()));
+  execute();
+  apply(); // finish operation to make sure the export is done on the current state of the history
+}
+
+
 /// Constructor with values for export in other formats than XAO.
 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                               const std::string & theFilePath,
@@ -149,4 +171,15 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
 }
 
+ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
+  const std::string & theFilePath, const ModelHighAPI_Selection& theSelectedShape,
+  const std::string & theAuthor, const std::string & theGeometryName)
+{
+  apply(); // finish previous operation to make sure all previous operations are done
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    thePart->addFeature(ExchangePlugin_ExportFeature::ID());
+  // special internal case when for XAO a selection list is filled
+  return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectedShape, "XAO"));
+}
+
 //--------------------------------------------------------------------------------------
index 927a07127615458d400eadf1f4582ac94fa4bcd2..6cfddfd8f65d13500e2b984bb59d85dc39a4dff5 100644 (file)
@@ -52,6 +52,14 @@ public:
                               const std::string & theAuthor = std::string(),
                               const std::string & theGeometryName = std::string());
 
+  /// Constructor with values for XAO of selected result export.
+  EXCHANGEAPI_EXPORT
+    explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+      const std::string & theFilePath,
+      const ModelHighAPI_Selection& theResult,
+      const std::string & theAuthor,
+      const std::string & theGeometryName = std::string());
+
   /// Constructor with values for export in other formats than XAO.
   EXCHANGEAPI_EXPORT
   explicit ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
@@ -97,7 +105,7 @@ ExportPtr exportToFile(const std::shared_ptr<ModelAPI_Document> & thePart,
                   const std::string & theFileFormat = std::string());
 
 /**\ingroup CPPHighAPI
- * \brief Export XAO
+ * \brief Exports to XAO file all results of the current document
  */
 EXCHANGEAPI_EXPORT
 ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
@@ -105,6 +113,16 @@ ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
                  const std::string & theAuthor = std::string(),
                  const std::string & theGeometryName = std::string());
 
+/**\ingroup CPPHighAPI
+* \brief Exports to XAO file the selected result with groups parts related to it only.
+*/
+EXCHANGEAPI_EXPORT
+ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
+  const std::string & theFilePath,
+  const ModelHighAPI_Selection& theSelectedShape,
+  const std::string & theAuthor = std::string(),
+  const std::string & theGeometryName = std::string());
+
 //--------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------
 #endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_EXPORT_H_ */
index 7ae2e133f301731019628a418f4e73e97c6ed85f..a8ecc73c1a408fa6d9147f99426bac3c47171953 100644 (file)
@@ -52,6 +52,7 @@
 #include <ModelAPI_ResultField.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Tools.h>
 
 #include <Events_InfoMessage.h>
 
@@ -212,6 +213,37 @@ static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
   return aStr.str();
 }
 
+/// Returns true if something in selection is presented in the results list
+static bool isInResults(AttributeSelectionListPtr theSelection,
+                        const std::list<ResultBodyPtr>& theResults,
+                        std::set<ResultBodyPtr>& theCashedResults)
+{
+  // collect all results into a cashed set
+  if (theCashedResults.empty()) {
+    std::list<ResultPtr> aResults;
+    std::list<ResultBodyPtr>::const_iterator aRes = theResults.cbegin();
+    for(; aRes != theResults.cend(); aRes++) {
+      if (theCashedResults.count(*aRes))
+        continue;
+      else
+        theCashedResults.insert(*aRes);
+      std::list<ResultPtr> aResults;
+      ModelAPI_Tools::allSubs(*aRes, aResults, false);
+      for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
+        theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
+      }
+    }
+  }
+  // if context is in results, return true
+  for(int a = 0; a < theSelection->size(); a++) {
+    AttributeSelectionPtr anAttr = theSelection->value(a);
+    ResultBodyPtr aSelected= std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+    if (aSelected.get() && theCashedResults.count(aSelected))
+      return true;
+  }
+  return false;
+}
+
 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 {
   try {
@@ -227,16 +259,39 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
   // make shape for export from all results
   std::list<GeomShapePtr> aShapes;
   std::list<ResultBodyPtr> aResults;
-  int aBodyCount = document()->size(ModelAPI_ResultBody::group());
-  for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
-    ResultBodyPtr aResultBody =
-        std::dynamic_pointer_cast<ModelAPI_ResultBody>(
-            document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
-    if (!aResultBody.get())
-      continue;
-    aShapes.push_back(aResultBody->shape());
-    aResults.push_back(aResultBody);
+
+  AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID());
+  bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
+  if (aIsSelection) { // a mode for export to geom result by result
+    for(int a = 0; a < aSelection->size(); a++) {
+      AttributeSelectionPtr anAttr = aSelection->value(a);
+      ResultBodyPtr aBodyContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+      if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
+        aResults.push_back(aBodyContext);
+        GeomShapePtr aShape = anAttr->value();
+        if (!aShape.get())
+          aShape = aBodyContext->shape();
+        aShapes.push_back(aShape);
+      }
+    }
+  } else {
+    int aBodyCount = document()->size(ModelAPI_ResultBody::group());
+    for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
+      ResultBodyPtr aResultBody =
+          std::dynamic_pointer_cast<ModelAPI_ResultBody>(
+              document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
+      if (!aResultBody.get())
+        continue;
+      aShapes.push_back(aResultBody->shape());
+      aResults.push_back(aResultBody);
+    }
+  }
+  if (aShapes.empty()) {
+    setError("No shapes to export");
+    return;
   }
+
+
   GeomShapePtr aShape = (aShapes.size() == 1)
       ? *aShapes.begin()
       : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
@@ -250,7 +305,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 
   // geometry name
   std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
-  if (aGeometryName.empty() && aBodyCount == 1) {
+  if (aGeometryName.empty() && aResults.size() == 1) {
     // get the name from the first result
     ResultBodyPtr aResultBody = *aResults.begin();
     aGeometryName = aResultBody->data()->name();
@@ -258,6 +313,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 
   aXao.getGeometry()->setName(aGeometryName);
 
+  std::set<ResultBodyPtr> allResultsCashed; // cash to speed up searching in all results selected
+
   // groups
   int aGroupCount = document()->size(ModelAPI_ResultGroup::group());
   for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
@@ -270,6 +327,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
     AttributeSelectionListPtr aSelectionList =
         aGroupFeature->selectionList("group_list");
 
+    if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in results
+      continue;
+
     // conversion of dimension
     std::string aSelectionType = aSelectionList->selectionType();
     std::string aDimensionString =
@@ -290,6 +350,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 
         int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value());
 
+        if (aReferenceID == 0) // selected value does not found in the exported shape
+          continue;
+
         std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
         int anElementID =
           aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
@@ -318,13 +381,17 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
 
     AttributeSelectionListPtr aSelectionList =
         aFieldFeature->selectionList("selected");
+    std::string aSelectionType = aSelectionList->selectionType();
+    bool isWholePart = aSelectionType == "part";
+
+    if (!isWholePart &&
+        !isInResults(aSelectionList, aResults, allResultsCashed))// skip field not used in results
+      continue;
 
     // conversion of dimension
-    std::string aSelectionType = aSelectionList->selectionType();
     std::string aDimensionString =
       ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
     XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
-    bool isWholePart = aSelectionType == "part";
     // get tables and their type
     std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
     std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
@@ -358,13 +425,9 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
             if (!isWholePart) {
               // element index actually is the ID of the selection
               AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1);
-
-              // complex conversion of reference id to element index
-              // gives bad id in case the selection is done from python script
-              // => using GeomAlgoAPI_CompoundBuilder::id instead
-              //int aReferenceID_old = aSelection->Id();
-
               int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value());
+              if (aReferenceID == 0) // selected value does not found in the exported shape
+                continue;
 
               std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
               anElementID =
index 4f442842e795195bbbd0763b7e8d3c2986ae9523..1be002979bd6cb54781fe94ece9bbb274e9b5292 100644 (file)
@@ -125,9 +125,9 @@ ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool forTree) cons
   return mySubs.at(theIndex);
 }
 
-bool Model_ResultBody::isSub(ObjectPtr theObject, int& theIndex) const
+bool Model_ResultBody::isSub(ObjectPtr theResult, int& theIndex) const
 {
-  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theResult);
   if (aFound != mySubsMap.end()) {
     theIndex = aFound->second;
     return true;
index 0991119bd56c931ed13a666172efc1fe8e2ed15d..c585280cc4c4c0e9ca30c32921aad5d5af7c6c74 100644 (file)
@@ -86,9 +86,9 @@ public:
   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(
     const int theIndex, bool forTree = false) const = 0;
 
-  /// Returns true if feature or result belong to this composite feature as subs
+  /// Returns true if theResult belong to this composite result as sub.
   /// Returns theIndex - zero based index of sub if found
-  MODELAPI_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0;
+  MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0;
 
   /// \brief Stores the shape (called by the execution method).
   /// param[in] theShape shape to store.