Salome HOME
0022747: [EDF] Improvement of Get Shared Shapes operation
authoreap <eap@opencascade.com>
Wed, 15 Oct 2014 15:26:27 +0000 (19:26 +0400)
committervsr <vsr@opencascade.com>
Thu, 13 Nov 2014 11:16:34 +0000 (14:16 +0300)
doc/salome/gui/GEOM/input/shared_shapes.doc
src/GEOMImpl/GEOMImpl_IShapesOperations.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.hxx
src/GEOM_I/GEOM_IShapesOperations_i.cc
src/GEOM_SWIG/GEOM_TestHealing.py
src/GEOM_SWIG/geomBuilder.py
src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx

index 81c0600160f076d70e056ad0b355b198f77497e1..7b201137afab37804f4ff71a2d7a4ded2c7826ca 100755 (executable)
@@ -5,7 +5,8 @@
 This operation is a special case of <b>Explode</b> operation. It
 produces sub-shapes of the exploded shape (the first shape in the list
 of argument shapes), which are shared with all other shapes in the
-arguments.
+arguments. The argument shapes can also be contained in a compound or
+group.
 
 To use this operation, select in the Main Menu <b>Operations -> Get
 Shared Shapes.</b> The following dialog box will appear.
@@ -13,15 +14,15 @@ Shared Shapes.</b> The following dialog box will appear.
 \image html shared_shapes.png
 
 <ul>
-<li> <b>Name</b> is the base name of the resulting shapes; </li>
-<li> <b>Shapes</b> are the shapes to fing shared sub-shapes of; </li>
-<li> <b>Sub-shapes Type</b> is the type of required sub-shapes; </li>
+<li> <b>Name</b> is the base name of the resulting shapes. </li>
+<li> <b>Shapes</b> are the shapes to fing shared sub-shapes of. </li>
+<li> <b>Sub-shapes Type</b> is the type of required sub-shapes. </li>
 </ul>
 
-\n <b>Advanced options</b> \ref preview_anchor "Preview"
-
-\n <b>TUI Command:</b> <em> geompy.GetSharedShapesMulti(Shapes,
-Type),</em> where \em Shapes is a list of shapes to fing shared sub-
+\n <b>Advanced options:</b> \ref preview_anchor "Preview"
+<p>
+<b>TUI Command:</b> <em> geompy.GetSharedShapesMulti( Shapes, Type ),</em> 
+<br> where \em Shapes is a list or compound of shapes to fing shared sub-
 shapes of and \em Type is the type of required sub-shapes.
 
 Our <b>TUI Scripts</b> provide you with useful examples of the use of
index a2738417fa7128bee6964948822a43767282bb88..eb22375c48bdaccf78dc34b7d1dbe6fab0daea1e 100644 (file)
@@ -2001,8 +2001,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
 //purpose  :
 //=======================================================================
 Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
-                                     (std::list<Handle(GEOM_Object)> theShapes,
-                                      const Standard_Integer         theShapeType)
+                                     (std::list<Handle(GEOM_Object)> theShapes,
+                                      const Standard_Integer           theShapeType)
 {
   SetErrorCode(KO);
 
@@ -2012,18 +2012,33 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
   int ind = 1;
   std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin();
 
-  Handle(GEOM_Object) aMainObj = (*it++);
+  Handle(GEOM_Object) aMainObj = *it;
   Handle(GEOM_Function) aMainShape = aMainObj->GetLastFunction();
-  if (aMainShape.IsNull()) {
-    SetErrorCode("NULL shape for GetSharedShapes");
-    return NULL;
+
+  TopTools_SequenceOfShape shapeSeq;
+  for (; it != theShapes.end(); it++, ind++) {
+    Handle(GEOM_Function) aRefShape = (*it)->GetLastFunction();
+    if (aRefShape.IsNull()) {
+      SetErrorCode("NULL shape for GetSharedShapes");
+      return NULL;
+    }
+    TopoDS_Shape aShape2 = aRefShape->GetValue();
+    if (aShape2.IsNull()) return NULL;
+    shapeSeq.Append( aShape2 );
   }
 
-  TopoDS_Shape aShape1 = aMainShape->GetValue();
-  if (aShape1.IsNull()) return NULL;
+  TopoDS_Shape aShape1 = shapeSeq.First();
+
+  if ( shapeSeq.Length() == 1 )
+  {
+    shapeSeq.Clear();
+    for ( TopoDS_Iterator it( aShape1); it.More(); it.Next() )
+      shapeSeq.Append( it.Value() );
+    aShape1 = shapeSeq.First();
+  }
 
   TopTools_IndexedMapOfShape anIndices;
-  TopExp::MapShapes(aShape1, anIndices);
+  TopExp::MapShapes(aMainShape->GetValue(), anIndices);
 
   TopTools_IndexedMapOfShape mapSelected;
   TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapSelected);
@@ -2032,23 +2047,17 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
   BRep_Builder B;
   TopoDS_Compound aCurrSelection;
 
-  for (; it != theShapes.end(); it++, ind++) {
-    Handle(GEOM_Function) aRefShape = (*it)->GetLastFunction();
-    if (aRefShape.IsNull()) {
-      SetErrorCode("NULL shape for GetSharedShapes");
-      return NULL;
-    }
+  for ( ind = 2; ind <= shapeSeq.Length(); ind++) {
 
     TopoDS_Compound aCompound;
     B.MakeCompound(aCompound);
 
-    TopoDS_Shape aShape2 = aRefShape->GetValue();
-    if (aShape2.IsNull()) return NULL;
+    const TopoDS_Shape& aShape2 = shapeSeq.Value( ind );
 
     TopTools_MapOfShape mapShape2;
     TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
     for (; exp.More(); exp.Next()) {
-      TopoDS_Shape aSS = exp.Current();
+      const TopoDS_Shape& aSS = exp.Current();
       if (mapShape2.Add(aSS) && mapSelected.Contains(aSS)) {
         B.Add(aCompound, aSS);
       }
@@ -2060,7 +2069,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
   }
 
   // Create GEOM_Object for each found shared shape (collected in aCurrSelection)
-  Handle(GEOM_Object) anObj;
+  Handle(GEOM_Object) anObj, aLastCreated;
   Handle(TColStd_HArray1OfInteger) anArray;
   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
   TCollection_AsciiString anAsciiList, anEntry;
@@ -2072,6 +2081,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
     anObj = GetEngine()->AddSubShape(aMainObj, anArray);
     aSeq->Append(anObj);
 
+    aLastCreated = GEOM::GetCreatedLast( aLastCreated, anObj );
+
     // for python command
     TDF_Tool::Entry(anObj->GetEntry(), anEntry);
     anAsciiList += anEntry;
@@ -2087,16 +2098,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
   anAsciiList.Trunc(anAsciiList.Length() - 1);
 
   // IPAL22904: TC6.5.0: order of python commands is wrong after dump study
-  Handle(TColStd_HSequenceOfTransient) anObjects = new TColStd_HSequenceOfTransient;
-  for( it = theShapes.begin(); it != theShapes.end(); it++ )
-  {
-    Handle(GEOM_Object) anObj = *it;
-    if( !anObj.IsNull() )
-      anObjects->Append( anObj );
-  }
-
   // Get the function of the latest published object
-  Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast( anObjects )->GetLastFunction();
+  Handle(GEOM_Function) aFunction = aLastCreated->GetLastFunction();
   if( aFunction.IsNull() ) // just in case
     aFunction = aMainShape;
 
index a5b81b4d35490608520c47fc323fbd4765f83325..a5b6bc3969aa72746521df338588b8df040a6680 100644 (file)
@@ -166,8 +166,8 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
                      const Standard_Integer theShapeType);
 
   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
-    GetSharedShapes (std::list<Handle(GEOM_Object)> theShapes,
-                     const Standard_Integer         theShapeType);
+    GetSharedShapes (std::list<Handle(GEOM_Object)>& theShapes,
+                     const Standard_Integer          theShapeType);
 
   Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
     GetShapesOnPlane (const Handle(GEOM_Object)& theShape,
index e109838e8aec11979cf7064a788e6335f626b960..1e965a7982f55e72895dae747ad071848a3801c3 100644 (file)
@@ -1047,12 +1047,8 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapesMulti
 
   //Get the shapes
   std::list<Handle(GEOM_Object)> aShapes;
-  int aLen = theShapes.length();
-  for (int ind = 0; ind < aLen; ind++) {
-    Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
-    if (aSh.IsNull()) return aSeq._retn();
-    aShapes.push_back(aSh);
-  }
+  if (! GetListOfObjectsImpl( theShapes, aShapes ))
+    return aSeq._retn();
 
   Handle(TColStd_HSequenceOfTransient) aHSeq =
     GetOperations()->GetSharedShapes(aShapes, theShapeType);
index 72ad4927e680176cccb8a9d7f6ea5425a06f3f85..7d399a252f4b215ad27165b23ebe37782c5e9b03 100644 (file)
@@ -501,6 +501,14 @@ def TestSewGluing(geompy):
   assert glueEL3.GetShapeType() == GEOM.COMPOUND
   assert geompy.NumberOfEdges( glueEL3 ) == geompy.NumberOfEdges( comp ) - 4
 
+  # check GetSharedShapesMulti()
+  sharedEE = geompy.GetSharedShapesMulti( glueEL3, geompy.ShapeType["EDGE"])
+  assert len( sharedEE ) == 4
+  assert sharedEE[0].GetShapeType() == GEOM.EDGE
+  assert sharedEE[1].GetShapeType() == GEOM.EDGE
+  assert sharedEE[2].GetShapeType() == GEOM.EDGE
+  assert sharedEE[3].GetShapeType() == GEOM.EDGE
+
   return
 
 def TestHealingOperations (geompy, math):
index 32c1c23dc1edc06e1988970066ea26c076e31019..91afbf8a856382018aceec95a7fb52382dff46d6 100644 (file)
@@ -4819,7 +4819,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             return aList
 
         ## Get all sub-shapes, shared by all shapes in the list <VAR>theShapes</VAR>.
-        #  @param theShapes Shapes to find common sub-shapes of.
+        #  @param theShapes Either a list or compound of shapes to find common sub-shapes of.
         #  @param theShapeType Type of sub-shapes to be retrieved (see ShapeType())
         #  @param theName Object name; when specified, this parameter is used
         #         for result publication in the study. Otherwise, if automatic
@@ -4834,7 +4834,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
             Get all sub-shapes, shared by all shapes in the list theShapes.
 
             Parameters:
-                theShapes Shapes to find common sub-shapes of.
+                theShapes Either a list or compound of shapes to find common sub-shapes of.
                 theShapeType Type of sub-shapes to be retrieved (see geompy.ShapeType)
                 theName Object name; when specified, this parameter is used
                         for result publication in the study. Otherwise, if automatic
@@ -4844,7 +4844,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
                 List of GEOM.GEOM_Object, that are sub-shapes of all given shapes.
             """
             # Example: see GEOM_TestOthers.py
-            aList = self.ShapesOp.GetSharedShapesMulti(theShapes, theShapeType)
+            aList = self.ShapesOp.GetSharedShapesMulti(ToList(theShapes), theShapeType)
             RaiseIfFailed("GetSharedShapesMulti", self.ShapesOp)
             self._autoPublish(aList, theName, "shared")
             return aList
index c5880d796c46df914b08d444afe6d2e60cc3147f..2c0d98c736927d0241a122693910a9f069eb6f0f 100644 (file)
@@ -308,11 +308,16 @@ GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
 //=================================================================================
 bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
 {
+  bool isOK = true;
   if (myListShapes.length() < 2) {
-    msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
-    return false;
+    isOK = false;
+    if ( myListShapes.length() == 1 )
+      isOK = ( myListShapes[0]->GetShapeType() == GEOM::COMPOUND );
   }
-  return true;
+  if ( !isOK )
+    msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
+
+  return isOK;
 }
 
 //=================================================================================