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.
\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
//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);
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);
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);
}
}
// 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;
anObj = GetEngine()->AddSubShape(aMainObj, anArray);
aSeq->Append(anObj);
+ aLastCreated = GEOM::GetCreatedLast( aLastCreated, anObj );
+
// for python command
TDF_Tool::Entry(anObj->GetEntry(), anEntry);
anAsciiList += anEntry;
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;
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,
//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);
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):
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
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
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
//=================================================================================
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;
}
//=================================================================================