]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make export to XAO working with groups BOPs and whole features in groups selected.
authormpv <mpv@opencascade.com>
Thu, 12 Sep 2019 08:14:55 +0000 (11:14 +0300)
committermpv <mpv@opencascade.com>
Thu, 12 Sep 2019 08:15:12 +0000 (11:15 +0300)
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/Test/TestGroupWholeResult2.py [new file with mode: 0644]
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp

index 936dd87e747ac39a65e863559d484c96974afd1f..6df77986673011e71091e0016ff46b271e06a6b0 100644 (file)
@@ -148,4 +148,5 @@ ADD_UNIT_TESTS(
                TestGroupSubstraction_Error2.py
                Test2977.py
                TestGroupWholeResult1.py
+               TestGroupWholeResult2.py
 )
diff --git a/src/CollectionPlugin/Test/TestGroupWholeResult2.py b/src/CollectionPlugin/Test/TestGroupWholeResult2.py
new file mode 100644 (file)
index 0000000..31114c3
--- /dev/null
@@ -0,0 +1,47 @@
+# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# Tests python API for the whole result (by feature) in group selection
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPOUND", "all-in-Box_1")])
+Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")])
+GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "Group_1")], [model.selection("COMPOUND", "Group_2")])
+model.end()
+
+aResultShape = GroupSubstraction_1.feature().firstResult().shape()
+
+from GeomAPI import GeomAPI_ShapeIterator
+anIter = GeomAPI_ShapeIterator(aResultShape)
+aNum = 0
+while anIter.more():
+  aFace = anIter.current()
+  assert(aFace.isFace())
+  aNum = aNum + 1
+  anIter.next()
+
+assert(aNum == 4) # 6 from the whole result minus 2 from the second group (local selection)
+
+
+assert(model.checkPythonDump())
index 60cae7e2fc88a29b63a060f49c7fbef0f2115b60..f38b1c60532e0bced2f5491a4bf4ea430209f903 100644 (file)
@@ -256,8 +256,42 @@ static bool isInResults(AttributeSelectionListPtr theSelection,
   // 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))
+    ResultPtr aContext = anAttr->context();
+    // check is it group selected for groups BOP
+    if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
+      // it is impossible by used results check which result is used in this group result,
+      // so check the results shapes is it in results of this document or not
+      FeaturePtr aSelFeature =
+        std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
+      if (!aSelFeature.get() || aSelFeature->results().empty())
+        continue;
+      GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
+
+      std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
+      for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
+        GeomShapePtr aResultShape = (*allResultsIter)->shape();
+
+        GeomAPI_Shape::ShapeType aType =
+          GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
+        GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
+        for(; aGroupResExp.more(); aGroupResExp.next()) {
+          if (aResultShape->isSubShape(aGroupResExp.current(), false))
+            return true; // at least one shape of the group is in the used results
+        }
+      }
+    }
+    ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+    if (!aSelected.get()) { // try to get selected feature and all its results
+      FeaturePtr aContextFeature = anAttr->contextFeature();
+      if (aContextFeature.get() && !aContextFeature->results().empty()) {
+        const std::list<ResultPtr>& allResluts = aContextFeature->results();
+        std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
+        for(; aResIter != allResluts.cend(); aResIter++) {
+          if (aResIter->get() && theCashedResults.count(*aResIter))
+            return true;
+        }
+      }
+    } else if (aSelected.get() && theCashedResults.count(aSelected))
       return true;
   }
   return false;
@@ -372,6 +406,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
     for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
       ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
           (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
+      if (!aResultGroup.get() || !aResultGroup->shape().get())
+        continue;
 
       FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
 
@@ -391,26 +427,15 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
                                             aResultGroup->data()->name());
 
       try {
-        for (int aSelectionIndex = 0; aSelectionIndex < aSelectionList->size(); ++aSelectionIndex){
-          AttributeSelectionPtr aSelection = aSelectionList->value(aSelectionIndex);
-          GeomShapePtr aSelShape = aSelection->value();
-          if (!aSelShape.get() && aSelection->context().get()) {
-            aSelShape = aSelection->context()->shape();
-          }
-
-          std::list<GeomShapePtr> allSubs;
-          allSubShapes(aSelShape, aSelType, allSubs);
-
-          std::list<GeomShapePtr>::iterator anIter = allSubs.begin();
-          for(; anIter != allSubs.end(); anIter++) {
-            int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, *anIter);
-            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);
-            aXaoGroup->add(anElementID);
-          }
+        GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
+        for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
+          int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current());
+          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);
+          aXaoGroup->add(anElementID);
         }
       } catch (XAO::XAO_Exception& e) {
         // LCOV_EXCL_START