]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2578: EDF 2018-2 Removal of faces.
authormzn <mzn@opencascade.com>
Fri, 31 Aug 2018 11:01:54 +0000 (14:01 +0300)
committermzn <mzn@opencascade.com>
Fri, 31 Aug 2018 11:01:54 +0000 (14:01 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/Test/TestRemoveSubShapes3.py [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/ModelAPI/Test/Test2228.py

index c173fe22a6c6b161216beb1ce1953127c3030eaa..ccc359c3cdd6af3afce3c1d252078729b7fb3308 100644 (file)
@@ -190,6 +190,7 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestUnionFaces.py
                TestRemoveSubShapes.py
                TestRemoveSubShapes2.py
+               TestRemoveSubShapes3.py
                TestPipe.py
                TestRecover.py
                TestRecover1798.py
index 75b1d9c09dceec344b4969a45518951d7d32f82e..19e66b19c75cbd89d6c8e7243f4868c866c2aa74 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
 #include <ModelAPI_Validator.h>
 
 #include <GeomAPI_ShapeIterator.h>
@@ -78,7 +79,7 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
     aSubShapesToRemoveAttrList->clear();
     return;
   }
-  const int aNumOfSubs = aResultBody->numberOfSubs();
+  const bool isHasSubs = ModelAPI_Tools::hasSubResults(aResultBody);
 
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
   if(!aBaseShape.get()) {
@@ -95,15 +96,19 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
       return;
     }
 
-    for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
-      GeomShapePtr aSubShape = anIt.current();
-      if(aNumOfSubs == 0) {
+    std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
+    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+      GeomShapePtr aSubShape = *anIt;
+      if(!isHasSubs) {
         aSubShapesToKeepAttrList->append(aContext, aSubShape);
       } else {
-        for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
-          ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
-          if(aSubResult->shape()->isEqual(aSubShape)) {
-            aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
+        std::list<ResultPtr> anAllSubs;
+        ModelAPI_Tools::allSubs(aResultBody, anAllSubs);
+        std::list<ResultPtr>::iterator aSubsIt = anAllSubs.begin();
+        for(; aSubsIt != anAllSubs.end(); aSubsIt++) {
+          ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubsIt);
+          if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) {
+            aSubShapesToKeepAttrList->append(aSub, aSubShape);
             break;
           }
         }
@@ -120,8 +125,9 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
 
     int anIndex;
     const int aSubsToKeepNb = aSubShapesToKeepAttrList->size();
-    for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
-      GeomShapePtr aSubShape = anIt.current();
+    std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
+    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+      GeomShapePtr aSubShape = *anIt;
       for(anIndex = 0; anIndex < aSubsToKeepNb; ++anIndex) {
         AttributeSelectionPtr anAttrSelectionInList = aSubShapesToKeepAttrList->value(anIndex);
         GeomShapePtr aSubShapeToKeep = anAttrSelectionInList->value();
@@ -131,13 +137,16 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
       }
 
       if (anIndex == aSubsToKeepNb) {
-        if(aNumOfSubs == 0) {
+        if(!isHasSubs) {
           aSubShapesToRemoveAttrList->append(aContext, aSubShape);
         } else {
-          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
-            if(aSubResult->shape()->isEqual(aSubShape)) {
-              aSubShapesToRemoveAttrList->append(aSubResult, aSubShape);
+          std::list<ResultPtr> anAllSubs;
+          ModelAPI_Tools::allSubs(aResultBody, anAllSubs);
+          std::list<ResultPtr>::iterator aSubsIt = anAllSubs.begin();
+          for(; aSubsIt != anAllSubs.end(); aSubsIt++) {
+            ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubsIt);
+            if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) {
+              aSubShapesToRemoveAttrList->append(aSub, aSubShape);
               break;
             }
           }
@@ -155,8 +164,9 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
 
     int anIndex;
     const int aSubsToRemoveNb = aSubShapesToRemoveAttrList->size();
-    for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
-      GeomShapePtr aSubShape = anIt.current();
+    std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
+    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+      GeomShapePtr aSubShape = *anIt;
       for(anIndex = 0; anIndex < aSubsToRemoveNb; ++anIndex) {
         AttributeSelectionPtr anAttrSelectionInList = aSubShapesToRemoveAttrList->value(anIndex);
         GeomShapePtr aSubShapeToRemove = anAttrSelectionInList->value();
@@ -166,13 +176,16 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
       }
 
       if (anIndex == aSubsToRemoveNb) {
-        if(aNumOfSubs == 0) {
+        if(!isHasSubs) {
           aSubShapesToKeepAttrList->append(aContext, aSubShape);
         } else {
-          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
-            if(aSubResult->shape()->isEqual(aSubShape)) {
-              aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
+          std::list<ResultPtr> anAllSubs;
+          ModelAPI_Tools::allSubs(aResultBody, anAllSubs);
+          std::list<ResultPtr>::iterator aSubsIt = anAllSubs.begin();
+          for(; aSubsIt != anAllSubs.end(); aSubsIt++) {
+            ResultBodyPtr aSub = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubsIt);
+            if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) {
+              aSubShapesToKeepAttrList->append(aSub, aSubShape);
               break;
             }
           }
@@ -222,22 +235,26 @@ void FeaturesPlugin_RemoveSubShapes::execute()
   std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aDeletedSubs(new GeomAlgoAPI_MakeShapeCustom);
   std::set<GeomAPI_Shape::ShapeType> aTypes; // types that where removed
   aTypes.insert(GeomAPI_Shape::FACE);
-  for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
-    if (!anIt.current().get() || anIt.current()->isNull())
+
+  std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
+  for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+    GeomShapePtr aSubShape = *anIt;
+    if (!aSubShape.get() || aSubShape->isNull())
       continue;
+
     int anIndex;
     for(anIndex = 0; anIndex < aSubsNb; ++anIndex) {
       AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
       GeomShapePtr aLeftShape = anAttrSelectionInList->value();
-      if (anIt.current()->isEqual(aLeftShape)) {
+      if (aSubShape->isEqual(aLeftShape)) {
         break; // found in a left-list
       }
     }
     if (anIndex == aSubsNb) { // not found in left
-      aDeletedSubs->addDeleted(anIt.current());
-      aTypes.insert(anIt.current()->shapeType());
-      if (anIt.current()->shapeType() != GeomAPI_Shape::FACE) {
-        GeomAPI_ShapeExplorer aFaces(anIt.current(), GeomAPI_Shape::FACE);
+      aDeletedSubs->addDeleted(aSubShape);
+      aTypes.insert(aSubShape->shapeType());
+      if (aSubShape->shapeType() != GeomAPI_Shape::FACE) {
+        GeomAPI_ShapeExplorer aFaces(aSubShape, GeomAPI_Shape::FACE);
         for(; aFaces.more(); aFaces.next())
           aDeletedSubs->addDeleted(aFaces.current());
       }
index 9dfd94eaa14a7147cd3b8397f7b36c5bbddd8720..d44710409a15209f86c73cffd0213f6cddbcd3c5 100644 (file)
@@ -805,17 +805,18 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
     return false;
   }
 
+  std::list<GeomShapePtr> aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape);
   for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
     bool isSameFound = false;
     AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
     GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
-    for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
-      if(anIt.current()->isEqual(aShapeToAdd)) {
+    for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) {
+      if ((*anIt)->isEqual(aShapeToAdd)) {
         isSameFound = true;
         break;
       }
     }
-    if(!isSameFound) {
+    if (!isSameFound) {
       theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
       return false;
     }
diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes3.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes3.py
new file mode 100644 (file)
index 0000000..c7f7d63
--- /dev/null
@@ -0,0 +1,86 @@
+## Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+
+# =============================================================================
+# Test 1. Remove face from shell
+# =============================================================================
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face_1")])
+Face_2 = model.addFace(Part_1_doc, [model.selection("FACE", "Cylinder_1_1/Face_1")])
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("FACE", "Face_2_1")], model.selection("EDGE", "PartSet/OZ"), 10)
+Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Translation_1_1"), model.selection("FACE", "Face_1_1")])
+
+Remove_SubShapes_1 = model.addRemoveSubShapes(Part_1_doc, model.selection("SHELL", "Shell_1_1"))
+Remove_SubShapes_1.setSubShapesToRemove([model.selection("FACE", "Shell_1_1/Modified_Face_2")])
+model.do()
+
+model.checkResult(Remove_SubShapes_1, model, 1, [0], [0], [1], [4], [8])
+model.testHaveNamingSubshapes(Remove_SubShapes_1, model, Part_1_doc)
+
+# =============================================================================
+# Test 2. Remove faces from compound
+# =============================================================================
+Part_2 = model.addPart(partSet)
+Part_2_doc = Part_2.document()
+
+Cylinder_1 = model.addCylinder(Part_2_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+Face_1 = model.addFace(Part_2_doc, [model.selection("FACE", "Cylinder_1_1/Face_1")])
+LinearCopy_1 = model.addMultiTranslation(Part_2_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), 10, 2)
+LinearCopy_2 = model.addMultiTranslation(Part_2_doc, [model.selection("COMPOUND", "LinearCopy_1_1")], model.selection("EDGE", "PartSet/OZ"), 20, 2)
+
+Remove_SubShapes_2 = model.addRemoveSubShapes(Part_2_doc, model.selection("COMPOUND", "LinearCopy_2_1"))
+Remove_SubShapes_2.setSubShapesToRemove([model.selection("FACE", "LinearCopy_2_1_2_2"), model.selection("FACE", "LinearCopy_2_1_2_1")])
+model.do()
+
+model.checkResult(Remove_SubShapes_2, model, 1, [2], [0], [2], [8], [16])
+model.testHaveNamingSubshapes(Remove_SubShapes_2, model, Part_2_doc)
+
+# =============================================================================
+# Test 3. Remove solid from compsolid
+# =============================================================================
+Part_3 = model.addPart(partSet)
+Part_3_doc = Part_3.document()
+
+Box_1 = model.addBox(Part_3_doc, 10, 10, 10)
+LinearCopy_1 = model.addMultiTranslation(Part_3_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OY"), 10, 6)
+CompSolid_1_objects = [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "LinearCopy_1_1_2"), model.selection("SOLID", "LinearCopy_1_1_3"), model.selection("SOLID", "LinearCopy_1_1_4"), model.selection("SOLID", "LinearCopy_1_1_5"), model.selection("SOLID", "LinearCopy_1_1_6")]
+CompSolid_1 = model.addCompSolid(Part_3_doc, CompSolid_1_objects)
+
+Remove_SubShapes_3_objects = [model.selection("SOLID", "CompSolid_1_1_3"), model.selection("SOLID", "CompSolid_1_1_4")]
+Remove_SubShapes_3 = model.addRemoveSubShapes(Part_3_doc, model.selection("COMPSOLID", "CompSolid_1_1"))
+Remove_SubShapes_3.setSubShapesToRemove(Remove_SubShapes_3_objects)
+model.do()
+
+model.checkResult(Remove_SubShapes_3, model, 1, [4], [4], [24], [96], [192])
+model.testHaveNamingSubshapes(Remove_SubShapes_3, model, Part_3_doc)
+
+# =============================================================================
+# Test 4. Check Python dump
+# =============================================================================
+model.end()
+assert(model.checkPythonDump())
index d39fd60301fda096d0e50e5b42b752c6dde13b02..a47c77c7f28d1fa298a72a1613b71a5eabdd06ff 100644 (file)
@@ -55,6 +55,7 @@
 #include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <GeomAPI_ShapeIterator.h>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <GeomLib_Tool.hxx>
 #include <GeomAPI_IntCS.hxx>
@@ -1064,3 +1065,25 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_ShapeTools::wireToEdge(
   }
   return anEdge;
 }
+
+ListOfShape GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(const GeomShapePtr& theShape)
+{
+  ListOfShape aSubShapes;
+
+  if (!theShape->isCompound() && !theShape->isCompSolid() &&
+      !theShape->isShell() && !theShape->isWire()) {
+    return aSubShapes;
+  }
+
+  for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
+    GeomShapePtr aSubShape = anIt.current();
+    if (aSubShape->isVertex() || aSubShape->isEdge() ||
+        aSubShape->isFace() || aSubShape->isSolid()) {
+      aSubShapes.push_back(aSubShape);
+    } else {
+      aSubShapes.splice(aSubShapes.end(), getLowLevelSubShapes(aSubShape));
+    }
+  }
+
+  return aSubShapes;
+}
\ No newline at end of file
index a9211e397b16dc03423c39544ba9ca5dfc32c4cf..af2a81f5c3e1580ecb5ccfb6fac7a98a6dcfb439 100644 (file)
@@ -187,6 +187,11 @@ public:
   /// \brief Reapproximate a wire to build a single edge
   GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Edge> wireToEdge(
       const std::shared_ptr<GeomAPI_Wire>& theWire);
+
+  /// \brief Get non-composite sub-shapes of the given shape.
+  /// \param[in] theShape shape that should be exploded
+  /// \return list of sub-shapes (vertices, edges, faces, solids)
+  GEOMALGOAPI_EXPORT static ListOfShape getLowLevelSubShapes(const GeomShapePtr& theShape);
 };
 
 #endif
index 46c17b094fdf603ae178e0e6e6b1f0a6b055d24c..1da5212a856bc0705b6a8e4ef5712b7b4dd900ae 100644 (file)
@@ -58,14 +58,21 @@ Face_1 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_2/Edge-Sketc
 Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_2_2f")], model.selection(), model.selection("FACE", "Extrusion_2_1/From_Face_1"), 0, model.selection(), 0)
 Boolean_2 = model.addCut(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_4_1")])
 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cut_1_1"), model.selection("SOLID", "Cut_2_1"), model.selection("FACE", "Face_1_1")])
+Remove_SubShapes_1_objects = [model.selection("SOLID", "Partition_1_1_1_1"), model.selection("SOLID", "Partition_1_1_1_2"), model.selection("SOLID", "Partition_1_1_1_3"), model.selection("SOLID", "Partition_1_1_1_4")]
 Remove_SubShapes_1 = model.addRemoveSubShapes(Part_1_doc, model.selection("COMPOUND", "Partition_1_1"))
-Remove_SubShapes_1.setSubShapesToKeep([model.selection("COMPSOLID", "Partition_1_1_1")])
-model.end()
+Remove_SubShapes_1.setSubShapesToKeep(Remove_SubShapes_1_objects)
+
 
+model.end()
 
 # check that remove sub-shapes contains correct selection
 from ModelAPI import *
 aFactory = ModelAPI_Session.get().validators()
 assert(aFactory.validate(Remove_SubShapes_1.feature()))
-assert(Remove_SubShapes_1.subshapesToKeep().size() == 1)
-assert(Remove_SubShapes_1.subshapesToKeep().value(0).namingName() == "Partition_1_1_1")
+assert(Remove_SubShapes_1.subshapesToKeep().size() == 4)
+assert(Remove_SubShapes_1.subshapesToKeep().value(0).namingName() == "Partition_1_1_1_1")
+assert(Remove_SubShapes_1.subshapesToKeep().value(1).namingName() == "Partition_1_1_1_2")
+assert(Remove_SubShapes_1.subshapesToKeep().value(2).namingName() == "Partition_1_1_1_3")
+assert(Remove_SubShapes_1.subshapesToKeep().value(3).namingName() == "Partition_1_1_1_4")
+assert(Remove_SubShapes_1.subshapesToRemove().size() == 1)
+assert(Remove_SubShapes_1.subshapesToRemove().value(0).namingName() == "Partition_1_1_2")