22747: [EDF] Improvement of Get Shared Shapes operation

This commit is contained in:
eap 2014-10-15 19:26:27 +04:00
parent e4a7d5ed70
commit 2bb925ff23
7 changed files with 63 additions and 50 deletions

View File

@ -5,7 +5,8 @@
This operation is a special case of <b>Explode</b> operation. It 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 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 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 To use this operation, select in the Main Menu <b>Operations -> Get
Shared Shapes.</b> The following dialog box will appear. 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 \image html shared_shapes.png
<ul> <ul>
<li> <b>Name</b> is the base name of the resulting 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>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>Sub-shapes Type</b> is the type of required sub-shapes. </li>
</ul> </ul>
\n <b>Advanced options</b> \ref preview_anchor "Preview" \n <b>Advanced options:</b> \ref preview_anchor "Preview"
<p>
\n <b>TUI Command:</b> <em> geompy.GetSharedShapesMulti(Shapes, <b>TUI Command:</b> <em> geompy.GetSharedShapesMulti( Shapes, Type ),</em>
Type),</em> where \em Shapes is a list of shapes to fing shared sub- <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. 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 Our <b>TUI Scripts</b> provide you with useful examples of the use of

View File

@ -2001,7 +2001,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
//purpose : //purpose :
//======================================================================= //=======================================================================
Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
(std::list<Handle(GEOM_Object)> theShapes, (std::list<Handle(GEOM_Object)> & theShapes,
const Standard_Integer theShapeType) const Standard_Integer theShapeType)
{ {
SetErrorCode(KO); SetErrorCode(KO);
@ -2012,18 +2012,33 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
int ind = 1; int ind = 1;
std::list<Handle(GEOM_Object)>::iterator it = theShapes.begin(); 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(); Handle(GEOM_Function) aMainShape = aMainObj->GetLastFunction();
if (aMainShape.IsNull()) {
TopTools_SequenceOfShape shapeSeq;
for (; it != theShapes.end(); it++, ind++) {
Handle(GEOM_Function) aRefShape = (*it)->GetLastFunction();
if (aRefShape.IsNull()) {
SetErrorCode("NULL shape for GetSharedShapes"); SetErrorCode("NULL shape for GetSharedShapes");
return NULL; return NULL;
} }
TopoDS_Shape aShape2 = aRefShape->GetValue();
if (aShape2.IsNull()) return NULL;
shapeSeq.Append( aShape2 );
}
TopoDS_Shape aShape1 = aMainShape->GetValue(); TopoDS_Shape aShape1 = shapeSeq.First();
if (aShape1.IsNull()) return NULL;
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; TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aShape1, anIndices); TopExp::MapShapes(aMainShape->GetValue(), anIndices);
TopTools_IndexedMapOfShape mapSelected; TopTools_IndexedMapOfShape mapSelected;
TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapSelected); TopExp::MapShapes(aShape1, TopAbs_ShapeEnum(theShapeType), mapSelected);
@ -2032,23 +2047,17 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
BRep_Builder B; BRep_Builder B;
TopoDS_Compound aCurrSelection; TopoDS_Compound aCurrSelection;
for (; it != theShapes.end(); it++, ind++) { for ( ind = 2; ind <= shapeSeq.Length(); ind++) {
Handle(GEOM_Function) aRefShape = (*it)->GetLastFunction();
if (aRefShape.IsNull()) {
SetErrorCode("NULL shape for GetSharedShapes");
return NULL;
}
TopoDS_Compound aCompound; TopoDS_Compound aCompound;
B.MakeCompound(aCompound); B.MakeCompound(aCompound);
TopoDS_Shape aShape2 = aRefShape->GetValue(); const TopoDS_Shape& aShape2 = shapeSeq.Value( ind );
if (aShape2.IsNull()) return NULL;
TopTools_MapOfShape mapShape2; TopTools_MapOfShape mapShape2;
TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType)); TopExp_Explorer exp (aShape2, TopAbs_ShapeEnum(theShapeType));
for (; exp.More(); exp.Next()) { for (; exp.More(); exp.Next()) {
TopoDS_Shape aSS = exp.Current(); const TopoDS_Shape& aSS = exp.Current();
if (mapShape2.Add(aSS) && mapSelected.Contains(aSS)) { if (mapShape2.Add(aSS) && mapSelected.Contains(aSS)) {
B.Add(aCompound, 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) // 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_HArray1OfInteger) anArray;
Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
TCollection_AsciiString anAsciiList, anEntry; TCollection_AsciiString anAsciiList, anEntry;
@ -2072,6 +2081,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
anObj = GetEngine()->AddSubShape(aMainObj, anArray); anObj = GetEngine()->AddSubShape(aMainObj, anArray);
aSeq->Append(anObj); aSeq->Append(anObj);
aLastCreated = GEOM::GetCreatedLast( aLastCreated, anObj );
// for python command // for python command
TDF_Tool::Entry(anObj->GetEntry(), anEntry); TDF_Tool::Entry(anObj->GetEntry(), anEntry);
anAsciiList += anEntry; anAsciiList += anEntry;
@ -2087,16 +2098,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetSharedShapes
anAsciiList.Trunc(anAsciiList.Length() - 1); anAsciiList.Trunc(anAsciiList.Length() - 1);
// IPAL22904: TC6.5.0: order of python commands is wrong after dump study // 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 // 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 if( aFunction.IsNull() ) // just in case
aFunction = aMainShape; aFunction = aMainShape;

View File

@ -166,7 +166,7 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
const Standard_Integer theShapeType); const Standard_Integer theShapeType);
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) Standard_EXPORT Handle(TColStd_HSequenceOfTransient)
GetSharedShapes (std::list<Handle(GEOM_Object)> theShapes, GetSharedShapes (std::list<Handle(GEOM_Object)>& theShapes,
const Standard_Integer theShapeType); const Standard_Integer theShapeType);
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) Standard_EXPORT Handle(TColStd_HSequenceOfTransient)

View File

@ -1047,12 +1047,8 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetSharedShapesMulti
//Get the shapes //Get the shapes
std::list<Handle(GEOM_Object)> aShapes; std::list<Handle(GEOM_Object)> aShapes;
int aLen = theShapes.length(); if (! GetListOfObjectsImpl( theShapes, aShapes ))
for (int ind = 0; ind < aLen; ind++) { return aSeq._retn();
Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
if (aSh.IsNull()) return aSeq._retn();
aShapes.push_back(aSh);
}
Handle(TColStd_HSequenceOfTransient) aHSeq = Handle(TColStd_HSequenceOfTransient) aHSeq =
GetOperations()->GetSharedShapes(aShapes, theShapeType); GetOperations()->GetSharedShapes(aShapes, theShapeType);

View File

@ -501,6 +501,14 @@ def TestSewGluing(geompy):
assert glueEL3.GetShapeType() == GEOM.COMPOUND assert glueEL3.GetShapeType() == GEOM.COMPOUND
assert geompy.NumberOfEdges( glueEL3 ) == geompy.NumberOfEdges( comp ) - 4 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 return
def TestHealingOperations (geompy, math): def TestHealingOperations (geompy, math):

View File

@ -4800,7 +4800,7 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
return aList return aList
## Get all sub-shapes, shared by all shapes in the list <VAR>theShapes</VAR>. ## 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 theShapeType Type of sub-shapes to be retrieved (see ShapeType())
# @param theName Object name; when specified, this parameter is used # @param theName Object name; when specified, this parameter is used
# for result publication in the study. Otherwise, if automatic # 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. Get all sub-shapes, shared by all shapes in the list theShapes.
Parameters: 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) theShapeType Type of sub-shapes to be retrieved (see geompy.ShapeType)
theName Object name; when specified, this parameter is used theName Object name; when specified, this parameter is used
for result publication in the study. Otherwise, if automatic 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. List of GEOM.GEOM_Object, that are sub-shapes of all given shapes.
""" """
# Example: see GEOM_TestOthers.py # Example: see GEOM_TestOthers.py
aList = self.ShapesOp.GetSharedShapesMulti(theShapes, theShapeType) aList = self.ShapesOp.GetSharedShapesMulti(ToList(theShapes), theShapeType)
RaiseIfFailed("GetSharedShapesMulti", self.ShapesOp) RaiseIfFailed("GetSharedShapesMulti", self.ShapesOp)
self._autoPublish(aList, theName, "shared") self._autoPublish(aList, theName, "shared")
return aList return aList

View File

@ -308,11 +308,16 @@ GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
//================================================================================= //=================================================================================
bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg) bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
{ {
bool isOK = true;
if (myListShapes.length() < 2) { if (myListShapes.length() < 2) {
msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES"); isOK = false;
return 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;
} }
//================================================================================= //=================================================================================