diff --git a/doc/salome/gui/GEOM/input/shared_shapes.doc b/doc/salome/gui/GEOM/input/shared_shapes.doc index 81c060016..7b201137a 100755 --- a/doc/salome/gui/GEOM/input/shared_shapes.doc +++ b/doc/salome/gui/GEOM/input/shared_shapes.doc @@ -5,7 +5,8 @@ This operation is a special case of Explode 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 Operations -> Get Shared Shapes. The following dialog box will appear. @@ -13,15 +14,15 @@ Shared Shapes. The following dialog box will appear. \image html shared_shapes.png -\n Advanced options \ref preview_anchor "Preview" - -\n TUI Command: geompy.GetSharedShapesMulti(Shapes, -Type), where \em Shapes is a list of shapes to fing shared sub- +\n Advanced options: \ref preview_anchor "Preview" +

+TUI Command: geompy.GetSharedShapesMulti( Shapes, Type ), +
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 TUI Scripts provide you with useful examples of the use of diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index d6db9cce7..c0613097d 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -2001,8 +2001,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes //purpose : //======================================================================= Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes - (std::list theShapes, - const Standard_Integer theShapeType) + (std::list & theShapes, + const Standard_Integer theShapeType) { SetErrorCode(KO); @@ -2012,18 +2012,33 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes int ind = 1; std::list::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; diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index a5b81b4d3..a5b6bc396 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -166,8 +166,8 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations const Standard_Integer theShapeType); Standard_EXPORT Handle(TColStd_HSequenceOfTransient) - GetSharedShapes (std::list theShapes, - const Standard_Integer theShapeType); + GetSharedShapes (std::list& theShapes, + const Standard_Integer theShapeType); Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnPlane (const Handle(GEOM_Object)& theShape, diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index e109838e8..1e965a798 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -1047,12 +1047,8 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapesMulti //Get the shapes std::list 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); diff --git a/src/GEOM_SWIG/GEOM_TestHealing.py b/src/GEOM_SWIG/GEOM_TestHealing.py index 72ad4927e..7d399a252 100644 --- a/src/GEOM_SWIG/GEOM_TestHealing.py +++ b/src/GEOM_SWIG/GEOM_TestHealing.py @@ -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): diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index b37da651a..a72a7d283 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -4800,7 +4800,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): return aList ## Get all sub-shapes, shared by all shapes in the list theShapes. - # @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 @@ -4815,7 +4815,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 @@ -4825,7 +4825,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 diff --git a/src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx b/src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx index c5880d796..2c0d98c73 100644 --- a/src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx +++ b/src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx @@ -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; } //=================================================================================